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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_pwm.h"
38 
59 #define IR2_STATE_HIGH 0x01
60 #define IR2_STATE_LOW 0x00
61 
66 #define IR2_DEF_FREQ 38000
67 #define IR2_DEF_DUTY_CYCLE 0.25
68  // ir2_cfg
70 
85 #define IR2_MAP_MIKROBUS( cfg, mikrobus ) \
86  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
87  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
88  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
89  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
90  // ir2_map // ir2
93 
98 typedef enum
99 {
108 typedef struct
109 {
110  // Input pins
111  digital_in_t out_pin;
113  // Modules
114  pwm_t pwm;
116  // ctx variable
117  uint32_t pwm_freq;
121 } ir2_t;
122 
127 typedef struct
128 {
129  // Communication gpio pins
130  pin_name_t pwm;
131  pin_name_t int_pin;
132  pin_name_t rx_pin;
133  pin_name_t tx_pin;
135  uint32_t dev_pwm_freq;
139 } ir2_cfg_t;
140 
145 typedef enum
146 {
147  IR2_OK = 0,
148  IR2_ERROR = -1
149 
151 
167 void ir2_cfg_setup ( ir2_cfg_t *cfg );
168 
184 
198 err_t ir2_init ( ir2_t *ctx, ir2_cfg_t *cfg );
199 
208 uint8_t ir2_get_out_pin ( ir2_t *ctx );
209 
220 void ir2_nec_send_data ( ir2_t *ctx, uint8_t address, uint8_t data_in );
221 
234 err_t ir2_nec_read_data ( ir2_t *ctx, uint8_t *address, uint8_t *data_out );
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 #endif // IR2_H
240  // ir2
242 
243 // ------------------------------------------------------------------------ END
ir2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ir2.h:132
IR2_DRV_SEL_GPIO
@ IR2_DRV_SEL_GPIO
Definition: ir2.h:100
IR2_DRV_SEL_UART
@ IR2_DRV_SEL_UART
Definition: ir2.h:101
IR2_ERROR
@ IR2_ERROR
Definition: ir2.h:148
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:128
ir2_cfg_t::pwm
pin_name_t pwm
Definition: ir2.h:130
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:117
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:109
ir2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ir2.h:133
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:119
ir2_t::out_pin
digital_in_t out_pin
Definition: ir2.h:111
ir2_drv_t
ir2_drv_t
IR 2 Click driver selector.
Definition: ir2.h:99
IR2_OK
@ IR2_OK
Definition: ir2.h:147
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:131
ir2_return_value_t
ir2_return_value_t
IR 2 Click return value data.
Definition: ir2.h:146
ir2_t::pwm
pwm_t pwm
Definition: ir2.h:114
ir2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: ir2.h:135
ir2_cfg_t::drv_sel
ir2_drv_t drv_sel
Definition: ir2.h:137