Skip to content

Commit

Permalink
bricks/ev3rt: Use pbsys.
Browse files Browse the repository at this point in the history
This gets it inline with the other hubs, making development easier.

It does not have any pbsys implementation for stdio, but it launches into the REPL and uses stdio as defined in mphalport. This allows it to be used with mpremote for the time being.
  • Loading branch information
laurensvalk committed Oct 15, 2024
1 parent e24e126 commit ad111f3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
"${workspaceFolder}/bricks/ev3rt/build",
"${workspaceFolder}/micropython",
"${workspaceFolder}/lib/ev3rt-lib/sdk/common",
"${workspaceFolder}/lib/ev3rt-lib/sdk/common/ev3api/include",
"${workspaceFolder}/lib/ev3rt-lib/sdk/common/ev3api/src",
"${workspaceFolder}/lib/ev3rt-lib/target/ev3_gcc/pil/include",
"${workspaceFolder}/lib/ev3rt-lib",
"${workspaceFolder}/lib/ev3rt-lib/include",
"${workspaceFolder}/lib/ev3rt-lib/target/ev3_gcc",
Expand Down
39 changes: 2 additions & 37 deletions bricks/ev3rt/app.c
Original file line number Diff line number Diff line change
@@ -1,37 +1,2 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors

#include "ev3api.h"
#include "app.h"

#include <pbsys/main.h>

// For now, this file is the main entry point from EV3RT. Eventually, this
// file can be dropped and main_task() can be mapped to main() in pbsys/main.
// For now it enters the MicroPython REPL directly for convenient debugging.

static char heap[1024 * 256];

void main_task(intptr_t unused) {

// Show the Pybricks logo on the screen so we know that something is
// running. This should be replaced by an appropriate driver in pbio and
// called from the system hmi interface in pbsys.
memfile_t memfile;
image_t image;
if (ev3_memfile_load("/pybricks.bmp", &memfile) == E_OK &&
ev3_image_load(&memfile, &image) == E_OK) {
ev3_lcd_draw_image(&image, 0, 0);
}

while (true) {
pbsys_main_program_t program = {
.id = PBIO_PYBRICKS_USER_PROGRAM_ID_REPL,
.code_start = heap,
.code_end = heap,
.user_ram_start = heap,
.user_ram_end = heap + sizeof(heap),
};
pbsys_main_run_program(&program);
}
}
// Unused, but required for EV3RT build system.
// The main Pybricks entry point is in pbio/platform/ev3rt/platform.c
5 changes: 5 additions & 0 deletions lib/pbio/platform/ev3rt/pbdrvconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#define PBDRV_CONFIG_CLOCK (1)
#define PBDRV_CONFIG_CLOCK_EV3RT (1)

#define PBDRV_CONFIG_BLOCK_DEVICE (1)
#define PBDRV_CONFIG_BLOCK_DEVICE_TEST (1)
#define PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE (8 * 1024)
#define PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE_USER (512)

#define PBDRV_CONFIG_HAS_PORT_A (1)
#define PBDRV_CONFIG_HAS_PORT_B (1)
#define PBDRV_CONFIG_HAS_PORT_C (1)
Expand Down
11 changes: 8 additions & 3 deletions lib/pbio/platform/ev3rt/pbsysconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
#define PBSYS_CONFIG_MAIN (1)
#define PBSYS_CONFIG_STORAGE (0)
#define PBSYS_CONFIG_STORAGE (1)
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (1)
#define PBSYS_CONFIG_STORAGE_RAM_SIZE (258 * 1024)
#define PBSYS_CONFIG_STORAGE_ROM_SIZE (PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE)
#define PBSYS_CONFIG_STORAGE_USER_DATA_SIZE (PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE_USER)
#define PBSYS_CONFIG_STATUS_LIGHT (0)
#define PBSYS_CONFIG_STATUS_LIGHT_BATTERY (0)
#define PBSYS_CONFIG_STATUS_LIGHT_BLUETOOTH (0)
#define PBSYS_CONFIG_STATUS_LIGHT_STATE_ANIMATIONS (1)
#define PBSYS_CONFIG_USER_PROGRAM (0)
#define PBSYS_CONFIG_STATUS_LIGHT_STATE_ANIMATIONS (0)
#define PBSYS_CONFIG_USER_PROGRAM (1)
#define PBSYS_CONFIG_USER_PROGRAM_AUTO_START (1)
#define PBSYS_CONFIG_PROGRAM_STOP (1)
35 changes: 33 additions & 2 deletions lib/pbio/platform/ev3rt/platform.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2022 The Pybricks Authors
// Copyright (c) 2024 The Pybricks Authors

// This file is unused, but required for the common make file.
#include "ev3api.h"
#include "app.h"

#include <pbsys/main.h>

/**
* Any device specific initialization that isn't already done by EV3RT can
* be done here. This follows the pattern of the embedded hubs where there is
* a bit more to do.
*/
static void SystemInit(void) {
// Show the Pybricks logo on the screen so we know that something is
// running. This should be replaced by an appropriate driver in pbio and
// called from the system hmi interface in pbsys.
memfile_t memfile;
image_t image;
if (ev3_memfile_load("/pybricks.bmp", &memfile) == E_OK &&
ev3_image_load(&memfile, &image) == E_OK) {
ev3_lcd_draw_image(&image, 0, 0);
}
}

/**
* This is the main user task launched by EV3RT. It initializes the system
* and then runs to the main pbsys function. This is similar to how these two
* subsequent calls are normally made from startup.s on the embedded hubs.
*/
void main_task(intptr_t unused) {
SystemInit();
extern int main(int argc, char **argv);
main(0, NULL);
}
2 changes: 1 addition & 1 deletion lib/pbio/platform/nxt/pbsysconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (1)
#define PBSYS_CONFIG_STORAGE_RAM_SIZE (10 * 1024)
#define PBSYS_CONFIG_STORAGE_ROM_SIZE (PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE)
#define PBSYS_CONFIG_STORAGE_USER_DATA_SIZE (512)
#define PBSYS_CONFIG_STORAGE_USER_DATA_SIZE (PBDRV_CONFIG_BLOCK_DEVICE_TEST_SIZE_USER)
#define PBSYS_CONFIG_STATUS_LIGHT (0)
#define PBSYS_CONFIG_STATUS_LIGHT_BATTERY (0)
#define PBSYS_CONFIG_STATUS_LIGHT_BLUETOOTH (0)
Expand Down

0 comments on commit ad111f3

Please sign in to comment.