Commit ddb97726 authored by 张金硕's avatar 张金硕

Merge branch 'jinshuo' into 'dev'

Jinshuo

See merge request !79
parents ce9abc76 9b31a9e8
...@@ -7,6 +7,7 @@ uint8_t GetBlueToothVaild = 0; ...@@ -7,6 +7,7 @@ uint8_t GetBlueToothVaild = 0;
uint8_t GetPhoneBookVaild = 0; uint8_t GetPhoneBookVaild = 0;
uint8_t TextInit = 0; uint8_t TextInit = 0;
uint8_t SetUUIDTimes = 0; uint8_t SetUUIDTimes = 0;
uint16_t LastPhoneBookTotalCount = 0;
_PICID_Struct PicObj; _PICID_Struct PicObj;
_QRCODE_RECT QRCode_Rect; _QRCODE_RECT QRCode_Rect;
const uint8_t HJBlueToothName[9]= {"HJ750"}; const uint8_t HJBlueToothName[9]= {"HJ750"};
...@@ -131,6 +132,9 @@ uint8_t PhoneNumber[40]; ...@@ -131,6 +132,9 @@ uint8_t PhoneNumber[40];
uint8_t LastPhoneNumber[20]; uint8_t LastPhoneNumber[20];
uint8_t LastBlueToothPhoneName[100]; uint8_t LastBlueToothPhoneName[100];
uint8_t CurBlueToothPhoneName[100]; uint8_t CurBlueToothPhoneName[100];
uint8_t BlueToothName[40];
uint8_t LastBlueToothName[20];
uint8_t PhoneNumberTotal[20];
void TextService(void) void TextService(void)
{ {
...@@ -141,6 +145,9 @@ void TextService(void) ...@@ -141,6 +145,9 @@ void TextService(void)
memset(LastPhoneNumber, 0, sizeof(LastPhoneNumber)); memset(LastPhoneNumber, 0, sizeof(LastPhoneNumber));
memset(LastBlueToothPhoneName, 0, sizeof(LastBlueToothPhoneName)); memset(LastBlueToothPhoneName, 0, sizeof(LastBlueToothPhoneName));
memset(CurBlueToothPhoneName, 0, sizeof(CurBlueToothPhoneName)); memset(CurBlueToothPhoneName, 0, sizeof(CurBlueToothPhoneName));
memset(BlueToothName, 0, sizeof(BlueToothName));
memset(LastBlueToothName, 0, sizeof(LastBlueToothName));
memset(PhoneNumberTotal, 0, sizeof(PhoneNumberTotal));
} }
if (BlueToothPhoneData.BlueToothSignalSate == BlueTooth_Connection) if (BlueToothPhoneData.BlueToothSignalSate == BlueTooth_Connection)
{ {
...@@ -167,5 +174,37 @@ void TextService(void) ...@@ -167,5 +174,37 @@ void TextService(void)
} }
} }
} }
if(Menu_Get_Current_Cursor_Information() == MENU_ITEM_BLUETOOTH_CONNECT)
{
if (memcmp(LastBlueToothName, BlueToothPhoneData.BlueToothName, sizeof(LastBlueToothName)) != 0)
{
for (uint8_t i = 0; i < sizeof(BlueToothPhoneData.BlueToothName); i++)
{
BlueToothName[i * 2] = BlueToothPhoneData.BlueToothName[i];
BlueToothName[(i * 2) + 1] = 0X00;
}
memcpy(LastBlueToothName, BlueToothPhoneData.BlueToothName, sizeof(LastBlueToothName));
TextPara[TEXT_NUM_BLUETOOTH_NAME].Vaild = 0X01;
}
}
if (LastPhoneBookTotalCount != BlueToothPhoneData.PhoneBookTotalCount)
{
uint8_t TempNumberCnts = 0;
if (BlueToothPhoneData.PhoneBookTotalCount > 100)
{
PhoneNumberTotal[TempNumberCnts++] = (BlueToothPhoneData.PhoneBookTotalCount / 100) + 0x30;
PhoneNumberTotal[TempNumberCnts++] = 0x00;
}
if (BlueToothPhoneData.PhoneBookTotalCount > 10)
{
PhoneNumberTotal[TempNumberCnts++] = (BlueToothPhoneData.PhoneBookTotalCount / 10 % 10) + 0x30;
PhoneNumberTotal[TempNumberCnts++] = 0x00;
}
PhoneNumberTotal[TempNumberCnts++] = (BlueToothPhoneData.PhoneBookTotalCount % 100 % 10) + 0x30;
PhoneNumberTotal[TempNumberCnts++] = 0x00;
TextPara[TEXT_NUM_PHONE_NUMBER_TOTAL].Vaild = 0x01;
LastPhoneBookTotalCount = BlueToothPhoneData.PhoneBookTotalCount;
}
} }
...@@ -39,6 +39,8 @@ extern _PICID_Struct PicObj; ...@@ -39,6 +39,8 @@ extern _PICID_Struct PicObj;
extern _QRCODE_RECT QRCode_Rect; extern _QRCODE_RECT QRCode_Rect;
extern uint8_t PhoneNumber[40]; extern uint8_t PhoneNumber[40];
extern uint8_t CurBlueToothPhoneName[100]; extern uint8_t CurBlueToothPhoneName[100];
extern uint8_t BlueToothName[40];
extern uint8_t PhoneNumberTotal[20];
extern TEXT_STRUCT TextPara[]; extern TEXT_STRUCT TextPara[];
#endif #endif
\ No newline at end of file
...@@ -73,7 +73,7 @@ void Key_Operation_Right(Key_Event_en_t enKeyEvent)//确认 ...@@ -73,7 +73,7 @@ void Key_Operation_Right(Key_Event_en_t enKeyEvent)//确认
case KEY_EVENT_LONG_PRESS_3: //5s case KEY_EVENT_LONG_PRESS_3: //5s
break; break;
case KEY_EVENT_LONG_PRESS_4: //10s case KEY_EVENT_LONG_PRESS_4: //10s
//TYW_RESET_ODO(); TYW_RESET_ODO();
Get_Into_OTA_Update_Mode(); Get_Into_OTA_Update_Mode();
break; break;
case KEY_EVENT_OFF_TO_ON: case KEY_EVENT_OFF_TO_ON:
...@@ -355,7 +355,7 @@ void TYW_RESET_ODO(void) ...@@ -355,7 +355,7 @@ void TYW_RESET_ODO(void)
if((Get_DispVechileSpeed() >= 1500)&&(Get_DispEngineSpeed() >= 12000)) if((Get_DispVechileSpeed() >= 1500)&&(Get_DispEngineSpeed() >= 12000))
{ {
ClearODO_Flag = 1; ClearODO_Flag = 1;
//Data_Mileage_Clear(); Data_Mileage_Clear();
} }
} }
} }
...@@ -390,7 +390,7 @@ void My_Key_Service(void) ...@@ -390,7 +390,7 @@ void My_Key_Service(void)
/* 自检时不可操作按键 */ /* 自检时不可操作按键 */
if(g_u8SelfCheck) if(g_u8SelfCheck)
{ {
if(Get_ActualVechileSpeed() == 0) if((Get_ActualVechileSpeed() == 0) ||((Get_DispVechileSpeed() >= 1990) && (Get_DispEngineSpeed() >= 12000)))
{ {
Key_Service(); Key_Service();
} }
......
...@@ -12,11 +12,8 @@ ...@@ -12,11 +12,8 @@
typedef struct typedef struct
{ {
TIMERM_PWM_Counter_en_t counter; //定时器选择 TIMERM_PWM_Counter_en_t counter; // 定时器选择
}Display_mode_Struct; } Display_mode_Struct;
/*-------------------PWM相关-------------------------------------*/ /*-------------------PWM相关-------------------------------------*/
// extern void TimerB_PWM_Init(void); // extern void TimerB_PWM_Init(void);
...@@ -31,10 +28,10 @@ typedef struct ...@@ -31,10 +28,10 @@ typedef struct
// extern void TimerB_PWM_Channel_Sleep(TIMERB_Channel_en_t enTimerBChannel); // extern void TimerB_PWM_Channel_Sleep(TIMERB_Channel_en_t enTimerBChannel);
TMM_InitTypeDef TIMM_InitStructure[2] = {0}; TMM_InitTypeDef TIMM_InitStructure[2] = {0};
static uint32_t cycle_pulse[2]; //一个周期的时钟数 //频率 static uint32_t cycle_pulse[2] = {0}; //一个周期的时钟数 //频率
static uint32_t high_level_Pulse[2][3]; //高电平时钟数 //占空比 static uint32_t high_level_Pulse[2][3] = {0}; //高电平时钟数 //占空比
static uint32_t pwm_duty[2][3]; static uint32_t pwm_duty[2][3] = {0};
/** /**
* @brief 设置TimerM的定时器x的模式为比较输出 * @brief 设置TimerM的定时器x的模式为比较输出
...@@ -43,84 +40,111 @@ static uint32_t pwm_duty[2][3]; ...@@ -43,84 +40,111 @@ static uint32_t pwm_duty[2][3];
* @param freq 比较输出频率 * @param freq 比较输出频率
* @return uint8_t 返回0成功,非0失败 * @return uint8_t 返回0成功,非0失败
*/ */
uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t freq, uint32_t PWM_Clock)//, uint32_t PWM_Clock //SystemCoreClock uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t freq, uint32_t PWM_Clock) //, uint32_t PWM_Clock //SystemCoreClock
{ {
if (counter == TIMERM_COUNTER0) if ((counter < 0) || (counter >= TIMERM_COUNTER_MAX))
{
TIMM_InitStructure[counter].TMM_Select = TMM0;
}
else if (counter == TIMERM_COUNTER1)
{
TIMM_InitStructure[counter].TMM_Select = TMM1;
}
else
{ {
return 1; return 1;
} }
TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B|TMM_Channel_C|TMM_Channel_D;
TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
TIMM_InitStructure[counter].TMM_Intp = TMM_Int_NONE; ///compare match interrupt enable A (IMIEA)
if (freq > 2000)
{
TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div1; // specify the operation clk of tim
cycle_pulse[counter] = PWM_Clock / freq;
}
// else if(freq >= 500)
// {
// TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div8; // specify the operation clk of tim
// cycle_pulse[counter] = PWM_Clock / 8 / freq;
// }
else if(freq >= 50)
{
TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div32; // specify the operation clk of tim
cycle_pulse[counter] = PWM_Clock / 32 / freq;
}
else else
{ {
return 1; if (counter == TIMERM_COUNTER0)
} {
TIMM_InitStructure[counter].TMM_Select = TMM0;
TIMM_InitStructure[counter].TMM_CHA_Pulse = cycle_pulse[counter] & 0x0FFFF;//这里需要计算,调试下 period; //周期设置为period
// TMM_Init(&TIMM_InitStructure[counter]);
// if (counter == TIMERM_COUNTER0)
// {
// TMM0_Start(ENABLE);
// }
// else if (counter == TIMERM_COUNTER1)
// {
// TMM1_Start(ENABLE);
// }
return 0; TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A | TMM_Channel_B | TMM_Channel_C | TMM_Channel_D;
TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; // when TM is matched with TMGRA, TM0 is cleared
TIMM_InitStructure[counter].TMM_Intp = TMM_Int_NONE; /// compare match interrupt enable A (IMIEA)
}
else if (counter == TIMERM_COUNTER1)
{
TIMM_InitStructure[counter].TMM_Select = TMM1;
TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A | TMM_Channel_B; //|TMM_Channel_C|TMM_Channel_D;
TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; // when TM is matched with TMGRA, TM0 is cleared
TIMM_InitStructure[counter].TMM_Intp = TMM_Int_NONE; /// compare match interrupt enable A (IMIEA)
}
else
{
return 1;
}
// TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B|TMM_Channel_C|TMM_Channel_D;
// TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
// TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
// TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA)
if (freq > 2000)
{
TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div1; // specify the operation clk of tim
cycle_pulse[counter] = PWM_Clock / freq;
}
// else if(freq >= 500)
// {
// TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div8; // specify the operation clk of tim
// cycle_pulse[counter] = PWM_Clock / 8 / freq;
// }
else if (freq >= 50)
{
TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div32; // specify the operation clk of tim
cycle_pulse[counter] = PWM_Clock / 32 / freq;
}
else
{
return 1;
}
TIMM_InitStructure[counter].TMM_CHA_Pulse = (uint16_t)(cycle_pulse[counter] & 0x0FFFF); // 这里需要计算,调试�? period; //周期设置为period
// TMM_Init(&TIMM_InitStructure[counter]);
// if (counter == TIMERM_COUNTER0)
// {
// TMM0_Start(ENABLE);
// }
// else if (counter == TIMERM_COUNTER1)
// {
// TMM1_Start(ENABLE);
// }
return 0;
}
return 1;
} }
//uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t freq)//, uint32_t PWM_Clock //SystemCoreClock // uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t freq)//, uint32_t PWM_Clock //SystemCoreClock
//{ //{
// if (counter == TIMERM_COUNTER0) // SystemCoreClock = 64000000UL;
// { //
// TIMM_InitStructure[counter].TMM_Select = TMM0; // if (counter == TIMERM_COUNTER0)
// } // {
// else if (counter == TIMERM_COUNTER1) // TIMM_InitStructure[counter].TMM_Select = TMM0;
// { //
// TIMM_InitStructure[counter].TMM_Select = TMM1; // TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_B|TMM_Channel_C|TMM_Channel_D;
// } // TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
// else // TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
// { // TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA)
// return 1; // }
// } // else if (counter == TIMERM_COUNTER1)
// // {
// TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B|TMM_Channel_C|TMM_Channel_D; // TIMM_InitStructure[counter].TMM_Select = TMM1;
// TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM; // TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_B;
// TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared // TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
// TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA) // TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
// // TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA)
// }
// else
// {
// return 1;
// }
//
//// TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B|TMM_Channel_C|TMM_Channel_D;
//// TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
//// TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
//// TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA)
//
// if (freq > 2000) // if (freq > 2000)
// { // {
// TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div1; // specify the operation clk of tim // TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div1; // specify the operation clk of tim
...@@ -140,11 +164,11 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t ...@@ -140,11 +164,11 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t
// { // {
// return 1; // return 1;
// } // }
// //
// TIMM_InitStructure[counter].TMM_CHA_Pulse = cycle_pulse[counter] & 0x0FFFF;//这里需要计算,调试 period; //周期设置为period // TIMM_InitStructure[counter].TMM_CHA_Pulse = cycle_pulse[counter] & 0x0FFFF;//这里需要计算,调试�? period; //周期设置为period
// //
// //
// //
// // TMM_Init(&TIMM_InitStructure[counter]); // // TMM_Init(&TIMM_InitStructure[counter]);
// // if (counter == TIMERM_COUNTER0) // // if (counter == TIMERM_COUNTER0)
...@@ -159,8 +183,6 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t ...@@ -159,8 +183,6 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t
// return 0; // return 0;
//} //}
/** /**
* @brief 设置timerM定时器x通道x的占空比 * @brief 设置timerM定时器x通道x的占空比
* *
...@@ -170,133 +192,153 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t ...@@ -170,133 +192,153 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t
* @param ActiveLevel 0负占空比 1正占空比 * @param ActiveLevel 0负占空比 1正占空比
* @return uint8_t 返回0成功,非0失败 * @return uint8_t 返回0成功,非0失败
*/ */
uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_en_t ch,TIMERM_PWM_ActiveLevel_en_t ActiveLevel) uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_en_t ch, TIMERM_PWM_ActiveLevel_en_t ActiveLevel)
{ {
GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitTypeDef GPIO_InitStruct;
if ((counter < 0) || (counter >= TIMERM_COUNTER_MAX))
switch (ch)
{ {
case TIMERM_CHB: return 1;
TIMM_InitStructure[counter].TMM_CHB_Pulse = ((cycle_pulse[counter]) ) & 0x0FFFF; //TM计数达到TMGRB. 占空比:duty2/period }
TIMM_InitStructure[counter].TMM_PWM.TMM_CHB.TMM_PWMInitLevel = TMM_PWMInitLevel_High; else
TIMM_InitStructure[counter].TMM_PWM.TMM_CHB.TMM_PWMActiveLevel = ActiveLevel; {
if (counter == TIMERM_COUNTER0) switch (ch)
{
GPIO_PinAFConfig(GPIO_PORT1,GPIO_Pin_4,GPIO_P14,GROUP_AF_ODEFAULT); //P14 used as TMIOB0 output(default function)
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4 ;
}
else if (counter == TIMERM_COUNTER1)
{ {
GPIO_PinAFConfig(GPIO_PORT1,GPIO_Pin_0,GPIO_P10,GROUP_AF_ODEFAULT); //P14 used as TMIOB1 output(default function) case TIMERM_CHB:
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 ; TIMM_InitStructure[counter].TMM_CHB_Pulse = (uint16_t)(cycle_pulse[counter] & 0x0FFFF); // TM计数达到TMGRB. 占空�?:duty2/period
TIMM_InitStructure[counter].TMM_PWM.TMM_CHB.TMM_PWMInitLevel = TMM_PWMInitLevel_High;
TIMM_InitStructure[counter].TMM_PWM.TMM_CHB.TMM_PWMActiveLevel = (uint8_t)ActiveLevel;
if (counter == TIMERM_COUNTER0)
{
GPIO_PinAFConfig(GPIO_PORT1, GPIO_Pin_4, GPIO_P14, GROUP_AF_ODEFAULT); // P14 used as TMIOB0 output(default function)
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
}
else if (counter == TIMERM_COUNTER1)
{
GPIO_PinAFConfig(GPIO_PORT1, GPIO_Pin_0, GPIO_P10, GROUP_AF_ODEFAULT); // P14 used as TMIOB1 output(default function)
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
}
break;
case TIMERM_CHC:
TIMM_InitStructure[counter].TMM_CHC_Pulse = (uint16_t)(cycle_pulse[counter] & 0x0FFFF); // TM计数达到TMGRC. 占空�?:duty2/period
TIMM_InitStructure[counter].TMM_PWM.TMM_CHC.TMM_PWMInitLevel = TMM_PWMInitLevel_High;
TIMM_InitStructure[counter].TMM_PWM.TMM_CHC.TMM_PWMActiveLevel = ActiveLevel;
if (counter == TIMERM_COUNTER0)
{
GPIO_PinAFConfig(GPIO_PORT1, GPIO_Pin_6, GPIO_P16, GROUP_AF_ODEFAULT); // P16 used as TMIOC0 output(default function)
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
}
else if (counter == TIMERM_COUNTER1)
{
/* code */
}
break;
case TIMERM_CHD:
TIMM_InitStructure[counter].TMM_CHD_Pulse = (uint16_t)(cycle_pulse[counter] & 0x0FFFF); // TM计数达到TMGRD. 占空�?:duty3/period
TIMM_InitStructure[counter].TMM_PWM.TMM_CHD.TMM_PWMInitLevel = TMM_PWMInitLevel_High; // TMM_PWMInitLevel_High;//
TIMM_InitStructure[counter].TMM_PWM.TMM_CHD.TMM_PWMActiveLevel = ActiveLevel; // TMM_PWMActiveLevel_Low;//TMM_PWMActiveLevel_High;//
if (counter == TIMERM_COUNTER0)
{
GPIO_PinAFConfig(GPIO_PORT1, GPIO_Pin_7, GPIO_P17, GROUP_AF_TMIOD0); // P15 used as TMIOD0 output(default function)
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
}
else if (counter == TIMERM_COUNTER1)
{
/* code */
}
break;
default:
return 1;
// break;
} }
break;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
case TIMERM_CHC: GPIO_InitStruct.GPIO_Level = GPIO_Level_LOW;
TIMM_InitStructure[counter].TMM_CHC_Pulse = ((cycle_pulse[counter]) ) & 0x0FFFF; //TM计数达到TMGRC. 占空比:duty2/period GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
TIMM_InitStructure[counter].TMM_PWM.TMM_CHC.TMM_PWMInitLevel = TMM_PWMInitLevel_High; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
TIMM_InitStructure[counter].TMM_PWM.TMM_CHC.TMM_PWMActiveLevel = ActiveLevel; GPIO_Init(GPIO_PORT1, &GPIO_InitStruct);
if (counter == TIMERM_COUNTER0)
if ((counter < 0) || (counter >= TIMERM_COUNTER_MAX))
{ {
GPIO_PinAFConfig(GPIO_PORT1,GPIO_Pin_6,GPIO_P16,GROUP_AF_ODEFAULT); //P16 used as TMIOC0 output(default function) return 1;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
} }
else if (counter == TIMERM_COUNTER1) else
{ {
/* code */ TMM_Init(&TIMM_InitStructure[counter]);
} }
break;
case TIMERM_CHD:
TIMM_InitStructure[counter].TMM_CHD_Pulse = ((cycle_pulse[counter]) ) & 0x0FFFF; //TM计数达到TMGRD. 占空比:duty3/period
TIMM_InitStructure[counter].TMM_PWM.TMM_CHD.TMM_PWMInitLevel = TMM_PWMInitLevel_High;//TMM_PWMInitLevel_High;//
TIMM_InitStructure[counter].TMM_PWM.TMM_CHD.TMM_PWMActiveLevel = ActiveLevel;//TMM_PWMActiveLevel_Low;//TMM_PWMActiveLevel_High;//
if (counter == TIMERM_COUNTER0) if (counter == TIMERM_COUNTER0)
{ {
GPIO_PinAFConfig(GPIO_PORT1,GPIO_Pin_7,GPIO_P17,GROUP_AF_TMIOD0); //P15 used as TMIOD0 output(default function) TMM0_Start(ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7 ;
} }
else if (counter == TIMERM_COUNTER1) else if (counter == TIMERM_COUNTER1)
{ {
/* code */ TMM1_Start(ENABLE);
}
else
{
return 1;
} }
break;
default:
return 1;
//break;
}
TMM_Init(&TIMM_InitStructure[counter]);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Level = GPIO_Level_LOW;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIO_PORT1,&GPIO_InitStruct);
if (counter == TIMERM_COUNTER0)
{
TMM0_Start(ENABLE);
}
else if (counter == TIMERM_COUNTER1)
{
TMM1_Start(ENABLE);
}
else
{
return 1;
}
high_level_Pulse[counter][ch] = ((cycle_pulse[counter]) ) & 0x0FFFF;
pwm_duty[counter][ch] = 1000;
return 0;
}
high_level_Pulse[counter][ch] = ((cycle_pulse[counter])) & 0x0FFFF;
pwm_duty[counter][ch] = 1000;
return 0;
}
return 1;
}
extern void TMM0_Set_Counter(uint8_t ch,uint16_t value); extern void TMM0_Set_Counter(uint8_t ch, uint16_t value);
extern void TMM1_Set_Counter(uint8_t ch,uint16_t value); extern void TMM1_Set_Counter(uint8_t ch, uint16_t value);
/** /**
* @brief 改变TimerM PWM输出的占空比 * @brief 改变TimerM PWM输出的占空比
* *
* @param counter 定时器x * @param counter 定时器x
* @param ch 通道x * @param ch 通道x
* @param duty 占空比 千分之一 * @param duty 占空比 千分之一
* @return uint8_t 返回0成功,非0失败 * @return uint8_t 返回0成功,非0失败
*/ */
uint8_t TimerM_PWM_set_duty(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_en_t ch, uint16_t duty ) uint8_t TimerM_PWM_set_duty(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_en_t ch, uint16_t duty)
{ {
if (duty >= 1000) if ((counter < 0) || (counter >= TIMERM_COUNTER_MAX))
{ {
duty = 0; return 1;
}
else if (duty <= 0)
{
duty = 1000;
}
if (counter == TIMERM_COUNTER0)
{
high_level_Pulse[counter][ch] = (((cycle_pulse[counter] * duty) / 1000) & 0x0FFFF);
TMM0_Set_Counter(1 << (ch + 1), high_level_Pulse[counter][ch]);
}
else if (counter == TIMERM_COUNTER1)
{
high_level_Pulse[counter][ch] = (((cycle_pulse[counter] * duty) / 1000) & 0x0FFFF);
TMM1_Set_Counter(1 << (ch + 1), high_level_Pulse[counter][ch]);
} }
else else
{ {
return 1; if (duty >= 1000)
} {
duty = 0;
}
else if (duty <= 0)
{
duty = 1000;
}
pwm_duty[counter][ch] = duty; if (counter == TIMERM_COUNTER0)
return 0; {
high_level_Pulse[counter][ch] = (((cycle_pulse[counter] * duty) / 1000) & 0x0FFFF);
TMM0_Set_Counter(1 << (ch + 1), (uint16_t)(high_level_Pulse[counter][ch] & 0x0FFFF));
}
else if (counter == TIMERM_COUNTER1)
{
high_level_Pulse[counter][ch] = (((cycle_pulse[counter] * duty) / 1000) & 0x0FFFF);
TMM1_Set_Counter(1 << (ch + 1), (uint16_t)(high_level_Pulse[counter][ch] & 0x0FFFF));
}
else
{
return 1;
}
pwm_duty[counter][ch] = duty;
return 0;
}
return 1;
} }
/** /**
...@@ -310,13 +352,18 @@ uint8_t TimerM_PWM_set_duty(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_ ...@@ -310,13 +352,18 @@ uint8_t TimerM_PWM_set_duty(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_
* 如果不在一个频率区间就需要使用TimerM_PWM_set_freq来不优雅的切换频率, * 如果不在一个频率区间就需要使用TimerM_PWM_set_freq来不优雅的切换频率,
* 如果看不懂注释也使用TimerM_PWM_set_freq来切换频率。 * 如果看不懂注释也使用TimerM_PWM_set_freq来切换频率。
*/ */
uint8_t TimerM_PWM_set_freq(TIMERM_PWM_Counter_en_t counter, uint16_t freq ) uint8_t TimerM_PWM_set_freq(TIMERM_PWM_Counter_en_t counter, uint16_t freq)
{ {
if (counter < TIMERM_COUNTER_MAX)
if ((counter < 0) || (counter >= TIMERM_COUNTER_MAX))
{
return 1;
}
else
{ {
if (freq > 2000) if (freq > 2000)
{ {
TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div1; // specify the operation clk of tim TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div1; // specify the operation clk of tim
cycle_pulse[counter] = SystemCoreClock / freq; cycle_pulse[counter] = SystemCoreClock / freq;
} }
// else if(freq >= 500) // else if(freq >= 500)
...@@ -324,9 +371,9 @@ uint8_t TimerM_PWM_set_freq(TIMERM_PWM_Counter_en_t counter, uint16_t freq ) ...@@ -324,9 +371,9 @@ uint8_t TimerM_PWM_set_freq(TIMERM_PWM_Counter_en_t counter, uint16_t freq )
// TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div8; // specify the operation clk of tim // TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div8; // specify the operation clk of tim
// cycle_pulse[counter] = SystemCoreClock / 8 / freq; // cycle_pulse[counter] = SystemCoreClock / 8 / freq;
// } // }
else if(freq >= 50) else if (freq >= 50)
{ {
TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div32; // specify the operation clk of tim TIMM_InitStructure[counter].TMM_Clk = TMM_FCLK_Div32; // specify the operation clk of tim
cycle_pulse[counter] = SystemCoreClock / 32 / freq; cycle_pulse[counter] = SystemCoreClock / 32 / freq;
} }
else else
...@@ -334,49 +381,46 @@ uint8_t TimerM_PWM_set_freq(TIMERM_PWM_Counter_en_t counter, uint16_t freq ) ...@@ -334,49 +381,46 @@ uint8_t TimerM_PWM_set_freq(TIMERM_PWM_Counter_en_t counter, uint16_t freq )
return 1; return 1;
} }
} high_level_Pulse[counter][TIMERM_CHB] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHB]) / 1000) & 0x0FFFF);
else high_level_Pulse[counter][TIMERM_CHC] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHC]) / 1000) & 0x0FFFF);
{ high_level_Pulse[counter][TIMERM_CHD] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHD]) / 1000) & 0x0FFFF);
return 1;
}
high_level_Pulse[counter][TIMERM_CHB] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHB]) / 1000) & 0x0FFFF);
high_level_Pulse[counter][TIMERM_CHC] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHC]) / 1000) & 0x0FFFF);
high_level_Pulse[counter][TIMERM_CHD] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHD]) / 1000) & 0x0FFFF);
TIMM_InitStructure[counter].TMM_CHB_Pulse = high_level_Pulse[counter][TIMERM_CHB]; TIMM_InitStructure[counter].TMM_CHB_Pulse = (uint16_t)(high_level_Pulse[counter][TIMERM_CHB] & 0x0FFFF);
TIMM_InitStructure[counter].TMM_CHC_Pulse = high_level_Pulse[counter][TIMERM_CHC]; TIMM_InitStructure[counter].TMM_CHC_Pulse = (uint16_t)(high_level_Pulse[counter][TIMERM_CHC] & 0x0FFFF);
TIMM_InitStructure[counter].TMM_CHD_Pulse = high_level_Pulse[counter][TIMERM_CHD]; TIMM_InitStructure[counter].TMM_CHD_Pulse = (uint16_t)(high_level_Pulse[counter][TIMERM_CHD] & 0x0FFFF);
TIMM_InitStructure[counter].TMM_CHA_Pulse = (uint16_t)(cycle_pulse[counter] & 0x0FFFF);
TIMM_InitStructure[counter].TMM_CHA_Pulse = cycle_pulse[counter] & 0x0FFFF;
TMM_Init(&TIMM_InitStructure[counter]); if ((counter < TIMERM_COUNTER_MAX) && (counter >= TIMERM_COUNTER0))
{
TMM_Init(&TIMM_InitStructure[counter]);
}
if (counter == TIMERM_COUNTER0) if (counter == TIMERM_COUNTER0)
{ {
TMM0_Start(ENABLE); TMM0_Start(ENABLE);
} }
else if (counter == TIMERM_COUNTER1) else if (counter == TIMERM_COUNTER1)
{ {
TMM1_Start(ENABLE); TMM1_Start(ENABLE);
}
return 0;
} }
return 0; return 1;
} }
uint8_t TimerM_PWM_set_freq2(TIMERM_PWM_Counter_en_t counter, uint16_t freq)
uint8_t TimerM_PWM_set_freq2(TIMERM_PWM_Counter_en_t counter, uint16_t freq )
{ {
if (counter == TIMERM_COUNTER0) if (counter == TIMERM_COUNTER0)
{ {
cycle_pulse[counter] = SystemCoreClock / freq; cycle_pulse[counter] = SystemCoreClock / freq;
high_level_Pulse[counter][TIMERM_CHB] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHB]) / 1000) & 0x0FFFF); high_level_Pulse[counter][TIMERM_CHB] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHB]) / 1000) & 0x0FFFF);
high_level_Pulse[counter][TIMERM_CHC] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHC]) / 1000) & 0x0FFFF); high_level_Pulse[counter][TIMERM_CHC] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHC]) / 1000) & 0x0FFFF);
high_level_Pulse[counter][TIMERM_CHD] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHD]) / 1000) & 0x0FFFF); high_level_Pulse[counter][TIMERM_CHD] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHD]) / 1000) & 0x0FFFF);
TMM0_Set_Counter(1 << 1, high_level_Pulse[counter][TIMERM_CHB]); TMM0_Set_Counter(1 << 1, (uint16_t)(high_level_Pulse[counter][TIMERM_CHB] & 0x0FFFF));
TMM0_Set_Counter(1 << 2, high_level_Pulse[counter][TIMERM_CHC]); TMM0_Set_Counter(1 << 2, (uint16_t)(high_level_Pulse[counter][TIMERM_CHC] & 0x0FFFF));
TMM0_Set_Counter(1 << 3, high_level_Pulse[counter][TIMERM_CHD]); TMM0_Set_Counter(1 << 3, (uint16_t)(high_level_Pulse[counter][TIMERM_CHD] & 0x0FFFF));
TMM0_Set_Counter(1, cycle_pulse[counter]); TMM0_Set_Counter(1, (uint16_t)(cycle_pulse[counter] & 0x0FFFF));
} }
else if (counter == TIMERM_COUNTER1) else if (counter == TIMERM_COUNTER1)
{ {
...@@ -384,22 +428,19 @@ uint8_t TimerM_PWM_set_freq2(TIMERM_PWM_Counter_en_t counter, uint16_t freq ) ...@@ -384,22 +428,19 @@ uint8_t TimerM_PWM_set_freq2(TIMERM_PWM_Counter_en_t counter, uint16_t freq )
high_level_Pulse[counter][TIMERM_CHB] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHB]) / 1000) & 0x0FFFF); high_level_Pulse[counter][TIMERM_CHB] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHB]) / 1000) & 0x0FFFF);
high_level_Pulse[counter][TIMERM_CHC] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHC]) / 1000) & 0x0FFFF); high_level_Pulse[counter][TIMERM_CHC] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHC]) / 1000) & 0x0FFFF);
high_level_Pulse[counter][TIMERM_CHD] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHD]) / 1000) & 0x0FFFF); high_level_Pulse[counter][TIMERM_CHD] = (((cycle_pulse[counter] * pwm_duty[counter][TIMERM_CHD]) / 1000) & 0x0FFFF);
TMM1_Set_Counter(1 << 1, high_level_Pulse[counter][TIMERM_CHB]); TMM1_Set_Counter(1 << 1, (uint16_t)(high_level_Pulse[counter][TIMERM_CHB] & 0x0FFFF));
TMM1_Set_Counter(1 << 2, high_level_Pulse[counter][TIMERM_CHC]); TMM1_Set_Counter(1 << 2, (uint16_t)(high_level_Pulse[counter][TIMERM_CHC] & 0x0FFFF));
TMM1_Set_Counter(1 << 3, high_level_Pulse[counter][TIMERM_CHD]); TMM1_Set_Counter(1 << 3, (uint16_t)(high_level_Pulse[counter][TIMERM_CHD] & 0x0FFFF));
TMM1_Set_Counter(1, cycle_pulse[counter]); TMM1_Set_Counter(1, (uint16_t)(cycle_pulse[counter] & 0x0FFFF));
} }
else else
{ {
return 1; return 1;
} }
return 0;
return 0;
} }
void TimerM_PWM_Init(void) void TimerM_PWM_Init(void)
{ {
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment