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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define MICROWAVE2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.da = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.dl = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define MICROWAVE2_RETVAL uint8_t
65 
66 #define MICROWAVE2_OK 0x00
67 #define MICROWAVE2_INIT_ERROR 0xFF
68 
74 #define DRV_RX_BUFFER_SIZE 500
75 
81 #define MICROWAVE2_MOVING_AWAY 1
82 #define MICROWAVE2_MOVING_CLOSER 2
83 #define MICROWAVE2_STOPPED_MOVING 4
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99  // Input pins
100 
101  digital_in_t da;
102  digital_in_t dl;
103 
104  // Modules
105 
106  uart_t uart;
107 
108  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
109  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
110 
111 } microwave2_t;
112 
116 typedef struct
117 {
118  // Communication gpio pins
119 
120  pin_name_t rx_pin;
121  pin_name_t tx_pin;
122 
123  // Additional gpio pins
124 
125  pin_name_t da;
126  pin_name_t dl;
127 
128  // static variable
129 
130  uint32_t baud_rate; // Clock speed.
132  uart_data_bits_t data_bit; // Data bits.
133  uart_parity_t parity_bit; // Parity bit.
134  uart_stop_bits_t stop_bit; // Stop bits.
135 
137  // End types group
139 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
140 
146 #ifdef __cplusplus
147 extern "C"{
148 #endif
149 
159 
168 
178 void microwave2_generic_multi_write ( microwave2_t *ctx, char *data_buf, uint8_t len );
179 
180 
188 int32_t microwave2_generic_read ( microwave2_t *ctx, char *data_buf, uint16_t max_len );
189 
190 
200 
209 void microwave2_generic_single_write ( microwave2_t *ctx, char tx_data );
210 
218 uint8_t microwave2_da_state ( microwave2_t *ctx );
219 
227 uint8_t microwave2_dl_state ( microwave2_t *ctx );
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 #endif // _MICROWAVE2_H_
233  // End public_function group
236 
237 // ------------------------------------------------------------------------- END
microwave2_cfg_t
Click configuration structure definition.
Definition: microwave2.h:116
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: microwave2.h:74
microwave2_cfg_t::dl
pin_name_t dl
Definition: microwave2.h:126
microwave2_init
MICROWAVE2_RETVAL microwave2_init(microwave2_t *ctx, microwave2_cfg_t *cfg)
Initialization function.
microwave2_da_state
uint8_t microwave2_da_state(microwave2_t *ctx)
Set pin DA.
microwave2_cfg_setup
void microwave2_cfg_setup(microwave2_cfg_t *cfg)
Config Object Initialization function.
MICROWAVE2_RETVAL
#define MICROWAVE2_RETVAL
Definition: microwave2.h:64
microwave2_t::da
digital_in_t da
Definition: microwave2.h:101
microwave2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: microwave2.h:133
microwave2_cfg_t::uart_blocking
bool uart_blocking
Definition: microwave2.h:131
microwave2_generic_single_read
char microwave2_generic_single_read(microwave2_t *ctx)
Generic single read function.
microwave2_generic_multi_write
void microwave2_generic_multi_write(microwave2_t *ctx, char *data_buf, uint8_t len)
Generic multi write function.
microwave2_generic_read
int32_t microwave2_generic_read(microwave2_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
microwave2_generic_single_write
void microwave2_generic_single_write(microwave2_t *ctx, char tx_data)
Generic single write function.
microwave2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: microwave2.h:121
microwave2_dl_state
uint8_t microwave2_dl_state(microwave2_t *ctx)
Set pin DL.
microwave2_t
Click ctx object definition.
Definition: microwave2.h:97
microwave2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: microwave2.h:120
microwave2_t::dl
digital_in_t dl
Definition: microwave2.h:102
microwave2_t::uart
uart_t uart
Definition: microwave2.h:106
microwave2_cfg_t::baud_rate
uint32_t baud_rate
Definition: microwave2.h:130
microwave2_cfg_t::da
pin_name_t da
Definition: microwave2.h:125
microwave2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: microwave2.h:132
microwave2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: microwave2.h:134