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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define UART1WIRE_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX )
55 
61 #define UART1WIRE_RETVAL uint8_t
62 
63 #define UART1WIRE_OK 0
64 #define UART1WIRE_ERROR -1
65 
71 #define UART1WIRE_COMMAND_MODE 0xE3
72 #define UART1WIRE_DATA_MODE 0xE1
73 #define UART1WIRE_RESET 0xC1
74 #define UART1WIRE_SKIP_ROM 0xCC
75 #define UART1WIRE_CONVERT_TEMPERATURE 0x44
76 #define UART1WIRE_READ_SCRATCHPAD 0xBE
77 #define UART1WIRE_READ_SEQ 0xFF
78 #define UART1WIRE_TEMP_SENSOR_RESOLUTION_12BIT 12
79 #define UART1WIRE_TEMP_SENSOR_RESOLUTION_11BIT 11
80 #define UART1WIRE_TEMP_SENSOR_RESOLUTION_10BIT 10
81 #define UART1WIRE_TEMP_SENSOR_RESOLUTION_9BIT 9
82 
88 #define DRV_RX_BUFFER_SIZE 300
89 #define DRV_TX_BUFFER_SIZE 100
90  // End group macro
93 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef struct
102 {
103  // Modules
104 
105  uart_t uart;
106 
107  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
108  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
109 
110 } uart1wire_t;
111 
115 typedef struct
116 {
117  // Communication gpio pins
118 
119  pin_name_t rx_pin;
120  pin_name_t tx_pin;
121 
122  // static variable
123 
124  uint32_t baud_rate; // Clock speed.
126  uart_data_bits_t data_bit; // Data bits.
127  uart_parity_t parity_bit; // Parity bit.
128  uart_stop_bits_t stop_bit; // Stop bits.
129 
131 
135 typedef uint8_t uart1wire_error_t;
136  // End types group
138 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
139 
145 #ifdef __cplusplus
146 extern "C"{
147 #endif
148 
158 
167 
174 void uart1wire_generic_write ( uart1wire_t *ctx, char *data_buf, uint16_t len );
175 
183 int32_t uart1wire_generic_read ( uart1wire_t *ctx, char *data_buf, uint16_t max_len );
184 
193 void uart1wire_write_command ( uart1wire_t *ctx, uint8_t cmd );
194 
205 
214 
227 int8_t uart1wire_read_data ( uart1wire_t *ctx, uint8_t *data_out, uint8_t num_bytes );
228 
241 int8_t uart1wire_read_temperature ( uart1wire_t *ctx, float *temperature, uint8_t resolution );
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 #endif // _UART1WIRE_H_
247  // End public_function group
250 
251 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: uart1wire.h:88
uart1wire_t::uart
uart_t uart
Definition: uart1wire.h:105
uart1wire_cfg_setup
void uart1wire_cfg_setup(uart1wire_cfg_t *cfg)
Config Object Initialization function.
uart1wire_init
UART1WIRE_RETVAL uart1wire_init(uart1wire_t *ctx, uart1wire_cfg_t *cfg)
Initialization function.
uart1wire_cfg_t::baud_rate
uint32_t baud_rate
Definition: uart1wire.h:124
uart1wire_generic_write
void uart1wire_generic_write(uart1wire_t *ctx, char *data_buf, uint16_t len)
Generic write function.
uart1wire_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: uart1wire.h:127
uart1wire_reset
void uart1wire_reset(uart1wire_t *ctx)
Reset function.
uart1wire_write_command
void uart1wire_write_command(uart1wire_t *ctx, uint8_t cmd)
Write command function.
uart1wire_cfg_t::rx_pin
pin_name_t rx_pin
Definition: uart1wire.h:119
uart1wire_read_byte
uint8_t uart1wire_read_byte(uart1wire_t *ctx)
Read byte function.
uart1wire_read_data
int8_t uart1wire_read_data(uart1wire_t *ctx, uint8_t *data_out, uint8_t num_bytes)
Read data function.
uart1wire_t
Click ctx object definition.
Definition: uart1wire.h:102
UART1WIRE_RETVAL
#define UART1WIRE_RETVAL
Definition: uart1wire.h:61
uart1wire_generic_read
int32_t uart1wire_generic_read(uart1wire_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
uart1wire_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: uart1wire.h:128
uart1wire_read_temperature
int8_t uart1wire_read_temperature(uart1wire_t *ctx, float *temperature, uint8_t resolution)
Read temperature function.
uart1wire_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: uart1wire.h:126
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: uart1wire.h:89
uart1wire_error_t
uint8_t uart1wire_error_t
Error type.
Definition: uart1wire.h:135
uart1wire_cfg_t
Click configuration structure definition.
Definition: uart1wire.h:116
uart1wire_cfg_t::uart_blocking
bool uart_blocking
Definition: uart1wire.h:125
uart1wire_cfg_t::tx_pin
pin_name_t tx_pin
Definition: uart1wire.h:120