Skip to content

Commit

Permalink
pbdrv/bluetooth: Report correct program size.
Browse files Browse the repository at this point in the history
Ensures the maximum program size can be saved on the hub.

Fixes pybricks/support#739
  • Loading branch information
laurensvalk committed Oct 20, 2022
1 parent 6171d8d commit 4637a84
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 20 deletions.
1 change: 0 additions & 1 deletion bricks/cityhub/pbsys_app_config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

#define PBSYS_APP_HUB_FEATURE_FLAGS (PBIO_PYBRICKS_FEATURE_REPL | PBIO_PYBRICKS_FEATURE_USER_PROG_FORMAT_MULTI_MPY_V6)
#define PBSYS_APP_USER_PROGRAM_SIZE (16 * 1024 - 512)
1 change: 0 additions & 1 deletion bricks/essentialhub/pbsys_app_config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

#define PBSYS_APP_HUB_FEATURE_FLAGS (PBIO_PYBRICKS_FEATURE_REPL | PBIO_PYBRICKS_FEATURE_USER_PROG_FORMAT_MULTI_MPY_V6)
#define PBSYS_APP_USER_PROGRAM_SIZE (255 * 1024)
1 change: 0 additions & 1 deletion bricks/movehub/pbsys_app_config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

#define PBSYS_APP_HUB_FEATURE_FLAGS (PBIO_PYBRICKS_FEATURE_USER_PROG_FORMAT_MULTI_MPY_V6)
#define PBSYS_APP_USER_PROGRAM_SIZE (4 * 1024 - 128)
1 change: 0 additions & 1 deletion bricks/primehub/pbsys_app_config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

#define PBSYS_APP_HUB_FEATURE_FLAGS (PBIO_PYBRICKS_FEATURE_REPL | PBIO_PYBRICKS_FEATURE_USER_PROG_FORMAT_MULTI_MPY_V6)
#define PBSYS_APP_USER_PROGRAM_SIZE (255 * 1024)
1 change: 0 additions & 1 deletion bricks/technichub/pbsys_app_config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

#define PBSYS_APP_HUB_FEATURE_FLAGS (PBIO_PYBRICKS_FEATURE_REPL | PBIO_PYBRICKS_FEATURE_USER_PROG_FORMAT_MULTI_MPY_V6)
#define PBSYS_APP_USER_PROGRAM_SIZE (16 * 1024 - 512)
3 changes: 2 additions & 1 deletion lib/pbio/drv/bluetooth/bluetooth_stm32_bluenrg.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <pbio/util.h>
#include <pbio/version.h>
#include <pbsys/app.h>
#include <pbsys/program_load.h>

#include <contiki.h>
#include <lego_lwp3.h>
Expand Down Expand Up @@ -845,7 +846,7 @@ static PT_THREAD(init_pybricks_service(struct pt *pt)) {
PT_WAIT_WHILE(pt, write_xfer_size);
{
uint8_t buf[PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE];
pbio_pybricks_hub_capabilities(buf, ATT_MTU - 3, PBSYS_APP_HUB_FEATURE_FLAGS, PBSYS_APP_USER_PROGRAM_SIZE);
pbio_pybricks_hub_capabilities(buf, ATT_MTU - 3, PBSYS_APP_HUB_FEATURE_FLAGS, PBSYS_PROGRAM_LOAD_MAX_PROGRAM_SIZE);
aci_gatt_update_char_value_begin(pybricks_service_handle, pybricks_hub_capabilities_char_handle,
0, PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE, buf);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <pbio/util.h>
#include <pbio/version.h>
#include <pbsys/app.h>
#include <pbsys/program_load.h>

#include <contiki.h>
#include <lego_lwp3.h>
Expand Down Expand Up @@ -1013,7 +1014,7 @@ static void handle_event(uint8_t *packet) {
uint8_t buf[PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE];

// REVISIT: client MTU may be smaller, in which case we can't used fixed value for MTU
pbio_pybricks_hub_capabilities(buf, ATT_MAX_MTU_SIZE - 3, PBSYS_APP_HUB_FEATURE_FLAGS, PBSYS_APP_USER_PROGRAM_SIZE);
pbio_pybricks_hub_capabilities(buf, ATT_MAX_MTU_SIZE - 3, PBSYS_APP_HUB_FEATURE_FLAGS, PBSYS_PROGRAM_LOAD_MAX_PROGRAM_SIZE);
rsp.len = sizeof(buf);
rsp.pValue = buf;
ATT_ReadRsp(connection_handle, &rsp);
Expand Down
6 changes: 4 additions & 2 deletions lib/pbio/drv/bluetooth/pybricks_service_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@
#include <stdint.h>
#include <string.h>

#include <pbsys/app.h>
#include <pbio/math.h>
#include <pbio/protocol.h>

#include <pbsys/app.h>
#include <pbsys/program_load.h>

#include "btstack_defines.h"
#include "ble/att_db.h"
#include "ble/att_server.h"
Expand Down Expand Up @@ -87,7 +89,7 @@ static uint16_t pybricks_service_read_callback(hci_con_handle_t con_handle, uint
if (attribute_handle == pybricks_hub_capabilities_value_handle) {
if (buffer && buffer_size >= PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE) {
pbio_pybricks_hub_capabilities(buffer, pbio_math_min(att_server_get_mtu(con_handle) - 3, 512),
PBSYS_APP_HUB_FEATURE_FLAGS, PBSYS_APP_USER_PROGRAM_SIZE);
PBSYS_APP_HUB_FEATURE_FLAGS, PBSYS_PROGRAM_LOAD_MAX_PROGRAM_SIZE);
}
return PBIO_PYBRICKS_HUB_CAPABILITIES_VALUE_SIZE;
}
Expand Down
10 changes: 0 additions & 10 deletions lib/pbio/include/pbsys/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@
#error "Application must define PBSYS_APP_HUB_FEATURE_FLAGS"
#endif

#if DOXYGEN
/**
* Specifies the maximum allowable user program size for the application.
*/
#define PBSYS_APP_USER_PROGRAM_SIZE
#endif
#ifndef PBSYS_APP_USER_PROGRAM_SIZE
#error "Application must define PBSYS_APP_USER_PROGRAM_SIZE"
#endif

#endif // _PBSYS_APP_H_

/** @} */
1 change: 0 additions & 1 deletion lib/pbio/test/pbsys_app_config.h
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#define PBSYS_APP_HUB_FEATURE_FLAGS 0
#define PBSYS_APP_USER_PROGRAM_SIZE 0

0 comments on commit 4637a84

Please sign in to comment.