File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ extern "C" {
25
25
#endif
26
26
27
27
static int _readResolution = 10 ;
28
- static int _writeResolution = 10 ;
28
+ static int _ADCResolution = 10 ;
29
+ static int _writeResolution = 8 ;
29
30
30
31
// Wait for synchronization of registers between the clock domains
31
32
static __inline__ void syncADC () __attribute__((always_inline , unused ));
@@ -43,20 +44,23 @@ static void syncDAC() {
43
44
44
45
void analogReadResolution ( int res )
45
46
{
47
+ _readResolution = res ;
46
48
syncADC ();
47
- switch ( res )
49
+ if ( res > 10 )
48
50
{
49
- case 12 :
50
- ADC -> CTRLB .bit .RESSEL = ADC_CTRLB_RESSEL_12BIT_Val ;
51
- break ;
52
- case 8 :
53
- ADC -> CTRLB .bit .RESSEL = ADC_CTRLB_RESSEL_8BIT_Val ;
54
- break ;
55
- default :
56
- ADC -> CTRLB .bit .RESSEL = ADC_CTRLB_RESSEL_10BIT_Val ;
57
- break ;
51
+ ADC -> CTRLB .bit .RESSEL = ADC_CTRLB_RESSEL_12BIT_Val ;
52
+ _ADCResolution = 12 ;
53
+ }
54
+ else if (res > 8 )
55
+ {
56
+ ADC -> CTRLB .bit .RESSEL = ADC_CTRLB_RESSEL_10BIT_Val ;
57
+ _ADCResolution = 10 ;
58
+ }
59
+ else
60
+ {
61
+ ADC -> CTRLB .bit .RESSEL = ADC_CTRLB_RESSEL_8BIT_Val ;
62
+ _ADCResolution = 8 ;
58
63
}
59
- _readResolution = res ;
60
64
}
61
65
62
66
void analogWriteResolution ( int res )
@@ -179,7 +183,7 @@ uint32_t analogRead( uint32_t ulPin )
179
183
ADC -> CTRLA .bit .ENABLE = 0x00 ; // Disable ADC
180
184
syncADC ();
181
185
182
- return valueRead ;
186
+ return mapResolution ( valueRead , _ADCResolution , _readResolution ) ;
183
187
}
184
188
185
189
You can’t perform that action at this time.
0 commit comments