Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions bricks/_common/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
sys/battery.c \
sys/command.c \
sys/core.c \
sys/hmi.c \
sys/hmi_lcd.c \
sys/hmi_pup.c \
sys/hmi_none.c \
sys/host.c \
sys/light_matrix.c \
sys/light.c \
sys/main.c \
sys/program_stop.c \
Expand Down
13 changes: 13 additions & 0 deletions lib/pbio/drv/pwm/pwm_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#if PBDRV_CONFIG_PWM_TEST

#include <math.h>
#include <stdint.h>
#include <stdio.h>

#include <tinytest.h>
Expand All @@ -16,6 +18,10 @@

#include "../drv/pwm/pwm.h"

#define MATRIX_SIZE (3)

uint8_t test_light_matrix_set_pixel_last_brightness[MATRIX_SIZE][MATRIX_SIZE];

typedef struct {
uint32_t duty_channel;
uint32_t duty_value;
Expand All @@ -27,6 +33,13 @@ static pbio_error_t test_set_duty(pbdrv_pwm_dev_t *dev, uint32_t ch, uint32_t va
test_private_data_t *priv = dev->priv;
priv->duty_channel = ch;
priv->duty_value = value;

// The value we get from the LED PWM driver is squared for gamma correction, so undo here.
float val = (value * 10000.0f) / UINT16_MAX;
uint8_t brightness = sqrt(val) + 0.5;

test_light_matrix_set_pixel_last_brightness[ch / MATRIX_SIZE][ch % MATRIX_SIZE] = brightness;

return PBIO_SUCCESS;
}

Expand Down
File renamed without changes.
31 changes: 28 additions & 3 deletions lib/pbio/include/pbio/light_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,51 @@

#include <stdint.h>

#include <pbdrv/led.h>

#include <pbio/config.h>
#include <pbio/error.h>
#include <pbio/geometry.h>
#include <pbio/light_animation.h>

/** A light matrix instance. */
typedef struct _pbio_light_matrix_t pbio_light_matrix_t;
typedef struct {
/** Animation instance for background animation. */
pbio_light_animation_t animation;
/** Animation cell data. */
const uint8_t *animation_cells;
/** The number of cells in @p animation_cells */
uint8_t num_animation_cells;
/** The index of the currently displayed animation cell. */
uint8_t current_cell;
/** Animation update rate in milliseconds. */
uint16_t interval;
/** Size of the matrix (assumes matrix is square). */
uint8_t size;
/** Orientation of the matrix: which side is "up". */
pbio_geometry_side_t up_side;
/** The driver for this light matrix. */
pbdrv_led_array_dev_t *led_array_dev;
} pbio_light_matrix_t;

#if PBIO_CONFIG_LIGHT_MATRIX

pbio_error_t pbio_light_matrix_get_dev(uint8_t index, uint8_t size, pbio_light_matrix_t **light_matrix);
uint8_t pbio_light_matrix_get_size(pbio_light_matrix_t *light_matrix);
void pbio_light_matrix_set_orientation(pbio_light_matrix_t *light_matrix, pbio_geometry_side_t up_side);
pbio_error_t pbio_light_matrix_clear(pbio_light_matrix_t *light_matrix);
pbio_error_t pbio_light_matrix_set_rows(pbio_light_matrix_t *light_matrix, const uint8_t *rows);
pbio_error_t pbio_light_matrix_set_pixel(pbio_light_matrix_t *light_matrix, uint8_t row, uint8_t col, uint8_t brightness);
pbio_error_t pbio_light_matrix_set_pixel(pbio_light_matrix_t *light_matrix, uint8_t row, uint8_t col, uint8_t brightness, bool clear_animation);
pbio_error_t pbio_light_matrix_set_image(pbio_light_matrix_t *light_matrix, const uint8_t *image);
void pbio_light_matrix_start_animation(pbio_light_matrix_t *light_matrix, const uint8_t *cells, uint8_t num_cells, uint16_t interval);
void pbio_light_matrix_stop_animation(pbio_light_matrix_t *light_matrix);

#else // PBIO_CONFIG_LIGHT_MATRIX

static inline pbio_error_t pbio_light_matrix_get_dev(uint8_t index, uint8_t size, pbio_light_matrix_t **light_matrix) {
return PBIO_ERROR_NOT_SUPPORTED;
}

static inline uint8_t pbio_light_matrix_get_size(pbio_light_matrix_t *light_matrix) {
return 0;
}
Expand All @@ -46,7 +71,7 @@ static inline pbio_error_t pbio_light_matrix_set_rows(pbio_light_matrix_t *light
return PBIO_ERROR_NOT_SUPPORTED;
}

static inline pbio_error_t pbio_light_matrix_set_pixel(pbio_light_matrix_t *light_matrix, uint8_t row, uint8_t col, uint8_t brightness) {
static inline pbio_error_t pbio_light_matrix_set_pixel(pbio_light_matrix_t *light_matrix, uint8_t row, uint8_t col, uint8_t brightness, bool clear_animation) {
return PBIO_ERROR_NOT_SUPPORTED;
}

Expand Down
2 changes: 0 additions & 2 deletions lib/pbio/include/pbio/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,4 @@ pbio_error_t pbio_port_process_none_thread(pbio_os_state_t *state, void *context

void pbio_os_process_start(pbio_os_process_t *process, pbio_os_process_func_t func, void *context);

void pbio_os_process_init(pbio_os_process_t *process, pbio_os_process_func_t func);

#endif // _PBIO_OS_H_
3 changes: 3 additions & 0 deletions lib/pbio/platform/city_hub/pbsysconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_3_NATIVE (0)
#define PBSYS_CONFIG_BATTERY_CHARGER (0)
#define PBSYS_CONFIG_BLUETOOTH (1)
#define PBSYS_CONFIG_HMI (1)
#define PBSYS_CONFIG_HMI_STOP_BUTTON (1 << 5) // center
#define PBSYS_CONFIG_HMI_PUP (1)
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
#define PBSYS_CONFIG_HOST (1)
Expand Down
3 changes: 3 additions & 0 deletions lib/pbio/platform/essential_hub/pbsysconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_3_NATIVE (1)
#define PBSYS_CONFIG_BATTERY_CHARGER (1)
#define PBSYS_CONFIG_BLUETOOTH (1)
#define PBSYS_CONFIG_HMI (1)
#define PBSYS_CONFIG_HMI_STOP_BUTTON (1 << 5) // center
#define PBSYS_CONFIG_HMI_PUP (1)
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
#define PBSYS_CONFIG_HOST (1)
Expand Down
1 change: 1 addition & 0 deletions lib/pbio/platform/ev3/pbdrvconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define PBDRV_CONFIG_BUTTON (1)
#define PBDRV_CONFIG_BUTTON_GPIO (1)
#define PBDRV_CONFIG_BUTTON_GPIO_NUM_BUTTON (6)
#define PBDRV_CONFIG_BUTTON_INSTANT_RESET (0)

#define PBDRV_CONFIG_DISPLAY (1)
#define PBDRV_CONFIG_DISPLAY_EV3 (1)
Expand Down
1 change: 0 additions & 1 deletion lib/pbio/platform/ev3/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define PBIO_CONFIG_IMAGE (1)
#define PBIO_CONFIG_IMU (0)
#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LIGHT_MATRIX (1)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_PORT (1)
Expand Down
8 changes: 4 additions & 4 deletions lib/pbio/platform/ev3/pbsysconfig.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2024 The Pybricks Authors
// Copyright (c) 2020-2025 The Pybricks Authors

#define PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_REPL (1)
#define PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_PORT_VIEW (0)
#define PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_IMU_CALIBRATION (0)
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6 (1)
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_3_NATIVE (0)
#define PBSYS_CONFIG_BATTERY_TEMP_ESTIMATION (1)
#define PBSYS_CONFIG_HMI (1)
#define PBSYS_CONFIG_HMI_STOP_BUTTON (1 << 7) // top left, back button
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using macro names instead of hard-coding numbers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including pbio which includes pbdrv here seems to mess things up, leading them to be always zero.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would leave out the include here since this is just a config file and it would be up to the code that actually uses it to add the proper include (which it should have anyway if it is doing something with buttons).

Files that don't use this config option won't have a problem because it is just a #define so it won't try to resolve the symbol.

#define PBSYS_CONFIG_HMI_LCD (1)
#define PBSYS_CONFIG_HMI_NUM_SLOTS (5)
#define PBSYS_CONFIG_HOST (1)
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (21)
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (1)
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX_DISPLAY (1)
#define PBSYS_CONFIG_MAIN (1)
#define PBSYS_CONFIG_STORAGE (1)
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (5)
Expand All @@ -22,5 +23,4 @@
#define PBSYS_CONFIG_STATUS_LIGHT_STATE_ANIMATIONS (1)
#define PBSYS_CONFIG_STATUS_LIGHT_STATE_ANIMATIONS_HUE (120)
#define PBSYS_CONFIG_USER_PROGRAM (1)
#define PBSYS_CONFIG_USER_PROGRAM_AUTO_START (0)
#define PBSYS_CONFIG_PROGRAM_STOP (1)
17 changes: 9 additions & 8 deletions lib/pbio/platform/ev3/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@

#include <umm_malloc.h>

#include <pbio/port_interface.h>
#include <pbio/button.h>

#include <pbdrv/cache.h>
#include <pbdrv/compiler.h>
#include <pbdrv/ioport.h>
#include <pbio/port_interface.h>
#include <pbdrv/reset.h>

#include "exceptionhandler.h"

Expand Down Expand Up @@ -852,18 +855,16 @@ void SystemInit(void) {
umm_init_heap(&pb_umm_heap_start, &pb_umm_heap_end - &pb_umm_heap_start);
}


#include <pbio/button.h>
#include <pbdrv/reset.h>

/*
* This is called from the IRQ handler after every systick. This should be
* removed when the final user interface is implemented. For now this serves
* as a very convenient way to power off the EV3 for fast iteration.
* This is called from the IRQ handler after every systick. Can be enabled
* to run emergency poweroff for faster iteration and debugging. User data
* is not saved when powering off this way.
*/
void lazy_poweroff_hook(void) {
#if PBDRV_CONFIG_BUTTON_INSTANT_RESET
if (pbdrv_button_get_pressed() & PBIO_BUTTON_LEFT_UP) {
pbdrv_reset_power_off();
return;
}
#endif
}
3 changes: 3 additions & 0 deletions lib/pbio/platform/move_hub/pbsysconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_3_NATIVE (0)
#define PBSYS_CONFIG_BATTERY_CHARGER (0)
#define PBSYS_CONFIG_BLUETOOTH (1)
#define PBSYS_CONFIG_HMI (1)
#define PBSYS_CONFIG_HMI_STOP_BUTTON (1 << 5) // center
#define PBSYS_CONFIG_HMI_PUP (1)
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
#define PBSYS_CONFIG_HOST (1)
Expand Down
8 changes: 5 additions & 3 deletions lib/pbio/platform/nxt/pbsysconfig.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2023 The Pybricks Authors
// Copyright (c) 2020-2025 The Pybricks Authors

#define PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_REPL (1)
#define PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_PORT_VIEW (0)
#define PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_IMU_CALIBRATION (0)
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6 (1)
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_3_NATIVE (0)
#define PBSYS_CONFIG_HMI_NUM_SLOTS (1)
#define PBSYS_CONFIG_HMI (1)
#define PBSYS_CONFIG_HMI_STOP_BUTTON (1 << 2) // down
#define PBSYS_CONFIG_HMI_NONE (1)
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
#define PBSYS_CONFIG_HOST (1)
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (64)
#define PBSYS_CONFIG_MAIN (1)
Expand All @@ -18,5 +21,4 @@
#define PBSYS_CONFIG_STATUS_LIGHT_BLUETOOTH (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)
1 change: 1 addition & 0 deletions lib/pbio/platform/prime_hub/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_LIGHT_MATRIX (1)
#define PBIO_CONFIG_LIGHT_MATRIX_NUM_DEV (1)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_PORT (1)
#define PBIO_CONFIG_PORT_NUM_DEV (6)
Expand Down
9 changes: 7 additions & 2 deletions lib/pbio/platform/prime_hub/pbsysconfig.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2023 The Pybricks Authors
// Copyright (c) 2020-2025 The Pybricks Authors

#define PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_REPL (1)
#define PBSYS_CONFIG_FEATURE_BUILTIN_USER_PROGRAM_PORT_VIEW (1)
Expand All @@ -9,8 +9,13 @@
#define PBSYS_CONFIG_BATTERY_CHARGER (1)
#define PBSYS_CONFIG_BLUETOOTH (1)
#define PBSYS_CONFIG_BLUETOOTH_TOGGLE (1)
#define PBSYS_CONFIG_BLUETOOTH_TOGGLE_BUTTON (512) // PBIO_BUTTON_RIGHT_UP, but enum value cannot be used here.
#define PBSYS_CONFIG_HMI (1)
#define PBSYS_CONFIG_HMI_STOP_BUTTON (1 << 5) // center
#define PBSYS_CONFIG_HMI_NUM_SLOTS (5)
#define PBSYS_CONFIG_HMI_PUP (1)
#define PBSYS_CONFIG_HMI_PUP_LIGHT_MATRIX_INDEX (0)
#define PBSYS_CONFIG_HMI_PUP_BLUETOOTH_BUTTON (1 << 9) // right up
#define PBSYS_CONFIG_HMI_PUP_LEFT_RIGHT_ENABLE (1)
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (1)
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX_LED_ARRAY (1)
#define PBSYS_CONFIG_HOST (1)
Expand Down
5 changes: 4 additions & 1 deletion lib/pbio/platform/technic_hub/pbsysconfig.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020-2023 The Pybricks Authors
// Copyright (c) 2020-2025 The Pybricks Authors

#include "pbdrvconfig.h"

Expand All @@ -10,6 +10,9 @@
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_3_NATIVE (0)
#define PBSYS_CONFIG_BATTERY_CHARGER (0)
#define PBSYS_CONFIG_BLUETOOTH (1)
#define PBSYS_CONFIG_HMI (1)
#define PBSYS_CONFIG_HMI_STOP_BUTTON (1 << 5) // center
#define PBSYS_CONFIG_HMI_PUP (1)
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
#define PBSYS_CONFIG_HOST (1)
Expand Down
4 changes: 3 additions & 1 deletion lib/pbio/platform/test/pbdrvconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#define PBDRV_CONFIG_LED_NUM_DEV (0)

#define PBDRV_CONFIG_LED_ARRAY (1)
#define PBDRV_CONFIG_LED_ARRAY_NUM_DEV (0)
#define PBDRV_CONFIG_LED_ARRAY_NUM_DEV (1)
#define PBDRV_CONFIG_LED_ARRAY_PWM (1)
#define PBDRV_CONFIG_LED_ARRAY_PWM_NUM_DEV (1)

#define PBDRV_CONFIG_MOTOR_DRIVER (1)
#define PBDRV_CONFIG_MOTOR_DRIVER_NUM_DEV (6)
Expand Down
1 change: 1 addition & 0 deletions lib/pbio/platform/test/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_LIGHT_MATRIX (1)
#define PBIO_CONFIG_LIGHT_MATRIX_NUM_DEV (1)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_PORT (1)
#define PBIO_CONFIG_PORT_NUM_DEV (6)
Expand Down
14 changes: 14 additions & 0 deletions lib/pbio/platform/test/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <pbio/port_interface.h>

#include "../../drv/motor_driver/motor_driver_virtual_simulation.h"
#include "../../drv/led/led_array_pwm.h"

const pbdrv_gpio_t pbdrv_ioport_platform_data_vcc_pin = {
.bank = NULL,
Expand Down Expand Up @@ -128,3 +129,16 @@ const pbdrv_motor_driver_virtual_simulation_platform_data_t
.endstop_angle_positive = INFINITY,
},
};

const pbdrv_led_array_pwm_platform_data_t pbdrv_led_array_pwm_platform_data[PBDRV_CONFIG_LED_ARRAY_PWM_NUM_DEV] = {
{
.pwm_chs = (const uint8_t[]) {
0, 1, 2,
3, 4, 5,
6, 7, 8
},
.num_pwm_chs = 9,
.pwm_id = 0,
.id = 0,
},
};
2 changes: 1 addition & 1 deletion lib/pbio/src/light/animation.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <pbio/util.h>

#include "animation.h"
#include <pbio/light_animation.h>

/**
* This is used as a value for the next_animation field to indicate when an
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/src/light/color_light.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <pbio/light.h>
#include <pbio/util.h>

#include "animation.h"
#include <pbio/light_animation.h>
#include "color_light.h"

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/src/light/color_light.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <pbio/error.h>
#include <pbio/light.h>

#include "animation.h"
#include <pbio/light_animation.h>

#ifndef _PBIO_LIGHT_COLOR_LIGHT_H_
#define _PBIO_LIGHT_COLOR_LIGHT_H_
Expand Down
Loading