leddriver3  2.0.0.0
leddriver3.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef LEDDRIVER3_H
36 #define LEDDRIVER3_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define LEDDRIVER3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define LEDDRIVER3_RETVAL uint8_t
62 
63 #define LEDDRIVER3_OK 0x00
64 #define LEDDRIVER3_INIT_ERROR 0xFF
65 
71 #define LEDDRIVER3_COLOR_RED 0x5F6080
72 #define LEDDRIVER3_COLOR_ORANGE 0x5F6280
73 #define LEDDRIVER3_COLOR_YELLOW 0x5F7480
74 #define LEDDRIVER3_COLOR_GREEN 0x407F80
75 #define LEDDRIVER3_COLOR_BLUE 0x40609F
76 #define LEDDRIVER3_COLOR_WHITE 0x5F7F9F
77 #define LEDDRIVER3_COLOR_PURPLE 0x58609C
78 #define LEDDRIVER3_COLOR_OFF 0x000000
79 
85 #define LEDDRIVER3_TIMER_8ms 0xE1
86 #define LEDDRIVER3_TIMER_16ms 0xE2
87 #define LEDDRIVER3_TIMER_32ms 0xE4
88 #define LEDDRIVER3_TIMER_64ms 0xE8
89 #define LEDDRIVER3_TIMER_128ms 0xE0
90 
96 #define LEDDRIVER3_INTENSITY_1 0x01
97 #define LEDDRIVER3_INTENSITY_2 0x02
98 #define LEDDRIVER3_INTENSITY_4 0x04
99 #define LEDDRIVER3_INTENSITY_8 0x08
100 #define LEDDRIVER3_INTENSITY_16 0x10
101 
102 #define LEDDRIVER3_INCREMENT 0xA0
103 #define LEDDRIVER3_DECREMENT 0xC0
104 #define LEDDRIVER3_CONSTANT 0x20
105  // End group macro
108 // --------------------------------------------------------------- PUBLIC TYPES
117 typedef struct
118 {
119  uint8_t red;
120  uint8_t green;
121  uint8_t blue;
123 
127 typedef struct
128 {
129  // Modules
130 
131  i2c_master_t i2c;
132 
133  // ctx variable
134 
135  uint8_t slave_address;
136 
137 } leddriver3_t;
138 
142 typedef struct
143 {
144  // Communication gpio pins
145 
146  pin_name_t scl;
147  pin_name_t sda;
148 
149  // static variable
150 
151  i2c_master_speed_t i2c_speed;
152  uint8_t i2c_address;
153 
155  // End types group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
164 #ifdef __cplusplus
165 extern "C"{
166 #endif
167 
177 
186 
197 void leddriver3_generic_write ( leddriver3_t *ctx, uint8_t reg, uint8_t mode );
198 
209 void leddriver3_generic_read ( leddriver3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
210 
223 void leddriver3_set_intensity ( leddriver3_t *ctx, uint8_t intensity );
224 
236 
253 void leddriver3_set_color ( leddriver3_t *ctx, uint32_t color );
254 
262 void leddriver3_shut_down ( leddriver3_t *ctx );
263 
272 void leddriver3_set_timer ( leddriver3_t *ctx, uint8_t time );
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 #endif // _LEDDRIVER3_H_
278  // End public_function group
281 
282 // ------------------------------------------------------------------------- END
uint8_t blue
Definition: leddriver3.h:121
uint8_t red
Definition: leddriver3.h:119
void leddriver3_generic_write(leddriver3_t *ctx, uint8_t reg, uint8_t mode)
Generic write function.
Click ctx object definition.
Definition: leddriver3.h:127
RGB color value definition.
Definition: leddriver3.h:117
void leddriver3_set_intensity(leddriver3_t *ctx, uint8_t intensity)
Set intensity function.
void leddriver3_set_timer(leddriver3_t *ctx, uint8_t time)
Set timer function.
uint8_t green
Definition: leddriver3.h:120
void leddriver3_shut_down(leddriver3_t *ctx)
Shut down function.
void leddriver3_generic_read(leddriver3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t slave_address
Definition: leddriver3.h:135
LEDDRIVER3_RETVAL leddriver3_init(leddriver3_t *ctx, leddriver3_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition: leddriver3.h:142
pin_name_t sda
Definition: leddriver3.h:147
uint8_t i2c_address
Definition: leddriver3.h:152
i2c_master_t i2c
Definition: leddriver3.h:131
void leddriver3_set_color(leddriver3_t *ctx, uint32_t color)
Function set color.
pin_name_t scl
Definition: leddriver3.h:146
void leddriver3_cfg_setup(leddriver3_cfg_t *cfg)
Config Object Initialization function.
i2c_master_speed_t i2c_speed
Definition: leddriver3.h:151
void leddriver3_set_rgb_color(leddriver3_t *ctx, leddriver3_rgb_t *rgb)
Function set RGB color.
#define LEDDRIVER3_RETVAL
Definition: leddriver3.h:61