leddriver16 2.1.0.0
leddriver16.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 LEDDRIVER16_H
29#define LEDDRIVER16_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_spi_master.h"
52#include "spi_specifics.h"
53
74#define LEDDRIVER16_REG_MODE1 0x00
75#define LEDDRIVER16_REG_MODE2 0x01
76#define LEDDRIVER16_REG_LEDOUT0 0x02
77#define LEDDRIVER16_REG_LEDOUT1 0x03
78#define LEDDRIVER16_REG_LEDOUT2 0x04
79#define LEDDRIVER16_REG_LEDOUT3 0x05
80#define LEDDRIVER16_REG_GRPPWM 0x06
81#define LEDDRIVER16_REG_GRPFREQ 0x07
82#define LEDDRIVER16_REG_PWM0 0x08
83#define LEDDRIVER16_REG_PWM1 0x09
84#define LEDDRIVER16_REG_PWM2 0x0A
85#define LEDDRIVER16_REG_PWM3 0x0B
86#define LEDDRIVER16_REG_PWM4 0x0C
87#define LEDDRIVER16_REG_PWM5 0x0D
88#define LEDDRIVER16_REG_PWM6 0x0E
89#define LEDDRIVER16_REG_PWM7 0x0F
90#define LEDDRIVER16_REG_PWM8 0x10
91#define LEDDRIVER16_REG_PWM9 0x11
92#define LEDDRIVER16_REG_PWM10 0x12
93#define LEDDRIVER16_REG_PWM11 0x13
94#define LEDDRIVER16_REG_PWM12 0x14
95#define LEDDRIVER16_REG_PWM13 0x15
96#define LEDDRIVER16_REG_PWM14 0x16
97#define LEDDRIVER16_REG_PWM15 0x17
98#define LEDDRIVER16_REG_IREF0 0x18
99#define LEDDRIVER16_REG_IREF1 0x19
100#define LEDDRIVER16_REG_IREF2 0x1A
101#define LEDDRIVER16_REG_IREF3 0x1B
102#define LEDDRIVER16_REG_IREF4 0x1C
103#define LEDDRIVER16_REG_IREF5 0x1D
104#define LEDDRIVER16_REG_IREF6 0x1E
105#define LEDDRIVER16_REG_IREF7 0x1F
106#define LEDDRIVER16_REG_IREF8 0x20
107#define LEDDRIVER16_REG_IREF9 0x21
108#define LEDDRIVER16_REG_IREF10 0x22
109#define LEDDRIVER16_REG_IREF11 0x23
110#define LEDDRIVER16_REG_IREF12 0x24
111#define LEDDRIVER16_REG_IREF13 0x25
112#define LEDDRIVER16_REG_IREF14 0x26
113#define LEDDRIVER16_REG_IREF15 0x27
114#define LEDDRIVER16_REG_RAMP_RATE_GRP0 0x28
115#define LEDDRIVER16_REG_STEP_TIME_GRP0 0x29
116#define LEDDRIVER16_REG_HOLD_CNTL_GRP0 0x2A
117#define LEDDRIVER16_REG_IREF_GRP0 0x2B
118#define LEDDRIVER16_REG_RAMP_RATE_GRP1 0x2C
119#define LEDDRIVER16_REG_STEP_TIME_GRP1 0x2D
120#define LEDDRIVER16_REG_HOLD_CNTL_GRP1 0x2E
121#define LEDDRIVER16_REG_IREF_GRP1 0x2F
122#define LEDDRIVER16_REG_RAMP_RATE_GRP2 0x30
123#define LEDDRIVER16_REG_STEP_TIME_GRP2 0x31
124#define LEDDRIVER16_REG_HOLD_CNTL_GRP2 0x32
125#define LEDDRIVER16_REG_IREF_GRP2 0x33
126#define LEDDRIVER16_REG_RAMP_RATE_GRP3 0x34
127#define LEDDRIVER16_REG_STEP_TIME_GRP3 0x35
128#define LEDDRIVER16_REG_HOLD_CNTL_GRP3 0x36
129#define LEDDRIVER16_REG_IREF_GRP3 0x37
130#define LEDDRIVER16_REG_GRAD_MODE_SEL0 0x38
131#define LEDDRIVER16_REG_GRAD_MODE_SEL1 0x39
132#define LEDDRIVER16_REG_GRAD_GRP_SEL0 0x3A
133#define LEDDRIVER16_REG_GRAD_GRP_SEL1 0x3B
134#define LEDDRIVER16_REG_GRAD_GRP_SEL2 0x3C
135#define LEDDRIVER16_REG_GRAD_GRP_SEL3 0x3D
136#define LEDDRIVER16_REG_GRAD_CNTL 0x3E
137#define LEDDRIVER16_REG_OFFSET 0x3F
138#define LEDDRIVER16_REG_PWMALL 0x40
139#define LEDDRIVER16_REG_IREFALL 0x41
140#define LEDDRIVER16_REG_EFLAG0 0x42
141#define LEDDRIVER16_REG_EFLAG1 0x43
142#define LEDDRIVER16_REG_EFLAG2 0x44
143#define LEDDRIVER16_REG_EFLAG3 0x45
144
145 // leddriver16_reg
146
161#define LEDDRIVER16_MODE1_NORMAL_MODE 0x00
162#define LEDDRIVER16_MODE1_LOW_POWER_MODE 0x10
163
168#define LEDDRIVER16_MODE2_OVERTEMP 0x80
169#define LEDDRIVER16_MODE2_ERROR 0x40
170#define LEDDRIVER16_MODE2_DMBLNK 0x20
171#define LEDDRIVER16_MODE2_CLRERR 0x10
172#define LEDDRIVER16_MODE2_EXP_EN 0x04
173
178#define LEDDRIVER16_LEDOUT_OFF 0x00
179#define LEDDRIVER16_LEDOUT_ON 0x01
180#define LEDDRIVER16_LEDOUT_PWM_ALL 0x02
181#define LEDDRIVER16_LEDOUT_PWM_GRPPWM 0x03
182#define LEDDRIVER16_LEDOUT_MASK 0x03
183
188#define LEDDRIVER16_PWM_DUTY_MIN 0x00
189#define LEDDRIVER16_PWM_DUTY_MAX 0xFF
190
195#define LEDDRIVER16_IREF_MIN 0x00
196#define LEDDRIVER16_IREF_MAX 0xFF
197
202#define LEDDRIVER16_LED_CHANNEL_0 0x0001u
203#define LEDDRIVER16_LED_CHANNEL_1 0x0002u
204#define LEDDRIVER16_LED_CHANNEL_2 0x0004u
205#define LEDDRIVER16_LED_CHANNEL_3 0x0008u
206#define LEDDRIVER16_LED_CHANNEL_4 0x0010u
207#define LEDDRIVER16_LED_CHANNEL_5 0x0020u
208#define LEDDRIVER16_LED_CHANNEL_6 0x0040u
209#define LEDDRIVER16_LED_CHANNEL_7 0x0080u
210#define LEDDRIVER16_LED_CHANNEL_8 0x0100u
211#define LEDDRIVER16_LED_CHANNEL_9 0x0200u
212#define LEDDRIVER16_LED_CHANNEL_10 0x0400u
213#define LEDDRIVER16_LED_CHANNEL_11 0x0800u
214#define LEDDRIVER16_LED_CHANNEL_12 0x1000u
215#define LEDDRIVER16_LED_CHANNEL_13 0x2000u
216#define LEDDRIVER16_LED_CHANNEL_14 0x4000u
217#define LEDDRIVER16_LED_CHANNEL_15 0x8000u
218#define LEDDRIVER16_LED_CHANNEL_GRP0 0x000Fu
219#define LEDDRIVER16_LED_CHANNEL_GRP1 0x00F0u
220#define LEDDRIVER16_LED_CHANNEL_GRP2 0x0F00u
221#define LEDDRIVER16_LED_CHANNEL_GRP3 0xF000u
222#define LEDDRIVER16_LED_CHANNEL_ALL 0xFFFFu
223
232#define LEDDRIVER16_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
233#define LEDDRIVER16_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
234
235 // leddriver16_set
236
251#define LEDDRIVER16_MAP_MIKROBUS( cfg, mikrobus ) \
252 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
253 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
254 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
255 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
256 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
257 cfg.oe = MIKROBUS( mikrobus, MIKROBUS_PWM );
258
259 // leddriver16_map
260 // leddriver16
261
266typedef struct
267{
268 // Output pins
269 digital_out_t rst;
270 digital_out_t oe;
272 // Modules
273 spi_master_t spi;
275 pin_name_t chip_select;
278
283typedef struct
284{
285 // Communication gpio pins
286 pin_name_t miso;
287 pin_name_t mosi;
288 pin_name_t sck;
289 pin_name_t cs;
291 // Additional gpio pins
292 pin_name_t rst;
293 pin_name_t oe;
295 // static variable
296 uint32_t spi_speed;
297 spi_master_mode_t spi_mode;
298 spi_master_chip_select_polarity_t cs_polarity;
301
312
329
344
358
371err_t leddriver16_write_register ( leddriver16_t *ctx, uint8_t reg, uint8_t data_in );
372
385err_t leddriver16_read_register ( leddriver16_t *ctx, uint8_t reg, uint8_t *data_out );
386
396
406
416
426
438
457err_t leddriver16_set_led_state ( leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t state );
458
473err_t leddriver16_set_led_pwm ( leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t duty_cycle );
474
487err_t leddriver16_set_led_iref ( leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t iref );
488
489#ifdef __cplusplus
490}
491#endif
492#endif // LEDDRIVER16_H
493
494 // leddriver16
495
496// ------------------------------------------------------------------------ END
err_t leddriver16_default_cfg(leddriver16_t *ctx)
LED Driver 16 default configuration function.
void leddriver16_enable_output(leddriver16_t *ctx)
LED Driver 16 enable output function.
err_t leddriver16_init(leddriver16_t *ctx, leddriver16_cfg_t *cfg)
LED Driver 16 initialization function.
err_t leddriver16_set_led_iref(leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t iref)
LED Driver 16 set led iref function.
err_t leddriver16_write_register(leddriver16_t *ctx, uint8_t reg, uint8_t data_in)
LED Driver 16 write register function.
void leddriver16_disable_output(leddriver16_t *ctx)
LED Driver 16 disable output function.
void leddriver16_enable_device(leddriver16_t *ctx)
LED Driver 16 enable device function.
err_t leddriver16_set_led_state(leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t state)
LED Driver 16 set led state function.
err_t leddriver16_clear_errors(leddriver16_t *ctx)
LED Driver 16 clear errors function.
err_t leddriver16_read_register(leddriver16_t *ctx, uint8_t reg, uint8_t *data_out)
LED Driver 16 read register function.
void leddriver16_cfg_setup(leddriver16_cfg_t *cfg)
LED Driver 16 configuration object setup function.
err_t leddriver16_set_led_pwm(leddriver16_t *ctx, uint16_t led_ch_mask, uint8_t duty_cycle)
LED Driver 16 set led pwm function.
void leddriver16_disable_device(leddriver16_t *ctx)
LED Driver 16 disable device function.
leddriver16_return_value_t
LED Driver 16 Click return value data.
Definition leddriver16.h:307
@ LEDDRIVER16_ERROR
Definition leddriver16.h:309
@ LEDDRIVER16_OK
Definition leddriver16.h:308
This file contains SPI specific macros, functions, etc.
LED Driver 16 Click configuration object.
Definition leddriver16.h:284
spi_master_chip_select_polarity_t cs_polarity
Definition leddriver16.h:298
pin_name_t sck
Definition leddriver16.h:288
pin_name_t oe
Definition leddriver16.h:293
spi_master_mode_t spi_mode
Definition leddriver16.h:297
pin_name_t mosi
Definition leddriver16.h:287
uint32_t spi_speed
Definition leddriver16.h:296
pin_name_t miso
Definition leddriver16.h:286
pin_name_t rst
Definition leddriver16.h:292
pin_name_t cs
Definition leddriver16.h:289
LED Driver 16 Click context object.
Definition leddriver16.h:267
spi_master_t spi
Definition leddriver16.h:273
digital_out_t oe
Definition leddriver16.h:270
digital_out_t rst
Definition leddriver16.h:269
pin_name_t chip_select
Definition leddriver16.h:275