Skip to content

Commit c6b47fe

Browse files
authored
rp2: use the correct channel mask for rp2350 ADC; hold lock during read (#4938)
1 parent 536deaa commit c6b47fe

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/machine/machine_rp2_adc.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,15 @@ func (c ADCChannel) Configure(config ADCConfig) error {
7373
func (c ADCChannel) getOnce() uint16 {
7474
// Make it safe to sample multiple ADC channels in separate go routines.
7575
adcLock.Lock()
76-
rp.ADC.CS.ReplaceBits(uint32(c), 0b111, rp.ADC_CS_AINSEL_Pos)
76+
rp.ADC.CS.ReplaceBits(uint32(c)<<rp.ADC_CS_AINSEL_Pos, rp.ADC_CS_AINSEL_Msk, 0)
7777
rp.ADC.CS.SetBits(rp.ADC_CS_START_ONCE)
7878

7979
waitForReady()
80+
v := rp.ADC.RESULT.Get()
8081
adcLock.Unlock()
8182

8283
// rp2040 is a 12-bit ADC, scale raw reading to 16-bits.
83-
return uint16(rp.ADC.RESULT.Get()) << 4
84+
return uint16(v) << 4
8485
}
8586

8687
// getVoltage does a one-shot sample and returns a millivolts reading.

0 commit comments

Comments
 (0)