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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define LEDDRIVER3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define LEDDRIVER3_RETVAL uint8_t
72 
73 #define LEDDRIVER3_OK 0x00
74 #define LEDDRIVER3_INIT_ERROR 0xFF
75 
81 #define LEDDRIVER3_COLOR_RED 0x5F6080
82 #define LEDDRIVER3_COLOR_ORANGE 0x5F6280
83 #define LEDDRIVER3_COLOR_YELLOW 0x5F7480
84 #define LEDDRIVER3_COLOR_GREEN 0x407F80
85 #define LEDDRIVER3_COLOR_BLUE 0x40609F
86 #define LEDDRIVER3_COLOR_WHITE 0x5F7F9F
87 #define LEDDRIVER3_COLOR_PURPLE 0x58609C
88 #define LEDDRIVER3_COLOR_OFF 0x000000
89 
95 #define LEDDRIVER3_TIMER_8ms 0xE1
96 #define LEDDRIVER3_TIMER_16ms 0xE2
97 #define LEDDRIVER3_TIMER_32ms 0xE4
98 #define LEDDRIVER3_TIMER_64ms 0xE8
99 #define LEDDRIVER3_TIMER_128ms 0xE0
100 
106 #define LEDDRIVER3_INTENSITY_1 0x01
107 #define LEDDRIVER3_INTENSITY_2 0x02
108 #define LEDDRIVER3_INTENSITY_4 0x04
109 #define LEDDRIVER3_INTENSITY_8 0x08
110 #define LEDDRIVER3_INTENSITY_16 0x10
111 
112 #define LEDDRIVER3_INCREMENT 0xA0
113 #define LEDDRIVER3_DECREMENT 0xC0
114 #define LEDDRIVER3_CONSTANT 0x20
115  // End group macro
118 // --------------------------------------------------------------- PUBLIC TYPES
127 typedef struct
128 {
129  uint8_t red;
130  uint8_t green;
131  uint8_t blue;
133 
137 typedef struct
138 {
139  // Modules
140 
141  i2c_master_t i2c;
142 
143  // ctx variable
144 
145  uint8_t slave_address;
146 
147 } leddriver3_t;
148 
152 typedef struct
153 {
154  // Communication gpio pins
155 
156  pin_name_t scl;
157  pin_name_t sda;
158 
159  // static variable
160 
161  i2c_master_speed_t i2c_speed;
162  uint8_t i2c_address;
163 
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
187 
196 
207 void leddriver3_generic_write ( leddriver3_t *ctx, uint8_t reg, uint8_t mode );
208 
219 void leddriver3_generic_read ( leddriver3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
220 
233 void leddriver3_set_intensity ( leddriver3_t *ctx, uint8_t intensity );
234 
246 
263 void leddriver3_set_color ( leddriver3_t *ctx, uint32_t color );
264 
273 
282 void leddriver3_set_timer ( leddriver3_t *ctx, uint8_t time );
283 
284 #ifdef __cplusplus
285 }
286 #endif
287 #endif // _LEDDRIVER3_H_
288  // End public_function group
291 
292 // ------------------------------------------------------------------------- END
leddriver3_set_rgb_color
void leddriver3_set_rgb_color(leddriver3_t *ctx, leddriver3_rgb_t *rgb)
Function set RGB color.
leddriver3_t::slave_address
uint8_t slave_address
Definition: leddriver3.h:145
leddriver3_cfg_setup
void leddriver3_cfg_setup(leddriver3_cfg_t *cfg)
Config Object Initialization function.
leddriver3_rgb_t
RGB color value definition.
Definition: leddriver3.h:128
leddriver3_cfg_t::sda
pin_name_t sda
Definition: leddriver3.h:157
leddriver3_rgb_t::blue
uint8_t blue
Definition: leddriver3.h:131
leddriver3_cfg_t
Click configuration structure definition.
Definition: leddriver3.h:153
leddriver3_rgb_t::red
uint8_t red
Definition: leddriver3.h:129
leddriver3_rgb_t::green
uint8_t green
Definition: leddriver3.h:130
leddriver3_t
Click ctx object definition.
Definition: leddriver3.h:138
leddriver3_init
LEDDRIVER3_RETVAL leddriver3_init(leddriver3_t *ctx, leddriver3_cfg_t *cfg)
Initialization function.
leddriver3_cfg_t::i2c_speed
i2c_master_speed_t i2c_speed
Definition: leddriver3.h:161
leddriver3_t::i2c
i2c_master_t i2c
Definition: leddriver3.h:141
leddriver3_generic_write
void leddriver3_generic_write(leddriver3_t *ctx, uint8_t reg, uint8_t mode)
Generic write function.
leddriver3_set_color
void leddriver3_set_color(leddriver3_t *ctx, uint32_t color)
Function set color.
leddriver3_cfg_t::scl
pin_name_t scl
Definition: leddriver3.h:156
leddriver3_generic_read
void leddriver3_generic_read(leddriver3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
LEDDRIVER3_RETVAL
#define LEDDRIVER3_RETVAL
Definition: leddriver3.h:71
leddriver3_cfg_t::i2c_address
uint8_t i2c_address
Definition: leddriver3.h:162
leddriver3_set_intensity
void leddriver3_set_intensity(leddriver3_t *ctx, uint8_t intensity)
Set intensity function.
leddriver3_set_timer
void leddriver3_set_timer(leddriver3_t *ctx, uint8_t time)
Set timer function.
leddriver3_shut_down
void leddriver3_shut_down(leddriver3_t *ctx)
Shut down function.