Skip to content

Commit 56e57d5

Browse files
committed
pbio/platform/nxt: Enable motors.
Everything is more fun with motors. This enables the minimal functionality to get ports going. Sensors and detection are not yet enabled.
1 parent 731b2ed commit 56e57d5

File tree

4 files changed

+91
-5
lines changed

4 files changed

+91
-5
lines changed

bricks/nxt/mpconfigport.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
#define PYBRICKS_PY_EV3DEVICES (0)
2929
#define PYBRICKS_PY_EXPERIMENTAL (0)
3030
#define PYBRICKS_PY_HUBS (1)
31-
#define PYBRICKS_PY_IODEVICES (0)
32-
#define PYBRICKS_PY_NXTDEVICES (0)
31+
#define PYBRICKS_PY_IODEVICES (1)
32+
#define PYBRICKS_PY_IODEVICES_I2CDEVICE (1)
33+
#define PYBRICKS_PY_NXTDEVICES (1)
3334
#define PYBRICKS_PY_PARAMETERS (1)
3435
#define PYBRICKS_PY_PARAMETERS_BUTTON (1)
3536
#define PYBRICKS_PY_PARAMETERS_ICON (0)

lib/pbio/platform/nxt/pbdrvconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#define PBDRV_CONFIG_COUNTER_NUM_DEV (3)
2525
#define PBDRV_CONFIG_COUNTER_NXT (1)
2626

27+
#define PBDRV_CONFIG_GPIO (1)
28+
#define PBDRV_CONFIG_GPIO_VIRTUAL (1) // TODO: Implement NXT GPIO driver
29+
2730
#define PBDRV_CONFIG_IOPORT (1)
2831
#define PBDRV_CONFIG_IOPORT_HAS_ADC (0)
2932
#define PBDRV_CONFIG_IOPORT_NUM_DEV (7)

lib/pbio/platform/nxt/pbioconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#define PBIO_CONFIG_LIGHT (0)
1010
#define PBIO_CONFIG_LOGGER (1)
1111
#define PBIO_CONFIG_MOTOR_PROCESS (1)
12-
#define PBIO_CONFIG_PORT (0)
13-
#define PBIO_CONFIG_PORT_NUM_DEV (0)
12+
#define PBIO_CONFIG_PORT (1)
13+
#define PBIO_CONFIG_PORT_NUM_DEV (7)
1414
#define PBIO_CONFIG_PORT_DCM (0)
1515
#define PBIO_CONFIG_PORT_DCM_PUP (0)
1616
#define PBIO_CONFIG_PORT_DCM_EV3 (0)

lib/pbio/platform/nxt/platform.c

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77
#include <stdint.h>
88
#include <string.h>
99

10-
#include <pbdrv/reset.h>
10+
#include <pbdrv/config.h>
11+
#include <pbdrv/ioport.h>
12+
1113
#include <pbio/button.h>
1214
#include <pbio/main.h>
1315
#include <pbio/os.h>
16+
#include <pbio/port_interface.h>
1417

1518
#include <pbsys/core.h>
1619
#include <pbsys/main.h>
1720
#include <pbsys/program_stop.h>
1821
#include <pbsys/status.h>
1922

23+
2024
#include <nxos/_display.h>
2125
#include <nxos/assert.h>
2226
#include <nxos/drivers/_aic.h>
@@ -29,6 +33,84 @@
2933
#include <nxos/drivers/systick.h>
3034
#include <nxos/interrupts.h>
3135

36+
const pbdrv_gpio_t pbdrv_ioport_platform_data_vcc_pin = {
37+
.bank = NULL,
38+
.pin = 0,
39+
};
40+
41+
const pbdrv_ioport_platform_data_t pbdrv_ioport_platform_data[PBDRV_CONFIG_IOPORT_NUM_DEV] = {
42+
{
43+
.port_id = PBIO_PORT_ID_A,
44+
.motor_driver_index = 0,
45+
.i2c_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
46+
.uart_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
47+
.external_port_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
48+
.counter_driver_index = 0,
49+
.pins = NULL,
50+
.supported_modes = PBIO_PORT_MODE_QUADRATURE,
51+
},
52+
{
53+
.port_id = PBIO_PORT_ID_B,
54+
.motor_driver_index = 1,
55+
.i2c_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
56+
.uart_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
57+
.external_port_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
58+
.counter_driver_index = 1,
59+
.pins = NULL,
60+
.supported_modes = PBIO_PORT_MODE_QUADRATURE,
61+
},
62+
{
63+
.port_id = PBIO_PORT_ID_C,
64+
.motor_driver_index = 2,
65+
.i2c_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
66+
.uart_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
67+
.external_port_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
68+
.counter_driver_index = 2,
69+
.pins = NULL,
70+
.supported_modes = PBIO_PORT_MODE_QUADRATURE,
71+
},
72+
{
73+
.port_id = PBIO_PORT_ID_1,
74+
.motor_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE, // todo, power pin, see ev3
75+
.external_port_index = 0,
76+
.counter_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
77+
.i2c_driver_index = 0,
78+
.uart_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
79+
.pins = NULL,
80+
.supported_modes = PBIO_PORT_MODE_NONE, // todo, lego mode, nxt dcm
81+
},
82+
{
83+
.port_id = PBIO_PORT_ID_2,
84+
.motor_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE, // todo, power pin, see ev3
85+
.external_port_index = 1,
86+
.counter_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
87+
.i2c_driver_index = 1,
88+
.uart_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
89+
.pins = NULL,
90+
.supported_modes = PBIO_PORT_MODE_NONE, // todo, lego mode, nxt dcm
91+
},
92+
{
93+
.port_id = PBIO_PORT_ID_3,
94+
.motor_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE, // todo, power pin, see ev3
95+
.external_port_index = 2,
96+
.counter_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
97+
.i2c_driver_index = 2,
98+
.uart_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
99+
.pins = NULL,
100+
.supported_modes = PBIO_PORT_MODE_NONE, // todo, lego mode, nxt dcm
101+
},
102+
{
103+
.port_id = PBIO_PORT_ID_4,
104+
.motor_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE, // todo, power pin, see ev3
105+
.external_port_index = 3,
106+
.counter_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
107+
.i2c_driver_index = 3,
108+
.uart_driver_index = PBDRV_IOPORT_INDEX_NOT_AVAILABLE,
109+
.pins = NULL,
110+
.supported_modes = PBIO_PORT_MODE_NONE, // todo, lego mode, nxt dcm
111+
},
112+
};
113+
32114
const char *pin = "1234";
33115

34116
static void legacy_bluetooth_init_blocking(void) {

0 commit comments

Comments
 (0)