Skip to content

Commit 0e30dd8

Browse files
committed
merge from upstream; working; includes debug_out code for debugging via Saleae for posterity
2 parents dfe50d0 + 837abd6 commit 0e30dd8

File tree

237 files changed

+9711
-3661
lines changed

Some content is hidden

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

237 files changed

+9711
-3661
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Install deps
3737
run: |
3838
sudo apt-get install -y eatmydata
39-
sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64
39+
sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64 latexmk texlive-fonts-recommended texlive-latex-recommended texlive-latex-extra
4040
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid isort black awscli
4141
- name: Versions
4242
run: |
@@ -73,12 +73,19 @@ jobs:
7373
with:
7474
name: stubs
7575
path: circuitpython-stubs*
76-
- name: Docs
76+
- name: Test Documentation Build (HTML)
7777
run: sphinx-build -E -W -b html -D version=${{ env.CP_VERSION }} -D release=${{ env.CP_VERSION }} . _build/html
7878
- uses: actions/upload-artifact@v2
7979
with:
8080
name: docs
8181
path: _build/html
82+
- name: Test Documentation Build (LaTeX/PDF)
83+
run: |
84+
make latexpdf
85+
- uses: actions/upload-artifact@v2
86+
with:
87+
name: docs
88+
path: _build/latex
8289
- name: Translations
8390
run: make check-translate
8491
- name: New boards check
@@ -253,6 +260,7 @@ jobs:
253260
- "pca10100"
254261
- "pewpew10"
255262
- "pewpew_m4"
263+
- "picoplanet"
256264
- "pirkey_m0"
257265
- "pitaya_go"
258266
- "pyb_nano_v2"

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ _build
5757
######################
5858
genrst/
5959
/autoapi/
60-
/shared-bindings/**/*.rst
60+
/shared-bindings/*/**/*.rst
6161

6262
# ctags and similar
6363
###################
@@ -80,3 +80,8 @@ TAGS
8080
*.mo
8181

8282
.vscode
83+
84+
# Python Virtual Environments
85+
####################
86+
.venv
87+
.env

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,6 @@
147147
[submodule "ports/esp32s2/esp-idf"]
148148
path = ports/esp32s2/esp-idf
149149
url = https://github.com/tannewt/esp-idf.git
150+
[submodule "frozen/Adafruit_CircuitPython_RFM9x"]
151+
path = frozen/Adafruit_CircuitPython_RFM9x
152+
url = https://github.com/adafruit/Adafruit_CircuitPython_RFM9x.git

.readthedocs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88

99
version: 2
1010

11+
submodules:
12+
include:
13+
- extmod/ulab
14+
15+
formats:
16+
- pdf
17+
1118
python:
1219
version: 3
1320
install:

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ stubs:
245245
@$(PYTHON) tools/extract_pyi.py ports/atmel-samd/bindings $(STUBDIR)
246246
@$(PYTHON) setup.py -q sdist
247247

248+
.PHONY: check-stubs
249+
check-stubs: stubs
250+
MYPYPATH=$(STUBDIR) mypy --strict $(STUBDIR)
251+
248252
update-frozen-libraries:
249253
@echo "Updating all frozen libraries to latest tagged version."
250254
cd frozen; for library in *; do cd $$library; ../../tools/git-checkout-latest-tag.sh; cd ..; done

conf.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
#
1818
# SPDX-License-Identifier: MIT
1919

20-
import json
2120
import logging
2221
import os
22+
import re
2323
import subprocess
2424
import sys
2525
import urllib.parse
2626

2727
import recommonmark
28+
from sphinx.transforms import SphinxTransform
29+
from docutils import nodes
30+
from sphinx import addnodes
2831

2932
# If extensions (or modules to document with autodoc) are in another directory,
3033
# add these directories to sys.path here. If the directory is relative to the
@@ -84,6 +87,7 @@
8487
autoapi_add_toctree_entry = False
8588
autoapi_options = ['members', 'undoc-members', 'private-members', 'show-inheritance', 'special-members', 'show-module-summary']
8689
autoapi_template_dir = 'docs/autoapi/templates'
90+
autoapi_python_class_content = "both"
8791
autoapi_python_use_implicit_namespaces = True
8892
autoapi_root = "shared-bindings"
8993

@@ -106,7 +110,25 @@
106110
#
107111
# We don't follow "The short X.Y version" vs "The full version, including alpha/beta/rc tags"
108112
# breakdown, so use the same version identifier for both to avoid confusion.
109-
version = release = '0.0.0'
113+
114+
final_version = ""
115+
git_describe = subprocess.run(
116+
["git", "describe", "--dirty", "--tags"],
117+
stdout=subprocess.PIPE,
118+
stderr=subprocess.STDOUT,
119+
encoding="utf-8"
120+
)
121+
if git_describe.returncode == 0:
122+
git_version = re.search(
123+
r"^\d(?:\.\d){0,2}(?:\-(?:alpha|beta|rc)\.\d+){0,1}",
124+
str(git_describe.stdout)
125+
)
126+
if git_version:
127+
final_version = git_version[0]
128+
else:
129+
print("Failed to retrieve git version:", git_describe.stdout)
130+
131+
version = release = final_version
110132

111133
# The language for content autogenerated by Sphinx. Refer to documentation
112134
# for a list of supported languages.
@@ -423,7 +445,38 @@ def generate_redirects(app):
423445
with open(redirected_filename, 'w') as f:
424446
f.write(TEMPLATE % urllib.parse.quote(to_path, '#/'))
425447

448+
449+
class CoreModuleTransform(SphinxTransform):
450+
default_priority = 870
451+
452+
def _convert_first_paragraph_into_title(self):
453+
title = self.document.next_node(nodes.title)
454+
paragraph = self.document.next_node(nodes.paragraph)
455+
if not title or not paragraph:
456+
return
457+
if isinstance(paragraph[0], nodes.paragraph):
458+
paragraph = paragraph[0]
459+
if all(isinstance(child, nodes.Text) for child in paragraph.children):
460+
for child in paragraph.children:
461+
title.append(nodes.Text(" \u2013 "))
462+
title.append(child)
463+
paragraph.parent.remove(paragraph)
464+
465+
def _enable_linking_to_nonclass_targets(self):
466+
for desc in self.document.traverse(addnodes.desc):
467+
for xref in desc.traverse(addnodes.pending_xref):
468+
if xref.attributes.get("reftype") == "class":
469+
xref.attributes.pop("refspecific", None)
470+
471+
def apply(self, **kwargs):
472+
docname = self.env.docname
473+
if docname.startswith(autoapi_root) and docname.endswith("/index"):
474+
self._convert_first_paragraph_into_title()
475+
self._enable_linking_to_nonclass_targets()
476+
477+
426478
def setup(app):
427479
app.add_css_file("customstyle.css")
428480
app.add_config_value('redirects_file', 'redirects', 'env')
429481
app.connect('builder-inited', generate_redirects)
482+
app.add_transform(CoreModuleTransform)

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ STATIC void bleio_adapter_hci_init(bleio_adapter_obj_t *self) {
280280
const size_t len = sizeof(default_ble_name);
281281

282282
bt_addr_t addr;
283-
check_hci_error(hci_read_bd_addr(&addr));
283+
hci_check_error(hci_read_bd_addr(&addr));
284284

285285
default_ble_name[len - 4] = nibble_to_hex_lower[addr.val[1] >> 4 & 0xf];
286286
default_ble_name[len - 3] = nibble_to_hex_lower[addr.val[1] & 0xf];
@@ -373,7 +373,7 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable
373373
}
374374

375375
// Enabling or disabling: stop any current activity; reset to known state.
376-
check_hci_error(hci_reset());
376+
hci_reset();
377377
self->now_advertising = false;
378378
self->extended_advertising = false;
379379
self->circuitpython_advertising = false;
@@ -397,7 +397,7 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
397397
check_enabled(self);
398398

399399
bt_addr_t addr;
400-
check_hci_error(hci_read_bd_addr(&addr));
400+
hci_check_error(hci_read_bd_addr(&addr));
401401

402402
bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t);
403403
address->base.type = &bleio_address_type;
@@ -406,6 +406,14 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
406406
return address;
407407
}
408408

409+
bool common_hal_bleio_adapter_set_address(bleio_adapter_obj_t *self, bleio_address_obj_t *address) {
410+
mp_buffer_info_t bufinfo;
411+
if (!mp_get_buffer(address->bytes, &bufinfo, MP_BUFFER_READ)) {
412+
return false;
413+
}
414+
return hci_le_set_random_address(bufinfo.buf) == HCI_OK;
415+
}
416+
409417
mp_obj_str_t* common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self) {
410418
return self->name;
411419
}
@@ -673,7 +681,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
673681
// Advertising interval.
674682
uint32_t interval_units = SEC_TO_UNITS(interval, UNIT_0_625_MS);
675683

676-
check_hci_error(
684+
hci_check_error(
677685
hci_le_set_extended_advertising_parameters(
678686
0, // handle
679687
props, // adv properties
@@ -697,7 +705,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
697705
uint8_t handle[1] = { 0 };
698706
uint16_t duration_10msec[1] = { timeout * 100 };
699707
uint8_t max_ext_adv_evts[1] = { 0 };
700-
check_hci_error(
708+
hci_check_error(
701709
hci_le_set_extended_advertising_enable(
702710
BT_HCI_LE_ADV_ENABLE,
703711
1, // one advertising set.
@@ -725,7 +733,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
725733
// Advertising interval.
726734
uint16_t interval_units = SEC_TO_UNITS(interval, UNIT_0_625_MS);
727735

728-
check_hci_error(
736+
hci_check_error(
729737
hci_le_set_advertising_parameters(
730738
interval_units, // min interval
731739
interval_units, // max interval
@@ -740,19 +748,19 @@ uint32_t _common_hal_bleio_adapter_start_advertising(bleio_adapter_obj_t *self,
740748
// even though the actual data length may be shorter.
741749
uint8_t full_data[MAX_ADVERTISEMENT_SIZE] = { 0 };
742750
memcpy(full_data, advertising_data, MIN(sizeof(full_data), advertising_data_len));
743-
check_hci_error(hci_le_set_advertising_data(advertising_data_len, full_data));
751+
hci_check_error(hci_le_set_advertising_data(advertising_data_len, full_data));
744752
memset(full_data, 0, sizeof(full_data));
745753
if (scan_response_data_len > 0) {
746754
memcpy(full_data, scan_response_data, MIN(sizeof(full_data), scan_response_data_len));
747-
check_hci_error(hci_le_set_scan_response_data(scan_response_data_len, full_data));
755+
hci_check_error(hci_le_set_scan_response_data(scan_response_data_len, full_data));
748756
}
749757

750758
// No duration mechanism is provided for legacy advertising, so we need to do our own.
751759
self->advertising_timeout_msecs = timeout * 1000;
752760
self->advertising_start_ticks = supervisor_ticks_ms64();
753761

754762
// Start advertising.
755-
check_hci_error(hci_le_set_advertising_enable(BT_HCI_LE_ADV_ENABLE));
763+
hci_check_error(hci_le_set_advertising_enable(BT_HCI_LE_ADV_ENABLE));
756764
self->extended_advertising = false;
757765
} // end legacy advertising setup
758766

@@ -809,7 +817,7 @@ void common_hal_bleio_adapter_stop_advertising(bleio_adapter_obj_t *self) {
809817
// OK if we're already stopped. There seems to be an ESP32 HCI bug:
810818
// If advertising is already off, then LE_SET_ADV_ENABLE does not return a response.
811819
if (result != HCI_RESPONSE_TIMEOUT) {
812-
check_hci_error(result);
820+
hci_check_error(result);
813821
}
814822

815823
//TODO startup CircuitPython advertising again.
@@ -942,5 +950,8 @@ void bleio_adapter_background(bleio_adapter_obj_t* adapter) {
942950
common_hal_bleio_adapter_stop_advertising(adapter);
943951
}
944952

945-
hci_poll_for_incoming_pkt();
953+
hci_result_t result = hci_poll_for_incoming_pkt();
954+
if (result != HCI_OK) {
955+
mp_printf(&mp_plat_print, "bad hci_poll_for_incoming_pkt() result in background: %d\n", result);
956+
}
946957
}

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,6 @@ bleio_uuid_obj_t cccd_uuid;
4343

4444
bool vm_used_ble;
4545

46-
void check_hci_error(hci_result_t result) {
47-
switch (result) {
48-
case HCI_OK:
49-
return;
50-
51-
case HCI_RESPONSE_TIMEOUT:
52-
mp_raise_bleio_BluetoothError(translate("Timeout waiting for HCI response"));
53-
return;
54-
55-
case HCI_WRITE_TIMEOUT:
56-
mp_raise_bleio_BluetoothError(translate("Timeout waiting to write HCI request"));
57-
return;
58-
59-
case HCI_READ_ERROR:
60-
mp_raise_bleio_BluetoothError(translate("Error reading from HCI adapter"));
61-
return;
62-
63-
case HCI_WRITE_ERROR:
64-
mp_raise_bleio_BluetoothError(translate("Error writing to HCI adapter"));
65-
return;
66-
67-
case HCI_ATT_ERROR:
68-
mp_raise_RuntimeError(translate("Error in ATT protocol code"));
69-
return;
70-
71-
default:
72-
// Should be an HCI status error, > 0.
73-
if (result > 0) {
74-
mp_raise_bleio_BluetoothError(translate("HCI status error: %02x"), result);
75-
} else {
76-
mp_raise_bleio_BluetoothError(translate("Unknown hci_result_t: %d"), result);
77-
}
78-
return;
79-
}
80-
}
81-
82-
8346
// void check_sec_status(uint8_t sec_status) {
8447
// if (sec_status == BLE_GAP_SEC_STATUS_SUCCESS) {
8548
// return;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ typedef struct {
5353
#define BLE_GATTS_FIX_ATTR_LEN_MAX (510) /**< Maximum length for fixed length Attribute Values. */
5454
#define BLE_GATTS_VAR_ATTR_LEN_MAX (512) /**< Maximum length for variable length Attribute Values. */
5555

56-
57-
// These helpers raise the appropriate exceptions if the code doesn't equal success.
58-
void check_hci_error(hci_result_t result);
59-
void check_gatt_status(uint16_t gatt_status);
60-
void check_sec_status(uint8_t sec_status);
61-
6256
// Track if the user code modified the BLE state to know if we need to undo it on reload.
6357
extern bool vm_used_ble;
6458

0 commit comments

Comments
 (0)