Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apa102: allow to specify SPI Mode in Opts #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions apa102/apa102.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ const NeutralTemp uint16 = 6500

// DefaultOpts is the recommended default options.
var DefaultOpts = Opts{
NumPixels: 150, // 150 LEDs is a common strip length.
Intensity: 255, // Full blinding power.
Temperature: 5000, // More pleasing white balance than NeutralTemp.
DisableGlobalPWM: false, // Use full 13 bits range.
NumPixels: 150, // 150 LEDs is a common strip length.
Intensity: 255, // Full blinding power.
Temperature: 5000, // More pleasing white balance than NeutralTemp.
DisableGlobalPWM: false, // Use full 13 bits range.
SpiMode: spi.Mode3, // SPI Mode3 works on most devices.
}

// PassThruOpts makes the driver draw RGB pixels exactly as specified.
Expand All @@ -51,6 +52,7 @@ var PassThruOpts = Opts{
Intensity: 255,
Temperature: NeutralTemp,
DisableGlobalPWM: true,
SpiMode: spi.Mode3,
}

// Opts defines the options for the device.
Expand Down Expand Up @@ -81,6 +83,12 @@ type Opts struct {
// to 8 bits, this also disables the dynamic perceptual mapping of intensity
// since there is not enough bits of resolution to do it effectively.
DisableGlobalPWM bool
// SpiMode sets the clock polarity and phase as one of the 4 possible SPI Modes.
//
// Most devices can use spi.Mode3, but the Raspberry Pi 3 secondary SPI port
// for example does not support this Mode. You may need to use spi.Mode0
// in this and similar cases.
SpiMode spi.Mode
}

// New returns a strip that communicates over SPI to APA102 LEDs.
Expand All @@ -93,7 +101,7 @@ type Opts struct {
// https://en.wikipedia.org/wiki/Flicker_fusion_threshold is a recommended
// reading.
func New(p spi.Port, o *Opts) (*Dev, error) {
c, err := p.Connect(20*physic.MegaHertz, spi.Mode3, 8)
c, err := p.Connect(20*physic.MegaHertz, o.SpiMode, 8)
if err != nil {
return nil, err
}
Expand Down