mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-25 00:48:59 +00:00
ili9341: add standard SPI driver
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// +build !atsamd51,!atsamd21
|
||||
|
||||
package ili9341
|
||||
|
||||
import (
|
||||
"machine"
|
||||
)
|
||||
|
||||
var buf [64]byte
|
||||
|
||||
type spiDriver struct {
|
||||
bus machine.SPI
|
||||
}
|
||||
|
||||
func NewSPI(bus machine.SPI, dc, cs, rst machine.Pin) *Device {
|
||||
return &Device{
|
||||
dc: dc,
|
||||
cs: cs,
|
||||
rst: rst,
|
||||
rd: machine.NoPin,
|
||||
driver: &spiDriver{
|
||||
bus: bus,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (pd *spiDriver) configure(config *Config) {
|
||||
}
|
||||
|
||||
func (pd *spiDriver) write8(b byte) {
|
||||
buf[0] = b
|
||||
pd.bus.Tx(buf[:1], nil)
|
||||
}
|
||||
|
||||
func (pd *spiDriver) write8n(b byte, n int) {
|
||||
buf[0] = b
|
||||
for i := 0; i < n; i++ {
|
||||
pd.bus.Tx(buf[:1], nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (pd *spiDriver) write8sl(b []byte) {
|
||||
pd.bus.Tx(b, nil)
|
||||
}
|
||||
|
||||
func (pd *spiDriver) write16(data uint16) {
|
||||
buf[0] = uint8(data >> 8)
|
||||
buf[1] = uint8(data)
|
||||
pd.bus.Tx(buf[:2], nil)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (pd *spiDriver) write16sl(data []uint16) {
|
||||
for i, c := 0, len(data); i < c; i++ {
|
||||
buf[0] = uint8(data[i] >> 8)
|
||||
buf[1] = uint8(data[i])
|
||||
pd.bus.Tx(buf[:2], nil)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user