Back to godoc.org

Package hd44780

v0.0.0-...-d3d8c0c
Latest Go to latest

The latest major version is .

Published: May 8, 2017 | License: MIT | Module: github.com/kidoman/embd

Overview

Package hd44780 allows controlling an HD44780-compatible character LCD controller. Currently the library is write-only and does not support reading from the display controller.

Resources

This library is based three other HD44780 libraries:

Adafruit	https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/blob/master/Adafruit_CharLCD/Adafruit_CharLCD.py
hwio		https://github.com/mrmorphic/hwio/blob/master/devices/hd44780/hd44780_i2c.go
LiquidCrystal	https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp

Index

Variables

var DefaultModes []ModeSetter = []ModeSetter{
	FourBitMode,
	OneLine,
	Dots5x8,
	EntryIncrement,
	EntryShiftOff,
	DisplayOn,
	CursorOff,
	BlinkOff,
}

DefaultModes are the default initialization modes for an HD44780. ModeSetters passed in to a constructor will override these default values.

func BlinkOff

func BlinkOff(hd *HD44780)

BlinkOff is a ModeSetter that sets the HD44780 to cursor blink off mode.

func BlinkOn

func BlinkOn(hd *HD44780)

BlinkOn is a ModeSetter that sets the HD44780 to cursor blink on mode.

func CursorOff

func CursorOff(hd *HD44780)

CursorOff is a ModeSetter that sets the HD44780 to cursor off mode.

func CursorOn

func CursorOn(hd *HD44780)

CursorOn is a ModeSetter that sets the HD44780 to cursor on mode.

func DisplayOff

func DisplayOff(hd *HD44780)

DisplayOff is a ModeSetter that sets the HD44780 to display off mode.

func DisplayOn

func DisplayOn(hd *HD44780)

DisplayOn is a ModeSetter that sets the HD44780 to display on mode.

func Dots5x10

func Dots5x10(hd *HD44780)

Dots5x10 is a ModeSetter that sets the HD44780 to 5x10-pixel character mode.

func Dots5x8

func Dots5x8(hd *HD44780)

Dots5x8 is a ModeSetter that sets the HD44780 to 5x8-pixel character mode.

func EightBitMode

func EightBitMode(hd *HD44780)

EightBitMode is a ModeSetter that sets the HD44780 to 8-bit bus mode.

func EntryDecrement

func EntryDecrement(hd *HD44780)

EntryDecrement is a ModeSetter that sets the HD44780 to entry decrement mode.

func EntryIncrement

func EntryIncrement(hd *HD44780)

EntryIncrement is a ModeSetter that sets the HD44780 to entry increment mode.

func EntryShiftOff

func EntryShiftOff(hd *HD44780)

EntryShiftOff is a ModeSetter that sets the HD44780 to entry shift off mode.

func EntryShiftOn

func EntryShiftOn(hd *HD44780)

EntryShiftOn is a ModeSetter that sets the HD44780 to entry shift on mode.

func FourBitMode

func FourBitMode(hd *HD44780)

FourBitMode is a ModeSetter that sets the HD44780 to 4-bit bus mode.

func OneLine

func OneLine(hd *HD44780)

OneLine is a ModeSetter that sets the HD44780 to 1-line display mode.

func TwoLine

func TwoLine(hd *HD44780)

TwoLine is a ModeSetter that sets the HD44780 to 2-line display mode.

type BacklightPolarity

type BacklightPolarity bool

BacklightPolarity is used to set the polarity of the backlight switch, either positive or negative.

const (
	// Negative indicates that the backlight is active-low and must have a logical low value to enable.
	Negative BacklightPolarity = false
	// Positive indicates that the backlight is active-high and must have a logical high value to enable.
	Positive BacklightPolarity = true
)

type Connection

type Connection interface {
	// Write writes a byte to the HD44780 controller with the register select
	// flag either on or off.
	Write(rs bool, data byte) error

	// BacklightOff turns the optional backlight off.
	BacklightOff() error

	// BacklightOn turns the optional backlight on.
	BacklightOn() error

	// Close closes all open resources.
	Close() error
}

Connection abstracts the different methods of communicating with an HD44780.

type GPIOConnection

type GPIOConnection struct {
	RS, EN         embd.DigitalPin
	D4, D5, D6, D7 embd.DigitalPin
	Backlight      embd.DigitalPin
	BLPolarity     BacklightPolarity
}

GPIOConnection implements Connection using a 4-bit GPIO bus.

func NewGPIOConnection

func NewGPIOConnection(
	rs, en, d4, d5, d6, d7, backlight embd.DigitalPin,
	blPolarity BacklightPolarity,
) *GPIOConnection

NewGPIOConnection returns a new Connection based on a 4-bit GPIO bus.

func (*GPIOConnection) BacklightOff

func (conn *GPIOConnection) BacklightOff() error

BacklightOff turns the optional backlight off.

func (*GPIOConnection) BacklightOn

func (conn *GPIOConnection) BacklightOn() error

BacklightOn turns the optional backlight on.

func (*GPIOConnection) Close

func (conn *GPIOConnection) Close() error

Close closes all open DigitalPins.

func (*GPIOConnection) Write

func (conn *GPIOConnection) Write(rs bool, data byte) error

Write writes a register select flag and byte to the 4-bit GPIO connection.

type HD44780

type HD44780 struct {
	Connection
	// contains filtered or unexported fields
}

HD44780 represents an HD44780-compatible character LCD controller.

func New

func New(bus Connection, rowAddr RowAddress, modes ...ModeSetter) (*HD44780, error)

New creates a new HD44780 connected by a Connection bus.

func NewGPIO

func NewGPIO(
	rs, en, d4, d5, d6, d7, backlight interface{},
	blPolarity BacklightPolarity,
	rowAddr RowAddress,
	modes ...ModeSetter,
) (*HD44780, error)

NewGPIO creates a new HD44780 connected by a 4-bit GPIO bus.

func NewI2C

func NewI2C(
	i2c embd.I2CBus,
	addr byte,
	pinMap I2CPinMap,
	rowAddr RowAddress,
	modes ...ModeSetter,
) (*HD44780, error)

NewI2C creates a new HD44780 connected by an I²C bus.

func (*HD44780) BlinkEnabled

func (hd *HD44780) BlinkEnabled() bool

BlinkEnabled returns true if the cursor blink mode is enabled.

func (*HD44780) BlinkOff

func (hd *HD44780) BlinkOff() error

BlinkOff sets cursor blink mode off.

func (*HD44780) BlinkOn

func (hd *HD44780) BlinkOn() error

BlinkOn sets cursor blink mode on.

func (*HD44780) Clear

func (hd *HD44780) Clear() error

Clear clears the display and mode settings sets the cursor to the home position.

func (*HD44780) Close

func (hd *HD44780) Close() error

Close closes the underlying Connection.

func (*HD44780) CursorEnabled

func (hd *HD44780) CursorEnabled() bool

CursorEnabled returns true if the cursor is on.

func (*HD44780) CursorOff

func (hd *HD44780) CursorOff() error

CursorOff turns the cursor off.

func (*HD44780) CursorOn

func (hd *HD44780) CursorOn() error

CursorOn turns the cursor on.

func (*HD44780) DisplayEnabled

func (hd *HD44780) DisplayEnabled() bool

DisplayEnabled returns true if the display is on.

func (*HD44780) DisplayOff

func (hd *HD44780) DisplayOff() error

DisplayOff sets the display mode to off.

func (*HD44780) DisplayOn

func (hd *HD44780) DisplayOn() error

DisplayOn sets the display mode to on.

func (*HD44780) Dots5x10Enabled

func (hd *HD44780) Dots5x10Enabled() bool

Dots5x10Enabled returns true if 5x10-pixel characters are enabled.

func (*HD44780) EightBitModeEnabled

func (hd *HD44780) EightBitModeEnabled() bool

EightBitModeEnabled returns true if 8-bit bus mode is enabled and false if 4-bit bus mode is enabled.

func (*HD44780) EntryIncrementEnabled

func (hd *HD44780) EntryIncrementEnabled() bool

EntryIncrementEnabled returns true if entry increment mode is enabled.

func (*HD44780) EntryShiftEnabled

func (hd *HD44780) EntryShiftEnabled() bool

EntryShiftEnabled returns true if entry shift mode is enabled.

func (*HD44780) Home

func (hd *HD44780) Home() error

Home moves the cursor and all characters to the home position.

func (*HD44780) SetCursor

func (hd *HD44780) SetCursor(col, row int) error

SetCursor sets the input cursor to the given position.

func (*HD44780) SetDDRamAddr

func (hd *HD44780) SetDDRamAddr(value byte) error

SetDDRamAddr sets the input cursor to the given address.

func (*HD44780) SetMode

func (hd *HD44780) SetMode(modes ...ModeSetter) error

SetModes modifies the entry mode, display mode, and function mode with the given mode setter functions.

func (*HD44780) ShiftLeft

func (hd *HD44780) ShiftLeft() error

ShiftLeft shifts the cursor and all characters to the left.

func (*HD44780) ShiftRight

func (hd *HD44780) ShiftRight() error

ShiftRight shifts the cursor and all characters to the right.

func (*HD44780) TwoLineEnabled

func (hd *HD44780) TwoLineEnabled() bool

TwoLineEnabled returns true if 2-line display mode is enabled and false if 1-line display mode is enabled.

func (*HD44780) WriteChar

func (hd *HD44780) WriteChar(value byte) error

WriteInstruction writes a byte to the bus with register select in data mode.

func (*HD44780) WriteInstruction

func (hd *HD44780) WriteInstruction(value byte) error

WriteInstruction writes a byte to the bus with register select in command mode.

type I2CConnection

type I2CConnection struct {
	I2C       embd.I2CBus
	Addr      byte
	PinMap    I2CPinMap
	Backlight bool
}

I2CConnection implements Connection using an I²C bus.

func NewI2CConnection

func NewI2CConnection(i2c embd.I2CBus, addr byte, pinMap I2CPinMap) *I2CConnection

NewI2CConnection returns a new Connection based on an I²C bus.

func (*I2CConnection) BacklightOff

func (conn *I2CConnection) BacklightOff() error

BacklightOff turns the optional backlight off.

func (*I2CConnection) BacklightOn

func (conn *I2CConnection) BacklightOn() error

BacklightOn turns the optional backlight on.

func (*I2CConnection) Close

func (conn *I2CConnection) Close() error

Close closes the I²C connection.

func (*I2CConnection) Write

func (conn *I2CConnection) Write(rs bool, data byte) error

Write writes a register select flag and byte to the I²C connection.

type I2CPinMap

type I2CPinMap struct {
	RS, RW, EN     byte
	D4, D5, D6, D7 byte
	Backlight      byte
	BLPolarity     BacklightPolarity
}

I2CPinMap represents a mapping between the pins on an I²C port expander and the pins on the HD44780 controller.

var (
	// MJKDZPinMap is the standard pin mapping for an MJKDZ-based I²C backpack.
	MJKDZPinMap I2CPinMap = I2CPinMap{
		RS: 6, RW: 5, EN: 4,
		D4: 0, D5: 1, D6: 2, D7: 3,
		Backlight:  7,
		BLPolarity: Negative,
	}
	// PCF8574PinMap is the standard pin mapping for a PCF8574-based I²C backpack.
	PCF8574PinMap I2CPinMap = I2CPinMap{
		RS: 0, RW: 1, EN: 2,
		D4: 4, D5: 5, D6: 6, D7: 7,
		Backlight:  3,
		BLPolarity: Positive,
	}
)

type ModeSetter

type ModeSetter func(*HD44780)

ModeSetter defines a function used for setting modes on an HD44780. ModeSetters must be used with the SetMode function or in a constructor.

type RowAddress

type RowAddress [4]byte

RowAddress defines the cursor (DDRAM) address of the first column of each row, up to 4 rows. You must use the RowAddress value that matches the number of columns on your character display for the SetCursor function to work correctly.

var (
	// RowAddress16Col are row addresses for a 16-column display
	RowAddress16Col RowAddress = [4]byte{0x00, 0x40, 0x10, 0x50}
	// RowAddress20Col are row addresses for a 20-column display
	RowAddress20Col RowAddress = [4]byte{0x00, 0x40, 0x14, 0x54}
)

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier