Peripherals: encoder base timer start fix &
All checks were successful
continuous-integration/drone/push Build is passing

adding Transmit functions that accept arrays.
This commit is contained in:
Erki 2021-04-15 17:45:32 +03:00
parent a4c4e0f826
commit df35b93d22
2 changed files with 49 additions and 2 deletions

View File

@ -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

View File

@ -12,6 +12,8 @@
#include "peripherals_utility.hpp"
#include <array>
#define USE_DELAY_US
namespace Peripherals
@ -111,10 +113,26 @@ struct SerialInterface
return transmit(handle, data, data_len, 100) == HAL_StatusTypeDef::HAL_OK;
}
template<typename Td, std::size_t N>
bool Transmit(std::array<Td, N>& array)
{
static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large.");
return Transmit(reinterpret_cast<std::uint8_t*>(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<typename Td, std::size_t N>
bool Receive(std::array<Td, N>& array)
{
static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large.");
return Receive(reinterpret_cast<std::uint8_t*>(array.data()), std::uint32_t(N));
}
};
template<typename T,
@ -136,10 +154,26 @@ struct SerialInterfaceAsync
return transmit(handle, data, data_len) == HAL_StatusTypeDef::HAL_OK;
}
template<typename Td, std::size_t N>
bool Transmit(std::array<Td, N>& array)
{
static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large.");
return Transmit(reinterpret_cast<std::uint8_t*>(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<typename Td, std::size_t N>
bool Receive(std::array<Td, N>& array)
{
static_assert(sizeof(Td) == sizeof(std::uint8_t), "Data is not a byte large.");
return Receive(reinterpret_cast<std::uint8_t*>(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<typename T, std::size_t N>
bool Transmit(std::array<T, N>& array)
{
static_assert(sizeof(T) == sizeof(std::uint8_t), "Data is not a byte large.");
return Transmit(reinterpret_cast<std::uint8_t*>(array.data()), std::uint32_t(N));
}
};
}// namespace St