tinygo-org / drivers

TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
605 stars 188 forks source link

ili9341: avoid heap allocations #395

Closed sago35 closed 2 years ago

sago35 commented 2 years ago

This PR removes the heap allocation from the ili9341 driver.

before

$ tinygo flash --target feather-m4-can --size short --programmer cmsis-dap --print-allocs . -opt s ./examples/ili9341/pyportal_boing/
C:\Users\sago3\dev\src\tinygo.org\x\drivers\ili9341\spi_atsamd51.go:21:21: object allocated on the heap: escapes at line 21
C:\Users\sago3\dev\src\tinygo.org\x\drivers\ili9341\spi_atsamd51.go:16:16: object allocated on the heap: escapes at line 16
C:\Users\sago3\dev\src\tinygo.org\x\drivers\ili9341\ili9341.go:308:31: object allocated on the heap: escapes at line 308
C:\Users\sago3\dev\src\tinygo.org\x\drivers\ili9341\ili9341.go:301:31: object allocated on the heap: escapes at line 301
C:\Users\sago3\dev\src\tinygo.org\x\drivers\ili9341\ili9341.go:270:31: object allocated on the heap: escapes at line 270
C:\Users\sago3\dev\src\tinygo.org\x\drivers\ili9341\ili9341.go:84:19: object allocated on the heap: escapes at line 110
C:\tinygo\tinygo\src\runtime\baremetal.go:42:14: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\runtime\slice.go:30:15: object allocated on the heap: size is not constant
C:\Go\src\errors\errors.go:59:21: object allocated on the heap: escapes at line 59
C:\tinygo\tinygo\src\internal\task\task_stack.go:67:15: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\internal\task\task_stack.go:101:12: object allocated on the heap: escapes at line 103

after:

$ tinygo flash --target feather-m4-can --size short --programmer cmsis-dap --print-allocs . -opt s ./examples/ili9341/pyportal_boing/
C:\Users\sago3\dev\src\tinygo.org\x\drivers\ili9341\spi_atsamd51.go:21:21: object allocated on the heap: escapes at line 21
C:\Users\sago3\dev\src\tinygo.org\x\drivers\ili9341\spi_atsamd51.go:16:16: object allocated on the heap: escapes at line 16
C:\tinygo\tinygo\src\runtime\baremetal.go:42:14: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\runtime\slice.go:30:15: object allocated on the heap: size is not constant
C:\Go\src\errors\errors.go:59:21: object allocated on the heap: escapes at line 59
C:\tinygo\tinygo\src\internal\task\task_stack.go:67:15: object allocated on the heap: size is not constant
C:\tinygo\tinygo\src\internal\task\task_stack.go:101:12: object allocated on the heap: escapes at line 103
deadprogram commented 2 years ago

Good work @sago35 :scissors:

Now merging.