mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-05 13:16:13 +03:00
Fix syntax error on wiring_analog
This commit is contained in:
@@ -14,31 +14,32 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#include "wiring_private.h"
|
//#include "wiring_private.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
#include "variant.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
eAnalogReference analog_reference = AR_DEFAULT;
|
||||||
|
|
||||||
eAnalogReference analog_reference = AR_DEFAULT ;
|
void analogReference(eAnalogReference ulMode) {
|
||||||
|
analog_reference = ulMode;
|
||||||
void analogReference( eAnalogReference ulMode )
|
|
||||||
{
|
|
||||||
analog_reference = ulMode ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t analogRead( uint32_t ulPin )
|
uint32_t analogRead(uint32_t ulPin) {
|
||||||
{
|
uint32_t ulValue = 0;
|
||||||
uint32_t ulValue=0 ;
|
uint32_t ulChannel;
|
||||||
uint32_t ulChannel ;
|
|
||||||
|
|
||||||
ulChannel=g_APinDescription[ulPin].ulAnalogChannel ;
|
if (ulPin < A0)
|
||||||
|
ulPin += A0;
|
||||||
|
|
||||||
#if defined SAM3U4E
|
ulChannel = g_APinDescription[ulPin].ulAnalogChannel;
|
||||||
|
|
||||||
|
#if defined __SAM3U4E__
|
||||||
switch ( ulChannel )
|
switch ( ulChannel )
|
||||||
{
|
{
|
||||||
// Handling ADC 10 bits channels
|
// Handling ADC 10 bits channels
|
||||||
@@ -51,23 +52,23 @@ uint32_t analogRead( uint32_t ulPin )
|
|||||||
case ADC6 :
|
case ADC6 :
|
||||||
case ADC7 :
|
case ADC7 :
|
||||||
// Enable the corresponding channel
|
// Enable the corresponding channel
|
||||||
adc_enable_channel( ADC, ulChannel ) ;
|
adc_enable_channel( ADC, ulChannel );
|
||||||
|
|
||||||
// Start the ADC
|
// Start the ADC
|
||||||
adc_start( ADC ) ;
|
adc_start( ADC );
|
||||||
|
|
||||||
// Wait for end of conversion
|
// Wait for end of conversion
|
||||||
while ( adc_get_status( ADC ) & (1<<ulChannel) ) == 0 ) ;
|
while ((adc_get_status(ADC) & (1<<ulChannel)) == 0);
|
||||||
|
|
||||||
// Read the value
|
// Read the value
|
||||||
ulValue=adc_get_value( ADC, ulChannel ) ;
|
ulValue=adc_get_value( ADC, ulChannel );
|
||||||
|
|
||||||
// Disable the corresponding channel
|
// Disable the corresponding channel
|
||||||
adc_disable_channel( ADC, ulChannel ) ;
|
adc_disable_channel( ADC, ulChannel );
|
||||||
|
|
||||||
// Stop the ADC
|
// Stop the ADC
|
||||||
// adc_stop( ADC ) ; // never do adc_stop() else we have to reconfigure the ADC each time
|
// adc_stop( ADC ) ; // never do adc_stop() else we have to reconfigure the ADC each time
|
||||||
break ;
|
break;
|
||||||
|
|
||||||
// Handling ADC 12 bits channels
|
// Handling ADC 12 bits channels
|
||||||
case ADC8 :
|
case ADC8 :
|
||||||
@@ -79,77 +80,55 @@ uint32_t analogRead( uint32_t ulPin )
|
|||||||
case ADC14 :
|
case ADC14 :
|
||||||
case ADC15 :
|
case ADC15 :
|
||||||
// Enable the corresponding channel
|
// Enable the corresponding channel
|
||||||
adc12_enable_channel( ADC12B, ulChannel-ADC8 ) ;
|
adc12_enable_channel( ADC12B, ulChannel-ADC8 );
|
||||||
|
|
||||||
// Start the ADC12B
|
// Start the ADC12B
|
||||||
adc12_start( ADC12B ) ;
|
adc12_start( ADC12B );
|
||||||
|
|
||||||
// Wait for end of conversion
|
// Wait for end of conversion
|
||||||
while ( adc12_get_status( ADC12B ) & (1<<(ulChannel-ADC8)) ) == 0 ) ;
|
while ((adc12_get_status(ADC12B) & (1<<(ulChannel-ADC8))) == 0);
|
||||||
|
|
||||||
// Read the value
|
// Read the value
|
||||||
ulValue=adc12_get_value( ADC12B, ulChannel-ADC8 ) ;
|
ulValue=adc12_get_value( ADC12B, ulChannel-ADC8 );
|
||||||
|
|
||||||
// Stop the ADC12B
|
// Stop the ADC12B
|
||||||
// adc12_stop( ADC12B ) ; // never do adc12_stop() else we have to reconfigure the ADC12B each time
|
// adc12_stop( ADC12B ) ; // never do adc12_stop() else we have to reconfigure the ADC12B each time
|
||||||
|
|
||||||
// Disable the corresponding channel
|
// Disable the corresponding channel
|
||||||
adc12_disable_channel( ADC12B, ulChannel-ADC8 ) ;
|
adc12_disable_channel( ADC12B, ulChannel-ADC8 );
|
||||||
break ;
|
break;
|
||||||
|
|
||||||
// Compiler could yell because we don't handle DAC pins
|
// Compiler could yell because we don't handle DAC pins
|
||||||
default :
|
default :
|
||||||
ulValue=0 ;
|
ulValue=0;
|
||||||
break ;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ulValue ;
|
return ulValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right now, PWM output only works on the pins with
|
// Right now, PWM output only works on the pins with
|
||||||
// hardware support. These are defined in the appropriate
|
// hardware support. These are defined in the appropriate
|
||||||
// pins_*.c file. For the rest of the pins, we default
|
// pins_*.c file. For the rest of the pins, we default
|
||||||
// to digital output.
|
// to digital output.
|
||||||
void analogWrite( uint32_t ulPin, uint32_t ulValue )
|
void analogWrite(uint32_t ulPin, uint32_t ulValue) {
|
||||||
{
|
pinMode(ulPin, OUTPUT);
|
||||||
pinMode( ulPin, OUTPUT ) ;
|
|
||||||
|
|
||||||
if ( ulValue == 0 )
|
if (ulValue == 0) {
|
||||||
{
|
digitalWrite(ulPin, LOW);
|
||||||
digitalWrite( ulPin, LOW ) ;
|
} else if (ulValue == 255) {
|
||||||
}
|
digitalWrite(ulPin, HIGH);
|
||||||
else
|
} else if ((g_APinDescription[ulPin].ulPinAttribute && PIN_ATTR_PWM)
|
||||||
{
|
== PIN_ATTR_PWM) {
|
||||||
if ( ulValue == 255 )
|
|
||||||
{
|
|
||||||
digitalWrite( ulPin, HIGH ) ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( (g_APinDescription[ulPin].ulPinAttribute && PIN_ATTR_PWM) == PIN_ATTR_PWM )
|
|
||||||
{
|
|
||||||
// Setup PWM for this pin
|
// Setup PWM for this pin
|
||||||
}
|
} else if ((g_APinDescription[ulPin].ulPinAttribute && PIN_ATTR_TIMER)
|
||||||
else
|
== PIN_ATTR_TIMER) {
|
||||||
{
|
|
||||||
if ( (g_APinDescription[ulPin].ulPinAttribute && PIN_ATTR_TIMER) == PIN_ATTR_TIMER )
|
|
||||||
{
|
|
||||||
// Setup Timer for this pin
|
// Setup Timer for this pin
|
||||||
}
|
} else if (ulValue < 128) {
|
||||||
else
|
digitalWrite(ulPin, LOW);
|
||||||
{
|
} else {
|
||||||
if ( ulValue < 128 )
|
digitalWrite(ulPin, HIGH);
|
||||||
{
|
|
||||||
digitalWrite( ulPin, LOW ) ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
digitalWrite( ulPin, HIGH ) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user