lighttemp  2.0.0.0
lighttemp.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 LIGHTTEMP_H
36 #define LIGHTTEMP_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 #include "drv_pwm.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define LIGHTTEMP_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.pwm1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
57  cfg.pwm2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
59 
65 #define LIGHTTEMP_RETVAL uint8_t
66 
67 #define LIGHTTEMP_OK 0x00
68 #define LIGHTTEMP_INIT_ERROR 0xFF
69 
75 #define LIGHTTEMP_DEF_FREQ 20000
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef struct
89 {
90  // Input pins
91 
92  digital_in_t int_pin;
93 
94  // Modules
95 
96  i2c_master_t i2c;
97  pwm_t pwm1;
98  pwm_t pwm2;
99 
100  // ctx variable
101 
102  uint8_t slave_address;
103  uint32_t pwm_freq;
104 
105 } lighttemp_t;
106 
110 typedef struct
111 {
112  // Communication gpio pins
113 
114  pin_name_t scl;
115  pin_name_t sda;
116  pin_name_t pwm1;
117  pin_name_t pwm2;
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 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133 
139 #ifdef __cplusplus
140 extern "C"{
141 #endif
142 
152 
162 
173 void lighttemp_generic_write ( lighttemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
174 
185 void lighttemp_generic_read ( lighttemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
186 
195 
205 
214 void lighttemp_led1_set_duty_cycle ( lighttemp_t *ctx, float duty_cycle );
215 
224 
233 
242 void lighttemp_led2_set_duty_cycle ( lighttemp_t *ctx, float duty_cycle );
243 
252 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif // _LIGHTTEMP_H_
265  // End public_function group
268 
269 // ------------------------------------------------------------------------- END
lighttemp_cfg_t
Click configuration structure definition.
Definition: lighttemp.h:111
lighttemp_t::int_pin
digital_in_t int_pin
Definition: lighttemp.h:92
lighttemp_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: lighttemp.h:125
lighttemp_generic_write
void lighttemp_generic_write(lighttemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
lighttemp_cfg_t::i2c_address
uint8_t i2c_address
Definition: lighttemp.h:126
lighttemp_led1_set_duty_cycle
void lighttemp_led1_set_duty_cycle(lighttemp_t *ctx, float duty_cycle)
Generic sets PWM duty cycle for LED1.
lighttemp_t::pwm2
pwm_t pwm2
Definition: lighttemp.h:98
lighttemp_t::i2c
i2c_master_t i2c
Definition: lighttemp.h:96
lighttemp_t
Click ctx object definition.
Definition: lighttemp.h:89
lighttemp_get_pg_voltage
uint16_t lighttemp_get_pg_voltage(lighttemp_t *ctx)
Get voltage.
lighttemp_cfg_t::scl
pin_name_t scl
Definition: lighttemp.h:114
lighttemp_t::slave_address
uint8_t slave_address
Definition: lighttemp.h:102
lighttemp_cfg_t::pwm2
pin_name_t pwm2
Definition: lighttemp.h:117
lighttemp_get_interrupt_state
uint8_t lighttemp_get_interrupt_state(lighttemp_t *ctx)
Get INT pin state.
lighttemp_generic_read
void lighttemp_generic_read(lighttemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
lighttemp_led1_pwm_start
void lighttemp_led1_pwm_start(lighttemp_t *ctx)
Start PWM module for LED1.
lighttemp_init
LIGHTTEMP_RETVAL lighttemp_init(lighttemp_t *ctx, lighttemp_cfg_t *cfg)
Initialization function.
lighttemp_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: lighttemp.h:127
lighttemp_cfg_t::pwm1
pin_name_t pwm1
Definition: lighttemp.h:116
LIGHTTEMP_RETVAL
#define LIGHTTEMP_RETVAL
Definition: lighttemp.h:65
lighttemp_t::pwm1
pwm_t pwm1
Definition: lighttemp.h:97
lighttemp_cfg_t::sda
pin_name_t sda
Definition: lighttemp.h:115
lighttemp_led2_set_duty_cycle
void lighttemp_led2_set_duty_cycle(lighttemp_t *ctx, float duty_cycle)
Generic sets PWM duty cycle for LED2.
lighttemp_led2_pwm_stop
void lighttemp_led2_pwm_stop(lighttemp_t *ctx)
Stop PWM module for LED2.
lighttemp_led2_pwm_start
void lighttemp_led2_pwm_start(lighttemp_t *ctx)
Start PWM module for LED2.
lighttemp_led1_pwm_stop
void lighttemp_led1_pwm_stop(lighttemp_t *ctx)
Stop PWM module for LED1.
lighttemp_cfg_setup
void lighttemp_cfg_setup(lighttemp_cfg_t *cfg)
Config Object Initialization function.
lighttemp_cfg_t::int_pin
pin_name_t int_pin
Definition: lighttemp.h:121
lighttemp_t::pwm_freq
uint32_t pwm_freq
Definition: lighttemp.h:103