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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define DUALLIN_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.en1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.en2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define DUALLIN_RETVAL uint8_t
75 
76 #define DUALLIN_OK 0x00
77 #define DUALLIN_INIT_ERROR 0xFF
78 
84 #define DUALLIN_PIN_STATE_LOW 0
85 #define DUALLIN_PIN_STATE_HIGH 1
86 
92 #define DRV_RX_BUFFER_SIZE 500
93  // End group macro
96 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106  // Output pins
107 
108  digital_out_t en1;
109  digital_out_t en2;
110 
111 
112  // Input pins
113 
114  digital_in_t int_pin;
115 
116  // Modules
117 
118  uart_t uart;
119 
120  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
121  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
122 
123 } duallin_t;
124 
128 typedef struct
129 {
130  // Communication gpio pins
131 
132  pin_name_t rx_pin;
133  pin_name_t tx_pin;
134 
135  // Additional gpio pins
136 
137  pin_name_t en1;
138  pin_name_t en2;
139  pin_name_t int_pin;
140 
141  // static variable
142 
143  uint32_t baud_rate; // Clock speed.
145  uart_data_bits_t data_bit; // Data bits.
146  uart_parity_t parity_bit; // Parity bit.
147  uart_stop_bits_t stop_bit; // Stop bits.
148 
149 } duallin_cfg_t;
150 
154 typedef uint8_t duallin_error_t;
155  // End types group
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
164 #ifdef __cplusplus
165 extern "C"{
166 #endif
167 
177 
187 
195 void duallin_generic_write ( duallin_t *ctx, char *data_buf, uint16_t len );
196 
206 int16_t duallin_generic_read ( duallin_t *ctx, char *data_buf, uint16_t max_len );
207 
214 void duallin_bus1_status ( duallin_t *ctx, uint8_t state );
215 
222 void duallin_bus2_status ( duallin_t *ctx, uint8_t state );
223 
230 void duallin_send_command ( duallin_t *ctx, char *command );
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 #endif // _DUALLIN_H_
236  // End public_function group
239 
240 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: duallin.h:92
duallin_generic_write
void duallin_generic_write(duallin_t *ctx, char *data_buf, uint16_t len)
Generic write function.
duallin_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: duallin.h:145
duallin_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: duallin.h:147
duallin_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: duallin.h:146
duallin_t::en2
digital_out_t en2
Definition: duallin.h:109
duallin_cfg_t::en1
pin_name_t en1
Definition: duallin.h:137
duallin_cfg_t::rx_pin
pin_name_t rx_pin
Definition: duallin.h:132
duallin_bus2_status
void duallin_bus2_status(duallin_t *ctx, uint8_t state)
Sets state of CS pin.
duallin_bus1_status
void duallin_bus1_status(duallin_t *ctx, uint8_t state)
Sets state of RST pin.
DUALLIN_RETVAL
#define DUALLIN_RETVAL
Definition: duallin.h:74
duallin_send_command
void duallin_send_command(duallin_t *ctx, char *command)
Send command.
duallin_cfg_t::int_pin
pin_name_t int_pin
Definition: duallin.h:139
duallin_t::int_pin
digital_in_t int_pin
Definition: duallin.h:114
duallin_t::en1
digital_out_t en1
Definition: duallin.h:108
duallin_cfg_t::uart_blocking
bool uart_blocking
Definition: duallin.h:144
duallin_cfg_t::baud_rate
uint32_t baud_rate
Definition: duallin.h:143
duallin_cfg_t::tx_pin
pin_name_t tx_pin
Definition: duallin.h:133
duallin_init
DUALLIN_RETVAL duallin_init(duallin_t *ctx, duallin_cfg_t *cfg)
Initialization function.
duallin_generic_read
int16_t duallin_generic_read(duallin_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
duallin_error_t
uint8_t duallin_error_t
Error type.
Definition: duallin.h:154
duallin_cfg_t
Click configuration structure definition.
Definition: duallin.h:129
duallin_cfg_setup
void duallin_cfg_setup(duallin_cfg_t *cfg)
Config Object Initialization function.
duallin_t
Click ctx object definition.
Definition: duallin.h:105
duallin_cfg_t::en2
pin_name_t en2
Definition: duallin.h:138
duallin_t::uart
uart_t uart
Definition: duallin.h:118