Skip to content

Re-enable native Erlang driver #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AtomVM SSD1306 Nif
# AtomVM SSD1306 Driver

This AtomVM Nif and Erlang library can be used to drive an SSD1306 display on the ESP32 SoC for any Erlang/Elixir programs targeted for AtomVM on the ESP32 platform.
This AtomVM drivers is provided both as a NIF and as a pure Erlang library. It can be used to drive an SSD1306 display on the ESP32 SoC for any Erlang/Elixir programs targeted for AtomVM on the ESP32 platform.

This Nif is included as an add-on to the AtomVM base image. In order to use this Nif in your AtomVM program, you must be able to build the AtomVM virtual machine, which in turn requires installation of the Espressif IDF SDK and tool chain.

Expand Down
2 changes: 2 additions & 0 deletions examples/ssd1306_example/rebar.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{erl_opts, [debug_info]}.

{deps, [
{atomvm_ssd1306, {git, "https://github.com/atomvm/atomvm_ssd1306.git", {branch, "master"}}}
]}.

{plugins, [atomvm_rebar3_plugin]}.
7 changes: 3 additions & 4 deletions examples/ssd1306_example/src/ssd1306_example.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
-export([start/0]).

start() ->
SSD1306Config = #{
sda_pin => 21,
scl_pin => 22
},
SSD1306Config = #{sda_pin => 21,
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general, my preference for formatting is to use 4-space indentation always (not a fan of traditional erlang/emacs formatting).

Some examples:

Map = #{
    foo => bar,
    bar => tapas
}.

PropList = [
    {foo, bar},
    {bar, tapas}
].

Fun = fun() ->
    // do something
end.

%% file that be consult'd
{foo, [
   {bar, [
       {tapas, [one, two three] %% if it fits 80 cols
    ]}
]}.

nested(
    function(
       call([if, I, am, being, anal])
    )
).

scl_pin => 22,
use_nif => true},
{ok, SSD1306} = ssd1306:start(SSD1306Config),
ssd1306:clear(SSD1306),
ssd1306:set_contrast(SSD1306, 0),
Expand Down
21 changes: 18 additions & 3 deletions markdown/ssd1306.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The SSD1306 driver provides support for integrating SSD1306 displays with [AtomV

> Note. Testing has primarily utilized standalone SSD1306 modules.

The SSD1306 supports the 2-pin I2C interface, and the `atomvm_lib` SSD1306 driver makes use of this interface to communicate with the SSD1306 modem to display data. Users may select any supported GPIO pins on your device to integrate with the module.
The SSD1306 supports the 2-pin I2C interface, and the `atomvm_lib` SSD1306 driver makes use of this interface to communicate with the SSD1306 modem to display data. Users may select any supported GPIO pins on your device to integrate with the module. It also supports a non-NIF interface by leveraging `i2c_bus` available at [atomvm_lib](https://github.com/atomvm/atomvm_lib).

For more information about the ESP32 I2C interface, see the [ESP IDF SDK I2C documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/i2c.html).

Expand All @@ -29,12 +29,13 @@ The `atomvm_lib` SSD1306 driver is designed to provide a simple and easy to use

An instance of the `atomvm_lib` SSD1306 driver is created via the `ssd1306:start/1` function. This function takes a set of configuration, described in more detail below.

For example, to configure the 2-wire I2C interface to use the specified ESP32 pins, you can use the following configuration:
For example, to configure the 2-wire I2C interface to use the specified ESP32 pins using the NIF driver, you can use the following configuration:

%% erlang
Config = #{
sda_pin => 21,
scl_pin => 22
scl_pin => 22,
use_nif => true
},
{ok, Display} = ssd1306:start(Config),
...
Expand All @@ -51,6 +52,20 @@ To delete an instance of the driver, use the `ssd1306:stop/1` function.

> Note. This function is not well tested and its use may result in a memory leak.

## Using the I2C Bus interface

The `SSD1306` driver can also be used without a NIF but it doesn't support the rest of the features the NIF provids, however using this method allows you to share the I2C via `i2c_bus` (available at [atomvm_lib](https://github.com/atomvm/atomvm_lib/)):

```erlang
%% erlang
Config = #{
i2c_bus => I2CBus,
use_nif => false
},
{ok, Display} = ssd1306:start(Config),
...
```

## Configuration

The `atomvm_lib` SSD1306 driver is initialized with a map containing keys and values used to configure the driver. The keys and values in this map are summarized in the following table:
Expand Down
Loading