From a004d2526a0fc95b56d1e12ce6d35f96967f084d Mon Sep 17 00:00:00 2001 From: Brendan Haines Date: Wed, 24 Apr 2024 00:25:40 -0600 Subject: [PATCH] fix bmp288 and stub in hdc1080 --- app/src/main.c | 68 ++++++++++++++++----- boards/bh/mellifera_rev1/mellifera_rev1.dts | 7 ++- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/app/src/main.c b/app/src/main.c index 675686b..392a9a1 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -30,7 +30,7 @@ int main(void) dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display)); if (!device_is_ready(dev)) { - printf("Device %s not ready\n", dev->name); + LOG_ERR("Device %s not ready\n", dev->name); return 0; } @@ -38,7 +38,7 @@ int main(void) { if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO01) != 0) { - printf("Failed to set required pixel format"); + LOG_ERR("Failed to set required pixel format"); return 0; } } @@ -47,7 +47,7 @@ int main(void) if (cfb_framebuffer_init(dev)) { - printf("Framebuffer initialization failed!\n"); + LOG_ERR("Framebuffer initialization failed!\n"); return 0; } @@ -81,29 +81,38 @@ int main(void) cfb_set_kerning(dev, 3); - const struct device *ina, *bmp; + const struct device *ina, *bmp, *hdc; ina = DEVICE_DT_GET(DT_NODELABEL(ina231)); if (!device_is_ready(dev)) { - printf("Device %s not ready\n", ina->name); + LOG_ERR("Device %s not ready\n", ina->name); return 0; } bmp = DEVICE_DT_GET(DT_NODELABEL(bmp388)); if (!device_is_ready(dev)) { - printf("Device %s not ready\n", bmp->name); + LOG_ERR("Device %s not ready\n", bmp->name); return 0; } + // hdc = DEVICE_DT_GET(DT_NODELABEL(hdc1080)); + // if (!device_is_ready(dev)) + // { + // printf("Device %s not ready\n", hdc->name); + // return 0; + // } + while (1) { int ret; - struct sensor_value voltage, current, pressure; + struct sensor_value voltage, current, pressure, temperature, humidity; char str_v[15] = {0}; char str_i[15] = {0}; - char str_p[15] = {0}; + char str_p[16] = {0}; + char str_t[16] = {0}; + char str_h[16] = {0}; ret = sensor_sample_fetch(ina); if (ret < 0) @@ -111,17 +120,16 @@ int main(void) LOG_ERR("Could not fetch sample (%d)", ret); return 0; } - ret = sensor_channel_get(ina, SENSOR_CHAN_VOLTAGE, &voltage); if (ret < 0) { - LOG_ERR("Could not get sample (%d)", ret); + LOG_ERR("Could not get voltage (%d)", ret); return 0; } ret = sensor_channel_get(ina, SENSOR_CHAN_CURRENT, ¤t); if (ret < 0) { - LOG_ERR("Could not get sample (%d)", ret); + LOG_ERR("Could not get current (%d)", ret); return 0; } @@ -131,12 +139,39 @@ int main(void) LOG_ERR("Could not fetch sample (%d)", ret); return 0; } + ret = sensor_channel_get(bmp, SENSOR_CHAN_PRESS, &pressure); + if (ret < 0) + { + LOG_ERR("Could not get pressure (%d)", ret); + return 0; + } + ret = sensor_channel_get(bmp, SENSOR_CHAN_AMBIENT_TEMP, &temperature); + if (ret < 0) + { + LOG_ERR("Could not get temperature (%d)", ret); + return 0; + } + + // ret = sensor_sample_fetch(hdc); + // if (ret < 0) + // { + // LOG_ERR("Could not fetch sample (%d)", ret); + // return 0; + // } + // ret = sensor_channel_get(ina, SENSOR_CHAN_HUMIDITY, &humidity); + // if (ret < 0) + // { + // LOG_ERR("Could not get sample (%d)", ret); + // return 0; + // } sprintf(str_v, "V:%01d.%06d", voltage.val1, voltage.val2); sprintf(str_i, "I:%01d.%06d", current.val1, current.val2); - sprintf(str_p, "P:%05d.%02d", pressure.val1, pressure.val2 / 10000); + sprintf(str_p, "P:%03d.%04d", pressure.val1, pressure.val2 / 100); + sprintf(str_t, "T:%03d.%04d", temperature.val1, temperature.val2 / 100); + sprintf(str_h, "H:%05d.%06d", humidity.val1, humidity.val2); - printf("%s\t%s\t%s\n", str_v, str_i, str_p); + printf("%s\t%s\t%s\t%s\n", str_v, str_i, str_p, str_t); cfb_framebuffer_clear(dev, false); if (cfb_print(dev, str_v, 0, 0)) @@ -149,7 +184,12 @@ int main(void) printf("Failed to print a string\n"); continue; } - if (cfb_print(dev, str_p, 0, 32)) + if (cfb_print(dev, str_p, 0, 16 * 2)) + { + printf("Failed to print a string\n"); + continue; + } + if (cfb_print(dev, str_t, 0, 16 * 3)) { printf("Failed to print a string\n"); continue; diff --git a/boards/bh/mellifera_rev1/mellifera_rev1.dts b/boards/bh/mellifera_rev1/mellifera_rev1.dts index fda9927..9ae1da8 100644 --- a/boards/bh/mellifera_rev1/mellifera_rev1.dts +++ b/boards/bh/mellifera_rev1/mellifera_rev1.dts @@ -160,9 +160,14 @@ compatible = "bosch,bmp388"; reg = <0x76>; int-gpios = <&gpio0 27 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; - odr = "1.563"; + // odr = "1.563"; osr-press = <1>; }; + + hdc1080: hdc1080@40 { + compatible = "ti,hdc20xx"; // FIXME: add proper support for this part. Hopefully these parts are close enough + reg = <0x40>; + }; }; &spi1 {