The Teensy LC has two (almost) identical SPIs. I was hoping that I could make use of that fact in DmaSpi, but SPI1 is implemented as a totally different class. They are entirely unrelated and don't have a shared base class, with minor additions in SPI1 for the FIFO features (and I think that's the only difference).
I'd really like to see a base class for both SPIs, because with that an instance of BasicSPI (or however it might be named) can be passed to the code that wants to use an SPI, and it would also be easier to write flexible code that is not hardwired for a specific SPI.
Related to this is the naming of *_SPI_t structs in cores/teensy3/kinetis.h: There's an KINETISK_SPI_t and a KINETISL_SPI_t, both wrapped in a conditional for each piece of hardware. I suggest to rename them to (or add a new define with the name) KINETIS_SPI_t that can be used in other code to "just get an SPI struct" (or a pointer or reference). Free functions can be used to manipulate such a struct on a low level, similar to the deprecated SPI::setBitOrder(...) methods. This would simplify the implementation of higher level SPI classes such as SPIClass and SPI1Class.
Why would I like a common SPI base for DmaSpi? This is due to the way the asynchronous chip selects work: They begin and end a transaction, and they also select the appropriate slave by pulling its SS line low. Beginning and ending a transaction requires a reference to the SPI used, and that must either be hardwired into the chip select class or passed to the chip select object at runtime. Either way, having a common base minimizes duplicated code. If the SPI class is hardwired into the chip select class, every chip needs its own chip select class and that would be a waste of resources. For now, my ActiveLowChipSelect covers most of the cases.
Regards
Christoph
I'd really like to see a base class for both SPIs, because with that an instance of BasicSPI (or however it might be named) can be passed to the code that wants to use an SPI, and it would also be easier to write flexible code that is not hardwired for a specific SPI.
Related to this is the naming of *_SPI_t structs in cores/teensy3/kinetis.h: There's an KINETISK_SPI_t and a KINETISL_SPI_t, both wrapped in a conditional for each piece of hardware. I suggest to rename them to (or add a new define with the name) KINETIS_SPI_t that can be used in other code to "just get an SPI struct" (or a pointer or reference). Free functions can be used to manipulate such a struct on a low level, similar to the deprecated SPI::setBitOrder(...) methods. This would simplify the implementation of higher level SPI classes such as SPIClass and SPI1Class.
Why would I like a common SPI base for DmaSpi? This is due to the way the asynchronous chip selects work: They begin and end a transaction, and they also select the appropriate slave by pulling its SS line low. Beginning and ending a transaction requires a reference to the SPI used, and that must either be hardwired into the chip select class or passed to the chip select object at runtime. Either way, having a common base minimizes duplicated code. If the SPI class is hardwired into the chip select class, every chip needs its own chip select class and that would be a waste of resources. For now, my ActiveLowChipSelect covers most of the cases.
Regards
Christoph