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 
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 
73 #define IRDA4_SHUTDOWN_DISABLED 0x00
74 #define IRDA4_SHUTDOWN_ENABLED 0x01
75 
80 #define IRDA4_RESET_DISABLED 0x00
81 #define IRDA4_RESET_ENABLED 0x01
82 
87 #define IRDA4_DRV_BUFFER_SIZE 300
88  // irda4_cmd
90 
105 #define IRDA4_MAP_MIKROBUS( cfg, mikrobus ) \
106  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
107  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
108  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
109  cfg.sd = MIKROBUS( mikrobus, MIKROBUS_PWM );
110  // irda4_map // irda4
113 
118 typedef struct
119 {
120  // Output pins
121  digital_out_t rst;
122  digital_out_t sd;
124  // Modules
125  uart_t uart;
127  // Buffers
128  uint8_t uart_rx_buffer[ IRDA4_DRV_BUFFER_SIZE ];
129  uint8_t uart_tx_buffer[ IRDA4_DRV_BUFFER_SIZE ];
131 } irda4_t;
132 
137 typedef struct
138 {
139  // Communication gpio pins
140  pin_name_t rx_pin;
141  pin_name_t tx_pin;
143  // Additional gpio pins
144  pin_name_t rst;
145  pin_name_t sd;
147  // Static variable
148  uint32_t baud_rate;
150  uart_data_bits_t data_bit;
151  uart_parity_t parity_bit;
152  uart_stop_bits_t stop_bit;
154 } irda4_cfg_t;
155 
160 typedef enum
161 {
162  IRDA4_OK = 0,
163  IRDA4_ERROR = -1
164 
166 
183 
197 err_t irda4_init ( irda4_t *ctx, irda4_cfg_t *cfg );
198 
211 err_t irda4_generic_write ( irda4_t *ctx, uint8_t *data_in, uint16_t len );
212 
225 err_t irda4_generic_read ( irda4_t *ctx, uint8_t *data_out, uint16_t len );
226 
236 void irda4_set_tx_shutdown ( irda4_t *ctx, uint8_t sd_state );
237 
247 void irda4_set_reset_state ( irda4_t *ctx, uint8_t rst_state );
248 
257 void irda_hw_reset ( irda4_t *ctx );
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 #endif // IRDA4_H
263  // irda4
265 
266 // ------------------------------------------------------------------------ END
IRDA4_OK
@ IRDA4_OK
Definition: irda4.h:162
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:87
irda4_cfg_t::sd
pin_name_t sd
Definition: irda4.h:145
irda4_cfg_t::uart_blocking
bool uart_blocking
Definition: irda4.h:149
irda4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: irda4.h:141
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:122
IRDA4_ERROR
@ IRDA4_ERROR
Definition: irda4.h:163
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:148
irda4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: irda4.h:152
irda4_return_value_t
irda4_return_value_t
IrDA 4 Click return value data.
Definition: irda4.h:161
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:144
irda4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: irda4.h:151
irda4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: irda4.h:150
irda4_cfg_t
IrDA 4 Click configuration object.
Definition: irda4.h:138
irda4_t::rst
digital_out_t rst
Definition: irda4.h:121
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:119
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:125
irda4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: irda4.h:140