Skip to content

Commit 431f3ea

Browse files
committed
[sam] preliminary update for analog
1 parent 650d2e9 commit 431f3ea

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

hardware/arduino/sam/cores/sam/wiring_analog.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,47 @@ uint32_t analogRead(uint32_t ulPin)
107107
}
108108
#endif
109109

110+
#if defined __SAM3X8E__
111+
switch ( g_APinDescription[ulPin].ulAnalogChannel )
112+
{
113+
// Handling ADC 10 bits channels
114+
case ADC0 :
115+
case ADC1 :
116+
case ADC2 :
117+
case ADC3 :
118+
case ADC4 :
119+
case ADC5 :
120+
case ADC6 :
121+
case ADC7 :
122+
case ADC8 :
123+
case ADC9 :
124+
case ADC10 :
125+
case ADC11 : // Enable the corresponding channel
126+
adc_enable_channel( ADC, ulChannel );
127+
128+
// Start the ADC
129+
adc_start( ADC );
130+
131+
// Wait for end of conversion
132+
while ((adc_get_status(ADC) & (1<<ulChannel)) == 0);
133+
134+
// Read the value
135+
ulValue=adc_get_value( ADC, ulChannel );
136+
137+
// Disable the corresponding channel
138+
adc_disable_channel( ADC, ulChannel );
139+
140+
// Stop the ADC
141+
// adc_stop( ADC ) ; // never do adc_stop() else we have to reconfigure the ADC each time
142+
break;
143+
144+
// Compiler could yell because we don't handle DAC pins
145+
default :
146+
ulValue=0;
147+
break;
148+
}
149+
#endif
150+
110151
return ulValue;
111152
}
112153

0 commit comments

Comments
 (0)