diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-02 21:02:34 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-02 21:04:13 -0400 |
commit | 1637300f8f751ccc17ff1a2f383c7fca902c0f8f (patch) | |
tree | 79c3a4ec21ed55d352ef2d7730182c1821e3b437 /wirish | |
parent | daa792f486ea7ce848c37eee636c73824efec396 (diff) | |
download | librambutan-1637300f8f751ccc17ff1a2f383c7fca902c0f8f.tar.gz librambutan-1637300f8f751ccc17ff1a2f383c7fca902c0f8f.zip |
Bring timer initialization back to init().
Turns out the F1 code was pretty portable after all, so take it from
the F1 boards_setup.cpp and stick it back into boards.cpp. The only
change needed was to add a call to the newly-minted
timer_has_cc_channel() (and this is necessary on F103 XL-density,
anyway).
Also assert LeafLabs copyright in boards.cpp. We really need to do
this throughout the library; it's basically been rewritten since
Perry.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'wirish')
-rw-r--r-- | wirish/boards.cpp | 43 | ||||
-rw-r--r-- | wirish/boards_private.h | 1 | ||||
-rw-r--r-- | wirish/stm32f1/boards_setup.cpp | 45 | ||||
-rw-r--r-- | wirish/stm32f2/boards_setup.cpp | 6 |
4 files changed, 43 insertions, 52 deletions
diff --git a/wirish/boards.cpp b/wirish/boards.cpp index 51ff50e..0faabfd 100644 --- a/wirish/boards.cpp +++ b/wirish/boards.cpp @@ -2,6 +2,7 @@ * The MIT License * * Copyright (c) 2010 Perry Hung. + * Copyright (c) 2011, 2012 LeafLabs, LLC. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -55,6 +56,7 @@ static void setup_flash(void); static void setup_clocks(void); static void setup_nvic(void); static void setup_adcs(void); +static void setup_timers(void); /* * Exported functions @@ -67,7 +69,7 @@ void init(void) { systick_init(SYSTICK_RELOAD_VAL); wirish::priv::board_setup_gpio(); setup_adcs(); - wirish::priv::board_setup_timers(); + setup_timers(); wirish::priv::board_setup_usb(); boardInit(); } @@ -157,3 +159,42 @@ static void setup_adcs(void) { adc_set_prescaler(wirish::priv::w_adc_pre); adc_foreach(adc_default_config); } + +static void timer_default_config(timer_dev *dev) { + timer_adv_reg_map *regs = (dev->regs).adv; + const uint16 full_overflow = 0xFFFF; + const uint16 half_duty = 0x8FFF; + + timer_init(dev); + timer_pause(dev); + + regs->CR1 = TIMER_CR1_ARPE; + regs->PSC = 1; + regs->SR = 0; + regs->DIER = 0; + regs->EGR = TIMER_EGR_UG; + switch (dev->type) { + case TIMER_ADVANCED: + regs->BDTR = TIMER_BDTR_MOE | TIMER_BDTR_LOCK_OFF; + // fall-through + case TIMER_GENERAL: + timer_set_reload(dev, full_overflow); + for (uint8 channel = 1; channel <= 4; channel++) { + if (timer_has_cc_channel(dev, channel)) { + timer_set_compare(dev, channel, half_duty); + timer_oc_set_mode(dev, channel, TIMER_OC_MODE_PWM_1, + TIMER_OC_PE); + } + } + // fall-through + case TIMER_BASIC: + break; + } + + timer_generate_update(dev); + timer_resume(dev); +} + +static void setup_timers(void) { + timer_foreach(timer_default_config); +} diff --git a/wirish/boards_private.h b/wirish/boards_private.h index e32f298..cdac844 100644 --- a/wirish/boards_private.h +++ b/wirish/boards_private.h @@ -58,7 +58,6 @@ namespace wirish { void board_reset_pll(void); void board_setup_clock_prescalers(void); void board_setup_gpio(void); - void board_setup_timers(void); void board_setup_usb(void); } diff --git a/wirish/stm32f1/boards_setup.cpp b/wirish/stm32f1/boards_setup.cpp index a71661d..423e5ec 100644 --- a/wirish/stm32f1/boards_setup.cpp +++ b/wirish/stm32f1/boards_setup.cpp @@ -62,8 +62,6 @@ namespace wirish { adc_prescaler w_adc_pre = ADC_PRE_PCLK2_DIV_6; adc_smp_rate w_adc_smp = ADC_SMPR_55_5; - static void config_timer(timer_dev*); - void board_reset_pll(void) { // TODO } @@ -81,10 +79,6 @@ namespace wirish { afio_init(); } - void board_setup_timers(void) { - timer_foreach(config_timer); - } - void board_setup_usb(void) { #if 0 # if STM32_HAVE_USB @@ -92,44 +86,5 @@ namespace wirish { # endif #endif } - - /* - * Auxiliary routines - */ - - static void config_timer(timer_dev *dev) { -#if 0 - timer_adv_reg_map *regs = (dev->regs).adv; - const uint16 full_overflow = 0xFFFF; - const uint16 half_duty = 0x8FFF; - - timer_init(dev); - timer_pause(dev); - - regs->CR1 = TIMER_CR1_ARPE; - regs->PSC = 1; - regs->SR = 0; - regs->DIER = 0; - regs->EGR = TIMER_EGR_UG; - - switch (dev->type) { - case TIMER_ADVANCED: - regs->BDTR = TIMER_BDTR_MOE | TIMER_BDTR_LOCK_OFF; - // fall-through - case TIMER_GENERAL: - timer_set_reload(dev, full_overflow); - - for (int channel = 1; channel <= 4; channel++) { - timer_set_compare(dev, channel, half_duty); - timer_oc_set_mode(dev, channel, TIMER_OC_MODE_PWM_1, TIMER_OC_PE); - } - // fall-through - case TIMER_BASIC: - break; - } - - timer_resume(dev); -#endif - } } } diff --git a/wirish/stm32f2/boards_setup.cpp b/wirish/stm32f2/boards_setup.cpp index e1bf1fd..9832bb7 100644 --- a/wirish/stm32f2/boards_setup.cpp +++ b/wirish/stm32f2/boards_setup.cpp @@ -81,12 +81,8 @@ namespace wirish { gpio_init_all(); } - void board_setup_timers(void) { - // TODO - } - void board_setup_usb(void) { - // TODO + // Nothing to do. } } |