The input is P. The macro calls pgm_read_byte() with an argument digital_pin_to_timer_PGM + (P).
The digital_pin_to_timer_PGM is defined in hardware/arduino/variants/standard/pins_arduino.h(in case of Arduino Uno). It is an array shown below. As this array is declared as PROGMEM, it is placed on flash memory rather than SRAM.
constuint8_tPROGMEMdigital_pin_to_timer_PGM[]={NOT_ON_TIMER,/* 0 - port D */NOT_ON_TIMER,NOT_ON_TIMER,TIMER2B,NOT_ON_TIMER,TIMER0B,TIMER0A,NOT_ON_TIMER,NOT_ON_TIMER,/* 8 - port B */TIMER1A,TIMER1B,TIMER2A,NOT_ON_TIMER,NOT_ON_TIMER,NOT_ON_TIMER,NOT_ON_TIMER,/* 14 - port C */NOT_ON_TIMER,NOT_ON_TIMER,NOT_ON_TIMER,NOT_ON_TIMER,};
As the digital_pin_to_timer_PGM is an array, adding (P) to the digital_pin_to_timer_PGM means the (P+1)th element of the array. In C++ language, the element of array x[i] can be accessed by *(x + i). For example, if the P is 3, the fortth element(note that the elements begins with 0) of the array, that is TIMER2B, is returned.
The pgm_read_byte() is a macro to read a valiable maked as PROGMEM and is defined in hardware/tools/avr/avr/include/avr/pgmspace.h.
As a result digitalPinToTimer() returns the (P+1)th element of digital_pin_to_timer_PGM which is placed on the flash memory.
/*
Copyright (c) 2016 garretlab.
Added source code explanation by garretlab.
*//*
Arduino.h - Main include file for the Arduino SDK
Copyright (c) 2005-2013 Arduino Team. All right reserved.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/