aboutsummaryrefslogtreecommitdiff
path: root/test_fw/src
diff options
context:
space:
mode:
Diffstat (limited to 'test_fw/src')
-rw-r--r--test_fw/src/bringup.cpp99
-rw-r--r--test_fw/src/main.cpp75
2 files changed, 127 insertions, 47 deletions
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));