Skip to content

Commit cda7489

Browse files
committed
bricks/virtualhub: Enable screen attribute.
1 parent 19359be commit cda7489

File tree

7 files changed

+38
-2
lines changed

7 files changed

+38
-2
lines changed

.vscode/c_cpp_properties.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@
367367
"includePath": [
368368
"${workspaceFolder}/bricks/virtualhub",
369369
"${workspaceFolder}/bricks/virtualhub/build",
370+
"${workspaceFolder}/bricks/virtualhub/build-debug",
370371
"${workspaceFolder}/lib/contiki-core",
371372
"${workspaceFolder}/lib/lego",
372373
"${workspaceFolder}/lib/lwrb/src/include",
@@ -375,6 +376,7 @@
375376
"${workspaceFolder}/lib/pbio/platform/virtual_hub",
376377
"${workspaceFolder}/micropython",
377378
"${workspaceFolder}",
379+
"${workspaceFolder}/lib/umm_malloc/src",
378380
"/usr/include/python3.10"
379381
],
380382
"defines": [

bricks/virtualhub/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ PBIO_PLATFORM = virtual_hub
55
PB_MCU_FAMILY = native
66
PB_FROZEN_MODULES = 1
77
MICROPY_ROM_TEXT_COMPRESSION = 1
8-
8+
PB_LIB_UMM_MALLOC = 1
99

1010
include ../_common/common.mk

bricks/virtualhub/dbglog/dbglog.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2025 The Pybricks Authors
3+
//
4+
// Hack to allow umm_info() to print in MicroPython.
5+
6+
#include "py/mpprint.h"
7+
8+
#undef DBGLOG_FORCE
9+
#define DBGLOG_FORCE(force, fmt, ...) mp_printf(&mp_plat_print, fmt,##__VA_ARGS__)
10+
11+
#define DBGLOG_32_BIT_PTR(p) (p)

bricks/virtualhub/mpconfigport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define PYBRICKS_PY_COMMON_MOTORS (1)
2626
#define PYBRICKS_PY_COMMON_SPEAKER (0)
2727
#define PYBRICKS_PY_COMMON_SYSTEM (1)
28+
#define PYBRICKS_PY_COMMON_SYSTEM_UMM_INFO (1)
2829
#define PYBRICKS_PY_EV3DEVICES (0)
2930
#define PYBRICKS_PY_EXPERIMENTAL (1)
3031
#define PYBRICKS_PY_HUBS (1)
@@ -33,7 +34,7 @@
3334
#define PYBRICKS_PY_PARAMETERS (1)
3435
#define PYBRICKS_PY_PARAMETERS_BUTTON (1)
3536
#define PYBRICKS_PY_PARAMETERS_ICON (0)
36-
#define PYBRICKS_PY_PARAMETERS_IMAGE (0)
37+
#define PYBRICKS_PY_PARAMETERS_IMAGE (1)
3738
#define PYBRICKS_PY_PUPDEVICES (1)
3839
#define PYBRICKS_PY_PUPDEVICES_REMOTE (0)
3940
#define PYBRICKS_PY_DEVICES (1)

lib/pbio/platform/virtual_hub/platform.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <pbdrv/config.h>
1818
#include <pbdrv/ioport.h>
1919

20+
#include <umm_malloc.h>
21+
2022
const pbdrv_gpio_t pbdrv_ioport_platform_data_vcc_pin = {
2123
.bank = NULL,
2224
.pin = 0,
@@ -144,6 +146,10 @@ extern void _main(void);
144146

145147
int main(int argc, char **argv) {
146148

149+
// Separate heap for large allocations - defined in linker script.
150+
static uint8_t umm_heap[1024 * 1024 * 2];
151+
umm_init_heap(umm_heap, sizeof(umm_heap));
152+
147153
// Parse given program, else otherwise default to REPL.
148154
if (argc > 1) {
149155

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2025 The Pybricks Authors
3+
//
4+
// Configuration for umm_malloc memory allocator for Virtual platform.
5+
// See lib/umm_malloc/src/umm_malloc_cfg.h for details.
6+
7+
// We only use this for large allocations, like images and we have a lot of RAM
8+
// on the host, so we can use a larger block size to reduce overhead.
9+
#define UMM_BLOCK_BODY_SIZE 256
10+
11+
#define UMM_INFO
12+
#define DBGLOG_ENABLE

pybricks/hubs/pb_type_virtualhub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
#include <pybricks/common.h>
1919
#include <pybricks/hubs.h>
20+
#include <pybricks/parameters.h>
2021

2122
typedef struct _hubs_VirtualHub_obj_t {
2223
mp_obj_base_t base;
2324
mp_obj_t battery;
2425
mp_obj_t buttons;
2526
mp_obj_t light;
27+
mp_obj_t screen;
2628
mp_obj_t system;
2729
} hubs_VirtualHub_obj_t;
2830

@@ -32,6 +34,7 @@ static mp_obj_t hubs_VirtualHub_make_new(const mp_obj_type_t *type, size_t n_arg
3234
self->buttons = pb_type_Keypad_obj_new(MP_OBJ_FROM_PTR(self), pb_type_button_pressed_hub_single_button);
3335
// FIXME: Implement lights.
3436
// self->light = common_ColorLight_internal_obj_new(pbsys_status_light_main);
37+
self->screen = pb_type_Image_display_obj_new();
3538
self->system = MP_OBJ_FROM_PTR(&pb_type_System);
3639
return MP_OBJ_FROM_PTR(self);
3740
}
@@ -40,6 +43,7 @@ static const pb_attr_dict_entry_t hubs_VirtualHub_attr_dict[] = {
4043
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_battery, hubs_VirtualHub_obj_t, battery),
4144
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_buttons, hubs_VirtualHub_obj_t, buttons),
4245
// PB_DEFINE_CONST_ATTR_RO(MP_QSTR_light, hubs_VirtualHub_obj_t, light),
46+
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_screen, hubs_VirtualHub_obj_t, screen),
4347
PB_DEFINE_CONST_ATTR_RO(MP_QSTR_system, hubs_VirtualHub_obj_t, system),
4448
PB_ATTR_DICT_SENTINEL
4549
};

0 commit comments

Comments
 (0)