Skip to content

Commit 4ae364e

Browse files
committed
Improve streaming API
Change the firmware streaming functions.
1 parent 8d1902f commit 4ae364e

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "cyw43_ll.h"
1414
#include "cyw43_config.h"
1515
#include "cybt_shared_bus_driver.h"
16-
#include "cyw43_firmware_defs.h"
1716

1817
#if CYW43_USE_HEX_BTFW
1918
extern const char brcm_patch_version[];
@@ -123,35 +122,20 @@ int cyw43_btbus_init(cyw43_ll_t *self) {
123122
}
124123

125124
cybt_debug("cybt_fw_download\n");
126-
const uint8_t *fw_data_buf;
127-
uint32_t fw_data_len;
125+
const uint8_t *fw_data_buf = NULL;
126+
uint32_t fw_data_len = 0;
128127
#if CYW43_USE_HEX_BTFW
129128
cybt_printf("CYW43_USE_HEX_BTFW is true\n");
130129
#ifndef NDEBUG
131130
cybt_printf("BT FW download, version = %s\n", brcm_patch_version);
132131
#endif
133132
fw_data_len = brcm_patch_ram_length;
134133
fw_data_buf = brcm_patchram_buf;
135-
#else
136-
const cyw43_firmware_details_t *firmware_details = cyw43_get_firmware_funcs()->firmware_details();
137-
fw_data_len = firmware_details->bt_fw_len;
138-
fw_data_buf = firmware_details->bt_fw_addr;
139-
if (cyw43_get_firmware_funcs()->start_bt_fw && cyw43_get_firmware_funcs()->start_bt_fw(firmware_details) != 0) {
140-
assert(false);
141-
return CYW43_EIO;
142-
}
143134
#endif
144135
ret = cybt_fw_download(fw_data_buf,
145136
fw_data_len,
146137
p_write_buf,
147138
p_hex_buf);
148-
149-
#if !CYW43_USE_HEX_BTFW
150-
if (cyw43_get_firmware_funcs()->end) {
151-
cyw43_get_firmware_funcs()->end();
152-
}
153-
#endif
154-
155139
cybt_debug("cybt_fw_download_finish\n");
156140
cybt_fw_download_finish(p_write_buf, p_hex_buf);
157141

src/rp2_common/pico_cyw43_driver/cybt_shared_bus/cybt_shared_bus_driver.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ typedef struct
8181
uint32_t bt2host_out_addr;
8282
} cybt_fw_membuf_info_t;
8383

84-
cybt_fw_membuf_info_t buf_info;
84+
static cybt_fw_membuf_info_t buf_info;
8585

8686
#define BTFW_ADDR_MODE_UNKNOWN (0)
8787
#define BTFW_ADDR_MODE_EXTENDED (1)
@@ -131,6 +131,7 @@ typedef struct hex_file_data
131131
#endif
132132

133133
static cyw43_ll_t *cyw43_ll = NULL;
134+
static void *streaming_context;
134135

135136
static cybt_result_t cybt_reg_write(uint32_t reg_addr, uint32_t value);
136137
static cybt_result_t cybt_reg_read(uint32_t reg_addr, uint32_t *p_value);
@@ -265,7 +266,7 @@ static void cybt_fw_get_bytes(uint8_t *dst, const uint8_t **addr, uint8_t count)
265266
#if CYW43_USE_HEX_BTFW
266267
memcpy(dst, *addr, count);
267268
#else
268-
const uint8_t *data = cyw43_get_firmware_funcs()->get_bt_fw(*addr, count, dst, count);
269+
const uint8_t *data = cyw43_get_firmware_funcs()->stream_fw(streaming_context, count, dst);
269270
if (data != dst) {
270271
memcpy(dst, data, count);
271272
}
@@ -334,12 +335,19 @@ cybt_result_t cybt_fw_download(const uint8_t *p_bt_firmware,
334335
return CYBT_ERR_BADARG;
335336
}
336337

337-
if (NULL == p_bt_firmware || 0 == bt_firmware_len || NULL == p_write_buf || NULL == p_hex_buf) {
338+
if (NULL == p_write_buf || NULL == p_hex_buf) {
338339
return CYBT_ERR_BADARG;
339340
}
340-
341+
#if CYW43_USE_HEX_BTFW
342+
if (NULL == p_bt_firmware || 0 == bt_firmware_len) {
343+
return CYBT_ERR_BADARG;
344+
}
345+
#else
346+
if (cyw43_get_firmware_funcs()->start_fw_stream(cyw43_get_firmware_funcs()->firmware_details(), CYW43_FIRMWARE_BLUETOOTH, &streaming_context) != 0) {
347+
assert(false);
348+
return CYW43_EIO;
349+
}
341350
// BT firmware starts with length of version string including a null terminator
342-
#if !CYW43_USE_HEX_BTFW
343351
uint8_t version_len;
344352
cybt_fw_get_bytes(&version_len, &p_bt_firmware, 1);
345353
cybt_fw_get_bytes(p_hex_buf, &p_bt_firmware, version_len);
@@ -413,6 +421,9 @@ cybt_result_t cybt_fw_download(const uint8_t *p_bt_firmware,
413421
write_data_len - first_write_len);
414422
}
415423
}
424+
#if !CYW43_USE_HEX_BTFW
425+
cyw43_get_firmware_funcs()->end_fw_stream(streaming_context, CYW43_FIRMWARE_BLUETOOTH);
426+
#endif
416427
return CYBT_SUCCESS;
417428
}
418429

0 commit comments

Comments
 (0)