Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c8c74e1
Add the STANDALONE external frame sync role
sb-lxn Nov 12, 2026
0ece0e2
Pipeline: start STANDALONE devices with the frame sync masters
sb-lxn Nov 12, 2026
aa2182c
Test on-board frame sync in the STANDALONE role
sb-lxn Nov 12, 2026
24563ef
Merge remote-tracking branch 'origin/develop' into feat/aux-controlle…
sb-lxn Nov 16, 2026
3457839
Bump rvc4 device
sb-lxn Nov 16, 2026
f440886
DeviceBase: document the frame sync role results
sb-lxn Nov 16, 2026
86b5a5a
bump rvc4 device
sb-lxn Nov 16, 2026
f844a30
Merge remote-tracking branch 'origin/develop' into feat/aux-controlle…
sb-lxn Nov 26, 2026
2eb8e79
FsyncController: keep the frame sync role in one RoleState
sb-lxn Nov 12, 2026
1d30b0f
FsyncController: write CONFIG 0 at start, apply the role when the pip…
sb-lxn Nov 12, 2026
712cd57
FsyncController: add the STANDALONE frame sync role
sb-lxn Nov 12, 2026
18dd10e
FsyncController: keep on-board sync when the FSYNC pin is unavailable
sb-lxn Nov 12, 2026
ed6a118
FsyncController: name the holder of a busy FSYNC pin
sb-lxn Nov 12, 2026
912f2f0
PipelineBuilder: check a forced frame sync role before building the n…
sb-lxn Nov 12, 2026
68b0f5c
FsyncController: read CONFIG back before keeping on-board sync
sb-lxn Nov 13, 2026
106fffa
FsyncController: fail an explicit role when fsync-stm cannot be opened
sb-lxn Nov 26, 2026
f3efcac
FsyncController: fail an explicit role after an earlier controller fa…
sb-lxn Nov 26, 2026
a762371
AuxConnector: plan a Script GPIO setup on a connector pin
sb-lxn Nov 13, 2026
8919177
Script: set up connector pins as GPIO by their line name
sb-lxn Nov 13, 2026
451ec4f
Script: name the connector pin of a busy TLMM GPIO
sb-lxn Nov 13, 2026
5065907
Test Script GPIO refusals on connector pins
sb-lxn Nov 13, 2026
ab52822
Merge remote-tracking branch 'origin/develop' into feat/aux-controlle…
sb-lxn Nov 30, 2026
7533ac3
chore(rvc4): pass the comment lint in the FSYNC and aux connector code
sb-lxn Nov 30, 2026
9e50976
Merge branch 'feat/aux-controller-integration' into feat/aux-script-gpio
sb-lxn Nov 30, 2026
6bbb59e
chore(rvc4): pass the comment lint in the Script GPIO code
sb-lxn Nov 30, 2026
1d96d47
Build the RVC4 firmware on Luxonis OS 1.50.0
sb-lxn Nov 30, 2026
7a36ec1
Merge remote-tracking branch 'origin/feat/aux-controller-integration'…
sb-lxn Nov 30, 2026
22b0c96
Merge remote-tracking branch 'origin/develop' into feat/aux-script-gpio
sb-lxn Dec 1, 2026
c2277c7
AuxConnector: name the ISOLATED role in the GPIO refusal
sb-lxn Dec 1, 2026
9e29692
AuxConnector: move the pin rules into AuxConnectorRules.cpp
sb-lxn Dec 1, 2026
10f6d6d
Tests: check the RVC4 aux connector pin rules on the host
sb-lxn Dec 1, 2026
f779d35
AuxConnector: say when to set ISOLATED in the FSYNC pin refusal
sb-lxn Dec 1, 2026
25e6a3e
Tests: set up and release a connector pin from a Script
sb-lxn Dec 1, 2026
b3f1106
Script: keep a set-up connector pin on a second setup
sb-lxn Dec 1, 2026
3d41620
Script: do not fail a release that the driver already did
sb-lxn Dec 1, 2026
51fa0e0
Script: name the connector line in a line request error
sb-lxn Dec 1, 2026
ca46f08
AuxConnector: drop the special case for pins without pulls
sb-lxn Dec 1, 2026
d079ec4
AuxConnector: parse the aux- prefix in one place
sb-lxn Dec 1, 2026
494461b
AuxConnector: own the requested pull instead of using gpio::Bias
sb-lxn Dec 1, 2026
eccc9d1
Tests: name the pa9496 R1 pin layout after its device tree
sb-lxn Dec 1, 2026
b584870
Tests: use the M16 pins in the Script GPIO case on OAK4-MAX
sb-lxn Dec 1, 2026
80d3738
Script: keep a set-up pin when a new pull is refused
sb-lxn Dec 2, 2026
0a6a172
Tests: run the Script GPIO case in the ISOLATED frame sync role
sb-lxn Dec 2, 2026
fc04b8f
Script: keep the record of a pin whose release failed
sb-lxn Dec 2, 2026
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
1 change: 1 addition & 0 deletions device/rvc4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ set(DEPTHAI_COMMON_SOURCES
src/utilities/FsyncController.cpp
src/utilities/FsyncRole.cpp
src/utilities/AuxConnector.cpp
src/utilities/AuxConnectorRules.cpp
src/pipeline/PipelineBuilder.cpp
src/pipeline/node/XLinkOut.cpp
src/pipeline/node/XLinkIn.cpp
Expand Down
173 changes: 146 additions & 27 deletions device/rvc4/src/pipeline/node/Script/GPIOBindings.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include "GPIOBindings.hpp"
#include "utilities/AuxConnector.hpp"
#include "utilities/ErrorMacros.hpp"
#include "utilities/GpioLine.hpp"

#include <atomic>
#include <bitset>
#include <condition_variable>
#include <mutex>
#include <optional>
#include <string>
#include <thread>
#include <variant>

#include <pybind11/chrono.h>
#include <pybind11/embed.h> // everything needed for embedding
Expand Down Expand Up @@ -51,6 +55,16 @@ enum class Edge {

std::unordered_map<int, dai::gpio::Line> gpioHandleMap;
std::unordered_map<int, py::object> gpioCallbackMap;

struct ConnectorLine {
dai::aux::AcquiredLine acquired;
dai::aux::Bias bias;
std::optional<dai::gpio::Line> line; // Empty while a failed RELEASE leaves the pin ours, so that a later release can retry it
};

dai::aux::GpioPins connectorPins;
std::unordered_map<std::string, ConnectorLine> connectorLineMap;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

std::thread interruptHandlerThread;

std::condition_variable gpioCv;
Expand All @@ -59,6 +73,79 @@ std::mutex gpioMutex;
std::bitset<256> gpioEventMap;
std::bitset<256> gpioEventCallbackMask;

dai::gpio::Direction toDirection(Direction dir) {
switch(dir) {
case Direction::IN:
return dai::gpio::Direction::Input;
case Direction::OUT:
return dai::gpio::Direction::Output;
default:
throw std::runtime_error("Invalid direction set for gpio!");
}
}

dai::gpio::Bias toBias(PullDownUp pud) {
switch(pud) {
case PullDownUp::PULL_NONE:
return dai::gpio::Bias::Disabled;
case PullDownUp::PULL_DOWN:
return dai::gpio::Bias::PullDown;
case PullDownUp::PULL_UP:
return dai::gpio::Bias::PullUp;
default:
throw std::runtime_error("Invalid pull setting for gpio!");
}
}

dai::aux::Bias toConnectorBias(PullDownUp pud) {
switch(pud) {
case PullDownUp::PULL_NONE:
return dai::aux::Bias::Disabled;
case PullDownUp::PULL_DOWN:
return dai::aux::Bias::PullDown;
case PullDownUp::PULL_UP:
return dai::aux::Bias::PullUp;
default:
throw std::runtime_error("Invalid pull setting for gpio!");
}
}

std::error_code releasePin(const dai::aux::AcquiredLine& acquired) {
auto error = connectorPins.release(acquired.pin);
if(error && !connectorPins.holds(acquired.pin)) { // The driver drops the lock before it returns the pin to its default, and retries a failed return
DAI_WARN("pin {} did not return to its default yet ({}), the aux connector driver retries it", acquired.label, error.message());
return {};
}
return error;
}

bool releaseConnectorLine(const std::string& name) {
auto held = connectorLineMap.find(name);
if(held == connectorLineMap.end()) {
return false;
}
held->second.line.reset();
if(auto error = releasePin(held->second.acquired)) {
throw std::runtime_error("Cannot release \"" + name + "\": " + error.message());
}
connectorLineMap.erase(held);
return true;
}

void requestConnectorLine(const std::string& name, ConnectorLine& held, dai::gpio::Direction direction) {
try {
held.line.emplace(held.acquired.chip.string(), held.acquired.offset, name, direction, dai::gpio::Bias::AsIs, "depthai-device");
} catch(const std::exception& error) {
auto setupError = dai::aux::gpioSetupError(name, error.what());
try {
releaseConnectorLine(name);
} catch(const std::exception& releaseError) {
throw std::runtime_error(setupError + ". " + releaseError.what());
}
throw std::runtime_error(setupError);
}
}

void bind(py::module_ m) {
if(initialized.exchange(true)) {
return;
Expand All @@ -85,36 +172,52 @@ void bind(py::module_ m) {
"setup",
[](int gpio, Direction dir, PullDownUp pud, bool exclusive) -> int {
(void)exclusive;

dai::gpio::Direction direction;
switch(dir) {
case Direction::IN:
direction = dai::gpio::Direction::Input;
break;
case Direction::OUT:
direction = dai::gpio::Direction::Output;
break;
default:
throw std::runtime_error("Invalid direction set for gpio!");
auto direction = toDirection(dir);
auto bias = toBias(pud);
gpioHandleMap.erase(gpio);
try {
gpioHandleMap.emplace(gpio, dai::gpio::Line(GPIO_CHIP_PATH, gpio, std::to_string(gpio), direction, bias, "depthai-device"));
} catch(const std::exception& error) {
auto hint = dai::aux::connectorHintForTlmm(gpio, dai::aux::lineConsumer(GPIO_CHIP_PATH, gpio));
if(!hint) {
throw;
}
throw std::runtime_error(std::string(error.what()) + ". " + *hint);
}
return 0;
},
py::arg("gpio"),
py::arg("dir") = Direction::IN,
py::arg("pud") = PullDownUp::PULL_NONE,
py::arg("exclusive") = false);

dai::gpio::Bias bias;
switch(pud) {
case PullDownUp::PULL_NONE:
bias = dai::gpio::Bias::Disabled;
break;
case PullDownUp::PULL_DOWN:
bias = dai::gpio::Bias::PullDown;
break;
case PullDownUp::PULL_UP:
bias = dai::gpio::Bias::PullUp;
break;
default:
throw std::runtime_error("Invalid pull setting for gpio!");
m.def(
"setup",
[](const std::string& name, Direction dir, PullDownUp pud, bool exclusive) -> int {
(void)exclusive;
auto direction = toDirection(dir);
auto bias = toConnectorBias(pud);
if(auto error = dai::aux::checkGpioRequest(name, bias)) {
throw std::runtime_error(*error);
}

gpioHandleMap.erase(gpio);
gpioHandleMap.emplace(gpio, dai::gpio::Line(GPIO_CHIP_PATH, gpio, direction, bias, "depthai-device"));
auto held = connectorLineMap.find(name);
if(held != connectorLineMap.end() && held->second.bias == bias) {
held->second.line.reset(); // Frees only the line, the pin stays gpio with its pull until a RELEASE
requestConnectorLine(name, held->second, direction);
return 0;
}
if(held != connectorLineMap.end()) {
if(auto error = dai::aux::checkGpioPull(held->second.acquired.label, held->second.acquired.gpioPullCaps, bias)) {
throw std::runtime_error(*error);
}
}
releaseConnectorLine(name);
auto acquired = connectorPins.acquire(name, bias);
if(const auto* error = std::get_if<std::string>(&acquired)) {
throw std::runtime_error(*error);
}
auto record = connectorLineMap.emplace(name, ConnectorLine{std::get<dai::aux::AcquiredLine>(acquired), bias, std::nullopt}).first;
requestConnectorLine(name, record->second, direction);
return 0;
},
py::arg("gpio"),
Expand Down Expand Up @@ -147,6 +250,22 @@ void bind(py::module_ m) {
}
return -1;
});

m.def("release", [](const std::string& name) -> int { return releaseConnectorLine(name) ? 0 : 1; });

m.def("write", [](const std::string& name, int value) -> int {
auto held = connectorLineMap.find(name);
if(held == connectorLineMap.end() || !held->second.line) {
return 1;
}
held->second.line->setValue(value);
return 0;
});

m.def("read", [](const std::string& name) -> int {
auto held = connectorLineMap.find(name);
return held == connectorLineMap.end() || !held->second.line ? -1 : held->second.line->getValue();
});
}

} // namespace gpio
Expand Down
Loading
Loading