From 25a3b367930825afde424ec3bf60dc33b31f6482 Mon Sep 17 00:00:00 2001 From: bobsayshilol Date: Wed, 19 Jan 2022 15:34:18 +0000 Subject: [PATCH] Fix assert in adc_set_round_robin() (#698) The mask passed in shouldn't already be shifted by ADC_CS_RROBIN_LSB (16) otherwise the shift in the call to hw_write_masked() would shift all of the bits off the end of the mask, hence we should be asserting not against ADC_CS_RROBIN_BITS (0x1f0000) but against the number of ADC channels available. --- src/rp2_common/hardware_adc/include/hardware/adc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_adc/include/hardware/adc.h b/src/rp2_common/hardware_adc/include/hardware/adc.h index be82025..b8987ee 100644 --- a/src/rp2_common/hardware_adc/include/hardware/adc.h +++ b/src/rp2_common/hardware_adc/include/hardware/adc.h @@ -106,7 +106,7 @@ static inline uint adc_get_selected_input(void) { * \param input_mask A bit pattern indicating which of the 5 inputs are to be sampled. Write a value of 0 to disable round robin sampling. */ static inline void adc_set_round_robin(uint input_mask) { - invalid_params_if(ADC, input_mask & ~ADC_CS_RROBIN_BITS); + valid_params_if(ADC, input_mask < (1 << NUM_ADC_CHANNELS)); hw_write_masked(&adc_hw->cs, input_mask << ADC_CS_RROBIN_LSB, ADC_CS_RROBIN_BITS); }