diff --git a/Makefile b/Makefile index edc5b7c..ee46143 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,8 @@ smoke-test: @md5sum ./build/test.hex tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic/main.go @md5sum ./build/test.hex + tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll/main.go + @md5sum ./build/test.hex tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis3dh/main.go @md5sum ./build/test.hex tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/lsm6ds3/main.go diff --git a/examples/ili9341/scroll/main.go b/examples/ili9341/scroll/main.go new file mode 100644 index 0000000..e302fdc --- /dev/null +++ b/examples/ili9341/scroll/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "image/color" + "machine" + "time" + + "tinygo.org/x/drivers/ili9341" +) + +var ( + display = ili9341.NewParallel( + machine.LCD_DATA0, + machine.TFT_WR, + machine.TFT_DC, + machine.TFT_CS, + machine.TFT_RESET, + machine.TFT_RD, + ) + + red = color.RGBA{255, 0, 0, 255} + blue = color.RGBA{0, 0, 255, 255} + green = color.RGBA{0, 255, 0, 255} + black = color.RGBA{0, 0, 0, 255} + white = color.RGBA{255, 255, 255, 255} +) + +func main() { + + machine.TFT_BACKLIGHT.Configure(machine.PinConfig{machine.PinOutput}) + + display.Configure(ili9341.Config{}) + width, height := display.Size() + + display.FillScreen(black) + machine.TFT_BACKLIGHT.High() + + display.FillRectangle(0, 0, width/2, height/2, white) + display.FillRectangle(width/2, 0, width/2, height/2, red) + display.FillRectangle(0, height/2, width/2, height/2, green) + display.FillRectangle(width/2, height/2, width/2, height/2, blue) + display.FillRectangle(width/4, height/4, width/2, height/2, black) + + for scroll := int16(0); ; scroll = (scroll + 1) % 320 { + time.Sleep(7500 * time.Microsecond) + display.SetScroll(scroll) + } + +} diff --git a/ili9341/ili9341.go b/ili9341/ili9341.go index 6b4f0a8..75b3585 100644 --- a/ili9341/ili9341.go +++ b/ili9341/ili9341.go @@ -7,8 +7,6 @@ import ( "time" ) -const _debug = false - type Config struct { Width int16 Height int16 @@ -229,6 +227,26 @@ func (d *Device) SetRotation(rotation Rotation) { d.rotation = rotation } +// SetScrollWindow sets an area to scroll with fixed top and bottom parts of the display +func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) { + d.sendCommand(VSCRDEF, []uint8{ + uint8(topFixedArea >> 8), uint8(topFixedArea), + uint8(d.height - topFixedArea - bottomFixedArea>>8), + uint8(d.height - topFixedArea - bottomFixedArea), + uint8(bottomFixedArea >> 8), uint8(bottomFixedArea), + }) +} + +// SetScroll sets the vertical scroll address of the display. +func (d *Device) SetScroll(line int16) { + d.sendCommand(VSCRSADD, []uint8{uint8(line >> 8), uint8(line)}) +} + +// SpotScroll returns the display to its normal state +func (d *Device) StopScroll() { + d.sendCommand(NORON, nil) +} + // setWindow prepares the screen to be modified at a given rectangle func (d *Device) setWindow(x, y, w, h int16) { //x += d.columnOffset