Added rgbled, for now still coupled with LL

This commit is contained in:
Jan Mrna 2022-06-17 09:36:42 +02:00
parent 286247f5a0
commit 612ab1d3dc
4 changed files with 6 additions and 158 deletions

View File

@ -35,6 +35,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/sgp40}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/scd4x}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/modbus}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/rgbled}&quot;"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.input.366934534" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.input"/>
</tool>
@ -67,6 +68,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/sgp40}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/scd4x}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/modbus}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/rgbled}&quot;"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1544503170" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
</tool>
@ -97,6 +99,7 @@
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Libs/crc8"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Libs/modbus"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Libs/rgbled"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Libs/scd4x"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Libs/sgp40"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Libs/sht4x"/>
@ -136,6 +139,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/sgp40}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/scd4x}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/modbus}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/rgbled}&quot;"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.input.1707174983" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.input"/>
</tool>
@ -167,6 +171,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/sgp40}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/scd4x}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/modbus}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Libs/rgbled}&quot;"/>
</option>
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.1160143889" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
</tool>

View File

@ -1,81 +0,0 @@
/*
* rgbled.h
*
* Created on: Nov 11, 2021
* Author: dooku
*/
#ifndef INC_RGBLED_H_
#define INC_RGBLED_H_
#include "stm32l0xx_ll_tim.h"
#include "stddef.h"
/*
* Return values for I2C functions
*/
#define RGBLED_OK 0
#define RGBLED_ERROR -1 // generic error
#define RGBLED_WRONG_CHANNEL -2 // channel number not in {1,2,3,4}
/*
* Defaults used for LL timer (PWM) initialization
*/
#define RGBLED_PRESCALER 0
#define RGBLED_PERIOD 255
#define RGBLED_MAX_INTENSITY 100
/*
* Shorthands for colors
*/
#define RGBLED_RED 255,0,0
#define RGBLED_GREEN 0,255,0
#define RGBLED_BLUE 0,0,255
#define RGBLED_WHITE 255,255,255
#define RGBLED_YELLOW 255,255,0
#define RGBLED_OFF 0,0,0
#define RGBLED_MAGENTA 255,0,255
/*
* Type definitions
*/
typedef struct {
// tim2 ch1 B
// tim22 ch1 G
// tim22 ch2 R
// TODO union, aby se dalo nastavovat LED v cyklu (set_color)
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;
/*
* Function declarations
*/
int8_t rgbled_init(rgbled_context_t *context);
int8_t rgbled_set_color(uint8_t R, uint8_t G, uint8_t B);
int8_t rgbled_set_intensity(uint8_t intensity);
int8_t rgbled_get_intensity(uint8_t *intensity);
int8_t rgbled_off(void);
#endif /* INC_RGBLED_H_ */

View File

@ -1,76 +0,0 @@
/*
* rgbled.c
*
* Created on: Nov 11, 2021
* Author: dooku
*/
#include "rgbled.h"
static rgbled_context_t *rgbled_context;
static uint8_t rgbled_intensity = RGBLED_MAX_INTENSITY; /* LED intensity from 0 (off) to RGBLED_MAX_INTENSITY (full power) */
int8_t rgbled_init(rgbled_context_t *context)
{
if (context == NULL) {
return RGBLED_ERROR;
}
rgbled_context = context;
return RGBLED_OK;
}
int8_t rgbled_set_color(uint8_t R, uint8_t G, uint8_t B)
{
uint8_t colors[3];
uint8_t i;
colors[0] = (uint32_t)R * rgbled_intensity / RGBLED_MAX_INTENSITY;
colors[1] = (uint32_t)G * rgbled_intensity / RGBLED_MAX_INTENSITY;
colors[2] = (uint32_t)B * rgbled_intensity / RGBLED_MAX_INTENSITY;
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;
}
}
return RGBLED_OK;
}
int8_t rgbled_set_intensity(uint8_t intensity)
{
if (intensity > RGBLED_MAX_INTENSITY) {
return RGBLED_ERROR;
}
rgbled_intensity = intensity;
}
int8_t rgbled_get_intensity(uint8_t *intensity)
{
if (intensity == NULL) {
return RGBLED_ERROR;
}
*intensity = rgbled_intensity;
}
int8_t rgbled_off(void)
{
rgbled_set_color(RGBLED_OFF);
}

@ -1 +1 @@
Subproject commit 4ab95c1da96078adda09aa32f78c7da3a326d2fc
Subproject commit 212249edf6abf7e9ba25a295c6697bd819cc94d4