leddriver12 2.0.0.0
leddriver12.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 LEDDRIVER12_H
29#define LEDDRIVER12_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 LEDDRIVER12_REG_INPUT0 0x00
74#define LEDDRIVER12_REG_INPUT1 0x01
75#define LEDDRIVER12_REG_PSC0 0x02
76#define LEDDRIVER12_REG_PWM0 0x03
77#define LEDDRIVER12_REG_PSC1 0x04
78#define LEDDRIVER12_REG_PWM1 0x05
79#define LEDDRIVER12_REG_LS0 0x06
80#define LEDDRIVER12_REG_LS1 0x07
81#define LEDDRIVER12_REG_LS2 0x08
82#define LEDDRIVER12_REG_LS3 0x09
83
84 // leddriver12_reg
85
100#define LEDDRIVER12_AUTO_INCREMENT_BIT 0x10
101
106#define LEDDRIVER12_LED_OFF 0x00
107#define LEDDRIVER12_LED_ON 0x01
108#define LEDDRIVER12_LED_PWM0 0x02
109#define LEDDRIVER12_LED_PWM1 0x03
110#define LEDDRIVER12_LED0 0x00
111#define LEDDRIVER12_LED1 0x01
112#define LEDDRIVER12_LED2 0x02
113#define LEDDRIVER12_LED3 0x03
114#define LEDDRIVER12_LED4 0x04
115#define LEDDRIVER12_LED5 0x05
116#define LEDDRIVER12_LED6 0x06
117#define LEDDRIVER12_LED7 0x07
118#define LEDDRIVER12_LED8 0x08
119#define LEDDRIVER12_LED9 0x09
120#define LEDDRIVER12_LED10 0x0A
121#define LEDDRIVER12_LED11 0x0B
122#define LEDDRIVER12_LED12 0x0C
123#define LEDDRIVER12_LED13 0x0D
124#define LEDDRIVER12_LED14 0x0E
125#define LEDDRIVER12_LED15 0x0F
126#define LEDDRIVER12_LED0_TO_3 0x00
127#define LEDDRIVER12_LED4_TO_7 0x01
128#define LEDDRIVER12_LED8_TO_11 0x02
129#define LEDDRIVER12_LED12_TO_15 0x03
130#define LEDDRIVER12_ALL_LEDS 0xFF
131
136#define LEDDRIVER12_BLINK_PERIOD_MAX 1.68421
137#define LEDDRIVER12_BLINK_PERIOD_MIN 0.00657
138#define LEDDRIVER12_BLINK_PERIOD_ONE_SECOND 1.0
139#define LEDDRIVER12_BLINK_PERIOD_HALF_SECOND 0.5
140#define LEDDRIVER12_DUTY_CYCLE_MAX 0xFF
141#define LEDDRIVER12_DUTY_CYCLE_HALF 0x80
142#define LEDDRIVER12_DUTY_CYCLE_QUARTER 0x40
143#define LEDDRIVER12_DUTY_CYCLE_MIN 0x00
144
150#define LEDDRIVER12_DEV_ADDR_A2A1A0_000 0x60
151#define LEDDRIVER12_DEV_ADDR_A2A1A0_001 0x61
152#define LEDDRIVER12_DEV_ADDR_A2A1A0_010 0x62
153#define LEDDRIVER12_DEV_ADDR_A2A1A0_011 0x63
154#define LEDDRIVER12_DEV_ADDR_A2A1A0_100 0x64
155#define LEDDRIVER12_DEV_ADDR_A2A1A0_101 0x65
156#define LEDDRIVER12_DEV_ADDR_A2A1A0_110 0x66
157#define LEDDRIVER12_DEV_ADDR_A2A1A0_111 0x67
158
159 // leddriver12_set
160
175#define LEDDRIVER12_MAP_MIKROBUS( cfg, mikrobus ) \
176 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
177 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
178 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
179
180 // leddriver12_map
181 // leddriver12
182
187typedef struct
188{
189 // Output pins
190 digital_out_t rst;
192 // Modules
193 i2c_master_t i2c;
195 // I2C slave address
199
204typedef struct
205{
206 pin_name_t scl;
207 pin_name_t sda;
209 pin_name_t rst;
211 uint32_t i2c_speed;
212 uint8_t i2c_address;
215
226
243
259
274
290err_t leddriver12_generic_write ( leddriver12_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
291
307err_t leddriver12_generic_read ( leddriver12_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
308
322err_t leddriver12_write_register ( leddriver12_t *ctx, uint8_t reg, uint8_t data_in );
323
337err_t leddriver12_read_register ( leddriver12_t *ctx, uint8_t reg, uint8_t *data_out );
338
348void leddriver12_set_rst_pin ( leddriver12_t *ctx, uint8_t state );
349
366err_t leddriver12_set_led_config ( leddriver12_t *ctx, uint8_t led_number, uint8_t led_cfg );
367
387err_t leddriver12_set_led_port_config ( leddriver12_t *ctx, uint8_t led_port_number, uint8_t led_cfg );
388
401err_t leddriver12_read_input_0 ( leddriver12_t *ctx, uint8_t *data_out );
402
415err_t leddriver12_read_input_1 ( leddriver12_t *ctx, uint8_t *data_out );
416
429err_t leddriver12_set_blink_period_pwm_0 ( leddriver12_t *ctx, float blink_period );
430
443err_t leddriver12_set_blink_period_pwm_1 ( leddriver12_t *ctx, float blink_period );
444
457err_t leddriver12_set_duty_cycle_pwm_0 ( leddriver12_t *ctx, uint8_t duty_cycle );
458
471err_t leddriver12_set_duty_cycle_pwm_1 ( leddriver12_t *ctx, uint8_t duty_cycle );
472
473#ifdef __cplusplus
474}
475#endif
476#endif // LEDDRIVER12_H
477
478 // leddriver12
479
480// ------------------------------------------------------------------------ END
err_t leddriver12_generic_write(leddriver12_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
LED Driver 12 I2C writing function.
err_t leddriver12_set_duty_cycle_pwm_1(leddriver12_t *ctx, uint8_t duty_cycle)
LED Driver 12 set duty cycle pwm 1 function.
err_t leddriver12_generic_read(leddriver12_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
LED Driver 12 I2C reading function.
err_t leddriver12_read_input_1(leddriver12_t *ctx, uint8_t *data_out)
LED Driver 12 read input 1 function.
void leddriver12_set_rst_pin(leddriver12_t *ctx, uint8_t state)
LED Driver 12 set rst pin function.
err_t leddriver12_set_blink_period_pwm_0(leddriver12_t *ctx, float blink_period)
LED Driver 12 set blink period pwm 0 function.
err_t leddriver12_set_led_port_config(leddriver12_t *ctx, uint8_t led_port_number, uint8_t led_cfg)
LED Driver 12 set led port config function.
err_t leddriver12_write_register(leddriver12_t *ctx, uint8_t reg, uint8_t data_in)
LED Driver 12 write register function.
err_t leddriver12_set_led_config(leddriver12_t *ctx, uint8_t led_number, uint8_t led_cfg)
LED Driver 12 set led config function.
err_t leddriver12_default_cfg(leddriver12_t *ctx)
LED Driver 12 default configuration function.
void leddriver12_cfg_setup(leddriver12_cfg_t *cfg)
LED Driver 12 configuration object setup function.
err_t leddriver12_read_input_0(leddriver12_t *ctx, uint8_t *data_out)
LED Driver 12 read input 0 function.
err_t leddriver12_set_blink_period_pwm_1(leddriver12_t *ctx, float blink_period)
LED Driver 12 set blink period pwm 1 function.
err_t leddriver12_read_register(leddriver12_t *ctx, uint8_t reg, uint8_t *data_out)
LED Driver 12 read register function.
err_t leddriver12_init(leddriver12_t *ctx, leddriver12_cfg_t *cfg)
LED Driver 12 initialization function.
err_t leddriver12_set_duty_cycle_pwm_0(leddriver12_t *ctx, uint8_t duty_cycle)
LED Driver 12 set duty cycle pwm 0 function.
leddriver12_return_value_t
LED Driver 12 Click return value data.
Definition leddriver12.h:221
@ LEDDRIVER12_ERROR
Definition leddriver12.h:223
@ LEDDRIVER12_OK
Definition leddriver12.h:222
LED Driver 12 Click configuration object.
Definition leddriver12.h:205
uint32_t i2c_speed
Definition leddriver12.h:211
pin_name_t scl
Definition leddriver12.h:206
pin_name_t sda
Definition leddriver12.h:207
pin_name_t rst
Definition leddriver12.h:209
uint8_t i2c_address
Definition leddriver12.h:212
LED Driver 12 Click context object.
Definition leddriver12.h:188
i2c_master_t i2c
Definition leddriver12.h:193
digital_out_t rst
Definition leddriver12.h:190
uint8_t slave_address
Definition leddriver12.h:196