obdii  2.0.0.0
obdii.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 OBDII_H
36 #define OBDII_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define OBDII_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define OBDII_RETVAL uint8_t
64 
65 #define OBDII_OK 0x00
66 #define OBDII_INIT_ERROR 0xFF
67 
73 #define DRV_RX_BUFFER_SIZE 500
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87  // Output pins
88 
89  digital_out_t rst;
90 
91  // Input pins
92 
93  digital_in_t int_pin;
94 
95  // Modules
96 
97  uart_t uart;
98 
99  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
100  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
101 
102 } obdii_t;
103 
107 typedef struct
108 {
109  // Communication gpio pins
110 
111  pin_name_t rx_pin;
112  pin_name_t tx_pin;
113 
114  // Additional gpio pins
115 
116  pin_name_t rst;
117  pin_name_t int_pin;
118 
119  // static variable
120 
121  uint32_t baud_rate; // Clock speed.
123  uart_data_bits_t data_bit; // Data bits.
124  uart_parity_t parity_bit; // Parity bit.
125  uart_stop_bits_t stop_bit; // Stop bits.
126 
127 } obdii_cfg_t;
128 
132 typedef uint8_t obdii_error_t;
133  // End types group
135 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
136 
142 #ifdef __cplusplus
143 extern "C"{
144 #endif
145 
154 void obdii_cfg_setup ( obdii_cfg_t *cfg );
155 
165 
171 void obdii_module_reset ( obdii_t *ctx );
172 
180 uint8_t obdii_get_int_pin ( obdii_t *ctx );
181 
189 void obdii_generic_write ( obdii_t *ctx, char *data_buf, uint16_t len );
190 
200 int32_t obdii_generic_read ( obdii_t *ctx, char *data_buf, uint16_t max_len );
201 
208 void obdii_send_command ( obdii_t *ctx, char *command );
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 #endif // _OBDII_H_
214  // End public_function group
217 
218 // ------------------------------------------------------------------------- END
obdii_get_int_pin
uint8_t obdii_get_int_pin(obdii_t *ctx)
Get INT pin state.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: obdii.h:73
obdii_generic_write
void obdii_generic_write(obdii_t *ctx, char *data_buf, uint16_t len)
Generic write function.
obdii_cfg_setup
void obdii_cfg_setup(obdii_cfg_t *cfg)
Config Object Initialization function.
obdii_cfg_t::rx_pin
pin_name_t rx_pin
Definition: obdii.h:111
obdii_cfg_t
Click configuration structure definition.
Definition: obdii.h:107
obdii_cfg_t::int_pin
pin_name_t int_pin
Definition: obdii.h:117
obdii_t::uart
uart_t uart
Definition: obdii.h:97
obdii_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: obdii.h:123
obdii_init
OBDII_RETVAL obdii_init(obdii_t *ctx, obdii_cfg_t *cfg)
Initialization function.
obdii_send_command
void obdii_send_command(obdii_t *ctx, char *command)
Function for send command.
obdii_module_reset
void obdii_module_reset(obdii_t *ctx)
Reset module.
obdii_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: obdii.h:125
obdii_t::rst
digital_out_t rst
Definition: obdii.h:89
obdii_cfg_t::baud_rate
uint32_t baud_rate
Definition: obdii.h:121
OBDII_RETVAL
#define OBDII_RETVAL
Definition: obdii.h:63
obdii_cfg_t::uart_blocking
bool uart_blocking
Definition: obdii.h:122
obdii_t
Click ctx object definition.
Definition: obdii.h:85
obdii_generic_read
int32_t obdii_generic_read(obdii_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
obdii_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: obdii.h:124
obdii_cfg_t::tx_pin
pin_name_t tx_pin
Definition: obdii.h:112
obdii_error_t
uint8_t obdii_error_t
Error type.
Definition: obdii.h:132
obdii_cfg_t::rst
pin_name_t rst
Definition: obdii.h:116
obdii_t::int_pin
digital_in_t int_pin
Definition: obdii.h:93