104 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			104 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 * File:        rgbled.h
 | 
						|
 * Description: RGB LED library
 | 
						|
 * Author:      Jan Mrna
 | 
						|
 * Date:        2021-10-11
 | 
						|
 *
 | 
						|
 *
 | 
						|
 * Copyright (c) 2024 Veles Labs s.r.o.
 | 
						|
 *
 | 
						|
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
						|
 * of this software and associated documentation files (the "Software"), to deal
 | 
						|
 * in the Software without restriction, including without limitation the rights
 | 
						|
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
						|
 * copies of the Software, and to permit persons to whom the Software is
 | 
						|
 * furnished to do so, subject to the following conditions:
 | 
						|
 *
 | 
						|
 * The above copyright notice and this permission notice shall be included in all
 | 
						|
 * copies or substantial portions of the Software.
 | 
						|
 *
 | 
						|
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
						|
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
						|
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
						|
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
						|
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
						|
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | 
						|
 * SOFTWARE.
 | 
						|
 *
 | 
						|
 */
 | 
						|
 | 
						|
#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_ */
 |