26
26
27
27
#include <string.h>
28
28
29
+ #include "genhdr/mpversion.h"
29
30
#include "shared-bindings/_bleio/__init__.h"
30
31
#include "shared-bindings/_bleio/Adapter.h"
31
32
#include "shared-bindings/_bleio/Characteristic.h"
39
40
40
41
#include "py/mpstate.h"
41
42
42
- STATIC bleio_service_obj_t supervisor_ble_serial_service ;
43
- STATIC bleio_uuid_obj_t supervisor_ble_serial_service_uuid ;
44
- STATIC bleio_characteristic_obj_t supervisor_ble_rx_characteristic ;
45
- STATIC bleio_uuid_obj_t supervisor_ble_rx_uuid ;
46
- STATIC bleio_characteristic_obj_t supervisor_ble_tx_characteristic ;
47
- STATIC bleio_uuid_obj_t supervisor_ble_tx_uuid ;
43
+ STATIC bleio_service_obj_t supervisor_ble_circuitpython_service ;
44
+ STATIC bleio_uuid_obj_t supervisor_ble_circuitpython_service_uuid ;
45
+ STATIC bleio_characteristic_obj_t supervisor_ble_circuitpython_rx_characteristic ;
46
+ STATIC bleio_uuid_obj_t supervisor_ble_circuitpython_rx_uuid ;
47
+ STATIC bleio_characteristic_obj_t supervisor_ble_circuitpython_tx_characteristic ;
48
+ STATIC bleio_uuid_obj_t supervisor_ble_circuitpython_tx_uuid ;
49
+ STATIC bleio_characteristic_obj_t supervisor_ble_circuitpython_version_characteristic ;
50
+ STATIC bleio_uuid_obj_t supervisor_ble_circuitpython_version_uuid ;
48
51
49
- // This is the base UUID for the nordic uart service.
50
- const uint8_t nordic_uart_base_uuid [16 ] = {0x9e , 0xca , 0xdc , 0x24 , 0x0e , 0xe5 , 0xa9 , 0xe0 , 0x93 , 0xf3 , 0xa3 , 0xb5 , 0x00 , 0x00 , 0x40 , 0x6e };
52
+ // This is the base UUID for the CircuitPython service.
53
+ const uint8_t circuitpython_base_uuid [16 ] = {0x6e , 0x68 , 0x74 , 0x79 , 0x50 , 0x74 , 0x69 , 0x75 , 0x63 , 0x72 , 0x69 , 0x43 , 0x00 , 0x00 , 0xaf , 0xad };
51
54
52
55
STATIC mp_obj_list_t characteristic_list ;
53
56
STATIC mp_obj_t characteristic_list_items [2 ];
@@ -64,8 +67,8 @@ STATIC bleio_characteristic_buffer_obj_t _rx_buffer;
64
67
STATIC bool _enabled ;
65
68
66
69
void supervisor_start_bluetooth_serial (void ) {
67
- supervisor_ble_serial_service_uuid .base .type = & bleio_uuid_type ;
68
- common_hal_bleio_uuid_construct (& supervisor_ble_serial_service_uuid , 0x0001 , nordic_uart_base_uuid );
70
+ supervisor_ble_circuitpython_service_uuid .base .type = & bleio_uuid_type ;
71
+ common_hal_bleio_uuid_construct (& supervisor_ble_circuitpython_service_uuid , 0x0001 , circuitpython_base_uuid );
69
72
70
73
// We know we'll only be N characteristics so we can statically allocate it.
71
74
characteristic_list .base .type = & mp_type_list ;
@@ -74,50 +77,72 @@ void supervisor_start_bluetooth_serial(void) {
74
77
characteristic_list .items = characteristic_list_items ;
75
78
mp_seq_clear (characteristic_list .items , 0 , characteristic_list .alloc , sizeof (* characteristic_list .items ));
76
79
77
- supervisor_ble_serial_service .base .type = & bleio_service_type ;
78
- _common_hal_bleio_service_construct (& supervisor_ble_serial_service , & supervisor_ble_serial_service_uuid , false /* is secondary */ , & characteristic_list );
80
+ supervisor_ble_circuitpython_service .base .type = & bleio_service_type ;
81
+ _common_hal_bleio_service_construct (& supervisor_ble_circuitpython_service , & supervisor_ble_circuitpython_service_uuid , false /* is secondary */ , & characteristic_list );
79
82
80
83
// RX
81
- supervisor_ble_rx_uuid .base .type = & bleio_uuid_type ;
82
- common_hal_bleio_uuid_construct (& supervisor_ble_rx_uuid , 0x0002 , nordic_uart_base_uuid );
83
- common_hal_bleio_characteristic_construct (& supervisor_ble_rx_characteristic ,
84
- & supervisor_ble_serial_service ,
84
+ supervisor_ble_circuitpython_rx_uuid .base .type = & bleio_uuid_type ;
85
+ common_hal_bleio_uuid_construct (& supervisor_ble_circuitpython_rx_uuid , 0x0002 , circuitpython_base_uuid );
86
+ common_hal_bleio_characteristic_construct (& supervisor_ble_circuitpython_rx_characteristic ,
87
+ & supervisor_ble_circuitpython_service ,
85
88
0 , // handle (for remote only)
86
- & supervisor_ble_rx_uuid ,
89
+ & supervisor_ble_circuitpython_rx_uuid ,
87
90
CHAR_PROP_WRITE | CHAR_PROP_WRITE_NO_RESPONSE ,
88
91
SECURITY_MODE_NO_ACCESS ,
89
92
SECURITY_MODE_ENC_NO_MITM ,
90
93
BLE_GATTS_VAR_ATTR_LEN_MAX , // max length
91
94
false, // fixed length
92
95
NULL , // no initial value
93
- "CircuitPython Serial" );
96
+ NULL );
94
97
95
98
// TX
96
- supervisor_ble_tx_uuid .base .type = & bleio_uuid_type ;
97
- common_hal_bleio_uuid_construct (& supervisor_ble_tx_uuid , 0x0003 , nordic_uart_base_uuid );
98
- common_hal_bleio_characteristic_construct (& supervisor_ble_tx_characteristic ,
99
- & supervisor_ble_serial_service ,
99
+ supervisor_ble_circuitpython_tx_uuid .base .type = & bleio_uuid_type ;
100
+ common_hal_bleio_uuid_construct (& supervisor_ble_circuitpython_tx_uuid , 0x0003 , circuitpython_base_uuid );
101
+ common_hal_bleio_characteristic_construct (& supervisor_ble_circuitpython_tx_characteristic ,
102
+ & supervisor_ble_circuitpython_service ,
100
103
0 , // handle (for remote only)
101
- & supervisor_ble_tx_uuid ,
104
+ & supervisor_ble_circuitpython_tx_uuid ,
102
105
CHAR_PROP_NOTIFY ,
103
106
SECURITY_MODE_ENC_NO_MITM ,
104
107
SECURITY_MODE_NO_ACCESS ,
105
108
BLE_GATTS_VAR_ATTR_LEN_MAX , // max length
106
109
false, // fixed length
107
110
NULL , // no initial value
108
- "CircuitPython Serial" );
111
+ NULL );
112
+
113
+ // Version number
114
+ const char * version = MICROPY_GIT_TAG ;
115
+ mp_buffer_info_t bufinfo ;
116
+ bufinfo .buf = (uint8_t * )version ;
117
+ bufinfo .len = strlen (version );
118
+
119
+ supervisor_ble_circuitpython_version_uuid .base .type = & bleio_uuid_type ;
120
+ common_hal_bleio_uuid_construct (& supervisor_ble_circuitpython_version_uuid , 0x0100 , circuitpython_base_uuid );
121
+ common_hal_bleio_characteristic_construct (& supervisor_ble_circuitpython_version_characteristic ,
122
+ & supervisor_ble_circuitpython_service ,
123
+ 0 , // handle (for remote only)
124
+ & supervisor_ble_circuitpython_version_uuid ,
125
+ CHAR_PROP_READ ,
126
+ SECURITY_MODE_OPEN ,
127
+ SECURITY_MODE_NO_ACCESS ,
128
+ bufinfo .len , // max length
129
+ true, // fixed length
130
+ NULL , // no initial value
131
+ NULL ); // no description
132
+
133
+ common_hal_bleio_characteristic_set_value (& supervisor_ble_circuitpython_version_characteristic , & bufinfo );
109
134
110
135
// Use a PacketBuffer to transmit so that we glom characters to transmit
111
136
// together and save BLE overhead.
112
137
_common_hal_bleio_packet_buffer_construct (
113
- & _tx_packet_buffer , & supervisor_ble_tx_characteristic ,
138
+ & _tx_packet_buffer , & supervisor_ble_circuitpython_tx_characteristic ,
114
139
NULL , 0 ,
115
140
_outgoing1 , _outgoing2 , BLE_GATTS_VAR_ATTR_LEN_MAX ,
116
141
& tx_static_handler_entry );
117
142
118
143
// Use a CharacteristicBuffer for rx so we can read a single character at a time.
119
144
_common_hal_bleio_characteristic_buffer_construct (& _rx_buffer ,
120
- & supervisor_ble_rx_characteristic ,
145
+ & supervisor_ble_circuitpython_rx_characteristic ,
121
146
0.1f ,
122
147
(uint8_t * )_incoming , sizeof (_incoming ) * sizeof (uint32_t ),
123
148
& rx_static_handler_entry );
0 commit comments