c2x4rgb  2.1.0.0
c2x4rgb.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef C2X4RGB_H
29 #define C2X4RGB_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 
72 #define C2X4RGB_LED_0 0
73 #define C2X4RGB_LED_1 1
74 #define C2X4RGB_LED_2 2
75 #define C2X4RGB_LED_3 3
76 #define C2X4RGB_LED_4 4
77 #define C2X4RGB_LED_5 5
78 #define C2X4RGB_LED_6 6
79 #define C2X4RGB_LED_7 7
80 #define C2X4RGB_NUM_LEDS 8
81 
86 #define C2X4RGB_LED_BRIGHTNESS_MIN 0
87 #define C2X4RGB_LED_BRIGHTNESS_DEFAULT 0
88 #define C2X4RGB_LED_BRIGHTNESS_MAX 15
89 
93 #define C2X4RGB_LED_CURRENT_GAIN_MIN 0
94 #define C2X4RGB_LED_CURRENT_GAIN_DEFAULT 0
95 #define C2X4RGB_LED_CURRENT_GAIN_MAX 15
96 
101 #define C2X4RGB_COLOR_BLACK 0x000000ul
102 #define C2X4RGB_COLOR_WHITE 0xFFFFFFul
103 #define C2X4RGB_COLOR_RED 0xFF0000ul
104 #define C2X4RGB_COLOR_LIME 0x00FF00ul
105 #define C2X4RGB_COLOR_BLUE 0x0000FFul
106 #define C2X4RGB_COLOR_YELLOW 0xFFFF00ul
107 #define C2X4RGB_COLOR_CYAN 0x00FFFFul
108 #define C2X4RGB_COLOR_MAGENTA 0xFF00FFul
109 #define C2X4RGB_COLOR_SILVER 0xC0C0C0ul
110 #define C2X4RGB_COLOR_GRAY 0x808080ul
111 #define C2X4RGB_COLOR_MAROON 0x800000ul
112 #define C2X4RGB_COLOR_OLIVE 0x808000ul
113 #define C2X4RGB_COLOR_GREEN 0x008000ul
114 #define C2X4RGB_COLOR_PURPLE 0x800080ul
115 #define C2X4RGB_COLOR_TEAL 0x008080ul
116 #define C2X4RGB_COLOR_NAVY 0x000080ul
117 #define C2X4RGB_NUM_COLORS 16
118 #define C2X4RGB_SIZE_COLOR_NAME 32
119  // c2x4rgb_set
121 
136 #define C2X4RGB_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.din = MIKROBUS( mikrobus, MIKROBUS_PWM );
138  // c2x4rgb_map // c2x4rgb
141 
146 typedef void ( *c2x4rgb_logic_t ) ( void );
147 
152 typedef struct
153 {
154  uint32_t rgb;
155  uint8_t name[ C2X4RGB_SIZE_COLOR_NAME ];
158 
163 typedef struct
164 {
165  uint8_t current_gain;
166  uint8_t brightness;
167  uint8_t red;
168  uint8_t green;
169  uint8_t blue;
171 } c2x4rgb_led_t;
172 
177 typedef struct
178 {
179  digital_out_t din;
186 } c2x4rgb_t;
187 
192 typedef struct
193 {
194  pin_name_t din;
196 } c2x4rgb_cfg_t;
197 
202 typedef enum
203 {
205  C2X4RGB_ERROR = -1
206 
208 
225 
241 err_t c2x4rgb_init ( c2x4rgb_t *ctx, c2x4rgb_logic_t logic_zero, c2x4rgb_logic_t logic_one, c2x4rgb_cfg_t *cfg );
242 
255 
270 err_t c2x4rgb_write_leds ( c2x4rgb_t *ctx, c2x4rgb_led_t *leds, uint8_t num_leds );
271 
283 
298 void c2x4rgb_set_led_intensity ( c2x4rgb_t *ctx, uint8_t led_num, uint8_t brightness, uint8_t gain );
299 
313 void c2x4rgb_set_leds_intensity ( c2x4rgb_t *ctx, uint8_t brightness, uint8_t gain );
314 
328 void c2x4rgb_set_led_color ( c2x4rgb_t *ctx, uint8_t led_num, uint32_t rgb );
329 
342 void c2x4rgb_set_leds_color ( c2x4rgb_t *ctx, uint32_t rgb );
343 
344 #ifdef __cplusplus
345 }
346 #endif
347 #endif // C2X4RGB_H
348  // c2x4rgb
350 
351 // ------------------------------------------------------------------------ END
c2x4rgb_led_t::red
uint8_t red
Definition: c2x4rgb.h:167
c2x4rgb_cfg_setup
void c2x4rgb_cfg_setup(c2x4rgb_cfg_t *cfg)
2x4 RGB configuration object setup function.
C2X4RGB_ERROR
@ C2X4RGB_ERROR
Definition: c2x4rgb.h:205
c2x4rgb_default_cfg
err_t c2x4rgb_default_cfg(c2x4rgb_t *ctx)
2x4 RGB default configuration function.
c2x4rgb_return_value_t
c2x4rgb_return_value_t
2x4 RGB Click return value data.
Definition: c2x4rgb.h:203
c2x4rgb_cfg_t
2x4 RGB Click configuration object.
Definition: c2x4rgb.h:193
c2x4rgb_color_t::rgb
uint32_t rgb
Definition: c2x4rgb.h:154
c2x4rgb_t::din
digital_out_t din
Definition: c2x4rgb.h:179
c2x4rgb_led_t::green
uint8_t green
Definition: c2x4rgb.h:168
c2x4rgb_set_leds_color
void c2x4rgb_set_leds_color(c2x4rgb_t *ctx, uint32_t rgb)
2x4 RGB set LEDs color function.
c2x4rgb_logic_t
void(* c2x4rgb_logic_t)(void)
Function pointer for logic level one and zero.
Definition: c2x4rgb.h:146
c2x4rgb_set_leds_intensity
void c2x4rgb_set_leds_intensity(c2x4rgb_t *ctx, uint8_t brightness, uint8_t gain)
2x4 RGB set LEDs intensity function.
c2x4rgb_set_led_intensity
void c2x4rgb_set_led_intensity(c2x4rgb_t *ctx, uint8_t led_num, uint8_t brightness, uint8_t gain)
2x4 RGB set LED intensity function.
c2x4rgb_led_t
2x4 RGB Click led object.
Definition: c2x4rgb.h:164
c2x4rgb_t::logic_one
c2x4rgb_logic_t logic_one
Definition: c2x4rgb.h:182
c2x4rgb_set_led_color
void c2x4rgb_set_led_color(c2x4rgb_t *ctx, uint8_t led_num, uint32_t rgb)
2x4 RGB set LED color function.
c2x4rgb_led_t::current_gain
uint8_t current_gain
Definition: c2x4rgb.h:165
c2x4rgb_write_leds
err_t c2x4rgb_write_leds(c2x4rgb_t *ctx, c2x4rgb_led_t *leds, uint8_t num_leds)
2x4 RGB write LEDs function.
c2x4rgb_color_t
2x4 RGB Click RGB color object.
Definition: c2x4rgb.h:153
c2x4rgb_init
err_t c2x4rgb_init(c2x4rgb_t *ctx, c2x4rgb_logic_t logic_zero, c2x4rgb_logic_t logic_one, c2x4rgb_cfg_t *cfg)
2x4 RGB initialization function.
C2X4RGB_SIZE_COLOR_NAME
#define C2X4RGB_SIZE_COLOR_NAME
Definition: c2x4rgb.h:118
c2x4rgb_cfg_t::din
pin_name_t din
Definition: c2x4rgb.h:194
c2x4rgb_led_t::brightness
uint8_t brightness
Definition: c2x4rgb.h:166
C2X4RGB_NUM_LEDS
#define C2X4RGB_NUM_LEDS
Definition: c2x4rgb.h:80
c2x4rgb_t
2x4 RGB Click context object.
Definition: c2x4rgb.h:178
c2x4rgb_t::logic_zero
c2x4rgb_logic_t logic_zero
Definition: c2x4rgb.h:181
c2x4rgb_write_led_matrix
err_t c2x4rgb_write_led_matrix(c2x4rgb_t *ctx)
2x4 RGB write LED matrix function.
c2x4rgb_led_t::blue
uint8_t blue
Definition: c2x4rgb.h:169
C2X4RGB_OK
@ C2X4RGB_OK
Definition: c2x4rgb.h:204