c10x10rgb2  2.1.0.0
c10x10rgb2.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 C10X10RGB2_H
29 #define C10X10RGB2_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 C10X10RGB2_FRAME_START 0x00
75 #define C10X10RGB2_FRAME_END 0xFF
76 
81 #define C10X10RGB2_LED_0 0
82 #define C10X10RGB2_LED_1 1
83 #define C10X10RGB2_LED_2 2
84 #define C10X10RGB2_LED_3 3
85 #define C10X10RGB2_LED_4 4
86 #define C10X10RGB2_LED_5 5
87 #define C10X10RGB2_LED_6 6
88 #define C10X10RGB2_LED_7 7
89 #define C10X10RGB2_LED_8 8
90 #define C10X10RGB2_LED_9 9
91 #define C10X10RGB2_LED_10 10
92 #define C10X10RGB2_LED_11 11
93 #define C10X10RGB2_LED_12 12
94 #define C10X10RGB2_LED_13 13
95 #define C10X10RGB2_LED_14 14
96 #define C10X10RGB2_LED_15 15
97 #define C10X10RGB2_LED_16 16
98 #define C10X10RGB2_LED_17 17
99 #define C10X10RGB2_LED_18 18
100 #define C10X10RGB2_LED_19 19
101 #define C10X10RGB2_LED_20 20
102 #define C10X10RGB2_LED_21 21
103 #define C10X10RGB2_LED_22 22
104 #define C10X10RGB2_LED_23 23
105 #define C10X10RGB2_LED_24 24
106 #define C10X10RGB2_LED_25 25
107 #define C10X10RGB2_LED_26 26
108 #define C10X10RGB2_LED_27 27
109 #define C10X10RGB2_LED_28 28
110 #define C10X10RGB2_LED_29 29
111 #define C10X10RGB2_LED_30 30
112 #define C10X10RGB2_LED_31 31
113 #define C10X10RGB2_LED_32 32
114 #define C10X10RGB2_LED_33 33
115 #define C10X10RGB2_LED_34 34
116 #define C10X10RGB2_LED_35 35
117 #define C10X10RGB2_LED_36 36
118 #define C10X10RGB2_LED_37 37
119 #define C10X10RGB2_LED_38 38
120 #define C10X10RGB2_LED_39 39
121 #define C10X10RGB2_LED_40 40
122 #define C10X10RGB2_LED_41 41
123 #define C10X10RGB2_LED_42 42
124 #define C10X10RGB2_LED_43 43
125 #define C10X10RGB2_LED_44 44
126 #define C10X10RGB2_LED_45 45
127 #define C10X10RGB2_LED_46 46
128 #define C10X10RGB2_LED_47 47
129 #define C10X10RGB2_LED_48 48
130 #define C10X10RGB2_LED_49 49
131 #define C10X10RGB2_LED_50 50
132 #define C10X10RGB2_LED_51 51
133 #define C10X10RGB2_LED_52 52
134 #define C10X10RGB2_LED_53 53
135 #define C10X10RGB2_LED_54 54
136 #define C10X10RGB2_LED_55 55
137 #define C10X10RGB2_LED_56 56
138 #define C10X10RGB2_LED_57 57
139 #define C10X10RGB2_LED_58 58
140 #define C10X10RGB2_LED_59 59
141 #define C10X10RGB2_LED_60 60
142 #define C10X10RGB2_LED_61 61
143 #define C10X10RGB2_LED_62 62
144 #define C10X10RGB2_LED_63 63
145 #define C10X10RGB2_LED_64 64
146 #define C10X10RGB2_LED_65 65
147 #define C10X10RGB2_LED_66 66
148 #define C10X10RGB2_LED_67 67
149 #define C10X10RGB2_LED_68 68
150 #define C10X10RGB2_LED_69 69
151 #define C10X10RGB2_LED_70 70
152 #define C10X10RGB2_LED_71 71
153 #define C10X10RGB2_LED_72 72
154 #define C10X10RGB2_LED_73 73
155 #define C10X10RGB2_LED_74 74
156 #define C10X10RGB2_LED_75 75
157 #define C10X10RGB2_LED_76 76
158 #define C10X10RGB2_LED_77 77
159 #define C10X10RGB2_LED_78 78
160 #define C10X10RGB2_LED_79 79
161 #define C10X10RGB2_LED_80 80
162 #define C10X10RGB2_LED_81 81
163 #define C10X10RGB2_LED_82 82
164 #define C10X10RGB2_LED_83 83
165 #define C10X10RGB2_LED_84 84
166 #define C10X10RGB2_LED_85 85
167 #define C10X10RGB2_LED_86 86
168 #define C10X10RGB2_LED_87 87
169 #define C10X10RGB2_LED_88 88
170 #define C10X10RGB2_LED_89 89
171 #define C10X10RGB2_LED_90 90
172 #define C10X10RGB2_LED_91 91
173 #define C10X10RGB2_LED_92 92
174 #define C10X10RGB2_LED_93 93
175 #define C10X10RGB2_LED_94 94
176 #define C10X10RGB2_LED_95 95
177 #define C10X10RGB2_LED_96 96
178 #define C10X10RGB2_LED_97 97
179 #define C10X10RGB2_LED_98 98
180 #define C10X10RGB2_LED_99 99
181 #define C10X10RGB2_NUM_LEDS 100
182 
187 #define C10X10RGB2_LED_BRIGHTNESS_MIN 0
188 #define C10X10RGB2_LED_BRIGHTNESS_DEFAULT 1
189 #define C10X10RGB2_LED_BRIGHTNESS_MAX 31
190 #define C10X10RGB2_LED_BRIGHTNESS_MASK 0xE0
191 
196 #define C10X10RGB2_COLOR_BLACK 0x000000ul
197 #define C10X10RGB2_COLOR_WHITE 0xFFFFFFul
198 #define C10X10RGB2_COLOR_RED 0xFF0000ul
199 #define C10X10RGB2_COLOR_LIME 0x00FF00ul
200 #define C10X10RGB2_COLOR_BLUE 0x0000FFul
201 #define C10X10RGB2_COLOR_YELLOW 0xFFFF00ul
202 #define C10X10RGB2_COLOR_CYAN 0x00FFFFul
203 #define C10X10RGB2_COLOR_MAGENTA 0xFF00FFul
204 #define C10X10RGB2_COLOR_SILVER 0xC0C0C0ul
205 #define C10X10RGB2_COLOR_GRAY 0x808080ul
206 #define C10X10RGB2_COLOR_MAROON 0x800000ul
207 #define C10X10RGB2_COLOR_OLIVE 0x808000ul
208 #define C10X10RGB2_COLOR_GREEN 0x008000ul
209 #define C10X10RGB2_COLOR_PURPLE 0x800080ul
210 #define C10X10RGB2_COLOR_TEAL 0x008080ul
211 #define C10X10RGB2_COLOR_NAVY 0x000080ul
212 
217 #define C10X10RGB2_ROTATION_V_0 0x00
218 #define C10X10RGB2_ROTATION_V_180 0x01
219 #define C10X10RGB2_ROTATION_H_0 0x10
220 #define C10X10RGB2_ROTATION_H_180 0x11
221 
230 #define C10X10RGB2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
231 #define C10X10RGB2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
232  // c10x10rgb2_set
234 
249 #define C10X10RGB2_MAP_MIKROBUS( cfg, mikrobus ) \
250  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
251  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
252  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK );
253  // c10x10rgb2_map // c10x10rgb2
256 
261 typedef struct
262 {
263  uint8_t brightness;
264  uint8_t red;
265  uint8_t green;
266  uint8_t blue;
269 
274 typedef struct
275 {
276  uint32_t txt_rgb;
277  uint32_t bg_rgb;
278  uint8_t rotation;
281 
286 typedef struct
287 {
288  // Modules
289  spi_master_t spi;
295 } c10x10rgb2_t;
296 
301 typedef struct
302 {
303  // Communication gpio pins
304  pin_name_t miso;
305  pin_name_t mosi;
306  pin_name_t sck;
308  // static variable
309  uint32_t spi_speed;
310  spi_master_mode_t spi_mode;
313 
318 typedef enum
319 {
321  C10X10RGB2_ERROR = -1
322 
324 
341 
356 
370 
385 err_t c10x10rgb2_write_leds ( c10x10rgb2_t *ctx, c10x10rgb2_led_t *leds, uint16_t num_leds );
386 
398 
412 void c10x10rgb2_set_led_brightness ( c10x10rgb2_t *ctx, uint16_t led_num, uint8_t brightness );
413 
426 void c10x10rgb2_set_leds_brightness ( c10x10rgb2_t *ctx, uint8_t brightness );
427 
441 void c10x10rgb2_set_led_color ( c10x10rgb2_t *ctx, uint16_t led_num, uint32_t rgb );
442 
455 void c10x10rgb2_set_leds_color ( c10x10rgb2_t *ctx, uint32_t rgb );
456 
467 uint32_t c10x10rgb2_make_color ( uint8_t red, uint8_t green, uint8_t blue, uint8_t rgb_pct );
468 
479 uint32_t c10x10rgb2_color_wheel ( uint8_t wheel_pos, uint8_t rgb_pct );
480 
492 err_t c10x10rgb2_fill_screen ( c10x10rgb2_t *ctx, uint32_t rgb );
493 
509 void c10x10rgb2_set_pen ( c10x10rgb2_t *ctx, uint32_t txt_rgb, uint32_t bg_rgb, uint8_t rotation );
510 
522 err_t c10x10rgb2_write_char ( c10x10rgb2_t *ctx, uint8_t data_in );
523 
536 err_t c10x10rgb2_write_string ( c10x10rgb2_t *ctx, uint8_t *data_in, uint16_t speed_ms );
537 
549 err_t c10x10rgb2_draw_picture ( c10x10rgb2_t *ctx, const uint32_t *image );
550 
564 err_t c10x10rgb2_demo_rainbow ( c10x10rgb2_t *ctx, uint8_t rgb_pct, uint16_t upd_rate_ms, uint16_t upd_num );
565 
566 #ifdef __cplusplus
567 }
568 #endif
569 #endif // C10X10RGB2_H
570  // c10x10rgb2
572 
573 // ------------------------------------------------------------------------ END
c10x10rgb2_pen_t::txt_rgb
uint32_t txt_rgb
Definition: c10x10rgb2.h:276
c10x10rgb2_return_value_t
c10x10rgb2_return_value_t
10x10 RGB 2 Click return value data.
Definition: c10x10rgb2.h:319
c10x10rgb2_draw_picture
err_t c10x10rgb2_draw_picture(c10x10rgb2_t *ctx, const uint32_t *image)
10x10 RGB 2 draw picture function.
c10x10rgb2_pen_t::bg_rgb
uint32_t bg_rgb
Definition: c10x10rgb2.h:277
c10x10rgb2_set_led_color
void c10x10rgb2_set_led_color(c10x10rgb2_t *ctx, uint16_t led_num, uint32_t rgb)
10x10 RGB 2 set led color function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
c10x10rgb2_t
10x10 RGB 2 Click context object.
Definition: c10x10rgb2.h:287
c10x10rgb2_t::spi
spi_master_t spi
Definition: c10x10rgb2.h:289
c10x10rgb2_cfg_t::sck
pin_name_t sck
Definition: c10x10rgb2.h:306
c10x10rgb2_set_led_brightness
void c10x10rgb2_set_led_brightness(c10x10rgb2_t *ctx, uint16_t led_num, uint8_t brightness)
10x10 RGB 2 set led brightness function.
c10x10rgb2_write_char
err_t c10x10rgb2_write_char(c10x10rgb2_t *ctx, uint8_t data_in)
10x10 RGB 2 write char function.
c10x10rgb2_demo_rainbow
err_t c10x10rgb2_demo_rainbow(c10x10rgb2_t *ctx, uint8_t rgb_pct, uint16_t upd_rate_ms, uint16_t upd_num)
10x10 RGB 2 demo rainbow function.
c10x10rgb2_fill_screen
err_t c10x10rgb2_fill_screen(c10x10rgb2_t *ctx, uint32_t rgb)
10x10 RGB 2 fill screen function.
c10x10rgb2_led_t::brightness
uint8_t brightness
Definition: c10x10rgb2.h:263
C10X10RGB2_ERROR
@ C10X10RGB2_ERROR
Definition: c10x10rgb2.h:321
c10x10rgb2_write_led_matrix
err_t c10x10rgb2_write_led_matrix(c10x10rgb2_t *ctx)
10x10 RGB 2 write led matrix function.
c10x10rgb2_default_cfg
err_t c10x10rgb2_default_cfg(c10x10rgb2_t *ctx)
10x10 RGB 2 default configuration function.
C10X10RGB2_NUM_LEDS
#define C10X10RGB2_NUM_LEDS
Definition: c10x10rgb2.h:181
c10x10rgb2_led_t
10x10 RGB 2 Click led object.
Definition: c10x10rgb2.h:262
c10x10rgb2_t::pen
c10x10rgb2_pen_t pen
Definition: c10x10rgb2.h:293
C10X10RGB2_OK
@ C10X10RGB2_OK
Definition: c10x10rgb2.h:320
c10x10rgb2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c10x10rgb2.h:310
c10x10rgb2_init
err_t c10x10rgb2_init(c10x10rgb2_t *ctx, c10x10rgb2_cfg_t *cfg)
10x10 RGB 2 initialization function.
c10x10rgb2_led_t::red
uint8_t red
Definition: c10x10rgb2.h:264
c10x10rgb2_write_leds
err_t c10x10rgb2_write_leds(c10x10rgb2_t *ctx, c10x10rgb2_led_t *leds, uint16_t num_leds)
10x10 RGB 2 write leds function.
c10x10rgb2_write_string
err_t c10x10rgb2_write_string(c10x10rgb2_t *ctx, uint8_t *data_in, uint16_t speed_ms)
10x10 RGB 2 write char function.
c10x10rgb2_cfg_t::mosi
pin_name_t mosi
Definition: c10x10rgb2.h:305
c10x10rgb2_set_leds_brightness
void c10x10rgb2_set_leds_brightness(c10x10rgb2_t *ctx, uint8_t brightness)
10x10 RGB 2 set leds brightness function.
c10x10rgb2_set_pen
void c10x10rgb2_set_pen(c10x10rgb2_t *ctx, uint32_t txt_rgb, uint32_t bg_rgb, uint8_t rotation)
10x10 RGB 2 set pen function.
c10x10rgb2_pen_t
10x10 RGB 2 Click pen object.
Definition: c10x10rgb2.h:275
c10x10rgb2_cfg_t::miso
pin_name_t miso
Definition: c10x10rgb2.h:304
c10x10rgb2_set_leds_color
void c10x10rgb2_set_leds_color(c10x10rgb2_t *ctx, uint32_t rgb)
10x10 RGB 2 set leds color function.
c10x10rgb2_cfg_setup
void c10x10rgb2_cfg_setup(c10x10rgb2_cfg_t *cfg)
10x10 RGB 2 configuration object setup function.
c10x10rgb2_led_t::blue
uint8_t blue
Definition: c10x10rgb2.h:266
c10x10rgb2_cfg_t
10x10 RGB 2 Click configuration object.
Definition: c10x10rgb2.h:302
c10x10rgb2_cfg_t::spi_speed
uint32_t spi_speed
Definition: c10x10rgb2.h:309
c10x10rgb2_make_color
uint32_t c10x10rgb2_make_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t rgb_pct)
10x10 RGB 2 make color function.
c10x10rgb2_pen_t::rotation
uint8_t rotation
Definition: c10x10rgb2.h:278
c10x10rgb2_color_wheel
uint32_t c10x10rgb2_color_wheel(uint8_t wheel_pos, uint8_t rgb_pct)
10x10 RGB 2 color wheel function.
c10x10rgb2_led_t::green
uint8_t green
Definition: c10x10rgb2.h:265