mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 19:49:58 +02:00
[Ion] Move to C++
Change-Id: Id75fca5e92a3fdf18258015bcda7cd70297b0fdb
This commit is contained in:
@@ -1,40 +1,39 @@
|
||||
extern "C" {
|
||||
#include <ion/led.h>
|
||||
}
|
||||
#include "led.h"
|
||||
#include "regs/regs.h"
|
||||
|
||||
extern "C" {
|
||||
void ion_led_init();
|
||||
// Public Ion::LED methods
|
||||
|
||||
void Ion::LED::setColor(KDColor c) {
|
||||
TIM1.CCR1()->set(15000);
|
||||
}
|
||||
|
||||
/* Pin used :
|
||||
* PA8 - Red LED - TIM1_CH1
|
||||
* PA9 - Green LED - TIM1_CH2
|
||||
* PA10 - Blue LED -TIM1_CH3
|
||||
*/
|
||||
// Private Ion::Device::LED methods
|
||||
|
||||
void sleep() {
|
||||
for (volatile int i=0;i<100000; i++) {
|
||||
}
|
||||
namespace Ion {
|
||||
namespace LED {
|
||||
namespace Device {
|
||||
|
||||
void init() {
|
||||
initGPIO();
|
||||
initTimer();
|
||||
}
|
||||
|
||||
void ion_led_gpio_init() {
|
||||
RCC.AHB1ENR()->setGPIOAEN(true);
|
||||
|
||||
void initGPIO() {
|
||||
/* RED_LED(PA8), GREEN_LED(PA9), BLUE_LED(PA10) are driven using a timer,
|
||||
* which is an alternate function. */
|
||||
GPIOA.MODER()->setMODER(8, GPIO::MODER::MODE::AlternateFunction);
|
||||
GPIOA.MODER()->setMODER(9, GPIO::MODER::MODE::AlternateFunction);
|
||||
GPIOA.MODER()->setMODER(10, GPIO::MODER::MODE::AlternateFunction);
|
||||
GPIOA.MODER()->setMode(8, GPIO::MODER::Mode::AlternateFunction);
|
||||
GPIOA.MODER()->setMode(9, GPIO::MODER::Mode::AlternateFunction);
|
||||
GPIOA.MODER()->setMode(10, GPIO::MODER::Mode::AlternateFunction);
|
||||
|
||||
/* More precisely, we will use AF01, which maps PA8 to TIM1_CH1, PA9 to
|
||||
* TIM1_CH2 and PA10 to TIM1_CH3. */
|
||||
GPIOA.AFR()->setAFR(8, GPIO::AFR::AlternateFunction::AF1);
|
||||
GPIOA.AFR()->setAFR(9, GPIO::AFR::AlternateFunction::AF1);
|
||||
GPIOA.AFR()->setAFR(10, GPIO::AFR::AlternateFunction::AF1);
|
||||
GPIOA.AFR()->setAlternateFunction(8, GPIO::AFR::AlternateFunction::AF1);
|
||||
GPIOA.AFR()->setAlternateFunction(9, GPIO::AFR::AlternateFunction::AF1);
|
||||
GPIOA.AFR()->setAlternateFunction(10, GPIO::AFR::AlternateFunction::AF1);
|
||||
}
|
||||
|
||||
void ion_led_timer_init() {
|
||||
void initTimer() {
|
||||
/* TIM1 lives on the APB2 bus. Let's enable its clock. */
|
||||
RCC.APB2ENR()->setTIM1EN(true);
|
||||
TIM1.PSC()->set(1000);
|
||||
@@ -75,11 +74,6 @@ void ion_led_timer_init() {
|
||||
TIM1.CR1()->setCEN(true);
|
||||
}
|
||||
|
||||
void ion_led_init() {
|
||||
ion_led_gpio_init();
|
||||
ion_led_timer_init();
|
||||
}
|
||||
|
||||
|
||||
void ion_led_set_color(ion_color_t color) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user