-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api): deploy libgpiod for gpio control and deprecate sysfs (#…
…5381) This moves our API server over to using libgpiod (https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/), the current state of the art for controlling GPIO pins in linux through a character device rather than sysfs. This should be faster, is easier to improve, and doesn't use an officially deprecated abi (https://www.kernel.org/doc/html/latest/admin-guide/gpio/sysfs.html). One key difference that drives many changes in this PR is that control over gpios through libgpiod is lifetimed to a process, and ownership over an individual gpio line is restricted to a single pid. That means that - We have a single gpio controller object instead of free functions; this has the lifetime of the main hardware controller and is passed around to other things that need it, notably the robot singleton in the robot server - Given that the hardware controller owns the object, we pushed down smoothie reprogramming into the hardware controller so that we don't have to do it in the server code, which involves multiple instantiations of hardware controller sections And finally, it means that only the robot server can control GPIOs. After this PR, protocols executed through jupyter or opentrons_execute cannot control GPIOs. closes #5310
- Loading branch information
1 parent
0db633b
commit 475ee25
Showing
19 changed files
with
494 additions
and
381 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,18 @@ | ||
import logging | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from .dev_types import GPIODriverLike | ||
|
||
MODULE_LOG = logging.getLogger(__name__) | ||
|
||
|
||
def build_gpio_chardev(chip_name: str) -> 'GPIODriverLike': | ||
try: | ||
from .gpio import GPIOCharDev | ||
return GPIOCharDev(chip_name) | ||
except (ImportError, OSError): | ||
MODULE_LOG.info( | ||
'Failed to initialize character device, cannot control gpios') | ||
from .gpio_simulator import SimulatingGPIOCharDev | ||
return SimulatingGPIOCharDev(chip_name) |
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,59 @@ | ||
from typing import Dict, Tuple | ||
from typing_extensions import Protocol | ||
|
||
|
||
class GPIODriverLike(Protocol): | ||
""" Interface for the GPIO drivers | ||
""" | ||
def __init__(self, chip_name: str): | ||
... | ||
|
||
@property | ||
def chip(self) -> str: | ||
... | ||
|
||
@property | ||
def lines(self) -> Dict[int, str]: | ||
... | ||
|
||
async def setup(self): | ||
... | ||
|
||
def set_high(self, offset: int): | ||
... | ||
|
||
def set_low(self, offset: int): | ||
... | ||
|
||
def set_button_light(self, | ||
red: bool = False, | ||
green: bool = False, | ||
blue: bool = False): | ||
... | ||
|
||
def set_rail_lights(self, on: bool = True): | ||
... | ||
|
||
def set_reset_pin(self, on: bool = True): | ||
... | ||
|
||
def set_isp_pin(self, on: bool = True): | ||
... | ||
|
||
def set_halt_pin(self, on: bool = True): | ||
... | ||
|
||
def get_button_light(self) -> Tuple[bool, bool, bool]: | ||
... | ||
|
||
def get_rail_lights(self) -> bool: | ||
... | ||
|
||
def read_button(self) -> bool: | ||
... | ||
|
||
def read_window_switches(self) -> bool: | ||
... | ||
|
||
def release_line(self, offset: int): | ||
... |
Oops, something went wrong.