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 
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_i2c_master.h"
52 
73 #define C2X2RGB_REG_ID 0x00
74 #define C2X2RGB_REG_MONITOR 0x01
75 #define C2X2RGB_REG_CONTROL 0x02
76 #define C2X2RGB_REG_IRED1 0x03
77 #define C2X2RGB_REG_IGRN1 0x04
78 #define C2X2RGB_REG_IBLU1 0x05
79 #define C2X2RGB_REG_IRED2 0x06
80 #define C2X2RGB_REG_IGRN2 0x07
81 #define C2X2RGB_REG_IBLU2 0x08
82 #define C2X2RGB_REG_IRED3 0x09
83 #define C2X2RGB_REG_IGRN3 0x0A
84 #define C2X2RGB_REG_IBLU3 0x0B
85 #define C2X2RGB_REG_IRED4 0x0C
86 #define C2X2RGB_REG_IGRN4 0x0D
87 #define C2X2RGB_REG_IBLU4 0x0E
88 #define C2X2RGB_REG_PG_CNTL 0x0F
89 #define C2X2RGB_REG_PG_FADE 0x10
90 #define C2X2RGB_REG_PG_RGB1 0x11
91 #define C2X2RGB_REG_PG_RGB2 0x12
92 #define C2X2RGB_REG_PG_RGB3 0x13
93 #define C2X2RGB_REG_PG_RGB4 0x14
94 #define C2X2RGB_REG_PG_WD 0x15
95  // c2x2rgb_reg
97 
112 #define C2X2RGB_SET_LD1 1
113 #define C2X2RGB_SET_LD2 2
114 #define C2X2RGB_SET_LD3 3
115 #define C2X2RGB_SET_LD4 4
116 
121 #define C2X2RGB_DEV_ID 0x06
122 #define C2X2RGB_DEV_ID_BIT_MASK 0x0F
123 #define C2X2RGB_VEN_ID 0x05
124 #define C2X2RGB_VEN_ID_BIT_MASK 0x07
125 
130 #define C2X2RGB_MONITOR_UV_OT_STAT 0x01
131 #define C2X2RGB_MONITOR_COOL_STAT 0x02
132 #define C2X2RGB_MONITOR_BE_STAT 0x04
133 #define C2X2RGB_MONITOR_SC_STAT 0x08
134 
139 #define C2X2RGB_LED_CURRENT_OFF 0
140 #define C2X2RGB_LED_CURRENT_3MA 3000
141 #define C2X2RGB_LED_CURRENT_MAX 24000
142 #define C2X2RGB_LED_CURRENT_STEP 125
143 
144 
149 #define C2X2RGB_EN_MODE_SHUTDOWN 0x00
150 #define C2X2RGB_EN_MODE_NIGHT 0x01
151 #define C2X2RGB_EN_MODE_NORMAL 0x02
152 #define C2X2RGB_EN_MODE_SW_RESET 0x03
153 #define C2X2RGB_EN_MODE_BIT_MASK 0xC0
154 #define C2X2RGB_BE_DISABLE 0x00
155 #define C2X2RGB_BE_ENABLE 0x01
156 #define C2X2RGB_BE_BIT_MASK 0x20
157 #define C2X2RGB_CE_TEMP_135C 0x00
158 #define C2X2RGB_CE_TEMP_120C 0x01
159 #define C2X2RGB_CE_TEMP_105C 0x02
160 #define C2X2RGB_CE_TEMP_90C 0x03
161 #define C2X2RGB_CE_TEMP_BIT_MASK 0x18
162 #define C2X2RGB_FADE_RATE0_32_MS 0x00
163 #define C2X2RGB_FADE_RATE0_63_MS 0x01
164 #define C2X2RGB_FADE_RATE0_125_MS 0x02
165 #define C2X2RGB_FADE_RATE0_250_MS 0x03
166 #define C2X2RGB_FADE_RATE0_500_MS 0x04
167 #define C2X2RGB_FADE_RATE0_1_S 0x05
168 #define C2X2RGB_FADE_RATE0_2_S 0x06
169 #define C2X2RGB_FADE_RATE0_4_S 0x07
170 #define C2X2RGB_FADE_RATE0_BIT_MASK 0x07
171 
176 #define C2X2RGB_PG_MODE_OFF 0x00
177 #define C2X2RGB_PG_MODE_4P_EN 0x01
178 #define C2X2RGB_PG_MODE_6P_EN 0x02
179 #define C2X2RGB_PG_MODE_8P_EN 0x03
180 #define C2X2RGB_PG_MODE_BIT_MASK 0xC0
181 #define C2X2RGB_PG_TIME_188_MS 0x00
182 #define C2X2RGB_PG_TIME_2_S 0x0F
183 #define C2X2RGB_PG_TIME_BIT_MASK 0x3C
184 
185 #define C2X2RGB_FADE_RATE1_32_MS 0x00
186 #define C2X2RGB_FADE_RATE1_4_S 0x07
187 #define C2X2RGB_FADE_RATE1_BIT_MASK 0x07
188 
189 
195 #define C2X2RGB_DEVICE_ADDRESS 0x74
196  // c2x2rgb_set
198 
213 #define C2X2RGB_MAP_MIKROBUS( cfg, mikrobus ) \
214  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
215  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
216  // c2x2rgb_map // c2x2rgb
219 
224 typedef struct
225 {
226 
227  // Modules
228  i2c_master_t i2c;
230  // I2C slave address
231  uint8_t slave_address;
233 } c2x2rgb_t;
234 
239 typedef struct
240 {
241  pin_name_t scl;
242  pin_name_t sda;
244  uint32_t i2c_speed;
245  uint8_t i2c_address;
247 } c2x2rgb_cfg_t;
248 
253 typedef struct
254 {
255  uint8_t en_mode;
256  uint16_t led1_ired;
257  uint16_t led1_igrn;
258  uint16_t led1_iblu;
259  uint16_t led2_ired;
260  uint16_t led2_igrn;
261  uint16_t led2_iblu;
262  uint16_t led3_ired;
263  uint16_t led3_igrn;
264  uint16_t led3_iblu;
265  uint16_t led4_ired;
266  uint16_t led4_igrn;
267  uint16_t led4_iblu;
270 
275 typedef enum
276 {
278  C2X2RGB_ERROR = -1
279 
281 
298 
312 err_t c2x2rgb_init ( c2x2rgb_t *ctx, c2x2rgb_cfg_t *cfg );
313 
327 
341 err_t c2x2rgb_generic_write ( c2x2rgb_t *ctx, uint8_t reg, uint8_t data_in );
342 
356 err_t c2x2rgb_generic_read ( c2x2rgb_t *ctx, uint8_t reg, uint8_t *data_out );
357 
371 err_t c2x2rgb_get_device_id ( c2x2rgb_t *ctx, uint8_t *vendor_id, uint8_t *device_id );
372 
387 err_t c2x2rgb_get_monitor_status ( c2x2rgb_t *ctx, uint8_t *sc_stat, uint8_t *be_stat,
388  uint8_t *cool_stat, uint8_t *uv_ot_stat );
389 
404 err_t c2x2rgb_set_control ( c2x2rgb_t *ctx, uint8_t en_mode, uint8_t be_en,
405  uint8_t ce_temp, uint8_t fade_rate );
406 
418 
430 
445 err_t c2x2rgb_set_rgb_led ( c2x2rgb_t *ctx, uint8_t led_num, uint16_t ired, uint16_t igrn, uint16_t iblu );
446 
460 
474 err_t c2x2rgb_set_pg_ctrl ( c2x2rgb_t *ctx, uint8_t pg_mode, uint8_t pg_time, uint8_t fade_rate );
475 
487 err_t c2x2rgb_set_pg_fade ( c2x2rgb_t *ctx, uint8_t pg_fade );
488 
501 err_t c2x2rgb_set_pg_rgb ( c2x2rgb_t *ctx, uint8_t led_num, uint8_t pg_rgb );
502 
514 err_t c2x2rgb_set_pg_wd ( c2x2rgb_t *ctx, uint8_t wd_pcr );
515 
516 #ifdef __cplusplus
517 }
518 #endif
519 #endif // C2X2RGB_H
520  // c2x2rgb
522 
523 // ------------------------------------------------------------------------ END
c2x2rgb_rgb_led_t::led3_ired
uint16_t led3_ired
Definition: c2x2rgb.h:262
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:277
c2x2rgb_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c2x2rgb.h:244
c2x2rgb_cfg_t::i2c_address
uint8_t i2c_address
Definition: c2x2rgb.h:245
c2x2rgb_rgb_led_t::led2_igrn
uint16_t led2_igrn
Definition: c2x2rgb.h:260
c2x2rgb_rgb_led_t::led4_iblu
uint16_t led4_iblu
Definition: c2x2rgb.h:267
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:263
c2x2rgb_cfg_t
2x2 RGB Click configuration object.
Definition: c2x2rgb.h:240
c2x2rgb_cfg_t::sda
pin_name_t sda
Definition: c2x2rgb.h:242
c2x2rgb_return_value_t
c2x2rgb_return_value_t
2x2 RGB Click return value data.
Definition: c2x2rgb.h:276
c2x2rgb_t
2x2 RGB Click context object.
Definition: c2x2rgb.h:225
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:231
c2x2rgb_rgb_led_t::en_mode
uint8_t en_mode
Definition: c2x2rgb.h:255
c2x2rgb_rgb_led_t::led1_igrn
uint16_t led1_igrn
Definition: c2x2rgb.h:257
c2x2rgb_rgb_led_t
2x2 RGB Click LED current setting object.
Definition: c2x2rgb.h:254
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:265
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:264
c2x2rgb_rgb_led_t::led2_ired
uint16_t led2_ired
Definition: c2x2rgb.h:259
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:266
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:241
c2x2rgb_t::i2c
i2c_master_t i2c
Definition: c2x2rgb.h:228
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:258
C2X2RGB_ERROR
@ C2X2RGB_ERROR
Definition: c2x2rgb.h:278
c2x2rgb_rgb_led_t::led1_ired
uint16_t led1_ired
Definition: c2x2rgb.h:256
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:261