Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/machine/machine_rp2_adc.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ func (c ADCChannel) Configure(config ADCConfig) error {
func (c ADCChannel) getOnce() uint16 {
// Make it safe to sample multiple ADC channels in separate go routines.
adcLock.Lock()
rp.ADC.CS.ReplaceBits(uint32(c), 0b111, rp.ADC_CS_AINSEL_Pos)
rp.ADC.CS.ReplaceBits(uint32(c)<<rp.ADC_CS_AINSEL_Pos, rp.ADC_CS_AINSEL_Msk, 0)
rp.ADC.CS.SetBits(rp.ADC_CS_START_ONCE)

waitForReady()
v := rp.ADC.RESULT.Get()
adcLock.Unlock()

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

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