Is there a web page or pdf file somewhere that summarizes all the magical predefined "things" that you can use in sketches? Code like this appears all over the place in examples: TIFR1 = _BV(TOV1); or TCCR2B = _BV(WGM22) | _BV(CS20); Where are all these magical things listed? How do you discover these names?
Probably the best thing is to download the datasheet:
http://atmel.com/dyn/resources/prod_documents/8271S.pdf
Most of the names are identical to what is in the datasheet. And things like:
_BV(WGM22)
means "the WGM22 bit".
So something like this:
TCCR2B = _BV(WGM22) | _BV(CS20)
Means: in the TCCR2B register (read the datasheet to see what it does) set the WGM22 and CS20 bits.
Those are register names. TIFR1 = "Timer/Counter1 Interrupt Flag Register". TCCR2B = "Timer/Counter Control Register B"
Oh well, I was afraid I might have to plough through the datasheet. I was hoping for a nice summary web page somewhere :-). Thanks.
There may be a summary of the names somewhere but without the information in the datasheet of what bits do what the summary would not be of much use.
Some anyway:
http://www.nongnu.org/avr-libc/user-manual/globals.html
and if you didn't know about that then bookmark this as well:
http://www.nongnu.org/avr-libc/user-manual/modules.html
Consider downloading the ctags utility and an editor with ctags capability. What this allows you to do (typically) is to place the cursor on an identifier, hit a hotkey, and have the source file in which that identifier is defined pop up in an edit window.
It may take an hour to set up, but it's worlds faster than almost any other method of finding definitions. I think it'll be worth your time to investigate, install, and learn to use.
It's funny you should mention that Morris. I was playing with ctags yesterday. Although the one that comes with the Mac isn't very good. I got Exuberant Ctags from here:
Then I found that if you weren't careful doing a full recursive ctags got all the bootloaders and stuff. So what worked for me was something like:
cd # go home
ctags -R /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino
ctags -R -a /Applications/Arduino.app/Contents/Resources/Java/libraries
Your paths may vary.
The idea is to put a "tags" file in the home directory, consisting of the Arduino cores, and then append (-a) the libraries. Then using vi:
vi -t digitalWrite
In a split second, it opens "/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino/wiring_digital.c" and puts the cursor at the start of that function. Pretty handy. Then move the cursor over some sub-function, hit Ctrl+] and it opens the file containing that function. And so on.
I was introduced to ctags back in the 90's when I worked on my first really large system (the trading system at the Philadelphia Stock exchange) and became an instant fan.
Since I'm somewhat of a packrat, over the years I've stashed away nearly all of the code I've written - migrating source from paper tape -> cards -> 8"FD -> 5-1/4"FD -> 3-1/2"FD -> CD -> DVD -> FLASH and now have about half of it on my iMac to minimize the amount of time spent re-inventing old wheels. My TAGS file is about 44MB and the ctags capability makes instant access to everything possible. All I have to do is remember the name of the module, the name of a module that called the one I'm interested in, or (worst case) the name of any module in a system that incorporated the module.
I'm also using exuberant ctags, and it's working well for me.
@Morris - apart from firing up vim, is there another way of finding which file function X is in? (Also apart from simply editing the tags file, of course, and searching).
Before ctags there was grep.
In a terminal window, man grep
Warning!
You're approaching a very slippery slope which could lead to non-return from POSIX land
I'm familiar with grep, but it has some limitations. For example, doing a recursive directory search isn't trivial. Also looking up something like digitalWrite is going to lead to all the places is it used rather than where it is defined.
Yes, that's why ctags is so convenient. There are ways to unclutter grep results. For example you can search for "void digitalWrite(int" instead of just "digitalWrite" - and if you're comfortable with regex patterns, they can be used to enhance grep's search capability.
Sure, but it can get fiddly. For example, you may not know what type digitalWrite returns. Or what type arguments it takes.
I just wrote a little helper function that reads the tags file into a Lua table, and then displays them, filtered on what you type:
Then when you choose one it opens Crimson Editor for the relevant file, copies the chosen word to the clipboard, so you can search to find it inside that file. Now that should save a bit of time!
I like it!
The Atmel data sheets have a "Register summary" section, that is a list of all the register names and bit position names.
That's a start.
Rob
And the AVR-Libc pages for the GCC specific names.