I'm struggling with some stuff at the moment and the only explanation or example I find are written in C.As you know Arduino is not genuine C and I'd like to know where I can find information for instance how Arduino functions are written.

Let say, what an analogRead() do ?It has to do with some ADMUX and ADCSRA stuff I guess.

Now I've been playing Arduino for a while, I think I need to go deeper and make the link between Arduino and real C language working with port and so on.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either 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, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Modified 28 September 2010 by Mark Sproul

$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $*/

#include "wiring_private.h"#include "pins_arduino.h"

uint8_t analog_reference = DEFAULT;

void analogReference(uint8_t mode){// can't actually set the register here because the default setting// will connect AVCC and the AREF pin, which would cause a short if// there's something connected to AREF.analog_reference = mode;}

// ADSC is cleared when the conversion finisheswhile (bit_is_set(ADCSRA, ADSC));

// we have to read ADCL first; doing so locks both ADCL// and ADCH until ADCH is read. reading ADCL second would// cause the results of each conversion to be discarded,// as ADCL and ADCH would be locked when it completed.low = ADCL;high = ADCH;#else// we dont have an ADC, return 0low = 0;high = 0;#endif

// combine the two bytesreturn (high << 8) | low;}

// Right now, PWM output only works on the pins with// hardware support. These are defined in the appropriate// pins_*.c file. For the rest of the pins, we default// to digital output.void analogWrite(uint8_t pin, int val){// We need to make sure the PWM output is enabled for those pins// that support it, as we turn it off when digitally reading or// writing with them. Also, make sure the pin is in output mode// for consistenty with Wiring, which doesn't require a pinMode// call for the analog output pins.pinMode(pin, OUTPUT);if (val == 0){digitalWrite(pin, LOW);}else if (val == 255){digitalWrite(pin, HIGH);}else{switch(digitalPinToTimer(pin)){// XXX fix needed for atmega8#if defined(TCCR0) && defined(COM00) && !defined(__AVR_ATmega8__)case TIMER0A:// connect pwm to pin on timer 0sbi(TCCR0, COM00);OCR0 = val; // set pwm dutybreak;#endif

The "housekeeping nonsense" is all the junk you need in a "regular" C/C++ program such as a function called main(), the need to declare function prototypes, lots of #includes, .h files etc etc etc etc.

No doubt it was all designed to ensure that the faint-hearted drop out so there is a limited supply of C programmers on the market in order to keep salaries up.