Skip to content
Snippets Groups Projects
Commit c012ba63 authored by schneider's avatar schneider
Browse files

feat(ecgtest): Allow to switch between USB and wirst, internal pulls yes/no

parent 19c15933
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
/***** Definitions *****/ /***** Definitions *****/
/***** Globals *****/ /***** Globals *****/
static bool ecg_switch;
static bool internal_pull;
/***** Functions *****/ /***** Functions *****/
static uint32_t ecg_read_reg(uint8_t reg) static uint32_t ecg_read_reg(uint8_t reg)
...@@ -66,7 +69,7 @@ static void ecg_write_reg(uint8_t reg, uint32_t data) ...@@ -66,7 +69,7 @@ static void ecg_write_reg(uint8_t reg, uint32_t data)
SPI_MasterTrans(SPI0, &req); SPI_MasterTrans(SPI0, &req);
} }
static void ecg_config(void) static void ecg_config(bool enable_internal_pull)
{ {
// Reset ECG to clear registers // Reset ECG to clear registers
ecg_write_reg(SW_RST , 0); ecg_write_reg(SW_RST , 0);
...@@ -74,9 +77,16 @@ static void ecg_config(void) ...@@ -74,9 +77,16 @@ static void ecg_config(void)
// General config register setting // General config register setting
union GeneralConfiguration_u CNFG_GEN_r; union GeneralConfiguration_u CNFG_GEN_r;
CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel CNFG_GEN_r.bits.en_ecg = 1; // Enable ECG channel
CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input if(enable_internal_pull) {
CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input
CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input
CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
} else {
CNFG_GEN_r.bits.rbiasn = 0; // Enable resistive bias on negative input
CNFG_GEN_r.bits.rbiasp = 0; // Enable resistive bias on positive input
CNFG_GEN_r.bits.en_rbias = 0; // Enable resistive bias
}
CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA CNFG_GEN_r.bits.imag = 2; // Current magnitude = 10nA
CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection CNFG_GEN_r.bits.en_dcloff = 1; // Enable DC lead-off detection
ecg_write_reg(CNFG_GEN , CNFG_GEN_r.all); ecg_write_reg(CNFG_GEN , CNFG_GEN_r.all);
...@@ -131,12 +141,11 @@ static void ecg_config(void) ...@@ -131,12 +141,11 @@ static void ecg_config(void)
#define SIZE_X 160 #define SIZE_X 160
#define SIZE_Y 80 #define SIZE_Y 80
static uint16_t content[SIZE_X*SIZE_Y];
static uint8_t prev; static uint8_t prev;
static void clear(void) static void clear(void)
{ {
memset(content, 0x00, sizeof(content)); Paint_Clear(BLACK);
prev = 32; prev = 32;
} }
...@@ -147,7 +156,7 @@ static void set(uint8_t index, int8_t val) ...@@ -147,7 +156,7 @@ static void set(uint8_t index, int8_t val)
if(val < -31) val = -31; if(val < -31) val = -31;
if(val > 32) val = 32; if(val > 32) val = 32;
int8_t pos = val + 32; int8_t pos = 32 + val;
int min, max; int min, max;
if(prev < pos) { if(prev < pos) {
...@@ -159,55 +168,50 @@ static void set(uint8_t index, int8_t val) ...@@ -159,55 +168,50 @@ static void set(uint8_t index, int8_t val)
} }
for(int i = min; i < max + 1; i++) { for(int i = min; i < max + 1; i++) {
uint16_t *p = content; LCD_SetUWORD(SIZE_X - index - 1, i, RED);
p += i * SIZE_X + (SIZE_X - index - 1);
*p = 0x00F8;
} }
prev = pos; prev = pos;
} }
static int16_t samples[SIZE_X*2]; static int16_t samples[SIZE_X];
void update(void) void update(void)
{ {
clear(); clear();
int16_t scale = 0;
for(int i=0; i<SIZE_X*2; i++) { char buf[128];
if(abs(samples[i]) > scale) { sprintf(buf, "Switch: %d Pull: %d", ecg_switch, internal_pull);
scale = abs(samples[i]); Paint_DrawString_EN(0, 0, buf, &Font8, 0x0000, 0xffff);
int16_t max = 0;
for(int i=0; i<SIZE_X; i++) {
if(abs(samples[i]) > max) {
max = abs(samples[i]);
} }
} }
scale /= 32; int16_t scale = max / 32;
for(int i=0; i<SIZE_X; i++) { for(int i=0; i<SIZE_X; i++) {
set(i, ((samples[i*2] + samples[i*2 + 1]) / scale) / 2); set(i, (samples[i] / scale));
//set(i, ((samples[i*2] + samples[i*2 + 1]) / scale) / 2);
} }
LCD_Set((uint8_t*)content, sizeof(content)); LCD_Update();
} }
static uint8_t sample_count = 0; static uint8_t sample_count = 0;
static void add_sample(int16_t sample) static void add_sample(int16_t sample)
{ {
#if 1 memmove(samples, samples + 1, sizeof(*samples) * (SIZE_X-1));
memmove(samples, samples + 1, sizeof(*samples) * (SIZE_X*2-1)); samples[SIZE_X-1] = sample;
samples[SIZE_X*2-1] = sample;
#else
static index = 0;
samples[index] = sample;
index++;
if(index == SIZE_X*2) {
index = 0;
}
#endif
sample_count++; sample_count++;
if(sample_count == 5) { if(sample_count == 5) {
update();
sample_count = 0; sample_count = 0;
update();
} }
} }
...@@ -230,13 +234,15 @@ int main(void) ...@@ -230,13 +234,15 @@ int main(void)
GPIO_IntEnable(&interrupt_pin); GPIO_IntEnable(&interrupt_pin);
NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(PORT_1)); NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(PORT_1));
// uncomment this to switch ECG to USB connector
#if 0
const gpio_cfg_t analog_switch = {PORT_0, PIN_31, GPIO_FUNC_OUT, GPIO_PAD_NONE}; const gpio_cfg_t analog_switch = {PORT_0, PIN_31, GPIO_FUNC_OUT, GPIO_PAD_NONE};
GPIO_OutSet(&analog_switch); GPIO_Config(&analog_switch);
#endif
ecg_config(); ecg_switch = false;
GPIO_OutClr(&analog_switch); // Wrist
internal_pull = true;
ecg_config(internal_pull);
for(int i=0; i<0x20; i++) { for(int i=0; i<0x20; i++) {
uint32_t val = ecg_read_reg(i); uint32_t val = ecg_read_reg(i);
...@@ -259,6 +265,22 @@ int main(void) ...@@ -259,6 +265,22 @@ int main(void)
if( ecgFIFOIntFlag ) { if( ecgFIFOIntFlag ) {
ecgFIFOIntFlag = false; ecgFIFOIntFlag = false;
if(PB_Get(0)) {
ecg_switch = !ecg_switch;
while(PB_Get(0));
if(ecg_switch) {
GPIO_OutSet(&analog_switch); // USB
} else {
GPIO_OutClr(&analog_switch); // Wrist
}
}
if(PB_Get(2)) {
internal_pull =! internal_pull;
while(PB_Get(2));
ecg_config(internal_pull);
}
//printf("Int\n"); //printf("Int\n");
status = ecg_read_reg( STATUS ); // Read the STATUS register status = ecg_read_reg( STATUS ); // Read the STATUS register
...@@ -291,7 +313,6 @@ int main(void) ...@@ -291,7 +313,6 @@ int main(void)
//printf("%6d\r\n", ecgSample[idx]); //printf("%6d\r\n", ecgSample[idx]);
add_sample(ecgSample[idx]); add_sample(ecgSample[idx]);
} }
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment