diff --git a/examples/nucleo_f429zi/adc_ads816x/main.cpp b/examples/nucleo_f429zi/adc_ads816x/main.cpp index a338477689..0d231e3d40 100644 --- a/examples/nucleo_f429zi/adc_ads816x/main.cpp +++ b/examples/nucleo_f429zi/adc_ads816x/main.cpp @@ -36,6 +36,7 @@ main() SpiMaster::initialize(); SpiMaster::connect(); + adc.configureBus(); Rst::setOutput(); Cs::setOutput(true); diff --git a/src/modm/architecture/interface/spi.hpp b/src/modm/architecture/interface/spi.hpp index 80e2dc85fe..17978cb2d3 100644 --- a/src/modm/architecture/interface/spi.hpp +++ b/src/modm/architecture/interface/spi.hpp @@ -15,6 +15,7 @@ #ifndef MODM_INTERFACE_SPI_HPP #define MODM_INTERFACE_SPI_HPP +#include #include namespace modm @@ -45,6 +46,15 @@ struct Spi }; }; +template +struct SpiConfiguration +{ + SpiMaster::DataMode dataMode{}; + SpiMaster::DataOrder dataOrder{}; + + constexpr auto operator<=>(const SpiConfiguration&) const = default; +}; + } // namespace modm #endif // MODM_INTERFACE_SPI_HPP diff --git a/src/modm/architecture/interface/spi_device.hpp b/src/modm/architecture/interface/spi_device.hpp index 89ac49b7b4..a5fd910125 100644 --- a/src/modm/architecture/interface/spi_device.hpp +++ b/src/modm/architecture/interface/spi_device.hpp @@ -27,7 +27,7 @@ namespace modm * @author Niklas Hauser * @ingroup modm_architecture_spi_device */ -template < class SpiMaster > +template < class SpiMaster, SpiConfiguration config > class SpiDevice { Spi::ConfigurationHandler configuration; @@ -44,6 +44,12 @@ class SpiDevice configuration = handler; } + void inline + configureBus() + { + SpiMaster::setDataMode(config.dataMode); + SpiMaster::setDataOrder(config.dataOrder); + } protected: bool inline acquireMaster() diff --git a/src/modm/driver/adc/ads816x.hpp b/src/modm/driver/adc/ads816x.hpp index faaf64ce94..a9ccc74992 100644 --- a/src/modm/driver/adc/ads816x.hpp +++ b/src/modm/driver/adc/ads816x.hpp @@ -87,6 +87,9 @@ struct ads816x }; }; +template +constexpr auto Ads816xSpiConfig = SpiConfiguration{SpiMaster::DataMode::Mode0, SpiMaster::DataOrder::MsbFirst}; + /** * @tparam SpiMaster SpiMaster interface * @tparam Cs Chip-select pin @@ -95,7 +98,9 @@ struct ads816x * @ingroup modm_driver_ads816x */ template -class Ads816x : public ads816x, public modm::SpiDevice, protected modm::NestedResumable<3> +class Ads816x : public ads816x, + public modm::SpiDevice>, + protected modm::NestedResumable<3> { public: Ads816x() = default;