Skip to content

Conversation

@laurensvalk
Copy link
Member

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_nxt driver 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.

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.
@coveralls
Copy link

coveralls commented Dec 16, 2025

Coverage Status

coverage: 56.232% (+0.01%) from 56.222%
when pulling 0b003f4 on avr
into f8863bd on master.

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.
@laurensvalk laurensvalk merged commit 0b003f4 into master Dec 16, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants