rgbdriver  2.0.0.0
rgbdriver.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 RGBDRIVER_H
36 #define RGBDRIVER_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 RGBDRIVER_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
55 
61 #define RGBDRIVER_RETVAL uint8_t
62 
63 #define RGBDRIVER_OK 0x00
64 #define RGBDRIVER_INIT_ERROR 0xFF
65 
72 #define RGBDRIVER_COLOR_RED_HIGH_INTENSITY 0x7F8040
73 #define RGBDRIVER_COLOR_ORANGE_HIGH_INTENSITY 0x7F8240
74 #define RGBDRIVER_COLOR_YELLOW_HIGH_INTENSITY 0x7F9440
75 #define RGBDRIVER_COLOR_GREEN_HIGH_INTENSITY 0x609F40
76 #define RGBDRIVER_COLOR_BLUE_HIGH_INTENSITY 0x60805F
77 #define RGBDRIVER_COLOR_WHITE_HIGH_INTENSITY 0x7F9F5F
78 #define RGBDRIVER_COLOR_PURPLE_HIGH_INTENSITY 0x78805C
79 
80 #define RGBDRIVER_COLOR_RED_LOW_INTENSITY 0x618040
81 #define RGBDRIVER_COLOR_ORANGE_LOW_INTENSITY 0x6A8140
82 #define RGBDRIVER_COLOR_YELLOW_LOW_INTENSITY 0x6A8540
83 #define RGBDRIVER_COLOR_GREEN_LOW_INTENSITY 0x608140
84 #define RGBDRIVER_COLOR_BLUE_LOW_INTENSITY 0x608041
85 #define RGBDRIVER_COLOR_WHITE_LOW_INTENSITY 0x618141
86 #define RGBDRIVER_COLOR_PURPLE_LOW_INTENSITY 0x658044
87 
88 #define RGBDRIVER_COLOR_OFF 0x000000
89  // End group macro
92 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef struct
102 {
103  // Modules
104 
105  i2c_master_t i2c;
106 
107  // ctx variable
108 
109  uint8_t slave_address;
110 
111 } rgbdriver_t;
112 
116 typedef struct
117 {
118  // Communication gpio pins
119 
120  pin_name_t scl;
121  pin_name_t sda;
122 
123  // static variable
124 
125  uint32_t i2c_speed;
126  uint8_t i2c_address;
127 
129  // End types group
131 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
132 
138 #ifdef __cplusplus
139 extern "C"{
140 #endif
141 
151 
161 
170 
180 void rgbdriver_generic_write ( rgbdriver_t *ctx, uint8_t *data_buf, uint8_t len );
181 
192 void rgbdriver_set_rgb_color ( rgbdriver_t *ctx, uint8_t red, uint8_t green, uint8_t blue );
193 
212 void rgbdriver_set_color ( rgbdriver_t *ctx, uint32_t color );
213 
221 void rgbdriver_shut_down ( rgbdriver_t *ctx );
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 #endif // _RGBDRIVER_H_
227  // End public_function group
230 
231 // ------------------------------------------------------------------------- END
rgbdriver_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rgbdriver.h:125
rgbdriver_set_rgb_color
void rgbdriver_set_rgb_color(rgbdriver_t *ctx, uint8_t red, uint8_t green, uint8_t blue)
Function set RGB color.
rgbdriver_generic_write
void rgbdriver_generic_write(rgbdriver_t *ctx, uint8_t *data_buf, uint8_t len)
Generic write function.
rgbdriver_cfg_t::i2c_address
uint8_t i2c_address
Definition: rgbdriver.h:126
rgbdriver_set_color
void rgbdriver_set_color(rgbdriver_t *ctx, uint32_t color)
Function set color.
rgbdriver_shut_down
void rgbdriver_shut_down(rgbdriver_t *ctx)
Shut down function.
rgbdriver_cfg_t
Click configuration structure definition.
Definition: rgbdriver.h:116
rgbdriver_cfg_t::scl
pin_name_t scl
Definition: rgbdriver.h:120
rgbdriver_cfg_setup
void rgbdriver_cfg_setup(rgbdriver_cfg_t *cfg)
Config Object Initialization function.
rgbdriver_t::i2c
i2c_master_t i2c
Definition: rgbdriver.h:105
RGBDRIVER_RETVAL
#define RGBDRIVER_RETVAL
Definition: rgbdriver.h:61
rgbdriver_init
RGBDRIVER_RETVAL rgbdriver_init(rgbdriver_t *ctx, rgbdriver_cfg_t *cfg)
Initialization function.
rgbdriver_cfg_t::sda
pin_name_t sda
Definition: rgbdriver.h:121
rgbdriver_t
Click ctx object definition.
Definition: rgbdriver.h:101
rgbdriver_t::slave_address
uint8_t slave_address
Definition: rgbdriver.h:109
rgbdriver_default_cfg
RGBDRIVER_RETVAL rgbdriver_default_cfg(rgbdriver_t *ctx)
Click Default Configuration function.