diff --git a/bootloader/bootloader-display.c b/bootloader/bootloader-display.c index c9f7f795e5d62b6b301fbd6bb9ae0a9137405a4b..abc8dfc209218c80046e46be7a12d1639f4644ec 100644 --- a/bootloader/bootloader-display.c +++ b/bootloader/bootloader-display.c @@ -19,7 +19,7 @@ static void bootloader_display_splash(void) Color white = gfx_color(&display_screen, WHITE); Color black = gfx_color(&display_screen, BLACK); for (int i = 0; i < sizeof(splash); i++) { - Color color = (splash[i] & 0x80) ? white : black; + Color color = (splash[i] & 0x80) ? white : black; uint8_t length = splash[i] & 0x7f; for (int j = 0; j < length; j++) { diff --git a/epicardium/main.c b/epicardium/main.c index bcbce41efe292e3f030c8006c41b43f09ca9450d..719bb3bba1f6666d8dc8f889b015a9c42e192378 100644 --- a/epicardium/main.c +++ b/epicardium/main.c @@ -51,8 +51,9 @@ int main(void) card10_init(); card10_diag(); - gfx_copy_region_raw(&display_screen, 0, 0, 160, 80, - 2, (const void *)(Heart)); + gfx_copy_region_raw( + &display_screen, 0, 0, 160, 80, 2, (const void *)(Heart) + ); gfx_update(&display_screen); /* TODO: Move this to its own function */ diff --git a/epicardium/modules/display.c b/epicardium/modules/display.c index 414a7a426341e33ec44e0f9f9b47f8021e6dd7ce..afb0401d2ad0e97666972345d2e120e132f1cc48 100644 --- a/epicardium/modules/display.c +++ b/epicardium/modules/display.c @@ -73,8 +73,15 @@ int epic_disp_line( return cl; } else { /* TODO add linestyle support to gfx code */ - gfx_thick_line(&display_screen, xstart, ystart, xend, yend, - pixelsize, color); + gfx_thick_line( + &display_screen, + xstart, + ystart, + xend, + yend, + pixelsize, + color + ); return 0; } } @@ -94,12 +101,25 @@ int epic_disp_rect( switch (fillstyle) { case FILLSTYLE_EMPTY: - gfx_rectangle(&display_screen, xstart, ystart, xend - xstart, - yend - ystart, pixelsize, color); + gfx_rectangle( + &display_screen, + xstart, + ystart, + xend - xstart, + yend - ystart, + pixelsize, + color + ); break; case FILLSTYLE_FILLED: - gfx_rectangle_fill(&display_screen, xstart, ystart, - xend - xstart, yend - ystart, color); + gfx_rectangle_fill( + &display_screen, + xstart, + ystart, + xend - xstart, + yend - ystart, + color + ); break; } return 0; diff --git a/hw-tests/bmetest/main.c b/hw-tests/bmetest/main.c index 7f2c592f9f0059dde266e4f06605901aa9d355cf..16244ec81b1eef71b8c28cc259c86c9ef18ff056 100644 --- a/hw-tests/bmetest/main.c +++ b/hw-tests/bmetest/main.c @@ -38,79 +38,90 @@ int main(void) /* amb_temp can be set to 25 prior to configuring the gas sensor * or by performing a few temperature readings without operating the gas sensor. */ - gas_sensor.amb_temp = 25; - - int8_t rslt = BME680_OK; - rslt = bme680_init(&gas_sensor); - - if(rslt != BME680_OK) { - printf("Failed to init BME680\n"); - } - uint8_t set_required_settings; - - /* Set the temperature, pressure and humidity settings */ - gas_sensor.tph_sett.os_hum = BME680_OS_2X; - gas_sensor.tph_sett.os_pres = BME680_OS_4X; - gas_sensor.tph_sett.os_temp = BME680_OS_8X; - gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3; - - /* Set the remaining gas sensor settings and link the heating profile */ - gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS; - /* Create a ramp heat waveform in 3 steps */ - gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */ - gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */ - - /* Select the power mode */ - /* Must be set before writing the sensor configuration */ - gas_sensor.power_mode = BME680_FORCED_MODE; - - /* Set the required sensor settings needed */ - set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL - | BME680_GAS_SENSOR_SEL; - - /* Set the desired sensor configuration */ - rslt = bme680_set_sensor_settings(set_required_settings,&gas_sensor); - - /* Set the power mode */ - rslt = bme680_set_sensor_mode(&gas_sensor); - - Color white = gfx_color(&display_screen, WHITE); - Color black = gfx_color(&display_screen, BLACK); - while (1) { - TMR_Delay(MXC_TMR0, MSEC(1000), 0); - - struct bme680_field_data data; - rslt = bme680_get_sensor_data(&data, &gas_sensor); - - printf("T: %.2Lf degC, P: %.2Lf hPa, H %.2Lf %%rH ", data.temperature / 100.0l, - data.pressure / 100.0l, data.humidity / 1000.0l ); - - char buf[128]; - sprintf(buf, "T: %.2Lf degC", data.temperature / 100.0l); - gfx_puts(&Font16, &display_screen, 0, 0, buf, white, black); - - sprintf(buf, "P: %.2Lf hPa", data.pressure / 100.0l); - gfx_puts(&Font16, &display_screen, 0, 16, buf, white, black); - - sprintf(buf, "H: %.2Lf %%rH", data.humidity / 1000.0l); - gfx_puts(&Font16, &display_screen, 0, 32, buf, white, black); - - //printf("%.2f,%.2f,%.2f\n", data.temperature / 100.0f, - // data.pressure / 100.0f, data.humidity / 1000.0f ); - /* Avoid using measurements from an unstable heating setup */ - if(data.status & BME680_GASM_VALID_MSK) { - printf(", 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_update(&display_screen); - - printf("\n"); - - /* Trigger the next measurement if you would like to read data out continuously */ - if (gas_sensor.power_mode == BME680_FORCED_MODE) { - rslt = bme680_set_sensor_mode(&gas_sensor); - } - } + gas_sensor.amb_temp = 25; + + int8_t rslt = BME680_OK; + rslt = bme680_init(&gas_sensor); + + if (rslt != BME680_OK) { + printf("Failed to init BME680\n"); + } + uint8_t set_required_settings; + + /* Set the temperature, pressure and humidity settings */ + gas_sensor.tph_sett.os_hum = BME680_OS_2X; + gas_sensor.tph_sett.os_pres = BME680_OS_4X; + gas_sensor.tph_sett.os_temp = BME680_OS_8X; + gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3; + + /* Set the remaining gas sensor settings and link the heating profile */ + gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS; + /* Create a ramp heat waveform in 3 steps */ + gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */ + gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */ + + /* Select the power mode */ + /* Must be set before writing the sensor configuration */ + gas_sensor.power_mode = BME680_FORCED_MODE; + + /* Set the required sensor settings needed */ + set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | + BME680_OSH_SEL | BME680_FILTER_SEL | + BME680_GAS_SENSOR_SEL; + + /* Set the desired sensor configuration */ + rslt = bme680_set_sensor_settings(set_required_settings, &gas_sensor); + + /* Set the power mode */ + rslt = bme680_set_sensor_mode(&gas_sensor); + + Color white = gfx_color(&display_screen, WHITE); + Color black = gfx_color(&display_screen, BLACK); + while (1) { + TMR_Delay(MXC_TMR0, MSEC(1000), 0); + + struct bme680_field_data data; + rslt = bme680_get_sensor_data(&data, &gas_sensor); + + printf("T: %.2Lf degC, P: %.2Lf hPa, H %.2Lf %%rH ", + data.temperature / 100.0l, + data.pressure / 100.0l, + data.humidity / 1000.0l); + + char buf[128]; + sprintf(buf, "T: %.2Lf degC", data.temperature / 100.0l); + gfx_puts(&Font16, &display_screen, 0, 0, buf, white, black); + + sprintf(buf, "P: %.2Lf hPa", data.pressure / 100.0l); + gfx_puts(&Font16, &display_screen, 0, 16, buf, white, black); + + sprintf(buf, "H: %.2Lf %%rH", data.humidity / 1000.0l); + gfx_puts(&Font16, &display_screen, 0, 32, buf, white, black); + + //printf("%.2f,%.2f,%.2f\n", data.temperature / 100.0f, + // data.pressure / 100.0f, data.humidity / 1000.0f ); + /* Avoid using measurements from an unstable heating setup */ + if (data.status & BME680_GASM_VALID_MSK) { + printf(", 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_update(&display_screen); + + printf("\n"); + + /* Trigger the next measurement if you would like to read data out continuously */ + if (gas_sensor.power_mode == BME680_FORCED_MODE) { + rslt = bme680_set_sensor_mode(&gas_sensor); + } + } } diff --git a/hw-tests/bootloader-update/main.c b/hw-tests/bootloader-update/main.c index 0cee4ae9331d9f1091502791e8f2177835dd4cb0..64b492525405431dbc439dfa8571d99147a95c27 100644 --- a/hw-tests/bootloader-update/main.c +++ b/hw-tests/bootloader-update/main.c @@ -42,54 +42,37 @@ int main(void) pmic_set_button_callback(pmic_button); printf("Erasing bootloader.\n"); - Paint_DrawString_EN( - 0, 16 * 0, "Erasing bootloader", &Font16, 0x0000, 0xffff - ); - LCD_Update(); + txt_puts(&display_textb, "Erasing bootloader.\n"); ICC_Disable(); int ret = FLC_MultiPageErase(0x10000000, 0x10000000 + 1024 * 64 - 1); if (ret != E_NO_ERROR) { printf("FLC_MultiPageErase failed with %d\n", ret); - Paint_DrawString_EN( - 0, 16 * 1, "Fail.", &Font16, 0x0000, 0xffff - ); - LCD_Update(); + txt_puts(&display_textb, "Fail.\n"); while (1) ; } - card10_init(); - pmic_set_button_callback(pmic_button); - - printf("Erasing bootloader.\n"); - txt_puts(&display_textb, "Erasing bootloader.\n"); - - ICC_Disable(); - - int ret = FLC_MultiPageErase(0x10000000, 0x10000000 + 1024*64-1); - if(ret != E_NO_ERROR) { - printf("FLC_MultiPageErase failed with %d\n", ret); - txt_puts(&display_textb, "Fail.\n"); - while(1); - } - - - printf("Writing bootloader.\n"); - txt_puts(&display_textb, "Writing bootloader.\n"); + printf("Writing bootloader.\n"); + txt_puts(&display_textb, "Writing bootloader.\n"); - ret = FLC_Write(0x10000000, sizeof(bootloader_data), (uint32_t *)bootloader_data); - if(ret != E_NO_ERROR) { - printf("FLC_Write failed with %d\n", ret); - txt_puts(&display_textb, "Fail.\n"); - while(1); - } - ICC_Enable(); + ret = FLC_Write( + 0x10000000, + sizeof(bootloader_data), + (uint32_t *)bootloader_data + ); + if (ret != E_NO_ERROR) { + printf("FLC_Write failed with %d\n", ret); + txt_puts(&display_textb, "Fail.\n"); + while (1) + ; + } + ICC_Enable(); - printf("Done.\n"); - txt_puts(&display_textb, "Done.\n"); - txt_puts(&display_textb, "Please restart.\n"); + printf("Done.\n"); + txt_puts(&display_textb, "Done.\n"); + txt_puts(&display_textb, "Please restart.\n"); while (1) { card10_poll(); diff --git a/hw-tests/dual-core/main.c b/hw-tests/dual-core/main.c index c451528aa653492dbcb9dc060c2905af53e1c4bd..60636833753d48b3812833266f01876297037a1d 100644 --- a/hw-tests/dual-core/main.c +++ b/hw-tests/dual-core/main.c @@ -22,8 +22,9 @@ int main(void) card10_init(); card10_diag(); - gfx_copy_region_raw(&display_screen, 0, 0, 160, 80, 2, - (const void *)(Heart)); + gfx_copy_region_raw( + &display_screen, 0, 0, 160, 80, 2, (const void *)(Heart) + ); gfx_update(&display_screen); // Release core1 diff --git a/hw-tests/ecgtest/main.c b/hw-tests/ecgtest/main.c index 8ee24ccef96cf776483420bc423d82c728048fac..2ca6cbdd84f9f3279af06eebccbc282b37f41fe9 100644 --- a/hw-tests/ecgtest/main.c +++ b/hw-tests/ecgtest/main.c @@ -152,61 +152,71 @@ static uint8_t prev; static void clear(void) { - gfx_clear(&display_screen); - prev = Y_OFFSET; + gfx_clear(&display_screen); + prev = Y_OFFSET; } static void set(uint8_t index, int8_t val) { + if (val < -Y_SCALE) + val = -Y_SCALE; + if (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; - - int min, max; - if(prev < pos) { - min = prev; - max = pos; - } else { - min = pos; - max = prev; - } + int min, max; + if (prev < pos) { + min = prev; + max = pos; + } else { + min = pos; + max = prev; + } - for(int i = min; i < max + 1; i++) { - LCD_SetUWORD(SIZE_X - index - 1, i, 0xf800); - } + for (int i = min; i < max + 1; i++) { + LCD_SetUWORD(SIZE_X - index - 1, i, 0xf800); + } - prev = pos; + prev = pos; } static int16_t samples[SIZE_X]; void update(void) { - clear(); - - int16_t max = 0; - for(int i=0; i<SIZE_X; i++) { - if(abs(samples[i]) > max) { - max = abs(samples[i]); - } - } - - int16_t scale = max / Y_SCALE + 1; - - char buf[128]; - sprintf(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, BLACK)); + clear(); + int16_t max = 0; + for (int i = 0; i < SIZE_X; i++) { + if (abs(samples[i]) > max) { + max = abs(samples[i]); + } + } - for(int i=0; i<SIZE_X; i++) { - set(i, (samples[i] / scale)); - //set(i, ((samples[i*2] + samples[i*2 + 1]) / scale) / 2); - } + int16_t scale = max / Y_SCALE + 1; + + char buf[128]; + sprintf(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, BLACK) + ); + + for (int i = 0; i < SIZE_X; i++) { + set(i, (samples[i] / scale)); + //set(i, ((samples[i*2] + samples[i*2 + 1]) / scale) / 2); + } - LCD_Update(); + LCD_Update(); } #if 0 diff --git a/hw-tests/hello-world/main.c b/hw-tests/hello-world/main.c index d3f4a285d1d882d816adf54fbd4966e4a50a052a..87fdab3ba7d8bf33eea462ce5b71d0bf1eacbd5e 100644 --- a/hw-tests/hello-world/main.c +++ b/hw-tests/hello-world/main.c @@ -30,9 +30,10 @@ int main(void) card10_init(); card10_diag(); - gfx_copy_region_raw(&display_screen, 0, 0, 160, 80, 2, - (const void *)(Heart)); - gfx_update(&display_screen); + gfx_copy_region_raw( + &display_screen, 0, 0, 160, 80, 2, (const void *)(Heart) + ); + gfx_update(&display_screen); for (int i = 0; i < 11; i++) { // leds_set_dim(i, 1); diff --git a/hw-tests/imutest/main.c b/hw-tests/imutest/main.c index b116d3b020ee88d452cd2f75e9423329b1e96ead..9472d57f0a8b5f363935df3e05d8b03a8a2df615 100644 --- a/hw-tests/imutest/main.c +++ b/hw-tests/imutest/main.c @@ -49,7 +49,7 @@ void draw_arrow(int angle, int color) int x2 = x1 - sin * 30; int y2 = y1 - cos * 30; - gfx_thick_line(&display_screen, x1, y1, x2, y2, 2, color); + gfx_thick_line(&display_screen, x1, y1, x2, y2, 2, color); sin = sinf((angle - 140) * 2 * M_PI / 360.); cos = cosf((angle - 140) * 2 * M_PI / 360.); @@ -57,7 +57,7 @@ void draw_arrow(int angle, int color) int x3 = x2 - sin * 10; int y3 = y2 - cos * 10; - gfx_thick_line(&display_screen, x2, y2, x3, y3, 2, color); + gfx_thick_line(&display_screen, x2, y2, x3, y3, 2, color); sin = sinf((angle + 140) * 2 * M_PI / 360.); cos = cosf((angle + 140) * 2 * M_PI / 360.); @@ -65,46 +65,51 @@ void draw_arrow(int angle, int color) int x4 = x2 - sin * 10; int y4 = y2 - cos * 10; - gfx_thick_line(&display_screen, x2, y2, x4, y4, 2, color); + gfx_thick_line(&display_screen, x2, y2, x4, y4, 2, color); } /***** Functions *****/ -static void sensors_callback_orientation(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id) -{ - static int prev = -1; - printf("azimuth=%05d, pitch=%05d, roll=%05d status=%d\n", - sensor_data->data_vector.x * 360 / 32768, - sensor_data->data_vector.y * 360 / 32768, - sensor_data->data_vector.z * 360 / 32768, - sensor_data->data_vector.status - ); - - int angle = sensor_data->data_vector.x * 360 / 32768; - - if(angle != prev) { - gfx_clear(&display_screen); - - int colors[] = { - gfx_color(&display_screen, RED), - gfx_color(&display_screen, YELLOW), - gfx_color(&display_screen, YELLOW), - gfx_color(&display_screen, GREEN) - }; - int color = colors[sensor_data->data_vector.status]; - draw_arrow(sensor_data->data_vector.x * 360 / 32768, color); - - char buf[128]; - //sprintf(buf, "Azimuth: %3d", angle); - //Paint_DrawString_EN(0, 0, buf, &Font12, BLACK, color); - - sprintf(buf, "%3d", angle); - gfx_puts(&Font24, &display_screen, 0, 30, buf, color, - gfx_color(&display_screen, BLACK)); - gfx_circle(&display_screen, 57, 35, 4, 2, color); - - gfx_update(&display_screen); - prev = angle; - } +static void sensors_callback_orientation( + bhy_data_generic_t *sensor_data, bhy_virtual_sensor_t sensor_id +) { + static int prev = -1; + printf("azimuth=%05d, pitch=%05d, roll=%05d status=%d\n", + sensor_data->data_vector.x * 360 / 32768, + sensor_data->data_vector.y * 360 / 32768, + sensor_data->data_vector.z * 360 / 32768, + sensor_data->data_vector.status); + + int angle = sensor_data->data_vector.x * 360 / 32768; + + if (angle != prev) { + gfx_clear(&display_screen); + + int colors[] = { gfx_color(&display_screen, RED), + gfx_color(&display_screen, YELLOW), + gfx_color(&display_screen, YELLOW), + gfx_color(&display_screen, GREEN) }; + int color = colors[sensor_data->data_vector.status]; + draw_arrow(sensor_data->data_vector.x * 360 / 32768, color); + + char buf[128]; + //sprintf(buf, "Azimuth: %3d", angle); + //Paint_DrawString_EN(0, 0, buf, &Font12, BLACK, color); + + sprintf(buf, "%3d", angle); + gfx_puts( + &Font24, + &display_screen, + 0, + 30, + buf, + color, + gfx_color(&display_screen, BLACK) + ); + gfx_circle(&display_screen, 57, 35, 4, 2, color); + + gfx_update(&display_screen); + prev = angle; + } } static __attribute__((unused)) void sensors_callback_vector( diff --git a/hw-tests/ips/main.c b/hw-tests/ips/main.c index f55edd4ee4c8cdf1e2ea92e3045d527c26c8d25f..888185ed07e856e29d47b9559c59efeeee9e91ca 100644 --- a/hw-tests/ips/main.c +++ b/hw-tests/ips/main.c @@ -21,32 +21,46 @@ // ***************************************************************************** int main(void) { - int count = 0; - - card10_init(); - card10_diag(); - - Color red = gfx_color(&display_screen, RED); - Color green = gfx_color(&display_screen, GREEN); - Color yellow = gfx_color(&display_screen, YELLOW); - - gfx_puts(&Font24, &display_screen, 0, 0, "123", 0x000f, 0xfff8); - gfx_puts(&Font24, &display_screen, 23, 0, "ABC", 0x000f, 0xfff8); - gfx_rectangle(&display_screen, 70, 10, 100, 40, 2, red); - gfx_thick_line(&display_screen, 70, 10, 100, 40, 2, green); - gfx_thick_line(&display_screen, 100, 10, 70, 40, 2, yellow); - gfx_circle(&display_screen, 85, 25, 22, 2, green); - - gfx_copy_region_raw(&display_screen, 120, 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); - - DEV_Delay_ms(3000); - - while (1) { - TMR_Delay(MXC_TMR0, MSEC(1000), 0); - printf("count = %d\n", count++); - } + int count = 0; + + card10_init(); + card10_diag(); + + Color red = gfx_color(&display_screen, RED); + Color green = gfx_color(&display_screen, GREEN); + Color yellow = gfx_color(&display_screen, YELLOW); + + gfx_puts(&Font24, &display_screen, 0, 0, "123", 0x000f, 0xfff8); + gfx_puts(&Font24, &display_screen, 23, 0, "ABC", 0x000f, 0xfff8); + gfx_rectangle(&display_screen, 70, 10, 100, 40, 2, red); + gfx_thick_line(&display_screen, 70, 10, 100, 40, 2, green); + gfx_thick_line(&display_screen, 100, 10, 70, 40, 2, yellow); + gfx_circle(&display_screen, 85, 25, 22, 2, green); + + gfx_copy_region_raw( + &display_screen, + 120, + 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); + + DEV_Delay_ms(3000); + + while (1) { + TMR_Delay(MXC_TMR0, MSEC(1000), 0); + printf("count = %d\n", count++); + } }