I am getting started learning more about AVR ATMEGA programming.
Reading an article about the inner workings of Arduinos, I am learning how the shiftOut
method is structured. I am kind of familiar with bitwise operations so far, but I have an expression I do not understand yet:
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{
uint8_t i;
for (i = 0; i < 8; i++) {
if (bitOrder == LSBFIRST) {
PORTD |= !!(val & (HIGH << i));
} else {
PORTD |= !!(val & (HIGH << (7 - i)));
}
PORTB |= (HIGH << clockPin);
PORTB ^= (HIGH << clockPin);
}
}
The line PORTD |= !!(val & (HIGH << i));
is not 100% clear to me. I understand that i set the i-th bit High on PORTD but what das the !!
mean and val&(HIGH <<i))
I know this might sound basic, but can you please help me out?