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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 #include "drv_pwm.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define LIGHTTEMP_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.pwm1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
67  cfg.pwm2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
69 
75 #define LIGHTTEMP_RETVAL uint8_t
76 
77 #define LIGHTTEMP_OK 0x00
78 #define LIGHTTEMP_INIT_ERROR 0xFF
79 
85 #define LIGHTTEMP_DEF_FREQ 20000
86  // End group macro
89 // --------------------------------------------------------------- PUBLIC TYPES
98 typedef struct
99 {
100  // Input pins
101 
102  digital_in_t int_pin;
103 
104  // Modules
105 
106  i2c_master_t i2c;
107  pwm_t pwm1;
108  pwm_t pwm2;
109 
110  // ctx variable
111 
112  uint8_t slave_address;
113  uint32_t pwm_freq;
114 
115 } lighttemp_t;
116 
120 typedef struct
121 {
122  // Communication gpio pins
123 
124  pin_name_t scl;
125  pin_name_t sda;
126  pin_name_t pwm1;
127  pin_name_t pwm2;
128 
129  // Additional gpio pins
130 
131  pin_name_t int_pin;
132 
133  // static variable
134 
135  uint32_t i2c_speed;
136  uint8_t i2c_address;
137  uint32_t dev_pwm_freq;
138 
140  // End types group
142 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 
149 #ifdef __cplusplus
150 extern "C"{
151 #endif
152 
162 
172 
183 void lighttemp_generic_write ( lighttemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
184 
195 void lighttemp_generic_read ( lighttemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
196 
205 
215 
224 void lighttemp_led1_set_duty_cycle ( lighttemp_t *ctx, float duty_cycle );
225 
234 
243 
252 void lighttemp_led2_set_duty_cycle ( lighttemp_t *ctx, float duty_cycle );
253 
262 
271 #ifdef __cplusplus
272 }
273 #endif
274 #endif // _LIGHTTEMP_H_
275  // End public_function group
278 
279 // ------------------------------------------------------------------------- END
lighttemp_cfg_t
Click configuration structure definition.
Definition: lighttemp.h:121
lighttemp_t::int_pin
digital_in_t int_pin
Definition: lighttemp.h:102
lighttemp_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: lighttemp.h:135
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:136
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:108
lighttemp_t::i2c
i2c_master_t i2c
Definition: lighttemp.h:106
lighttemp_t
Click ctx object definition.
Definition: lighttemp.h:99
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:124
lighttemp_t::slave_address
uint8_t slave_address
Definition: lighttemp.h:112
lighttemp_cfg_t::pwm2
pin_name_t pwm2
Definition: lighttemp.h:127
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:137
lighttemp_cfg_t::pwm1
pin_name_t pwm1
Definition: lighttemp.h:126
LIGHTTEMP_RETVAL
#define LIGHTTEMP_RETVAL
Definition: lighttemp.h:75
lighttemp_t::pwm1
pwm_t pwm1
Definition: lighttemp.h:107
lighttemp_cfg_t::sda
pin_name_t sda
Definition: lighttemp.h:125
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:131
lighttemp_t::pwm_freq
uint32_t pwm_freq
Definition: lighttemp.h:113