Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 14 of 14

Thread: Quick Question - Finding source of AnalogWrite in teensy source files

  1. #1
    Junior Member
    Join Date
    Jun 2021
    Posts
    5

    Quick Question - Finding source of AnalogWrite in teensy source files

    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;
    		}
    		analogWriteDAC0(val);
    		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

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,056
    It is in analog.c
    See here: https://github.com/PaulStoffregen/co.../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)

  3. #3
    Junior Member
    Join Date
    Jun 2021
    Posts
    5
    Awesome thank you very much

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,869
    Quote Originally Posted by Frank B View Post
    It is in analog.c
    See here: https://github.com/PaulStoffregen/co.../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 )

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,056
    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.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,869
    Quote Originally Posted by Frank B View Post
    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.

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,056
    Hm. Where is this post?

  8. #8
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,180
    You can get standalone file content search tools, including versions of the original grep unix tool https://en.wikipedia.org/wiki/Grep
    No idea how anyone would cope without such a tool frankly!

  9. #9
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,056
    Agreed.
    But grep on a commandline is pain compared with a editor which is open anyway.. I use it for Arduino, too

  10. #10
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,869
    Quote Originally Posted by Frank B View Post
    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 ...

  11. #11
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,056
    Thx I'll look again..

  12. #12
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,594
    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/VisualTeen...ng-with-VSCode for the wiki entry and some videos (the second chapter shows how to quickly drill down in source file trees)

  13. #13
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,180
    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"...

  14. #14
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,869
    Quote Originally Posted by Frank B View Post
    Thx I'll look again..
    Just installed NPPexec here for NPP - updated on that linked thread - seems to work for 'manually' entered commands

    $PAID$ for Sublime Text v4 - does it all much better - but nice to have a usable alternative.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •