3232#include "py/mphal.h"
3333#include "py/obj.h"
3434#include "py/objarray.h"
35- #include "py/objstr.h"
3635#include "py/qstr.h"
3736#include "py/runtime.h"
3837#include "extmod/modbluetooth.h"
@@ -62,9 +61,8 @@ typedef struct {
6261 mp_obj_t irq_data_tuple ;
6362 uint8_t irq_data_addr_bytes [6 ];
6463 uint16_t irq_data_data_alloc ;
65- uint8_t * irq_data_data_bytes ;
66- mp_obj_str_t irq_data_addr ;
67- mp_obj_str_t irq_data_data ;
64+ mp_obj_array_t irq_data_addr ;
65+ mp_obj_array_t irq_data_data ;
6866 mp_obj_bluetooth_uuid_t irq_data_uuid ;
6967 ringbuf_t ringbuf ;
7068 #if MICROPY_PY_BLUETOOTH_GATTS_ON_READ_CALLBACK
@@ -262,11 +260,9 @@ STATIC mp_obj_t bluetooth_ble_make_new(const mp_obj_type_t *type, size_t n_args,
262260 #endif
263261
264262 // Pre-allocated buffers for address, payload and uuid.
265- o -> irq_data_addr .base .type = & mp_type_bytes ;
266- o -> irq_data_addr .data = o -> irq_data_addr_bytes ;
263+ mp_obj_memoryview_init (& o -> irq_data_addr , 'B' , 0 , 0 , o -> irq_data_addr_bytes );
267264 o -> irq_data_data_alloc = MICROPY_PY_BLUETOOTH_MAX_EVENT_DATA_BYTES_LEN (MICROPY_PY_BLUETOOTH_RINGBUF_SIZE );
268- o -> irq_data_data .base .type = & mp_type_bytes ;
269- o -> irq_data_data .data = m_new (uint8_t , o -> irq_data_data_alloc );
265+ mp_obj_memoryview_init (& o -> irq_data_data , 'B' , 0 , 0 , m_new (uint8_t , o -> irq_data_data_alloc ));
270266 o -> irq_data_uuid .base .type = & bluetooth_uuid_type ;
271267
272268 // Allocate the default ringbuf.
@@ -352,7 +348,7 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
352348 // Get old buffer sizes and pointers
353349 uint8_t * old_ringbuf_buf = self -> ringbuf .buf ;
354350 size_t old_ringbuf_alloc = self -> ringbuf .size ;
355- uint8_t * old_irq_data_buf = (uint8_t * )self -> irq_data_data .data ;
351+ uint8_t * old_irq_data_buf = (uint8_t * )self -> irq_data_data .items ;
356352 size_t old_irq_data_alloc = self -> irq_data_data_alloc ;
357353
358354 // Atomically update the ringbuf and irq data
@@ -362,7 +358,7 @@ STATIC mp_obj_t bluetooth_ble_config(size_t n_args, const mp_obj_t *args, mp_map
362358 self -> ringbuf .iget = 0 ;
363359 self -> ringbuf .iput = 0 ;
364360 self -> irq_data_data_alloc = irq_data_alloc ;
365- self -> irq_data_data .data = irq_data ;
361+ self -> irq_data_data .items = irq_data ;
366362 MICROPY_PY_BLUETOOTH_EXIT
367363
368364 // Free old buffers
@@ -850,7 +846,7 @@ const mp_obj_module_t mp_module_ubluetooth = {
850846
851847#include <stdio.h>
852848
853- STATIC void ringbuf_extract (ringbuf_t * ringbuf , mp_obj_tuple_t * data_tuple , size_t n_u16 , size_t n_u8 , mp_obj_str_t * bytes_addr , size_t n_i8 , mp_obj_bluetooth_uuid_t * uuid , mp_obj_str_t * bytes_data ) {
849+ STATIC void ringbuf_extract (ringbuf_t * ringbuf , mp_obj_tuple_t * data_tuple , size_t n_u16 , size_t n_u8 , mp_obj_array_t * bytes_addr , size_t n_i8 , mp_obj_bluetooth_uuid_t * uuid , mp_obj_array_t * bytes_data ) {
854850 assert (ringbuf_avail (ringbuf ) >= n_u16 * 2 + n_u8 + (bytes_addr ? 6 : 0 ) + n_i8 + (uuid ? 1 : 0 ) + (bytes_data ? 1 : 0 ));
855851 size_t j = 0 ;
856852
@@ -863,8 +859,7 @@ STATIC void ringbuf_extract(ringbuf_t *ringbuf, mp_obj_tuple_t *data_tuple, size
863859 if (bytes_addr ) {
864860 bytes_addr -> len = 6 ;
865861 for (size_t i = 0 ; i < bytes_addr -> len ; ++ i ) {
866- // cast away const, this is actually bt->irq_addr_bytes.
867- ((uint8_t * )bytes_addr -> data )[i ] = ringbuf_get (ringbuf );
862+ ((uint8_t * )bytes_addr -> items )[i ] = ringbuf_get (ringbuf );
868863 }
869864 data_tuple -> items [j ++ ] = MP_OBJ_FROM_PTR (bytes_addr );
870865 }
@@ -880,12 +875,11 @@ STATIC void ringbuf_extract(ringbuf_t *ringbuf, mp_obj_tuple_t *data_tuple, size
880875 #endif
881876 // The code that enqueues into the ringbuf should ensure that it doesn't
882877 // put more than bt->irq_data_data_alloc bytes into the ringbuf, because
883- // that's what's available here in bt->irq_data_bytes .
878+ // that's what's available here.
884879 if (bytes_data ) {
885880 bytes_data -> len = ringbuf_get16 (ringbuf );
886881 for (size_t i = 0 ; i < bytes_data -> len ; ++ i ) {
887- // cast away const, this is actually bt->irq_data_bytes.
888- ((uint8_t * )bytes_data -> data )[i ] = ringbuf_get (ringbuf );
882+ ((uint8_t * )bytes_data -> items )[i ] = ringbuf_get (ringbuf );
889883 }
890884 data_tuple -> items [j ++ ] = MP_OBJ_FROM_PTR (bytes_data );
891885 }
0 commit comments