Skip to content

Conversation

@schnittchen
Copy link

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

Signed-off-by: schnittchen <schnittchen@das-labor.org>
Signed-off-by: schnittchen <schnittchen@das-labor.org>
Copy link
Collaborator

@bettio bettio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you take the code verbatim from the component, or did you apply any change? If so, can you let me know which changes?
Also, let's add this to our sdkconfig so we can make it optional when building AtomVM from scratch.

@schnittchen
Copy link
Author

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?

@bettio
Copy link
Collaborator

bettio commented Nov 26, 2025

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 <arpunk@fatelectron.net>
 * Copyright 2022-2024 Winford <winford@object.stream>

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?

Copy link
Collaborator

@bettio bettio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@schnittchen
Copy link
Author

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
Copy link
Author

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?

@petermm
Copy link
Contributor

petermm commented Nov 26, 2025

Where did you see that?

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

Signed-off-by: schnittchen <schnittchen@das-labor.org>
Signed-off-by: schnittchen <schnittchen@das-labor.org>
@petermm

This comment was marked as outdated.

@petermm
Copy link
Contributor

petermm commented Nov 29, 2025

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()

Signed-off-by: schnittchen <schnittchen@das-labor.org>
Signed-off-by: schnittchen <schnittchen@das-labor.org>
Signed-off-by: schnittchen <schnittchen@das-labor.org>
Signed-off-by: schnittchen <schnittchen@das-labor.org>
@schnittchen
Copy link
Author

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

set(AVM_BUILTIN_COMPONENT_SRCS "adc_driver.c" ${AVM_BUILTIN_COMPONENT_SRCS})
if(CONFIG_AVM_ENABLE_DAC_NIF)
set(ADDITIONAL_PRIV_REQUIRES "esp_adc" ${ADDITIONAL_PRIV_REQUIRES})
set(AVM_BUILTIN_COMPONENT_SRCS "adc_driver.c" ${AVM_BUILTIN_COMPONENT_SRCS})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is putting the esp_adc under the CONFIG_AVM_ENABLE_DAC_NIF flag which we don't want..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so? My thinking was, if the DAC nif is disabled, we don't need to add that dependency...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AVM_ENABLE_DAC_NIF is only true for esp32/esp32s2 - the adc is available all boards..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I see it now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed now.

Signed-off-by: schnittchen <schnittchen@das-labor.org>
Signed-off-by: schnittchen <schnittchen@das-labor.org>
// References
// https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/dac.html

#include <context.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <sdkconfig.h>
#ifdef CONFIG_AVM_ENABLE_DAC_NIF

on top? just to follow all/most other nifs pattern?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants