machine: add __tinygo_spi_tx function to simulator

This is much, _much_ faster than __tinygo_spi_transfer which can only
transfer a single byte at a time. This is especially important for
simulated displays.

I've already implemented the browser side of this on the playground and
have used this patch for local testing where it massively speeds up
display operations.
This commit is contained in:
Ayke van Laethem
2024-04-12 14:54:27 +02:00
committed by Ron Evans
parent 90b0bf646c
commit 85b59e66da
2 changed files with 36 additions and 1 deletions
+35
View File
@@ -66,12 +66,47 @@ func (spi SPI) Transfer(w byte) (byte, error) {
return spiTransfer(spi.Bus, w), nil
}
// Tx handles read/write operation for SPI interface. Since SPI is a syncronous write/read
// interface, there must always be the same number of bytes written as bytes read.
// The Tx method knows about this, and offers a few different ways of calling it.
//
// This form sends the bytes in tx buffer, putting the resulting bytes read into the rx buffer.
// Note that the tx and rx buffers must be the same size:
//
// spi.Tx(tx, rx)
//
// This form sends the tx buffer, ignoring the result. Useful for sending "commands" that return zeros
// until all the bytes in the command packet have been received:
//
// spi.Tx(tx, nil)
//
// This form sends zeros, putting the result into the rx buffer. Good for reading a "result packet":
//
// spi.Tx(nil, rx)
func (spi SPI) Tx(w, r []byte) error {
var wptr, rptr *byte
var wlen, rlen int
if len(w) != 0 {
wptr = &w[0]
wlen = len(w)
}
if len(r) != 0 {
rptr = &r[0]
rlen = len(r)
}
spiTX(spi.Bus, wptr, wlen, rptr, rlen)
return nil
}
//export __tinygo_spi_configure
func spiConfigure(bus uint8, sck Pin, SDO Pin, SDI Pin)
//export __tinygo_spi_transfer
func spiTransfer(bus uint8, w uint8) uint8
//export __tinygo_spi_tx
func spiTX(bus uint8, wptr *byte, wlen int, rptr *byte, rlen int) uint8
// InitADC enables support for ADC peripherals.
func InitADC() {
// Nothing to do here.
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !baremetal || atmega || fe310 || k210 || (nxp && !mk66f18) || (stm32 && !stm32f7x2 && !stm32l5x2)
//go:build atmega || fe310 || k210 || (nxp && !mk66f18) || (stm32 && !stm32f7x2 && !stm32l5x2)
// This file implements the SPI Tx function for targets that don't have a custom
// (faster) implementation for it.