From 381463903a6697fea9e741cd15200b1e6573527e Mon Sep 17 00:00:00 2001 From: MichaelYKersey <144640226+MichaelYKersey@users.noreply.github.com> Date: Sat, 11 Jan 2025 12:23:19 -0800 Subject: [PATCH] Revert "remove demos for pr" This reverts commit 7b01ef57b3734838e097412c70977a966013b2f7. --- demos/CMakeLists.txt | 3 ++ demos/applications/tla2528_adc.cpp | 36 ++++++++++++++++ demos/applications/tla2528_input_pin.cpp | 37 +++++++++++++++++ demos/applications/tla2528_output_pin.cpp | 50 +++++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100644 demos/applications/tla2528_adc.cpp create mode 100644 demos/applications/tla2528_input_pin.cpp create mode 100644 demos/applications/tla2528_output_pin.cpp diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index eff48ed..c355c49 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -19,6 +19,9 @@ project(demos LANGUAGES CXX) libhal_build_demos( DEMOS pca9685 + tla2528_adc + tla2528_input_pin + tla2528_output_pin INCLUDES . diff --git a/demos/applications/tla2528_adc.cpp b/demos/applications/tla2528_adc.cpp new file mode 100644 index 0000000..505e544 --- /dev/null +++ b/demos/applications/tla2528_adc.cpp @@ -0,0 +1,36 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace hal::literals; +using namespace std::chrono_literals; + +void application(resource_list& p_map) +{ + auto& terminal = *p_map.console.value(); + auto& i2c = *p_map.i2c.value(); + auto& steady_clock = *p_map.clock.value(); + auto adc_mux = hal::expander::tla2528(i2c); + std::array adcs{ + make_adc(adc_mux, 0), make_adc(adc_mux, 1), make_adc(adc_mux, 2), + make_adc(adc_mux, 3), make_adc(adc_mux, 4), make_adc(adc_mux, 5), + make_adc(adc_mux, 6), make_adc(adc_mux, 7) + }; + + while (true) { + hal::print(terminal, "\nvalues:\n"); + for (int i = 0; i < 8; i++) { + hal::print<64>(terminal, "%d:%f\n", i, adcs[i].read()); + } + hal::delay(steady_clock, 500ms); + } +} diff --git a/demos/applications/tla2528_input_pin.cpp b/demos/applications/tla2528_input_pin.cpp new file mode 100644 index 0000000..17c8ad2 --- /dev/null +++ b/demos/applications/tla2528_input_pin.cpp @@ -0,0 +1,37 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace hal::literals; +using namespace std::chrono_literals; + +void application(resource_list& p_map) +{ + auto& terminal = *p_map.console.value(); + auto& i2c = *p_map.i2c.value(); + auto& steady_clock = *p_map.clock.value(); + auto gpi_expander = hal::expander::tla2528(i2c); + std::array gpis{ + make_input_pin(gpi_expander, 0), make_input_pin(gpi_expander, 1), + make_input_pin(gpi_expander, 2), make_input_pin(gpi_expander, 3), + make_input_pin(gpi_expander, 4), make_input_pin(gpi_expander, 5), + make_input_pin(gpi_expander, 6), make_input_pin(gpi_expander, 7) + }; + + while (true) { + hal::print(terminal, "\nvalues:"); + for (int i = 0; i < 8; i++) { + hal::print<4>(terminal, "%x", gpis[i].level()); + } + hal::delay(steady_clock, 500ms); + } +} diff --git a/demos/applications/tla2528_output_pin.cpp b/demos/applications/tla2528_output_pin.cpp new file mode 100644 index 0000000..7ac0415 --- /dev/null +++ b/demos/applications/tla2528_output_pin.cpp @@ -0,0 +1,50 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace hal::literals; +using namespace std::chrono_literals; + +void application(resource_list& p_map) +{ + constexpr bool demo_open_drain = false; + + auto& terminal = *p_map.console.value(); + auto& i2c = *p_map.i2c.value(); + auto& steady_clock = *p_map.clock.value(); + auto gpo_expander = hal::expander::tla2528(i2c); + constexpr hal::output_pin::settings output_pin_config = { + .resistor = hal::pin_resistor::none, .open_drain = demo_open_drain + }; + std::array gpos{ + make_output_pin(gpo_expander, 0, output_pin_config), + make_output_pin(gpo_expander, 1, output_pin_config), + make_output_pin(gpo_expander, 2, output_pin_config), + make_output_pin(gpo_expander, 3, output_pin_config), + make_output_pin(gpo_expander, 4, output_pin_config), + make_output_pin(gpo_expander, 5, output_pin_config), + make_output_pin(gpo_expander, 6, output_pin_config), + make_output_pin(gpo_expander, 7, output_pin_config) + }; + + // output counts in binary to go though all out put combinations + hal::byte counter = 0; + hal::print(terminal, "Starting Binary Count\n"); + while (true) { + counter++; + for (int i = 0; i < 8; i++) { + gpos[i].level(hal::bit_extract(hal::bit_mask::from(i), counter)); + } + hal::print<16>(terminal, "count:%x\n", counter); + hal::delay(steady_clock, 200ms); + } +}