Skip to content

Commit

Permalink
add catch
Browse files Browse the repository at this point in the history
  • Loading branch information
wxkim committed Sep 10, 2024
1 parent 52ec9bf commit da53682
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Platform/Interfaces/iadc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ namespace platform
virtual ~IADC() = 0;

//adc operations
virtual uint16_t convert() = 0;
virtual uint16_t convert() const = 0;
virtual void write() = 0;

//buffer mngmt
virtual void read() = 0;
//virtual void read() = 0;

private:

protected:
std::shared_ptr<std::vector<uint16_t>> adc_buf; //container for adc read
std::shared_ptr<size_t> buffer_size; //unsigned
size_t buffer_size; //unsigned



Expand All @@ -44,4 +44,4 @@ namespace platform

#endif

//shared pointers buffer and buffer size inside ADCSTMf4
//shared pointers buffer and buffer size inside ADCSTMf4
21 changes: 14 additions & 7 deletions Platform/STM/F4/ADC/adc_stmf4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "adc_stmf4.hpp" //include header

namespace platform {
AdcStmF4::AdcStmF4(ADC_HandleTypeDef* hadc, DMA_HandleTypeDef* hdma, uint16_t pin)
{
AdcStmF4::AdcStmF4(ADC_HandleTypeDef* hadc, DMA_HandleTypeDef* hdma)
: hdma(hdma), hadc(hadc){
MX_ADC1_Init();
HAL_ADC_Init(hadc);
HAL_DMA_Init(hdma);
Expand All @@ -31,14 +31,21 @@ namespace platform {
{
HAL_ADC_Start(hadc);

uint16_t value = HAL_ADC_GetValue(hadc);
}
if(HAL_ADC_PollForConversion(hadc,HAL_MAX_DELAY) == HAL_OK)
{
return HAL_ADC_GetValue(hadc);
}


else {//use during debug

printf("HAL ADC error code: "+HAL_ADC_GetError(hadc));
}

void AdcStmF4::write()
{
}

void AdcStmF4::write() //redundant?
{
uint16_t value = convert();
}
}

Expand Down
5 changes: 2 additions & 3 deletions Platform/STM/F4/ADC/adc_stmf4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
namespace platform {
class AdcStmF4 : public IADC {
public:
AdcStmF4(ADC_HandleTypeDef*, DMA_HandleTypeDef*, uint16_t);
AdcStmF4(ADC_HandleTypeDef*, DMA_HandleTypeDef*);

virtual ~AdcStmF4();

uint16_t convert();

void write();



private:

ADC_HandleTypeDef* hadc;
DMA_HandleTypeDef* hdma;
//uint16_t pin_;
Expand Down

0 comments on commit da53682

Please sign in to comment.