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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define DUALLIN_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.en1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.en2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define DUALLIN_RETVAL uint8_t
65 
66 #define DUALLIN_OK 0x00
67 #define DUALLIN_INIT_ERROR 0xFF
68 
74 #define DUALLIN_PIN_STATE_LOW 0
75 #define DUALLIN_PIN_STATE_HIGH 1
76 
82 #define DRV_RX_BUFFER_SIZE 500
83  // End group macro
86 // --------------------------------------------------------------- PUBLIC TYPES
94 typedef struct
95 {
96  // Output pins
97 
98  digital_out_t en1;
99  digital_out_t en2;
100 
101 
102  // Input pins
103 
104  digital_in_t int_pin;
105 
106  // Modules
107 
108  uart_t uart;
109 
110  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
111  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
112 
113 } duallin_t;
114 
118 typedef struct
119 {
120  // Communication gpio pins
121 
122  pin_name_t rx_pin;
123  pin_name_t tx_pin;
124 
125  // Additional gpio pins
126 
127  pin_name_t en1;
128  pin_name_t en2;
129  pin_name_t int_pin;
130 
131  // static variable
132 
133  uint32_t baud_rate; // Clock speed.
135  uart_data_bits_t data_bit; // Data bits.
136  uart_parity_t parity_bit; // Parity bit.
137  uart_stop_bits_t stop_bit; // Stop bits.
138 
139 } duallin_cfg_t;
140 
144 typedef uint8_t duallin_error_t;
145  // End types group
147 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148 
154 #ifdef __cplusplus
155 extern "C"{
156 #endif
157 
166 void duallin_cfg_setup ( duallin_cfg_t *cfg );
167 
177 
185 void duallin_generic_write ( duallin_t *ctx, char *data_buf, uint16_t len );
186 
196 int16_t duallin_generic_read ( duallin_t *ctx, char *data_buf, uint16_t max_len );
197 
204 void duallin_bus1_status ( duallin_t *ctx, uint8_t state );
205 
212 void duallin_bus2_status ( duallin_t *ctx, uint8_t state );
213 
220 void duallin_send_command ( duallin_t *ctx, char *command );
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 #endif // _DUALLIN_H_
226  // End public_function group
229 
230 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: duallin.h:82
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:135
duallin_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: duallin.h:137
duallin_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: duallin.h:136
duallin_t::en2
digital_out_t en2
Definition: duallin.h:99
duallin_cfg_t::en1
pin_name_t en1
Definition: duallin.h:127
duallin_cfg_t::rx_pin
pin_name_t rx_pin
Definition: duallin.h:122
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:64
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:129
duallin_t::int_pin
digital_in_t int_pin
Definition: duallin.h:104
duallin_t::en1
digital_out_t en1
Definition: duallin.h:98
duallin_cfg_t::uart_blocking
bool uart_blocking
Definition: duallin.h:134
duallin_cfg_t::baud_rate
uint32_t baud_rate
Definition: duallin.h:133
duallin_cfg_t::tx_pin
pin_name_t tx_pin
Definition: duallin.h:123
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:144
duallin_cfg_t
Click configuration structure definition.
Definition: duallin.h:118
duallin_cfg_setup
void duallin_cfg_setup(duallin_cfg_t *cfg)
Config Object Initialization function.
duallin_t
Click ctx object definition.
Definition: duallin.h:94
duallin_cfg_t::en2
pin_name_t en2
Definition: duallin.h:128
duallin_t::uart
uart_t uart
Definition: duallin.h:108