Skip to content

Commit 33e7cd0

Browse files
committed
chore(review): honor
Signed-off-by: Paul Schroeder <[email protected]>
1 parent de4ef7a commit 33e7cd0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/machine/machine_nrf52xxx.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func InitADC() {
2525
// SampleTime will be ceiled to 3(default), 5, 10, 15, 20 or 40(max) µS respectively
2626
// Samples can be 1(default), 2, 4, 8, 16, 32, 64, 128, 256 samples
2727
func (a *ADC) Configure(config ADCConfig) {
28-
2928
var configVal uint32 = nrf.SAADC_CH_CONFIG_RESP_Bypass<<nrf.SAADC_CH_CONFIG_RESP_Pos |
3029
nrf.SAADC_CH_CONFIG_RESP_Bypass<<nrf.SAADC_CH_CONFIG_RESN_Pos |
3130
nrf.SAADC_CH_CONFIG_REFSEL_Internal<<nrf.SAADC_CH_CONFIG_REFSEL_Pos |
@@ -169,7 +168,22 @@ func (a *ADC) Get() uint16 {
169168
}
170169
nrf.SAADC.EVENTS_STOPPED.Set(0)
171170

172-
return rawValue.Get()
171+
// convert to 16 bit resolution/value
172+
var resolutionAdjustment uint8
173+
switch nrf.SAADC.RESOLUTION.Get() {
174+
case nrf.SAADC_RESOLUTION_VAL_8bit:
175+
resolutionAdjustment = 8
176+
case nrf.SAADC_RESOLUTION_VAL_10bit:
177+
resolutionAdjustment = 6
178+
case nrf.SAADC_RESOLUTION_VAL_12bit:
179+
resolutionAdjustment = 4
180+
case nrf.SAADC_RESOLUTION_VAL_14bit:
181+
resolutionAdjustment = 2
182+
default:
183+
resolutionAdjustment = 4 // 12bit
184+
}
185+
186+
return rawValue.Get() << resolutionAdjustment
173187
}
174188

175189
// SPI on the NRF.

0 commit comments

Comments
 (0)