From 79e7e22d273c2a2409d34d021cbaf56119a50b96 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Thu, 11 Jan 2024 01:18:22 +0100 Subject: [PATCH] [examples] Deduplicate sensor examples --- .github/workflows/linux.yml | 2 +- .github/workflows/macos.yml | 2 +- .../lis3mdl/main.cpp | 29 +++++------------- examples/generic/lis3mdl/project.xml | 30 +++++++++++++++++++ .../sk6812/main.cpp | 8 ++--- examples/generic/sk6812/project.xml | 17 +++++++++++ examples/nucleo_f031k6/sk6812/project.xml | 12 -------- examples/nucleo_f042k6/lis3mdl/project.xml | 11 ------- 8 files changed, 61 insertions(+), 50 deletions(-) rename examples/{nucleo_f042k6 => generic}/lis3mdl/main.cpp (65%) create mode 100644 examples/generic/lis3mdl/project.xml rename examples/{nucleo_f031k6 => generic}/sk6812/main.cpp (88%) create mode 100644 examples/generic/sk6812/project.xml delete mode 100644 examples/nucleo_f031k6/sk6812/project.xml delete mode 100644 examples/nucleo_f042k6/lis3mdl/project.xml diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index ee59ab87a8..ac0f20b76c 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -133,7 +133,7 @@ jobs: - name: Examples STM32F0 Series if: always() run: | - (cd examples && ../tools/scripts/examples_compile.py stm32f0_discovery stm32f072_discovery nucleo_f031k6 nucleo_f072rb nucleo_f042k6 stm32f030f4p6_demo_board) + (cd examples && ../tools/scripts/examples_compile.py stm32f0_discovery stm32f072_discovery nucleo_f072rb nucleo_f042k6 stm32f030f4p6_demo_board) - name: Examples STM32F1 Series if: always() run: | diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index f98b6c0697..7eed70fbc2 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -76,7 +76,7 @@ jobs: if: always() run: | (cd examples && ../tools/scripts/examples_compile.py nucleo_f031k6 nucleo_f103rb nucleo_f303re nucleo_f411re) - (cd examples && ../tools/scripts/examples_compile.py nucleo_g071rb nucleo_l031k6 nucleo_l152re nucleo_l476rg nucleo_g474re) + (cd examples && ../tools/scripts/examples_compile.py nucleo_g071rb nucleo_l152re nucleo_l476rg nucleo_g474re) - name: Compile AVR Examples if: always() diff --git a/examples/nucleo_f042k6/lis3mdl/main.cpp b/examples/generic/lis3mdl/main.cpp similarity index 65% rename from examples/nucleo_f042k6/lis3mdl/main.cpp rename to examples/generic/lis3mdl/main.cpp index 461a11c476..8885aab86b 100644 --- a/examples/nucleo_f042k6/lis3mdl/main.cpp +++ b/examples/generic/lis3mdl/main.cpp @@ -14,48 +14,35 @@ using namespace Board; using namespace std::chrono_literals; -using I2cSda = GpioA10; -using I2cScl = GpioA9; +// Create a sensor object with the address of the sensor built onto the Pololu AltIMU-10 v5 +modm::Lis3mdl sensor(0x1E); int main() { Board::initialize(); - LedD13::setOutput(); + Board::initializeI2c(); MODM_LOG_INFO << "LIS3MDL demo" << modm::endl; - I2cMaster1::connect(); - I2cMaster1::initialize(); - - // Create a sensor object with the adress of the sensor built onto the Pololu AltIMU-10 v5 - modm::Lis3mdl sensor(0x1E); - // Turn on and configure the magnetometer - bool success = RF_CALL_BLOCKING(sensor.configure(modm::lis3mdl::DataRate::Rate_5_Hz, - modm::lis3mdl::Scale::Scale_8_gauss)); - - - if(!success) + if(!RF_CALL_BLOCKING(sensor.configure(modm::lis3mdl::DataRate::Rate_5_Hz, + modm::lis3mdl::Scale::Scale_8_gauss))) { MODM_LOG_INFO << "Sensor could not be configured!" << modm::endl; } // Set the sensor to continous acquistion and turn on the temperature sensing - success = RF_CALL_BLOCKING(sensor.setMode(modm::lis3mdl::OperationMode::Continous)); - if(!success) + if(!RF_CALL_BLOCKING(sensor.setMode(modm::lis3mdl::OperationMode::Continous))) { MODM_LOG_INFO << "Sensor could not be started!" << modm::endl; } modm::Vector3f magVector; - while (true) { - //Read the sensor data and print it out - success = RF_CALL_BLOCKING(sensor.readMagnetometer(magVector)); - - if(success) + // Read the sensor data and print it out + if(RF_CALL_BLOCKING(sensor.readMagnetometer(magVector))) { MODM_LOG_INFO << "Magnetic Vector:" << modm::endl; MODM_LOG_INFO << "X: "<< magVector.x << " gauss" << modm::endl; diff --git a/examples/generic/lis3mdl/project.xml b/examples/generic/lis3mdl/project.xml new file mode 100644 index 0000000000..a05693e68d --- /dev/null +++ b/examples/generic/lis3mdl/project.xml @@ -0,0 +1,30 @@ + + modm:nucleo-f031k6 + + + + + + + + + + + + + + + + + + + + + + + + + modm:build:scons + modm:driver:lis3mdl + + diff --git a/examples/nucleo_f031k6/sk6812/main.cpp b/examples/generic/sk6812/main.cpp similarity index 88% rename from examples/nucleo_f031k6/sk6812/main.cpp rename to examples/generic/sk6812/main.cpp index a1285b7db3..f9b66b18be 100644 --- a/examples/nucleo_f031k6/sk6812/main.cpp +++ b/examples/generic/sk6812/main.cpp @@ -16,15 +16,15 @@ using namespace Board; -using Output = Board::D11; -modm::Sk6812w leds; +using Output = Board::spi::Sdo; +modm::Sk6812w leds; modm::ShortPeriodicTimer tmr{33ms}; int main() { Board::initialize(); - LedD13::setOutput(); + Leds::setOutput(); leds.initialize(); constexpr uint8_t max = 62; @@ -45,7 +45,7 @@ main() leds.write(); while(not tmr.execute()) ; - LedD13::toggle(); + Leds::toggle(); } return 0; diff --git a/examples/generic/sk6812/project.xml b/examples/generic/sk6812/project.xml new file mode 100644 index 0000000000..d78103b460 --- /dev/null +++ b/examples/generic/sk6812/project.xml @@ -0,0 +1,17 @@ + + + modm:nucleo-f031k6 + + + + + + + + + + modm:build:scons + modm:driver:sk6812 + modm:ui:led + + diff --git a/examples/nucleo_f031k6/sk6812/project.xml b/examples/nucleo_f031k6/sk6812/project.xml deleted file mode 100644 index 376998bffb..0000000000 --- a/examples/nucleo_f031k6/sk6812/project.xml +++ /dev/null @@ -1,12 +0,0 @@ - - modm:nucleo-f031k6 - - - - - modm:build:scons - modm:driver:sk6812 - modm:platform:spi:1 - modm:ui:led - - diff --git a/examples/nucleo_f042k6/lis3mdl/project.xml b/examples/nucleo_f042k6/lis3mdl/project.xml deleted file mode 100644 index e03311dcad..0000000000 --- a/examples/nucleo_f042k6/lis3mdl/project.xml +++ /dev/null @@ -1,11 +0,0 @@ - - modm:nucleo-f042k6 - - - - - modm:build:scons - modm:driver:lis3mdl - modm:platform:i2c:1 - -