leddriver18 2.1.0.0
leddriver18.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 LEDDRIVER18_H
29#define LEDDRIVER18_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 LEDDRIVER18_WRITE_TO_RDAC 0x00
74#define LEDDRIVER18_ONE_TIME_PROG 0x80
75
76 // leddriver18_reg
77
92#define LEDDRIVER18_PWM_MAX_VALUE 0x0FFF
93#define LEDDRIVER18_MAX_OUTPUT_NUM 24
94#define LEDDRIVER18_MAX_RES_BITS 12
95#define LEDDRIVER18_CC_MASK 0x3F
96#define LEDDRIVER18_CC_ERROR 0x80
97
102#define LEDDRIVER18_CURRENT_30_mA 0x00
103#define LEDDRIVER18_CURRENT_20_mA 0x01
104#define LEDDRIVER18_CURRENT_15_mA 0x02
105#define LEDDRIVER18_CURRENT_10_mA 0x04
106#define LEDDRIVER18_CURRENT_5_mA 0x0B
107#define LEDDRIVER18_CURRENT_2_mA 0x1E
108
114#define LEDDRIVER18_DEVICE_ADDRESS 0x2C
115
116 // leddriver18_set
117
132#define LEDDRIVER18_MAP_MIKROBUS( cfg, mikrobus ) \
133 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
134 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
135 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
136 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
137 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
138 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
139 cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM )
140
141 // leddriver18_map
142 // leddriver18
143
148typedef struct
149{
150 // Output pins
151 digital_out_t cs;
152 digital_out_t sck;
153 digital_out_t mosi;
154 digital_out_t rst;
155 digital_out_t en;
157 // Modules
158 i2c_master_t i2c;
160 // I2C slave address
164
169typedef struct
170{
171 pin_name_t scl;
172 pin_name_t sda;
174 pin_name_t cs;
175 pin_name_t sck;
176 pin_name_t mosi;
177 pin_name_t rst;
178 pin_name_t en;
180 uint32_t i2c_speed;
181 uint8_t i2c_address;
184
195
212
227
241
256err_t leddriver18_generic_write ( leddriver18_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
257
272err_t leddriver18_generic_read ( leddriver18_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
273
286err_t leddriver18_set_output_pwm ( uint8_t out_num, float pwm_val );
287
296float leddriver18_get_output_pwm ( uint8_t out_num );
297
308
319
330
343err_t leddriver18_set_cc_output ( leddriver18_t *ctx, uint8_t current_limit );
344
357err_t leddriver18_get_cc_output ( leddriver18_t *ctx, uint8_t *current_limit );
358
359#ifdef __cplusplus
360}
361#endif
362#endif // LEDDRIVER18_H
363
364 // leddriver18
365
366// ------------------------------------------------------------------------ END
err_t leddriver18_generic_read(leddriver18_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
LED Driver 18 I2C reading function.
err_t leddriver18_default_cfg(leddriver18_t *ctx)
LED Driver 18 default configuration function.
void leddriver18_disable_output(leddriver18_t *ctx)
LED Driver 18 disable output function.
err_t leddriver18_set_output_pwm(uint8_t out_num, float pwm_val)
LED Driver 18 set output channel PWM value function.
err_t leddriver18_init(leddriver18_t *ctx, leddriver18_cfg_t *cfg)
LED Driver 18 initialization function.
void leddriver18_enable_output(leddriver18_t *ctx)
LED Driver 18 enable output function.
err_t leddriver18_set_cc_output(leddriver18_t *ctx, uint8_t current_limit)
LED Driver 18 set constant current output function.
void leddriver18_cfg_setup(leddriver18_cfg_t *cfg)
LED Driver 18 configuration object setup function.
void leddriver18_write_config(leddriver18_t *ctx)
LED Driver 18 write config function.
err_t leddriver18_get_cc_output(leddriver18_t *ctx, uint8_t *current_limit)
LED Driver 18 get constant current output function.
err_t leddriver18_generic_write(leddriver18_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
LED Driver 18 I2C writing function.
float leddriver18_get_output_pwm(uint8_t out_num)
LED Driver 18 get output channel PWM value function.
leddriver18_return_value_t
LED Driver 18 Click return value data.
Definition leddriver18.h:190
@ LEDDRIVER18_OK
Definition leddriver18.h:191
@ LEDDRIVER18_ERROR
Definition leddriver18.h:192
LED Driver 18 Click configuration object.
Definition leddriver18.h:170
uint32_t i2c_speed
Definition leddriver18.h:180
pin_name_t sck
Definition leddriver18.h:175
pin_name_t mosi
Definition leddriver18.h:176
pin_name_t scl
Definition leddriver18.h:171
pin_name_t en
Definition leddriver18.h:178
pin_name_t sda
Definition leddriver18.h:172
pin_name_t rst
Definition leddriver18.h:177
pin_name_t cs
Definition leddriver18.h:174
uint8_t i2c_address
Definition leddriver18.h:181
LED Driver 18 Click context object.
Definition leddriver18.h:149
digital_out_t cs
Definition leddriver18.h:151
digital_out_t sck
Definition leddriver18.h:152
digital_out_t mosi
Definition leddriver18.h:153
i2c_master_t i2c
Definition leddriver18.h:158
digital_out_t en
Definition leddriver18.h:155
digital_out_t rst
Definition leddriver18.h:154
uint8_t slave_address
Definition leddriver18.h:161