leddriver6  2.0.0.0
leddriver6.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 LEDDRIVER6_H
36 #define LEDDRIVER6_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_pwm.h"
41 #include "drv_i2c_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define LEDDRIVER6_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
55  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
56  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define LEDDRIVER6_RETVAL uint8_t
65 
66 #define LEDDRIVER6_OK 0x00
67 #define LEDDRIVER6_INIT_ERROR 0xFF
68 
74 #define LEDDRIVER6_DEF_FREQ 20000
75  // End group macro
78 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef struct
88 {
89 
90  // Input pins
91 
92  digital_in_t int_pin;
93 
94  // Modules
95 
96  pwm_t pwm;
97 
98  i2c_master_t i2c;
99 
100  // ctx variable
101 
102  uint32_t pwm_freq;
103 
104  uint8_t slave_address;
105 
106 } leddriver6_t;
107 
111 typedef struct
112 {
113  // Communication gpio pins
114 
115  pin_name_t scl;
116  pin_name_t sda;
117  pin_name_t pwm;
118 
119  // Additional gpio pins
120 
121  pin_name_t int_pin;
122 
123  // static variable
124 
125  uint32_t i2c_speed;
126  uint8_t i2c_address;
127  uint32_t dev_pwm_freq;
128 
130  // End types group
132 
133 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
134 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
153 
163 
172 void leddriver6_set_duty_cycle ( leddriver6_t *ctx, float duty_cycle );
173 
181 void leddriver6_pwm_stop ( leddriver6_t *ctx );
182 
190 void leddriver6_pwm_start ( leddriver6_t *ctx );
191 
202 void leddriver6_generic_read ( leddriver6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
203 
213 uint16_t leddriver6_get_pg_voltage ( leddriver6_t *ctx );
214 
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 #endif // _LEDDRIVER6_H_
230  // End public_function group
233 
234 // ------------------------------------------------------------------------- END
uint8_t i2c_address
Definition: leddriver6.h:126
i2c_master_t i2c
Definition: leddriver6.h:98
pwm_t pwm
Definition: leddriver6.h:96
uint8_t leddriver6_get_interrupt_state(leddriver6_t *ctx)
Function for get interrupt pin state.
Click ctx object definition.
Definition: leddriver6.h:87
uint32_t pwm_freq
Definition: leddriver6.h:102
pin_name_t pwm
Definition: leddriver6.h:117
digital_in_t int_pin
Definition: leddriver6.h:92
pin_name_t int_pin
Definition: leddriver6.h:121
void leddriver6_generic_read(leddriver6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pin_name_t sda
Definition: leddriver6.h:116
void leddriver6_pwm_start(leddriver6_t *ctx)
Start PWM module.
void leddriver6_set_duty_cycle(leddriver6_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
Click configuration structure definition.
Definition: leddriver6.h:111
uint32_t i2c_speed
Definition: leddriver6.h:125
uint16_t leddriver6_get_pg_voltage(leddriver6_t *ctx)
Function for reads current PG output voltage.
void leddriver6_cfg_setup(leddriver6_cfg_t *cfg)
Config Object Initialization function.
void leddriver6_pwm_stop(leddriver6_t *ctx)
Stop PWM module.
#define LEDDRIVER6_RETVAL
Definition: leddriver6.h:64
LEDDRIVER6_RETVAL leddriver6_init(leddriver6_t *ctx, leddriver6_cfg_t *cfg)
Initialization function.
uint8_t slave_address
Definition: leddriver6.h:104
pin_name_t scl
Definition: leddriver6.h:115
uint32_t dev_pwm_freq
Definition: leddriver6.h:127