aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/machine_atsamd51.go
diff options
context:
space:
mode:
authorsago35 <[email protected]>2021-05-04 15:13:50 +0900
committerRon Evans <[email protected]>2021-05-05 06:51:09 +0200
commitbb509ec91dcc558752ad6768a2e26e0bc706fd71 (patch)
tree6acb91ccf9556c5be23a6bde50f2e9f8ad726d96 /src/machine/machine_atsamd51.go
parent944f0220602bb6a30af8f3b894499e51a69517ed (diff)
downloadtinygo-bb509ec91dcc558752ad6768a2e26e0bc706fd71.tar.gz
tinygo-bb509ec91dcc558752ad6768a2e26e0bc706fd71.zip
atsamd51, atsamd21: fix ADC.Get() value at 8bit and 10bit
Diffstat (limited to 'src/machine/machine_atsamd51.go')
-rw-r--r--src/machine/machine_atsamd51.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go
index a251f6704..0ce476ccc 100644
--- a/src/machine/machine_atsamd51.go
+++ b/src/machine/machine_atsamd51.go
@@ -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 {