SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
esp32_mcu.cpp
Go to the documentation of this file.
1#include "esp32_mcu.h"
2
3#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32)
4
5/**
6 * Inline adc reading implementation
7*/
8// function reading an ADC value and returning the read voltage
9float IRAM_ATTR _readADCVoltageInline(const int pinA, const void* cs_params){
10 uint32_t raw_adc = adcRead(pinA);
11 return raw_adc * ((ESP32CurrentSenseParams*)cs_params)->adc_voltage_conv;
12}
13
14// function reading an ADC value and returning the read voltage
15void* IRAM_ATTR _configureADCInline(const void* driver_params, const int pinA, const int pinB, const int pinC){
16
17 ESP32CurrentSenseParams* params = new ESP32CurrentSenseParams {
18 .pins = { pinA, pinB, pinC },
19 .adc_voltage_conv = (_ADC_VOLTAGE)/(_ADC_RESOLUTION)
20 };
21
22 // initialize the ADC pins
23 // fail if the pin is not an ADC pin
24 for (int i = 0; i < 3; i++){
25 if(_isset(params->pins[i])){
26 pinMode(params->pins[i], ANALOG);
27 if(!adcInit(params->pins[i])) {
28 SIMPLEFOC_ESP32_CS_DEBUG("ERROR: Failed to initialise ADC pin: "+String(params->pins[i]) + String(", maybe not an ADC pin?"));
30 }
31 }
32 }
33
34 return params;
35}
36
37
38#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)
#define SIMPLEFOC_CURRENT_SENSE_INIT_FAILED
const int const int const int pinC
GenericCurrentSenseParams * params
#define _isset(a)
Definition foc_utils.h:13