duallin 2.0.0.0
duallin.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef DUALLIN_H
36#define DUALLIN_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define DUALLIN_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.en1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.en2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define DUALLIN_RETVAL uint8_t
79
80#define DUALLIN_OK 0x00
81#define DUALLIN_INIT_ERROR 0xFF
88#define DUALLIN_PIN_STATE_LOW 0
89#define DUALLIN_PIN_STATE_HIGH 1
96#define DRV_RX_BUFFER_SIZE 500
99 // End group macro
100// --------------------------------------------------------------- PUBLIC TYPES
108typedef struct
109{
110 // Output pins
111
112 digital_out_t en1;
113 digital_out_t en2;
114
115
116 // Input pins
117
118 digital_in_t int_pin;
119
120 // Modules
121
122 uart_t uart;
123
124 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
125 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
126
127} duallin_t;
128
132typedef struct
133{
134 // Communication gpio pins
135
136 pin_name_t rx_pin;
137 pin_name_t tx_pin;
138
139 // Additional gpio pins
140
141 pin_name_t en1;
142 pin_name_t en2;
143 pin_name_t int_pin;
144
145 // static variable
146
147 uint32_t baud_rate; // Clock speed.
149 uart_data_bits_t data_bit; // Data bits.
150 uart_parity_t parity_bit; // Parity bit.
151 uart_stop_bits_t stop_bit; // Stop bits.
152
154
158typedef uint8_t duallin_error_t;
159
160 // End types group
161// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162
168#ifdef __cplusplus
169extern "C"{
170#endif
171
181
191
199void duallin_generic_write ( duallin_t *ctx, char *data_buf, uint16_t len );
200
210int16_t duallin_generic_read ( duallin_t *ctx, char *data_buf, uint16_t max_len );
211
218void duallin_bus1_status ( duallin_t *ctx, uint8_t state );
219
226void duallin_bus2_status ( duallin_t *ctx, uint8_t state );
227
234void duallin_send_command ( duallin_t *ctx, char *command );
235
236#ifdef __cplusplus
237}
238#endif
239#endif // _DUALLIN_H_
240
241 // End public_function group
243
244// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition duallin.h:96
#define DUALLIN_RETVAL
Definition duallin.h:78
DUALLIN_RETVAL duallin_init(duallin_t *ctx, duallin_cfg_t *cfg)
Initialization function.
void duallin_send_command(duallin_t *ctx, char *command)
Send command.
void duallin_bus1_status(duallin_t *ctx, uint8_t state)
Sets state of RST pin.
int16_t duallin_generic_read(duallin_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void duallin_generic_write(duallin_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void duallin_bus2_status(duallin_t *ctx, uint8_t state)
Sets state of CS pin.
void duallin_cfg_setup(duallin_cfg_t *cfg)
Config Object Initialization function.
uint8_t duallin_error_t
Error type.
Definition duallin.h:158
Click configuration structure definition.
Definition duallin.h:133
pin_name_t en2
Definition duallin.h:142
uint32_t baud_rate
Definition duallin.h:147
bool uart_blocking
Definition duallin.h:148
uart_data_bits_t data_bit
Definition duallin.h:149
pin_name_t en1
Definition duallin.h:141
pin_name_t tx_pin
Definition duallin.h:137
pin_name_t rx_pin
Definition duallin.h:136
uart_stop_bits_t stop_bit
Definition duallin.h:151
pin_name_t int_pin
Definition duallin.h:143
uart_parity_t parity_bit
Definition duallin.h:150
Click ctx object definition.
Definition duallin.h:109
digital_out_t en2
Definition duallin.h:113
digital_out_t en1
Definition duallin.h:112
uart_t uart
Definition duallin.h:122
digital_in_t int_pin
Definition duallin.h:118