mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Added ADC implementation for STM32
This commit is contained in:
parent
0d02d57cbb
commit
266cc46a09
@ -11,10 +11,26 @@ namespace sta
|
||||
class STM32ADC
|
||||
{
|
||||
public:
|
||||
STM32ADC();
|
||||
/**
|
||||
* @param handle A handle to a STM32 ADC.
|
||||
*/
|
||||
STM32ADC(ADC_HandleTypeDef * handle);
|
||||
|
||||
/**
|
||||
* @brief Starts conversion of the incoming analog signal.
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param timeout
|
||||
*/
|
||||
void poll(uint32_t timeout);
|
||||
|
||||
uint32_t getValue();
|
||||
private:
|
||||
|
||||
ADC_HandleTypeDef * handle_;
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
33
src/devices/stm32/adc.cpp
Normal file
33
src/devices/stm32/adc.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <sta/devices/stm32/adc.hpp>
|
||||
|
||||
#ifdef STA_PLATFORM_STM32
|
||||
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
STM32ADC::STM32ADC(ADC_HandleTypeDef * handle)
|
||||
: handle_{handle}
|
||||
{
|
||||
STA_ASSERT(handle != nullptr);
|
||||
}
|
||||
|
||||
void STM32ADC::start()
|
||||
{
|
||||
HAL_ADC_Start(handle_);
|
||||
}
|
||||
|
||||
void STM32ADC::poll(uint32_t timeout)
|
||||
{
|
||||
HAL_StatusTypeDef res = HAL_ADC_PollForConversion(handle_, timeout);
|
||||
|
||||
STA_ASSERT(res == HAL_OK);
|
||||
}
|
||||
|
||||
uint32_t STM32ADC::getValue()
|
||||
{
|
||||
return HAL_ADC_GetValue(handle_);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_STM32
|
Loading…
x
Reference in New Issue
Block a user