AtomVM icon indicating copy to clipboard operation
AtomVM copied to clipboard

Update ESP32 GPIO driver errors to match other MCU platforms

Open UncleGrumpy opened this issue 1 year ago • 8 comments

These changes move the GPIO specific atoms out of the ESP32 platform default atoms (created at boot) into the GPIO driver where they are only created as needed.

Breaking changes update the error returns to match the spec. Nifs raise Error, and port functions return {error, Reason} when errors are encountered.

Adds gpio driver tests to the Wokwi sim to test driver functionality and error return correctness for invalid parameters.

With #1448 closes #894

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

UncleGrumpy avatar Dec 21 '24 19:12 UncleGrumpy

do we need to remove RISING_ATOM_INDEX et al in platform_defaultatoms.h ?https://github.com/atomvm/AtomVM/blob/63ba9663df3908e72bef8039f018b41ee465e568/src/platforms/esp32/components/avm_sys/include/platform_defaultatoms.h#L28

petermm avatar Dec 21 '24 20:12 petermm

do we need to remove RISING_ATOM_INDEX et al in platform_defaultatoms.h ?

https://github.com/atomvm/AtomVM/blob/63ba9663df3908e72bef8039f018b41ee465e568/src/platforms/esp32/components/avm_sys/include/platform_defaultatoms.h#L28

This is done in commit bede918

UncleGrumpy avatar Dec 21 '24 21:12 UncleGrumpy

My mistake, you are correct! Those changes should have been included in the commit I mentioned, but were not added. Correction has been pushed.

UncleGrumpy avatar Dec 21 '24 22:12 UncleGrumpy

LGTM, but assume it needs rebasing to new defaultatoms setup.

petermm avatar Dec 27 '24 11:12 petermm

Indeed. I also realized that I should be using port_create_error_tuple, and remove the unnecessary error_tuple_maybe_gc and update/remove the usage of create_pair as well.

UncleGrumpy avatar Dec 27 '24 19:12 UncleGrumpy

All fixed. This should be ready now. We needed to keep create_pair, because we need to preserve a root, if gc is necessary.

UncleGrumpy avatar Dec 27 '24 20:12 UncleGrumpy

Please, see also #1442

bettio avatar Dec 29 '24 14:12 bettio

Please, see also #1442

I believe I have followed the guidelines you laid out in #1442, and the comments you made above about atom creation and fixed all of the atoms used by the driver to insure they are created in a safe way. I also used ATOM_STR() inline, removing the const char* declarations.

UncleGrumpy avatar Dec 30 '24 05:12 UncleGrumpy