ADC basic functionality finished
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "SHAL_CORE.h"
|
#include "SHAL_CORE.h"
|
||||||
#include "SHAL_ADC_TYPES.h"
|
#include "SHAL_ADC_TYPES.h"
|
||||||
|
|
||||||
|
#define SHAL_ADC1 SHAL_ADC(1)
|
||||||
|
|
||||||
enum class ADC_Key : uint8_t{
|
enum class ADC_Key : uint8_t{
|
||||||
S_ADC1,
|
S_ADC1,
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public:
|
|||||||
/// \param numChannels Number of channels to convert
|
/// \param numChannels Number of channels to convert
|
||||||
/// \param result Pointer to store converted channel results in
|
/// \param result Pointer to store converted channel results in
|
||||||
/// \param time ADC_SampleTime - amount of clock cycles per conversion
|
/// \param time ADC_SampleTime - amount of clock cycles per conversion
|
||||||
void singleConvertSingle(ADC_Channel* channels, const int numChannels, uint16_t* result, ADC_SampleTime time = ADC_SampleTime::C239);
|
void multiConvertSingle(ADC_Channel* channels, const int numChannels, uint16_t* result, ADC_SampleTime time = ADC_SampleTime::C239);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -44,8 +44,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#define SHAL_ADC(x) ADCManager::getByIndex(x-1)
|
||||||
|
|
||||||
|
|
||||||
class ADCManager{
|
class ADCManager{
|
||||||
|
|
||||||
@@ -53,6 +52,9 @@ public:
|
|||||||
|
|
||||||
static SHAL_ADC& get(ADC_Key key);
|
static SHAL_ADC& get(ADC_Key key);
|
||||||
|
|
||||||
|
static SHAL_ADC& getByIndex(int index);
|
||||||
|
|
||||||
|
|
||||||
ADCManager() = delete;
|
ADCManager() = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -12,5 +12,6 @@
|
|||||||
#include "SHAL_GPIO.h"
|
#include "SHAL_GPIO.h"
|
||||||
#include "SHAL_UART.h"
|
#include "SHAL_UART.h"
|
||||||
#include "SHAL_I2C.h"
|
#include "SHAL_I2C.h"
|
||||||
|
#include "SHAL_ADC.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ uint16_t SHAL_ADC::singleConvertSingle(ADC_Channel channel, ADC_SampleTime time)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHAL_ADC::singleConvertSingle(ADC_Channel* channels, const int numChannels, uint16_t* result, ADC_SampleTime time) {
|
void SHAL_ADC::multiConvertSingle(ADC_Channel* channels, const int numChannels, uint16_t* result, ADC_SampleTime time) {
|
||||||
ADC_TypeDef* ADC_reg = getADCRegister(m_ADCKey);
|
ADC_TypeDef* ADC_reg = getADCRegister(m_ADCKey);
|
||||||
|
|
||||||
ADC->CCR |= ADC_CCR_VREFEN | ADC_CCR_TSEN; //Enable VREFINT and Temp sensor in global ADC struct
|
ADC->CCR |= ADC_CCR_VREFEN | ADC_CCR_TSEN; //Enable VREFINT and Temp sensor in global ADC struct
|
||||||
@@ -100,4 +100,16 @@ void SHAL_ADC::singleConvertSingle(ADC_Channel* channels, const int numChannels,
|
|||||||
|
|
||||||
result[i] = ADC_reg->DR;
|
result[i] = ADC_reg->DR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHAL_ADC &ADCManager::get(ADC_Key key) {
|
||||||
|
return m_ADCs[static_cast<uint8_t>(key)];
|
||||||
|
}
|
||||||
|
|
||||||
|
SHAL_ADC& ADCManager::getByIndex(int index) {
|
||||||
|
|
||||||
|
if(index < static_cast<int>(ADC_Key::NUM_ADC)){
|
||||||
|
return m_ADCs[index];
|
||||||
|
}
|
||||||
|
return m_ADCs[0];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user