Refactoring of files and function names
- Files for interfaces connected via UEXT are stored in separate uext/ directory - UEXT init and process function names independent of connected module - LED function names adjusted to start with leds_ - main.cpp structure simplified
This commit is contained in:
+95
-80
@@ -4,82 +4,17 @@
|
||||
|
||||
#include "mbed.h"
|
||||
|
||||
bool led_states[NUM_LEDS];
|
||||
static bool led_states[NUM_LEDS];
|
||||
|
||||
int blink_state = 1;
|
||||
bool flicker_state = 1;
|
||||
static int blink_state = 1;
|
||||
static bool flicker_state = 1;
|
||||
|
||||
bool charging = false;
|
||||
bool rx_flag = false;
|
||||
bool tx_flag = false;
|
||||
int rxtx_trigger_timestamp;
|
||||
static bool charging = false;
|
||||
static bool rx_flag = false;
|
||||
static bool tx_flag = false;
|
||||
static int rxtx_trigger_timestamp;
|
||||
|
||||
|
||||
#if defined(STM32F0)
|
||||
|
||||
void led_timer_start(int freq_Hz) // max. 10 kHz
|
||||
{
|
||||
// Enable TIM17 clock
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM17EN;
|
||||
|
||||
// Set timer clock to 10 kHz
|
||||
TIM17->PSC = SystemCoreClock / 10000 - 1;
|
||||
|
||||
// Interrupt on timer update
|
||||
TIM17->DIER |= TIM_DIER_UIE;
|
||||
|
||||
// Auto Reload Register sets interrupt frequency
|
||||
TIM17->ARR = 10000 / freq_Hz - 1;
|
||||
|
||||
// 3 = lowest priority of STM32L0/F0
|
||||
NVIC_SetPriority(TIM17_IRQn, 3);
|
||||
NVIC_EnableIRQ(TIM17_IRQn);
|
||||
|
||||
// Control Register 1
|
||||
// TIM_CR1_CEN = 1: Counter enable
|
||||
TIM17->CR1 |= TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
extern "C" void TIM17_IRQHandler(void)
|
||||
{
|
||||
TIM17->SR &= ~TIM_SR_UIF; // clear update interrupt flag to restart timer
|
||||
charlieplexing();
|
||||
}
|
||||
|
||||
#elif defined(STM32L0)
|
||||
|
||||
void led_timer_start(int freq_Hz) // max. 10 kHz
|
||||
{
|
||||
// Enable TIM22 clock
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM22EN;
|
||||
|
||||
// Set timer clock to 10 kHz
|
||||
TIM22->PSC = SystemCoreClock / 10000 - 1;
|
||||
|
||||
// Interrupt on timer update
|
||||
TIM22->DIER |= TIM_DIER_UIE;
|
||||
|
||||
// Auto Reload Register sets interrupt frequency
|
||||
TIM22->ARR = 10000 / freq_Hz - 1;
|
||||
|
||||
// 3 = lowest priority of STM32L0/F0
|
||||
NVIC_SetPriority(TIM22_IRQn, 3);
|
||||
NVIC_EnableIRQ(TIM22_IRQn);
|
||||
|
||||
// Control Register 1
|
||||
// TIM_CR1_CEN = 1: Counter enable
|
||||
TIM22->CR1 |= TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
extern "C" void TIM22_IRQHandler(void)
|
||||
{
|
||||
TIM22->SR &= ~(1 << 0);
|
||||
charlieplexing();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void charlieplexing()
|
||||
static void charlieplexing()
|
||||
{
|
||||
static int led_count = 0;
|
||||
static int flicker_count = 0;
|
||||
@@ -123,12 +58,76 @@ void charlieplexing()
|
||||
flicker_count++;
|
||||
}
|
||||
|
||||
#if defined(STM32F0)
|
||||
|
||||
void leds_init()
|
||||
static void timer_start(int freq_Hz) // max. 10 kHz
|
||||
{
|
||||
// Enable TIM17 clock
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM17EN;
|
||||
|
||||
// Set timer clock to 10 kHz
|
||||
TIM17->PSC = SystemCoreClock / 10000 - 1;
|
||||
|
||||
// Interrupt on timer update
|
||||
TIM17->DIER |= TIM_DIER_UIE;
|
||||
|
||||
// Auto Reload Register sets interrupt frequency
|
||||
TIM17->ARR = 10000 / freq_Hz - 1;
|
||||
|
||||
// 3 = lowest priority of STM32L0/F0
|
||||
NVIC_SetPriority(TIM17_IRQn, 3);
|
||||
NVIC_EnableIRQ(TIM17_IRQn);
|
||||
|
||||
// Control Register 1
|
||||
// TIM_CR1_CEN = 1: Counter enable
|
||||
TIM17->CR1 |= TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
extern "C" void TIM17_IRQHandler(void)
|
||||
{
|
||||
TIM17->SR &= ~TIM_SR_UIF; // clear update interrupt flag to restart timer
|
||||
charlieplexing();
|
||||
}
|
||||
|
||||
#elif defined(STM32L0)
|
||||
|
||||
static void timer_start(int freq_Hz) // max. 10 kHz
|
||||
{
|
||||
// Enable TIM22 clock
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM22EN;
|
||||
|
||||
// Set timer clock to 10 kHz
|
||||
TIM22->PSC = SystemCoreClock / 10000 - 1;
|
||||
|
||||
// Interrupt on timer update
|
||||
TIM22->DIER |= TIM_DIER_UIE;
|
||||
|
||||
// Auto Reload Register sets interrupt frequency
|
||||
TIM22->ARR = 10000 / freq_Hz - 1;
|
||||
|
||||
// 3 = lowest priority of STM32L0/F0
|
||||
NVIC_SetPriority(TIM22_IRQn, 3);
|
||||
NVIC_EnableIRQ(TIM22_IRQn);
|
||||
|
||||
// Control Register 1
|
||||
// TIM_CR1_CEN = 1: Counter enable
|
||||
TIM22->CR1 |= TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
extern "C" void TIM22_IRQHandler(void)
|
||||
{
|
||||
TIM22->SR &= ~(1 << 0);
|
||||
charlieplexing();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void leds_init(bool enabled)
|
||||
{
|
||||
for (int led = 0; led < NUM_LEDS; led++) {
|
||||
led_states[led] = 1;
|
||||
led_states[led] = enabled;
|
||||
}
|
||||
timer_start(NUM_LEDS * 60); // 60 Hz
|
||||
}
|
||||
|
||||
void leds_set_charging(bool enabled)
|
||||
@@ -139,7 +138,15 @@ void leds_set_charging(bool enabled)
|
||||
#endif
|
||||
}
|
||||
|
||||
void update_rxtx_led()
|
||||
void leds_set_load(bool enabled)
|
||||
{
|
||||
#ifdef LED_LOAD
|
||||
if (enabled) led_states[LED_LOAD] = 1;
|
||||
else led_states[LED_LOAD] = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void leds_update_rxtx()
|
||||
{
|
||||
#ifdef LED_RXTX
|
||||
if (time(NULL) >= rxtx_trigger_timestamp + 2) {
|
||||
@@ -158,27 +165,35 @@ void update_rxtx_led()
|
||||
#endif
|
||||
}
|
||||
|
||||
void trigger_rx_led()
|
||||
void leds_trigger_rx()
|
||||
{
|
||||
rx_flag = true;
|
||||
tx_flag = false;
|
||||
rxtx_trigger_timestamp = time(NULL);
|
||||
}
|
||||
|
||||
void trigger_tx_led()
|
||||
void leds_trigger_tx()
|
||||
{
|
||||
rx_flag = false;
|
||||
tx_flag = true;
|
||||
rxtx_trigger_timestamp = time(NULL);
|
||||
}
|
||||
|
||||
void toggle_led_blink()
|
||||
void leds_toggle_blink()
|
||||
{
|
||||
blink_state = !blink_state;
|
||||
}
|
||||
|
||||
void leds_toggle_error()
|
||||
{
|
||||
for (int led = 0; led < NUM_LEDS; led++) {
|
||||
led_states[led] = (led % 2) ^ blink_state;
|
||||
}
|
||||
blink_state = !blink_state;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void update_soc_led(int soc)
|
||||
void leds_update_soc(int soc)
|
||||
{
|
||||
#ifndef LED_DCDC
|
||||
// if there is no dedicated LED for the DC/DC converter status, blink SOC
|
||||
|
||||
Reference in New Issue
Block a user