Skip to content

Commit 9d2a026

Browse files
committed
ESP32 adc_driver.c: update deprecated APIs
Update deprecated `term_from_int32` to use `term_from_int28`. See also: #1897 Signed-off-by: Winford <winford@object.stream>
1 parent 1066bf6 commit 9d2a026

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
strict format validation
2222
- Stop using deprecated `term_from_int32` on STM32 platform
2323
- Stop using deprecated `term_from_int32` on RP2 platform
24+
- Stop using deprecated `term_from_int32` on ESP32 platform
2425

2526
### Fixed
2627
- Fixed `erlang:cancel_timer/1` return type spec and documentation to match OTP

src/platforms/esp32/components/avm_builtins/adc_driver.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static term nif_adc_sample(Context *ctx, int argc, term argv[])
595595

596596
term read_options = argv[2];
597597
VALIDATE_VALUE(read_options, term_is_list);
598-
term samples = interop_kv_get_value_default(read_options, ATOM_STR("\x7", "samples"), term_from_int32(DEFAULT_SAMPLES), ctx->global);
598+
term samples = interop_kv_get_value_default(read_options, ATOM_STR("\x7", "samples"), term_from_int28(DEFAULT_SAMPLES), ctx->global);
599599
if (UNLIKELY(!term_is_integer(samples))) {
600600
ESP_LOGE(TAG, "samples value must be an integer from 1 to 1024.");
601601
RAISE_ERROR(BADARG_ATOM);
@@ -625,20 +625,20 @@ static term nif_adc_sample(Context *ctx, int argc, term argv[])
625625
adc_raw /= samples_val;
626626
ESP_LOGD(TAG, "read adc raw reading: %i", adc_raw);
627627

628-
raw = raw == TRUE_ATOM ? term_from_int32(adc_raw) : UNDEFINED_ATOM;
628+
raw = raw == TRUE_ATOM ? term_from_int28(adc_raw) : UNDEFINED_ATOM;
629629
if (voltage == TRUE_ATOM) {
630630
int millivolts = 0;
631631
if (chan_rsrc->calibration > ESTIMATED) {
632632
err = adc_cali_raw_to_voltage(chan_rsrc->cali_handle, adc_raw, &millivolts);
633633
if (UNLIKELY(err != ESP_OK)) {
634634
ESP_LOGW(TAG, "Failed to get calibrated voltage, returning estimated voltage");
635-
voltage = term_from_int32(approximate_millivolts(adc_raw, chan_rsrc->attenuation, chan_rsrc->width));
635+
voltage = term_from_int28(approximate_millivolts(adc_raw, chan_rsrc->attenuation, chan_rsrc->width));
636636
} else {
637-
voltage = term_from_int32(millivolts);
637+
voltage = term_from_int28(millivolts);
638638
}
639639
} else {
640640
ESP_LOGD(TAG, "ADC channel not calibrated, using estimated voltage");
641-
voltage = term_from_int32(approximate_millivolts(adc_raw, chan_rsrc->attenuation, chan_rsrc->width));
641+
voltage = term_from_int28(approximate_millivolts(adc_raw, chan_rsrc->attenuation, chan_rsrc->width));
642642
}
643643
} else {
644644
voltage = UNDEFINED_ATOM;

0 commit comments

Comments
 (0)