ADC basic functionality finished

This commit is contained in:
Ea-r-th
2025-09-22 19:47:15 -07:00
parent f980e62407
commit 8214617e3a
4 changed files with 21 additions and 5 deletions

View File

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

View File

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

View File

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

View File

@@ -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];
}