Skip to content

Commit 4c98d0b

Browse files
Amblyopiusdeadprogram
authored andcommitted
- Fix for RAMWR bug:
It can not be skipped as you may call setwindow even if device is not ready for data write to buffer. Data can only be written if last command was Memory Write or Write Memory Continue which was not guaranteed There's no performance loss as having the exact same window on a consecutive call is extremely unlikely - Fixed some typos and added a few missing comments to please go-lint
1 parent 65f8299 commit 4c98d0b

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

ili9341/ili9341.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ type Device struct {
2020
driver driver
2121

2222
x0, x1 int16 // cached address window; prevents useless/expensive
23-
y0, y1 int16 // syscalls to PASET, CASET, and RAMWR
23+
y0, y1 int16 // syscalls to PASET and CASET
2424

2525
dc machine.Pin
2626
cs machine.Pin
2727
rst machine.Pin
2828
rd machine.Pin
2929
}
3030

31+
// Configure prepares display for use
3132
func (d *Device) Configure(config Config) {
3233

3334
if config.Width == 0 {
@@ -145,6 +146,7 @@ func (d *Device) Display() error {
145146
return nil
146147
}
147148

149+
// DrawRGBBitmap copies an RGB bitmap to the internal buffer at given coordinates
148150
func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error {
149151
k, i := d.Size()
150152
if x < 0 || y < 0 || w <= 0 || h <= 0 ||
@@ -158,7 +160,7 @@ func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error {
158160
return nil
159161
}
160162

161-
// FillRectangle fills a rectangle at a given coordinates with a color
163+
// FillRectangle fills a rectangle at given coordinates with a color
162164
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
163165
k, i := d.Size()
164166
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
@@ -173,7 +175,7 @@ func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
173175
return nil
174176
}
175177

176-
// DrawRectangle fills a rectangle at a given coordinates with a color
178+
// DrawRectangle draws a rectangle at given coordinates with a color
177179
func (d *Device) DrawRectangle(x, y, w, h int16, c color.RGBA) error {
178180
if err := d.DrawFastHLine(x, x+w-1, y, c); err != nil {
179181
return err
@@ -215,6 +217,7 @@ func (d *Device) FillScreen(c color.RGBA) {
215217
}
216218
}
217219

220+
// GetRotation returns the current rotation of the device
218221
func (d *Device) GetRotation() Rotation {
219222
return d.rotation
220223
}
@@ -236,7 +239,8 @@ func (d *Device) SetRotation(rotation Rotation) {
236239
d.rotation = rotation
237240
}
238241

239-
// SetScrollWindow sets an area to scroll with fixed top and bottom parts of the display
242+
// SetScrollArea sets an area to scroll with fixed top/bottom or left/right parts of the display
243+
// Rotation affects scroll direction
240244
func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) {
241245
d.sendCommand(VSCRDEF, []uint8{
242246
uint8(topFixedArea >> 8), uint8(topFixedArea),
@@ -251,7 +255,7 @@ func (d *Device) SetScroll(line int16) {
251255
d.sendCommand(VSCRSADD, []uint8{uint8(line >> 8), uint8(line)})
252256
}
253257

254-
// SpotScroll returns the display to its normal state
258+
// StopScroll returns the display to its normal state
255259
func (d *Device) StopScroll() {
256260
d.sendCommand(NORON, nil)
257261
}
@@ -260,26 +264,21 @@ func (d *Device) StopScroll() {
260264
func (d *Device) setWindow(x, y, w, h int16) {
261265
//x += d.columnOffset
262266
//y += d.rowOffset
263-
wr := false
264267
x1 := x + w - 1
265268
if x != d.x0 || x1 != d.x1 {
266-
wr = true
267269
d.sendCommand(CASET, []uint8{
268270
uint8(x >> 8), uint8(x), uint8(x1 >> 8), uint8(x1),
269271
})
270272
d.x0, d.x1 = x, x1
271273
}
272274
y1 := y + h - 1
273275
if y != d.y0 || y1 != d.y1 {
274-
wr = true
275276
d.sendCommand(PASET, []uint8{
276277
uint8(y >> 8), uint8(y), uint8(y1 >> 8), uint8(y1),
277278
})
278279
d.y0, d.y1 = y, y1
279280
}
280-
if wr {
281-
d.sendCommand(RAMWR, nil)
282-
}
281+
d.sendCommand(RAMWR, nil)
283282
}
284283

285284
//go:inline

0 commit comments

Comments
 (0)