diff --git a/fw/.cproject b/fw/.cproject index 0005a9c..51ffe1b 100644 --- a/fw/.cproject +++ b/fw/.cproject @@ -188,4 +188,5 @@ + \ No newline at end of file diff --git a/fw/Core/Inc/rgbled.h b/fw/Core/Inc/rgbled.h index a9fdd56..9580f20 100644 --- a/fw/Core/Inc/rgbled.h +++ b/fw/Core/Inc/rgbled.h @@ -17,6 +17,7 @@ #define RGBLED_OK 0 #define RGBLED_ERROR -1 // generic error +#define RGBLED_WRONG_CHANNEL -2 // channel number not in {1,2,3,4} #define RGBLED_PRESCALER 0 #define RGBLED_PERIOD 255 @@ -30,12 +31,22 @@ typedef struct { // tim22 ch1 G // tim22 ch2 R // TODO union, aby se dalo nastavovat LED v cyklu (set_color) - TIM_TypeDef *timer_R; - TIM_TypeDef *timer_G; - TIM_TypeDef *timer_B; - uint8_t channel_R; - uint8_t channel_G; - uint8_t channel_B; + union { + struct { + TIM_TypeDef *R; + TIM_TypeDef *G; + TIM_TypeDef *B; + } timer; + TIM_TypeDef *timer_array[3]; + }; + union { + struct { + uint8_t R; + uint8_t G; + uint8_t B; + } channel; + uint8_t channel_array[3]; + }; } rgbled_context_t; @@ -44,7 +55,7 @@ typedef struct { */ int8_t rgbled_init(rgbled_context_t *context); -int8_t rgbled_set_color(uint16_t R, uint16_t G, uint16_t B); +int8_t rgbled_set_color(uint8_t R, uint8_t G, uint8_t B); int8_t rgbled_off(void); diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index 85ab184..787f38a 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -217,18 +217,17 @@ int main(void) /* RGB LED context init */ rgbled_context_t rgbled_context; - rgbled_context.timer_R = TIM22; - rgbled_context.timer_G = TIM22; - rgbled_context.timer_B = TIM2; - rgbled_context.channel_R = 2; - rgbled_context.channel_G = 1; - rgbled_context.channel_B = 1; + rgbled_context.timer.R = TIM22; + rgbled_context.timer.G = TIM22; + rgbled_context.timer.B = TIM2; + rgbled_context.channel.R = 2; + rgbled_context.channel.G = 1; + rgbled_context.channel.B = 1; rgbled_init(&rgbled_context); - rgbled_set_color(255, 0, 0); + rgbled_set_color(50, 50, 0); while (1) { -// rgbled_set_color(30000, 0, 0); LL_mDelay(1000); } diff --git a/fw/Core/Src/rgbled.c b/fw/Core/Src/rgbled.c index c3c998e..917202d 100644 --- a/fw/Core/Src/rgbled.c +++ b/fw/Core/Src/rgbled.c @@ -20,21 +20,37 @@ int8_t rgbled_init(rgbled_context_t *context) return RGBLED_OK; } -int8_t rgbled_set_color(uint16_t R, uint16_t G, uint16_t B) +int8_t rgbled_set_color(uint8_t R, uint8_t G, uint8_t B) { - // tim2 ch1 B - // tim22 ch1 G - // tim22 ch2 R - if ( - R > RGBLED_PERIOD || \ - G > RGBLED_PERIOD || \ - B > RGBLED_PERIOD) - { - return RGBLED_ERROR; + uint8_t colors[3]; + uint8_t i; + + colors[0] = R; + colors[1] = G; + colors[2] = B; + for (i = 0; i < 3; i++) { + if (colors[i] > RGBLED_PERIOD) { + return RGBLED_ERROR; + } + } + for (i = 0; i < 3; i++) { + switch (rgbled_context->channel_array[i]) { + case 1: + LL_TIM_OC_SetCompareCH1(rgbled_context->timer_array[i], (uint32_t)(RGBLED_PERIOD - colors[i])); + break; + case 2: + LL_TIM_OC_SetCompareCH2(rgbled_context->timer_array[i], (uint32_t)(RGBLED_PERIOD - colors[i])); + break; + case 3: + LL_TIM_OC_SetCompareCH3(rgbled_context->timer_array[i], (uint32_t)(RGBLED_PERIOD - colors[i])); + break; + case 4: + LL_TIM_OC_SetCompareCH4(rgbled_context->timer_array[i], (uint32_t)(RGBLED_PERIOD - colors[i])); + break; + default: + return RGBLED_WRONG_CHANNEL; + } } - LL_TIM_OC_SetCompareCH1(rgbled_context->timer_B, (uint32_t)(RGBLED_PERIOD - B)); // B - LL_TIM_OC_SetCompareCH1(rgbled_context->timer_G, (uint32_t)(RGBLED_PERIOD - G)); // G - LL_TIM_OC_SetCompareCH2(rgbled_context->timer_R, (uint32_t)(RGBLED_PERIOD - R)); // R return RGBLED_OK; } diff --git a/fw/iaq_wired_sensor Debug.launch b/fw/iaq_wired_sensor Debug.launch index 420a890..8aa4a98 100644 --- a/fw/iaq_wired_sensor Debug.launch +++ b/fw/iaq_wired_sensor Debug.launch @@ -28,7 +28,7 @@ - +