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 
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_i2c_master.h"
55 #include "drv_pwm.h"
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define LIGHTTEMP_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.pwm1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
71  cfg.pwm2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
73 
79 #define LIGHTTEMP_RETVAL uint8_t
80 
81 #define LIGHTTEMP_OK 0x00
82 #define LIGHTTEMP_INIT_ERROR 0xFF
83 
89 #define LIGHTTEMP_DEF_FREQ 20000
90  // End group macro
93 // --------------------------------------------------------------- PUBLIC TYPES
102 typedef struct
103 {
104  // Input pins
105 
106  digital_in_t int_pin;
107 
108  // Modules
109 
110  i2c_master_t i2c;
111  pwm_t pwm1;
112  pwm_t pwm2;
113 
114  // ctx variable
115 
116  uint8_t slave_address;
117  uint32_t pwm_freq;
118 
119 } lighttemp_t;
120 
124 typedef struct
125 {
126  // Communication gpio pins
127 
128  pin_name_t scl;
129  pin_name_t sda;
130  pin_name_t pwm1;
131  pin_name_t pwm2;
132 
133  // Additional gpio pins
134 
135  pin_name_t int_pin;
136 
137  // static variable
138 
139  uint32_t i2c_speed;
140  uint8_t i2c_address;
141  uint32_t dev_pwm_freq;
142 
144  // End types group
146 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147 
153 #ifdef __cplusplus
154 extern "C"{
155 #endif
156 
166 
176 
187 void lighttemp_generic_write ( lighttemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
188 
199 void lighttemp_generic_read ( lighttemp_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
200 
209 
219 
228 void lighttemp_led1_set_duty_cycle ( lighttemp_t *ctx, float duty_cycle );
229 
238 
247 
256 void lighttemp_led2_set_duty_cycle ( lighttemp_t *ctx, float duty_cycle );
257 
266 
275 #ifdef __cplusplus
276 }
277 #endif
278 #endif // _LIGHTTEMP_H_
279  // End public_function group
282 
283 // ------------------------------------------------------------------------- END
lighttemp_cfg_t
Click configuration structure definition.
Definition: lighttemp.h:125
lighttemp_t::int_pin
digital_in_t int_pin
Definition: lighttemp.h:106
lighttemp_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: lighttemp.h:139
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:140
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:112
lighttemp_t::i2c
i2c_master_t i2c
Definition: lighttemp.h:110
lighttemp_t
Click ctx object definition.
Definition: lighttemp.h:103
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:128
lighttemp_t::slave_address
uint8_t slave_address
Definition: lighttemp.h:116
lighttemp_cfg_t::pwm2
pin_name_t pwm2
Definition: lighttemp.h:131
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:141
lighttemp_cfg_t::pwm1
pin_name_t pwm1
Definition: lighttemp.h:130
LIGHTTEMP_RETVAL
#define LIGHTTEMP_RETVAL
Definition: lighttemp.h:79
lighttemp_t::pwm1
pwm_t pwm1
Definition: lighttemp.h:111
lighttemp_cfg_t::sda
pin_name_t sda
Definition: lighttemp.h:129
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:135
lighttemp_t::pwm_freq
uint32_t pwm_freq
Definition: lighttemp.h:117