as1130

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2017 License: MIT Imports: 13 Imported by: 0

README

Documentation Build Status

AS1130

Go library for the AS1130 LED driver, as used by The Matrix from Boldport.

It can be used from hardware that supports I²C such as a Raspberry Pi.

as1130 text scrolling

Library

To fetch the library:

go get -u github.com/dcarley/as1130

Refer to godoc for documentation and examples.

CLI

The as1130ctl command line utility lets you:

  • turn on individual LEDs
  • scroll text
  • read registers
  • and more

To fetch and install it:

go get -u github.com/dcarley/as1130/as1130ctl

To see detailed usage information:

as1130ctl --help

Documentation

Overview

Package as1130 is a library for controlling the AS1130 LED driver, as used by The Matrix from Boldport.

Configuration

The device is configured using registers. Each register is represented as a struct with descriptive field names, comments, and default values. The struct can be passed to the corresponding Set method.

You may also wish to refer to the datasheet: http://ams.com/eng/content/download/185846/834724/105034

Connecting

To connect using the default device path and address:

as, err := as1130.NewAS1130("", 0)

If you need to use another path or address:

as, err := as1130.NewAS1130("/dev/i2c-2", 0x31)

Initialisation

It's advisable to reset the device before using it:

err = as.Reset()

After which you must choose how many blink and PWM sets you want to use and perform the startup sequence. There's a helper method to make this easier:

err = as.Init(1)

Or you can call SetConfig(), SetCurrentSource() and SetDisplayOption() yourself if you need more control.

Frames

Frames are defined as grayscale images. They can be manipulated using standard Go image libraries:

ledsOn := as1130.NewFrame24x5()
draw.Draw(ledsOn, ledsOn.Bounds(), &image.Uniform{as1130.On}, image.ZP, draw.Src)
err = as.SetFrame(1, ledsOn)

Each frame is associated with blink and PWM set, which defines flashing and intensity for individual LEDs. You should set the first (default) blink and PWM set at a minimum:

noBlink , pwmFull := as1130.NewFrame24x5(), as1130.NewFrame24x5()
draw.Draw(pwm, pwm.Bounds(), &image.Uniform{as1130.On}, image.ZP, draw.Src)
err = as.SetBlinkAndPWMSet(1, noBlink, pwmFull)

Pictures

An individual frame can be displayed in picture mode:

err = as.SetPicture(as1130.Picture{Display: true})

Movies

Multiple frames can be displayed in movie mode:

err = as.SetMovie(as1130.Movie{Display: true})
err = as.SetMovieMode(as1130.MovieMode{Frames: 2})

Start

When you have finished setting all of the frames you can turn on the display:

err = as.Start()

Examples

Have a look at the as1130ctl sub-package for more complete examples.

Index

Constants

View Source
const (
	DeviceDefault        = "/dev/i2c-1"
	AddressDefault       = 0x30
	CurrentSourceDefault = 5
)
View Source
const (
	RegisterOnOffFrameFirst    byte = 0x01
	RegisterOnOffFrameLast     byte = 0x24
	RegisterBlinkPWMFrameFirst byte = 0x40
	RegisterBlinkPWMFrameLast  byte = 0x45
	RegisterControl            byte = 0xC0
	RegisterSelect             byte = 0xFD
)

Register Selection Address Map (datasheet fig. 31)

View Source
const (
	ControlPicture byte = iota
	ControlMovie
	ControlMovieMode
	ControlFrameTime
	ControlDisplayOption
	ControlCurrentSource
	ControlConfig
	ControlInterruptMask
	ControlInterruptFrame
	ControlShutdown
	ControlI2CMonitoring
	ControlClockSync
	ControlInterruptStatus
	ControlStatus
)

Control Register Address Map (datasheet fig. 38)

View Source
const (
	FrameSegmentFirst byte = 0x00
	FrameSegmentLast  byte = 0x17
)

LEDs On/Off Frame Register Format (fig. 34) and LEDs Blink Frame Register Format (fig. 35)

View Source
const (
	PWMSegmentFirst byte = 0x18
	PWMSegmentLast  byte = 0x9B
)

LEDs PWM Register Format (fig. 36)

Variables

View Source
var (
	Off = color.Gray{0}   // Min off
	On  = color.Gray{255} // Max on
)

Functions

This section is empty.

Types

type AS1130

type AS1130 struct {
	// contains filtered or unexported fields
}

AS1130 is a connected controller.

func NewAS1130

func NewAS1130(device string, address int) (*AS1130, error)

NewAS1130 opens a connection to an AS1130 controller. If `device` or `address` are zero values for their type then the defaults will be used. You must call Close() when you're done.

func (*AS1130) Close

func (a *AS1130) Close() error

Close closes the connection to an AS1130 controller.

func (*AS1130) Init

func (a *AS1130) Init(blinkAndPWMSets uint8) error

Init performs the startup sequence with default settings. You still need to call Start() when all frames and related settings have been set.

func (*AS1130) InterruptStatus

func (a *AS1130) InterruptStatus() (Interrupt, error)

InterruptStatus returns the contents of the interrupt status register.

func (*AS1130) MaxFrames

func (a *AS1130) MaxFrames() (uint8, error)

MaxFrames returns the total amount of frames that you can use after Config.BlinkAndPWMSets has been set.

func (*AS1130) Read

func (a *AS1130) Read(register, subregister byte) (byte, error)

Read a register from the AS1130.

func (*AS1130) Reset

func (a *AS1130) Reset() error

Reset performs a soft reset of the device. It shuts down the outputs and state machine, then waits for the device to become ready again. Not all registers are reset. You will need to call Init() afterwards.

func (*AS1130) SetBlinkAndPWMSet

func (a *AS1130) SetBlinkAndPWMSet(set uint8, blink Framer, pwm Framer) error

SetBlinkAndPWMSet sets a blink and PWM set.

func (*AS1130) SetClockSync

func (a *AS1130) SetClockSync(c ClockSync) error

SetClockSync sets the Clock Synchronization register.

func (*AS1130) SetConfig

func (a *AS1130) SetConfig(c Config) error

SetConfig sets the config register. The config cannot be changed once you have written any frame data, you will need to hard reset the device.

func (*AS1130) SetCurrentSource

func (a *AS1130) SetCurrentSource(milliAmps byte) error

SetCurrentSource sets the current (mA) for all LEDs.

func (*AS1130) SetDisplayOption

func (a *AS1130) SetDisplayOption(d DisplayOption) error

SetDisplayOption sets the display option.

func (*AS1130) SetFrame

func (a *AS1130) SetFrame(frame uint8, img Framer) error

SetFrame sets an On/Off frame.

func (*AS1130) SetFrameTime

func (a *AS1130) SetFrameTime(f FrameTime) error

SetFrameTime sets the frame time register.

func (*AS1130) SetInterruptFrame

func (a *AS1130) SetInterruptFrame(lastFrame uint8) error

SetInterruptFrame sets the interrupt frame register. This should be used in combination with Interrupt.Frame

func (*AS1130) SetInterruptMask

func (a *AS1130) SetInterruptMask(i Interrupt) error

SetInterruptMask sets the interrupt mask register.

func (*AS1130) SetMovie

func (a *AS1130) SetMovie(m Movie) error

SetMovie sets the movie register.

func (*AS1130) SetMovieMode

func (a *AS1130) SetMovieMode(m MovieMode) error

SetMovieMode sets the movie mode register.

func (*AS1130) SetPicture

func (a *AS1130) SetPicture(p Picture) error

SetPicture sets the picture register.

func (*AS1130) SetShutdown

func (a *AS1130) SetShutdown(s Shutdown) error

SetShutdown sets the shutdown register.

func (*AS1130) Start

func (a *AS1130) Start() error

Start takes the device out of shutdown mode, enables the display, and starts the state machine.

func (*AS1130) Status

func (a *AS1130) Status() (Status, error)

Status returns the contents of the status register.

func (*AS1130) Write

func (a *AS1130) Write(register, subregister, data byte) error

Write sends a command to the AS1130.

type ClockFreq

type ClockFreq byte

ClockFreq is a clock frequency value.

const (
	Clock1MHz ClockFreq = iota
	Clock500kHz
	Clock125kHz
	Clock32kHz
)

Clock synchronization frequencies.

type ClockSync

type ClockSync struct {
	ClockOutFreq ClockFreq // Adjustable clock out frequency
	SyncOut      bool      // Internal oscillator is used and made available on the SYNC pin
	SyncIn       bool      // Internal oscillator is disabled and input from SYNC pin is used
}

CLK Synchronization Register Format (datasheet fig. 50)

type Config

type Config struct {
	LowVDDReset        bool  // Reset LowVDD at end of movie or picture
	LowVDDStatus       bool  // Map LowVDD to IRQ pin
	LEDErrorCorrection bool  // Disable open LEDs
	DotCorrection      bool  // Analog current DotCorrection
	CommonAddress      bool  // I2C common address for all AS1130
	BlinkAndPWMSets    uint8 // Number of blink and PWM sets, 1 if unset, each uses 6 On/Off frames
}

Config Register Format (datasheet fig. 45)

type DisplayOption

type DisplayOption struct {
	Loops          uint8 // Number of loops played in one movie, forever (7) if unset
	BlinkFrequency bool  // Blink every 3s instead of 1.5s
	ScanLimit      uint8 // Number of displayed segments in one frame, all (12) if unset
}

DisplayOption Register Format (datasheet fig. 43)

type Frame12x11

type Frame12x11 struct {
	*image.Gray
	// contains filtered or unexported fields
}

Frame12x11 is a frame for a 12x11 matrix with every LED connected.

func NewFrame12x11

func NewFrame12x11() *Frame12x11

NewFrame12x11 creates a new Frame12x11 of the correct size.

func (*Frame12x11) OnOffBytes

func (f *Frame12x11) OnOffBytes() ([24]byte, error)

OnOffBytes renders On/Off LED data. Pixels with colour values greater than 0 are considered on or blinking.

func (*Frame12x11) PWMBytes

func (f *Frame12x11) PWMBytes() ([132]byte, error)

PWMBytes renders PWM (brightness) LED data. Each pixel has 255 steps.

func (*Frame12x11) PWMSet

func (f *Frame12x11) PWMSet() uint8

PWMSet returns the PWM set associated with the frame.

func (*Frame12x11) SetPWMSet

func (f *Frame12x11) SetPWMSet(set uint8)

SetPWMSet sets the PWM set to associate with the frame.

type Frame24x5

type Frame24x5 struct {
	*image.Gray
	// contains filtered or unexported fields
}

Frame24x5 is a frame for a 24x5 matrix where the last LED in each segment is disconnected.

func NewFrame24x5

func NewFrame24x5() *Frame24x5

NewFrame24x5 creates a new Frame24x5 of the correct size.

func TextFrames

func TextFrames(text string) ([]*Frame24x5, error)

TextFrames renders some text into a slice of frames that can be scrolled across a 24x5 display.

func (*Frame24x5) OnOffBytes

func (f *Frame24x5) OnOffBytes() ([24]byte, error)

OnOffBytes renders On/Off LED data. Pixels with colour values greater than 0 are considered on or blinking.

func (*Frame24x5) PWMBytes

func (f *Frame24x5) PWMBytes() ([132]byte, error)

PWMBytes renders PWM (brightness) LED data. Each pixel has 255 steps.

func (*Frame24x5) PWMSet

func (f *Frame24x5) PWMSet() uint8

PWMSet returns the PWM set associated with the frame.

func (*Frame24x5) SetPWMSet

func (f *Frame24x5) SetPWMSet(set uint8)

SetPWMSet sets the PWM set to associate with the frame.

type FrameTime

type FrameTime struct {
	Fade        bool  // Fade at end of frame
	ScrollRight bool  // Scroll right instead of left
	Scroll12x11 bool  // Scroll in 12x11 mode instead of 24x5
	Scrolling   bool  // Scroll digits at play movie
	Delay       uint8 // Delay between frame change in a movie, multiple of 32.5ms
}

FrameTime & Scroll Register Format (datasheet fig. 42)

type Framer

type Framer interface {
	draw.Image
	OnOffBytes() ([24]byte, error)
	PWMBytes() ([132]byte, error)
	SetPWMSet(uint8)
	PWMSet() uint8
}

Framer renders an image into frame data.

type Interrupt

type Interrupt struct {
	Frame        bool // Trigger IRQ when frame defined by SetInterruptFrame is displayed
	Watchdog     bool // Trigger IRQ when the I²C watchdog triggers
	PowerOrReset bool // Trigger IRQ when power or reset has occurred
	OverTemp     bool // Trigger IRQ when the overtemperature limit is reached
	LowVDD       bool // Trigger IRQ when VDD is too low for used LEDs
	OpenError    bool // Trigger IRQ when an error on the open test occurs
	ShortError   bool // Trigger IRQ when an error on the short test occurs
	MovieFinish  bool // Trigger IRQ when movie is finished
}

Interrupt Mask Register Format (datasheet fig. 46) and Interrupt Status Register Format (datasheet fig. 51)

type Movie

type Movie struct {
	Blink   bool  // All LEDs in blink mode during play movie
	Display bool  // Display movie
	Frame   uint8 // Number of first frame in movie, 1 if unset
}

Movie Register Format (datasheet fig. 40)

type MovieMode

type MovieMode struct {
	Blink   bool  // All LEDs in blink mode during play movie
	EndLast bool  // End movie with last frame instead of first
	Frames  uint8 // Number of frames to play in movie, 1 if unset
}

MovieMode Register Format (datasheet fig. 41)

type Picture

type Picture struct {
	Blink   bool  // All LEDs in blink mode during display picture
	Display bool  // Display picture
	Frame   uint8 // Number of picture frame, 1 if unset
}

Picture Register Format (datasheet fig. 39)

type Shutdown

type Shutdown struct {
	TestAll    bool // LED open/short test is performed on all LED locations
	AutoTest   bool // Automatic LED open/short test is started when picture or movie is displayed
	ManualTest bool // Manual LED open/short test is started after updating shutdown register
	Initialise bool // Initialise control logic (internal state machine is reset again)
	Shutdown   bool // Put device in shutdown mode (outputs are turned off, internal state machine stops)
}

Shutdown & Open/Short Register Format (datasheet fig. 48)

type Status

type Status struct {
	Frame uint8 // Currently displayed frame
	Movie bool  // Movie playing
	Test  bool  // Test running
}

Status Register Format (datasheet fig. 52)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL