Skip to content

Commit 1684239

Browse files
committed
Forward port changes from v0.6 release branch
Merge fixes (such as esp_adc NIF declarations and UART doc) from release-0.6 branch into main.
2 parents 24084c5 + 0d5437f commit 1684239

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Added a limited implementation of the OTP `ets` interface
1111
- Added `code:all_loaded/0` and `code:all_available/0`
1212

13+
## [0.6.6] - Unreleased
14+
15+
### Fixed
16+
17+
- Fixed specifications of nifs from `esp_adc` module
18+
1319
## [0.6.5] - 2024-10-15
1420

1521
### Added

doc/src/programmers-guide.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,34 +1795,37 @@ Information about the ESP32 UART interface can be found in the IDF SDK [UART Doc
17951795

17961796
The AtomVM UART implementation uses the AtomVM Port mechanism and must be initialized using the [`uart:open/2`](./apidocs/erlang/eavmlib/uart.md#open2) function.
17971797

1798-
The first parameter indicates the ESP32 UART hardware interface. Legal values are:
1798+
The first parameter indicates the ESP32 UART hardware interface. Valid values are:
17991799

18001800
```erlang
18011801
"UART0" | "UART1" | "UART2"
18021802
```
18031803

1804-
The selection of the hardware interface dictates the default RX and TX pins on the ESP32:
1805-
1806-
| Port | RX pin | TX pin |
1807-
|-------------|--------|-------|
1808-
| `UART0` | GPIO_3 | GPIO_1 |
1809-
| `UART1` | GPIO_9 | GPIO_10 |
1810-
| `UART2` | GPIO_16 | GPIO_17 |
1811-
18121804
The second parameter is a properties list, containing the following elements:
18131805

18141806
| Key | Value Type | Required | Default Value | Description |
18151807
|-----|------------|----------|---------------|-------------|
1808+
| `rx` | `integer()` | no | -1 (`UART_PIN_NO_CHANGE`) | RX GPIO Pin |
1809+
| `tx` | `integer()` | no | -1 (`UART_PIN_NO_CHANGE`) | TX GPIO Pin |
18161810
| `speed` | `integer()` | no | 115200 | UART baud rate (bits/sec) |
18171811
| `data_bits` | `5 \| 6 \| 7 \| 8` | no | 8 | UART data bits |
18181812
| `stop_bits` | `1 \| 2` | no | 1 | UART stop bits |
18191813
| `flow_control` | `hardware \| software \| none` | no | `none` | Flow control |
18201814
| `parity` | `even \| odd \| none` | no | `none` | UART parity check |
18211815

1816+
1817+
These are the usual RX and TX pins for the various UARTs on the ESP32 (as always check your board specs):
1818+
1819+
| Port | RX pin | TX pin |
1820+
|-------------|--------|-------|
1821+
| `UART0` | GPIO_3 | GPIO_1 |
1822+
| `UART1` | GPIO_9 | GPIO_10 |
1823+
| `UART2` | GPIO_16 | GPIO_17 |
1824+
18221825
For example,
18231826

18241827
```erlang
1825-
UART = uart:open("UART0", [{speed, 9600}])
1828+
UART = uart:open("UART0", [{rx, 3}, {tx, 1}, {speed, 9600}])
18261829
```
18271830

18281831
Once the port is opened, you can use the returned `UART` instance to read and write bytes to the attached device.

libs/eavmlib/src/esp_adc.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
%%-----------------------------------------------------------------------------
118118
-spec init() -> {ok, ADCUnit :: adc_rsrc()} | {error, Reason :: term()}.
119119
init() ->
120-
throw(nif_error).
120+
erlang:nif_error(undefined).
121121

122122
%%-----------------------------------------------------------------------------
123123
%% @param UnitResource returned from init/0
@@ -134,7 +134,7 @@ init() ->
134134
%%-----------------------------------------------------------------------------
135135
-spec deinit(UnitResource :: adc_rsrc()) -> ok | {error, Reason :: term()}.
136136
deinit(_UnitResource) ->
137-
throw(nif_error).
137+
erlang:nif_error(undefined).
138138

139139
%%-----------------------------------------------------------------------------
140140
%% @param Pin Pin to configure as ADC
@@ -185,7 +185,7 @@ acquire(Pin, UnitHandle) ->
185185
Attenuation :: attenuation()
186186
) -> {ok, Channel :: adc_rsrc()} | {error, Reason :: term()}.
187187
acquire(_Pin, _UnitHandle, _BitWidth, _Attenuation) ->
188-
throw(nif_error).
188+
erlang:nif_error(undefined).
189189

190190
%%-----------------------------------------------------------------------------
191191
%% @param ChannelResource of the pin returned from acquire/4
@@ -204,7 +204,7 @@ acquire(_Pin, _UnitHandle, _BitWidth, _Attenuation) ->
204204
%%-----------------------------------------------------------------------------
205205
-spec release_channel(ChannelResource :: adc_rsrc()) -> ok | {error, Reason :: term()}.
206206
release_channel(_ChannelResource) ->
207-
throw(nif_error).
207+
erlang:nif_error(undefined).
208208

209209
%%-----------------------------------------------------------------------------
210210
%% @param ChannelResource of the pin returned from acquire/4
@@ -256,7 +256,7 @@ sample(ChannelResource, UnitResource) ->
256256
ChannelResource :: adc_rsrc(), UnitResource :: adc_rsrc(), ReadOptions :: read_options()
257257
) -> {ok, Result :: reading()} | {error, Reason :: term()}.
258258
sample(_ChannelResource, _UnitResource, _ReadOptions) ->
259-
throw(nif_error).
259+
erlang:nif_error(undefined).
260260

261261
%%-----------------------------------------------------------------------------
262262
%% @returns {ok, Pid}

0 commit comments

Comments
 (0)