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
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_uart.h"
38#include "drv_pwm.h"
39
60#define IR_STATE_HIGH 0x01
61#define IR_STATE_LOW 0x00
62
68#define DRV_BUFFER_SIZE 200
69
74#define IR_DEF_FREQ 38000
75 // ir_cmd
77
92#define IR_MAP_MIKROBUS( cfg, mikrobus ) \
93 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
94 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
95 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
96 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
97 // ir_map // ir
100
105typedef enum
106{
111
116typedef struct
117{
118
119 // Input pins
120 digital_in_t an;
122 // Modules
123 uart_t uart;
124 pwm_t pwm;
126 // ctx variable
127 uint32_t pwm_freq;
129 // Buffers
130 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
131 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
135} ir_t;
136
141typedef struct
142{
143 // Communication gpio pins
144 pin_name_t rx_pin;
145 pin_name_t tx_pin;
147 // Additional gpio pins
148 pin_name_t an;
149 pin_name_t pwm;
151 // Static variable
152 uint32_t baud_rate;
154 uart_data_bits_t data_bit;
155 uart_parity_t parity_bit;
156 uart_stop_bits_t stop_bit;
158 uint32_t dev_pwm_freq;
162} ir_cfg_t;
163
168typedef enum
169{
170 IR_OK = 0,
171 IR_ERROR = -1
172
174
190void ir_cfg_setup ( ir_cfg_t *cfg );
191
207
221err_t ir_init ( ir_t *ctx, ir_cfg_t *cfg );
222
235err_t ir_generic_write ( ir_t *ctx, char *data_buf, uint16_t len );
236
249err_t ir_generic_read ( ir_t *ctx, char *data_buf, uint16_t max_len );
250
259uint8_t ir_get_an_state ( ir_t *ctx );
260
272void ir_nec_send_command ( ir_t *ctx, uint8_t address, uint8_t command );
273
287err_t ir_nec_read_command ( ir_t *ctx, uint8_t *address, uint8_t *command );
288
289#ifdef __cplusplus
290}
291#endif
292#endif // IR_H
293 // ir
295
296// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
IR driver buffer size.
Definition: ir.h:68
err_t ir_generic_read(ir_t *ctx, char *data_buf, uint16_t max_len)
IR data reading function.
err_t ir_init(ir_t *ctx, ir_cfg_t *cfg)
IR initialization function.
uint8_t ir_get_an_state(ir_t *ctx)
IR get AN pin state function.
err_t ir_nec_read_command(ir_t *ctx, uint8_t *address, uint8_t *command)
IR NEC data reading function.
void ir_nec_send_command(ir_t *ctx, uint8_t address, uint8_t command)
IR NEC send data function.
void ir_drv_interface_selection(ir_cfg_t *cfg, ir_drv_t drv_sel)
IR driver interface setup function.
err_t ir_generic_write(ir_t *ctx, char *data_buf, uint16_t len)
IR data writing function.
void ir_cfg_setup(ir_cfg_t *cfg)
IR configuration object setup function.
ir_drv_t
IR Click driver selector.
Definition: ir.h:106
@ IR_DRV_SEL_GPIO
Definition: ir.h:107
@ IR_DRV_SEL_UART
Definition: ir.h:108
ir_return_value_t
IR Click return value data.
Definition: ir.h:169
@ IR_OK
Definition: ir.h:170
@ IR_ERROR
Definition: ir.h:171
IR Click configuration object.
Definition: ir.h:142
uint32_t baud_rate
Definition: ir.h:152
bool uart_blocking
Definition: ir.h:153
uart_data_bits_t data_bit
Definition: ir.h:154
pin_name_t tx_pin
Definition: ir.h:145
uint32_t dev_pwm_freq
Definition: ir.h:158
pin_name_t rx_pin
Definition: ir.h:144
ir_drv_t drv_sel
Definition: ir.h:160
uart_stop_bits_t stop_bit
Definition: ir.h:156
pin_name_t pwm
Definition: ir.h:149
uart_parity_t parity_bit
Definition: ir.h:155
pin_name_t an
Definition: ir.h:148
IR Click context object.
Definition: ir.h:117
uint32_t pwm_freq
Definition: ir.h:127
uart_t uart
Definition: ir.h:123
digital_in_t an
Definition: ir.h:120
ir_drv_t drv_sel
Definition: ir.h:133
pwm_t pwm
Definition: ir.h:124