Skip to content
Snippets Groups Projects
Commit 095c0b7c authored by Mateusz Zalega's avatar Mateusz Zalega
Browse files

coding style: reformatted files modified by the fb & gfx refactor

parent d6c17abe
No related branches found
No related tags found
No related merge requests found
Pipeline #1811 passed
...@@ -51,8 +51,9 @@ int main(void) ...@@ -51,8 +51,9 @@ int main(void)
card10_init(); card10_init();
card10_diag(); card10_diag();
gfx_copy_region_raw(&display_screen, 0, 0, 160, 80, gfx_copy_region_raw(
2, (const void *)(Heart)); &display_screen, 0, 0, 160, 80, 2, (const void *)(Heart)
);
gfx_update(&display_screen); gfx_update(&display_screen);
/* TODO: Move this to its own function */ /* TODO: Move this to its own function */
......
...@@ -73,8 +73,15 @@ int epic_disp_line( ...@@ -73,8 +73,15 @@ int epic_disp_line(
return cl; return cl;
} else { } else {
/* TODO add linestyle support to gfx code */ /* TODO add linestyle support to gfx code */
gfx_thick_line(&display_screen, xstart, ystart, xend, yend, gfx_thick_line(
pixelsize, color); &display_screen,
xstart,
ystart,
xend,
yend,
pixelsize,
color
);
return 0; return 0;
} }
} }
...@@ -94,12 +101,25 @@ int epic_disp_rect( ...@@ -94,12 +101,25 @@ int epic_disp_rect(
switch (fillstyle) { switch (fillstyle) {
case FILLSTYLE_EMPTY: case FILLSTYLE_EMPTY:
gfx_rectangle(&display_screen, xstart, ystart, xend - xstart, gfx_rectangle(
yend - ystart, pixelsize, color); &display_screen,
xstart,
ystart,
xend - xstart,
yend - ystart,
pixelsize,
color
);
break; break;
case FILLSTYLE_FILLED: case FILLSTYLE_FILLED:
gfx_rectangle_fill(&display_screen, xstart, ystart, gfx_rectangle_fill(
xend - xstart, yend - ystart, color); &display_screen,
xstart,
ystart,
xend - xstart,
yend - ystart,
color
);
break; break;
} }
return 0; return 0;
......
...@@ -65,8 +65,9 @@ int main(void) ...@@ -65,8 +65,9 @@ int main(void)
gas_sensor.power_mode = BME680_FORCED_MODE; gas_sensor.power_mode = BME680_FORCED_MODE;
/* Set the required sensor settings needed */ /* Set the required sensor settings needed */
set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL set_required_settings = BME680_OST_SEL | BME680_OSP_SEL |
| BME680_GAS_SENSOR_SEL; BME680_OSH_SEL | BME680_FILTER_SEL |
BME680_GAS_SENSOR_SEL;
/* Set the desired sensor configuration */ /* Set the desired sensor configuration */
rslt = bme680_set_sensor_settings(set_required_settings, &gas_sensor); rslt = bme680_set_sensor_settings(set_required_settings, &gas_sensor);
...@@ -82,8 +83,10 @@ int main(void) ...@@ -82,8 +83,10 @@ int main(void)
struct bme680_field_data data; struct bme680_field_data data;
rslt = bme680_get_sensor_data(&data, &gas_sensor); rslt = bme680_get_sensor_data(&data, &gas_sensor);
printf("T: %.2Lf degC, P: %.2Lf hPa, H %.2Lf %%rH ", data.temperature / 100.0l, printf("T: %.2Lf degC, P: %.2Lf hPa, H %.2Lf %%rH ",
data.pressure / 100.0l, data.humidity / 1000.0l ); data.temperature / 100.0l,
data.pressure / 100.0l,
data.humidity / 1000.0l);
char buf[128]; char buf[128];
sprintf(buf, "T: %.2Lf degC", data.temperature / 100.0l); sprintf(buf, "T: %.2Lf degC", data.temperature / 100.0l);
...@@ -101,7 +104,15 @@ int main(void) ...@@ -101,7 +104,15 @@ int main(void)
if (data.status & BME680_GASM_VALID_MSK) { if (data.status & BME680_GASM_VALID_MSK) {
printf(", G: %ld ohms", data.gas_resistance); printf(", G: %ld ohms", data.gas_resistance);
sprintf(buf, "G: %ld ohms", data.gas_resistance); sprintf(buf, "G: %ld ohms", data.gas_resistance);
gfx_puts(&Font16, &display_screen, 0, 48, buf, white, black); gfx_puts(
&Font16,
&display_screen,
0,
48,
buf,
white,
black
);
} }
gfx_update(&display_screen); gfx_update(&display_screen);
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "gfx.h" #include "gfx.h"
#include "pmic.h" #include "pmic.h"
#include "flc.h" #include "flc.h"
#include "icc.h" #include "icc.h"
#include "tmr_utils.h" #include "tmr_utils.h"
...@@ -37,10 +36,8 @@ static void pmic_button(bool falling) ...@@ -37,10 +36,8 @@ static void pmic_button(bool falling)
} }
} }
int main(void) int main(void)
{ {
card10_init(); card10_init();
pmic_set_button_callback(pmic_button); pmic_set_button_callback(pmic_button);
...@@ -53,18 +50,23 @@ int main(void) ...@@ -53,18 +50,23 @@ int main(void)
if (ret != E_NO_ERROR) { if (ret != E_NO_ERROR) {
printf("FLC_MultiPageErase failed with %d\n", ret); printf("FLC_MultiPageErase failed with %d\n", ret);
txt_puts(&display_textb, "Fail.\n"); txt_puts(&display_textb, "Fail.\n");
while(1); while (1)
;
} }
printf("Writing bootloader.\n"); printf("Writing bootloader.\n");
txt_puts(&display_textb, "Writing bootloader.\n"); txt_puts(&display_textb, "Writing bootloader.\n");
ret = FLC_Write(0x10000000, sizeof(bootloader_data), (uint32_t *)bootloader_data); ret = FLC_Write(
0x10000000,
sizeof(bootloader_data),
(uint32_t *)bootloader_data
);
if (ret != E_NO_ERROR) { if (ret != E_NO_ERROR) {
printf("FLC_Write failed with %d\n", ret); printf("FLC_Write failed with %d\n", ret);
txt_puts(&display_textb, "Fail.\n"); txt_puts(&display_textb, "Fail.\n");
while(1); while (1)
;
} }
ICC_Enable(); ICC_Enable();
......
...@@ -22,8 +22,9 @@ int main(void) ...@@ -22,8 +22,9 @@ int main(void)
card10_init(); card10_init();
card10_diag(); card10_diag();
gfx_copy_region_raw(&display_screen, 0, 0, 160, 80, 2, gfx_copy_region_raw(
(const void *)(Heart)); &display_screen, 0, 0, 160, 80, 2, (const void *)(Heart)
);
gfx_update(&display_screen); gfx_update(&display_screen);
for (int i = 0; i < 11; i++) { for (int i = 0; i < 11; i++) {
......
...@@ -58,7 +58,9 @@ static void ecg_write_reg(uint8_t reg, uint32_t data) ...@@ -58,7 +58,9 @@ static void ecg_write_reg(uint8_t reg, uint32_t data)
{ {
printf("write %02x %06lx\n", reg, data); printf("write %02x %06lx\n", reg, data);
spi_req_t req; spi_req_t req;
uint8_t tx_data[] = {(reg << 1) | 0 , data >> 16, (data >> 8 ) & 0xFF, data & 0xFF}; uint8_t tx_data[] = {
(reg << 1) | 0, data >> 16, (data >> 8) & 0xFF, data & 0xFF
};
uint8_t rx_data[] = { 0, 0, 0, 0 }; uint8_t rx_data[] = { 0, 0, 0, 0 };
req.tx_data = tx_data; req.tx_data = tx_data;
req.rx_data = rx_data; req.rx_data = rx_data;
...@@ -83,12 +85,16 @@ static void ecg_config(bool enable_internal_pull) ...@@ -83,12 +85,16 @@ static void ecg_config(bool enable_internal_pull)
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
if (enable_internal_pull) { if (enable_internal_pull) {
CNFG_GEN_r.bits.rbiasn = 1; // Enable resistive bias on negative input CNFG_GEN_r.bits.rbiasn =
CNFG_GEN_r.bits.rbiasp = 1; // Enable resistive bias on positive input 1; // Enable resistive bias on negative input
CNFG_GEN_r.bits.rbiasp =
1; // Enable resistive bias on positive input
CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias CNFG_GEN_r.bits.en_rbias = 1; // Enable resistive bias
} else { } else {
CNFG_GEN_r.bits.rbiasn = 0; // Enable resistive bias on negative input CNFG_GEN_r.bits.rbiasn =
CNFG_GEN_r.bits.rbiasp = 0; // Enable resistive bias on positive input 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.en_rbias = 0; // Enable resistive bias
} }
...@@ -96,7 +102,6 @@ static void ecg_config(bool enable_internal_pull) ...@@ -96,7 +102,6 @@ static void ecg_config(bool enable_internal_pull)
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);
// ECG Config register setting // ECG Config register setting
union ECGConfiguration_u CNFG_ECG_r; union ECGConfiguration_u CNFG_ECG_r;
CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz CNFG_ECG_r.bits.dlpf = 1; // Digital LPF cutoff = 40Hz
...@@ -107,20 +112,17 @@ static void ecg_config(bool enable_internal_pull) ...@@ -107,20 +112,17 @@ static void ecg_config(bool enable_internal_pull)
//CNFG_ECG_r.bits.rate = 1; // Sample rate = 256 sps //CNFG_ECG_r.bits.rate = 1; // Sample rate = 256 sps
ecg_write_reg(CNFG_ECG, CNFG_ECG_r.all); ecg_write_reg(CNFG_ECG, CNFG_ECG_r.all);
//R-to-R configuration //R-to-R configuration
union RtoR1Configuration_u CNFG_RTOR_r; union RtoR1Configuration_u CNFG_RTOR_r;
CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection CNFG_RTOR_r.bits.en_rtor = 1; // Enable R-to-R detection
ecg_write_reg(CNFG_RTOR1, CNFG_RTOR_r.all); ecg_write_reg(CNFG_RTOR1, CNFG_RTOR_r.all);
//Manage interrupts register setting //Manage interrupts register setting
union ManageInterrupts_u MNG_INT_r; union ManageInterrupts_u MNG_INT_r;
MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples MNG_INT_r.bits.efit = 0b00011; // Assert EINT w/ 4 unread samples
MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back MNG_INT_r.bits.clr_rrint = 0b01; // Clear R-to-R on RTOR reg. read back
ecg_write_reg(MNGR_INT, MNG_INT_r.all); ecg_write_reg(MNGR_INT, MNG_INT_r.all);
//Enable interrupts register setting //Enable interrupts register setting
union EnableInterrupts_u EN_INT_r; union EnableInterrupts_u EN_INT_r;
EN_INT_r.all = 0; EN_INT_r.all = 0;
...@@ -129,7 +131,6 @@ static void ecg_config(bool enable_internal_pull) ...@@ -129,7 +131,6 @@ static void ecg_config(bool enable_internal_pull)
EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup EN_INT_r.bits.intb_type = 3; // Open-drain NMOS with internal pullup
ecg_write_reg(EN_INT, EN_INT_r.all); ecg_write_reg(EN_INT, EN_INT_r.all);
//Dyanmic modes config //Dyanmic modes config
union ManageDynamicModes_u MNG_DYN_r; union ManageDynamicModes_u MNG_DYN_r;
MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled MNG_DYN_r.bits.fast = 0; // Fast recovery mode disabled
...@@ -155,12 +156,12 @@ static void clear(void) ...@@ -155,12 +156,12 @@ static void clear(void)
prev = Y_OFFSET; prev = Y_OFFSET;
} }
static void set(uint8_t index, int8_t val) static void set(uint8_t index, int8_t val)
{ {
if (val < -Y_SCALE)
if(val < -Y_SCALE) val = -Y_SCALE; val = -Y_SCALE;
if(val > Y_SCALE) val = Y_SCALE; if (val > Y_SCALE)
val = Y_SCALE;
int8_t pos = Y_OFFSET + val; int8_t pos = Y_OFFSET + val;
...@@ -195,11 +196,20 @@ void update(void) ...@@ -195,11 +196,20 @@ void update(void)
int16_t scale = max / Y_SCALE + 1; int16_t scale = max / Y_SCALE + 1;
char buf[128]; char buf[128];
sprintf(buf, "Switch: %d Pull: %d Scale: %d", ecg_switch, internal_pull, scale); sprintf(buf,
gfx_puts(&Font8, &display_screen, 0, 0, buf, "Switch: %d Pull: %d Scale: %d",
ecg_switch,
internal_pull,
scale);
gfx_puts(
&Font8,
&display_screen,
0,
0,
buf,
gfx_color(&display_screen, WHITE), gfx_color(&display_screen, WHITE),
gfx_color(&display_screen, BLACK)); gfx_color(&display_screen, BLACK)
);
for (int i = 0; i < SIZE_X; i++) { for (int i = 0; i < SIZE_X; i++) {
set(i, (samples[i] / scale)); set(i, (samples[i] / scale));
...@@ -278,76 +288,41 @@ sampling frequency: 200 Hz ...@@ -278,76 +288,41 @@ sampling frequency: 200 Hz
#define FILTER_TAP_NUM 71 #define FILTER_TAP_NUM 71
static double filter_taps[FILTER_TAP_NUM] = { static double filter_taps[FILTER_TAP_NUM] = {
0.0057445089465822975, 0.0057445089465822975, 0.007451288673767406,
0.007451288673767406, -0.0011523652638272097, -0.0030609271459832005,
-0.0011523652638272097, -0.002596310763437956, 0.004452951934981218,
-0.0030609271459832005, 0.003740429140762826, -0.002351310203707235,
-0.002596310763437956, -0.00638990322759006, 0.000013108391204023357,
0.004452951934981218, 0.007226767366250225, 0.003994033360879168,
0.003740429140762826, -0.00665189327484351, -0.008058131222070393,
-0.002351310203707235, 0.0035814528837470965, 0.011450459869389184,
-0.00638990322759006, 0.0016796020911726648, -0.012657785603199918,
0.000013108391204023357, -0.008611714082779583, 0.010587105712461298,
0.007226767366250225, 0.01581354994840992, -0.0044174953741535905,
0.003994033360879168, -0.021419548904285074, -0.005927897725436821,
-0.00665189327484351, 0.023159558089340265, 0.01973520678092361,
-0.008058131222070393, -0.018604692334579287, -0.035495574517452874,
0.0035814528837470965, 0.004958680854279203, 0.05116349477789529,
0.011450459869389184, 0.02244341207607204, -0.06449371846227892,
0.0016796020911726648, -0.0790927656214483, 0.07342794634140555,
-0.012657785603199918, 0.3089023630319309, 0.42341742792869774,
-0.008611714082779583, 0.3089023630319309, 0.07342794634140555,
0.010587105712461298, -0.0790927656214483, -0.06449371846227892,
0.01581354994840992, 0.02244341207607204, 0.05116349477789529,
-0.0044174953741535905, 0.004958680854279203, -0.035495574517452874,
-0.021419548904285074, -0.018604692334579287, 0.01973520678092361,
-0.005927897725436821, 0.023159558089340265, -0.005927897725436821,
0.023159558089340265, -0.021419548904285074, -0.0044174953741535905,
0.01973520678092361, 0.01581354994840992, 0.010587105712461298,
-0.018604692334579287, -0.008611714082779583, -0.012657785603199918,
-0.035495574517452874, 0.0016796020911726648, 0.011450459869389184,
0.004958680854279203, 0.0035814528837470965, -0.008058131222070393,
0.05116349477789529, -0.00665189327484351, 0.003994033360879168,
0.02244341207607204, 0.007226767366250225, 0.000013108391204023357,
-0.06449371846227892, -0.00638990322759006, -0.002351310203707235,
-0.0790927656214483, 0.003740429140762826, 0.004452951934981218,
0.07342794634140555, -0.002596310763437956, -0.0030609271459832005,
0.3089023630319309, -0.0011523652638272097, 0.007451288673767406,
0.42341742792869774,
0.3089023630319309,
0.07342794634140555,
-0.0790927656214483,
-0.06449371846227892,
0.02244341207607204,
0.05116349477789529,
0.004958680854279203,
-0.035495574517452874,
-0.018604692334579287,
0.01973520678092361,
0.023159558089340265,
-0.005927897725436821,
-0.021419548904285074,
-0.0044174953741535905,
0.01581354994840992,
0.010587105712461298,
-0.008611714082779583,
-0.012657785603199918,
0.0016796020911726648,
0.011450459869389184,
0.0035814528837470965,
-0.008058131222070393,
-0.00665189327484351,
0.003994033360879168,
0.007226767366250225,
0.000013108391204023357,
-0.00638990322759006,
-0.002351310203707235,
0.003740429140762826,
0.004452951934981218,
-0.002596310763437956,
-0.0030609271459832005,
-0.0011523652638272097,
0.007451288673767406,
0.0057445089465822975 0.0057445089465822975
}; };
#endif #endif
...@@ -380,28 +355,31 @@ static void add_sample(int16_t sample) ...@@ -380,28 +355,31 @@ static void add_sample(int16_t sample)
} }
static volatile bool ecgFIFOIntFlag = false; static volatile bool ecgFIFOIntFlag = false;
static void ecgFIFO_callback(void *data) { static void ecgFIFO_callback(void *data)
{
ecgFIFOIntFlag = true; ecgFIFOIntFlag = true;
} }
// ***************************************************************************** // *****************************************************************************
int main(void) int main(void)
{ {
card10_init(); card10_init();
card10_diag(); card10_diag();
const gpio_cfg_t interrupt_pin = {PORT_1, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP}; const gpio_cfg_t interrupt_pin = {
PORT_1, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP
};
GPIO_Config(&interrupt_pin); GPIO_Config(&interrupt_pin);
GPIO_RegisterCallback(&interrupt_pin, ecgFIFO_callback, NULL); GPIO_RegisterCallback(&interrupt_pin, ecgFIFO_callback, NULL);
GPIO_IntConfig(&interrupt_pin, GPIO_INT_EDGE, GPIO_INT_FALLING); GPIO_IntConfig(&interrupt_pin, GPIO_INT_EDGE, GPIO_INT_FALLING);
GPIO_IntEnable(&interrupt_pin); GPIO_IntEnable(&interrupt_pin);
NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(PORT_1)); NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(PORT_1));
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_Config(&analog_switch); GPIO_Config(&analog_switch);
ecg_switch = false; ecg_switch = false;
GPIO_OutClr(&analog_switch); // Wrist GPIO_OutClr(&analog_switch); // Wrist
...@@ -421,7 +399,6 @@ int main(void) ...@@ -421,7 +399,6 @@ int main(void)
max86150_setup(0x1F, 4, 3, 400, 411, 4096); max86150_setup(0x1F, 4, 3, 400, 411, 4096);
#endif #endif
uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status; uint32_t ecgFIFO, readECGSamples, idx, ETAG[32], status;
int16_t ecgSample[32]; int16_t ecgSample[32];
const int EINT_STATUS_MASK = 1 << 23; const int EINT_STATUS_MASK = 1 << 23;
...@@ -430,8 +407,6 @@ int main(void) ...@@ -430,8 +407,6 @@ int main(void)
const int FIFO_FAST_SAMPLE_MASK = 0x1; const int FIFO_FAST_SAMPLE_MASK = 0x1;
const int ETAG_BITS_MASK = 0x7; const int ETAG_BITS_MASK = 0x7;
while (1) { while (1) {
#if 1 #if 1
// Read back ECG samples from the FIFO // Read back ECG samples from the FIFO
...@@ -440,7 +415,8 @@ int main(void) ...@@ -440,7 +415,8 @@ int main(void)
if (PB_Get(3)) { if (PB_Get(3)) {
ecg_switch = !ecg_switch; ecg_switch = !ecg_switch;
while(PB_Get(0)); while (PB_Get(0))
;
if (ecg_switch) { if (ecg_switch) {
GPIO_OutSet(&analog_switch); // USB GPIO_OutSet(&analog_switch); // USB
} else { } else {
...@@ -450,31 +426,40 @@ int main(void) ...@@ -450,31 +426,40 @@ int main(void)
if (PB_Get(4)) { if (PB_Get(4)) {
internal_pull = !internal_pull; internal_pull = !internal_pull;
while(PB_Get(2)); while (PB_Get(2))
;
ecg_config(internal_pull); 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
// Check if EINT interrupt asserted // Check if EINT interrupt asserted
if ((status & EINT_STATUS_MASK) == EINT_STATUS_MASK) { if ((status & EINT_STATUS_MASK) == EINT_STATUS_MASK) {
readECGSamples = 0; // Reset sample counter readECGSamples = 0; // Reset sample counter
do { do {
ecgFIFO = ecg_read_reg(ECG_FIFO ); // Read FIFO ecgFIFO = ecg_read_reg(
ecgSample[readECGSamples] = ecgFIFO >> 8; // Isolate voltage data ECG_FIFO); // Read FIFO
ETAG[readECGSamples] = ( ecgFIFO >> 3 ) & ETAG_BITS_MASK; // Isolate ETAG ecgSample[readECGSamples] =
ecgFIFO >>
8; // Isolate voltage data
ETAG[readECGSamples] =
(ecgFIFO >> 3) &
ETAG_BITS_MASK; // Isolate ETAG
readECGSamples++; // Increment sample counter readECGSamples++; // Increment sample counter
// Check that sample is not last sample in FIFO // Check that sample is not last sample in FIFO
} while ( ETAG[readECGSamples-1] == FIFO_VALID_SAMPLE_MASK || } while (ETAG[readECGSamples - 1] ==
ETAG[readECGSamples-1] == FIFO_FAST_SAMPLE_MASK ); FIFO_VALID_SAMPLE_MASK ||
ETAG[readECGSamples - 1] ==
FIFO_FAST_SAMPLE_MASK);
// Check if FIFO has overflowed // Check if FIFO has overflowed
if (ETAG[readECGSamples - 1] == FIFO_OVF_MASK) { if (ETAG[readECGSamples - 1] == FIFO_OVF_MASK) {
ecg_write_reg(FIFO_RST , 0); // Reset FIFO ecg_write_reg(
FIFO_RST, 0); // Reset FIFO
//printf("OV\n"); //printf("OV\n");
// notifies the user that an over flow occured // notifies the user that an over flow occured
//LED_On(0); //LED_On(0);
......
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
/***** Definitions *****/ /***** Definitions *****/
/***** Globals *****/ /***** Globals *****/
static __attribute__((unused)) const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE}; static __attribute__((unused))
const gpio_cfg_t motor_pin = { PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE };
int main(void) int main(void)
{ {
...@@ -29,8 +30,9 @@ int main(void) ...@@ -29,8 +30,9 @@ int main(void)
card10_init(); card10_init();
card10_diag(); card10_diag();
gfx_copy_region_raw(&display_screen, 0, 0, 160, 80, 2, gfx_copy_region_raw(
(const void *)(Heart)); &display_screen, 0, 0, 160, 80, 2, (const void *)(Heart)
);
gfx_update(&display_screen); gfx_update(&display_screen);
for (int i = 0; i < 11; i++) { for (int i = 0; i < 11; i++) {
......
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
#define MAX_PACKET_LENGTH 18 #define MAX_PACKET_LENGTH 18
#define OUT_BUFFER_SIZE 60 #define OUT_BUFFER_SIZE 60
/***** Globals *****/ /***** Globals *****/
char out_buffer[OUT_BUFFER_SIZE] = " W: 0.999 X: 0.999 Y: 0.999 Z: 0.999 \r"; char out_buffer[OUT_BUFFER_SIZE] =
" W: 0.999 X: 0.999 Y: 0.999 Z: 0.999 \r";
uint8_t fifo[FIFO_SIZE]; uint8_t fifo[FIFO_SIZE];
void draw_arrow(int angle, int color) void draw_arrow(int angle, int color)
...@@ -69,27 +69,25 @@ void draw_arrow(int angle, int color) ...@@ -69,27 +69,25 @@ void draw_arrow(int angle, int color)
} }
/***** Functions *****/ /***** Functions *****/
static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id) static void sensors_callback_orientation(
{ bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
static int prev = -1; static int prev = -1;
printf("azimuth=%05d, pitch=%05d, roll=%05d status=%d\n", printf("azimuth=%05d, pitch=%05d, roll=%05d status=%d\n",
sensor_data->data_vector.x * 360 / 32768, sensor_data->data_vector.x * 360 / 32768,
sensor_data->data_vector.y * 360 / 32768, sensor_data->data_vector.y * 360 / 32768,
sensor_data->data_vector.z * 360 / 32768, sensor_data->data_vector.z * 360 / 32768,
sensor_data->data_vector.status sensor_data->data_vector.status);
);
int angle = sensor_data->data_vector.x * 360 / 32768; int angle = sensor_data->data_vector.x * 360 / 32768;
if (angle != prev) { if (angle != prev) {
gfx_clear(&display_screen); gfx_clear(&display_screen);
int colors[] = { int colors[] = { gfx_color(&display_screen, RED),
gfx_color(&display_screen, RED),
gfx_color(&display_screen, YELLOW), gfx_color(&display_screen, YELLOW),
gfx_color(&display_screen, YELLOW), gfx_color(&display_screen, YELLOW),
gfx_color(&display_screen, GREEN) gfx_color(&display_screen, GREEN) };
};
int color = colors[sensor_data->data_vector.status]; int color = colors[sensor_data->data_vector.status];
draw_arrow(sensor_data->data_vector.x * 360 / 32768, color); draw_arrow(sensor_data->data_vector.x * 360 / 32768, color);
...@@ -98,8 +96,15 @@ static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_v ...@@ -98,8 +96,15 @@ static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_v
//Paint_DrawString_EN(0, 0, buf, &Font12, BLACK, color); //Paint_DrawString_EN(0, 0, buf, &Font12, BLACK, color);
sprintf(buf, "%3d", angle); sprintf(buf, "%3d", angle);
gfx_puts(&Font24, &display_screen, 0, 30, buf, color, gfx_puts(
gfx_color(&display_screen, BLACK)); &Font24,
&display_screen,
0,
30,
buf,
color,
gfx_color(&display_screen, BLACK)
);
gfx_circle(&display_screen, 57, 35, 4, 2, color); gfx_circle(&display_screen, 57, 35, 4, 2, color);
gfx_update(&display_screen); gfx_update(&display_screen);
...@@ -107,36 +112,35 @@ static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_v ...@@ -107,36 +112,35 @@ static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_v
} }
} }
static __attribute__((unused)) void sensors_callback_vector(
static __attribute__((unused)) void sensors_callback_vector(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id) bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
{ ) {
printf("x=%05d, y=%05d, z=%05d status=%d\n", printf("x=%05d, y=%05d, z=%05d status=%d\n",
sensor_data->data_vector.x, sensor_data->data_vector.x,
sensor_data->data_vector.y, sensor_data->data_vector.y,
sensor_data->data_vector.z, sensor_data->data_vector.z,
sensor_data->data_vector.status sensor_data->data_vector.status);
);
} }
static __attribute__((unused)) void sensors_callback_vector_uncalib(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id) static __attribute__((unused)) void sensors_callback_vector_uncalib(
{ bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
printf("x=%05d, y=%05d, z=%05d status=%d\n", printf("x=%05d, y=%05d, z=%05d status=%d\n",
sensor_data->data_uncalib_vector.x, sensor_data->data_uncalib_vector.x,
sensor_data->data_uncalib_vector.y, sensor_data->data_uncalib_vector.y,
sensor_data->data_uncalib_vector.z, sensor_data->data_uncalib_vector.z,
sensor_data->data_uncalib_vector.status sensor_data->data_uncalib_vector.status);
);
} }
/*! /*!
* @brief This function is callback function for acquring sensor datas * @brief This function is callback function for acquring sensor datas
* *
* @param[in] sensor_data * @param[in] sensor_data
* @param[in] sensor_id * @param[in] sensor_id
*/ */
static __attribute__((unused)) void sensors_callback_rotation_vector(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id) static __attribute__((unused)) void sensors_callback_rotation_vector(
{ bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id
) {
#if 0 #if 0
float temp; float temp;
uint8_t index; uint8_t index;
...@@ -190,8 +194,7 @@ static __attribute__((unused)) void sensors_callback_rotation_vector(bhy_data_ge ...@@ -190,8 +194,7 @@ static __attribute__((unused)) void sensors_callback_rotation_vector(bhy_data_ge
sensor_data->data_quaternion.x, sensor_data->data_quaternion.x,
sensor_data->data_quaternion.y, sensor_data->data_quaternion.y,
sensor_data->data_quaternion.z, sensor_data->data_quaternion.z,
sensor_data->data_quaternion.w sensor_data->data_quaternion.w);
);
} }
// ***************************************************************************** // *****************************************************************************
...@@ -221,8 +224,10 @@ int main(void) ...@@ -221,8 +224,10 @@ int main(void)
//if(bhy_install_sensor_callback(VS_TYPE_GRAVITY, VS_WAKEUP, sensors_callback_vector)) //if(bhy_install_sensor_callback(VS_TYPE_GRAVITY, VS_WAKEUP, sensors_callback_vector))
//if(bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sensors_callback_vector)) //if(bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sensors_callback_vector))
//if(bhy_install_sensor_callback(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, sensors_callback_vector_uncalib)) //if(bhy_install_sensor_callback(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, sensors_callback_vector_uncalib))
if(bhy_install_sensor_callback(VS_TYPE_ORIENTATION, VS_WAKEUP, sensors_callback_orientation)) if (bhy_install_sensor_callback(
{ VS_TYPE_ORIENTATION,
VS_WAKEUP,
sensors_callback_orientation)) {
printf("Fail to install sensor callback\n"); printf("Fail to install sensor callback\n");
} }
...@@ -234,52 +239,67 @@ int main(void) ...@@ -234,52 +239,67 @@ int main(void)
} }
#endif #endif
/* enables the virtual sensor */ /* enables the virtual sensor */
//if(bhy_enable_virtual_sensor(VS_TYPE_GEOMAGNETIC_FIELD, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0)) //if(bhy_enable_virtual_sensor(VS_TYPE_GEOMAGNETIC_FIELD, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_GRAVITY, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0)) //if(bhy_enable_virtual_sensor(VS_TYPE_GRAVITY, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0)) //if(bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0)) //if(bhy_enable_virtual_sensor(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
if(bhy_enable_virtual_sensor(VS_TYPE_ORIENTATION, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0)) if (bhy_enable_virtual_sensor(
{ VS_TYPE_ORIENTATION,
printf("Fail to enable sensor id=%d\n", VS_TYPE_GEOMAGNETIC_FIELD); VS_WAKEUP,
ROTATION_VECTOR_SAMPLE_RATE,
0,
VS_FLUSH_NONE,
0,
0)) {
printf("Fail to enable sensor id=%d\n",
VS_TYPE_GEOMAGNETIC_FIELD);
} }
while (1) {
while(1)
{
/* wait until the interrupt fires */ /* wait until the interrupt fires */
/* unless we already know there are bytes remaining in the fifo */ /* unless we already know there are bytes remaining in the fifo */
while (!GPIO_InGet(&bhi_interrupt_pin) && !bytes_remaining); while (!GPIO_InGet(&bhi_interrupt_pin) && !bytes_remaining)
;
bhy_read_fifo(fifo + bytes_left_in_fifo, FIFO_SIZE - bytes_left_in_fifo, &bytes_read, &bytes_remaining);
bhy_read_fifo(
fifo + bytes_left_in_fifo,
FIFO_SIZE - bytes_left_in_fifo,
&bytes_read,
&bytes_remaining
);
bytes_read += bytes_left_in_fifo; bytes_read += bytes_left_in_fifo;
fifoptr = fifo; fifoptr = fifo;
packet_type = BHY_DATA_TYPE_PADDING; packet_type = BHY_DATA_TYPE_PADDING;
do do {
{
/* this function will call callbacks that are registered */ /* this function will call callbacks that are registered */
result = bhy_parse_next_fifo_packet(&fifoptr, &bytes_read, &fifo_packet, &packet_type); result = bhy_parse_next_fifo_packet(
&fifoptr,
&bytes_read,
&fifo_packet,
&packet_type
);
/* prints all the debug packets */ /* prints all the debug packets */
if (packet_type == BHY_DATA_TYPE_DEBUG) if (packet_type == BHY_DATA_TYPE_DEBUG) {
{ bhy_print_debug_packet(
bhy_print_debug_packet(&fifo_packet.data_debug, bhy_printf); &fifo_packet.data_debug, bhy_printf
);
} }
/* the logic here is that if doing a partial parsing of the fifo, then we should not parse */ /* the logic here is that if doing a partial parsing of the fifo, then we should not parse */
/* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */ /* the last 18 bytes (max length of a packet) so that we don't try to parse an incomplete */
/* packet */ /* packet */
} while ((result == BHY_SUCCESS) && (bytes_read > (bytes_remaining ? MAX_PACKET_LENGTH : 0))); } while ((result == BHY_SUCCESS) &&
(bytes_read >
(bytes_remaining ? MAX_PACKET_LENGTH : 0)));
bytes_left_in_fifo = 0; bytes_left_in_fifo = 0;
if (bytes_remaining) if (bytes_remaining) {
{
/* shifts the remaining bytes to the beginning of the buffer */ /* shifts the remaining bytes to the beginning of the buffer */
while (bytes_left_in_fifo < bytes_read) while (bytes_left_in_fifo < bytes_read) {
{
fifo[bytes_left_in_fifo++] = *(fifoptr++); fifo[bytes_left_in_fifo++] = *(fifoptr++);
} }
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
// ***************************************************************************** // *****************************************************************************
int main(void) int main(void)
{ {
...@@ -38,10 +37,24 @@ int main(void) ...@@ -38,10 +37,24 @@ int main(void)
gfx_thick_line(&display_screen, 100, 10, 70, 40, 2, yellow); gfx_thick_line(&display_screen, 100, 10, 70, 40, 2, yellow);
gfx_circle(&display_screen, 85, 25, 22, 2, green); gfx_circle(&display_screen, 85, 25, 22, 2, green);
gfx_copy_region_raw(&display_screen, 120, 0, 40, 40, 2, gfx_copy_region_raw(
(const void *)(gImage_40X40)); &display_screen,
gfx_copy_region_raw(&display_screen, 0, 0, 160, 80, 2, 120,
(const void *)(gImage_160X80)); 0,
40,
40,
2,
(const void *)(gImage_40X40)
);
gfx_copy_region_raw(
&display_screen,
0,
0,
160,
80,
2,
(const void *)(gImage_160X80)
);
gfx_update(&display_screen); gfx_update(&display_screen);
DEV_Delay_ms(3000); DEV_Delay_ms(3000);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment