From 44d683f41c5848246eea7e310ffc2cadbc0259cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 25 Jan 2019 10:10:44 +0100 Subject: [PATCH] [ion/f730] Fix LED GPIO and Timers --- ion/src/f730/led.cpp | 22 +++++++++++----------- ion/src/f730/led.h | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ion/src/f730/led.cpp b/ion/src/f730/led.cpp index 028e8e846..a7ff247db 100644 --- a/ion/src/f730/led.cpp +++ b/ion/src/f730/led.cpp @@ -16,8 +16,8 @@ void Ion::LED::setColor(KDColor c) { sLedColor = c; /* Active all RGB colors */ + TIM3.CCMR()->setOC1M(TIM::CCMR::OCM::PWM1); TIM3.CCMR()->setOC2M(TIM::CCMR::OCM::PWM1); - TIM3.CCMR()->setOC4M(TIM::CCMR::OCM::PWM1); TIM3.CCMR()->setOC3M(TIM::CCMR::OCM::PWM1); /* Set the PWM duty cycles to display the right color */ @@ -30,8 +30,8 @@ void Ion::LED::setBlinking(uint16_t period, float dutyCycle) { * Consequently, we do not use PWM to display the right color anymore but to * blink. We cannot use the PWM to display the exact color so we 'project the * color on 3 bits' : all colors have 2 states - active or not. */ - TIM3.CCMR()->setOC2M(sLedColor.red() > 0 ? TIM::CCMR::OCM::PWM1 : TIM::CCMR::OCM::ForceInactive); - TIM3.CCMR()->setOC4M(sLedColor.green() > 0 ? TIM::CCMR::OCM::PWM1 : TIM::CCMR::OCM::ForceInactive); + TIM3.CCMR()->setOC1M(sLedColor.red() > 0 ? TIM::CCMR::OCM::PWM1 : TIM::CCMR::OCM::ForceInactive); + TIM3.CCMR()->setOC2M(sLedColor.green() > 0 ? TIM::CCMR::OCM::PWM1 : TIM::CCMR::OCM::ForceInactive); TIM3.CCMR()->setOC3M(sLedColor.blue() > 0 ? TIM::CCMR::OCM::PWM1 : TIM::CCMR::OCM::ForceInactive); Device::setPeriodAndDutyCycles(Device::Mode::Blink, dutyCycle, dutyCycle, dutyCycle, period); @@ -56,7 +56,7 @@ void shutdown() { void initGPIO() { /* RED_LED(PC7), GREEN_LED(PB1), and BLUE_LED(PB0) are driven using a timer, * which is an alternate function. More precisely, we will use AF2, which maps - * PB0 to TIM3_CH2, PB1 to TIM3_CH4, and PC7 to TIM3_CH2. */ + * PB0 to TIM3_CH3, PB5 to TIM3_CH2, and PB4 to TIM3_CH1. */ for(const GPIOPin & g : RGBPins) { g.group().MODER()->setMode(g.pin(), GPIO::MODER::Mode::AlternateFunction); g.group().AFR()->setAlternateFunction(g.pin(), GPIO::AFR::AlternateFunction::AF2); @@ -71,18 +71,18 @@ void shutdownGPIO() { } void initTimer() { - // Output preload enable for channels 2-4 + // Output preload enable for channels 1 to 3 + TIM3.CCMR()->setOC1PE(true); TIM3.CCMR()->setOC2PE(true); TIM3.CCMR()->setOC3PE(true); - TIM3.CCMR()->setOC4PE(true); // Auto-reload preload enable TIM3.CR1()->setARPE(true); - // Enable Capture/Compare for channel 2 to 4 + // Enable Capture/Compare for channel 1 to 3 + TIM3.CCER()->setCC1E(true); TIM3.CCER()->setCC2E(true); TIM3.CCER()->setCC3E(true); - TIM3.CCER()->setCC4E(true); TIM3.BDTR()->setMOE(true); @@ -90,8 +90,8 @@ void initTimer() { } void shutdownTimer() { + TIM3.CCMR()->setOC1M(TIM::CCMR::OCM::ForceInactive); TIM3.CCMR()->setOC2M(TIM::CCMR::OCM::ForceInactive); - TIM3.CCMR()->setOC4M(TIM::CCMR::OCM::ForceInactive); TIM3.CCMR()->setOC3M(TIM::CCMR::OCM::ForceInactive); } @@ -123,9 +123,9 @@ void setPeriodAndDutyCycles(Mode mode, float dutyCycleRed, float dutyCycleGreen, break; } - TIM3.CCR2()->set(dutyCycleRed*period); + TIM3.CCR1()->set(dutyCycleRed*period); TIM3.CCR3()->set(dutyCycleBlue*period); - TIM3.CCR4()->set(dutyCycleGreen*period); + TIM3.CCR2()->set(dutyCycleGreen*period); } } diff --git a/ion/src/f730/led.h b/ion/src/f730/led.h index fe46994d9..66574269d 100644 --- a/ion/src/f730/led.h +++ b/ion/src/f730/led.h @@ -10,8 +10,8 @@ namespace Device { /* Pin | Role | Mode | Function * -----+-------------------+-----------------------+---------- * PB0 | LED blue | Alternate Function 2 | TIM3_CH3 - * PB1 | LED green | Alternate Function 2 | TIM3_CH4 - * PC7 | LED red | Alternate Function 2 | TIM3_CH2 + * PB5 | LED green | Alternate Function 2 | TIM3_CH2 + * PB4 | LED red | Alternate Function 2 | TIM3_CH1 */ enum class Mode { @@ -35,7 +35,7 @@ void initTimer(); void shutdownTimer(); constexpr static GPIOPin RGBPins[] = { - GPIOPin(GPIOC, 7), GPIOPin(GPIOB, 1), GPIOPin(GPIOB, 0) + GPIOPin(GPIOB, 4), GPIOPin(GPIOB, 5), GPIOPin(GPIOB, 0) };