irda4  2.1.0.0
irda4.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 IRDA4_H
29 #define IRDA4_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 
69 #define IRDA4_SHUTDOWN_DISABLED 0x00
70 #define IRDA4_SHUTDOWN_ENABLED 0x01
71 
76 #define IRDA4_RESET_DISABLED 0x00
77 #define IRDA4_RESET_ENABLED 0x01
78 
83 #define IRDA4_DRV_BUFFER_SIZE 300
84  // irda4_cmd
86 
101 #define IRDA4_MAP_MIKROBUS( cfg, mikrobus ) \
102  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
103  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
104  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
105  cfg.sd = MIKROBUS( mikrobus, MIKROBUS_PWM );
106  // irda4_map // irda4
109 
114 typedef struct
115 {
116  // Output pins
117  digital_out_t rst;
118  digital_out_t sd;
120  // Modules
121  uart_t uart;
123  // Buffers
124  uint8_t uart_rx_buffer[ IRDA4_DRV_BUFFER_SIZE ];
125  uint8_t uart_tx_buffer[ IRDA4_DRV_BUFFER_SIZE ];
127 } irda4_t;
128 
133 typedef struct
134 {
135  // Communication gpio pins
136  pin_name_t rx_pin;
137  pin_name_t tx_pin;
139  // Additional gpio pins
140  pin_name_t rst;
141  pin_name_t sd;
143  // Static variable
144  uint32_t baud_rate;
146  uart_data_bits_t data_bit;
147  uart_parity_t parity_bit;
148  uart_stop_bits_t stop_bit;
150 } irda4_cfg_t;
151 
156 typedef enum
157 {
158  IRDA4_OK = 0,
159  IRDA4_ERROR = -1
160 
162 
179 
193 err_t irda4_init ( irda4_t *ctx, irda4_cfg_t *cfg );
194 
207 err_t irda4_generic_write ( irda4_t *ctx, uint8_t *data_in, uint16_t len );
208 
221 err_t irda4_generic_read ( irda4_t *ctx, uint8_t *data_out, uint16_t len );
222 
232 void irda4_set_tx_shutdown ( irda4_t *ctx, uint8_t sd_state );
233 
243 void irda4_set_reset_state ( irda4_t *ctx, uint8_t rst_state );
244 
253 void irda_hw_reset ( irda4_t *ctx );
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 #endif // IRDA4_H
259  // irda4
261 
262 // ------------------------------------------------------------------------ END
IRDA4_OK
@ IRDA4_OK
Definition: irda4.h:158
irda4_generic_write
err_t irda4_generic_write(irda4_t *ctx, uint8_t *data_in, uint16_t len)
IrDA 4 data writing function.
IRDA4_DRV_BUFFER_SIZE
#define IRDA4_DRV_BUFFER_SIZE
IrDA 4 driver buffer size.
Definition: irda4.h:83
irda4_cfg_t::sd
pin_name_t sd
Definition: irda4.h:141
irda4_cfg_t::uart_blocking
bool uart_blocking
Definition: irda4.h:145
irda4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: irda4.h:137
irda4_generic_read
err_t irda4_generic_read(irda4_t *ctx, uint8_t *data_out, uint16_t len)
IrDA 4 data reading function.
irda4_t::sd
digital_out_t sd
Definition: irda4.h:118
IRDA4_ERROR
@ IRDA4_ERROR
Definition: irda4.h:159
irda_hw_reset
void irda_hw_reset(irda4_t *ctx)
IrDA 4 hardware reset function.
irda4_cfg_setup
void irda4_cfg_setup(irda4_cfg_t *cfg)
IrDA 4 configuration object setup function.
irda4_cfg_t::baud_rate
uint32_t baud_rate
Definition: irda4.h:144
irda4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: irda4.h:148
irda4_return_value_t
irda4_return_value_t
IrDA 4 Click return value data.
Definition: irda4.h:157
irda4_set_reset_state
void irda4_set_reset_state(irda4_t *ctx, uint8_t rst_state)
IrDA 4 set reset pin state function.
irda4_cfg_t::rst
pin_name_t rst
Definition: irda4.h:140
irda4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: irda4.h:147
irda4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: irda4.h:146
irda4_cfg_t
IrDA 4 Click configuration object.
Definition: irda4.h:134
irda4_t::rst
digital_out_t rst
Definition: irda4.h:117
irda4_init
err_t irda4_init(irda4_t *ctx, irda4_cfg_t *cfg)
IrDA 4 initialization function.
irda4_t
IrDA 4 Click context object.
Definition: irda4.h:115
irda4_set_tx_shutdown
void irda4_set_tx_shutdown(irda4_t *ctx, uint8_t sd_state)
IrDA 4 TX shutdown function.
irda4_t::uart
uart_t uart
Definition: irda4.h:121
irda4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: irda4.h:136