It was enabled, but commented out, now it works! Thanks! =D
How can it be enabled if it is commented out?
We all understand what he meant.
Yeah, I was just being a pedant. This is a geek forum, right?
Whew, that's a lot of questions! For starters, check out Bitwise operations in C on Wikipedia.
I'm not familiar with this part of TMK's codebase, so my help will have to stop here.
Haha I was linking to that myself, and got the message "Warning - while you were typing a new reply has been posted. You may wish to review your post."
I don't know if that will solve sean4star's problems, but it's a good start...
1. I don't understand what the difference is between |= and &= or what the ~ is doing. Sorry, I'm a programming noob...
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
DDRD |= (1<<6);
PORTD |= (1<<6);
} else {
DDRD |= (1<<6);
PORTD &= ~(1<<6);
}
Well I'm no expert either, but << is a bitwise left shift, so (1<<6) means take a binary 1 and shift it to the left 6 places, ie binary 1000000.
|= is a compound operator, basically a shortcut. | means OR. "DDRD |= (1<<6);" is the same as "DDRD = (DDRD | (1<<6));", which OR's each bit of DDRD with the corresponding bit of "(1<<6)".
DDRD is the direction for the pins on Port D, so "DDRD |= (1<<6);" makes sure that pin 6 on Port D is set as an output, then "PORTD |= (1<<6);" actually sets pin 6 on port D high, which lights the LED connected to pin 6 on port D.
~ means invert, so "PORTD &= ~(1<<6);" sets pin 6 on port D low, which will turn off the LED.
I'm not super confident with bitwise stuff myself, I mostly play around with java.