mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-18 21:53:56 +00:00
ili9341: add standard SPI driver
This commit is contained in:
+17
-1
@@ -160,6 +160,20 @@ func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DrawRGBBitmap8 copies an RGB bitmap to the internal buffer at given coordinates
|
||||
func (d *Device) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error {
|
||||
k, i := d.Size()
|
||||
if x < 0 || y < 0 || w <= 0 || h <= 0 ||
|
||||
x >= k || (x+w) > k || y >= i || (y+h) > i {
|
||||
return errors.New("rectangle coordinates outside display area")
|
||||
}
|
||||
d.setWindow(x, y, w, h)
|
||||
d.startWrite()
|
||||
d.driver.write8sl(data)
|
||||
d.endWrite()
|
||||
return nil
|
||||
}
|
||||
|
||||
// FillRectangle fills a rectangle at given coordinates with a color
|
||||
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
|
||||
k, i := d.Size()
|
||||
@@ -300,7 +314,9 @@ func (d *Device) sendCommand(cmd byte, data []byte) {
|
||||
d.dc.Low()
|
||||
d.driver.write8(cmd)
|
||||
d.dc.High()
|
||||
d.driver.write8sl(data)
|
||||
if data != nil {
|
||||
d.driver.write8sl(data)
|
||||
}
|
||||
d.endWrite()
|
||||
}
|
||||
|
||||
|
||||
@@ -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