singlewirecan 2.0.0.0
singlewirecan.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 SINGLEWIRECAN_H
36#define SINGLEWIRECAN_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 SINGLEWIRECAN_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.md0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.md1 = MIKROBUS( mikrobus, MIKROBUS_CS )
78#define SINGLEWIRECAN_RETVAL uint8_t
79
80#define SINGLEWIRECAN_OK 0x00
81#define SINGLEWIRECAN_INIT_ERROR 0xFF
88#define SINGLEWIRECAN_OPERATING_MODE_SLEEP 0x00
89#define SINGLEWIRECAN_OPERATING_MODE_HIGH_SPEED 0x01
90#define SINGLEWIRECAN_OPERATING_MODE_HIGH_VOLTAGE_WAKE_UP 0x02
91#define SINGLEWIRECAN_OPERATING_MODE_NORMAL 0x03
98#define SINGLEWIRECAN_PIN_STATE_LOW 0x00
99#define SINGLEWIRECAN_PIN_STATE_HIGH 0x01
106#define SINGLEWIRECAN_END_BUFF 0x00
113#define DRV_RX_BUFFER_SIZE 500
116 // End group macro
117// --------------------------------------------------------------- PUBLIC TYPES
125typedef struct
126{
127 // Output pins
128
129 digital_out_t md0;
130 digital_out_t md1;
131
132 // Modules
133
134 uart_t uart;
135
136 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
137 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
138
140
144typedef struct
145{
146 // Communication gpio pins
147
148 pin_name_t rx_pin;
149 pin_name_t tx_pin;
150
151 // Additional gpio pins
152
153 pin_name_t md0;
154 pin_name_t md1;
155
156 // static variable
157
158 uint32_t baud_rate; // Clock speed.
160 uart_data_bits_t data_bit; // Data bits.
161 uart_parity_t parity_bit; // Parity bit.
162 uart_stop_bits_t stop_bit; // Stop bits.
163
165
166 // End types group
167// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168
174#ifdef __cplusplus
175extern "C"{
176#endif
177
188
198
208void singlewirecan_generic_write ( singlewirecan_t *ctx, char *data_buf, uint16_t len );
209
221int32_t singlewirecan_generic_read ( singlewirecan_t *ctx, char *data_buf, uint16_t max_len );
222
231void singlewirecan_set_md_0_pin_state ( singlewirecan_t *ctx, uint8_t rst_state );
232
241void singlewirecan_set_md_1_pin_state ( singlewirecan_t *ctx, uint8_t cs_state );
242
259
260#ifdef __cplusplus
261}
262#endif
263#endif // _SINGLEWIRECAN_H_
264
265 // End public_function group
267
268// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition singlewirecan.h:113
#define SINGLEWIRECAN_RETVAL
Definition singlewirecan.h:78
int32_t singlewirecan_generic_read(singlewirecan_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void singlewirecan_cfg_setup(singlewirecan_cfg_t *cfg)
Config Object Initialization function.
void singlewirecan_set_operating_mode(singlewirecan_t *ctx, uint8_t op_mode)
Set operating mode function.
void singlewirecan_generic_write(singlewirecan_t *ctx, char *data_buf, uint16_t len)
Generic write function.
SINGLEWIRECAN_RETVAL singlewirecan_init(singlewirecan_t *ctx, singlewirecan_cfg_t *cfg)
Initialization function.
void singlewirecan_set_md_0_pin_state(singlewirecan_t *ctx, uint8_t rst_state)
Sets MD0 pin state.
void singlewirecan_set_md_1_pin_state(singlewirecan_t *ctx, uint8_t cs_state)
Sets MD1 pin state.
Click configuration structure definition.
Definition singlewirecan.h:145
uint32_t baud_rate
Definition singlewirecan.h:158
pin_name_t md1
Definition singlewirecan.h:154
bool uart_blocking
Definition singlewirecan.h:159
uart_data_bits_t data_bit
Definition singlewirecan.h:160
pin_name_t md0
Definition singlewirecan.h:153
pin_name_t tx_pin
Definition singlewirecan.h:149
pin_name_t rx_pin
Definition singlewirecan.h:148
uart_stop_bits_t stop_bit
Definition singlewirecan.h:162
uart_parity_t parity_bit
Definition singlewirecan.h:161
Click ctx object definition.
Definition singlewirecan.h:126
digital_out_t md0
Definition singlewirecan.h:129
uart_t uart
Definition singlewirecan.h:134
digital_out_t md1
Definition singlewirecan.h:130