bikelight.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /**
  2. * @file bikelight.h
  3. * @author Wang, Zhiyu(wangzy49@midea.com)
  4. * @brief Light of ebike
  5. * @version 0.1
  6. * @date 2021-10-09
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. /************************************************************************
  12. Beginning of File, do not put anything above here except notes
  13. Compiler Directives:
  14. *************************************************************************/
  15. #ifndef BIKELIGHT_H
  16. #define BIKELIGHT_H
  17. #include "typedefine.h"
  18. typedef _Bool BOOL;
  19. #ifdef BIKELIGHT_
  20. #define EXTERNBIKE
  21. #else
  22. #define EXTERNBIKE extern
  23. #endif
  24. #define BIKEMODE_LUNGU_NORMOL 0X01 //常规控轮毂控制器,前后灯1路DCDC,1个IO控制使能
  25. #define BIKEMODE_LUNGU_OXFORD 0X02 //oxfordPCB版本,前后灯2路DCDC,2个IO控制器使能,2个IO选择电压
  26. #define BIKEMODE_LUNGU_750MINI 0x03 //短款750W,前后灯1路DCDC,开机使能,2个IO控制MOS,1个IO选择电压
  27. #define BIKEMODE BIKEMODE_LUNGU_OXFORD
  28. #define LED_OUTVOLT_6V 0X01
  29. #define LED_OUTVOLT_12V 0X02
  30. #define LED_OUTVOLT_6VOR12V 0X03
  31. #if(BIKEMODE==BIKEMODE_LUNGU_NORMOL) //常规控轮毂控制器,前后灯1路DCDC,1个IO控制使能
  32. #define LED_OUTVOLT LED_OUTVOLT_6V // led输出电压
  33. #define BIKELEDCHECK_F_ENABLE 0 //led前灯故障检测 0-失能 ,1使能LED灯压检测
  34. #define BIKELEDCHECK_R_ENABLE 0 //led尾灯故障检测 0-失能 ,1使能LED灯压检测
  35. #define BIKELEDOPEN_F_ENABLE 1 //前灯使能,0-失能,1-使能
  36. #define BIKELEDOPEN_R_ENABLE 1 //尾灯使能,0-失能,1-使能
  37. //- 管脚分配
  38. /*前灯控制IO on/off */
  39. #define IO_FORWARDLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_3)//
  40. #define IO_FORWARDLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_3)//
  41. #define IO_FORWARDLED_12V_ENABLE() __NOP()
  42. #define IO_FORWARDLED_12V_DISABLE() __NOP()
  43. /* 后灯控制IO on/off */
  44. #define IO_BACKLED_ON() __NOP()
  45. #define IO_BACKLED_OFF() __NOP()
  46. #define IO_BACKLED_12V_ENABLE() __NOP()
  47. #define IO_BACKLED_12V_DISABLE() __NOP()
  48. #elif(BIKEMODE==BIKEMODE_LUNGU_OXFORD) //oxfordPCB版本,前后灯2路DCDC,2个IO控制器使能,2个IO选择电压
  49. #define LED_OUTVOLT LED_OUTVOLT_6VOR12V // led检测电压
  50. #define BIKELEDCHECK_F_ENABLE 0 //led前灯故障检测 0-失能 ,1使能LED灯压检测
  51. #define BIKELEDCHECK_R_ENABLE 0 //led尾灯故障检测 0-失能 ,1使能LED灯压检测
  52. #define BIKELEDOPEN_F_ENABLE 1 //前灯使能,0-失能,1-使能
  53. #define BIKELEDOPEN_R_ENABLE 1 //尾灯使能,0-失能,1-使能
  54. //- -管脚分配
  55. /* 前灯控制IO on/off */
  56. //#define IO_FORWARDLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_3)////PB3
  57. //#define IO_FORWARDLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_3)//PB3
  58. //#define IO_FORWARDLED_12V_ENABLE() GPIO_SetBits(GPIOB,GPIO_Pin_6)//PB6
  59. //#define IO_FORWARDLED_12V_DISABLE() GPIO_ResetBits(GPIOB,GPIO_Pin_6)//PB6
  60. /* 后灯控制IO on/off */
  61. //#define IO_BACKLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_5)//PB5
  62. //#define IO_BACKLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_5) //PB5
  63. //#define IO_BACKLED_12V_ENABLE() GPIO_SetBits(GPIOB,GPIO_Pin_7)//PB7
  64. //#define IO_BACKLED_12V_DISABLE() GPIO_ResetBits(GPIOB,GPIO_Pin_7)//PB7
  65. #elif(BIKEMODE==BIKEMODE_LUNGU_750MINI) //短款750W,前后灯1路DCDC,开机使能,2个IO控制MOS,1个IO选择电压
  66. #define LED_OUTVOLT LED_OUTVOLT_6VOR12V // led检测电压
  67. #define BIKELEDCHECK_F_ENABLE 0 //led前灯故障检测 0-失能 ,1使能LED灯压检测
  68. #define BIKELEDCHECK_R_ENABLE 0 //led尾灯故障检测 0-失能 ,1使能LED灯压检测
  69. #define BIKELEDOPEN_F_ENABLE 1 //前灯使能,0-失能,1-使能
  70. #define BIKELEDOPEN_R_ENABLE 1 //尾灯使能,0-失能,1-使能
  71. //- -管脚分配
  72. /* 前灯控制IO on/off */
  73. #define IO_FORWARDLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_7) //PB7
  74. #define IO_FORWARDLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_7) //PB7
  75. #define IO_FORWARDLED_12V_ENABLE() GPIO_SetBits(GPIOB,GPIO_Pin_3) //PB3
  76. #define IO_FORWARDLED_12V_DISABLE() GPIO_ResetBits(GPIOB,GPIO_Pin_3) //PB3
  77. /* 后灯控制IO on/off */
  78. #define IO_BACKLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_6) //PB6
  79. #define IO_BACKLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_6) //PB6
  80. #define IO_BACKLED_12V_ENABLE() __NOP()
  81. #define IO_BACKLED_12V_DISABLE() __NOP()
  82. #else
  83. #define BIKELEDCHECK_F_ENABLE 0 //led前灯故障检测 0-失能 ,1使能LED灯压检测
  84. #define BIKELEDCHECK_R_ENABLE 0 //led尾灯故障检测 0-失能 ,1使能LED灯压检测
  85. #define BIKELEDOPEN_F_ENABLE 1 //前灯使能,0-失能,1-使能
  86. #define BIKELEDOPEN_R_ENABLE 0 //尾灯使能,0-失能,1-使能
  87. //- 管脚分配
  88. /* 前灯控制IO on/off */
  89. #define IO_FORWARDLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_3)//
  90. #define IO_FORWARDLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_3)//
  91. #endif
  92. //---------------------------------------
  93. #define BikeLedAddCycle 12 //亮尾灯周期
  94. #define BikeLedAddDuty 5 //亮尾灯占空比
  95. #define BikeLedFlickerHZ 50 //亮尾闪烁频率
  96. #define BikeLedFlickerCycle 1000/BikeLedFlickerHZ //亮尾灯周期
  97. #define BikeLedFlickerDuty BikeLedFlickerCycle/2 //亮尾灯占比
  98. //#define BikeLedOverSpedHZ 3 //亮尾闪烁频率
  99. #define BikeLedOverSpedCycle 3000 //周期
  100. #define BikeLedOverSpedDuty 500 //超速15KM/H亮尾灯占比
  101. #define BikeLedOverSpeedMax 150 //基本单位0.1km/h
  102. #define BikeLedOverSpeedMin 140 //基本单位0.1km/h
  103. //---------------------------------------------------------
  104. #define LIGHT_ERR_VOLTAGE_MAX 75 // 0.1v
  105. #define LIGHT_ERR_VOLTAGE_MIN 50 // 0.1v
  106. #define LIGHT_OFFERR_VOLTAGE 15 // 0.1v
  107. #define LEDERRTIME 5 //LED灯电路检测错误次数
  108. #define LEDRISETIME 200 //上升沿时间 1ms单位
  109. #define LEDFALLTIME 2000 //下降沿时间 1ms单位
  110. #define LIGHT_FIRSTPWM 144 //64KHZ,max=2304
  111. #define LIGHT_SECTPWM 691 //64KHZ,max=2304
  112. typedef enum
  113. {
  114. one_byte = 1,
  115. two_byte = 2,
  116. Three_byte = 3,
  117. four_byte = 4,
  118. five_byte = 5,
  119. six_byte = 6,
  120. seven_byte = 7,
  121. eight_byte = 8
  122. } LED_TYPE_STR;
  123. //typedef struct
  124. //{
  125. // UBYTE ubBike_keyLedSta; // 开关灯临时状态
  126. //
  127. // UWORD uwLedAddcnt;
  128. //
  129. //} BIKELED_STR;
  130. typedef enum
  131. {
  132. F_PWM_byte = 1,
  133. B_PWM_byte = 2,
  134. L_PWM_byte = 3,
  135. R_PWM_byte = 4,
  136. } LED_PWM_STR;
  137. typedef struct
  138. {
  139. UWORD uwLedOnVoltMax; // 开灯时上限电压
  140. UWORD uwLedOnVoltMin; //开灯时下限电压
  141. BOOL blBike_LedOnErr; // 开灯电路故障状态
  142. UWORD uwBike_LedOnErrCnt; // 开灯电路滤波
  143. UWORD uwBike_LedOnErrDCnt; // 开灯电路滤波
  144. UWORD uwBike_LedOnErrAddNO; // 开灯电路错误次数累加值
  145. UWORD uwLedOffVoltMax; // 关灯时上限电压
  146. BOOL blBike_LedOffErr; // 关灯电路故障状态
  147. UWORD uwBike_LedOffErrCnt; // 关灯电路滤波
  148. UWORD uwBike_LedOffErrDCnt; // 关灯电路滤波
  149. UWORD uwBike_LedOffErrAddNO; // 光灯电路错误次数累加值
  150. UWORD uwBike_LedVolt; //
  151. UWORD uwBike_LedMode; //
  152. UWORD uwBike_OpenPreTime; //
  153. UWORD uwBike_OpenLedEn; //
  154. UWORD uwBikeLight_PWM;
  155. UWORD uwBike_LedCheckLowTime; //
  156. UWORD uwBike_keyLedHighSta; // 开关灯临时状态
  157. UWORD uwBike_keyLedLowSta; // 开关灯临时状态
  158. UWORD uwLedAddcnt;
  159. BOOL blBike_LedCurErr; // 灯电路过流
  160. BOOL blBike_ForwardLedStart; // 前灯开灯过流反复标志
  161. } BIKELEDCHECK_STR;
  162. typedef struct
  163. {
  164. BOOL blBike_ForwardLedFlag; // 前灯开关状态
  165. BOOL blBike_BackLedSta;//尾灯开关状态
  166. // BOOL blBike_ForwardLedCurErr; // 前灯电路过流
  167. BOOL blBike_BackLedDetErr; // 尾灯电路
  168. BOOL blBike_BackLedStart; // 尾灯开灯过流反复标志
  169. //UWORD uwlBike_ForwardLedDetErrTime; // 前灯电路短路累计时间
  170. UWORD uwBike_BackLedDetErrTime; // 前灯电路短路累计时间
  171. UWORD uwBikeLight_L_PWM; //
  172. UWORD uwBikeLight_F_PWM; //
  173. } BIKELED_Global_STR;
  174. EXTERNBIKE BIKELED_Global_STR BikeLedGloFun;
  175. EXTERNBIKE BIKELEDCHECK_STR BikeLedCheck_F;//前灯参数
  176. EXTERNBIKE BIKELEDCHECK_STR BikeLedCheck_B;//尾灯参数
  177. EXTERNBIKE BIKELEDCHECK_STR BikeLedCheck_L;//左灯参数
  178. EXTERNBIKE BIKELEDCHECK_STR BikeLedCheck_R;//右灯参数
  179. //---------------------------------------
  180. /****************************************
  181. *
  182. * Definitions & Macros
  183. *
  184. ****************************************/
  185. #define BIKELIGHT_OUT_DEFAULT \
  186. { \
  187. 0, 0, 0, FALSE, LIGHT_Off \
  188. } // Default value of BIKELIGHT_OUT
  189. #define BIKELIGHT_COEF_DEFAULT \
  190. { \
  191. 0, 0, 0, 0, 0 \
  192. }
  193. #define LIGHT_POWER_ERROR_VOLTAGE_UP 70 // 0.1v
  194. #define LIGHT_POWER_ERROR_VOLTAGE_DOWN 50 // 0.1v
  195. #define LIGHT_POWER_ERROR_DETECT 2000 // ms
  196. #define LIGHT_POWER_ERROR_RECOVER 2000 // ms
  197. #define LIGHT_POWER_ERROR_SHUT 2000 // ms
  198. #define LIGHT_POWER_ERROR_TIMEUNIT 200 // ms
  199. /***************************************
  200. *
  201. * Type Definations
  202. *
  203. ***************************************/
  204. /**
  205. * @brief Light state
  206. *
  207. */
  208. typedef enum
  209. {
  210. LIGHT_Off = 0,
  211. LIGHT_On = 1,
  212. LIGHT_Error = 2,
  213. LIGHT_Shut = 3
  214. } LIGHT_STATE;
  215. /**
  216. * @brief BikeLight out
  217. *
  218. */
  219. typedef struct
  220. {
  221. UWORD uwBikeLightErrorCnt; // Cnt of detect GPIO low voltage
  222. UWORD uwBikeLightRecoverCnt; // Cnt of detect GPIO high voltage
  223. UWORD uwBikeLightShutCnt; // Cnt of detect GPIO high voltage
  224. BOOL blBikeLightErrorFlg; // flag of light error
  225. LIGHT_STATE LightState; // state of light
  226. } BIKELIGHT_OUT;
  227. typedef struct
  228. {
  229. UWORD uwBikeLightErrorCnt; // Cnt of detect GPIO low voltage
  230. UWORD uwBikeLightRecoverCnt; // Cnt of detect GPIO high voltage
  231. UWORD uwBikeLightShutCnt; // Cnt of detect GPIO high voltage
  232. UWORD uwBikeLightErrorVoltagePuDown; // flag of light error
  233. UWORD uwBikeLightErrorVoltagePuUp; // flag of light error
  234. } BIKELIGHT_COEF;
  235. /****************************************
  236. *
  237. * Exported variable
  238. *
  239. ****************************************/
  240. EXTERNBIKE BIKELIGHT_OUT bikelight_stBikeLightOut;
  241. /***************************************
  242. *
  243. * Function Definations
  244. *
  245. ***************************************/
  246. void bikelight_voBikeLightInit(void); // interface function
  247. void bikelight_voBikeLightCoef(UWORD volt);
  248. void bikelight_voGetBikeLightError(UWORD LightPowerVolPu,BOOL Ledsta,BIKELEDCHECK_STR *p);
  249. void bikelight_voBikeLightControl(UWORD switchAction, BOOL Brate_Sta);
  250. /************************************************************************
  251. Flag Define (N/A)
  252. *************************************************************************/
  253. #endif
  254. /************************************************************************
  255. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  256. All rights reserved.
  257. *************************************************************************
  258. End of this File (EOF):
  259. Do not put anything after this part!
  260. *************************************************************************/