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