diff --git a/Peripherals/Inc/peripherals_encoder.hpp b/Peripherals/Inc/peripherals_encoder.hpp index da68e75..b0b7efc 100644 --- a/Peripherals/Inc/peripherals_encoder.hpp +++ b/Peripherals/Inc/peripherals_encoder.hpp @@ -36,6 +36,7 @@ public: void start() { + HAL_TIM_Base_Start_IT(_htim); HAL_TIM_Encoder_Start_IT(_htim, _channels); } @@ -53,6 +54,7 @@ public: void setRevolutionTickCount(const std::uint16_t& count) { __HAL_TIM_SET_COMPARE(_htim, _channels, count); + __HAL_TIM_SET_AUTORELOAD(_htim, count); } std::uint16_t getCurrentClicks() const diff --git a/Peripherals/Inc/peripherals_hal_st.hpp b/Peripherals/Inc/peripherals_hal_st.hpp index 4599e6f..5dc07e8 100644 --- a/Peripherals/Inc/peripherals_hal_st.hpp +++ b/Peripherals/Inc/peripherals_hal_st.hpp @@ -12,6 +12,8 @@ #include "peripherals_utility.hpp" +#include + #define USE_DELAY_US namespace Peripherals @@ -111,10 +113,26 @@ struct SerialInterface return transmit(handle, data, data_len, 100) == HAL_StatusTypeDef::HAL_OK; } + template + bool Transmit(std::array& array) + { + static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large."); + + return Transmit(reinterpret_cast(array.data()), std::uint32_t(N)); + } + bool Receive(std::uint8_t* data, const std::uint32_t data_len) { return receive(handle, data, data_len, 100) == HAL_StatusTypeDef::HAL_OK; } + + template + bool Receive(std::array& array) + { + static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large."); + + return Receive(reinterpret_cast(array.data()), std::uint32_t(N)); + } }; template + bool Transmit(std::array& array) + { + static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large."); + + return Transmit(reinterpret_cast(array.data()), std::uint32_t(N)); + } + bool Receive(std::uint8_t* data, const std::uint32_t data_len) { return receive(handle, data, data_len) == HAL_StatusTypeDef::HAL_OK; } + + template + bool Receive(std::array& array) + { + static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large."); + + return Receive(reinterpret_cast(array.data()), std::uint32_t(N)); + } }; #ifdef HAL_SPI_MODULE_ENABLED @@ -153,8 +187,11 @@ struct SpiRegisters Gpio chip_select; SpiRegisters() = delete; - explicit SpiRegisters(const SpiInterface& handle, const Gpio& chip_select) - : handle(handle), chip_select(chip_select) {} + explicit SpiRegisters(const SpiInterface& handle, const Gpio& cs) + : handle(handle), chip_select(cs) + { + chip_select.Set(true); + } void WriteRegister(std::uint8_t reg, uint8_t data) { @@ -260,6 +297,14 @@ struct ItmSerialInterface } return true; } + + template + bool Transmit(std::array& array) + { + static_assert(sizeof(T) == sizeof(std::uint8_t), "Data is not a byte large."); + + return Transmit(reinterpret_cast(array.data()), std::uint32_t(N)); + } }; }// namespace St