Skip to content

ESP32-S2: AnalogOut #3514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions ports/esp32s2/common-hal/analogio/AnalogOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 0 additions & 1 deletion ports/esp32s2/common-hal/analogio/AnalogOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions ports/esp32s2/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down