diff --git a/src/SensorBHI260AP.hpp b/src/SensorBHI260AP.hpp index b991f58..f99961a 100644 --- a/src/SensorBHI260AP.hpp +++ b/src/SensorBHI260AP.hpp @@ -28,6 +28,7 @@ * @note Most source code references come from the https://github.com/boschsensortec/BHY2-Sensor-API * Simplification for Arduino */ +#pragma once #include "bosch/BoschParse.h" #include "bosch/SensorBhy2Define.h" @@ -332,22 +333,22 @@ class SensorBHI260AP return data; } - void printInterruptCtrl(Stream &steram) + void printInterruptCtrl(Stream &stream) { uint8_t data; __error_code = bhy2_get_host_interrupt_ctrl(&data, bhy2); if (__error_code != BHY2_OK) { return ; } - steram.printf("Host interrupt control\r\n"); - steram.printf("-- Wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_W) ? "disabled" : "enabled"); - steram.printf("-- Non wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_NW) ? "disabled" : "enabled"); - steram.printf("-- Status FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_STATUS_FIFO) ? "disabled" : "enabled"); - steram.printf("-- Debugging %s.\r\n", (data & BHY2_ICTL_DISABLE_DEBUG) ? "disabled" : "enabled"); - steram.printf("-- Fault %s.\r\n", (data & BHY2_ICTL_DISABLE_FAULT) ? "disabled" : "enabled"); - steram.printf("-- Interrupt is %s.\r\n", (data & BHY2_ICTL_ACTIVE_LOW) ? "active low" : "active high"); - steram.printf("-- Interrupt is %s triggered.\r\n", (data & BHY2_ICTL_EDGE) ? "pulse" : "level"); - steram.printf("-- Interrupt pin drive is %s.\r\n", (data & BHY2_ICTL_OPEN_DRAIN) ? "open drain" : "push-pull"); + stream.printf("Host interrupt control\r\n"); + stream.printf("-- Wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_W) ? "disabled" : "enabled"); + stream.printf("-- Non wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_NW) ? "disabled" : "enabled"); + stream.printf("-- Status FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_STATUS_FIFO) ? "disabled" : "enabled"); + stream.printf("-- Debugging %s.\r\n", (data & BHY2_ICTL_DISABLE_DEBUG) ? "disabled" : "enabled"); + stream.printf("-- Fault %s.\r\n", (data & BHY2_ICTL_DISABLE_FAULT) ? "disabled" : "enabled"); + stream.printf("-- Interrupt is %s.\r\n", (data & BHY2_ICTL_ACTIVE_LOW) ? "active low" : "active high"); + stream.printf("-- Interrupt is %s triggered.\r\n", (data & BHY2_ICTL_EDGE) ? "pulse" : "level"); + stream.printf("-- Interrupt pin drive is %s.\r\n", (data & BHY2_ICTL_OPEN_DRAIN) ? "open drain" : "push-pull"); } bool isReady() @@ -449,7 +450,7 @@ class SensorBHI260AP BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_upload_firmware_to_flash failed!", false); } else { log_i("Loading firmware into RAM.\r\n"); - log_i("upload size = %u", length); + log_i("upload size = %lu", length); __error_code = bhy2_upload_firmware_to_ram(firmware, length, bhy2); BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_upload_firmware_to_ram failed!", false); } @@ -500,7 +501,7 @@ class SensorBHI260AP { bhy2_virt_sensor_conf conf; bhy2_get_virt_sensor_cfg(sensor_id, &conf, bhy2); - log_i("range:%u sample_rate:%f latency:%u sensitivity:%u\n", conf.range, conf.sample_rate, conf.latency, conf.sensitivity); + log_i("range:%u sample_rate:%f latency:%lu sensitivity:%u\n", conf.range, conf.sample_rate, conf.latency, conf.sensitivity); return conf; } @@ -522,10 +523,9 @@ class SensorBHI260AP } private: - - static void IRAM_ATTR handleISR(void *available) + static void IRAM_ATTR handleISR() { - *(bool *)(available) = true; + *(bool *)(__data_available) = true; } @@ -545,7 +545,7 @@ class SensorBHI260AP switch (__handler.intf) { case BHY2_I2C_INTERFACE: // esp32s3 test I2C maximum read and write is 64 bytes - __max_rw_lenght = 64; + __max_rw_length = 64; BHY2_RLST_CHECK(!__handler.u.i2c_dev.wire, "Wire ptr NULL", false); if (!SensorInterfaces::setup_interfaces(__handler)) { log_e("setup_interfaces failed"); @@ -555,7 +555,7 @@ class SensorBHI260AP SensorInterfaces::bhy2_i2c_read, SensorInterfaces::bhy2_i2c_write, SensorInterfaces::bhy2_delay_us, - __max_rw_lenght, &__handler, bhy2); + __max_rw_length, &__handler, bhy2); BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_init failed!", false); // __error_code = bhy2_set_host_intf_ctrl(BHY2_I2C_INTERFACE, bhy2); // BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_set_host_intf_ctrl failed!", false); @@ -563,7 +563,7 @@ class SensorBHI260AP case BHY2_SPI_INTERFACE: // esp32s3 test SPI maximum read and write is 256 bytes - __max_rw_lenght = 256; + __max_rw_length = 256; BHY2_RLST_CHECK(!__handler.u.spi_dev.spi, "SPI ptr NULL", false); if (!SensorInterfaces::setup_interfaces(__handler)) { log_e("setup_interfaces failed"); @@ -573,7 +573,7 @@ class SensorBHI260AP SensorInterfaces::bhy2_spi_read, SensorInterfaces::bhy2_spi_write, SensorInterfaces::bhy2_delay_us, - __max_rw_lenght, + __max_rw_length, &__handler, bhy2); BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_init failed!", false); @@ -657,9 +657,11 @@ class SensorBHI260AP if (__handler.irq != SENSOR_PIN_NONE) { #if defined(ARDUINO_ARCH_RP2040) - attachInterruptParam((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING, (void *)&__data_available); + attachInterrupt((pin_size_t)(__handler.irq), handleISR, (PinStatus )RISING); +#elif defined(NRF52840_XXAA) || defined(NRF52832_XXAA) || defined(ESP32) + attachInterrupt(__handler.irq, handleISR, RISING); #else - attachInterruptArg(__handler.irq, handleISR, (void *)&__data_available, RISING); +#error "No support ." #endif } @@ -670,15 +672,16 @@ class SensorBHI260AP struct bhy2_dev *bhy2 = NULL; SensorLibConfigure __handler; int8_t __error_code; - volatile bool __data_available; + static volatile bool __data_available; uint8_t *processBuffer = NULL; size_t processBufferSize = BHY_PROCESS_BUFFER_SZIE; const uint8_t *__firmware; size_t __firmware_size; bool __write_flash; - uint16_t __max_rw_lenght; + uint16_t __max_rw_length; }; +volatile bool SensorBHI260AP::__data_available; #endif /*defined(ARDUINO)*/