I am trying to understand how any pin is set as an output by simple example of blink sketch.
in blink example sketch pinMode function is used as pinMode(LED_BUILTIN,OUTPUT);
further de-coupled pinMode() function i have found" void pinMode(uint8_t pin, uint8_t mode)" again further decoupled "digitalPinToBitMask(pin);" found" #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )"
then
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(0), /* 14, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
};
" my question is "digital_pin_to_bit_mask_PGM[]"is an array of 8 bit unsigned integer type and this array is stored in programe memory . array elements here should be integer type but looking into array all element starts"_BV()" which is not integer . as i have learned c,c++,preprocessor directive i dindnt found this type of array declaration.Please explain how it works like array and data type of array elements are changed?
Elements are uint8_t in the array. If you provide some other type of integral number in the array initialization then they are silently promoted (truncated) to the destination’s type
Here BV(x), is of type int which will be 2 bytes or 4 bytes depending on your arduino and the promotion takes the LSB so it does what’s expected.
as i have understood from your reply tha _BV(x) is preprocessor function defined as "#define _BV(bit) (1 << (bit))" here before compiler strats to compile _BV(x ) is replaced by (1<<(x)) and " (1<<(x))" is a integer so array elements type rule not violated.