diff options
| -rw-r--r-- | test_fw/include/board.h | 20 | ||||
| -rw-r--r-- | test_fw/include/bringup.h | 18 | ||||
| -rw-r--r-- | test_fw/include/veml.h | 8 | ||||
| -rw-r--r-- | test_fw/platformio.ini | 24 | ||||
| -rw-r--r-- | test_fw/src/bringup.cpp | 99 | ||||
| -rw-r--r-- | test_fw/src/main.cpp | 75 |
6 files changed, 192 insertions, 52 deletions
diff --git a/test_fw/include/board.h b/test_fw/include/board.h new file mode 100644 index 0000000..3f4be82 --- /dev/null +++ b/test_fw/include/board.h @@ -0,0 +1,20 @@ +#pragma once + +#include <SPI.h> + +constexpr auto SDA_PIN = 6, SCL_PIN = 23; + +constexpr auto SD_CS = 17, SD_SCK = 18, SD_MOSI = 19, SD_MISO = 20; +constexpr auto CARD_DETECT = 12; + +constexpr auto LSM_CS = 13, LSM_SCK = 10, LSM_MOSI = 11, LSM_MISO = 8; +constexpr auto LSM_INT1 = 4, LSM_INT2 = 5; + +constexpr auto LED_FAULT = 0, LED_CAPTURING = 1, LED_OTHER = 2, LED_STORAGE = 3; +constexpr auto I2S_DATA = 22, I2S_BCLK = 24, I2S_WS = 25; + +constexpr auto BME_ADDR = 0x76; + +#define SD_SPI SPI +#define LSM_SPI SPI1 + diff --git a/test_fw/include/bringup.h b/test_fw/include/bringup.h new file mode 100644 index 0000000..762a26a --- /dev/null +++ b/test_fw/include/bringup.h @@ -0,0 +1,18 @@ +#pragma once + +#include <Arduino.h> +#include <etl/span.h> + +namespace ocularium::bringup { + struct init_check + { + const String name; + bool (*f)(); + bool succeeded; + }; + + void startup_checks(const etl::span<init_check> &checks); + void init_buses(); + void init_pins(); + void boot_animation(); +} diff --git a/test_fw/include/veml.h b/test_fw/include/veml.h index 89282c8..51345a9 100644 --- a/test_fw/include/veml.h +++ b/test_fw/include/veml.h @@ -50,9 +50,9 @@ namespace ocularium AmbientLightGain gain = AmbientLightGain::Eighth; IntegrationTime integration = IntegrationTime::Ms100; - uint16_t to_reg() const; + [[nodiscard]] uint16_t to_reg() const; - int32_t gain_factor() const + [[nodiscard]] int32_t gain_factor() const { int32_t gain = 0; @@ -122,8 +122,8 @@ namespace ocularium bool init(const Config& config = Config{}); - uint16_t chipid() const; - float lux() const; + [[nodiscard]] uint16_t chipid() const; + [[nodiscard]] float lux() const; void set_config(const Config& config); diff --git a/test_fw/platformio.ini b/test_fw/platformio.ini index 661a561..d041309 100644 --- a/test_fw/platformio.ini +++ b/test_fw/platformio.ini @@ -1,9 +1,31 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + [env:pico] -platform = raspberrypi +platform = https://github.com/maxgerhardt/platform-raspberrypi.git +;platform = raspberrypi board = pico +board_build.core = earlephilhower +board_build.filesystem_size = 0m +board_build.arduino.earlephilhower.usb_manufacturer = Nathan Perry +board_build.arduino.earlephilhower.usb_product = ocularium (v0.2.0) +board_build.arduino.earlephilhower.usb_vid = 0x8888 +board_build.arduino.earlephilhower.usb_pid = 0x2008 + framework = arduino lib_deps = adafruit/Adafruit BME680 Library@^2.0.5 etlcpp/Embedded Template Library@^20.39.4 + arduino-libraries/SD@^1.3.0 build_flags = -std=c++2a + -DPIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS + -DDEBUG_RP2040_WIRE -DDEBUG_RP2040_SPI -DDEBUG_RP2040_CORE -DDEBUG_RP2040_PORT=Serial + -fstack-protector diff --git a/test_fw/src/bringup.cpp b/test_fw/src/bringup.cpp new file mode 100644 index 0000000..44a07c0 --- /dev/null +++ b/test_fw/src/bringup.cpp @@ -0,0 +1,99 @@ +#include "bringup.h" +#include "board.h" + +#include <Wire.h> + +using namespace ocularium; + +void bringup::startup_checks(const etl::span<bringup::init_check> &checks) +{ + auto success = true; + + do + { + success = true; + + for (auto &[name, f, succeeded] : checks) + { + if (succeeded) + continue; + + Serial.print("checking " + name + "... "); + + succeeded = f(); + success = success && succeeded; + + if (succeeded) Serial.println("ok"); + else Serial.println("bad"); + } + + if (!success) delay(10); + } while (!success); +} + +void bringup::init_buses() +{ + Wire1.setSCL(SCL_PIN); + Wire1.setSDA(SDA_PIN); + Wire1.setClock(100000); + Wire1.begin(); + + SD_SPI.setCS(SD_CS); + SD_SPI.setMOSI(SD_MOSI); + SD_SPI.setMISO(SD_MISO); + SD_SPI.setSCK(SD_SCK); + SD_SPI.begin(); + + LSM_SPI.setCS(LSM_CS); + LSM_SPI.setMOSI(LSM_MOSI); + LSM_SPI.setMISO(LSM_MISO); + LSM_SPI.setSCK(LSM_SCK); + LSM_SPI.begin(); +} + +void bringup::init_pins() +{ + pinMode(CARD_DETECT, INPUT); + pinMode(LED_FAULT, OUTPUT); + pinMode(LED_CAPTURING, OUTPUT); + pinMode(LED_OTHER, OUTPUT); + pinMode(LED_STORAGE, OUTPUT); + pinMode(LSM_INT1, INPUT); + pinMode(LSM_INT2, INPUT); +} + +void bringup::boot_animation() +{ + constexpr pin_size_t chase[] = { + LED_STORAGE, + LED_OTHER, + LED_FAULT, + LED_CAPTURING, + }; + + for (auto i = 0; i < 5; i++) + { + for (const auto pin: chase) + { + digitalWrite(pin, HIGH); + delay(75); + digitalWrite(pin, LOW); + } + } + + delay(100); + + for (auto i = 0; i < 2; i++) + { + for (const auto pin : chase) + { + digitalWrite(pin, HIGH); + } + delay(100); + for (const auto pin : chase) + { + digitalWrite(pin, LOW); + } + delay(100); + } +} diff --git a/test_fw/src/main.cpp b/test_fw/src/main.cpp index c6d3834..5f8e1d4 100644 --- a/test_fw/src/main.cpp +++ b/test_fw/src/main.cpp @@ -1,5 +1,7 @@ #include <Arduino.h> #include <Wire.h> +#include <SPI.h> +#include <SD.h> #include <Adafruit_BME680.h> @@ -7,25 +9,21 @@ #include "i2c_scan.h" #include "veml.h" +#include "board.h" +#include "bringup.h" -constexpr auto SDA = 6; -constexpr auto SCL = 23; +using namespace ocularium; -constexpr auto BME_ADDR = 0x76; -static TwoWire wire(SDA, SCL); +static Adafruit_BME680 bme(&Wire1); +static VEML lux(Wire1); -static Adafruit_BME680 bme(&wire); -static ocularium::VEML veml(wire); +#define SCAN_I2C 0 -struct init_check -{ - const String name; - bool (*f)(); - bool succeeded; -}; +#define SDCARD_SPI SD_SPI +static SDClass sd; -static init_check STARTUP_CHECKS[] = { +static bringup::init_check STARTUP_CHECKS[] = { { .name = String("bme680"), .f = [] { return bme.begin(BME_ADDR); }, @@ -33,50 +31,33 @@ static init_check STARTUP_CHECKS[] = { }, { .name = String("veml7700"), - .f = []{ return veml.init(ocularium::veml::Config { - .gain = ocularium::veml::AmbientLightGain::Quarter, + .f = []{ return lux.init(veml::Config { + .gain = veml::AmbientLightGain::Quarter, }); }, .succeeded = false, } }; -void startup_checks() -{ - auto success = true; - - do - { - success = true; - - for (auto & check : STARTUP_CHECKS) - { - if (check.succeeded) - continue; - - Serial.print("checking " + check.name + "... "); - - check.succeeded = check.f(); - success = success && check.succeeded; - - if (check.succeeded) Serial.println("ok"); - else Serial.println("bad"); - } - - if (!success) delay(10); - } while (!success); -} - void setup() { Serial.begin(115200); - delay(2000); - Serial.println("boot"); - wire.begin(); - ocularium::scan(wire); - startup_checks(); + bringup::init_buses(); + bringup::init_pins(); + +#if SCAN_I2C + Serial.println("scanning..."); + scan(Wire1); +#endif + + bringup::startup_checks(STARTUP_CHECKS); Serial.println("sensors initialized"); + + bringup::boot_animation(); + delay(100); + + digitalWrite(LED_CAPTURING, HIGH); } void loop() { @@ -92,7 +73,7 @@ void loop() { bme_target_millis = bme.beginReading(); } - Serial.print("lux: " + String(veml.lux())); + Serial.print("lux: " + String(lux.lux())); Serial.print(", temp: " + String(bme.temperature)); Serial.print(", hum: " + String(bme.humidity)); Serial.print(", pres: " + String(bme.pressure)); |
