Teensyduino 1.59 Beta #3

Should IntervalTimer.h have two versions of update()?

IntervalTimer.h now has just one version of begin() that uses "template <typename period_t" and handles both integer and float period arguments, but there are still two versions of update(). One takes unsigned int and the other uses the template approach. Is this correct? Can update(unsigned int) be removed?

EDIT: I tested by commenting out the update(unsigned int), and the template version seems to work correctly for both integer and float arguments.

Code:
	template <typename period_t>
	bool begin(callback_t funct, period_t period) {
		uint32_t cycles = cyclesFromPeriod(period);
		return cycles >= 17 ? beginCycles(funct, cycles) : false;
	}

	// Change the timer's interval.  The current interval is completed
	// as previously configured, and then the next interval begins with
	// with this new setting.
	void update(unsigned int microseconds) {
		if (microseconds == 0 || microseconds > MAX_PERIOD) return;
		uint32_t cycles = (24000000 / 1000000) * microseconds - 1;
		if (cycles < 17) return;
		if (channel) channel->LDVAL = cycles;
	}

	// Change the timer's interval.  The current interval is completed
	// as previously configured, and then the next interval begins with
	// with this new setting.
	template <typename period_t>
	void update(period_t period){
		uint32_t cycles = cyclesFromPeriod(period);
		if (cycles < 17) return;
		if (channel) channel->LDVAL = cycles;
	}
 
Did the F() macro get broken for Teensy4 somewhere along the line?
According to https://www.pjrc.com/store/teensy41.html "F()" is meant to be able to place strings in PROGMEM (Flash). But because of this definition in WString.h:
Code:
// Brian Cook's "no overhead" Flash String type (message on Dec 14, 2010)
// modified by Mikal Hart for his FlashString library
class __FlashStringHelper;
#ifndef F
#define F(string_literal) ((const __FlashStringHelper *)(string_literal))
#endif
... all it does it cast the const string to a different type of pointer, which then gets cast back to char* when printed.

As an alternative the PSTR() macro does properly place strings in PROGMEM, but that isn't mentioned at all on the store page (and seems to be used less commonly in arduino-based libraries).
Although it seems the compiler can still be a bit over-aggressive in those cases - it automatically transforms code such as
Code:
printf(PSTR("Hello World\n"));
into
Code:
puts("Hello World");
and somehow the modification of the string to remove the newline makes it end up in the regular data section (DTCM) instead of PROGMEM (Flash.)
 
Last edited:
Changes since Teensyduino 1.59-beta2:

Fix const init on Wire, SPI, HardwareSerial
The SPI constexpr constructor fix works for T4.1, but the T3.x code section was not fixed. I posted issue #69 on github with a fix in the first comment.

I know T3 is no longer produced, but there are a lot of T3.6 boards out there and a lot of code that passes an SPI instance as a constructor parameter...
 
TD1.59 Beta 3 on Teensy 3.6 => attempts to use the predefined Wire2 interface result in a program freeze. The problem is solved by calling:

Code:
Wire2.begin();
Wire2.setClock(400000);

before calling beginTransmission();

However, this is not necessary for Wire or Wire1.
 
Back
Top