diff --git a/SHAL/Include/Peripheral/ADC/Reg/SHAL_ADC_REG_F072xB.h b/SHAL/Include/Peripheral/ADC/Reg/SHAL_ADC_REG_F072xB.h index 3b1046d..5ff0c50 100644 --- a/SHAL/Include/Peripheral/ADC/Reg/SHAL_ADC_REG_F072xB.h +++ b/SHAL/Include/Peripheral/ADC/Reg/SHAL_ADC_REG_F072xB.h @@ -8,6 +8,7 @@ #include "SHAL_CORE.h" #include "SHAL_ADC_TYPES.h" +#define SHAL_ADC1 SHAL_ADC(1) enum class ADC_Key : uint8_t{ S_ADC1, diff --git a/SHAL/Include/Peripheral/ADC/SHAL_ADC.h b/SHAL/Include/Peripheral/ADC/SHAL_ADC.h index 55cb95f..2f287d5 100644 --- a/SHAL/Include/Peripheral/ADC/SHAL_ADC.h +++ b/SHAL/Include/Peripheral/ADC/SHAL_ADC.h @@ -31,7 +31,7 @@ public: /// \param numChannels Number of channels to convert /// \param result Pointer to store converted channel results in /// \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{ @@ -53,6 +52,9 @@ public: static SHAL_ADC& get(ADC_Key key); + static SHAL_ADC& getByIndex(int index); + + ADCManager() = delete; private: diff --git a/SHAL/Include/SHAL.h b/SHAL/Include/SHAL.h index 2e6d6de..32edae4 100644 --- a/SHAL/Include/SHAL.h +++ b/SHAL/Include/SHAL.h @@ -12,5 +12,6 @@ #include "SHAL_GPIO.h" #include "SHAL_UART.h" #include "SHAL_I2C.h" +#include "SHAL_ADC.h" #endif diff --git a/SHAL/Src/Peripheral/ADC/SHAL_ADC.cpp b/SHAL/Src/Peripheral/ADC/SHAL_ADC.cpp index 7cb499e..aab394b 100644 --- a/SHAL/Src/Peripheral/ADC/SHAL_ADC.cpp +++ b/SHAL/Src/Peripheral/ADC/SHAL_ADC.cpp @@ -81,7 +81,7 @@ uint16_t SHAL_ADC::singleConvertSingle(ADC_Channel channel, ADC_SampleTime time) 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->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; } -} \ No newline at end of file +} + +SHAL_ADC &ADCManager::get(ADC_Key key) { + return m_ADCs[static_cast(key)]; +} + +SHAL_ADC& ADCManager::getByIndex(int index) { + + if(index < static_cast(ADC_Key::NUM_ADC)){ + return m_ADCs[index]; + } + return m_ADCs[0]; +}