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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define C2X2RGB_REG_ID 0x00
60 #define C2X2RGB_REG_MONITOR 0x01
61 #define C2X2RGB_REG_CONTROL 0x02
62 #define C2X2RGB_REG_IRED1 0x03
63 #define C2X2RGB_REG_IGRN1 0x04
64 #define C2X2RGB_REG_IBLU1 0x05
65 #define C2X2RGB_REG_IRED2 0x06
66 #define C2X2RGB_REG_IGRN2 0x07
67 #define C2X2RGB_REG_IBLU2 0x08
68 #define C2X2RGB_REG_IRED3 0x09
69 #define C2X2RGB_REG_IGRN3 0x0A
70 #define C2X2RGB_REG_IBLU3 0x0B
71 #define C2X2RGB_REG_IRED4 0x0C
72 #define C2X2RGB_REG_IGRN4 0x0D
73 #define C2X2RGB_REG_IBLU4 0x0E
74 #define C2X2RGB_REG_PG_CNTL 0x0F
75 #define C2X2RGB_REG_PG_FADE 0x10
76 #define C2X2RGB_REG_PG_RGB1 0x11
77 #define C2X2RGB_REG_PG_RGB2 0x12
78 #define C2X2RGB_REG_PG_RGB3 0x13
79 #define C2X2RGB_REG_PG_RGB4 0x14
80 #define C2X2RGB_REG_PG_WD 0x15
81  // c2x2rgb_reg
83 
98 #define C2X2RGB_SET_LD1 1
99 #define C2X2RGB_SET_LD2 2
100 #define C2X2RGB_SET_LD3 3
101 #define C2X2RGB_SET_LD4 4
102 
107 #define C2X2RGB_DEV_ID 0x06
108 #define C2X2RGB_DEV_ID_BIT_MASK 0x0F
109 #define C2X2RGB_VEN_ID 0x05
110 #define C2X2RGB_VEN_ID_BIT_MASK 0x07
111 
116 #define C2X2RGB_MONITOR_UV_OT_STAT 0x01
117 #define C2X2RGB_MONITOR_COOL_STAT 0x02
118 #define C2X2RGB_MONITOR_BE_STAT 0x04
119 #define C2X2RGB_MONITOR_SC_STAT 0x08
120 
125 #define C2X2RGB_LED_CURRENT_OFF 0
126 #define C2X2RGB_LED_CURRENT_3MA 3000
127 #define C2X2RGB_LED_CURRENT_MAX 24000
128 #define C2X2RGB_LED_CURRENT_STEP 125
129 
130 
135 #define C2X2RGB_EN_MODE_SHUTDOWN 0x00
136 #define C2X2RGB_EN_MODE_NIGHT 0x01
137 #define C2X2RGB_EN_MODE_NORMAL 0x02
138 #define C2X2RGB_EN_MODE_SW_RESET 0x03
139 #define C2X2RGB_EN_MODE_BIT_MASK 0xC0
140 #define C2X2RGB_BE_DISABLE 0x00
141 #define C2X2RGB_BE_ENABLE 0x01
142 #define C2X2RGB_BE_BIT_MASK 0x20
143 #define C2X2RGB_CE_TEMP_135C 0x00
144 #define C2X2RGB_CE_TEMP_120C 0x01
145 #define C2X2RGB_CE_TEMP_105C 0x02
146 #define C2X2RGB_CE_TEMP_90C 0x03
147 #define C2X2RGB_CE_TEMP_BIT_MASK 0x18
148 #define C2X2RGB_FADE_RATE0_32_MS 0x00
149 #define C2X2RGB_FADE_RATE0_63_MS 0x01
150 #define C2X2RGB_FADE_RATE0_125_MS 0x02
151 #define C2X2RGB_FADE_RATE0_250_MS 0x03
152 #define C2X2RGB_FADE_RATE0_500_MS 0x04
153 #define C2X2RGB_FADE_RATE0_1_S 0x05
154 #define C2X2RGB_FADE_RATE0_2_S 0x06
155 #define C2X2RGB_FADE_RATE0_4_S 0x07
156 #define C2X2RGB_FADE_RATE0_BIT_MASK 0x07
157 
162 #define C2X2RGB_PG_MODE_OFF 0x00
163 #define C2X2RGB_PG_MODE_4P_EN 0x01
164 #define C2X2RGB_PG_MODE_6P_EN 0x02
165 #define C2X2RGB_PG_MODE_8P_EN 0x03
166 #define C2X2RGB_PG_MODE_BIT_MASK 0xC0
167 #define C2X2RGB_PG_TIME_188_MS 0x00
168 #define C2X2RGB_PG_TIME_2_S 0x0F
169 #define C2X2RGB_PG_TIME_BIT_MASK 0x3C
170 
171 #define C2X2RGB_FADE_RATE1_32_MS 0x00
172 #define C2X2RGB_FADE_RATE1_4_S 0x07
173 #define C2X2RGB_FADE_RATE1_BIT_MASK 0x07
174 
175 
181 #define C2X2RGB_DEVICE_ADDRESS 0x74
182  // c2x2rgb_set
184 
199 #define C2X2RGB_MAP_MIKROBUS( cfg, mikrobus ) \
200  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
201  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
202  // c2x2rgb_map // c2x2rgb
205 
210 typedef struct
211 {
212 
213  // Modules
214  i2c_master_t i2c;
216  // I2C slave address
217  uint8_t slave_address;
219 } c2x2rgb_t;
220 
225 typedef struct
226 {
227  pin_name_t scl;
228  pin_name_t sda;
230  uint32_t i2c_speed;
231  uint8_t i2c_address;
233 } c2x2rgb_cfg_t;
234 
239 typedef struct
240 {
241  uint8_t en_mode;
242  uint16_t led1_ired;
243  uint16_t led1_igrn;
244  uint16_t led1_iblu;
245  uint16_t led2_ired;
246  uint16_t led2_igrn;
247  uint16_t led2_iblu;
248  uint16_t led3_ired;
249  uint16_t led3_igrn;
250  uint16_t led3_iblu;
251  uint16_t led4_ired;
252  uint16_t led4_igrn;
253  uint16_t led4_iblu;
256 
261 typedef enum
262 {
264  C2X2RGB_ERROR = -1
265 
267 
284 
298 err_t c2x2rgb_init ( c2x2rgb_t *ctx, c2x2rgb_cfg_t *cfg );
299 
313 
327 err_t c2x2rgb_generic_write ( c2x2rgb_t *ctx, uint8_t reg, uint8_t data_in );
328 
342 err_t c2x2rgb_generic_read ( c2x2rgb_t *ctx, uint8_t reg, uint8_t *data_out );
343 
357 err_t c2x2rgb_get_device_id ( c2x2rgb_t *ctx, uint8_t *vendor_id, uint8_t *device_id );
358 
373 err_t c2x2rgb_get_monitor_status ( c2x2rgb_t *ctx, uint8_t *sc_stat, uint8_t *be_stat,
374  uint8_t *cool_stat, uint8_t *uv_ot_stat );
375 
390 err_t c2x2rgb_set_control ( c2x2rgb_t *ctx, uint8_t en_mode, uint8_t be_en,
391  uint8_t ce_temp, uint8_t fade_rate );
392 
404 
416 
431 err_t c2x2rgb_set_rgb_led ( c2x2rgb_t *ctx, uint8_t led_num, uint16_t ired, uint16_t igrn, uint16_t iblu );
432 
446 
460 err_t c2x2rgb_set_pg_ctrl ( c2x2rgb_t *ctx, uint8_t pg_mode, uint8_t pg_time, uint8_t fade_rate );
461 
473 err_t c2x2rgb_set_pg_fade ( c2x2rgb_t *ctx, uint8_t pg_fade );
474 
487 err_t c2x2rgb_set_pg_rgb ( c2x2rgb_t *ctx, uint8_t led_num, uint8_t pg_rgb );
488 
500 err_t c2x2rgb_set_pg_wd ( c2x2rgb_t *ctx, uint8_t wd_pcr );
501 
502 #ifdef __cplusplus
503 }
504 #endif
505 #endif // C2X2RGB_H
506  // c2x2rgb
508 
509 // ------------------------------------------------------------------------ END
c2x2rgb_rgb_led_t::led3_ired
uint16_t led3_ired
Definition: c2x2rgb.h:248
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:263
c2x2rgb_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c2x2rgb.h:230
c2x2rgb_cfg_t::i2c_address
uint8_t i2c_address
Definition: c2x2rgb.h:231
c2x2rgb_rgb_led_t::led2_igrn
uint16_t led2_igrn
Definition: c2x2rgb.h:246
c2x2rgb_rgb_led_t::led4_iblu
uint16_t led4_iblu
Definition: c2x2rgb.h:253
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:249
c2x2rgb_cfg_t
2x2 RGB Click configuration object.
Definition: c2x2rgb.h:226
c2x2rgb_cfg_t::sda
pin_name_t sda
Definition: c2x2rgb.h:228
c2x2rgb_return_value_t
c2x2rgb_return_value_t
2x2 RGB Click return value data.
Definition: c2x2rgb.h:262
c2x2rgb_t
2x2 RGB Click context object.
Definition: c2x2rgb.h:211
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:217
c2x2rgb_rgb_led_t::en_mode
uint8_t en_mode
Definition: c2x2rgb.h:241
c2x2rgb_rgb_led_t::led1_igrn
uint16_t led1_igrn
Definition: c2x2rgb.h:243
c2x2rgb_rgb_led_t
2x2 RGB Click LED current setting object.
Definition: c2x2rgb.h:240
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:251
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:250
c2x2rgb_rgb_led_t::led2_ired
uint16_t led2_ired
Definition: c2x2rgb.h:245
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:252
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:227
c2x2rgb_t::i2c
i2c_master_t i2c
Definition: c2x2rgb.h:214
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:244
C2X2RGB_ERROR
@ C2X2RGB_ERROR
Definition: c2x2rgb.h:264
c2x2rgb_rgb_led_t::led1_ired
uint16_t led1_ired
Definition: c2x2rgb.h:242
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:247