-
-
Notifications
You must be signed in to change notification settings - Fork 82
pbio/port_dcm: Partially implement NXT sensors. #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or 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
NXT does not have this GPIO, and there are other ways to test disconnection.
We can't detect everything this way, but crucially we can still detect the NXT light sensor and NXT color sensor in order to drive their active background processes.
We'll need to make several modifications and add features such as access to the sensor power pins, so bring this into a dedicated pbio driver. Apply code formatting while we are doing this.
We used to drive not only transmission but also (un)packing of the AVR data from the timer ISR, which is unsafe. Encoding and decoding now happens safely in the event loop. While we are at it, convert the synchronization state machine to a simple async process.
Create an rproc interface for other pbio drivers to call into, skipping nxos as an intermediate API. Pack data when set instead of every time around the loop. Checksums are only updated if there is anything new to send. Also clean up some terminology such as speed -> duty cycle brake -> decay mode.
The copy right notices refer to this file, so we should include it.
There isn't a display driver yet, but it means we can start and stop programs with the button and upload new programs with Pybricks Code.
This can be removed when NXT blocks are available.
This was referenced Dec 16, 2025
This helps catching mistakes prior to pushing to CI.
Not all platforms support this.
It appears that nxos had these in reverse. Update according to AVR source.
The center button is an actual digital switch that adds exactly 0x07FF to the ADC value when pressed, according to the AVR source. This lets us detect the center button independently from the other three. This lets you do button combinations in user code.
This is useful on systems without a debug UART.
On NXT, new samples are not available right away after activating their mode manually.
Instead of attempting to use partial autodetect when full detection is not possible, it is more reliable to just set the intended type when the user initializes a class. This also simplifies the #if PBDRV_CONFIG_IOPORT_HAS_GPIO_P2 logic to disable all detection code instead of many selective portions.
This ensures we get ENODEV when the device is unplugged instead of EPERM (invalid operation).
We don't have signals for the ADC being ready yet, so we have to wait for a full communications cycle.
These should return values 0--100.0 instead of 0--1000 as we did so far. Also heuristically adjust scale. We have made some ADC adjustments since originally writing this code so we can reset these scaling values.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes major steps towards enabling sensors on the NXT brick. It enables the common sensor framework used on EV3 but without the device detection component. All analog sensor variants are enabled. The digital aspect of the NXT Color Sensor is also enabled, but reading the ADCs on pin6 of each port is not yet implemented.
This introduces a new
rproc_nxtdriver to interface with all the devices attached to the AVR co-processor. This is migrated from the nxos code and mostly rewritten into the driver format that we need. This fixes a few errors in the nxos drivers along the way, such as setting the correct values to enter SAMBA mode. And adds functionality such as setting the sensor power pins. We can now also detect the center button independently from the other three buttons, allowing you to detect basic combinations.This also enables a basic HMI that lets us download and run programs with USB so we can test basic programs.
A USB debug driver has been added to simplify debugging on NXT.