• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef APP_DEMO_MULTI_SAMPLE_H
17 #define APP_DEMO_MULTI_SAMPLE_H
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <memory.h>
22 #include <hi_time.h>
23 #include <hi_watchdog.h>
24 #include <hi_io.h>
25 #include "ssd1306_oled.h"
26 #include "hi_gpio.h"
27 #include "iot_gpio_ex.h"
28 #include "iot_errno.h"
29 
30 #define KEY_INTERRUPT_PROTECT_TIME (40)
31 #define KEY_DOWN_INTERRUPT          (1)
32 #define GPIO_DEMO_TASK_STAK_SIZE    (1024*2)
33 #define GPIO_DEMO_TASK_PRIORITY     (25)
34 
35 #define MAX_FUNCTION_SINGLE_DEMO    (1)
36 #define MAX_FUNCTION_DEMO_NUM       (4)
37 #define MAX_COLORFUL_LIGHT_MODE     (8)
38 #define MAX_TRAFFIC_LIGHT_MODE      (4)
39 #define MAX_NFC_TAG_MODE            (6)
40 #define MAX_ENVIRONMENT_MODE        (5)
41 
42 #define MAX_CONTROL_MODE_TYPE       (2)
43 #define MAX_COLORFUL_LIGHT_TYPE     (2)
44 #define MAX_PWM_CONTROL_TYPE        (4)
45 #define MAX_BRIGHTNESS_TYPE         (2)
46 #define RETURN_TYPE_MODE            (2)
47 
48 #define MAX_TRAFFIC_CONTROL_TYPE    (3)
49 #define MAX_TRAFFIC_AUTO_TYPE       (2)
50 #define MAX_TRAFFIC_HUMAN_TYPE      (1)
51 
52 #define OLED_FLAG_ON                ((hi_u8)0x01)
53 #define OLED_FLAG_OFF               ((hi_u8)0x00)
54 
55 #define  KEY_GPIO_5                 (1)
56 #define  KEY_GPIO_7                 (2)
57 
58 #define LIGHT_ONE_SECOND_INTERVAL       (60)
59 #define BEEP_ONE_SECOND_INTERVAL        (15)
60 #define BEEP_HALF_SECOND_INTERVAL       (8)
61 #define BEEP_QUARTER_SECOND_INTERVAL    (4)
62 
63 
64 #define RED_LIGHT_FLASH_TIME        (3)    // 红灯闪3秒
65 #define YELLOW_LIGHT_FLASH_TIME     (3)    // 黄灯闪3秒
66 #define GREEN_LIGHT_FLASH_TIME      (3)    // 绿灯闪3秒
67 
68 #define TRAFFIC_AUTO_MODE_TIME_COUNT            (3)
69 #define TRAFFIC_HUMAN_MODE_NORMAL_TIME_COUNT    (3)
70 #define TRAFFIC_HUMAN_MODE_TIME_CONUT           (3)
71 
72 #define COUNT_NUM (3)
73 
74 #define FACTORY_HISPARK_BOARD_TEST(fmt, ...) \
75 do { \
76     printf(fmt, ##__VA_ARGS__); \
77     for (hi_s32 i = 0; i < COUNT_NUM; i++) { \
78         HisparkBoardTest(HI_GPIO_VALUE0); \
79         hi_udelay(DELAY_250_MS); \
80         HisparkBoardTest(HI_GPIO_VALUE1); \
81         hi_udelay(DELAY_250_MS); \
82     } \
83 } while (0)
84 
85 typedef enum {
86     HI_GPIO_0 = 0,
87     HI_GPIO_1,
88     HI_GPIO_2,
89     HI_GPIO_3,
90     HI_GPIO_4,
91     HI_GPIO_5,
92     HI_GPIO_6,
93     HI_GPIO_7,
94     HI_GPIO_8,
95     HI_GPIO_9,
96     HI_GPIO_10,
97     HI_GPIO_11,
98     HI_GPIO_12,
99     HI_GPIO_13,
100     HI_GPIO_14
101 } HiGpioNum;
102 
103 typedef enum {
104     HI_PWM0 = 0,
105     HI_PWM1,
106     HI_PWM2,
107     HI_PWM3,
108     HI_PWM_OUT = 5,
109     HI_PWM_MAX
110 } HiPwmChannal;
111 
112 typedef enum {
113     BEEP_BY_ONE_SECOND,
114     BEEP_BY_HALF_SECOND,
115     BEEP_BY_QUARTER_SECOND
116 } HiBeepStatus;
117 
118 typedef enum {
119     RED_COUNT = 0,
120     YELLOW_COUNT,
121     GREEN_COUNT,
122     DEFAULT
123 } HiLedTimeCount;
124 
125 typedef enum {
126     MAIN_FUNCTION_SELECT_MODE = 0,
127     SUB_MODE_SELECT_MODE
128 } HiMenuMode;
129 
130 typedef enum {
131     COLORFUL_LIGHT_FUNC = 0,
132     TRAFFIC_LIGHT_FUNC,
133     ENVIRONMENT_FUNC,
134     NFC_TEST_FUNC
135 } HiSelectFunc;
136 
137 typedef enum {
138     COLORFUL_LIGHT_MENU = 0,
139     TRAFFIC_LIGHT_MENU,
140     ENVIRONMENT_MENU,
141     NFC_TEST_MENU
142 } HiSelectMenuMode;
143 
144 typedef enum {
145     CONTROL_MODE = 0,
146     COLORFUL_LIGHT_MODE,
147     PWM_CONTROL_MODE,
148     BRIGHTNESS_MODE,
149     HUMAN_DETECT_MODE,
150     LIGHT_DETECT_MODE,
151     UNION_DETECT_MODE,
152     RETURN_MODE
153 } HiColorfulLightMode;
154 
155 typedef enum {
156     TRAFFIC_CONTROL_MODE = 0,
157     TRAFFIC_AUTO_MODE,
158     TRAFFIC_HUMAN_MODE,
159     TRAFFIC_RETURN_MODE
160 } HiTrafficLightMode;
161 
162 typedef enum {
163     TRAFFIC_NORMAL_TYPE = 0,
164     TRAFFIC_HUMAN_TYPE
165 } HiTrafficLightType;
166 
167 typedef enum {
168     NFC_TAG_WECHAT_MODE = 0,
169     NFC_TAG_TODAY_HEADLINE_MODE,
170     NFC_TAG_TAOBAO_MODE,
171     NFC_TAG_HW_LIFE_MODE,
172     NFC_TAG_HISTREAMING_MODE,
173     NFC_RETURN_MODE
174 } HiNfcMode;
175 
176 typedef enum {
177     ENV_ALL_MODE = 0,
178     ENV_TEMPERATURE_MODE,
179     ENV_HUMIDITY_MODE,
180     COMBUSTIBLE_GAS_MODE,
181     ENV_RETURN_MODE
182 } HiEnvironmentMode;
183 
184 typedef enum {
185     RED_ON = 0,
186     YELLOW_ON,
187     GREEN_ON
188 } HiControlModeType;
189 
190 typedef enum {
191     BEEP_OFF = 0,
192     BEEP_ON,
193 } HiBeepStatusType;
194 
195 typedef enum {
196     CYCLE_FOR_ONE_SECOND = 0,
197     CYCLE_FOR_HALF_SECOND,
198     CYCLE_FOR_QUARTER_SECOND
199 } HiColorfulLightType;
200 
201 typedef enum {
202     PWM_CONTROL_RED = 0,
203     PWM_CONTROL_YELLOW,
204     PWM_CONTROL_GREEN,
205     PWM_CONTROL_PURPLE,
206     PWM_CONTROL_ALL
207 } PwmControlModeType;
208 
209 typedef enum {
210     BRIGHTNESS_LOW = 0,
211     BRIGHTNESS_MIDDLE,
212     BRIGHTNESS_HIGH
213 } BrightnessType;
214 
215 typedef enum {
216     KEY_UP = 0,
217     KEY_DOWN
218 } HiReturnSelectType;
219 
220 typedef enum {
221     ZERO = 0,
222     ONE,
223     TWO,
224     THREE,
225     FOUR,
226     FIVE
227 } TimeCount;
228 
229 typedef enum {
230     MENU_SELECT = 0,
231     MENU_MODE,
232     CURRENT_MODE,
233     CURRENT_TYPE,
234     KEY_DOWN_FLAG,
235     OC_BEEP_STATUS = 5,
236     SOMEONE_WALKING,
237 }GlobalStatusDef;
238 
239 typedef struct {
240     unsigned char g_menuSelect;
241     unsigned char g_menuMode;
242     unsigned char g_currentMode;
243     unsigned char g_currentType;
244     unsigned char g_keyDownFlag;
245     unsigned int g_gpio5Tick;
246     unsigned int g_gpio7Tick;
247     unsigned int g_gpio8Tick;
248     unsigned char g_gpio9Tick;
249     unsigned int g_gpio7FirstKeyDown;
250     unsigned char g_gpio8CurrentType;
251     unsigned char g_ocBeepStatus;
252     unsigned char g_someoneWalkingFlag;
253     unsigned char g_withLightFlag;
254 } GlobalStatusType;
255 
256 void GpioKey1IsrFuncMode(void);
257 void GpioKey2IsrFuncType(void);
258 void HisparkBoardTest(IotGpioValue value);
259 void GpioControl(unsigned int gpio, unsigned int id, IotGpioDir dir, IotGpioValue gpioVal, unsigned char val);
260 void PwmInit(unsigned int id, unsigned char val, unsigned int port);
261 void HiSwitchInit(unsigned int id, unsigned char val, unsigned int idx, IotGpioDir dir, IotIoPull pval);
262 void TestGpioInit(void);
263 void ControlModeSample(void);
264 unsigned char DelayAndCheckKeyInterrupt(unsigned int delayTime);
265 void CycleForOneSecond(void);
266 void CycleForHalfSecond(void);
267 void CycleForQuarterSecond(void);
268 void ColorfulLightSample(void);
269 void AllLightOut(void);
270 void RedLightDarkToBright(void);
271 void GreenLightDarkToBright(void);
272 void BlueLightDarkToBright(void);
273 void PurpleLightDarkToBright(void);
274 void AllLightDarkToBright(void);
275 void PwmControlSample(void);
276 void BrightnessControlSample(void);
277 void HumanDetectSample(void);
278 void LightDetectSample(void);
279 void UnionDetectSample(void);
280 void ReturnMainEnumSample(void);
281 void Gpio9LedLightFunc(void);
282 void Gpio8Interrupt(const char *param);
283 void AppMultiSampleDemo(void);
284 unsigned char SetKeyStatus(HiColorfulLightMode setSta);
285 unsigned char SetKeyType(HiColorfulLightMode setSta);
286 unsigned char GetKeyStatus(GlobalStatuDef staDef);
287 #endif