1 /****************************************************************************** 2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK") 3 * All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *****************************************************************************/ 18 #ifndef BLT_LED_H_ 19 #define BLT_LED_H_ 20 21 #include "tl_common.h" 22 23 #ifndef BLT_APP_LED_ENABLE 24 #define BLT_APP_LED_ENABLE 0 25 #endif 26 27 /** 28 * @brief Configure the parameters for led event 29 */ 30 typedef struct { 31 unsigned short onTime_ms; 32 unsigned short offTime_ms; 33 34 unsigned char repeatCount; // 0xff special for long on(offTime_ms=0)/long off(onTime_ms=0) 35 unsigned char priority; // 0x00 < 0x01 < 0x02 < 0x04 < 0x08 < 0x10 < 0x20 < 0x40 < 0x80 36 } led_cfg_t; 37 38 /** 39 * @brief the status of led event 40 */ 41 typedef struct { 42 unsigned char isOn; 43 unsigned char polar; 44 unsigned char repeatCount; 45 unsigned char priority; 46 47 unsigned short onTime_ms; 48 unsigned short offTime_ms; 49 50 unsigned int gpio_led; 51 unsigned int startTick; 52 } device_led_t; 53 54 extern device_led_t device_led; 55 56 #define DEVICE_LED_BUSY (device_led.repeatCount) 57 58 /** 59 * @brief This function is used to manage led tasks 60 * @param[in] none 61 * @return none 62 */ 63 extern void led_proc(void); 64 65 /** 66 * @brief This function is used to initialize device led setting 67 * @param[in] gpio - the GPIO corresponding to device led 68 * @param[in] polarity - 1 for high led on, 0 for low led on 69 * @return none 70 */ 71 extern void device_led_init(u32 gpio, u8 polarity); 72 73 /** 74 * @brief This function is used to create new led task 75 * @param[in] led_cfg - Configure the parameters for led event 76 * @return 0 - new led event priority not higher than the not ongoing one 77 * 1 - new led event created successfully 78 */ 79 int device_led_setup(led_cfg_t led_cfg); 80 81 /** 82 * @brief This function is used to manage led tasks 83 * @param[in] none 84 * @return none 85 */ device_led_process(void)86static inline void device_led_process(void) 87 { 88 #if (BLT_APP_LED_ENABLE) 89 if (DEVICE_LED_BUSY) { 90 led_proc(); 91 } 92 #endif 93 } 94 95 #endif /* BLT_LED_H_ */ 96