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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define IRDA4_SHUTDOWN_DISABLED 0x00
60 #define IRDA4_SHUTDOWN_ENABLED 0x01
61 
66 #define IRDA4_RESET_DISABLED 0x00
67 #define IRDA4_RESET_ENABLED 0x01
68 
73 #define IRDA4_DRV_BUFFER_SIZE 300
74  // irda4_cmd
76 
91 #define IRDA4_MAP_MIKROBUS( cfg, mikrobus ) \
92  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
93  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
94  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
95  cfg.sd = MIKROBUS( mikrobus, MIKROBUS_PWM );
96  // irda4_map // irda4
99 
104 typedef struct
105 {
106  // Output pins
107  digital_out_t rst;
108  digital_out_t sd;
110  // Modules
111  uart_t uart;
113  // Buffers
114  uint8_t uart_rx_buffer[ IRDA4_DRV_BUFFER_SIZE ];
115  uint8_t uart_tx_buffer[ IRDA4_DRV_BUFFER_SIZE ];
117 } irda4_t;
118 
123 typedef struct
124 {
125  // Communication gpio pins
126  pin_name_t rx_pin;
127  pin_name_t tx_pin;
129  // Additional gpio pins
130  pin_name_t rst;
131  pin_name_t sd;
133  // Static variable
134  uint32_t baud_rate;
136  uart_data_bits_t data_bit;
137  uart_parity_t parity_bit;
138  uart_stop_bits_t stop_bit;
140 } irda4_cfg_t;
141 
146 typedef enum
147 {
148  IRDA4_OK = 0,
149  IRDA4_ERROR = -1
150 
152 
169 
183 err_t irda4_init ( irda4_t *ctx, irda4_cfg_t *cfg );
184 
197 err_t irda4_generic_write ( irda4_t *ctx, uint8_t *data_in, uint16_t len );
198 
211 err_t irda4_generic_read ( irda4_t *ctx, uint8_t *data_out, uint16_t len );
212 
222 void irda4_set_tx_shutdown ( irda4_t *ctx, uint8_t sd_state );
223 
233 void irda4_set_reset_state ( irda4_t *ctx, uint8_t rst_state );
234 
243 void irda_hw_reset ( irda4_t *ctx );
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 #endif // IRDA4_H
249  // irda4
251 
252 // ------------------------------------------------------------------------ END
IRDA4_OK
@ IRDA4_OK
Definition: irda4.h:148
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:73
irda4_cfg_t::sd
pin_name_t sd
Definition: irda4.h:131
irda4_cfg_t::uart_blocking
bool uart_blocking
Definition: irda4.h:135
irda4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: irda4.h:127
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:108
IRDA4_ERROR
@ IRDA4_ERROR
Definition: irda4.h:149
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:134
irda4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: irda4.h:138
irda4_return_value_t
irda4_return_value_t
IrDA 4 Click return value data.
Definition: irda4.h:147
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:130
irda4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: irda4.h:137
irda4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: irda4.h:136
irda4_cfg_t
IrDA 4 Click configuration object.
Definition: irda4.h:124
irda4_t::rst
digital_out_t rst
Definition: irda4.h:107
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:105
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:111
irda4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: irda4.h:126