1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/nrf52: add VDDHDIV5 as ADC input

This commit is contained in:
Hauke Petersen 2021-02-10 17:20:01 +01:00
parent d7f3e92c30
commit 63c23598b3
2 changed files with 18 additions and 1 deletions

View File

@ -60,7 +60,11 @@ extern "C" {
/**
* @brief The nRF52 family of CPUs provides a fixed number of 9 ADC lines
*/
#ifdef SAADC_CH_PSELP_PSELP_VDDHDIV5
#define ADC_NUMOF (10U)
#else
#define ADC_NUMOF (9U)
#endif
/**
* @brief SPI temporary buffer size for storing const data in RAM before
@ -83,6 +87,9 @@ enum {
NRF52_AIN6 = 6, /**< Analog Input 6 */
NRF52_AIN7 = 7, /**< Analog Input 7 */
NRF52_VDD = 8, /**< VDD, not useful if VDD is reference... */
#ifdef SAADC_CH_PSELP_PSELP_VDDHDIV5
NRF52_VDDHDIV5 = 9, /**< VDDH divided by 5 */
#endif
};
#ifndef DOXYGEN

View File

@ -114,13 +114,23 @@ int32_t adc_sample(adc_t line, adc_res_t res)
return -1;
}
#ifdef SAADC_CH_PSELP_PSELP_VDDHDIV5
if (line == NRF52_VDDHDIV5) {
line = SAADC_CH_PSELP_PSELP_VDDHDIV5;
} else {
line += 1;
}
#else
line += 1;
#endif
/* prepare device */
prep();
/* set resolution */
NRF_SAADC->RESOLUTION = res;
/* set line to sample */
NRF_SAADC->CH[0].PSELP = (line + 1);
NRF_SAADC->CH[0].PSELP = line;
/* start the SAADC and wait for the started event */
NRF_SAADC->EVENTS_STARTED = 0;