[X9D] Trims working, RTC driver fix

This commit is contained in:
bernet.andre@gmail.com
2013-01-11 21:38:04 +00:00
parent b3d26bc21f
commit 51a665cec7
3 changed files with 44 additions and 42 deletions
+14 -14
View File
@@ -8,22 +8,22 @@
#define RCC_AHB1Periph_GPIOBUTTON (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE) #define RCC_AHB1Periph_GPIOBUTTON (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE)
// Keys // Keys
#define PIN_BUTTON_PLUS GPIO_Pin_10 //SW3 PE.10 #define PIN_BUTTON_PLUS GPIO_Pin_10 //SW3 PE.10
#define PIN_BUTTON_MINUS GPIO_Pin_11 //SW1 PE.12 #define PIN_BUTTON_MINUS GPIO_Pin_11 //SW1 PE.12
#define PIN_BUTTON_ENTER GPIO_Pin_12 //SW2 PE.11 #define PIN_BUTTON_ENTER GPIO_Pin_12 //SW2 PE.11
#define PIN_BUTTON_MENU GPIO_Pin_7 //SW4 PD.07 #define PIN_BUTTON_MENU GPIO_Pin_7 //SW4 PD.07
#define PIN_BUTTON_PAGE GPIO_Pin_3 //SW6 PD.02 #define PIN_BUTTON_PAGE GPIO_Pin_3 //SW6 PD.02
#define PIN_BUTTON_EXIT GPIO_Pin_2 //SW5 PD.03 #define PIN_BUTTON_EXIT GPIO_Pin_2 //SW5 PD.03
// Trims // Trims
#define PIN_TRIM1_UP GPIO_Pin_3 //PE.03 #define PIN_TRIM_RV_DN GPIO_Pin_3 //PC.03
#define PIN_TRIM1_DN GPIO_Pin_4 //PE.04 #define PIN_TRIM_RV_UP GPIO_Pin_2 //PC.02
#define PIN_TRIM2_UP GPIO_Pin_6 //PE.06 #define PIN_TRIM_RH_L GPIO_Pin_1 //PC.01
#define PIN_TRIM2_DN GPIO_Pin_5 //PE.05 #define PIN_TRIM_RH_R GPIO_Pin_13 //PC.13
#define PIN_TRIM3_UP GPIO_Pin_2 //PC.02 #define PIN_TRIM_LH_R GPIO_Pin_4 //PE.04
#define PIN_TRIM3_DN GPIO_Pin_3 //PC.03 #define PIN_TRIM_LH_L GPIO_Pin_3 //PE.03
#define PIN_TRIM4_UP GPIO_Pin_1 //PC.01 #define PIN_TRIM_LV_DN GPIO_Pin_6 //PE.06
#define PIN_TRIM4_DN GPIO_Pin_13 //PC.13 #define PIN_TRIM_LV_UP GPIO_Pin_5 //PE.05
// Switchs // Switchs
#define PIN_SW_F GPIO_Pin_14 //PE.14 #define PIN_SW_F GPIO_Pin_14 //PE.14
+19 -19
View File
@@ -67,23 +67,23 @@ uint32_t readTrims()
register uint32_t e = GPIOE->IDR; register uint32_t e = GPIOE->IDR;
register uint32_t result = 0; register uint32_t result = 0;
if (e & PIN_TRIM1_DN) if (~e & PIN_TRIM_LH_L)
result |= 0x01; result |= 0x01; // LH_L
if (e & PIN_TRIM1_UP) if (~e & PIN_TRIM_LH_R)
result |= 0x02; result |= 0x02; // LH_R
if (e & PIN_TRIM2_UP) if (~e & PIN_TRIM_LV_DN)
result |= 0x04; result |= 0x04; // LV_DN
if (e & PIN_TRIM2_DN) if (~e & PIN_TRIM_LV_UP)
result |= 0x08; result |= 0x08; // LV_UP
if (c & PIN_TRIM3_UP) if (~c & PIN_TRIM_RV_DN)
result |= 0x10; result |= 0x10; // RV_DN
if (c & PIN_TRIM3_DN) if (~c & PIN_TRIM_RV_UP)
result |= 0x20; result |= 0x20; // RV_UP
if (c & PIN_TRIM4_UP) if (~c & PIN_TRIM_RH_L)
result |= 0x80; result |= 0x40; // RH_L
if (c & PIN_TRIM4_DN) if (~c & PIN_TRIM_RH_R)
result |= 0x40; result |= 0x80; // RH_R
return result; return result;
} }
@@ -217,8 +217,8 @@ void keysInit()
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOBUTTON, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOBUTTON, ENABLE);
/* GPIO Configuration*/ /* GPIO Configuration*/
GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_PLUS | PIN_BUTTON_ENTER | PIN_BUTTON_MINUS | PIN_TRIM3_UP | PIN_TRIM3_DN GPIO_InitStructure.GPIO_Pin = PIN_BUTTON_PLUS | PIN_BUTTON_ENTER | PIN_BUTTON_MINUS | PIN_TRIM_LH_R | PIN_TRIM_LH_L
| PIN_TRIM4_UP |PIN_TRIM4_DN | PIN_SW_A_L | PIN_SW_D_L | PIN_SW_F | PIN_SW_C_L | PIN_TRIM_LV_DN | PIN_TRIM_LV_UP | PIN_SW_A_L | PIN_SW_D_L | PIN_SW_F | PIN_SW_C_L
| PIN_SW_D_H | PIN_SW_H; | PIN_SW_D_H | PIN_SW_H;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
@@ -233,7 +233,7 @@ void keysInit()
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PIN_TRIM1_UP | PIN_TRIM1_DN | PIN_TRIM2_UP | PIN_TRIM2_DN; GPIO_InitStructure.GPIO_Pin = PIN_TRIM_RV_DN | PIN_TRIM_RV_UP | PIN_TRIM_RH_L | PIN_TRIM_RH_R;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+10 -8
View File
@@ -46,8 +46,8 @@ void rtc_settime(struct gtm * t)
RTC_DateStruct.RTC_Month = t->tm_mon; RTC_DateStruct.RTC_Month = t->tm_mon;
RTC_DateStruct.RTC_Date = t->tm_mday; RTC_DateStruct.RTC_Date = t->tm_mday;
RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct); RTC_SetTime(RTC_Format_BCD, &RTC_TimeStruct);
RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct); RTC_SetDate(RTC_Format_BCD, &RTC_DateStruct);
} }
void rtc_gettime(struct gtm * t) void rtc_gettime(struct gtm * t)
@@ -55,8 +55,8 @@ void rtc_gettime(struct gtm * t)
RTC_TimeTypeDef RTC_TimeStruct; RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct; RTC_DateTypeDef RTC_DateStruct;
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct); RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct);
RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct); RTC_GetDate(RTC_Format_BCD, &RTC_DateStruct);
t->tm_hour = RTC_TimeStruct.RTC_Hours; t->tm_hour = RTC_TimeStruct.RTC_Hours;
t->tm_min = RTC_TimeStruct.RTC_Minutes; t->tm_min = RTC_TimeStruct.RTC_Minutes;
@@ -72,14 +72,16 @@ void rtcInit()
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_BackupAccessCmd(ENABLE); PWR_BackupAccessCmd(ENABLE);
RCC_LSEConfig(RCC_LSE_ON);
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RCC_RTCCLKCmd(ENABLE); RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
// RTC time base = LSE / ((AsynchPrediv+1) * (SynchPrediv+1)) = 1 Hz*/
RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24; RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
RTC_InitStruct.RTC_AsynchPrediv = 128; RTC_InitStruct.RTC_AsynchPrediv = 127;
RTC_InitStruct.RTC_SynchPrediv = 256; RTC_InitStruct.RTC_SynchPrediv = 255;
RTC_Init(&RTC_InitStruct); RTC_Init(&RTC_InitStruct);
struct gtm utm; struct gtm utm;