preliminary support for the two RGB status leds

Note: pin assignments not final
This commit is contained in:
2023-12-04 18:45:29 +01:00
parent cef05f52bc
commit b24fc66caf
7 changed files with 179 additions and 16 deletions

View File

@ -4,6 +4,7 @@
#include "shunt_monitoring.h"
#include "stm32f3xx_hal.h"
#include "stm32f3xx_hal_gpio.h"
#include "status_led.h"
#include <stdint.h>
TSStateHandle ts_state;
@ -15,11 +16,11 @@ static uint32_t discharge_begin_timestamp = 0;
void ts_sm_init() {
ts_state.current_state = TS_INACTIVE;
ts_state.target_state = TS_INACTIVE;
ts_state.error = 0;
ts_state.error_source = 0;
}
void ts_sm_update() {
if (ts_state.error) {
if (ts_state.error_source) {
ts_state.current_state = TS_ERROR;
}
@ -48,6 +49,7 @@ void ts_sm_update() {
}
ts_sm_set_relay_positions(ts_state.current_state);
status_led_state(ts_state.current_state, (TSErrorKind) ts_state.error_type);
}
TSState ts_sm_update_inactive() {
@ -89,7 +91,7 @@ TSState ts_sm_update_precharge() {
uint32_t now = HAL_GetTick();
if (precharge_95_reached_timestamp == 0) {
precharge_95_reached_timestamp = now;
} else if (now - precharge_95_reached_timestamp >= PRECHARGE_95_DURATION) {
} else if ((now - precharge_95_reached_timestamp) >= PRECHARGE_95_DURATION) {
precharge_95_reached_timestamp = 0;
return TS_ACTIVE;
}
@ -108,7 +110,7 @@ TSState ts_sm_update_discharge() {
TSState ts_sm_update_error() {
static uint32_t no_error_since = 0;
if (ts_state.error == 0) {
if (ts_state.error_source == 0) {
uint32_t now = HAL_GetTick();
if (no_error_since == 0) {
no_error_since = now;
@ -220,10 +222,12 @@ void ts_sm_handle_ams_in(const uint8_t *data) {
}
}
void ts_sm_set_error_source(uint32_t flag, int state) {
if (state) {
ts_state.error |= flag;
void ts_sm_set_error_source(TSErrorSource source, TSErrorKind error_type, bool is_errored) {
if (is_errored) {
ts_state.error_source |= source;
ts_state.error_type = error_type;
} else {
ts_state.error &= ~flag;
ts_state.error_source &= ~source;
ts_state.error_type = ~error_type;
}
}