Skip to content

MCUs: update deprecated use of term_from_int32 - #2241

Merged
bettio merged 7 commits into
atomvm:release-0.7from
UncleGrumpy:update_adc_deprecations
Apr 10, 2026
Merged

MCUs: update deprecated use of term_from_int32#2241
bettio merged 7 commits into
atomvm:release-0.7from
UncleGrumpy:update_adc_deprecations

Conversation

@UncleGrumpy

@UncleGrumpy UncleGrumpy commented Mar 28, 2026

Copy link
Copy Markdown
Collaborator

Update all MCU platforms useage of term_from_int32 to safer variants of term_from_int*

See also: #1897

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
UncleGrumpy force-pushed the update_adc_deprecations branch 3 times, most recently from 90bf284 to 0bd3c10 Compare March 28, 2026 17:31
@UncleGrumpy UncleGrumpy changed the title ESP32 adc_driver.c: update deprecated APIs ESP32: update deprecated use of term_from_int32 Mar 28, 2026
@UncleGrumpy
UncleGrumpy requested a review from pguyot March 28, 2026 17:35

@UncleGrumpy UncleGrumpy Mar 28, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

All values encoded in adc_driver.c with term_from_int28 are 17 bits or less.

@UncleGrumpy
UncleGrumpy removed the request for review from pguyot March 28, 2026 17:39
@UncleGrumpy
UncleGrumpy force-pushed the update_adc_deprecations branch from 0bd3c10 to 793c199 Compare March 28, 2026 18:28
@UncleGrumpy
UncleGrumpy requested a review from pguyot March 28, 2026 18:29
Comment thread src/platforms/esp32/components/avm_builtins/socket_driver.c
Comment thread src/platforms/esp32/components/avm_sys/sys.c
@UncleGrumpy
UncleGrumpy force-pushed the update_adc_deprecations branch from 793c199 to 4bb7414 Compare March 29, 2026 15:49
@petermm

petermm commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Know this extends the scope - but the last remaining is below:

Remaining term_from_int32 call-sites

1. STM32 — gpio_driver.c

File: src/platforms/stm32/src/lib/gpio_driver.c:675

term_put_tuple_element(gpio_tuple, 1, term_from_int32((int32_t) gpio_pin));

Context: Converts an STM32 GPIO pin number to a term inside the interrupt callback.

Recommended replacement: term_from_int11
STM32 GPIO pin numbers are 0–15 per bank, well within 11 bits.
Matches the ESP32 gpio_driver.c fix already applied in this PR.

term_put_tuple_element(gpio_tuple, 1, term_from_int11((int16_t) gpio_pin));

2. RP2 — networkdriver.c (IP address octets)

File: src/platforms/rp2/src/lib/networkdriver.c:131-134

terms[0] = term_from_int32((addr >> 24) & 0xFF);
terms[1] = term_from_int32((addr >> 16) & 0xFF);
terms[2] = term_from_int32((addr >> 8) & 0xFF);
terms[3] = term_from_int32(addr & 0xFF);

Context: Builds a {A, B, C, D} IP address tuple. Each octet is 0–255.

Recommended replacement: term_from_int11
Each octet is an unsigned byte (0–255), fits in 11 bits. Alternatively
term_from_int works since these are small constants.

terms[0] = term_from_int11((addr >> 24) & 0xFF);
terms[1] = term_from_int11((addr >> 16) & 0xFF);
terms[2] = term_from_int11((addr >> 8) & 0xFF);
terms[3] = term_from_int11(addr & 0xFF);

3. RP2 — networkdriver.c (RSSI)

File: src/platforms/rp2/src/lib/networkdriver.c:718

term rssi = term_from_int32(sta_rssi);

Context: WiFi signal strength (RSSI). Typically −90 to 0 dBm, always a small signed integer.

Recommended replacement: term_from_int11
RSSI values are well within ±1024.

term rssi = term_from_int11((int16_t) sta_rssi);

@UncleGrumpy
UncleGrumpy force-pushed the update_adc_deprecations branch 2 times, most recently from 064164e to 2dcde17 Compare March 30, 2026 17:31
@UncleGrumpy UncleGrumpy changed the title ESP32: update deprecated use of term_from_int32 MCUs: update deprecated use of term_from_int32 Mar 30, 2026
@UncleGrumpy
UncleGrumpy force-pushed the update_adc_deprecations branch from 2dcde17 to 9d2a026 Compare March 30, 2026 17:40
@UncleGrumpy

Copy link
Copy Markdown
Collaborator Author

This should take care of all of the remaining uses of term_from_int32.

Update the use of deprecated `term_from_int32` to `term_from_int11` for
encoding gpio pin values. The values will fit in an int4, but the type
is uint16_t, so `term_to_int11` is used for correctness.

Signed-off-by: Winford <winford@object.stream>
Change all uses of the `term_from_int32` to `term_from_int11`, which is
of adequate size to contain all of the encoded terms.

Signed-off-by: Winford <winford@object.stream>
Replace use of `term_from_int32` other safe term_from_int* variants.

Signed-off-by: Winford <winford@object.stream>
Updates use of deprecated `term_from_int32` to `term_from_int` when
encoding the `send_timeout_ms` value.

Signed-off-by: Winford <winford@object.stream>
Update the use of `term_from_int32` to encode `port` (`u16_t`) values
to the new `term_from_int28`.

Signed-off-by: Winford <winford@object.stream>
Update the use of deprecated `term_from_int32` to `term_from_int11` for
encoding gpio pin values. The 11-bit value is more than enough to allow
for the number of pins available on any ESP32 for many years.

Signed-off-by: Winford <winford@object.stream>
Update deprecated `term_from_int32` to use `term_from_int28`.

See also: atomvm#1897

Signed-off-by: Winford <winford@object.stream>
@UncleGrumpy
UncleGrumpy force-pushed the update_adc_deprecations branch from 9d2a026 to dcab3cd Compare April 10, 2026 06:22
@bettio
bettio merged commit 8ea71cc into atomvm:release-0.7 Apr 10, 2026
84 of 85 checks passed
bettio added a commit that referenced this pull request Apr 27, 2026
Merge fixes, features, and optimizations from release-0.7, including:
- JIT: Add WASM32 backend with emscripten integration (#2260)
- Add SPI support to STM32 platform (#2127)
- Add network:wifi_scan/0,1 to esp32 network driver (#1165)
- Add serial (UART) distribution support (#2249)
- Add more reset reasons to esp:reset_reason/0 (#2275)
- Implement nif_start, executable_line and debug_line opcodes (#2264)
- MCUs: update deprecated use of term_from_int32 (#2241)
- Fix JIT crash on scheduler destroy by joining threads (#2280)
- Fix race condition in context_destroy (#2277)
- JIT x86-64: fix xorq encoding to use signed shorter form (#2278)
- JIT arm32: assemble push/pop with single reg as gnu as does (#2276)
- Fix sign of result of several functions from binary module (#2256)
- Fix offset and mod_offset sign using size_t (#2266)
- Fix warning with os:system_time/1 (#2265)
- Fix test_timer assertions (#2261)
- Normalize system_architecture strings (#2171)
- emscripten: Use EXPORT_ES6 setting and .mjs suffix (#2273)
- RP2: Improve initial flash message (#2122)
- CI: Rename pico combined for sorting (#2220)
- STM32 CI: Use tag release for renode 1.16.1 (#2268)
- CI: Fix macos - use setup-beam for gleam (#2263)
@UncleGrumpy
UncleGrumpy deleted the update_adc_deprecations branch May 19, 2026 02:57
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.

4 participants