rotaryrgb  2.1.0.0
rotaryrgb.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 ROTARYRGB_H
29 #define ROTARYRGB_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 ROTARYRGB_COLOR_WHITE_100 0x002F2F2Ful
73 #define ROTARYRGB_COLOR_WHITE_75 0x00232323ul
74 #define ROTARYRGB_COLOR_WHITE_50 0x00181818ul
75 #define ROTARYRGB_COLOR_WHITE_25 0x000C0C0Cul
76 #define ROTARYRGB_COLOR_RED_100 0x00002F00ul
77 #define ROTARYRGB_COLOR_RED_75 0x00002300ul
78 #define ROTARYRGB_COLOR_RED_50 0x00001800ul
79 #define ROTARYRGB_COLOR_RED_25 0x00000C00ul
80 #define ROTARYRGB_COLOR_GREEN_100 0x002F0000ul
81 #define ROTARYRGB_COLOR_GREEN_75 0x00230000ul
82 #define ROTARYRGB_COLOR_GREEN_50 0x00180000ul
83 #define ROTARYRGB_COLOR_GREEN_25 0x000C0000ul
84 #define ROTARYRGB_COLOR_BLUE_100 0x0000002Ful
85 #define ROTARYRGB_COLOR_BLUE_75 0x00000023ul
86 #define ROTARYRGB_COLOR_BLUE_50 0x00000018ul
87 #define ROTARYRGB_COLOR_BLUE_25 0x0000000Cul
88 #define ROTARYRGB_COLOR_LIGHT_BLUE_100 0x002F002Ful
89 #define ROTARYRGB_COLOR_LIGHT_BLUE_75 0x00230023ul
90 #define ROTARYRGB_COLOR_LIGHT_BLUE_50 0x00180018ul
91 #define ROTARYRGB_COLOR_LIGHT_BLUE_25 0x000C000Cul
92 #define ROTARYRGB_COLOR_YELLOW_100 0x002F2F00ul
93 #define ROTARYRGB_COLOR_YELLOW_75 0x00232300ul
94 #define ROTARYRGB_COLOR_YELLOW_50 0x00181800ul
95 #define ROTARYRGB_COLOR_YELLOW_25 0x000C0C00ul
96 #define ROTARYRGB_COLOR_PURPLE_100 0x00002F2Ful
97 #define ROTARYRGB_COLOR_PURPLE_75 0x00002323ul
98 #define ROTARYRGB_COLOR_PURPLE_50 0x00001818ul
99 #define ROTARYRGB_COLOR_PURPLE_25 0x00000C0Cul
100 #define ROTARYRGB_COLOR_OFF 0x00000000ul
101 
106 #define ROTARYRGB_SET_LED_POS_1 1
107 #define ROTARYRGB_SET_LED_POS_2 2
108 #define ROTARYRGB_SET_LED_POS_3 3
109 #define ROTARYRGB_SET_LED_POS_4 4
110 #define ROTARYRGB_SET_LED_POS_5 5
111 #define ROTARYRGB_SET_LED_POS_6 6
112 #define ROTARYRGB_SET_LED_POS_7 7
113 #define ROTARYRGB_SET_LED_POS_8 8
114 #define ROTARYRGB_SET_LED_POS_9 9
115 #define ROTARYRGB_SET_LED_POS_10 10
116 #define ROTARYRGB_SET_LED_POS_11 11
117 #define ROTARYRGB_SET_LED_POS_12 12
118 #define ROTARYRGB_SET_LED_POS_13 13
119 #define ROTARYRGB_SET_LED_POS_14 14
120 #define ROTARYRGB_SET_LED_POS_15 15
121 #define ROTARYRGB_SET_LED_POS_16 16
122  // rotaryrgb_set
124 
139 #define ROTARYRGB_MAP_MIKROBUS( cfg, mikrobus ) \
140  cfg.enb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
141  cfg.di_pin = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
142  cfg.do_pin = MIKROBUS( mikrobus, MIKROBUS_RST ); \
143  cfg.ena = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
144  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_INT )
145  // rotaryrgb_map // rotaryrgb
148 
149 typedef void ( *drv_logic_t ) ( void );
150 
155 typedef struct
156 {
157  digital_out_t di_pin;
159  digital_in_t enb;
160  digital_in_t do_pin;
161  digital_in_t ena;
162  digital_in_t sw;
164  // Function pointers
167 
168 } rotaryrgb_t;
169 
174 typedef struct
175 {
176  pin_name_t enb;
177  pin_name_t do_pin;
178  pin_name_t di_pin;
179  pin_name_t ena;
180  pin_name_t sw;
182  // Function pointers
185 
187 
192 typedef enum
193 {
195  ROTARYRGB_ERROR = -1
196 
198 
214 void rotaryrgb_cfg_setup ( rotaryrgb_cfg_t *cfg, drv_logic_t logic_zero, drv_logic_t logic_one );
215 
230 
242 void rotaryrgb_set_led_data ( rotaryrgb_t *ctx, uint32_t data_in );
243 
256 void rotaryrgb_set_all_leds_data ( rotaryrgb_t *ctx, uint32_t *data_in );
257 
269 void rotaryrgb_set_all_led_color ( rotaryrgb_t *ctx, uint32_t led_color );
270 
285 err_t rotaryrgb_set_led_pos_color ( rotaryrgb_t *ctx, uint8_t led_pos, uint32_t led_color );
286 
299 uint32_t rotaryrgb_make_color ( uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness );
300 
311 
322 
334 
346 
358 
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 #endif // ROTARYRGB_H
375  // rotaryrgb
377 
378 // ------------------------------------------------------------------------ END
rotaryrgb_cfg_t
Rotary RGB Click configuration object.
Definition: rotaryrgb.h:175
rotaryrgb_return_value_t
rotaryrgb_return_value_t
Rotary RGB Click return value data.
Definition: rotaryrgb.h:193
rotaryrgb_cfg_t::di_pin
pin_name_t di_pin
Definition: rotaryrgb.h:178
rotaryrgb_set_all_led_color
void rotaryrgb_set_all_led_color(rotaryrgb_t *ctx, uint32_t led_color)
Rotary RGB set all LEDs color function.
ROTARYRGB_ERROR
@ ROTARYRGB_ERROR
Definition: rotaryrgb.h:195
rotaryrgb_get_state_do_pin
uint8_t rotaryrgb_get_state_do_pin(rotaryrgb_t *ctx)
Rotary RGB get DO pin state function.
rotaryrgb_t::do_pin
digital_in_t do_pin
Definition: rotaryrgb.h:160
rotaryrgb_t::enb
digital_in_t enb
Definition: rotaryrgb.h:159
rotaryrgb_di_pin_clear
void rotaryrgb_di_pin_clear(rotaryrgb_t *ctx)
Rotary RGB DI pin clearing function.
rotaryrgb_cfg_t::ena
pin_name_t ena
Definition: rotaryrgb.h:179
rotaryrgb_set_all_leds_data
void rotaryrgb_set_all_leds_data(rotaryrgb_t *ctx, uint32_t *data_in)
Rotary RGB set all LEDs data function.
ROTARYRGB_OK
@ ROTARYRGB_OK
Definition: rotaryrgb.h:194
drv_logic_t
void(* drv_logic_t)(void)
Definition: rotaryrgb.h:149
rotaryrgb_get_state_switch
uint8_t rotaryrgb_get_state_switch(rotaryrgb_t *ctx)
Rotary RGB get switch state function.
rotaryrgb_t::logic_zero
drv_logic_t logic_zero
Definition: rotaryrgb.h:165
rotaryrgb_init
err_t rotaryrgb_init(rotaryrgb_t *ctx, rotaryrgb_cfg_t *cfg)
Rotary RGB initialization function.
rotaryrgb_cfg_t::enb
pin_name_t enb
Definition: rotaryrgb.h:176
rotaryrgb_set_led_pos_color
err_t rotaryrgb_set_led_pos_color(rotaryrgb_t *ctx, uint8_t led_pos, uint32_t led_color)
Rotary RGB set LED position color function.
rotaryrgb_make_color
uint32_t rotaryrgb_make_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness)
Rotary RGB make color function.
rotaryrgb_cfg_t::logic_one
drv_logic_t logic_one
Definition: rotaryrgb.h:184
rotaryrgb_set_led_data
void rotaryrgb_set_led_data(rotaryrgb_t *ctx, uint32_t data_in)
Rotary RGB set LED data function.
rotaryrgb_t::logic_one
drv_logic_t logic_one
Definition: rotaryrgb.h:166
rotaryrgb_set_state_di_pin
void rotaryrgb_set_state_di_pin(rotaryrgb_t *ctx)
Rotary RGB DI pin setting function.
rotaryrgb_get_state_enb
uint8_t rotaryrgb_get_state_enb(rotaryrgb_t *ctx)
Rotary RGB get encoder B state function.
rotaryrgb_cfg_setup
void rotaryrgb_cfg_setup(rotaryrgb_cfg_t *cfg, drv_logic_t logic_zero, drv_logic_t logic_one)
Rotary RGB configuration object setup function.
rotaryrgb_t::sw
digital_in_t sw
Definition: rotaryrgb.h:162
rotaryrgb_t::ena
digital_in_t ena
Definition: rotaryrgb.h:161
rotaryrgb_cfg_t::logic_zero
drv_logic_t logic_zero
Definition: rotaryrgb.h:183
rotaryrgb_cfg_t::sw
pin_name_t sw
Definition: rotaryrgb.h:180
rotaryrgb_cfg_t::do_pin
pin_name_t do_pin
Definition: rotaryrgb.h:177
rotaryrgb_t
Rotary RGB Click context object.
Definition: rotaryrgb.h:156
rotaryrgb_get_state_ena
uint8_t rotaryrgb_get_state_ena(rotaryrgb_t *ctx)
Rotary RGB get encoder A state function.
rotaryrgb_t::di_pin
digital_out_t di_pin
Definition: rotaryrgb.h:157