ir  2.0.0.0
ir.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 IR_H
29 #define IR_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 #include "drv_pwm.h"
53 
74 #define IR_STATE_HIGH 0x01
75 #define IR_STATE_LOW 0x00
76 
82 #define DRV_BUFFER_SIZE 200
83 
88 #define IR_DEF_FREQ 38000
89  // ir_cmd
91 
106 #define IR_MAP_MIKROBUS( cfg, mikrobus ) \
107  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
108  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
109  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
110  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
111  // ir_map // ir
114 
119 typedef enum
120 {
125 
130 typedef struct
131 {
132 
133  // Input pins
134  digital_in_t an;
136  // Modules
137  uart_t uart;
138  pwm_t pwm;
140  // ctx variable
141  uint32_t pwm_freq;
143  // Buffers
144  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
145  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
149 } ir_t;
150 
155 typedef struct
156 {
157  // Communication gpio pins
158  pin_name_t rx_pin;
159  pin_name_t tx_pin;
161  // Additional gpio pins
162  pin_name_t an;
163  pin_name_t pwm;
165  // Static variable
166  uint32_t baud_rate;
168  uart_data_bits_t data_bit;
169  uart_parity_t parity_bit;
170  uart_stop_bits_t stop_bit;
172  uint32_t dev_pwm_freq;
176 } ir_cfg_t;
177 
182 typedef enum
183 {
184  IR_OK = 0,
185  IR_ERROR = -1
186 
188 
204 void ir_cfg_setup ( ir_cfg_t *cfg );
205 
221 
235 err_t ir_init ( ir_t *ctx, ir_cfg_t *cfg );
236 
249 err_t ir_generic_write ( ir_t *ctx, char *data_buf, uint16_t len );
250 
263 err_t ir_generic_read ( ir_t *ctx, char *data_buf, uint16_t max_len );
264 
273 uint8_t ir_get_an_state ( ir_t *ctx );
274 
286 void ir_nec_send_command ( ir_t *ctx, uint8_t address, uint8_t command );
287 
301 err_t ir_nec_read_command ( ir_t *ctx, uint8_t *address, uint8_t *command );
302 
303 #ifdef __cplusplus
304 }
305 #endif
306 #endif // IR_H
307  // ir
309 
310 // ------------------------------------------------------------------------ END
ir_cfg_t::uart_blocking
bool uart_blocking
Definition: ir.h:167
ir_cfg_t
IR Click configuration object.
Definition: ir.h:156
ir_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ir.h:170
ir_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ir.h:169
ir_init
err_t ir_init(ir_t *ctx, ir_cfg_t *cfg)
IR initialization function.
ir_cfg_t::baud_rate
uint32_t baud_rate
Definition: ir.h:166
ir_t::an
digital_in_t an
Definition: ir.h:134
ir_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: ir.h:172
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
IR driver buffer size.
Definition: ir.h:82
ir_cfg_t::drv_sel
ir_drv_t drv_sel
Definition: ir.h:174
IR_DRV_SEL_UART
@ IR_DRV_SEL_UART
Definition: ir.h:122
ir_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ir.h:168
ir_get_an_state
uint8_t ir_get_an_state(ir_t *ctx)
IR get AN pin state function.
ir_t::pwm
pwm_t pwm
Definition: ir.h:138
ir_t
IR Click context object.
Definition: ir.h:131
ir_drv_interface_selection
void ir_drv_interface_selection(ir_cfg_t *cfg, ir_drv_t drv_sel)
IR driver interface setup function.
IR_DRV_SEL_GPIO
@ IR_DRV_SEL_GPIO
Definition: ir.h:121
ir_cfg_setup
void ir_cfg_setup(ir_cfg_t *cfg)
IR configuration object setup function.
ir_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ir.h:159
ir_cfg_t::an
pin_name_t an
Definition: ir.h:162
ir_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ir.h:158
ir_t::pwm_freq
uint32_t pwm_freq
Definition: ir.h:141
ir_cfg_t::pwm
pin_name_t pwm
Definition: ir.h:163
ir_return_value_t
ir_return_value_t
IR Click return value data.
Definition: ir.h:183
ir_nec_send_command
void ir_nec_send_command(ir_t *ctx, uint8_t address, uint8_t command)
IR NEC send data function.
ir_t::drv_sel
ir_drv_t drv_sel
Definition: ir.h:147
ir_generic_write
err_t ir_generic_write(ir_t *ctx, char *data_buf, uint16_t len)
IR data writing function.
IR_ERROR
@ IR_ERROR
Definition: ir.h:185
ir_generic_read
err_t ir_generic_read(ir_t *ctx, char *data_buf, uint16_t max_len)
IR data reading function.
ir_drv_t
ir_drv_t
IR Click driver selector.
Definition: ir.h:120
IR_OK
@ IR_OK
Definition: ir.h:184
ir_t::uart
uart_t uart
Definition: ir.h:137
ir_nec_read_command
err_t ir_nec_read_command(ir_t *ctx, uint8_t *address, uint8_t *command)
IR NEC data reading function.