summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/timer.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-01-29 22:44:43 +0000
committerDamien George <damien.p.george@gmail.com>2016-01-29 22:44:43 +0000
commita8a4b01af6501ff7ab61b251fc30fcf8a286f8d1 (patch)
tree635f0e2dd81d6391ca77f4866f93ba1b3d8a06b9 /stmhal/timer.c
parentea89b80ff4f842b010f9f8ec3280675f81bc6bc5 (diff)
downloadmicropython-a8a4b01af6501ff7ab61b251fc30fcf8a286f8d1.tar.gz
micropython-a8a4b01af6501ff7ab61b251fc30fcf8a286f8d1.zip
stmhal: Add PWM capability for LED(3) and LED(4) on pyboards.
USB CDC no longer needs TIM3 (which was originally used for LED(4) PWM) and so TIM3 has been freed for general purpose use by the user. Hence LED(4) lost its PWM capabilities. This patch reinstates the PWM capabilities using a semi-generic piece of code which allows to configure a timer and PWM channel to use for any LED. But the PWM capability is only configured if the LED is set to an intensity between 1 and 254 (ie only when needed). In that case the relevant timer is configured for PWM. It's up to the user to make sure the timers are not used if PWM is active. This patch also makes sure that PWM LEDs are turned off using standard GPIO when calling led.off() or led.intensity(0), instead of just setting the PWM counter to zero.
Diffstat (limited to 'stmhal/timer.c')
-rw-r--r--stmhal/timer.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/stmhal/timer.c b/stmhal/timer.c
index 9caa056a2f..8d462975e1 100644
--- a/stmhal/timer.c
+++ b/stmhal/timer.c
@@ -147,7 +147,6 @@ TIM_HandleTypeDef TIM6_Handle;
#define PYB_TIMER_OBJ_ALL_NUM MP_ARRAY_SIZE(MP_STATE_PORT(pyb_timer_obj_all))
-STATIC uint32_t timer_get_source_freq(uint32_t tim_id);
STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in);
STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback);
STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback);
@@ -229,7 +228,7 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
// If the APB prescaler is 1, then the timer clock is equal to its respective
// APB clock. Otherwise (APB prescaler > 1) the timer clock is twice its
// respective APB clock. See DM00031020 Rev 4, page 115.
-STATIC uint32_t timer_get_source_freq(uint32_t tim_id) {
+uint32_t timer_get_source_freq(uint32_t tim_id) {
uint32_t source;
if (tim_id == 1 || (8 <= tim_id && tim_id <= 11)) {
// TIM{1,8,9,10,11} are on APB2