AtomVM icon indicating copy to clipboard operation
AtomVM copied to clipboard

Add optional I2C Nif-based resource driver

Open fadushin opened this issue 1 year ago • 0 comments

This PR adds an optional Nif-based resource for use with the I2C interface. Using a Nif-based resource has several advantages, including:

  • More predictable (and less) latency between the I2C client and IDF calls, since Nifs are not as beholden to the whims of the scheduler as ports/processes;
  • One less process needed (as opposed to the port-based implementation), so has less memory overhead;
  • Automated resource reclamation when resource is GC’d (after ref count goes to 0), so users can call close, but in cases where they do not, the i2c driver will be removed (eventually).

This implementation is currently opt-in. Set use_nif to true in the initialization parameter when creating an I2C instance, to use it. Otherwise, the port-based implementation will be used.

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

fadushin avatar Jan 21 '24 23:01 fadushin