Dx_INPUT_TRUE_PULL_DOWN = pin.D3
Dx_OUTPUT_TRUE = pin.D4
Dx_OUTPUT_FALSE = pin.D5
+# Special "digital" pins
+NEOPIXEL = pin.D6
# Analog pins
Ax_INPUT_RAND_INT = pin.A0
-Ax_INPUT_FIXED_INT = pin.A1
+Ax_INPUT_FIXED_INT_PI = pin.A1
Ax_OUTPUT_WAVE_SINE = pin.A2
Ax_OUTPUT_WAVE_SAWTOOTH = pin.A3
--- /dev/null
+# SPDX-FileCopyrightText: 2024 Brent Rubell for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
+"""Chip Definition for a generic, os-agnostic, board."""
+
+class GENERIC_AGNOSTIC_BOARD:
+ """Generic Agnostic Board Device Class Definition"""
+
+ def __init__(self):
+ pass # This implementation is for a generic board, no initialization is required
+
+ def __del__(self):
+ # try to close the device before destroying the instance
+ return
+
+ # pylint: enable=unused-argument
+
+
+generic_agnostic_board = GENERIC_AGNOSTIC_BOARD()
--- /dev/null
+# SPDX-FileCopyrightText: 2024 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
+"""generic_agnostic_board pin interface"""
+import random
+
+class Pin:
+ """A basic Pin class for use with generic_agnostic_board"""
+ # pin modes
+ OUT = 0
+ IN = 1
+ ADC = 2
+ DAC = 3
+ # pin values
+ LOW = 0
+ HIGH = 1
+
+ expected_pin_behavior = {
+ 'Dx_INPUT_TRUE': return_true,
+ 'Dx_INPUT_FALSE': return_false,
+ 'Dx_INPUT_TRUE_THEN_FALSE': return_toggle,
+ 'Dx_INPUT_TRUE_PULL_UP': return_true,
+ 'Dx_INPUT_TRUE_PULL_DOWN': return_true,
+ 'Dx_OUTPUT_TRUE': return_true,
+ 'Dx_OUTPUT_FALSE': return_true,
+ 'Ax_INPUT_RAND_INT': return_random_int
+ }
+
+ def __init__(self, pin_id=None):
+ self.id = pin_id
+ self._mode = None
+ self.previous_value = None
+ self.current_value = None
+
+ def init(self, mode=IN, pull=None):
+ """Initialize the Pin"""
+ if self.id is None:
+ raise RuntimeError("Can not init a None type pin.")
+ if pull is not None:
+ raise NotImplementedError("Internal pullups and pulldowns not supported")
+ self._mode = mode
+
+ def write(self, new_value):
+ """Saves the new_value to the pin for subsequent calls to .value"""
+ self.previous_value = self.current_value
+ self.current_value = new_value
+
+ def read(self):
+ """Returns the pin's expected value."""
+ self.previous_value = self.current_value
+ self.current_value = self.expected_pin_behavior.get(self.pin_id)
+ return self.current_value
+
+ def return_toggle(self):
+ """Returns the pin's expected value, toggling between True and False"""
+ toggle_state = not self.previous_value
+ return toggle_state
+
+ def return_false(self):
+ """Returns the pin's expected value, False"""
+ return False
+
+ def return_true(self):
+ """Returns the pin's expected value, True"""
+ return True
+
+ def return_random_int(self):
+ """Returns a random integer"""
+ return random.randint(0, 65535)
+
+ def return_fixed_int_pi(self):
+ """Returns the first five digits of Pi, 31415"""
+ return 31415
+
+ def value(self, val=None):
+ """Set or return the Pin Value"""
+ # Digital In / Out
+ if self._mode in (Pin.IN, Pin.OUT):
+ # digital read
+ if val is None:
+ return self.read()
+ # digital write
+ if val in (Pin.LOW, Pin.HIGH):
+ return self.write(val)
+ # nope
+ raise ValueError("Invalid value for pin.")
+ # Analog In
+ if self._mode == Pin.ADC:
+ if val is None:
+ return self.read()
+ # read only
+ raise AttributeError("'AnalogIn' object has no attribute 'value'")
+ # Analog Out
+ if self._mode == Pin.DAC:
+ if val is None:
+ # write only
+ raise AttributeError("unreadable attribute")
+ self.write(val)
+ return None
+ raise RuntimeError(
+ "No action for mode {} with value {}".format(self._mode, val)
+ )
* Author(s): Carter Nelson, Melissa LeBlanc-Williams
"""
+import os
import sys
from adafruit_blinka.agnostic import detector
from adafruit_blinka.microcontroller.rp2040_u2if.analogio import (
AnalogIn_ItsyBitsy as AnalogIn,
)
+elif "BLINKA_FORCECHIP" in os.environ and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD":
+ from adafruit_blinka.microcontroller.generic_agnostic_board.analogio import AnalogIn
+ from adafruit_blinka.microcontroller.generic_agnostic_board.analogio import AnalogOut
else:
raise NotImplementedError("analogio not supported for this board.")
import sys
+import os
import adafruit_platformdetect.constants.boards as ap_board
from adafruit_blinka.agnostic import board_id, detector
elif board_id == ap_board.MILKV_DUO:
from adafruit_blinka.board.milkv_duo import *
+elif "BLINKA_FORCECHIP" in os.environ and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD":
+ from adafruit_blinka.board.generic_agnostic_board import *
+
elif "sphinx" in sys.modules:
pass
* Author(s): cefn
"""
+import os
from adafruit_blinka.agnostic import board_id, detector
# pylint: disable=ungrouped-imports,wrong-import-position,unused-wildcard-import,wildcard-import
from machine import Pin
elif detector.chip.CV1800B:
from adafruit_blinka.microcontroller.cv1800b.pin import Pin
+elif "BLINKA_FORCECHIP" in os.environ and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD":
+ from adafruit_blinka.microcontroller.generic_agnostic.pin import Pin
from adafruit_blinka import Enum, ContextManaged
from adafruit_blinka.microcontroller.thead.th1520 import *
elif chip_id == ap_chip.GENERIC_X86:
print("WARNING: GENERIC_X86 is not fully supported. Some features may not work.")
+ elif "BLINKA_FORCECHIP" in os.environ and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD":
+ from adafruit_blinka.microcontroller.generic_agnostic_board import *
elif chip_id is None:
print(
"WARNING: chip_id == None is not fully supported. Some features may not work."
#
# SPDX-License-Identifier: MIT
"""Pins named after their chip name."""
+import os
import sys
from adafruit_platformdetect.constants import chips as ap_chip, boards as ap_boards
from adafruit_blinka.agnostic import board_id, chip_id
elif chip_id == ap_chip.GENERIC_X86:
print("WARNING: GENERIC_X86 is not fully supported. Some features may not work.")
from adafruit_blinka.microcontroller.generic_micropython import Pin
+elif "BLINKA_FORCECHIP" in os.environ and os.environ["BLINKA_FORCEBOARD"] == "GENERIC_AGNOSTIC_BOARD":
+ from adafruit_blinka.microcontroller.generic_agnostic_board.pin import *
elif chip_id is None:
print(
"WARNING: chip_id == None is not fully supported. Some features may not work."