@@ -17,6 +17,8 @@ type WS2812B struct {
17
17
}
18
18
19
19
func NewWS2812B (sm pio.StateMachine , pin machine.Pin ) (* WS2812B , error ) {
20
+ // See ws2812b.pio for more information on how the timings are calculated.
21
+ // WS2812B Datasheet:
20
22
// https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf
21
23
const (
22
24
baseline = 1250.
@@ -78,7 +80,7 @@ func (ws *WS2812B) PutColor(c color.Color) {
78
80
}
79
81
80
82
// WriteRaw writes raw GRB values to a strip of WS2812B LEDs. Each uint32 is a WS2812B color
81
- // which can be created with 3 uint8 color values::
83
+ // which can be created with 3 uint8 color values:
82
84
//
83
85
// color := uint32(g)<<24 | uint32(r)<<16 | uint32(b)<<8
84
86
func (ws * WS2812B ) WriteRaw (rawGRB []uint32 ) error {
@@ -101,25 +103,6 @@ func (ws *WS2812B) WriteRaw(rawGRB []uint32) error {
101
103
return nil
102
104
}
103
105
104
- // EnableDMA enables DMA for vectorized writes.
105
- func (ws * WS2812B ) EnableDMA (enabled bool ) error {
106
- dmaAlreadyEnabled := ws .IsDMAEnabled ()
107
- if ! enabled || dmaAlreadyEnabled {
108
- if ! enabled && dmaAlreadyEnabled {
109
- ws .dma .Unclaim ()
110
- ws .dma = dmaChannel {} // Invalidate DMA channel.
111
- }
112
- return nil
113
- }
114
- channel , ok := _DMA .ClaimChannel ()
115
- if ! ok {
116
- return errDMAUnavail
117
- }
118
- channel .dl = ws .dma .dl // Copy deadline.
119
- ws .dma = channel
120
- return nil
121
- }
122
-
123
106
func (ws * WS2812B ) writeDMA (w []uint32 ) error {
124
107
dreq := dmaPIO_TxDREQ (ws .sm )
125
108
err := ws .dma .Push32 (& ws .sm .TxReg ().Reg , w , dreq )
@@ -129,7 +112,12 @@ func (ws *WS2812B) writeDMA(w []uint32) error {
129
112
return nil
130
113
}
131
114
115
+ // EnableDMA enables DMA for vectorized writes.
116
+ func (ws * WS2812B ) EnableDMA (enabled bool ) error {
117
+ return ws .dma .helperEnableDMA (enabled )
118
+ }
119
+
132
120
// IsDMAEnabled returns true if DMA is enabled.
133
121
func (ws * WS2812B ) IsDMAEnabled () bool {
134
- return ws .dma .IsValid ()
122
+ return ws .dma .helperIsEnabled ()
135
123
}
0 commit comments