From c67e6723cd8102af61a9d4cd5b2536c29f2113d0 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 26 Sep 2024 22:51:29 +0200 Subject: [PATCH] Examples: Add main_adc --- examples/main_adc.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++ examples/main_adc.hh | 28 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 examples/main_adc.cc create mode 100644 examples/main_adc.hh diff --git a/examples/main_adc.cc b/examples/main_adc.cc new file mode 100644 index 0000000..0e5df5d --- /dev/null +++ b/examples/main_adc.cc @@ -0,0 +1,46 @@ +#include "main_adc.hh" +#include "utils.hh" +#include + +namespace Heck { + namespace { // anonymous namespace for internal linkage + ld::DaisySeed seed{}; + Observer pot1{}; + SWTimer scan_pots{}; + + void init() + { + seed.Init(Constants::CPU_BOOST480MHZ); + seed.StartLog(Constants::Developer::LOG_BLOCKS_BOOT); + + ld::AdcChannelConfig adc_cfg[3]; + adc_cfg[0].InitSingle(ld::DaisySeed::GetPin(Constants::Hardware::PIN_POT_1)); + + seed.adc.Init(adc_cfg, 1); + seed.adc.Start(); + + scan_pots.set_period(10); + scan_pots.set_callback([]() { + pot1.on_change_fuzzy(seed.adc.Get(0), 10, [](int val) { + seed.PrintLine("POT_1: %d", val); + }); + }); + } + + void mainloop() + { + u32&& time_boot_ms{}; + while (true) { + time_boot_ms = ld::System::GetNow(); + scan_pots.is_it_already_time_again(time_boot_ms); + } + } + } // namespace +} // namespace Heck + + +int main() +{ + Heck::init(); + Heck::mainloop(); +} \ No newline at end of file diff --git a/examples/main_adc.hh b/examples/main_adc.hh new file mode 100644 index 0000000..a84eb4c --- /dev/null +++ b/examples/main_adc.hh @@ -0,0 +1,28 @@ +#ifndef HECK_MAIN_ADC_HH +#define HECK_MAIN_ADC_HH + +#include +#include "types.hh" + +namespace Heck { + namespace Constants { + namespace Hardware { + constexpr int PIN_BUTTON_1 = 28; + constexpr int PIN_POT_1 = 15; + constexpr int PIN_POT_2 = 16; + constexpr int PIN_POT_3 = 15; + } + + constexpr bool CPU_BOOST480MHZ = false; + + namespace Developer { + constexpr bool LOG_BLOCKS_BOOT = false; + } + } // namespace Constants + + //Hardware + extern ld::DaisySeed seed; + // extern ld::Switch but_rec; +} // namespace Heck + +#endif \ No newline at end of file