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 )
72 
78 #define DUALLIN_RETVAL uint8_t
79 
80 #define DUALLIN_OK 0x00
81 #define DUALLIN_INIT_ERROR 0xFF
82 
88 #define DUALLIN_PIN_STATE_LOW 0
89 #define DUALLIN_PIN_STATE_HIGH 1
90 
96 #define DRV_RX_BUFFER_SIZE 500
97  // End group macro
100 // --------------------------------------------------------------- PUBLIC TYPES
108 typedef 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 
132 typedef 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 
153 } duallin_cfg_t;
154 
158 typedef uint8_t duallin_error_t;
159  // End types group
161 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
162 
168 #ifdef __cplusplus
169 extern "C"{
170 #endif
171 
181 
191 
199 void duallin_generic_write ( duallin_t *ctx, char *data_buf, uint16_t len );
200 
210 int16_t duallin_generic_read ( duallin_t *ctx, char *data_buf, uint16_t max_len );
211 
218 void duallin_bus1_status ( duallin_t *ctx, uint8_t state );
219 
226 void duallin_bus2_status ( duallin_t *ctx, uint8_t state );
227 
234 void duallin_send_command ( duallin_t *ctx, char *command );
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 #endif // _DUALLIN_H_
240  // End public_function group
243 
244 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: duallin.h:96
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:149
duallin_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: duallin.h:151
duallin_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: duallin.h:150
duallin_t::en2
digital_out_t en2
Definition: duallin.h:113
duallin_cfg_t::en1
pin_name_t en1
Definition: duallin.h:141
duallin_cfg_t::rx_pin
pin_name_t rx_pin
Definition: duallin.h:136
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:78
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:143
duallin_t::int_pin
digital_in_t int_pin
Definition: duallin.h:118
duallin_t::en1
digital_out_t en1
Definition: duallin.h:112
duallin_cfg_t::uart_blocking
bool uart_blocking
Definition: duallin.h:148
duallin_cfg_t::baud_rate
uint32_t baud_rate
Definition: duallin.h:147
duallin_cfg_t::tx_pin
pin_name_t tx_pin
Definition: duallin.h:137
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:158
duallin_cfg_t
Click configuration structure definition.
Definition: duallin.h:133
duallin_cfg_setup
void duallin_cfg_setup(duallin_cfg_t *cfg)
Config Object Initialization function.
duallin_t
Click ctx object definition.
Definition: duallin.h:109
duallin_cfg_t::en2
pin_name_t en2
Definition: duallin.h:142
duallin_t::uart
uart_t uart
Definition: duallin.h:122