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
- Variables
- type AS1130
- func (a *AS1130) Close() error
- func (a *AS1130) Init(blinkAndPWMSets uint8) error
- func (a *AS1130) InterruptStatus() (Interrupt, error)
- func (a *AS1130) MaxFrames() (uint8, error)
- func (a *AS1130) Read(register, subregister byte) (byte, error)
- func (a *AS1130) Reset() error
- func (a *AS1130) SetBlinkAndPWMSet(set uint8, blink Framer, pwm Framer) error
- func (a *AS1130) SetClockSync(c ClockSync) error
- func (a *AS1130) SetConfig(c Config) error
- func (a *AS1130) SetCurrentSource(milliAmps byte) error
- func (a *AS1130) SetDisplayOption(d DisplayOption) error
- func (a *AS1130) SetFrame(frame uint8, img Framer) error
- func (a *AS1130) SetFrameTime(f FrameTime) error
- func (a *AS1130) SetInterruptFrame(lastFrame uint8) error
- func (a *AS1130) SetInterruptMask(i Interrupt) error
- func (a *AS1130) SetMovie(m Movie) error
- func (a *AS1130) SetMovieMode(m MovieMode) error
- func (a *AS1130) SetPicture(p Picture) error
- func (a *AS1130) SetShutdown(s Shutdown) error
- func (a *AS1130) Start() error
- func (a *AS1130) Status() (Status, error)
- func (a *AS1130) Write(register, subregister, data byte) error
- type ClockFreq
- type ClockSync
- type Config
- type DisplayOption
- type Frame12x11
- type Frame24x5
- type FrameTime
- type Framer
- type Interrupt
- type Movie
- type MovieMode
- type Picture
- type Shutdown
- type Status
Constants ¶
const ( DeviceDefault = "/dev/i2c-1" AddressDefault = 0x30 CurrentSourceDefault = 5 )
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)
const ( ControlPicture byte = iota ControlMovie ControlMovieMode ControlFrameTime ControlDisplayOption ControlCurrentSource ControlConfig ControlInterruptMask ControlInterruptFrame ControlShutdown ControlI2CMonitoring ControlClockSync ControlInterruptStatus ControlStatus )
Control Register Address Map (datasheet fig. 38)
const ( FrameSegmentFirst byte = 0x00 FrameSegmentLast byte = 0x17 )
LEDs On/Off Frame Register Format (fig. 34) and LEDs Blink Frame Register Format (fig. 35)
const ( PWMSegmentFirst byte = 0x18 PWMSegmentLast byte = 0x9B )
LEDs PWM Register Format (fig. 36)
Variables ¶
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 ¶
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) Init ¶
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 ¶
InterruptStatus returns the contents of the interrupt status register.
func (*AS1130) MaxFrames ¶
MaxFrames returns the total amount of frames that you can use after Config.BlinkAndPWMSets has been set.
func (*AS1130) Reset ¶
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 ¶
SetBlinkAndPWMSet sets a blink and PWM set.
func (*AS1130) SetClockSync ¶
SetClockSync sets the Clock Synchronization register.
func (*AS1130) SetConfig ¶
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 ¶
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) SetFrameTime ¶
SetFrameTime sets the frame time register.
func (*AS1130) SetInterruptFrame ¶
SetInterruptFrame sets the interrupt frame register. This should be used in combination with Interrupt.Frame
func (*AS1130) SetInterruptMask ¶
SetInterruptMask sets the interrupt mask register.
func (*AS1130) SetMovieMode ¶
SetMovieMode sets the movie mode register.
func (*AS1130) SetPicture ¶
SetPicture sets the picture register.
func (*AS1130) SetShutdown ¶
SetShutdown sets the shutdown register.
func (*AS1130) Start ¶
Start takes the device out of shutdown mode, enables the display, and starts the state machine.
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 ¶
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 ¶
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 ¶
TextFrames renders some text into a slice of frames that can be scrolled across a 24x5 display.
func (*Frame24x5) OnOffBytes ¶
OnOffBytes renders On/Off LED data. Pixels with colour values greater than 0 are considered on or blinking.
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)