-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
869b4c0
commit 0f308fd
Showing
4 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# SPDX-FileCopyrightText: 2025 Christopher Parrott for Pimoroni Ltd | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from .common import YukonModule, ADC_FLOAT, ADC_HIGH, IO_HIGH, IO_LOW | ||
from machine import Pin | ||
from pimoroni import RGBLED | ||
|
||
|
||
class MechKeyModule(YukonModule): | ||
NAME = "Mechanical Key + RGB" | ||
|
||
# | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | | ||
# |-------|-------|-------|-------|-------|----------------------|-----------------------------| | ||
# | HIGH | FLOAT | 1 | 0 | 0 | Mechanical Key | | | ||
@staticmethod | ||
def is_module(adc1_level, adc2_level, slow1, slow2, slow3): | ||
return adc1_level is ADC_HIGH and adc2_level is ADC_FLOAT and slow1 is IO_HIGH and slow2 is IO_LOW and slow3 is IO_LOW | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def initialise(self, slot, adc1_func, adc2_func): | ||
|
||
# Create the key pin object | ||
self.__key = slot.FAST4 | ||
self.__key.init(Pin.IN, Pin.PULL_UP) | ||
|
||
# Create the RGB LED object | ||
self.__led = RGBLED(slot.FAST1, slot.FAST2, slot.FAST3, invert=True) | ||
|
||
# Pass the slot and adc functions up to the parent now that module specific initialisation has finished | ||
super().initialise(slot, adc1_func, adc2_func) | ||
|
||
def reset(self): | ||
self.__led.set_rgb(0, 0, 0) | ||
|
||
def set_rgb(self, r, g, b): | ||
self.__led.set_rgb(r, g, b) | ||
|
||
def set_hsv(self, h, s, v): | ||
self.__led.set_hsv(h, s, v) | ||
|
||
def is_pressed(self): | ||
return self.__key.value() != 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# SPDX-FileCopyrightText: 2025 Christopher Parrott for Pimoroni Ltd | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import vfs | ||
from machine import SPI | ||
from sdcard import SDCard | ||
from .common import YukonModule, ADC_LOW, ADC_FLOAT, IO_LOW, IO_HIGH | ||
|
||
|
||
class MicroSDModule(YukonModule): | ||
NAME = "Micro SD Card" | ||
|
||
CARD_DETECT_LEVEL = 1.65 | ||
|
||
# | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | | ||
# |-------|-------|-------|-------|-------|----------------------|-----------------------------| | ||
# | LOW | LOW | 1 | 0 | 1 | Micro SD Card | Card Inserted | | ||
# | LOW | HIGH | 1 | 0 | 1 | Micro SD Card | No Card | | ||
@staticmethod | ||
def is_module(adc1_level, adc2_level, slow1, slow2, slow3): | ||
return adc1_level == ADC_LOW and adc2_level != ADC_FLOAT and slow1 is IO_HIGH and slow2 is IO_LOW and slow3 is IO_HIGH | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
try: | ||
import sdcard | ||
except ImportError: | ||
raise RuntimeError("This build does not contain sd card support. Please flash your Yukon with a build that supports sd cards in order to use this module.") | ||
|
||
def initialise(self, slot, adc1_func, adc2_func): | ||
try: | ||
# Create the SPI object | ||
spi_id = (((slot.ID - 1) * 4) // 8) % 2 | ||
self.__spi = SPI(spi_id, sck=slot.FAST3, mosi=slot.FAST4, miso=slot.FAST1) | ||
|
||
except ValueError as e: | ||
raise type(e)("SPI perhiperal already in use. Check that a module in another slot does not share the same SPI perhiperal") from None | ||
|
||
self.__card_cs = slot.FAST2 | ||
self.__sd = None | ||
self.__path = None | ||
|
||
# Pass the slot and adc functions up to the parent now that module specific initialisation has finished | ||
super().initialise(slot, adc1_func, adc2_func) | ||
|
||
def reset(self): | ||
self.umount() | ||
|
||
def mount(self, path="/sd", baudrate=26400000): | ||
if self.__sd is None: | ||
self.__sd = SDCard(self.__spi, self.__card_cs, baudrate=baudrate) | ||
self.__path = path | ||
vfs.mount(self.__sd, self.__path) | ||
|
||
def umount(self): | ||
if self.__sd is not None: | ||
vfs.umount(self.__path) | ||
self.__sd = None | ||
self.__path = None | ||
|
||
def card_present(self): | ||
return self.__read_adc2() >= self.CARD_DETECT_LEVEL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-FileCopyrightText: 2023 Christopher Parrott for Pimoroni Ltd | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from .common import YukonModule, ADC_HIGH, ADC_LOW, IO_HIGH, IO_LOW | ||
from machine import Pin | ||
from pimoroni import RGBLED | ||
|
||
|
||
class PotModule(YukonModule): | ||
NAME = "Potentiometer + RGB" | ||
|
||
# | ADC1 | ADC2 | SLOW1 | SLOW2 | SLOW3 | Module | Condition (if any) | | ||
# |-------|-------|-------|-------|-------|----------------------|-----------------------------| | ||
# | HIGH | LOW | 1 | 1 | 0 | Potentiometer + RGB | | | ||
@staticmethod | ||
def is_module(adc1_level, adc2_level, slow1, slow2, slow3): | ||
return adc1_level is ADC_HIGH and adc2_level is ADC_LOW and slow1 is IO_HIGH and slow2 is IO_HIGH and slow3 is IO_LOW | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def initialise(self, slot, adc1_func, adc2_func): | ||
|
||
# Create the potentiometer end pin object | ||
self.__pot_a = slot.SLOW1 | ||
self.__pot_b = slot.SLOW2 | ||
self.__pot_a.init(Pin.OUT, value=False) | ||
self.__pot_b.init(Pin.OUT, value=True) | ||
|
||
# Create the RGB LED object | ||
self.__led = RGBLED(slot.FAST1, slot.FAST2, slot.FAST3, invert=True) | ||
|
||
# Pass the slot and adc functions up to the parent now that module specific initialisation has finished | ||
super().initialise(slot, adc1_func, adc2_func) | ||
|
||
def reset(self): | ||
self.__led.set_rgb(0, 0, 0) | ||
|
||
def set_rgb(self, r, g, b): | ||
self.__led.set_rgb(r, g, b) | ||
|
||
def set_hsv(self, h, s, v): | ||
self.__led.set_hsv(h, s, v) | ||
|
||
def read(self, samples=1): | ||
return self.__read_adc1(samples) / 3.3 |