uart1wire 2.0.0.0
uart1wire.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 UART1WIRE_H
36#define UART1WIRE_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// -------------------------------------------------------------- PUBLIC MACROS
66#define UART1WIRE_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
75#define UART1WIRE_RETVAL uint8_t
76
77#define UART1WIRE_OK 0
78#define UART1WIRE_ERROR -1
85#define UART1WIRE_COMMAND_MODE 0xE3
86#define UART1WIRE_DATA_MODE 0xE1
87#define UART1WIRE_RESET 0xC1
88#define UART1WIRE_SKIP_ROM 0xCC
89#define UART1WIRE_CONVERT_TEMPERATURE 0x44
90#define UART1WIRE_READ_SCRATCHPAD 0xBE
91#define UART1WIRE_READ_SEQ 0xFF
92#define UART1WIRE_TEMP_SENSOR_RESOLUTION_12BIT 12
93#define UART1WIRE_TEMP_SENSOR_RESOLUTION_11BIT 11
94#define UART1WIRE_TEMP_SENSOR_RESOLUTION_10BIT 10
95#define UART1WIRE_TEMP_SENSOR_RESOLUTION_9BIT 9
102#define DRV_RX_BUFFER_SIZE 300
103#define DRV_TX_BUFFER_SIZE 100
106 // End group macro
107// --------------------------------------------------------------- PUBLIC TYPES
115typedef struct
116{
117 // Modules
118
119 uart_t uart;
120
121 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
122 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
123
125
129typedef struct
130{
131 // Communication gpio pins
132
133 pin_name_t rx_pin;
134 pin_name_t tx_pin;
135
136 // static variable
137
138 uint32_t baud_rate; // Clock speed.
140 uart_data_bits_t data_bit; // Data bits.
141 uart_parity_t parity_bit; // Parity bit.
142 uart_stop_bits_t stop_bit; // Stop bits.
143
145
149typedef uint8_t uart1wire_error_t;
150
151 // End types group
152// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153
159#ifdef __cplusplus
160extern "C"{
161#endif
162
172
181
188void uart1wire_generic_write ( uart1wire_t *ctx, char *data_buf, uint16_t len );
189
197int32_t uart1wire_generic_read ( uart1wire_t *ctx, char *data_buf, uint16_t max_len );
198
207void uart1wire_write_command ( uart1wire_t *ctx, uint8_t cmd );
208
219
228
241int8_t uart1wire_read_data ( uart1wire_t *ctx, uint8_t *data_out, uint8_t num_bytes );
242
255int8_t uart1wire_read_temperature ( uart1wire_t *ctx, float *temperature, uint8_t resolution );
256
257#ifdef __cplusplus
258}
259#endif
260#endif // _UART1WIRE_H_
261
262 // End public_function group
264
265// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition uart1wire.h:102
#define DRV_TX_BUFFER_SIZE
Definition uart1wire.h:103
#define UART1WIRE_RETVAL
Definition uart1wire.h:75
int8_t uart1wire_read_data(uart1wire_t *ctx, uint8_t *data_out, uint8_t num_bytes)
Read data function.
UART1WIRE_RETVAL uart1wire_init(uart1wire_t *ctx, uart1wire_cfg_t *cfg)
Initialization function.
uint8_t uart1wire_read_byte(uart1wire_t *ctx)
Read byte function.
void uart1wire_reset(uart1wire_t *ctx)
Reset function.
void uart1wire_cfg_setup(uart1wire_cfg_t *cfg)
Config Object Initialization function.
int32_t uart1wire_generic_read(uart1wire_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void uart1wire_write_command(uart1wire_t *ctx, uint8_t cmd)
Write command function.
void uart1wire_generic_write(uart1wire_t *ctx, char *data_buf, uint16_t len)
Generic write function.
int8_t uart1wire_read_temperature(uart1wire_t *ctx, float *temperature, uint8_t resolution)
Read temperature function.
uint8_t uart1wire_error_t
Error type.
Definition uart1wire.h:149
Click configuration structure definition.
Definition uart1wire.h:130
uint32_t baud_rate
Definition uart1wire.h:138
bool uart_blocking
Definition uart1wire.h:139
uart_data_bits_t data_bit
Definition uart1wire.h:140
pin_name_t tx_pin
Definition uart1wire.h:134
pin_name_t rx_pin
Definition uart1wire.h:133
uart_stop_bits_t stop_bit
Definition uart1wire.h:142
uart_parity_t parity_bit
Definition uart1wire.h:141
Click ctx object definition.
Definition uart1wire.h:116
uart_t uart
Definition uart1wire.h:119