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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define ECG4_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.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
57 
63 #define ECG4_RETVAL uint8_t
64 
65 #define ECG4_OK 0x00
66 #define ECG4_INIT_ERROR 0xFF
67 
69 #define ECG4_SYNC_BYTE 0xAA
70 #define ECG4_EXCODE_BYTE 0x55
71 #define ECG4_SIGNAL_QUALITY_CODE_BYTE 0x02
72 #define ECG4_HEART_RATE_CODE_BYTE 0x03
73 #define ECG4_RAW_DATA_CODE_BYTE 0x80
74 #define ECG4_RESPONSE_READY 0x01
75 #define ECG4_RESPONSE_NOT_READY 0x00
76 #define ECG4_ENABLE_LDO_CTRL 0x01
77 #define ECG4_DISABLE_LDO_CTRL 0x00
78 
83 #define DRV_RX_BUFFER_SIZE 1000
84 #define DRV_TX_BUFFER_SIZE 50
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
89 
99 typedef void ( *ecg4_hdl_t )( uint8_t*, uint8_t*, uint8_t*, uint8_t* );
100 
104 typedef struct
105 {
106  // Output pins
107 
108  digital_out_t rst;
109  digital_out_t cs;
110 
111  // Modules
112 
113  uart_t uart;
114 
115  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
116  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
117 
119  uint8_t response_ready;
120 
121 } ecg4_t;
122 
126 typedef struct
127 {
128  // Communication gpio pins
129 
130  pin_name_t rx_pin;
131  pin_name_t tx_pin;
132 
133  // Additional gpio pins
134 
135  pin_name_t rst;
136  pin_name_t cs;
137 
138  // static variable
139 
140  uint32_t baud_rate; // Clock speed.
142  uart_data_bits_t data_bit; // Data bits.
143  uart_parity_t parity_bit; // Parity bit.
144  uart_stop_bits_t stop_bit; // Stop bits.
145 
146 } ecg4_cfg_t;
147 
151 typedef uint8_t ecg4_error_t;
152  // End types group
154 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
155 
161 #ifdef __cplusplus
162 extern "C"{
163 #endif
164 
174 
184 
189 void ecg4_module_reset ( ecg4_t *ctx );
190 
197 void ecg4_generic_write ( ecg4_t *ctx, char *data_buf, uint16_t len );
198 
206 int32_t ecg4_generic_read ( ecg4_t *ctx, char *data_buf, uint16_t max_len );
207 
222 void ecg4_enable_ldo_ctrl ( ecg4_t *ctx, uint8_t state );
223 
231 void ecg4_uart_isr( ecg4_t *ctx, uint8_t rx_dat );
232 
240 uint8_t ecg4_responseReady( ecg4_t *ctx );
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // _ECG4_H_
246  // End public_function group
249 
250 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: ecg4.h:83
ecg4_cfg_t::baud_rate
uint32_t baud_rate
Definition: ecg4.h:140
ecg4_cfg_t::rst
pin_name_t rst
Definition: ecg4.h:135
ecg4_hdl_t
void(* ecg4_hdl_t)(uint8_t *, uint8_t *, uint8_t *, uint8_t *)
Definition: ecg4.h:99
ecg4_error_t
uint8_t ecg4_error_t
Error type.
Definition: ecg4.h:151
ecg4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ecg4.h:144
ecg4_t::response_ready
uint8_t response_ready
Definition: ecg4.h:119
ecg4_t::cs
digital_out_t cs
Definition: ecg4.h:109
ecg4_t
Click ctx object definition.
Definition: ecg4.h:105
ecg4_module_reset
void ecg4_module_reset(ecg4_t *ctx)
Reset module.
ecg4_cfg_t::cs
pin_name_t cs
Definition: ecg4.h:136
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:130
ecg4_cfg_t
Click configuration structure definition.
Definition: ecg4.h:127
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:113
ecg4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ecg4.h:143
ECG4_RETVAL
#define ECG4_RETVAL
Definition: ecg4.h:63
ecg4_t::rst
digital_out_t rst
Definition: ecg4.h:108
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:84
ecg4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ecg4.h:131
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:142
ecg4_t::driver_hdl
ecg4_hdl_t driver_hdl
Definition: ecg4.h:118
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:141