-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more refactoring of the current sensing
- Loading branch information
Showing
6 changed files
with
98 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/current_sense/hardware_specific/esp32/esp32_ledc_mcu.cpp
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "../../hardware_api.h" | ||
#include "../../../drivers/hardware_api.h" | ||
|
||
#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32) | ||
|
||
#include "esp32_adc_driver.h" | ||
#include "esp32_mcu.h" | ||
|
||
|
||
/** | ||
* Inline adc reading implementation | ||
*/ | ||
// function reading an ADC value and returning the read voltage | ||
float _readADCVoltageInline(const int pinA, const void* cs_params){ | ||
uint32_t raw_adc = adcRead(pinA); | ||
return raw_adc * ((ESP32CurrentSenseParams*)cs_params)->adc_voltage_conv; | ||
} | ||
|
||
// function reading an ADC value and returning the read voltage | ||
void* _configureADCInline(const void* driver_params, const int pinA, const int pinB, const int pinC){ | ||
|
||
ESP32CurrentSenseParams* params = new ESP32CurrentSenseParams { | ||
.pins = { pinA, pinB, pinC }, | ||
.adc_voltage_conv = (_ADC_VOLTAGE)/(_ADC_RESOLUTION) | ||
}; | ||
|
||
// initialize the ADC pins | ||
// fail if the pin is not an ADC pin | ||
for (int i = 0; i < 3; i++){ | ||
if(_isset(params->pins[i])){ | ||
pinMode(params->pins[i], ANALOG); | ||
if(!adcInit(params->pins[i])) { | ||
SIMPLEFOC_ESP32_CS_DEBUG("ERROR: Failed to initialise ADC pin: "+String(params->pins[i]) + String(", maybe not an ADC pin?")); | ||
return SIMPLEFOC_CURRENT_SENSE_INIT_FAILED; | ||
} | ||
} | ||
} | ||
|
||
return params; | ||
} | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef ESP32_MCU_CURRENT_SENSING_H | ||
#define ESP32_MCU_CURRENT_SENSING_H | ||
|
||
|
||
#if defined(ESP_H) && defined(ARDUINO_ARCH_ESP32) | ||
|
||
#include "../../hardware_api.h" | ||
#include "../../../drivers/hardware_api.h" | ||
|
||
#include "esp32_adc_driver.h" | ||
|
||
|
||
// esp32 current sense parameters | ||
typedef struct ESP32CurrentSenseParams { | ||
int pins[3]; | ||
float adc_voltage_conv; | ||
int adc_buffer[3] = {}; | ||
int buffer_index = 0; | ||
int no_adc_channels = 0; | ||
} ESP32CurrentSenseParams; | ||
|
||
// macros for debugging wuing the simplefoc debug system | ||
#define SIMPLEFOC_ESP32_CS_DEBUG(str)\ | ||
SimpleFOCDebug::println( "ESP32-CS"+String(tag)+ ": "+ String(str));\ | ||
|
||
#define CHECK_CS_ERR(func_call, message) \ | ||
if ((func_call) != ESP_OK) { \ | ||
SIMPLEFOC_ESP32_CS_DEBUG("ERROR - " + String(message)); \ | ||
return SIMPLEFOC_CURRENT_SENSE_INIT_FAILED; \ | ||
} | ||
|
||
|
||
#define _ADC_VOLTAGE 3.3f | ||
#define _ADC_RESOLUTION 4095.0f | ||
|
||
#endif // ESP_H && ARDUINO_ARCH_ESP32 | ||
#endif |