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.
This commit is contained in:
bobsayshilol 2022-01-19 15:34:18 +00:00 committed by GitHub
parent 96afce8ece
commit 25a3b36793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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. * \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) { 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); hw_write_masked(&adc_hw->cs, input_mask << ADC_CS_RROBIN_LSB, ADC_CS_RROBIN_BITS);
} }