embd: github.com/kidoman/embd/controller/hd44780 Index | Files

package hd44780

import "github.com/kidoman/embd/controller/hd44780"

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

Package Files

hd44780.go

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 Uses

func BlinkOff(hd *HD44780)

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

func BlinkOn Uses

func BlinkOn(hd *HD44780)

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

func CursorOff Uses

func CursorOff(hd *HD44780)

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

func CursorOn Uses

func CursorOn(hd *HD44780)

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

func DisplayOff Uses

func DisplayOff(hd *HD44780)

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

func DisplayOn Uses

func DisplayOn(hd *HD44780)

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

func Dots5x10 Uses

func Dots5x10(hd *HD44780)

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

func Dots5x8 Uses

func Dots5x8(hd *HD44780)

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

func EightBitMode Uses

func EightBitMode(hd *HD44780)

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

func EntryDecrement Uses

func EntryDecrement(hd *HD44780)

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

func EntryIncrement Uses

func EntryIncrement(hd *HD44780)

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

func EntryShiftOff Uses

func EntryShiftOff(hd *HD44780)

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

func EntryShiftOn Uses

func EntryShiftOn(hd *HD44780)

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

func FourBitMode Uses

func FourBitMode(hd *HD44780)

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

func OneLine Uses

func OneLine(hd *HD44780)

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

func TwoLine Uses

func TwoLine(hd *HD44780)

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

type BacklightPolarity Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (conn *GPIOConnection) BacklightOff() error

BacklightOff turns the optional backlight off.

func (*GPIOConnection) BacklightOn Uses

func (conn *GPIOConnection) BacklightOn() error

BacklightOn turns the optional backlight on.

func (*GPIOConnection) Close Uses

func (conn *GPIOConnection) Close() error

Close closes all open DigitalPins.

func (*GPIOConnection) Write Uses

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 Uses

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

HD44780 represents an HD44780-compatible character LCD controller.

func New Uses

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

New creates a new HD44780 connected by a Connection bus.

func NewGPIO Uses

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 Uses

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 Uses

func (hd *HD44780) BlinkEnabled() bool

BlinkEnabled returns true if the cursor blink mode is enabled.

func (*HD44780) BlinkOff Uses

func (hd *HD44780) BlinkOff() error

BlinkOff sets cursor blink mode off.

func (*HD44780) BlinkOn Uses

func (hd *HD44780) BlinkOn() error

BlinkOn sets cursor blink mode on.

func (*HD44780) Clear Uses

func (hd *HD44780) Clear() error

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

func (*HD44780) Close Uses

func (hd *HD44780) Close() error

Close closes the underlying Connection.

func (*HD44780) CursorEnabled Uses

func (hd *HD44780) CursorEnabled() bool

CursorEnabled returns true if the cursor is on.

func (*HD44780) CursorOff Uses

func (hd *HD44780) CursorOff() error

CursorOff turns the cursor off.

func (*HD44780) CursorOn Uses

func (hd *HD44780) CursorOn() error

CursorOn turns the cursor on.

func (*HD44780) DisplayEnabled Uses

func (hd *HD44780) DisplayEnabled() bool

DisplayEnabled returns true if the display is on.

func (*HD44780) DisplayOff Uses

func (hd *HD44780) DisplayOff() error

DisplayOff sets the display mode to off.

func (*HD44780) DisplayOn Uses

func (hd *HD44780) DisplayOn() error

DisplayOn sets the display mode to on.

func (*HD44780) Dots5x10Enabled Uses

func (hd *HD44780) Dots5x10Enabled() bool

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

func (*HD44780) EightBitModeEnabled Uses

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 Uses

func (hd *HD44780) EntryIncrementEnabled() bool

EntryIncrementEnabled returns true if entry increment mode is enabled.

func (*HD44780) EntryShiftEnabled Uses

func (hd *HD44780) EntryShiftEnabled() bool

EntryShiftEnabled returns true if entry shift mode is enabled.

func (*HD44780) Home Uses

func (hd *HD44780) Home() error

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

func (*HD44780) SetCursor Uses

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

SetCursor sets the input cursor to the given position.

func (*HD44780) SetDDRamAddr Uses

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

SetDDRamAddr sets the input cursor to the given address.

func (*HD44780) SetMode Uses

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 Uses

func (hd *HD44780) ShiftLeft() error

ShiftLeft shifts the cursor and all characters to the left.

func (*HD44780) ShiftRight Uses

func (hd *HD44780) ShiftRight() error

ShiftRight shifts the cursor and all characters to the right.

func (*HD44780) TwoLineEnabled Uses

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 Uses

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

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

func (*HD44780) WriteInstruction Uses

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

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

type I2CConnection Uses

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

I2CConnection implements Connection using an I²C bus.

func NewI2CConnection Uses

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

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

func (*I2CConnection) BacklightOff Uses

func (conn *I2CConnection) BacklightOff() error

BacklightOff turns the optional backlight off.

func (*I2CConnection) BacklightOn Uses

func (conn *I2CConnection) BacklightOn() error

BacklightOn turns the optional backlight on.

func (*I2CConnection) Close Uses

func (conn *I2CConnection) Close() error

Close closes the I²C connection.

func (*I2CConnection) Write Uses

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

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

type I2CPinMap Uses

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 Uses

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 Uses

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 hd44780 imports 3 packages (graph) and is imported by 2 packages. Updated 2016-10-23. Refresh now. Tools for package owners.