mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-02 13:24:12 +01:00
Fix syntax error on wiring_analog
This commit is contained in:
parent
f77fcec4e9
commit
1c9738e3db
@ -1,156 +1,135 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2011 Arduino. All right reserved.
|
Copyright (c) 2011 Arduino. All right reserved.
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
License as published by the Free Software Foundation; either
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
See the GNU Lesser General Public License for more details.
|
See the GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
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;
|
||||||
switch ( ulChannel )
|
|
||||||
{
|
|
||||||
// Handling ADC 10 bits channels
|
|
||||||
case ADC0 :
|
|
||||||
case ADC1 :
|
|
||||||
case ADC2 :
|
|
||||||
case ADC3 :
|
|
||||||
case ADC4 :
|
|
||||||
case ADC5 :
|
|
||||||
case ADC6 :
|
|
||||||
case ADC7 :
|
|
||||||
// Enable the corresponding channel
|
|
||||||
adc_enable_channel( ADC, ulChannel ) ;
|
|
||||||
|
|
||||||
// Start the ADC
|
#if defined __SAM3U4E__
|
||||||
adc_start( ADC ) ;
|
switch ( ulChannel )
|
||||||
|
{
|
||||||
|
// Handling ADC 10 bits channels
|
||||||
|
case ADC0 :
|
||||||
|
case ADC1 :
|
||||||
|
case ADC2 :
|
||||||
|
case ADC3 :
|
||||||
|
case ADC4 :
|
||||||
|
case ADC5 :
|
||||||
|
case ADC6 :
|
||||||
|
case ADC7 :
|
||||||
|
// Enable the corresponding channel
|
||||||
|
adc_enable_channel( ADC, ulChannel );
|
||||||
|
|
||||||
// Wait for end of conversion
|
// Start the ADC
|
||||||
while ( adc_get_status( ADC ) & (1<<ulChannel) ) == 0 ) ;
|
adc_start( ADC );
|
||||||
|
|
||||||
// Read the value
|
// Wait for end of conversion
|
||||||
ulValue=adc_get_value( ADC, ulChannel ) ;
|
while ((adc_get_status(ADC) & (1<<ulChannel)) == 0);
|
||||||
|
|
||||||
// Disable the corresponding channel
|
// Read the value
|
||||||
adc_disable_channel( ADC, ulChannel ) ;
|
ulValue=adc_get_value( ADC, ulChannel );
|
||||||
|
|
||||||
// Stop the ADC
|
// Disable the corresponding channel
|
||||||
// adc_stop( ADC ) ; // never do adc_stop() else we have to reconfigure the ADC each time
|
adc_disable_channel( ADC, ulChannel );
|
||||||
break ;
|
|
||||||
|
|
||||||
// Handling ADC 12 bits channels
|
// Stop the ADC
|
||||||
case ADC8 :
|
// adc_stop( ADC ) ; // never do adc_stop() else we have to reconfigure the ADC each time
|
||||||
case ADC9 :
|
break;
|
||||||
case ADC10 :
|
|
||||||
case ADC11 :
|
|
||||||
case ADC12 :
|
|
||||||
case ADC13 :
|
|
||||||
case ADC14 :
|
|
||||||
case ADC15 :
|
|
||||||
// Enable the corresponding channel
|
|
||||||
adc12_enable_channel( ADC12B, ulChannel-ADC8 ) ;
|
|
||||||
|
|
||||||
// Start the ADC12B
|
// Handling ADC 12 bits channels
|
||||||
adc12_start( ADC12B ) ;
|
case ADC8 :
|
||||||
|
case ADC9 :
|
||||||
|
case ADC10 :
|
||||||
|
case ADC11 :
|
||||||
|
case ADC12 :
|
||||||
|
case ADC13 :
|
||||||
|
case ADC14 :
|
||||||
|
case ADC15 :
|
||||||
|
// Enable the corresponding channel
|
||||||
|
adc12_enable_channel( ADC12B, ulChannel-ADC8 );
|
||||||
|
|
||||||
// Wait for end of conversion
|
// Start the ADC12B
|
||||||
while ( adc12_get_status( ADC12B ) & (1<<(ulChannel-ADC8)) ) == 0 ) ;
|
adc12_start( ADC12B );
|
||||||
|
|
||||||
// Read the value
|
// Wait for end of conversion
|
||||||
ulValue=adc12_get_value( ADC12B, ulChannel-ADC8 ) ;
|
while ((adc12_get_status(ADC12B) & (1<<(ulChannel-ADC8))) == 0);
|
||||||
|
|
||||||
// Stop the ADC12B
|
// Read the value
|
||||||
// adc12_stop( ADC12B ) ; // never do adc12_stop() else we have to reconfigure the ADC12B each time
|
ulValue=adc12_get_value( ADC12B, ulChannel-ADC8 );
|
||||||
|
|
||||||
// Disable the corresponding channel
|
// Stop the ADC12B
|
||||||
adc12_disable_channel( ADC12B, ulChannel-ADC8 ) ;
|
// adc12_stop( ADC12B ) ; // never do adc12_stop() else we have to reconfigure the ADC12B each time
|
||||||
break ;
|
|
||||||
|
|
||||||
// Compiler could yell because we don't handle DAC pins
|
// Disable the corresponding channel
|
||||||
default :
|
adc12_disable_channel( ADC12B, ulChannel-ADC8 );
|
||||||
ulValue=0 ;
|
break;
|
||||||
break ;
|
|
||||||
}
|
// Compiler could yell because we don't handle DAC pins
|
||||||
|
default :
|
||||||
|
ulValue=0;
|
||||||
|
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 if ((g_APinDescription[ulPin].ulPinAttribute && PIN_ATTR_PWM)
|
||||||
|
== PIN_ATTR_PWM) {
|
||||||
|
// Setup PWM for this pin
|
||||||
|
} else if ((g_APinDescription[ulPin].ulPinAttribute && PIN_ATTR_TIMER)
|
||||||
|
== PIN_ATTR_TIMER) {
|
||||||
|
// Setup Timer for this pin
|
||||||
|
} else if (ulValue < 128) {
|
||||||
|
digitalWrite(ulPin, LOW);
|
||||||
|
} else {
|
||||||
|
digitalWrite(ulPin, HIGH);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( ulValue == 255 )
|
|
||||||
{
|
|
||||||
digitalWrite( ulPin, HIGH ) ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( (g_APinDescription[ulPin].ulPinAttribute && PIN_ATTR_PWM) == PIN_ATTR_PWM )
|
|
||||||
{
|
|
||||||
// Setup PWM for this pin
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( (g_APinDescription[ulPin].ulPinAttribute && PIN_ATTR_TIMER) == PIN_ATTR_TIMER )
|
|
||||||
{
|
|
||||||
// Setup Timer for this pin
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( ulValue < 128 )
|
|
||||||
{
|
|
||||||
digitalWrite( ulPin, LOW ) ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
digitalWrite( ulPin, HIGH ) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
Reference in New Issue
Block a user