leddriver14 2.0.0.0
leddriver14.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 LEDDRIVER14_H
29#define LEDDRIVER14_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#include "drv_pwm.h"
53
74#define LEDDRIVER14_RSET_1 0
75#define LEDDRIVER14_RSET_2 1
76#define LEDDRIVER14_RSET_3 2
77#define LEDDRIVER14_RSET_4 3
78
83#define LEDDRIVER14_DIGIPOT_MAX_VALUE 50000
84#define LEDDRIVER14_DIGIPOT_RESOLUTION 257
85#define LEDDRIVER14_ROUND_TO_NEAREST_INT 0.5
86#define LEDDRIVER14_RSET_RES_MAX 24000
87#define LEDDRIVER14_RSET_RES_DEFAULT 12000
88#define LEDDRIVER14_RSET1_AND_RSET3_ADDRESS 0x10
89
94#define LEDDRIVER14_WRITE_PROTECT_ENABLE 0
95#define LEDDRIVER14_WRITE_PROTECT_DISABLE 1
96
102#define LEDDRIVER14_U2_ADDR_A2_GND 0x28
103#define LEDDRIVER14_U2_ADDR_A2_VCC 0x2C
104#define LEDDRIVER14_U3_ADDR_A2_GND 0x29
105#define LEDDRIVER14_U3_ADDR_A2_VCC 0x2D
106
111#define LEDDRIVER14_DEF_FREQ 500
112
113 // leddriver14_set
114
129#define LEDDRIVER14_MAP_MIKROBUS( cfg, mikrobus ) \
130 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
131 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
132 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
133 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
134 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
135
136 // leddriver14_map
137 // leddriver14
138
143typedef struct
144{
145 // Output pins
146 digital_out_t wp;
148 // Input pins
149 digital_in_t int_pin;
151 // Modules
152 i2c_master_t i2c;
153 pwm_t pwm;
155 // I2C slave address
158 uint32_t pwm_freq;
161
166typedef struct
167{
168 pin_name_t scl;
169 pin_name_t sda;
171 pin_name_t wp;
172 pin_name_t pwm;
173 pin_name_t int_pin;
175 uint32_t i2c_speed;
178 uint32_t dev_pwm_freq;
181
192
209
225
240
254err_t leddriver14_set_rset ( leddriver14_t *ctx, uint8_t rset, uint16_t res_ohm );
255
267
278
291err_t leddriver14_set_duty_cycle ( leddriver14_t *ctx, float duty_cycle );
292
305
318
319#ifdef __cplusplus
320}
321#endif
322#endif // LEDDRIVER14_H
323
324 // leddriver14
325
326// ------------------------------------------------------------------------ END
err_t leddriver14_init(leddriver14_t *ctx, leddriver14_cfg_t *cfg)
LED Driver 14 initialization function.
void leddriver14_rset_write_protect(leddriver14_t *ctx, uint8_t state)
LED Driver 14 rset write protect function.
err_t leddriver14_pwm_start(leddriver14_t *ctx)
LED Driver 14 start PWM module.
err_t leddriver14_default_cfg(leddriver14_t *ctx)
LED Driver 14 default configuration function.
uint8_t leddriver14_get_int_pin(leddriver14_t *ctx)
LED Driver 14 get int pin function.
err_t leddriver14_set_duty_cycle(leddriver14_t *ctx, float duty_cycle)
LED Driver 14 sets PWM duty cycle.
err_t leddriver14_pwm_stop(leddriver14_t *ctx)
LED Driver 14 stop PWM module.
err_t leddriver14_set_rset(leddriver14_t *ctx, uint8_t rset, uint16_t res_ohm)
LED Driver 14 set rset function.
void leddriver14_cfg_setup(leddriver14_cfg_t *cfg)
LED Driver 14 configuration object setup function.
leddriver14_return_value_t
LED Driver 14 Click return value data.
Definition leddriver14.h:187
@ LEDDRIVER14_OK
Definition leddriver14.h:188
@ LEDDRIVER14_ERROR
Definition leddriver14.h:189
LED Driver 14 Click configuration object.
Definition leddriver14.h:167
uint8_t i2c_address_u3
Definition leddriver14.h:177
uint32_t i2c_speed
Definition leddriver14.h:175
uint8_t i2c_address_u2
Definition leddriver14.h:176
pin_name_t wp
Definition leddriver14.h:171
uint32_t dev_pwm_freq
Definition leddriver14.h:178
pin_name_t scl
Definition leddriver14.h:168
pin_name_t int_pin
Definition leddriver14.h:173
pin_name_t pwm
Definition leddriver14.h:172
pin_name_t sda
Definition leddriver14.h:169
LED Driver 14 Click context object.
Definition leddriver14.h:144
uint8_t slave_address_u2
Definition leddriver14.h:156
uint32_t pwm_freq
Definition leddriver14.h:158
digital_in_t int_pin
Definition leddriver14.h:149
i2c_master_t i2c
Definition leddriver14.h:152
uint8_t slave_address_u3
Definition leddriver14.h:157
pwm_t pwm
Definition leddriver14.h:153
digital_out_t wp
Definition leddriver14.h:146