Skip to content

Commit 58679dc

Browse files
committed
Merge remote-tracking branch 'origin/main' into bitmap-read-2
2 parents 97b6664 + bc690d4 commit 58679dc

File tree

1,779 files changed

+32294
-25646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,779 files changed

+32294
-25646
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ jobs:
4343
run: |
4444
gcc --version
4545
python3 --version
46-
- name: Translations
47-
run: make check-translate
4846
- name: New boards check
4947
run: python3 -u ci_new_boards_check.py
5048
working-directory: tools

.github/workflows/pre-commit.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ name: pre-commit
77
on:
88
pull_request:
99
push:
10-
branches: [main]
1110

1211
jobs:
1312
pre-commit:
@@ -16,10 +15,13 @@ jobs:
1615
- uses: actions/checkout@v1
1716
- uses: actions/setup-python@v1
1817
- name: Install deps
19-
run: sudo apt-get update && sudo apt-get install -y gettext
18+
run: |
19+
sudo apt-add-repository -y -u ppa:pybricks/ppa
20+
sudo apt-get install -y black gettext uncrustify
21+
pip3 install polib
2022
- name: Populate selected submodules
2123
run: git submodule update --init extmod/ulab
22-
- name: set PY
24+
- name: Set PY
2325
run: echo >>$GITHUB_ENV PY="$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')"
2426
- uses: actions/cache@v2
2527
with:

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ repos:
1111
exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*|ports/esp32s2/esp-idf-config/.*|ports/esp32s2/boards/.*/sdkconfig)'
1212
- id: trailing-whitespace
1313
exclude: '^(tests/.*\.exp|tests/cmdline/.*|tests/.*/data/.*)'
14+
- repo: local
15+
hooks:
16+
- id: translations
17+
name: Translations
18+
entry: sh -c "if ! make check-translate; then make translate; fi"
19+
types: [c]
20+
pass_filenames: false
21+
language: system
22+
- id: formatting
23+
name: Formatting
24+
entry: python3 tools/codeformat.py
25+
types_or: [c, python]
26+
language: system

BUILDING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,23 @@ Example:
8585

8686
If your port/build includes `arm-none-eabi-gdb-py`, consider using it instead, as it can be used for better register
8787
debugging with https://github.com/bnahill/PyCortexMDebug
88+
89+
# Code Quality Checks
90+
91+
We apply code quality checks using pre-commit. Install pre-commit once per system with
92+
93+
python3 -mpip install pre-commit
94+
95+
Activate it once per git clone with
96+
97+
pre-commit --install
98+
99+
Pre-commit also requires some additional programs to be installed through your package manager:
100+
101+
* Standard Unix tools such as make, find, etc
102+
* The gettext package, any modern version
103+
* uncrustify version 0.71 (0.72 is also tested)
104+
105+
Each time you create a git commit, the pre-commit quality checks will be run. You can also run them e.g., with `pre-commit run foo.c` or `pre-commit run --all` to run on all files whether modified or not.
106+
107+
Some pre-commit quality checks require your active attention to resolve, others (such as the formatting checks of uncrustify) are made automatically and must simply be incorporated into your code changes by committing them.

devices/ble_hci/common-hal/_bleio/Adapter.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
5353
#define SEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000000) / (RESOLUTION))
54-
#define UNITS_TO_SEC(TIME, RESOLUTION) (((TIME) * (RESOLUTION)) / 1000000)
54+
#define UNITS_TO_SEC(TIME, RESOLUTION) (((TIME)*(RESOLUTION)) / 1000000)
5555
// 0.625 msecs (625 usecs)
5656
#define ADV_INTERVAL_UNIT_FLOAT_SECS (0.000625)
5757
// Microseconds is the base unit. The macros above know that.
@@ -63,7 +63,7 @@
6363

6464
// TODO make this settable from Python.
6565
#define DEFAULT_TX_POWER 0 // 0 dBm
66-
#define MAX_ANONYMOUS_ADV_TIMEOUT_SECS (60*15)
66+
#define MAX_ANONYMOUS_ADV_TIMEOUT_SECS (60 * 15)
6767
#define MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS (180)
6868

6969
#define BLE_MIN_CONN_INTERVAL MSEC_TO_UNITS(15, UNIT_0_625_MS)
@@ -289,7 +289,7 @@ STATIC void bleio_adapter_hci_init(bleio_adapter_obj_t *self) {
289289

290290
// Get version information.
291291
if (hci_read_local_version(&self->hci_version, &self->hci_revision, &self->lmp_version,
292-
&self->manufacturer, &self->lmp_subversion) != HCI_OK) {
292+
&self->manufacturer, &self->lmp_subversion) != HCI_OK) {
293293
mp_raise_bleio_BluetoothError(translate("Could not read HCI version"));
294294
}
295295
// Get supported features.
@@ -414,11 +414,11 @@ bool common_hal_bleio_adapter_set_address(bleio_adapter_obj_t *self, bleio_addre
414414
return hci_le_set_random_address(bufinfo.buf) == HCI_OK;
415415
}
416416

417-
mp_obj_str_t* common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self) {
417+
mp_obj_str_t *common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self) {
418418
return self->name;
419419
}
420420

421-
void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char* name) {
421+
void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char *name) {
422422
self->name = mp_obj_new_str(name, strlen(name));
423423
mp_buffer_info_t bufinfo;
424424
mp_get_buffer_raise(self->name, &bufinfo, MP_BUFFER_READ);
@@ -459,7 +459,7 @@ void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char* na
459459
// return true;
460460
// }
461461

462-
mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t* prefixes, size_t prefix_length, bool extended, mp_int_t buffer_size, mp_float_t timeout, mp_float_t interval, mp_float_t window, mp_int_t minimum_rssi, bool active) {
462+
mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t *prefixes, size_t prefix_length, bool extended, mp_int_t buffer_size, mp_float_t timeout, mp_float_t interval, mp_float_t window, mp_int_t minimum_rssi, bool active) {
463463
// TODO
464464
mp_raise_NotImplementedError(NULL);
465465
check_enabled(self);
@@ -704,7 +704,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
704704

705705
uint8_t handle[1] = { 0 };
706706
uint16_t duration_10msec[1] = { timeout * 100 };
707-
uint8_t max_ext_adv_evts[1] = { 0 };
707+
uint8_t max_ext_adv_evts[1] = { 0 };
708708
hci_check_error(
709709
hci_le_set_extended_advertising_enable(
710710
BT_HCI_LE_ADV_ENABLE,
@@ -789,11 +789,11 @@ void common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self, bool
789789
} else {
790790
if (timeout > MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS) {
791791
mp_raise_bleio_BluetoothError(translate("Timeout is too long: Maximum timeout length is %d seconds"),
792-
MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS);
792+
MAX_LIMITED_DISCOVERABLE_ADV_TIMEOUT_SECS);
793793
}
794794
}
795795

796-
const uint32_t result =_common_hal_bleio_adapter_start_advertising(
796+
const uint32_t result = _common_hal_bleio_adapter_start_advertising(
797797
self, connectable, anonymous, timeout, interval,
798798
advertising_data_bufinfo->buf,
799799
advertising_data_bufinfo->len,
@@ -820,11 +820,11 @@ void common_hal_bleio_adapter_stop_advertising(bleio_adapter_obj_t *self) {
820820
hci_check_error(result);
821821
}
822822

823-
//TODO startup CircuitPython advertising again.
823+
// TODO startup CircuitPython advertising again.
824824
}
825825

826826
// Note that something stopped advertising, such as a connection happening.
827-
//Don't ask the adapter to stop.
827+
// Don't ask the adapter to stop.
828828
void bleio_adapter_advertising_was_stopped(bleio_adapter_obj_t *self) {
829829
self->now_advertising = false;
830830
self->extended_advertising = false;
@@ -876,14 +876,14 @@ void common_hal_bleio_adapter_erase_bonding(bleio_adapter_obj_t *self) {
876876
mp_raise_NotImplementedError(NULL);
877877
check_enabled(self);
878878

879-
//FIX bonding_erase_storage();
879+
// FIX bonding_erase_storage();
880880
}
881881

882882
uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *attribute) {
883883
check_enabled(adapter);
884884

885885
// The handle is the index of this attribute in the attributes list.
886-
uint16_t handle = (uint16_t) adapter->attributes->len;
886+
uint16_t handle = (uint16_t)adapter->attributes->len;
887887
mp_obj_list_append(adapter->attributes, attribute);
888888

889889
if (MP_OBJ_IS_TYPE(attribute, &bleio_service_type)) {
@@ -896,7 +896,7 @@ uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *att
896896
return handle;
897897
}
898898

899-
mp_obj_t* bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle) {
899+
mp_obj_t *bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle) {
900900
check_enabled(adapter);
901901

902902
if (handle == 0 || handle >= adapter->attributes->len) {
@@ -912,12 +912,12 @@ uint16_t bleio_adapter_max_attribute_handle(bleio_adapter_obj_t *adapter) {
912912
}
913913

914914

915-
void bleio_adapter_gc_collect(bleio_adapter_obj_t* adapter) {
916-
gc_collect_root((void**)adapter, sizeof(bleio_adapter_obj_t) / sizeof(size_t));
917-
gc_collect_root((void**)bleio_connections, sizeof(bleio_connections) / sizeof(size_t));
915+
void bleio_adapter_gc_collect(bleio_adapter_obj_t *adapter) {
916+
gc_collect_root((void **)adapter, sizeof(bleio_adapter_obj_t) / sizeof(size_t));
917+
gc_collect_root((void **)bleio_connections, sizeof(bleio_connections) / sizeof(size_t));
918918
}
919919

920-
void bleio_adapter_reset(bleio_adapter_obj_t* adapter) {
920+
void bleio_adapter_reset(bleio_adapter_obj_t *adapter) {
921921

922922
if (!common_hal_bleio_adapter_get_enabled(adapter)) {
923923
return;
@@ -939,7 +939,7 @@ void bleio_adapter_reset(bleio_adapter_obj_t* adapter) {
939939

940940
}
941941

942-
void bleio_adapter_background(bleio_adapter_obj_t* adapter) {
942+
void bleio_adapter_background(bleio_adapter_obj_t *adapter) {
943943
if (!common_hal_bleio_adapter_get_enabled(adapter)) {
944944
return;
945945
}

devices/ble_hci/common-hal/_bleio/Adapter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef struct _bleio_adapter_obj_t {
4949
bleio_scanresults_obj_t *scan_results;
5050
mp_obj_t name;
5151
mp_obj_tuple_t *connection_objs;
52-
busio_uart_obj_t* hci_uart;
52+
busio_uart_obj_t *hci_uart;
5353
digitalio_digitalinout_obj_t *rts_digitalinout;
5454
digitalio_digitalinout_obj_t *cts_digitalinout;
5555
bool allocated; // True when in use.
@@ -72,7 +72,7 @@ typedef struct _bleio_adapter_obj_t {
7272
// Generic services characteristics.
7373
bleio_characteristic_obj_t *device_name_characteristic;
7474
bleio_characteristic_obj_t *appearance_characteristic;
75-
bleio_characteristic_obj_t * service_changed_characteristic;
75+
bleio_characteristic_obj_t *service_changed_characteristic;
7676

7777
uint16_t max_acl_buffer_len;
7878
uint16_t max_acl_num_buffers;
@@ -90,10 +90,10 @@ typedef struct _bleio_adapter_obj_t {
9090

9191
uint16_t bleio_adapter_add_attribute(bleio_adapter_obj_t *adapter, mp_obj_t *attribute);
9292
void bleio_adapter_advertising_was_stopped(bleio_adapter_obj_t *self);
93-
mp_obj_t* bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle);
93+
mp_obj_t *bleio_adapter_get_attribute(bleio_adapter_obj_t *adapter, uint16_t handle);
9494
uint16_t bleio_adapter_max_attribute_handle(bleio_adapter_obj_t *adapter);
95-
void bleio_adapter_background(bleio_adapter_obj_t* adapter);
96-
void bleio_adapter_gc_collect(bleio_adapter_obj_t* adapter);
97-
void bleio_adapter_reset(bleio_adapter_obj_t* adapter);
95+
void bleio_adapter_background(bleio_adapter_obj_t *adapter);
96+
void bleio_adapter_gc_collect(bleio_adapter_obj_t *adapter);
97+
void bleio_adapter_reset(bleio_adapter_obj_t *adapter);
9898

9999
#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_ADAPTER_H

devices/ble_hci/common-hal/_bleio/Characteristic.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ bleio_service_obj_t *common_hal_bleio_characteristic_get_service(bleio_character
7878
return self->service;
7979
}
8080

81-
size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self, uint8_t* buf, size_t len) {
81+
size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self, uint8_t *buf, size_t len) {
8282
// Do GATT operations only if this characteristic has been added to a registered service.
8383
if (self->handle != BLE_GATT_HANDLE_INVALID) {
84-
//FIX uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
84+
// FIX uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
8585
if (common_hal_bleio_service_get_is_remote(self->service)) {
86-
//FIX read remote chars
87-
//uint8_t rsp[MAX(len, 512)];
88-
//FIX improve att_read_req to write into our requested buffer.
86+
// FIX read remote chars
87+
// uint8_t rsp[MAX(len, 512)];
88+
// FIX improve att_read_req to write into our requested buffer.
8989
// return att_read_req(conn_handle, self->handle, rsp);
90-
return 0; //FIX
90+
return 0; // FIX
9191
} else {
9292
mp_buffer_info_t bufinfo;
9393
if (!mp_get_buffer(self->value, &bufinfo, MP_BUFFER_READ)) {
@@ -113,13 +113,13 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self,
113113
// Do GATT operations only if this characteristic has been added to a registered service.
114114
if (self->handle != BLE_GATT_HANDLE_INVALID) {
115115
if (common_hal_bleio_service_get_is_remote(self->service)) {
116-
//FIX uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
116+
// FIX uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection);
117117
if (self->props & CHAR_PROP_WRITE) {
118-
//FIX writing remote chars
119-
//uint8_t rsp[sizeof(bt_att_error_rsp)];
120-
//att_write_req(conn_handle, self->handle, bufinfo->buf, bufinfo->len, rsp);
118+
// FIX writing remote chars
119+
// uint8_t rsp[sizeof(bt_att_error_rsp)];
120+
// att_write_req(conn_handle, self->handle, bufinfo->buf, bufinfo->len, rsp);
121121
} else if (self->props & CHAR_PROP_WRITE_NO_RESPONSE) {
122-
//att_write_cmd(conn_handle, self->handle, bufinfo->buff, bufinfo->len);
122+
// att_write_cmd(conn_handle, self->handle, bufinfo->buff, bufinfo->len);
123123
} else {
124124
mp_raise_bleio_BluetoothError(translate("Characteristic not writable"));
125125
}
@@ -172,7 +172,7 @@ void common_hal_bleio_characteristic_add_descriptor(bleio_characteristic_obj_t *
172172
self->service->end_handle = descriptor->handle;
173173

174174
mp_obj_list_append(MP_OBJ_FROM_PTR(self->descriptor_list),
175-
MP_OBJ_FROM_PTR(descriptor));
175+
MP_OBJ_FROM_PTR(descriptor));
176176
}
177177

178178
void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate) {
@@ -191,8 +191,8 @@ void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self,
191191
(notify ? CCCD_NOTIFY : 0) |
192192
(indicate ? CCCD_INDICATE : 0);
193193

194-
//FIX do remote
195-
(void) cccd_value;
194+
// FIX do remote
195+
(void)cccd_value;
196196
// uint8_t rsp[sizeof(bt_att_error_rsp)];
197197
// if (att_write_req(conn_handle, self->cccd->handle, &cccd_value, sizeof(cccd_value)) == 0) {
198198
// mp_raise_bleio_BluetoothError(translate("Could not write CCCD"));

devices/ble_hci/common-hal/_bleio/CharacteristicBuffer.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ void bleio_characteristic_buffer_update(bleio_characteristic_buffer_obj_t *self,
4747

4848
// Assumes that timeout and buffer_size have been validated before call.
4949
void common_hal_bleio_characteristic_buffer_construct(bleio_characteristic_buffer_obj_t *self,
50-
bleio_characteristic_obj_t *characteristic,
51-
mp_float_t timeout,
52-
size_t buffer_size) {
50+
bleio_characteristic_obj_t *characteristic,
51+
mp_float_t timeout,
52+
size_t buffer_size) {
5353

5454
self->characteristic = characteristic;
5555
self->timeout_ms = timeout * 1000;
@@ -64,10 +64,10 @@ uint32_t common_hal_bleio_characteristic_buffer_read(bleio_characteristic_buffer
6464
uint64_t start_ticks = supervisor_ticks_ms64();
6565

6666
// Wait for all bytes received or timeout
67-
while ( (ringbuf_num_filled(&self->ringbuf) < len) && (supervisor_ticks_ms64() - start_ticks < self->timeout_ms) ) {
67+
while ((ringbuf_num_filled(&self->ringbuf) < len) && (supervisor_ticks_ms64() - start_ticks < self->timeout_ms)) {
6868
RUN_BACKGROUND_TASKS;
6969
// Allow user to break out of a timeout with a KeyboardInterrupt.
70-
if ( mp_hal_is_interrupted() ) {
70+
if (mp_hal_is_interrupted()) {
7171
return 0;
7272
}
7373
}
@@ -97,8 +97,8 @@ void common_hal_bleio_characteristic_buffer_deinit(bleio_characteristic_buffer_o
9797

9898
bool common_hal_bleio_characteristic_buffer_connected(bleio_characteristic_buffer_obj_t *self) {
9999
return self->characteristic != NULL &&
100-
self->characteristic->service != NULL &&
101-
(!self->characteristic->service->is_remote ||
102-
(self->characteristic->service->connection != MP_OBJ_NULL &&
103-
common_hal_bleio_connection_get_connected(self->characteristic->service->connection)));
100+
self->characteristic->service != NULL &&
101+
(!self->characteristic->service->is_remote ||
102+
(self->characteristic->service->connection != MP_OBJ_NULL &&
103+
common_hal_bleio_connection_get_connected(self->characteristic->service->connection)));
104104
}

0 commit comments

Comments
 (0)