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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define C4X4RGB2_FRAME_START 0x00
61 #define C4X4RGB2_FRAME_END 0xFF
62 
67 #define C4X4RGB2_LED_0 0
68 #define C4X4RGB2_LED_1 1
69 #define C4X4RGB2_LED_2 2
70 #define C4X4RGB2_LED_3 3
71 #define C4X4RGB2_LED_4 4
72 #define C4X4RGB2_LED_5 5
73 #define C4X4RGB2_LED_6 6
74 #define C4X4RGB2_LED_7 7
75 #define C4X4RGB2_LED_8 8
76 #define C4X4RGB2_LED_9 9
77 #define C4X4RGB2_LED_10 10
78 #define C4X4RGB2_LED_11 11
79 #define C4X4RGB2_LED_12 12
80 #define C4X4RGB2_LED_13 13
81 #define C4X4RGB2_LED_14 14
82 #define C4X4RGB2_LED_15 15
83 #define C4X4RGB2_NUM_LEDS 16
84 
89 #define C4X4RGB2_LED_BRIGHTNESS_MIN 0
90 #define C4X4RGB2_LED_BRIGHTNESS_DEFAULT 1
91 #define C4X4RGB2_LED_BRIGHTNESS_MAX 31
92 #define C4X4RGB2_LED_BRIGHTNESS_MASK 0xE0
93 
98 #define C4X4RGB2_COLOR_BLACK 0x000000ul
99 #define C4X4RGB2_COLOR_WHITE 0xFFFFFFul
100 #define C4X4RGB2_COLOR_RED 0xFF0000ul
101 #define C4X4RGB2_COLOR_LIME 0x00FF00ul
102 #define C4X4RGB2_COLOR_BLUE 0x0000FFul
103 #define C4X4RGB2_COLOR_YELLOW 0xFFFF00ul
104 #define C4X4RGB2_COLOR_CYAN 0x00FFFFul
105 #define C4X4RGB2_COLOR_MAGENTA 0xFF00FFul
106 #define C4X4RGB2_COLOR_SILVER 0xC0C0C0ul
107 #define C4X4RGB2_COLOR_GRAY 0x808080ul
108 #define C4X4RGB2_COLOR_MAROON 0x800000ul
109 #define C4X4RGB2_COLOR_OLIVE 0x808000ul
110 #define C4X4RGB2_COLOR_GREEN 0x008000ul
111 #define C4X4RGB2_COLOR_PURPLE 0x800080ul
112 #define C4X4RGB2_COLOR_TEAL 0x008080ul
113 #define C4X4RGB2_COLOR_NAVY 0x000080ul
114 #define C4X4RGB2_NUM_COLORS 16
115 #define C4X4RGB2_SIZE_COLOR_NAME 32
116 
125 #define C4X4RGB2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
126 #define C4X4RGB2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
127  // c4x4rgb2_set
129 
144 #define C4X4RGB2_MAP_MIKROBUS( cfg, mikrobus ) \
145  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
146  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
147  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK );
148  // c4x4rgb2_map // c4x4rgb2
151 
156 typedef struct
157 {
158  uint32_t rgb;
159  uint8_t name[ C4X4RGB2_SIZE_COLOR_NAME ];
162 
167 typedef struct
168 {
169  uint8_t brightness;
170  uint8_t red;
171  uint8_t green;
172  uint8_t blue;
175 
180 typedef struct
181 {
182  // Modules
183  spi_master_t spi;
187 } c4x4rgb2_t;
188 
193 typedef struct
194 {
195  // Communication gpio pins
196  pin_name_t miso;
197  pin_name_t mosi;
198  pin_name_t sck;
200  // static variable
201  uint32_t spi_speed;
202  spi_master_mode_t spi_mode;
205 
210 typedef enum
211 {
213  C4X4RGB2_ERROR = -1
214 
216 
233 
248 
262 
277 err_t c4x4rgb2_write_leds ( c4x4rgb2_t *ctx, c4x4rgb2_led_t *leds, uint8_t num_leds );
278 
290 
304 void c4x4rgb2_set_led_brightness ( c4x4rgb2_t *ctx, uint8_t led_num, uint8_t brightness );
305 
318 void c4x4rgb2_set_all_leds_brightness ( c4x4rgb2_t *ctx, uint8_t brightness );
319 
333 void c4x4rgb2_set_led_color ( c4x4rgb2_t *ctx, uint8_t led_num, uint32_t rgb );
334 
347 void c4x4rgb2_set_all_leds_color ( c4x4rgb2_t *ctx, uint32_t rgb );
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 #endif // C4X4RGB2_H
353  // c4x4rgb2
355 
356 // ------------------------------------------------------------------------ END
spi_specifics.h
This file contains SPI specific macros, functions, etc.
C4X4RGB2_OK
@ C4X4RGB2_OK
Definition: c4x4rgb2.h:212
C4X4RGB2_ERROR
@ C4X4RGB2_ERROR
Definition: c4x4rgb2.h:213
c4x4rgb2_return_value_t
c4x4rgb2_return_value_t
4x4 RGB 2 Click return value data.
Definition: c4x4rgb2.h:211
c4x4rgb2_cfg_t::mosi
pin_name_t mosi
Definition: c4x4rgb2.h:197
c4x4rgb2_t
4x4 RGB 2 Click context object.
Definition: c4x4rgb2.h:181
C4X4RGB2_NUM_LEDS
#define C4X4RGB2_NUM_LEDS
Definition: c4x4rgb2.h:83
c4x4rgb2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c4x4rgb2.h:202
c4x4rgb2_cfg_t::miso
pin_name_t miso
Definition: c4x4rgb2.h:196
c4x4rgb2_color_t::rgb
uint32_t rgb
Definition: c4x4rgb2.h:158
c4x4rgb2_cfg_t::spi_speed
uint32_t spi_speed
Definition: c4x4rgb2.h:201
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:157
c4x4rgb2_cfg_t
4x4 RGB 2 Click configuration object.
Definition: c4x4rgb2.h:194
C4X4RGB2_SIZE_COLOR_NAME
#define C4X4RGB2_SIZE_COLOR_NAME
Definition: c4x4rgb2.h:115
c4x4rgb2_led_t::red
uint8_t red
Definition: c4x4rgb2.h:170
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:183
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:168
c4x4rgb2_led_t::brightness
uint8_t brightness
Definition: c4x4rgb2.h:169
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:171
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:172
c4x4rgb2_cfg_t::sck
pin_name_t sck
Definition: c4x4rgb2.h:198
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.