Skip to content

Commit

Permalink
[beken-72xx] Improve ddev ADC support (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
szupi-ipuzs committed Jan 6, 2024
1 parent c90794e commit 1e3a82f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cores/beken-72xx/arduino/src/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,21 @@ uint16_t analogReadVoltage(pin_size_t pinNumber) {
adc.pData = adcData;
adc.data_buff_size = 1;
handle = ddev_open(SARADC_DEV_NAME, &status, (uint32_t)&adc);
if (status)
if (handle == -1) {
return 0;
}

if (status != SARADC_SUCCESS) {
ddev_close(handle);
return 0;
}

// wait for data
while (!adc.has_data || adc.current_sample_data_cnt < 1) {
delay(1);
}
ddev_control(handle, SARADC_CMD_RUN_OR_STOP_ADC, (void *)false);
uint8_t run_stop = 0; // stop
ddev_control(handle, SARADC_CMD_RUN_OR_STOP_ADC, &run_stop);
ddev_close(handle);
return adcData[0];
}
Expand Down

0 comments on commit 1e3a82f

Please sign in to comment.