rstransceiver 2.1.0.0
rstransceiver.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 RSTRANSCEIVER_H
29#define RSTRANSCEIVER_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_i2c_master.h"
52#include "drv_uart.h"
53
74#define RSTRANSCEIVER_REG_INPUT_PORT 0x00
75#define RSTRANSCEIVER_REG_OUTPUT_PORT 0x01
76#define RSTRANSCEIVER_REG_POLARITY_INV 0x02
77#define RSTRANSCEIVER_REG_CONFIG 0x03
78#define RSTRANSCEIVER_REG_SPECIAL_FUNC 0x50
79
80 // rstransceiver_reg
81
96#define RSTRANSCEIVER_NO_PIN_BIT_MASK 0x00
97#define RSTRANSCEIVER_PIN_0_BIT_MASK 0x01
98#define RSTRANSCEIVER_PIN_1_BIT_MASK 0x02
99#define RSTRANSCEIVER_PIN_2_BIT_MASK 0x04
100#define RSTRANSCEIVER_PIN_3_BIT_MASK 0x08
101#define RSTRANSCEIVER_ALL_PINS_BIT_MASK 0x0F
102
107#define RSTRANSCEIVER_OUTPUT_DIRECTION 0x00
108#define RSTRANSCEIVER_INPUT_DIRECTION 0x01
109
114#define RSTRANSCEIVER_SPECIAL_FUNC_P3_AS_INT 0x80
115#define RSTRANSCEIVER_SPECIAL_FUNC_PU_DISABLED 0x40
116
121#define RSTRANSCEIVER_SLEW_DISABLE 0x00
122#define RSTRANSCEIVER_SLEW_ENABLE 0x01
123
128#define RSTRANSCEIVER_OP_MODE_LOOPBACK 0x00
129#define RSTRANSCEIVER_OP_MODE_RS232 0x01
130#define RSTRANSCEIVER_OP_MODE_HALF_DUPLEX 0x02
131#define RSTRANSCEIVER_OP_MODE_FULL_DUPLEX 0x03
132#define RSTRANSCEIVER_OP_MODE_PIN_BIT_MASK 0x09
133
138#define RSTRANSCEIVER_DIR_DISABLE 0x00
139#define RSTRANSCEIVER_DIR_T1_EN 0x01
140#define RSTRANSCEIVER_DIR_T1_EN_R1_DIS 0x01
141#define RSTRANSCEIVER_DIR_PIN_BIT_MASK 0x0E
142
147#define RSTRANSCEIVER_TERM_DISABLE 0x00
148#define RSTRANSCEIVER_TERM_ENABLE 0x01
149#define RSTRANSCEIVER_TERM_DIS_PIN_BIT_MASK 0x07
150#define RSTRANSCEIVER_TERM_EN_PIN_BIT_MASK 0x08
151
157#define RSTRANSCEIVER_TX_DRV_BUFFER_SIZE 100
158#define RSTRANSCEIVER_RX_DRV_BUFFER_SIZE 300
159
165#define RSTRANSCEIVER_DEVICE_ADDRESS 0x41
166
167 // rstransceiver_set
168
183#define RSTRANSCEIVER_MAP_MIKROBUS( cfg, mikrobus ) \
184 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
185 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
186 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
187 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
188 cfg.slw = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
189 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
190 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
191 cfg.cst = MIKROBUS( mikrobus, MIKROBUS_INT )
192
193 // rstransceiver_map
194 // rstransceiver
195
200typedef struct
201{
202 // Output pins
203 digital_out_t cs;
204 digital_out_t rst;
205 digital_out_t slw;
207 // Input pins
208 digital_in_t cst;
210 // Modules
211 i2c_master_t i2c;
212 uart_t uart;
214 // I2C slave address
217 // Buffers
218 char uart_rx_buffer[ RSTRANSCEIVER_RX_DRV_BUFFER_SIZE ];
219 char uart_tx_buffer[ RSTRANSCEIVER_TX_DRV_BUFFER_SIZE ];
222
227typedef struct
228{
229 pin_name_t scl;
230 pin_name_t sda;
231 pin_name_t rx_pin;
232 pin_name_t tx_pin;
234 pin_name_t cs;
235 pin_name_t rst;
236 pin_name_t slw;
237 pin_name_t cst;
239 uint32_t i2c_speed;
240 uint8_t i2c_address;
242 // Static variable
243 uint32_t baud_rate;
245 uart_data_bits_t data_bit;
246 uart_parity_t parity_bit;
247 uart_stop_bits_t stop_bit;
250
261
278
293
307
320
333
348void rstransceiver_set_slew ( rstransceiver_t *ctx, uint8_t slew );
349
362void rstransceiver_set_rts ( rstransceiver_t *ctx, uint8_t rts );
363
376
395err_t rstransceiver_set_op_mode ( rstransceiver_t *ctx, uint8_t op_mode );
396
411
428err_t rstransceiver_mode_rs232 ( rstransceiver_t *ctx, uint8_t slew );
429
449err_t rstransceiver_mode_half_duplex ( rstransceiver_t *ctx, uint8_t slew, uint8_t dir1, uint8_t term );
450
470err_t rstransceiver_mode_full_duplex ( rstransceiver_t *ctx, uint8_t slew, uint8_t dir1, uint8_t term );
471
488err_t rstransceiver_set_dir1 ( rstransceiver_t *ctx, uint8_t dir1 );
489
503
517
530err_t rstransceiver_generic_write ( rstransceiver_t *ctx, char *data_in, uint16_t len );
531
544err_t rstransceiver_generic_read ( rstransceiver_t *ctx, char *data_out, uint16_t len );
545
546#ifdef __cplusplus
547}
548#endif
549#endif // RSTRANSCEIVER_H
550
551 // rstransceiver
552
553// ------------------------------------------------------------------------ END
#define RSTRANSCEIVER_TX_DRV_BUFFER_SIZE
RS Transceiver driver buffer size.
Definition rstransceiver.h:157
#define RSTRANSCEIVER_RX_DRV_BUFFER_SIZE
Definition rstransceiver.h:158
void rstransceiver_set_slew(rstransceiver_t *ctx, uint8_t slew)
RS Transceiver sets the slew limit function.
void rstransceiver_cfg_setup(rstransceiver_cfg_t *cfg)
RS Transceiver configuration object setup function.
err_t rstransceiver_mode_full_duplex(rstransceiver_t *ctx, uint8_t slew, uint8_t dir1, uint8_t term)
RS Transceiver sets the Full-Duplex mode function.
err_t rstransceiver_set_dir1(rstransceiver_t *ctx, uint8_t dir1)
RS Transceiver sets the DIR1 pin function.
err_t rstransceiver_term_enable(rstransceiver_t *ctx)
RS Transceiver term enable function.
void rstransceiver_set_rts(rstransceiver_t *ctx, uint8_t rts)
RS Transceiver request to send function.
err_t rstransceiver_generic_write(rstransceiver_t *ctx, char *data_in, uint16_t len)
RS Transceiver data writing function.
err_t rstransceiver_default_cfg(rstransceiver_t *ctx)
RS Transceiver default configuration function.
err_t rstransceiver_mode_loopback(rstransceiver_t *ctx)
RS Transceiver sets the loopback mode function.
err_t rstransceiver_set_op_mode(rstransceiver_t *ctx, uint8_t op_mode)
RS Transceiver sets the operating mode function.
void rstransceiver_device_disable(rstransceiver_t *ctx)
RS Transceiver disable the device function.
err_t rstransceiver_mode_rs232(rstransceiver_t *ctx, uint8_t slew)
RS Transceiver sets the RS-232 mode function.
err_t rstransceiver_term_disable(rstransceiver_t *ctx)
RS Transceiver term disable function.
uint8_t rstransceiver_get_cts(rstransceiver_t *ctx)
RS Transceiver clear to send function.
err_t rstransceiver_init(rstransceiver_t *ctx, rstransceiver_cfg_t *cfg)
RS Transceiver initialization function.
err_t rstransceiver_generic_read(rstransceiver_t *ctx, char *data_out, uint16_t len)
RS Transceiver data reading function.
err_t rstransceiver_mode_half_duplex(rstransceiver_t *ctx, uint8_t slew, uint8_t dir1, uint8_t term)
RS Transceiver sets the Half-Duplex mode function.
void rstransceiver_device_enable(rstransceiver_t *ctx)
RS Transceiver enables the device function.
rstransceiver_return_value_t
RS Transceiver Click return value data.
Definition rstransceiver.h:256
@ RSTRANSCEIVER_OK
Definition rstransceiver.h:257
@ RSTRANSCEIVER_ERROR
Definition rstransceiver.h:258
RS Transceiver Click configuration object.
Definition rstransceiver.h:228
uint32_t baud_rate
Definition rstransceiver.h:243
pin_name_t cst
Definition rstransceiver.h:237
uint32_t i2c_speed
Definition rstransceiver.h:239
bool uart_blocking
Definition rstransceiver.h:244
uart_data_bits_t data_bit
Definition rstransceiver.h:245
pin_name_t tx_pin
Definition rstransceiver.h:232
pin_name_t slw
Definition rstransceiver.h:236
pin_name_t rx_pin
Definition rstransceiver.h:231
uart_stop_bits_t stop_bit
Definition rstransceiver.h:247
pin_name_t scl
Definition rstransceiver.h:229
uart_parity_t parity_bit
Definition rstransceiver.h:246
pin_name_t sda
Definition rstransceiver.h:230
pin_name_t rst
Definition rstransceiver.h:235
pin_name_t cs
Definition rstransceiver.h:234
uint8_t i2c_address
Definition rstransceiver.h:240
RS Transceiver Click context object.
Definition rstransceiver.h:201
digital_out_t cs
Definition rstransceiver.h:203
uart_t uart
Definition rstransceiver.h:212
i2c_master_t i2c
Definition rstransceiver.h:211
digital_out_t rst
Definition rstransceiver.h:204
uint8_t slave_address
Definition rstransceiver.h:215
digital_out_t slw
Definition rstransceiver.h:205
digital_in_t cst
Definition rstransceiver.h:208