Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
558d813
pbio/port_dcm_ev3: Don't use GPIO 2 for light and color sensor.
laurensvalk Dec 12, 2025
12a3994
pbio/drv/ioport: Allow GPIO 2 to be disabled.
laurensvalk Dec 12, 2025
89c366c
pbio/drv/rproc_nxt: Migrate nxos driver.
laurensvalk Dec 12, 2025
c85bb06
pbio/drv/rproc_nxt: Implement power off.
laurensvalk Dec 12, 2025
80e834a
pbio/drv/rproc_nxt: Decouple AVR data handling from ISR.
laurensvalk Dec 12, 2025
16eb988
pbio/drv/rproc_nxt: Full overhaul.
laurensvalk Dec 12, 2025
857eccb
pbio/platform/nxt: Add nxos AUTHORS file.
laurensvalk Dec 12, 2025
8ab873b
pbio/image: Add missing inline variants when disabled.
laurensvalk Dec 12, 2025
4fbb159
pbio/sys/hmi_lcd: Allow use without lights and slots.
laurensvalk Dec 12, 2025
389b547
pbio/platform/nxt: Enable basic HMI.
laurensvalk Dec 12, 2025
53b61c0
bricks/nxt: Enable PUP aliases for easier testing.
laurensvalk Dec 12, 2025
1a61b03
pbio/platform/nxt: Add placeholders for ADC and GPIO.
laurensvalk Dec 12, 2025
9720a8a
Makefile: Add buildhat target.
laurensvalk Dec 16, 2025
bd2cebb
pbio/drv/ioport: Selectively enable UART.
laurensvalk Dec 12, 2025
323802e
pbio/drv/motor_driver_nxt: Prepare setting sensor power.
laurensvalk Dec 12, 2025
f84a083
pbio/drv/rproc_nxt: Fix SAMBA reset.
laurensvalk Dec 12, 2025
3cfa6a0
pbio/drv/rproc_nxt: Detect multiple buttons.
laurensvalk Dec 12, 2025
d30b93c
pbio/drv/rproc_nxt: Implement sensor power.
laurensvalk Dec 12, 2025
510c3ef
pbio/drv/usb: Add debug print functions.
laurensvalk Dec 12, 2025
56a6277
pbio/drv/usb: Include \r before \n in debug.
laurensvalk Dec 12, 2025
69b9b80
pbio/platform/nxt: Partially implement GPIO and ADC.
laurensvalk Dec 12, 2025
dbc6649
pybricks.nxtdevices: Wait for new analog samples.
laurensvalk Dec 16, 2025
352b6b7
pbio/port_dcm_ev3: Allow use without autodetect.
laurensvalk Dec 16, 2025
322c59e
pbio/port_dcm: Return error if analog device disconnected.
laurensvalk Dec 16, 2025
f3125f3
pbio/drv/adc_nxt: Adjust sample wait time.
laurensvalk Dec 16, 2025
0b003f4
pybricks.nxtdevices.LightSensor: Return values as fraction.
laurensvalk Dec 16, 2025
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Added
- Added preliminary BTstack support for EV3 ([pybricks-micropython#405]).
- Enabled NXT Light Sensor, NXT Touch Sensor, NXT Sound Sensor on NXT.

### Changed
- Make 3D orientation default for heading and drivebase heading control ([support#1962]).
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ doc:
clean-doc:
@$(MAKE) -C lib/pbio/doc clean

all: movehub cityhub technichub primehub essentialhub virtualhub nxt ev3 doc
all: movehub cityhub technichub primehub essentialhub virtualhub nxt ev3 buildhat doc

clean-all: clean-movehub clean-cityhub clean-technichub clean-primehub clean-essentialhub clean-virtualhub clean-nxt clean-ev3 clean-doc
clean-all: clean-movehub clean-cityhub clean-technichub clean-primehub clean-essentialhub clean-virtualhub clean-nxt clean-ev3 clean-buildhat clean-doc

ev3: mpy-cross
@$(MAKE) -C bricks/ev3
Expand Down Expand Up @@ -82,6 +82,12 @@ clean-virtualhub: clean-mpy-cross
@$(MAKE) -C bricks/virtualhub clean BUILD=build-debug
@$(MAKE) -C bricks/virtualhub clean BUILD=build-coverage

buildhat: mpy-cross
@$(MAKE) -C bricks/buildhat

clean-buildhat: clean-mpy-cross
@$(MAKE) -C bricks/buildhat clean

mpy-cross:
@$(MAKE) -C micropython/mpy-cross CROSS_COMPILE=$(HOST_CROSS_COMPILE)

Expand Down
1 change: 0 additions & 1 deletion bricks/_common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ NXOS_SRC_C = $(addprefix lib/pbio/platform/nxt/nxos/,\
drivers/_twi.c \
drivers/_uart.c \
drivers/aic.c \
drivers/avr.c \
drivers/bt.c \
drivers/i2c_memory.c \
drivers/i2c.c \
Expand Down
2 changes: 1 addition & 1 deletion bricks/_common/qstrdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Q(pybricks.nxtdevices)
Q(pybricks.parameters)
#endif

#if PYBRICKS_PY_PUPDEVICES || PYBRICKS_PY_EV3_PUP_ALIAS
#if PYBRICKS_PY_PUPDEVICES || PYBRICKS_PY_EV3_PUP_ALIAS || PYBRICKS_PY_NXT_PUP_ALIAS
Q(pybricks.pupdevices)
#endif

Expand Down
3 changes: 3 additions & 0 deletions bricks/_common/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ PYBRICKS_PYBRICKS_SRC_C = $(addprefix pybricks/,\

PBIO_SRC_C = $(addprefix lib/pbio/,\
drv/adc/adc_ev3.c \
drv/adc/adc_nxt.c \
drv/adc/adc_stm32_hal.c \
drv/adc/adc_stm32f0.c \
drv/battery/battery_adc.c \
Expand Down Expand Up @@ -144,6 +145,7 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
drv/display/display_ev3.c \
drv/display/display_virtual.c \
drv/gpio/gpio_ev3.c \
drv/gpio/gpio_nxt.c \
drv/gpio/gpio_pico.c \
drv/gpio/gpio_stm32f0.c \
drv/gpio/gpio_stm32f4.c \
Expand Down Expand Up @@ -174,6 +176,7 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
drv/reset/reset_stm32.c \
drv/resistor_ladder/resistor_ladder.c \
drv/rproc/rproc_ev3.c \
drv/rproc/rproc_nxt.c \
drv/sound/beep_sampled.c \
drv/sound/sound_ev3.c \
drv/sound/sound_nxt.c \
Expand Down
3 changes: 3 additions & 0 deletions bricks/nxt/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#define PYBRICKS_HUB_CLASS_NAME (MP_QSTR_NXTBrick)

#define PYBRICKS_HUB_NXTBRICK (1)
// On EV3, allow PUP imports for easy beta testing
#define PYBRICKS_PY_NXT_PUP_ALIAS (1)
#define PYBRICKS_HUB_CLASS_NAME_ALIAS (MP_QSTR_PrimeHub)

// Pybricks modules
#define PYBRICKS_PY_COMMON (1)
Expand Down
43 changes: 43 additions & 0 deletions lib/pbio/drv/adc/adc_nxt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2023 The Pybricks Authors

#include <pbdrv/config.h>

#if PBDRV_CONFIG_ADC_NXT

#include <stdbool.h>
#include <stdint.h>

#include <pbdrv/adc.h>
#include <pbdrv/clock.h>

#include <pbio/error.h>
#include <pbio/util.h>

#include "../rproc/rproc_nxt.h"

void pbdrv_adc_init(void) {
}

pbio_error_t pbdrv_adc_await_new_samples(pbio_os_state_t *state, uint32_t *start_time_us, uint32_t future_us) {

PBIO_OS_ASYNC_BEGIN(state);
*start_time_us = pbdrv_clock_get_ms();
// REVISIT: Pass channel ID to this function so we can adjust the wait time
// to the specific sample coming in. The AVR adc samples will be slower.
PBIO_OS_AWAIT_UNTIL(state, pbio_util_time_has_passed(pbdrv_clock_get_ms(), *start_time_us + 7));
PBIO_OS_ASYNC_END(PBIO_SUCCESS);
}

pbio_error_t pbdrv_adc_get_ch(uint8_t ch, uint16_t *value) {

if (ch < 4) {
return pbdrv_rproc_nxt_get_sensor_adc(ch, value);
}

// TODO: AT91SAM7S256 internal ADC.
*value = 0;
return PBIO_SUCCESS;
}

#endif // PBDRV_CONFIG_ADC_NXT
10 changes: 5 additions & 5 deletions lib/pbio/drv/battery/battery_nxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
#include <stdbool.h>
#include <stdio.h>

#include <nxos/drivers/avr.h>

#include <pbdrv/battery.h>
#include <pbio/error.h>

#include "../rproc/rproc_nxt.h"

void pbdrv_battery_init(void) {
}

pbio_error_t pbdrv_battery_get_voltage_now(uint16_t *value) {
// REVISIT: Voltage appears off by a factor 2
*value = nx_avr_get_battery_voltage();
pbdrv_rproc_nxt_get_battery_info(value);
return PBIO_SUCCESS;
}

Expand All @@ -30,7 +29,8 @@ pbio_error_t pbdrv_battery_get_current_now(uint16_t *value) {
}

pbio_error_t pbdrv_battery_get_type(pbdrv_battery_type_t *value) {
*value = nx_avr_battery_is_accu_pack() ? PBDRV_BATTERY_TYPE_LIION : PBDRV_BATTERY_TYPE_ALKALINE;
uint16_t voltage;
*value = pbdrv_rproc_nxt_get_battery_info(&voltage) ? PBDRV_BATTERY_TYPE_LIION : PBDRV_BATTERY_TYPE_ALKALINE;
return PBIO_SUCCESS;
}

Expand Down
23 changes: 2 additions & 21 deletions lib/pbio/drv/button/button_nxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,15 @@
#if PBDRV_CONFIG_BUTTON_NXT

#include <pbio/button.h>
#include <pbio/config.h>
#include <pbio/error.h>

#include <nxos/drivers/avr.h>
#include "../rproc/rproc_nxt.h"

void pbdrv_button_init(void) {
}

pbio_button_flags_t pbdrv_button_get_pressed(void) {

nx_avr_button_t button = nx_avr_get_button();

pbio_button_flags_t pressed = 0;

if (button == BUTTON_OK) {
pressed |= PBIO_BUTTON_CENTER;
}
if (button == BUTTON_LEFT) {
pressed |= PBIO_BUTTON_LEFT;
}
if (button == BUTTON_RIGHT) {
pressed |= PBIO_BUTTON_RIGHT;
}
if (button == BUTTON_CANCEL) {
pressed |= PBIO_BUTTON_DOWN;
}

return pressed;
return pbdrv_rproc_nxt_get_button_pressed();
}

#endif // PBDRV_CONFIG_BUTTON_NXT
10 changes: 1 addition & 9 deletions lib/pbio/drv/clock/clock_nxt.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (C) 2007 the NxOS developers
// See AUTHORS for a full list of the developers.
// See lib/pbio/platform/nxt/nxos/AUTHORS for a full list of the developers.
// Copyright (c) 2023 The Pybricks Authors

#include <pbdrv/config.h>
Expand All @@ -15,7 +15,6 @@
#include <nxos/nxt.h>
#include <nxos/interrupts.h>
#include <nxos/drivers/aic.h>
#include <nxos/drivers/_avr.h>
#include <nxos/drivers/_lcd.h>

/* The main clock is at 48MHz, and the PIT divides that by 16 to get
Expand Down Expand Up @@ -43,13 +42,6 @@ static void systick_isr(void) {
pbdrv_clock_ticks++;
pbio_os_request_poll();

/* Keeping up with the AVR link is a crucial task in the system, and
* must absolutely be kept up with at all costs.
*
* As a result, this handler must be *very* fast.
*/
nx__avr_fast_update();

/* The LCD dirty display routine can be done here too, since it is
* very short.
*/
Expand Down
68 changes: 68 additions & 0 deletions lib/pbio/drv/gpio/gpio_nxt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2025 The Pybricks Authors

#include "pbdrv/config.h"

#if PBDRV_CONFIG_GPIO_NXT

#include <stdint.h>

#include "pbdrv/gpio.h"

#include "at91sam7s256.h"

// Bank field is ignored for AT91SAM7S256. It is always PIOA.

#include <pbdrv/usb.h>

void pbdrv_gpio_out_low(const pbdrv_gpio_t *gpio) {
if (!gpio) {
return;
}
*AT91C_PIOA_OER = (1 << gpio->pin);
*AT91C_PIOA_CODR = (1 << gpio->pin);
}

void pbdrv_gpio_out_high(const pbdrv_gpio_t *gpio) {
if (!gpio) {
return;
}
*AT91C_PIOA_OER = (1 << gpio->pin);
*AT91C_PIOA_SODR = (1 << gpio->pin);
}

uint8_t pbdrv_gpio_input(const pbdrv_gpio_t *gpio) {
if (!gpio) {
return 0;
}
*AT91C_PIOA_ODR = (1 << gpio->pin);
return !!(*AT91C_PIOA_PDSR & (1 << gpio->pin));
}

void pbdrv_gpio_alt(const pbdrv_gpio_t *gpio, uint8_t alt) {
if (!gpio) {
return;
}
if (alt) {
// Enable peripheral control.
*AT91C_PIOA_PDR = (1 << gpio->pin);
} else {
// Enable GPIO control.
*AT91C_PIOA_PER = (1 << gpio->pin);
}
}

void pbdrv_gpio_set_pull(const pbdrv_gpio_t *gpio, pbdrv_gpio_pull_t pull) {
if (!gpio) {
return;
}
if (pull == PBDRV_GPIO_PULL_UP) {
*AT91C_PIOA_PPUER = (1 << gpio->pin);
} else if (pull == PBDRV_GPIO_PULL_NONE) {
*AT91C_PIOA_PPUDR = (1 << gpio->pin);
} else {
// AT91SAM7S256 does not have pull-down.
}
}

#endif // PBDRV_CONFIG_GPIO_NXT
9 changes: 9 additions & 0 deletions lib/pbio/drv/ioport/ioport.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@ static pbio_error_t pbdrv_ioport_p5p6_pin_reset(const pbdrv_ioport_pins_t *pins)

pbdrv_gpio_input(&pins->p5);
pbdrv_gpio_input(&pins->p6);
#if PBDRV_CONFIG_IOPORT_HAS_UART
pbdrv_gpio_input(&pins->uart_tx);
pbdrv_gpio_input(&pins->uart_rx);
pbdrv_gpio_out_high(&pins->uart_buf);
#endif

// These should be set by default already, but it seems that the
// bootloader on the Technic hub changes these and causes wrong
// detection if we don't make sure pull is disabled.
pbdrv_gpio_set_pull(&pins->p5, PBDRV_GPIO_PULL_NONE);
pbdrv_gpio_set_pull(&pins->p6, PBDRV_GPIO_PULL_NONE);

#if PBDRV_CONFIG_IOPORT_HAS_UART
pbdrv_gpio_set_pull(&pins->uart_buf, PBDRV_GPIO_PULL_NONE);
pbdrv_gpio_set_pull(&pins->uart_tx, PBDRV_GPIO_PULL_NONE);
pbdrv_gpio_set_pull(&pins->uart_rx, PBDRV_GPIO_PULL_NONE);
#endif

return PBIO_SUCCESS;
}
Expand All @@ -44,6 +49,7 @@ pbio_error_t pbdrv_ioport_p5p6_set_mode(const pbdrv_ioport_pins_t *pins, pbdrv_i
// This is the same as the default mode.
return pbdrv_ioport_p5p6_pin_reset(pins);
} else if (mode == PBDRV_IOPORT_P5P6_MODE_UART) {
#if PBDRV_CONFIG_IOPORT_HAS_UART
err = pbdrv_ioport_p5p6_pin_reset(pins);
if (err != PBIO_SUCCESS) {
return err;
Expand All @@ -53,6 +59,9 @@ pbio_error_t pbdrv_ioport_p5p6_set_mode(const pbdrv_ioport_pins_t *pins, pbdrv_i
pbdrv_gpio_alt(&pins->uart_tx, pins->uart_tx_alt_uart);
pbdrv_gpio_out_low(&pins->uart_buf);
return PBIO_SUCCESS;
#else // PBDRV_CONFIG_IOPORT_HAS_UART
return PBIO_ERROR_NOT_SUPPORTED;
#endif // PBDRV_CONFIG_IOPORT_HAS_UART
} else if (mode == PBDRV_IOPORT_P5P6_MODE_I2C) {
err = pbdrv_ioport_p5p6_pin_reset(pins);
if (err != PBIO_SUCCESS) {
Expand Down
Loading