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
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
90 // 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
112 // ir_map
113 // ir
114
125
130typedef 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
155typedef 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
182typedef enum
183{
184 IR_OK = 0,
185 IR_ERROR = -1
186
188
204void ir_cfg_setup ( ir_cfg_t *cfg );
205
221
235err_t ir_init ( ir_t *ctx, ir_cfg_t *cfg );
236
249err_t ir_generic_write ( ir_t *ctx, char *data_buf, uint16_t len );
250
263err_t ir_generic_read ( ir_t *ctx, char *data_buf, uint16_t max_len );
264
273uint8_t ir_get_an_state ( ir_t *ctx );
274
286void ir_nec_send_command ( ir_t *ctx, uint8_t address, uint8_t command );
287
301err_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
308 // ir
309
310// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
IR driver buffer size.
Definition ir.h:82
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:120
@ IR_DRV_SEL_GPIO
Definition ir.h:121
@ IR_DRV_SEL_UART
Definition ir.h:122
ir_return_value_t
IR Click return value data.
Definition ir.h:183
@ IR_OK
Definition ir.h:184
@ IR_ERROR
Definition ir.h:185
IR Click configuration object.
Definition ir.h:156
uint32_t baud_rate
Definition ir.h:166
bool uart_blocking
Definition ir.h:167
uart_data_bits_t data_bit
Definition ir.h:168
pin_name_t tx_pin
Definition ir.h:159
uint32_t dev_pwm_freq
Definition ir.h:172
pin_name_t rx_pin
Definition ir.h:158
ir_drv_t drv_sel
Definition ir.h:174
uart_stop_bits_t stop_bit
Definition ir.h:170
pin_name_t pwm
Definition ir.h:163
uart_parity_t parity_bit
Definition ir.h:169
pin_name_t an
Definition ir.h:162
IR Click context object.
Definition ir.h:131
uint32_t pwm_freq
Definition ir.h:141
uart_t uart
Definition ir.h:137
digital_in_t an
Definition ir.h:134
ir_drv_t drv_sel
Definition ir.h:147
pwm_t pwm
Definition ir.h:138