Quick Question - Finding source of AnalogWrite in teensy source files

Status
Not open for further replies.

con_103

Member
I am trying to learn how the analog write function works in the source files but it seems I've come to a dead end.

This is with a Teensy 3.2 so I am looking in
Arduino/Teensy IDE/hardware/teensy/avr/cores/teensy3/pins_teensy.c

I found the analogWrite function,
but there is a function analogWriteDAC0 I can't seem to find its source.
Code:
void analogWrite(uint8_t pin, int val)
{
	uint32_t cval, max;

#if defined(__MK20DX256__)
	if (pin == A14) {
		uint8_t res = analog_write_res;
		if (res < 12) {
			val <<= 12 - res;
		} else if (res > 12) {
			val >>= res - 12;
		}
		[B]analogWriteDAC0(val);[/B]
		return;
	}

I use my IDE to find the declaration in core_pins.h
Code:
void analogWriteDAC0(int val);
But it just appears to be an empty function definition. I have tried searching through the other files to no avail. Is there something I am missing here?
I would love if someone could shed some light.

Thank you
 
It is in analog.c
See here: https://github.com/PaulStoffregen/c...f3951a1df44b05f0fb8c3fd/teensy3/analog.c#L522

You can find this easly with an good editor like npp (notepad++).
It can search for a string in all files in directory (and all its subdirectories)

Search / Find in Files - then specify the Directory!
That is GREAT to know Frank B! Also "Open Folder as Workspace" !

Installed NPP++ as spare editor - did not realize it had those features ( that SubLime text editor offer )
 
If you have a file open, and want to search within its (sub)directories, it's even easier - NPP uses the active directory as default.
You can search with a regex, too.
 
If you have a file open, and want to search within its (sub)directories, it's even easier - NPP uses the active directory as default.
You can search with a regex, too.

Very nice. Using Sublime as primary editor because it has all those things, nice to have them in NP++ too.
BTW: I posted about getting TSET to work from NP++ - though that was on old machine. Also I have some TSET 'fix' to upload - storing Main INO name for multi INO projects.
 
Agreed.
But grep on a commandline is pain compared with a editor which is open anyway.. I use it for Arduino, too :)
 
Hm. Where is this post? :)

Geez Frank ... it's on the forum ... see search :)

Here :: pjrc.com/threads/65230-Best-C-compiler-IDE-for-Windows-10

The addon was :: Install the NppExec { if it works as suggested to run TSET }

And as Frank notes - CMDLINE tools were fun - but when searching with SubLime ( or NPP++ ) the files and context are displayed and just click away from viewing or editing.

With a 'Project' Global search on Sublime can be : All folders/subfolders of Teensy/AVR and SKETCHBOOK and Examples ...
 
I am trying to learn how the analog write function works in the source files but it seems I've come to a dead end.

This is with a Teensy 3.2 so I am looking in Arduino/Teensy IDE/hardware/teensy/avr/cores/teensy3/pins_teensy.c

I found the analogWrite function, but there is a function analogWriteDAC0 I can't seem to find its source.

As an alternative to the traditional text searching tools like grep I would like to point out that these days IDEs are quite good in finding that kind of information. I added a (not yet complete) demonstration showing what can be done with vsCode based IDEs (e.g. PlatformIO, VisualTeensy, Arduino2 ?) to the VisualTeensy WIKI and used your question as an example. Basically it requires only two clicks and two F12 presses to have the definition of analogWriteDAC0 in your editor.

See here https://github.com/luni64/VisualTeensy/wiki/Developing-with-VSCode for the wiki entry and some videos (the second chapter shows how to quickly drill down in source file trees)
 
Searching by content is a useful operation in its own right, not just in the context of programming languages, a generic
tool for search is usually much easier to learn and use than learning a different search interface for each software package
you use! One of the principles of good design is "do one thing well"...
 
Status
Not open for further replies.
Back
Top