atsamd51, atsamd21: fix ADC.Get() value at 8bit and 10bit

This commit is contained in:
sago35
2021-05-04 15:13:50 +09:00
committed by Ron Evans
parent 944f022060
commit bb509ec91d
2 changed files with 24 additions and 2 deletions
+12 -1
View File
@@ -433,7 +433,18 @@ func (a ADC) Get() uint16 {
sam.ADC.CTRLA.ClearBits(sam.ADC_CTRLA_ENABLE)
waitADCSync()
return uint16(val) << 4 // scales from 12 to 16-bit result
// scales to 16-bit result
switch (sam.ADC.CTRLB.Get() & sam.ADC_CTRLB_RESSEL_Msk) >> sam.ADC_CTRLB_RESSEL_Pos {
case sam.ADC_CTRLB_RESSEL_8BIT:
val = val << 8
case sam.ADC_CTRLB_RESSEL_10BIT:
val = val << 6
case sam.ADC_CTRLB_RESSEL_16BIT:
val = val << 4
case sam.ADC_CTRLB_RESSEL_12BIT:
val = val << 4
}
return val
}
func (a ADC) getADCChannel() uint8 {
+12 -1
View File
@@ -863,7 +863,18 @@ func (a ADC) Get() uint16 {
for bus.SYNCBUSY.HasBits(sam.ADC_SYNCBUSY_ENABLE) {
}
return uint16(val) << 4 // scales from 12 to 16-bit result
// scales to 16-bit result
switch (bus.CTRLB.Get() & sam.ADC_CTRLB_RESSEL_Msk) >> sam.ADC_CTRLB_RESSEL_Pos {
case sam.ADC_CTRLB_RESSEL_8BIT:
val = val << 8
case sam.ADC_CTRLB_RESSEL_10BIT:
val = val << 6
case sam.ADC_CTRLB_RESSEL_16BIT:
val = val << 4
case sam.ADC_CTRLB_RESSEL_12BIT:
val = val << 4
}
return val
}
func (a ADC) getADCBus() *sam.ADC_Type {