Berry simplify DAC support (#22546)

This commit is contained in:
s-hadinger 2024-11-24 23:30:24 +01:00 committed by GitHub
parent 3448e17317
commit 2402f7cbd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 11 deletions

View File

@ -23,13 +23,6 @@
#include <berry.h>
#include "esp8266toEsp32.h"
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
#if ESP_IDF_VERSION_MAJOR >= 5
#include <driver/dac_oneshot.h>
#else
#include <driver/dac.h>
#endif
#endif
/*********************************************************************************************\
* Native functions mapped to Berry functions
*
@ -40,9 +33,10 @@
extern "C" {
#include "berry/include/be_gpio_defines.h"
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
#ifdef SOC_DAC_SUPPORTED
#include "soc/dac_channel.h"
#endif // defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
#include <driver/dac_oneshot.h>
#endif // SOC_DAC_SUPPORTED
// virtual member
int gp_member(bvm *vm);
@ -65,7 +59,7 @@ extern "C" {
// synthetic mode
if (-1 == mode) {
// DAC
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
#ifdef SOC_DAC_SUPPORTED
if (pin != DAC_CHAN0_GPIO_NUM && pin != DAC_CHAN1_GPIO_NUM) {
be_raisef(vm, "value_error", "DAC only supported on GPIO%i-%i", DAC_CHAN0_GPIO_NUM, DAC_CHAN1_GPIO_NUM);
}
@ -113,7 +107,7 @@ extern "C" {
int gp_dac_voltage(bvm *vm);
int gp_dac_voltage(bvm *vm) {
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2)
#ifdef SOC_DAC_SUPPORTED
int32_t argc = be_top(vm); // Get the number of arguments
if (argc == 2 && be_isint(vm, 1) && be_isnumber(vm, 2)) {
int32_t pin = be_toint(vm, 1);