diff --git a/app/src/main.c b/app/src/main.c index aea0bb7..89dc302 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -78,14 +78,46 @@ int main(void) rows, cfb_get_display_parameter(dev, CFB_DISPLAY_COLS)); - cfb_framebuffer_invert(dev); - cfb_set_kerning(dev, 3); + const struct device *ina; + + ina = DEVICE_DT_GET(DT_NODELABEL(ina231)); + if (!device_is_ready(dev)) + { + printf("Device %s not ready\n", ina->name); + return 0; + } + while (1) { for (int i = 0; i < MIN(x_res, y_res); i++) { + int ret; + + ret = sensor_sample_fetch(ina); + if (ret < 0) + { + LOG_ERR("Could not fetch sample (%d)", ret); + return 0; + } + + struct sensor_value voltage, current; + ret = sensor_channel_get(ina, SENSOR_CHAN_VOLTAGE, &voltage); + if (ret < 0) + { + LOG_ERR("Could not get sample (%d)", ret); + return 0; + } + ret = sensor_channel_get(ina, SENSOR_CHAN_CURRENT, ¤t); + if (ret < 0) + { + LOG_ERR("Could not get sample (%d)", ret); + return 0; + } + + printf("voltage: %d.%06d\tcurrent: %d.%06d\n", voltage.val1, voltage.val2, current.val1, current.val2); + cfb_framebuffer_clear(dev, false); if (cfb_print(dev, "0123456789mMgj!\"ยง$%&/()=", diff --git a/boards/bh/mellifera_rev1/mellifera_rev1.dts b/boards/bh/mellifera_rev1/mellifera_rev1.dts index 325e769..d44faa1 100644 --- a/boards/bh/mellifera_rev1/mellifera_rev1.dts +++ b/boards/bh/mellifera_rev1/mellifera_rev1.dts @@ -101,12 +101,6 @@ label = "Interrupt from BMP388 barometer"; zephyr,code = ; }; - - int_pow: int_pow { - gpios = <&gpio0 31 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; - label = "Interrupt from current sensor"; - zephyr,code = ; - }; }; @@ -145,7 +139,6 @@ pinctrl-1 = <&i2c0_sleep>; pinctrl-names = "default", "sleep"; - ssd1306: ssd1306@3d { compatible = "solomon,ssd1306fb"; reg = <0x3d>; @@ -159,6 +152,15 @@ com-invdir; prechargep = <0x22>; }; + + ina231: ina231@45 { + compatible = "ti,ina230"; + reg = <0x45>; + // irq-gpios = <&gpio0 31 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + current-lsb-microamps = <7>; + rshunt-micro-ohms = <50000>; + adc-mode = "Bus and shunt voltage continuous"; + }; }; &spi1 {