From ba4de1efb8bd73f4d2589916b175e4769c0e6cdd Mon Sep 17 00:00:00 2001 From: k-brk <25877802+k-brk@users.noreply.github.com> Date: Sat, 4 May 2019 15:37:10 +0200 Subject: [PATCH] SetPixel removed, formatting --- .circleci/config.yml | 4 +-- examples/hd44780/customchar/main.go | 15 ++++++++-- examples/hd44780/text/main.go | 15 ++++++++-- hd44780/gpio.go | 6 +++- hd44780/hd44780.go | 43 +++++++++++++---------------- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5157683..65f95bc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,6 +23,8 @@ jobs: - run: tinygo build -size short -o test.elf -target=itsybitsy-m0 ./examples/espat/espconsole/main.go - run: tinygo build -size short -o test.elf -target=itsybitsy-m0 ./examples/espat/esphub/main.go - run: tinygo build -size short -o test.elf -target=itsybitsy-m0 ./examples/espat/espstation/main.go + - run: tinygo build -size short -o test.elf -target=microbit ./examples/hd44780/customchar/main.go + - run: tinygo build -size short -o test.elf -target=microbit ./examples/hd44780/text/main.go - run: tinygo build -size short -o test.elf -target=microbit ./examples/hub75/main.go - run: tinygo build -size short -o test.elf -target=circuitplay-express ./examples/lis3dh/main.go - run: tinygo build -size short -o test.elf -target=itsybitsy-m0 ./examples/mag3110/main.go @@ -33,5 +35,3 @@ jobs: - run: tinygo build -size short -o test.elf -target=circuitplay-express ./examples/thermistor/main.go - run: tinygo build -size short -o test.elf -target=itsybitsy-m0 ./examples/vl53l1x/main.go - run: tinygo build -size short -o test.elf -target=circuitplay-express ./examples/ws2812/main.go - - run: tinygo build -size short -o test.elf -target=microbit ./examples/hd44780/text/main.go - - run: tinygo build -size short -o test.elf -target=microbit ./examples/hd44780/customchar/main.go diff --git a/examples/hd44780/customchar/main.go b/examples/hd44780/customchar/main.go index 0366232..ba686d1 100644 --- a/examples/hd44780/customchar/main.go +++ b/examples/hd44780/customchar/main.go @@ -8,9 +8,20 @@ import ( func main() { - lcd, _ := hd44780.NewGPIO4Bit([]uint8{machine.P0, machine.P1, machine.P2, machine.P3}, machine.P4, machine.P5, machine.P6) + lcd, _ := hd44780.NewGPIO4Bit( + []uint8{machine.P0, machine.P1, machine.P2, machine.P3}, + machine.P4, + machine.P5, + machine.P6, + ) + + lcd.Configure(hd44780.Config{ + Width: 16, + Height: 2, + CursorOnOff: true, + CursorBlink: true, + }) - lcd.Configure(hd44780.Config{Width: 16, Height: 2, CursorOnOff: true, CursorBlink: true}) lcd.CreateCharacter(0x0, []byte{0x04, 0x0E, 0x0E, 0x0E, 0x0E, 0x1F, 0x04, 0x0}) lcd.Write([]byte{0x0}) lcd.Display() diff --git a/examples/hd44780/text/main.go b/examples/hd44780/text/main.go index 497b83a..94237dd 100644 --- a/examples/hd44780/text/main.go +++ b/examples/hd44780/text/main.go @@ -8,9 +8,20 @@ import ( func main() { - lcd, _ := hd44780.NewGPIO4Bit([]uint8{machine.P0, machine.P1, machine.P2, machine.P3}, machine.P4, machine.P5, machine.P6) + lcd, _ := hd44780.NewGPIO4Bit( + []uint8{machine.P0, machine.P1, machine.P2, machine.P3}, + machine.P4, + machine.P5, + machine.P6, + ) + + lcd.Configure(hd44780.Config{ + Width: 16, + Height: 2, + CursorOnOff: true, + CursorBlink: true, + }) - lcd.Configure(hd44780.Config{Width: 16, Height: 2, CursorOnOff: true, CursorBlink: true}) lcd.Write([]byte("This is a long line")) lcd.Display() diff --git a/hd44780/gpio.go b/hd44780/gpio.go index fafa646..8fe11b7 100644 --- a/hd44780/gpio.go +++ b/hd44780/gpio.go @@ -62,6 +62,7 @@ func (g *GPIO) SetCommandMode(set bool) { } } +// Write writes len(data) bytes from data to display driver func (g *GPIO) Write(data []byte) (n int, err error) { g.rw.Low() for _, d := range data { @@ -87,11 +88,12 @@ func (g *GPIO) write4BitMode(data byte) { g.e.Low() } +// Read reads len(data) bytes from display RAM to data starting from RAM address counter position +// Ram address can be changed by writing address in command mode func (g *GPIO) Read(data []byte) (n int, err error) { if len(data) == 0 { return 0, errors.New("Length greater than 0 is required") } - g.rs.Low() g.rw.High() g.reconfigureGPIOMode(machine.GPIO_INPUT) for i := 0; i < len(data); i++ { @@ -111,12 +113,14 @@ func (g *GPIO) read4BitMode() byte { g.e.Low() return data } + func (g *GPIO) read8BitMode() byte { g.e.High() data := g.pins() g.e.Low() return data } + func (g *GPIO) reconfigureGPIOMode(mode machine.GPIOMode) { for i := 0; i < len(g.dataPins); i++ { g.dataPins[i].Configure(machine.GPIOConfig{Mode: mode}) diff --git a/hd44780/hd44780.go b/hd44780/hd44780.go index f2de062..bfd3104 100644 --- a/hd44780/hd44780.go +++ b/hd44780/hd44780.go @@ -2,7 +2,6 @@ package hd44780 import ( "errors" - "image/color" "io" "time" ) @@ -12,24 +11,6 @@ type Buser interface { SetCommandMode(set bool) } -// NewGPIO4Bit returns 4bit data length HD44780 driver. Datapins are LCD DB pins starting from DB4 to DB7 -func NewGPIO4Bit(dataPins []uint8, e, rs, rw uint8) (Device, error) { - const fourBitMode = 4 - if len(dataPins) != fourBitMode { - return Device{}, errors.New("4 pins are required in data slice (D7-D4) when HD44780 is used in 4 bit mode") - } - return newGPIO(dataPins, e, rs, rw, DATA_LENGTH_4BIT), nil -} - -// NewGPIO8Bit returns 8bit data length HD44780 driver. Datapins are LCD DB pins starting from DB0 to DB7 -func NewGPIO8Bit(dataPins []uint8, e, rs, rw uint8) (Device, error) { - const eightBitMode = 8 - if len(dataPins) != eightBitMode { - return Device{}, errors.New("8 pins are required in data slice (D7-D0) when HD44780 is used in 8 bit mode") - } - return newGPIO(dataPins, e, rs, rw, DATA_LENGTH_8BIT), nil -} - type Device struct { bus Buser width uint8 @@ -56,6 +37,24 @@ type Config struct { Font uint8 } +// NewGPIO4Bit returns 4bit data length HD44780 driver. Datapins are LCD DB pins starting from DB4 to DB7 +func NewGPIO4Bit(dataPins []uint8, e, rs, rw uint8) (Device, error) { + const fourBitMode = 4 + if len(dataPins) != fourBitMode { + return Device{}, errors.New("4 pins are required in data slice (D4-D7) when HD44780 is used in 4 bit mode") + } + return newGPIO(dataPins, e, rs, rw, DATA_LENGTH_4BIT), nil +} + +// NewGPIO8Bit returns 8bit data length HD44780 driver. Datapins are LCD DB pins starting from DB0 to DB7 +func NewGPIO8Bit(dataPins []uint8, e, rs, rw uint8) (Device, error) { + const eightBitMode = 8 + if len(dataPins) != eightBitMode { + return Device{}, errors.New("8 pins are required in data slice (D0-D7) when HD44780 is used in 8 bit mode") + } + return newGPIO(dataPins, e, rs, rw, DATA_LENGTH_8BIT), nil +} + // Configure initializes device func (d *Device) Configure(cfg Config) error { d.busyStatus = make([]byte, 1) @@ -205,15 +204,11 @@ func (d *Device) CreateCharacter(cgramAddr uint8, data []byte) { // Busy returns true when hd447890 is busy func (d *Device) Busy() bool { + d.bus.SetCommandMode(true) d.bus.Read(d.busyStatus) return (d.busyStatus[0] & BUSY) > 0 } -// SetPixel is not supported on devices which uses HD44780 driver -func (d *Device) SetPixel(x, y int16, c color.RGBA) { - panic("HD44780 does not support setting individual pixels") -} - // Size returns the current size of the display. func (d *Device) Size() (w, h int16) { return int16(d.width), int16(d.height)