Skip to content

Commit

Permalink
Increase button debounce time
Browse files Browse the repository at this point in the history
  • Loading branch information
ReservedField committed Jul 25, 2016
1 parent c6f24c7 commit 9515484
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/startup/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,29 @@ void Sys_Init() {
// HIRC clock (internal RC 22.1184MHz)
CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);


// LIRC clock (internal RC 10kHz)
CLK_EnableXtalRC(CLK_PWRCTL_LIRCEN_Msk);
CLK_WaitClockReady(CLK_STATUS_LIRCSTB_Msk);

// HCLK clock source: HIRC, HCLK source divider: 1
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

// HXT clock (external XTAL 12MHz)
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);

// Enable 72MHz optimization
FMC_EnableFreqOptimizeMode(FMC_FTCTL_OPTIMIZE_72MHZ);

// Core clock: PLL
CLK_SetCoreClock(PLL_CLOCK);
CLK_WaitClockReady(CLK_STATUS_PLLSTB_Msk);

// SPI0 clock: PCLK0
CLK_SetModuleClock(SPI0_MODULE, CLK_CLKSEL2_SPI0SEL_PCLK0, 0);
CLK_EnableModuleClock(SPI0_MODULE);

// TMR0-3 clock: HXT
CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0SEL_HXT, 0);
CLK_SetModuleClock(TMR1_MODULE, CLK_CLKSEL1_TMR1SEL_HXT, 0);
Expand All @@ -76,17 +80,17 @@ void Sys_Init() {
// USBD clock
CLK_SetModuleClock(USBD_MODULE, 0, CLK_CLKDIV0_USB(3));
CLK_EnableModuleClock(USBD_MODULE);

// Enable USB 3.3V LDO
SYS->USBPHY = SYS_USBPHY_LDO33EN_Msk;

// EADC clock: 72Mhz / 8
CLK_SetModuleClock(EADC_MODULE, 0, CLK_CLKDIV0_EADC(8));
CLK_EnableModuleClock(EADC_MODULE);

// Enable BOD (reset, 2.2V)
SYS_EnableBOD(SYS_BODCTL_BOD_RST_EN, SYS_BODCTL_BODVL_2_2V);

// Update system core clock
SystemCoreClockUpdate();

Expand All @@ -95,13 +99,12 @@ void Sys_Init() {
Dataflash_Init();

// Setup debounce, used both by buttons and battery presence pin.
// Buttons only need 100us, while at least 200us is needed by
// Good buttons only need 100us, while at least 200us is needed by
// battery presence. The original firmware uses 100ms for battery and
// timer-based debounce for buttons, but that's excessive.
// 200us will work fine for both. Button debounce isn't really noticeable
// up to 128 LIRC clock cycles, so this can be upped if battery presence
// is unstable.
GPIO_SET_DEBOUNCE_TIME(GPIO_DBCTL_DBCLKSRC_LIRC, GPIO_DBCTL_DBCLKSEL_2);
// Older buttons need more debouncing (a few ms). Button debounce
// isn't really noticeable up to 128 LIRC clock cycles.
GPIO_SET_DEBOUNCE_TIME(GPIO_DBCTL_DBCLKSRC_LIRC, GPIO_DBCTL_DBCLKSEL_32);

// Initialize I/O
Display_SetupSPI();
Expand Down

0 comments on commit 9515484

Please sign in to comment.