ecg4 2.0.0.0
ecg4.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4 * All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef ECG4_H
36#define ECG4_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 ECG4_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
77#define ECG4_RETVAL uint8_t
78
79#define ECG4_OK 0x00
80#define ECG4_INIT_ERROR 0xFF
83#define ECG4_SYNC_BYTE 0xAA
84#define ECG4_EXCODE_BYTE 0x55
85#define ECG4_SIGNAL_QUALITY_CODE_BYTE 0x02
86#define ECG4_HEART_RATE_CODE_BYTE 0x03
87#define ECG4_RAW_DATA_CODE_BYTE 0x80
88#define ECG4_RESPONSE_READY 0x01
89#define ECG4_RESPONSE_NOT_READY 0x00
90#define ECG4_ENABLE_LDO_CTRL 0x01
91#define ECG4_DISABLE_LDO_CTRL 0x00
92
97#define DRV_RX_BUFFER_SIZE 1000
98#define DRV_TX_BUFFER_SIZE 50
101 // End group macro
102// --------------------------------------------------------------- PUBLIC TYPES
103
113typedef void ( *ecg4_hdl_t )( uint8_t*, uint8_t*, uint8_t*, uint8_t* );
114
118typedef struct
119{
120 // Output pins
121
122 digital_out_t rst;
123 digital_out_t cs;
124
125 // Modules
126
127 uart_t uart;
128
129 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
130 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
131
134
135} ecg4_t;
136
140typedef struct
141{
142 // Communication gpio pins
143
144 pin_name_t rx_pin;
145 pin_name_t tx_pin;
146
147 // Additional gpio pins
148
149 pin_name_t rst;
150 pin_name_t cs;
151
152 // static variable
153
154 uint32_t baud_rate; // Clock speed.
156 uart_data_bits_t data_bit; // Data bits.
157 uart_parity_t parity_bit; // Parity bit.
158 uart_stop_bits_t stop_bit; // Stop bits.
159
160} ecg4_cfg_t;
161
165typedef uint8_t ecg4_error_t;
166
167 // End types group
168// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
169
175#ifdef __cplusplus
176extern "C"{
177#endif
178
188
198
204
211void ecg4_generic_write ( ecg4_t *ctx, char *data_buf, uint16_t len );
212
220int32_t ecg4_generic_read ( ecg4_t *ctx, char *data_buf, uint16_t max_len );
221
236void ecg4_enable_ldo_ctrl ( ecg4_t *ctx, uint8_t state );
237
245void ecg4_uart_isr( ecg4_t *ctx, uint8_t rx_dat );
246
255
256#ifdef __cplusplus
257}
258#endif
259#endif // _ECG4_H_
260
261 // End public_function group
263
264// ------------------------------------------------------------------------- END
uint8_t ecg4_error_t
Error type.
Definition ecg4.h:165
void(* ecg4_hdl_t)(uint8_t *, uint8_t *, uint8_t *, uint8_t *)
Definition ecg4.h:113
#define DRV_RX_BUFFER_SIZE
Definition ecg4.h:97
#define DRV_TX_BUFFER_SIZE
Definition ecg4.h:98
#define ECG4_RETVAL
Definition ecg4.h:77
void ecg4_enable_ldo_ctrl(ecg4_t *ctx, uint8_t state)
LDO Control function.
void ecg4_uart_isr(ecg4_t *ctx, uint8_t rx_dat)
Uart Interrupt Routine function.
void ecg4_generic_write(ecg4_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void ecg4_module_reset(ecg4_t *ctx)
Reset module.
void ecg4_cfg_setup(ecg4_cfg_t *cfg)
Config Object Initialization function.
uint8_t ecg4_responseReady(ecg4_t *ctx)
Response ready check function.
ECG4_RETVAL ecg4_init(ecg4_t *ctx, ecg4_cfg_t *cfg)
Initialization function.
int32_t ecg4_generic_read(ecg4_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
Click configuration structure definition.
Definition ecg4.h:141
uint32_t baud_rate
Definition ecg4.h:154
bool uart_blocking
Definition ecg4.h:155
uart_data_bits_t data_bit
Definition ecg4.h:156
pin_name_t tx_pin
Definition ecg4.h:145
pin_name_t rx_pin
Definition ecg4.h:144
uart_stop_bits_t stop_bit
Definition ecg4.h:158
uart_parity_t parity_bit
Definition ecg4.h:157
pin_name_t rst
Definition ecg4.h:149
pin_name_t cs
Definition ecg4.h:150
Click ctx object definition.
Definition ecg4.h:119
digital_out_t cs
Definition ecg4.h:123
uint8_t response_ready
Definition ecg4.h:133
ecg4_hdl_t driver_hdl
Definition ecg4.h:132
uart_t uart
Definition ecg4.h:127
digital_out_t rst
Definition ecg4.h:122