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
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_i2c_master.h"
48 #include "drv_uart.h"
49 
70 #define RSTRANSCEIVER_REG_INPUT_PORT 0x00
71 #define RSTRANSCEIVER_REG_OUTPUT_PORT 0x01
72 #define RSTRANSCEIVER_REG_POLARITY_INV 0x02
73 #define RSTRANSCEIVER_REG_CONFIG 0x03
74 #define RSTRANSCEIVER_REG_SPECIAL_FUNC 0x50
75  // rstransceiver_reg
77 
92 #define RSTRANSCEIVER_NO_PIN_BIT_MASK 0x00
93 #define RSTRANSCEIVER_PIN_0_BIT_MASK 0x01
94 #define RSTRANSCEIVER_PIN_1_BIT_MASK 0x02
95 #define RSTRANSCEIVER_PIN_2_BIT_MASK 0x04
96 #define RSTRANSCEIVER_PIN_3_BIT_MASK 0x08
97 #define RSTRANSCEIVER_ALL_PINS_BIT_MASK 0x0F
98 
103 #define RSTRANSCEIVER_OUTPUT_DIRECTION 0x00
104 #define RSTRANSCEIVER_INPUT_DIRECTION 0x01
105 
110 #define RSTRANSCEIVER_SPECIAL_FUNC_P3_AS_INT 0x80
111 #define RSTRANSCEIVER_SPECIAL_FUNC_PU_DISABLED 0x40
112 
117 #define RSTRANSCEIVER_SLEW_DISABLE 0x00
118 #define RSTRANSCEIVER_SLEW_ENABLE 0x01
119 
124 #define RSTRANSCEIVER_OP_MODE_LOOPBACK 0x00
125 #define RSTRANSCEIVER_OP_MODE_RS232 0x01
126 #define RSTRANSCEIVER_OP_MODE_HALF_DUPLEX 0x02
127 #define RSTRANSCEIVER_OP_MODE_FULL_DUPLEX 0x03
128 #define RSTRANSCEIVER_OP_MODE_PIN_BIT_MASK 0x09
129 
134 #define RSTRANSCEIVER_DIR_DISABLE 0x00
135 #define RSTRANSCEIVER_DIR_T1_EN 0x01
136 #define RSTRANSCEIVER_DIR_T1_EN_R1_DIS 0x01
137 #define RSTRANSCEIVER_DIR_PIN_BIT_MASK 0x0E
138 
143 #define RSTRANSCEIVER_TERM_DISABLE 0x00
144 #define RSTRANSCEIVER_TERM_ENABLE 0x01
145 #define RSTRANSCEIVER_TERM_DIS_PIN_BIT_MASK 0x07
146 #define RSTRANSCEIVER_TERM_EN_PIN_BIT_MASK 0x08
147 
153 #define RSTRANSCEIVER_TX_DRV_BUFFER_SIZE 100
154 #define RSTRANSCEIVER_RX_DRV_BUFFER_SIZE 300
155 
161 #define RSTRANSCEIVER_DEVICE_ADDRESS 0x41
162  // rstransceiver_set
164 
179 #define RSTRANSCEIVER_MAP_MIKROBUS( cfg, mikrobus ) \
180  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
181  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
182  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
183  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
184  cfg.slw = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
185  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
186  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
187  cfg.cst = MIKROBUS( mikrobus, MIKROBUS_INT )
188  // rstransceiver_map // rstransceiver
191 
196 typedef struct
197 {
198  // Output pins
199  digital_out_t cs;
200  digital_out_t rst;
201  digital_out_t slw;
203  // Input pins
204  digital_in_t cst;
206  // Modules
207  i2c_master_t i2c;
208  uart_t uart;
210  // I2C slave address
211  uint8_t slave_address;
213  // Buffers
214  char uart_rx_buffer[ RSTRANSCEIVER_RX_DRV_BUFFER_SIZE ];
215  char uart_tx_buffer[ RSTRANSCEIVER_TX_DRV_BUFFER_SIZE ];
218 
223 typedef struct
224 {
225  pin_name_t scl;
226  pin_name_t sda;
227  pin_name_t rx_pin;
228  pin_name_t tx_pin;
230  pin_name_t cs;
231  pin_name_t rst;
232  pin_name_t slw;
233  pin_name_t cst;
235  uint32_t i2c_speed;
236  uint8_t i2c_address;
238  // Static variable
239  uint32_t baud_rate;
241  uart_data_bits_t data_bit;
242  uart_parity_t parity_bit;
243  uart_stop_bits_t stop_bit;
246 
251 typedef enum
252 {
255 
257 
274 
289 
303 
316 
329 
344 void rstransceiver_set_slew ( rstransceiver_t *ctx, uint8_t slew );
345 
358 void rstransceiver_set_rts ( rstransceiver_t *ctx, uint8_t rts );
359 
372 
391 err_t rstransceiver_set_op_mode ( rstransceiver_t *ctx, uint8_t op_mode );
392 
407 
424 err_t rstransceiver_mode_rs232 ( rstransceiver_t *ctx, uint8_t slew );
425 
445 err_t rstransceiver_mode_half_duplex ( rstransceiver_t *ctx, uint8_t slew, uint8_t dir1, uint8_t term );
446 
466 err_t rstransceiver_mode_full_duplex ( rstransceiver_t *ctx, uint8_t slew, uint8_t dir1, uint8_t term );
467 
484 err_t rstransceiver_set_dir1 ( rstransceiver_t *ctx, uint8_t dir1 );
485 
499 
513 
526 err_t rstransceiver_generic_write ( rstransceiver_t *ctx, char *data_in, uint16_t len );
527 
540 err_t rstransceiver_generic_read ( rstransceiver_t *ctx, char *data_out, uint16_t len );
541 
542 #ifdef __cplusplus
543 }
544 #endif
545 #endif // RSTRANSCEIVER_H
546  // rstransceiver
548 
549 // ------------------------------------------------------------------------ END
rstransceiver_mode_loopback
err_t rstransceiver_mode_loopback(rstransceiver_t *ctx)
RS Transceiver sets the loopback mode function.
rstransceiver_device_disable
void rstransceiver_device_disable(rstransceiver_t *ctx)
RS Transceiver disable the device function.
rstransceiver_set_op_mode
err_t rstransceiver_set_op_mode(rstransceiver_t *ctx, uint8_t op_mode)
RS Transceiver sets the operating mode function.
rstransceiver_mode_full_duplex
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.
rstransceiver_return_value_t
rstransceiver_return_value_t
RS Transceiver Click return value data.
Definition: rstransceiver.h:252
rstransceiver_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rstransceiver.h:227
rstransceiver_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rstransceiver.h:228
rstransceiver_cfg_t::sda
pin_name_t sda
Definition: rstransceiver.h:226
rstransceiver_t
RS Transceiver Click context object.
Definition: rstransceiver.h:197
rstransceiver_cfg_t::slw
pin_name_t slw
Definition: rstransceiver.h:232
rstransceiver_cfg_t::baud_rate
uint32_t baud_rate
Definition: rstransceiver.h:239
RSTRANSCEIVER_TX_DRV_BUFFER_SIZE
#define RSTRANSCEIVER_TX_DRV_BUFFER_SIZE
RS Transceiver driver buffer size.
Definition: rstransceiver.h:153
rstransceiver_cfg_t::i2c_address
uint8_t i2c_address
Definition: rstransceiver.h:236
rstransceiver_t::uart
uart_t uart
Definition: rstransceiver.h:208
rstransceiver_generic_read
err_t rstransceiver_generic_read(rstransceiver_t *ctx, char *data_out, uint16_t len)
RS Transceiver data reading function.
rstransceiver_t::i2c
i2c_master_t i2c
Definition: rstransceiver.h:207
rstransceiver_generic_write
err_t rstransceiver_generic_write(rstransceiver_t *ctx, char *data_in, uint16_t len)
RS Transceiver data writing function.
rstransceiver_cfg_t::cs
pin_name_t cs
Definition: rstransceiver.h:230
rstransceiver_mode_rs232
err_t rstransceiver_mode_rs232(rstransceiver_t *ctx, uint8_t slew)
RS Transceiver sets the RS-232 mode function.
rstransceiver_cfg_t
RS Transceiver Click configuration object.
Definition: rstransceiver.h:224
rstransceiver_t::cst
digital_in_t cst
Definition: rstransceiver.h:204
RSTRANSCEIVER_RX_DRV_BUFFER_SIZE
#define RSTRANSCEIVER_RX_DRV_BUFFER_SIZE
Definition: rstransceiver.h:154
rstransceiver_term_disable
err_t rstransceiver_term_disable(rstransceiver_t *ctx)
RS Transceiver term disable function.
rstransceiver_term_enable
err_t rstransceiver_term_enable(rstransceiver_t *ctx)
RS Transceiver term enable function.
rstransceiver_t::rst
digital_out_t rst
Definition: rstransceiver.h:200
rstransceiver_set_dir1
err_t rstransceiver_set_dir1(rstransceiver_t *ctx, uint8_t dir1)
RS Transceiver sets the DIR1 pin function.
RSTRANSCEIVER_ERROR
@ RSTRANSCEIVER_ERROR
Definition: rstransceiver.h:254
rstransceiver_t::slave_address
uint8_t slave_address
Definition: rstransceiver.h:211
rstransceiver_t::cs
digital_out_t cs
Definition: rstransceiver.h:199
rstransceiver_device_enable
void rstransceiver_device_enable(rstransceiver_t *ctx)
RS Transceiver enables the device function.
rstransceiver_cfg_t::uart_blocking
bool uart_blocking
Definition: rstransceiver.h:240
rstransceiver_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rstransceiver.h:241
rstransceiver_t::slw
digital_out_t slw
Definition: rstransceiver.h:201
rstransceiver_cfg_t::rst
pin_name_t rst
Definition: rstransceiver.h:231
rstransceiver_mode_half_duplex
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.
rstransceiver_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rstransceiver.h:243
rstransceiver_cfg_t::scl
pin_name_t scl
Definition: rstransceiver.h:225
rstransceiver_set_slew
void rstransceiver_set_slew(rstransceiver_t *ctx, uint8_t slew)
RS Transceiver sets the slew limit function.
RSTRANSCEIVER_OK
@ RSTRANSCEIVER_OK
Definition: rstransceiver.h:253
rstransceiver_cfg_setup
void rstransceiver_cfg_setup(rstransceiver_cfg_t *cfg)
RS Transceiver configuration object setup function.
rstransceiver_default_cfg
err_t rstransceiver_default_cfg(rstransceiver_t *ctx)
RS Transceiver default configuration function.
rstransceiver_get_cts
uint8_t rstransceiver_get_cts(rstransceiver_t *ctx)
RS Transceiver clear to send function.
rstransceiver_init
err_t rstransceiver_init(rstransceiver_t *ctx, rstransceiver_cfg_t *cfg)
RS Transceiver initialization function.
rstransceiver_cfg_t::cst
pin_name_t cst
Definition: rstransceiver.h:233
rstransceiver_set_rts
void rstransceiver_set_rts(rstransceiver_t *ctx, uint8_t rts)
RS Transceiver request to send function.
rstransceiver_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rstransceiver.h:242
rstransceiver_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rstransceiver.h:235