c2x2rgb  2.1.0.0
c2x2rgb.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 C2X2RGB_H
29 #define C2X2RGB_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define C2X2RGB_REG_ID 0x00
70 #define C2X2RGB_REG_MONITOR 0x01
71 #define C2X2RGB_REG_CONTROL 0x02
72 #define C2X2RGB_REG_IRED1 0x03
73 #define C2X2RGB_REG_IGRN1 0x04
74 #define C2X2RGB_REG_IBLU1 0x05
75 #define C2X2RGB_REG_IRED2 0x06
76 #define C2X2RGB_REG_IGRN2 0x07
77 #define C2X2RGB_REG_IBLU2 0x08
78 #define C2X2RGB_REG_IRED3 0x09
79 #define C2X2RGB_REG_IGRN3 0x0A
80 #define C2X2RGB_REG_IBLU3 0x0B
81 #define C2X2RGB_REG_IRED4 0x0C
82 #define C2X2RGB_REG_IGRN4 0x0D
83 #define C2X2RGB_REG_IBLU4 0x0E
84 #define C2X2RGB_REG_PG_CNTL 0x0F
85 #define C2X2RGB_REG_PG_FADE 0x10
86 #define C2X2RGB_REG_PG_RGB1 0x11
87 #define C2X2RGB_REG_PG_RGB2 0x12
88 #define C2X2RGB_REG_PG_RGB3 0x13
89 #define C2X2RGB_REG_PG_RGB4 0x14
90 #define C2X2RGB_REG_PG_WD 0x15
91  // c2x2rgb_reg
93 
108 #define C2X2RGB_SET_LD1 1
109 #define C2X2RGB_SET_LD2 2
110 #define C2X2RGB_SET_LD3 3
111 #define C2X2RGB_SET_LD4 4
112 
117 #define C2X2RGB_DEV_ID 0x06
118 #define C2X2RGB_DEV_ID_BIT_MASK 0x0F
119 #define C2X2RGB_VEN_ID 0x05
120 #define C2X2RGB_VEN_ID_BIT_MASK 0x07
121 
126 #define C2X2RGB_MONITOR_UV_OT_STAT 0x01
127 #define C2X2RGB_MONITOR_COOL_STAT 0x02
128 #define C2X2RGB_MONITOR_BE_STAT 0x04
129 #define C2X2RGB_MONITOR_SC_STAT 0x08
130 
135 #define C2X2RGB_LED_CURRENT_OFF 0
136 #define C2X2RGB_LED_CURRENT_3MA 3000
137 #define C2X2RGB_LED_CURRENT_MAX 24000
138 #define C2X2RGB_LED_CURRENT_STEP 125
139 
140 
145 #define C2X2RGB_EN_MODE_SHUTDOWN 0x00
146 #define C2X2RGB_EN_MODE_NIGHT 0x01
147 #define C2X2RGB_EN_MODE_NORMAL 0x02
148 #define C2X2RGB_EN_MODE_SW_RESET 0x03
149 #define C2X2RGB_EN_MODE_BIT_MASK 0xC0
150 #define C2X2RGB_BE_DISABLE 0x00
151 #define C2X2RGB_BE_ENABLE 0x01
152 #define C2X2RGB_BE_BIT_MASK 0x20
153 #define C2X2RGB_CE_TEMP_135C 0x00
154 #define C2X2RGB_CE_TEMP_120C 0x01
155 #define C2X2RGB_CE_TEMP_105C 0x02
156 #define C2X2RGB_CE_TEMP_90C 0x03
157 #define C2X2RGB_CE_TEMP_BIT_MASK 0x18
158 #define C2X2RGB_FADE_RATE0_32_MS 0x00
159 #define C2X2RGB_FADE_RATE0_63_MS 0x01
160 #define C2X2RGB_FADE_RATE0_125_MS 0x02
161 #define C2X2RGB_FADE_RATE0_250_MS 0x03
162 #define C2X2RGB_FADE_RATE0_500_MS 0x04
163 #define C2X2RGB_FADE_RATE0_1_S 0x05
164 #define C2X2RGB_FADE_RATE0_2_S 0x06
165 #define C2X2RGB_FADE_RATE0_4_S 0x07
166 #define C2X2RGB_FADE_RATE0_BIT_MASK 0x07
167 
172 #define C2X2RGB_PG_MODE_OFF 0x00
173 #define C2X2RGB_PG_MODE_4P_EN 0x01
174 #define C2X2RGB_PG_MODE_6P_EN 0x02
175 #define C2X2RGB_PG_MODE_8P_EN 0x03
176 #define C2X2RGB_PG_MODE_BIT_MASK 0xC0
177 #define C2X2RGB_PG_TIME_188_MS 0x00
178 #define C2X2RGB_PG_TIME_2_S 0x0F
179 #define C2X2RGB_PG_TIME_BIT_MASK 0x3C
180 
181 #define C2X2RGB_FADE_RATE1_32_MS 0x00
182 #define C2X2RGB_FADE_RATE1_4_S 0x07
183 #define C2X2RGB_FADE_RATE1_BIT_MASK 0x07
184 
185 
191 #define C2X2RGB_DEVICE_ADDRESS 0x74
192  // c2x2rgb_set
194 
209 #define C2X2RGB_MAP_MIKROBUS( cfg, mikrobus ) \
210  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
211  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
212  // c2x2rgb_map // c2x2rgb
215 
220 typedef struct
221 {
222 
223  // Modules
224  i2c_master_t i2c;
226  // I2C slave address
227  uint8_t slave_address;
229 } c2x2rgb_t;
230 
235 typedef struct
236 {
237  pin_name_t scl;
238  pin_name_t sda;
240  uint32_t i2c_speed;
241  uint8_t i2c_address;
243 } c2x2rgb_cfg_t;
244 
249 typedef struct
250 {
251  uint8_t en_mode;
252  uint16_t led1_ired;
253  uint16_t led1_igrn;
254  uint16_t led1_iblu;
255  uint16_t led2_ired;
256  uint16_t led2_igrn;
257  uint16_t led2_iblu;
258  uint16_t led3_ired;
259  uint16_t led3_igrn;
260  uint16_t led3_iblu;
261  uint16_t led4_ired;
262  uint16_t led4_igrn;
263  uint16_t led4_iblu;
266 
271 typedef enum
272 {
274  C2X2RGB_ERROR = -1
275 
277 
294 
308 err_t c2x2rgb_init ( c2x2rgb_t *ctx, c2x2rgb_cfg_t *cfg );
309 
323 
337 err_t c2x2rgb_generic_write ( c2x2rgb_t *ctx, uint8_t reg, uint8_t data_in );
338 
352 err_t c2x2rgb_generic_read ( c2x2rgb_t *ctx, uint8_t reg, uint8_t *data_out );
353 
367 err_t c2x2rgb_get_device_id ( c2x2rgb_t *ctx, uint8_t *vendor_id, uint8_t *device_id );
368 
383 err_t c2x2rgb_get_monitor_status ( c2x2rgb_t *ctx, uint8_t *sc_stat, uint8_t *be_stat,
384  uint8_t *cool_stat, uint8_t *uv_ot_stat );
385 
400 err_t c2x2rgb_set_control ( c2x2rgb_t *ctx, uint8_t en_mode, uint8_t be_en,
401  uint8_t ce_temp, uint8_t fade_rate );
402 
414 
426 
441 err_t c2x2rgb_set_rgb_led ( c2x2rgb_t *ctx, uint8_t led_num, uint16_t ired, uint16_t igrn, uint16_t iblu );
442 
456 
470 err_t c2x2rgb_set_pg_ctrl ( c2x2rgb_t *ctx, uint8_t pg_mode, uint8_t pg_time, uint8_t fade_rate );
471 
483 err_t c2x2rgb_set_pg_fade ( c2x2rgb_t *ctx, uint8_t pg_fade );
484 
497 err_t c2x2rgb_set_pg_rgb ( c2x2rgb_t *ctx, uint8_t led_num, uint8_t pg_rgb );
498 
510 err_t c2x2rgb_set_pg_wd ( c2x2rgb_t *ctx, uint8_t wd_pcr );
511 
512 #ifdef __cplusplus
513 }
514 #endif
515 #endif // C2X2RGB_H
516  // c2x2rgb
518 
519 // ------------------------------------------------------------------------ END
c2x2rgb_rgb_led_t::led3_ired
uint16_t led3_ired
Definition: c2x2rgb.h:258
c2x2rgb_set_pg_rgb
err_t c2x2rgb_set_pg_rgb(c2x2rgb_t *ctx, uint8_t led_num, uint8_t pg_rgb)
2x2 RGB set PG fade function.
c2x2rgb_set_rgb_led
err_t c2x2rgb_set_rgb_led(c2x2rgb_t *ctx, uint8_t led_num, uint16_t ired, uint16_t igrn, uint16_t iblu)
2x2 RGB set RGB LED function.
C2X2RGB_OK
@ C2X2RGB_OK
Definition: c2x2rgb.h:273
c2x2rgb_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c2x2rgb.h:240
c2x2rgb_cfg_t::i2c_address
uint8_t i2c_address
Definition: c2x2rgb.h:241
c2x2rgb_rgb_led_t::led2_igrn
uint16_t led2_igrn
Definition: c2x2rgb.h:256
c2x2rgb_rgb_led_t::led4_iblu
uint16_t led4_iblu
Definition: c2x2rgb.h:263
c2x2rgb_default_cfg
err_t c2x2rgb_default_cfg(c2x2rgb_t *ctx)
2x2 RGB default configuration function.
c2x2rgb_set_all_rgb_led
err_t c2x2rgb_set_all_rgb_led(c2x2rgb_t *ctx, c2x2rgb_rgb_led_t cfg_rgb_led)
2x2 RGB set all RGB LED function.
c2x2rgb_rgb_led_t::led3_igrn
uint16_t led3_igrn
Definition: c2x2rgb.h:259
c2x2rgb_cfg_t
2x2 RGB Click configuration object.
Definition: c2x2rgb.h:236
c2x2rgb_cfg_t::sda
pin_name_t sda
Definition: c2x2rgb.h:238
c2x2rgb_return_value_t
c2x2rgb_return_value_t
2x2 RGB Click return value data.
Definition: c2x2rgb.h:272
c2x2rgb_t
2x2 RGB Click context object.
Definition: c2x2rgb.h:221
c2x2rgb_init
err_t c2x2rgb_init(c2x2rgb_t *ctx, c2x2rgb_cfg_t *cfg)
2x2 RGB initialization function.
c2x2rgb_t::slave_address
uint8_t slave_address
Definition: c2x2rgb.h:227
c2x2rgb_rgb_led_t::en_mode
uint8_t en_mode
Definition: c2x2rgb.h:251
c2x2rgb_rgb_led_t::led1_igrn
uint16_t led1_igrn
Definition: c2x2rgb.h:253
c2x2rgb_rgb_led_t
2x2 RGB Click LED current setting object.
Definition: c2x2rgb.h:250
c2x2rgb_get_device_id
err_t c2x2rgb_get_device_id(c2x2rgb_t *ctx, uint8_t *vendor_id, uint8_t *device_id)
2x2 RGB get device ID function.
c2x2rgb_rgb_led_t::led4_ired
uint16_t led4_ired
Definition: c2x2rgb.h:261
c2x2rgb_set_pg_fade
err_t c2x2rgb_set_pg_fade(c2x2rgb_t *ctx, uint8_t pg_fade)
2x2 RGB set PG fade function.
c2x2rgb_set_control
err_t c2x2rgb_set_control(c2x2rgb_t *ctx, uint8_t en_mode, uint8_t be_en, uint8_t ce_temp, uint8_t fade_rate)
2x2 RGB set control function.
c2x2rgb_set_pg_wd
err_t c2x2rgb_set_pg_wd(c2x2rgb_t *ctx, uint8_t wd_pcr)
2x2 RGB set pattern watchdog counter function.
c2x2rgb_set_normal_mode
err_t c2x2rgb_set_normal_mode(c2x2rgb_t *ctx)
2x2 RGB set normal mode function.
c2x2rgb_rgb_led_t::led3_iblu
uint16_t led3_iblu
Definition: c2x2rgb.h:260
c2x2rgb_rgb_led_t::led2_ired
uint16_t led2_ired
Definition: c2x2rgb.h:255
c2x2rgb_cfg_setup
void c2x2rgb_cfg_setup(c2x2rgb_cfg_t *cfg)
2x2 RGB configuration object setup function.
c2x2rgb_rgb_led_t::led4_igrn
uint16_t led4_igrn
Definition: c2x2rgb.h:262
c2x2rgb_sw_reset
err_t c2x2rgb_sw_reset(c2x2rgb_t *ctx)
2x2 RGB set soft reset function.
c2x2rgb_cfg_t::scl
pin_name_t scl
Definition: c2x2rgb.h:237
c2x2rgb_t::i2c
i2c_master_t i2c
Definition: c2x2rgb.h:224
c2x2rgb_set_pg_ctrl
err_t c2x2rgb_set_pg_ctrl(c2x2rgb_t *ctx, uint8_t pg_mode, uint8_t pg_time, uint8_t fade_rate)
2x2 RGB set PG control function.
c2x2rgb_rgb_led_t::led1_iblu
uint16_t led1_iblu
Definition: c2x2rgb.h:254
C2X2RGB_ERROR
@ C2X2RGB_ERROR
Definition: c2x2rgb.h:274
c2x2rgb_rgb_led_t::led1_ired
uint16_t led1_ired
Definition: c2x2rgb.h:252
c2x2rgb_generic_read
err_t c2x2rgb_generic_read(c2x2rgb_t *ctx, uint8_t reg, uint8_t *data_out)
2x2 RGB I2C reading function.
c2x2rgb_generic_write
err_t c2x2rgb_generic_write(c2x2rgb_t *ctx, uint8_t reg, uint8_t data_in)
2x2 RGB I2C writing function.
c2x2rgb_get_monitor_status
err_t c2x2rgb_get_monitor_status(c2x2rgb_t *ctx, uint8_t *sc_stat, uint8_t *be_stat, uint8_t *cool_stat, uint8_t *uv_ot_stat)
2x2 RGB get monitor status function.
c2x2rgb_rgb_led_t::led2_iblu
uint16_t led2_iblu
Definition: c2x2rgb.h:257