Easiest way to port teensy2.0 avr C code to teensyLC?

Status
Not open for further replies.

gipetto

Member
I saw some posts where a few used chibios to do so. does that require a rewrite of the code? I've been trying to write c code for the teensyLC but considering the scarcity of examples, it's hard going.
 
There is no single easy answer. The best way is to let us help you with the details by showing us the actual code in need of porting.

If you look over the many threads on this forum, you'll see lots of examples where this worked out pretty well. But the details matter. Sometimes the changes are simple, like minor differences with I/O ports. Sometimes it's more complex stuff like the hardware timers, but often people in the Arduino world just use the timers for periodic interrupt which is easy to port using IntervalTimer. Sometimes the "porting" is stuff like needing to add delays for multiplexed signals, where AVR is so slow that the ~500 ns time for a pullup resistor doesn't matter, but a fast 32 bit chip running the same code reads the signal too early while the voltage is still changing. Details matter, and the best way to talk about details is with the actual code and any necessary info like the hardware it uses.
 
Thanks for responding. here is the code I am using, you'll recognize it as based on the pjrc usb mouse example code. it uses timers and interrupts and some spi data transfers. I guess I could strip out much of the button interrupt code to make it easier to port.

https://yadi.sk/d/_nV-ORVl3Q2NNQ
 
Given it used the mouse example code as a base, it might be simpler to start from scratch using the Teensy LC/3.x mouse examples, rather than trying to hack the 2.00 examples.

One thing you might want to do is add a button or switch connected to a Teensy pin/ground When the button is engaged disable the mouse code. This makes it so much easier to reprogram.
 
the mouse.h library is horrible, I used it in another project. polling rate is too slow,
buggy, only supports 3 buttons+ wheel, 8 bit usb reports.
it's bad and I lack the skill to upgrade it.

There is a jump to bootloader section in it, and you're absolutely right to want to keep
it but it's a non critical feature.
 
This is a tough one. Probably easiest to just use Teensy 2.0.

If *really* want to port the code, this is probably several mini projects to port and test each part. The button debouncing could be done with the Bounce library, for example. The custom USB mouse is going to involve editing the mouse code within the Teensyduino core library. Again, it's doable, but a small project in itself. Likewise for the SPI code and other stuff.
 
Status
Not open for further replies.
Back
Top