Go Down

Topic: questions about Arduino.h code....Plz read (Read 438 times) previous topic - next topic

Hovic

Code: [Select]
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
#define analogInPinToBit(P) (P)
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )

the code above is out of the Arduino.h and these lines of code is where i have the the question.
  1. What is the (P)  mean in the code above and what is it reference too? ex. digitalPinToPort(P)  does it mean port?
  2. what does  digitalPinToPort(P),digitalPinToBitMask(P),digitalPinToTimer(P),analogInPinToBit(P) (P), portOutputRegister(P), portInputRegister(P),  and portModeRegister(P) do?

AWOL

P is simply "pin" or even "parameter".

They're all just mapping macros, to allow consistent Arduino pin numbering across various AVR ports, independent of processor.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

pYro_65

read up on c++ macros and defines

the '(p)' is a parameter for the macro, like a function parameter, but not the same.

These macros convert 'virtual' arduino pin numbers to actual avr ports registers and the respective pin bits inside the registers ( 8-bit register can represent 8 unique pins )

Or what AWOL said.

Hovic


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy