Add a luni library to VScode

Status
Not open for further replies.
I am newbie on teensy and have not much idea in makefiles or json.
I have seen several libraries at gitub for the teensy board.

What is the way to upload it to the project?

I tried to copy the directory of the TeensyTimerTool library to D:\Arduino\hardware\teensy\avr\libraries and used the Visualteensy to generate the project, then the new library appeared named "TeensyTimerTool-master"
To test it I copied the example "UsingChronoDurations2.ino" to the main and appeared an error in the last line:

Code:
void setup()
{
    while (!Serial) {} // wait for PC to connect the virtual serial port

    for (OneShotTimer& t : timer) // for the sake of simplicity, attach the same isr to all timers in array
    {
        t.begin(isr);
    }

    timer[0].trigger(10ms);                                  // 10 ms
    timer[1].trigger(0.5s + 10ms);                           // 510 ms
    timer[2].trigger(2.5 * 0.3s + 20'000us / 2);             // 760 ms
    timer[3].trigger(milliseconds(50) + microseconds(5000)); // 55ms
    t_0 = millis();

    pt1.begin([]{digitalToggleFast(LED_BUILTIN)})
}

The error is:
Code:
> Executing task: D:/VisualTeensy_v0_9_9_2/make.exe all -j -Otarget <

USER [CPP] main.cpp 
src/main.cpp: In lambda function:
src/main.cpp:29:48: error: expected ';' before '}' token
     pt1.begin([]{digitalToggleFast(LED_BUILTIN)})
                                                ^
src/main.cpp: In function 'void setup()':
src/main.cpp:29:49: error: no matching function for call to 'TeensyTimerTool::PeriodicTimer::begin(setup()::<lambda()>)'
     pt1.begin([]{digitalToggleFast(LED_BUILTIN)})
                                                 ^
In file included from lib/TeensyTimerTool-master/src/timer.h:4:0,
                 from lib/TeensyTimerTool-master/src/TeensyTimerTool.h:4,
                 from src/main.cpp:2:
lib/TeensyTimerTool-master/src/baseTimer.h:57:15: note: candidate: template<class T> TeensyTimerTool::errorCode TeensyTimerTool::BaseTimer::begin(TeensyTimerTool::callback_t, T, bool)
     errorCode BaseTimer::begin(callback_t callback, T p, bool start)
               ^
lib/TeensyTimerTool-master/src/baseTimer.h:57:15: note:   template argument deduction/substitution failed:
src/main.cpp:29:49: note:   candidate expects 3 arguments, 1 provided
     pt1.begin([]{digitalToggleFast(LED_BUILTIN)})
                                                 ^
make: *** [makefile:230: .vsteensy/build/src/main.o] Error 1
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command D:/VisualTeensy_v0_9_9_2/make.exe all -j -Otarget" terminated with exit code: 1.

The question is if the implementation of the library is correct and what is the right method to include a lib
 
You are right, there is a bug in this example. Here a fix:

Code:
#include "Arduino.h"
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;

OneShotTimer timer[]{TCK, TCK, TCK, TCK}; // 4 one-shot-timers
PeriodicTimer pt1;                        // 1 periodic timer
unsigned t_0;                             // start time

void isr()
{
    Serial.printf("called @: %u ms\n", millis() - t_0);
}

void setup()
{
    pinMode(LED_BUILTIN, OUTPUT);  // <=============  was missing !!!
    
    while (!Serial) {} // wait for PC to connect the virtual serial port

    for (OneShotTimer& t : timer) // for the sake of simplicity, attach the same isr to all timers in array
    {
        t.begin(isr);
    }

    timer[0].trigger(10ms);                                  // 10 ms
    timer[1].trigger(0.5s + 10ms);                           // 510 ms
    timer[2].trigger(2.5 * 0.3s + 20'000us / 2);             // 760 ms
    timer[3].trigger(milliseconds(50) + microseconds(5000)); // 55ms
    t_0 = millis();

    pt1.begin([] { digitalToggleFast(LED_BUILTIN); }, 10_Hz);  // <=========== two semicolons and the period/frequency were missing
}

void loop(){
}

I'll fix the code in the library later today.

what is the right method to include a lib

Usually, there is no need to manually copy libs. In any case you should not copy anything to the Arduino folder, this will be gone with the next Arduino update. To install a library you need to open the library tab and select one of the available repositories. You'll find the TeensyTimerTool in the Arduino repository:

Screenshot 2021-03-27 061618.jpg

Either scroll down to the library you need or type into the search field to narrow down the list.

Screenshot 2021-03-27 063219.jpg

If you don't find the library you are searching for you can try updating the list with the Get-Index button (this will take some time).

Don't forget to drag the lib into the list on the left side and do a file|save to update the project.

Hope that helps
 
Great!, thank you, that is a great micro with your great libraries
It would be interesting have something like delay_ns() to have a delay of nanoseconds in a teensy 4x board
 
t would be interesting have something like delay_ns() to have a delay of nanoseconds in a teensy 4x board

Code:
delayNanoseconds(500)

Should delay for about 500ns.
 
Status
Not open for further replies.
Back
Top