monarchadapter 2.0.0.0
monarchadapter.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 MONARCHADAPTER_H
36#define MONARCHADAPTER_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 MONARCHADAPTER_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.rng = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
79#define MONARCHADAPTER_RETVAL uint8_t
80
81#define MONARCHADAPTER_OK 0x00
82#define MONARCHADAPTER_INIT_ERROR 0xFF
89#define DRV_RX_BUFFER_SIZE 600
90#define DRV_TX_BUFFER_SIZE 100
93 // End group macro
94// --------------------------------------------------------------- PUBLIC TYPES
102typedef struct
103{
104 // Output pins
105
106 digital_out_t rst;
107 digital_out_t rts;
108
109 // Input pins
110
111 digital_in_t rng;
112 digital_in_t int_pin;
113
114 // Modules
115
116 uart_t uart;
117
118 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
119 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
120
122
126typedef struct
127{
128 // Communication gpio pins
129
130 pin_name_t rx_pin;
131 pin_name_t tx_pin;
132
133 // Additional gpio pins
134
135 pin_name_t rng;
136 pin_name_t rst;
137 pin_name_t rts;
138 pin_name_t int_pin;
139
140 // static variable
141
142 uint32_t baud_rate; // Clock speed.
144 uart_data_bits_t data_bit; // Data bits.
145 uart_parity_t parity_bit; // Parity bit.
146 uart_stop_bits_t stop_bit; // Stop bits.
147
149
154
155 // End types group
156// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
157
163#ifdef __cplusplus
164extern "C"{
165#endif
166
176
185
194
201void monarchadapter_set_rst_pin ( monarchadapter_t *ctx, uint8_t state );
202
209void monarchadapter_set_rts_pin ( monarchadapter_t *ctx, uint8_t state );
210
219
228
235void monarchadapter_generic_write ( monarchadapter_t *ctx, char *data_buf, uint16_t len );
236
244int32_t monarchadapter_generic_read ( monarchadapter_t *ctx, char *data_buf, uint16_t max_len );
245
253
254#ifdef __cplusplus
255}
256#endif
257#endif // _MONARCHADAPTER_H_
258
259 // End public_function group
261
262// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition monarchadapter.h:89
#define DRV_TX_BUFFER_SIZE
Definition monarchadapter.h:90
#define MONARCHADAPTER_RETVAL
Definition monarchadapter.h:79
void monarchadapter_cfg_setup(monarchadapter_cfg_t *cfg)
Config Object Initialization function.
void monarchadapter_send_command(monarchadapter_t *ctx, char *command)
Function for send command.
uint8_t monarchadapter_get_int_pin(monarchadapter_t *ctx)
Get INT pin state.
void monarchadapter_set_rts_pin(monarchadapter_t *ctx, uint8_t state)
Set RTS ( cs ) pin state.
MONARCHADAPTER_RETVAL monarchadapter_init(monarchadapter_t *ctx, monarchadapter_cfg_t *cfg)
Initialization function.
uint8_t monarchadapter_get_rng_pin(monarchadapter_t *ctx)
Get RNG ( an ) pin state.
void monarchadapter_generic_write(monarchadapter_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void monarchadapter_power_on(monarchadapter_t *ctx)
Monarch Adapter power on.
void monarchadapter_set_rst_pin(monarchadapter_t *ctx, uint8_t state)
Set RST ( reset ) pin state.
int32_t monarchadapter_generic_read(monarchadapter_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
uint8_t monarchadapter_error_t
Error type.
Definition monarchadapter.h:153
Click configuration structure definition.
Definition monarchadapter.h:127
pin_name_t rts
Definition monarchadapter.h:137
uint32_t baud_rate
Definition monarchadapter.h:142
bool uart_blocking
Definition monarchadapter.h:143
uart_data_bits_t data_bit
Definition monarchadapter.h:144
pin_name_t tx_pin
Definition monarchadapter.h:131
pin_name_t rng
Definition monarchadapter.h:135
pin_name_t rx_pin
Definition monarchadapter.h:130
uart_stop_bits_t stop_bit
Definition monarchadapter.h:146
pin_name_t int_pin
Definition monarchadapter.h:138
uart_parity_t parity_bit
Definition monarchadapter.h:145
pin_name_t rst
Definition monarchadapter.h:136
Click ctx object definition.
Definition monarchadapter.h:103
digital_in_t rng
Definition monarchadapter.h:111
digital_out_t rts
Definition monarchadapter.h:107
uart_t uart
Definition monarchadapter.h:116
digital_in_t int_pin
Definition monarchadapter.h:112
digital_out_t rst
Definition monarchadapter.h:106