Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/adafruit_blinka/importing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT

"""
`adafruit_blinka.importing` - Import utilities that run on Linux and MicroPython
======================================================================================

* Author(s): Melissa LeBlanc-Williams
"""

try:
from importlib import import_module
except ImportError as e:

def import_module(module_name: str, package: str = None):
"""importlib not available, define an alternate import_module function"""
package_list = []
if package is not None:
package_list.append(package)
return __import__(module_name, globals(), locals(), package_list)


def get_import_file(json_file_name, script_file_location):
"""Get the full path to the microcontroller imports file."""
try:
from pathlib import Path

script_folder = Path(script_file_location).parent.absolute()
return script_folder / json_file_name
except ImportError:
# MicroPython doesn't have pathlib, so we have to do it manually
if script_file_location.startswith("/"):
script_folder = "/".join(script_file_location.split("/")[:-1])
else:
script_folder = "."
return f"{script_folder}/{json_file_name}"


def import_mod(caller_globals, module_name: str, package_name: str = "*"):
"""Function to allow importing with * or specific package name."""
if package_name == "*":
module = import_module(module_name)
caller_globals.update(
{name: getattr(module, name) for name in module.__all__}
if hasattr(module, "__all__")
else {
key: value
for (key, value) in module.__dict__.items()
if not key.startswith("_")
}
)
else:
module = import_module(module_name, package=package_name)
caller_globals[package_name] = getattr(module, package_name)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
#
# SPDX-License-Identifier: MIT
"""Generic Pin class for use with MicroPython boards"""
from adafruit_blinka import Enum
# from adafruit_blinka import Enum
try:
from machine import Pin as MachinePin
except ImportError:
# Fall back to a simple Pin class if machine.Pin is not available for CI testing
from adafruit_blinka import Enum as MachinePin


class Pin(Enum):
class Pin(MachinePin):
"""
Identifies an IO pin on the microcontroller.

Expand Down
6 changes: 3 additions & 3 deletions src/adafruit_blinka/microcontroller/nova/pwmout.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _open(self, pin, duty=0, freq=750, variable_frequency=False):
if variable_frequency:
print("Variable Frequency is not supported, continuing without it...")

PWMOut._nova.setIOpinMode(self._pwmpin, Pin.PWM)
PWMOut._nova.setIOpinMode(self._pwmpin, Pin.PWM) # pylint: disable=no-member

# set frequency
self.frequency = freq
Expand Down Expand Up @@ -149,7 +149,7 @@ def _set_period(self, period):
"""

def _get_duty_cycle(self):
duty_cycle = Pin._nova.getIOpinValue(self._pwmpin)
duty_cycle = Pin._nova.getIOpinValue(self._pwmpin) # pylint: disable=no-member

# Convert duty cycle to ratio from 0.0 to 1.0
duty_cycle = duty_cycle / PWMOut.MAX_CYCLE_LEVEL
Expand All @@ -172,7 +172,7 @@ def _set_duty_cycle(self, duty_cycle):

# Set duty cycle
# pylint: disable=protected-access
Pin._nova.setIOpinValue(self._pwmpin, duty_cycle)
Pin._nova.setIOpinValue(self._pwmpin, duty_cycle) # pylint: disable=no-member
# pylint: enable=protected-access

duty_cycle = property(_get_duty_cycle, _set_duty_cycle)
Expand Down
2 changes: 1 addition & 1 deletion src/adafruit_blinka/microcontroller/rp2040/pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT
"""RP2040 pins"""

from machine import Pin
from adafruit_blinka.microcontroller.generic_micropython import Pin

GP0 = Pin(0)
GP1 = Pin(1)
Expand Down
2 changes: 1 addition & 1 deletion src/adafruit_blinka/microcontroller/stm32/stm32f405/pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT
"""STM32F405 pins"""

from machine import Pin
from adafruit_blinka.microcontroller.generic_micropython import Pin

A0 = Pin("A0")
A1 = Pin("A1")
Expand Down
Loading