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
32extern "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
142 // 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
163 // c4x4rgb2_map
164 // c4x4rgb2
165
170typedef struct
171{
172 uint32_t rgb;
173 uint8_t name[ C4X4RGB2_SIZE_COLOR_NAME ];
176
181typedef struct
182{
183 uint8_t brightness;
184 uint8_t red;
185 uint8_t green;
186 uint8_t blue;
189
194typedef struct
195{
196 // Modules
197 spi_master_t spi;
201} c4x4rgb2_t;
202
207typedef 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
224typedef enum
225{
227 C4X4RGB2_ERROR = -1
228
230
247
262
276
291err_t c4x4rgb2_write_leds ( c4x4rgb2_t *ctx, c4x4rgb2_led_t *leds, uint8_t num_leds );
292
304
318void c4x4rgb2_set_led_brightness ( c4x4rgb2_t *ctx, uint8_t led_num, uint8_t brightness );
319
332void c4x4rgb2_set_all_leds_brightness ( c4x4rgb2_t *ctx, uint8_t brightness );
333
347void c4x4rgb2_set_led_color ( c4x4rgb2_t *ctx, uint8_t led_num, uint32_t rgb );
348
361void c4x4rgb2_set_all_leds_color ( c4x4rgb2_t *ctx, uint32_t rgb );
362
363#ifdef __cplusplus
364}
365#endif
366#endif // C4X4RGB2_H
367
368 // c4x4rgb2
369
370// ------------------------------------------------------------------------ END
c4x4rgb2_return_value_t
4x4 RGB 2 Click return value data.
Definition c4x4rgb2.h:225
@ C4X4RGB2_OK
Definition c4x4rgb2.h:226
@ C4X4RGB2_ERROR
Definition c4x4rgb2.h:227
#define C4X4RGB2_SIZE_COLOR_NAME
Definition c4x4rgb2.h:129
#define C4X4RGB2_NUM_LEDS
Definition c4x4rgb2.h:97
void c4x4rgb2_cfg_setup(c4x4rgb2_cfg_t *cfg)
4x4 RGB 2 configuration object setup function.
void c4x4rgb2_set_led_color(c4x4rgb2_t *ctx, uint8_t led_num, uint32_t rgb)
4x4 RGB 2 set led color function.
err_t c4x4rgb2_init(c4x4rgb2_t *ctx, c4x4rgb2_cfg_t *cfg)
4x4 RGB 2 initialization function.
err_t c4x4rgb2_write_leds(c4x4rgb2_t *ctx, c4x4rgb2_led_t *leds, uint8_t num_leds)
4x4 RGB 2 write leds function.
void c4x4rgb2_set_all_leds_brightness(c4x4rgb2_t *ctx, uint8_t brightness)
4x4 RGB 2 set all leds brightness function.
err_t c4x4rgb2_default_cfg(c4x4rgb2_t *ctx)
4x4 RGB 2 default configuration function.
void c4x4rgb2_set_led_brightness(c4x4rgb2_t *ctx, uint8_t led_num, uint8_t brightness)
4x4 RGB 2 set led brightness function.
err_t c4x4rgb2_write_led_matrix(c4x4rgb2_t *ctx)
4x4 RGB 2 write led matrix function.
void c4x4rgb2_set_all_leds_color(c4x4rgb2_t *ctx, uint32_t rgb)
4x4 RGB 2 set all leds color function.
This file contains SPI specific macros, functions, etc.
4x4 RGB 2 Click configuration object.
Definition c4x4rgb2.h:208
pin_name_t sck
Definition c4x4rgb2.h:212
spi_master_mode_t spi_mode
Definition c4x4rgb2.h:216
pin_name_t mosi
Definition c4x4rgb2.h:211
uint32_t spi_speed
Definition c4x4rgb2.h:215
pin_name_t miso
Definition c4x4rgb2.h:210
4x4 RGB 2 Click RGB color object.
Definition c4x4rgb2.h:171
uint32_t rgb
Definition c4x4rgb2.h:172
4x4 RGB 2 Click led object.
Definition c4x4rgb2.h:182
uint8_t blue
Definition c4x4rgb2.h:186
uint8_t brightness
Definition c4x4rgb2.h:183
uint8_t green
Definition c4x4rgb2.h:185
uint8_t red
Definition c4x4rgb2.h:184
4x4 RGB 2 Click context object.
Definition c4x4rgb2.h:195
spi_master_t spi
Definition c4x4rgb2.h:197