bsp_led.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #include "include.h"
  2. #include "bsp_led.h"
  3. #if LED_DISP_EN
  4. extern led_cb_t led_cb;
  5. extern led_cb_t led_bak;
  6. extern sys_led_t sys_led;
  7. void bt_set_sync_info(u8 *buf);
  8. void speaker_unmute_charge_rled_on(void);
  9. void port_2bled_on(gpio_t *g);
  10. void port_2rled_on(gpio_t *g);
  11. void port_2led_off(gpio_t *g);
  12. void pwm_led_func_set(void);
  13. void pwm_led_stop(void);
  14. ////50ms调用周期
  15. //AT(.com_text.led_disp)
  16. //void led_scan(void)
  17. //{
  18. // uint bcnt;
  19. //
  20. // if (sys_led.scan_dis) { //关LED扫描
  21. // return;
  22. // }
  23. // if (led_cb.wait) {
  24. // led_cb.wait--;
  25. // return;
  26. // }
  27. //
  28. // //等待间隔时间
  29. // if (led_cb.unit) {
  30. // bcnt = led_cb.cnt / led_cb.unit;
  31. // } else {
  32. // bcnt = led_cb.cnt;
  33. // }
  34. // if (bcnt <= 7) {
  35. // if (led_cb.bled_sta & BIT(bcnt)) {
  36. // bled_set_on();
  37. // } else {
  38. // bled_set_off();
  39. // }
  40. // if (led_cb.rled_sta & BIT(bcnt)) {
  41. // rled_set_on();
  42. // } else {
  43. // rled_set_off();
  44. // }
  45. // }
  46. // if (led_cb.cnt < 0xffff) {
  47. // led_cb.cnt++;
  48. // if (led_cb.cnt > led_cb.circle) {
  49. // led_cb.cnt = 0;
  50. // }
  51. // if (led_cb.period == 0xff) { //只循环一次
  52. // if (bcnt && bcnt <= 8) {
  53. // led_cb.bled_sta &= ~BIT(bcnt - 1);
  54. // led_cb.rled_sta &= ~BIT(bcnt - 1);
  55. // }
  56. // }
  57. // }
  58. //}
  59. #if USER_PWM_LED_EN
  60. AT(.com_text.led_disp)
  61. void led_cfg_pwm_init(gpio_t *g)
  62. {
  63. sys_cb1.pwm_bled_on = 0;
  64. pwm_led_func_set();
  65. }
  66. AT(.com_text.led_disp)
  67. void led_cfg_pwm_set_on(gpio_t *g)
  68. {
  69. sys_cb1.pwm_bled_on = 1;
  70. pwm_led_start();
  71. }
  72. AT(.com_text.led_disp)
  73. void led_cfg_pwm_set_off(gpio_t *g)
  74. {
  75. sys_cb1.pwm_bled_on = 0;
  76. pwm_led_stop();
  77. }
  78. AT(.com_text.led_disp)
  79. void rled_cfg_pwm_init(gpio_t *g)
  80. {
  81. sys_cb1.pwm_rled_on = 0;
  82. pwm_led_func_set();
  83. }
  84. AT(.com_text.led_disp)
  85. void rled_cfg_pwm_set_on(gpio_t *g)
  86. {
  87. sys_cb1.pwm_rled_on = 1;
  88. pwm_led_start();
  89. }
  90. AT(.com_text.led_disp)
  91. void rled_cfg_pwm_set_off(gpio_t *g)
  92. {
  93. sys_cb1.pwm_rled_on = 0;
  94. pwm_led_stop();
  95. }
  96. #endif
  97. #if PORT_2LED_FIX_EN
  98. AT(.com_text.led_disp)
  99. void bled2_set_on_fix(gpio_t *g)
  100. {
  101. if ((g == NULL) || (g->sfr == NULL)) {
  102. return;
  103. }
  104. if (!(sys_led.port2led_sta & BIT(0))) {
  105. port_2bled_on(g);
  106. sys_led.port2led_sta |= BIT(0);
  107. }
  108. }
  109. AT(.com_text.led_disp)
  110. void bled2_set_off_fix(gpio_t *g)
  111. {
  112. if ((g == NULL) || (g->sfr == NULL)) {
  113. return;
  114. }
  115. if (sys_led.port2led_sta & BIT(0)) {
  116. port_2led_off(g);
  117. sys_led.port2led_sta &= ~BIT(0);
  118. }
  119. }
  120. AT(.com_text.led_disp)
  121. void rled2_set_on_fix(gpio_t *g)
  122. {
  123. if ((g == NULL) || (g->sfr == NULL)) {
  124. return;
  125. }
  126. if (!(sys_led.port2led_sta & BIT(1))) {
  127. port_2rled_on(g);
  128. sys_led.port2led_sta |= BIT(1);
  129. }
  130. }
  131. AT(.com_text.led_disp)
  132. void rled2_set_off_fix(gpio_t *g)
  133. {
  134. if ((g == NULL) || (g->sfr == NULL)) {
  135. return;
  136. }
  137. if (sys_led.port2led_sta & BIT(1)) {
  138. port_2led_off(g);
  139. sys_led.port2led_sta &= ~BIT(1);
  140. }
  141. }
  142. #endif // PORT_2LED_FIX_EN
  143. //充电红灯亮
  144. AT(.com_text.led_disp)
  145. void charge_led_on(void)
  146. {
  147. if (sys_led.charge_rled_en) {
  148. speaker_unmute_charge_rled_on();
  149. LED_PWR_SET_ON();
  150. }
  151. if (sys_led.charge_bled_en) {
  152. LED_SET_ON(); //充电过程中同时亮红,蓝灯
  153. }
  154. #if LED_BREATHE_EN
  155. if (sys_led.charge_bre_en) {
  156. breathe_led_start(T_BRE_CHARGE, sys_led.charge_bre_cfg);
  157. }
  158. #endif
  159. }
  160. #if USER_LED_GPIO
  161. #define USER_GPIO_PU_SEL GPIOxPU //可选上拉电阻: GPIOxPU, GPIOxPU200K, GPIOxPU300
  162. #define USER_GPIO_PD_SEL GPIOxPD //可选上拉电阻: GPIOxPD, GPIOxPD200K, GPIOxPD300
  163. AT(.com_text.led_disp)
  164. void user_led_cfg_set_on(gpio_t *g)
  165. {
  166. led_cfg_set_on(g);
  167. if (!(g->type)) {
  168. g->sfr[GPIOxPU300] &= ~BIT(g->num); //固定去掉上拉300K,不要修改
  169. g->sfr[USER_GPIO_PU_SEL] |= BIT(g->num);
  170. }
  171. }
  172. AT(.com_text.led_disp)
  173. void user_led_cfg_set_off(gpio_t *g)
  174. {
  175. led_cfg_set_off(g);
  176. if (!(g->type)) {
  177. g->sfr[USER_GPIO_PU_SEL] &= ~BIT(g->num);
  178. }
  179. }
  180. //一个IO口推两个LED灯
  181. void user_led2_port_init(gpio_t *g)
  182. {
  183. led2_port_init(g);
  184. g->sfr[USER_GPIO_PU_SEL] &= ~BIT(g->num);
  185. g->sfr[USER_GPIO_PD_SEL] &= ~BIT(g->num);
  186. }
  187. AT(.com_text.led_disp)
  188. void user_led2_set_off(gpio_t *g)
  189. {
  190. if (!(g->type)) {
  191. g->sfr[USER_GPIO_PU_SEL] &= ~BIT(g->num);
  192. g->sfr[USER_GPIO_PD_SEL] &= ~BIT(g->num);
  193. }
  194. }
  195. //蓝灯亮,红灯灭
  196. AT(.com_text.led_disp)
  197. void user_bled2_set_on(gpio_t *g)
  198. {
  199. #if PORT_2LED_FIX_EN
  200. bled2_set_on_fix(g);
  201. #else
  202. bled2_set_on(g);
  203. #endif
  204. if (!(g->type)) {
  205. g->sfr[GPIOxPD300] &= ~BIT(g->num); //固定去掉下拉300K,不要修改
  206. g->sfr[USER_GPIO_PD_SEL] |= BIT(g->num);
  207. }
  208. }
  209. AT(.com_text.led_disp)
  210. void user_bled2_set_off(gpio_t *g)
  211. {
  212. #if PORT_2LED_FIX_EN
  213. bled2_set_off_fix(g);
  214. #else
  215. bled2_set_off(g);
  216. #endif
  217. user_led2_set_off(g);
  218. }
  219. AT(.com_text.led_disp)
  220. void user_rled2_set_on(gpio_t *g)
  221. {
  222. #if PORT_2LED_FIX_EN
  223. rled2_set_on_fix(g);
  224. #else
  225. rled2_set_on(g);
  226. #endif
  227. if (!(g->type)) {
  228. g->sfr[GPIOxPU300] &= ~BIT(g->num); //固定去掉上拉300K,不要修改
  229. g->sfr[USER_GPIO_PU_SEL] |= BIT(g->num);
  230. }
  231. }
  232. AT(.com_text.led_disp)
  233. void user_rled2_set_off(gpio_t *g)
  234. {
  235. #if PORT_2LED_FIX_EN
  236. rled2_set_off_fix(g);
  237. #else
  238. rled2_set_off(g);
  239. #endif
  240. user_led2_set_off(g);
  241. }
  242. #endif // USER_LED_GPIO
  243. #endif