ir2  2.0.0.0
ir2.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef IR2_H
29 #define IR2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_pwm.h"
48 
69 #define IR2_STATE_HIGH 0x01
70 #define IR2_STATE_LOW 0x00
71 
76 #define IR2_DEF_FREQ 38000
77 #define IR2_DEF_DUTY_CYCLE 0.25
78  // ir2_cfg
80 
95 #define IR2_MAP_MIKROBUS( cfg, mikrobus ) \
96  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
97  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
98  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
99  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
100  // ir2_map // ir2
103 
108 typedef enum
109 {
118 typedef struct
119 {
120  // Input pins
121  digital_in_t out_pin;
123  // Modules
124  pwm_t pwm;
126  // ctx variable
127  uint32_t pwm_freq;
131 } ir2_t;
132 
137 typedef struct
138 {
139  // Communication gpio pins
140  pin_name_t pwm;
141  pin_name_t int_pin;
142  pin_name_t rx_pin;
143  pin_name_t tx_pin;
145  uint32_t dev_pwm_freq;
149 } ir2_cfg_t;
150 
155 typedef enum
156 {
157  IR2_OK = 0,
158  IR2_ERROR = -1
159 
161 
177 void ir2_cfg_setup ( ir2_cfg_t *cfg );
178 
194 
208 err_t ir2_init ( ir2_t *ctx, ir2_cfg_t *cfg );
209 
218 uint8_t ir2_get_out_pin ( ir2_t *ctx );
219 
230 void ir2_nec_send_data ( ir2_t *ctx, uint8_t address, uint8_t data_in );
231 
244 err_t ir2_nec_read_data ( ir2_t *ctx, uint8_t *address, uint8_t *data_out );
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 #endif // IR2_H
250  // ir2
252 
253 // ------------------------------------------------------------------------ END
ir2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ir2.h:142
IR2_DRV_SEL_GPIO
@ IR2_DRV_SEL_GPIO
Definition: ir2.h:110
IR2_DRV_SEL_UART
@ IR2_DRV_SEL_UART
Definition: ir2.h:111
IR2_ERROR
@ IR2_ERROR
Definition: ir2.h:158
ir2_nec_read_data
err_t ir2_nec_read_data(ir2_t *ctx, uint8_t *address, uint8_t *data_out)
IR 2 NEC read data function.
ir2_cfg_setup
void ir2_cfg_setup(ir2_cfg_t *cfg)
IR 2 configuration object setup function.
ir2_cfg_t
IR 2 Click configuration object.
Definition: ir2.h:138
ir2_cfg_t::pwm
pin_name_t pwm
Definition: ir2.h:140
ir2_drv_interface_selection
void ir2_drv_interface_selection(ir2_cfg_t *cfg, ir2_drv_t drv_sel)
IR 2 driver interface setup function.
ir2_t::pwm_freq
uint32_t pwm_freq
Definition: ir2.h:127
ir2_get_out_pin
uint8_t ir2_get_out_pin(ir2_t *ctx)
IR 2 get OUT pin function.
ir2_t
IR 2 Click context object.
Definition: ir2.h:119
ir2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ir2.h:143
ir2_init
err_t ir2_init(ir2_t *ctx, ir2_cfg_t *cfg)
IR 2 initialization function.
ir2_t::drv_sel
ir2_drv_t drv_sel
Definition: ir2.h:129
ir2_t::out_pin
digital_in_t out_pin
Definition: ir2.h:121
ir2_drv_t
ir2_drv_t
IR 2 Click driver selector.
Definition: ir2.h:109
IR2_OK
@ IR2_OK
Definition: ir2.h:157
ir2_nec_send_data
void ir2_nec_send_data(ir2_t *ctx, uint8_t address, uint8_t data_in)
IR 2 NEC send data function.
ir2_cfg_t::int_pin
pin_name_t int_pin
Definition: ir2.h:141
ir2_return_value_t
ir2_return_value_t
IR 2 Click return value data.
Definition: ir2.h:156
ir2_t::pwm
pwm_t pwm
Definition: ir2.h:124
ir2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: ir2.h:145
ir2_cfg_t::drv_sel
ir2_drv_t drv_sel
Definition: ir2.h:147