SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
current_sense/hardware_specific/stm32/stm32_mcu.cpp
Go to the documentation of this file.
1
2#include "../../hardware_api.h"
3
4#if defined(_STM32_DEF_) and !defined(ARDUINO_B_G431B_ESC1)
5
6#include "stm32_mcu.h"
7
8#define _ADC_VOLTAGE 3.3f
9#define _ADC_RESOLUTION 1024.0f
10
11extern ADC_HandleTypeDef hadc[];
12
13// function reading an ADC value and returning the read voltage
14void* _configureADCInline(const void* driver_params, const int pinA,const int pinB,const int pinC){
15 _UNUSED(driver_params);
16
17 if( _isset(pinA) ) pinMode(pinA, INPUT);
18 if( _isset(pinB) ) pinMode(pinB, INPUT);
19 if( _isset(pinC) ) pinMode(pinC, INPUT);
20
21 Stm32CurrentSenseParams* params = new Stm32CurrentSenseParams {
22 .pins = { pinA, pinB, pinC },
23 .adc_voltage_conv = (_ADC_VOLTAGE)/(_ADC_RESOLUTION)
24 };
25
26 return params;
27}
28
29// function reading an ADC value and returning the read voltage
30__attribute__((weak)) float _readADCVoltageInline(const int pinA, const void* cs_params){
31 uint32_t raw_adc = analogRead(pinA);
32 return raw_adc * ((Stm32CurrentSenseParams*)cs_params)->adc_voltage_conv;
33}
34
35#endif
void * _configureADCInline(const void *driver_params, const int pinA, const int pinB, const int pinC=NOT_SET)
float _readADCVoltageInline(const int pinA, const void *cs_params)
const int const int const int pinC
GenericCurrentSenseParams * params
__attribute__((weak)) float _sin(float a)
Definition foc_utils.cpp:7
#define _UNUSED(v)
Definition foc_utils.h:14
#define _isset(a)
Definition foc_utils.h:13