Go Down

Topic: summary of predefined names, routines, macros? (Read 1 time) previous topic - next topic

Claghorn

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?
http://home.comcast.net/~tomhorsley/hardware/arduino/arduino.html

Nick Gammon

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:

Code: [Select]
_BV(WGM22)

means "the WGM22 bit".

So something like this:

Code: [Select]
TCCR2B = _BV(WGM22) | _BV(CS20)

Means: in the TCCR2B register (read the datasheet to see what it does) set the WGM22 and CS20 bits.
http://www.gammon.com.au/electronics

johnwasser

Those are register names.  TIFR1 = "Timer/Counter1 Interrupt Flag Register". TCCR2B = "Timer/Counter Control Register B"

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Claghorn

Oh well, I was afraid I might have to plough through the datasheet. I was hoping for a nice summary web page somewhere :-). Thanks.
http://home.comcast.net/~tomhorsley/hardware/arduino/arduino.html

johnwasser

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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

GoForSmoke

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
I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Morris Dovey

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.
There's always a better way!

Nick Gammon

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:

http://ctags.sourceforge.net/

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:

Code: [Select]
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:

Code: [Select]
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.
http://www.gammon.com.au/electronics

Morris Dovey

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.
There's always a better way!

Nick Gammon

@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).
http://www.gammon.com.au/electronics

Morris Dovey

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   :smiley-mr-green:
There's always a better way!

Nick Gammon

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.
http://www.gammon.com.au/electronics

Morris Dovey

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.
There's always a better way!

Nick Gammon

#13
Mar 25, 2012, 11:46 pm Last Edit: Mar 26, 2012, 02:57 am by Nick Gammon Reason: 1
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!
http://www.gammon.com.au/electronics

Morris Dovey

There's always a better way!

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview