lancaster-university / microbit-dal

http://lancaster-university.github.io/microbit-docs
Other
256 stars 130 forks source link

Please implement a faster, native unidirectional spiTransfer() capability #466

Open MTKilpatrick opened 4 years ago

MTKilpatrick commented 4 years ago

Having experimented with SPI and being grateful for help on a previous issue in this respect, I would like to suggest:

Please consider implementing a native SPI buffer transfer function for Microbit avoiding some of the overheads of the existing spiTransfer() method which simply repeatedly calls spiWrite() byte per byte. My assumption is that many of the overheads involve repeated checks of the configuration of the SPI pins and other house-keeping functions which, for a continuous transfer of bytes from a buffer, could be avoided.

For unidirectional transfer from a Microbit - let's say to an LCD or OLED screen other device which requires the transfer of a data buffer of considerable size - a call to spiTransfer() can result in an overall data transfer rate equivalent to less than 1Mbit/second even with an SPI clock frequency of 4MHz.

I experimented with an assembler routine to deliver a buffer by a software implementation using a clock pin and a data out pin and this was able to deliver an average continuous bit-rate of upto 1.3Mbit/s: for a byte buffer of 504 bytes I found it taking only 65% of the time taken by the current spiTransfer() method with the SPI clock speed set to 4MHz, which indicates a considerable dead-time between each byte transfer.

For SPI transfers which do not need to monitor return data at the input buffer, a faster native buffer method would be most welcome.