https://github.com/ag88/stm32duino_spi_ ... /SPI/SPI.h
- added externs to SPI instance (this defaults to SPI 1)
- SPIDMA classes are different for each series and SPIDMA uses a different/specific class for each SPI peripheral.
Typedefs are defined for SPIClass1, SPIClass2, SPIClass3 in spi.h
This is so that codes likeshould work, and does not need to reference the specific class name for each series and peripheral.Code: Select all
SPIClass1 spi1; SPIClass2 spi2; SPIClass3 spi3;
Note that each SPIClassN is actually derived from SPIClass, hence they can be passed to functions / methods
that use SPIClass for the SPI api.
each SPIClass1, SPIClass2, SPIClass3 connects to the specific SPI peripheral 1, 2, 3 respectively
If you do test that, do drop a comment about it here or in github discussions etc.
edit:
there is a 'catch' in that actually for series that do not have a SPIDMA class, it uses SPIBasic which is generic (across SPI 1, 2, 3) and follows the original SPIClass definition instead. But that if no pin parameters are given, it defaults to SPI1.
I'd need to figure out how to make the declarations similar.
edit2:
this is done, SPIClass2 spi2; and SPIClass3 spi3; now works for SPIBasic based class as well, it is done by deriving a class and passing default pins to the constructor.
SPIBasic remains as a generic SPIClass implementation that can be used for any SPI peripherals.
SPIDMA implementations are specific to each SPI peripheral, i.e. it isn't possible to use SPIClass2 for SPIClass1 and vice versa.
I'm also thinking about in the constructor to add a parameter to specify the particular SPI peripheral used (e.g. using the SPI_BASE symbol for the register base address). This would deviate from the current constructor, but that it could make defaulting behaviour simpler to implement.
Such an implementation can enable specific pins tied to the SPI peripheral by default and helps avoid usage errors binding the incorrect pins,