123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- /**
- * @file bikelight.h
- * @author Wang, Zhiyu(wangzy49@midea.com)
- * @brief Light of ebike
- * @version 0.1
- * @date 2021-10-09
- *
- * @copyright Copyright (c) 2021
- *
- */
- /************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
- *************************************************************************/
- #ifndef BIKELIGHT_H
- #define BIKELIGHT_H
- #include "typedefine.h"
- typedef _Bool BOOL;
- #ifdef BIKELIGHT_
- #define EXTERNBIKE
- #else
- #define EXTERNBIKE extern
- #endif
- #define BIKEMODE_LUNGU_NORMOL 0X01 //常规控轮毂控制器,前后灯1路DCDC,1个IO控制使能
- #define BIKEMODE_LUNGU_OXFORD 0X02 //oxfordPCB版本,前后灯2路DCDC,2个IO控制器使能,2个IO选择电压
- #define BIKEMODE_LUNGU_750MINI 0x03 //短款750W,前后灯1路DCDC,开机使能,2个IO控制MOS,1个IO选择电压
- #define BIKEMODE BIKEMODE_LUNGU_OXFORD
- #define LED_OUTVOLT_6V 0X01
- #define LED_OUTVOLT_12V 0X02
- #define LED_OUTVOLT_6VOR12V 0X03
- #if(BIKEMODE==BIKEMODE_LUNGU_NORMOL) //常规控轮毂控制器,前后灯1路DCDC,1个IO控制使能
- #define LED_OUTVOLT LED_OUTVOLT_6V // led输出电压
- #define BIKELEDCHECK_F_ENABLE 0 //led前灯故障检测 0-失能 ,1使能LED灯压检测
- #define BIKELEDCHECK_R_ENABLE 0 //led尾灯故障检测 0-失能 ,1使能LED灯压检测
- #define BIKELEDOPEN_F_ENABLE 1 //前灯使能,0-失能,1-使能
- #define BIKELEDOPEN_R_ENABLE 1 //尾灯使能,0-失能,1-使能
- //- 管脚分配
- /*前灯控制IO on/off */
- #define IO_FORWARDLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_3)//
- #define IO_FORWARDLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_3)//
- #define IO_FORWARDLED_12V_ENABLE() __NOP()
- #define IO_FORWARDLED_12V_DISABLE() __NOP()
- /* 后灯控制IO on/off */
- #define IO_BACKLED_ON() __NOP()
- #define IO_BACKLED_OFF() __NOP()
- #define IO_BACKLED_12V_ENABLE() __NOP()
- #define IO_BACKLED_12V_DISABLE() __NOP()
- #elif(BIKEMODE==BIKEMODE_LUNGU_OXFORD) //oxfordPCB版本,前后灯2路DCDC,2个IO控制器使能,2个IO选择电压
- #define LED_OUTVOLT LED_OUTVOLT_6VOR12V // led检测电压
- #define BIKELEDCHECK_F_ENABLE 0 //led前灯故障检测 0-失能 ,1使能LED灯压检测
- #define BIKELEDCHECK_R_ENABLE 0 //led尾灯故障检测 0-失能 ,1使能LED灯压检测
- #define BIKELEDOPEN_F_ENABLE 1 //前灯使能,0-失能,1-使能
- #define BIKELEDOPEN_R_ENABLE 1 //尾灯使能,0-失能,1-使能
- //- -管脚分配
- /* 前灯控制IO on/off */
- //#define IO_FORWARDLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_3)////PB3
- //#define IO_FORWARDLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_3)//PB3
- //#define IO_FORWARDLED_12V_ENABLE() GPIO_SetBits(GPIOB,GPIO_Pin_6)//PB6
- //#define IO_FORWARDLED_12V_DISABLE() GPIO_ResetBits(GPIOB,GPIO_Pin_6)//PB6
- /* 后灯控制IO on/off */
- //#define IO_BACKLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_5)//PB5
- //#define IO_BACKLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_5) //PB5
- //#define IO_BACKLED_12V_ENABLE() GPIO_SetBits(GPIOB,GPIO_Pin_7)//PB7
- //#define IO_BACKLED_12V_DISABLE() GPIO_ResetBits(GPIOB,GPIO_Pin_7)//PB7
- #elif(BIKEMODE==BIKEMODE_LUNGU_750MINI) //短款750W,前后灯1路DCDC,开机使能,2个IO控制MOS,1个IO选择电压
- #define LED_OUTVOLT LED_OUTVOLT_6VOR12V // led检测电压
- #define BIKELEDCHECK_F_ENABLE 0 //led前灯故障检测 0-失能 ,1使能LED灯压检测
- #define BIKELEDCHECK_R_ENABLE 0 //led尾灯故障检测 0-失能 ,1使能LED灯压检测
- #define BIKELEDOPEN_F_ENABLE 1 //前灯使能,0-失能,1-使能
- #define BIKELEDOPEN_R_ENABLE 1 //尾灯使能,0-失能,1-使能
- //- -管脚分配
- /* 前灯控制IO on/off */
- #define IO_FORWARDLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_7) //PB7
- #define IO_FORWARDLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_7) //PB7
- #define IO_FORWARDLED_12V_ENABLE() GPIO_SetBits(GPIOB,GPIO_Pin_3) //PB3
- #define IO_FORWARDLED_12V_DISABLE() GPIO_ResetBits(GPIOB,GPIO_Pin_3) //PB3
- /* 后灯控制IO on/off */
- #define IO_BACKLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_6) //PB6
- #define IO_BACKLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_6) //PB6
- #define IO_BACKLED_12V_ENABLE() __NOP()
- #define IO_BACKLED_12V_DISABLE() __NOP()
- #else
- #define BIKELEDCHECK_F_ENABLE 0 //led前灯故障检测 0-失能 ,1使能LED灯压检测
- #define BIKELEDCHECK_R_ENABLE 0 //led尾灯故障检测 0-失能 ,1使能LED灯压检测
- #define BIKELEDOPEN_F_ENABLE 1 //前灯使能,0-失能,1-使能
- #define BIKELEDOPEN_R_ENABLE 0 //尾灯使能,0-失能,1-使能
- //- 管脚分配
- /* 前灯控制IO on/off */
- #define IO_FORWARDLED_ON() GPIO_SetBits(GPIOB,GPIO_Pin_3)//
- #define IO_FORWARDLED_OFF() GPIO_ResetBits(GPIOB,GPIO_Pin_3)//
- #endif
- //---------------------------------------
- #define BikeLedAddCycle 12 //亮尾灯周期
- #define BikeLedAddDuty 5 //亮尾灯占空比
- #define BikeLedFlickerHZ 50 //亮尾闪烁频率
- #define BikeLedFlickerCycle 1000/BikeLedFlickerHZ //亮尾灯周期
- #define BikeLedFlickerDuty BikeLedFlickerCycle/2 //亮尾灯占比
- //#define BikeLedOverSpedHZ 3 //亮尾闪烁频率
- #define BikeLedOverSpedCycle 3000 //周期
- #define BikeLedOverSpedDuty 500 //超速15KM/H亮尾灯占比
- #define BikeLedOverSpeedMax 150 //基本单位0.1km/h
- #define BikeLedOverSpeedMin 140 //基本单位0.1km/h
- //---------------------------------------------------------
- #define LIGHT_ERR_VOLTAGE_MAX 75 // 0.1v
- #define LIGHT_ERR_VOLTAGE_MIN 50 // 0.1v
- #define LIGHT_OFFERR_VOLTAGE 15 // 0.1v
- #define LEDERRTIME 5 //LED灯电路检测错误次数
- #define LEDRISETIME 200 //上升沿时间 1ms单位
- #define LEDFALLTIME 2000 //下降沿时间 1ms单位
- #define LIGHT_FIRSTPWM 144 //64KHZ,max=2304
- #define LIGHT_SECTPWM 691 //64KHZ,max=2304
- typedef enum
- {
- one_byte = 1,
- two_byte = 2,
- Three_byte = 3,
- four_byte = 4,
- five_byte = 5,
- six_byte = 6,
- seven_byte = 7,
- eight_byte = 8
- } LED_TYPE_STR;
- //typedef struct
- //{
- // UBYTE ubBike_keyLedSta; // 开关灯临时状态
- //
- // UWORD uwLedAddcnt;
- //
- //} BIKELED_STR;
- typedef enum
- {
- F_PWM_byte = 1,
- B_PWM_byte = 2,
- L_PWM_byte = 3,
- R_PWM_byte = 4,
- } LED_PWM_STR;
- typedef struct
- {
- UWORD uwLedOnVoltMax; // 开灯时上限电压
- UWORD uwLedOnVoltMin; //开灯时下限电压
- BOOL blBike_LedOnErr; // 开灯电路故障状态
- UWORD uwBike_LedOnErrCnt; // 开灯电路滤波
- UWORD uwBike_LedOnErrDCnt; // 开灯电路滤波
- UWORD uwBike_LedOnErrAddNO; // 开灯电路错误次数累加值
- UWORD uwLedOffVoltMax; // 关灯时上限电压
- BOOL blBike_LedOffErr; // 关灯电路故障状态
- UWORD uwBike_LedOffErrCnt; // 关灯电路滤波
- UWORD uwBike_LedOffErrDCnt; // 关灯电路滤波
- UWORD uwBike_LedOffErrAddNO; // 光灯电路错误次数累加值
- UWORD uwBike_LedVolt; //
- UWORD uwBike_LedMode; //
- UWORD uwBike_OpenPreTime; //
- UWORD uwBike_OpenLedEn; //
- UWORD uwBikeLight_PWM;
- UWORD uwBike_LedCheckLowTime; //
- UWORD uwBike_keyLedHighSta; // 开关灯临时状态
- UWORD uwBike_keyLedLowSta; // 开关灯临时状态
- UWORD uwLedAddcnt;
- BOOL blBike_LedCurErr; // 灯电路过流
- BOOL blBike_ForwardLedStart; // 前灯开灯过流反复标志
- } BIKELEDCHECK_STR;
- typedef struct
- {
- BOOL blBike_ForwardLedFlag; // 前灯开关状态
- BOOL blBike_BackLedSta;//尾灯开关状态
- // BOOL blBike_ForwardLedCurErr; // 前灯电路过流
- BOOL blBike_BackLedDetErr; // 尾灯电路
- BOOL blBike_BackLedStart; // 尾灯开灯过流反复标志
- //UWORD uwlBike_ForwardLedDetErrTime; // 前灯电路短路累计时间
- UWORD uwBike_BackLedDetErrTime; // 前灯电路短路累计时间
- UWORD uwBikeLight_L_PWM; //
- UWORD uwBikeLight_F_PWM; //
- } BIKELED_Global_STR;
- EXTERNBIKE BIKELED_Global_STR BikeLedGloFun;
- EXTERNBIKE BIKELEDCHECK_STR BikeLedCheck_F;//前灯参数
- EXTERNBIKE BIKELEDCHECK_STR BikeLedCheck_B;//尾灯参数
- EXTERNBIKE BIKELEDCHECK_STR BikeLedCheck_L;//左灯参数
- EXTERNBIKE BIKELEDCHECK_STR BikeLedCheck_R;//右灯参数
- //---------------------------------------
- /****************************************
- *
- * Definitions & Macros
- *
- ****************************************/
- #define BIKELIGHT_OUT_DEFAULT \
- { \
- 0, 0, 0, FALSE, LIGHT_Off \
- } // Default value of BIKELIGHT_OUT
- #define BIKELIGHT_COEF_DEFAULT \
- { \
- 0, 0, 0, 0, 0 \
- }
- #define LIGHT_POWER_ERROR_VOLTAGE_UP 70 // 0.1v
- #define LIGHT_POWER_ERROR_VOLTAGE_DOWN 50 // 0.1v
- #define LIGHT_POWER_ERROR_DETECT 2000 // ms
- #define LIGHT_POWER_ERROR_RECOVER 2000 // ms
- #define LIGHT_POWER_ERROR_SHUT 2000 // ms
- #define LIGHT_POWER_ERROR_TIMEUNIT 200 // ms
- /***************************************
- *
- * Type Definations
- *
- ***************************************/
- /**
- * @brief Light state
- *
- */
- typedef enum
- {
- LIGHT_Off = 0,
- LIGHT_On = 1,
- LIGHT_Error = 2,
- LIGHT_Shut = 3
- } LIGHT_STATE;
- /**
- * @brief BikeLight out
- *
- */
- typedef struct
- {
- UWORD uwBikeLightErrorCnt; // Cnt of detect GPIO low voltage
- UWORD uwBikeLightRecoverCnt; // Cnt of detect GPIO high voltage
- UWORD uwBikeLightShutCnt; // Cnt of detect GPIO high voltage
- BOOL blBikeLightErrorFlg; // flag of light error
- LIGHT_STATE LightState; // state of light
- } BIKELIGHT_OUT;
- typedef struct
- {
- UWORD uwBikeLightErrorCnt; // Cnt of detect GPIO low voltage
- UWORD uwBikeLightRecoverCnt; // Cnt of detect GPIO high voltage
- UWORD uwBikeLightShutCnt; // Cnt of detect GPIO high voltage
- UWORD uwBikeLightErrorVoltagePuDown; // flag of light error
- UWORD uwBikeLightErrorVoltagePuUp; // flag of light error
- } BIKELIGHT_COEF;
- /****************************************
- *
- * Exported variable
- *
- ****************************************/
- EXTERNBIKE BIKELIGHT_OUT bikelight_stBikeLightOut;
- /***************************************
- *
- * Function Definations
- *
- ***************************************/
- void bikelight_voBikeLightInit(void); // interface function
- void bikelight_voBikeLightCoef(UWORD volt);
- void bikelight_voGetBikeLightError(UWORD LightPowerVolPu,BOOL Ledsta,BIKELEDCHECK_STR *p);
- void bikelight_voBikeLightControl(UWORD switchAction, BOOL Brate_Sta);
- /************************************************************************
- Flag Define (N/A)
- *************************************************************************/
- #endif
- /************************************************************************
- Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
- All rights reserved.
- *************************************************************************
- End of this File (EOF):
- Do not put anything after this part!
- *************************************************************************/
|