Skip to content

Commit ed3272d

Browse files
dlechlaurensvalk
authored andcommitted
pbio/protocol: Add slots info to hub capabilities and status.
In order to support multiple program slots, connected apps will need to know how many slots are available on the hub and what the currently selected slot is. These are added to the hub capabilities and status report respectively and the Pybricks Profile version is bumped to 1.5.0.
1 parent 6fdc7e1 commit ed3272d

File tree

12 files changed

+53
-16
lines changed

12 files changed

+53
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
### Added
88
- Experimental support for USB connectivity on SPIKE Prime ([pybricks-micropython#208]).
99
- Initial support for `pybricks.iodevices.UARTDevice` ([support#220]).
10+
- Enabled previously hidden support for multiple code
11+
slots ([pybricks-micropython#264], [pybricks-micropython#312]). A new
12+
(unreleased) version of Pybricks Code is needed to use this.
1013

1114
### Changed
1215
- Extensive overhaul of UART and port drivers on all hubs. This affects all
@@ -21,6 +24,8 @@
2124
[support#220]: https://github.com/pybricks/support/issues/220
2225
[support#2206]: https://github.com/pybricks/support/issues/2206
2326
[pybricks-micropython#208]: https://github.com/pybricks/pybricks-micropython/pull/208
27+
[pybricks-micropython#264]: https://github.com/pybricks/pybricks-micropython/pull/264
28+
[pybricks-micropython#312]: https://github.com/pybricks/pybricks-micropython/pull/312
2429

2530
## [3.6.1] - 2025-03-11
2631

lib/pbio/drv/bluetooth/bluetooth_stm32_bluenrg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ static PT_THREAD(init_pybricks_service(struct pt *pt)) {
10781078
PT_WAIT_WHILE(pt, write_xfer_size);
10791079
{
10801080
uint8_t buf[PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE];
1081-
pbio_pybricks_hub_capabilities(buf, ATT_MTU - 3, PBSYS_CONFIG_APP_FEATURE_FLAGS, pbsys_storage_get_maximum_program_size());
1081+
pbio_pybricks_hub_capabilities(buf, ATT_MTU - 3, PBSYS_CONFIG_APP_FEATURE_FLAGS, pbsys_storage_get_maximum_program_size(), 0);
10821082
aci_gatt_update_char_value_begin(pybricks_service_handle, pybricks_hub_capabilities_char_handle,
10831083
0, PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE, buf);
10841084
}

lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ static void handle_event(uint8_t *packet) {
14831483
uint8_t buf[PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE];
14841484

14851485
// REVISIT: this assumes connection_handle == conn_handle
1486-
pbio_pybricks_hub_capabilities(buf, conn_mtu - 3, PBSYS_CONFIG_APP_FEATURE_FLAGS, pbsys_storage_get_maximum_program_size());
1486+
pbio_pybricks_hub_capabilities(buf, conn_mtu - 3, PBSYS_CONFIG_APP_FEATURE_FLAGS, pbsys_storage_get_maximum_program_size(), 0);
14871487
rsp.len = sizeof(buf);
14881488
rsp.pValue = buf;
14891489
ATT_ReadRsp(connection_handle, &rsp);

lib/pbio/drv/bluetooth/pybricks_service_server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static uint16_t pybricks_service_read_callback(hci_con_handle_t con_handle, uint
8989
if (attribute_handle == pybricks_hub_capabilities_value_handle) {
9090
if (buffer && buffer_size >= PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE) {
9191
pbio_pybricks_hub_capabilities(buffer, pbio_int_math_min(att_server_get_mtu(con_handle) - 3, 512),
92-
PBSYS_CONFIG_APP_FEATURE_FLAGS, pbsys_storage_get_maximum_program_size());
92+
PBSYS_CONFIG_APP_FEATURE_FLAGS, pbsys_storage_get_maximum_program_size(), PBSYS_CONFIG_HMI_NUM_SLOTS);
9393
}
9494
return PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE;
9595
}

lib/pbio/drv/usb/stm32_usbd/usbd_desc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ void USBD_Pybricks_Desc_Init(void) {
536536
pbio_pybricks_hub_capabilities(ptr,
537537
USBD_PYBRICKS_MAX_PACKET_SIZE - 1,
538538
PBSYS_CONFIG_APP_FEATURE_FLAGS,
539-
pbsys_storage_get_maximum_program_size());
539+
pbsys_storage_get_maximum_program_size(),
540+
PBSYS_CONFIG_HMI_NUM_SLOTS);
540541
ptr += PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE;
541542

542543
/* Update wTotalLength field in BOS Descriptor */

lib/pbio/include/pbio/protocol.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#define PBIO_PROTOCOL_VERSION_MAJOR 1
2525

2626
/** The minor version number for the protocol. */
27-
#define PBIO_PROTOCOL_VERSION_MINOR 4
27+
#define PBIO_PROTOCOL_VERSION_MINOR 5
2828

2929
/** The patch version number for the protocol. */
3030
#define PBIO_PROTOCOL_VERSION_PATCH 0
@@ -342,9 +342,9 @@ typedef enum {
342342
#define PBIO_PYBRICKS_STATUS_FLAG(status) (1 << status)
343343

344344
/** Size of status report event message in bytes. */
345-
#define PBIO_PYBRICKS_EVENT_STATUS_REPORT_SIZE 6
345+
#define PBIO_PYBRICKS_EVENT_STATUS_REPORT_SIZE 7
346346

347-
uint32_t pbio_pybricks_event_status_report(uint8_t *buf, uint32_t flags, pbio_pybricks_user_program_id_t program_id);
347+
uint32_t pbio_pybricks_event_status_report(uint8_t *buf, uint32_t flags, pbio_pybricks_user_program_id_t program_id, uint8_t slot);
348348

349349
/**
350350
* Application-specific feature flag supported by a hub.
@@ -391,12 +391,13 @@ typedef enum {
391391
void pbio_pybricks_hub_capabilities(uint8_t *buf,
392392
uint16_t max_char_size,
393393
pbio_pybricks_feature_flags_t feature_flags,
394-
uint32_t max_user_prog_size);
394+
uint32_t max_user_prog_size,
395+
uint8_t num_slots);
395396

396397
/**
397398
* Number of bytes in the Pybricks hub capabilities characteristic value.
398399
*/
399-
#define PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE 10
400+
#define PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE 11
400401

401402
extern const uint8_t pbio_pybricks_service_uuid[];
402403
extern const uint8_t pbio_pybricks_command_event_char_uuid[];

lib/pbio/include/pbsys/status.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <pbio/protocol.h>
1616

17-
#define PBSYS_STATUS_REPORT_SIZE 6
17+
#define PBSYS_STATUS_REPORT_SIZE 7
1818

1919
/**
2020
* Status flag change.

lib/pbio/platform/prime_hub/pbsysconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define PBSYS_CONFIG_BLUETOOTH (1)
1111
#define PBSYS_CONFIG_BLUETOOTH_TOGGLE (1)
1212
#define PBSYS_CONFIG_BLUETOOTH_TOGGLE_BUTTON (512) // PBIO_BUTTON_RIGHT_UP, but enum value cannot be used here.
13-
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
13+
#define PBSYS_CONFIG_HMI_NUM_SLOTS (5)
1414
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (1)
1515
#define PBSYS_CONFIG_HOST (1)
1616
#define PBSYS_CONFIG_MAIN (1)

lib/pbio/platform/test/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_1_NATIVE (0)
99
#define PBSYS_CONFIG_BLUETOOTH (1)
1010
#define PBSYS_CONFIG_HOST (1)
11+
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
1112
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
1213
#define PBSYS_CONFIG_MAIN (0)
1314
#define PBSYS_CONFIG_STORAGE (0)

lib/pbio/src/protocol/pybricks.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@ _Static_assert(NUM_PBIO_PYBRICKS_STATUS <= sizeof(uint32_t) * 8,
1717
*
1818
* The buffer must be at least ::PBIO_PYBRICKS_EVENT_STATUS_REPORT_SIZE bytes.
1919
*
20+
* @since Pybricks Profile v1.0.0
21+
*
22+
* Program ID parameter was added in Pybricks Profile v1.4.0.
23+
* Slot parameter was added in Pybricks Profile v1.5.0.
24+
*
2025
* @param [in] buf The buffer to hold the binary data.
2126
* @param [in] flags The status flags.
22-
* @param [in] program_id Program identifier.
27+
* @param [in] program_id Program identifier of currently running program.
28+
* @param [in] slot The currently selected program slot.
2329
* @return The number of bytes written to @p buf.
2430
*/
25-
uint32_t pbio_pybricks_event_status_report(uint8_t *buf, uint32_t flags, pbio_pybricks_user_program_id_t program_id) {
31+
uint32_t pbio_pybricks_event_status_report(uint8_t *buf, uint32_t flags, pbio_pybricks_user_program_id_t program_id, uint8_t slot) {
2632
buf[0] = PBIO_PYBRICKS_EVENT_STATUS_REPORT;
2733
pbio_set_uint32_le(&buf[1], flags);
2834
buf[5] = program_id;
35+
buf[6] = slot;
2936
return PBIO_PYBRICKS_EVENT_STATUS_REPORT_SIZE;
3037
}
3138

@@ -37,15 +44,22 @@ uint32_t pbio_pybricks_event_status_report(uint8_t *buf, uint32_t flags, pbio_py
3744
* @param [in] max_char_size The maximum characteristic value size (negotiated MTU - 3).
3845
* @param [in] feature_flags The feature flags.
3946
* @param [in] max_user_prog_size The maximum allowable size for the user program.
47+
* @param [in] num_slots The number of program slots available on the hub.
48+
*
49+
* @since Pybricks Profile v1.2.0
50+
*
51+
* num_slots was added in Pybricks Profile v1.5.0.
4052
*/
4153
void pbio_pybricks_hub_capabilities(uint8_t *buf,
4254
uint16_t max_char_size,
4355
pbio_pybricks_feature_flags_t feature_flags,
44-
uint32_t max_user_prog_size) {
56+
uint32_t max_user_prog_size,
57+
uint8_t num_slots) {
4558

4659
pbio_set_uint16_le(&buf[0], max_char_size);
4760
pbio_set_uint32_le(&buf[2], feature_flags);
4861
pbio_set_uint32_le(&buf[6], max_user_prog_size);
62+
buf[10] = num_slots;
4963
}
5064

5165
/**

0 commit comments

Comments
 (0)