mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-25 17:09:01 +00:00
apa102: avoid creating garbage
Avoid creating unnecessary garbage in the following ways:
* Use the Transfer method instead of the Tx method for single byte
transfers.
* Use a statically allocated buffer for the fixed start-of-frame
sequence.
Running this for a few minutes did not cause the garbage collector to
run. Previously, it would run every second or so in a
persistence-of-vision application.
This commit is contained in:
committed by
Ron Evans
parent
c3f3af5ffa
commit
91539d9ef8
+5
-3
@@ -41,8 +41,9 @@ func (s *bbSPI) delay() {
|
||||
}
|
||||
}
|
||||
|
||||
// Transfer is used to send a single byte.
|
||||
func (s *bbSPI) Transfer(b byte) {
|
||||
// Transfer matches signature of machine.SPI.Transfer() and is used to send a
|
||||
// single byte. The received data is ignored and no error will ever be returned.
|
||||
func (s *bbSPI) Transfer(b byte) (byte, error) {
|
||||
for i := uint8(0); i < 8; i++ {
|
||||
|
||||
// half clock cycle high to start
|
||||
@@ -63,6 +64,7 @@ func (s *bbSPI) Transfer(b byte) {
|
||||
|
||||
// for actual SPI would try to read the MISO value here
|
||||
s.delay()
|
||||
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user