Fix Pin is not configured as analog channel error
#458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Forum conversation on the issue here: https://community.simplefoc.com/t/pin-is-not-configured-as-analog-channel/6751/5
Current sense align is currently not working on ESP32 boards due to a
__analogChannelConfig(): Pin is not configured as analog channelerror duringcurrent_sense.init().The error is coming from this function in the
arduino-esp32framework. It is checking to see if the pin type isESP32_BUS_TYPE_ADC_ONESHOT.In
arduino-esp32, it appears that theESP32_BUS_TYPE_ADC_ONESHOTsetting is only applied to a pin in the__analogInitfunction, which in turn is only ever invoked during ananalogRead(oranalogReadMilliVolts, which SimpleFOC doesn’t use).This is mainly a bug in
arduino-esp32(sinceanalogSetPinAttenuationshould be able to work before ananalogReadis called). But we can (and should) work around this in the SimpleFOC library since it may be a long time until a fix is released upstream. We can ensure the pin is initialised correctly by reversing the order of theanalogSetPinAttenuationand theanalogReadcalls in the hardware specific driver for ESP32.