AtomVM icon indicating copy to clipboard operation
AtomVM copied to clipboard

Add esp_dac, for now only with oneshot mode

Open schnittchen opened this issue 1 month ago • 9 comments

These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

schnittchen avatar Nov 21 '25 22:11 schnittchen

Did you take the code verbatim from the component, or did you apply any change?

I don't understand what you mean here, which component?

schnittchen avatar Nov 24 '25 18:11 schnittchen

Did you take the code verbatim from the component, or did you apply any change?

I don't understand what you mean here, which component?

I saw the following copyright:

 * Copyright 2020-2023 dushin.net
 * Copyright 2024 Ricardo Lanziano <[email protected]>
 * Copyright 2022-2024 Winford <[email protected]>

So my assumption is that this PR is based on this code: https://github.com/atomvm/atomvm_adc . Am I right? If so, what kind of changes did you do to it?

bettio avatar Nov 26 '25 12:11 bettio

So my assumption is that this PR is based on this code: https://github.com/atomvm/atomvm_adc . Am I right? If so, what kind of changes did you do to it?

Ah, thanks for clarifying. The new code started out as the adc code but with most of the details removed. Few things should really have survived: some of the #include lines; create_pair and error_return_tuple; how to expose the resource to the Erlang world (although with significantly different code). The happy case result building on nif_oneshot_new_channel_p should be 1:1 the same.

I don't really know the implications on the copyright.

schnittchen avatar Nov 26 '25 12:11 schnittchen

In order to merge this code this issue has to be fixed: esp_dac.erl:19: Call to missing or unexported function esp_dac:oneshot_new_channel_p/1

Where did you see that?

schnittchen avatar Nov 26 '25 20:11 schnittchen

Where did you see that?

Most CI is red eg. https://github.com/atomvm/AtomVM/actions/runs/19595789851/job/56245058688?pr=1998

petermm avatar Nov 26 '25 20:11 petermm

looks like DAC is only on esp32 and esp32-s2, so we need some guards in the proper places: (you have CONFIG_IDF_TARGET_ESP32S3 CONFIG_IDF_TARGET_ESP32C3 etc. so ESP32 is for that chip only - a bit confusing..)

#if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) 
    ..
#endif

petermm avatar Nov 29 '25 09:11 petermm

Looks like DAC is only on esp32 and esp32-s2, so we need some guards in the proper places, so let's make a CONFIG_AVM_ENABLE_DAC_NIF guard in the dac_driver.c:

#include <sdkconfig.h>
#ifdef CONFIG_AVM_ENABLE_DAC_NIF
..
#endif /* CONFIG_AVM_ENABLE_DAC_NIF */

then in the kconfig: https://github.com/atomvm/AtomVM/blob/main/src/platforms/esp32/components/avm_builtins/Kconfig

config AVM_ENABLE_DAC_NIF
    bool "Enable DAC NIF"
    default "y" if IDF_TARGET_ESP32
    default "y" if IDF_TARGET_ESP32S2
    default n

and in https://github.com/schnittchen/AtomVM/blob/8eaf1bfc27e24c874393457293d4edd329d7ab04/src/platforms/esp32/components/avm_builtins/CMakeLists.txt#L40

if(CONFIG_AVM_ENABLE_DAC_NIF)
   //big conditional for dac driver
endif()

petermm avatar Nov 29 '25 09:11 petermm

The remaining failed checks seem unrelated. Also, I think I've taken care of all comments so far

schnittchen avatar Nov 29 '25 14:11 schnittchen

Squashed and rebased.

I'm delaying adding to the Changelog for the moment, hoping that #1977 will get in before.

schnittchen avatar Dec 09 '25 20:12 schnittchen

Rebased and added to the Changelog

schnittchen avatar Dec 10 '25 19:12 schnittchen