leddriver9 2.0.0.0
leddriver9.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 LEDDRIVER9_H
29#define LEDDRIVER9_H
30
31#ifdef __cplusplus
32extern "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 LEDDRIVER9_REG_MODE1 0x00
74
79#define LEDDRIVER9_REG_MODE2 0x01
80
85#define LEDDRIVER9_REG_PWM0 0x02
86
91#define LEDDRIVER9_REG_PWM1 0x03
92
97#define LEDDRIVER9_REG_PWM2 0x04
98
103#define LEDDRIVER9_REG_PWM3 0x05
104
109#define LEDDRIVER9_REG_PWM4 0x06
110
115#define LEDDRIVER9_REG_PWM5 0x07
116
121#define LEDDRIVER9_REG_PWM6 0x08
122
127#define LEDDRIVER9_REG_PWM7 0x09
128
133#define LEDDRIVER9_REG_PWM8 0x0A
134
139#define LEDDRIVER9_REG_PWM9 0x0B
140
145#define LEDDRIVER9_REG_PWM10 0x0C
146
151#define LEDDRIVER9_REG_PWM11 0x0D
152
157#define LEDDRIVER9_REG_PWM12 0x0E
158
163#define LEDDRIVER9_REG_PWM13 0x0F
164
169#define LEDDRIVER9_REG_PWM14 0x10
170
175#define LEDDRIVER9_REG_PWM15 0x11
176
181#define LEDDRIVER9_REG_GRPPWM 0x12
182
187#define LEDDRIVER9_REG_GRPFREQ 0x13
188
193#define LEDDRIVER9_REG_LEDOUT0 0x14
194
199#define LEDDRIVER9_REG_LEDOUT1 0x15
200
205#define LEDDRIVER9_REG_LEDOUT2 0x16
206
211#define LEDDRIVER9_REG_LEDOUT3 0x17
212
217#define LEDDRIVER9_REG_SUBADR1 0x18
218
223#define LEDDRIVER9_REG_SUBADR2 0x19
224
229#define LEDDRIVER9_REG_SUBADR3 0x1A
230
235#define LEDDRIVER9_REG_ALLCALLADR 0x1B
236
241#define LEDDRIVER9_REG_IREF 0x1C
242
247#define LEDDRIVER9_REG_EFLAG1 0x1D
248
253#define LEDDRIVER9_REG_EFLAG2 0x1E
254
255 // leddriver9_reg
256
272#define LEDDRIVER9_SET_DEV_ADDR 0x60
273
274 // leddriver9_set
275
290#define LEDDRIVER9_MAP_MIKROBUS( cfg, mikrobus ) \
291 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
292 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
293 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
294
295 // leddriver9_map
296 // leddriver9
297
302typedef struct
303{
304 // Output pins
305
306 digital_out_t rst;
307
308 // Modules
309
310 i2c_master_t i2c;
312 // I2C slave address
313
317
322typedef struct
323{
324 pin_name_t scl;
325 pin_name_t sda;
327 pin_name_t rst;
329 uint32_t i2c_speed;
330 uint8_t i2c_address;
333
344
345
370
371
384
385
390typedef struct
391{
392 union
393 {
394 uint8_t byte;
395 struct
396 {
397 uint8_t ALLCALL : 1;
398 uint8_t SUB3 : 1;
399 uint8_t SUB2 : 1;
400 uint8_t SUB1 : 1;
401 uint8_t OSC : 1;
402 uint8_t AI0 : 1;
403 uint8_t AI1 : 1;
404 uint8_t AI2 : 1;
405 };
406 } mode_1;
407
408 union
409 {
410 uint8_t byte;
411 struct
412 {
413 uint8_t RES : 3;
414 uint8_t OCH : 1;
415 uint8_t RES1 : 1;
416 uint8_t DMBLNK : 1;
417 uint8_t RES2 : 1;
418 uint8_t EFCLR : 1;
419 };
420 } mode_2;
421
423
428typedef struct
429{
430 union
431 {
432 uint8_t byte;
433 struct
434 {
435 uint8_t LDR0 : 2;
436 uint8_t LDR1 : 2;
437 uint8_t LDR2 : 2;
438 uint8_t LDR3 : 2;
439 };
440 } LEDOUT0;
441
442 union
443 {
444 uint8_t byte;
445 struct
446 {
447 uint8_t LDR4 : 2;
448 uint8_t LDR5 : 2;
449 uint8_t LDR6 : 2;
450 uint8_t LDR7 : 2;
451 };
452 } LEDOUT1;
453
454 union
455 {
456 uint8_t byte;
457 struct
458 {
459 uint8_t LDR8 : 2;
460 uint8_t LDR9 : 2;
461 uint8_t LDR10 : 2;
462 uint8_t LDR11 : 2;
463 };
464 } LEDOUT2;
465
466 union
467 {
468 uint8_t byte;
469 struct
470 {
471 uint8_t LDR12 : 2;
472 uint8_t LDR13 : 2;
473 uint8_t LDR14 : 2;
474 uint8_t LDR15 : 2;
475 };
476 } LEDOUT3;
477
479
498
516
530
548err_t leddriver9_generic_write ( leddriver9_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
549
567err_t leddriver9_generic_read ( leddriver9_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
568
585
602
619
636
653
669err_t leddriver9_set_pwm ( leddriver9_t *ctx, leddriver9_channel_sel_t ch_out, float duty_cycle );
670
687err_t leddriver9_set_dimmer_pwm ( leddriver9_t *ctx, float duty_cycle );
688
705err_t leddriver9_set_blink_period ( leddriver9_t *ctx, float period );
706
718
719#ifdef __cplusplus
720}
721#endif
722#endif // LEDDRIVER9_H
723
724 // leddriver9
725
726// ------------------------------------------------------------------------ END
err_t leddriver9_ledout_state(leddriver9_t *ctx, leddriver9_output_state_t *output_state)
LED Driver 9 LEDOUT state function.
err_t leddriver9_set_pwm(leddriver9_t *ctx, leddriver9_channel_sel_t ch_out, float duty_cycle)
LED Driver 9 set PWM function.
err_t leddriver9_set_dimmer_pwm(leddriver9_t *ctx, float duty_cycle)
LED Driver 9 set dimmer PWM function.
void leddriver9_cfg_setup(leddriver9_cfg_t *cfg)
LED Driver 9 configuration object setup function.
err_t leddriver9_init(leddriver9_t *ctx, leddriver9_cfg_t *cfg)
LED Driver 9 initialization function.
err_t leddriver9_mode1_reg_read(leddriver9_t *ctx, leddriver9_mode_reg_t *mode_reg)
LED Driver 9 MODE1 reg read function.
err_t leddriver9_mode1_reg_write(leddriver9_t *ctx, leddriver9_mode_reg_t *mode_reg)
LED Driver 9 MODE1 reg write function.
err_t leddriver9_mode2_reg_write(leddriver9_t *ctx, leddriver9_mode_reg_t *mode_reg)
LED Driver 9 MODE2 reg write function.
err_t leddriver9_generic_read(leddriver9_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
LED Driver 9 I2C reading function.
err_t leddriver9_mode2_reg_read(leddriver9_t *ctx, leddriver9_mode_reg_t *mode_reg)
LED Driver 9 MODE2 reg read function.
err_t leddriver9_set_blink_period(leddriver9_t *ctx, float period)
LED Driver 9 set blink period function.
void leddriver9_hardware_reset(leddriver9_t *ctx)
LED Driver 9 hardware reset function.
void leddriver9_default_cfg(leddriver9_t *ctx)
LED Driver 9 default configuration function.
err_t leddriver9_generic_write(leddriver9_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
LED Driver 9 I2C writing function.
leddriver9_channel_sel_t
LED Driver 9 Click channel select options.
Definition leddriver9.h:351
@ LEDDRIVER9_CHANNEL11
Definition leddriver9.h:363
@ LEDDRIVER9_CHANNEL15
Definition leddriver9.h:367
@ LEDDRIVER9_CHANNEL12
Definition leddriver9.h:364
@ LEDDRIVER9_CHANNEL6
Definition leddriver9.h:358
@ LEDDRIVER9_CHANNEL3
Definition leddriver9.h:355
@ LEDDRIVER9_CHANNEL14
Definition leddriver9.h:366
@ LEDDRIVER9_CHANNEL7
Definition leddriver9.h:359
@ LEDDRIVER9_CHANNEL0
Definition leddriver9.h:352
@ LEDDRIVER9_CHANNEL1
Definition leddriver9.h:353
@ LEDDRIVER9_CHANNEL2
Definition leddriver9.h:354
@ LEDDRIVER9_CHANNEL8
Definition leddriver9.h:360
@ LEDDRIVER9_CHANNEL9
Definition leddriver9.h:361
@ LEDDRIVER9_CHANNEL10
Definition leddriver9.h:362
@ LEDDRIVER9_CHANNEL5
Definition leddriver9.h:357
@ LEDDRIVER9_CHANNEL13
Definition leddriver9.h:365
@ LEDDRIVER9_CHANNEL4
Definition leddriver9.h:356
leddriver9_return_value_t
LED Driver 9 Click return value data.
Definition leddriver9.h:339
@ LEDDRIVER9_ERROR
Definition leddriver9.h:341
@ LEDDRIVER9_OK
Definition leddriver9.h:340
leddriver9_ledout_sel_t
LED Driver 9 Click ledout select options.
Definition leddriver9.h:377
@ LEDDRIVER9_OFF
Definition leddriver9.h:378
@ LEDDRIVER9_INDIVIDUAL
Definition leddriver9.h:380
@ LEDDRIVER9_GROUP
Definition leddriver9.h:381
@ LEDDRIVER9_FULL_ON
Definition leddriver9.h:379
LED Driver 9 Click configuration object.
Definition leddriver9.h:323
uint32_t i2c_speed
Definition leddriver9.h:329
pin_name_t scl
Definition leddriver9.h:324
pin_name_t sda
Definition leddriver9.h:325
pin_name_t rst
Definition leddriver9.h:327
uint8_t i2c_address
Definition leddriver9.h:330
LED Driver 9 Click mode registers.
Definition leddriver9.h:391
uint8_t EFCLR
Definition leddriver9.h:418
uint8_t ALLCALL
Definition leddriver9.h:397
uint8_t AI1
Definition leddriver9.h:403
uint8_t OCH
Definition leddriver9.h:414
uint8_t AI2
Definition leddriver9.h:404
uint8_t DMBLNK
Definition leddriver9.h:416
uint8_t RES2
Definition leddriver9.h:417
uint8_t RES1
Definition leddriver9.h:415
uint8_t byte
Definition leddriver9.h:394
uint8_t OSC
Definition leddriver9.h:401
uint8_t SUB1
Definition leddriver9.h:400
uint8_t RES
Definition leddriver9.h:413
uint8_t AI0
Definition leddriver9.h:402
uint8_t SUB3
Definition leddriver9.h:398
uint8_t SUB2
Definition leddriver9.h:399
LED Driver 9 Click LED output state registers.
Definition leddriver9.h:429
uint8_t LDR8
Definition leddriver9.h:459
uint8_t LDR11
Definition leddriver9.h:462
uint8_t LDR15
Definition leddriver9.h:474
uint8_t LDR5
Definition leddriver9.h:448
uint8_t LDR4
Definition leddriver9.h:447
uint8_t LDR10
Definition leddriver9.h:461
uint8_t byte
Definition leddriver9.h:432
uint8_t LDR12
Definition leddriver9.h:471
uint8_t LDR6
Definition leddriver9.h:449
uint8_t LDR9
Definition leddriver9.h:460
uint8_t LDR0
Definition leddriver9.h:435
uint8_t LDR7
Definition leddriver9.h:450
uint8_t LDR14
Definition leddriver9.h:473
uint8_t LDR3
Definition leddriver9.h:438
uint8_t LDR1
Definition leddriver9.h:436
uint8_t LDR2
Definition leddriver9.h:437
uint8_t LDR13
Definition leddriver9.h:472
LED Driver 9 Click context object.
Definition leddriver9.h:303
i2c_master_t i2c
Definition leddriver9.h:310
digital_out_t rst
Definition leddriver9.h:306
uint8_t slave_address
Definition leddriver9.h:314