PlatformIO Community

Using ETL library doesn't work

I created a new project for Teensy 4.1 and installed/added the " Embedded Template Library" via library browser. When I try to import any header from the library in main.cpp, I get a error that the header can’t be found.

Bildschirmfoto 2020-12-18 um 09.59.44

My platformio.ini looks like that:

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
lib_deps = etlcpp/Embedded Template Library@^19.3.5

It’s my first time using PlatformIO, so maybe I’m doing something obvious wrong.

Here is my tiny test project: https://www.dropbox.com/s/gy9z82zt4m0jdac/ETLTestProject.zip?dl=0

Thanks in advance :slight_smile:

First of all: Why. The C++ standard template library works on the Teensy thanks to using the arm-none-eabi-gcc/g++ compiler (and not a e.g. a handycapped AVR compiler). Code like this

#include <Arduino.h>
#include <vector>

std::vector<uint8_t> myVec = {1,2,3};

void setup() {
  Serial.println("Firmware Start!");
  for (uint8_t elem : myVec) {
    Serial.println(String(elem));
  }
}

void loop() { }

works.

Second of all: According to https://github.com/ETLCPP/etl/issues/318#issuecomment-745524599 this is a known issue of the library. Include paths have to prefixed with etl/. This works.

#include <Arduino.h>

#undef min
#undef max
#include <etl/list.h>
#include <etl/container.h>


void setup()
{
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

void iterate(const etl::ilist<int>& delays)
{
    etl::ilist<int>::const_iterator itr;

    // Iterate through the list.
    itr = delays.begin();

    while (itr != delays.end())
    {
      digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(100);               // wait
      digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
      delay(*itr++);            // wait
    }
}

void loop()
{
  int delay_times1[] = { 900, 800, 700, 600, 500, 400, 300, 200, 100 };
  int delay_times2[] = { 400, 300, 200, 100 };

  // Fill the first delay list, then reverse it.
  // Notice how we don't have to know the size of the array!
  const size_t size1 = sizeof(etl::array_size(delay_times1));
  etl::list<int, size1> delays1(etl::begin(delay_times1), etl::end(delay_times1));
  delays1.reverse();

  // Fill the second delay list,
  const size_t size2 = sizeof(etl::array_size(delay_times2));
  etl::list<int, size2> delays2(etl::begin(delay_times2), etl::end(delay_times2));

  while (true)
  {
    iterate(delays1);
    iterate(delays2);
  }
}

with the same platformio.ini that you’ve posted.

1 Like

It works indeed. Thanks for the help :slight_smile: