kopia lustrzana https://github.com/blaz-r/pi_pico_neopixel
Merge branch 'main' into dma_solution
commit
ea8b554cee
17
neopixel.py
17
neopixel.py
|
@ -1,5 +1,5 @@
|
|||
import array, time
|
||||
from machine import Pin
|
||||
from machine import Pin, enable_irq, disable_irq
|
||||
import rp2
|
||||
|
||||
|
||||
|
@ -73,7 +73,7 @@ class Neopixel:
|
|||
# 'brightnessvalue', # brightness scale factor 1..255
|
||||
# ]
|
||||
|
||||
def __init__(self, num_leds, state_machine, pin, mode="RGB", delay=0.0003):
|
||||
def __init__(self, num_leds, state_machine, pin, mode="RGB", delay=0.0003, critical=False):
|
||||
"""
|
||||
Constructor for library class
|
||||
|
||||
|
@ -83,6 +83,8 @@ class Neopixel:
|
|||
:param mode: [default: "RGB"] mode and order of bits representing the color value.
|
||||
This can be any order of RGB or RGBW (neopixels are usually GRB)
|
||||
:param delay: [default: 0.0001] delay used for latching of leds when sending data
|
||||
:param critical: [default: False] if True, disable interrupts while sending data to the PIO
|
||||
This will eliminate glitching tearing, but could be a problem is have other high priority interrupts
|
||||
"""
|
||||
self.pixels = array.array("I", [0] * num_leds)
|
||||
self.mode = mode
|
||||
|
@ -104,6 +106,7 @@ class Neopixel:
|
|||
self.dma = rp2.DMA()
|
||||
DATA_REQUEST_INDEX = (pin << 3) + state_machine
|
||||
self.dma_ctrl = self.dma.pack_ctrl(size=2, inc_write=False, treq_sel=DATA_REQUEST_INDEX)
|
||||
self.critical = critical
|
||||
|
||||
def brightness(self, brightness=None):
|
||||
"""
|
||||
|
@ -344,7 +347,12 @@ class Neopixel:
|
|||
cut = 8
|
||||
if self.W_in_mode:
|
||||
cut = 0
|
||||
|
||||
|
||||
if self.critical:
|
||||
irq_state = disable_irq()
|
||||
|
||||
self.sm.put(self.pixels, cut)
|
||||
|
||||
data = array.array('I',self.pixels)
|
||||
for i,_ in enumerate(data):
|
||||
data[i] <<= cut
|
||||
|
@ -358,6 +366,9 @@ class Neopixel:
|
|||
while self.dma.active():
|
||||
pass
|
||||
|
||||
if self.critical:
|
||||
enable_irq(irq_state)
|
||||
|
||||
time.sleep(self.delay)
|
||||
|
||||
def fill(self, rgb_w, how_bright=None):
|
||||
|
|
Ładowanie…
Reference in New Issue