Skip to content

Commit 4169408

Browse files
sago35deadprogram
authored andcommitted
Improve performance of ILI9341 on ATSAMD5X
1 parent fd9b1ba commit 4169408

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

ili9341/parallel_atsamd51.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ package ili9341
55
import (
66
"machine"
77
"runtime/volatile"
8+
"unsafe"
89
)
910

1011
type parallelDriver struct {
1112
d0 machine.Pin
1213
wr machine.Pin
1314

14-
setPort *uint32
15-
setMask uint32
15+
setPort *uint8
1616

1717
clrPort *uint32
1818
clrMask uint32
@@ -46,8 +46,12 @@ func (pd *parallelDriver) configure(config *Config) {
4646
pd.wr.Configure(output)
4747
pd.wr.High()
4848

49-
pd.setPort, _ = pd.d0.PortMaskSet()
50-
pd.setMask = uint32(pd.d0) & 0x1f
49+
// Calculates the address of the OUT register from the OUTSET register and obtains an address that allows 8-bit access.
50+
// OUT : offset = 0x10
51+
// OUTSET : offset = 0x18
52+
setPort, _ := pd.d0.PortMaskSet()
53+
setMask := uint32(pd.d0) & 0x1f
54+
pd.setPort = (*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(setPort)) - uintptr(8) + uintptr(setMask/8)))
5155

5256
pd.clrPort, _ = (pd.d0).PortMaskClear()
5357
pd.clrMask = 0xFF << uint32(pd.d0)
@@ -58,8 +62,12 @@ func (pd *parallelDriver) configure(config *Config) {
5862

5963
//go:inline
6064
func (pd *parallelDriver) write8(b byte) {
61-
volatile.StoreUint32(pd.clrPort, pd.clrMask)
62-
volatile.StoreUint32(pd.setPort, uint32(b)<<pd.setMask)
65+
volatile.StoreUint8(pd.setPort, uint8(b))
66+
pd.wrx()
67+
}
68+
69+
//go:inline
70+
func (pd *parallelDriver) wrx() {
6371
volatile.StoreUint32(pd.wrPortClr, pd.wrMaskClr)
6472
volatile.StoreUint32(pd.wrPortSet, pd.wrMaskSet)
6573
}

0 commit comments

Comments
 (0)