c4x4rgb2  2.1.0.0
c4x4rgb2.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 C4X4RGB2_H
29 #define C4X4RGB2_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 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define C4X4RGB2_FRAME_START 0x00
75 #define C4X4RGB2_FRAME_END 0xFF
76 
81 #define C4X4RGB2_LED_0 0
82 #define C4X4RGB2_LED_1 1
83 #define C4X4RGB2_LED_2 2
84 #define C4X4RGB2_LED_3 3
85 #define C4X4RGB2_LED_4 4
86 #define C4X4RGB2_LED_5 5
87 #define C4X4RGB2_LED_6 6
88 #define C4X4RGB2_LED_7 7
89 #define C4X4RGB2_LED_8 8
90 #define C4X4RGB2_LED_9 9
91 #define C4X4RGB2_LED_10 10
92 #define C4X4RGB2_LED_11 11
93 #define C4X4RGB2_LED_12 12
94 #define C4X4RGB2_LED_13 13
95 #define C4X4RGB2_LED_14 14
96 #define C4X4RGB2_LED_15 15
97 #define C4X4RGB2_NUM_LEDS 16
98 
103 #define C4X4RGB2_LED_BRIGHTNESS_MIN 0
104 #define C4X4RGB2_LED_BRIGHTNESS_DEFAULT 1
105 #define C4X4RGB2_LED_BRIGHTNESS_MAX 31
106 #define C4X4RGB2_LED_BRIGHTNESS_MASK 0xE0
107 
112 #define C4X4RGB2_COLOR_BLACK 0x000000ul
113 #define C4X4RGB2_COLOR_WHITE 0xFFFFFFul
114 #define C4X4RGB2_COLOR_RED 0xFF0000ul
115 #define C4X4RGB2_COLOR_LIME 0x00FF00ul
116 #define C4X4RGB2_COLOR_BLUE 0x0000FFul
117 #define C4X4RGB2_COLOR_YELLOW 0xFFFF00ul
118 #define C4X4RGB2_COLOR_CYAN 0x00FFFFul
119 #define C4X4RGB2_COLOR_MAGENTA 0xFF00FFul
120 #define C4X4RGB2_COLOR_SILVER 0xC0C0C0ul
121 #define C4X4RGB2_COLOR_GRAY 0x808080ul
122 #define C4X4RGB2_COLOR_MAROON 0x800000ul
123 #define C4X4RGB2_COLOR_OLIVE 0x808000ul
124 #define C4X4RGB2_COLOR_GREEN 0x008000ul
125 #define C4X4RGB2_COLOR_PURPLE 0x800080ul
126 #define C4X4RGB2_COLOR_TEAL 0x008080ul
127 #define C4X4RGB2_COLOR_NAVY 0x000080ul
128 #define C4X4RGB2_NUM_COLORS 16
129 #define C4X4RGB2_SIZE_COLOR_NAME 32
130 
139 #define C4X4RGB2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
140 #define C4X4RGB2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
141  // c4x4rgb2_set
143 
158 #define C4X4RGB2_MAP_MIKROBUS( cfg, mikrobus ) \
159  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
160  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
161  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK );
162  // c4x4rgb2_map // c4x4rgb2
165 
170 typedef struct
171 {
172  uint32_t rgb;
173  uint8_t name[ C4X4RGB2_SIZE_COLOR_NAME ];
176 
181 typedef struct
182 {
183  uint8_t brightness;
184  uint8_t red;
185  uint8_t green;
186  uint8_t blue;
189 
194 typedef struct
195 {
196  // Modules
197  spi_master_t spi;
201 } c4x4rgb2_t;
202 
207 typedef struct
208 {
209  // Communication gpio pins
210  pin_name_t miso;
211  pin_name_t mosi;
212  pin_name_t sck;
214  // static variable
215  uint32_t spi_speed;
216  spi_master_mode_t spi_mode;
219 
224 typedef enum
225 {
227  C4X4RGB2_ERROR = -1
228 
230 
247 
262 
276 
291 err_t c4x4rgb2_write_leds ( c4x4rgb2_t *ctx, c4x4rgb2_led_t *leds, uint8_t num_leds );
292 
304 
318 void c4x4rgb2_set_led_brightness ( c4x4rgb2_t *ctx, uint8_t led_num, uint8_t brightness );
319 
332 void c4x4rgb2_set_all_leds_brightness ( c4x4rgb2_t *ctx, uint8_t brightness );
333 
347 void c4x4rgb2_set_led_color ( c4x4rgb2_t *ctx, uint8_t led_num, uint32_t rgb );
348 
361 void c4x4rgb2_set_all_leds_color ( c4x4rgb2_t *ctx, uint32_t rgb );
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 #endif // C4X4RGB2_H
367  // c4x4rgb2
369 
370 // ------------------------------------------------------------------------ END
spi_specifics.h
This file contains SPI specific macros, functions, etc.
C4X4RGB2_OK
@ C4X4RGB2_OK
Definition: c4x4rgb2.h:226
C4X4RGB2_ERROR
@ C4X4RGB2_ERROR
Definition: c4x4rgb2.h:227
c4x4rgb2_return_value_t
c4x4rgb2_return_value_t
4x4 RGB 2 Click return value data.
Definition: c4x4rgb2.h:225
c4x4rgb2_cfg_t::mosi
pin_name_t mosi
Definition: c4x4rgb2.h:211
c4x4rgb2_t
4x4 RGB 2 Click context object.
Definition: c4x4rgb2.h:195
C4X4RGB2_NUM_LEDS
#define C4X4RGB2_NUM_LEDS
Definition: c4x4rgb2.h:97
c4x4rgb2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c4x4rgb2.h:216
c4x4rgb2_cfg_t::miso
pin_name_t miso
Definition: c4x4rgb2.h:210
c4x4rgb2_color_t::rgb
uint32_t rgb
Definition: c4x4rgb2.h:172
c4x4rgb2_cfg_t::spi_speed
uint32_t spi_speed
Definition: c4x4rgb2.h:215
c4x4rgb2_set_led_brightness
void c4x4rgb2_set_led_brightness(c4x4rgb2_t *ctx, uint8_t led_num, uint8_t brightness)
4x4 RGB 2 set led brightness function.
c4x4rgb2_color_t
4x4 RGB 2 Click RGB color object.
Definition: c4x4rgb2.h:171
c4x4rgb2_cfg_t
4x4 RGB 2 Click configuration object.
Definition: c4x4rgb2.h:208
C4X4RGB2_SIZE_COLOR_NAME
#define C4X4RGB2_SIZE_COLOR_NAME
Definition: c4x4rgb2.h:129
c4x4rgb2_led_t::red
uint8_t red
Definition: c4x4rgb2.h:184
c4x4rgb2_default_cfg
err_t c4x4rgb2_default_cfg(c4x4rgb2_t *ctx)
4x4 RGB 2 default configuration function.
c4x4rgb2_init
err_t c4x4rgb2_init(c4x4rgb2_t *ctx, c4x4rgb2_cfg_t *cfg)
4x4 RGB 2 initialization function.
c4x4rgb2_t::spi
spi_master_t spi
Definition: c4x4rgb2.h:197
c4x4rgb2_set_led_color
void c4x4rgb2_set_led_color(c4x4rgb2_t *ctx, uint8_t led_num, uint32_t rgb)
4x4 RGB 2 set led color function.
c4x4rgb2_led_t
4x4 RGB 2 Click led object.
Definition: c4x4rgb2.h:182
c4x4rgb2_led_t::brightness
uint8_t brightness
Definition: c4x4rgb2.h:183
c4x4rgb2_cfg_setup
void c4x4rgb2_cfg_setup(c4x4rgb2_cfg_t *cfg)
4x4 RGB 2 configuration object setup function.
c4x4rgb2_led_t::green
uint8_t green
Definition: c4x4rgb2.h:185
c4x4rgb2_write_leds
err_t c4x4rgb2_write_leds(c4x4rgb2_t *ctx, c4x4rgb2_led_t *leds, uint8_t num_leds)
4x4 RGB 2 write leds function.
c4x4rgb2_set_all_leds_brightness
void c4x4rgb2_set_all_leds_brightness(c4x4rgb2_t *ctx, uint8_t brightness)
4x4 RGB 2 set all leds brightness function.
c4x4rgb2_led_t::blue
uint8_t blue
Definition: c4x4rgb2.h:186
c4x4rgb2_cfg_t::sck
pin_name_t sck
Definition: c4x4rgb2.h:212
c4x4rgb2_write_led_matrix
err_t c4x4rgb2_write_led_matrix(c4x4rgb2_t *ctx)
4x4 RGB 2 write led matrix function.
c4x4rgb2_set_all_leds_color
void c4x4rgb2_set_all_leds_color(c4x4rgb2_t *ctx, uint32_t rgb)
4x4 RGB 2 set all leds color function.