Skip to content

Commit a6f8d38

Browse files
committed
add pixels
1 parent 35a39ce commit a6f8d38

File tree

7 files changed

+105
-7
lines changed

7 files changed

+105
-7
lines changed

src/adafruit_blinka/board/generic_agnostic_board.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
Dx_INPUT_TRUE_PULL_DOWN = pin.D3
1212
Dx_OUTPUT = pin.D4
1313
Dx_INPUT_TOGGLE = pin.D7
14-
# Special "digital" pins
15-
NEOPIXEL = pin.D6
1614

15+
# Special digital pins for pixels
16+
NEOPIXEL = pin.D6
17+
DOTSTAR_DATA = pin.D8
18+
DOTSTAR_CLK = pin.D9
1719

1820
# Analog pins
1921
Ax_INPUT_RAND_INT = pin.A0
@@ -33,6 +35,9 @@
3335
MISO = pin.MISO
3436
CS = pin.D6
3537

38+
# SPI port
39+
spiPorts = ((0, SCK, MOSI, MISO),)
40+
3641
# UART pins
3742
UART_TX = pin.UART_TX
3843
UART_RX = pin.UART_RX
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-FileCopyrightText: 2024 Brent Rubell for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""NeoPixel write mocks for a generic board."""
5+
6+
7+
def neopixel_write(gpio, buf):
8+
"""Mocks a neopixel_write function"""
9+
# pad output buffer from 3 bpp to 4 bpp
10+
buffer = []
11+
for i in range(0, len(buf), 3):
12+
buffer.append(0)
13+
buffer.append(buf[i + 2])
14+
buffer.append(buf[i + 1])
15+
buffer.append(buf[i])
16+
17+
# then, do nothing

src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ def value(self, val=None):
204204
A3 = Pin(10)
205205
A4 = Pin(12)
206206

207+
# Special digital pins for pixels
207208
D7 = Pin(11)
209+
D8 = Pin(13)
210+
D9 = Pin(14)
208211

209212
# I2C pins
210213
SDA = Pin()
@@ -217,6 +220,9 @@ def value(self, val=None):
217220
MISO = Pin()
218221
CS = Pin()
219222

223+
spiPorts = ((0, SCK, MOSI, MISO),)
224+
225+
220226
# UART pins
221227
UART_TX = Pin()
222228
UART_RX = Pin()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2024 Brent Rubell for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""SPI class for a generic agnostic board."""
5+
# from .rp2040_u2if import rp2040_u2if
6+
7+
8+
# pylint: disable=protected-access, no-self-use
9+
class SPI:
10+
"""SPI Base Class for a generic agnostic board."""
11+
12+
MSB = 0
13+
14+
def __init__(self, index, *, baudrate=100000):
15+
self._index = index
16+
self._frequency = baudrate
17+
18+
# pylint: disable=too-many-arguments,unused-argument
19+
def init(
20+
self,
21+
baudrate=1000000,
22+
polarity=0,
23+
phase=0,
24+
bits=8,
25+
firstbit=MSB,
26+
sck=None,
27+
mosi=None,
28+
miso=None,
29+
):
30+
"""Initialize the Port"""
31+
self._frequency = baudrate
32+
33+
# pylint: enable=too-many-arguments
34+
35+
@property
36+
def frequency(self):
37+
"""Return the current frequency"""
38+
return self._frequency
39+
40+
def write(self, buf, start=0, end=None):
41+
"""Write data from the buffer to SPI"""
42+
pass
43+
44+
def readinto(self, buf, start=0, end=None, write_value=0):
45+
"""Read data from SPI and into the buffer"""
46+
pass
47+
48+
# pylint: disable=too-many-arguments
49+
def write_readinto(
50+
self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
51+
):
52+
"""Perform a half-duplex write from buffer_out and then
53+
read data into buffer_in
54+
"""
55+
pass

src/busio.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ def __init__(self, clock, MOSI=None, MISO=None):
363363
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
364364
elif detector.board.ftdi_ft2232h:
365365
from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.spi import SPI as _SPI
366+
elif (
367+
"BLINKA_FORCECHIP" in os.environ
368+
and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD"
369+
):
370+
from adafruit_blinka.microcontroller.generic_agnostic_board.spi import (
371+
SPI as _SPI,
372+
)
366373
else:
367374
from adafruit_blinka.microcontroller.generic_micropython.spi import (
368375
SPI as _SPI,

src/microcontroller/pin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
from adafruit_blinka.microcontroller.nova.pin import *
9797
elif chip_id == ap_chip.LPC4330:
9898
from adafruit_blinka.microcontroller.nxp_lpc4330.pin import *
99+
elif (
100+
"BLINKA_FORCECHIP" in os.environ
101+
and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD"
102+
):
103+
from adafruit_blinka.microcontroller.generic_agnostic_board.pin import *
99104
elif chip_id == ap_chip.MCP2221:
100105
from adafruit_blinka.microcontroller.mcp2221.pin import *
101106
elif chip_id == ap_chip.A10:
@@ -149,11 +154,6 @@
149154
elif chip_id == ap_chip.GENERIC_X86:
150155
print("WARNING: GENERIC_X86 is not fully supported. Some features may not work.")
151156
from adafruit_blinka.microcontroller.generic_micropython import Pin
152-
elif (
153-
"BLINKA_FORCECHIP" in os.environ
154-
and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD"
155-
):
156-
from adafruit_blinka.microcontroller.generic_agnostic_board.pin import *
157157
elif chip_id is None:
158158
print(
159159
"WARNING: chip_id == None is not fully supported. Some features may not work."

src/neopixel_write.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Author(s): ladyada
1212
"""
1313
# pylint: disable=too-many-boolean-expressions
14+
import os
1415
import sys
1516

1617
from adafruit_blinka.agnostic import detector
@@ -19,6 +20,13 @@
1920
from adafruit_blinka.microcontroller.bcm283x import neopixel as _neopixel
2021
elif detector.board.pico_u2if:
2122
from adafruit_blinka.microcontroller.rp2040_u2if import neopixel as _neopixel
23+
elif (
24+
"BLINKA_FORCECHIP" in os.environ
25+
and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD"
26+
):
27+
from adafruit_blinka.microcontroller.generic_agnostic_board import (
28+
neopixel as _neopixel,
29+
)
2230
elif (
2331
detector.board.feather_u2if
2432
or detector.board.feather_can_u2if

0 commit comments

Comments
 (0)