Merge pull request #3514 from hierophect/esp32-analogout

ESP32-S2: AnalogOut
This commit is contained in:
Scott Shawcroft 2020-10-12 15:08:50 -07:00 committed by GitHub
commit 638c7f7b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

View File

@ -35,25 +35,39 @@
#include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate.h"
#include "components/driver/include/driver/dac_common.h"
#include "common-hal/microcontroller/Pin.h"
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
const mcu_pin_obj_t *pin) {
mp_raise_NotImplementedError(translate("No DAC on chip"));
if (pin == &pin_GPIO17) {
self->channel = DAC_CHANNEL_1;
} else if (pin == &pin_GPIO18) {
self->channel = DAC_CHANNEL_2;
} else {
mp_raise_ValueError(translate("Invalid DAC pin supplied"));
}
dac_output_enable(self->channel);
}
bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
return true;
return (self->channel == DAC_CHANNEL_MAX);
}
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
dac_output_disable(self->channel);
self->channel = DAC_CHANNEL_MAX;
}
void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
uint16_t value) {
uint8_t dac_value = (value * 255) / 65535;
dac_output_enable(self->channel);
dac_output_voltage(self->channel, dac_value);
}
void analogout_reset(void) {
dac_output_disable(DAC_CHANNEL_1);
dac_output_disable(DAC_CHANNEL_2);
}

View File

@ -36,7 +36,6 @@ typedef struct {
mp_obj_base_t base;
const mcu_pin_obj_t * pin;
uint8_t channel;
uint8_t dac_index:1;
} analogio_analogout_obj_t;
void analogout_reset(void);

View File

@ -35,6 +35,7 @@
#include "freertos/task.h"
#include "common-hal/microcontroller/Pin.h"
#include "common-hal/analogio/AnalogOut.h"
#include "common-hal/busio/I2C.h"
#include "common-hal/busio/SPI.h"
#include "common-hal/busio/UART.h"
@ -95,6 +96,10 @@ void reset_port(void) {
// A larger delay so the idle task can run and do any IDF cleanup needed.
vTaskDelay(4);
#if CIRCUITPY_ANALOGIO
analogout_reset();
#endif
#if CIRCUITPY_PULSEIO
esp32s2_peripherals_rmt_reset();
pulsein_reset();