-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
li9341: change to use the standard SPI #242
Conversation
The problem of slow
I would like to add TxN() to the machine package (and tinygo-org/drivers.SPI interface), what do you think? func (spi SPI) TxN(w, r []byte, n int) error {
// At this time, it can only transmit.
for i := 0; i < len(w)*n; i++ {
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPIM_INTFLAG_DRE) {
}
spi.Bus.DATA.Set(uint32(w[i%len(w)]))
}
for !spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPIM_INTFLAG_TXC) {
}
// read to clear RXC register
for spi.Bus.INTFLAG.HasBits(sam.SERCOM_SPIM_INTFLAG_RXC) {
spi.Bus.DATA.Get()
}
return nil
} |
} | ||
} | ||
display.DrawRGBBitmap(0, j, frameBuffer[0:w], w, 1) | ||
display.DrawRGBBitmap8(0, j, frameBuffer[0:w*2], w, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is necessary.
When using the standard SPI, it is not possible to send while converting endianness.
The same problem will occur in the future when converting to DMA, so it is necessary to use byte-by-byte endianness-aware arrays.
b3759d5
to
6378baa
Compare
func (pd *spiDriver) write16n(data uint16, n int) { | ||
for i := 0; i < len(buf); i += 2 { | ||
buf[i] = uint8(data >> 8) | ||
buf[i+1] = uint8(data) | ||
} | ||
|
||
for i := 0; i < (n >> 5); i++ { | ||
pd.bus.Tx(buf[:], nil) | ||
} | ||
|
||
pd.bus.Tx(buf[:n%64], nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPI.Tx() every 64 bytes at most, with minimal slowdown
SPI.TxN() is not necessary.
Checked with feather-m4 (atsamd51) and xiao (atsamd21). However, it does not work at 24MHz on xiao at this time. It will probably work on other chips, such as nrf and teensy. |
I have confirmed that // +build feather_m4 feather_m4_can feather_nrf52840 feather_stm32f405
package main
import (
"machine"
"tinygo.org/x/drivers/ili9341"
)
var (
display = ili9341.NewSPI(
machine.SPI0,
machine.D10, // LCD_DC,
machine.D11, // LCD_SS_PIN,
machine.D12, // LCD_RESET,
)
backlight = machine.D13 // LCD_BACKLIGHT
)
func init() {
machine.SPI0.Configure(machine.SPIConfig{
SCK: machine.SPI0_SCK_PIN,
SDO: machine.SPI0_SDO_PIN,
SDI: machine.SPI0_SDI_PIN,
Frequency: 40000000,
})
} The fps is as follows.
|
However, according to #196, the spi driver for stm32f405 seems to have a speed of 68 - 88 fps. I think this can be solved by using DMA on the SPI driver side. |
6378baa
to
3dd7136
Compare
I've changed my approach to #274, so I'm closing this PR. |
The following changes make the SPI faster, so you can now use the standard SPI.
tinygo-org/tinygo#1453
The FPS of
examples/ili9341/pyportal_boing
is as follows, with acceptable performance.However,
FillRectangle()
, which useswrite16n()
, is very slow.For example, it is used in
examples/ili9341/basic
.It is visibly slow.
The following is the waveform during
FillRectangle()
, the new one is very slow with a gap of less than 500ns.org:

fillscreen (320x240) == 51.38ms
new:

fillscreen (320x240) == 380.70ms