functional LED code, first untested implementation

This commit is contained in:
2025-07-08 22:42:23 +02:00
parent 93642b1c11
commit 9c4b60fd18
1416 changed files with 1339716 additions and 1328321 deletions

43
Software/Core/Src/led.c Normal file
View File

@ -0,0 +1,43 @@
#include "led.h"
#include "main.h"
HAL_StatusTypeDef led_init(TIM_HandleTypeDef* htim) {
TRY(HAL_TIM_PWM_Start(htim, LED_CH_R));
TRY(HAL_TIM_PWM_Start(htim, LED_CH_G));
TRY(HAL_TIM_PWM_Start(htim, LED_CH_B));
int32_t color = COLOR_ERROR;
int32_t Blue = color & 0x000000FF;
int32_t Green = (color & 0x0000FF00) >> 8;
int32_t Red = (color & 0x00FF0000) >> 16;
DUTY_CYCLE_R = Red;
DUTY_CYCLE_G = Green;
DUTY_CYCLE_B = Blue;
return HAL_OK;
}
// function for setting the blink functionality of the status LED, set blink_period to 0 to make it light up constantly
HAL_StatusTypeDef led_blink(TIM_HandleTypeDef* htim, int32_t color, int16_t blink_period) {
int32_t Blue = color & 0x000000FF;
int32_t Green = (color & 0x0000FF00) >> 8;
int32_t Red = (color & 0x00FF0000) >> 16;
DUTY_CYCLE_R = Red;
DUTY_CYCLE_G = Green;
DUTY_CYCLE_B = Blue;
if ((HAL_GetTick() % blink_period) < blink_period/2) {
TRY(HAL_TIM_PWM_Stop(htim, LED_CH_R));
TRY(HAL_TIM_PWM_Stop(htim, LED_CH_G));
TRY(HAL_TIM_PWM_Stop(htim, LED_CH_B));
} else {
TRY(HAL_TIM_PWM_Start(htim, LED_CH_R));
TRY(HAL_TIM_PWM_Start(htim, LED_CH_G));
TRY(HAL_TIM_PWM_Start(htim, LED_CH_B));
}
return HAL_OK;
}