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 
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_uart.h"
48 #include "drv_pwm.h"
49 
70 #define IR_STATE_HIGH 0x01
71 #define IR_STATE_LOW 0x00
72 
78 #define DRV_BUFFER_SIZE 200
79 
84 #define IR_DEF_FREQ 38000
85  // ir_cmd
87 
102 #define IR_MAP_MIKROBUS( cfg, mikrobus ) \
103  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
104  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
105  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
106  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
107  // ir_map // ir
110 
115 typedef enum
116 {
121 
126 typedef struct
127 {
128 
129  // Input pins
130  digital_in_t an;
132  // Modules
133  uart_t uart;
134  pwm_t pwm;
136  // ctx variable
137  uint32_t pwm_freq;
139  // Buffers
140  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
141  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
145 } ir_t;
146 
151 typedef struct
152 {
153  // Communication gpio pins
154  pin_name_t rx_pin;
155  pin_name_t tx_pin;
157  // Additional gpio pins
158  pin_name_t an;
159  pin_name_t pwm;
161  // Static variable
162  uint32_t baud_rate;
164  uart_data_bits_t data_bit;
165  uart_parity_t parity_bit;
166  uart_stop_bits_t stop_bit;
168  uint32_t dev_pwm_freq;
172 } ir_cfg_t;
173 
178 typedef enum
179 {
180  IR_OK = 0,
181  IR_ERROR = -1
182 
184 
200 void ir_cfg_setup ( ir_cfg_t *cfg );
201 
217 
231 err_t ir_init ( ir_t *ctx, ir_cfg_t *cfg );
232 
245 err_t ir_generic_write ( ir_t *ctx, char *data_buf, uint16_t len );
246 
259 err_t ir_generic_read ( ir_t *ctx, char *data_buf, uint16_t max_len );
260 
269 uint8_t ir_get_an_state ( ir_t *ctx );
270 
282 void ir_nec_send_command ( ir_t *ctx, uint8_t address, uint8_t command );
283 
297 err_t ir_nec_read_command ( ir_t *ctx, uint8_t *address, uint8_t *command );
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 #endif // IR_H
303  // ir
305 
306 // ------------------------------------------------------------------------ END
ir_cfg_t::uart_blocking
bool uart_blocking
Definition: ir.h:163
ir_cfg_t
IR Click configuration object.
Definition: ir.h:152
ir_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ir.h:166
ir_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ir.h:165
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:162
ir_t::an
digital_in_t an
Definition: ir.h:130
ir_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: ir.h:168
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
IR driver buffer size.
Definition: ir.h:78
ir_cfg_t::drv_sel
ir_drv_t drv_sel
Definition: ir.h:170
IR_DRV_SEL_UART
@ IR_DRV_SEL_UART
Definition: ir.h:118
ir_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ir.h:164
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:134
ir_t
IR Click context object.
Definition: ir.h:127
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:117
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:155
ir_cfg_t::an
pin_name_t an
Definition: ir.h:158
ir_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ir.h:154
ir_t::pwm_freq
uint32_t pwm_freq
Definition: ir.h:137
ir_cfg_t::pwm
pin_name_t pwm
Definition: ir.h:159
ir_return_value_t
ir_return_value_t
IR Click return value data.
Definition: ir.h:179
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:143
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:181
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:116
IR_OK
@ IR_OK
Definition: ir.h:180
ir_t::uart
uart_t uart
Definition: ir.h:133
ir_nec_read_command
err_t ir_nec_read_command(ir_t *ctx, uint8_t *address, uint8_t *command)
IR NEC data reading function.