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 )
71 
77 #define ECG4_RETVAL uint8_t
78 
79 #define ECG4_OK 0x00
80 #define ECG4_INIT_ERROR 0xFF
81 
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
99  // End group macro
102 // --------------------------------------------------------------- PUBLIC TYPES
103 
113 typedef void ( *ecg4_hdl_t )( uint8_t*, uint8_t*, uint8_t*, uint8_t* );
114 
118 typedef 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 
133  uint8_t response_ready;
134 
135 } ecg4_t;
136 
140 typedef 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 
165 typedef uint8_t ecg4_error_t;
166  // End types group
168 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
169 
175 #ifdef __cplusplus
176 extern "C"{
177 #endif
178 
188 
198 
203 void ecg4_module_reset ( ecg4_t *ctx );
204 
211 void ecg4_generic_write ( ecg4_t *ctx, char *data_buf, uint16_t len );
212 
220 int32_t ecg4_generic_read ( ecg4_t *ctx, char *data_buf, uint16_t max_len );
221 
236 void ecg4_enable_ldo_ctrl ( ecg4_t *ctx, uint8_t state );
237 
245 void ecg4_uart_isr( ecg4_t *ctx, uint8_t rx_dat );
246 
254 uint8_t ecg4_responseReady( ecg4_t *ctx );
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 #endif // _ECG4_H_
260  // End public_function group
263 
264 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: ecg4.h:97
ecg4_cfg_t::baud_rate
uint32_t baud_rate
Definition: ecg4.h:154
ecg4_cfg_t::rst
pin_name_t rst
Definition: ecg4.h:149
ecg4_hdl_t
void(* ecg4_hdl_t)(uint8_t *, uint8_t *, uint8_t *, uint8_t *)
Definition: ecg4.h:113
ecg4_error_t
uint8_t ecg4_error_t
Error type.
Definition: ecg4.h:165
ecg4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ecg4.h:158
ecg4_t::response_ready
uint8_t response_ready
Definition: ecg4.h:133
ecg4_t::cs
digital_out_t cs
Definition: ecg4.h:123
ecg4_t
Click ctx object definition.
Definition: ecg4.h:119
ecg4_module_reset
void ecg4_module_reset(ecg4_t *ctx)
Reset module.
ecg4_cfg_t::cs
pin_name_t cs
Definition: ecg4.h:150
ecg4_uart_isr
void ecg4_uart_isr(ecg4_t *ctx, uint8_t rx_dat)
Uart Interrupt Routine function.
ecg4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ecg4.h:144
ecg4_cfg_t
Click configuration structure definition.
Definition: ecg4.h:141
ecg4_cfg_setup
void ecg4_cfg_setup(ecg4_cfg_t *cfg)
Config Object Initialization function.
ecg4_generic_write
void ecg4_generic_write(ecg4_t *ctx, char *data_buf, uint16_t len)
Generic write function.
ecg4_t::uart
uart_t uart
Definition: ecg4.h:127
ecg4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ecg4.h:157
ECG4_RETVAL
#define ECG4_RETVAL
Definition: ecg4.h:77
ecg4_t::rst
digital_out_t rst
Definition: ecg4.h:122
ecg4_enable_ldo_ctrl
void ecg4_enable_ldo_ctrl(ecg4_t *ctx, uint8_t state)
LDO Control function.
ecg4_generic_read
int32_t ecg4_generic_read(ecg4_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: ecg4.h:98
ecg4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ecg4.h:145
ecg4_responseReady
uint8_t ecg4_responseReady(ecg4_t *ctx)
Response ready check function.
ecg4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ecg4.h:156
ecg4_t::driver_hdl
ecg4_hdl_t driver_hdl
Definition: ecg4.h:132
ecg4_init
ECG4_RETVAL ecg4_init(ecg4_t *ctx, ecg4_cfg_t *cfg)
Initialization function.
ecg4_cfg_t::uart_blocking
bool uart_blocking
Definition: ecg4.h:155