leddriver8 2.0.0.0
leddriver8.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef LEDDRIVER8_H
36#define LEDDRIVER8_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define LEDDRIVER8_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
73 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
80#define LEDDRIVER8_RETVAL uint8_t
81
82#define LEDDRIVER8_OK 0x00
83#define LEDDRIVER8_INIT_ERROR 0xFF
90#define LEDDRIVER8_REG_MODE_1 0x00
91#define LEDDRIVER8_REG_MODE_2 0x01
92#define LEDDRIVER8_REG_OUT_ERROR_FLAG_0 0x02
93#define LEDDRIVER8_REG_OUT_ERROR_FLAG_1 0x03
94#define LEDDRIVER8_REG_OUT_ERROR_FLAG_2 0x04
95#define LEDDRIVER8_REG_OUT_ERROR_FLAG_3 0x05
96#define LEDDRIVER8_REG_OUT_ERROR_FLAG_4 0x06
97#define LEDDRIVER8_REG_OUT_ERROR_FLAG_5 0x07
98#define LEDDRIVER8_REG_LED_OUTPUT_0 0x08
99#define LEDDRIVER8_REG_LED_OUTPUT_1 0x09
100#define LEDDRIVER8_REG_LED_OUTPUT_2 0x0A
101#define LEDDRIVER8_REG_LED_OUTPUT_3 0x0B
102#define LEDDRIVER8_REG_LED_OUTPUT_4 0x0C
103#define LEDDRIVER8_REG_LED_OUTPUT_5 0x0D
104#define LEDDRIVER8_REG_GRP_PWM 0x0E
105#define LEDDRIVER8_REG_GRP_FREQ 0x0F
106#define LEDDRIVER8_REG_BRIGHTNESS_LED_0 0x10
107#define LEDDRIVER8_REG_BRIGHTNESS_LED_1 0x11
108#define LEDDRIVER8_REG_BRIGHTNESS_LED_2 0x12
109#define LEDDRIVER8_REG_BRIGHTNESS_LED_3 0x13
110#define LEDDRIVER8_REG_BRIGHTNESS_LED_4 0x14
111#define LEDDRIVER8_REG_BRIGHTNESS_LED_5 0x15
112#define LEDDRIVER8_REG_BRIGHTNESS_LED_6 0x16
113#define LEDDRIVER8_REG_BRIGHTNESS_LED_7 0x17
114#define LEDDRIVER8_REG_BRIGHTNESS_LED_8 0x18
115#define LEDDRIVER8_REG_BRIGHTNESS_LED_9 0x19
116#define LEDDRIVER8_REG_BRIGHTNESS_LED_10 0x1A
117#define LEDDRIVER8_REG_BRIGHTNESS_LED_11 0x1B
118#define LEDDRIVER8_REG_BRIGHTNESS_LED_12 0x1C
119#define LEDDRIVER8_REG_BRIGHTNESS_LED_13 0x1D
120#define LEDDRIVER8_REG_BRIGHTNESS_LED_14 0x1E
121#define LEDDRIVER8_REG_BRIGHTNESS_LED_15 0x1F
122#define LEDDRIVER8_REG_BRIGHTNESS_LED_16 0x20
123#define LEDDRIVER8_REG_BRIGHTNESS_LED_17 0x21
124#define LEDDRIVER8_REG_BRIGHTNESS_LED_18 0x22
125#define LEDDRIVER8_REG_BRIGHTNESS_LED_19 0x23
126#define LEDDRIVER8_REG_BRIGHTNESS_LED_20 0x24
127#define LEDDRIVER8_REG_BRIGHTNESS_LED_21 0x25
128#define LEDDRIVER8_REG_BRIGHTNESS_LED_22 0x26
129#define LEDDRIVER8_REG_BRIGHTNESS_LED_23 0x27
130#define LEDDRIVER8_REG_IREF_0 0x28
131#define LEDDRIVER8_REG_IREF_1 0x29
132#define LEDDRIVER8_REG_IREF_2 0x2A
133#define LEDDRIVER8_REG_IREF_3 0x2B
134#define LEDDRIVER8_REG_IREF_4 0x2C
135#define LEDDRIVER8_REG_IREF_5 0x2D
136#define LEDDRIVER8_REG_IREF_6 0x2E
137#define LEDDRIVER8_REG_IREF_7 0x2F
138#define LEDDRIVER8_REG_IREF_8 0x30
139#define LEDDRIVER8_REG_IREF_9 0x31
140#define LEDDRIVER8_REG_IREF_10 0x32
141#define LEDDRIVER8_REG_IREF_11 0x33
142#define LEDDRIVER8_REG_IREF_12 0x34
143#define LEDDRIVER8_REG_IREF_13 0x35
144#define LEDDRIVER8_REG_IREF_14 0x36
145#define LEDDRIVER8_REG_IREF_15 0x37
146#define LEDDRIVER8_REG_IREF_16 0x38
147#define LEDDRIVER8_REG_IREF_17 0x39
148#define LEDDRIVER8_REG_IREF_18 0x3A
149#define LEDDRIVER8_REG_IREF_19 0x3B
150#define LEDDRIVER8_REG_IREF_20 0x3C
151#define LEDDRIVER8_REG_IREF_21 0x3D
152#define LEDDRIVER8_REG_IREF_22 0x3E
153#define LEDDRIVER8_REG_IREF_23 0x3F
154#define LEDDRIVER8_REG_RAMP_RATE_GRP0 0x40
155#define LEDDRIVER8_REG_STEP_TIME_GRP0 0x41
156#define LEDDRIVER8_REG_HOLD_CNTL_GRP0 0x42
157#define LEDDRIVER8_REG_IREF_GRP0 0x43
158#define LEDDRIVER8_REG_RAMP_RATE_GRP1 0x44
159#define LEDDRIVER8_REG_STEP_TIME_GRP1 0x45
160#define LEDDRIVER8_REG_HOLD_CNTL_GRP1 0x46
161#define LEDDRIVER8_REG_IREF_GRP1 0x47
162#define LEDDRIVER8_REG_RAMP_RATE_GRP2 0x48
163#define LEDDRIVER8_REG_STEP_TIME_GRP2 0x49
164#define LEDDRIVER8_REG_HOLD_CNTL_GRP2 0x4A
165#define LEDDRIVER8_REG_IREF_GRP2 0x4B
166#define LEDDRIVER8_REG_RAMP_RATE_GRP3 0x4C
167#define LEDDRIVER8_REG_STEP_TIME_GRP3 0x4D
168#define LEDDRIVER8_REG_HOLD_CNTL_GRP3 0x4E
169#define LEDDRIVER8_REG_IREF_GRP3 0x4F
170#define LEDDRIVER8_REG_RAMP_RATE_GRP4 0x50
171#define LEDDRIVER8_REG_STEP_TIME_GRP4 0x51
172#define LEDDRIVER8_REG_HOLD_CNTL_GRP4 0x52
173#define LEDDRIVER8_REG_IREF_GRP4 0x53
174#define LEDDRIVER8_REG_RAMP_RATE_GRP5 0x54
175#define LEDDRIVER8_REG_STEP_TIME_GRP5 0x55
176#define LEDDRIVER8_REG_HOLD_CNTL_GRP5 0x56
177#define LEDDRIVER8_REG_IREF_GRP5 0x57
178#define LEDDRIVER8_REG_GRAD_MODE_SEL0 0x58
179#define LEDDRIVER8_REG_GRAD_MODE_SEL1 0x59
180#define LEDDRIVER8_REG_GRAD_MODE_SEL2 0x5A
181#define LEDDRIVER8_REG_GRAD_GRP_SEL0 0x5B
182#define LEDDRIVER8_REG_GRAD_GRP_SEL1 0x5C
183#define LEDDRIVER8_REG_GRAD_GRP_SEL2 0x5D
184#define LEDDRIVER8_REG_GRAD_GRP_SEL3 0x5E
185#define LEDDRIVER8_REG_GRAD_GRP_SEL4 0x5F
186#define LEDDRIVER8_REG_GRAD_GRP_SEL5 0x60
187#define LEDDRIVER8_REG_GRAD_GRP_SEL6 0x61
188#define LEDDRIVER8_REG_GRAD_GRP_SEL7 0x62
189#define LEDDRIVER8_REG_GRAD_GRP_SEL8 0x63
190#define LEDDRIVER8_REG_GRAD_GRP_SEL9 0x64
191#define LEDDRIVER8_REG_GRAD_GRP_SEL10 0x65
192#define LEDDRIVER8_REG_GRAD_GRP_SEL11 0x66
193#define LEDDRIVER8_REG_GRAD_CTRL_0 0x67
194#define LEDDRIVER8_REG_GRAD_CTRL_1 0x68
195#define LEDDRIVER8_REG_OFFSET 0x69
196#define LEDDRIVER8_REG_PWM_ALL 0x6A
197#define LEDDRIVER8_REG_IREF_ALL 0x6B
204#define LEDDRIVER8_MODE1_NORMAL_MODE 0x00
205#define LEDDRIVER8_MODE1_SLEEP_MODE 0x10
212#define LEDDRIVER8_MODE2_DMBLNK_DIMMING 0x00
213#define LEDDRIVER8_MODE2_DMBLNK_BLINKING 0x20
214#define LEDDRIVER8_MODE2_CLRERR_NO 0x00
215#define LEDDRIVER8_MODE2_CLRERR_ALL 0x10
216#define LEDDRIVER8_MODE2_AUTO_SWITCH_OFF_DIS 0x08
217#define LEDDRIVER8_MODE2_EXP_ENABLE 0x04
218#define LEDDRIVER8_MODE2_EXP_DISABLE 0x00
225#define LEDDRIVER8_LED_DRIVER_0_23 0x00
226#define LEDDRIVER8_LED_DRIVER_FULL 0x01
227#define LEDDRIVER8_LED_DRIVER_PWMX 0x02
228#define LEDDRIVER8_LED_DRIVER_GRPPWM 0x03
229
230#define LEDDRIVER8_BRIGHTNESS_ALL_LED 0x30
231#define LEDDRIVER8_OUTPUT_GAIN_ALL_LED 0x40
232#define LEDDRIVER8_FULL_OUTPUT_CURRENT_GAIN 0xFF
233
234#define LEDDRIVER8_ENABLE_LED_OUTPUTS 0x00
235#define LEDDRIVER8_DISABLE_LED_OUTPUTS 0x01
236
237#define LEDDRIVER8_MAX_BRIGHTNESS 0xFF
238#define LEDDRIVER8_MIN_BRIGHTNESS 0x00
245#define LEDDRIVER8_LED_0 0x00
246#define LEDDRIVER8_LED_1 0x01
247#define LEDDRIVER8_LED_2 0x02
248#define LEDDRIVER8_LED_3 0x03
249#define LEDDRIVER8_LED_4 0x04
250#define LEDDRIVER8_LED_5 0x05
251#define LEDDRIVER8_LED_6 0x06
252#define LEDDRIVER8_LED_7 0x07
253#define LEDDRIVER8_LED_8 0x08
254#define LEDDRIVER8_LED_9 0x09
255#define LEDDRIVER8_LED_10 0x0A
256#define LEDDRIVER8_LED_11 0x0B
257#define LEDDRIVER8_LED_12 0x0C
258#define LEDDRIVER8_LED_13 0x0D
259#define LEDDRIVER8_LED_14 0x0E
260#define LEDDRIVER8_LED_15 0x0F
261#define LEDDRIVER8_LED_16 0x10
262#define LEDDRIVER8_LED_17 0x11
263#define LEDDRIVER8_LED_18 0x12
264#define LEDDRIVER8_LED_19 0x13
265#define LEDDRIVER8_LED_20 0x14
266#define LEDDRIVER8_LED_21 0x15
267#define LEDDRIVER8_LED_22 0x16
268#define LEDDRIVER8_LED_23 0x17
271 // End group macro
272// --------------------------------------------------------------- PUBLIC TYPES
281typedef struct
282{
283 digital_out_t cs;
284 // Output pins
285
286 digital_out_t rst;
287 digital_out_t pwm;
288
289 // Modules
290
291 spi_master_t spi;
292 pin_name_t chip_select;
293
295
299typedef struct
300{
301 // Communication gpio pins
302
303 pin_name_t miso;
304 pin_name_t mosi;
305 pin_name_t sck;
306 pin_name_t cs;
307
308 // Additional gpio pins
309
310 pin_name_t rst;
311 pin_name_t pwm;
312
313 // static variable
314
315 uint32_t spi_speed;
316 spi_master_mode_t spi_mode;
317 spi_master_chip_select_polarity_t cs_polarity;
318
320
321 // End types group
322// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
323
328#ifdef __cplusplus
329extern "C"{
330#endif
331
341
350
358void leddriver8_write_data ( leddriver8_t *ctx, uint8_t reg, uint8_t data_byte );
359
367uint8_t leddriver8_read_data ( leddriver8_t *ctx, uint8_t reg );
368
375void leddriver8_output_enable_pin( leddriver8_t *ctx, uint8_t state );
376
384
396void leddriver8_set_brightness ( leddriver8_t *ctx, uint8_t num_led, uint8_t value );
397
409void leddriver8_set_output_gain ( leddriver8_t *ctx, uint8_t num_led, uint8_t value );
410
418void leddriver8_set_mode_register( leddriver8_t *ctx, uint8_t mode_1, uint8_t mode_2 );
419
420#ifdef __cplusplus
421}
422#endif
423#endif // _LEDDRIVER8_H_
424
425 // End public_function group
427
428// ------------------------------------------------------------------------- END
#define LEDDRIVER8_RETVAL
Definition leddriver8.h:80
LEDDRIVER8_RETVAL leddriver8_init(leddriver8_t *ctx, leddriver8_cfg_t *cfg)
Initialization function.
void leddriver8_set_brightness(leddriver8_t *ctx, uint8_t num_led, uint8_t value)
Function for set Brightness.
void leddriver8_write_data(leddriver8_t *ctx, uint8_t reg, uint8_t data_byte)
Functions for write one byte in the register.
void leddriver8_cfg_setup(leddriver8_cfg_t *cfg)
Config Object Initialization function.
void leddriver8_set_mode_register(leddriver8_t *ctx, uint8_t mode_1, uint8_t mode_2)
Function for set mode registers.
void leddriver8_output_enable_pin(leddriver8_t *ctx, uint8_t state)
Functions for enable led output.
uint8_t leddriver8_read_data(leddriver8_t *ctx, uint8_t reg)
Functions for read byte from register.
void leddriver8_set_output_gain(leddriver8_t *ctx, uint8_t num_led, uint8_t value)
Function for set output gain.
void leddriver8_reset(leddriver8_t *ctx)
Device reset function.
Click configuration structure definition.
Definition leddriver8.h:300
spi_master_chip_select_polarity_t cs_polarity
Definition leddriver8.h:317
pin_name_t sck
Definition leddriver8.h:305
spi_master_mode_t spi_mode
Definition leddriver8.h:316
pin_name_t mosi
Definition leddriver8.h:304
uint32_t spi_speed
Definition leddriver8.h:315
pin_name_t pwm
Definition leddriver8.h:311
pin_name_t miso
Definition leddriver8.h:303
pin_name_t rst
Definition leddriver8.h:310
pin_name_t cs
Definition leddriver8.h:306
Click ctx object definition.
Definition leddriver8.h:282
digital_out_t cs
Definition leddriver8.h:283
spi_master_t spi
Definition leddriver8.h:291
digital_out_t pwm
Definition leddriver8.h:287
digital_out_t rst
Definition leddriver8.h:286
pin_name_t chip_select
Definition leddriver8.h:292