microwave2 2.0.0.0
microwave2.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 MICROWAVE2_H
36#define MICROWAVE2_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
57// -------------------------------------------------------------- PUBLIC MACROS
67#define MICROWAVE2_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.da = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.dl = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define MICROWAVE2_RETVAL uint8_t
79
80#define MICROWAVE2_OK 0x00
81#define MICROWAVE2_INIT_ERROR 0xFF
88#define DRV_RX_BUFFER_SIZE 500
95#define MICROWAVE2_MOVING_AWAY 1
96#define MICROWAVE2_MOVING_CLOSER 2
97#define MICROWAVE2_STOPPED_MOVING 4
100 // End group macro
101// --------------------------------------------------------------- PUBLIC TYPES
111typedef struct
112{
113 // Input pins
114
115 digital_in_t da;
116 digital_in_t dl;
117
118 // Modules
119
120 uart_t uart;
121
122 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
123 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
124
126
130typedef struct
131{
132 // Communication gpio pins
133
134 pin_name_t rx_pin;
135 pin_name_t tx_pin;
136
137 // Additional gpio pins
138
139 pin_name_t da;
140 pin_name_t dl;
141
142 // static variable
143
144 uint32_t baud_rate; // Clock speed.
146 uart_data_bits_t data_bit; // Data bits.
147 uart_parity_t parity_bit; // Parity bit.
148 uart_stop_bits_t stop_bit; // Stop bits.
149
151
152 // End types group
153// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154
160#ifdef __cplusplus
161extern "C"{
162#endif
163
173
182
192void microwave2_generic_multi_write ( microwave2_t *ctx, char *data_buf, uint8_t len );
193
194
202int32_t microwave2_generic_read ( microwave2_t *ctx, char *data_buf, uint16_t max_len );
203
204
214
224
233
242
243#ifdef __cplusplus
244}
245#endif
246#endif // _MICROWAVE2_H_
247
248 // End public_function group
250
251// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition microwave2.h:88
#define MICROWAVE2_RETVAL
Definition microwave2.h:78
uint8_t microwave2_da_state(microwave2_t *ctx)
Set pin DA.
uint8_t microwave2_dl_state(microwave2_t *ctx)
Set pin DL.
void microwave2_cfg_setup(microwave2_cfg_t *cfg)
Config Object Initialization function.
MICROWAVE2_RETVAL microwave2_init(microwave2_t *ctx, microwave2_cfg_t *cfg)
Initialization function.
void microwave2_generic_single_write(microwave2_t *ctx, char tx_data)
Generic single write function.
int32_t microwave2_generic_read(microwave2_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
char microwave2_generic_single_read(microwave2_t *ctx)
Generic single read function.
void microwave2_generic_multi_write(microwave2_t *ctx, char *data_buf, uint8_t len)
Generic multi write function.
Click configuration structure definition.
Definition microwave2.h:131
uint32_t baud_rate
Definition microwave2.h:144
pin_name_t da
Definition microwave2.h:139
bool uart_blocking
Definition microwave2.h:145
uart_data_bits_t data_bit
Definition microwave2.h:146
pin_name_t tx_pin
Definition microwave2.h:135
pin_name_t rx_pin
Definition microwave2.h:134
uart_stop_bits_t stop_bit
Definition microwave2.h:148
uart_parity_t parity_bit
Definition microwave2.h:147
pin_name_t dl
Definition microwave2.h:140
Click ctx object definition.
Definition microwave2.h:112
digital_in_t dl
Definition microwave2.h:116
digital_in_t da
Definition microwave2.h:115
uart_t uart
Definition microwave2.h:120