mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Update the RGB LED pins
Change-Id: I25c116d67cde14a305eb67dfaf5488f8916f9ba5
This commit is contained in:
@@ -6,15 +6,12 @@
|
||||
// Public Ion::LED methods
|
||||
|
||||
void Ion::LED::setColor(KDColor c) {
|
||||
TIM3.CCR1()->set(Device::dutyCycleForUInt8(c.red()));
|
||||
TIM3.CCR2()->set(Device::dutyCycleForUInt8(c.green()));
|
||||
TIM3.CCR2()->set(Device::dutyCycleForUInt8(c.red()));
|
||||
TIM3.CCR3()->set(Device::dutyCycleForUInt8(c.blue()));
|
||||
TIM3.CCR4()->set(Device::dutyCycleForUInt8(c.green()));
|
||||
}
|
||||
|
||||
// We're also implementing backlight control
|
||||
|
||||
void Ion::Display::setBacklightIntensity(uint8_t intensity) {
|
||||
TIM3.CCR4()->set(Ion::LED::Device::dutyCycleForUInt8(intensity));
|
||||
}
|
||||
|
||||
// Private Ion::Device::LED methods
|
||||
@@ -29,19 +26,17 @@ void init() {
|
||||
}
|
||||
|
||||
void initGPIO() {
|
||||
/* RED_LED(PA6), GREEN_LED(PA7), BLUE_LED(PB0), LCD_LED(PC9) are driven using
|
||||
* a timer, which is an alternate function. */
|
||||
GPIOA.MODER()->setMode(6, GPIO::MODER::Mode::AlternateFunction);
|
||||
GPIOA.MODER()->setMode(7, GPIO::MODER::Mode::AlternateFunction);
|
||||
/* RED_LED(PC7), GREEN_LED(PB1), and BLUE_LED(PB0) are driven using a timer,
|
||||
* which is an alternate function. */
|
||||
GPIOB.MODER()->setMode(0, GPIO::MODER::Mode::AlternateFunction);
|
||||
GPIOC.MODER()->setMode(9, GPIO::MODER::Mode::AlternateFunction);
|
||||
GPIOB.MODER()->setMode(1, GPIO::MODER::Mode::AlternateFunction);
|
||||
GPIOC.MODER()->setMode(7, GPIO::MODER::Mode::AlternateFunction);
|
||||
|
||||
/* More precisely, we will use AF02, which maps PA6 to TIM3_CH1, PA7 to
|
||||
* TIM3_CH2, PB0 to TIM3_CH3 and PC9 to TIM3_CH4. */
|
||||
GPIOA.AFR()->setAlternateFunction(6, GPIO::AFR::AlternateFunction::AF2);
|
||||
GPIOA.AFR()->setAlternateFunction(7, GPIO::AFR::AlternateFunction::AF2);
|
||||
/* More precisely, we will use AF2, which maps PB0 to TIM3_CH2, PB1 to
|
||||
* TIM3_CH4, and PC7 to TIM3_CH2. */
|
||||
GPIOB.AFR()->setAlternateFunction(0, GPIO::AFR::AlternateFunction::AF2);
|
||||
GPIOC.AFR()->setAlternateFunction(9, GPIO::AFR::AlternateFunction::AF2);
|
||||
GPIOB.AFR()->setAlternateFunction(1, GPIO::AFR::AlternateFunction::AF2);
|
||||
GPIOC.AFR()->setAlternateFunction(7, GPIO::AFR::AlternateFunction::AF2);
|
||||
}
|
||||
|
||||
void initTimer() {
|
||||
@@ -53,19 +48,16 @@ void initTimer() {
|
||||
* frequency determined by the value of the TIMx_ARR register and a duty cycle
|
||||
* determined by the value of the TIMx_CCRx register. */
|
||||
TIM3.ARR()->set(PWMPeriod);
|
||||
TIM3.CCR1()->set(0);
|
||||
TIM3.CCR2()->set(0);
|
||||
TIM3.CCR3()->set(0);
|
||||
TIM3.CCR4()->set(0);
|
||||
|
||||
// Set Channels 1-4 as outputs, PWM mode 1
|
||||
TIM3.CCMR()->setOC1M(TIM::CCMR::OCM::PWM1);
|
||||
// Set Channels 2-4 as outputs, PWM mode 1
|
||||
TIM3.CCMR()->setOC2M(TIM::CCMR::OCM::PWM1);
|
||||
TIM3.CCMR()->setOC3M(TIM::CCMR::OCM::PWM1);
|
||||
TIM3.CCMR()->setOC4M(TIM::CCMR::OCM::PWM1);
|
||||
|
||||
// Output preload enable for channels 1-4
|
||||
TIM3.CCMR()->setOC1PE(true);
|
||||
// Output preload enable for channels 2-4
|
||||
TIM3.CCMR()->setOC2PE(true);
|
||||
TIM3.CCMR()->setOC3PE(true);
|
||||
TIM3.CCMR()->setOC4PE(true);
|
||||
@@ -73,8 +65,7 @@ void initTimer() {
|
||||
// Auto-reload preload enable
|
||||
TIM3.CR1()->setARPE(true);
|
||||
|
||||
// Enable Capture/Compare for channel 1 to 4
|
||||
TIM3.CCER()->setCC1E(true);
|
||||
// Enable Capture/Compare for channel 2 to 4
|
||||
TIM3.CCER()->setCC2E(true);
|
||||
TIM3.CCER()->setCC3E(true);
|
||||
TIM3.CCER()->setCC4E(true);
|
||||
@@ -85,14 +76,12 @@ void initTimer() {
|
||||
}
|
||||
|
||||
void suspend() {
|
||||
TIM3.CCMR()->setOC1M(TIM::CCMR::OCM::ForceInactive);
|
||||
TIM3.CCMR()->setOC2M(TIM::CCMR::OCM::ForceInactive);
|
||||
TIM3.CCMR()->setOC3M(TIM::CCMR::OCM::ForceInactive);
|
||||
TIM3.CCMR()->setOC4M(TIM::CCMR::OCM::ForceInactive);
|
||||
}
|
||||
|
||||
void resume() {
|
||||
TIM3.CCMR()->setOC1M(TIM::CCMR::OCM::PWM1);
|
||||
TIM3.CCMR()->setOC2M(TIM::CCMR::OCM::PWM1);
|
||||
TIM3.CCMR()->setOC3M(TIM::CCMR::OCM::PWM1);
|
||||
TIM3.CCMR()->setOC4M(TIM::CCMR::OCM::PWM1);
|
||||
|
||||
@@ -7,10 +7,9 @@ namespace Device {
|
||||
|
||||
/* Pin | Role | Mode | Function
|
||||
* -----+-------------------+-----------------------+----------
|
||||
* PA6 | LED red | Alternate Function 12 | TIM3_CH1
|
||||
* PA7 | LED green | Alternate Function 12 | TIM3_CH2
|
||||
* PB0 | LED blue | Alternate Function 12 | TIM3_CH3
|
||||
* PC9 | LCD backlight | Alternate Function 12 | TIM3_CH4
|
||||
* PB0 | LED blue | Alternate Function 2 | TIM3_CH3
|
||||
* PB1 | LED green | Alternate Function 2 | TIM3_CH4
|
||||
* PC7 | LED red | Alternate Function 2 | TIM3_CH2
|
||||
*/
|
||||
|
||||
void init();
|
||||
|
||||
Reference in New Issue
Block a user