Skip to content

Commit 349dfb9

Browse files
author
Jonathan Reichelt Gjertsen
committed
Add function to get the currently selected channel
This is most useful in combination with round-robin sampling to avoid having to track it manually.
1 parent a531123 commit 349dfb9

File tree

1 file changed

+10
-0
lines changed
  • src/rp2_common/hardware_adc/include/hardware

1 file changed

+10
-0
lines changed

src/rp2_common/hardware_adc/include/hardware/adc.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ static inline void adc_select_input(uint input) {
8888
hw_write_masked(&adc_hw->cs, input << ADC_CS_AINSEL_LSB, ADC_CS_AINSEL_BITS);
8989
}
9090

91+
/*! \brief ADC get input
92+
* \ingroup hardware_adc
93+
*
94+
* Returns the currently selected input. 0...3 are GPIOs 26...29 respectively.
95+
* Input 4 is the onboard temperature sensor.
96+
*/
97+
static inline uint adc_selected_input(void) {
98+
return (adc_hw->cs & ADC_CS_AINSEL_BITS) >> ADC_CS_AINSEL_LSB;
99+
}
100+
91101
/*! \brief Round Robin sampling selector
92102
* \ingroup hardware_adc
93103
*

0 commit comments

Comments
 (0)