obdii 2.1.0.0
obdii.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef OBDII_H
29#define OBDII_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
73#define OBDII_CMD_FIRMWARE_VERSION "ATI"
74#define OBDII_CMD_DISABLE_ECHO "ATE0"
75#define OBDII_CMD_ENABLE_ECHO "ATE1"
76#define OBDII_CMD_AUTO_PROTOCOL "ATSP0"
77#define OBDII_CMD_SPACES_OFF "ATS0"
78#define OBDII_CMD_RESET_DEFAULT "ATD"
79#define OBDII_CMD_RESET_DEVICE "ATZ"
80#define OBDII_CMD_GET_CURRENT_RPM "010C"
81#define OBDII_CMD_GET_CURRENT_SPEED "010D"
82
87#define OBDII_RSP_OK "OK"
88#define OBDII_RSP_UNKNOWN_CMD "ERROR"
89#define OBDII_RSP_PROMPT ">"
90#define OBDII_RSP_CURRENT_RPM "410C"
91#define OBDII_RSP_CURRENT_SPEED "410D"
92
98#define OBDII_TX_DRV_BUFFER_SIZE 100
99#define OBDII_RX_DRV_BUFFER_SIZE 300
100
101 // obdii_cmd
102
117#define OBDII_MAP_MIKROBUS( cfg, mikrobus ) \
118 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
119 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
120 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
121 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
122
123 // obdii_map
124 // obdii
125
130typedef struct
131{
132 // Output pins
133 digital_out_t rst;
135 // Input pins
136 digital_in_t int_pin;
138 // Modules
139 uart_t uart;
141 // Buffers
142 uint8_t uart_rx_buffer[ OBDII_RX_DRV_BUFFER_SIZE ];
143 uint8_t uart_tx_buffer[ OBDII_TX_DRV_BUFFER_SIZE ];
145} obdii_t;
146
151typedef struct
152{
153 // Communication gpio pins
154 pin_name_t rx_pin;
155 pin_name_t tx_pin;
157 // Additional gpio pins
158 pin_name_t rst;
159 pin_name_t int_pin;
161 // Static variable
162 uint32_t baud_rate;
164 uart_data_bits_t data_bit;
165 uart_parity_t parity_bit;
166 uart_stop_bits_t stop_bit;
169
181
198
212err_t obdii_init ( obdii_t *ctx, obdii_cfg_t *cfg );
213
226err_t obdii_generic_write ( obdii_t *ctx, uint8_t *data_in, uint16_t len );
227
240err_t obdii_generic_read ( obdii_t *ctx, uint8_t *data_out, uint16_t len );
241
253void obdii_send_command ( obdii_t *ctx, uint8_t *cmd );
254
264
274void obdii_set_rst_pin ( obdii_t *ctx, uint8_t state );
275
284uint8_t obdii_get_int_pin ( obdii_t *ctx );
285
286#ifdef __cplusplus
287}
288#endif
289#endif // OBDII_H
290
291 // obdii
292
293// ------------------------------------------------------------------------ END
#define OBDII_TX_DRV_BUFFER_SIZE
OBDII driver buffer size.
Definition obdii.h:98
#define OBDII_RX_DRV_BUFFER_SIZE
Definition obdii.h:99
err_t obdii_generic_write(obdii_t *ctx, uint8_t *data_in, uint16_t len)
OBDII data writing function.
void obdii_set_rst_pin(obdii_t *ctx, uint8_t state)
OBDII set rst pin function.
void obdii_cfg_setup(obdii_cfg_t *cfg)
OBDII configuration object setup function.
uint8_t obdii_get_int_pin(obdii_t *ctx)
OBDII get int pin function.
void obdii_reset_device(obdii_t *ctx)
OBDII reset device function.
void obdii_send_command(obdii_t *ctx, uint8_t *cmd)
OBDII send command function.
err_t obdii_generic_read(obdii_t *ctx, uint8_t *data_out, uint16_t len)
OBDII data reading function.
err_t obdii_init(obdii_t *ctx, obdii_cfg_t *cfg)
OBDII initialization function.
obdii_return_value_t
OBDII Click return value data.
Definition obdii.h:175
@ OBDII_ERROR
Definition obdii.h:177
@ OBDII_ERROR_TIMEOUT
Definition obdii.h:178
@ OBDII_OK
Definition obdii.h:176
OBDII Click configuration object.
Definition obdii.h:152
uint32_t baud_rate
Definition obdii.h:162
bool uart_blocking
Definition obdii.h:163
uart_data_bits_t data_bit
Definition obdii.h:164
pin_name_t tx_pin
Definition obdii.h:155
pin_name_t rx_pin
Definition obdii.h:154
uart_stop_bits_t stop_bit
Definition obdii.h:166
pin_name_t int_pin
Definition obdii.h:159
uart_parity_t parity_bit
Definition obdii.h:165
pin_name_t rst
Definition obdii.h:158
OBDII Click context object.
Definition obdii.h:131
uart_t uart
Definition obdii.h:139
digital_in_t int_pin
Definition obdii.h:136
digital_out_t rst
Definition obdii.h:133