Commit 495be71d authored by IhorNehrutsa's avatar IhorNehrutsa Committed by Damien George

esp32/machine_dac: Support one-shot mode of driver.

And simplify board configuration of DAC by using SOC_DAC_SUPPORTED.
Signed-off-by: default avatarIhorNehrutsa <Ihor.Nehrutsa@gmail.com>
parent 3106ee48
......@@ -4,8 +4,6 @@
// Network config
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-nano-esp32"
#define MICROPY_PY_MACHINE_DAC (0)
#define MICROPY_HW_I2C0_SCL (12)
#define MICROPY_HW_I2C0_SDA (11)
......
......@@ -4,7 +4,6 @@
#define MICROPY_HW_MCU_NAME "ESP32C3"
#define MICROPY_HW_ENABLE_SDCARD (0)
#define MICROPY_PY_MACHINE_DAC (0)
#define MICROPY_PY_MACHINE_I2S (0)
// Enable UART REPL for modules that have an external USB-UART and don't use native USB.
......
......@@ -4,8 +4,6 @@
#endif
#define MICROPY_HW_MCU_NAME "ESP32S3"
#define MICROPY_PY_MACHINE_DAC (0)
// Enable UART REPL for modules that have an external USB-UART and don't use native USB.
#define MICROPY_HW_ENABLE_UART_REPL (1)
......
......@@ -3,7 +3,6 @@
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-c3-mini"
#define MICROPY_HW_ENABLE_SDCARD (0)
#define MICROPY_PY_MACHINE_DAC (0)
#define MICROPY_PY_MACHINE_I2S (0)
#define MICROPY_HW_I2C0_SCL (10)
......
......@@ -2,8 +2,6 @@
#define MICROPY_HW_MCU_NAME "ESP32-S3"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "FeatherS3"
#define MICROPY_PY_MACHINE_DAC (0)
#define MICROPY_HW_I2C0_SCL (9)
#define MICROPY_HW_I2C0_SDA (8)
......
......@@ -2,8 +2,6 @@
#define MICROPY_HW_MCU_NAME "ESP32-S3-FN8"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "NanoS3"
#define MICROPY_PY_MACHINE_DAC (0)
#define MICROPY_HW_I2C0_SCL (9)
#define MICROPY_HW_I2C0_SDA (8)
......
......@@ -2,8 +2,6 @@
#define MICROPY_HW_MCU_NAME "ESP32-S3"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "ProS3"
#define MICROPY_PY_MACHINE_DAC (0)
#define MICROPY_HW_I2C0_SCL (9)
#define MICROPY_HW_I2C0_SDA (8)
......
......@@ -2,8 +2,6 @@
#define MICROPY_HW_MCU_NAME "ESP32-S3-FN8"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "TinyS3"
#define MICROPY_PY_MACHINE_DAC (0)
#define MICROPY_HW_I2C0_SCL (9)
#define MICROPY_HW_I2C0_SDA (8)
......
......@@ -2,8 +2,6 @@
#define MICROPY_HW_MCU_NAME "ESP32-S3-PICO-1-N8R2"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "TinyWATCHS3"
#define MICROPY_PY_MACHINE_DAC (0)
#define MICROPY_HW_I2C0_SCL (9)
#define MICROPY_HW_I2C0_SDA (8)
......
......@@ -34,21 +34,30 @@
#if MICROPY_PY_MACHINE_DAC
#include "driver/gpio.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
#include "driver/dac_oneshot.h"
#else
#include "driver/dac.h"
#define DAC_CHAN_0 DAC_CHANNEL_1
#define DAC_CHAN_1 DAC_CHANNEL_2
#endif
typedef struct _mdac_obj_t {
mp_obj_base_t base;
gpio_num_t gpio_id;
dac_channel_t dac_id;
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
dac_oneshot_handle_t dac_oneshot_handle;
#endif
} mdac_obj_t;
STATIC const mdac_obj_t mdac_obj[] = {
STATIC mdac_obj_t mdac_obj[] = {
#if CONFIG_IDF_TARGET_ESP32
{{&machine_dac_type}, GPIO_NUM_25, DAC_CHANNEL_1},
{{&machine_dac_type}, GPIO_NUM_26, DAC_CHANNEL_2},
{{&machine_dac_type}, GPIO_NUM_25, DAC_CHAN_0},
{{&machine_dac_type}, GPIO_NUM_26, DAC_CHAN_1},
#else
{{&machine_dac_type}, GPIO_NUM_17, DAC_CHANNEL_1},
{{&machine_dac_type}, GPIO_NUM_18, DAC_CHANNEL_2},
{{&machine_dac_type}, GPIO_NUM_17, DAC_CHAN_0},
{{&machine_dac_type}, GPIO_NUM_18, DAC_CHAN_1},
#endif
};
......@@ -68,6 +77,12 @@ STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
mp_raise_ValueError(MP_ERROR_TEXT("invalid Pin for DAC"));
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
dac_oneshot_config_t dac_oneshot_config = {.chan_id = self->dac_id};
check_esp_err(dac_oneshot_new_channel(&dac_oneshot_config, (dac_oneshot_handle_t *)&self->dac_oneshot_handle));
check_esp_err(dac_oneshot_output_voltage(self->dac_oneshot_handle, 0));
return MP_OBJ_FROM_PTR(self);
#else
esp_err_t err = dac_output_enable(self->dac_id);
if (err == ESP_OK) {
err = dac_output_voltage(self->dac_id, 0);
......@@ -76,6 +91,7 @@ STATIC mp_obj_t mdac_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
return MP_OBJ_FROM_PTR(self);
}
mp_raise_ValueError(MP_ERROR_TEXT("parameter error"));
#endif
}
STATIC void mdac_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
......@@ -90,11 +106,16 @@ STATIC mp_obj_t mdac_write(mp_obj_t self_in, mp_obj_t value_in) {
mp_raise_ValueError(MP_ERROR_TEXT("value out of range"));
}
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0)
check_esp_err(dac_oneshot_output_voltage(self->dac_oneshot_handle, value));
return mp_const_none;
#else
esp_err_t err = dac_output_voltage(self->dac_id, value);
if (err == ESP_OK) {
return mp_const_none;
}
mp_raise_ValueError(MP_ERROR_TEXT("parameter error"));
#endif
}
MP_DEFINE_CONST_FUN_OBJ_2(mdac_write_obj, mdac_write);
......
......@@ -123,7 +123,7 @@
#define MICROPY_PY_MACHINE_SPI_LSB (1)
#define MICROPY_PY_MACHINE_SOFTSPI (1)
#ifndef MICROPY_PY_MACHINE_DAC
#define MICROPY_PY_MACHINE_DAC (1)
#define MICROPY_PY_MACHINE_DAC (SOC_DAC_SUPPORTED)
#endif
#ifndef MICROPY_PY_MACHINE_I2S
#define MICROPY_PY_MACHINE_I2S (1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment