From ee8119779e22c21fe7771a054e4cf6ee921b4352 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 17 May 2019 15:47:12 -0400 Subject: [PATCH 01/61] WIP --- shared-bindings/bleio/ScanEntry.c | 7 ++----- shared-bindings/bleio/Scanner.c | 23 ++++++++--------------- shared-bindings/bleio/Scanner.h | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index e6b9550780..67e4a38c02 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -37,9 +37,6 @@ #include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/ScanEntry.h" -// Work-in-progress: orphaned for now. -//| :orphan: -//| //| .. currentmodule:: bleio //| //| :class:`ScanEntry` -- BLE scan response entry @@ -63,7 +60,7 @@ //| .. attribute:: name //| //| The name of the device. (read-only) -//| This attribute might be `None` if the data was missing from the advertisement packet. +//| Will be be `None` if the data was missing from the advertisement packet. //| //| .. attribute:: raw_data @@ -87,7 +84,7 @@ //| .. attribute:: tx_power_level //| //| The transmit power level of the device. (read-only) -//| This attribute might be `None` if the data was missing from the advertisement packet. +//| Will be `None` if the data was missing from the advertisement packet. //| static uint8_t find_data_item(mp_obj_array_t *data_in, uint8_t type, uint8_t **data_out) { uint16_t i = 0; diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index f5424f706c..73b6e6a0b2 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -32,9 +33,6 @@ #define DEFAULT_INTERVAL 100 #define DEFAULT_WINDOW 100 -// Work-in-progress: orphaned for now. -//| :orphan: -//| //| .. currentmodule:: bleio //| //| :class:`Scanner` -- scan for nearby BLE devices @@ -46,7 +44,7 @@ //| //| import bleio //| scanner = bleio.Scanner() -//| entries = scanner.scan(2500) +//| entries = scanner.scan(2.5) # Scan for 2.5 seconds //| print(entries) //| @@ -57,33 +55,28 @@ //| .. attribute:: interval //| -//| The interval (in ms) between the start of two consecutive scan windows. -//| Allowed values are between 10ms and 10.24 sec. +//| The interval (in seconds) between the start of two consecutive scan windows. +//| Allowed values are between 0.010 and 10.24 sec. //| //| .. attribute:: window //| -//| The duration (in ms) in which a single BLE channel is scanned. -//| Allowed values are between 10ms and 10.24 sec. +//| The duration (in seconds) in which a single BLE channel is scanned. +//| Allowed values are between 0.010 and 10.24 sec. //| //| .. method:: scan(timeout) //| //| Performs a BLE scan. //| -//| :param int timeout: the scan timeout in ms +//| :param float timeout: the scan timeout in seconds //| :returns: advertising packets found //| :rtype: list of :py:class:`bleio.ScanEntry` //| -STATIC void bleio_scanner_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - - mp_printf(print, "Scanner(interval: %d window: %d)", self->interval, self->window); -} - STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *all_args, mp_map_t *kw_args) { mp_arg_check_num(n_args, kw_args, 0, 0, false); + bleio_scanner_obj_t *self = m_new_obj(bleio_scanner_obj_t); self->base.type = type; diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index 9bd0717476..c72136389b 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy From 1639354e5fc886ee4b2064eaceedfd26ebbe1cd3 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 23 May 2019 16:07:54 -0400 Subject: [PATCH 02/61] Scanner working, but not very first time --- ports/nrf/bluetooth/ble_drv.h | 5 +- ports/nrf/common-hal/bleio/Scanner.c | 26 ++---- shared-bindings/bleio/Scanner.c | 120 ++++++++++----------------- shared-bindings/bleio/Scanner.h | 2 +- shared-bindings/bleio/__init__.c | 8 +- 5 files changed, 56 insertions(+), 105 deletions(-) diff --git a/ports/nrf/bluetooth/ble_drv.h b/ports/nrf/bluetooth/ble_drv.h index cdb4c9b033..133d77b48d 100644 --- a/ports/nrf/bluetooth/ble_drv.h +++ b/ports/nrf/bluetooth/ble_drv.h @@ -30,10 +30,6 @@ #include "ble.h" -#if (BLUETOOTH_SD == 132) && (BLE_API_VERSION == 2) -#define NRF52 -#endif - #define MAX_TX_IN_PROGRESS 10 #ifndef BLE_GATT_ATT_MTU_DEFAULT @@ -43,6 +39,7 @@ #define BLE_CONN_CFG_TAG_CUSTOM 1 #define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION)) +#define SEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000000) / (RESOLUTION)) // 0.625 msecs (625 usecs) #define ADV_INTERVAL_UNIT_FLOAT_SECS (0.000625) #define UNIT_0_625_MS (625) diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index d2e19b5f9f..d4479515e7 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -36,14 +36,12 @@ #include "shared-bindings/bleio/Scanner.h" #include "shared-module/bleio/ScanEntry.h" -#if (BLUETOOTH_SD == 140) static uint8_t m_scan_buffer_data[BLE_GAP_SCAN_BUFFER_MIN]; static ble_data_t m_scan_buffer = { m_scan_buffer_data, BLE_GAP_SCAN_BUFFER_MIN }; -#endif STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { bleio_scanner_obj_t *scanner = (bleio_scanner_obj_t*)scanner_in; @@ -61,48 +59,34 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { entry->address.type = report->peer_addr.addr_type; memcpy(entry->address.value, report->peer_addr.addr, BLEIO_ADDRESS_BYTES); -#if (BLUETOOTH_SD == 140) entry->data = mp_obj_new_bytearray(report->data.len, report->data.p_data); -#else - entry->data = mp_obj_new_bytearray(report->dlen, report->data); -#endif mp_obj_list_append(scanner->adv_reports, entry); -#if (BLUETOOTH_SD == 140) const uint32_t err_code = sd_ble_gap_scan_start(NULL, &m_scan_buffer); if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to continue scanning, err 0x%04x"), err_code); } -#endif } -void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_int_t timeout) { +void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { ble_drv_add_event_handler(on_ble_evt, self); ble_gap_scan_params_t scan_params = { - .interval = MSEC_TO_UNITS(self->interval, UNIT_0_625_MS), - .window = MSEC_TO_UNITS(self->window, UNIT_0_625_MS), -#if (BLUETOOTH_SD == 140) + .interval = SEC_TO_UNITS(interval, UNIT_0_625_MS), + .window = SEC_TO_UNITS(window, UNIT_0_625_MS), .scan_phys = BLE_GAP_PHY_1MBPS, -#endif }; common_hal_bleio_adapter_set_enabled(true); uint32_t err_code; -#if (BLUETOOTH_SD == 140) err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); -#else - err_code = sd_ble_gap_scan_start(&scan_params); -#endif if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to start scanning, err 0x%04x"), err_code); } - if (timeout > 0) { - mp_hal_delay_ms(timeout); - sd_ble_gap_scan_stop(); - } + mp_hal_delay_ms(timeout * 1000); + sd_ble_gap_scan_stop(); } diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index 73b6e6a0b2..5615ce1030 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -30,8 +30,12 @@ #include "shared-bindings/bleio/ScanEntry.h" #include "shared-bindings/bleio/Scanner.h" -#define DEFAULT_INTERVAL 100 -#define DEFAULT_WINDOW 100 +#define INTERVAL_DEFAULT (0.1f) +#define INTERVAL_MIN (0.0025f) +#define INTERVAL_MIN_STRING "0.0025" +#define INTERVAL_MAX (40.959375f) +#define INTERVAL_MAX_STRING "40.959375" +#define WINDOW_DEFAULT (0.1f) //| .. currentmodule:: bleio //| @@ -45,109 +49,76 @@ //| import bleio //| scanner = bleio.Scanner() //| entries = scanner.scan(2.5) # Scan for 2.5 seconds -//| print(entries) //| //| .. class:: Scanner() //| //| Create a new Scanner object. //| - -//| .. attribute:: interval -//| -//| The interval (in seconds) between the start of two consecutive scan windows. -//| Allowed values are between 0.010 and 10.24 sec. -//| - -//| .. attribute:: window -//| -//| The duration (in seconds) in which a single BLE channel is scanned. -//| Allowed values are between 0.010 and 10.24 sec. -//| - -//| .. method:: scan(timeout) -//| -//| Performs a BLE scan. -//| -//| :param float timeout: the scan timeout in seconds -//| :returns: advertising packets found -//| :rtype: list of :py:class:`bleio.ScanEntry` -//| STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *all_args, mp_map_t *kw_args) { mp_arg_check_num(n_args, kw_args, 0, 0, false); - bleio_scanner_obj_t *self = m_new_obj(bleio_scanner_obj_t); self->base.type = type; - self->interval = DEFAULT_INTERVAL; - self->window = DEFAULT_WINDOW; - return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t bleio_scanner_get_interval(mp_obj_t self_in) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); +//| .. method:: scan(timeout, \*, interval=0.1, window=0.1) +//| +//| Performs a BLE scan. +//| +//| :param float timeout: the scan timeout in seconds +//| :param float interval: the interval (in seconds) between the start of two consecutive scan windows +//| Must be in the range 0.0025 - 40.959375 seconds. +//| :param float window: the duration (in seconds) to scan a single BLE channel +//| `window` must be <= `interval`. +//| :returns: advertising packets found +//| :rtype: list of :py:class:`bleio.ScanEntry` +//| +STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_timeout, ARG_interval, ARG_window }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_timeout, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_interval, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_window, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_obj = MP_OBJ_NULL} }, + }; - return mp_obj_new_int(self->interval); -} -MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanner_get_interval_obj, bleio_scanner_get_interval); + bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); -static mp_obj_t bleio_scanner_set_interval(mp_obj_t self_in, mp_obj_t value) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); + const mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); - self->interval = mp_obj_get_int(value); + if (args[ARG_interval].u_obj == MP_OBJ_NULL) { + args[ARG_interval].u_obj = mp_obj_new_float(INTERVAL_DEFAULT); + } - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_scanner_set_interval_obj, bleio_scanner_set_interval); + if (args[ARG_window].u_obj == MP_OBJ_NULL) { + args[ARG_window].u_obj = mp_obj_new_float(WINDOW_DEFAULT); + } -const mp_obj_property_t bleio_scanner_interval_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_scanner_get_interval_obj, - (mp_obj_t)&bleio_scanner_set_interval_obj, - (mp_obj_t)&mp_const_none_obj }, -}; + const mp_float_t interval = mp_obj_float_get(args[ARG_interval].u_obj); + if (interval < INTERVAL_MIN || interval > INTERVAL_MAX) { + mp_raise_ValueError_varg(translate("interval must be in range %s-%s"), INTERVAL_MIN_STRING, INTERVAL_MAX_STRING); + } -STATIC mp_obj_t scanner_scan(mp_obj_t self_in, mp_obj_t timeout_in) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - const mp_int_t timeout = mp_obj_get_int(timeout_in); + const mp_float_t window = mp_obj_float_get(args[ARG_window].u_obj); + if (window > interval) { + mp_raise_ValueError(translate("window must be <= interval")); + } self->adv_reports = mp_obj_new_list(0, NULL); - common_hal_bleio_scanner_scan(self, timeout); + common_hal_bleio_scanner_scan(self, timeout, interval, window); return self->adv_reports; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_scanner_scan_obj, scanner_scan); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan); -STATIC mp_obj_t bleio_scanner_get_window(mp_obj_t self_in) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return mp_obj_new_int(self->window); -} -MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanner_get_window_obj, bleio_scanner_get_window); - -static mp_obj_t bleio_scanner_set_window(mp_obj_t self_in, mp_obj_t value) { - bleio_scanner_obj_t *self = MP_OBJ_TO_PTR(self_in); - - self->window = mp_obj_get_int(value); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_scanner_set_window_obj, bleio_scanner_set_window); - -const mp_obj_property_t bleio_scanner_window_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_scanner_get_window_obj, - (mp_obj_t)&bleio_scanner_set_window_obj, - (mp_obj_t)&mp_const_none_obj }, -}; STATIC const mp_rom_map_elem_t bleio_scanner_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_interval), MP_ROM_PTR(&bleio_scanner_interval_obj) }, { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&bleio_scanner_scan_obj) }, - { MP_ROM_QSTR(MP_QSTR_window), MP_ROM_PTR(&bleio_scanner_window_obj) }, }; STATIC MP_DEFINE_CONST_DICT(bleio_scanner_locals_dict, bleio_scanner_locals_dict_table); @@ -155,7 +126,6 @@ STATIC MP_DEFINE_CONST_DICT(bleio_scanner_locals_dict, bleio_scanner_locals_dict const mp_obj_type_t bleio_scanner_type = { { &mp_type_type }, .name = MP_QSTR_Scanner, - .print = bleio_scanner_print, .make_new = bleio_scanner_make_new, .locals_dict = (mp_obj_dict_t*)&bleio_scanner_locals_dict }; diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index c72136389b..54c09675ba 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -33,7 +33,7 @@ extern const mp_obj_type_t bleio_scanner_type; -extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_int_t timeout); +void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 7348655acc..907d211016 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -64,8 +64,8 @@ // Descriptor // Device //| Peripheral -// ScanEntry -// Scanner +//| ScanEntry +//| Scanner //| Service //| UUID //| @@ -86,8 +86,8 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, { MP_ROM_QSTR(MP_QSTR_Peripheral), MP_ROM_PTR(&bleio_peripheral_type) }, // Hide work-in-progress. -// { MP_ROM_QSTR(MP_QSTR_ScanEntry), MP_ROM_PTR(&bleio_scanentry_type) }, -// { MP_ROM_QSTR(MP_QSTR_Scanner), MP_ROM_PTR(&bleio_scanner_type) }, + { MP_ROM_QSTR(MP_QSTR_ScanEntry), MP_ROM_PTR(&bleio_scanentry_type) }, + { MP_ROM_QSTR(MP_QSTR_Scanner), MP_ROM_PTR(&bleio_scanner_type) }, { MP_ROM_QSTR(MP_QSTR_Service), MP_ROM_PTR(&bleio_service_type) }, { MP_ROM_QSTR(MP_QSTR_UUID), MP_ROM_PTR(&bleio_uuid_type) }, From 6cec81bcb54fe69d179f6596d8dae96b6f3beea2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 23 May 2019 22:05:16 -0400 Subject: [PATCH 03/61] Need to enable ble before scanning --- ports/nrf/common-hal/bleio/Peripheral.c | 2 +- ports/nrf/common-hal/bleio/Scanner.c | 1 + shared-bindings/bleio/__init__.c | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 0a5a8069de..83191d4870 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -288,7 +288,7 @@ STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self) { - common_hal_bleio_adapter_set_enabled(true); // TODO -- Do this somewhere else maybe bleio __init__ + common_hal_bleio_adapter_set_enabled(true); self->gatt_role = GATT_ROLE_SERVER; self->conn_handle = BLE_CONN_HANDLE_INVALID; diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index d4479515e7..b76caaf213 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -70,6 +70,7 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { } void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { + common_hal_bleio_adapter_set_enabled(true); ble_drv_add_event_handler(on_ble_evt, self); ble_gap_scan_params_t scan_params = { diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 907d211016..03aef2eced 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -85,7 +85,6 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_CharacteristicBuffer), MP_ROM_PTR(&bleio_characteristic_buffer_type) }, // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, { MP_ROM_QSTR(MP_QSTR_Peripheral), MP_ROM_PTR(&bleio_peripheral_type) }, -// Hide work-in-progress. { MP_ROM_QSTR(MP_QSTR_ScanEntry), MP_ROM_PTR(&bleio_scanentry_type) }, { MP_ROM_QSTR(MP_QSTR_Scanner), MP_ROM_PTR(&bleio_scanner_type) }, { MP_ROM_QSTR(MP_QSTR_Service), MP_ROM_PTR(&bleio_service_type) }, From 12f1d9d30cf6e8c73db2eac5512c332cfde3031f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 31 May 2019 18:03:05 -0400 Subject: [PATCH 04/61] fix advertisement length check; add Service.secondary attribute --- ports/nrf/common-hal/bleio/Peripheral.c | 2 +- shared-bindings/bleio/Service.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 83191d4870..4aff75c9b7 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -52,7 +52,7 @@ static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; STATIC void check_data_fit(size_t pos, size_t data_len) { - if (pos + data_len >= BLE_GAP_ADV_SET_DATA_SIZE_MAX) { + if (pos + data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX) { mp_raise_ValueError(translate("Data too large for advertisement packet")); } } diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index c3be262602..d9bc4021f4 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -118,6 +118,24 @@ const mp_obj_property_t bleio_service_characteristics_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| .. attribute:: secondary +//| +//| True if this is a secondary service. (read-only) +//| +STATIC mp_obj_t bleio_service_get_secondary(mp_obj_t self_in) { + bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return mp_obj_new_bool(self->is_secondary); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_secondary_obj, bleio_service_get_secondary); + +const mp_obj_property_t bleio_service_secondary_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&bleio_service_get_secondary_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| .. attribute:: uuid //| //| The UUID of this service. (read-only) @@ -138,6 +156,7 @@ const mp_obj_property_t bleio_service_uuid_obj = { STATIC const mp_rom_map_elem_t bleio_service_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_characteristics), MP_ROM_PTR(&bleio_service_characteristics_obj) }, + { MP_ROM_QSTR(MP_QSTR_secondary), MP_ROM_PTR(&bleio_service_secondary_obj) }, { MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_service_uuid_obj) }, }; From 63ac37946df041519ffa822fde292f3be6d1840c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 2 Jun 2019 23:21:30 -0400 Subject: [PATCH 05/61] 1. Remove advertising data construction in C: it's all done in Python now 2. Add scan response capability to advertising. --- ports/nrf/common-hal/bleio/Broadcaster.c | 2 +- ports/nrf/common-hal/bleio/Peripheral.c | 141 +++-------------------- ports/nrf/common-hal/bleio/Peripheral.h | 7 +- shared-bindings/bleio/Broadcaster.c | 2 +- shared-bindings/bleio/Peripheral.c | 26 +++-- shared-bindings/bleio/Peripheral.h | 2 +- 6 files changed, 38 insertions(+), 142 deletions(-) diff --git a/ports/nrf/common-hal/bleio/Broadcaster.c b/ports/nrf/common-hal/bleio/Broadcaster.c index a70209a7fc..a9e2a04c3f 100644 --- a/ports/nrf/common-hal/bleio/Broadcaster.c +++ b/ports/nrf/common-hal/bleio/Broadcaster.c @@ -39,7 +39,7 @@ static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; void common_hal_bleio_broadcaster_construct(bleio_broadcaster_obj_t *self, mp_float_t interval) { - common_hal_bleio_adapter_set_enabled(true); // TODO -- Do this somewhere else maybe bleio __init__ + common_hal_bleio_adapter_set_enabled(true); const mp_float_t min = BLE_GAP_ADV_INTERVAL_MIN * ADV_INTERVAL_UNIT_FLOAT_SECS; const mp_float_t max = BLE_GAP_ADV_INTERVAL_MAX * ADV_INTERVAL_UNIT_FLOAT_SECS; diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 4aff75c9b7..ad28523ae8 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -51,63 +51,15 @@ static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; -STATIC void check_data_fit(size_t pos, size_t data_len) { - if (pos + data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX) { +STATIC void check_data_fit(size_t data_len) { + if (data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX) { mp_raise_ValueError(translate("Data too large for advertisement packet")); } } -STATIC uint32_t add_services_to_advertisement(bleio_peripheral_obj_t *self, size_t* adv_data_pos_p, size_t uuid_len) { - uint32_t uuids_total_size = 0; - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); - uint32_t err_code = NRF_SUCCESS; - - check_data_fit(*adv_data_pos_p, 1 + 1); - - // Remember where length byte is; fill in later when we know the size. - const size_t length_pos = *adv_data_pos_p; - (*adv_data_pos_p)++; - - self->adv_data[(*adv_data_pos_p)++] = (uuid_len == 16) - ? BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE - : BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE; - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - uint8_t encoded_size = 0; - - // Skip services of the wrong length and secondary services. - if (common_hal_bleio_uuid_get_size(service->uuid) != uuid_len || service->is_secondary) { - continue; - } - - ble_uuid_t uuid; - bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); - - err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &(self->adv_data[*adv_data_pos_p])); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - check_data_fit(*adv_data_pos_p, encoded_size); - uuids_total_size += encoded_size; - (*adv_data_pos_p) += encoded_size; - } - - self->adv_data[length_pos] = 1 + uuids_total_size; // 1 for the field type. - return err_code; -} - - - -// if raw_data is a zero-length buffer, generate an advertising packet that advertises the -// services passed in when this Peripheral was created. -// If raw_data contains some bytes, use those bytes as the advertising packet. -// TODO: Generate the advertising packet in Python, not here. -STATIC uint32_t set_advertisement_data(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *raw_data) { +STATIC uint32_t start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { common_hal_bleio_adapter_set_enabled(true); - size_t adv_data_pos = 0; uint32_t err_code; GET_STR_DATA_LEN(self->name, name_data, name_len); @@ -115,86 +67,18 @@ STATIC uint32_t set_advertisement_data(bleio_peripheral_obj_t *self, bool connec ble_gap_conn_sec_mode_t sec_mode; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - // We'll add the name after everything else, shortening it if necessary. err_code = sd_ble_gap_device_name_set(&sec_mode, name_data, name_len); if (err_code != NRF_SUCCESS) { return err_code; } } - if (raw_data->len != 0) { - // User-supplied advertising packet. - check_data_fit(adv_data_pos, raw_data->len); - memcpy(&(self->adv_data[adv_data_pos]), raw_data->buf, raw_data->len); - adv_data_pos += raw_data->len; - } else { - // Build up advertising packet. - check_data_fit(adv_data_pos, 1 + 1 + 1); - self->adv_data[adv_data_pos++] = 2; - self->adv_data[adv_data_pos++] = BLE_GAP_AD_TYPE_FLAGS; - self->adv_data[adv_data_pos++] = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; + check_data_fit(advertising_data_bufinfo->len); + memcpy(self->advertising_data, advertising_data_bufinfo->buf, advertising_data_bufinfo->len); - // The 16-bit ids and 128-bit ids are grouped together by length, so find it whether we have - // 16 and/or 128-bit service UUIDs. + check_data_fit(scan_response_data_bufinfo->len); + memcpy(self->scan_response_data, scan_response_data_bufinfo->buf, scan_response_data_bufinfo->len); - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); - if (service_list->len > 0) { - bool has_128bit_services = false; - bool has_16bit_services = false; - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - - if (service->is_secondary) { - continue; - } - - switch (common_hal_bleio_uuid_get_size(service->uuid)) { - case 16: - has_16bit_services = true; - break; - case 128: - has_128bit_services = true; - break; - } - } - - // Add 16-bit service UUID's in a group, then 128-bit service UUID's. - - if (has_16bit_services) { - err_code = add_services_to_advertisement(self, &adv_data_pos, 16); - if (err_code != NRF_SUCCESS) { - return err_code; - } - } - - if (has_128bit_services) { - err_code = add_services_to_advertisement(self, &adv_data_pos, 128); - if (err_code != NRF_SUCCESS) { - return err_code; - } - } - } - - // Always include TX power. - check_data_fit(adv_data_pos, 1 + 1 + 1); - self->adv_data[adv_data_pos++] = 1 + 1; - self->adv_data[adv_data_pos++] = BLE_GAP_AD_TYPE_TX_POWER_LEVEL; - self->adv_data[adv_data_pos++] = 0; // TODO - allow power level to be set later. - - // We need room for at least a one-character name. - check_data_fit(adv_data_pos, 1 + 1 + 1); - - // How big a name can we fit? - size_t bytes_left = BLE_GAP_ADV_SET_DATA_SIZE_MAX - adv_data_pos - 1 - 1; - size_t partial_name_len = MIN(bytes_left, name_len); - self->adv_data[adv_data_pos++] = 1 + partial_name_len; - self->adv_data[adv_data_pos++] = (partial_name_len == name_len) - ? BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME - : BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME; - memcpy(&(self->adv_data[adv_data_pos]), name_data, partial_name_len); - adv_data_pos += partial_name_len; - } // end of advertising packet construction static ble_gap_adv_params_t m_adv_params = { .interval = MSEC_TO_UNITS(1000, UNIT_0_625_MS), @@ -211,8 +95,10 @@ STATIC uint32_t set_advertisement_data(bleio_peripheral_obj_t *self, bool connec common_hal_bleio_peripheral_stop_advertising(self); const ble_gap_adv_data_t ble_gap_adv_data = { - .adv_data.p_data = self->adv_data, - .adv_data.len = adv_data_pos, + .adv_data.p_data = self->advertising_data, + .adv_data.len = advertising_data_bufinfo->len, + .scan_rsp_data.p_data = scan_response_data_bufinfo-> len > 0 ? self->scan_response_data : NULL, + .scan_rsp_data.len = scan_response_data_bufinfo->len, }; err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &ble_gap_adv_data, &m_adv_params); @@ -322,12 +208,13 @@ bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self) { return self->conn_handle != BLE_CONN_HANDLE_INVALID; } -void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *raw_data) { +void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { if (connectable) { ble_drv_add_event_handler(peripheral_on_ble_evt, self); } - const uint32_t err_code = set_advertisement_data(self, connectable, raw_data); + const uint32_t err_code = start_advertising(self, connectable, + advertising_data_bufinfo, scan_response_data_bufinfo); if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to start advertising, err 0x%04x"), err_code); } diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index b255fe9f40..bf1931dda4 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -43,10 +43,11 @@ typedef struct { mp_obj_t service_list; mp_obj_t notif_handler; mp_obj_t conn_handler; - // The advertising data buffer is held by us, not by the SD, so we must - // maintain it and not change it. If we need to change its contents during advertising, + // The advertising data and scan response buffers are held by us, not by the SD, so we must + // maintain them and not change it. If we need to change the contents during advertising, // there are tricks to get the SD to notice (see DevZone - TBS). - uint8_t adv_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; + uint8_t advertising_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; + uint8_t scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; } bleio_peripheral_obj_t; diff --git a/shared-bindings/bleio/Broadcaster.c b/shared-bindings/bleio/Broadcaster.c index 209e664902..294f1a83a4 100644 --- a/shared-bindings/bleio/Broadcaster.c +++ b/shared-bindings/bleio/Broadcaster.c @@ -82,7 +82,7 @@ STATIC mp_obj_t bleio_broadcaster_make_new(const mp_obj_type_t *type, size_t n_a //| //| Start advertising using the given data packet. //| -//| :param buf data: advertising data packet, starting with advertising data flags (0x01) +//| :param buf data: advertising data packet //| STATIC mp_obj_t bleio_broadcaster_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_broadcaster_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 340485f353..960b3723c7 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -68,7 +68,8 @@ static const char default_name[] = "CIRCUITPY"; //| //| # Create a peripheral and start it up. //| periph = bleio.Peripheral([service]) -//| periph.start_advertising() +//| adv = ServerAdvertisement(periph) +//| periph.start_advertising(adv.advertising_data_bytes, adv.scan_response_bytes) //| //| while not periph.connected: //| # Wait for connection. @@ -181,33 +182,40 @@ const mp_obj_property_t bleio_peripheral_name_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| .. method:: start_advertising(*, connectable=True, data=None) +//| .. method:: start_advertising(data, *, scan_response=None, connectable=True) //| //| Starts advertising the peripheral. The peripheral's name and //| services are included in the advertisement packets. //| +//| :param buf data: advertising data packet bytes +//| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed. //| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral. -//| :param buf data: If `None`, advertise the services passed to this Peripheral when it was created. -//| If not `None`, then send the bytes in ``data`` as the advertising packet. +//| //| STATIC mp_obj_t bleio_peripheral_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_connectable, ARG_data }; + enum { ARG_data, ARG_scan_response, ARG_connectable }; static const mp_arg_t allowed_args[] = { + { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_scan_response, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_connectable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, - { MP_QSTR_data, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_buffer_info_t bufinfo = { 0 }; + mp_buffer_info_t data_bufinfo; + mp_get_buffer_raise(args[ARG_data].u_obj, &data_bufinfo, MP_BUFFER_READ); + + // Pass an empty buffer if scan_response not provided. + mp_buffer_info_t scan_response_bufinfo = { 0 }; if (args[ARG_data].u_obj != mp_const_none) { - mp_get_buffer_raise(args[ARG_data].u_obj, &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(args[ARG_scan_response].u_obj, &scan_response_bufinfo, MP_BUFFER_READ); } - common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool, &bufinfo); + common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool, + &data_bufinfo, &scan_response_bufinfo); return mp_const_none; } diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index 02a5c1ef8e..c09c600885 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -34,7 +34,7 @@ extern const mp_obj_type_t bleio_peripheral_type; extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self); extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self); -extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, mp_buffer_info_t *raw_data); +extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_PERIPHERAL_H From 613e12f99fd101a2c6b4b738da398a270aede538 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 3 Jun 2019 20:40:05 -0400 Subject: [PATCH 06/61] Replace Broadcaster with enhanced Peripheral --- ports/nrf/common-hal/bleio/Broadcaster.c | 98 ---------------- ports/nrf/common-hal/bleio/Peripheral.c | 117 +++++++++---------- ports/nrf/common-hal/bleio/Peripheral.h | 1 + py/circuitpy_defns.mk | 2 - shared-bindings/bleio/AdvertisementData.c | 90 --------------- shared-bindings/bleio/Broadcaster.c | 132 ---------------------- shared-bindings/bleio/Broadcaster.h | 38 ------- shared-bindings/bleio/Device.c | 1 - shared-bindings/bleio/Device.h | 1 - shared-bindings/bleio/Peripheral.c | 46 +++++--- shared-bindings/bleio/Peripheral.h | 2 +- shared-bindings/bleio/__init__.c | 5 - shared-module/bleio/AdvertisementData.h | 7 -- 13 files changed, 90 insertions(+), 450 deletions(-) delete mode 100644 ports/nrf/common-hal/bleio/Broadcaster.c delete mode 100644 shared-bindings/bleio/AdvertisementData.c delete mode 100644 shared-bindings/bleio/Broadcaster.c delete mode 100644 shared-bindings/bleio/Broadcaster.h diff --git a/ports/nrf/common-hal/bleio/Broadcaster.c b/ports/nrf/common-hal/bleio/Broadcaster.c deleted file mode 100644 index a9e2a04c3f..0000000000 --- a/ports/nrf/common-hal/bleio/Broadcaster.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Dan Halbert for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "ble.h" -#include "ble_drv.h" -#include "ble_hci.h" -#include "nrf_soc.h" -#include "py/runtime.h" - -#include "common-hal/bleio/Broadcaster.h" -#include "shared-bindings/bleio/Adapter.h" -#include "shared-bindings/bleio/Broadcaster.h" - -static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; - -void common_hal_bleio_broadcaster_construct(bleio_broadcaster_obj_t *self, mp_float_t interval) { - common_hal_bleio_adapter_set_enabled(true); - const mp_float_t min = BLE_GAP_ADV_INTERVAL_MIN * ADV_INTERVAL_UNIT_FLOAT_SECS; - const mp_float_t max = BLE_GAP_ADV_INTERVAL_MAX * ADV_INTERVAL_UNIT_FLOAT_SECS; - - if (interval < min || interval > max) { - // Would like to print range using the constants above, but vargs would convert to double. - mp_raise_ValueError(translate("interval not in range 0.0020 to 10.24")); - } - self->interval = interval; -} - - -void common_hal_bleio_broadcaster_start_advertising(bleio_broadcaster_obj_t *self, mp_buffer_info_t *data) { - uint32_t err_code; - - if (data->len >= BLE_GAP_ADV_SET_DATA_SIZE_MAX) { - mp_raise_ValueError(translate("Data too large for advertisement packet")); - } - memcpy(self->adv_data, data->buf, data->len); - - ble_gap_adv_params_t m_adv_params = { - .interval = (uint32_t) (self->interval / ADV_INTERVAL_UNIT_FLOAT_SECS), - .properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED, - .duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED, - .filter_policy = BLE_GAP_ADV_FP_ANY, - .primary_phy = BLE_GAP_PHY_1MBPS, - }; - - common_hal_bleio_broadcaster_stop_advertising(self); - - const ble_gap_adv_data_t ble_gap_adv_data = { - .adv_data.p_data = self->adv_data, - .adv_data.len = data->len, - }; - - err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &ble_gap_adv_data, &m_adv_params); - if (err_code == NRF_SUCCESS) { - err_code = sd_ble_gap_adv_start(m_adv_handle, BLE_CONN_CFG_TAG_CUSTOM); - } - - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg_varg(translate("Failed to start advertising, err 0x%04x"), err_code); - } -} - -void common_hal_bleio_broadcaster_stop_advertising(bleio_broadcaster_obj_t *self) { - - if (m_adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) { - return; - } - - const uint32_t err_code = sd_ble_gap_adv_stop(m_adv_handle); - - if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE)) { - mp_raise_OSError_msg_varg(translate("Failed to stop advertising, err 0x%04x"), err_code); - } -} diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index ad28523ae8..2cd52841a3 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -49,68 +49,12 @@ #define BLE_ADV_AD_TYPE_FIELD_SIZE 1 #define BLE_AD_TYPE_FLAGS_DATA_SIZE 1 -static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; - STATIC void check_data_fit(size_t data_len) { if (data_len > BLE_GAP_ADV_SET_DATA_SIZE_MAX) { mp_raise_ValueError(translate("Data too large for advertisement packet")); } } -STATIC uint32_t start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { - common_hal_bleio_adapter_set_enabled(true); - - uint32_t err_code; - - GET_STR_DATA_LEN(self->name, name_data, name_len); - if (name_len > 0) { - ble_gap_conn_sec_mode_t sec_mode; - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - - err_code = sd_ble_gap_device_name_set(&sec_mode, name_data, name_len); - if (err_code != NRF_SUCCESS) { - return err_code; - } - } - - check_data_fit(advertising_data_bufinfo->len); - memcpy(self->advertising_data, advertising_data_bufinfo->buf, advertising_data_bufinfo->len); - - check_data_fit(scan_response_data_bufinfo->len); - memcpy(self->scan_response_data, scan_response_data_bufinfo->buf, scan_response_data_bufinfo->len); - - - static ble_gap_adv_params_t m_adv_params = { - .interval = MSEC_TO_UNITS(1000, UNIT_0_625_MS), - .properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED, - .duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED, - .filter_policy = BLE_GAP_ADV_FP_ANY, - .primary_phy = BLE_GAP_PHY_1MBPS, - }; - - if (!connectable) { - m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED; - } - - common_hal_bleio_peripheral_stop_advertising(self); - - const ble_gap_adv_data_t ble_gap_adv_data = { - .adv_data.p_data = self->advertising_data, - .adv_data.len = advertising_data_bufinfo->len, - .scan_rsp_data.p_data = scan_response_data_bufinfo-> len > 0 ? self->scan_response_data : NULL, - .scan_rsp_data.len = scan_response_data_bufinfo->len, - }; - - err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &ble_gap_adv_data, &m_adv_params); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - err_code = sd_ble_gap_adv_start(m_adv_handle, BLE_CONN_CFG_TAG_CUSTOM); - - return err_code; -} - STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { bleio_peripheral_obj_t *self = (bleio_peripheral_obj_t*)self_in; @@ -172,12 +116,12 @@ STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { } } - void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self) { common_hal_bleio_adapter_set_enabled(true); self->gatt_role = GATT_ROLE_SERVER; self->conn_handle = BLE_CONN_HANDLE_INVALID; + self->adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; // Add all the services. @@ -208,13 +152,62 @@ bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self) { return self->conn_handle != BLE_CONN_HANDLE_INVALID; } -void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { +void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_float_t interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { + + // interval value has already been validated. + if (connectable) { ble_drv_add_event_handler(peripheral_on_ble_evt, self); } - const uint32_t err_code = start_advertising(self, connectable, - advertising_data_bufinfo, scan_response_data_bufinfo); + common_hal_bleio_adapter_set_enabled(true); + + uint32_t err_code; + + GET_STR_DATA_LEN(self->name, name_data, name_len); + if (name_len > 0) { + ble_gap_conn_sec_mode_t sec_mode; + BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); + + err_code = sd_ble_gap_device_name_set(&sec_mode, name_data, name_len); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg_varg(translate("Failed to set device name, err 0x%04x"), err_code); + + } + } + + check_data_fit(advertising_data_bufinfo->len); + memcpy(self->advertising_data, advertising_data_bufinfo->buf, advertising_data_bufinfo->len); + + check_data_fit(scan_response_data_bufinfo->len); + memcpy(self->scan_response_data, scan_response_data_bufinfo->buf, scan_response_data_bufinfo->len); + + + ble_gap_adv_params_t adv_params = { + .interval = SEC_TO_UNITS(interval, UNIT_0_625_MS), + .properties.type = connectable ? BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED + : BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED, + .duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED, + .filter_policy = BLE_GAP_ADV_FP_ANY, + .primary_phy = BLE_GAP_PHY_1MBPS, + }; + + common_hal_bleio_peripheral_stop_advertising(self); + + const ble_gap_adv_data_t ble_gap_adv_data = { + .adv_data.p_data = self->advertising_data, + .adv_data.len = advertising_data_bufinfo->len, + .scan_rsp_data.p_data = scan_response_data_bufinfo-> len > 0 ? self->scan_response_data : NULL, + .scan_rsp_data.len = scan_response_data_bufinfo->len, + }; + + err_code = sd_ble_gap_adv_set_configure(&self->adv_handle, &ble_gap_adv_data, &adv_params); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg_varg(translate("Failed to configure advertising, err 0x%04x"), err_code); + } + + err_code = sd_ble_gap_adv_start(self->adv_handle, BLE_CONN_CFG_TAG_CUSTOM); + if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to start advertising, err 0x%04x"), err_code); } @@ -222,10 +215,10 @@ void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *self) { - if (m_adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) + if (self->adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) return; - const uint32_t err_code = sd_ble_gap_adv_stop(m_adv_handle); + const uint32_t err_code = sd_ble_gap_adv_stop(self->adv_handle); if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE)) { mp_raise_OSError_msg_varg(translate("Failed to stop advertising, err 0x%04x"), err_code); diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index bf1931dda4..58526fc484 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -48,6 +48,7 @@ typedef struct { // there are tricks to get the SD to notice (see DevZone - TBS). uint8_t advertising_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; uint8_t scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; + uint8_t adv_handle; } bleio_peripheral_obj_t; diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 1aca339011..31af38d8d4 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -221,7 +221,6 @@ $(filter $(SRC_PATTERNS), \ audioio/AudioOut.c \ bleio/__init__.c \ bleio/Adapter.c \ - bleio/Broadcaster.c \ bleio/Characteristic.c \ bleio/CharacteristicBuffer.c \ bleio/Descriptor.c \ @@ -285,7 +284,6 @@ SRC_BINDINGS_ENUMS += \ $(filter $(SRC_PATTERNS), \ bleio/Address.c \ bleio/AddressType.c \ - bleio/AdvertisementData.c \ bleio/ScanEntry.c \ ) diff --git a/shared-bindings/bleio/AdvertisementData.c b/shared-bindings/bleio/AdvertisementData.c deleted file mode 100644 index 9cfdd74e90..0000000000 --- a/shared-bindings/bleio/AdvertisementData.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/obj.h" -#include "shared-module/bleio/AdvertisementData.h" - -//| .. currentmodule:: bleio -//| -//| :class:`AdvertisementData` -- data used during BLE advertising -//| ============================================================== -//| -//| Represents the data to be broadcast during BLE advertising. -//| - -STATIC const mp_rom_map_elem_t bleio_advertisementdata_locals_dict_table[] = { - // Static variables - { MP_ROM_QSTR(MP_QSTR_FLAGS), MP_ROM_INT(AdFlags) }, - { MP_ROM_QSTR(MP_QSTR_INCOMPLETE_LIST_OF_16BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdIncompleteListOf16BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_COMPLETE_LIST_OF_16BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdCompleteListOf16BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_INCOMPLETE_LIST_OF_32BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdIncompleteListOf32BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_COMPLETE_LIST_OF_32BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdCompleteListOf32BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_INCOMPLETE_LIST_OF_128BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdIncompleteListOf128BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_COMPLETE_LIST_OF_128BIT_SERVICE_CLASS_UUIDS), MP_ROM_INT(AdCompleteListOf128BitServiceClassUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_SHORTENED_LOCAL_NAME), MP_ROM_INT(AdShortenedLocalName) }, - { MP_ROM_QSTR(MP_QSTR_COMPLETE_LOCAL_NAME), MP_ROM_INT(AdCompleteLocalName) }, - { MP_ROM_QSTR(MP_QSTR_TX_POWER_LEVEL), MP_ROM_INT(AdTxPowerLevel) }, - { MP_ROM_QSTR(MP_QSTR_CLASS_OF_DEVICE), MP_ROM_INT(AdClassOfDevice) }, - { MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_HASH_C), MP_ROM_INT(AdSimplePairingHashC) }, - { MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_RANDOMIZER_R), MP_ROM_INT(AdSimplePairingRandomizerR) }, - { MP_ROM_QSTR(MP_QSTR_SECURITY_MANAGER_TK_VALUE), MP_ROM_INT(AdSecurityManagerTKValue) }, - { MP_ROM_QSTR(MP_QSTR_SECURITY_MANAGER_OOB_FLAGS), MP_ROM_INT(AdSecurityManagerOOBFlags) }, - { MP_ROM_QSTR(MP_QSTR_SLAVE_CONNECTION_INTERVAL_RANGE), MP_ROM_INT(AdSlaveConnectionIntervalRange) }, - { MP_ROM_QSTR(MP_QSTR_LIST_OF_16BIT_SERVICE_SOLICITATION_UUIDS), MP_ROM_INT(AdListOf16BitServiceSolicitationUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_LIST_OF_128BIT_SERVICE_SOLICITATION_UUIDS), MP_ROM_INT(AdListOf128BitServiceSolicitationUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_SERVICE_DATA), MP_ROM_INT(AdServiceData) }, - { MP_ROM_QSTR(MP_QSTR_PUBLIC_TARGET_ADDRESS), MP_ROM_INT(AdPublicTargetAddress) }, - { MP_ROM_QSTR(MP_QSTR_RANDOM_TARGET_ADDRESS), MP_ROM_INT(AdRandomTargetAddress) }, - { MP_ROM_QSTR(MP_QSTR_APPEARANCE), MP_ROM_INT(AdAppearance) }, - { MP_ROM_QSTR(MP_QSTR_ADVERTISING_INTERNAL), MP_ROM_INT(AdAdvertisingInterval) }, - { MP_ROM_QSTR(MP_QSTR_LE_BLUETOOTH_DEVICE_ADDRESS), MP_ROM_INT(AdLEBluetoothDeviceAddress) }, - { MP_ROM_QSTR(MP_QSTR_LE_ROLE), MP_ROM_INT(AdLERole) }, - { MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_HASH_C256), MP_ROM_INT(AdSimplePairingHashC256) }, - { MP_ROM_QSTR(MP_QSTR_SIMPLE_PAIRING_RANDOMIZER_R256), MP_ROM_INT(AdSimplePairingRandomizerR256) }, - { MP_ROM_QSTR(MP_QSTR_LIST_OF_32BIT_SERVICE_SOLICITATION_UUIDS), MP_ROM_INT(AdListOf32BitServiceSolicitationUUIDs) }, - { MP_ROM_QSTR(MP_QSTR_SERVICE_DATA_32BIT_UUID), MP_ROM_INT(AdServiceData32BitUUID) }, - { MP_ROM_QSTR(MP_QSTR_SERVICE_DATA_128BIT_UUID), MP_ROM_INT(AdServiceData128BitUUID) }, - { MP_ROM_QSTR(MP_QSTR_LE_SECURE_CONNECTIONS_CONFIRMATION_VALUE), MP_ROM_INT(AdLESecureConnectionsConfirmationValue) }, - { MP_ROM_QSTR(MP_QSTR_LE_SECURE_CONNECTIONS_RANDOM_VALUE), MP_ROM_INT(AdLESecureConnectionsRandomValue) }, - { MP_ROM_QSTR(MP_QSTR_URI), MP_ROM_INT(AdURI) }, - { MP_ROM_QSTR(MP_QSTR_INDOOR_POSITIONING), MP_ROM_INT(AdIndoorPositioning) }, - { MP_ROM_QSTR(MP_QSTR_TRANSPORT_DISCOVERY_DATA), MP_ROM_INT(AdTransportDiscoveryData) }, - { MP_ROM_QSTR(MP_QSTR_LE_SUPPORTED_FEATURES), MP_ROM_INT(AdLESupportedFeatures) }, - { MP_ROM_QSTR(MP_QSTR_CHANNEL_MAP_UPDATE_INDICATION), MP_ROM_INT(AdChannelMapUpdateIndication) }, - { MP_ROM_QSTR(MP_QSTR_PB_ADV), MP_ROM_INT(AdPBADV) }, - { MP_ROM_QSTR(MP_QSTR_MESH_MESSAGE), MP_ROM_INT(AdMeshMessage) }, - { MP_ROM_QSTR(MP_QSTR_MESH_BEACON), MP_ROM_INT(AdMeshBeacon) }, - { MP_ROM_QSTR(MP_QSTR_3D_INFORMATION_DATA), MP_ROM_INT(Ad3DInformationData) }, - { MP_ROM_QSTR(MP_QSTR_MANUFACTURER_SPECIFIC_DATA), MP_ROM_INT(AdManufacturerSpecificData) }, -}; - -STATIC MP_DEFINE_CONST_DICT(bleio_advertisementdata_locals_dict, bleio_advertisementdata_locals_dict_table); - -const mp_obj_type_t bleio_advertisementdata_type = { - { &mp_type_type }, - .name = MP_QSTR_AdvertisementData, - .locals_dict = (mp_obj_dict_t*)&bleio_advertisementdata_locals_dict -}; diff --git a/shared-bindings/bleio/Broadcaster.c b/shared-bindings/bleio/Broadcaster.c deleted file mode 100644 index 294f1a83a4..0000000000 --- a/shared-bindings/bleio/Broadcaster.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Dan Halbert for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "ble_drv.h" -#include "py/runtime.h" - -#include "shared-bindings/bleio/Broadcaster.h" - -//| .. currentmodule:: bleio -//| -//| :class:`Broadcaster` -- Broadcast advertising packets. -//| ========================================================= -//| -//| Implement a BLE broadcaster which sends data in advertising packets and does not connect. -//| Used for beacons and other one-way data transmission. -//| -//| Usage:: -//| -//| import bleio -//| import time -//| -//| # Broadcast once a second. -//| broadcaster = bleio.Broadcaster(interval=1) -//| data = 0 -//| # Broadcast a byte of data that's incremented once a minute -//| while True: -//| # data is an entire advertising data packet, starting with flags. -//| broadcaster.start_advertising(data) -//| time.sleep(60) -//| data += 1 -//| -//| .. class:: Broadcaster(interval=1) -//| -//| Create a new Broadcaster object. - -//| :param float interval: how often to broadcast -//| - -STATIC mp_obj_t bleio_broadcaster_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_interval }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_interval, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_float_t interval = mp_obj_get_float(args[ARG_interval].u_obj); - - bleio_broadcaster_obj_t *self = m_new_obj(bleio_broadcaster_obj_t); - self->base.type = &bleio_broadcaster_type; - // Do port-specific initialization. interval will be validated. - common_hal_bleio_broadcaster_construct(self, interval); - - return MP_OBJ_FROM_PTR(self); -} - -//| .. method:: start_advertising(data) -//| -//| Start advertising using the given data packet. -//| -//| :param buf data: advertising data packet -//| -STATIC mp_obj_t bleio_broadcaster_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - bleio_broadcaster_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - - enum { ARG_data }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(args[ARG_data].u_obj, &bufinfo, MP_BUFFER_READ); - - common_hal_bleio_broadcaster_start_advertising(self, &bufinfo); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_broadcaster_start_advertising_obj, 0, bleio_broadcaster_start_advertising); - -//| .. method:: stop_advertising() -//| -//| Stop sending advertising packets. -STATIC mp_obj_t bleio_broadcaster_stop_advertising(mp_obj_t self_in) { - bleio_broadcaster_obj_t *self = MP_OBJ_TO_PTR(self_in); - - common_hal_bleio_broadcaster_stop_advertising(self); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_broadcaster_stop_advertising_obj, bleio_broadcaster_stop_advertising); - -STATIC const mp_rom_map_elem_t bleio_broadcaster_locals_dict_table[] = { - // Methods - { MP_ROM_QSTR(MP_QSTR_start_advertising), MP_ROM_PTR(&bleio_broadcaster_start_advertising_obj) }, - { MP_ROM_QSTR(MP_QSTR_stop_advertising), MP_ROM_PTR(&bleio_broadcaster_stop_advertising_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(bleio_broadcaster_locals_dict, bleio_broadcaster_locals_dict_table); - -const mp_obj_type_t bleio_broadcaster_type = { - { &mp_type_type }, - .name = MP_QSTR_Broadcaster, - .make_new = bleio_broadcaster_make_new, - .locals_dict = (mp_obj_dict_t*)&bleio_broadcaster_locals_dict -}; diff --git a/shared-bindings/bleio/Broadcaster.h b/shared-bindings/bleio/Broadcaster.h deleted file mode 100644 index 8aa125af97..0000000000 --- a/shared-bindings/bleio/Broadcaster.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_BROADCASTER_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_BROADCASTER_H - -#include "common-hal/bleio/Broadcaster.h" - -extern const mp_obj_type_t bleio_broadcaster_type; - -extern void common_hal_bleio_broadcaster_construct(bleio_broadcaster_obj_t *self, mp_float_t interval); -extern void common_hal_bleio_broadcaster_start_advertising(bleio_broadcaster_obj_t *self, mp_buffer_info_t *data); -extern void common_hal_bleio_broadcaster_stop_advertising(bleio_broadcaster_obj_t *self); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_BROADCASTER_H diff --git a/shared-bindings/bleio/Device.c b/shared-bindings/bleio/Device.c index 80595ef339..fcdc84d270 100644 --- a/shared-bindings/bleio/Device.c +++ b/shared-bindings/bleio/Device.c @@ -39,7 +39,6 @@ #include "shared-bindings/bleio/Device.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/UUID.h" -#include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/Device.h" #include "shared-module/bleio/ScanEntry.h" diff --git a/shared-bindings/bleio/Device.h b/shared-bindings/bleio/Device.h index aebf1d639d..1f85abe9a1 100644 --- a/shared-bindings/bleio/Device.h +++ b/shared-bindings/bleio/Device.h @@ -27,7 +27,6 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H -#include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/Device.h" #include "shared-module/bleio/Service.h" diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 960b3723c7..1d657635f4 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -40,14 +40,18 @@ #include "shared-bindings/bleio/Peripheral.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/UUID.h" -#include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/ScanEntry.h" #include "common-hal/bleio/Peripheral.h" -// TODO: Add unique MAC address part to name static const char default_name[] = "CIRCUITPY"; +#define ADV_INTERVAL_DEFAULT (1.0f) +#define ADV_INTERVAL_MIN (0.0020f) +#define ADV_INTERVAL_MIN_STRING "0.0020" +#define ADV_INTERVAL_MAX (10.24f) +#define ADV_INTERVAL_MAX_STRING "10.24" + //| .. currentmodule:: bleio //| //| :class:`Peripheral` -- A BLE peripheral device @@ -75,19 +79,21 @@ static const char default_name[] = "CIRCUITPY"; //| # Wait for connection. //| pass //| -//| .. class:: Peripheral(services, *, name='CIRCUITPY') +//| .. class:: Peripheral(services=(), \*, name='CIRCUITPY') //| //| Create a new Peripheral object. -//| :param iterable services: the Service objects representing services available from this peripheral. -//| :param str name: The name used when advertising this peripheral +//| :param iterable services: the Service objects representing services available from this peripheral, if any. +//| A non-connectable peripheral will have no services. +//| :param str name: The name used when advertising this peripheral. Use ``None`` when a name is not needed, +//| such as when the peripheral is a beacon //| STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_services, ARG_name }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_services, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_name, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + { MP_QSTR_services, MP_ARG_OBJ, {.u_obj = mp_const_empty_tuple} }, + { MP_QSTR_name, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -112,8 +118,11 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar } const mp_obj_t name = args[ARG_name].u_obj; - if (name == mp_const_none) { + if (name == MP_OBJ_NULL) { self->name = mp_obj_new_str(default_name, strlen(default_name)); + } else if (name == mp_const_none) { + // Make None be the empty string. + self->name = MP_OBJ_NEW_QSTR(MP_QSTR_); } else if (MP_OBJ_IS_STR(name)) { self->name = name; } else { @@ -182,7 +191,7 @@ const mp_obj_property_t bleio_peripheral_name_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| .. method:: start_advertising(data, *, scan_response=None, connectable=True) +//| .. method:: start_advertising(data, *, scan_response=None, connectable=True, interval=1) //| //| Starts advertising the peripheral. The peripheral's name and //| services are included in the advertisement packets. @@ -190,16 +199,17 @@ const mp_obj_property_t bleio_peripheral_name_obj = { //| :param buf data: advertising data packet bytes //| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed. //| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral. -//| +//| :param float interval: advertising interval, in seconds //| STATIC mp_obj_t bleio_peripheral_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_data, ARG_scan_response, ARG_connectable }; + enum { ARG_data, ARG_scan_response, ARG_connectable, ARG_interval }; static const mp_arg_t allowed_args[] = { { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_scan_response, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_connectable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, + { MP_QSTR_interval, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -210,11 +220,21 @@ STATIC mp_obj_t bleio_peripheral_start_advertising(mp_uint_t n_args, const mp_ob // Pass an empty buffer if scan_response not provided. mp_buffer_info_t scan_response_bufinfo = { 0 }; - if (args[ARG_data].u_obj != mp_const_none) { + if (args[ARG_scan_response].u_obj != mp_const_none) { mp_get_buffer_raise(args[ARG_scan_response].u_obj, &scan_response_bufinfo, MP_BUFFER_READ); } - common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool, + if (args[ARG_interval].u_obj == MP_OBJ_NULL) { + args[ARG_interval].u_obj = mp_obj_new_float(1.0F); + } + + const mp_float_t interval = mp_obj_float_get(args[ARG_interval].u_obj); + if (interval < ADV_INTERVAL_MIN || interval > ADV_INTERVAL_MAX) { + mp_raise_ValueError_varg(translate("interval must be in range %s-%s"), + ADV_INTERVAL_MIN_STRING, ADV_INTERVAL_MAX_STRING); + } + + common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool, interval, &data_bufinfo, &scan_response_bufinfo); return mp_const_none; diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index c09c600885..7ef45edcd6 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -34,7 +34,7 @@ extern const mp_obj_type_t bleio_peripheral_type; extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self); extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self); -extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); +extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, float interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_PERIPHERAL_H diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 03aef2eced..4b98e4673c 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -28,8 +28,6 @@ #include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/AddressType.h" -#include "shared-bindings/bleio/AdvertisementData.h" -#include "shared-bindings/bleio/Broadcaster.h" #include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/CharacteristicBuffer.h" #include "shared-bindings/bleio/Descriptor.h" @@ -57,7 +55,6 @@ //| AddressType //| AdvertisementData //| Adapter -//| Broadcaster //| Characteristic //| CharacteristicBuffer // Work-in-progress classes are omitted, and marked as :orphan: in their files. @@ -79,8 +76,6 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) }, { MP_ROM_QSTR(MP_QSTR_Address), MP_ROM_PTR(&bleio_address_type) }, - { MP_ROM_QSTR(MP_QSTR_AdvertisementData), MP_ROM_PTR(&bleio_advertisementdata_type) }, - { MP_ROM_QSTR(MP_QSTR_Broadcaster), MP_ROM_PTR(&bleio_broadcaster_type) }, { MP_ROM_QSTR(MP_QSTR_Characteristic), MP_ROM_PTR(&bleio_characteristic_type) }, { MP_ROM_QSTR(MP_QSTR_CharacteristicBuffer), MP_ROM_PTR(&bleio_characteristic_buffer_type) }, // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, diff --git a/shared-module/bleio/AdvertisementData.h b/shared-module/bleio/AdvertisementData.h index 738d53b23f..66855172ab 100644 --- a/shared-module/bleio/AdvertisementData.h +++ b/shared-module/bleio/AdvertisementData.h @@ -75,11 +75,4 @@ enum { AdManufacturerSpecificData = 0xFF, }; -typedef struct { - mp_obj_t device_name; - mp_obj_t services; - mp_obj_t data; - bool connectable; -} bleio_advertisement_data_t; - #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H From 9de46f3edd9bd6a827ba92ef4978143b109e912c Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 4 Jun 2019 21:20:43 -0500 Subject: [PATCH 07/61] [supervisor/shared/rgb_led_status.c] Initial support for RGB led as Status --- supervisor/shared/rgb_led_status.c | 96 +++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 7 deletions(-) diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 209eef55eb..2d7bb067ef 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -50,10 +50,28 @@ busio_spi_obj_t status_apa102; #endif #endif -#if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) +#if defined(CP_RGB_STATUS_R) || defined(CP_RGB_STATUS_G) || defined(CP_RGB_STATUS_B) +#define CP_RGB_STATUS_LED + +#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/microcontroller/Pin.h" + +pulseio_pwmout_obj_t rgb_status_r; +pulseio_pwmout_obj_t rgb_status_g; +pulseio_pwmout_obj_t rgb_status_b; + +uint8_t rgb_status_brightness = 0xFF; + +uint16_t status_rgb_color[3] = { + 0 /* red */, 0 /* green */, 0 /* blue */ +}; +#endif + +#if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || (defined(CP_RGB_STATUS_LED)) static uint32_t current_status_color = 0; #endif + void rgb_led_status_init() { #ifdef MICROPY_HW_NEOPIXEL common_hal_digitalio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL); @@ -93,7 +111,34 @@ void rgb_led_status_init() { #endif #endif - #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) + + #if defined(CP_RGB_STATUS_LED) + if (common_hal_mcu_pin_is_free(CP_RGB_STATUS_R)) { + pwmout_result_t red_result = common_hal_pulseio_pwmout_construct(&rgb_status_r, CP_RGB_STATUS_R, 0, 50000, false); + + if (PWMOUT_OK == red_result) { + common_hal_pulseio_pwmout_never_reset(&rgb_status_r); + } + } + + if (common_hal_mcu_pin_is_free(CP_RGB_STATUS_G)) { + pwmout_result_t green_result = common_hal_pulseio_pwmout_construct(&rgb_status_g, CP_RGB_STATUS_G, 0, 50000, false); + + if (PWMOUT_OK == green_result) { + common_hal_pulseio_pwmout_never_reset(&rgb_status_g); + } + } + + if (common_hal_mcu_pin_is_free(CP_RGB_STATUS_B)) { + pwmout_result_t blue_result = common_hal_pulseio_pwmout_construct(&rgb_status_b, CP_RGB_STATUS_B, 0, 50000, false); + + if (PWMOUT_OK == blue_result) { + common_hal_pulseio_pwmout_never_reset(&rgb_status_b); + } + } + #endif + + #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || (defined(CP_RGB_STATUS_LED)) // Force a write of the current status color. uint32_t rgb = current_status_color; current_status_color = 0x1000000; // Not a valid color @@ -109,10 +154,15 @@ void reset_status_led() { reset_pin_number(MICROPY_HW_APA102_MOSI->number); reset_pin_number(MICROPY_HW_APA102_SCK->number); #endif + #if defined(CP_RGB_STATUS_LED) + reset_pin_number(CP_RGB_STATUS_R->number); + reset_pin_number(CP_RGB_STATUS_G->number); + reset_pin_number(CP_RGB_STATUS_B->number); + #endif } void new_status_color(uint32_t rgb) { - #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) + #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || (defined(CP_RGB_STATUS_LED)) if (current_status_color == rgb) { return; } @@ -143,10 +193,24 @@ void new_status_color(uint32_t rgb) { common_hal_busio_spi_write(&status_apa102, status_apa102_color, 8); #endif #endif + + #if defined(CP_RGB_STATUS_LED) + uint8_t red_u8 = (rgb_adjusted >> 16) & 0xFF; + uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF; + uint8_t blue_u8 = rgb_adjusted & 0xFF; + + status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8; + status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8; + status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8; + + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]); + #endif } void temp_status_color(uint32_t rgb) { - #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) + #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || (defined(CP_RGB_STATUS_LED)) uint32_t rgb_adjusted = rgb; rgb_adjusted = color_brightness(rgb, rgb_status_brightness); #endif @@ -168,6 +232,19 @@ void temp_status_color(uint32_t rgb) { common_hal_busio_spi_write(&status_apa102, colors, 12); #endif #endif + #if defined(CP_RGB_STATUS_LED) + uint8_t red_u8 = (rgb_adjusted >> 16) & 0xFF; + uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF; + uint8_t blue_u8 = rgb_adjusted & 0xFF; + + status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8; + status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8; + status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8; + + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]); + #endif } void clear_temp_status() { @@ -181,6 +258,11 @@ void clear_temp_status() { common_hal_busio_spi_write(&status_apa102, status_apa102_color, 8); #endif #endif + #if defined(CP_RGB_STATUS_LED) + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]); + #endif } uint32_t color_brightness(uint32_t color, uint8_t brightness) { @@ -210,7 +292,7 @@ void prep_rgb_status_animation(const pyexec_result_t* result, bool found_main, safe_mode_t safe_mode, rgb_status_animation_t* status) { - #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) + #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || (defined(CP_RGB_STATUS_LED)) new_status_color(ALL_DONE); status->pattern_start = ticks_ms; status->safe_mode = safe_mode; @@ -256,7 +338,7 @@ void prep_rgb_status_animation(const pyexec_result_t* result, } void tick_rgb_status_animation(rgb_status_animation_t* status) { - #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) + #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || (defined(CP_RGB_STATUS_LED)) uint32_t tick_diff = ticks_ms - status->pattern_start; if (status->ok) { // All is good. Ramp ALL_DONE up and down. @@ -326,4 +408,4 @@ void tick_rgb_status_animation(rgb_status_animation_t* status) { } } #endif -} +} \ No newline at end of file From 1905d90eaa65b6b306c84038cc1ad32e4e601f65 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 5 Jun 2019 20:08:53 -0400 Subject: [PATCH 08/61] Make advertising data buffers long-lived --- ports/nrf/common-hal/bleio/Peripheral.c | 5 ++++- ports/nrf/common-hal/bleio/Peripheral.h | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 2cd52841a3..e522b50d28 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -177,9 +177,13 @@ void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, } check_data_fit(advertising_data_bufinfo->len); + // The advertising data buffers must not move, because the SoftDevice depends on them. + // So make them long-lived. + self->advertising_data = (uint8_t *) gc_alloc(BLE_GAP_ADV_SET_DATA_SIZE_MAX * sizeof(uint8_t), false, true); memcpy(self->advertising_data, advertising_data_bufinfo->buf, advertising_data_bufinfo->len); check_data_fit(scan_response_data_bufinfo->len); + self->scan_response_data = (uint8_t *) gc_alloc(BLE_GAP_ADV_SET_DATA_SIZE_MAX * sizeof(uint8_t), false, true); memcpy(self->scan_response_data, scan_response_data_bufinfo->buf, scan_response_data_bufinfo->len); @@ -214,7 +218,6 @@ void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, } void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *self) { - if (self->adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) return; diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index 58526fc484..eb0b0417a1 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -46,8 +46,8 @@ typedef struct { // The advertising data and scan response buffers are held by us, not by the SD, so we must // maintain them and not change it. If we need to change the contents during advertising, // there are tricks to get the SD to notice (see DevZone - TBS). - uint8_t advertising_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; - uint8_t scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; + uint8_t* advertising_data; + uint8_t* scan_response_data; uint8_t adv_handle; } bleio_peripheral_obj_t; From 6fed24e1b6fce58f2c06328b9bc8b8f9d9512b42 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 10 Jun 2019 07:18:28 -0400 Subject: [PATCH 09/61] WIP --- shared-bindings/bleio/Address.c | 58 +++++---------------------------- shared-bindings/bleio/UUID.c | 5 +-- 2 files changed, 12 insertions(+), 51 deletions(-) diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index b7c76b7b2e..226c011a3d 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -53,9 +53,8 @@ STATIC uint8_t xdigit_8b_value(byte nibble1, byte nibble2) { //| Create a new Address object encapsulating the address value. //| The value itself can be one of: //| -//| - a `str` value in the format of 'XXXXXXXXXXXX' or 'XX:XX:XX:XX:XX:XX' (12 hex digits) -//| - a `bytes` or `bytearray` containing 6 bytes -//| - another Address object +//| :param buf: The address value to encapsulate +//| - a buffer object (bytearray, bytes) of 6 bytes //| //| :param address: The address to encapsulate //| @@ -84,54 +83,15 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t address = args[ARG_address].u_obj; - if (MP_OBJ_IS_STR(address)) { - GET_STR_DATA_LEN(address, str, str_len); - - size_t value_index = 0; - int str_index = str_len; - bool error = false; - - // Loop until fewer than two characters left. - while (str_index >= 1 && value_index < sizeof(self->value)) { - if (str[str_index] == ':') { - // Skip colon separators. - str_index--; - continue; - } - - if (!unichar_isxdigit(str[str_index]) || - !unichar_isxdigit(str[str_index-1])) { - error = true; - break; - } - - self->value[value_index] = xdigit_8b_value(str[str_index], - str[str_index-1]); - value_index += 1; - str_index -= 2; - } - // Check for correct number of hex digits and no parsing errors. - if (error || value_index != ADDRESS_BYTE_LEN || str_index != -1) { - mp_raise_ValueError_varg(translate("Address is not %d bytes long or is in wrong format"), - ADDRESS_BYTE_LEN); - } - } else if (MP_OBJ_IS_TYPE(address, &mp_type_bytearray) || MP_OBJ_IS_TYPE(address, &mp_type_bytes)) { - mp_buffer_info_t buf_info; - mp_get_buffer_raise(address, &buf_info, MP_BUFFER_READ); - if (buf_info.len != BLEIO_ADDRESS_BYTES) { - mp_raise_ValueError_varg(translate("Address must be %d bytes long"), BLEIO_ADDRESS_BYTES); - } - - for (size_t b = 0; b < BLEIO_ADDRESS_BYTES; ++b) { - self->value[BLEIO_ADDRESS_BYTES - b - 1] = ((uint8_t*)buf_info.buf)[b]; - } - } else if (MP_OBJ_IS_TYPE(address, &bleio_address_type)) { - // deep copy - bleio_address_obj_t *other = MP_OBJ_TO_PTR(address); - self->type = other->type; - memcpy(self->value, other->value, BLEIO_ADDRESS_BYTES); + mp_buffer_info_t buf_info; + mp_get_buffer_raise(address, &buf_info, MP_BUFFER_READ); + if (buf_info.len != BLEIO_ADDRESS_BYTES) { + mp_raise_ValueError_varg(translate("Address must be %d bytes long"), BLEIO_ADDRESS_BYTES); } + for (size_t b = 0; b < BLEIO_ADDRESS_BYTES; ++b) { + self->value[BLEIO_ADDRESS_BYTES - b - 1] = ((uint8_t*)buf_info.buf)[b]; + } return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c index c6ad9e6266..d054ea7191 100644 --- a/shared-bindings/bleio/UUID.c +++ b/shared-bindings/bleio/UUID.c @@ -48,8 +48,9 @@ //| //| - an `int` value in range 0 to 0xFFFF (Bluetooth SIG 16-bit UUID) //| - a buffer object (bytearray, bytes) of 16 bytes in little-endian order (128-bit UUID) +//| - a string of hex digits of the form 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' //| -//| :param int/buffer value: The uuid value to encapsulate +//| :param value: The uuid value to encapsulate //| STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_arg_check_num(n_args, kw_args, 1, 1, false); @@ -63,7 +64,7 @@ STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, co if (MP_OBJ_IS_INT(value)) { mp_int_t uuid16 = mp_obj_get_int(value); if (uuid16 < 0 || uuid16 > 0xffff) { - mp_raise_ValueError(translate("UUID integer value not in range 0 to 0xffff")); + mp_raise_ValueError(translate("UUID integer value must be 0-0xffff")); } // NULL means no 128-bit value. From 1356819de195810da09b5fc051ef5cc9dc21b2f4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 17 Jun 2019 23:16:40 -0400 Subject: [PATCH 10/61] Handle None for BLE name; fix ScanEntry bug; compile issue --- ports/nrf/Makefile | 2 +- shared-bindings/bleio/Peripheral.c | 5 +---- shared-bindings/bleio/ScanEntry.c | 1 + shared-module/displayio/TileGrid.c | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index d947ab34c0..b7ff2fcbaa 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -91,7 +91,7 @@ INC += -I../../supervisor/shared/usb ifeq ($(DEBUG), 1) CFLAGS += -ggdb # You may want to enable these flags to make setting breakpoints easier. - CFLAGS += -fno-inline -fno-ipa-sra + # CFLAGS += -fno-inline -fno-ipa-sra else CFLAGS += -Os -DNDEBUG # TODO: Test with -flto diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index ca703bd535..4492a8e269 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -117,11 +117,8 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar } const mp_obj_t name = args[ARG_name].u_obj; - if (name == MP_OBJ_NULL) { + if (name == MP_OBJ_NULL || name == mp_const_none) { self->name = mp_obj_new_str(default_name, strlen(default_name)); - } else if (name == mp_const_none) { - // Make None be the empty string. - self->name = MP_OBJ_NEW_QSTR(MP_QSTR_); } else if (MP_OBJ_IS_STR(name)) { self->name = name; } else { diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index 475bade153..f66b3df4b8 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -55,6 +55,7 @@ STATIC mp_obj_t bleio_scanentry_get_address(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); + address->base.type = &bleio_address_type; memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); address->type = self->address.type; return MP_OBJ_TO_PTR(address); diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 97b704c40e..43ce36ed37 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -440,7 +440,7 @@ void displayio_tilegrid_finish_refresh(displayio_tilegrid_t *self) { displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *self, displayio_area_t* tail) { if (self->moved && !self->first_draw) { displayio_area_union(&self->previous_area, &self->current_area, &self->dirty_area); - if (displayio_area_size(&self->dirty_area) <= 2 * self->pixel_width * self->pixel_height) { + if (displayio_area_size(&self->dirty_area) <= 2U * self->pixel_width * self->pixel_height) { self->dirty_area.next = tail; return &self->dirty_area; } From 35b919185747c42e183ccfc41f99fd370acca450 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 18 Jun 2019 23:46:20 -0400 Subject: [PATCH 11/61] Don't operate directly on bleio objects in shared-bindings: use common_hal routines instead. Changes made but not yet tested. --- ports/nrf/common-hal/bleio/Broadcaster.h | 6 +-- ports/nrf/common-hal/bleio/Characteristic.c | 16 +++++- ports/nrf/common-hal/bleio/Characteristic.h | 8 +-- .../common-hal/bleio/CharacteristicBuffer.h | 6 +-- ports/nrf/common-hal/bleio/Device.c | 14 +++--- ports/nrf/common-hal/bleio/Peripheral.c | 18 ++++++- ports/nrf/common-hal/bleio/Peripheral.h | 12 +++-- ports/nrf/common-hal/bleio/Scanner.c | 12 ++++- .../nrf/common-hal}/bleio/Scanner.h | 9 ++-- ports/nrf/common-hal/bleio/Service.c | 36 ++++++++++++-- .../nrf/common-hal}/bleio/Service.h | 8 +-- ports/nrf/common-hal/bleio/__init__.h | 6 +-- py/circuitpy_defns.mk | 2 + py/obj.h | 1 + py/objlist.c | 4 +- shared-bindings/bleio/Address.c | 10 ++-- shared-bindings/bleio/Address.h | 5 ++ shared-bindings/bleio/Characteristic.c | 22 ++++----- shared-bindings/bleio/Characteristic.h | 5 +- shared-bindings/bleio/CharacteristicBuffer.c | 3 +- shared-bindings/bleio/Device.h | 2 +- shared-bindings/bleio/Peripheral.c | 25 +++++----- shared-bindings/bleio/Peripheral.h | 4 +- shared-bindings/bleio/ScanEntry.c | 24 +++------ shared-bindings/bleio/ScanEntry.h | 5 ++ shared-bindings/bleio/Scanner.c | 6 +-- shared-bindings/bleio/Scanner.h | 6 ++- shared-bindings/bleio/Service.c | 24 ++++----- shared-bindings/bleio/Service.h | 8 ++- shared-module/bleio/Address.c | 45 +++++++++++++++++ shared-module/bleio/Address.h | 2 + shared-module/bleio/Characteristic.h | 1 + shared-module/bleio/ScanEntry.c | 49 +++++++++++++++++++ shared-module/bleio/ScanEntry.h | 3 +- 34 files changed, 294 insertions(+), 113 deletions(-) rename {shared-module => ports/nrf/common-hal}/bleio/Scanner.h (83%) rename {shared-module => ports/nrf/common-hal}/bleio/Service.h (88%) create mode 100644 shared-module/bleio/Address.c create mode 100644 shared-module/bleio/ScanEntry.c diff --git a/ports/nrf/common-hal/bleio/Broadcaster.h b/ports/nrf/common-hal/bleio/Broadcaster.h index 72f93a4431..2d1ae69a12 100644 --- a/ports/nrf/common-hal/bleio/Broadcaster.h +++ b/ports/nrf/common-hal/bleio/Broadcaster.h @@ -25,8 +25,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_BROADCASTER_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_BROADCASTER_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H #include "ble.h" @@ -44,4 +44,4 @@ typedef struct { } bleio_broadcaster_obj_t; -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_BROADCASTER_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 9409b73ce6..45fb1d092a 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -237,7 +237,11 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, } -void common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self) { +void common_hal_bleio_characteristic_set_service(bleio_characteristic_obj_t *self, bleio_service_obj_t *service) { + self->service = service; +} + +mp_obj_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self) { switch (common_hal_bleio_device_get_gatt_role(self->service->device)) { case GATT_ROLE_CLIENT: gattc_read(self); @@ -251,6 +255,8 @@ void common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self) mp_raise_RuntimeError(translate("bad GATT role")); break; } + + return self->value_data; } void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo) { @@ -285,3 +291,11 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, break; } } + +bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self) { + return self->uuid; +} + +bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self) { + return self->props; +} diff --git a/ports/nrf/common-hal/bleio/Characteristic.h b/ports/nrf/common-hal/bleio/Characteristic.h index bce1eec1d3..662485bad5 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.h +++ b/ports/nrf/common-hal/bleio/Characteristic.h @@ -24,11 +24,11 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTIC_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTIC_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H #include "shared-module/bleio/Characteristic.h" -#include "shared-module/bleio/Service.h" +#include "common-hal/bleio/Service.h" #include "common-hal/bleio/UUID.h" typedef struct { @@ -43,4 +43,4 @@ typedef struct { uint16_t sccd_handle; } bleio_characteristic_obj_t; -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTIC_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H diff --git a/ports/nrf/common-hal/bleio/CharacteristicBuffer.h b/ports/nrf/common-hal/bleio/CharacteristicBuffer.h index b36f63fec3..6a44229f7a 100644 --- a/ports/nrf/common-hal/bleio/CharacteristicBuffer.h +++ b/ports/nrf/common-hal/bleio/CharacteristicBuffer.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H #include "nrf_soc.h" @@ -40,4 +40,4 @@ typedef struct { ringbuf_t ringbuf; } bleio_characteristic_buffer_obj_t; -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H diff --git a/ports/nrf/common-hal/bleio/Device.c b/ports/nrf/common-hal/bleio/Device.c index 5f625829e4..b1ac72e754 100644 --- a/ports/nrf/common-hal/bleio/Device.c +++ b/ports/nrf/common-hal/bleio/Device.c @@ -323,7 +323,7 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); service->base.type = &bleio_service_type; service->device = device; - service->char_list = mp_obj_new_list(0, NULL); + service->characteristic_list = mp_obj_new_list(0, NULL); service->start_handle = gattc_service->handle_range.start_handle; service->end_handle = gattc_service->handle_range.end_handle; service->handle = gattc_service->handle_range.start_handle; @@ -366,7 +366,7 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio characteristic->handle = gattc_char->handle_value; characteristic->service = m_char_discovery_service; - mp_obj_list_append(m_char_discovery_service->char_list, MP_OBJ_FROM_PTR(characteristic)); + mp_obj_list_append(m_char_discovery_service->characteristic_list, MP_OBJ_FROM_PTR(characteristic)); } if (response->count > 0) { @@ -491,9 +491,9 @@ void common_hal_bleio_device_add_service(bleio_device_obj_t *device, bleio_servi mp_raise_OSError_msg(translate("Failed to add service")); } - const mp_obj_list_t *char_list = MP_OBJ_TO_PTR(service->char_list); - for (size_t i = 0; i < char_list->len; ++i) { - bleio_characteristic_obj_t *characteristic = char_list->items[i]; + const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); + for (size_t i = 0; i < characteristic_list->len; ++i) { + bleio_characteristic_obj_t *characteristic = characteristic_list->items[i]; common_hal_bleio_service_add_characteristic(service, characteristic); } } @@ -583,8 +583,8 @@ void common_hal_bleio_device_connect(bleio_device_obj_t *device) { bool found_char = discover_characteristics(device, service, service->start_handle); while (found_char) { - const mp_obj_list_t *char_list = MP_OBJ_TO_PTR(service->char_list); - const bleio_characteristic_obj_t *characteristic = char_list->items[char_list->len - 1]; + const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); + const bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_list->len - 1]; const uint16_t next_handle = characteristic->handle + 1; if (next_handle >= service->end_handle) { diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index e59676fde4..36c20373d3 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -33,6 +33,7 @@ #include "ble_hci.h" #include "nrf_soc.h" #include "py/gc.h" +#include "py/objlist.h" #include "py/objstr.h" #include "py/runtime.h" #include "shared-bindings/bleio/Adapter.h" @@ -40,6 +41,7 @@ #include "shared-bindings/bleio/Peripheral.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/UUID.h" +#include "common-hal/bleio/Service.h" #define BLE_MIN_CONN_INTERVAL MSEC_TO_UNITS(15, UNIT_0_625_MS) #define BLE_MAX_CONN_INTERVAL MSEC_TO_UNITS(300, UNIT_0_625_MS) @@ -117,19 +119,23 @@ STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { } } -void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self) { +void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self, mp_obj_list_t *service_list, mp_obj_t name) { common_hal_bleio_adapter_set_enabled(true); + self->service_list = service_list; + self->name = name; + self->gatt_role = GATT_ROLE_SERVER; self->conn_handle = BLE_CONN_HANDLE_INVALID; self->adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; // Add all the services. - mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); for (size_t service_idx = 0; service_idx < service_list->len; ++service_idx) { bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[service_idx]); + common_hal_bleio_service_set_device(service, MP_OBJ_FROM_PTR(self)); + ble_uuid_t uuid; bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); @@ -149,10 +155,18 @@ void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self) { } +mp_obj_list_t *common_hal_bleio_peripheral_get_service_list(bleio_peripheral_obj_t *self) { + return self->service_list; +} + bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self) { return self->conn_handle != BLE_CONN_HANDLE_INVALID; } +mp_obj_t common_hal_bleio_peripheral_get_name(bleio_peripheral_obj_t *self) { + return self->name; +} + void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self, bool connectable, mp_float_t interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo) { // interval value has already been validated. diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index eb0b0417a1..9103fcf943 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -25,13 +25,16 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_PERIPHERAL_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_PERIPHERAL_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_PERIPHERAL_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_PERIPHERAL_H #include #include "ble.h" +#include "py/obj.h" +#include "py/objlist.h" + #include "shared-module/bleio/__init__.h" #include "shared-module/bleio/Address.h" @@ -40,8 +43,7 @@ typedef struct { mp_obj_t name; gatt_role_t gatt_role; volatile uint16_t conn_handle; - mp_obj_t service_list; - mp_obj_t notif_handler; + mp_obj_list_t *service_list; mp_obj_t conn_handler; // The advertising data and scan response buffers are held by us, not by the SD, so we must // maintain them and not change it. If we need to change the contents during advertising, @@ -52,4 +54,4 @@ typedef struct { } bleio_peripheral_obj_t; -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_PERIPHERAL_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_PERIPHERAL_H diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index 08600bc0ae..64f7decad2 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -30,6 +30,7 @@ #include "ble_drv.h" #include "ble_gap.h" #include "py/mphal.h" +#include "py/objlist.h" #include "py/runtime.h" #include "shared-bindings/bleio/Adapter.h" #include "shared-bindings/bleio/ScanEntry.h" @@ -68,6 +69,10 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { } } +void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self) { + self->adv_reports = mp_obj_new_list(0, NULL); +} + void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { common_hal_bleio_adapter_set_enabled(true); ble_drv_add_event_handler(on_ble_evt, self); @@ -78,7 +83,8 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout .scan_phys = BLE_GAP_PHY_1MBPS, }; - common_hal_bleio_adapter_set_enabled(true); + // Empty the advertising reports list. + mp_obj_list_clear(self->adv_reports); uint32_t err_code; err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); @@ -90,3 +96,7 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout mp_hal_delay_ms(timeout * 1000); sd_ble_gap_scan_stop(); } + +mp_obj_t common_hal_bleio_scanner_get_adv_reports(bleio_scanner_obj_t *self) { + return self->adv_reports; +} diff --git a/shared-module/bleio/Scanner.h b/ports/nrf/common-hal/bleio/Scanner.h similarity index 83% rename from shared-module/bleio/Scanner.h rename to ports/nrf/common-hal/bleio/Scanner.h index 76f5e58669..a710664877 100644 --- a/shared-module/bleio/Scanner.h +++ b/ports/nrf/common-hal/bleio/Scanner.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -24,16 +25,16 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SCANNER_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SCANNER_H #include "py/obj.h" typedef struct { mp_obj_base_t base; - mp_obj_t adv_reports; + mp_obj_t adv_reports; // List of reports. uint16_t interval; uint16_t window; } bleio_scanner_obj_t; -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANNER_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SCANNER_H diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c index 26a1f1cff5..77d3f02599 100644 --- a/ports/nrf/common-hal/bleio/Service.c +++ b/ports/nrf/common-hal/bleio/Service.c @@ -29,18 +29,46 @@ #include "py/runtime.h" #include "common-hal/bleio/__init__.h" #include "common-hal/bleio/Characteristic.h" +#include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/Adapter.h" -void common_hal_bleio_service_construct(bleio_service_obj_t *self) { +void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, mp_obj_list_t *characteristic_list, bool is_secondary) { + self->device = mp_const_none; + self->handle = 0xFFFF; + self->uuid = uuid; + self->characteristic_list = characteristic_list; + self->is_secondary = is_secondary; + + for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { + bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(characteristic_list->items[characteristic_idx]); + common_hal_bleio_characteristic_set_service(characteristic, self); + } + +} + +bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self) { + return self->uuid; +} + +mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self) { + return self->characteristic_list; +} + +bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self) { + return self->is_secondary; +} + +void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t device) { + self->device = device; } // Call this after the Service has been added to the Peripheral. void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self) { // Add all the characteristics. - const mp_obj_list_t *char_list = MP_OBJ_TO_PTR(self->char_list); - for (size_t char_idx = 0; char_idx < char_list->len; ++char_idx) { - bleio_characteristic_obj_t *characteristic = char_list->items[char_idx]; + const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(self->characteristic_list); + for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { + bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_idx]; ble_gatts_char_md_t char_md = { .char_props.broadcast = characteristic->props.broadcast, diff --git a/shared-module/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h similarity index 88% rename from shared-module/bleio/Service.h rename to ports/nrf/common-hal/bleio/Service.h index 828d4cdc87..7998cc862a 100644 --- a/shared-module/bleio/Service.h +++ b/ports/nrf/common-hal/bleio/Service.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H #include "common-hal/bleio/UUID.h" @@ -36,9 +36,9 @@ typedef struct { bleio_uuid_obj_t *uuid; // May be a Peripheral, Central, etc. mp_obj_t *device; - mp_obj_t char_list; + mp_obj_t characteristic_list; uint16_t start_handle; uint16_t end_handle; } bleio_service_obj_t; -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SERVICE_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H diff --git a/ports/nrf/common-hal/bleio/__init__.h b/ports/nrf/common-hal/bleio/__init__.h index 9e044f37c1..0c46b631fc 100644 --- a/ports/nrf/common-hal/bleio/__init__.h +++ b/ports/nrf/common-hal/bleio/__init__.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_COMMON_HAL_BLEIO_INIT_H -#define MICROPY_INCLUDED_COMMON_HAL_BLEIO_INIT_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_INIT_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_INIT_H #include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/Adapter.h" @@ -39,4 +39,4 @@ gatt_role_t common_hal_bleio_device_get_gatt_role(mp_obj_t device); uint16_t common_hal_bleio_device_get_conn_handle(mp_obj_t device); -#endif // MICROPY_INCLUDED_COMMON_HAL_BLEIO_INIT_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_INIT_H diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index fd43a11a67..435cf2c334 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -308,6 +308,8 @@ $(filter $(SRC_PATTERNS), \ bitbangio/SPI.c \ bitbangio/__init__.c \ board/__init__.c \ + bleio/Address.c \ + bleio/ScanEntry.c \ busio/OneWire.c \ displayio/Bitmap.c \ displayio/ColorConverter.c \ diff --git a/py/obj.h b/py/obj.h index 773043b593..6eead377db 100644 --- a/py/obj.h +++ b/py/obj.h @@ -763,6 +763,7 @@ void mp_obj_tuple_del(mp_obj_t self_in); mp_int_t mp_obj_tuple_hash(mp_obj_t self_in); // list +mp_obj_t mp_obj_list_clear(mp_obj_t self_in); mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg); mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value); void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items); diff --git a/py/objlist.c b/py/objlist.c index 16ca4b353e..558c4c6115 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -340,7 +340,7 @@ mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ return mp_const_none; } -STATIC mp_obj_t list_clear(mp_obj_t self_in) { +mp_obj_t mp_obj_list_clear(mp_obj_t self_in) { mp_check_self(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); self->len = 0; @@ -418,7 +418,7 @@ STATIC mp_obj_t list_reverse(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append); STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_extend_obj, list_extend); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, list_clear); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, mp_obj_list_clear); STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_copy_obj, list_copy); STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_count_obj, list_count); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index); diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index 7367da5352..5875cf9bd8 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -74,13 +75,12 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_ValueError_varg(translate("Address must be %d bytes long"), NUM_BLEIO_ADDRESS_BYTES); } - memcpy(self->bytes, buf_info.buf, buf_info.len); - const mp_int_t address_type = args[ARG_address_type].u_int; if (address_type < BLEIO_ADDRESS_TYPE_MIN || address_type > BLEIO_ADDRESS_TYPE_MAX) { mp_raise_ValueError(translate("Address type out of range")); } - self->type = address_type; + + common_hal_bleio_address_construct(self, buf_info.buf, buf_info.len, address_type); return MP_OBJ_FROM_PTR(self); } @@ -97,7 +97,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bytes(self->bytes, NUM_BLEIO_ADDRESS_BYTES); + return common_hal_bleio_address_get_address_bytes(self); } MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_address_bytes_obj, bleio_address_get_address_bytes); @@ -113,7 +113,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_address_bytes_obj, bleio_address_get STATIC mp_obj_t bleio_address_get_type(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_NEW_SMALL_INT(self->type); + return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_address_get_type(self)); } MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_type_obj, bleio_address_get_type); diff --git a/shared-bindings/bleio/Address.h b/shared-bindings/bleio/Address.h index ef84d7432b..9652a9841a 100644 --- a/shared-bindings/bleio/Address.h +++ b/shared-bindings/bleio/Address.h @@ -28,6 +28,7 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADDRESS_H #include "py/objtype.h" +#include "shared-module/bleio/Address.h" #define BLEIO_ADDRESS_TYPE_PUBLIC (0) #define BLEIO_ADDRESS_TYPE_RANDOM_STATIC (1) @@ -39,4 +40,8 @@ extern const mp_obj_type_t bleio_address_type; +extern void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type); +extern mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self); +extern uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADDRESS_H diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index ae83de8643..e48cfd433b 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -73,10 +73,10 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t if (!MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) { mp_raise_ValueError(translate("Expected a UUID")); } + bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid); bleio_characteristic_obj_t *self = m_new_obj(bleio_characteristic_obj_t); self->base.type = &bleio_characteristic_type; - self->uuid = MP_OBJ_TO_PTR(uuid); bleio_characteristic_properties_t properties; @@ -87,7 +87,7 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t properties.write = args[ARG_write].u_bool; properties.write_no_response = args[ARG_write_no_response].u_bool; - common_hal_bleio_characteristic_construct(self, uuid, properties); + common_hal_bleio_characteristic_construct(self, uuid_obj, properties); return MP_OBJ_FROM_PTR(self); } @@ -99,7 +99,7 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t STATIC mp_obj_t bleio_characteristic_get_broadcast(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.broadcast); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).broadcast); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_broadcast_obj, bleio_characteristic_get_broadcast); @@ -117,7 +117,7 @@ const mp_obj_property_t bleio_characteristic_broadcast_obj = { STATIC mp_obj_t bleio_characteristic_get_indicate(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.indicate); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).indicate); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_indicate_obj, bleio_characteristic_get_indicate); @@ -136,7 +136,7 @@ const mp_obj_property_t bleio_characteristic_indicate_obj = { STATIC mp_obj_t bleio_characteristic_get_notify(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.notify); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).notify); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_notify_obj, bleio_characteristic_get_notify); @@ -154,7 +154,7 @@ const mp_obj_property_t bleio_characteristic_notify_obj = { STATIC mp_obj_t bleio_characteristic_get_read(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.read); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).read); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_read_obj, bleio_characteristic_get_read); @@ -172,7 +172,7 @@ const mp_obj_property_t bleio_characteristic_read_obj = { STATIC mp_obj_t bleio_characteristic_get_write(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.write); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).write); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_write_obj, bleio_characteristic_get_write); @@ -190,7 +190,7 @@ const mp_obj_property_t bleio_characteristic_write_obj = { STATIC mp_obj_t bleio_characteristic_get_write_no_response(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->props.write_no_response); + return mp_obj_new_bool(common_hal_bleio_characteristic_get_properties(self).write_no_response); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_write_no_response_obj, bleio_characteristic_get_write_no_response); @@ -208,7 +208,7 @@ const mp_obj_property_t bleio_characteristic_write_no_response_obj = { STATIC mp_obj_t bleio_characteristic_get_uuid(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(self->uuid); + return MP_OBJ_FROM_PTR(common_hal_bleio_characteristic_get_uuid(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_uuid_obj, bleio_characteristic_get_uuid); @@ -228,9 +228,7 @@ const mp_obj_property_t bleio_characteristic_uuid_obj = { STATIC mp_obj_t bleio_characteristic_get_value(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_bleio_characteristic_get_value(self); - - return self->value_data; + return common_hal_bleio_characteristic_get_value(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_value_obj, bleio_characteristic_get_value); diff --git a/shared-bindings/bleio/Characteristic.h b/shared-bindings/bleio/Characteristic.h index 206cbcd403..ffee6bdbc7 100644 --- a/shared-bindings/bleio/Characteristic.h +++ b/shared-bindings/bleio/Characteristic.h @@ -32,7 +32,10 @@ extern const mp_obj_type_t bleio_characteristic_type; extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props); -extern void common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self); +extern void common_hal_bleio_characteristic_set_service(bleio_characteristic_obj_t *self, bleio_service_obj_t *service); +extern mp_obj_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self); extern void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo); +extern bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self); +extern bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index a1dc663fd1..da79c5d7ae 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -85,9 +85,8 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, bleio_characteristic_buffer_obj_t *self = m_new_obj(bleio_characteristic_buffer_obj_t); self->base.type = &bleio_characteristic_buffer_type; - self->characteristic = MP_OBJ_TO_PTR(characteristic); - common_hal_bleio_characteristic_buffer_construct(self, self->characteristic, timeout, buffer_size); + common_hal_bleio_characteristic_buffer_construct(self, characteristic, timeout, buffer_size); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/Device.h b/shared-bindings/bleio/Device.h index 1f85abe9a1..e452a8ad6c 100644 --- a/shared-bindings/bleio/Device.h +++ b/shared-bindings/bleio/Device.h @@ -28,7 +28,7 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H #include "shared-module/bleio/Device.h" -#include "shared-module/bleio/Service.h" +#include "common-hal/bleio/Service.h" extern const mp_obj_type_t bleio_device_type; diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 4492a8e269..5397f4c3ab 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -101,32 +101,33 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar // If services is not an iterable, an exception will be thrown. mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(args[ARG_services].u_obj, &iter_buf); - mp_obj_t service; bleio_peripheral_obj_t *self = m_new_obj(bleio_peripheral_obj_t); self->base.type = &bleio_peripheral_type; - self->service_list = mp_obj_new_list(0, NULL); - self->notif_handler = mp_const_none; + + // Copy the services list and validate its items. + mp_obj_t service_list = mp_obj_new_list(0, NULL); + mp_obj_list_t *service_list_obj = MP_OBJ_FROM_PTR(service_list); + + mp_obj_t service; while ((service = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (!MP_OBJ_IS_TYPE(service, &bleio_service_type)) { mp_raise_ValueError(translate("services includes an object that is not a Service")); } - bleio_service_obj_t *service_ptr = MP_OBJ_TO_PTR(service); - service_ptr->device = MP_OBJ_FROM_PTR(self); - mp_obj_list_append(self->service_list, service); + mp_obj_list_append(service_list, service); } const mp_obj_t name = args[ARG_name].u_obj; + mp_obj_t name_str; if (name == MP_OBJ_NULL || name == mp_const_none) { - self->name = mp_obj_new_str(default_name, strlen(default_name)); + name_str = mp_obj_new_str(default_name, strlen(default_name)); } else if (MP_OBJ_IS_STR(name)) { - self->name = name; + name_str = name; } else { mp_raise_ValueError(translate("name must be a string")); } - // Do port-specific initialization. - common_hal_bleio_peripheral_construct(self); + common_hal_bleio_peripheral_construct(self, service_list_obj, name_str); return MP_OBJ_FROM_PTR(self); } @@ -157,7 +158,7 @@ const mp_obj_property_t bleio_peripheral_connected_obj = { STATIC mp_obj_t bleio_peripheral_get_services(mp_obj_t self_in) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); // Return list as a tuple so user won't be able to change it. - mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + mp_obj_list_t *service_list = common_hal_bleio_peripheral_get_service_list(self); return mp_obj_new_tuple(service_list->len, service_list->items); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_get_services_obj, bleio_peripheral_get_services); @@ -176,7 +177,7 @@ const mp_obj_property_t bleio_peripheral_services_obj = { STATIC mp_obj_t bleio_peripheral_get_name(mp_obj_t self_in) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); - return self->name; + return common_hal_bleio_peripheral_get_name(self); } MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_get_name_obj, bleio_peripheral_get_name); diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index 7ef45edcd6..6468325c27 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -32,8 +32,10 @@ extern const mp_obj_type_t bleio_peripheral_type; -extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self); +extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self, mp_obj_list_t *service_list, mp_obj_t name); +extern mp_obj_list_t *common_hal_bleio_peripheral_get_service_list(bleio_peripheral_obj_t *self); extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self); +extern mp_obj_t common_hal_bleio_peripheral_get_name(bleio_peripheral_obj_t *self); extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, float interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device); diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index f66b3df4b8..145d2b0236 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * Copyright (c) 2017 Glenn Ruben Bakke * @@ -27,10 +28,7 @@ #include -#include "py/objarray.h" #include "py/objproperty.h" -#include "py/objstr.h" -#include "py/objtuple.h" #include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/ScanEntry.h" #include "shared-bindings/bleio/UUID.h" @@ -53,18 +51,13 @@ //| STATIC mp_obj_t bleio_scanentry_get_address(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); - - bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); - address->base.type = &bleio_address_type; - memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); - address->type = self->address.type; - return MP_OBJ_TO_PTR(address); + return common_hal_bleio_scanentry_get_address(self); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scanentry_get_address_obj, bleio_scanentry_get_address); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_address_obj, bleio_scanentry_get_address); const mp_obj_property_t bleio_scanentry_address_obj = { .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bluepy_scanentry_get_address_obj, + .proxy = { (mp_obj_t)&bleio_scanentry_get_address_obj, (mp_obj_t)&mp_const_none_obj, (mp_obj_t)&mp_const_none_obj }, }; @@ -75,7 +68,7 @@ const mp_obj_property_t bleio_scanentry_address_obj = { //| STATIC mp_obj_t scanentry_get_raw_data(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); - return self->data; + return common_hal_bleio_scanentry_get_raw_data(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_raw_data_obj, scanentry_get_raw_data); @@ -92,14 +85,13 @@ const mp_obj_property_t bleio_scanentry_raw_data_obj = { //| STATIC mp_obj_t scanentry_get_rssi(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return mp_obj_new_int(self->rssi); + return mp_obj_new_int(common_hal_bleio_scanentry_get_rssi(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bluepy_scanentry_get_rssi_obj, scanentry_get_rssi); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_rssi_obj, scanentry_get_rssi); const mp_obj_property_t bleio_scanentry_rssi_obj = { .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bluepy_scanentry_get_rssi_obj, + .proxy = { (mp_obj_t)&bleio_scanentry_get_rssi_obj, (mp_obj_t)&mp_const_none_obj, (mp_obj_t)&mp_const_none_obj }, }; diff --git a/shared-bindings/bleio/ScanEntry.h b/shared-bindings/bleio/ScanEntry.h index 2b44ba3f4b..c1b52e6b4e 100644 --- a/shared-bindings/bleio/ScanEntry.h +++ b/shared-bindings/bleio/ScanEntry.h @@ -29,7 +29,12 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H #include "py/obj.h" +#include "shared-module/bleio/ScanEntry.h" extern const mp_obj_type_t bleio_scanentry_type; +mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self); +mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self); +mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index a249d53438..92f6a2a18b 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -61,6 +61,8 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, bleio_scanner_obj_t *self = m_new_obj(bleio_scanner_obj_t); self->base.type = type; + common_hal_bleio_scanner_construct(self); + return MP_OBJ_FROM_PTR(self); } @@ -108,11 +110,9 @@ STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_m mp_raise_ValueError(translate("window must be <= interval")); } - self->adv_reports = mp_obj_new_list(0, NULL); - common_hal_bleio_scanner_scan(self, timeout, interval, window); - return self->adv_reports; + return common_hal_bleio_scanner_get_adv_reports(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan); diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index 54c09675ba..b9e3ecdee5 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -29,11 +29,13 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H #include "py/objtype.h" -#include "shared-module/bleio/Scanner.h" +#include "common-hal/bleio/Scanner.h" extern const mp_obj_type_t bleio_scanner_type; -void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); +extern void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self); +extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self); +extern mp_obj_t common_hal_bleio_scanner_get_adv_reports(bleio_scanner_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index d9bc4021f4..352ef8d6a8 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -67,18 +67,20 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, } bleio_service_obj_t *self = m_new_obj(bleio_service_obj_t); - self->char_list = mp_obj_new_list(0, NULL); self->base.type = &bleio_service_type; - self->device = mp_const_none; - self->handle = 0xFFFF; - self->is_secondary = args[ARG_secondary].u_bool; - self->uuid = MP_OBJ_TO_PTR(uuid); + + const bool is_secondary = args[ARG_secondary].u_bool; + bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid); // If characteristics is not an iterable, an exception will be thrown. mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(args[ARG_characteristics].u_obj, &iter_buf); mp_obj_t characteristic; + // Copy the characteristics list and validate its items. + mp_obj_t char_list = mp_obj_new_list(0, NULL); + mp_obj_list_t *char_list_obj = MP_OBJ_FROM_PTR(char_list); + while ((characteristic = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (!MP_OBJ_IS_TYPE(characteristic, &bleio_characteristic_type)) { mp_raise_ValueError(translate("characteristics includes an object that is not a Characteristic")); @@ -89,12 +91,10 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, // The descriptor base UUID doesn't match the characteristic base UUID. mp_raise_ValueError(translate("Characteristic UUID doesn't match Service UUID")); } - characteristic_ptr->service = self; - mp_obj_list_append(self->char_list, characteristic); + mp_obj_list_append(char_list, characteristic); } - // Do port-specific initialization. - common_hal_bleio_service_construct(self); + common_hal_bleio_service_construct(self, uuid_obj, char_list_obj, is_secondary); return MP_OBJ_FROM_PTR(self); } @@ -106,7 +106,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t bleio_service_get_characteristics(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); // Return list as a tuple so user won't be able to change it. - mp_obj_list_t *char_list = MP_OBJ_TO_PTR(self->char_list); + mp_obj_list_t *char_list = common_hal_bleio_service_get_characteristic_list(self); return mp_obj_new_tuple(char_list->len, char_list->items); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_characteristics_obj, bleio_service_get_characteristics); @@ -125,7 +125,7 @@ const mp_obj_property_t bleio_service_characteristics_obj = { STATIC mp_obj_t bleio_service_get_secondary(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->is_secondary); + return mp_obj_new_bool(common_hal_bleio_service_get_is_secondary(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_secondary_obj, bleio_service_get_secondary); @@ -143,7 +143,7 @@ const mp_obj_property_t bleio_service_secondary_obj = { STATIC mp_obj_t bleio_service_get_uuid(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(self->uuid); + return MP_OBJ_FROM_PTR(common_hal_bleio_service_get_uuid(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_uuid_obj, bleio_service_get_uuid); diff --git a/shared-bindings/bleio/Service.h b/shared-bindings/bleio/Service.h index 389db3b2e9..27d79f9539 100644 --- a/shared-bindings/bleio/Service.h +++ b/shared-bindings/bleio/Service.h @@ -28,11 +28,15 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H #include "shared-module/bleio/Characteristic.h" -#include "shared-module/bleio/Service.h" +#include "common-hal/bleio/Service.h" const mp_obj_type_t bleio_service_type; -extern void common_hal_bleio_service_construct(bleio_service_obj_t *self); +extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, mp_obj_list_t *char_list, bool is_secondary); +extern bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self); +extern mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self); +extern bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self); +extern void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t device); extern void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H diff --git a/shared-module/bleio/Address.c b/shared-module/bleio/Address.c new file mode 100644 index 0000000000..e26bbe2acb --- /dev/null +++ b/shared-module/bleio/Address.c @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/objproperty.h" +#include "shared-bindings/bleio/Address.h" +#include "shared-module/bleio/Address.h" + +void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type) { + memcpy(self->bytes, bytes, bytes_length); + self->type = address_type; +} + +mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self) { + return mp_obj_new_bytes(self->bytes, NUM_BLEIO_ADDRESS_BYTES); +} + +uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self) { + return self->type; +} diff --git a/shared-module/bleio/Address.h b/shared-module/bleio/Address.h index 65f493c16a..f66e97d640 100644 --- a/shared-module/bleio/Address.h +++ b/shared-module/bleio/Address.h @@ -27,6 +27,8 @@ #ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H #define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H +#include "py/obj.h" + #define NUM_BLEIO_ADDRESS_BYTES 6 typedef struct { diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h index 958837e64f..3132fd47b4 100644 --- a/shared-module/bleio/Characteristic.h +++ b/shared-module/bleio/Characteristic.h @@ -37,5 +37,6 @@ typedef struct { bool indicate : 1; } bleio_characteristic_properties_t; +// bleio_characteristic_obj_t is defined in ports/*/common-hal. #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H diff --git a/shared-module/bleio/ScanEntry.c b/shared-module/bleio/ScanEntry.c new file mode 100644 index 0000000000..44b50a4ce0 --- /dev/null +++ b/shared-module/bleio/ScanEntry.c @@ -0,0 +1,49 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "shared-bindings/bleio/Address.h" +#include "shared-module/bleio/Address.h" +#include "shared-module/bleio/ScanEntry.h" + +mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self) { + bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); + address->base.type = &bleio_address_type; + memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); + address->type = self->address.type; + return MP_OBJ_TO_PTR(address); +} + +mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self) { + return self->data; +} + +mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self) { + return self->rssi; +} diff --git a/shared-module/bleio/ScanEntry.h b/shared-module/bleio/ScanEntry.h index 6ae7334a80..40e02f9fa0 100644 --- a/shared-module/bleio/ScanEntry.h +++ b/shared-module/bleio/ScanEntry.h @@ -27,7 +27,8 @@ #ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H #define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_SCANENTRY_H -#include "shared-module/bleio/Address.h" +#include "py/obj.h" +#include "shared-bindings/bleio/Address.h" typedef struct { mp_obj_base_t base; From a1b5d800f30418a08a39e73ba4b3e276ca6c7241 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 19 Jun 2019 10:42:36 -0400 Subject: [PATCH 12/61] Update copyrights; get ready for Central --- locale/ID.po | 69 +- locale/circuitpython.pot | 65 +- locale/de_DE.po | 82 ++- locale/en_US.po | 65 +- locale/en_x_pirate.po | 65 +- locale/es.po | 82 ++- locale/fil.po | 69 +- locale/fr.po | 82 ++- locale/it_IT.po | 69 +- locale/pl.po | 82 ++- locale/pt_BR.po | 69 +- locale/zh_Latn_pinyin.po | 82 ++- ports/nrf/Makefile | 1 - ports/nrf/bluetooth/ble_drv.c | 3 +- ports/nrf/bluetooth/ble_drv.h | 3 +- ports/nrf/bluetooth/ble_uart.c | 3 +- ports/nrf/common-hal/analogio/AnalogIn.c | 2 +- ports/nrf/common-hal/bleio/Adapter.c | 1 + ports/nrf/common-hal/bleio/Adapter.h | 3 +- ports/nrf/common-hal/bleio/Broadcaster.h | 47 -- ports/nrf/common-hal/bleio/Characteristic.c | 2 +- ports/nrf/common-hal/bleio/Characteristic.h | 3 +- .../common-hal/bleio/CharacteristicBuffer.h | 2 +- ports/nrf/common-hal/bleio/Descriptor.c | 3 +- ports/nrf/common-hal/bleio/Descriptor.h | 3 +- ports/nrf/common-hal/bleio/Device.c | 601 ------------------ ports/nrf/common-hal/bleio/Peripheral.c | 2 +- ports/nrf/common-hal/bleio/Peripheral.h | 2 +- ports/nrf/common-hal/bleio/Scanner.c | 3 +- ports/nrf/common-hal/bleio/Service.c | 1 + ports/nrf/common-hal/bleio/Service.h | 1 + ports/nrf/common-hal/bleio/UUID.c | 3 +- ports/nrf/common-hal/bleio/UUID.h | 3 +- ports/nrf/common-hal/bleio/__init__.c | 3 +- ports/nrf/common-hal/busio/I2C.c | 5 +- ports/nrf/common-hal/busio/SPI.c | 8 +- ports/nrf/mphalport.c | 3 +- shared-bindings/bleio/Adapter.c | 1 + shared-bindings/bleio/Adapter.h | 1 + shared-bindings/bleio/Address.h | 1 + shared-bindings/bleio/AdvertisementData.h | 1 + shared-bindings/bleio/Characteristic.c | 3 +- shared-bindings/bleio/Characteristic.h | 2 + shared-bindings/bleio/CharacteristicBuffer.h | 2 +- shared-bindings/bleio/Descriptor.c | 3 +- shared-bindings/bleio/Descriptor.h | 1 + shared-bindings/bleio/Device.c | 362 ----------- shared-bindings/bleio/Device.h | 1 + shared-bindings/bleio/Peripheral.c | 3 +- shared-bindings/bleio/Peripheral.h | 2 +- shared-bindings/bleio/ScanEntry.h | 1 + shared-bindings/bleio/Service.c | 3 +- shared-bindings/bleio/Service.h | 4 +- shared-bindings/bleio/UUID.c | 4 +- shared-bindings/bleio/UUID.h | 1 + shared-bindings/bleio/__init__.c | 7 +- shared-bindings/bleio/__init__.h | 3 +- shared-module/bleio/Address.h | 1 + shared-module/bleio/AdvertisementData.h | 1 + shared-module/bleio/Characteristic.h | 42 -- shared-module/bleio/Device.h | 45 -- shared-module/bleio/ScanEntry.h | 1 + 62 files changed, 602 insertions(+), 1486 deletions(-) delete mode 100644 ports/nrf/common-hal/bleio/Broadcaster.h delete mode 100644 ports/nrf/common-hal/bleio/Device.c delete mode 100644 shared-bindings/bleio/Device.c delete mode 100644 shared-module/bleio/Characteristic.h delete mode 100644 shared-module/bleio/Device.h diff --git a/locale/ID.po b/locale/ID.po index c1760e6b49..7017631095 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -218,16 +218,15 @@ msgstr "" msgid "A hardware interrupt channel is already in use" msgstr "Sebuah channel hardware interrupt sedang digunakan" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "buffers harus mempunyai panjang yang sama" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Semua perangkat I2C sedang digunakan" @@ -354,19 +353,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -494,13 +493,12 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Tidak bisa menyesuaikan data ke dalam paket advertisment" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Tidak bisa menyesuaikan data ke dalam paket advertisment" @@ -551,7 +549,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX" @@ -566,7 +564,7 @@ msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX" msgid "Failed to add characteristic, err 0x%04x" msgstr "Gagal untuk menambahkan karakteristik, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Gagal untuk menambahkan layanan, status: 0x%08lX" @@ -591,12 +589,17 @@ msgstr "Gagal untuk megalokasikan buffer RX dari %d byte" msgid "Failed to change softdevice state" msgstr "Gagal untuk merubah status softdevice, error: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "Gagal untuk menyambungkan, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "Gagal untuk melanjutkan scanning, status: 0x%08lX" @@ -606,12 +609,12 @@ msgstr "Gagal untuk melanjutkan scanning, status: 0x%08lX" msgid "Failed to continue scanning, err 0x%04x" msgstr "Gagal untuk melanjutkan scanning, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Gagal untuk membuat mutex, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Gagal untuk menemukan layanan, status: 0x%08lX" @@ -651,7 +654,7 @@ msgstr "Gagal untuk menulis nilai gatts, status: 0x%08lX" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Gagal untuk menambahkan Vendor Spesific UUID, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" @@ -661,18 +664,22 @@ msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" msgid "Failed to release mutex, err 0x%04x" msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Gagal untuk memulai advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Gagal untuk memulai advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" @@ -682,12 +689,11 @@ msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" msgid "Failed to start scanning, err 0x%04x" msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Gagal untuk memberhentikan advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1221,7 +1227,7 @@ msgid "USB Error" msgstr "" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1366,8 +1372,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "argumen num/types tidak cocok" @@ -1920,8 +1926,9 @@ msgstr "" msgid "integer required" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2616,6 +2623,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index d32502e181..bbf77887ae 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-12 00:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -219,12 +219,11 @@ msgstr "" #: shared-bindings/bleio/Address.c #, c-format -msgid "Address is not %d bytes long or is in wrong format" +msgid "Address must be %d bytes long" msgstr "" #: shared-bindings/bleio/Address.c -#, c-format -msgid "Address must be %d bytes long" +msgid "Address type out of range" msgstr "" #: ports/nrf/common-hal/busio/I2C.c @@ -349,19 +348,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -484,12 +483,11 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "" @@ -539,7 +537,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "" @@ -553,7 +551,7 @@ msgstr "" msgid "Failed to add characteristic, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "" @@ -576,11 +574,16 @@ msgstr "" msgid "Failed to change softdevice state" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "" @@ -589,11 +592,11 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "" @@ -630,7 +633,7 @@ msgstr "" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "" @@ -639,17 +642,21 @@ msgstr "" msgid "Failed to release mutex, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "" @@ -658,11 +665,10 @@ msgstr "" msgid "Failed to start scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1188,7 +1194,7 @@ msgid "USB Error" msgstr "" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1323,8 +1329,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "" @@ -1876,8 +1882,9 @@ msgstr "" msgid "integer required" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2569,6 +2576,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 2bdaaf7126..8b559edab7 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -219,16 +219,15 @@ msgstr "3-arg pow() wird nicht unterstützt" msgid "A hardware interrupt channel is already in use" msgstr "Ein Hardware Interrupt Kanal wird schon benutzt" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "Die Adresse ist nicht %d Bytes lang oder das Format ist falsch" - #: shared-bindings/bleio/Address.c #, c-format msgid "Address must be %d bytes long" msgstr "Die Adresse muss %d Bytes lang sein" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Alle I2C-Peripheriegeräte sind in Benutzung" @@ -353,19 +352,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Kann dotstar nicht mit %s verwenden" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Im Central mode können Dienste nicht hinzugefügt werden" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Im Central mode kann advertise nicht gemacht werden" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Im Central mode kann name nicht geändert werden" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Im Peripheral mode kann keine Verbindung hergestellt werden" @@ -488,12 +487,11 @@ msgstr "Data 0 pin muss am Byte ausgerichtet sein" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "Zu vielen Daten für das advertisement packet" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "Daten sind zu groß für das advertisement packet" @@ -543,7 +541,7 @@ msgstr "Habe ein Tupel der Länge %d erwartet aber %d erhalten" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "Akquirieren des Mutex gescheitert" @@ -557,7 +555,7 @@ msgstr "Mutex konnte nicht akquiriert werden. Status: 0x%04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Hinzufügen des Characteristic ist gescheitert. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "Dienst konnte nicht hinzugefügt werden" @@ -580,11 +578,16 @@ msgstr "Konnte keine RX Buffer mit %d allozieren" msgid "Failed to change softdevice state" msgstr "Fehler beim Ändern des Softdevice-Status" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "Verbindung fehlgeschlagen:" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "Der Scanvorgang kann nicht fortgesetzt werden" @@ -593,11 +596,11 @@ msgstr "Der Scanvorgang kann nicht fortgesetzt werden" msgid "Failed to continue scanning, err 0x%04x" msgstr "Der Scanvorgang kann nicht fortgesetzt werden. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "Erstellen des Mutex ist fehlgeschlagen" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "Es konnten keine Dienste gefunden werden" @@ -634,7 +637,7 @@ msgstr "gatts value konnte nicht gelesen werden. Status: 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Kann keine herstellerspezifische UUID hinzufügen. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "Loslassen des Mutex gescheitert" @@ -643,17 +646,21 @@ msgstr "Loslassen des Mutex gescheitert" msgid "Failed to release mutex, err 0x%04x" msgstr "Mutex konnte nicht freigegeben werden. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "Kann advertisement nicht starten" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Kann advertisement nicht starten. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "Der Scanvorgang kann nicht gestartet werden" @@ -662,11 +669,10 @@ msgstr "Der Scanvorgang kann nicht gestartet werden" msgid "Failed to start scanning, err 0x%04x" msgstr "Der Scanvorgang kann nicht gestartet werden. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "Kann advertisement nicht stoppen" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1217,8 +1223,8 @@ msgid "USB Error" msgstr "USB Fehler" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "UUID-Integer nicht im Bereich 0 bis 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1363,8 +1369,8 @@ msgstr "arg ist eine leere Sequenz" msgid "argument has wrong type" msgstr "Argument hat falschen Typ" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "Anzahl/Type der Argumente passen nicht" @@ -1917,9 +1923,10 @@ msgstr "int() arg 2 muss >= 2 und <= 36 sein" msgid "integer required" msgstr "integer erforderlich" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "Das Interval ist nicht im Bereich 0.0020 bis 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2625,6 +2632,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "write_args muss eine Liste, ein Tupel oder None sein" @@ -2656,6 +2667,9 @@ msgstr "" #~ msgid "AP required" #~ msgstr "AP erforderlich" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "Die Adresse ist nicht %d Bytes lang oder das Format ist falsch" + #~ msgid "C-level assert" #~ msgstr "C-Level Assert" @@ -2761,6 +2775,9 @@ msgstr "" #~ msgid "UART(1) can't read" #~ msgstr "UART(1) kann nicht lesen" +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "UUID-Integer nicht im Bereich 0 bis 0xffff" + #~ msgid "Unable to remount filesystem" #~ msgstr "Dateisystem konnte nicht wieder eingebunden werden." @@ -2792,6 +2809,9 @@ msgstr "" #~ msgid "impossible baudrate" #~ msgstr "Unmögliche Baudrate" +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "Das Interval ist nicht im Bereich 0.0020 bis 10.24" + #~ msgid "invalid alarm" #~ msgstr "ungültiger Alarm" diff --git a/locale/en_US.po b/locale/en_US.po index 152ece4327..616e89630a 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -219,12 +219,11 @@ msgstr "" #: shared-bindings/bleio/Address.c #, c-format -msgid "Address is not %d bytes long or is in wrong format" +msgid "Address must be %d bytes long" msgstr "" #: shared-bindings/bleio/Address.c -#, c-format -msgid "Address must be %d bytes long" +msgid "Address type out of range" msgstr "" #: ports/nrf/common-hal/busio/I2C.c @@ -349,19 +348,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -484,12 +483,11 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "" @@ -539,7 +537,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "" @@ -553,7 +551,7 @@ msgstr "" msgid "Failed to add characteristic, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "" @@ -576,11 +574,16 @@ msgstr "" msgid "Failed to change softdevice state" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "" @@ -589,11 +592,11 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "" @@ -630,7 +633,7 @@ msgstr "" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "" @@ -639,17 +642,21 @@ msgstr "" msgid "Failed to release mutex, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "" @@ -658,11 +665,10 @@ msgstr "" msgid "Failed to start scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1188,7 +1194,7 @@ msgid "USB Error" msgstr "" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1323,8 +1329,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "" @@ -1876,8 +1882,9 @@ msgstr "" msgid "integer required" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2569,6 +2576,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index d91dc95cad..44db050456 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -221,12 +221,11 @@ msgstr "Avast! A hardware interrupt channel be used already" #: shared-bindings/bleio/Address.c #, c-format -msgid "Address is not %d bytes long or is in wrong format" +msgid "Address must be %d bytes long" msgstr "" #: shared-bindings/bleio/Address.c -#, c-format -msgid "Address must be %d bytes long" +msgid "Address type out of range" msgstr "" #: ports/nrf/common-hal/busio/I2C.c @@ -353,19 +352,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -488,12 +487,11 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "" @@ -543,7 +541,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "" @@ -557,7 +555,7 @@ msgstr "" msgid "Failed to add characteristic, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "" @@ -580,11 +578,16 @@ msgstr "" msgid "Failed to change softdevice state" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "" @@ -593,11 +596,11 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "" @@ -634,7 +637,7 @@ msgstr "" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "" @@ -643,17 +646,21 @@ msgstr "" msgid "Failed to release mutex, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "" @@ -662,11 +669,10 @@ msgstr "" msgid "Failed to start scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1192,7 +1198,7 @@ msgid "USB Error" msgstr "" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1327,8 +1333,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "" @@ -1880,8 +1886,9 @@ msgstr "" msgid "integer required" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2573,6 +2580,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/es.po b/locale/es.po index d954d574c3..194dea86ba 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -223,16 +223,15 @@ msgstr "pow() con 3 argumentos no soportado" msgid "A hardware interrupt channel is already in use" msgstr "El canal EXTINT ya está siendo utilizado" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "Direción no es %d bytes largo o esta en el formato incorrecto" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "Direción debe ser %d bytes de largo" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Todos los periféricos I2C están siendo usados" @@ -363,19 +362,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "No se puede usar dotstar con %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "No se pueden agregar servicio en modo Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "No se puede anunciar en modo Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "No se puede cambiar el nombre en modo Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "No se puede conectar en modo Peripheral" @@ -500,13 +499,12 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "El Data Chunk debe seguir el fmt chunk" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Los datos no caben en el paquete de anuncio." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Los datos no caben en el paquete de anuncio." @@ -559,7 +557,7 @@ msgstr "Se esperaba un tuple de %d, se obtuvo %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "No se puede adquirir el mutex, status: 0x%08lX" @@ -574,7 +572,7 @@ msgstr "No se puede adquirir el mutex, status: 0x%08lX" msgid "Failed to add characteristic, err 0x%04x" msgstr "No se puede añadir caracteristica, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "No se puede detener el anuncio. status: 0x%02x" @@ -599,12 +597,17 @@ msgstr "Falló la asignación del buffer RX de %d bytes" msgid "Failed to change softdevice state" msgstr "No se puede cambiar el estado del softdevice, error: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "No se puede conectar. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "No se puede iniciar el escaneo. status: 0x%02x" @@ -614,12 +617,12 @@ msgstr "No se puede iniciar el escaneo. status: 0x%02x" msgid "Failed to continue scanning, err 0x%04x" msgstr "No se puede iniciar el escaneo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "No se puede leer el valor del atributo. status 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "No se puede descubrir servicios, status: 0x%08lX" @@ -659,7 +662,7 @@ msgstr "No se puede escribir el valor del atributo. status: 0x%02x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "No se puede agregar el Vendor Specific 128-bit UUID." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "No se puede liberar el mutex, status: 0x%08lX" @@ -669,18 +672,22 @@ msgstr "No se puede liberar el mutex, status: 0x%08lX" msgid "Failed to release mutex, err 0x%04x" msgstr "No se puede liberar el mutex, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "No se puede inicar el anuncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "No se puede inicar el anuncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "No se puede iniciar el escaneo. status: 0x%02x" @@ -690,12 +697,11 @@ msgstr "No se puede iniciar el escaneo. status: 0x%02x" msgid "Failed to start scanning, err 0x%04x" msgstr "No se puede iniciar el escaneo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "No se puede detener el anuncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1244,8 +1250,8 @@ msgid "USB Error" msgstr "Error USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "El valor integer UUID no está en el rango 0 a 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1389,8 +1395,8 @@ msgstr "argumento es una secuencia vacía" msgid "argument has wrong type" msgstr "el argumento tiene un tipo erroneo" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "argumento número/tipos no coinciden" @@ -1951,9 +1957,10 @@ msgstr "int() arg 2 debe ser >= 2 y <= 36" msgid "integer required" msgstr "Entero requerido" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "El intervalo está fuera del rango de 0.0020 a 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2658,6 +2665,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "value_count debe ser > 0" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "write_args debe ser lista, tuple, o None" @@ -2691,6 +2702,9 @@ msgstr "paso cero" #~ msgid "AP required" #~ msgstr "AP requerido" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "Direción no es %d bytes largo o esta en el formato incorrecto" + #~ msgid "Cannot connect to AP" #~ msgstr "No se puede conectar a AP" @@ -2803,6 +2817,9 @@ msgstr "paso cero" #~ msgid "UART(1) can't read" #~ msgstr "UART(1) no puede leer" +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "El valor integer UUID no está en el rango 0 a 0xffff" + #~ msgid "Unable to remount filesystem" #~ msgstr "Incapaz de montar de nuevo el sistema de archivos" @@ -2852,6 +2869,9 @@ msgstr "paso cero" #~ msgid "impossible baudrate" #~ msgstr "baudrate imposible" +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "El intervalo está fuera del rango de 0.0020 a 10.24" + #~ msgid "invalid alarm" #~ msgstr "alarma inválida" diff --git a/locale/fil.po b/locale/fil.po index b6ad3643c8..9c688ec14b 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -220,16 +220,15 @@ msgstr "3-arg pow() hindi suportado" msgid "A hardware interrupt channel is already in use" msgstr "Isang channel ng hardware interrupt ay ginagamit na" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "ang palette ay dapat 32 bytes ang haba" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Lahat ng I2C peripherals ginagamit" @@ -356,19 +355,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Hindi maarang maglagay ng service sa Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Hindi ma advertise habang nasa Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Hindi mapalitan ang pangalan sa Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Hindi maconnect sa Peripheral mode" @@ -494,13 +493,12 @@ msgstr "graphic ay dapat 2048 bytes ang haba" msgid "Data chunk must follow fmt chunk" msgstr "Dapat sunurin ng Data chunk ang fmt chunk" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Hindi makasya ang data sa loob ng advertisement packet" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Hindi makasya ang data sa loob ng advertisement packet" @@ -554,7 +552,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Nabigo sa pag kuha ng mutex, status: 0x%08lX" @@ -569,7 +567,7 @@ msgstr "Nabigo sa pag kuha ng mutex, status: 0x%08lX" msgid "Failed to add characteristic, err 0x%04x" msgstr "Nabigo sa paglagay ng characteristic, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Hindi matagumpay ang paglagay ng service, status: 0x%08lX" @@ -594,12 +592,17 @@ msgstr "Nabigong ilaan ang RX buffer ng %d bytes" msgid "Failed to change softdevice state" msgstr "Nabigo sa pagbago ng softdevice state, error: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "Hindi makaconnect, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "Hindi maituloy ang pag scan, status: 0x%0xlX" @@ -609,12 +612,12 @@ msgstr "Hindi maituloy ang pag scan, status: 0x%0xlX" msgid "Failed to continue scanning, err 0x%04x" msgstr "Hindi maituloy ang pag scan, status: 0x%0xlX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Hindi matagumpay ang pagbuo ng mutex, status: 0x%0xlX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Nabigo sa pagdiscover ng services, status: 0x%08lX" @@ -654,7 +657,7 @@ msgstr "Hindi maisulat ang gatts value, status: 0x%08lX" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Hindi matagumpay ang paglagay ng Vender Specific UUID, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" @@ -664,18 +667,22 @@ msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" msgid "Failed to release mutex, err 0x%04x" msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Hindi masimulaan ang advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Hindi masimulaan ang advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" @@ -685,12 +692,11 @@ msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" msgid "Failed to start scanning, err 0x%04x" msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Hindi mahinto ang advertisement, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1241,7 +1247,7 @@ msgid "USB Error" msgstr "May pagkakamali ang USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1386,8 +1392,8 @@ msgstr "arg ay walang laman na sequence" msgid "argument has wrong type" msgstr "may maling type ang argument" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "hindi tugma ang argument num/types" @@ -1952,8 +1958,9 @@ msgstr "int() arg 2 ay dapat >=2 at <= 36" msgid "integer required" msgstr "kailangan ng int" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2657,6 +2664,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/fr.po b/locale/fr.po index 6fd6e90157..60122a5d0b 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -221,16 +221,15 @@ msgstr "pow() non supporté avec 3 arguments" msgid "A hardware interrupt channel is already in use" msgstr "Un canal d'interruptions matérielles est déjà utilisé" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "L'adresse n'est pas longue de %d octets ou est d'un format erroné" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "L'adresse doit être longue de %d octets" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c #, fuzzy msgid "All I2C peripherals are in use" @@ -361,19 +360,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Impossible d'utiliser 'dotstar' avec %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Impossible d'ajouter des services en mode Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Impossible de publier en mode Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Modification du nom impossible en mode Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Impossible de se connecter en mode 'Peripheral'" @@ -500,12 +499,11 @@ msgstr "La broche 'Data 0' doit être aligné sur l'octet" msgid "Data chunk must follow fmt chunk" msgstr "Un bloc de données doit suivre un bloc de format" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "Données trop volumineuses pour un paquet de diffusion" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "Données trop volumineuses pour le paquet de diffusion" @@ -557,7 +555,7 @@ msgstr "Tuple de longueur %d attendu, obtenu %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Echec de l'obtention de mutex" @@ -572,7 +570,7 @@ msgstr "Echec de l'obtention de mutex, err 0x%04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Echec de l'ajout de caractéristique, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Echec de l'ajout de service" @@ -597,12 +595,17 @@ msgstr "Echec de l'allocation de %d octets du tampon RX" msgid "Failed to change softdevice state" msgstr "Echec de la modification de l'état du périphérique" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "Echec de connection:" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "Impossible de poursuivre le scan" @@ -612,12 +615,12 @@ msgstr "Impossible de poursuivre le scan" msgid "Failed to continue scanning, err 0x%04x" msgstr "Impossible de poursuivre le scan, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Echec de la création de mutex" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Echec de la découverte de services" @@ -658,7 +661,7 @@ msgstr "Impossible de lire la valeur de 'gatts', err 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Echec de l'ajout de l'UUID du fournisseur, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Impossible de libérer mutex" @@ -668,18 +671,22 @@ msgstr "Impossible de libérer mutex" msgid "Failed to release mutex, err 0x%04x" msgstr "Impossible de libérer mutex, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Echec du démarrage de la diffusion" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Impossible de commencer à diffuser, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Impossible de commencer à scanner" @@ -689,12 +696,11 @@ msgstr "Impossible de commencer à scanner" msgid "Failed to start scanning, err 0x%04x" msgstr "Impossible de commencer à scanner, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Echec de l'arrêt de diffusion" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1261,8 +1267,8 @@ msgid "USB Error" msgstr "Erreur USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "valeur de l'entier UUID est hors-bornes 0 à 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1410,8 +1416,8 @@ msgstr "l'argument est une séquence vide" msgid "argument has wrong type" msgstr "l'argument est d'un mauvais type" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "argument num/types ne correspond pas" @@ -1984,9 +1990,10 @@ msgstr "l'argument 2 de int() doit être >=2 et <=36" msgid "integer required" msgstr "entier requis" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "intervalle hors bornes 0.0020 à 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2699,6 +2706,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "'value_count' doit être > 0" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "'write_args' doit être une liste, un tuple ou 'None'" @@ -2733,6 +2744,9 @@ msgstr "'step' nul" #~ msgid "AP required" #~ msgstr "'AP' requis" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "L'adresse n'est pas longue de %d octets ou est d'un format erroné" + #~ msgid "Cannot connect to AP" #~ msgstr "Impossible de se connecter à 'AP'" @@ -2835,6 +2849,9 @@ msgstr "'step' nul" #~ msgid "UART(1) can't read" #~ msgstr "UART(1) ne peut pas lire" +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "valeur de l'entier UUID est hors-bornes 0 à 0xffff" + #~ msgid "Unable to remount filesystem" #~ msgstr "Impossible de remonter le système de fichiers" @@ -2881,6 +2898,9 @@ msgstr "'step' nul" #~ msgid "impossible baudrate" #~ msgstr "débit impossible" +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "intervalle hors bornes 0.0020 à 10.24" + #~ msgid "invalid alarm" #~ msgstr "alarme invalide" diff --git a/locale/it_IT.po b/locale/it_IT.po index d89d4ae07b..6f0e90e176 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -219,16 +219,15 @@ msgstr "pow() con tre argmomenti non supportata" msgid "A hardware interrupt channel is already in use" msgstr "Un canale di interrupt hardware è già in uso" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "la palette deve essere lunga 32 byte" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Tutte le periferiche I2C sono in uso" @@ -356,19 +355,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "dotstar non può essere usato con %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "non si può aggiungere servizi in Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "non si può pubblicizzare in Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "non si può cambiare il nome in Central mode" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "non si può connettere in Periferal mode" @@ -495,13 +494,12 @@ msgstr "graphic deve essere lunga 2048 byte" msgid "Data chunk must follow fmt chunk" msgstr "" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Impossibile inserire dati nel pacchetto di advertisement." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Impossibile inserire dati nel pacchetto di advertisement." @@ -554,7 +552,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Impossibile allocare buffer RX" @@ -569,7 +567,7 @@ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Impossibile fermare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Impossibile fermare advertisement. status: 0x%02x" @@ -594,12 +592,17 @@ msgstr "Fallita allocazione del buffer RX di %d byte" msgid "Failed to change softdevice state" msgstr "Impossibile fermare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to connect:" msgstr "Impossibile connettersi. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to continue scanning" msgstr "Impossible iniziare la scansione. status: 0x%02x" @@ -609,12 +612,12 @@ msgstr "Impossible iniziare la scansione. status: 0x%02x" msgid "Failed to continue scanning, err 0x%04x" msgstr "Impossible iniziare la scansione. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Impossibile fermare advertisement. status: 0x%02x" @@ -653,7 +656,7 @@ msgstr "Impossibile scrivere valore dell'attributo. status: 0x%02x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Non è possibile aggiungere l'UUID del vendor specifico da 128-bit" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" @@ -663,18 +666,22 @@ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" msgid "Failed to release mutex, err 0x%04x" msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Impossibile avviare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Impossibile avviare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Impossible iniziare la scansione. status: 0x%02x" @@ -684,12 +691,11 @@ msgstr "Impossible iniziare la scansione. status: 0x%02x" msgid "Failed to start scanning, err 0x%04x" msgstr "Impossible iniziare la scansione. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Impossibile fermare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1240,7 +1246,7 @@ msgid "USB Error" msgstr "Errore USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1380,8 +1386,8 @@ msgstr "l'argomento è una sequenza vuota" msgid "argument has wrong type" msgstr "il tipo dell'argomento è errato" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "discrepanza di numero/tipo di argomenti" @@ -1944,8 +1950,9 @@ msgstr "il secondo argomanto di int() deve essere >= 2 e <= 36" msgid "integer required" msgstr "intero richiesto" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2655,6 +2662,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/pl.po b/locale/pl.po index e7dc248be9..a7155e0c8d 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -218,16 +218,15 @@ msgstr "3-argumentowy pow() jest niewspierany" msgid "A hardware interrupt channel is already in use" msgstr "Kanał przerwań sprzętowych w użyciu" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "Adres nie ma długości %d bajtów lub zły format" - #: shared-bindings/bleio/Address.c #, c-format msgid "Address must be %d bytes long" msgstr "Adres musi mieć %d bajtów" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Wszystkie peryferia I2C w użyciu" @@ -352,19 +351,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Nie można używać dotstar z %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Nie można dodać serwisów w trybie Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Nie można rozgłaszać w trybie Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Nie można zmienić nazwy w trybie Central" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Nie można się łączyć w trybie Peripheral" @@ -487,12 +486,11 @@ msgstr "Nóżka data 0 musi być wyrównana do bajtu" msgid "Data chunk must follow fmt chunk" msgstr "Fragment danych musi następować po fragmencie fmt" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "Zbyt dużo danych pakietu rozgłoszeniowego" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "Zbyt dużo danych pakietu rozgłoszeniowego" @@ -542,7 +540,7 @@ msgstr "Oczekiwano krotkę długości %d, otrzymano %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "Nie udało się uzyskać blokady" @@ -556,7 +554,7 @@ msgstr "Nie udało się uzyskać blokady, błąd 0x$04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Nie udało się dodać charakterystyki, błąd 0x$04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "Nie udało się dodać serwisu" @@ -579,11 +577,16 @@ msgstr "Nie udała się alokacja %d bajtów na bufor RX" msgid "Failed to change softdevice state" msgstr "Nie udało się zmienić stanu softdevice" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "Nie udało się połączenie:" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "Nie udała się kontynuacja skanowania" @@ -592,11 +595,11 @@ msgstr "Nie udała się kontynuacja skanowania" msgid "Failed to continue scanning, err 0x%04x" msgstr "Nie udała się kontynuacja skanowania, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "Nie udało się stworzyć blokady" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "Nie udało się odkryć serwisów" @@ -633,7 +636,7 @@ msgstr "Nie udało się odczytać gatts, błąd 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Nie udało się zarejestrować UUID dostawcy, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "Nie udało się zwolnić blokady" @@ -642,17 +645,21 @@ msgstr "Nie udało się zwolnić blokady" msgid "Failed to release mutex, err 0x%04x" msgstr "Nie udało się zwolnić blokady, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "Nie udało się rozpocząć rozgłaszania" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Nie udało się rozpocząć rozgłaszania, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "Nie udało się rozpocząć skanowania" @@ -661,11 +668,10 @@ msgstr "Nie udało się rozpocząć skanowania" msgid "Failed to start scanning, err 0x%04x" msgstr "Nie udało się rozpocząć skanowania, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "Nie udało się zatrzymać rozgłaszania" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1208,8 +1214,8 @@ msgid "USB Error" msgstr "Błąd USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "Wartość UUID poza zakresem 0 do 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1347,8 +1353,8 @@ msgstr "arg jest puste" msgid "argument has wrong type" msgstr "argument ma zły typ" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "zła liczba lub typ argumentów" @@ -1901,9 +1907,10 @@ msgstr "argument 2 do int() busi być pomiędzy 2 a 36" msgid "integer required" msgstr "wymagana liczba całkowita" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "przedział poza zakresem 0.0020 do 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2596,6 +2603,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "value_count musi być > 0" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "write_args musi być listą, krotką lub None" @@ -2624,6 +2635,9 @@ msgstr "y poza zakresem" msgid "zero step" msgstr "zerowy krok" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "Adres nie ma długości %d bajtów lub zły format" + #~ msgid "Invalid bit clock pin" #~ msgstr "Zła nóżka zegara" @@ -2635,3 +2649,9 @@ msgstr "zerowy krok" #~ msgid "Must be a Group subclass." #~ msgstr "Musi dziedziczyć z Group." + +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "Wartość UUID poza zakresem 0 do 0xffff" + +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "przedział poza zakresem 0.0020 do 10.24" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index f086191870..01eda181f5 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -219,16 +219,15 @@ msgstr "" msgid "A hardware interrupt channel is already in use" msgstr "Um canal de interrupção de hardware já está em uso" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "" - #: shared-bindings/bleio/Address.c #, fuzzy, c-format msgid "Address must be %d bytes long" msgstr "buffers devem ser o mesmo tamanho" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Todos os periféricos I2C estão em uso" @@ -353,19 +352,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "" @@ -490,13 +489,12 @@ msgstr "" msgid "Data chunk must follow fmt chunk" msgstr "Pedaço de dados deve seguir o pedaço de cortes" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy msgid "Data too large for advertisement packet" msgstr "Não é possível ajustar dados no pacote de anúncios." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Data too large for the advertisement packet" msgstr "Não é possível ajustar dados no pacote de anúncios." @@ -549,7 +547,7 @@ msgstr "" msgid "Failed sending command." msgstr "Falha ao enviar comando." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to acquire mutex" msgstr "Falha ao alocar buffer RX" @@ -564,7 +562,7 @@ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Não pode parar propaganda. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to add service" msgstr "Não pode parar propaganda. status: 0x%02x" @@ -589,11 +587,16 @@ msgstr "Falha ao alocar buffer RX de %d bytes" msgid "Failed to change softdevice state" msgstr "Não pode parar propaganda. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "" @@ -602,12 +605,12 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to create mutex" msgstr "Não é possível ler o valor do atributo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" msgstr "Não pode parar propaganda. status: 0x%02x" @@ -646,7 +649,7 @@ msgstr "Não é possível gravar o valor do atributo. status: 0x%02x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Não é possível adicionar o UUID de 128 bits específico do fornecedor." -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to release mutex" msgstr "Não é possível ler o valor do atributo. status: 0x%02x" @@ -656,18 +659,22 @@ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" msgid "Failed to release mutex, err 0x%04x" msgstr "Não é possível ler o valor do atributo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start advertising" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to start scanning" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" @@ -677,12 +684,11 @@ msgstr "Não é possível iniciar o anúncio. status: 0x%02x" msgid "Failed to start scanning, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to stop advertising" msgstr "Não pode parar propaganda. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1216,7 +1222,7 @@ msgid "USB Error" msgstr "Erro na USB" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" +msgid "UUID integer value must be 0-0xffff" msgstr "" #: shared-bindings/bleio/UUID.c @@ -1352,8 +1358,8 @@ msgstr "" msgid "argument has wrong type" msgstr "argumento tem tipo errado" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "" @@ -1909,8 +1915,9 @@ msgstr "" msgid "integer required" msgstr "inteiro requerido" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" msgstr "" #: extmod/machine_i2c.c @@ -2606,6 +2613,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index dd61f13628..79d803d674 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-11 14:59-0700\n" +"POT-Creation-Date: 2019-06-19 09:49-0400\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -219,16 +219,15 @@ msgstr "bù zhīchí 3-arg pow ()" msgid "A hardware interrupt channel is already in use" msgstr "Yìngjiàn zhōngduàn tōngdào yǐ zài shǐyòng zhōng" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "Dìzhǐ bùshì %d zì jié zhǎng, huòzhě géshì cuòwù" - #: shared-bindings/bleio/Address.c #, c-format msgid "Address must be %d bytes long" msgstr "Dìzhǐ bìxū shì %d zì jié zhǎng" +#: shared-bindings/bleio/Address.c +msgid "Address type out of range" +msgstr "" + #: ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Suǒyǒu I2C wàiwéi qì zhèngzài shǐyòng" @@ -353,19 +352,19 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Wúfǎ yǔ dotstar yīqǐ shǐyòng %s" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't add services in Central mode" msgstr "Wúfǎ zài zhōngyāng móshì xià tiānjiā fúwù" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't advertise in Central mode" msgstr "Wúfǎ zài zhōngyāng móshì zhōng guǎnggào" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't change the name in Central mode" msgstr "Wúfǎ gēnggǎi zhōngyāng móshì de míngchēng" -#: shared-bindings/bleio/Device.c +#: shared-bindings/bleio/Central.c msgid "Can't connect in Peripheral mode" msgstr "Wúfǎ zài biānyuán móshì zhōng liánjiē" @@ -488,12 +487,11 @@ msgstr "Shùjù 0 de yǐn jiǎo bìxū shì zì jié duìqí" msgid "Data chunk must follow fmt chunk" msgstr "Shùjù kuài bìxū zūnxún fmt qū kuài" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c msgid "Data too large for advertisement packet" msgstr "Guǎnggào bāo de shùjù tài dà" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Data too large for the advertisement packet" msgstr "Guǎnggào bāo de shùjù tài dà" @@ -543,7 +541,7 @@ msgstr "Qīwàng de chángdù wèi %d de yuán zǔ, dédào %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to acquire mutex" msgstr "Wúfǎ huòdé mutex" @@ -557,7 +555,7 @@ msgstr "Wúfǎ huòdé mutex, err 0x%04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Tiānjiā tèxìng shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to add service" msgstr "Tiānjiā fúwù shībài" @@ -580,11 +578,16 @@ msgstr "Fēnpèi RX huǎnchōng qū%d zì jié shībài" msgid "Failed to change softdevice state" msgstr "Gēnggǎi ruǎn shèbèi zhuàngtài shībài" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to configure advertising, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to connect:" msgstr "Liánjiē shībài:" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to continue scanning" msgstr "Jìxù sǎomiáo shībài" @@ -593,11 +596,11 @@ msgstr "Jìxù sǎomiáo shībài" msgid "Failed to continue scanning, err 0x%04x" msgstr "Jìxù sǎomiáo shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to create mutex" msgstr "Wúfǎ chuàngjiàn hù chì suǒ" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "Fāxiàn fúwù shībài" @@ -634,7 +637,7 @@ msgstr "Wúfǎ dòu qǔ gatts zhí, err 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Wúfǎ zhùcè màizhǔ tèdìng de UUID, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to release mutex" msgstr "Wúfǎ shìfàng mutex" @@ -643,17 +646,21 @@ msgstr "Wúfǎ shìfàng mutex" msgid "Failed to release mutex, err 0x%04x" msgstr "Wúfǎ shìfàng mutex, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Peripheral.c +#, c-format +msgid "Failed to set device name, err 0x%04x" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start advertising" msgstr "Qǐdòng guǎnggào shībài" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Qǐdòng guǎnggào shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to start scanning" msgstr "Qǐdòng sǎomiáo shībài" @@ -662,11 +669,10 @@ msgstr "Qǐdòng sǎomiáo shībài" msgid "Failed to start scanning, err 0x%04x" msgstr "Qǐdòng sǎomiáo shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Device.c +#: ports/nrf/common-hal/bleio/Central.c msgid "Failed to stop advertising" msgstr "Wúfǎ tíngzhǐ guǎnggào" -#: ports/nrf/common-hal/bleio/Broadcaster.c #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" @@ -1213,8 +1219,8 @@ msgid "USB Error" msgstr "USB Cuòwù" #: shared-bindings/bleio/UUID.c -msgid "UUID integer value not in range 0 to 0xffff" -msgstr "UUID zhěngshù zhí bùzài fànwéi 0 zhì 0xffff" +msgid "UUID integer value must be 0-0xffff" +msgstr "" #: shared-bindings/bleio/UUID.c msgid "UUID string not 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'" @@ -1355,8 +1361,8 @@ msgstr "cānshù shì yīgè kōng de xùliè" msgid "argument has wrong type" msgstr "cānshù lèixíng cuòwù" -#: py/argcheck.c shared-bindings/_stage/__init__.c -#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c +#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c msgid "argument num/types mismatch" msgstr "cānshù biānhào/lèixíng bù pǐpèi" @@ -1911,9 +1917,10 @@ msgstr "zhěngshù() cānshù 2 bìxū > = 2 qiě <= 36" msgid "integer required" msgstr "xūyào zhěngshù" -#: ports/nrf/common-hal/bleio/Broadcaster.c -msgid "interval not in range 0.0020 to 10.24" -msgstr "jùlí 0.0020 Zhì 10.24 Zhī jiān de jiàngé shíjiān" +#: shared-bindings/bleio/Peripheral.c shared-bindings/bleio/Scanner.c +#, c-format +msgid "interval must be in range %s-%s" +msgstr "" #: extmod/machine_i2c.c msgid "invalid I2C peripheral" @@ -2608,6 +2615,10 @@ msgstr "" msgid "value_count must be > 0" msgstr "zhí jìshù bìxū wèi > 0" +#: shared-bindings/bleio/Scanner.c +msgid "window must be <= interval" +msgstr "" + #: shared-bindings/_pixelbuf/PixelBuf.c msgid "write_args must be a list, tuple, or None" msgstr "xiě cānshù bìxū shì yuán zǔ, lièbiǎo huò None" @@ -2636,6 +2647,9 @@ msgstr "y zhí chāochū biānjiè" msgid "zero step" msgstr "líng bù" +#~ msgid "Address is not %d bytes long or is in wrong format" +#~ msgstr "Dìzhǐ bùshì %d zì jié zhǎng, huòzhě géshì cuòwù" + #~ msgid "Invalid bit clock pin" #~ msgstr "Wúxiào de wèi shízhōng yǐn jiǎo" @@ -2660,9 +2674,15 @@ msgstr "líng bù" #~ msgid "Only bit maps of 8 bit color or less are supported" #~ msgstr "Jǐn zhīchí 8 wèi yánsè huò xiǎoyú" +#~ msgid "UUID integer value not in range 0 to 0xffff" +#~ msgstr "UUID zhěngshù zhí bùzài fànwéi 0 zhì 0xffff" + #~ msgid "expected a DigitalInOut" #~ msgstr "qídài de DigitalInOut" +#~ msgid "interval not in range 0.0020 to 10.24" +#~ msgstr "jùlí 0.0020 Zhì 10.24 Zhī jiān de jiàngé shíjiān" + #~ msgid "row must be packed and word aligned" #~ msgstr "xíng bìxū dǎbāo bìngqiě zì duìqí" diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index b7ff2fcbaa..18990485b4 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -159,7 +159,6 @@ SRC_C += \ boards/$(BOARD)/pins.c \ device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \ bluetooth/ble_drv.c \ - bluetooth/ble_uart.c \ lib/libc/string0.c \ lib/mp-readline/readline.c \ lib/oofatfs/ff.c \ diff --git a/ports/nrf/bluetooth/ble_drv.c b/ports/nrf/bluetooth/ble_drv.c index f6e575a8c2..6b17e7af29 100644 --- a/ports/nrf/bluetooth/ble_drv.c +++ b/ports/nrf/bluetooth/ble_drv.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/bluetooth/ble_drv.h b/ports/nrf/bluetooth/ble_drv.h index 133d77b48d..d349fa4e07 100644 --- a/ports/nrf/bluetooth/ble_drv.h +++ b/ports/nrf/bluetooth/ble_drv.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/bluetooth/ble_uart.c b/ports/nrf/bluetooth/ble_uart.c index 7faaafb0ef..91d10cff15 100644 --- a/ports/nrf/bluetooth/ble_uart.c +++ b/ports/nrf/bluetooth/ble_uart.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/analogio/AnalogIn.c b/ports/nrf/common-hal/analogio/AnalogIn.c index 1e572f7cb9..f20802ac98 100644 --- a/ports/nrf/common-hal/analogio/AnalogIn.c +++ b/ports/nrf/common-hal/analogio/AnalogIn.c @@ -3,8 +3,8 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries - * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Adapter.c b/ports/nrf/common-hal/bleio/Adapter.c index 120fcf0559..9d0912930b 100644 --- a/ports/nrf/common-hal/bleio/Adapter.c +++ b/ports/nrf/common-hal/bleio/Adapter.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2016 Glenn Ruben Bakke * Copyright (c) 2018 Artur Pacholec * diff --git a/ports/nrf/common-hal/bleio/Adapter.h b/ports/nrf/common-hal/bleio/Adapter.h index 0497f9ac9c..5dcc625406 100644 --- a/ports/nrf/common-hal/bleio/Adapter.h +++ b/ports/nrf/common-hal/bleio/Adapter.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Broadcaster.h b/ports/nrf/common-hal/bleio/Broadcaster.h deleted file mode 100644 index 2d1ae69a12..0000000000 --- a/ports/nrf/common-hal/bleio/Broadcaster.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * Copyright (c) 2018 Dan Halbert for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H -#define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H - -#include "ble.h" - -#include "shared-module/bleio/__init__.h" -#include "shared-module/bleio/Address.h" - -typedef struct { - mp_obj_base_t base; - // In seconds. - mp_float_t interval; - // The advertising data buffer is held by us, not by the SD, so we must - // maintain it and not change it. If we need to change its contents during advertising, - // there are tricks to get the SD to notice (see DevZone - TBS). - uint8_t adv_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; - -} bleio_broadcaster_obj_t; - -#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_BROADCASTER_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 45fb1d092a..346cfefbc5 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -34,7 +35,6 @@ #include "py/runtime.h" #include "common-hal/bleio/__init__.h" #include "common-hal/bleio/Characteristic.h" -#include "shared-module/bleio/Characteristic.h" STATIC volatile bleio_characteristic_obj_t *m_read_characteristic; STATIC volatile uint8_t m_tx_in_progress; diff --git a/ports/nrf/common-hal/bleio/Characteristic.h b/ports/nrf/common-hal/bleio/Characteristic.h index 662485bad5..451bae4712 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.h +++ b/ports/nrf/common-hal/bleio/Characteristic.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -27,9 +28,9 @@ #ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H #define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_CHARACTERISTIC_H -#include "shared-module/bleio/Characteristic.h" #include "common-hal/bleio/Service.h" #include "common-hal/bleio/UUID.h" +#include "shared-module/bleio/Characteristic.h" typedef struct { mp_obj_base_t base; diff --git a/ports/nrf/common-hal/bleio/CharacteristicBuffer.h b/ports/nrf/common-hal/bleio/CharacteristicBuffer.h index 6a44229f7a..db8fd2fade 100644 --- a/ports/nrf/common-hal/bleio/CharacteristicBuffer.h +++ b/ports/nrf/common-hal/bleio/CharacteristicBuffer.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Descriptor.c b/ports/nrf/common-hal/bleio/Descriptor.c index 8282be8f2d..418cc07c17 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.c +++ b/ports/nrf/common-hal/bleio/Descriptor.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Descriptor.h b/ports/nrf/common-hal/bleio/Descriptor.h index ee0886c22f..47552f39d8 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.h +++ b/ports/nrf/common-hal/bleio/Descriptor.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Device.c b/ports/nrf/common-hal/bleio/Device.c deleted file mode 100644 index b1ac72e754..0000000000 --- a/ports/nrf/common-hal/bleio/Device.c +++ /dev/null @@ -1,601 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include - -#include "ble.h" -#include "ble_drv.h" -#include "ble_hci.h" -#include "nrf_soc.h" -#include "py/objstr.h" -#include "py/runtime.h" -#include "shared-bindings/bleio/Adapter.h" -#include "shared-bindings/bleio/Characteristic.h" -#include "shared-bindings/bleio/Device.h" -#include "shared-bindings/bleio/Service.h" -#include "shared-bindings/bleio/UUID.h" - -#define BLE_MIN_CONN_INTERVAL MSEC_TO_UNITS(15, UNIT_0_625_MS) -#define BLE_MAX_CONN_INTERVAL MSEC_TO_UNITS(300, UNIT_0_625_MS) -#define BLE_SLAVE_LATENCY 0 -#define BLE_CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) - -#define BLE_ADV_LENGTH_FIELD_SIZE 1 -#define BLE_ADV_AD_TYPE_FIELD_SIZE 1 -#define BLE_AD_TYPE_FLAGS_DATA_SIZE 1 - -#ifndef BLE_GAP_ADV_MAX_SIZE -#define BLE_GAP_ADV_MAX_SIZE 31 -#endif - -static bleio_service_obj_t *m_char_discovery_service; -static volatile bool m_discovery_successful; -static nrf_mutex_t *m_discovery_mutex; - -#if (BLUETOOTH_SD == 140) -static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET; - -static uint8_t m_scan_buffer_data[BLE_GAP_SCAN_BUFFER_MIN]; - -static ble_data_t m_scan_buffer = { - .p_data = m_scan_buffer_data, - .len = BLE_GAP_SCAN_BUFFER_MIN -}; -#endif - -STATIC uint32_t set_advertisement_data(bleio_device_obj_t *device, bool connectable, mp_buffer_info_t *raw_data) { - common_hal_bleio_adapter_set_enabled(true); - - uint8_t adv_data[BLE_GAP_ADV_MAX_SIZE]; - uint8_t byte_pos = 0; - uint32_t err_code; - -#define ADD_FIELD(field, len) \ - do { \ - if (byte_pos + (len) > BLE_GAP_ADV_MAX_SIZE) { \ - mp_raise_ValueError(translate("Data too large for the advertisement packet")); \ - } \ - adv_data[byte_pos] = (field); \ - byte_pos += (len); \ - } while (0) - - GET_STR_DATA_LEN(device->name, name_data, name_len); - if (name_len > 0) { - ble_gap_conn_sec_mode_t sec_mode; - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - - err_code = sd_ble_gap_device_name_set(&sec_mode, name_data, name_len); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - // TODO: Shorten if too long - - ADD_FIELD(BLE_ADV_AD_TYPE_FIELD_SIZE + name_len, BLE_ADV_LENGTH_FIELD_SIZE); - ADD_FIELD(BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, BLE_ADV_AD_TYPE_FIELD_SIZE); - - memcpy(&adv_data[byte_pos], name_data, name_len); - byte_pos += name_len; - } - - // set flags, default to disc mode - if (raw_data->len == 0) { - ADD_FIELD(BLE_ADV_AD_TYPE_FIELD_SIZE + BLE_AD_TYPE_FLAGS_DATA_SIZE, BLE_ADV_LENGTH_FIELD_SIZE); - ADD_FIELD(BLE_GAP_AD_TYPE_FLAGS, BLE_AD_TYPE_FLAGS_DATA_SIZE); - ADD_FIELD(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE, BLE_AD_TYPE_FLAGS_DATA_SIZE); - } else { - if (byte_pos + raw_data->len > BLE_GAP_ADV_MAX_SIZE) { - mp_raise_ValueError(translate("Data too large for the advertisement packet")); - } - - memcpy(&adv_data[byte_pos], raw_data->buf, raw_data->len); - byte_pos += raw_data->len; - } - - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(device->service_list); - if (service_list->len > 0) { - bool has_128bit_services = false; - bool has_16bit_services = false; - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - - if (service->is_secondary) { - continue; - } - - switch (common_hal_bleio_uuid_get_size(service->uuid)) { - case 16: - has_16bit_services = true; - break; - case 128: - has_128bit_services = true; - break; - } - } - - if (has_16bit_services) { - const uint8_t size_byte_pos = byte_pos; - uint8_t uuid_total_size = 0; - - // skip length byte for now, apply total length post calculation - byte_pos += BLE_ADV_LENGTH_FIELD_SIZE; - - ADD_FIELD(BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE, BLE_ADV_AD_TYPE_FIELD_SIZE); - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - uint8_t encoded_size = 0; - - if (common_hal_bleio_uuid_get_size(service->uuid) != 16 || service->is_secondary) { - continue; - } - - ble_uuid_t uuid; - bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); - - err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - uuid_total_size += encoded_size; - byte_pos += encoded_size; - } - - adv_data[size_byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + uuid_total_size); - } - - if (has_128bit_services) { - const uint8_t size_byte_pos = byte_pos; - uint8_t uuid_total_size = 0; - - // skip length byte for now, apply total length post calculation - byte_pos += BLE_ADV_LENGTH_FIELD_SIZE; - - ADD_FIELD(BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE, BLE_ADV_AD_TYPE_FIELD_SIZE); - - for (size_t i = 0; i < service_list->len; ++i) { - const bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[i]); - uint8_t encoded_size = 0; - - if (common_hal_bleio_uuid_get_size(service->uuid) != 16 || service->is_secondary) { - continue; - } - - ble_uuid_t uuid; - bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); - - err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - uuid_total_size += encoded_size; - byte_pos += encoded_size; - } - - adv_data[size_byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + uuid_total_size); - } - } - -#if (BLUETOOTH_SD == 132) - err_code = sd_ble_gap_adv_data_set(adv_data, byte_pos, NULL, 0); - if (err_code != NRF_SUCCESS) { - return err_code; - } -#endif - - static ble_gap_adv_params_t m_adv_params = { - .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), -#if (BLUETOOTH_SD == 140) - .properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED, - .duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED, - .filter_policy = BLE_GAP_ADV_FP_ANY, - .primary_phy = BLE_GAP_PHY_1MBPS, -#else - .type = BLE_GAP_ADV_TYPE_ADV_IND, - .fp = BLE_GAP_ADV_FP_ANY, -#endif - }; - - if (!connectable) { -#if (BLUETOOTH_SD == 140) - m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED; -#else - m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND; -#endif - } - - common_hal_bleio_device_stop_advertising(device); - -#if (BLUETOOTH_SD == 140) - const ble_gap_adv_data_t ble_gap_adv_data = { - .adv_data.p_data = adv_data, - .adv_data.len = byte_pos, - }; - - err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &ble_gap_adv_data, &m_adv_params); - if (err_code != NRF_SUCCESS) { - return err_code; - } - - err_code = sd_ble_gap_adv_start(m_adv_handle, BLE_CONN_CFG_TAG_CUSTOM); -#elif (BLUETOOTH_SD == 132 && BLE_API_VERSION == 4) - err_code = sd_ble_gap_adv_start(&m_adv_params, BLE_CONN_CFG_TAG_CUSTOM); -#else - err_code = sd_ble_gap_adv_start(&m_adv_params); -#endif - - return err_code; -} - -STATIC bool discover_services(bleio_device_obj_t *device, uint16_t start_handle) { - m_discovery_successful = false; - - uint32_t err_code = sd_ble_gattc_primary_services_discover(device->conn_handle, start_handle, NULL); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to discover services")); - } - - // Serialize discovery. - err_code = sd_mutex_acquire(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to acquire mutex")); - } - - // Wait for someone else to release m_discovery_mutex. - while (sd_mutex_acquire(m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - err_code = sd_mutex_release(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } - - return m_discovery_successful; -} - -STATIC bool discover_characteristics(bleio_device_obj_t *device, bleio_service_obj_t *service, uint16_t start_handle) { - m_char_discovery_service = service; - - ble_gattc_handle_range_t handle_range; - handle_range.start_handle = start_handle; - handle_range.end_handle = service->end_handle; - - m_discovery_successful = false; - - uint32_t err_code = sd_ble_gattc_characteristics_discover(device->conn_handle, &handle_range); - if (err_code != NRF_SUCCESS) { - return false; - } - - err_code = sd_mutex_acquire(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to acquire mutex")); - } - - while (sd_mutex_acquire(m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - err_code = sd_mutex_release(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } - - return m_discovery_successful; -} - -STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *response, bleio_device_obj_t *device) { - for (size_t i = 0; i < response->count; ++i) { - ble_gattc_service_t *gattc_service = &response->services[i]; - - bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); - service->base.type = &bleio_service_type; - service->device = device; - service->characteristic_list = mp_obj_new_list(0, NULL); - service->start_handle = gattc_service->handle_range.start_handle; - service->end_handle = gattc_service->handle_range.end_handle; - service->handle = gattc_service->handle_range.start_handle; - - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); - bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid); - service->uuid = uuid; - - mp_obj_list_append(device->service_list, service); - } - - if (response->count > 0) { - m_discovery_successful = true; - } - - const uint32_t err_code = sd_mutex_release(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } -} - -STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio_device_obj_t *device) { - for (size_t i = 0; i < response->count; ++i) { - ble_gattc_char_t *gattc_char = &response->chars[i]; - - bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); - characteristic->base.type = &bleio_characteristic_type; - - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); - uuid->base.type = &bleio_uuid_type; - bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); - characteristic->uuid = uuid; - - characteristic->props.broadcast = gattc_char->char_props.broadcast; - characteristic->props.indicate = gattc_char->char_props.indicate; - characteristic->props.notify = gattc_char->char_props.notify; - characteristic->props.read = gattc_char->char_props.read; - characteristic->props.write = gattc_char->char_props.write; - characteristic->props.write_no_response = gattc_char->char_props.write_wo_resp; - characteristic->handle = gattc_char->handle_value; - characteristic->service = m_char_discovery_service; - - mp_obj_list_append(m_char_discovery_service->characteristic_list, MP_OBJ_FROM_PTR(characteristic)); - } - - if (response->count > 0) { - m_discovery_successful = true; - } - - const uint32_t err_code = sd_mutex_release(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } -} - -STATIC void on_adv_report(ble_gap_evt_adv_report_t *report, bleio_device_obj_t *device) { - uint32_t err_code; - - if (memcmp(report->peer_addr.addr, device->address.value, BLEIO_ADDRESS_BYTES) != 0) { -#if (BLUETOOTH_SD == 140) - err_code = sd_ble_gap_scan_start(NULL, &m_scan_buffer); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to continue scanning")); - } -#endif - return; - } - - ble_gap_scan_params_t scan_params = { - .active = 1, - .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), - .window = MSEC_TO_UNITS(100, UNIT_0_625_MS), - }; - - ble_gap_addr_t addr; - memset(&addr, 0, sizeof(addr)); - - addr.addr_type = report->peer_addr.addr_type; - memcpy(addr.addr, report->peer_addr.addr, BLEIO_ADDRESS_BYTES); - - ble_gap_conn_params_t conn_params = { - .min_conn_interval = BLE_MIN_CONN_INTERVAL, - .max_conn_interval = BLE_MAX_CONN_INTERVAL, - .conn_sup_timeout = BLE_CONN_SUP_TIMEOUT, - .slave_latency = BLE_SLAVE_LATENCY, - }; - -#if (BLE_API_VERSION == 2) - err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params); -#else - err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params, BLE_CONN_CFG_TAG_CUSTOM); -#endif - - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to connect:")); - } -} - -STATIC void on_ble_evt(ble_evt_t *ble_evt, void *device_in) { - bleio_device_obj_t *device = (bleio_device_obj_t*)device_in; - - switch (ble_evt->header.evt_id) { - case BLE_GAP_EVT_CONNECTED: - { - ble_gap_conn_params_t conn_params; - device->conn_handle = ble_evt->evt.gap_evt.conn_handle; - - sd_ble_gap_ppcp_get(&conn_params); - sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); - break; - } - - case BLE_GAP_EVT_DISCONNECTED: - device->conn_handle = BLE_CONN_HANDLE_INVALID; - break; - - case BLE_GAP_EVT_ADV_REPORT: - on_adv_report(&ble_evt->evt.gap_evt.params.adv_report, device); - break; - - case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: - on_primary_srv_discovery_rsp(&ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp, device); - break; - - case BLE_GATTC_EVT_CHAR_DISC_RSP: - on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, device); - break; - - case BLE_GATTS_EVT_SYS_ATTR_MISSING: - sd_ble_gatts_sys_attr_set(ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0); - break; - -#if (BLE_API_VERSION == 4) - case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: - sd_ble_gatts_exchange_mtu_reply(device->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); - break; -#endif - - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: - sd_ble_gap_sec_params_reply(device->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); - break; - - case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: - { - ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; - sd_ble_gap_conn_param_update(device->conn_handle, &request->conn_params); - break; - } - } -} - -void common_hal_bleio_device_add_service(bleio_device_obj_t *device, bleio_service_obj_t *service) { - ble_uuid_t uuid; - bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); - - uint8_t service_type = BLE_GATTS_SRVC_TYPE_PRIMARY; - if (service->is_secondary) { - service_type = BLE_GATTS_SRVC_TYPE_SECONDARY; - } - - common_hal_bleio_adapter_set_enabled(true); - - const uint32_t err_code = sd_ble_gatts_service_add(service_type, &uuid, &service->handle); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to add service")); - } - - const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); - for (size_t i = 0; i < characteristic_list->len; ++i) { - bleio_characteristic_obj_t *characteristic = characteristic_list->items[i]; - common_hal_bleio_service_add_characteristic(service, characteristic); - } -} - -void common_hal_bleio_device_start_advertising(bleio_device_obj_t *device, bool connectable, mp_buffer_info_t *raw_data) { - if (connectable) { - ble_drv_add_event_handler(on_ble_evt, device); - } - - const uint32_t err_code = set_advertisement_data(device, connectable, raw_data); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to start advertising")); - } -} - -void common_hal_bleio_device_stop_advertising(bleio_device_obj_t *device) { - uint32_t err_code; - -#if (BLUETOOTH_SD == 140) - if (m_adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET) - return; - - err_code = sd_ble_gap_adv_stop(m_adv_handle); -#else - err_code = sd_ble_gap_adv_stop(); -#endif - - if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE)) { - mp_raise_OSError_msg(translate("Failed to stop advertising")); - } -} - -void common_hal_bleio_device_connect(bleio_device_obj_t *device) { - ble_drv_add_event_handler(on_ble_evt, device); - - ble_gap_scan_params_t scan_params = { - .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), - .window = MSEC_TO_UNITS(100, UNIT_0_625_MS), -#if (BLUETOOTH_SD == 140) - .scan_phys = BLE_GAP_PHY_1MBPS, -#endif - }; - - common_hal_bleio_adapter_set_enabled(true); - - uint32_t err_code; -#if (BLUETOOTH_SD == 140) - err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); -#else - err_code = sd_ble_gap_scan_start(&scan_params); -#endif - - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to start scanning")); - } - - while (device->conn_handle == BLE_CONN_HANDLE_INVALID) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - // TODO: read name - - if (m_discovery_mutex == NULL) { - m_discovery_mutex = m_new_ll(nrf_mutex_t, 1); - - err_code = sd_mutex_new(m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to create mutex")); - } - } - - // find services - bool found_service = discover_services(device, BLE_GATT_HANDLE_START); - while (found_service) { - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(device->service_list); - const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; - - found_service = discover_services(device, service->end_handle + 1); - } - - // find characteristics in each service - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(device->service_list); - for (size_t i = 0; i < service_list->len; ++i) { - bleio_service_obj_t *service = service_list->items[i]; - - bool found_char = discover_characteristics(device, service, service->start_handle); - while (found_char) { - const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); - const bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_list->len - 1]; - - const uint16_t next_handle = characteristic->handle + 1; - if (next_handle >= service->end_handle) { - break; - } - - found_char = discover_characteristics(device, service, next_handle); - } - } -} - -void common_hal_bleio_device_disconnect(bleio_device_obj_t *device) { - sd_ble_gap_disconnect(device->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); -} diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 36c20373d3..69e75ff27d 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -3,8 +3,8 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Artur Pacholec * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index 9103fcf943..725bc14314 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -3,8 +3,8 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec - * Copyright (c) 2018 Dan Halbert for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index 64f7decad2..6715bd7a28 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c index 77d3f02599..55193c5cb0 100644 --- a/ports/nrf/common-hal/bleio/Service.c +++ b/ports/nrf/common-hal/bleio/Service.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/ports/nrf/common-hal/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h index 7998cc862a..b5acf39ae0 100644 --- a/ports/nrf/common-hal/bleio/Service.h +++ b/ports/nrf/common-hal/bleio/Service.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/ports/nrf/common-hal/bleio/UUID.c b/ports/nrf/common-hal/bleio/UUID.c index 23e643433f..ebd6b6d1fb 100644 --- a/ports/nrf/common-hal/bleio/UUID.c +++ b/ports/nrf/common-hal/bleio/UUID.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/UUID.h b/ports/nrf/common-hal/bleio/UUID.h index b464093ea1..7d3a6204ec 100644 --- a/ports/nrf/common-hal/bleio/UUID.h +++ b/ports/nrf/common-hal/bleio/UUID.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/bleio/__init__.c b/ports/nrf/common-hal/bleio/__init__.c index cfb701019d..58b81f066d 100644 --- a/ports/nrf/common-hal/bleio/__init__.c +++ b/ports/nrf/common-hal/bleio/__init__.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/busio/I2C.c b/ports/nrf/common-hal/busio/I2C.c index 05106d4905..538c87f2da 100644 --- a/ports/nrf/common-hal/busio/I2C.c +++ b/ports/nrf/common-hal/busio/I2C.c @@ -3,9 +3,10 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Sandeep Mistry All right reserved. - * Copyright (c) 2017 hathach + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 hathach + * Copyright (c) 2016 Sandeep Mistry All right reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index 8881bdc6b3..6ab6d9493b 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -1,9 +1,11 @@ /* * SPI Master library for nRF5x. - * Copyright (c) 2015 Arduino LLC - * Copyright (c) 2016 Sandeep Mistry All right reserved. - * Copyright (c) 2017 hathach + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 hathach + * Copyright (c) 2016 Sandeep Mistry All right reserved. + * Copyright (c) 2015 Arduino LLC * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/ports/nrf/mphalport.c b/ports/nrf/mphalport.c index ea864e7ceb..7d9463d0be 100644 --- a/ports/nrf/mphalport.c +++ b/ports/nrf/mphalport.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2015 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2015 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Adapter.c b/shared-bindings/bleio/Adapter.c index d9449d3ab0..7b8df51034 100644 --- a/shared-bindings/bleio/Adapter.c +++ b/shared-bindings/bleio/Adapter.c @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Adapter.h b/shared-bindings/bleio/Adapter.h index fe3886e59e..de9d1d6db1 100644 --- a/shared-bindings/bleio/Adapter.h +++ b/shared-bindings/bleio/Adapter.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2018 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Address.h b/shared-bindings/bleio/Address.h index 9652a9841a..bff1542cf0 100644 --- a/shared-bindings/bleio/Address.h +++ b/shared-bindings/bleio/Address.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/AdvertisementData.h b/shared-bindings/bleio/AdvertisementData.h index 05b5a2c8da..3313cde3b2 100644 --- a/shared-bindings/bleio/AdvertisementData.h +++ b/shared-bindings/bleio/AdvertisementData.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index e48cfd433b..859611f91a 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Characteristic.h b/shared-bindings/bleio/Characteristic.h index ffee6bdbc7..1938845a9a 100644 --- a/shared-bindings/bleio/Characteristic.h +++ b/shared-bindings/bleio/Characteristic.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -27,6 +28,7 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H +#include "shared-module/bleio/Characteristic.h" #include "common-hal/bleio/Characteristic.h" extern const mp_obj_type_t bleio_characteristic_type; diff --git a/shared-bindings/bleio/CharacteristicBuffer.h b/shared-bindings/bleio/CharacteristicBuffer.h index f25017c19e..b45835ff39 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.h +++ b/shared-bindings/bleio/CharacteristicBuffer.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c index b32f4f08ec..9e051c89e3 100644 --- a/shared-bindings/bleio/Descriptor.c +++ b/shared-bindings/bleio/Descriptor.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Descriptor.h b/shared-bindings/bleio/Descriptor.h index f47378ee16..f4634d3933 100644 --- a/shared-bindings/bleio/Descriptor.h +++ b/shared-bindings/bleio/Descriptor.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Device.c b/shared-bindings/bleio/Device.c deleted file mode 100644 index fcdc84d270..0000000000 --- a/shared-bindings/bleio/Device.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Glenn Ruben Bakke - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include - -#include "ble_drv.h" -#include "py/objarray.h" -#include "py/objproperty.h" -#include "py/objstr.h" -#include "py/runtime.h" -#include "shared-bindings/bleio/Adapter.h" -#include "shared-bindings/bleio/AddressType.h" -#include "shared-bindings/bleio/Characteristic.h" -#include "shared-bindings/bleio/Device.h" -#include "shared-bindings/bleio/Service.h" -#include "shared-bindings/bleio/UUID.h" -#include "shared-module/bleio/Device.h" -#include "shared-module/bleio/ScanEntry.h" - -// Work-in-progress: orphaned for now. -//| :orphan: -//| -//| .. currentmodule:: bleio -//| -//| :class:`Device` -- BLE device -//| ========================================================= -//| -//| **IGNORE ``Device`` and all its documentation. -//| It is being replaced by `Peripheral` and other classes.** -//| -//| Provides access a to BLE device, either in a Peripheral or Central role. -//| When a device is created without any parameter passed to the constructor, -//| it will be set to the Peripheral role. If a address is passed, the device -//| will be a Central. For a Peripheral you can set the `name`, add services -//| via `add_service` and then start and stop advertising via `bleio.Device.start_advertising` -//| and `bleio.Device.stop_advertising`. For the Central, you can `bleio.Device.connect` and `bleio.Device.disconnect` -//| to the device, once a connection is established, the device's services can -//| be accessed using `bleio.Device.services`. -//| -//| Usage:: -//| -//| import bleio -//| -//| # Peripheral -//| periph = bleio.Device() -//| -//| serv = bleio.Service(bleio.UUID(0x180f)) -//| p.add_service(serv) -//| -//| chara = bleio.Characteristic(bleio.UUID(0x2919)) -//| chara.read = True -//| chara.notify = True -//| serv.add_characteristic(chara) -//| -//| periph.start_advertising() -//| -//| # Central -//| scanner = bleio.Scanner() -//| entries = scanner.scan(2500) -//| -//| my_entry = None -//| for entry in entries: -//| if entry.name is not None and entry.name == 'MyDevice': -//| my_entry = entry -//| break -//| -//| central = bleio.Device(my_entry.address) -//| central.connect() -//| - -//| .. class:: Device(address=None, scan_entry=None) -//| -//| Create a new Device object. If the `address` or :py:data:`scan_entry` parameters are not `None`, -//| the role is set to Central, otherwise it's set to Peripheral. -//| -//| :param bleio.Address address: The address of the device to connect to -//| :param bleio.ScanEntry scan_entry: The scan entry returned from `bleio.Scanner` -//| - -//| .. attribute:: name -//| -//| For the Peripheral role, this property can be used to read and write the device's name. -//| For the Central role, this property will equal the name of the remote device, if one was -//| advertised by the device. In the Central role this property is read-only. -//| - -//| .. attribute:: services -//| -//| A `list` of `bleio.Service` that are offered by this device. (read-only) -//| For a Peripheral device, this list will contain services added using `add_service`, -//| for a Central, this list will be empty until a connection is established, at which point -//| it will be filled with the remote device's services. -//| - -//| .. method:: add_service(service) -//| -//| Appends the :py:data:`service` to the list of this devices's services. -//| This method can only be called for Peripheral devices. -//| -//| :param bleio.Service service: the service to append -//| - -//| .. method:: connect() -//| -//| Attempts a connection to the remote device. If the connection is successful, -//| the device's services are available via `services`. -//| This method can only be called for Central devices. -//| - -//| .. method:: disconnect() -//| -//| Disconnects from the remote device. -//| This method can only be called for Central devices. -//| - -//| .. method:: start_advertising(connectable=True) -//| -//| Starts advertising the device. The device's name and -//| services are put into the advertisement packets. -//| If :py:data:`connectable` is `True` then other devices are allowed to conncet to this device. -//| This method can only be called for Peripheral devices. -//| - -//| .. method:: stop_advertising() -//| -//| Disconnects from the remote device. -//| This method can only be called for Peripheral devices. -//| - -// TODO: Add unique MAC address part to name -static const char default_name[] = "CIRCUITPY"; - -STATIC void bleio_device_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - mp_printf(print, "Device(role: %s)", self->is_peripheral ? "Peripheral" : "Central"); -} - -STATIC mp_obj_t bleio_device_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { - mp_arg_check_num(n_args, n_kw, 0, 1, true); - bleio_device_obj_t *self = m_new_obj(bleio_device_obj_t); - self->base.type = &bleio_device_type; - self->service_list = mp_obj_new_list(0, NULL); - self->notif_handler = mp_const_none; - self->conn_handler = mp_const_none; - self->conn_handle = 0xFFFF; - self->is_peripheral = true; - - mp_map_t kw_args; - mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); - - enum { ARG_address, ARG_scan_entry }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_address, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_scan_entry, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - const mp_obj_t address_obj = args[ARG_address].u_obj; - const mp_obj_t scan_entry_obj = args[ARG_scan_entry].u_obj; - - if (address_obj != mp_const_none) { - bleio_address_obj_t *address = MP_OBJ_TO_PTR(address_obj); - - self->is_peripheral = false; - self->address.type = address->type; - memcpy(self->address.value, address->value, BLEIO_ADDRESS_BYTES); - } else if (scan_entry_obj != mp_const_none) { - bleio_scanentry_obj_t *scan_entry = MP_OBJ_TO_PTR(scan_entry_obj); - - self->is_peripheral = false; - self->address.type = scan_entry->address.type; - memcpy(self->address.value, scan_entry->address.value, BLEIO_ADDRESS_BYTES); - } else { - self->name = mp_obj_new_str(default_name, strlen(default_name)); - common_hal_bleio_adapter_get_address(&self->address); - } - - return MP_OBJ_FROM_PTR(self); -} - -STATIC mp_obj_t bleio_device_add_service(mp_obj_t self_in, mp_obj_t service_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_in); - - if (!self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't add services in Central mode"))); - } - - service->device = self; - - mp_obj_list_append(self->service_list, service); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_device_add_service_obj, bleio_device_add_service); - -STATIC mp_obj_t bleio_device_connect(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't connect in Peripheral mode"))); - } - - common_hal_bleio_device_connect(self); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_connect_obj, bleio_device_connect); - -STATIC mp_obj_t bleio_device_disconnect(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - common_hal_bleio_device_disconnect(self); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_disconnect_obj, bleio_device_disconnect); - -STATIC mp_obj_t bleio_device_get_name(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return self->name; -} -MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_get_name_obj, bleio_device_get_name); - -static mp_obj_t bleio_device_set_name(mp_obj_t self_in, mp_obj_t value) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (!self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't change the name in Central mode"))); - } - - self->name = value; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_device_set_name_obj, bleio_device_set_name); - -const mp_obj_property_t bleio_device_name_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_device_get_name_obj, - (mp_obj_t)&bleio_device_set_name_obj, - (mp_obj_t)&mp_const_none_obj }, -}; - -STATIC mp_obj_t bleio_device_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - - if (!self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't advertise in Central mode"))); - } - - enum { ARG_connectable, ARG_data }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_connectable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, - { MP_QSTR_data, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_buffer_info_t bufinfo = { 0 }; - if (args[ARG_data].u_obj != mp_const_none) { - mp_get_buffer_raise(args[ARG_data].u_obj, &bufinfo, MP_BUFFER_READ); - } - - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); - for (size_t i = 0; i < service_list->len; ++i) { - bleio_service_obj_t *service = service_list->items[i]; - if (service->handle == 0xFFFF) { - common_hal_bleio_device_add_service(self, service); - } - } - - common_hal_bleio_device_start_advertising(self, args[ARG_connectable].u_bool, &bufinfo); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_device_start_advertising_obj, 0, bleio_device_start_advertising); - -STATIC mp_obj_t bleio_device_stop_advertising(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (!self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't advertise in Central mode"))); - } - - common_hal_bleio_device_stop_advertising(self); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_stop_advertising_obj, bleio_device_stop_advertising); - -STATIC mp_obj_t bleio_device_get_services(mp_obj_t self_in) { - bleio_device_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return self->service_list; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_device_get_services_obj, bleio_device_get_services); - -const mp_obj_property_t bleio_device_services_obj = { - .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_device_get_services_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj }, -}; - -STATIC const mp_rom_map_elem_t bleio_device_locals_dict_table[] = { - // Methods - { MP_ROM_QSTR(MP_QSTR_add_service), MP_ROM_PTR(&bleio_device_add_service_obj) }, - { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&bleio_device_connect_obj) }, - { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_device_disconnect_obj) }, - { MP_ROM_QSTR(MP_QSTR_start_advertising), MP_ROM_PTR(&bleio_device_start_advertising_obj) }, - { MP_ROM_QSTR(MP_QSTR_stop_advertising), MP_ROM_PTR(&bleio_device_stop_advertising_obj) }, - - // Properties - { MP_ROM_QSTR(MP_QSTR_name), MP_ROM_PTR(&bleio_device_name_obj) }, - { MP_ROM_QSTR(MP_QSTR_services), MP_ROM_PTR(&bleio_device_services_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(bleio_device_locals_dict, bleio_device_locals_dict_table); - -const mp_obj_type_t bleio_device_type = { - { &mp_type_type }, - .name = MP_QSTR_Device, - .print = bleio_device_print, - .make_new = bleio_device_make_new, - .locals_dict = (mp_obj_dict_t*)&bleio_device_locals_dict -}; diff --git a/shared-bindings/bleio/Device.h b/shared-bindings/bleio/Device.h index e452a8ad6c..d19b8c886b 100644 --- a/shared-bindings/bleio/Device.h +++ b/shared-bindings/bleio/Device.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 5397f4c3ab..e270c599c6 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index 6468325c27..16438bba6d 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -3,8 +3,8 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec - * Copyright (c) 2018 Dan Halbert for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/ScanEntry.h b/shared-bindings/bleio/ScanEntry.h index c1b52e6b4e..3a02f2facf 100644 --- a/shared-bindings/bleio/ScanEntry.h +++ b/shared-bindings/bleio/ScanEntry.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * Copyright (c) 2017 Glenn Ruben Bakke * diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index 352ef8d6a8..2719164d88 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/Service.h b/shared-bindings/bleio/Service.h index 27d79f9539..6693cc3bb3 100644 --- a/shared-bindings/bleio/Service.h +++ b/shared-bindings/bleio/Service.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -27,12 +28,11 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H #define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H -#include "shared-module/bleio/Characteristic.h" #include "common-hal/bleio/Service.h" const mp_obj_type_t bleio_service_type; -extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, mp_obj_list_t *char_list, bool is_secondary); +extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, mp_obj_list_t *characteristic_list, bool is_secondary); extern bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self); extern mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self); extern bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self); diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c index f79dfa6752..9725050586 100644 --- a/shared-bindings/bleio/UUID.c +++ b/shared-bindings/bleio/UUID.c @@ -3,9 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2017 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec - * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * Copyright (c) 2017 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/bleio/UUID.h b/shared-bindings/bleio/UUID.h index aef2c1e29e..caf039aecb 100644 --- a/shared-bindings/bleio/UUID.h +++ b/shared-bindings/bleio/UUID.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 06c00d5880..ca45a846ec 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -53,11 +54,10 @@ //| Address //| AdvertisementData //| Adapter +//| Central //| Characteristic //| CharacteristicBuffer -// Work-in-progress classes are omitted, and marked as :orphan: in their files. // Descriptor -// Device //| Peripheral //| ScanEntry //| Scanner @@ -74,6 +74,7 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) }, { MP_ROM_QSTR(MP_QSTR_Address), MP_ROM_PTR(&bleio_address_type) }, +// { MP_ROM_QSTR(MP_QSTR_Central), MP_ROM_PTR(&bleio_central_type) }, { MP_ROM_QSTR(MP_QSTR_Characteristic), MP_ROM_PTR(&bleio_characteristic_type) }, { MP_ROM_QSTR(MP_QSTR_CharacteristicBuffer), MP_ROM_PTR(&bleio_characteristic_buffer_type) }, // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, diff --git a/shared-bindings/bleio/__init__.h b/shared-bindings/bleio/__init__.h index 1f4e0a66ff..4aa6dd45b7 100644 --- a/shared-bindings/bleio/__init__.h +++ b/shared-bindings/bleio/__init__.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-module/bleio/Address.h b/shared-module/bleio/Address.h index f66e97d640..eb1aab2581 100644 --- a/shared-module/bleio/Address.h +++ b/shared-module/bleio/Address.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-module/bleio/AdvertisementData.h b/shared-module/bleio/AdvertisementData.h index 66855172ab..89cdfb0700 100644 --- a/shared-module/bleio/AdvertisementData.h +++ b/shared-module/bleio/AdvertisementData.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h deleted file mode 100644 index 3132fd47b4..0000000000 --- a/shared-module/bleio/Characteristic.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H - -// Flags for each characteristic property. Common across ports. -typedef struct { - bool broadcast : 1; - bool read : 1; - bool write_no_response : 1; - bool write : 1; - bool notify : 1; - bool indicate : 1; -} bleio_characteristic_properties_t; - -// bleio_characteristic_obj_t is defined in ports/*/common-hal. - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H diff --git a/shared-module/bleio/Device.h b/shared-module/bleio/Device.h deleted file mode 100644 index 8d9ece5ef0..0000000000 --- a/shared-module/bleio/Device.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H - -#include - -#include "shared-module/bleio/Address.h" - -typedef struct { - mp_obj_base_t base; - bool is_peripheral; - mp_obj_t name; - bleio_address_obj_t address; - volatile uint16_t conn_handle; - mp_obj_t service_list; - mp_obj_t notif_handler; - mp_obj_t conn_handler; -} bleio_device_obj_t; - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_DEVICE_H diff --git a/shared-module/bleio/ScanEntry.h b/shared-module/bleio/ScanEntry.h index 40e02f9fa0..4e7028ba2a 100644 --- a/shared-module/bleio/ScanEntry.h +++ b/shared-module/bleio/ScanEntry.h @@ -3,6 +3,7 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries * Copyright (c) 2018 Artur Pacholec * * Permission is hereby granted, free of charge, to any person obtaining a copy From 24ac1fdcabdcdb02f9807192d3cb2a4210b4afc8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 19 Jun 2019 21:54:28 -0400 Subject: [PATCH 13/61] WIP: backup only; not compiled --- ports/nrf/bluetooth/ble_drv.h | 2 + ports/nrf/common-hal/bleio/Central.c | 312 ++++++++++++++++++++ ports/nrf/common-hal/bleio/Central.h | 45 +++ ports/nrf/common-hal/bleio/Characteristic.c | 88 +++--- ports/nrf/common-hal/bleio/Service.h | 2 + ports/nrf/common-hal/bleio/__init__.c | 10 +- py/circuitpy_defns.mk | 1 + shared-bindings/bleio/Central.c | 186 ++++++++++++ shared-bindings/bleio/Central.h | 39 +++ shared-module/bleio/Characteristic.h | 40 +++ 10 files changed, 664 insertions(+), 61 deletions(-) create mode 100644 ports/nrf/common-hal/bleio/Central.c create mode 100644 ports/nrf/common-hal/bleio/Central.h create mode 100644 shared-bindings/bleio/Central.c create mode 100644 shared-bindings/bleio/Central.h create mode 100644 shared-module/bleio/Characteristic.h diff --git a/ports/nrf/bluetooth/ble_drv.h b/ports/nrf/bluetooth/ble_drv.h index d349fa4e07..a066f588fa 100644 --- a/ports/nrf/bluetooth/ble_drv.h +++ b/ports/nrf/bluetooth/ble_drv.h @@ -43,7 +43,9 @@ #define SEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000000) / (RESOLUTION)) // 0.625 msecs (625 usecs) #define ADV_INTERVAL_UNIT_FLOAT_SECS (0.000625) +// Microseconds is the base unit. The macros above know that. #define UNIT_0_625_MS (625) +#define UNIT_1_25_MS (1250) #define UNIT_10_MS (10000) typedef void (*ble_drv_evt_handler_t)(ble_evt_t*, void*); diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c new file mode 100644 index 0000000000..af5a56b76c --- /dev/null +++ b/ports/nrf/common-hal/bleio/Central.c @@ -0,0 +1,312 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +#include "ble.h" +#include "ble_drv.h" +#include "ble_hci.h" +#include "nrf_soc.h" +#include "py/objstr.h" +#include "py/runtime.h" +#include "shared-bindings/bleio/Adapter.h" +#include "shared-bindings/bleio/Characteristic.h" +#include "shared-bindings/bleio/Central.h" +#include "shared-bindings/bleio/Service.h" +#include "shared-bindings/bleio/UUID.h" + +static bleio_service_obj_t *m_char_discovery_service; +static volatile bool m_discovery_successful; + +STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_handle) { + m_discovery_successful = false; + + uint32_t err_code = sd_ble_gattc_primary_services_discover(self->conn_handle, start_handle, NULL); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to discover services")); + } + + // Serialize discovery. + err_code = sd_mutex_acquire(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to acquire mutex")); + } + + // Wait for someone else to release m_discovery_mutex. + while (sd_mutex_acquire(&m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { +#ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP +#endif + } + + err_code = sd_mutex_release(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to release mutex")); + } + + return m_discovery_successful; +} + +STATIC bool discover_next_characteristics(bleio_central_obj_t *self, bleio_service_obj_t *service, uint16_t start_handle) { + m_char_discovery_service = service; + + ble_gattc_handle_range_t handle_range; + handle_range.start_handle = start_handle; + handle_range.end_handle = service->end_handle; + + m_discovery_successful = false; + + uint32_t err_code = sd_ble_gattc_characteristics_discover(self->conn_handle, &handle_range); + if (err_code != NRF_SUCCESS) { + return false; + } + + err_code = sd_mutex_acquire(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to acquire mutex")); + } + + while (sd_mutex_acquire(&m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { + MICROPY_VM_HOOK_LOOP; + } + + err_code = sd_mutex_release(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to release mutex")); + } + + return m_discovery_successful; +} + +STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *response, bleio_central_obj_t *central) { + for (size_t i = 0; i < response->count; ++i) { + ble_gattc_service_t *gattc_service = &response->services[i]; + + bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); + service->base.type = &bleio_service_type; + service->device = central; + service->characteristic_list = mp_obj_new_list(0, NULL); + service->start_handle = gattc_service->handle_range.start_handle; + service->end_handle = gattc_service->handle_range.end_handle; + service->handle = gattc_service->handle_range.start_handle; + + bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid); + service->uuid = uuid; + + mp_obj_list_append(central->service_list, service); + } + + if (response->count > 0) { + m_discovery_successful = true; + } + + const uint32_t err_code = sd_mutex_release(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to release mutex")); + } +} + +STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio_central_obj_t *central) { + for (size_t i = 0; i < response->count; ++i) { + ble_gattc_char_t *gattc_char = &response->chars[i]; + + bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); + characteristic->base.type = &bleio_characteristic_type; + + bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + uuid->base.type = &bleio_uuid_type; + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); + characteristic->uuid = uuid; + + characteristic->props.broadcast = gattc_char->char_props.broadcast; + characteristic->props.indicate = gattc_char->char_props.indicate; + characteristic->props.notify = gattc_char->char_props.notify; + characteristic->props.read = gattc_char->char_props.read; + characteristic->props.write = gattc_char->char_props.write; + characteristic->props.write_no_response = gattc_char->char_props.write_wo_resp; + characteristic->handle = gattc_char->handle_value; + characteristic->service = m_char_discovery_service; + + mp_obj_list_append(m_char_discovery_service->characteristic_list, MP_OBJ_FROM_PTR(characteristic)); + } + + if (response->count > 0) { + m_discovery_successful = true; + } + + const uint32_t err_code = sd_mutex_release(&m_discovery_mutex); + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg(translate("Failed to release mutex")); + } +} + +STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { + bleio_central_obj_t *central = (bleio_central_obj_t*)central_in; + + switch (ble_evt->header.evt_id) { + case BLE_GAP_EVT_CONNECTED: + { + ble_gap_conn_params_t conn_params; + central->conn_handle = ble_evt->evt.gap_evt.conn_handle; + + sd_ble_gap_ppcp_get(&conn_params); + sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); + break; + } + + case BLE_GAP_EVT_TIMEOUT: + if (central->attempting_to_connect) { + // Signal that connection attempt has timed out. + central->attempting_to_connect = false; + } + break; + + case BLE_GAP_EVT_DISCONNECTED: + central->conn_handle = BLE_CONN_HANDLE_INVALID; + break; + + case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: + on_primary_srv_discovery_rsp(&ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp, central); + break; + + case BLE_GATTC_EVT_CHAR_DISC_RSP: + on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); + break; + + case BLE_GATTS_EVT_SYS_ATTR_MISSING: + sd_ble_gatts_sys_attr_set(ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0); + break; + + case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: + sd_ble_gatts_exchange_mtu_reply(central->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); + break; + + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: + sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); + break; + + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: + { + ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; + sd_ble_gap_conn_param_update(central->conn_handle, &request->conn_params); + break; + } + } +} + +void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout) { + common_hal_bleio_adapter_set_enabled(true); + ble_drv_add_event_handler(on_ble_evt, self); + + ble_gap_scan_params_t scan_params = { + .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), + .window = MSEC_TO_UNITS(100, UNIT_0_625_MS), + .scan_phys = BLE_GAP_PHY_1MBPS, + // timeout of 0 means no timeout + .timeout = SEC_TO_UNITS(timeout, UNIT_10_MS), + }; + + ble_gap_conn_params_t conn_params = { + .conn_sup_timeout = MSEC_TO_UNITS(4000, UNIT_10_MS), + .min_conn_interval = MSEC_TO_UNITS(15, UNIT_1_25_MS), + .max_conn_interval = MSEC_TO_UNITS(300, UNIT_1_25_MS), + .slave_latency = 0, // number of conn events + }; + + self->attempting_to_connect = true; + + uint32_t err_code = sd_ble_gap_connect(&scan_params, &m_scan_buffer); + + if (err_code != NRF_SUCCESS) { + mp_raise_OSError_msg_varg(translate("Failed to start connecting, error 0x%04x"), err_code); + } + + while (self->conn_handle == BLE_CONN_HANDLE_INVALID && self->attempting_to_connect) { + #ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP + #endif + } + + if (!self->attempting_to_connect) { + mp_raise_OSError_msg(translate("Failed to connect: timeout")); + } + + // Conenction successful. + // Now discover all services on the remote peripheral. Ask for services repeatedly + // until no more are left. + + uint16_t next_start_handle; + + next_start_handle = BLE_GATT_HANDLE_START; + + while (1) { + if(!discover_next_services(self, discovery_start_handle)) { + break; + } + + // discover_next_services() appends to service_list. + const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + + // Get the most recently discovered service, and ask for services with handles + // starting after the last attribute handle of t + const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; + next_start_handle = service->end_handle + 1; + } + + // Now, for each service, discover its characteristics. + // find characteristics in each service + const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + for (size_t i = 0; i < service_list->len; ++i) { + bleio_service_obj_t *service = service_list->items[i]; + + next_start_handle = service->start_handle; + + while (1) { + if (!discover_next_characteristics(self, service, service->start_handle)) { + break; + } + + // discover_next_characteristics() appends to the characteristic_list. + const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); + + // Get the most recently discovered characteristic. + const bleio_characteristic_obj_t *characteristic = + characteristic_list->items[characteristic_list->len - 1]; + next_start_handle = characteristic->handle + 1; + if (next_start_handle >= service->end_handle) { + // Went past the end of the range of handles for this service. + break; + } + } + } +} + +void common_hal_bleio_central_disconnect(bleio_central_obj_t *self) { + sd_ble_gap_disconnect(self->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); +} diff --git a/ports/nrf/common-hal/bleio/Central.h b/ports/nrf/common-hal/bleio/Central.h new file mode 100644 index 0000000000..c44cf3b771 --- /dev/null +++ b/ports/nrf/common-hal/bleio/Central.h @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H +#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H + +#include + +#include "shared-module/bleio/Address.h" + +typedef struct { + mp_obj_base_t base; + mp_obj_t remote_name; + bleio_address_obj_t address; + volatile bool attempting_to_connect; + volatile uint16_t conn_handle; + mp_obj_t service_list; + mp_obj_t conn_handler; +} bleio_central_obj_t; + +#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 346cfefbc5..70ebd7aba3 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -37,9 +37,6 @@ #include "common-hal/bleio/Characteristic.h" STATIC volatile bleio_characteristic_obj_t *m_read_characteristic; -STATIC volatile uint8_t m_tx_in_progress; -// Serialize gattc writes that send a response. This might be done per object? -STATIC nrf_mutex_t *m_write_mutex; STATIC uint16_t get_cccd(bleio_characteristic_obj_t *characteristic) { const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); @@ -118,17 +115,21 @@ STATIC void gatts_notify_indicate(bleio_characteristic_obj_t *characteristic, mp .p_data = bufinfo->buf, }; - while (m_tx_in_progress >= MAX_TX_IN_PROGRESS) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); - m_tx_in_progress++; - const uint32_t err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params); - if (err_code != NRF_SUCCESS) { - m_tx_in_progress--; + + while (1) { + const uint32_t err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params); + if (err_code == NRF_SUCCESS) { + break; + } + // TX buffer is full + // We could wait for an event indicating the write is complete, but just retrying is easier. + if (err_code == NRF_ERROR_RESOURCES) { + MICROPY_VM_HOOK_LOOP; + continue; + } + + // Some real error has occurred. mp_raise_OSError_msg_varg(translate("Failed to notify or indicate attribute value, err 0x%04x"), err_code); } @@ -144,11 +145,8 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) { mp_raise_OSError_msg_varg(translate("Failed to read attribute value, err 0x%04x"), err_code); } -// while (m_read_characteristic != NULL) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif + MICROPY_VM_HOOK_LOOP; } } @@ -158,67 +156,47 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in ble_gattc_write_params_t write_params = { .flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL, - .write_op = BLE_GATT_OP_WRITE_REQ, + .write_op = characteristic->props.write_no_response ? BLE_GATT_OP_WRITE_CMD : BLE_GATT_OP_WRITE_REQ, .handle = characteristic->handle, .p_value = bufinfo->buf, .len = bufinfo->len, }; - if (characteristic->props.write_no_response) { - write_params.write_op = BLE_GATT_OP_WRITE_CMD; - - err_code = sd_mutex_acquire(m_write_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg_varg(translate("Failed to acquire mutex, err 0x%04x"), err_code); + while (1) { + uint32 err_code = sd_ble_gattc_write(conn_handle, &write_params); + if (err_code == NRF_SUCCESS) { + break; } - } - err_code = sd_ble_gattc_write(conn_handle, &write_params); - if (err_code != NRF_SUCCESS) { + // Write with response will return NRF_ERROR_BUSY if the response has not been received. + // Write without reponse will return NRF_ERROR_RESOURCES if too many writes are pending. + if (err_code == NRF_ERROR_BUSY || err_code == NRF_ERROR_RESOURCES) { + // We could wait for an event indicating the write is complete, but just retrying is easier. + MICROPY_VM_HOOK_LOOP; + continue; + } + + // Some real error occurred. mp_raise_OSError_msg_varg(translate("Failed to write attribute value, err 0x%04x"), err_code); } - while (sd_mutex_acquire(m_write_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - err_code = sd_mutex_release(m_write_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg_varg(translate("Failed to release mutex, err 0x%04x"), err_code); - } } STATIC void characteristic_on_ble_evt(ble_evt_t *ble_evt, void *param) { switch (ble_evt->header.evt_id) { - case BLE_GATTS_EVT_HVN_TX_COMPLETE: - { - uint8_t count = ble_evt->evt.gatts_evt.params.hvn_tx_complete.count; - // Don't underflow the count. - if (count >= m_tx_in_progress) { - m_tx_in_progress = 0; - } else { - m_tx_in_progress -= count; - } - break; - } + + // More events may be handled later, so keep this as a switch. case BLE_GATTC_EVT_READ_RSP: { ble_gattc_evt_read_rsp_t *response = &ble_evt->evt.gattc_evt.params.read_rsp; m_read_characteristic->value_data = mp_obj_new_bytearray(response->len, response->data); - // Flag to busy-wait loop that we've read the characteristic. + // Indicate to busy-wait loop that we've read the characteristic. m_read_characteristic = NULL; break; } - case BLE_GATTC_EVT_WRITE_RSP: - // Someone else can write now. - sd_mutex_release(m_write_mutex); - break; - - // For debugging. + // For debugging. default: // mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id); break; diff --git a/ports/nrf/common-hal/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h index b5acf39ae0..dc794ff28c 100644 --- a/ports/nrf/common-hal/bleio/Service.h +++ b/ports/nrf/common-hal/bleio/Service.h @@ -32,12 +32,14 @@ typedef struct { mp_obj_base_t base; + // Handle for this service. uint16_t handle; bool is_secondary; bleio_uuid_obj_t *uuid; // May be a Peripheral, Central, etc. mp_obj_t *device; mp_obj_t characteristic_list; + // Range of attribute handles of this service. uint16_t start_handle; uint16_t end_handle; } bleio_service_obj_t; diff --git a/ports/nrf/common-hal/bleio/__init__.c b/ports/nrf/common-hal/bleio/__init__.c index 58b81f066d..699dcc57fd 100644 --- a/ports/nrf/common-hal/bleio/__init__.c +++ b/ports/nrf/common-hal/bleio/__init__.c @@ -49,9 +49,8 @@ const super_adapter_obj_t common_hal_bleio_adapter_obj = { gatt_role_t common_hal_bleio_device_get_gatt_role(mp_obj_t device) { if (MP_OBJ_IS_TYPE(device, &bleio_peripheral_type)) { return ((bleio_peripheral_obj_t*) MP_OBJ_TO_PTR(device))->gatt_role; -// Does not exist yet. -// } else if (MP_OBJ_IS_TYPE(device, &bleio_central_type)) { -// return ((bleio_central_obj_t*) MP_OBJ_TO_PTR(device))->gatt_role; + } else if (MP_OBJ_IS_TYPE(device, &bleio_central_type)) { + return ((bleio_central_obj_t*) MP_OBJ_TO_PTR(device))->gatt_role; } else { return GATT_ROLE_NONE; } @@ -60,9 +59,8 @@ gatt_role_t common_hal_bleio_device_get_gatt_role(mp_obj_t device) { uint16_t common_hal_bleio_device_get_conn_handle(mp_obj_t device) { if (MP_OBJ_IS_TYPE(device, &bleio_peripheral_type)) { return ((bleio_peripheral_obj_t*) MP_OBJ_TO_PTR(device))->conn_handle; -// Does not exist yet. -// } else if (MP_OBJ_IS_TYPE(device, &bleio_central_type)) { -// return ((bleio_central_obj_t*) MP_OBJ_TO_PTR(device))->conn_handle; + } else if (MP_OBJ_IS_TYPE(device, &bleio_central_type)) { + return ((bleio_central_obj_t*) MP_OBJ_TO_PTR(device))->conn_handle; } else { return 0; } diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 435cf2c334..782314fc70 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -224,6 +224,7 @@ $(filter $(SRC_PATTERNS), \ audioio/AudioOut.c \ bleio/__init__.c \ bleio/Adapter.c \ + bleio/Central.c \ bleio/Characteristic.c \ bleio/CharacteristicBuffer.c \ bleio/Descriptor.c \ diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c new file mode 100644 index 0000000000..e5fd66348e --- /dev/null +++ b/shared-bindings/bleio/Central.c @@ -0,0 +1,186 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * Copyright (c) 2016 Glenn Ruben Bakke + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +#include "ble_drv.h" +#include "py/objarray.h" +#include "py/objproperty.h" +#include "py/objstr.h" +#include "py/runtime.h" +#include "shared-bindings/bleio/Adapter.h" +#include "shared-bindings/bleio/AddressType.h" +#include "shared-bindings/bleio/Characteristic.h" +#include "shared-bindings/bleio/Central.h" +#include "shared-bindings/bleio/Service.h" +#include "shared-bindings/bleio/UUID.h" + +//| .. currentmodule:: bleio +//| +//| :class:`Central` -- A BLE central device +//| ========================================================= +//| +//| Implement a BLE central, which runs locally. Can connect to a given address. +//| +//| Usage:: +//| +//| import bleio +//| +//| scanner = bleio.Scanner() +//| entries = scanner.scan(2.5) +//| +//| my_entry = None +//| for entry in entries: +//| if entry.name is not None and entry.name == 'MyCentral': +//| my_entry = entry +//| break +//| +//| central = bleio.Central(my_entry.address) +//| central.connect() +//| + +//| .. class:: Central(address=None, scan_entry=None) +//| +//| Create a new Central object. If the `address` or :py:data:`scan_entry` parameters are not `None`, +//| the role is set to Central, otherwise it's set to Peripheral. +//| +//| :param bleio.Address address: The address of the central to connect to +//| :param bleio.ScanEntry scan_entry: The scan entry returned from `bleio.Scanner` +//| +STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { + mp_arg_check_num(n_args, n_kw, 0, 1, true); + bleio_central_obj_t *self = m_new_obj(bleio_central_obj_t); + self->base.type = &bleio_central_type; + self->service_list = mp_obj_new_list(0, NULL); + self->conn_handler = mp_const_none; + self->conn_handle = 0xFFFF; + + mp_map_t kw_args; + mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); + + enum { ARG_address, ARG_scan_entry }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_address, MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_scan_entry, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + const mp_obj_t address_obj = args[ARG_address].u_obj; + const mp_obj_t scan_entry_obj = args[ARG_scan_entry].u_obj; + + if (!MP_OBJ_IS_TYPE(address_obj, &bleio_address_type)) { + mp_raise_ValueError("Expected an Address"); + } + + return MP_OBJ_FROM_PTR(self); +} + + + +//| .. method:: connect() +//| +//| Attempts a connection to the remote peripheral. If the connection is successful, +//| +STATIC mp_obj_t bleio_central_connect(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + if (self->is_peripheral) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, + translate("Can't connect in Peripheral mode"))); + } + + common_hal_bleio_central_connect(self); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_connect_obj, bleio_central_connect); + + +//| .. method:: disconnect() +//| +//| Disconnects from the remote peripheral. +//| +STATIC mp_obj_t bleio_central_disconnect(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + common_hal_bleio_central_disconnect(self); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_disconnect_obj, bleio_central_disconnect); + +//| .. attribute:: remote_name (read-only) +//| +//| The name of the remote peripheral, if connected. May be None if no name was advertised. +//| +STATIC mp_obj_t bleio_central_get_remote_name(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return self->remote_name; +} +MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_name_obj, bleio_central_get_remote_name); + +//| .. attribute:: remote_services (read-only) +//| +//| Empty until connected, then a list of services provided by the remote peripheral. +//| +STATIC mp_obj_t bleio_central_get_remote_services(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return self->service_list; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_services_obj, bleio_central_get_remote_services); + +const mp_obj_property_t bleio_central_remote_services_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&bleio_central_get_remote_services_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + +STATIC const mp_rom_map_elem_t bleio_central_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&bleio_central_connect_obj) }, + { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_central_disconnect_obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_remote_name), MP_ROM_PTR(&bleio_central_remote_name_obj) }, + { MP_ROM_QSTR(MP_QSTR_remote_services), MP_ROM_PTR(&bleio_central_remote_services_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(bleio_central_locals_dict, bleio_central_locals_dict_table); + +const mp_obj_type_t bleio_central_type = { + { &mp_type_type }, + .name = MP_QSTR_Central, + .make_new = bleio_central_make_new, + .locals_dict = (mp_obj_dict_t*)&bleio_central_locals_dict +}; diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h new file mode 100644 index 0000000000..5ea2119af0 --- /dev/null +++ b/shared-bindings/bleio/Central.h @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * Copyright (c) 2018 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H + +#include "common-hal/bleio/Central.h" +#include "common-hal/bleio/Service.h" + +extern const mp_obj_type_t bleio_device_type; + +extern void common_hal_bleio_device_connect(bleio_device_obj_t *device); +extern void common_hal_bleio_device_disconnect(bleio_device_obj_t *device); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H diff --git a/shared-module/bleio/Characteristic.h b/shared-module/bleio/Characteristic.h new file mode 100644 index 0000000000..27b43588fa --- /dev/null +++ b/shared-module/bleio/Characteristic.h @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Dan Halbert for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H +#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H + +// Flags for each characteristic property. Common across ports. +typedef struct { + bool broadcast : 1; + bool read : 1; + bool write_no_response : 1; + bool write : 1; + bool notify : 1; + bool indicate : 1; +} bleio_characteristic_properties_t; + +#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CHARACTERISTIC_H From 23bd861c9ac27644c1568a0c89be6bc1d48362a4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 20 Jun 2019 18:02:14 -0400 Subject: [PATCH 14/61] nrf: fix neopixel_write pwm buf size calc --- ports/nrf/common-hal/neopixel_write/__init__.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ports/nrf/common-hal/neopixel_write/__init__.c b/ports/nrf/common-hal/neopixel_write/__init__.c index fe2bab9996..78e0038e8f 100644 --- a/ports/nrf/common-hal/neopixel_write/__init__.c +++ b/ports/nrf/common-hal/neopixel_write/__init__.c @@ -111,18 +111,23 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout // // If there is not enough memory, we will fall back to cycle counter // using DWT - uint32_t pattern_size = numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t); + +#define PATTERN_SIZE(numBytes) (numBytes * 8 * sizeof(uint16_t) + 2 * sizeof(uint16_t)) + + uint32_t pattern_size = PATTERN_SIZE(numBytes); uint16_t* pixels_pattern = NULL; bool pattern_on_heap = false; // Use the stack to store 1 pixels worth of PWM data for the status led. uint32_t to ensure alignment. - uint32_t one_pixel[8 * sizeof(uint16_t) + 1]; + // Make it at least as big as PATTERN_SIZE(3), for one pixel of RGB data. + // PATTERN_SIZE is a multiple of 4, so we don't need round up to make sure one_pixel is large enough. + uint32_t one_pixel[PATTERN_SIZE(3)/sizeof(uint32_t)]; NRF_PWM_Type* pwm = find_free_pwm(); // only malloc if there is PWM device available if ( pwm != NULL ) { - if (pattern_size <= sizeof(one_pixel) * sizeof(uint32_t)) { + if (pattern_size <= sizeof(one_pixel)) { pixels_pattern = (uint16_t *) one_pixel; } else { pixels_pattern = (uint16_t *) m_malloc_maybe(pattern_size, false); From 4881e1ff55768c027404cc6a1375c43d4c3acf2a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 21 Jun 2019 18:04:04 -0400 Subject: [PATCH 15/61] WIP: Central compiles; now will test --- ports/nrf/common-hal/bleio/Central.c | 73 +++++++++----------- ports/nrf/common-hal/bleio/Central.h | 4 +- ports/nrf/common-hal/bleio/Characteristic.c | 3 +- ports/nrf/common-hal/bleio/Service.h | 2 +- ports/nrf/common-hal/bleio/__init__.c | 1 + shared-bindings/bleio/Central.c | 67 +++++------------- shared-bindings/bleio/Central.h | 8 ++- shared-bindings/bleio/Characteristic.c | 8 +-- shared-bindings/bleio/CharacteristicBuffer.c | 2 +- shared-bindings/bleio/Device.h | 42 ----------- shared-bindings/bleio/Peripheral.c | 6 +- shared-bindings/bleio/Service.c | 24 +++---- 12 files changed, 78 insertions(+), 162 deletions(-) delete mode 100644 shared-bindings/bleio/Device.h diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index af5a56b76c..5864a8a56f 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -41,34 +41,22 @@ #include "shared-bindings/bleio/UUID.h" static bleio_service_obj_t *m_char_discovery_service; +static volatile bool m_discovery_in_process; static volatile bool m_discovery_successful; STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_handle) { m_discovery_successful = false; + m_discovery_in_process = true; uint32_t err_code = sd_ble_gattc_primary_services_discover(self->conn_handle, start_handle, NULL); if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg(translate("Failed to discover services")); } - // Serialize discovery. - err_code = sd_mutex_acquire(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to acquire mutex")); + // Wait for a discovery event. + while (m_discovery_in_process) { + MICROPY_VM_HOOK_LOOP; } - - // Wait for someone else to release m_discovery_mutex. - while (sd_mutex_acquire(&m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP -#endif - } - - err_code = sd_mutex_release(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } - return m_discovery_successful; } @@ -80,26 +68,17 @@ STATIC bool discover_next_characteristics(bleio_central_obj_t *self, bleio_servi handle_range.end_handle = service->end_handle; m_discovery_successful = false; + m_discovery_in_process = true; uint32_t err_code = sd_ble_gattc_characteristics_discover(self->conn_handle, &handle_range); if (err_code != NRF_SUCCESS) { return false; } - err_code = sd_mutex_acquire(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to acquire mutex")); - } - - while (sd_mutex_acquire(&m_discovery_mutex) == NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN) { + // Wait for a discovery event. + while (m_discovery_in_process) { MICROPY_VM_HOOK_LOOP; } - - err_code = sd_mutex_release(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } - return m_discovery_successful; } @@ -109,7 +88,7 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); service->base.type = &bleio_service_type; - service->device = central; + service->device = MP_OBJ_FROM_PTR(central); service->characteristic_list = mp_obj_new_list(0, NULL); service->start_handle = gattc_service->handle_range.start_handle; service->end_handle = gattc_service->handle_range.end_handle; @@ -125,11 +104,7 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res if (response->count > 0) { m_discovery_successful = true; } - - const uint32_t err_code = sd_mutex_release(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } + m_discovery_in_process = false; } STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio_central_obj_t *central) { @@ -159,11 +134,7 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio if (response->count > 0) { m_discovery_successful = true; } - - const uint32_t err_code = sd_mutex_release(&m_discovery_mutex); - if (err_code != NRF_SUCCESS) { - mp_raise_OSError_msg(translate("Failed to release mutex")); - } + m_discovery_in_process = false; } STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { @@ -189,6 +160,8 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { case BLE_GAP_EVT_DISCONNECTED: central->conn_handle = BLE_CONN_HANDLE_INVALID; + m_discovery_successful = false; + m_discovery_in_process = false; break; case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: @@ -220,10 +193,22 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { } } +void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address_obj_t *address) { + common_hal_bleio_adapter_set_enabled(true); + + self->service_list = mp_obj_new_list(0, NULL); + self->gatt_role = GATT_ROLE_CLIENT; + self->conn_handle = BLE_CONN_HANDLE_INVALID; +} + void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout) { common_hal_bleio_adapter_set_enabled(true); ble_drv_add_event_handler(on_ble_evt, self); + ble_gap_addr_t addr; + addr.addr_type = self->address.type; + memcpy(addr.addr, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); + ble_gap_scan_params_t scan_params = { .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), .window = MSEC_TO_UNITS(100, UNIT_0_625_MS), @@ -241,7 +226,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time self->attempting_to_connect = true; - uint32_t err_code = sd_ble_gap_connect(&scan_params, &m_scan_buffer); + uint32_t err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params, BLE_CONN_CFG_TAG_CUSTOM); if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg_varg(translate("Failed to start connecting, error 0x%04x"), err_code); @@ -266,7 +251,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time next_start_handle = BLE_GATT_HANDLE_START; while (1) { - if(!discover_next_services(self, discovery_start_handle)) { + if(!discover_next_services(self, next_start_handle)) { break; } @@ -310,3 +295,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time void common_hal_bleio_central_disconnect(bleio_central_obj_t *self) { sd_ble_gap_disconnect(self->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); } + +mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self) { + return self->service_list; +} diff --git a/ports/nrf/common-hal/bleio/Central.h b/ports/nrf/common-hal/bleio/Central.h index c44cf3b771..ba4a92187b 100644 --- a/ports/nrf/common-hal/bleio/Central.h +++ b/ports/nrf/common-hal/bleio/Central.h @@ -30,16 +30,16 @@ #include +#include "shared-module/bleio/__init__.h" #include "shared-module/bleio/Address.h" typedef struct { mp_obj_base_t base; - mp_obj_t remote_name; + gatt_role_t gatt_role; bleio_address_obj_t address; volatile bool attempting_to_connect; volatile uint16_t conn_handle; mp_obj_t service_list; - mp_obj_t conn_handler; } bleio_central_obj_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 70ebd7aba3..d2f961fe65 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -152,7 +152,6 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) { STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_info_t *bufinfo) { const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); - uint32_t err_code; ble_gattc_write_params_t write_params = { .flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL, @@ -163,7 +162,7 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in }; while (1) { - uint32 err_code = sd_ble_gattc_write(conn_handle, &write_params); + uint32_t err_code = sd_ble_gattc_write(conn_handle, &write_params); if (err_code == NRF_SUCCESS) { break; } diff --git a/ports/nrf/common-hal/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h index dc794ff28c..90f52027db 100644 --- a/ports/nrf/common-hal/bleio/Service.h +++ b/ports/nrf/common-hal/bleio/Service.h @@ -37,7 +37,7 @@ typedef struct { bool is_secondary; bleio_uuid_obj_t *uuid; // May be a Peripheral, Central, etc. - mp_obj_t *device; + mp_obj_t device; mp_obj_t characteristic_list; // Range of attribute handles of this service. uint16_t start_handle; diff --git a/ports/nrf/common-hal/bleio/__init__.c b/ports/nrf/common-hal/bleio/__init__.c index 699dcc57fd..2dba5780c1 100644 --- a/ports/nrf/common-hal/bleio/__init__.c +++ b/ports/nrf/common-hal/bleio/__init__.c @@ -28,6 +28,7 @@ #include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/Adapter.h" +#include "shared-bindings/bleio/Central.h" #include "shared-bindings/bleio/Peripheral.h" #include "common-hal/bleio/__init__.h" diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index e5fd66348e..b3be906067 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -35,11 +35,10 @@ #include "py/objstr.h" #include "py/runtime.h" #include "shared-bindings/bleio/Adapter.h" -#include "shared-bindings/bleio/AddressType.h" +#include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/Central.h" #include "shared-bindings/bleio/Service.h" -#include "shared-bindings/bleio/UUID.h" //| .. currentmodule:: bleio //| @@ -62,44 +61,28 @@ //| break //| //| central = bleio.Central(my_entry.address) -//| central.connect() +//| central.connect(10.0) # timeout after 10 seconds //| -//| .. class:: Central(address=None, scan_entry=None) -//| -//| Create a new Central object. If the `address` or :py:data:`scan_entry` parameters are not `None`, -//| the role is set to Central, otherwise it's set to Peripheral. +//| .. class:: Central(address) //| +//| Create a new Central object. //| :param bleio.Address address: The address of the central to connect to -//| :param bleio.ScanEntry scan_entry: The scan entry returned from `bleio.Scanner` //| -STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) { - mp_arg_check_num(n_args, n_kw, 0, 1, true); +STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 1, 1, false); + bleio_central_obj_t *self = m_new_obj(bleio_central_obj_t); self->base.type = &bleio_central_type; - self->service_list = mp_obj_new_list(0, NULL); - self->conn_handler = mp_const_none; - self->conn_handle = 0xFFFF; - - mp_map_t kw_args; - mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); - - enum { ARG_address, ARG_scan_entry }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_address, MP_ARG_OBJ, {.u_obj = mp_const_none} }, - { MP_QSTR_scan_entry, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, - }; - - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - const mp_obj_t address_obj = args[ARG_address].u_obj; - const mp_obj_t scan_entry_obj = args[ARG_scan_entry].u_obj; + const mp_obj_t address_obj = pos_args[0]; if (!MP_OBJ_IS_TYPE(address_obj, &bleio_address_type)) { - mp_raise_ValueError("Expected an Address"); + mp_raise_ValueError(translate("Expected an Address")); } + bleio_address_obj_t *address = MP_OBJ_TO_PTR(address_obj); + common_hal_bleio_central_construct(self, address); + return MP_OBJ_FROM_PTR(self); } @@ -109,19 +92,15 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, //| //| Attempts a connection to the remote peripheral. If the connection is successful, //| -STATIC mp_obj_t bleio_central_connect(mp_obj_t self_in) { +STATIC mp_obj_t bleio_central_connect(mp_obj_t self_in, mp_obj_t timeout_in) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - if (self->is_peripheral) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - translate("Can't connect in Peripheral mode"))); - } - - common_hal_bleio_central_connect(self); + mp_float_t timeout = mp_obj_float_get(timeout_in); + common_hal_bleio_central_connect(self, timeout); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_connect_obj, bleio_central_connect); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_central_connect_obj, bleio_central_connect); //| .. method:: disconnect() @@ -137,17 +116,6 @@ STATIC mp_obj_t bleio_central_disconnect(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_disconnect_obj, bleio_central_disconnect); -//| .. attribute:: remote_name (read-only) -//| -//| The name of the remote peripheral, if connected. May be None if no name was advertised. -//| -STATIC mp_obj_t bleio_central_get_remote_name(mp_obj_t self_in) { - bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return self->remote_name; -} -MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_name_obj, bleio_central_get_remote_name); - //| .. attribute:: remote_services (read-only) //| //| Empty until connected, then a list of services provided by the remote peripheral. @@ -155,7 +123,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_name_obj, bleio_central_get_r STATIC mp_obj_t bleio_central_get_remote_services(mp_obj_t self_in) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - return self->service_list; + return common_hal_bleio_central_get_remote_services(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_services_obj, bleio_central_get_remote_services); @@ -172,7 +140,6 @@ STATIC const mp_rom_map_elem_t bleio_central_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_central_disconnect_obj) }, // Properties - { MP_ROM_QSTR(MP_QSTR_remote_name), MP_ROM_PTR(&bleio_central_remote_name_obj) }, { MP_ROM_QSTR(MP_QSTR_remote_services), MP_ROM_PTR(&bleio_central_remote_services_obj) }, }; diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h index 5ea2119af0..c6fb50bc0c 100644 --- a/shared-bindings/bleio/Central.h +++ b/shared-bindings/bleio/Central.h @@ -31,9 +31,11 @@ #include "common-hal/bleio/Central.h" #include "common-hal/bleio/Service.h" -extern const mp_obj_type_t bleio_device_type; +extern const mp_obj_type_t bleio_central_type; -extern void common_hal_bleio_device_connect(bleio_device_obj_t *device); -extern void common_hal_bleio_device_disconnect(bleio_device_obj_t *device); +extern void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address_obj_t *address); +extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout); +extern void common_hal_bleio_central_disconnect(bleio_central_obj_t *self); +extern mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index 859611f91a..050992bb86 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -69,12 +69,12 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mp_obj_t uuid = args[ARG_uuid].u_obj; + const mp_obj_t uuid_obj = args[ARG_uuid].u_obj; - if (!MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) { + if (!MP_OBJ_IS_TYPE(uuid_obj, &bleio_uuid_type)) { mp_raise_ValueError(translate("Expected a UUID")); } - bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid); + bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_obj); bleio_characteristic_obj_t *self = m_new_obj(bleio_characteristic_obj_t); self->base.type = &bleio_characteristic_type; @@ -88,7 +88,7 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t properties.write = args[ARG_write].u_bool; properties.write_no_response = args[ARG_write_no_response].u_bool; - common_hal_bleio_characteristic_construct(self, uuid_obj, properties); + common_hal_bleio_characteristic_construct(self, uuid, properties); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index da79c5d7ae..827f4947b3 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -86,7 +86,7 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, bleio_characteristic_buffer_obj_t *self = m_new_obj(bleio_characteristic_buffer_obj_t); self->base.type = &bleio_characteristic_buffer_type; - common_hal_bleio_characteristic_buffer_construct(self, characteristic, timeout, buffer_size); + common_hal_bleio_characteristic_buffer_construct(self, MP_OBJ_TO_PTR(characteristic), timeout, buffer_size); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/Device.h b/shared-bindings/bleio/Device.h deleted file mode 100644 index d19b8c886b..0000000000 --- a/shared-bindings/bleio/Device.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Dan Halbert for Adafruit Industries - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H - -#include "shared-module/bleio/Device.h" -#include "common-hal/bleio/Service.h" - -extern const mp_obj_type_t bleio_device_type; - -extern void common_hal_bleio_device_add_service(bleio_device_obj_t *device, bleio_service_obj_t *service); -extern void common_hal_bleio_device_start_advertising(bleio_device_obj_t *device, bool connectable, mp_buffer_info_t *raw_data); -extern void common_hal_bleio_device_stop_advertising(bleio_device_obj_t *device); -extern void common_hal_bleio_device_connect(bleio_device_obj_t *device); -extern void common_hal_bleio_device_disconnect(bleio_device_obj_t *device); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_DEVICE_H diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index e270c599c6..002999b5d6 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -107,8 +107,8 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar self->base.type = &bleio_peripheral_type; // Copy the services list and validate its items. - mp_obj_t service_list = mp_obj_new_list(0, NULL); - mp_obj_list_t *service_list_obj = MP_OBJ_FROM_PTR(service_list); + mp_obj_t service_list_obj = mp_obj_new_list(0, NULL); + mp_obj_list_t *service_list = MP_OBJ_FROM_PTR(service_list_obj); mp_obj_t service; while ((service = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { @@ -128,7 +128,7 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar mp_raise_ValueError(translate("name must be a string")); } - common_hal_bleio_peripheral_construct(self, service_list_obj, name_str); + common_hal_bleio_peripheral_construct(self, service_list, name_str); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index 2719164d88..e687019d14 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -61,9 +61,9 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - const mp_obj_t uuid = args[ARG_uuid].u_obj; + const mp_obj_t uuid_obj = args[ARG_uuid].u_obj; - if (!MP_OBJ_IS_TYPE(uuid, &bleio_uuid_type)) { + if (!MP_OBJ_IS_TYPE(uuid_obj, &bleio_uuid_type)) { mp_raise_ValueError(translate("Expected a UUID")); } @@ -71,31 +71,31 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, self->base.type = &bleio_service_type; const bool is_secondary = args[ARG_secondary].u_bool; - bleio_uuid_obj_t *uuid_obj = MP_OBJ_TO_PTR(uuid); + bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_obj); // If characteristics is not an iterable, an exception will be thrown. mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(args[ARG_characteristics].u_obj, &iter_buf); - mp_obj_t characteristic; + mp_obj_t characteristic_obj; // Copy the characteristics list and validate its items. - mp_obj_t char_list = mp_obj_new_list(0, NULL); - mp_obj_list_t *char_list_obj = MP_OBJ_FROM_PTR(char_list); + mp_obj_t char_list_obj = mp_obj_new_list(0, NULL); + mp_obj_list_t *char_list = MP_OBJ_FROM_PTR(char_list); - while ((characteristic = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { - if (!MP_OBJ_IS_TYPE(characteristic, &bleio_characteristic_type)) { + while ((characteristic_obj = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + if (!MP_OBJ_IS_TYPE(characteristic_obj, &bleio_characteristic_type)) { mp_raise_ValueError(translate("characteristics includes an object that is not a Characteristic")); } - bleio_characteristic_obj_t *characteristic_ptr = MP_OBJ_TO_PTR(characteristic); + bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(characteristic_obj); if (common_hal_bleio_uuid_get_uuid128_reference(uuid) != - common_hal_bleio_uuid_get_uuid128_reference(characteristic_ptr->uuid)) { + common_hal_bleio_uuid_get_uuid128_reference(characteristic->uuid)) { // The descriptor base UUID doesn't match the characteristic base UUID. mp_raise_ValueError(translate("Characteristic UUID doesn't match Service UUID")); } - mp_obj_list_append(char_list, characteristic); + mp_obj_list_append(char_list_obj, characteristic_obj); } - common_hal_bleio_service_construct(self, uuid_obj, char_list_obj, is_secondary); + common_hal_bleio_service_construct(self, uuid, char_list, is_secondary); return MP_OBJ_FROM_PTR(self); } From 140904ec84ad1900f280c1febaa89a499c42b8c5 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sat, 22 Jun 2019 22:10:15 -0400 Subject: [PATCH 16/61] getting Scanner to work --- ports/nrf/common-hal/bleio/Scanner.c | 17 +++++---- ports/nrf/common-hal/bleio/Scanner.h | 2 +- shared-bindings/bleio/Address.c | 53 ++++++++++++++++++++++++++-- shared-bindings/bleio/Address.h | 2 +- shared-bindings/bleio/ScanEntry.c | 19 +++++----- shared-bindings/bleio/ScanEntry.h | 2 +- shared-bindings/bleio/Scanner.c | 4 +-- shared-bindings/bleio/Scanner.h | 2 +- shared-bindings/bleio/UUID.c | 6 ++++ shared-module/bleio/Address.c | 8 ++--- shared-module/bleio/Address.h | 2 +- shared-module/bleio/ScanEntry.c | 8 ++--- shared-module/bleio/ScanEntry.h | 2 +- 13 files changed, 90 insertions(+), 37 deletions(-) diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index 6715bd7a28..04dc62f956 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -57,12 +57,15 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { entry->base.type = &bleio_scanentry_type; entry->rssi = report->rssi; - memcpy(entry->address.bytes, report->data.p_data, NUM_BLEIO_ADDRESS_BYTES); - entry->address.type = report->peer_addr.addr_type; + bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); + address->base.type = &bleio_address_type; + common_hal_bleio_address_construct(MP_OBJ_TO_PTR(address), + report->peer_addr.addr, report->peer_addr.addr_type); + entry->address = address; entry->data = mp_obj_new_bytes(report->data.p_data, report->data.len); - mp_obj_list_append(scanner->adv_reports, entry); + mp_obj_list_append(scanner->scan_entries, MP_OBJ_FROM_PTR(entry)); const uint32_t err_code = sd_ble_gap_scan_start(NULL, &m_scan_buffer); if (err_code != NRF_SUCCESS) { @@ -71,7 +74,7 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { } void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self) { - self->adv_reports = mp_obj_new_list(0, NULL); + self->scan_entries = mp_obj_new_list(0, NULL); } void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { @@ -85,7 +88,7 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout }; // Empty the advertising reports list. - mp_obj_list_clear(self->adv_reports); + mp_obj_list_clear(self->scan_entries); uint32_t err_code; err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); @@ -98,6 +101,6 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout sd_ble_gap_scan_stop(); } -mp_obj_t common_hal_bleio_scanner_get_adv_reports(bleio_scanner_obj_t *self) { - return self->adv_reports; +mp_obj_t common_hal_bleio_scanner_get_scan_entries(bleio_scanner_obj_t *self) { + return self->scan_entries; } diff --git a/ports/nrf/common-hal/bleio/Scanner.h b/ports/nrf/common-hal/bleio/Scanner.h index a710664877..3768a52cb8 100644 --- a/ports/nrf/common-hal/bleio/Scanner.h +++ b/ports/nrf/common-hal/bleio/Scanner.h @@ -32,7 +32,7 @@ typedef struct { mp_obj_base_t base; - mp_obj_t adv_reports; // List of reports. + mp_obj_t scan_entries; uint16_t interval; uint16_t window; } bleio_scanner_obj_t; diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index 5875cf9bd8..0e094c2e35 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -80,7 +80,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, mp_raise_ValueError(translate("Address type out of range")); } - common_hal_bleio_address_construct(self, buf_info.buf, buf_info.len, address_type); + common_hal_bleio_address_construct(self, buf_info.buf, address_type); return MP_OBJ_FROM_PTR(self); } @@ -101,6 +101,13 @@ STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_address_bytes_obj, bleio_address_get_address_bytes); +const mp_obj_property_t bleio_address_address_bytes_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&bleio_address_get_address_bytes_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + //| .. attribute:: type //| //| The address type (read-only). One of these integers: @@ -124,9 +131,47 @@ const mp_obj_property_t bleio_address_type_obj = { (mp_obj_t)&mp_const_none_obj}, }; +//| .. method:: __eq__(other) +//| +//| Two Address objects are equal if their addresses and address types are equal. +//| +STATIC mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { + switch (op) { + // Two Addresses are equal if their address bytes and address_type are equal + case MP_BINARY_OP_EQUAL: + if (MP_OBJ_IS_TYPE(rhs_in, &bleio_address_type)) { + bleio_address_obj_t *lhs = MP_OBJ_TO_PTR(lhs_in); + bleio_address_obj_t *rhs = MP_OBJ_TO_PTR(rhs_in); + return mp_obj_new_bool( + mp_obj_equal(common_hal_bleio_address_get_address_bytes(lhs), + common_hal_bleio_address_get_address_bytes(rhs)) && + common_hal_bleio_address_get_type(lhs) == + common_hal_bleio_address_get_type(rhs)); + + } else { + return mp_const_false; + } + + default: + return MP_OBJ_NULL; // op not supported + } +} + +STATIC void bleio_address_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_obj_t address_bytes = common_hal_bleio_address_get_address_bytes(self); + + mp_buffer_info_t buf_info; + mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ); + const uint8_t *buf = (uint8_t *) buf_info.buf; + mp_printf(print, + "%02x:%02x:%02x:%02x:%02x:%02x", + buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); +} + STATIC const mp_rom_map_elem_t bleio_address_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_get_address_bytes_obj) }, - { MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_get_type_obj) }, + { MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_address_bytes_obj) }, + { MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_type_obj) }, // These match the BLE_GAP_ADDR_TYPES values used by the nRF library. { MP_ROM_QSTR(MP_QSTR_PUBLIC), MP_OBJ_NEW_SMALL_INT(0) }, { MP_ROM_QSTR(MP_QSTR_RANDOM_STATIC), MP_OBJ_NEW_SMALL_INT(1) }, @@ -141,5 +186,7 @@ const mp_obj_type_t bleio_address_type = { { &mp_type_type }, .name = MP_QSTR_Address, .make_new = bleio_address_make_new, + .print = bleio_address_print, + .binary_op = bleio_address_binary_op, .locals_dict = (mp_obj_dict_t*)&bleio_address_locals_dict }; diff --git a/shared-bindings/bleio/Address.h b/shared-bindings/bleio/Address.h index bff1542cf0..5e02ee210f 100644 --- a/shared-bindings/bleio/Address.h +++ b/shared-bindings/bleio/Address.h @@ -41,7 +41,7 @@ extern const mp_obj_type_t bleio_address_type; -extern void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type); +extern void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, uint8_t address_type); extern mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self); extern uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self); diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index 145d2b0236..b7798175cc 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -62,19 +62,19 @@ const mp_obj_property_t bleio_scanentry_address_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| .. attribute:: raw_data +//| .. attribute:: advertisement_bytes //| //| All the advertisement data present in the packet, returned as a ``bytes`` object. (read-only) //| -STATIC mp_obj_t scanentry_get_raw_data(mp_obj_t self_in) { +STATIC mp_obj_t scanentry_get_advertisement_bytes(mp_obj_t self_in) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_bleio_scanentry_get_raw_data(self); + return common_hal_bleio_scanentry_get_advertisement_bytes(self); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_raw_data_obj, scanentry_get_raw_data); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_advertisement_bytes_obj, scanentry_get_advertisement_bytes); -const mp_obj_property_t bleio_scanentry_raw_data_obj = { +const mp_obj_property_t bleio_scanentry_advertisement_bytes_obj = { .base.type = &mp_type_property, - .proxy = { (mp_obj_t)&bleio_scanentry_get_raw_data_obj, + .proxy = { (mp_obj_t)&bleio_scanentry_get_advertisement_bytes_obj, (mp_obj_t)&mp_const_none_obj, (mp_obj_t)&mp_const_none_obj }, }; @@ -96,10 +96,11 @@ const mp_obj_property_t bleio_scanentry_rssi_obj = { (mp_obj_t)&mp_const_none_obj }, }; + STATIC const mp_rom_map_elem_t bleio_scanentry_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&bleio_scanentry_address_obj) }, - { MP_ROM_QSTR(MP_QSTR_raw_data), MP_ROM_PTR(&bleio_scanentry_raw_data_obj) }, - { MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bleio_scanentry_rssi_obj) }, + { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&bleio_scanentry_address_obj) }, + { MP_ROM_QSTR(MP_QSTR_advertisement_bytes), MP_ROM_PTR(&bleio_scanentry_advertisement_bytes_obj) }, + { MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bleio_scanentry_rssi_obj) }, }; STATIC MP_DEFINE_CONST_DICT(bleio_scanentry_locals_dict, bleio_scanentry_locals_dict_table); diff --git a/shared-bindings/bleio/ScanEntry.h b/shared-bindings/bleio/ScanEntry.h index 3a02f2facf..77e93175f9 100644 --- a/shared-bindings/bleio/ScanEntry.h +++ b/shared-bindings/bleio/ScanEntry.h @@ -35,7 +35,7 @@ extern const mp_obj_type_t bleio_scanentry_type; mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self); -mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self); +mp_obj_t common_hal_bleio_scanentry_get_advertisement_bytes(bleio_scanentry_obj_t *self); mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index 92f6a2a18b..d50f69fc5b 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -42,7 +42,7 @@ //| :class:`Scanner` -- scan for nearby BLE devices //| ========================================================= //| -//| Allows scanning for nearby BLE devices. +//| Scan for nearby BLE devices. //| //| Usage:: //| @@ -112,7 +112,7 @@ STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_m common_hal_bleio_scanner_scan(self, timeout, interval, window); - return common_hal_bleio_scanner_get_adv_reports(self); + return common_hal_bleio_scanner_get_scan_entries(self); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan); diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index b9e3ecdee5..1bbab78f4f 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -36,6 +36,6 @@ extern const mp_obj_type_t bleio_scanner_type; extern void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self); extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self); -extern mp_obj_t common_hal_bleio_scanner_get_adv_reports(bleio_scanner_obj_t *self); +extern mp_obj_t common_hal_bleio_scanner_get_scan_entries(bleio_scanner_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c index 9725050586..0db7435f44 100644 --- a/shared-bindings/bleio/UUID.c +++ b/shared-bindings/bleio/UUID.c @@ -220,6 +220,12 @@ STATIC mp_obj_t bleio_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } +//| + +//| .. method:: __eq__(other) +//| +//| Two UUID objects are equal if their values match and they are both 128-bit or both 16-bit. +//| STATIC mp_obj_t bleio_uuid_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { switch (op) { // Two UUID's are equal if their uuid16 values and uuid128 references match. diff --git a/shared-module/bleio/Address.c b/shared-module/bleio/Address.c index e26bbe2acb..6bc458b7cc 100644 --- a/shared-module/bleio/Address.c +++ b/shared-module/bleio/Address.c @@ -27,17 +27,17 @@ #include -#include "py/objproperty.h" +#include "py/objstr.h" #include "shared-bindings/bleio/Address.h" #include "shared-module/bleio/Address.h" -void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type) { - memcpy(self->bytes, bytes, bytes_length); +void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, uint8_t address_type) { + self->bytes = mp_obj_new_bytes(bytes, NUM_BLEIO_ADDRESS_BYTES); self->type = address_type; } mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self) { - return mp_obj_new_bytes(self->bytes, NUM_BLEIO_ADDRESS_BYTES); + return self->bytes; } uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self) { diff --git a/shared-module/bleio/Address.h b/shared-module/bleio/Address.h index eb1aab2581..39789842f7 100644 --- a/shared-module/bleio/Address.h +++ b/shared-module/bleio/Address.h @@ -35,7 +35,7 @@ typedef struct { mp_obj_base_t base; uint8_t type; - uint8_t bytes[NUM_BLEIO_ADDRESS_BYTES]; + mp_obj_t bytes; // a bytes() object } bleio_address_obj_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADDRESS_H diff --git a/shared-module/bleio/ScanEntry.c b/shared-module/bleio/ScanEntry.c index 44b50a4ce0..306ac33c58 100644 --- a/shared-module/bleio/ScanEntry.c +++ b/shared-module/bleio/ScanEntry.c @@ -33,14 +33,10 @@ #include "shared-module/bleio/ScanEntry.h" mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self) { - bleio_address_obj_t *address = m_new_obj(bleio_address_obj_t); - address->base.type = &bleio_address_type; - memcpy(address->bytes, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); - address->type = self->address.type; - return MP_OBJ_TO_PTR(address); + return MP_OBJ_FROM_PTR(self->address); } -mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self) { +mp_obj_t common_hal_bleio_scanentry_get_advertisement_bytes(bleio_scanentry_obj_t *self) { return self->data; } diff --git a/shared-module/bleio/ScanEntry.h b/shared-module/bleio/ScanEntry.h index 4e7028ba2a..b302460e67 100644 --- a/shared-module/bleio/ScanEntry.h +++ b/shared-module/bleio/ScanEntry.h @@ -35,7 +35,7 @@ typedef struct { mp_obj_base_t base; bool connectable; int8_t rssi; - bleio_address_obj_t address; + bleio_address_obj_t *address; mp_obj_t data; } bleio_scanentry_obj_t; From 48443c9c3fd3109edee22d6f698b1d135d035bb4 Mon Sep 17 00:00:00 2001 From: Alexander Hagerman Date: Tue, 25 Jun 2019 08:36:44 -0400 Subject: [PATCH 17/61] Update import statement in code snippet. The code snippets in the Design Guide article reference without the statement. --- docs/design_guide.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 2efbdc34c0..5d965f9074 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -60,6 +60,7 @@ For example, a user can then use ``deinit()```:: import digitalio import board + import time led = digitalio.DigitalInOut(board.D13) led.direction = digitalio.Direction.OUTPUT @@ -79,6 +80,7 @@ Alternatively, using a ``with`` statement ensures that the hardware is deinitial import digitalio import board + import time with digitalio.DigitalInOut(board.D13) as led: led.direction = digitalio.Direction.OUTPUT From 330517bde9d7b6a78583e42dfdf585118db40dfb Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Jun 2019 15:39:07 -0700 Subject: [PATCH 18/61] Validate portions of mpy load to detect corruption Fixes #1917 --- py/persistentcode.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/py/persistentcode.c b/py/persistentcode.c index f6de782ed8..c0358faa02 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -128,6 +128,12 @@ STATIC qstr load_qstr(mp_reader_t *reader) { size_t len = read_uint(reader); char str[len]; read_bytes(reader, (byte*)str, len); + // Validate the QSTRs by ensuring they do not contain any null terminations. They are length encoded instead. + for (size_t i = 0; i < len; i++) { + if (str[i] == '\0') { + mp_raise_RuntimeError(translate("Corrupt .mpy file")); + } + } qstr qst = qstr_from_strn(str, len); return qst; } @@ -145,11 +151,12 @@ STATIC mp_obj_t load_obj(mp_reader_t *reader) { return mp_obj_new_str_from_vstr(obj_type == 's' ? &mp_type_str : &mp_type_bytes, &vstr); } else if (obj_type == 'i') { return mp_parse_num_integer(vstr.buf, vstr.len, 10, NULL); - } else { - assert(obj_type == 'f' || obj_type == 'c'); + } else if (obj_type == 'f' || obj_type == 'c') { return mp_parse_num_decimal(vstr.buf, vstr.len, obj_type == 'c', false, NULL); } } + mp_raise_RuntimeError(translate("Corrupt .mpy file")); + return MP_OBJ_FROM_PTR(&mp_const_none_obj); } STATIC void load_bytecode_qstrs(mp_reader_t *reader, byte *ip, byte *ip_top) { From 77355cbb2f5a3cc2b48468955774a830f18ecf39 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Jun 2019 16:52:52 -0700 Subject: [PATCH 19/61] Update translations --- locale/ID.po | 6 +++++- locale/circuitpython.pot | 6 +++++- locale/de_DE.po | 6 +++++- locale/en_US.po | 6 +++++- locale/en_x_pirate.po | 6 +++++- locale/es.po | 6 +++++- locale/fil.po | 6 +++++- locale/fr.po | 6 +++++- locale/it_IT.po | 6 +++++- locale/pl.po | 6 +++++- locale/pt_BR.po | 6 +++++- locale/zh_Latn_pinyin.po | 6 +++++- 12 files changed, 60 insertions(+), 12 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index f5c0c09495..9545845cd9 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -460,6 +460,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 34070dc69b..7e9f655817 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:41-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -450,6 +450,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/de_DE.po b/locale/de_DE.po index 2cb97c3d31..5e948cb6b6 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -454,6 +454,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "Der Befehl muss ein int zwischen 0 und 255 sein" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/en_US.po b/locale/en_US.po index ebc18cfaee..a50263d9fe 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -450,6 +450,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 04706abdcd..443204fb57 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -454,6 +454,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/es.po b/locale/es.po index 77739f49cb..2135b7e77f 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -466,6 +466,10 @@ msgstr "La entrada en la columna debe ser digitalio.DigitalInOut" msgid "Command must be an int between 0 and 255" msgstr "Bytes debe estar entre 0 y 255." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/fil.po b/locale/fil.po index 5954e29b49..8f3996d16a 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -459,6 +459,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "Sa gitna ng 0 o 255 dapat ang bytes." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/fr.po b/locale/fr.po index 0bd0f8771e..6ee7b4d5a1 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -465,6 +465,10 @@ msgstr "L'entrée 'Column' doit être un digitalio.DigitalInOut" msgid "Command must be an int between 0 and 255" msgstr "La commande doit être un entier entre 0 et 255" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/it_IT.po b/locale/it_IT.po index 12f21c38ea..ef1e306a1e 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -460,6 +460,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "I byte devono essere compresi tra 0 e 255" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/pl.po b/locale/pl.po index 1a7471f728..09187eb671 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -453,6 +453,10 @@ msgstr "Kolumny muszą być typu digitalio.DigitalInOut" msgid "Command must be an int between 0 and 255" msgstr "Komenda musi być int pomiędzy 0 a 255" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 390610041e..734491dd75 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -456,6 +456,10 @@ msgstr "" msgid "Command must be an int between 0 and 255" msgstr "Os bytes devem estar entre 0 e 255." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 82264cb526..8ad03c968f 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-05-13 17:34-0700\n" +"POT-Creation-Date: 2019-06-25 16:50-0700\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -454,6 +454,10 @@ msgstr "Liè tiáomù bìxū shì digitalio.DigitalInOut" msgid "Command must be an int between 0 and 255" msgstr "Mìnglìng bìxū shì 0 dào 255 zhī jiān de int" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" From 2494bfdc8626aadb7d3197d165daf2569f3a8db1 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Jun 2019 17:54:27 -0700 Subject: [PATCH 20/61] Validate raw code and mpy read length --- locale/ID.po | 6 +++++- locale/circuitpython.pot | 6 +++++- locale/de_DE.po | 6 +++++- locale/en_US.po | 6 +++++- locale/en_x_pirate.po | 6 +++++- locale/es.po | 6 +++++- locale/fil.po | 6 +++++- locale/fr.po | 6 +++++- locale/it_IT.po | 6 +++++- locale/pl.po | 6 +++++- locale/pt_BR.po | 6 +++++- locale/zh_Latn_pinyin.po | 6 +++++- py/emitglue.c | 7 ++++--- py/persistentcode.c | 29 +++++++++++++++++++---------- 14 files changed, 83 insertions(+), 25 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 9545845cd9..60d882bc60 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -464,6 +464,10 @@ msgstr "" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 7e9f655817..1c48658ec7 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -454,6 +454,10 @@ msgstr "" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/de_DE.po b/locale/de_DE.po index 5e948cb6b6..2b3b25ce7c 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -458,6 +458,10 @@ msgstr "Der Befehl muss ein int zwischen 0 und 255 sein" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/en_US.po b/locale/en_US.po index a50263d9fe..1b5c360109 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -454,6 +454,10 @@ msgstr "" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 443204fb57..12a134a7dc 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -458,6 +458,10 @@ msgstr "" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/es.po b/locale/es.po index 2135b7e77f..63dae87de0 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -470,6 +470,10 @@ msgstr "Bytes debe estar entre 0 y 255." msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/fil.po b/locale/fil.po index 8f3996d16a..393c67ad13 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -463,6 +463,10 @@ msgstr "Sa gitna ng 0 o 255 dapat ang bytes." msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/fr.po b/locale/fr.po index 6ee7b4d5a1..a64deeace7 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -469,6 +469,10 @@ msgstr "La commande doit être un entier entre 0 et 255" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/it_IT.po b/locale/it_IT.po index ef1e306a1e..52c229e030 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -464,6 +464,10 @@ msgstr "I byte devono essere compresi tra 0 e 255" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/pl.po b/locale/pl.po index 09187eb671..bdb6f47958 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -457,6 +457,10 @@ msgstr "Komenda musi być int pomiędzy 0 a 255" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 734491dd75..8b61c23b81 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -460,6 +460,10 @@ msgstr "Os bytes devem estar entre 0 e 255." msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 8ad03c968f..314591560a 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-25 16:50-0700\n" +"POT-Creation-Date: 2019-06-25 17:53-0700\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -458,6 +458,10 @@ msgstr "Mìnglìng bìxū shì 0 dào 255 zhī jiān de int" msgid "Corrupt .mpy file" msgstr "" +#: py/emitglue.c +msgid "Corrupt raw code" +msgstr "" + #: ports/nrf/common-hal/bleio/UUID.c #, c-format msgid "Could not decode ble_uuid, err 0x%04x" diff --git a/py/emitglue.c b/py/emitglue.c index 74bf8ddca2..7708689dd4 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -142,11 +142,12 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar fun = mp_obj_new_fun_asm(rc->n_pos_args, rc->data.u_native.fun_data, rc->data.u_native.type_sig); break; #endif - default: - // rc->kind should always be set and BYTECODE is the only remaining case - assert(rc->kind == MP_CODE_BYTECODE); + case MP_CODE_BYTECODE: fun = mp_obj_new_fun_bc(def_args, def_kw_args, rc->data.u_byte.bytecode, rc->data.u_byte.const_table); break; + default: + // All other kinds are invalid. + mp_raise_RuntimeError(translate("Corrupt raw code")); } // check for generator functions and if so wrap in generator object diff --git a/py/persistentcode.c b/py/persistentcode.c index c0358faa02..eb69bd4079 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -102,20 +102,35 @@ STATIC void extract_prelude(const byte **ip, const byte **ip2, bytecode_prelude_ #include "py/parsenum.h" +STATIC void raise_corrupt_mpy(void) { + mp_raise_RuntimeError(translate("Corrupt .mpy file")); +} + STATIC int read_byte(mp_reader_t *reader) { - return reader->readbyte(reader->data); + mp_uint_t b = reader->readbyte(reader->data); + if (b == MP_READER_EOF) { + raise_corrupt_mpy(); + } + return b; } STATIC void read_bytes(mp_reader_t *reader, byte *buf, size_t len) { while (len-- > 0) { - *buf++ = reader->readbyte(reader->data); + mp_uint_t b =reader->readbyte(reader->data); + if (b == MP_READER_EOF) { + raise_corrupt_mpy(); + } + *buf++ = b; } } STATIC size_t read_uint(mp_reader_t *reader) { size_t unum = 0; for (;;) { - byte b = reader->readbyte(reader->data); + mp_uint_t b = reader->readbyte(reader->data); + if (b == MP_READER_EOF) { + raise_corrupt_mpy(); + } unum = (unum << 7) | (b & 0x7f); if ((b & 0x80) == 0) { break; @@ -128,12 +143,6 @@ STATIC qstr load_qstr(mp_reader_t *reader) { size_t len = read_uint(reader); char str[len]; read_bytes(reader, (byte*)str, len); - // Validate the QSTRs by ensuring they do not contain any null terminations. They are length encoded instead. - for (size_t i = 0; i < len; i++) { - if (str[i] == '\0') { - mp_raise_RuntimeError(translate("Corrupt .mpy file")); - } - } qstr qst = qstr_from_strn(str, len); return qst; } @@ -155,7 +164,7 @@ STATIC mp_obj_t load_obj(mp_reader_t *reader) { return mp_parse_num_decimal(vstr.buf, vstr.len, obj_type == 'c', false, NULL); } } - mp_raise_RuntimeError(translate("Corrupt .mpy file")); + raise_corrupt_mpy(); return MP_OBJ_FROM_PTR(&mp_const_none_obj); } From 6d2072f9cb3385eb6d69ac876d9d415a4e41e062 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 26 Jun 2019 11:02:18 -0700 Subject: [PATCH 21/61] Fix tests --- tests/import/mpy_invalid.py | 4 ++-- tests/import/mpy_invalid.py.exp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/import/mpy_invalid.py b/tests/import/mpy_invalid.py index 6a4e116e78..b9dd99a440 100644 --- a/tests/import/mpy_invalid.py +++ b/tests/import/mpy_invalid.py @@ -59,8 +59,8 @@ for i in range(len(user_files)): mod = 'mod%u' % i try: __import__(mod) - except ValueError as er: - print(mod, 'ValueError', er) + except Exception as e: + print(mod, type(e).__name__, e) # unmount and undo path addition uos.umount('/userfs') diff --git a/tests/import/mpy_invalid.py.exp b/tests/import/mpy_invalid.py.exp index e4f2b13e99..197eb4f7b2 100644 --- a/tests/import/mpy_invalid.py.exp +++ b/tests/import/mpy_invalid.py.exp @@ -1,3 +1,3 @@ -mod0 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. -mod1 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. -mod2 ValueError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. +mod0 RuntimeError Corrupt .mpy file +mod1 RuntimeError Corrupt .mpy file +mod2 MpyError Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info. From 6785e0259faee64b823eeae32ee4e4883eaf8b81 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 26 Jun 2019 11:14:45 -0700 Subject: [PATCH 22/61] Add keep alive to Travis deploy Some deploys take over 10 minutes and Travis kills the job. This workaround is from https://github.com/travis-ci/dpl/issues/568 --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1702089c37..b2fb016989 100755 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,16 @@ addons: - $(ls -d1 bin/*/*/* | tr "\n" ":") target_paths: / +# Some deploy jobs take over 10 minutes so use this keep alive hack to make sure Travis doesn't kill us. +before_deploy: | + function keep_alive() { + while true; do + echo -en "\a" + sleep 5 + done + } + keep_alive & + deploy: provider: releases api_key: From 1f105e0ac0313be9752f68c664c145ca5156a1e9 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 26 Jun 2019 15:10:51 -0700 Subject: [PATCH 23/61] Update frozen libraries to save space --- frozen/Adafruit_CircuitPython_BusDevice | 2 +- frozen/Adafruit_CircuitPython_CircuitPlayground | 2 +- frozen/Adafruit_CircuitPython_HID | 2 +- frozen/Adafruit_CircuitPython_LIS3DH | 2 +- frozen/Adafruit_CircuitPython_Motor | 2 +- frozen/Adafruit_CircuitPython_seesaw | 2 +- frozen/circuitpython-stage | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frozen/Adafruit_CircuitPython_BusDevice b/frozen/Adafruit_CircuitPython_BusDevice index 182eebdc81..b9280af514 160000 --- a/frozen/Adafruit_CircuitPython_BusDevice +++ b/frozen/Adafruit_CircuitPython_BusDevice @@ -1 +1 @@ -Subproject commit 182eebdc8168e3d14cd0cb28db3abb734c9e45f3 +Subproject commit b9280af5142fc41639229544678e23b5cca07c3a diff --git a/frozen/Adafruit_CircuitPython_CircuitPlayground b/frozen/Adafruit_CircuitPython_CircuitPlayground index 0cc2e975ed..154b74de02 160000 --- a/frozen/Adafruit_CircuitPython_CircuitPlayground +++ b/frozen/Adafruit_CircuitPython_CircuitPlayground @@ -1 +1 @@ -Subproject commit 0cc2e975ed22ace0d679c6fb8f3388034b88bcf1 +Subproject commit 154b74de020764597ba49f0d1e8cc18d55b3643b diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index c9e07857dc..89faee0eb0 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit c9e07857dc10ff5e6c743e5e8c00e9b049800d09 +Subproject commit 89faee0eb08a6855e14f117c514fecf2dd90769d diff --git a/frozen/Adafruit_CircuitPython_LIS3DH b/frozen/Adafruit_CircuitPython_LIS3DH index f5892e24f7..bd7ddc67dc 160000 --- a/frozen/Adafruit_CircuitPython_LIS3DH +++ b/frozen/Adafruit_CircuitPython_LIS3DH @@ -1 +1 @@ -Subproject commit f5892e24f7235c4bde2908cbb3cd0a3d6b34d421 +Subproject commit bd7ddc67dc86f7ad0115f58ab80d5605739c6482 diff --git a/frozen/Adafruit_CircuitPython_Motor b/frozen/Adafruit_CircuitPython_Motor index 5a50830814..ddc7484498 160000 --- a/frozen/Adafruit_CircuitPython_Motor +++ b/frozen/Adafruit_CircuitPython_Motor @@ -1 +1 @@ -Subproject commit 5a50830814aaeeb1fda34ed0ba2f8397415d9796 +Subproject commit ddc74844983b35b027bd45091c7b8bb3c8d7a2d1 diff --git a/frozen/Adafruit_CircuitPython_seesaw b/frozen/Adafruit_CircuitPython_seesaw index 4b101f0032..f1171f9408 160000 --- a/frozen/Adafruit_CircuitPython_seesaw +++ b/frozen/Adafruit_CircuitPython_seesaw @@ -1 +1 @@ -Subproject commit 4b101f00320d36b23f8cc28cf3f12127085894c1 +Subproject commit f1171f94083ba64d153ff3f90eeb07500331d6e1 diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage index 397badae58..6d1ae72916 160000 --- a/frozen/circuitpython-stage +++ b/frozen/circuitpython-stage @@ -1 +1 @@ -Subproject commit 397badae5863a1ce932213ef527e82314ac498a1 +Subproject commit 6d1ae72916cf240ea86185c45f844d59f56d8ec3 From fe507db45f7fa21c6de4aafb288a7f83d9903f71 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 26 Jun 2019 16:49:23 -0700 Subject: [PATCH 24/61] Shrink pIRkey build down. Rollback HID to save string space and remove board mapping for default buses that don't exist. --- frozen/Adafruit_CircuitPython_HID | 2 +- ports/atmel-samd/boards/pirkey_m0/pins.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index 89faee0eb0..c9e07857dc 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit 89faee0eb08a6855e14f117c514fecf2dd90769d +Subproject commit c9e07857dc10ff5e6c743e5e8c00e9b049800d09 diff --git a/ports/atmel-samd/boards/pirkey_m0/pins.c b/ports/atmel-samd/boards/pirkey_m0/pins.c index e1f43c83cc..41d02e3291 100644 --- a/ports/atmel-samd/boards/pirkey_m0/pins.c +++ b/ports/atmel-samd/boards/pirkey_m0/pins.c @@ -5,8 +5,5 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) }, - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 2004be96acf1a29fd312362f84dbf86461f0500f Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 26 Jun 2019 17:36:30 -0700 Subject: [PATCH 25/61] Properly reset the terminal each init. Fixes #1944 --- supervisor/shared/display.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index c3afb3e008..414f850344 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -71,6 +71,8 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { if (tiles == NULL) { return; } + grid->y = 0; + grid->top_left_y = 0; if (remaining_pixels > 0) { grid->y -= (grid->tile_height - remaining_pixels); } From 6ea01ea9b0334a175419f9d449be25a5838627da Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sat, 29 Jun 2019 00:20:06 -0400 Subject: [PATCH 26/61] Central is connecting; characteristics can be read and written --- ports/nrf/Makefile | 2 +- ports/nrf/common-hal/bleio/Central.c | 151 +++++++++++--------- ports/nrf/common-hal/bleio/Central.h | 3 +- ports/nrf/common-hal/bleio/Characteristic.c | 10 +- ports/nrf/common-hal/bleio/Scanner.c | 4 +- shared-bindings/bleio/Central.c | 59 +++++--- shared-bindings/bleio/Central.h | 4 +- shared-bindings/bleio/Characteristic.c | 17 ++- shared-bindings/bleio/Peripheral.c | 4 +- shared-bindings/bleio/Service.c | 17 ++- shared-bindings/bleio/UUID.c | 3 + shared-bindings/bleio/__init__.c | 5 +- 12 files changed, 182 insertions(+), 97 deletions(-) diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 18990485b4..83f87536bd 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -91,7 +91,7 @@ INC += -I../../supervisor/shared/usb ifeq ($(DEBUG), 1) CFLAGS += -ggdb # You may want to enable these flags to make setting breakpoints easier. - # CFLAGS += -fno-inline -fno-ipa-sra + CFLAGS += -fno-inline -fno-ipa-sra else CFLAGS += -Os -DNDEBUG # TODO: Test with -flto diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index 5864a8a56f..0eedd2b568 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -44,11 +44,13 @@ static bleio_service_obj_t *m_char_discovery_service; static volatile bool m_discovery_in_process; static volatile bool m_discovery_successful; -STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_handle) { +// service_uuid may be NULL, to discover all services. +STATIC bool discover_next_services(bleio_central_obj_t *self, uint16_t start_handle, ble_uuid_t *service_uuid) { m_discovery_successful = false; m_discovery_in_process = true; - uint32_t err_code = sd_ble_gattc_primary_services_discover(self->conn_handle, start_handle, NULL); + uint32_t err_code = sd_ble_gattc_primary_services_discover(self->conn_handle, start_handle, service_uuid); + if (err_code != NRF_SUCCESS) { mp_raise_OSError_msg(translate("Failed to discover services")); } @@ -88,15 +90,26 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); service->base.type = &bleio_service_type; + service->device = MP_OBJ_FROM_PTR(central); service->characteristic_list = mp_obj_new_list(0, NULL); service->start_handle = gattc_service->handle_range.start_handle; service->end_handle = gattc_service->handle_range.end_handle; service->handle = gattc_service->handle_range.start_handle; - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); - bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid); - service->uuid = uuid; + if (gattc_service->uuid.type != BLE_UUID_TYPE_UNKNOWN) { + // Known service UUID. + bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + uuid->base.type = &bleio_uuid_type; + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_service->uuid); + service->uuid = uuid; + service->device = MP_OBJ_FROM_PTR(central); + } else { + // The discovery response contained a 128-bit UUID that has not yet been registered with the + // softdevice via sd_ble_uuid_vs_add(). We need to fetch the 128-bit value and register it. + // For now, just set the UUID to NULL. + service->uuid = NULL; + } mp_obj_list_append(central->service_list, service); } @@ -114,10 +127,18 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); characteristic->base.type = &bleio_characteristic_type; - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); - uuid->base.type = &bleio_uuid_type; - bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); - characteristic->uuid = uuid; + if (gattc_char->uuid.type != BLE_UUID_TYPE_UNKNOWN) { + // Known characteristic UUID. + bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + uuid->base.type = &bleio_uuid_type; + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); + characteristic->uuid = uuid; + } else { + // The discovery response contained a 128-bit UUID that has not yet been registered with the + // softdevice via sd_ble_uuid_vs_add(). We need to fetch the 128-bit value and register it. + // For now, just set the UUID to NULL. + characteristic->uuid = NULL; + } characteristic->props.broadcast = gattc_char->char_props.broadcast; characteristic->props.indicate = gattc_char->char_props.indicate; @@ -137,25 +158,18 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio m_discovery_in_process = false; } -STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { +STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { bleio_central_obj_t *central = (bleio_central_obj_t*)central_in; switch (ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: - { - ble_gap_conn_params_t conn_params; central->conn_handle = ble_evt->evt.gap_evt.conn_handle; - - sd_ble_gap_ppcp_get(&conn_params); - sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); + central->waiting_to_connect = false; break; - } case BLE_GAP_EVT_TIMEOUT: - if (central->attempting_to_connect) { - // Signal that connection attempt has timed out. - central->attempting_to_connect = false; - } + // Handle will be invalid. + central->waiting_to_connect = false; break; case BLE_GAP_EVT_DISCONNECTED: @@ -172,14 +186,6 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); break; - case BLE_GATTS_EVT_SYS_ATTR_MISSING: - sd_ble_gatts_sys_attr_set(ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0); - break; - - case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: - sd_ble_gatts_exchange_mtu_reply(central->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); - break; - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); break; @@ -193,7 +199,7 @@ STATIC void on_ble_evt(ble_evt_t *ble_evt, void *central_in) { } } -void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address_obj_t *address) { +void common_hal_bleio_central_construct(bleio_central_obj_t *self) { common_hal_bleio_adapter_set_enabled(true); self->service_list = mp_obj_new_list(0, NULL); @@ -201,13 +207,16 @@ void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address self->conn_handle = BLE_CONN_HANDLE_INVALID; } -void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout) { +void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_obj_t *address, mp_float_t timeout, mp_obj_t service_uuids) { common_hal_bleio_adapter_set_enabled(true); - ble_drv_add_event_handler(on_ble_evt, self); + ble_drv_add_event_handler(central_on_ble_evt, self); ble_gap_addr_t addr; - addr.addr_type = self->address.type; - memcpy(addr.addr, self->address.bytes, NUM_BLEIO_ADDRESS_BYTES); + + addr.addr_type = address->type; + mp_buffer_info_t address_buf_info; + mp_get_buffer_raise(address->bytes, &address_buf_info, MP_BUFFER_READ); + memcpy(addr.addr, (uint8_t *) address_buf_info.buf, NUM_BLEIO_ADDRESS_BYTES); ble_gap_scan_params_t scan_params = { .interval = MSEC_TO_UNITS(100, UNIT_0_625_MS), @@ -224,7 +233,7 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time .slave_latency = 0, // number of conn events }; - self->attempting_to_connect = true; + self->waiting_to_connect = true; uint32_t err_code = sd_ble_gap_connect(&addr, &scan_params, &conn_params, BLE_CONN_CFG_TAG_CUSTOM); @@ -232,50 +241,68 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time mp_raise_OSError_msg_varg(translate("Failed to start connecting, error 0x%04x"), err_code); } - while (self->conn_handle == BLE_CONN_HANDLE_INVALID && self->attempting_to_connect) { - #ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP - #endif + while (self->waiting_to_connect) { + MICROPY_VM_HOOK_LOOP; } - if (!self->attempting_to_connect) { + if (self->conn_handle == BLE_CONN_HANDLE_INVALID) { mp_raise_OSError_msg(translate("Failed to connect: timeout")); } - // Conenction successful. - // Now discover all services on the remote peripheral. Ask for services repeatedly - // until no more are left. + // Connection successful. + // Now discover services on the remote peripheral. - uint16_t next_start_handle; + if (service_uuids == mp_const_none) { - next_start_handle = BLE_GATT_HANDLE_START; + // List of service UUID's not given, so discover all available services. - while (1) { - if(!discover_next_services(self, next_start_handle)) { - break; + uint16_t next_start_handle = BLE_GATT_HANDLE_START; + + while (discover_next_services(self, next_start_handle, MP_OBJ_NULL)) { + // discover_next_services() appends to service_list. + const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + + // Get the most recently discovered service, and then ask for services + // whose handles start after the last attribute handle inside that service. + const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; + next_start_handle = service->end_handle + 1; } + } else { + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(service_uuids, &iter_buf); + mp_obj_t uuid_obj; + while ((uuid_obj = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + if (!MP_OBJ_IS_TYPE(uuid_obj, &bleio_uuid_type)) { + mp_raise_ValueError(translate("non-UUID found in service_uuids")); + } + bleio_uuid_obj_t *uuid = MP_OBJ_TO_PTR(uuid_obj); - // discover_next_services() appends to service_list. - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); + ble_uuid_t nrf_uuid; + bleio_uuid_convert_to_nrf_ble_uuid(uuid, &nrf_uuid); - // Get the most recently discovered service, and ask for services with handles - // starting after the last attribute handle of t - const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; - next_start_handle = service->end_handle + 1; + // Service might or might not be discovered; that's ok. Caller has to check + // Central.remote_services to find out. + // We only need to call this once for each service to discover. + discover_next_services(self, BLE_GATT_HANDLE_START, &nrf_uuid); + } } - // Now, for each service, discover its characteristics. - // find characteristics in each service + const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); for (size_t i = 0; i < service_list->len; ++i) { bleio_service_obj_t *service = service_list->items[i]; - next_start_handle = service->start_handle; + // Skip the service if it had an unknown (unregistered) UUID. + if (service->uuid == NULL) { + continue; + } - while (1) { - if (!discover_next_characteristics(self, service, service->start_handle)) { - break; - } + uint16_t next_start_handle = service->start_handle; + + // Stop when we go past the end of the range of handles for this service or + // discovery call returns nothing. + while (next_start_handle <= service->end_handle && + discover_next_characteristics(self, service, next_start_handle)) { // discover_next_characteristics() appends to the characteristic_list. const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); @@ -284,10 +311,6 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t time const bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_list->len - 1]; next_start_handle = characteristic->handle + 1; - if (next_start_handle >= service->end_handle) { - // Went past the end of the range of handles for this service. - break; - } } } } diff --git a/ports/nrf/common-hal/bleio/Central.h b/ports/nrf/common-hal/bleio/Central.h index ba4a92187b..8b38e87ac0 100644 --- a/ports/nrf/common-hal/bleio/Central.h +++ b/ports/nrf/common-hal/bleio/Central.h @@ -36,8 +36,7 @@ typedef struct { mp_obj_base_t base; gatt_role_t gatt_role; - bleio_address_obj_t address; - volatile bool attempting_to_connect; + volatile bool waiting_to_connect; volatile uint16_t conn_handle; mp_obj_t service_list; } bleio_central_obj_t; diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index d2f961fe65..ea43d8a8ab 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -60,7 +60,7 @@ STATIC uint16_t get_cccd(bleio_characteristic_obj_t *characteristic) { } STATIC void gatts_read(bleio_characteristic_obj_t *characteristic) { - // This might be BLE_CONN_HANDLE_INVALID if we're not conected, but that's OK, because + // This might be BLE_CONN_HANDLE_INVALID if we're not connected, but that's OK, because // we can still read and write the local value. const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); @@ -135,8 +135,15 @@ STATIC void gatts_notify_indicate(bleio_characteristic_obj_t *characteristic, mp } +STATIC void check_connected(uint16_t conn_handle) { + if (conn_handle == BLE_CONN_HANDLE_INVALID) { + mp_raise_OSError_msg(translate("Not connected")); + } +} + STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) { const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); + check_connected(conn_handle); m_read_characteristic = characteristic; @@ -152,6 +159,7 @@ STATIC void gattc_read(bleio_characteristic_obj_t *characteristic) { STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_info_t *bufinfo) { const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(characteristic->service->device); + check_connected(conn_handle); ble_gattc_write_params_t write_params = { .flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL, diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index 04dc62f956..fa4f3923c8 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -45,7 +45,7 @@ static ble_data_t m_scan_buffer = { BLE_GAP_SCAN_BUFFER_MIN }; -STATIC void on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { +STATIC void scanner_on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { bleio_scanner_obj_t *scanner = (bleio_scanner_obj_t*)scanner_in; ble_gap_evt_adv_report_t *report = &ble_evt->evt.gap_evt.params.adv_report; @@ -79,7 +79,7 @@ void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self) { void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { common_hal_bleio_adapter_set_enabled(true); - ble_drv_add_event_handler(on_ble_evt, self); + ble_drv_add_event_handler(scanner_on_ble_evt, self); ble_gap_scan_params_t scan_params = { .interval = SEC_TO_UNITS(interval, UNIT_0_625_MS), diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index b3be906067..dd2dd0d50f 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -64,43 +64,68 @@ //| central.connect(10.0) # timeout after 10 seconds //| -//| .. class:: Central(address) +//| .. class:: Central() //| //| Create a new Central object. -//| :param bleio.Address address: The address of the central to connect to //| STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); + mp_arg_check_num(n_args, kw_args, 0, 0, false); bleio_central_obj_t *self = m_new_obj(bleio_central_obj_t); self->base.type = &bleio_central_type; - const mp_obj_t address_obj = pos_args[0]; - if (!MP_OBJ_IS_TYPE(address_obj, &bleio_address_type)) { - mp_raise_ValueError(translate("Expected an Address")); - } - - bleio_address_obj_t *address = MP_OBJ_TO_PTR(address_obj); - common_hal_bleio_central_construct(self, address); + common_hal_bleio_central_construct(self); return MP_OBJ_FROM_PTR(self); } -//| .. method:: connect() -//| +//| .. method:: connect(address, timeout, *, service_uuids=None) //| Attempts a connection to the remote peripheral. If the connection is successful, +//| Do BLE discovery for the listed services, to find their handles and characteristics. +//| The attribute `remote_services` will contain a list of all discovered services. //| -STATIC mp_obj_t bleio_central_connect(mp_obj_t self_in, mp_obj_t timeout_in) { - bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); +//| :param bleio.Address address: The address of the peripheral to connect to +//| :param float/int timeout: Try to connect for timeout seconds. +//| :param iterable service_uuids: a collection of `UUID` objects for the services +//| provided by the peripheral that you want to use. +//| The peripheral may provide more services, but services not listed are ignored. +//| If a service in `service_uuids` is not found during discovery, it will not +//| appear in `remote_services`. +//| +//| If `services` is None, then all services will undergo discovery, which can be slow. +//| +//| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you +//| you must have already created a `UUID` object for that UUID in order for the +//| service or characteristic to be discovered. (This restriction may be lifted in the future.) +//| +STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - mp_float_t timeout = mp_obj_float_get(timeout_in); - common_hal_bleio_central_connect(self, timeout); + enum { ARG_address, ARG_timeout, ARG_service_uuids }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_address, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_timeout, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_service_uuids, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + if (!MP_OBJ_IS_TYPE(args[ARG_address].u_obj, &bleio_address_type)) { + mp_raise_ValueError(translate("Expected an Address")); + } + + bleio_address_obj_t *address = MP_OBJ_TO_PTR(args[ARG_address].u_obj); + mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); + + // common_hal_bleio_central_connect() will validate that services is an iterable or None. + common_hal_bleio_central_connect(self, address, timeout, args[ARG_service_uuids].u_obj); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_central_connect_obj, bleio_central_connect); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_central_connect_obj, 3, bleio_central_connect); //| .. method:: disconnect() diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h index c6fb50bc0c..542ba8fa2f 100644 --- a/shared-bindings/bleio/Central.h +++ b/shared-bindings/bleio/Central.h @@ -33,8 +33,8 @@ extern const mp_obj_type_t bleio_central_type; -extern void common_hal_bleio_central_construct(bleio_central_obj_t *self, bleio_address_obj_t *address); -extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, mp_float_t timeout); +extern void common_hal_bleio_central_construct(bleio_central_obj_t *self); +extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_obj_t *address, mp_float_t timeout, mp_obj_t service_uuids); extern void common_hal_bleio_central_disconnect(bleio_central_obj_t *self); extern mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index 050992bb86..ede38c86b3 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -205,11 +205,13 @@ const mp_obj_property_t bleio_characteristic_write_no_response_obj = { //| .. attribute:: uuid //| //| The UUID of this characteristic. (read-only) +//| Will be ``None`` if the 128-bit UUID for this characteristic is not known. //| STATIC mp_obj_t bleio_characteristic_get_uuid(mp_obj_t self_in) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(common_hal_bleio_characteristic_get_uuid(self)); + bleio_uuid_obj_t *uuid = common_hal_bleio_characteristic_get_uuid(self); + return uuid ? MP_OBJ_FROM_PTR(uuid) : mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_uuid_obj, bleio_characteristic_get_uuid); @@ -262,12 +264,23 @@ STATIC const mp_rom_map_elem_t bleio_characteristic_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&bleio_characteristic_write_obj) }, { MP_ROM_QSTR(MP_QSTR_write_no_response), MP_ROM_PTR(&bleio_characteristic_write_no_response_obj) }, }; - STATIC MP_DEFINE_CONST_DICT(bleio_characteristic_locals_dict, bleio_characteristic_locals_dict_table); +STATIC void bleio_characteristic_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "Characteristic("); + if (self->uuid) { + bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + } else { + mp_printf(print, "Unregistered uUID"); + } + mp_printf(print, ")"); +} + const mp_obj_type_t bleio_characteristic_type = { { &mp_type_type }, .name = MP_QSTR_Characteristic, .make_new = bleio_characteristic_make_new, + .print = bleio_characteristic_print, .locals_dict = (mp_obj_dict_t*)&bleio_characteristic_locals_dict }; diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 002999b5d6..37a765ae9c 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -113,7 +113,7 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar mp_obj_t service; while ((service = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (!MP_OBJ_IS_TYPE(service, &bleio_service_type)) { - mp_raise_ValueError(translate("services includes an object that is not a Service")); + mp_raise_ValueError(translate("non-Service found in services")); } mp_obj_list_append(service_list, service); } @@ -237,7 +237,7 @@ STATIC mp_obj_t bleio_peripheral_start_advertising(mp_uint_t n_args, const mp_ob return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_peripheral_start_advertising_obj, 0, bleio_peripheral_start_advertising); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_peripheral_start_advertising_obj, 2, bleio_peripheral_start_advertising); //| .. method:: stop_advertising() //| diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index e687019d14..e6bb7dcc3f 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -140,11 +140,13 @@ const mp_obj_property_t bleio_service_secondary_obj = { //| .. attribute:: uuid //| //| The UUID of this service. (read-only) +//| Will be ``None`` if the 128-bit UUID for this service is not known. //| STATIC mp_obj_t bleio_service_get_uuid(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(common_hal_bleio_service_get_uuid(self)); + bleio_uuid_obj_t *uuid = common_hal_bleio_service_get_uuid(self); + return uuid ? MP_OBJ_FROM_PTR(uuid) : mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_service_get_uuid_obj, bleio_service_get_uuid); @@ -160,12 +162,23 @@ STATIC const mp_rom_map_elem_t bleio_service_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_secondary), MP_ROM_PTR(&bleio_service_secondary_obj) }, { MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_service_uuid_obj) }, }; - STATIC MP_DEFINE_CONST_DICT(bleio_service_locals_dict, bleio_service_locals_dict_table); +STATIC void bleio_service_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "Service("); + if (self->uuid) { + bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + } else { + mp_printf(print, "unregistered UUID"); + } + mp_printf(print, ")"); +} + const mp_obj_type_t bleio_service_type = { { &mp_type_type }, .name = MP_QSTR_Service, .make_new = bleio_service_make_new, + .print = bleio_service_print, .locals_dict = (mp_obj_dict_t*)&bleio_service_locals_dict }; diff --git a/shared-bindings/bleio/UUID.c b/shared-bindings/bleio/UUID.c index 0db7435f44..dca7ea0109 100644 --- a/shared-bindings/bleio/UUID.c +++ b/shared-bindings/bleio/UUID.c @@ -50,6 +50,9 @@ //| - a buffer object (bytearray, bytes) of 16 bytes in little-endian order (128-bit UUID) //| - a string of hex digits of the form 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' //| +//| Creating a 128-bit UUID registers the UUID with the onboard BLE software, and provides a +//| temporary 16-bit UUID that can be used in place of the full 128-bit UUID. +//| //| :param value: The uuid value to encapsulate //| :type value: int or typing.ByteString //| diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index ca45a846ec..9e80b49e37 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -28,9 +28,10 @@ #include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/Address.h" +#include "shared-bindings/bleio/Central.h" #include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/CharacteristicBuffer.h" -#include "shared-bindings/bleio/Descriptor.h" +// #include "shared-bindings/bleio/Descriptor.h" #include "shared-bindings/bleio/Peripheral.h" #include "shared-bindings/bleio/ScanEntry.h" #include "shared-bindings/bleio/Scanner.h" @@ -74,7 +75,7 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) }, { MP_ROM_QSTR(MP_QSTR_Address), MP_ROM_PTR(&bleio_address_type) }, -// { MP_ROM_QSTR(MP_QSTR_Central), MP_ROM_PTR(&bleio_central_type) }, + { MP_ROM_QSTR(MP_QSTR_Central), MP_ROM_PTR(&bleio_central_type) }, { MP_ROM_QSTR(MP_QSTR_Characteristic), MP_ROM_PTR(&bleio_characteristic_type) }, { MP_ROM_QSTR(MP_QSTR_CharacteristicBuffer), MP_ROM_PTR(&bleio_characteristic_buffer_type) }, // { MP_ROM_QSTR(MP_QSTR_Descriptor), MP_ROM_PTR(&bleio_descriptor_type) }, From 7c908b08ee3704a4784919e68b17e1a2f571fa17 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sun, 30 Jun 2019 01:10:47 +0200 Subject: [PATCH 27/61] Use FONTBOUNDINGBOX for font metrics Instead of iterating over all the glyphs and calculating the maximum width and height, use the FONTBOUNDINGBOX to determine the size of a tile for terminalio. This works better with fonts such as generated by FontForge, that don't include the empty space in the glyph bitmap itself. It also lets the font author specify vertical spacing they want. I only tested this with the default font and with one I generated with FontForge. --- tools/gen_display_resources.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py index 7b28c31056..2c674c8ebd 100644 --- a/tools/gen_display_resources.py +++ b/tools/gen_display_resources.py @@ -29,7 +29,6 @@ class BitmapStub: self.rows[y] = bytes(row) f = bitmap_font.load_font(args.font, BitmapStub) -real_bb = [0, 0] # Load extra characters from the sample file. sample_characters = set() @@ -61,13 +60,11 @@ for c in all_characters: print("Font missing character:", c, ord(c)) filtered_characters = filtered_characters.replace(c, "") continue - x, y, dx, dy = g["bounds"] if g["shift"][1] != 0: raise RuntimeError("y shift") - real_bb[0] = max(real_bb[0], x - dx) - real_bb[1] = max(real_bb[1], y - dy) -tile_x, tile_y = real_bb +x, y, dx, dy = f.get_bounding_box() +tile_x, tile_y = x - dx, y - dy total_bits = tile_x * len(all_characters) total_bits += 32 - total_bits % 32 bytes_per_row = total_bits // 8 From e45eac5016c6ca5deed1061dde442a19b1694b62 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Mon, 1 Jul 2019 23:05:07 +0200 Subject: [PATCH 28/61] Switch the terminal font for ugame10 I designed this really tiny, minimalist font for use on very small displays. On uGame it lets one see the whole text that CircuitPython prints on boot. The characters are 4x6 pixels each, and they are optimized for legibility (large x-height, right angles, blocky shapes). It might make sense to also use that font in other boards. --- .../atmel-samd/boards/ugame10/brutalist-6.bdf | 1147 +++++++++++++++++ ports/atmel-samd/boards/ugame10/brutalist.sfd | 1034 +++++++++++++++ .../boards/ugame10/mpconfigboard.mk | 2 +- 3 files changed, 2182 insertions(+), 1 deletion(-) create mode 100644 ports/atmel-samd/boards/ugame10/brutalist-6.bdf create mode 100644 ports/atmel-samd/boards/ugame10/brutalist.sfd diff --git a/ports/atmel-samd/boards/ugame10/brutalist-6.bdf b/ports/atmel-samd/boards/ugame10/brutalist-6.bdf new file mode 100644 index 0000000000..f9e21e76a9 --- /dev/null +++ b/ports/atmel-samd/boards/ugame10/brutalist-6.bdf @@ -0,0 +1,1147 @@ +STARTFONT 2.1 +FONT -FontForge-Brutalist-Regular-R-Normal--6-60-75-75-P-40-ISO8859-1 +SIZE 6 100 100 +FONTBOUNDINGBOX 4 6 0 0 +COMMENT "Generated by fontforge, http://fontforge.sourceforge.net" +STARTPROPERTIES 17 +FAMILY_NAME "brutalist" +WEIGHT_NAME "Regular" +SLANT "R" +SETWIDTH_NAME "Normal" +PIXEL_SIZE 6 +POINT_SIZE 60 +RESOLUTION_X 100 +RESOLUTION_Y 100 +SPACING "C" +AVERAGE_WIDTH 40 +CHARSET_REGISTRY "ISO8859" +CHARSET_ENCODING "1" +FONTNAME_REGISTRY "" +FONT_ASCENT 4 +FONT_DESCENT 2 +MIN_SPACE 6 +FIGURE_WIDTH 4 +ENDPROPERTIES +CHARS 96 +STARTCHAR space +ENCODING 32 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 1 1 3 -2 +BITMAP +00 +ENDCHAR +STARTCHAR exclam +ENCODING 33 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 1 6 0 -2 +BITMAP +80 +80 +80 +80 +00 +80 +ENDCHAR +STARTCHAR quotedbl +ENCODING 34 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 2 0 2 +BITMAP +A0 +A0 +ENDCHAR +STARTCHAR numbersign +ENCODING 35 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +A0 +E0 +A0 +A0 +E0 +A0 +ENDCHAR +STARTCHAR dollar +ENCODING 36 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +40 +E0 +C0 +60 +E0 +40 +ENDCHAR +STARTCHAR percent +ENCODING 37 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +A0 +20 +40 +40 +80 +A0 +ENDCHAR +STARTCHAR ampersand +ENCODING 38 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +40 +A0 +40 +A0 +A0 +60 +ENDCHAR +STARTCHAR quotesingle +ENCODING 39 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 1 2 0 2 +BITMAP +80 +80 +ENDCHAR +STARTCHAR parenleft +ENCODING 40 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +60 +80 +80 +80 +80 +60 +ENDCHAR +STARTCHAR parenright +ENCODING 41 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +C0 +20 +20 +20 +20 +C0 +ENDCHAR +STARTCHAR asterisk +ENCODING 42 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 3 0 0 +BITMAP +A0 +40 +A0 +ENDCHAR +STARTCHAR plus +ENCODING 43 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 3 0 0 +BITMAP +40 +E0 +40 +ENDCHAR +STARTCHAR comma +ENCODING 44 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 2 3 0 -2 +BITMAP +40 +40 +80 +ENDCHAR +STARTCHAR hyphen +ENCODING 45 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 1 0 1 +BITMAP +E0 +ENDCHAR +STARTCHAR period +ENCODING 46 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 1 1 0 -1 +BITMAP +80 +ENDCHAR +STARTCHAR slash +ENCODING 47 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +20 +20 +40 +40 +80 +80 +ENDCHAR +STARTCHAR zero +ENCODING 48 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +60 +A0 +A0 +A0 +C0 +ENDCHAR +STARTCHAR one +ENCODING 49 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 2 5 0 -1 +BITMAP +40 +C0 +40 +40 +40 +ENDCHAR +STARTCHAR two +ENCODING 50 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +20 +E0 +80 +E0 +ENDCHAR +STARTCHAR three +ENCODING 51 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +20 +E0 +20 +E0 +ENDCHAR +STARTCHAR four +ENCODING 52 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +A0 +E0 +20 +20 +ENDCHAR +STARTCHAR five +ENCODING 53 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +80 +E0 +20 +E0 +ENDCHAR +STARTCHAR six +ENCODING 54 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +80 +E0 +A0 +E0 +ENDCHAR +STARTCHAR seven +ENCODING 55 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +20 +20 +20 +20 +ENDCHAR +STARTCHAR eight +ENCODING 56 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +A0 +E0 +A0 +E0 +ENDCHAR +STARTCHAR nine +ENCODING 57 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +A0 +E0 +20 +E0 +ENDCHAR +STARTCHAR colon +ENCODING 58 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 1 3 1 0 +BITMAP +80 +00 +80 +ENDCHAR +STARTCHAR semicolon +ENCODING 59 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 2 5 0 -2 +BITMAP +40 +00 +40 +40 +80 +ENDCHAR +STARTCHAR less +ENCODING 60 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +20 +40 +80 +40 +20 +ENDCHAR +STARTCHAR equal +ENCODING 61 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 3 0 0 +BITMAP +E0 +00 +E0 +ENDCHAR +STARTCHAR greater +ENCODING 62 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +80 +40 +20 +40 +80 +ENDCHAR +STARTCHAR question +ENCODING 63 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +E0 +20 +60 +40 +00 +40 +ENDCHAR +STARTCHAR at +ENCODING 64 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +E0 +A0 +E0 +E0 +80 +E0 +ENDCHAR +STARTCHAR A +ENCODING 65 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +A0 +A0 +E0 +A0 +ENDCHAR +STARTCHAR B +ENCODING 66 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +C0 +A0 +C0 +A0 +E0 +ENDCHAR +STARTCHAR C +ENCODING 67 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +A0 +80 +A0 +E0 +ENDCHAR +STARTCHAR D +ENCODING 68 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +C0 +A0 +A0 +A0 +C0 +ENDCHAR +STARTCHAR E +ENCODING 69 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +80 +E0 +80 +E0 +ENDCHAR +STARTCHAR F +ENCODING 70 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +80 +80 +E0 +80 +ENDCHAR +STARTCHAR G +ENCODING 71 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +E0 +80 +A0 +A0 +E0 +20 +ENDCHAR +STARTCHAR H +ENCODING 72 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +A0 +E0 +A0 +A0 +ENDCHAR +STARTCHAR I +ENCODING 73 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +40 +40 +40 +E0 +ENDCHAR +STARTCHAR J +ENCODING 74 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +20 +20 +20 +A0 +E0 +ENDCHAR +STARTCHAR K +ENCODING 75 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +C0 +E0 +A0 +A0 +ENDCHAR +STARTCHAR L +ENCODING 76 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +80 +80 +80 +80 +E0 +ENDCHAR +STARTCHAR M +ENCODING 77 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +E0 +A0 +A0 +A0 +ENDCHAR +STARTCHAR N +ENCODING 78 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +E0 +E0 +E0 +A0 +ENDCHAR +STARTCHAR O +ENCODING 79 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +A0 +A0 +A0 +E0 +ENDCHAR +STARTCHAR P +ENCODING 80 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +A0 +A0 +E0 +80 +ENDCHAR +STARTCHAR Q +ENCODING 81 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +E0 +A0 +A0 +A0 +E0 +20 +ENDCHAR +STARTCHAR R +ENCODING 82 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +A0 +A0 +C0 +A0 +ENDCHAR +STARTCHAR S +ENCODING 83 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +80 +E0 +20 +E0 +ENDCHAR +STARTCHAR T +ENCODING 84 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +40 +40 +40 +40 +ENDCHAR +STARTCHAR U +ENCODING 85 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +A0 +A0 +A0 +E0 +ENDCHAR +STARTCHAR V +ENCODING 86 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +A0 +A0 +E0 +40 +ENDCHAR +STARTCHAR W +ENCODING 87 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +A0 +A0 +E0 +A0 +ENDCHAR +STARTCHAR X +ENCODING 88 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +A0 +40 +A0 +A0 +ENDCHAR +STARTCHAR Y +ENCODING 89 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +A0 +A0 +E0 +40 +40 +ENDCHAR +STARTCHAR Z +ENCODING 90 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +E0 +20 +40 +80 +E0 +ENDCHAR +STARTCHAR bracketleft +ENCODING 91 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +E0 +80 +80 +80 +80 +E0 +ENDCHAR +STARTCHAR backslash +ENCODING 92 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +80 +80 +40 +40 +20 +20 +ENDCHAR +STARTCHAR bracketright +ENCODING 93 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +E0 +20 +20 +20 +20 +E0 +ENDCHAR +STARTCHAR asciicircum +ENCODING 94 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 3 0 1 +BITMAP +40 +E0 +A0 +ENDCHAR +STARTCHAR underscore +ENCODING 95 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 1 0 -1 +BITMAP +E0 +ENDCHAR +STARTCHAR grave +ENCODING 96 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 2 2 1 2 +BITMAP +80 +40 +ENDCHAR +STARTCHAR a +ENCODING 97 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +E0 +60 +A0 +E0 +ENDCHAR +STARTCHAR b +ENCODING 98 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +80 +E0 +A0 +A0 +E0 +ENDCHAR +STARTCHAR c +ENCODING 99 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +E0 +A0 +80 +E0 +ENDCHAR +STARTCHAR d +ENCODING 100 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +20 +E0 +A0 +A0 +E0 +ENDCHAR +STARTCHAR e +ENCODING 101 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +E0 +A0 +C0 +E0 +ENDCHAR +STARTCHAR f +ENCODING 102 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +60 +40 +E0 +40 +40 +40 +ENDCHAR +STARTCHAR g +ENCODING 103 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -2 +BITMAP +E0 +A0 +E0 +20 +E0 +ENDCHAR +STARTCHAR h +ENCODING 104 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +80 +E0 +A0 +A0 +A0 +ENDCHAR +STARTCHAR i +ENCODING 105 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 2 5 1 -1 +BITMAP +80 +00 +80 +80 +C0 +ENDCHAR +STARTCHAR j +ENCODING 106 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +20 +00 +60 +20 +A0 +E0 +ENDCHAR +STARTCHAR k +ENCODING 107 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +80 +A0 +C0 +A0 +A0 +ENDCHAR +STARTCHAR l +ENCODING 108 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +C0 +40 +40 +40 +60 +ENDCHAR +STARTCHAR m +ENCODING 109 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +E0 +E0 +E0 +A0 +ENDCHAR +STARTCHAR n +ENCODING 110 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +E0 +A0 +A0 +A0 +ENDCHAR +STARTCHAR o +ENCODING 111 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +E0 +A0 +A0 +E0 +ENDCHAR +STARTCHAR p +ENCODING 112 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -2 +BITMAP +E0 +A0 +A0 +E0 +80 +ENDCHAR +STARTCHAR q +ENCODING 113 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -2 +BITMAP +E0 +A0 +A0 +E0 +20 +ENDCHAR +STARTCHAR r +ENCODING 114 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +E0 +A0 +80 +80 +ENDCHAR +STARTCHAR s +ENCODING 115 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +E0 +80 +60 +E0 +ENDCHAR +STARTCHAR t +ENCODING 116 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -1 +BITMAP +40 +E0 +40 +40 +60 +ENDCHAR +STARTCHAR u +ENCODING 117 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +A0 +A0 +A0 +E0 +ENDCHAR +STARTCHAR v +ENCODING 118 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +A0 +A0 +E0 +40 +ENDCHAR +STARTCHAR w +ENCODING 119 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +A0 +A0 +E0 +A0 +ENDCHAR +STARTCHAR x +ENCODING 120 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +A0 +40 +A0 +A0 +ENDCHAR +STARTCHAR y +ENCODING 121 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 5 0 -2 +BITMAP +A0 +A0 +E0 +20 +E0 +ENDCHAR +STARTCHAR z +ENCODING 122 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 4 0 -1 +BITMAP +E0 +40 +80 +E0 +ENDCHAR +STARTCHAR braceleft +ENCODING 123 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +60 +40 +C0 +40 +40 +60 +ENDCHAR +STARTCHAR bar +ENCODING 124 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 1 6 1 -2 +BITMAP +80 +80 +80 +80 +80 +80 +ENDCHAR +STARTCHAR braceright +ENCODING 125 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +C0 +40 +60 +40 +40 +C0 +ENDCHAR +STARTCHAR asciitilde +ENCODING 126 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 4 3 0 1 +BITMAP +50 +F0 +A0 +ENDCHAR +STARTCHAR uni007F +ENCODING 127 +SWIDTH 666 0 +DWIDTH 5 0 +BBX 3 6 0 -2 +BITMAP +E0 +A0 +A0 +A0 +A0 +E0 +ENDCHAR +ENDFONT diff --git a/ports/atmel-samd/boards/ugame10/brutalist.sfd b/ports/atmel-samd/boards/ugame10/brutalist.sfd new file mode 100644 index 0000000000..2a48515aa5 --- /dev/null +++ b/ports/atmel-samd/boards/ugame10/brutalist.sfd @@ -0,0 +1,1034 @@ +SplineFontDB: 3.0 +FontName: brutalistRegular +FullName: brutalist Regular +FamilyName: brutalist +Weight: Regular +Copyright: Copyright (c) 2019, sheep,,, +UComments: "2019-6-28: Created with FontForge (http://fontforge.org)" +Version: 001.000 +ItalicAngle: 0 +UnderlinePosition: -100 +UnderlineWidth: 50 +Ascent: 666 +Descent: 334 +InvalidEm: 0 +LayerCount: 2 +Layer: 0 0 "Back" 1 +Layer: 1 0 "Fore" 0 +XUID: [1021 455 -922482232 13638063] +OS2Version: 0 +OS2_WeightWidthSlopeOnly: 0 +OS2_UseTypoMetrics: 1 +CreationTime: 1561742286 +ModificationTime: 1561742286 +OS2TypoAscent: 0 +OS2TypoAOffset: 1 +OS2TypoDescent: 0 +OS2TypoDOffset: 1 +OS2TypoLinegap: 0 +OS2WinAscent: 0 +OS2WinAOffset: 1 +OS2WinDescent: 0 +OS2WinDOffset: 1 +HheadAscent: 0 +HheadAOffset: 1 +HheadDescent: 0 +HheadDOffset: 1 +OS2Vendor: 'PfEd' +DEI: 91125 +Encoding: ISO8859-1 +UnicodeInterp: none +NameList: AGL For New Fonts +DisplaySize: 6 +AntiAlias: 1 +FitToEm: 0 +WinInfo: 0 32 23 +OnlyBitmaps: 1 +BeginChars: 256 96 + +StartChar: space +Encoding: 32 32 0 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: exclam +Encoding: 33 33 1 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: quotedbl +Encoding: 34 34 2 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: numbersign +Encoding: 35 35 3 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: dollar +Encoding: 36 36 4 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: percent +Encoding: 37 37 5 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: ampersand +Encoding: 38 38 6 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: quotesingle +Encoding: 39 39 7 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: parenleft +Encoding: 40 40 8 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: parenright +Encoding: 41 41 9 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: asterisk +Encoding: 42 42 10 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: plus +Encoding: 43 43 11 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: comma +Encoding: 44 44 12 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: hyphen +Encoding: 45 45 13 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: period +Encoding: 46 46 14 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: slash +Encoding: 47 47 15 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: zero +Encoding: 48 48 16 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: one +Encoding: 49 49 17 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: two +Encoding: 50 50 18 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: three +Encoding: 51 51 19 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: four +Encoding: 52 52 20 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: five +Encoding: 53 53 21 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: six +Encoding: 54 54 22 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: seven +Encoding: 55 55 23 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: eight +Encoding: 56 56 24 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: nine +Encoding: 57 57 25 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: colon +Encoding: 58 58 26 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: semicolon +Encoding: 59 59 27 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: less +Encoding: 60 60 28 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: equal +Encoding: 61 61 29 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: greater +Encoding: 62 62 30 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: question +Encoding: 63 63 31 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: at +Encoding: 64 64 32 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: A +Encoding: 65 65 33 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: B +Encoding: 66 66 34 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: C +Encoding: 67 67 35 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: D +Encoding: 68 68 36 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: E +Encoding: 69 69 37 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: F +Encoding: 70 70 38 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: G +Encoding: 71 71 39 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: H +Encoding: 72 72 40 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: I +Encoding: 73 73 41 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: J +Encoding: 74 74 42 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: K +Encoding: 75 75 43 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: L +Encoding: 76 76 44 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: M +Encoding: 77 77 45 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: N +Encoding: 78 78 46 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: O +Encoding: 79 79 47 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: P +Encoding: 80 80 48 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: Q +Encoding: 81 81 49 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: R +Encoding: 82 82 50 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: S +Encoding: 83 83 51 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: T +Encoding: 84 84 52 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: U +Encoding: 85 85 53 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: V +Encoding: 86 86 54 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: W +Encoding: 87 87 55 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: X +Encoding: 88 88 56 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: Y +Encoding: 89 89 57 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: Z +Encoding: 90 90 58 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: bracketleft +Encoding: 91 91 59 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: backslash +Encoding: 92 92 60 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: bracketright +Encoding: 93 93 61 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: asciicircum +Encoding: 94 94 62 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: underscore +Encoding: 95 95 63 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: grave +Encoding: 96 96 64 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: a +Encoding: 97 97 65 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: b +Encoding: 98 98 66 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: c +Encoding: 99 99 67 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: d +Encoding: 100 100 68 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: e +Encoding: 101 101 69 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: f +Encoding: 102 102 70 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: g +Encoding: 103 103 71 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: h +Encoding: 104 104 72 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: i +Encoding: 105 105 73 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: j +Encoding: 106 106 74 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: k +Encoding: 107 107 75 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: l +Encoding: 108 108 76 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: m +Encoding: 109 109 77 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: n +Encoding: 110 110 78 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: o +Encoding: 111 111 79 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: p +Encoding: 112 112 80 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: q +Encoding: 113 113 81 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: r +Encoding: 114 114 82 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: s +Encoding: 115 115 83 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: t +Encoding: 116 116 84 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: u +Encoding: 117 117 85 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: v +Encoding: 118 118 86 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: w +Encoding: 119 119 87 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: x +Encoding: 120 120 88 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: y +Encoding: 121 121 89 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: z +Encoding: 122 122 90 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: braceleft +Encoding: 123 123 91 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: bar +Encoding: 124 124 92 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: braceright +Encoding: 125 125 93 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: asciitilde +Encoding: 126 126 94 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar + +StartChar: uni007F +Encoding: 127 127 95 +Width: 666 +VWidth: 0 +Flags: W +LayerCount: 2 +EndChar +EndChars +BitmapFont: 6 96 4 2 1 +BDFStartProperties: 20 +FONT 1 "-FontForge-Brutalist-Regular-R-Normal--6-60-75-75-P-40-ISO8859-1" +SIZE 1 "6 100 100" +FONTBOUNDINGBOX 1 "4 6 0 -1" +FAMILY_NAME 16 "brutalist" +WEIGHT_NAME 16 "Regular" +SLANT 16 "R" +SETWIDTH_NAME 16 "Normal" +PIXEL_SIZE 18 6 +POINT_SIZE 18 60 +RESOLUTION_X 19 100 +RESOLUTION_Y 19 100 +SPACING 16 "C" +AVERAGE_WIDTH 18 40 +CHARSET_REGISTRY 16 "ISO8859" +CHARSET_ENCODING 16 "1" +FONTNAME_REGISTRY 16 "" +FONT_ASCENT 18 4 +FONT_DESCENT 18 2 +MIN_SPACE 18 6 +FIGURE_WIDTH 18 4 +BDFEndProperties +Resolution: 100 +BDFChar: 0 32 5 3 3 -2 -2 +z +BDFChar: 1 33 5 0 0 -2 3 +J:N0#!.Y%L +BDFChar: 2 34 5 0 2 2 3 +TV)8b +BDFChar: 3 35 5 0 2 -2 3 +T\uK9i1L&M +BDFChar: 4 36 5 0 2 -2 3 +5iBFci'78B +BDFChar: 5 37 5 0 2 -2 3 +THHKbJ=llB +BDFChar: 6 38 5 0 2 -2 3 +5bLB8TO7a" +BDFChar: 7 39 5 0 0 2 3 +J:IV" +BDFChar: 8 40 5 0 2 -2 3 +@" Date: Tue, 2 Jul 2019 18:15:23 -0700 Subject: [PATCH 29/61] Fix Group subscr to detect delete correctly Fixes #1957 --- shared-bindings/displayio/Group.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 76719c5808..5a35424ce4 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -295,7 +295,7 @@ STATIC mp_obj_t group_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t valu if (value == MP_OBJ_SENTINEL) { // load return common_hal_displayio_group_get(self, index); - } else if (value == mp_const_none) { + } else if (value == MP_OBJ_NULL) { common_hal_displayio_group_pop(self, index); } else { common_hal_displayio_group_set(self, index, value); From bf8a35b2f835fbc97d54867f8e21b486a46c245b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 2 Jul 2019 22:34:54 -0400 Subject: [PATCH 30/61] WIP: CharacteristicBuffer for Central; not working: need to set remote Characteristic Service --- ports/nrf/common-hal/bleio/Central.c | 61 +++++++------ ports/nrf/common-hal/bleio/Characteristic.c | 47 +++++----- .../common-hal/bleio/CharacteristicBuffer.c | 45 ++++++--- ports/nrf/common-hal/bleio/Peripheral.c | 91 ++++++++++--------- shared-bindings/bleio/Central.c | 26 +++++- shared-bindings/bleio/Central.h | 1 + shared-bindings/bleio/CharacteristicBuffer.c | 9 +- shared-bindings/bleio/Peripheral.c | 1 - shared-bindings/bleio/Service.c | 2 +- 9 files changed, 164 insertions(+), 119 deletions(-) diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index 0eedd2b568..5bd5a6321e 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -162,40 +162,41 @@ STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { bleio_central_obj_t *central = (bleio_central_obj_t*)central_in; switch (ble_evt->header.evt_id) { - case BLE_GAP_EVT_CONNECTED: - central->conn_handle = ble_evt->evt.gap_evt.conn_handle; - central->waiting_to_connect = false; - break; + case BLE_GAP_EVT_CONNECTED: + central->conn_handle = ble_evt->evt.gap_evt.conn_handle; + central->waiting_to_connect = false; + break; - case BLE_GAP_EVT_TIMEOUT: - // Handle will be invalid. - central->waiting_to_connect = false; - break; + case BLE_GAP_EVT_TIMEOUT: + // Handle will be invalid. + central->waiting_to_connect = false; + break; - case BLE_GAP_EVT_DISCONNECTED: - central->conn_handle = BLE_CONN_HANDLE_INVALID; - m_discovery_successful = false; - m_discovery_in_process = false; - break; + case BLE_GAP_EVT_DISCONNECTED: + central->conn_handle = BLE_CONN_HANDLE_INVALID; + m_discovery_successful = false; + m_discovery_in_process = false; + break; - case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: - on_primary_srv_discovery_rsp(&ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp, central); - break; + case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP: + on_primary_srv_discovery_rsp(&ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp, central); + break; - case BLE_GATTC_EVT_CHAR_DISC_RSP: - on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); - break; + case BLE_GATTC_EVT_CHAR_DISC_RSP: + on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); + break; - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: - sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); - break; + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: + sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); + break; - case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: - { - ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; - sd_ble_gap_conn_param_update(central->conn_handle, &request->conn_params); - break; - } + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: + { + ble_gap_evt_conn_param_update_request_t *request = + &ble_evt->evt.gap_evt.params.conn_param_update_request; + sd_ble_gap_conn_param_update(central->conn_handle, &request->conn_params); + break; + } } } @@ -319,6 +320,10 @@ void common_hal_bleio_central_disconnect(bleio_central_obj_t *self) { sd_ble_gap_disconnect(self->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); } +bool common_hal_bleio_central_get_connected(bleio_central_obj_t *self) { + return self->conn_handle != BLE_CONN_HANDLE_INVALID; +} + mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self) { return self->service_list; } diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index ea43d8a8ab..c00d8c30bf 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -249,34 +249,35 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, uint16_t cccd = 0; switch (common_hal_bleio_device_get_gatt_role(self->service->device)) { - case GATT_ROLE_SERVER: - if (self->props.notify || self->props.indicate) { - cccd = get_cccd(self); - } - // It's possible that both notify and indicate are set. - if (self->props.notify && (cccd & BLE_GATT_HVX_NOTIFICATION)) { - gatts_notify_indicate(self, bufinfo, BLE_GATT_HVX_NOTIFICATION); - sent = true; - } - if (self->props.indicate && (cccd & BLE_GATT_HVX_INDICATION)) { - gatts_notify_indicate(self, bufinfo, BLE_GATT_HVX_INDICATION); - sent = true; - } - if (!sent) { - gatts_write(self, bufinfo); - } - break; + case GATT_ROLE_SERVER: + if (self->props.notify || self->props.indicate) { + cccd = get_cccd(self); + } + // It's possible that both notify and indicate are set. + if (self->props.notify && (cccd & BLE_GATT_HVX_NOTIFICATION)) { + gatts_notify_indicate(self, bufinfo, BLE_GATT_HVX_NOTIFICATION); + sent = true; + } + if (self->props.indicate && (cccd & BLE_GATT_HVX_INDICATION)) { + gatts_notify_indicate(self, bufinfo, BLE_GATT_HVX_INDICATION); + sent = true; + } + if (!sent) { + gatts_write(self, bufinfo); + } + break; - case GATT_ROLE_CLIENT: - gattc_write(self, bufinfo); - break; + case GATT_ROLE_CLIENT: + gattc_write(self, bufinfo); + break; - default: - mp_raise_RuntimeError(translate("bad GATT role")); - break; + default: + mp_raise_RuntimeError(translate("bad GATT role")); + break; } } + bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self) { return self->uuid; } diff --git a/ports/nrf/common-hal/bleio/CharacteristicBuffer.c b/ports/nrf/common-hal/bleio/CharacteristicBuffer.c index 19b3b85ea7..59eaaf02b9 100644 --- a/ports/nrf/common-hal/bleio/CharacteristicBuffer.c +++ b/ports/nrf/common-hal/bleio/CharacteristicBuffer.c @@ -40,25 +40,42 @@ #include "common-hal/bleio/__init__.h" #include "common-hal/bleio/CharacteristicBuffer.h" +STATIC void write_to_ringbuf(bleio_characteristic_buffer_obj_t *self, uint8_t *data, uint16_t len) { + // Push all the data onto the ring buffer. + uint8_t is_nested_critical_region; + sd_nvic_critical_region_enter(&is_nested_critical_region); + for (size_t i = 0; i < len; i++) { + ringbuf_put(&self->ringbuf, data[i]); + } + sd_nvic_critical_region_exit(is_nested_critical_region); +} + STATIC void characteristic_buffer_on_ble_evt(ble_evt_t *ble_evt, void *param) { bleio_characteristic_buffer_obj_t *self = (bleio_characteristic_buffer_obj_t *) param; switch (ble_evt->header.evt_id) { - case BLE_GATTS_EVT_WRITE: { - ble_gatts_evt_write_t *evt_write = &ble_evt->evt.gatts_evt.params.write; - // Event handle must match the handle for my characteristic. - if (evt_write->handle == self->characteristic->handle) { - // Push all the data onto the ring buffer. - uint8_t is_nested_critical_region; - sd_nvic_critical_region_enter(&is_nested_critical_region); - for (size_t i = 0; i < evt_write->len; i++) { - ringbuf_put(&self->ringbuf, evt_write->data[i]); + case BLE_GATTS_EVT_WRITE: { + // A client wrote to this server characteristic. + + ble_gatts_evt_write_t *evt_write = &ble_evt->evt.gatts_evt.params.write; + // Event handle must match the handle for my characteristic. + if (evt_write->handle == self->characteristic->handle) { + write_to_ringbuf(self, evt_write->data, evt_write->len); + } + break; + } + + case BLE_GATTC_EVT_HVX: { + // A remote service wrote to this characteristic. + + ble_gattc_evt_hvx_t* evt_hvx = &ble_evt->evt.gattc_evt.params.hvx; + // Must be a notification, and event handle must match the handle for my characteristic. + if (evt_hvx->type == BLE_GATT_HVX_NOTIFICATION && + evt_hvx->handle == self->characteristic->handle) { + write_to_ringbuf(self, evt_hvx->data, evt_hvx->len); } - sd_nvic_critical_region_exit(is_nested_critical_region); break; } } - } - } // Assumes that timeout and buffer_size have been validated before call. @@ -82,13 +99,11 @@ int common_hal_bleio_characteristic_buffer_read(bleio_characteristic_buffer_obj_ // Wait for all bytes received or timeout while ( (ringbuf_count(&self->ringbuf) < len) && (ticks_ms - start_ticks < self->timeout_ms) ) { -#ifdef MICROPY_VM_HOOK_LOOP - MICROPY_VM_HOOK_LOOP ; + MICROPY_VM_HOOK_LOOP; // Allow user to break out of a timeout with a KeyboardInterrupt. if ( mp_hal_is_interrupted() ) { return 0; } -#endif } // Copy received data. Lock out write interrupt handler while copying. diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index 69e75ff27d..fc9a146c31 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -62,60 +62,61 @@ STATIC void peripheral_on_ble_evt(ble_evt_t *ble_evt, void *self_in) { bleio_peripheral_obj_t *self = (bleio_peripheral_obj_t*)self_in; switch (ble_evt->header.evt_id) { - case BLE_GAP_EVT_CONNECTED: { - // Central has connected. - ble_gap_conn_params_t conn_params; - self->conn_handle = ble_evt->evt.gap_evt.conn_handle; - sd_ble_gap_ppcp_get(&conn_params); - sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); - break; - } + case BLE_GAP_EVT_CONNECTED: { + // Central has connected. + ble_gap_conn_params_t conn_params; + self->conn_handle = ble_evt->evt.gap_evt.conn_handle; + sd_ble_gap_ppcp_get(&conn_params); + sd_ble_gap_conn_param_update(ble_evt->evt.gap_evt.conn_handle, &conn_params); + break; + } - case BLE_GAP_EVT_DISCONNECTED: - // Central has disconnected. - self->conn_handle = BLE_CONN_HANDLE_INVALID; - break; + case BLE_GAP_EVT_DISCONNECTED: + // Central has disconnected. + self->conn_handle = BLE_CONN_HANDLE_INVALID; + break; - case BLE_GAP_EVT_PHY_UPDATE_REQUEST: { - ble_gap_phys_t const phys = { - .rx_phys = BLE_GAP_PHY_AUTO, - .tx_phys = BLE_GAP_PHY_AUTO, - }; - sd_ble_gap_phy_update(ble_evt->evt.gap_evt.conn_handle, &phys); - break; - } + case BLE_GAP_EVT_PHY_UPDATE_REQUEST: { + ble_gap_phys_t const phys = { + .rx_phys = BLE_GAP_PHY_AUTO, + .tx_phys = BLE_GAP_PHY_AUTO, + }; + sd_ble_gap_phy_update(ble_evt->evt.gap_evt.conn_handle, &phys); + break; + } - case BLE_GAP_EVT_ADV_SET_TERMINATED: - // Someday may handle timeouts or limit reached. - break; + case BLE_GAP_EVT_ADV_SET_TERMINATED: + // Someday may handle timeouts or limit reached. + break; - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: - sd_ble_gap_sec_params_reply(self->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); - break; + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: + sd_ble_gap_sec_params_reply(self->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); + break; - case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: { - ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; - sd_ble_gap_conn_param_update(self->conn_handle, &request->conn_params); - break; - } + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: { + ble_gap_evt_conn_param_update_request_t *request = + &ble_evt->evt.gap_evt.params.conn_param_update_request; + sd_ble_gap_conn_param_update(self->conn_handle, &request->conn_params); + break; + } - case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: - sd_ble_gap_data_length_update(self->conn_handle, NULL, NULL); - break; + case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: + sd_ble_gap_data_length_update(self->conn_handle, NULL, NULL); + break; - case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: { - sd_ble_gatts_exchange_mtu_reply(self->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); - break; - } + case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: { + sd_ble_gatts_exchange_mtu_reply(self->conn_handle, BLE_GATT_ATT_MTU_DEFAULT); + break; + } - case BLE_GATTS_EVT_SYS_ATTR_MISSING: - sd_ble_gatts_sys_attr_set(self->conn_handle, NULL, 0, 0); - break; + case BLE_GATTS_EVT_SYS_ATTR_MISSING: + sd_ble_gatts_sys_attr_set(self->conn_handle, NULL, 0, 0); + break; - default: - // For debugging. - // mp_printf(&mp_plat_print, "Unhandled peripheral event: 0x%04x\n", ble_evt->header.evt_id); - break; + default: + // For debugging. + // mp_printf(&mp_plat_print, "Unhandled peripheral event: 0x%04x\n", ble_evt->header.evt_id); + break; } } diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index dd2dd0d50f..efadcbb2ab 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -141,6 +141,25 @@ STATIC mp_obj_t bleio_central_disconnect(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_disconnect_obj, bleio_central_disconnect); +//| .. attribute:: connected +//| +//| True if connected to a remove peripheral. +//| +STATIC mp_obj_t bleio_central_get_connected(mp_obj_t self_in) { + bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return mp_obj_new_bool(common_hal_bleio_central_get_connected(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_connected_obj, bleio_central_get_connected); + +const mp_obj_property_t bleio_central_connected_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&bleio_central_get_connected_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + + //| .. attribute:: remote_services (read-only) //| //| Empty until connected, then a list of services provided by the remote peripheral. @@ -161,11 +180,12 @@ const mp_obj_property_t bleio_central_remote_services_obj = { STATIC const mp_rom_map_elem_t bleio_central_locals_dict_table[] = { // Methods - { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&bleio_central_connect_obj) }, - { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_central_disconnect_obj) }, + { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&bleio_central_connect_obj) }, + { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_central_disconnect_obj) }, // Properties - { MP_ROM_QSTR(MP_QSTR_remote_services), MP_ROM_PTR(&bleio_central_remote_services_obj) }, + { MP_ROM_QSTR(MP_QSTR_connected), MP_ROM_PTR(&bleio_central_connected_obj) }, + { MP_ROM_QSTR(MP_QSTR_remote_services), MP_ROM_PTR(&bleio_central_remote_services_obj) }, }; STATIC MP_DEFINE_CONST_DICT(bleio_central_locals_dict, bleio_central_locals_dict_table); diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h index 542ba8fa2f..2ca4239454 100644 --- a/shared-bindings/bleio/Central.h +++ b/shared-bindings/bleio/Central.h @@ -36,6 +36,7 @@ extern const mp_obj_type_t bleio_central_type; extern void common_hal_bleio_central_construct(bleio_central_obj_t *self); extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_obj_t *address, mp_float_t timeout, mp_obj_t service_uuids); extern void common_hal_bleio_central_disconnect(bleio_central_obj_t *self); +extern bool common_hal_bleio_central_get_connected(bleio_central_obj_t *self); extern mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H diff --git a/shared-bindings/bleio/CharacteristicBuffer.c b/shared-bindings/bleio/CharacteristicBuffer.c index 827f4947b3..26f9e012b5 100644 --- a/shared-bindings/bleio/CharacteristicBuffer.c +++ b/shared-bindings/bleio/CharacteristicBuffer.c @@ -49,10 +49,13 @@ STATIC void raise_error_if_not_connected(bleio_characteristic_buffer_obj_t *self //| //| .. class:: CharacteristicBuffer(characteristic, *, timeout=1, buffer_size=64) //| -//| Create a new Characteristic object identified by the specified UUID. +//| Monitor the given Characteristic. Each time a new value is written to the Characteristic +//| add the newly-written bytes to a FIFO buffer. //| -//| :param bleio.Characteristic characteristic: The characteristic to monitor -//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters.//| +//| :param bleio.Characteristic characteristic: The Characteristic to monitor. +//| It may be a local Characteristic provided by a Peripheral Service, or a remote Characteristic +//| in a remote Service that a Central has connected to. +//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters. //| :param int buffer_size: Size of ring buffer that stores incoming data coming from client. //| Must be >= 1. //| diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 37a765ae9c..665f5baafe 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -140,7 +140,6 @@ STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_ar STATIC mp_obj_t bleio_peripheral_get_connected(mp_obj_t self_in) { bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); - // Return list as a tuple so user won't be able to change it. return mp_obj_new_bool(common_hal_bleio_peripheral_get_connected(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_get_connected_obj, bleio_peripheral_get_connected); diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index e6bb7dcc3f..f8993ef619 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -80,7 +80,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, // Copy the characteristics list and validate its items. mp_obj_t char_list_obj = mp_obj_new_list(0, NULL); - mp_obj_list_t *char_list = MP_OBJ_FROM_PTR(char_list); + mp_obj_list_t *char_list = MP_OBJ_TO_PTR(char_list_obj); while ((characteristic_obj = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { if (!MP_OBJ_IS_TYPE(characteristic_obj, &bleio_characteristic_type)) { From 6e5d70fa1929a6ab2b2de4d9fb0fb224d7618700 Mon Sep 17 00:00:00 2001 From: iot49 Date: Wed, 3 Jul 2019 12:02:01 -0700 Subject: [PATCH 31/61] changed type of receiver_buffer_size to uint16_t --- ports/nrf/common-hal/busio/UART.c | 2 +- shared-bindings/busio/UART.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 593914afc0..b9e9e55387 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -131,7 +131,7 @@ void uart_reset(void) { void common_hal_busio_uart_construct (busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, - uint8_t receiver_buffer_size) { + uint16_t receiver_buffer_size) { // Find a free UART peripheral. self->uarte = NULL; for (size_t i = 0 ; i < MP_ARRAY_SIZE(nrfx_uartes); i++) { diff --git a/shared-bindings/busio/UART.h b/shared-bindings/busio/UART.h index e171f8bb45..776a996be8 100644 --- a/shared-bindings/busio/UART.h +++ b/shared-bindings/busio/UART.h @@ -42,7 +42,7 @@ typedef enum { extern void common_hal_busio_uart_construct(busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, - uint8_t receiver_buffer_size); + uint16_t receiver_buffer_size); extern void common_hal_busio_uart_deinit(busio_uart_obj_t *self); extern bool common_hal_busio_uart_deinited(busio_uart_obj_t *self); From 55f15e3c056f3653415e0d8f3752a33e50abd3c4 Mon Sep 17 00:00:00 2001 From: Anthony DiGirolamo Date: Thu, 4 Jul 2019 11:14:50 -0700 Subject: [PATCH 32/61] Update Arch Linux ARM compiler installation instructions - Add copy-pasteable Arch Linux `arm-none-eabi-gcc` install line similar to Ubuntu example - Add `arm-none-eabi-newlib` as a required package for Arch - Reformat Ubuntu and Arch install code-blocks to catch the eye for the impatient Arch Linux changed their packaging for [arm-none-eabi-gcc](https://www.archlinux.org/packages/community/x86_64/arm-none-eabi-gcc/) by creating [arm-none-eabi-newlib](https://www.archlinux.org/packages/community/any/arm-none-eabi-newlib/) as an optional package. Without it users will get errors about missing header files like: ``` In file included from asf4/samd51/include/samd51j19a.h:49, from asf4/samd51/include/sam.h:38, from ./mpconfigport.h:31, from ../../py/mpconfig.h:45, from ../../py/emitnx64.c:3: /usr/lib/gcc/arm-none-eabi/9.1.0/include/stdint.h:9:16: fatal error: stdint.h: No such file or directory 9 | # include_next | ^~~~~~~~~~ compilation terminated. ``` --- ports/atmel-samd/README.rst | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ports/atmel-samd/README.rst b/ports/atmel-samd/README.rst index 167373b262..9afa19b837 100644 --- a/ports/atmel-samd/README.rst +++ b/ports/atmel-samd/README.rst @@ -124,15 +124,20 @@ Setup ----- An ARM compiler is required for the build, along with the associated binary -utilities. On Ubuntu, these can be installed as follows: +utilities. They can be installed as follows: -.. code-block:: shell +- Ubuntu - sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa - sudo apt-get install gcc-arm-embedded + .. code-block:: shell -On Arch Linux the compiler is available for via the package -``arm-none-eabi-gcc``. + sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa + sudo apt-get install gcc-arm-embedded + +- Arch Linux + + .. code-block:: shell + + sudo pacman -S arm-none-eabi-gcc arm-none-eabi-newlib For other systems, the `GNU Arm Embedded Toolchain `_ may be available in binary form. From 4c72a3991ed53889b2ecba9b3fbb742e261a8cc3 Mon Sep 17 00:00:00 2001 From: iot49 Date: Fri, 5 Jul 2019 10:01:51 -0700 Subject: [PATCH 33/61] updated samd and esp8266 ports --- ports/atmel-samd/common-hal/busio/UART.c | 2 +- ports/esp8266/common-hal/busio/UART.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c index 10618d1cec..b4539eb931 100644 --- a/ports/atmel-samd/common-hal/busio/UART.c +++ b/ports/atmel-samd/common-hal/busio/UART.c @@ -55,7 +55,7 @@ static void usart_async_rxc_callback(const struct usart_async_descriptor *const void common_hal_busio_uart_construct(busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, - uint8_t receiver_buffer_size) { + uint16_t receiver_buffer_size) { Sercom* sercom = NULL; uint8_t sercom_index = 255; // Unset index uint32_t rx_pinmux = 0; diff --git a/ports/esp8266/common-hal/busio/UART.c b/ports/esp8266/common-hal/busio/UART.c index f10e3dc555..e72dce639c 100644 --- a/ports/esp8266/common-hal/busio/UART.c +++ b/ports/esp8266/common-hal/busio/UART.c @@ -40,7 +40,7 @@ extern UartDevice UartDev; void common_hal_busio_uart_construct(busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, - uint8_t receiver_buffer_size) { + uint16_t receiver_buffer_size) { if (rx != mp_const_none || tx != &pin_GPIO2) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, translate("Only tx supported on UART1 (GPIO2)."))); } From 5610e05b8c19c3892dfe9bfced719307a95f365e Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Sat, 6 Jul 2019 12:48:16 -0700 Subject: [PATCH 34/61] Fix up nrf so that it is initialized properly. Also, do not reset it's pins. --- .../nrf/boards/particle_xenon/mpconfigboard.h | 6 +- ports/nrf/common-hal/pulseio/PWMOut.c | 55 ++++++++++--------- supervisor/shared/rgb_led_status.c | 23 ++++---- 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/ports/nrf/boards/particle_xenon/mpconfigboard.h b/ports/nrf/boards/particle_xenon/mpconfigboard.h index 41551d2e1e..c8da667369 100644 --- a/ports/nrf/boards/particle_xenon/mpconfigboard.h +++ b/ports/nrf/boards/particle_xenon/mpconfigboard.h @@ -35,9 +35,9 @@ #define MICROPY_HW_LED_STATUS (&pin_P1_12) -#define MICROPY_HW_RGB_LED_RED (&pin_P0_13) -#define MICROPY_HW_RGB_LED_GREEN (&pin_P0_14) -#define MICROPY_HW_RGB_LED_BLUE (&pin_P0_15) +#define CP_RGB_STATUS_R (&pin_P0_13) +#define CP_RGB_STATUS_G (&pin_P0_14) +#define CP_RGB_STATUS_B (&pin_P0_15) #if QSPI_FLASH_FILESYSTEM #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 20) diff --git a/ports/nrf/common-hal/pulseio/PWMOut.c b/ports/nrf/common-hal/pulseio/PWMOut.c index 5485a75d0a..5233c9adc6 100644 --- a/ports/nrf/common-hal/pulseio/PWMOut.c +++ b/ports/nrf/common-hal/pulseio/PWMOut.c @@ -77,33 +77,37 @@ void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { } } +void reset_single_pwmout(uint8_t i) { + NRF_PWM_Type* pwm = pwms[i]; + + pwm->ENABLE = 0; + pwm->MODE = PWM_MODE_UPDOWN_Up; + pwm->DECODER = PWM_DECODER_LOAD_Individual; + pwm->LOOP = 0; + pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_1; // default is 500 hz + pwm->COUNTERTOP = (PWM_MAX_FREQ/500); // default is 500 hz + + pwm->SEQ[0].PTR = (uint32_t) pwm_seq[i]; + pwm->SEQ[0].CNT = CHANNELS_PER_PWM; // default mode is Individual --> count must be 4 + pwm->SEQ[0].REFRESH = 0; + pwm->SEQ[0].ENDDELAY = 0; + + pwm->SEQ[1].PTR = 0; + pwm->SEQ[1].CNT = 0; + pwm->SEQ[1].REFRESH = 0; + pwm->SEQ[1].ENDDELAY = 0; + + for(int ch =0; ch < CHANNELS_PER_PWM; ch++) { + pwm_seq[i][ch] = (1 << 15); // polarity = 0 + } +} + void pwmout_reset(void) { for(size_t i=0; i < MP_ARRAY_SIZE(pwms); i++) { if (never_reset_pwm[i] > 0) { continue; } - NRF_PWM_Type* pwm = pwms[i]; - - pwm->ENABLE = 0; - pwm->MODE = PWM_MODE_UPDOWN_Up; - pwm->DECODER = PWM_DECODER_LOAD_Individual; - pwm->LOOP = 0; - pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_1; // default is 500 hz - pwm->COUNTERTOP = (PWM_MAX_FREQ/500); // default is 500 hz - - pwm->SEQ[0].PTR = (uint32_t) pwm_seq[i]; - pwm->SEQ[0].CNT = CHANNELS_PER_PWM; // default mode is Individual --> count must be 4 - pwm->SEQ[0].REFRESH = 0; - pwm->SEQ[0].ENDDELAY = 0; - - pwm->SEQ[1].PTR = 0; - pwm->SEQ[1].CNT = 0; - pwm->SEQ[1].REFRESH = 0; - pwm->SEQ[1].ENDDELAY = 0; - - for(int ch =0; ch < CHANNELS_PER_PWM; ch++) { - pwm_seq[i][ch] = (1 << 15); // polarity = 0 - } + reset_single_pwmout(i); } } @@ -148,9 +152,9 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, self->channel = CHANNELS_PER_PWM; // out-of-range value. bool pwm_already_in_use; NRF_PWM_Type* pwm; - - for (size_t i = 0 ; i < MP_ARRAY_SIZE(pwms); i++) { - pwm = pwms[i]; + size_t pwm_index = 0; + for (; pwm_index < MP_ARRAY_SIZE(pwms); pwm_index++) { + pwm = pwms[pwm_index]; pwm_already_in_use = pwm->ENABLE & SPIM_ENABLE_ENABLE_Msk; if (pwm_already_in_use) { if (variable_frequency) { @@ -199,6 +203,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, nrf_pwm_disable(pwm); if (!pwm_already_in_use) { + reset_single_pwmout(pwm_index); nrf_pwm_configure(pwm, base_clock, NRF_PWM_MODE_UP, countertop); } diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 2d7bb067ef..3146cc686f 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -155,9 +155,7 @@ void reset_status_led() { reset_pin_number(MICROPY_HW_APA102_SCK->number); #endif #if defined(CP_RGB_STATUS_LED) - reset_pin_number(CP_RGB_STATUS_R->number); - reset_pin_number(CP_RGB_STATUS_G->number); - reset_pin_number(CP_RGB_STATUS_B->number); + // TODO: Support sharing status LED with user. #endif } @@ -199,9 +197,9 @@ void new_status_color(uint32_t rgb) { uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF; uint8_t blue_u8 = rgb_adjusted & 0xFF; - status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8; - status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8; - status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8; + status_rgb_color[0] = (1<<16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8); + status_rgb_color[1] = (1<<16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8); + status_rgb_color[2] = (1<<16) - 1 - ((uint16_t) (blue_u8 << 8) + blue_u8); common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]); common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]); @@ -237,13 +235,14 @@ void temp_status_color(uint32_t rgb) { uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF; uint8_t blue_u8 = rgb_adjusted & 0xFF; - status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8; - status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8; - status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8; + uint16_t temp_status_color_rgb[3]; + temp_status_color_rgb[0] = (uint16_t) (red_u8 << 8) + red_u8; + temp_status_color_rgb[1] = (uint16_t) (green_u8 << 8) + green_u8; + temp_status_color_rgb[2] = (uint16_t) (blue_u8 << 8) + blue_u8; - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, temp_status_color_rgb[0]); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, temp_status_color_rgb[1]); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, temp_status_color_rgb[2]); #endif } From 46b75755507f58a186a62069cfdb26c5eb6c1d82 Mon Sep 17 00:00:00 2001 From: jandjstudios Date: Sat, 6 Jul 2019 13:41:03 -0700 Subject: [PATCH 35/61] Initial commit to support boards in the datum series. --- .../atmel-samd/boards/datum_distance/board.c | 38 +++++++++++++++++++ .../boards/datum_distance/mpconfigboard.h | 29 ++++++++++++++ .../boards/datum_distance/mpconfigboard.mk | 14 +++++++ ports/atmel-samd/boards/datum_distance/pins.c | 27 +++++++++++++ ports/atmel-samd/boards/datum_imu/board.c | 38 +++++++++++++++++++ .../boards/datum_imu/mpconfigboard.h | 29 ++++++++++++++ .../boards/datum_imu/mpconfigboard.mk | 14 +++++++ ports/atmel-samd/boards/datum_imu/pins.c | 29 ++++++++++++++ ports/atmel-samd/boards/datum_light/board.c | 38 +++++++++++++++++++ .../boards/datum_light/mpconfigboard.h | 29 ++++++++++++++ .../boards/datum_light/mpconfigboard.mk | 14 +++++++ ports/atmel-samd/boards/datum_light/pins.c | 27 +++++++++++++ ports/atmel-samd/boards/datum_weather/board.c | 38 +++++++++++++++++++ .../boards/datum_weather/mpconfigboard.h | 29 ++++++++++++++ .../boards/datum_weather/mpconfigboard.mk | 14 +++++++ ports/atmel-samd/boards/datum_weather/pins.c | 27 +++++++++++++ 16 files changed, 434 insertions(+) create mode 100644 ports/atmel-samd/boards/datum_distance/board.c create mode 100644 ports/atmel-samd/boards/datum_distance/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/datum_distance/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/datum_distance/pins.c create mode 100644 ports/atmel-samd/boards/datum_imu/board.c create mode 100644 ports/atmel-samd/boards/datum_imu/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/datum_imu/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/datum_imu/pins.c create mode 100644 ports/atmel-samd/boards/datum_light/board.c create mode 100644 ports/atmel-samd/boards/datum_light/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/datum_light/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/datum_light/pins.c create mode 100644 ports/atmel-samd/boards/datum_weather/board.c create mode 100644 ports/atmel-samd/boards/datum_weather/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/datum_weather/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/datum_weather/pins.c diff --git a/ports/atmel-samd/boards/datum_distance/board.c b/ports/atmel-samd/boards/datum_distance/board.c new file mode 100644 index 0000000000..c8e20206a1 --- /dev/null +++ b/ports/atmel-samd/boards/datum_distance/board.c @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "boards/board.h" + +void board_init(void) +{ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/datum_distance/mpconfigboard.h b/ports/atmel-samd/boards/datum_distance/mpconfigboard.h new file mode 100644 index 0000000000..e02e437805 --- /dev/null +++ b/ports/atmel-samd/boards/datum_distance/mpconfigboard.h @@ -0,0 +1,29 @@ +// LEDs +#define MICROPY_HW_LED_STATUS (&pin_PA17) +#define MICROPY_HW_LED_TX &pin_PA27 +#define MICROPY_HW_LED_RX &pin_PA17 + +#define MICROPY_HW_BOARD_NAME "J&J Studios datum-Distance" +#define MICROPY_HW_MCU_NAME "samd21g18" + +#define MICROPY_PORT_A (0) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000 - CIRCUITPY_INTERNAL_NVM_SIZE) + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) + +#define DEFAULT_SPI_BUS_SCK (&pin_PB11) +#define DEFAULT_SPI_BUS_MOSI (&pin_PB10) +#define DEFAULT_SPI_BUS_MISO (&pin_PA12) + +#define DEFAULT_UART_BUS_RX (&pin_PA11) +#define DEFAULT_UART_BUS_TX (&pin_PA10) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/datum_distance/mpconfigboard.mk b/ports/atmel-samd/boards/datum_distance/mpconfigboard.mk new file mode 100644 index 0000000000..a7bb8293d4 --- /dev/null +++ b/ports/atmel-samd/boards/datum_distance/mpconfigboard.mk @@ -0,0 +1,14 @@ +LD_FILE = boards/samd21x18-bootloader.ld +USB_VID = 0x04D8 +USB_PID = 0xEE8C +USB_PRODUCT = "datum-Distance" +USB_MANUFACTURER = "J&J Studios LLC" + +CHIP_VARIANT = SAMD21G18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE +CIRCUITPY_SMALL_BUILD = 1 + +SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/datum_distance/pins.c b/ports/atmel-samd/boards/datum_distance/pins.c new file mode 100644 index 0000000000..b29a859b64 --- /dev/null +++ b/ports/atmel-samd/boards/datum_distance/pins.c @@ -0,0 +1,27 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/datum_imu/board.c b/ports/atmel-samd/boards/datum_imu/board.c new file mode 100644 index 0000000000..c8e20206a1 --- /dev/null +++ b/ports/atmel-samd/boards/datum_imu/board.c @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "boards/board.h" + +void board_init(void) +{ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/datum_imu/mpconfigboard.h b/ports/atmel-samd/boards/datum_imu/mpconfigboard.h new file mode 100644 index 0000000000..b87739dd0e --- /dev/null +++ b/ports/atmel-samd/boards/datum_imu/mpconfigboard.h @@ -0,0 +1,29 @@ +// LEDs +#define MICROPY_HW_LED_STATUS (&pin_PA17) +#define MICROPY_HW_LED_TX &pin_PA27 +#define MICROPY_HW_LED_RX &pin_PA17 + +#define MICROPY_HW_BOARD_NAME "J&J Studios datum-IMU" +#define MICROPY_HW_MCU_NAME "samd21g18" + +#define MICROPY_PORT_A (0) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000 - CIRCUITPY_INTERNAL_NVM_SIZE) + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) + +#define DEFAULT_SPI_BUS_SCK (&pin_PB11) +#define DEFAULT_SPI_BUS_MOSI (&pin_PB10) +#define DEFAULT_SPI_BUS_MISO (&pin_PA12) + +#define DEFAULT_UART_BUS_RX (&pin_PA11) +#define DEFAULT_UART_BUS_TX (&pin_PA10) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/datum_imu/mpconfigboard.mk b/ports/atmel-samd/boards/datum_imu/mpconfigboard.mk new file mode 100644 index 0000000000..507c83b041 --- /dev/null +++ b/ports/atmel-samd/boards/datum_imu/mpconfigboard.mk @@ -0,0 +1,14 @@ +LD_FILE = boards/samd21x18-bootloader.ld +USB_VID = 0x04D8 +USB_PID = 0xEE8D +USB_PRODUCT = "datum-IMU" +USB_MANUFACTURER = "J&J Studios LLC" + +CHIP_VARIANT = SAMD21G18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE +CIRCUITPY_SMALL_BUILD = 1 + +SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/datum_imu/pins.c b/ports/atmel-samd/boards/datum_imu/pins.c new file mode 100644 index 0000000000..237b5774ec --- /dev/null +++ b/ports/atmel-samd/boards/datum_imu/pins.c @@ -0,0 +1,29 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA03) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/datum_light/board.c b/ports/atmel-samd/boards/datum_light/board.c new file mode 100644 index 0000000000..c8e20206a1 --- /dev/null +++ b/ports/atmel-samd/boards/datum_light/board.c @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "boards/board.h" + +void board_init(void) +{ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/datum_light/mpconfigboard.h b/ports/atmel-samd/boards/datum_light/mpconfigboard.h new file mode 100644 index 0000000000..2a91c112dd --- /dev/null +++ b/ports/atmel-samd/boards/datum_light/mpconfigboard.h @@ -0,0 +1,29 @@ +// LEDs +#define MICROPY_HW_LED_STATUS (&pin_PA17) +#define MICROPY_HW_LED_TX &pin_PA27 +#define MICROPY_HW_LED_RX &pin_PA17 + +#define MICROPY_HW_BOARD_NAME "J&J Studios datum-Light" +#define MICROPY_HW_MCU_NAME "samd21g18" + +#define MICROPY_PORT_A (0) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000 - CIRCUITPY_INTERNAL_NVM_SIZE) + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) + +#define DEFAULT_SPI_BUS_SCK (&pin_PB11) +#define DEFAULT_SPI_BUS_MOSI (&pin_PB10) +#define DEFAULT_SPI_BUS_MISO (&pin_PA12) + +#define DEFAULT_UART_BUS_RX (&pin_PA11) +#define DEFAULT_UART_BUS_TX (&pin_PA10) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/datum_light/mpconfigboard.mk b/ports/atmel-samd/boards/datum_light/mpconfigboard.mk new file mode 100644 index 0000000000..4bb227ba4e --- /dev/null +++ b/ports/atmel-samd/boards/datum_light/mpconfigboard.mk @@ -0,0 +1,14 @@ +LD_FILE = boards/samd21x18-bootloader.ld +USB_VID = 0x04D8 +USB_PID = 0xEE8E +USB_PRODUCT = "datum-Light" +USB_MANUFACTURER = "J&J Studios LLC" + +CHIP_VARIANT = SAMD21G18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE +CIRCUITPY_SMALL_BUILD = 1 + +SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/datum_light/pins.c b/ports/atmel-samd/boards/datum_light/pins.c new file mode 100644 index 0000000000..b29a859b64 --- /dev/null +++ b/ports/atmel-samd/boards/datum_light/pins.c @@ -0,0 +1,27 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/datum_weather/board.c b/ports/atmel-samd/boards/datum_weather/board.c new file mode 100644 index 0000000000..c8e20206a1 --- /dev/null +++ b/ports/atmel-samd/boards/datum_weather/board.c @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "boards/board.h" + +void board_init(void) +{ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/datum_weather/mpconfigboard.h b/ports/atmel-samd/boards/datum_weather/mpconfigboard.h new file mode 100644 index 0000000000..45619197b9 --- /dev/null +++ b/ports/atmel-samd/boards/datum_weather/mpconfigboard.h @@ -0,0 +1,29 @@ +// LEDs +#define MICROPY_HW_LED_STATUS (&pin_PA17) +#define MICROPY_HW_LED_TX &pin_PA27 +#define MICROPY_HW_LED_RX &pin_PA17 + +#define MICROPY_HW_BOARD_NAME "J&J Studios datum-Weather" +#define MICROPY_HW_MCU_NAME "samd21g18" + +#define MICROPY_PORT_A (0) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000 - CIRCUITPY_INTERNAL_NVM_SIZE) + +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) + +#define DEFAULT_SPI_BUS_SCK (&pin_PB11) +#define DEFAULT_SPI_BUS_MOSI (&pin_PB10) +#define DEFAULT_SPI_BUS_MISO (&pin_PA12) + +#define DEFAULT_UART_BUS_RX (&pin_PA11) +#define DEFAULT_UART_BUS_TX (&pin_PA10) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/datum_weather/mpconfigboard.mk b/ports/atmel-samd/boards/datum_weather/mpconfigboard.mk new file mode 100644 index 0000000000..411aee6254 --- /dev/null +++ b/ports/atmel-samd/boards/datum_weather/mpconfigboard.mk @@ -0,0 +1,14 @@ +LD_FILE = boards/samd21x18-bootloader.ld +USB_VID = 0x04D8 +USB_PID = 0xEE8F +USB_PRODUCT = "datum-Weather" +USB_MANUFACTURER = "J&J Studios LLC" + +CHIP_VARIANT = SAMD21G18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE +CIRCUITPY_SMALL_BUILD = 1 + +SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/datum_weather/pins.c b/ports/atmel-samd/boards/datum_weather/pins.c new file mode 100644 index 0000000000..b29a859b64 --- /dev/null +++ b/ports/atmel-samd/boards/datum_weather/pins.c @@ -0,0 +1,27 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From fae1039401fe2eef70d21ae2148e8eeeec0560bd Mon Sep 17 00:00:00 2001 From: C47D Date: Sat, 6 Jul 2019 16:50:48 -0500 Subject: [PATCH 36/61] [rgb led status] Add CP_RGB_STATUS_PWM_INVERTED symbol to invert pwm signals. --- supervisor/shared/rgb_led_status.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 3146cc686f..2e1b8260bc 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -196,11 +196,17 @@ void new_status_color(uint32_t rgb) { uint8_t red_u8 = (rgb_adjusted >> 16) & 0xFF; uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF; uint8_t blue_u8 = rgb_adjusted & 0xFF; - - status_rgb_color[0] = (1<<16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8); - status_rgb_color[1] = (1<<16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8); - status_rgb_color[2] = (1<<16) - 1 - ((uint16_t) (blue_u8 << 8) + blue_u8); - + + #if defined(CP_RGB_STATUS_INVERTED_PWM) + status_rgb_color[0] = (1 << 16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8); + status_rgb_color[1] = (1 << 16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8); + status_rgb_color[2] = (1 << 16) - 1 - ((uint16_t) (blue_u8 << 8) + blue_u8); + #else + status_rgb_color[0] = (uint16_t) (red_u8 << 8) + red_u8; + status_rgb_color[1] = (uint16_t) (green_u8 << 8) + green_u8; + status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8; + #endif + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]); common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]); common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]); @@ -235,11 +241,18 @@ void temp_status_color(uint32_t rgb) { uint8_t green_u8 = (rgb_adjusted >> 8) & 0xFF; uint8_t blue_u8 = rgb_adjusted & 0xFF; - uint16_t temp_status_color_rgb[3]; + uint16_t temp_status_color_rgb[3] = {0}; + + #if defined(CP_RGB_STATUS_INVERTED_PWM) + temp_status_color_rgb[0] = (1 << 16) - 1 - ((uint16_t) (red_u8 << 8) + red_u8); + temp_status_color_rgb[1] = (1 << 16) - 1 - ((uint16_t) (green_u8 << 8) + green_u8); + temp_status_color_rgb[2] = (1 << 16) - 1 - ((uint16_t) (blue_u8 << 8) + blue_u8); + #else temp_status_color_rgb[0] = (uint16_t) (red_u8 << 8) + red_u8; temp_status_color_rgb[1] = (uint16_t) (green_u8 << 8) + green_u8; temp_status_color_rgb[2] = (uint16_t) (blue_u8 << 8) + blue_u8; - + #endif + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, temp_status_color_rgb[0]); common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, temp_status_color_rgb[1]); common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, temp_status_color_rgb[2]); @@ -407,4 +420,4 @@ void tick_rgb_status_animation(rgb_status_animation_t* status) { } } #endif -} \ No newline at end of file +} From 09ddff8df1349c590e6c0533b6f5085fbcb92483 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 7 Jul 2019 00:07:47 -0400 Subject: [PATCH 37/61] WIP: Need descriptors for Central CCCD discovery; not done yet --- ports/nrf/common-hal/bleio/Central.c | 163 ++++++++++++++++---- ports/nrf/common-hal/bleio/Central.h | 3 +- ports/nrf/common-hal/bleio/Characteristic.c | 27 ++-- ports/nrf/common-hal/bleio/Characteristic.h | 3 +- ports/nrf/common-hal/bleio/Descriptor.c | 1 - ports/nrf/common-hal/bleio/Descriptor.h | 2 + ports/nrf/common-hal/bleio/Peripheral.c | 4 + ports/nrf/common-hal/bleio/Service.c | 9 +- ports/nrf/common-hal/bleio/Service.h | 3 +- shared-bindings/bleio/Central.c | 4 +- shared-bindings/bleio/Central.h | 2 +- shared-bindings/bleio/Descriptor.c | 3 - shared-bindings/bleio/Peripheral.c | 16 ++ shared-bindings/bleio/Peripheral.h | 1 + 14 files changed, 183 insertions(+), 58 deletions(-) diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index 5bd5a6321e..f7077f4b9a 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -37,10 +37,13 @@ #include "shared-bindings/bleio/Adapter.h" #include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/Central.h" +#include "shared-bindings/bleio/Descriptor.h" #include "shared-bindings/bleio/Service.h" #include "shared-bindings/bleio/UUID.h" static bleio_service_obj_t *m_char_discovery_service; +static bleio_characteristic_obj_t *m_desc_discovery_characteristic; + static volatile bool m_discovery_in_process; static volatile bool m_discovery_successful; @@ -84,6 +87,28 @@ STATIC bool discover_next_characteristics(bleio_central_obj_t *self, bleio_servi return m_discovery_successful; } +STATIC bool discover_next_descriptors(bleio_central_obj_t *self, bleio_characteristic_obj_t *characteristic, uint16_t start_handle, uint16_t end_handle) { + m_desc_discovery_characteristic = characteristic; + + ble_gattc_handle_range_t handle_range; + handle_range.start_handle = start_handle; + handle_range.end_handle = end_handle; + + m_discovery_successful = false; + m_discovery_in_process = true; + + uint32_t err_code = sd_ble_gattc_characteristics_discover(self->conn_handle, &handle_range); + if (err_code != NRF_SUCCESS) { + return false; + } + + // Wait for a discovery event. + while (m_discovery_in_process) { + MICROPY_VM_HOOK_LOOP; + } + return m_discovery_successful; +} + STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *response, bleio_central_obj_t *central) { for (size_t i = 0; i < response->count; ++i) { ble_gattc_service_t *gattc_service = &response->services[i]; @@ -127,25 +152,30 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); characteristic->base.type = &bleio_characteristic_type; + bleio_uuid_obj_t *uuid = NULL; + if (gattc_char->uuid.type != BLE_UUID_TYPE_UNKNOWN) { // Known characteristic UUID. - bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t); + uuid = m_new_obj(bleio_uuid_obj_t); uuid->base.type = &bleio_uuid_type; bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_char->uuid); - characteristic->uuid = uuid; } else { // The discovery response contained a 128-bit UUID that has not yet been registered with the // softdevice via sd_ble_uuid_vs_add(). We need to fetch the 128-bit value and register it. - // For now, just set the UUID to NULL. - characteristic->uuid = NULL; + // For now, just leave the UUID as NULL. } - characteristic->props.broadcast = gattc_char->char_props.broadcast; - characteristic->props.indicate = gattc_char->char_props.indicate; - characteristic->props.notify = gattc_char->char_props.notify; - characteristic->props.read = gattc_char->char_props.read; - characteristic->props.write = gattc_char->char_props.write; - characteristic->props.write_no_response = gattc_char->char_props.write_wo_resp; + bleio_characteristic_properties_t props; + + props.broadcast = gattc_char->char_props.broadcast; + props.indicate = gattc_char->char_props.indicate; + props.notify = gattc_char->char_props.notify; + props.read = gattc_char->char_props.read; + props.write = gattc_char->char_props.write; + props.write_no_response = gattc_char->char_props.write_wo_resp; + + // Call common_hal_bleio_characteristic_construct() to set up evt handler. + common_hal_bleio_characteristic_construct(characteristic, uuid, props); characteristic->handle = gattc_char->handle_value; characteristic->service = m_char_discovery_service; @@ -158,6 +188,39 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio m_discovery_in_process = false; } +STATIC void on_desc_discovery_rsp(ble_gattc_evt_desc_disc_rsp_t *response, bleio_central_obj_t *central) { + for (size_t i = 0; i < response->count; ++i) { + ble_gattc_desc_t *gattc_desc = &response->descs[i]; + + bleio_descriptor_obj_t *descriptor = m_new_obj(bleio_descriptor_obj_t); + descriptor->base.type = &bleio_descriptor_type; + + bleio_uuid_obj_t *uuid = NULL; + + if (gattc_desc->uuid.type != BLE_UUID_TYPE_UNKNOWN) { + // Known descriptor UUID. + uuid = m_new_obj(bleio_uuid_obj_t); + uuid->base.type = &bleio_uuid_type; + bleio_uuid_construct_from_nrf_ble_uuid(uuid, &gattc_desc->uuid); + } else { + // The discovery response contained a 128-bit UUID that has not yet been registered with the + // softdevice via sd_ble_uuid_vs_add(). We need to fetch the 128-bit value and register it. + // For now, just leave the UUID as NULL. + } + + common_hal_bleio_descriptor_construct(descriptor, uuid); + descriptor->handle = gattc_desc->handle; + descriptor->characteristic = m_desc_discovery_characteristic; + + mp_obj_list_append(m_desc_discovery_characteristic->descriptor_list, MP_OBJ_FROM_PTR(descriptor)); + } + + if (response->count > 0) { + m_discovery_successful = true; + } + m_discovery_in_process = false; +} + STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { bleio_central_obj_t *central = (bleio_central_obj_t*)central_in; @@ -186,17 +249,24 @@ STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { on_char_discovery_rsp(&ble_evt->evt.gattc_evt.params.char_disc_rsp, central); break; + case BLE_GATTC_EVT_DESC_DISC_RSP: + on_desc_discovery_rsp(&ble_evt->evt.gattc_evt.params.desc_disc_rsp, central); + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); break; - case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: - { + case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: { ble_gap_evt_conn_param_update_request_t *request = &ble_evt->evt.gap_evt.params.conn_param_update_request; sd_ble_gap_conn_param_update(central->conn_handle, &request->conn_params); break; } + + default: + // For debugging. + mp_printf(&mp_plat_print, "Unhandled central event: 0x%04x\n", ble_evt->header.evt_id); + break; } } @@ -257,16 +327,16 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o // List of service UUID's not given, so discover all available services. - uint16_t next_start_handle = BLE_GATT_HANDLE_START; + uint16_t next_service_start_handle = BLE_GATT_HANDLE_START; - while (discover_next_services(self, next_start_handle, MP_OBJ_NULL)) { + while (discover_next_services(self, next_service_start_handle, MP_OBJ_NULL)) { // discover_next_services() appends to service_list. - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); // Get the most recently discovered service, and then ask for services // whose handles start after the last attribute handle inside that service. - const bleio_service_obj_t *service = service_list->items[service_list->len - 1]; - next_start_handle = service->end_handle + 1; + const bleio_service_obj_t *service = + MP_OBJ_TO_PTR(self->service_list->items[self->service_list->len - 1]); + next_service_start_handle = service->end_handle + 1; } } else { mp_obj_iter_buf_t iter_buf; @@ -289,30 +359,65 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o } - const mp_obj_list_t *service_list = MP_OBJ_TO_PTR(self->service_list); - for (size_t i = 0; i < service_list->len; ++i) { - bleio_service_obj_t *service = service_list->items[i]; + for (size_t service_idx = 0; service_idx < self->service_list->len; ++service_idx) { + bleio_service_obj_t *service = MP_OBJ_TO_PTR(self->service_list->items[service_idx]); // Skip the service if it had an unknown (unregistered) UUID. if (service->uuid == NULL) { continue; } - uint16_t next_start_handle = service->start_handle; + uint16_t next_char_start_handle = service->start_handle; // Stop when we go past the end of the range of handles for this service or // discovery call returns nothing. - while (next_start_handle <= service->end_handle && - discover_next_characteristics(self, service, next_start_handle)) { + // discover_next_characteristics() appends to the characteristic_list. + while (next_char_start_handle <= service->end_handle && + discover_next_characteristics(self, service, next_char_start_handle)) { - // discover_next_characteristics() appends to the characteristic_list. - const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(service->characteristic_list); - // Get the most recently discovered characteristic. + // Get the most recently discovered characteristic, and then ask for characteristics + // whose handles start after the last attribute handle inside that characteristic. const bleio_characteristic_obj_t *characteristic = - characteristic_list->items[characteristic_list->len - 1]; - next_start_handle = characteristic->handle + 1; + MP_OBJ_TO_PTR(service->characteristic_list->items[service->characteristic_list->len - 1]); + next_char_start_handle = characteristic->handle + 1; } + + // Got characteristics for this service. Now discover descriptors for each characteristic. + for (size_t char_idx = 0; char_idx < service->characteristic_list->len; ++char_idx) { + bleio_characteristic_obj_t *characteristic = + MP_OBJ_TO_PTR(service->characteristic_list->items[char_idx]); + const bool last_characteristic = char_idx == service->characteristic_list->len - 1; + bleio_characteristic_obj_t *next_characteristic = last_characteristic + ? NULL + : MP_OBJ_TO_PTR(service->characteristic_list->items[char_idx + 1]); + + // Skip the characteristic if it had an unknown (unregistered) UUID. + if (characteristic->uuid == NULL) { + continue; + } + + uint16_t next_desc_start_handle = characteristic->handle + 1; + + // Don't run past the end of this service or the beginning of the next characteristic. + uint16_t next_desc_end_handle = next_characteristic == NULL + ? service->end_handle + : next_characteristic->handle; + + // Stop when we go past the end of the range of handles for this service or + // discovery call returns nothing. + // discover_next_descriptors() appends to the descriptor_list. + while (next_desc_start_handle <= service->end_handle && + discover_next_descriptors(self, characteristic, next_desc_start_handle, next_desc_end_handle)) { + + // Get the most recently discovered descriptor, and then ask for descriptors + // whose handles start after that descriptor's handle. + const bleio_descriptor_obj_t *descriptor = + MP_OBJ_TO_PTR(characteristic->descriptor_list->items[characteristic->descriptor_list->len - 1]); + next_desc_start_handle = descriptor->handle + 1; + } + } + } } @@ -324,6 +429,6 @@ bool common_hal_bleio_central_get_connected(bleio_central_obj_t *self) { return self->conn_handle != BLE_CONN_HANDLE_INVALID; } -mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self) { +mp_obj_list_t *common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self) { return self->service_list; } diff --git a/ports/nrf/common-hal/bleio/Central.h b/ports/nrf/common-hal/bleio/Central.h index 8b38e87ac0..ac16700888 100644 --- a/ports/nrf/common-hal/bleio/Central.h +++ b/ports/nrf/common-hal/bleio/Central.h @@ -30,6 +30,7 @@ #include +#include "py/objlist.h" #include "shared-module/bleio/__init__.h" #include "shared-module/bleio/Address.h" @@ -38,7 +39,7 @@ typedef struct { gatt_role_t gatt_role; volatile bool waiting_to_connect; volatile uint16_t conn_handle; - mp_obj_t service_list; + mp_obj_list_t *service_list; } bleio_central_obj_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_CENTRAL_H diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index c00d8c30bf..1db0a9378d 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -194,27 +194,26 @@ STATIC void characteristic_on_ble_evt(ble_evt_t *ble_evt, void *param) { // More events may be handled later, so keep this as a switch. - case BLE_GATTC_EVT_READ_RSP: - { - ble_gattc_evt_read_rsp_t *response = &ble_evt->evt.gattc_evt.params.read_rsp; - m_read_characteristic->value_data = mp_obj_new_bytearray(response->len, response->data); - // Indicate to busy-wait loop that we've read the characteristic. - m_read_characteristic = NULL; - break; - } + case BLE_GATTC_EVT_READ_RSP: { + ble_gattc_evt_read_rsp_t *response = &ble_evt->evt.gattc_evt.params.read_rsp; + m_read_characteristic->value_data = mp_obj_new_bytearray(response->len, response->data); + // Indicate to busy-wait loop that we've read the characteristic. + m_read_characteristic = NULL; + break; + } - // For debugging. - default: - // mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id); - break; + // For debugging. + default: + // mp_printf(&mp_plat_print, "Unhandled characteristic event: 0x%04x\n", ble_evt->header.evt_id); + break; } } void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props) { - self->service = NULL; + self->service = mp_const_none; self->uuid = uuid; - self->value_data = NULL; + self->value_data = mp_const_none; self->props = props; self->handle = BLE_GATT_HANDLE_INVALID; diff --git a/ports/nrf/common-hal/bleio/Characteristic.h b/ports/nrf/common-hal/bleio/Characteristic.h index 451bae4712..7cb2275968 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.h +++ b/ports/nrf/common-hal/bleio/Characteristic.h @@ -36,9 +36,10 @@ typedef struct { mp_obj_base_t base; bleio_service_obj_t *service; bleio_uuid_obj_t *uuid; - mp_obj_t value_data; + volatile mp_obj_t value_data; uint16_t handle; bleio_characteristic_properties_t props; + mp_obj_list_t *descriptor_list; uint16_t user_desc_handle; uint16_t cccd_handle; uint16_t sccd_handle; diff --git a/ports/nrf/common-hal/bleio/Descriptor.c b/ports/nrf/common-hal/bleio/Descriptor.c index 418cc07c17..d3f2a0ff84 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.c +++ b/ports/nrf/common-hal/bleio/Descriptor.c @@ -30,7 +30,6 @@ #include "shared-bindings/bleio/UUID.h" void common_hal_bleio_descriptor_construct(bleio_descriptor_obj_t *self, bleio_uuid_obj_t *uuid) { - // TODO: set handle ??? self->uuid = uuid; } diff --git a/ports/nrf/common-hal/bleio/Descriptor.h b/ports/nrf/common-hal/bleio/Descriptor.h index 47552f39d8..b7af6a42f9 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.h +++ b/ports/nrf/common-hal/bleio/Descriptor.h @@ -30,11 +30,13 @@ #define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_DESCRIPTOR_H #include "py/obj.h" +#include "common-hal/bleio/Characteristic.h" #include "common-hal/bleio/UUID.h" typedef struct { mp_obj_base_t base; uint16_t handle; + bleio_characteristic_obj_t *characteristic; bleio_uuid_obj_t *uuid; } bleio_descriptor_obj_t; diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index fc9a146c31..b31bb84b0c 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -243,3 +243,7 @@ void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *self) mp_raise_OSError_msg_varg(translate("Failed to stop advertising, err 0x%04x"), err_code); } } + +void common_hal_bleio_peripheral_disconnect(bleio_peripheral_obj_t *self) { + sd_ble_gap_disconnect(self->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); +} diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c index 55193c5cb0..9939de775d 100644 --- a/ports/nrf/common-hal/bleio/Service.c +++ b/ports/nrf/common-hal/bleio/Service.c @@ -42,7 +42,8 @@ void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_ob self->is_secondary = is_secondary; for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { - bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(characteristic_list->items[characteristic_idx]); + bleio_characteristic_obj_t *characteristic = + MP_OBJ_TO_PTR(characteristic_list->items[characteristic_idx]); common_hal_bleio_characteristic_set_service(characteristic, self); } @@ -67,9 +68,9 @@ void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t dev // Call this after the Service has been added to the Peripheral. void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self) { // Add all the characteristics. - const mp_obj_list_t *characteristic_list = MP_OBJ_TO_PTR(self->characteristic_list); - for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { - bleio_characteristic_obj_t *characteristic = characteristic_list->items[characteristic_idx]; + for (size_t characteristic_idx = 0; characteristic_idx < self->characteristic_list->len; ++characteristic_idx) { + bleio_characteristic_obj_t *characteristic = + MP_OBJ_TO_PTR(self->characteristic_list->items[characteristic_idx]); ble_gatts_char_md_t char_md = { .char_props.broadcast = characteristic->props.broadcast, diff --git a/ports/nrf/common-hal/bleio/Service.h b/ports/nrf/common-hal/bleio/Service.h index 90f52027db..583593fb80 100644 --- a/ports/nrf/common-hal/bleio/Service.h +++ b/ports/nrf/common-hal/bleio/Service.h @@ -28,6 +28,7 @@ #ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H #define MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_SERVICE_H +#include "py/objlist.h" #include "common-hal/bleio/UUID.h" typedef struct { @@ -38,7 +39,7 @@ typedef struct { bleio_uuid_obj_t *uuid; // May be a Peripheral, Central, etc. mp_obj_t device; - mp_obj_t characteristic_list; + mp_obj_list_t *characteristic_list; // Range of attribute handles of this service. uint16_t start_handle; uint16_t end_handle; diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index efadcbb2ab..95ba19dd0b 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -79,8 +79,6 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(self); } - - //| .. method:: connect(address, timeout, *, service_uuids=None) //| Attempts a connection to the remote peripheral. If the connection is successful, //| Do BLE discovery for the listed services, to find their handles and characteristics. @@ -167,7 +165,7 @@ const mp_obj_property_t bleio_central_connected_obj = { STATIC mp_obj_t bleio_central_get_remote_services(mp_obj_t self_in) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_bleio_central_get_remote_services(self); + return MP_OBJ_FROM_PTR(common_hal_bleio_central_get_remote_services(self)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_services_obj, bleio_central_get_remote_services); diff --git a/shared-bindings/bleio/Central.h b/shared-bindings/bleio/Central.h index 2ca4239454..0e84037f91 100644 --- a/shared-bindings/bleio/Central.h +++ b/shared-bindings/bleio/Central.h @@ -37,6 +37,6 @@ extern void common_hal_bleio_central_construct(bleio_central_obj_t *self); extern void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_obj_t *address, mp_float_t timeout, mp_obj_t service_uuids); extern void common_hal_bleio_central_disconnect(bleio_central_obj_t *self); extern bool common_hal_bleio_central_get_connected(bleio_central_obj_t *self); -extern mp_obj_t common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); +extern mp_obj_list_t *common_hal_bleio_central_get_remote_services(bleio_central_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CENTRAL_H diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c index 9e051c89e3..723352ea12 100644 --- a/shared-bindings/bleio/Descriptor.c +++ b/shared-bindings/bleio/Descriptor.c @@ -49,9 +49,6 @@ enum { DescriptorUuidTimeTriggerSetting = 0x290E, }; -// Work-in-progress: orphaned for now. -//| :orphan: -//| //| .. currentmodule:: bleio //| //| :class:`Descriptor` -- BLE descriptor diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 665f5baafe..320d834718 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -250,10 +250,26 @@ STATIC mp_obj_t bleio_peripheral_stop_advertising(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_stop_advertising_obj, bleio_peripheral_stop_advertising); +//| .. method:: disconnect() +//| +//| Disconnects from the remote central. +//| Normally the central initiates a disconnection. Use this only +//| if necessary for your application. +//| +STATIC mp_obj_t bleio_peripheral_disconnect(mp_obj_t self_in) { + bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); + + common_hal_bleio_peripheral_disconnect(self); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_peripheral_disconnect_obj, bleio_peripheral_disconnect); + STATIC const mp_rom_map_elem_t bleio_peripheral_locals_dict_table[] = { // Methods { MP_ROM_QSTR(MP_QSTR_start_advertising), MP_ROM_PTR(&bleio_peripheral_start_advertising_obj) }, { MP_ROM_QSTR(MP_QSTR_stop_advertising), MP_ROM_PTR(&bleio_peripheral_stop_advertising_obj) }, + { MP_ROM_QSTR(MP_QSTR_disconnect), MP_ROM_PTR(&bleio_peripheral_disconnect_obj) }, // Properties { MP_ROM_QSTR(MP_QSTR_connected), MP_ROM_PTR(&bleio_peripheral_connected_obj) }, diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h index 16438bba6d..846250a5fc 100644 --- a/shared-bindings/bleio/Peripheral.h +++ b/shared-bindings/bleio/Peripheral.h @@ -38,5 +38,6 @@ extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *se extern mp_obj_t common_hal_bleio_peripheral_get_name(bleio_peripheral_obj_t *self); extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, float interval, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo); extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device); +extern void common_hal_bleio_peripheral_disconnect(bleio_peripheral_obj_t *device); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_PERIPHERAL_H From 64507207da5a5b0a32cf0f8d51d6ca324b7dec21 Mon Sep 17 00:00:00 2001 From: Carl Elkins Date: Mon, 8 Jul 2019 02:08:39 +0100 Subject: [PATCH 38/61] Added conditional compilation around selection of TX pad candidates Original code was correct for SAMD21 New code for SAMD51 only permits pad-0 for TX --- ports/atmel-samd/common-hal/busio/UART.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c index 10618d1cec..c32919365c 100644 --- a/ports/atmel-samd/common-hal/busio/UART.c +++ b/ports/atmel-samd/common-hal/busio/UART.c @@ -88,11 +88,19 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, continue; } potential_sercom = sercom_insts[sercom_index]; - if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 || +#ifdef SAMD21 + if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 || !(tx->sercom[i].pad == 0 || tx->sercom[i].pad == 2)) { continue; } +#endif +#ifdef SAMD51 + if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 || + !(tx->sercom[i].pad == 0)) { + continue; + } +#endif tx_pinmux = PINMUX(tx->number, (i == 0) ? MUX_C : MUX_D); tx_pad = tx->sercom[i].pad; if (rx == mp_const_none) { From 324cbe432753297f8de6c512e2186b5075c050d0 Mon Sep 17 00:00:00 2001 From: C47D Date: Sun, 7 Jul 2019 21:15:51 -0500 Subject: [PATCH 39/61] [rgb status] Also invert the pwm values on clear_temp_status --- supervisor/shared/rgb_led_status.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 2e1b8260bc..7ca92c6777 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -271,9 +271,24 @@ void clear_temp_status() { #endif #endif #if defined(CP_RGB_STATUS_LED) - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]); + + uint16_t red = 0; + uint16_t green = 0; + uint16_t blue = 0; + + #if defined(CP_RGB_STATUS_INVERTED_PWM) + red = (1 << 16) - 1 - status_rgb_color[0]; + green = (1 << 16) - 1 - status_rgb_color[1]; + blue = (1 << 16) - 1 - status_rgb_color[2]; + #else + red = status_rgb_color[0]; + green = status_rgb_color[1]; + blue = status_rgb_color[2]; + #endif + + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, red); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, green); + common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, blue); #endif } From 7f97cc19408c50d2c2fb53c9bc82ae24da5a4b0d Mon Sep 17 00:00:00 2001 From: Tavish Naruka Date: Mon, 8 Jul 2019 14:16:31 +0530 Subject: [PATCH 40/61] Generate .hex for Blip. --- tools/build_board_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/build_board_info.py b/tools/build_board_info.py index 307d90d7aa..8731a6feb0 100644 --- a/tools/build_board_info.py +++ b/tools/build_board_info.py @@ -39,7 +39,8 @@ extension_by_board = { "makerdiary_nrf52840_mdk": HEX, "makerdiary_nrf52840_mdk_usb_dongle": HEX, "pca10056": BIN_UF2, - "pca10059": BIN_UF2 + "pca10059": BIN_UF2, + "electronut_labs_blip": HEX } aliases_by_board = { From 96cf9053f4c4d56ce159d1fb79e9109126e85ace Mon Sep 17 00:00:00 2001 From: jandjstudios Date: Mon, 8 Jul 2019 19:27:14 -0700 Subject: [PATCH 41/61] Added datum boards to travis.yml --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index de5f34c684..3290cea030 100755 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,10 @@ git: # just try to make the builds "about equal in run time" env: - TRAVIS_TESTS="unix docs translations website" TRAVIS_BOARDS="circuitplayground_express mini_sam_m4 grandcentral_m4_express capablerobot_usbhub pygamer pca10056 pca10059 feather_nrf52840_express makerdiary_nrf52840_mdk makerdiary_nrf52840_mdk_usb_dongle particle_boron particle_argon particle_xenon sparkfun_nrf52840_mini electronut_labs_papyr electronut_labs_blip" TRAVIS_SDK=arm:nrf - - TRAVIS_BOARDS="metro_m0_express metro_m4_express metro_m4_airlift_lite pirkey_m0 trellis_m4_express trinket_m0 sparkfun_lumidrive sparkfun_redboard_turbo bast_pro_mini_m0" TRAVIS_SDK=arm - - TRAVIS_BOARDS="feather_radiofruit_zigbee gemma_m0 hallowing_m0_express itsybitsy_m0_express itsybitsy_m4_express meowmeow sam32 uchip escornabot_makech pygamer_advance" TRAVIS_SDK=arm - - TRAVIS_BOARDS="feather_m0_express_crickit feather_m0_rfm69 feather_m0_rfm9x feather_m4_express arduino_zero arduino_mkr1300 arduino_mkrzero pewpew10 kicksat-sprite ugame10 robohatmm1" TRAVIS_SDK=arm - - TRAVIS_BOARDS="circuitplayground_express_crickit feather_m0_adalogger feather_m0_basic feather_m0_express catwan_usbstick pyportal sparkfun_samd21_mini sparkfun_samd21_dev pybadge pybadge_airlift" TRAVIS_SDK=arm + - TRAVIS_BOARDS="metro_m0_express metro_m4_express metro_m4_airlift_lite pirkey_m0 trellis_m4_express trinket_m0 sparkfun_lumidrive sparkfun_redboard_turbo bast_pro_mini_m0 datum_distance" TRAVIS_SDK=arm + - TRAVIS_BOARDS="feather_radiofruit_zigbee gemma_m0 hallowing_m0_express itsybitsy_m0_express itsybitsy_m4_express meowmeow sam32 uchip escornabot_makech pygamer_advance datum_imu" TRAVIS_SDK=arm + - TRAVIS_BOARDS="feather_m0_express_crickit feather_m0_rfm69 feather_m0_rfm9x feather_m4_express arduino_zero arduino_mkr1300 arduino_mkrzero pewpew10 kicksat-sprite ugame10 robohatmm1 datum_light" TRAVIS_SDK=arm + - TRAVIS_BOARDS="circuitplayground_express_crickit feather_m0_adalogger feather_m0_basic feather_m0_express catwan_usbstick pyportal sparkfun_samd21_mini sparkfun_samd21_dev pybadge pybadge_airlift datum_weather" TRAVIS_SDK=arm addons: artifacts: From 40fbac13cdf3743d2a9f218fa067399a88ad164a Mon Sep 17 00:00:00 2001 From: C47D Date: Mon, 8 Jul 2019 22:06:43 -0500 Subject: [PATCH 42/61] [rgb status] Adjust to current brightness --- supervisor/shared/rgb_led_status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 7ca92c6777..0e69cd2e0e 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -293,7 +293,7 @@ void clear_temp_status() { } uint32_t color_brightness(uint32_t color, uint8_t brightness) { - #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) + #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || (defined(CP_RGB_STATUS_LED)) uint32_t result = ((color & 0xff0000) * brightness / 255) & 0xff0000; result += ((color & 0xff00) * brightness / 255) & 0xff00; result += ((color & 0xff) * brightness / 255) & 0xff; @@ -304,7 +304,7 @@ uint32_t color_brightness(uint32_t color, uint8_t brightness) { } void set_rgb_status_brightness(uint8_t level){ - #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) + #if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || (defined(CP_RGB_STATUS_LED)) rgb_status_brightness = level; uint32_t current_color = current_status_color; // Temporarily change the current color global to force the new_status_color call to update the From 118b26b335c7153eeb4847e04019cdc0829ca960 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 9 Jul 2019 00:21:46 -0400 Subject: [PATCH 43/61] UARTClient now works both directions --- ports/nrf/common-hal/bleio/Central.c | 59 +++++++++---- ports/nrf/common-hal/bleio/Characteristic.c | 53 ++++++++++-- ports/nrf/common-hal/bleio/Descriptor.c | 4 +- ports/nrf/common-hal/bleio/Peripheral.c | 4 +- ports/nrf/common-hal/bleio/Peripheral.h | 1 - ports/nrf/common-hal/bleio/Service.c | 6 +- shared-bindings/bleio/Address.c | 21 ++--- shared-bindings/bleio/AdvertisementData.h | 35 -------- shared-bindings/bleio/Characteristic.c | 50 ++++++++++- shared-bindings/bleio/Characteristic.h | 5 +- shared-bindings/bleio/Descriptor.c | 93 +++++++++++++-------- shared-bindings/bleio/Descriptor.h | 18 ++++ shared-bindings/bleio/Peripheral.c | 3 +- shared-bindings/bleio/Service.c | 2 +- shared-bindings/bleio/Service.h | 1 - shared-bindings/bleio/__init__.c | 7 +- 16 files changed, 239 insertions(+), 123 deletions(-) delete mode 100644 shared-bindings/bleio/AdvertisementData.h diff --git a/ports/nrf/common-hal/bleio/Central.c b/ports/nrf/common-hal/bleio/Central.c index f7077f4b9a..d90737411f 100644 --- a/ports/nrf/common-hal/bleio/Central.c +++ b/ports/nrf/common-hal/bleio/Central.c @@ -97,7 +97,7 @@ STATIC bool discover_next_descriptors(bleio_central_obj_t *self, bleio_character m_discovery_successful = false; m_discovery_in_process = true; - uint32_t err_code = sd_ble_gattc_characteristics_discover(self->conn_handle, &handle_range); + uint32_t err_code = sd_ble_gattc_descriptors_discover(self->conn_handle, &handle_range); if (err_code != NRF_SUCCESS) { return false; } @@ -116,8 +116,10 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res bleio_service_obj_t *service = m_new_obj(bleio_service_obj_t); service->base.type = &bleio_service_type; + // Initialize several fields at once. + common_hal_bleio_service_construct(service, NULL, mp_obj_new_list(0, NULL), false); + service->device = MP_OBJ_FROM_PTR(central); - service->characteristic_list = mp_obj_new_list(0, NULL); service->start_handle = gattc_service->handle_range.start_handle; service->end_handle = gattc_service->handle_range.end_handle; service->handle = gattc_service->handle_range.start_handle; @@ -152,6 +154,8 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); characteristic->base.type = &bleio_characteristic_type; + characteristic->descriptor_list = mp_obj_new_list(0, NULL); + bleio_uuid_obj_t *uuid = NULL; if (gattc_char->uuid.type != BLE_UUID_TYPE_UNKNOWN) { @@ -174,8 +178,8 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, bleio props.write = gattc_char->char_props.write; props.write_no_response = gattc_char->char_props.write_wo_resp; - // Call common_hal_bleio_characteristic_construct() to set up evt handler. - common_hal_bleio_characteristic_construct(characteristic, uuid, props); + // Call common_hal_bleio_characteristic_construct() to initalize some fields and set up evt handler. + common_hal_bleio_characteristic_construct(characteristic, uuid, props, mp_obj_new_list(0, NULL)); characteristic->handle = gattc_char->handle_value; characteristic->service = m_char_discovery_service; @@ -192,6 +196,27 @@ STATIC void on_desc_discovery_rsp(ble_gattc_evt_desc_disc_rsp_t *response, bleio for (size_t i = 0; i < response->count; ++i) { ble_gattc_desc_t *gattc_desc = &response->descs[i]; + // Remember handles for certain well-known descriptors. + switch (gattc_desc->uuid.uuid) { + case DESCRIPTOR_UUID_CLIENT_CHARACTERISTIC_CONFIGURATION: + m_desc_discovery_characteristic->cccd_handle = gattc_desc->handle; + break; + + case DESCRIPTOR_UUID_SERVER_CHARACTERISTIC_CONFIGURATION: + m_desc_discovery_characteristic->sccd_handle = gattc_desc->handle; + break; + + case DESCRIPTOR_UUID_CHARACTERISTIC_USER_DESCRIPTION: + m_desc_discovery_characteristic->user_desc_handle = gattc_desc->handle; + break; + + default: + // TODO: sd_ble_gattc_descriptors_discover() can return things that are not descriptors, + // so ignore those. + // https://devzone.nordicsemi.com/f/nordic-q-a/49500/sd_ble_gattc_descriptors_discover-is-returning-attributes-that-are-not-descriptors + break; + } + bleio_descriptor_obj_t *descriptor = m_new_obj(bleio_descriptor_obj_t); descriptor->base.type = &bleio_descriptor_type; @@ -251,6 +276,7 @@ STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { case BLE_GATTC_EVT_DESC_DISC_RSP: on_desc_discovery_rsp(&ble_evt->evt.gattc_evt.params.desc_disc_rsp, central); + break; case BLE_GAP_EVT_SEC_PARAMS_REQUEST: sd_ble_gap_sec_params_reply(central->conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL); @@ -265,7 +291,7 @@ STATIC void central_on_ble_evt(ble_evt_t *ble_evt, void *central_in) { default: // For debugging. - mp_printf(&mp_plat_print, "Unhandled central event: 0x%04x\n", ble_evt->header.evt_id); + // mp_printf(&mp_plat_print, "Unhandled central event: 0x%04x\n", ble_evt->header.evt_id); break; } } @@ -330,13 +356,13 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o uint16_t next_service_start_handle = BLE_GATT_HANDLE_START; while (discover_next_services(self, next_service_start_handle, MP_OBJ_NULL)) { - // discover_next_services() appends to service_list. + // discover_next_services() appends to service_list. - // Get the most recently discovered service, and then ask for services - // whose handles start after the last attribute handle inside that service. - const bleio_service_obj_t *service = - MP_OBJ_TO_PTR(self->service_list->items[self->service_list->len - 1]); - next_service_start_handle = service->end_handle + 1; + // Get the most recently discovered service, and then ask for services + // whose handles start after the last attribute handle inside that service. + const bleio_service_obj_t *service = + MP_OBJ_TO_PTR(self->service_list->items[self->service_list->len - 1]); + next_service_start_handle = service->end_handle + 1; } } else { mp_obj_iter_buf_t iter_buf; @@ -384,10 +410,11 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o } // Got characteristics for this service. Now discover descriptors for each characteristic. - for (size_t char_idx = 0; char_idx < service->characteristic_list->len; ++char_idx) { + size_t char_list_len = service->characteristic_list->len; + for (size_t char_idx = 0; char_idx < char_list_len; ++char_idx) { bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(service->characteristic_list->items[char_idx]); - const bool last_characteristic = char_idx == service->characteristic_list->len - 1; + const bool last_characteristic = char_idx == char_list_len - 1; bleio_characteristic_obj_t *next_characteristic = last_characteristic ? NULL : MP_OBJ_TO_PTR(service->characteristic_list->items[char_idx + 1]); @@ -402,13 +429,15 @@ void common_hal_bleio_central_connect(bleio_central_obj_t *self, bleio_address_o // Don't run past the end of this service or the beginning of the next characteristic. uint16_t next_desc_end_handle = next_characteristic == NULL ? service->end_handle - : next_characteristic->handle; + : next_characteristic->handle - 1; // Stop when we go past the end of the range of handles for this service or // discovery call returns nothing. // discover_next_descriptors() appends to the descriptor_list. while (next_desc_start_handle <= service->end_handle && - discover_next_descriptors(self, characteristic, next_desc_start_handle, next_desc_end_handle)) { + next_desc_start_handle < next_desc_end_handle && + discover_next_descriptors(self, characteristic, + next_desc_start_handle, next_desc_end_handle)) { // Get the most recently discovered descriptor, and then ask for descriptors // whose handles start after that descriptor's handle. diff --git a/ports/nrf/common-hal/bleio/Characteristic.c b/ports/nrf/common-hal/bleio/Characteristic.c index 1db0a9378d..17417a5e64 100644 --- a/ports/nrf/common-hal/bleio/Characteristic.c +++ b/ports/nrf/common-hal/bleio/Characteristic.c @@ -162,7 +162,6 @@ STATIC void gattc_write(bleio_characteristic_obj_t *characteristic, mp_buffer_in check_connected(conn_handle); ble_gattc_write_params_t write_params = { - .flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL, .write_op = characteristic->props.write_no_response ? BLE_GATT_OP_WRITE_CMD : BLE_GATT_OP_WRITE_REQ, .handle = characteristic->handle, .p_value = bufinfo->buf, @@ -210,19 +209,19 @@ STATIC void characteristic_on_ble_evt(ble_evt_t *ble_evt, void *param) { } -void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props) { +void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props, mp_obj_list_t *descriptor_list) { self->service = mp_const_none; self->uuid = uuid; self->value_data = mp_const_none; self->props = props; + self->descriptor_list = descriptor_list; self->handle = BLE_GATT_HANDLE_INVALID; ble_drv_add_event_handler(characteristic_on_ble_evt, self); - } -void common_hal_bleio_characteristic_set_service(bleio_characteristic_obj_t *self, bleio_service_obj_t *service) { - self->service = service; +mp_obj_list_t *common_hal_bleio_characteristic_get_descriptor_list(bleio_characteristic_obj_t *self) { + return self->descriptor_list; } mp_obj_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self) { @@ -284,3 +283,47 @@ bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_ bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self) { return self->props; } + +void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate) { + if (self->cccd_handle == BLE_GATT_HANDLE_INVALID) { + mp_raise_ValueError(translate("No CCCD for this Characteristic")); + } + + if (common_hal_bleio_device_get_gatt_role(self->service->device) != GATT_ROLE_CLIENT) { + mp_raise_ValueError(translate("Can't set CCCD for local Characteristic")); + } + + uint16_t cccd_value = + (notify ? BLE_GATT_HVX_NOTIFICATION : 0) | + (indicate ? BLE_GATT_HVX_INDICATION : 0); + + const uint16_t conn_handle = common_hal_bleio_device_get_conn_handle(self->service->device); + check_connected(conn_handle); + + + ble_gattc_write_params_t write_params = { + .write_op = BLE_GATT_OP_WRITE_REQ, + .handle = self->cccd_handle, + .p_value = (uint8_t *) &cccd_value, + .len = 2, + }; + + while (1) { + uint32_t err_code = sd_ble_gattc_write(conn_handle, &write_params); + if (err_code == NRF_SUCCESS) { + break; + } + + // Write with response will return NRF_ERROR_BUSY if the response has not been received. + // Write without reponse will return NRF_ERROR_RESOURCES if too many writes are pending. + if (err_code == NRF_ERROR_BUSY || err_code == NRF_ERROR_RESOURCES) { + // We could wait for an event indicating the write is complete, but just retrying is easier. + MICROPY_VM_HOOK_LOOP; + continue; + } + + // Some real error occurred. + mp_raise_OSError_msg_varg(translate("Failed to write CCCD, err 0x%04x"), err_code); + } + +} diff --git a/ports/nrf/common-hal/bleio/Descriptor.c b/ports/nrf/common-hal/bleio/Descriptor.c index d3f2a0ff84..005af6eaae 100644 --- a/ports/nrf/common-hal/bleio/Descriptor.c +++ b/ports/nrf/common-hal/bleio/Descriptor.c @@ -37,6 +37,6 @@ mp_int_t common_hal_bleio_descriptor_get_handle(bleio_descriptor_obj_t *self) { return self->handle; } -mp_obj_t common_hal_bleio_descriptor_get_uuid(bleio_descriptor_obj_t *self) { - return MP_OBJ_FROM_PTR(self->uuid); +bleio_uuid_obj_t *common_hal_bleio_descriptor_get_uuid(bleio_descriptor_obj_t *self) { + return self->uuid; } diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c index b31bb84b0c..608bd1342b 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.c +++ b/ports/nrf/common-hal/bleio/Peripheral.c @@ -135,13 +135,13 @@ void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self, mp_obj_ for (size_t service_idx = 0; service_idx < service_list->len; ++service_idx) { bleio_service_obj_t *service = MP_OBJ_TO_PTR(service_list->items[service_idx]); - common_hal_bleio_service_set_device(service, MP_OBJ_FROM_PTR(self)); + service->device = MP_OBJ_FROM_PTR(self); ble_uuid_t uuid; bleio_uuid_convert_to_nrf_ble_uuid(service->uuid, &uuid); uint8_t service_type = BLE_GATTS_SRVC_TYPE_PRIMARY; - if (service->is_secondary) { + if (common_hal_bleio_service_get_is_secondary(service)) { service_type = BLE_GATTS_SRVC_TYPE_SECONDARY; } diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h index 725bc14314..2a12517159 100644 --- a/ports/nrf/common-hal/bleio/Peripheral.h +++ b/ports/nrf/common-hal/bleio/Peripheral.h @@ -44,7 +44,6 @@ typedef struct { gatt_role_t gatt_role; volatile uint16_t conn_handle; mp_obj_list_t *service_list; - mp_obj_t conn_handler; // The advertising data and scan response buffers are held by us, not by the SD, so we must // maintain them and not change it. If we need to change the contents during advertising, // there are tricks to get the SD to notice (see DevZone - TBS). diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c index 9939de775d..b6fcde8277 100644 --- a/ports/nrf/common-hal/bleio/Service.c +++ b/ports/nrf/common-hal/bleio/Service.c @@ -44,7 +44,7 @@ void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_ob for (size_t characteristic_idx = 0; characteristic_idx < characteristic_list->len; ++characteristic_idx) { bleio_characteristic_obj_t *characteristic = MP_OBJ_TO_PTR(characteristic_list->items[characteristic_idx]); - common_hal_bleio_characteristic_set_service(characteristic, self); + characteristic->service = self; } } @@ -61,10 +61,6 @@ bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self) { return self->is_secondary; } -void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t device) { - self->device = device; -} - // Call this after the Service has been added to the Peripheral. void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self) { // Add all the characteristics. diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index 0e094c2e35..cfad8fc11d 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -49,10 +49,10 @@ //| //| :param buf address: The address value to encapsulate. A buffer object (bytearray, bytes) of 6 bytes. //| :param int address_type: one of these integers: -//| - `bleio.Address.PUBLIC` = 0 -//| - `bleio.Address.RANDOM_STATIC` = 1 -//| - `bleio.Address.RANDOM_PRIVATE_RESOLVABLE` = 2 -//| - `bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE` = 3 +//| - ``bleio.Address.PUBLIC`` = 0 +//| - ``bleio.Address.RANDOM_STATIC`` = 1 +//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 +//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 //| STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -89,11 +89,6 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, //| //| The bytes that make up the device address (read-only) //| -//| - `bleio.Address.PUBLIC` -//| - `bleio.Address.RANDOM_STATIC` -//| - `bleio.Address.RANDOM_PRIVATE_RESOLVABLE` -//| - `bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE` -//| STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -112,10 +107,10 @@ const mp_obj_property_t bleio_address_address_bytes_obj = { //| //| The address type (read-only). One of these integers: //| -//| - `bleio.Address.PUBLIC` -//| - `bleio.Address.RANDOM_STATIC` -//| - `bleio.Address.RANDOM_PRIVATE_RESOLVABLE` -//| - `bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE` +//| - ``bleio.Address.PUBLIC`` = 0 +//| - ``bleio.Address.RANDOM_STATIC`` = 1 +//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 +//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 //| STATIC mp_obj_t bleio_address_get_type(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/bleio/AdvertisementData.h b/shared-bindings/bleio/AdvertisementData.h deleted file mode 100644 index 3313cde3b2..0000000000 --- a/shared-bindings/bleio/AdvertisementData.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Dan Halbert for Adafruit Industries - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADVERTISEMENTDATA_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADVERTISEMENTDATA_H - -#include "py/obj.h" - -extern const mp_obj_type_t bleio_advertisementdata_type; - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_ADVERTISEMENTDATA_H diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index ede38c86b3..0d5f8f79ac 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -88,7 +88,8 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t properties.write = args[ARG_write].u_bool; properties.write_no_response = args[ARG_write_no_response].u_bool; - common_hal_bleio_characteristic_construct(self, uuid, properties); + // Initialize, with an empty descriptor list. + common_hal_bleio_characteristic_construct(self, uuid, properties, mp_obj_new_list(0, NULL)); return MP_OBJ_FROM_PTR(self); } @@ -254,11 +255,58 @@ const mp_obj_property_t bleio_characteristic_value_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| .. attribute:: descriptors +//| +//| A tuple of `bleio.Descriptor` that describe this characteristic. (read-only) +//| +STATIC mp_obj_t bleio_characteristic_get_descriptors(mp_obj_t self_in) { + bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); + // Return list as a tuple so user won't be able to change it. + mp_obj_list_t *char_list = common_hal_bleio_characteristic_get_descriptor_list(self); + return mp_obj_new_tuple(char_list->len, char_list->items); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_descriptors_obj, bleio_characteristic_get_descriptors); + +const mp_obj_property_t bleio_characteristic_descriptors_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&bleio_characteristic_get_descriptors_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + +//| .. method:: set_cccd(*, notify=False, indicate=False) +//| +//| Set the remote characteristic's CCCD to enable or disable notification and indication. +//| +//| :param bool notify: True if Characteristic should receive notifications of remote writes +//| :param float indicate: True if Characteristic should receive indications of remote writes +//| +STATIC mp_obj_t bleio_characteristic_set_cccd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + + enum { ARG_notify, ARG_indicate }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_notify, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + { MP_QSTR_indicate, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + common_hal_bleio_characteristic_set_cccd(self, args[ARG_notify].u_bool, args[ARG_indicate].u_bool); + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_characteristic_set_cccd_obj, 1, bleio_characteristic_set_cccd); + + STATIC const mp_rom_map_elem_t bleio_characteristic_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_broadcast), MP_ROM_PTR(&bleio_characteristic_broadcast_obj) }, + { MP_ROM_QSTR(MP_QSTR_descriptors), MP_ROM_PTR(&bleio_characteristic_descriptors_obj) }, { MP_ROM_QSTR(MP_QSTR_indicate), MP_ROM_PTR(&bleio_characteristic_indicate_obj) }, { MP_ROM_QSTR(MP_QSTR_notify), MP_ROM_PTR(&bleio_characteristic_notify_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&bleio_characteristic_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_set_cccd), MP_ROM_PTR(&bleio_characteristic_set_cccd_obj) }, { MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_characteristic_uuid_obj) }, { MP_ROM_QSTR(MP_QSTR_value), MP_ROM_PTR(&bleio_characteristic_value_obj) }, { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&bleio_characteristic_write_obj) }, diff --git a/shared-bindings/bleio/Characteristic.h b/shared-bindings/bleio/Characteristic.h index 1938845a9a..d450c42b4e 100644 --- a/shared-bindings/bleio/Characteristic.h +++ b/shared-bindings/bleio/Characteristic.h @@ -33,11 +33,12 @@ extern const mp_obj_type_t bleio_characteristic_type; -extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props); -extern void common_hal_bleio_characteristic_set_service(bleio_characteristic_obj_t *self, bleio_service_obj_t *service); +extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props, mp_obj_list_t *descriptor_list); extern mp_obj_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self); extern void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo); extern bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties(bleio_characteristic_obj_t *self); extern bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self); +extern mp_obj_list_t *common_hal_bleio_characteristic_get_descriptor_list(bleio_characteristic_obj_t *self); +extern void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, bool notify, bool indicate); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CHARACTERISTIC_H diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c index 723352ea12..f392838926 100644 --- a/shared-bindings/bleio/Descriptor.c +++ b/shared-bindings/bleio/Descriptor.c @@ -31,24 +31,6 @@ #include "shared-bindings/bleio/Descriptor.h" #include "shared-bindings/bleio/UUID.h" -enum { - DescriptorUuidCharacteristicExtendedProperties = 0x2900, - DescriptorUuidCharacteristicUserDescription = 0x2901, - DescriptorUuidClientCharacteristicConfiguration = 0x2902, - DescriptorUuidServerCharacteristicConfiguration = 0x2903, - DescriptorUuidCharacteristicPresentationFormat = 0x2904, - DescriptorUuidCharacteristicAggregateFormat = 0x2905, - DescriptorUuidValidRange = 0x2906, - DescriptorUuidExternalReportReference = 0x2907, - DescriptorUuidReportReference = 0x2908, - DescriptorUuidNumberOfDigitals = 0x2909, - DescriptorUuidValueTriggerSetting = 0x290A, - DescriptorUuidEnvironmentalSensingConfiguration = 0x290B, - DescriptorUuidEnvironmentalSensingMeasurement = 0x290C, - DescriptorUuidEnvironmentalSensingTriggerSetting = 0x290D, - DescriptorUuidTimeTriggerSetting = 0x290E, -}; - //| .. currentmodule:: bleio //| //| :class:`Descriptor` -- BLE descriptor @@ -111,7 +93,9 @@ const mp_obj_property_t bleio_descriptor_handle_obj = { STATIC mp_obj_t bleio_descriptor_get_uuid(mp_obj_t self_in) { bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_bleio_descriptor_get_uuid(self); + + bleio_uuid_obj_t *uuid = common_hal_bleio_descriptor_get_uuid(self); + return uuid ? MP_OBJ_FROM_PTR(uuid) : mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(bleio_descriptor_get_uuid_obj, bleio_descriptor_get_uuid); @@ -128,28 +112,69 @@ STATIC const mp_rom_map_elem_t bleio_descriptor_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_uuid), MP_ROM_PTR(&bleio_descriptor_uuid_obj) }, // Static variables - { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_EXTENDED_PROPERTIES), MP_ROM_INT(DescriptorUuidCharacteristicExtendedProperties) }, - { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_USER_DESCRIPTION), MP_ROM_INT(DescriptorUuidCharacteristicUserDescription) }, - { MP_ROM_QSTR(MP_QSTR_CLIENT_CHARACTERISTIC_CONFIGURATION), MP_ROM_INT(DescriptorUuidClientCharacteristicConfiguration) }, - { MP_ROM_QSTR(MP_QSTR_SERVER_CHARACTERISTIC_CONFIGURATION), MP_ROM_INT(DescriptorUuidServerCharacteristicConfiguration) }, - { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_PRESENTATION_FORMAT), MP_ROM_INT(DescriptorUuidCharacteristicPresentationFormat) }, - { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_AGGREGATE_FORMAT), MP_ROM_INT(DescriptorUuidCharacteristicAggregateFormat) }, - { MP_ROM_QSTR(MP_QSTR_VALID_RANGE), MP_ROM_INT(DescriptorUuidValidRange) }, - { MP_ROM_QSTR(MP_QSTR_EXTERNAL_REPORT_REFERENCE), MP_ROM_INT(DescriptorUuidExternalReportReference) }, - { MP_ROM_QSTR(MP_QSTR_REPORT_REFERENCE), MP_ROM_INT(DescriptorUuidReportReference) }, - { MP_ROM_QSTR(MP_QSTR_NUMBER_OF_DIGITALS), MP_ROM_INT(DescriptorUuidNumberOfDigitals) }, - { MP_ROM_QSTR(MP_QSTR_VALUE_TRIGGER_SETTING), MP_ROM_INT(DescriptorUuidValueTriggerSetting) }, - { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_CONFIGURATION), MP_ROM_INT(DescriptorUuidEnvironmentalSensingConfiguration) }, - { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_MEASUREMENT ), MP_ROM_INT(DescriptorUuidEnvironmentalSensingMeasurement) }, - { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_TRIGGER_SETTING), MP_ROM_INT(DescriptorUuidEnvironmentalSensingTriggerSetting) }, - { MP_ROM_QSTR(MP_QSTR_TIME_TRIGGER_SETTING), MP_ROM_INT(DescriptorUuidTimeTriggerSetting) } + { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_EXTENDED_PROPERTIES), + MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_EXTENDED_PROPERTIES) }, + + { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_USER_DESCRIPTION), + MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_USER_DESCRIPTION) }, + + { MP_ROM_QSTR(MP_QSTR_CLIENT_CHARACTERISTIC_CONFIGURATION), + MP_ROM_INT(DESCRIPTOR_UUID_CLIENT_CHARACTERISTIC_CONFIGURATION) }, + + { MP_ROM_QSTR(MP_QSTR_SERVER_CHARACTERISTIC_CONFIGURATION), + MP_ROM_INT(DESCRIPTOR_UUID_SERVER_CHARACTERISTIC_CONFIGURATION) }, + + { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_PRESENTATION_FORMAT), + MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_PRESENTATION_FORMAT) }, + + { MP_ROM_QSTR(MP_QSTR_CHARACTERISTIC_AGGREGATE_FORMAT), + MP_ROM_INT(DESCRIPTOR_UUID_CHARACTERISTIC_AGGREGATE_FORMAT) }, + + { MP_ROM_QSTR(MP_QSTR_VALID_RANGE), + MP_ROM_INT(DESCRIPTOR_UUID_VALID_RANGE) }, + + { MP_ROM_QSTR(MP_QSTR_EXTERNAL_REPORT_REFERENCE), + MP_ROM_INT(DESCRIPTOR_UUID_EXTERNAL_REPORT_REFERENCE) }, + + { MP_ROM_QSTR(MP_QSTR_REPORT_REFERENCE), + MP_ROM_INT(DESCRIPTOR_UUID_REPORT_REFERENCE) }, + + { MP_ROM_QSTR(MP_QSTR_NUMBER_OF_DIGITALS), + MP_ROM_INT(DESCRIPTOR_UUID_NUMBER_OF_DIGITALS) }, + + { MP_ROM_QSTR(MP_QSTR_VALUE_TRIGGER_SETTING), + MP_ROM_INT(DESCRIPTOR_UUID_VALUE_TRIGGER_SETTING) }, + + { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_CONFIGURATION), + MP_ROM_INT(DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_CONFIGURATION) }, + + { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_MEASUREMENT ), + MP_ROM_INT(DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_MEASUREMENT) }, + + { MP_ROM_QSTR(MP_QSTR_ENVIRONMENTAL_SENSING_TRIGGER_SETTING), + MP_ROM_INT(DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_TRIGGER_SETTING) }, + + { MP_ROM_QSTR(MP_QSTR_TIME_TRIGGER_SETTING), + MP_ROM_INT(DESCRIPTOR_UUID_TIME_TRIGGER_SETTING) }, }; STATIC MP_DEFINE_CONST_DICT(bleio_descriptor_locals_dict, bleio_descriptor_locals_dict_table); +STATIC void bleio_descriptor_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_printf(print, "Descriptor("); + if (self->uuid) { + bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + } else { + mp_printf(print, "Unregistered uUID"); + } + mp_printf(print, ")"); +} + const mp_obj_type_t bleio_descriptor_type = { { &mp_type_type }, .name = MP_QSTR_Descriptor, .make_new = bleio_descriptor_make_new, + .print = bleio_descriptor_print, .locals_dict = (mp_obj_dict_t*)&bleio_descriptor_locals_dict }; diff --git a/shared-bindings/bleio/Descriptor.h b/shared-bindings/bleio/Descriptor.h index f4634d3933..fd11ea08cd 100644 --- a/shared-bindings/bleio/Descriptor.h +++ b/shared-bindings/bleio/Descriptor.h @@ -31,6 +31,24 @@ #include "common-hal/bleio/Descriptor.h" #include "common-hal/bleio/UUID.h" +enum { + DESCRIPTOR_UUID_CHARACTERISTIC_EXTENDED_PROPERTIES = 0x2900, + DESCRIPTOR_UUID_CHARACTERISTIC_USER_DESCRIPTION = 0x2901, + DESCRIPTOR_UUID_CLIENT_CHARACTERISTIC_CONFIGURATION = 0x2902, + DESCRIPTOR_UUID_SERVER_CHARACTERISTIC_CONFIGURATION = 0x2903, + DESCRIPTOR_UUID_CHARACTERISTIC_PRESENTATION_FORMAT = 0x2904, + DESCRIPTOR_UUID_CHARACTERISTIC_AGGREGATE_FORMAT = 0x2905, + DESCRIPTOR_UUID_VALID_RANGE = 0x2906, + DESCRIPTOR_UUID_EXTERNAL_REPORT_REFERENCE = 0x2907, + DESCRIPTOR_UUID_REPORT_REFERENCE = 0x2908, + DESCRIPTOR_UUID_NUMBER_OF_DIGITALS = 0x2909, + DESCRIPTOR_UUID_VALUE_TRIGGER_SETTING = 0x290A, + DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_CONFIGURATION = 0x290B, + DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_MEASUREMENT = 0x290C, + DESCRIPTOR_UUID_ENVIRONMENTAL_SENSING_TRIGGER_SETTING = 0x290D, + DESCRIPTOR_UUID_TIME_TRIGGER_SETTING = 0x290E, +}; + extern const mp_obj_type_t bleio_descriptor_type; extern void common_hal_bleio_descriptor_construct(bleio_descriptor_obj_t *self, bleio_uuid_obj_t *uuid); diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index 320d834718..b8d4c39753 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -82,13 +82,12 @@ static const char default_name[] = "CIRCUITPY"; //| .. class:: Peripheral(services=(), \*, name='CIRCUITPY') //| //| Create a new Peripheral object. - +//| //| :param iterable services: the Service objects representing services available from this peripheral, if any. //| A non-connectable peripheral will have no services. //| :param str name: The name used when advertising this peripheral. Use ``None`` when a name is not needed, //| such as when the peripheral is a beacon //| - STATIC mp_obj_t bleio_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_services, ARG_name }; static const mp_arg_t allowed_args[] = { diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index f8993ef619..af215c6a50 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -102,7 +102,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, //| .. attribute:: characteristics //| -//| A `list` of `bleio.Characteristic` that are offered by this service. (read-only) +//| A tuple of `bleio.Characteristic` that are offered by this service. (read-only) //| STATIC mp_obj_t bleio_service_get_characteristics(mp_obj_t self_in) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/bleio/Service.h b/shared-bindings/bleio/Service.h index 6693cc3bb3..f646c81a9b 100644 --- a/shared-bindings/bleio/Service.h +++ b/shared-bindings/bleio/Service.h @@ -36,7 +36,6 @@ extern void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_ extern bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self); extern mp_obj_list_t *common_hal_bleio_service_get_characteristic_list(bleio_service_obj_t *self); extern bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self); -extern void common_hal_bleio_service_set_device(bleio_service_obj_t *self, mp_obj_t device); extern void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SERVICE_H diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 9e80b49e37..ba3bae6c75 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -53,15 +53,14 @@ //| :maxdepth: 3 //| //| Address -//| AdvertisementData //| Adapter //| Central //| Characteristic //| CharacteristicBuffer -// Descriptor +//| Descriptor //| Peripheral -//| ScanEntry -//| Scanner +//| ScanEntry +//| Scanner //| Service //| UUID //| From ddd4d616db3d60e5f6aa2a313be3206393e104b1 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 9 Jul 2019 08:43:54 -0400 Subject: [PATCH 44/61] make translate --- locale/ID.po | 139 +++++++++++++++++----------------- locale/circuitpython.pot | 85 ++++++++------------- locale/de_DE.po | 133 ++++++++++++++++++--------------- locale/en_US.po | 85 ++++++++------------- locale/en_x_pirate.po | 85 ++++++++------------- locale/es.po | 156 ++++++++++++++++++++++----------------- locale/fil.po | 153 +++++++++++++++++++++----------------- locale/fr.po | 154 +++++++++++++++++++++----------------- locale/it_IT.po | 153 +++++++++++++++++++++----------------- locale/pl.po | 136 +++++++++++++++++++--------------- locale/pt_BR.po | 127 ++++++++++++++++--------------- locale/zh_Latn_pinyin.po | 136 +++++++++++++++++++--------------- 12 files changed, 801 insertions(+), 741 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 7017631095..ea16b3dec1 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -353,20 +353,8 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c @@ -498,11 +486,6 @@ msgstr "" msgid "Data too large for advertisement packet" msgstr "Tidak bisa menyesuaikan data ke dalam paket advertisment" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Data too large for the advertisement packet" -msgstr "Tidak bisa menyesuaikan data ke dalam paket advertisment" - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "" @@ -540,6 +523,10 @@ msgstr "" msgid "Expected a UUID" msgstr "" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -549,12 +536,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to acquire mutex" -msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX" @@ -564,11 +546,6 @@ msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX" msgid "Failed to add characteristic, err 0x%04x" msgstr "Gagal untuk menambahkan karakteristik, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to add service" -msgstr "Gagal untuk menambahkan layanan, status: 0x%08lX" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to add service, err 0x%04x" @@ -595,25 +572,14 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to connect:" -msgstr "Gagal untuk menyambungkan, status: 0x%08lX" - -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to continue scanning" -msgstr "Gagal untuk melanjutkan scanning, status: 0x%08lX" +msgid "Failed to connect: timeout" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to continue scanning, err 0x%04x" msgstr "Gagal untuk melanjutkan scanning, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to create mutex" -msgstr "Gagal untuk membuat mutex, status: 0x%08lX" - #: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" @@ -654,12 +620,7 @@ msgstr "Gagal untuk menulis nilai gatts, status: 0x%08lX" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Gagal untuk menambahkan Vendor Spesific UUID, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to release mutex" -msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" @@ -669,36 +630,31 @@ msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start advertising" -msgstr "Gagal untuk memulai advertisement, status: 0x%08lX" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Gagal untuk memulai advertisement, status: 0x%08lX" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start scanning" -msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" +#, c-format +msgid "Failed to start connecting, error 0x%04x" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to start scanning, err 0x%04x" msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to stop advertising" -msgstr "Gagal untuk memberhentikan advertisement, status: 0x%08lX" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Gagal untuk memberhentikan advertisement, status: 0x%08lX" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, fuzzy, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -914,6 +870,10 @@ msgstr "" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "Tidak ada DAC (Digital Analog Converter) di dalam chip" @@ -964,6 +924,7 @@ msgstr "" msgid "No such file/directory" msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "Not connected" @@ -2143,6 +2104,14 @@ msgstr "tidak ada modul yang bernama '%q'" msgid "no such attribute" msgstr "" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "argumen non-default mengikuti argumen standar(default)" @@ -2352,10 +2321,6 @@ msgstr "" msgid "script compilation not supported" msgstr "kompilasi script tidak didukung" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "" @@ -2673,6 +2638,10 @@ msgstr "" #~ msgid "Cannot update i/f status" #~ msgstr "Tidak dapat memperbarui status i/f" +#, fuzzy +#~ msgid "Data too large for the advertisement packet" +#~ msgstr "Tidak bisa menyesuaikan data ke dalam paket advertisment" + #~ msgid "Don't know how to pass object to native function" #~ msgstr "Tidak tahu cara meloloskan objek ke fungsi native" @@ -2685,6 +2654,26 @@ msgstr "" #~ msgid "Error in ffi_prep_cif" #~ msgstr "Errod pada ffi_prep_cif" +#, fuzzy +#~ msgid "Failed to acquire mutex" +#~ msgstr "Gagal untuk mendapatkan mutex, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to add service" +#~ msgstr "Gagal untuk menambahkan layanan, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to connect:" +#~ msgstr "Gagal untuk menyambungkan, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to continue scanning" +#~ msgstr "Gagal untuk melanjutkan scanning, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to create mutex" +#~ msgstr "Gagal untuk membuat mutex, status: 0x%08lX" + #, fuzzy #~ msgid "Failed to notify or indicate attribute value, err %0x04x" #~ msgstr "Gagal untuk melaporkan nilai atribut, status: 0x%08lX" @@ -2693,6 +2682,22 @@ msgstr "" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Gagal untuk membaca nilai atribut, status: 0x%08lX" +#, fuzzy +#~ msgid "Failed to release mutex" +#~ msgstr "Gagal untuk melepaskan mutex, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to start advertising" +#~ msgstr "Gagal untuk memulai advertisement, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to start scanning" +#~ msgstr "Gagal untuk melakukan scanning, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to stop advertising" +#~ msgstr "Gagal untuk memberhentikan advertisement, status: 0x%08lX" + #~ msgid "GPIO16 does not support pull up." #~ msgstr "GPIO16 tidak mendukung pull up" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index bbf77887ae..4c399471be 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -348,20 +348,8 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c @@ -487,10 +475,6 @@ msgstr "" msgid "Data too large for advertisement packet" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Data too large for the advertisement packet" -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "" @@ -528,6 +512,10 @@ msgstr "" msgid "Expected a UUID" msgstr "" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -537,11 +525,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to acquire mutex" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "" @@ -551,10 +535,6 @@ msgstr "" msgid "Failed to add characteristic, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to add service" -msgstr "" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to add service, err 0x%04x" @@ -580,11 +560,7 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to connect:" -msgstr "" - -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to continue scanning" +msgid "Failed to connect: timeout" msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c @@ -592,10 +568,6 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to create mutex" -msgstr "" - #: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "" @@ -633,11 +605,7 @@ msgstr "" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to release mutex" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "" @@ -647,17 +615,14 @@ msgstr "" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start advertising" -msgstr "" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start scanning" +#, c-format +msgid "Failed to start connecting, error 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c @@ -665,15 +630,16 @@ msgstr "" msgid "Failed to start scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to stop advertising" -msgstr "" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -889,6 +855,10 @@ msgstr "" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "" @@ -939,6 +909,7 @@ msgstr "" msgid "No such file/directory" msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c msgid "Not connected" msgstr "" @@ -2098,6 +2069,14 @@ msgstr "" msgid "no such attribute" msgstr "" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "" @@ -2306,10 +2285,6 @@ msgstr "" msgid "script compilation not supported" msgstr "" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 8b559edab7..5231231295 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -352,21 +352,9 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Kann dotstar nicht mit %s verwenden" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "Im Central mode können Dienste nicht hinzugefügt werden" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "Im Central mode kann advertise nicht gemacht werden" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "Im Central mode kann name nicht geändert werden" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" -msgstr "Im Peripheral mode kann keine Verbindung hergestellt werden" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" +msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -491,10 +479,6 @@ msgstr "" msgid "Data too large for advertisement packet" msgstr "Zu vielen Daten für das advertisement packet" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Data too large for the advertisement packet" -msgstr "Daten sind zu groß für das advertisement packet" - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "Die Zielkapazität ist kleiner als destination_length." @@ -532,6 +516,10 @@ msgstr "Characteristic wird erwartet" msgid "Expected a UUID" msgstr "Eine UUID wird erwartet" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -541,11 +529,7 @@ msgstr "Habe ein Tupel der Länge %d erwartet aber %d erhalten" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to acquire mutex" -msgstr "Akquirieren des Mutex gescheitert" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "Mutex konnte nicht akquiriert werden. Status: 0x%04x" @@ -555,10 +539,6 @@ msgstr "Mutex konnte nicht akquiriert werden. Status: 0x%04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Hinzufügen des Characteristic ist gescheitert. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to add service" -msgstr "Dienst konnte nicht hinzugefügt werden" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to add service, err 0x%04x" @@ -584,22 +564,14 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to connect:" -msgstr "Verbindung fehlgeschlagen:" - -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to continue scanning" -msgstr "Der Scanvorgang kann nicht fortgesetzt werden" +msgid "Failed to connect: timeout" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, c-format msgid "Failed to continue scanning, err 0x%04x" msgstr "Der Scanvorgang kann nicht fortgesetzt werden. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to create mutex" -msgstr "Erstellen des Mutex ist fehlgeschlagen" - #: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "Es konnten keine Dienste gefunden werden" @@ -637,11 +609,7 @@ msgstr "gatts value konnte nicht gelesen werden. Status: 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Kann keine herstellerspezifische UUID hinzufügen. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to release mutex" -msgstr "Loslassen des Mutex gescheitert" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "Mutex konnte nicht freigegeben werden. Status: 0x%04x" @@ -651,33 +619,31 @@ msgstr "Mutex konnte nicht freigegeben werden. Status: 0x%04x" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start advertising" -msgstr "Kann advertisement nicht starten" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Kann advertisement nicht starten. Status: 0x%04x" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start scanning" -msgstr "Der Scanvorgang kann nicht gestartet werden" +#, c-format +msgid "Failed to start connecting, error 0x%04x" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, c-format msgid "Failed to start scanning, err 0x%04x" msgstr "Der Scanvorgang kann nicht gestartet werden. Status: 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to stop advertising" -msgstr "Kann advertisement nicht stoppen" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Kann advertisement nicht stoppen. Status: 0x%04x" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -902,6 +868,10 @@ msgstr "" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "Kein DAC im Chip vorhanden" @@ -952,6 +922,7 @@ msgstr "Kein Speicherplatz auf Gerät" msgid "No such file/directory" msgstr "Keine solche Datei/Verzeichnis" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c msgid "Not connected" msgstr "Nicht verbunden" @@ -2145,6 +2116,14 @@ msgstr "Kein Modul mit dem Namen '%q'" msgid "no such attribute" msgstr "" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "ein non-default argument folgt auf ein default argument" @@ -2357,10 +2336,6 @@ msgstr "Der schedule stack ist voll" msgid "script compilation not supported" msgstr "kompilieren von Skripten ist nicht unterstützt" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "" @@ -2673,6 +2648,18 @@ msgstr "" #~ msgid "C-level assert" #~ msgstr "C-Level Assert" +#~ msgid "Can't add services in Central mode" +#~ msgstr "Im Central mode können Dienste nicht hinzugefügt werden" + +#~ msgid "Can't advertise in Central mode" +#~ msgstr "Im Central mode kann advertise nicht gemacht werden" + +#~ msgid "Can't change the name in Central mode" +#~ msgstr "Im Central mode kann name nicht geändert werden" + +#~ msgid "Can't connect in Peripheral mode" +#~ msgstr "Im Peripheral mode kann keine Verbindung hergestellt werden" + #~ msgid "Cannot connect to AP" #~ msgstr "Kann nicht zu AP verbinden" @@ -2685,6 +2672,9 @@ msgstr "" #~ msgid "Cannot update i/f status" #~ msgstr "Kann i/f Status nicht updaten" +#~ msgid "Data too large for the advertisement packet" +#~ msgstr "Daten sind zu groß für das advertisement packet" + #~ msgid "Don't know how to pass object to native function" #~ msgstr "" #~ "Ich weiß nicht, wie man das Objekt an die native Funktion übergeben kann" @@ -2698,12 +2688,39 @@ msgstr "" #~ msgid "Error in ffi_prep_cif" #~ msgstr "Fehler in ffi_prep_cif" +#~ msgid "Failed to acquire mutex" +#~ msgstr "Akquirieren des Mutex gescheitert" + +#~ msgid "Failed to add service" +#~ msgstr "Dienst konnte nicht hinzugefügt werden" + +#~ msgid "Failed to connect:" +#~ msgstr "Verbindung fehlgeschlagen:" + +#~ msgid "Failed to continue scanning" +#~ msgstr "Der Scanvorgang kann nicht fortgesetzt werden" + +#~ msgid "Failed to create mutex" +#~ msgstr "Erstellen des Mutex ist fehlgeschlagen" + #~ msgid "Failed to notify or indicate attribute value, err %0x04x" #~ msgstr "Kann den Attributwert nicht mitteilen. Status: 0x%04x" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Kann den Attributwert nicht lesen. Status: 0x%04x" +#~ msgid "Failed to release mutex" +#~ msgstr "Loslassen des Mutex gescheitert" + +#~ msgid "Failed to start advertising" +#~ msgstr "Kann advertisement nicht starten" + +#~ msgid "Failed to start scanning" +#~ msgstr "Der Scanvorgang kann nicht gestartet werden" + +#~ msgid "Failed to stop advertising" +#~ msgstr "Kann advertisement nicht stoppen" + #~ msgid "Function requires lock." #~ msgstr "" #~ "Die Funktion erwartet, dass der 'lock'-Befehl zuvor ausgeführt wurde" diff --git a/locale/en_US.po b/locale/en_US.po index 616e89630a..f1b9bae28c 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -348,20 +348,8 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c @@ -487,10 +475,6 @@ msgstr "" msgid "Data too large for advertisement packet" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Data too large for the advertisement packet" -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "" @@ -528,6 +512,10 @@ msgstr "" msgid "Expected a UUID" msgstr "" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -537,11 +525,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to acquire mutex" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "" @@ -551,10 +535,6 @@ msgstr "" msgid "Failed to add characteristic, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to add service" -msgstr "" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to add service, err 0x%04x" @@ -580,11 +560,7 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to connect:" -msgstr "" - -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to continue scanning" +msgid "Failed to connect: timeout" msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c @@ -592,10 +568,6 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to create mutex" -msgstr "" - #: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "" @@ -633,11 +605,7 @@ msgstr "" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to release mutex" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "" @@ -647,17 +615,14 @@ msgstr "" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start advertising" -msgstr "" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start scanning" +#, c-format +msgid "Failed to start connecting, error 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c @@ -665,15 +630,16 @@ msgstr "" msgid "Failed to start scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to stop advertising" -msgstr "" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -889,6 +855,10 @@ msgstr "" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "" @@ -939,6 +909,7 @@ msgstr "" msgid "No such file/directory" msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c msgid "Not connected" msgstr "" @@ -2098,6 +2069,14 @@ msgstr "" msgid "no such attribute" msgstr "" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "" @@ -2306,10 +2285,6 @@ msgstr "" msgid "script compilation not supported" msgstr "" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 44db050456..1c9ca9f1bb 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -352,20 +352,8 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c @@ -491,10 +479,6 @@ msgstr "" msgid "Data too large for advertisement packet" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Data too large for the advertisement packet" -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "" @@ -532,6 +516,10 @@ msgstr "" msgid "Expected a UUID" msgstr "" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -541,11 +529,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to acquire mutex" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "" @@ -555,10 +539,6 @@ msgstr "" msgid "Failed to add characteristic, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to add service" -msgstr "" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to add service, err 0x%04x" @@ -584,11 +564,7 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to connect:" -msgstr "" - -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to continue scanning" +msgid "Failed to connect: timeout" msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c @@ -596,10 +572,6 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to create mutex" -msgstr "" - #: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "" @@ -637,11 +609,7 @@ msgstr "" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to release mutex" -msgstr "" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "" @@ -651,17 +619,14 @@ msgstr "" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start advertising" -msgstr "" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start scanning" +#, c-format +msgid "Failed to start connecting, error 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c @@ -669,15 +634,16 @@ msgstr "" msgid "Failed to start scanning, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to stop advertising" -msgstr "" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -893,6 +859,10 @@ msgstr "" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "Shiver me timbers! There be no DAC on this chip" @@ -943,6 +913,7 @@ msgstr "" msgid "No such file/directory" msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c msgid "Not connected" msgstr "" @@ -2102,6 +2073,14 @@ msgstr "" msgid "no such attribute" msgstr "" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "" @@ -2310,10 +2289,6 @@ msgstr "" msgid "script compilation not supported" msgstr "" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "" diff --git a/locale/es.po b/locale/es.po index 194dea86ba..013266aa7c 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -362,21 +362,9 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "No se puede usar dotstar con %s" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "No se pueden agregar servicio en modo Central" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "No se puede anunciar en modo Central" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "No se puede cambiar el nombre en modo Central" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" -msgstr "No se puede conectar en modo Peripheral" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" +msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -504,11 +492,6 @@ msgstr "El Data Chunk debe seguir el fmt chunk" msgid "Data too large for advertisement packet" msgstr "Los datos no caben en el paquete de anuncio." -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Data too large for the advertisement packet" -msgstr "Los datos no caben en el paquete de anuncio." - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "Capacidad de destino es mas pequeña que destination_length." @@ -548,6 +531,10 @@ msgstr "No se puede agregar la Característica." msgid "Expected a UUID" msgstr "Se espera un %q" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -557,12 +544,7 @@ msgstr "Se esperaba un tuple de %d, se obtuvo %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to acquire mutex" -msgstr "No se puede adquirir el mutex, status: 0x%08lX" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "No se puede adquirir el mutex, status: 0x%08lX" @@ -572,11 +554,6 @@ msgstr "No se puede adquirir el mutex, status: 0x%08lX" msgid "Failed to add characteristic, err 0x%04x" msgstr "No se puede añadir caracteristica, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to add service" -msgstr "No se puede detener el anuncio. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to add service, err 0x%04x" @@ -603,25 +580,14 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to connect:" -msgstr "No se puede conectar. status: 0x%02x" - -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to continue scanning" -msgstr "No se puede iniciar el escaneo. status: 0x%02x" +msgid "Failed to connect: timeout" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to continue scanning, err 0x%04x" msgstr "No se puede iniciar el escaneo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to create mutex" -msgstr "No se puede leer el valor del atributo. status 0x%02x" - #: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" @@ -662,12 +628,7 @@ msgstr "No se puede escribir el valor del atributo. status: 0x%02x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "No se puede agregar el Vendor Specific 128-bit UUID." -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to release mutex" -msgstr "No se puede liberar el mutex, status: 0x%08lX" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "No se puede liberar el mutex, status: 0x%08lX" @@ -677,36 +638,31 @@ msgstr "No se puede liberar el mutex, status: 0x%08lX" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start advertising" -msgstr "No se puede inicar el anuncio. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "No se puede inicar el anuncio. status: 0x%02x" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start scanning" -msgstr "No se puede iniciar el escaneo. status: 0x%02x" +#, c-format +msgid "Failed to start connecting, error 0x%04x" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to start scanning, err 0x%04x" msgstr "No se puede iniciar el escaneo. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to stop advertising" -msgstr "No se puede detener el anuncio. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "No se puede detener el anuncio. status: 0x%02x" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, fuzzy, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -928,6 +884,10 @@ msgstr "" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "El chip no tiene DAC" @@ -978,6 +938,7 @@ msgstr "No queda espacio en el dispositivo" msgid "No such file/directory" msgstr "No existe el archivo/directorio" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "Not connected" @@ -2177,6 +2138,14 @@ msgstr "ningún módulo se llama '%q'" msgid "no such attribute" msgstr "no hay tal atributo" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "argumento no predeterminado sigue argumento predeterminado" @@ -2393,10 +2362,6 @@ msgstr "" msgid "script compilation not supported" msgstr "script de compilación no soportado" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "services incluye un objeto que no es servicio" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "signo no permitido en el espeficador de string format" @@ -2705,6 +2670,18 @@ msgstr "paso cero" #~ msgid "Address is not %d bytes long or is in wrong format" #~ msgstr "Direción no es %d bytes largo o esta en el formato incorrecto" +#~ msgid "Can't add services in Central mode" +#~ msgstr "No se pueden agregar servicio en modo Central" + +#~ msgid "Can't advertise in Central mode" +#~ msgstr "No se puede anunciar en modo Central" + +#~ msgid "Can't change the name in Central mode" +#~ msgstr "No se puede cambiar el nombre en modo Central" + +#~ msgid "Can't connect in Peripheral mode" +#~ msgstr "No se puede conectar en modo Peripheral" + #~ msgid "Cannot connect to AP" #~ msgstr "No se puede conectar a AP" @@ -2717,6 +2694,10 @@ msgstr "paso cero" #~ msgid "Cannot update i/f status" #~ msgstr "No se puede actualizar i/f status" +#, fuzzy +#~ msgid "Data too large for the advertisement packet" +#~ msgstr "Los datos no caben en el paquete de anuncio." + #~ msgid "Don't know how to pass object to native function" #~ msgstr "No se sabe cómo pasar objeto a función nativa" @@ -2729,6 +2710,26 @@ msgstr "paso cero" #~ msgid "Error in ffi_prep_cif" #~ msgstr "Error en ffi_prep_cif" +#, fuzzy +#~ msgid "Failed to acquire mutex" +#~ msgstr "No se puede adquirir el mutex, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to add service" +#~ msgstr "No se puede detener el anuncio. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to connect:" +#~ msgstr "No se puede conectar. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to continue scanning" +#~ msgstr "No se puede iniciar el escaneo. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to create mutex" +#~ msgstr "No se puede leer el valor del atributo. status 0x%02x" + #, fuzzy #~ msgid "Failed to notify or indicate attribute value, err %0x04x" #~ msgstr "No se puede notificar el valor del anuncio. status: 0x%02x" @@ -2737,6 +2738,22 @@ msgstr "paso cero" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "No se puede leer el valor del atributo. status 0x%02x" +#, fuzzy +#~ msgid "Failed to release mutex" +#~ msgstr "No se puede liberar el mutex, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to start advertising" +#~ msgstr "No se puede inicar el anuncio. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to start scanning" +#~ msgstr "No se puede iniciar el escaneo. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to stop advertising" +#~ msgstr "No se puede detener el anuncio. status: 0x%02x" + #~ msgid "Function requires lock." #~ msgstr "La función requiere lock" @@ -2909,6 +2926,9 @@ msgstr "paso cero" #~ msgid "scan failed" #~ msgstr "scan ha fallado" +#~ msgid "services includes an object that is not a Service" +#~ msgstr "services incluye un objeto que no es servicio" + #~ msgid "too many arguments" #~ msgstr "muchos argumentos" diff --git a/locale/fil.po b/locale/fil.po index 9c688ec14b..951695bb79 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -355,21 +355,9 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "Hindi maarang maglagay ng service sa Central mode" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "Hindi ma advertise habang nasa Central mode" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "Hindi mapalitan ang pangalan sa Central mode" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" -msgstr "Hindi maconnect sa Peripheral mode" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" +msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -498,11 +486,6 @@ msgstr "Dapat sunurin ng Data chunk ang fmt chunk" msgid "Data too large for advertisement packet" msgstr "Hindi makasya ang data sa loob ng advertisement packet" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Data too large for the advertisement packet" -msgstr "Hindi makasya ang data sa loob ng advertisement packet" - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "" @@ -543,6 +526,10 @@ msgstr "Hindi mabasa and Characteristic." msgid "Expected a UUID" msgstr "Umasa ng %q" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -552,12 +539,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to acquire mutex" -msgstr "Nabigo sa pag kuha ng mutex, status: 0x%08lX" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "Nabigo sa pag kuha ng mutex, status: 0x%08lX" @@ -567,11 +549,6 @@ msgstr "Nabigo sa pag kuha ng mutex, status: 0x%08lX" msgid "Failed to add characteristic, err 0x%04x" msgstr "Nabigo sa paglagay ng characteristic, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to add service" -msgstr "Hindi matagumpay ang paglagay ng service, status: 0x%08lX" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to add service, err 0x%04x" @@ -598,25 +575,14 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to connect:" -msgstr "Hindi makaconnect, status: 0x%08lX" - -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to continue scanning" -msgstr "Hindi maituloy ang pag scan, status: 0x%0xlX" +msgid "Failed to connect: timeout" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to continue scanning, err 0x%04x" msgstr "Hindi maituloy ang pag scan, status: 0x%0xlX" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to create mutex" -msgstr "Hindi matagumpay ang pagbuo ng mutex, status: 0x%0xlX" - #: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" @@ -657,12 +623,7 @@ msgstr "Hindi maisulat ang gatts value, status: 0x%08lX" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Hindi matagumpay ang paglagay ng Vender Specific UUID, status: 0x%08lX" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to release mutex" -msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" @@ -672,36 +633,31 @@ msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start advertising" -msgstr "Hindi masimulaan ang advertisement, status: 0x%08lX" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Hindi masimulaan ang advertisement, status: 0x%08lX" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start scanning" -msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" +#, c-format +msgid "Failed to start connecting, error 0x%04x" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to start scanning, err 0x%04x" msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to stop advertising" -msgstr "Hindi mahinto ang advertisement, status: 0x%08lX" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Hindi mahinto ang advertisement, status: 0x%08lX" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, fuzzy, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -923,6 +879,10 @@ msgstr "Ang delay ng startup ng mikropono ay dapat na nasa 0.0 hanggang 1.0" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "Walang DAC sa chip" @@ -973,6 +933,7 @@ msgstr "" msgid "No such file/directory" msgstr "Walang file/directory" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "Not connected" @@ -2179,6 +2140,14 @@ msgstr "walang module na '%q'" msgid "no such attribute" msgstr "walang ganoon na attribute" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "non-default argument sumusunod sa default argument" @@ -2392,10 +2361,6 @@ msgstr "puno na ang schedule stack" msgid "script compilation not supported" msgstr "script kompilasyon hindi supportado" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "sign hindi maaring string format specifier" @@ -2704,6 +2669,18 @@ msgstr "zero step" #~ msgid "C-level assert" #~ msgstr "C-level assert" +#~ msgid "Can't add services in Central mode" +#~ msgstr "Hindi maarang maglagay ng service sa Central mode" + +#~ msgid "Can't advertise in Central mode" +#~ msgstr "Hindi ma advertise habang nasa Central mode" + +#~ msgid "Can't change the name in Central mode" +#~ msgstr "Hindi mapalitan ang pangalan sa Central mode" + +#~ msgid "Can't connect in Peripheral mode" +#~ msgstr "Hindi maconnect sa Peripheral mode" + #~ msgid "Cannot connect to AP" #~ msgstr "Hindi maka connect sa AP" @@ -2716,6 +2693,10 @@ msgstr "zero step" #~ msgid "Cannot update i/f status" #~ msgstr "Hindi ma-update i/f status" +#, fuzzy +#~ msgid "Data too large for the advertisement packet" +#~ msgstr "Hindi makasya ang data sa loob ng advertisement packet" + #~ msgid "Don't know how to pass object to native function" #~ msgstr "Hindi alam ipasa ang object sa native function" @@ -2728,6 +2709,26 @@ msgstr "zero step" #~ msgid "Error in ffi_prep_cif" #~ msgstr "Pagkakamali sa ffi_prep_cif" +#, fuzzy +#~ msgid "Failed to acquire mutex" +#~ msgstr "Nabigo sa pag kuha ng mutex, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to add service" +#~ msgstr "Hindi matagumpay ang paglagay ng service, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to connect:" +#~ msgstr "Hindi makaconnect, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to continue scanning" +#~ msgstr "Hindi maituloy ang pag scan, status: 0x%0xlX" + +#, fuzzy +#~ msgid "Failed to create mutex" +#~ msgstr "Hindi matagumpay ang pagbuo ng mutex, status: 0x%0xlX" + #, fuzzy #~ msgid "Failed to notify or indicate attribute value, err %0x04x" #~ msgstr "Hindi mabalitaan ang attribute value, status: 0x%08lX" @@ -2736,6 +2737,22 @@ msgstr "zero step" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Hindi mabasa ang value ng attribute, status: 0x%08lX" +#, fuzzy +#~ msgid "Failed to release mutex" +#~ msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to start advertising" +#~ msgstr "Hindi masimulaan ang advertisement, status: 0x%08lX" + +#, fuzzy +#~ msgid "Failed to start scanning" +#~ msgstr "Hindi masimulaan mag i-scan, status: 0x%0xlX" + +#, fuzzy +#~ msgid "Failed to stop advertising" +#~ msgstr "Hindi mahinto ang advertisement, status: 0x%08lX" + #~ msgid "Function requires lock." #~ msgstr "Kailangan ng lock ang function." diff --git a/locale/fr.po b/locale/fr.po index 60122a5d0b..abed1204c5 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -360,21 +360,9 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Impossible d'utiliser 'dotstar' avec %s" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "Impossible d'ajouter des services en mode Central" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "Impossible de publier en mode Central" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "Modification du nom impossible en mode Central" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" -msgstr "Impossible de se connecter en mode 'Peripheral'" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" +msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -503,10 +491,6 @@ msgstr "Un bloc de données doit suivre un bloc de format" msgid "Data too large for advertisement packet" msgstr "Données trop volumineuses pour un paquet de diffusion" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Data too large for the advertisement packet" -msgstr "Données trop volumineuses pour le paquet de diffusion" - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "La capacité de destination est plus petite que 'destination_length'." @@ -546,6 +530,10 @@ msgstr "Une 'Characteristic' est attendue" msgid "Expected a UUID" msgstr "Un UUID est attendu" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -555,12 +543,7 @@ msgstr "Tuple de longueur %d attendu, obtenu %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to acquire mutex" -msgstr "Echec de l'obtention de mutex" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "Echec de l'obtention de mutex, err 0x%04x" @@ -570,11 +553,6 @@ msgstr "Echec de l'obtention de mutex, err 0x%04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Echec de l'ajout de caractéristique, err 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to add service" -msgstr "Echec de l'ajout de service" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to add service, err 0x%04x" @@ -601,25 +579,14 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to connect:" -msgstr "Echec de connection:" - -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to continue scanning" -msgstr "Impossible de poursuivre le scan" +msgid "Failed to connect: timeout" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to continue scanning, err 0x%04x" msgstr "Impossible de poursuivre le scan, err 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to create mutex" -msgstr "Echec de la création de mutex" - #: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" @@ -661,12 +628,7 @@ msgstr "Impossible de lire la valeur de 'gatts', err 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Echec de l'ajout de l'UUID du fournisseur, err 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to release mutex" -msgstr "Impossible de libérer mutex" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "Impossible de libérer mutex, err 0x%04x" @@ -676,36 +638,31 @@ msgstr "Impossible de libérer mutex, err 0x%04x" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start advertising" -msgstr "Echec du démarrage de la diffusion" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Impossible de commencer à diffuser, err 0x%04x" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start scanning" -msgstr "Impossible de commencer à scanner" +#, c-format +msgid "Failed to start connecting, error 0x%04x" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to start scanning, err 0x%04x" msgstr "Impossible de commencer à scanner, err 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to stop advertising" -msgstr "Echec de l'arrêt de diffusion" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Echec de l'arrêt de diffusion, err 0x%04x" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, fuzzy, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -931,6 +888,10 @@ msgstr "Le délais au démarrage du micro doit être entre 0.0 et 1.0" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "Pas de DAC sur la puce" @@ -981,6 +942,7 @@ msgstr "Il n'y a plus d'espace libre sur le périphérique" msgid "No such file/directory" msgstr "Fichier/dossier introuvable" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "Not connected" @@ -2212,6 +2174,14 @@ msgstr "pas de module '%q'" msgid "no such attribute" msgstr "pas de tel attribut" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "" @@ -2432,10 +2402,6 @@ msgstr "pile de planification pleine" msgid "script compilation not supported" msgstr "compilation de script non supportée" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "'services' inclut un object qui n'est pas un 'Service'" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "signe non autorisé dans les spéc. de formats de chaînes de caractères" @@ -2747,6 +2713,18 @@ msgstr "'step' nul" #~ msgid "Address is not %d bytes long or is in wrong format" #~ msgstr "L'adresse n'est pas longue de %d octets ou est d'un format erroné" +#~ msgid "Can't add services in Central mode" +#~ msgstr "Impossible d'ajouter des services en mode Central" + +#~ msgid "Can't advertise in Central mode" +#~ msgstr "Impossible de publier en mode Central" + +#~ msgid "Can't change the name in Central mode" +#~ msgstr "Modification du nom impossible en mode Central" + +#~ msgid "Can't connect in Peripheral mode" +#~ msgstr "Impossible de se connecter en mode 'Peripheral'" + #~ msgid "Cannot connect to AP" #~ msgstr "Impossible de se connecter à 'AP'" @@ -2759,6 +2737,9 @@ msgstr "'step' nul" #~ msgid "Cannot update i/f status" #~ msgstr "le status i/f ne peut être mis à jour" +#~ msgid "Data too large for the advertisement packet" +#~ msgstr "Données trop volumineuses pour le paquet de diffusion" + #~ msgid "Don't know how to pass object to native function" #~ msgstr "Ne sais pas comment passer l'objet à une fonction native" @@ -2771,6 +2752,26 @@ msgstr "'step' nul" #~ msgid "Error in ffi_prep_cif" #~ msgstr "Erreur dans ffi_prep_cif" +#, fuzzy +#~ msgid "Failed to acquire mutex" +#~ msgstr "Echec de l'obtention de mutex" + +#, fuzzy +#~ msgid "Failed to add service" +#~ msgstr "Echec de l'ajout de service" + +#, fuzzy +#~ msgid "Failed to connect:" +#~ msgstr "Echec de connection:" + +#, fuzzy +#~ msgid "Failed to continue scanning" +#~ msgstr "Impossible de poursuivre le scan" + +#, fuzzy +#~ msgid "Failed to create mutex" +#~ msgstr "Echec de la création de mutex" + #, fuzzy #~ msgid "Failed to notify or indicate attribute value, err %0x04x" #~ msgstr "Impossible de notifier la valeur de l'attribut. status: 0x%08lX" @@ -2779,6 +2780,22 @@ msgstr "'step' nul" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Impossible de lire la valeur de l'attribut. status: 0x%08lX" +#, fuzzy +#~ msgid "Failed to release mutex" +#~ msgstr "Impossible de libérer mutex" + +#, fuzzy +#~ msgid "Failed to start advertising" +#~ msgstr "Echec du démarrage de la diffusion" + +#, fuzzy +#~ msgid "Failed to start scanning" +#~ msgstr "Impossible de commencer à scanner" + +#, fuzzy +#~ msgid "Failed to stop advertising" +#~ msgstr "Echec de l'arrêt de diffusion" + #~ msgid "Function requires lock." #~ msgstr "La fonction nécessite un verrou." @@ -2936,6 +2953,9 @@ msgstr "'step' nul" #~ msgid "scan failed" #~ msgstr "échec du scan" +#~ msgid "services includes an object that is not a Service" +#~ msgstr "'services' inclut un object qui n'est pas un 'Service'" + #~ msgid "too many arguments" #~ msgstr "trop d'arguments" diff --git a/locale/it_IT.po b/locale/it_IT.po index 6f0e90e176..0637d2e493 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -355,21 +355,9 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "dotstar non può essere usato con %s" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "non si può aggiungere servizi in Central mode" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "non si può pubblicizzare in Central mode" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "non si può cambiare il nome in Central mode" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" -msgstr "non si può connettere in Periferal mode" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" +msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -499,11 +487,6 @@ msgstr "" msgid "Data too large for advertisement packet" msgstr "Impossibile inserire dati nel pacchetto di advertisement." -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Data too large for the advertisement packet" -msgstr "Impossibile inserire dati nel pacchetto di advertisement." - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "La capacità di destinazione è più piccola di destination_length." @@ -543,6 +526,10 @@ msgstr "Non è possibile aggiungere Characteristic." msgid "Expected a UUID" msgstr "Atteso un %q" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -552,12 +539,7 @@ msgstr "" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to acquire mutex" -msgstr "Impossibile allocare buffer RX" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" @@ -567,11 +549,6 @@ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Impossibile fermare advertisement. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to add service" -msgstr "Impossibile fermare advertisement. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to add service, err 0x%04x" @@ -598,25 +575,14 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to connect:" -msgstr "Impossibile connettersi. status: 0x%02x" - -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to continue scanning" -msgstr "Impossible iniziare la scansione. status: 0x%02x" +msgid "Failed to connect: timeout" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to continue scanning, err 0x%04x" msgstr "Impossible iniziare la scansione. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to create mutex" -msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" @@ -656,12 +622,7 @@ msgstr "Impossibile scrivere valore dell'attributo. status: 0x%02x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Non è possibile aggiungere l'UUID del vendor specifico da 128-bit" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to release mutex" -msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" @@ -671,36 +632,31 @@ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start advertising" -msgstr "Impossibile avviare advertisement. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Impossibile avviare advertisement. status: 0x%02x" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start scanning" -msgstr "Impossible iniziare la scansione. status: 0x%02x" +#, c-format +msgid "Failed to start connecting, error 0x%04x" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to start scanning, err 0x%04x" msgstr "Impossible iniziare la scansione. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to stop advertising" -msgstr "Impossibile fermare advertisement. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Impossibile fermare advertisement. status: 0x%02x" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, fuzzy, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -922,6 +878,10 @@ msgstr "" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "Nessun DAC sul chip" @@ -972,6 +932,7 @@ msgstr "Non che spazio sul dispositivo" msgid "No such file/directory" msgstr "Nessun file/directory esistente" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "Not connected" @@ -2173,6 +2134,14 @@ msgstr "nessun modulo chiamato '%q'" msgid "no such attribute" msgstr "attributo inesistente" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "argomento non predefinito segue argmoento predfinito" @@ -2390,10 +2359,6 @@ msgstr "" msgid "script compilation not supported" msgstr "compilazione dello scrip non suportata" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "segno non permesso nello spcificatore di formato della stringa" @@ -2702,6 +2667,18 @@ msgstr "zero step" #~ msgid "C-level assert" #~ msgstr "assert a livello C" +#~ msgid "Can't add services in Central mode" +#~ msgstr "non si può aggiungere servizi in Central mode" + +#~ msgid "Can't advertise in Central mode" +#~ msgstr "non si può pubblicizzare in Central mode" + +#~ msgid "Can't change the name in Central mode" +#~ msgstr "non si può cambiare il nome in Central mode" + +#~ msgid "Can't connect in Peripheral mode" +#~ msgstr "non si può connettere in Periferal mode" + #~ msgid "Cannot connect to AP" #~ msgstr "Impossible connettersi all'AP" @@ -2714,6 +2691,10 @@ msgstr "zero step" #~ msgid "Cannot update i/f status" #~ msgstr "Impossibile aggiornare status di i/f" +#, fuzzy +#~ msgid "Data too large for the advertisement packet" +#~ msgstr "Impossibile inserire dati nel pacchetto di advertisement." + #~ msgid "Don't know how to pass object to native function" #~ msgstr "Non so come passare l'oggetto alla funzione nativa" @@ -2726,6 +2707,26 @@ msgstr "zero step" #~ msgid "Error in ffi_prep_cif" #~ msgstr "Errore in ffi_prep_cif" +#, fuzzy +#~ msgid "Failed to acquire mutex" +#~ msgstr "Impossibile allocare buffer RX" + +#, fuzzy +#~ msgid "Failed to add service" +#~ msgstr "Impossibile fermare advertisement. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to connect:" +#~ msgstr "Impossibile connettersi. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to continue scanning" +#~ msgstr "Impossible iniziare la scansione. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to create mutex" +#~ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" + #, fuzzy #~ msgid "Failed to notify or indicate attribute value, err %0x04x" #~ msgstr "Impossibile notificare valore dell'attributo. status: 0x%02x" @@ -2734,6 +2735,22 @@ msgstr "zero step" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" +#, fuzzy +#~ msgid "Failed to release mutex" +#~ msgstr "Impossibile leggere valore dell'attributo. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to start advertising" +#~ msgstr "Impossibile avviare advertisement. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to start scanning" +#~ msgstr "Impossible iniziare la scansione. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to stop advertising" +#~ msgstr "Impossibile fermare advertisement. status: 0x%02x" + #~ msgid "GPIO16 does not support pull up." #~ msgstr "GPIO16 non supporta pull-up" diff --git a/locale/pl.po b/locale/pl.po index a7155e0c8d..4ea878146a 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -351,21 +351,9 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Nie można używać dotstar z %s" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "Nie można dodać serwisów w trybie Central" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "Nie można rozgłaszać w trybie Central" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "Nie można zmienić nazwy w trybie Central" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" -msgstr "Nie można się łączyć w trybie Peripheral" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" +msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -490,10 +478,6 @@ msgstr "Fragment danych musi następować po fragmencie fmt" msgid "Data too large for advertisement packet" msgstr "Zbyt dużo danych pakietu rozgłoszeniowego" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Data too large for the advertisement packet" -msgstr "Zbyt dużo danych pakietu rozgłoszeniowego" - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "Pojemność celu mniejsza od destination_length." @@ -531,6 +515,10 @@ msgstr "Oczekiwano charakterystyki" msgid "Expected a UUID" msgstr "Oczekiwano UUID" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -540,11 +528,7 @@ msgstr "Oczekiwano krotkę długości %d, otrzymano %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to acquire mutex" -msgstr "Nie udało się uzyskać blokady" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "Nie udało się uzyskać blokady, błąd 0x$04x" @@ -554,10 +538,6 @@ msgstr "Nie udało się uzyskać blokady, błąd 0x$04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Nie udało się dodać charakterystyki, błąd 0x$04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to add service" -msgstr "Nie udało się dodać serwisu" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to add service, err 0x%04x" @@ -583,22 +563,14 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to connect:" -msgstr "Nie udało się połączenie:" - -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to continue scanning" -msgstr "Nie udała się kontynuacja skanowania" +msgid "Failed to connect: timeout" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, c-format msgid "Failed to continue scanning, err 0x%04x" msgstr "Nie udała się kontynuacja skanowania, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to create mutex" -msgstr "Nie udało się stworzyć blokady" - #: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "Nie udało się odkryć serwisów" @@ -636,11 +608,7 @@ msgstr "Nie udało się odczytać gatts, błąd 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Nie udało się zarejestrować UUID dostawcy, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to release mutex" -msgstr "Nie udało się zwolnić blokady" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "Nie udało się zwolnić blokady, błąd 0x%04x" @@ -650,33 +618,31 @@ msgstr "Nie udało się zwolnić blokady, błąd 0x%04x" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start advertising" -msgstr "Nie udało się rozpocząć rozgłaszania" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Nie udało się rozpocząć rozgłaszania, błąd 0x%04x" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start scanning" -msgstr "Nie udało się rozpocząć skanowania" +#, c-format +msgid "Failed to start connecting, error 0x%04x" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, c-format msgid "Failed to start scanning, err 0x%04x" msgstr "Nie udało się rozpocząć skanowania, błąd 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to stop advertising" -msgstr "Nie udało się zatrzymać rozgłaszania" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Nie udało się zatrzymać rozgłaszania, błąd 0x%04x" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -899,6 +865,10 @@ msgstr "Opóźnienie włączenia mikrofonu musi być w zakresie od 0.0 do 1.0" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "Brak DAC" @@ -949,6 +919,7 @@ msgstr "Brak miejsca" msgid "No such file/directory" msgstr "Brak pliku/katalogu" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c msgid "Not connected" msgstr "Nie podłączono" @@ -2123,6 +2094,14 @@ msgstr "brak modułu o nazwie '%q'" msgid "no such attribute" msgstr "nie ma takiego atrybutu" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "argument z wartością domyślną przed argumentem bez" @@ -2333,10 +2312,6 @@ msgstr "stos planu pełen" msgid "script compilation not supported" msgstr "kompilowanie skryptów nieobsługiwane" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "obiekt typu innego niż Service w services" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "znak jest niedopuszczalny w specyfikacji formatu łańcucha" @@ -2638,6 +2613,48 @@ msgstr "zerowy krok" #~ msgid "Address is not %d bytes long or is in wrong format" #~ msgstr "Adres nie ma długości %d bajtów lub zły format" +#~ msgid "Can't add services in Central mode" +#~ msgstr "Nie można dodać serwisów w trybie Central" + +#~ msgid "Can't advertise in Central mode" +#~ msgstr "Nie można rozgłaszać w trybie Central" + +#~ msgid "Can't change the name in Central mode" +#~ msgstr "Nie można zmienić nazwy w trybie Central" + +#~ msgid "Can't connect in Peripheral mode" +#~ msgstr "Nie można się łączyć w trybie Peripheral" + +#~ msgid "Data too large for the advertisement packet" +#~ msgstr "Zbyt dużo danych pakietu rozgłoszeniowego" + +#~ msgid "Failed to acquire mutex" +#~ msgstr "Nie udało się uzyskać blokady" + +#~ msgid "Failed to add service" +#~ msgstr "Nie udało się dodać serwisu" + +#~ msgid "Failed to connect:" +#~ msgstr "Nie udało się połączenie:" + +#~ msgid "Failed to continue scanning" +#~ msgstr "Nie udała się kontynuacja skanowania" + +#~ msgid "Failed to create mutex" +#~ msgstr "Nie udało się stworzyć blokady" + +#~ msgid "Failed to release mutex" +#~ msgstr "Nie udało się zwolnić blokady" + +#~ msgid "Failed to start advertising" +#~ msgstr "Nie udało się rozpocząć rozgłaszania" + +#~ msgid "Failed to start scanning" +#~ msgstr "Nie udało się rozpocząć skanowania" + +#~ msgid "Failed to stop advertising" +#~ msgstr "Nie udało się zatrzymać rozgłaszania" + #~ msgid "Invalid bit clock pin" #~ msgstr "Zła nóżka zegara" @@ -2655,3 +2672,6 @@ msgstr "zerowy krok" #~ msgid "interval not in range 0.0020 to 10.24" #~ msgstr "przedział poza zakresem 0.0020 do 10.24" + +#~ msgid "services includes an object that is not a Service" +#~ msgstr "obiekt typu innego niż Service w services" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 01eda181f5..d924171566 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -352,20 +352,8 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c @@ -494,11 +482,6 @@ msgstr "Pedaço de dados deve seguir o pedaço de cortes" msgid "Data too large for advertisement packet" msgstr "Não é possível ajustar dados no pacote de anúncios." -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Data too large for the advertisement packet" -msgstr "Não é possível ajustar dados no pacote de anúncios." - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "" @@ -538,6 +521,10 @@ msgstr "Não é possível adicionar Característica." msgid "Expected a UUID" msgstr "Esperado um" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -547,12 +534,7 @@ msgstr "" msgid "Failed sending command." msgstr "Falha ao enviar comando." -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to acquire mutex" -msgstr "Falha ao alocar buffer RX" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "Não é possível ler o valor do atributo. status: 0x%02x" @@ -562,11 +544,6 @@ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Não pode parar propaganda. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to add service" -msgstr "Não pode parar propaganda. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to add service, err 0x%04x" @@ -593,11 +570,7 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to connect:" -msgstr "" - -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to continue scanning" +msgid "Failed to connect: timeout" msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c @@ -605,11 +578,6 @@ msgstr "" msgid "Failed to continue scanning, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to create mutex" -msgstr "Não é possível ler o valor do atributo. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Central.c #, fuzzy msgid "Failed to discover services" @@ -649,12 +617,7 @@ msgstr "Não é possível gravar o valor do atributo. status: 0x%02x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Não é possível adicionar o UUID de 128 bits específico do fornecedor." -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to release mutex" -msgstr "Não é possível ler o valor do atributo. status: 0x%02x" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, fuzzy, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "Não é possível ler o valor do atributo. status: 0x%02x" @@ -664,36 +627,31 @@ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start advertising" -msgstr "Não é possível iniciar o anúncio. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" #: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to start scanning" -msgstr "Não é possível iniciar o anúncio. status: 0x%02x" +#, c-format +msgid "Failed to start connecting, error 0x%04x" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, fuzzy, c-format msgid "Failed to start scanning, err 0x%04x" msgstr "Não é possível iniciar o anúncio. status: 0x%02x" -#: ports/nrf/common-hal/bleio/Central.c -#, fuzzy -msgid "Failed to stop advertising" -msgstr "Não pode parar propaganda. status: 0x%02x" - #: ports/nrf/common-hal/bleio/Peripheral.c #, fuzzy, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Não pode parar propaganda. status: 0x%02x" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, fuzzy, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -912,6 +870,10 @@ msgstr "" msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "Nenhum DAC no chip" @@ -962,6 +924,7 @@ msgstr "" msgid "No such file/directory" msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c #, fuzzy msgid "Not connected" @@ -2132,6 +2095,14 @@ msgstr "" msgid "no such attribute" msgstr "" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "" @@ -2341,10 +2312,6 @@ msgstr "" msgid "script compilation not supported" msgstr "compilação de script não suportada" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "" @@ -2660,6 +2627,10 @@ msgstr "passo zero" #~ msgid "Cannot update i/f status" #~ msgstr "Não é possível atualizar o status i/f" +#, fuzzy +#~ msgid "Data too large for the advertisement packet" +#~ msgstr "Não é possível ajustar dados no pacote de anúncios." + #~ msgid "Don't know how to pass object to native function" #~ msgstr "Não sabe como passar o objeto para a função nativa" @@ -2672,6 +2643,18 @@ msgstr "passo zero" #~ msgid "Error in ffi_prep_cif" #~ msgstr "Erro no ffi_prep_cif" +#, fuzzy +#~ msgid "Failed to acquire mutex" +#~ msgstr "Falha ao alocar buffer RX" + +#, fuzzy +#~ msgid "Failed to add service" +#~ msgstr "Não pode parar propaganda. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to create mutex" +#~ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" + #, fuzzy #~ msgid "Failed to notify or indicate attribute value, err %0x04x" #~ msgstr "Não é possível gravar o valor do atributo. status: 0x%02x" @@ -2680,6 +2663,22 @@ msgstr "passo zero" #~ msgid "Failed to read attribute value, err %0x04x" #~ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" +#, fuzzy +#~ msgid "Failed to release mutex" +#~ msgstr "Não é possível ler o valor do atributo. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to start advertising" +#~ msgstr "Não é possível iniciar o anúncio. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to start scanning" +#~ msgstr "Não é possível iniciar o anúncio. status: 0x%02x" + +#, fuzzy +#~ msgid "Failed to stop advertising" +#~ msgstr "Não pode parar propaganda. status: 0x%02x" + #~ msgid "GPIO16 does not support pull up." #~ msgstr "GPIO16 não suporta pull up." diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 79d803d674..c48cb6b2c7 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-06-19 09:49-0400\n" +"POT-Creation-Date: 2019-07-09 08:43-0400\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -352,21 +352,9 @@ msgstr "" msgid "Can not use dotstar with %s" msgstr "Wúfǎ yǔ dotstar yīqǐ shǐyòng %s" -#: shared-bindings/bleio/Central.c -msgid "Can't add services in Central mode" -msgstr "Wúfǎ zài zhōngyāng móshì xià tiānjiā fúwù" - -#: shared-bindings/bleio/Central.c -msgid "Can't advertise in Central mode" -msgstr "Wúfǎ zài zhōngyāng móshì zhōng guǎnggào" - -#: shared-bindings/bleio/Central.c -msgid "Can't change the name in Central mode" -msgstr "Wúfǎ gēnggǎi zhōngyāng móshì de míngchēng" - -#: shared-bindings/bleio/Central.c -msgid "Can't connect in Peripheral mode" -msgstr "Wúfǎ zài biānyuán móshì zhōng liánjiē" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "Can't set CCCD for local Characteristic" +msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -491,10 +479,6 @@ msgstr "Shùjù kuài bìxū zūnxún fmt qū kuài" msgid "Data too large for advertisement packet" msgstr "Guǎnggào bāo de shùjù tài dà" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Data too large for the advertisement packet" -msgstr "Guǎnggào bāo de shùjù tài dà" - #: shared-bindings/audiobusio/PDMIn.c msgid "Destination capacity is smaller than destination_length." msgstr "Mùbiāo róngliàng xiǎoyú mùdì de_chángdù." @@ -532,6 +516,10 @@ msgstr "Yùqí de tèdiǎn" msgid "Expected a UUID" msgstr "Yùqí UUID" +#: shared-bindings/bleio/Central.c +msgid "Expected an Address" +msgstr "" + #: shared-module/_pixelbuf/PixelBuf.c #, c-format msgid "Expected tuple of length %d, got %d" @@ -541,11 +529,7 @@ msgstr "Qīwàng de chángdù wèi %d de yuán zǔ, dédào %d" msgid "Failed sending command." msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to acquire mutex" -msgstr "Wúfǎ huòdé mutex" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to acquire mutex, err 0x%04x" msgstr "Wúfǎ huòdé mutex, err 0x%04x" @@ -555,10 +539,6 @@ msgstr "Wúfǎ huòdé mutex, err 0x%04x" msgid "Failed to add characteristic, err 0x%04x" msgstr "Tiānjiā tèxìng shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to add service" -msgstr "Tiānjiā fúwù shībài" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to add service, err 0x%04x" @@ -584,22 +564,14 @@ msgid "Failed to configure advertising, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to connect:" -msgstr "Liánjiē shībài:" - -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to continue scanning" -msgstr "Jìxù sǎomiáo shībài" +msgid "Failed to connect: timeout" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, c-format msgid "Failed to continue scanning, err 0x%04x" msgstr "Jìxù sǎomiáo shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to create mutex" -msgstr "Wúfǎ chuàngjiàn hù chì suǒ" - #: ports/nrf/common-hal/bleio/Central.c msgid "Failed to discover services" msgstr "Fāxiàn fúwù shībài" @@ -637,11 +609,7 @@ msgstr "Wúfǎ dòu qǔ gatts zhí, err 0x%04x" msgid "Failed to register Vendor-Specific UUID, err 0x%04x" msgstr "Wúfǎ zhùcè màizhǔ tèdìng de UUID, err 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to release mutex" -msgstr "Wúfǎ shìfàng mutex" - -#: ports/nrf/common-hal/bleio/Characteristic.c ports/nrf/sd_mutex.c +#: ports/nrf/sd_mutex.c #, c-format msgid "Failed to release mutex, err 0x%04x" msgstr "Wúfǎ shìfàng mutex, err 0x%04x" @@ -651,33 +619,31 @@ msgstr "Wúfǎ shìfàng mutex, err 0x%04x" msgid "Failed to set device name, err 0x%04x" msgstr "" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start advertising" -msgstr "Qǐdòng guǎnggào shībài" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to start advertising, err 0x%04x" msgstr "Qǐdòng guǎnggào shībài, err 0x%04x" #: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to start scanning" -msgstr "Qǐdòng sǎomiáo shībài" +#, c-format +msgid "Failed to start connecting, error 0x%04x" +msgstr "" #: ports/nrf/common-hal/bleio/Scanner.c #, c-format msgid "Failed to start scanning, err 0x%04x" msgstr "Qǐdòng sǎomiáo shībài, err 0x%04x" -#: ports/nrf/common-hal/bleio/Central.c -msgid "Failed to stop advertising" -msgstr "Wúfǎ tíngzhǐ guǎnggào" - #: ports/nrf/common-hal/bleio/Peripheral.c #, c-format msgid "Failed to stop advertising, err 0x%04x" msgstr "Wúfǎ tíngzhǐ guǎnggào, err 0x%04x" +#: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format +msgid "Failed to write CCCD, err 0x%04x" +msgstr "" + #: ports/nrf/common-hal/bleio/Characteristic.c #, c-format msgid "Failed to write attribute value, err 0x%04x" @@ -899,6 +865,10 @@ msgstr "Màikèfēng qǐdòng yánchí bìxū zài 0.0 Dào 1.0 De fànwéi nèi msgid "Must be a %q subclass." msgstr "" +#: ports/nrf/common-hal/bleio/Characteristic.c +msgid "No CCCD for this Characteristic" +msgstr "" + #: ports/atmel-samd/common-hal/analogio/AnalogOut.c msgid "No DAC on chip" msgstr "Méiyǒu DAC zài xīnpiàn shàng de" @@ -949,6 +919,7 @@ msgstr "Shèbèi shàng méiyǒu kònggé" msgid "No such file/directory" msgstr "Méiyǒu cǐ lèi wénjiàn/mùlù" +#: ports/nrf/common-hal/bleio/Characteristic.c #: shared-bindings/bleio/CharacteristicBuffer.c msgid "Not connected" msgstr "Wèi liánjiē" @@ -2135,6 +2106,14 @@ msgstr "méiyǒu mókuài '%q'" msgid "no such attribute" msgstr "méiyǒu cǐ shǔxìng" +#: shared-bindings/bleio/Peripheral.c +msgid "non-Service found in services" +msgstr "" + +#: ports/nrf/common-hal/bleio/Central.c +msgid "non-UUID found in service_uuids" +msgstr "" + #: py/compile.c msgid "non-default argument follows default argument" msgstr "bùshì mòrèn cānshù zūnxún mòrèn cānshù" @@ -2345,10 +2324,6 @@ msgstr "jìhuà duīzhàn yǐ mǎn" msgid "script compilation not supported" msgstr "bù zhīchí jiǎoběn biānyì" -#: shared-bindings/bleio/Peripheral.c -msgid "services includes an object that is not a Service" -msgstr "fúwù bāokuò yīgè bùshì fúwù de wùjiàn" - #: py/objstr.c msgid "sign not allowed in string format specifier" msgstr "zìfú chuàn géshì shuōmíng fú zhōng bù yǔnxǔ shǐyòng fúhào" @@ -2650,6 +2625,48 @@ msgstr "líng bù" #~ msgid "Address is not %d bytes long or is in wrong format" #~ msgstr "Dìzhǐ bùshì %d zì jié zhǎng, huòzhě géshì cuòwù" +#~ msgid "Can't add services in Central mode" +#~ msgstr "Wúfǎ zài zhōngyāng móshì xià tiānjiā fúwù" + +#~ msgid "Can't advertise in Central mode" +#~ msgstr "Wúfǎ zài zhōngyāng móshì zhōng guǎnggào" + +#~ msgid "Can't change the name in Central mode" +#~ msgstr "Wúfǎ gēnggǎi zhōngyāng móshì de míngchēng" + +#~ msgid "Can't connect in Peripheral mode" +#~ msgstr "Wúfǎ zài biānyuán móshì zhōng liánjiē" + +#~ msgid "Data too large for the advertisement packet" +#~ msgstr "Guǎnggào bāo de shùjù tài dà" + +#~ msgid "Failed to acquire mutex" +#~ msgstr "Wúfǎ huòdé mutex" + +#~ msgid "Failed to add service" +#~ msgstr "Tiānjiā fúwù shībài" + +#~ msgid "Failed to connect:" +#~ msgstr "Liánjiē shībài:" + +#~ msgid "Failed to continue scanning" +#~ msgstr "Jìxù sǎomiáo shībài" + +#~ msgid "Failed to create mutex" +#~ msgstr "Wúfǎ chuàngjiàn hù chì suǒ" + +#~ msgid "Failed to release mutex" +#~ msgstr "Wúfǎ shìfàng mutex" + +#~ msgid "Failed to start advertising" +#~ msgstr "Qǐdòng guǎnggào shībài" + +#~ msgid "Failed to start scanning" +#~ msgstr "Qǐdòng sǎomiáo shībài" + +#~ msgid "Failed to stop advertising" +#~ msgstr "Wúfǎ tíngzhǐ guǎnggào" + #~ msgid "Invalid bit clock pin" #~ msgstr "Wúxiào de wèi shízhōng yǐn jiǎo" @@ -2686,6 +2703,9 @@ msgstr "líng bù" #~ msgid "row must be packed and word aligned" #~ msgstr "xíng bìxū dǎbāo bìngqiě zì duìqí" +#~ msgid "services includes an object that is not a Service" +#~ msgstr "fúwù bāokuò yīgè bùshì fúwù de wùjiàn" + #~ msgid "too many arguments" #~ msgstr "tài duō cānshù" From d8a4f71ec77a9aa8f5e037a94b7dd72022f24e86 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 9 Jul 2019 09:11:04 -0400 Subject: [PATCH 45/61] translation merges --- locale/ID.po | 6 +++--- locale/circuitpython.pot | 6 +++--- locale/de_DE.po | 6 +++--- locale/en_US.po | 6 +++--- locale/en_x_pirate.po | 6 +++--- locale/es.po | 31 ++++++++++++++++++------------- locale/fil.po | 6 +++--- locale/fr.po | 6 +++--- locale/it_IT.po | 6 +++--- locale/pl.po | 6 +++--- locale/pt_BR.po | 6 +++--- locale/zh_Latn_pinyin.po | 6 +++--- 12 files changed, 51 insertions(+), 46 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 65e21e5e4c..33e63bd2ce 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1341,8 +1341,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "argumen num/types tidak cocok" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index eb1c3cc739..6b38f11e31 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:07-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1308,8 +1308,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index dc9199dbc0..cf115716fb 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -1348,8 +1348,8 @@ msgstr "arg ist eine leere Sequenz" msgid "argument has wrong type" msgstr "Argument hat falschen Typ" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "Anzahl/Type der Argumente passen nicht" diff --git a/locale/en_US.po b/locale/en_US.po index a7b7cb36bd..ab1776aa24 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -1308,8 +1308,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index dc157140c5..550966a943 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -1312,8 +1312,8 @@ msgstr "" msgid "argument has wrong type" msgstr "" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "" diff --git a/locale/es.po b/locale/es.po index 441b1af5c5..a1e90b0eb9 100644 --- a/locale/es.po +++ b/locale/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:07-0400\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -219,11 +219,6 @@ msgstr "pow() con 3 argumentos no soportado" msgid "A hardware interrupt channel is already in use" msgstr "El canal EXTINT ya está siendo utilizado" -#: shared-bindings/bleio/Address.c -#, c-format -msgid "Address is not %d bytes long or is in wrong format" -msgstr "Direción no es %d bytes largo o esta en el formato incorrecto" - #: shared-bindings/bleio/Address.c #, c-format msgid "Address must be %d bytes long" @@ -251,7 +246,9 @@ msgstr "Todos los canales de eventos estan siendo usados" #: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "All sync event channels in use" -msgstr "Todos los canales de eventos de sincronización (sync event channels) están siendo utilizados" +msgstr "" +"Todos los canales de eventos de sincronización (sync event channels) están " +"siendo utilizados" #: shared-bindings/pulseio/PWMOut.c msgid "All timers for this pin are in use" @@ -291,7 +288,9 @@ msgstr "Valores del array deben ser bytes individuales." #: supervisor/shared/safe_mode.c msgid "Attempted heap allocation when MicroPython VM not running.\n" -msgstr "Intento de allocation de heap cuando la VM de MicroPython no estaba corriendo.\n" +msgstr "" +"Intento de allocation de heap cuando la VM de MicroPython no estaba " +"corriendo.\n" #: main.c msgid "Auto-reload is off.\n" @@ -301,7 +300,9 @@ msgstr "Auto-recarga deshabilitada.\n" msgid "" "Auto-reload is on. Simply save files over USB to run them or enter REPL to " "disable.\n" -msgstr "Auto-reload habilitado. Simplemente guarda los archivos via USB para ejecutarlos o entra al REPL para desabilitarlos.\n" +msgstr "" +"Auto-reload habilitado. Simplemente guarda los archivos via USB para " +"ejecutarlos o entra al REPL para desabilitarlos.\n" #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c msgid "Bit clock and word select must share a clock unit" @@ -657,6 +658,7 @@ msgid "Failed to write CCCD, err 0x%04x" msgstr "" #: ports/nrf/common-hal/bleio/Characteristic.c +#, c-format msgid "Failed to write attribute value, err 0x%04x" msgstr "No se puede escribir el valor del atributo. err: 0x%04x" @@ -712,7 +714,9 @@ msgstr "operación I2C no soportada" msgid "" "Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/" "mpy-update for more info." -msgstr "Archivo .mpy incompatible. Actualice todos los archivos .mpy. Consulte http://adafru.it/mpy-update para más información" +msgstr "" +"Archivo .mpy incompatible. Actualice todos los archivos .mpy. Consulte " +"http://adafru.it/mpy-update para más información" #: shared-bindings/_pew/PewPew.c msgid "Incorrect buffer size" @@ -941,7 +945,8 @@ msgstr "No reproduciendo" msgid "" "Object has been deinitialized and can no longer be used. Create a new object." msgstr "" -"El objeto se ha desinicializado y ya no se puede utilizar. Crea un nuevo objeto" +"El objeto se ha desinicializado y ya no se puede utilizar. Crea un nuevo " +"objeto" #: ports/nrf/common-hal/busio/UART.c msgid "Odd parity is not supported" @@ -1352,8 +1357,8 @@ msgstr "argumento es una secuencia vacía" msgid "argument has wrong type" msgstr "el argumento tiene un tipo erroneo" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "argumento número/tipos no coinciden" diff --git a/locale/fil.po b/locale/fil.po index 3e8e53f08b..29e969566d 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -1361,8 +1361,8 @@ msgstr "arg ay walang laman na sequence" msgid "argument has wrong type" msgstr "may maling type ang argument" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "hindi tugma ang argument num/types" diff --git a/locale/fr.po b/locale/fr.po index 4ce6d5e0ba..3a4c418d48 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -1386,8 +1386,8 @@ msgstr "l'argument est une séquence vide" msgid "argument has wrong type" msgstr "l'argument est d'un mauvais type" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "argument num/types ne correspond pas" diff --git a/locale/it_IT.po b/locale/it_IT.po index 47ed3d95c9..7504fb1575 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -1355,8 +1355,8 @@ msgstr "l'argomento è una sequenza vuota" msgid "argument has wrong type" msgstr "il tipo dell'argomento è errato" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "discrepanza di numero/tipo di argomenti" diff --git a/locale/pl.po b/locale/pl.po index 1361119cf0..dd4cf7db4a 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -1332,8 +1332,8 @@ msgstr "arg jest puste" msgid "argument has wrong type" msgstr "argument ma zły typ" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "zła liczba lub typ argumentów" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 897a057f97..8b74349faa 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -1329,8 +1329,8 @@ msgstr "" msgid "argument has wrong type" msgstr "argumento tem tipo errado" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 5f03dc6aa4..d8d11cd858 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 08:43-0400\n" +"POT-Creation-Date: 2019-07-09 09:06-0400\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -1340,8 +1340,8 @@ msgstr "cānshù shì yīgè kōng de xùliè" msgid "argument has wrong type" msgstr "cānshù lèixíng cuòwù" -#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c -#: shared-bindings/gamepad/GamePad.c shared-bindings/_stage/__init__.c +#: py/argcheck.c shared-bindings/_stage/__init__.c +#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c msgid "argument num/types mismatch" msgstr "cānshù biānhào/lèixíng bù pǐpèi" From d905958db1070cae0c250884fa97031cb6fc66c6 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 9 Jul 2019 16:02:39 -0400 Subject: [PATCH 46/61] Adding PyRuler to CircuitPython. --- .travis.yml | 2 +- ports/atmel-samd/boards/pyruler/board.c | 37 +++++++++++ .../atmel-samd/boards/pyruler/mpconfigboard.h | 64 +++++++++++++++++++ .../boards/pyruler/mpconfigboard.mk | 14 ++++ ports/atmel-samd/boards/pyruler/pins.c | 50 +++++++++++++++ 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 ports/atmel-samd/boards/pyruler/board.c create mode 100644 ports/atmel-samd/boards/pyruler/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/pyruler/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/pyruler/pins.c diff --git a/.travis.yml b/.travis.yml index 3290cea030..d75b4e7d4a 100755 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ git: # just try to make the builds "about equal in run time" env: - TRAVIS_TESTS="unix docs translations website" TRAVIS_BOARDS="circuitplayground_express mini_sam_m4 grandcentral_m4_express capablerobot_usbhub pygamer pca10056 pca10059 feather_nrf52840_express makerdiary_nrf52840_mdk makerdiary_nrf52840_mdk_usb_dongle particle_boron particle_argon particle_xenon sparkfun_nrf52840_mini electronut_labs_papyr electronut_labs_blip" TRAVIS_SDK=arm:nrf - - TRAVIS_BOARDS="metro_m0_express metro_m4_express metro_m4_airlift_lite pirkey_m0 trellis_m4_express trinket_m0 sparkfun_lumidrive sparkfun_redboard_turbo bast_pro_mini_m0 datum_distance" TRAVIS_SDK=arm + - TRAVIS_BOARDS="metro_m0_express metro_m4_express metro_m4_airlift_lite pirkey_m0 trellis_m4_express trinket_m0 sparkfun_lumidrive sparkfun_redboard_turbo bast_pro_mini_m0 datum_distance pyruler" TRAVIS_SDK=arm - TRAVIS_BOARDS="feather_radiofruit_zigbee gemma_m0 hallowing_m0_express itsybitsy_m0_express itsybitsy_m4_express meowmeow sam32 uchip escornabot_makech pygamer_advance datum_imu" TRAVIS_SDK=arm - TRAVIS_BOARDS="feather_m0_express_crickit feather_m0_rfm69 feather_m0_rfm9x feather_m4_express arduino_zero arduino_mkr1300 arduino_mkrzero pewpew10 kicksat-sprite ugame10 robohatmm1 datum_light" TRAVIS_SDK=arm - TRAVIS_BOARDS="circuitplayground_express_crickit feather_m0_adalogger feather_m0_basic feather_m0_express catwan_usbstick pyportal sparkfun_samd21_mini sparkfun_samd21_dev pybadge pybadge_airlift datum_weather" TRAVIS_SDK=arm diff --git a/ports/atmel-samd/boards/pyruler/board.c b/ports/atmel-samd/boards/pyruler/board.c new file mode 100644 index 0000000000..d7e856d611 --- /dev/null +++ b/ports/atmel-samd/boards/pyruler/board.c @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "boards/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/pyruler/mpconfigboard.h b/ports/atmel-samd/boards/pyruler/mpconfigboard.h new file mode 100644 index 0000000000..c2369c4b7f --- /dev/null +++ b/ports/atmel-samd/boards/pyruler/mpconfigboard.h @@ -0,0 +1,64 @@ +#define MICROPY_HW_BOARD_NAME "Adafruit PyRuler" +#define MICROPY_HW_MCU_NAME "samd21e18" + +// Rev B - Black +#define MICROPY_HW_LED_STATUS (&pin_PA10) + +#define MICROPY_HW_APA102_MOSI (&pin_PA00) +#define MICROPY_HW_APA102_SCK (&pin_PA01) + +#define MICROPY_PORT_A (PORT_PA00 | PORT_PA01) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + +#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000 - CIRCUITPY_INTERNAL_NVM_SIZE) + +#define IGNORE_PIN_PA12 1 +#define IGNORE_PIN_PA13 1 +#define IGNORE_PIN_PA16 1 +#define IGNORE_PIN_PA17 1 +#define IGNORE_PIN_PA18 1 +#define IGNORE_PIN_PA19 1 +#define IGNORE_PIN_PA20 1 +#define IGNORE_PIN_PA21 1 +#define IGNORE_PIN_PA22 1 +#define IGNORE_PIN_PA23 1 +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 +#define IGNORE_PIN_PA30 1 +#define IGNORE_PIN_PA31 1 +#define IGNORE_PIN_PB01 1 +#define IGNORE_PIN_PB02 1 +#define IGNORE_PIN_PB03 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB06 1 +#define IGNORE_PIN_PB07 1 +#define IGNORE_PIN_PB08 1 +#define IGNORE_PIN_PB09 1 +#define IGNORE_PIN_PB10 1 +#define IGNORE_PIN_PB11 1 +#define IGNORE_PIN_PB12 1 +#define IGNORE_PIN_PB13 1 +#define IGNORE_PIN_PB14 1 +#define IGNORE_PIN_PB15 1 +#define IGNORE_PIN_PB16 1 +#define IGNORE_PIN_PB17 1 +#define IGNORE_PIN_PB22 1 +#define IGNORE_PIN_PB23 1 +#define IGNORE_PIN_PB30 1 +#define IGNORE_PIN_PB31 1 +#define IGNORE_PIN_PB00 1 + +#define DEFAULT_I2C_BUS_SCL (&pin_PA09) +#define DEFAULT_I2C_BUS_SDA (&pin_PA08) + +#define DEFAULT_SPI_BUS_SCK (&pin_PA07) +#define DEFAULT_SPI_BUS_MOSI (&pin_PA06) +#define DEFAULT_SPI_BUS_MISO (&pin_PA09) + +#define DEFAULT_UART_BUS_RX (&pin_PA07) +#define DEFAULT_UART_BUS_TX (&pin_PA06) diff --git a/ports/atmel-samd/boards/pyruler/mpconfigboard.mk b/ports/atmel-samd/boards/pyruler/mpconfigboard.mk new file mode 100644 index 0000000000..9663944a38 --- /dev/null +++ b/ports/atmel-samd/boards/pyruler/mpconfigboard.mk @@ -0,0 +1,14 @@ +LD_FILE = boards/samd21x18-bootloader.ld +USB_VID = 0x239A +USB_PID = 0x804C +USB_PRODUCT = "PyRuler" +USB_MANUFACTURER = "Adafruit Industries LLC" + +CHIP_VARIANT = SAMD21E18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE +CIRCUITPY_SMALL_BUILD = 1 + +SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/pyruler/pins.c b/ports/atmel-samd/boards/pyruler/pins.c new file mode 100644 index 0000000000..8d0cbb6599 --- /dev/null +++ b/ports/atmel-samd/boards/pyruler/pins.c @@ -0,0 +1,50 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA08) }, + + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + + { MP_ROM_QSTR(MP_QSTR_CAP0), MP_ROM_PTR(&pin_PA11) }, + + { MP_ROM_QSTR(MP_QSTR_CAP1), MP_ROM_PTR(&pin_PA05) }, + + { MP_ROM_QSTR(MP_QSTR_CAP2), MP_ROM_PTR(&pin_PA04) }, + + { MP_ROM_QSTR(MP_QSTR_CAP3), MP_ROM_PTR(&pin_PA03) }, + + { MP_ROM_QSTR(MP_QSTR_LED4), MP_ROM_PTR(&pin_PA15) }, + + { MP_ROM_QSTR(MP_QSTR_LED5), MP_ROM_PTR(&pin_PA14) }, + + { MP_ROM_QSTR(MP_QSTR_LED6), MP_ROM_PTR(&pin_PA28) }, + + { MP_ROM_QSTR(MP_QSTR_LED7), MP_ROM_PTR(&pin_PA27) }, + + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA09) }, + + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA06) }, + + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA07) }, + + { MP_ROM_QSTR(MP_QSTR_D13),MP_ROM_PTR(&pin_PA10) }, // ???? + + { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) }, + { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 582acdaa0acd14dd725845786576903b9f5689d6 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 9 Jul 2019 16:12:24 -0400 Subject: [PATCH 47/61] Requested changes. --- ports/atmel-samd/boards/pyruler/mpconfigboard.h | 1 - ports/atmel-samd/boards/pyruler/pins.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/pyruler/mpconfigboard.h b/ports/atmel-samd/boards/pyruler/mpconfigboard.h index c2369c4b7f..171873b47c 100644 --- a/ports/atmel-samd/boards/pyruler/mpconfigboard.h +++ b/ports/atmel-samd/boards/pyruler/mpconfigboard.h @@ -1,7 +1,6 @@ #define MICROPY_HW_BOARD_NAME "Adafruit PyRuler" #define MICROPY_HW_MCU_NAME "samd21e18" -// Rev B - Black #define MICROPY_HW_LED_STATUS (&pin_PA10) #define MICROPY_HW_APA102_MOSI (&pin_PA00) diff --git a/ports/atmel-samd/boards/pyruler/pins.c b/ports/atmel-samd/boards/pyruler/pins.c index 8d0cbb6599..315dbe6303 100644 --- a/ports/atmel-samd/boards/pyruler/pins.c +++ b/ports/atmel-samd/boards/pyruler/pins.c @@ -39,7 +39,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA07) }, { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA07) }, - { MP_ROM_QSTR(MP_QSTR_D13),MP_ROM_PTR(&pin_PA10) }, // ???? + { MP_ROM_QSTR(MP_QSTR_D13),MP_ROM_PTR(&pin_PA10) }, { MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_PA01) }, From 514d4146d3bf786fe6c582a645e305e709b618ad Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Jul 2019 18:23:45 -0400 Subject: [PATCH 48/61] Fix sphinx warnings. --- shared-bindings/bleio/Central.c | 8 ++++---- shared-bindings/bleio/Scanner.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index 95ba19dd0b..a21f711af7 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -86,16 +86,16 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, //| //| :param bleio.Address address: The address of the peripheral to connect to //| :param float/int timeout: Try to connect for timeout seconds. -//| :param iterable service_uuids: a collection of `UUID` objects for the services +//| :param iterable service_uuids: a collection of :py:class:~`UUID` objects for the services //| provided by the peripheral that you want to use. //| The peripheral may provide more services, but services not listed are ignored. -//| If a service in `service_uuids` is not found during discovery, it will not +//| If a service in service_uuids is not found during discovery, it will not //| appear in `remote_services`. //| -//| If `services` is None, then all services will undergo discovery, which can be slow. +//| If service_uuids is None, then all services will undergo discovery, which can be slow. //| //| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you -//| you must have already created a `UUID` object for that UUID in order for the +//| you must have already created a :py:class:~`UUID` object for that UUID in order for the //| service or characteristic to be discovered. (This restriction may be lifted in the future.) //| STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index d50f69fc5b..79ab34931e 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -73,8 +73,8 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, //| :param float timeout: the scan timeout in seconds //| :param float interval: the interval (in seconds) between the start of two consecutive scan windows //| Must be in the range 0.0025 - 40.959375 seconds. -//| :param float window: the duration (in seconds) to scan a single BLE channel -//| `window` must be <= `interval`. +//| :param float window: the duration (in seconds) to scan a single BLE channel. +//| window must be <= interval. //| :returns: advertising packets found //| :rtype: list of :py:class:`bleio.ScanEntry` //| From 12b98be7441d189ff3d26fde188729a9bc3d257f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Jul 2019 18:42:41 -0400 Subject: [PATCH 49/61] merge from master and make translate --- locale/circuitpython.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 6b38f11e31..2ad3316c7f 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:07-0400\n" +"POT-Creation-Date: 2019-07-11 18:42-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" From cb99546ea569bd91421e7ee0884c2756387a12d3 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 11 Jul 2019 18:56:29 -0400 Subject: [PATCH 50/61] update frozen libraries --- frozen/Adafruit_CircuitPython_BusDevice | 2 +- frozen/Adafruit_CircuitPython_CircuitPlayground | 2 +- frozen/Adafruit_CircuitPython_Crickit | 2 +- frozen/Adafruit_CircuitPython_HID | 2 +- frozen/Adafruit_CircuitPython_IRRemote | 2 +- frozen/Adafruit_CircuitPython_LIS3DH | 2 +- frozen/Adafruit_CircuitPython_Motor | 2 +- frozen/Adafruit_CircuitPython_NeoPixel | 2 +- frozen/Adafruit_CircuitPython_seesaw | 2 +- frozen/circuitpython-stage | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frozen/Adafruit_CircuitPython_BusDevice b/frozen/Adafruit_CircuitPython_BusDevice index 6b34029659..b9280af514 160000 --- a/frozen/Adafruit_CircuitPython_BusDevice +++ b/frozen/Adafruit_CircuitPython_BusDevice @@ -1 +1 @@ -Subproject commit 6b3402965999d068316882d63fae3ab26006477c +Subproject commit b9280af5142fc41639229544678e23b5cca07c3a diff --git a/frozen/Adafruit_CircuitPython_CircuitPlayground b/frozen/Adafruit_CircuitPython_CircuitPlayground index 1d38fd81ed..154b74de02 160000 --- a/frozen/Adafruit_CircuitPython_CircuitPlayground +++ b/frozen/Adafruit_CircuitPython_CircuitPlayground @@ -1 +1 @@ -Subproject commit 1d38fd81edd30f1bd70c0cfe77819ab610ea89a3 +Subproject commit 154b74de020764597ba49f0d1e8cc18d55b3643b diff --git a/frozen/Adafruit_CircuitPython_Crickit b/frozen/Adafruit_CircuitPython_Crickit index a168680356..617bb0787f 160000 --- a/frozen/Adafruit_CircuitPython_Crickit +++ b/frozen/Adafruit_CircuitPython_Crickit @@ -1 +1 @@ -Subproject commit a1686803566793ec2de7e043bf6822e47cfa31d1 +Subproject commit 617bb0787f2c61283d248632a62b27be80f64b29 diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index 836bb9843f..89faee0eb0 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit 836bb9843fd793683061c15150944f8897d806e9 +Subproject commit 89faee0eb08a6855e14f117c514fecf2dd90769d diff --git a/frozen/Adafruit_CircuitPython_IRRemote b/frozen/Adafruit_CircuitPython_IRRemote index aa4428f304..70865ac6e0 160000 --- a/frozen/Adafruit_CircuitPython_IRRemote +++ b/frozen/Adafruit_CircuitPython_IRRemote @@ -1 +1 @@ -Subproject commit aa4428f304b982aa19a5800822e78c47dc8a3b6c +Subproject commit 70865ac6e09f821b26ec727e2df300a6d9ebf6b3 diff --git a/frozen/Adafruit_CircuitPython_LIS3DH b/frozen/Adafruit_CircuitPython_LIS3DH index a03f901127..bd7ddc67dc 160000 --- a/frozen/Adafruit_CircuitPython_LIS3DH +++ b/frozen/Adafruit_CircuitPython_LIS3DH @@ -1 +1 @@ -Subproject commit a03f9011279f9e630549432589463912831fcee1 +Subproject commit bd7ddc67dc86f7ad0115f58ab80d5605739c6482 diff --git a/frozen/Adafruit_CircuitPython_Motor b/frozen/Adafruit_CircuitPython_Motor index 98563ab658..ddc7484498 160000 --- a/frozen/Adafruit_CircuitPython_Motor +++ b/frozen/Adafruit_CircuitPython_Motor @@ -1 +1 @@ -Subproject commit 98563ab65800aac6464f671c0d005df56ecaa6c6 +Subproject commit ddc74844983b35b027bd45091c7b8bb3c8d7a2d1 diff --git a/frozen/Adafruit_CircuitPython_NeoPixel b/frozen/Adafruit_CircuitPython_NeoPixel index c0ed34813a..c0bdd8b103 160000 --- a/frozen/Adafruit_CircuitPython_NeoPixel +++ b/frozen/Adafruit_CircuitPython_NeoPixel @@ -1 +1 @@ -Subproject commit c0ed34813a608b64ed044826553918ddbad12f0c +Subproject commit c0bdd8b10383725ee9293f5d88fb8d47eb1272bd diff --git a/frozen/Adafruit_CircuitPython_seesaw b/frozen/Adafruit_CircuitPython_seesaw index 1d12cfc0b7..f1171f9408 160000 --- a/frozen/Adafruit_CircuitPython_seesaw +++ b/frozen/Adafruit_CircuitPython_seesaw @@ -1 +1 @@ -Subproject commit 1d12cfc0b729b4ae0a2f3f4e7c1933a0fbd3b166 +Subproject commit f1171f94083ba64d153ff3f90eeb07500331d6e1 diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage index 733cdf5916..6d1ae72916 160000 --- a/frozen/circuitpython-stage +++ b/frozen/circuitpython-stage @@ -1 +1 @@ -Subproject commit 733cdf591639f9dbb5d9187a21411f759e1ba82f +Subproject commit 6d1ae72916cf240ea86185c45f844d59f56d8ec3 From 364ee62d108bbdc1d4da8bb646a9332a68964b76 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 16 Jul 2019 19:53:36 -0400 Subject: [PATCH 51/61] Address review comments. --- conf.py | 1 + ports/nrf/common-hal/bleio/Scanner.c | 13 ++-- shared-bindings/bleio/Address.c | 52 ++++++++++------ shared-bindings/bleio/Central.c | 19 +++--- shared-bindings/bleio/Characteristic.c | 6 +- shared-bindings/bleio/Descriptor.c | 6 +- shared-bindings/bleio/Peripheral.c | 1 + shared-bindings/bleio/ScanEntry.c | 1 - shared-bindings/bleio/Scanner.c | 8 +-- shared-bindings/bleio/Scanner.h | 3 +- shared-bindings/bleio/Service.c | 6 +- shared-module/bleio/AdvertisementData.h | 79 ------------------------- 12 files changed, 65 insertions(+), 130 deletions(-) delete mode 100644 shared-module/bleio/AdvertisementData.h diff --git a/conf.py b/conf.py index 8586573887..6b0f40da6b 100644 --- a/conf.py +++ b/conf.py @@ -84,6 +84,7 @@ version = release = '0.0.0' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ["**/build*", + ".git", ".venv", ".direnv", "docs/README.md", diff --git a/ports/nrf/common-hal/bleio/Scanner.c b/ports/nrf/common-hal/bleio/Scanner.c index fa4f3923c8..57ce940abd 100644 --- a/ports/nrf/common-hal/bleio/Scanner.c +++ b/ports/nrf/common-hal/bleio/Scanner.c @@ -74,10 +74,9 @@ STATIC void scanner_on_ble_evt(ble_evt_t *ble_evt, void *scanner_in) { } void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self) { - self->scan_entries = mp_obj_new_list(0, NULL); } -void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { +mp_obj_t common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window) { common_hal_bleio_adapter_set_enabled(true); ble_drv_add_event_handler(scanner_on_ble_evt, self); @@ -87,8 +86,7 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout .scan_phys = BLE_GAP_PHY_1MBPS, }; - // Empty the advertising reports list. - mp_obj_list_clear(self->scan_entries); + self->scan_entries = mp_obj_new_list(0, NULL); uint32_t err_code; err_code = sd_ble_gap_scan_start(&scan_params, &m_scan_buffer); @@ -99,8 +97,9 @@ void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout mp_hal_delay_ms(timeout * 1000); sd_ble_gap_scan_stop(); -} -mp_obj_t common_hal_bleio_scanner_get_scan_entries(bleio_scanner_obj_t *self) { - return self->scan_entries; + // Return list, and don't hang on to it, so it can be GC'd. + mp_obj_t entries = self->scan_entries; + self->scan_entries = MP_OBJ_NULL; + return entries; } diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index cfad8fc11d..37f01042ce 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -48,13 +48,9 @@ //| The value itself can be one of: //| //| :param buf address: The address value to encapsulate. A buffer object (bytearray, bytes) of 6 bytes. -//| :param int address_type: one of these integers: -//| - ``bleio.Address.PUBLIC`` = 0 -//| - ``bleio.Address.RANDOM_STATIC`` = 1 -//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 -//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 +//| :param int address_type: one of the integer values: `PUBLIC`, `RANDOM_STATIC`, +//| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`. //| - STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_address, ARG_address_type }; static const mp_arg_t allowed_args[] = { @@ -105,12 +101,9 @@ const mp_obj_property_t bleio_address_address_bytes_obj = { //| .. attribute:: type //| -//| The address type (read-only). One of these integers: -//| -//| - ``bleio.Address.PUBLIC`` = 0 -//| - ``bleio.Address.RANDOM_STATIC`` = 1 -//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 -//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 +//| The address type (read-only). +//| One of the integer values: `PUBLIC`, `RANDOM_STATIC`, +//| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`. //| STATIC mp_obj_t bleio_address_get_type(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -154,16 +147,37 @@ STATIC mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_o STATIC void bleio_address_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_obj_t address_bytes = common_hal_bleio_address_get_address_bytes(self); + if (kind == PRINT_STR) { + mp_buffer_info_t buf_info; + mp_obj_t address_bytes = common_hal_bleio_address_get_address_bytes(self); + mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ); - mp_buffer_info_t buf_info; - mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ); - const uint8_t *buf = (uint8_t *) buf_info.buf; - mp_printf(print, - "%02x:%02x:%02x:%02x:%02x:%02x", - buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); + const uint8_t *buf = (uint8_t *) buf_info.buf; + mp_printf(print, + "%02x:%02x:%02x:%02x:%02x:%02x", + buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); + } else { + mp_printf(print, "
"); + } } +//| .. data:: PUBLIC +//| +//| A publicly known address, with a company ID (high 24 bits)and company-assigned part (low 24 bits). +//| +//| .. data:: RANDOM_STATIC +//| +//| A randomly generated address that does not change often. It may never change or may change after +//| a power cycle. +//| +//| .. data:: RANDOM_PRIVATE_RESOLVABLE +//| +//| An address that is usable when the peer knows the other device's secret Identity Resolving Key (IRK). +//| +//| .. data:: RANDOM_PRIVATE_NON_RESOLVABLE +//| +//| A randomly generated address that changes on every connection. +//| STATIC const mp_rom_map_elem_t bleio_address_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_address_bytes_obj) }, { MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_type_obj) }, diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index a21f711af7..fc00bce5cc 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -56,7 +56,7 @@ //| //| my_entry = None //| for entry in entries: -//| if entry.name is not None and entry.name == 'MyCentral': +//| if entry.name is not None and entry.name == 'MyPeripheral': //| my_entry = entry //| break //| @@ -86,13 +86,13 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, //| //| :param bleio.Address address: The address of the peripheral to connect to //| :param float/int timeout: Try to connect for timeout seconds. -//| :param iterable service_uuids: a collection of :py:class:~`UUID` objects for the services +//| :param iterable service_uuids_whitelist: an iterable of :py:class:~`UUID` objects for the services //| provided by the peripheral that you want to use. //| The peripheral may provide more services, but services not listed are ignored. //| If a service in service_uuids is not found during discovery, it will not //| appear in `remote_services`. //| -//| If service_uuids is None, then all services will undergo discovery, which can be slow. +//| If service_uuids_whitelist is None, then all services will undergo discovery, which can be slow. //| //| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you //| you must have already created a :py:class:~`UUID` object for that UUID in order for the @@ -101,11 +101,11 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_address, ARG_timeout, ARG_service_uuids }; + enum { ARG_address, ARG_timeout, ARG_service_uuids_whitelist }; static const mp_arg_t allowed_args[] = { { MP_QSTR_address, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_timeout, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_service_uuids, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_service_uuids_whitelist, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -119,7 +119,7 @@ STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); // common_hal_bleio_central_connect() will validate that services is an iterable or None. - common_hal_bleio_central_connect(self, address, timeout, args[ARG_service_uuids].u_obj); + common_hal_bleio_central_connect(self, address, timeout, args[ARG_service_uuids_whitelist].u_obj); return mp_const_none; } @@ -160,12 +160,15 @@ const mp_obj_property_t bleio_central_connected_obj = { //| .. attribute:: remote_services (read-only) //| -//| Empty until connected, then a list of services provided by the remote peripheral. +//| A tuple of services provided by the remote peripheral. +//| If the Central is not connected, an empty tuple will be returned. //| STATIC mp_obj_t bleio_central_get_remote_services(mp_obj_t self_in) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(common_hal_bleio_central_get_remote_services(self)); + // Return list as a tuple so user won't be able to change it. + mp_obj_list_t *service_list = common_hal_bleio_central_get_remote_services(self); + return mp_obj_new_tuple(service_list->len, service_list->items); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_services_obj, bleio_central_get_remote_services); diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index 0d5f8f79ac..3bf0476ab5 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -316,13 +316,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_characteristic_locals_dict, bleio_characterist STATIC void bleio_characteristic_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "Characteristic("); if (self->uuid) { + mp_printf(print, "Characteristic("); bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + mp_printf(print, ")"); } else { - mp_printf(print, "Unregistered uUID"); + mp_printf(print, ""); } - mp_printf(print, ")"); } const mp_obj_type_t bleio_characteristic_type = { diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c index f392838926..f2e5aa01df 100644 --- a/shared-bindings/bleio/Descriptor.c +++ b/shared-bindings/bleio/Descriptor.c @@ -162,13 +162,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_descriptor_locals_dict, bleio_descriptor_local STATIC void bleio_descriptor_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "Descriptor("); if (self->uuid) { + mp_printf(print, "Descriptor("); bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + mp_printf(print, ")"); } else { - mp_printf(print, "Unregistered uUID"); + mp_printf(print, ""); } - mp_printf(print, ")"); } const mp_obj_type_t bleio_descriptor_type = { diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index b8d4c39753..1302c96523 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -63,6 +63,7 @@ static const char default_name[] = "CIRCUITPY"; //| Usage:: //| //| import bleio +//| from adafruit_ble.advertising import ServerAdvertisement //| //| # Create a Characteristic. //| chara = bleio.Characteristic(bleio.UUID(0x2919), read=True, notify=True) diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index b7798175cc..6eb02c7166 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -32,7 +32,6 @@ #include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/ScanEntry.h" #include "shared-bindings/bleio/UUID.h" -#include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/ScanEntry.h" //| .. currentmodule:: bleio diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index 79ab34931e..712425c25f 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -75,8 +75,8 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, //| Must be in the range 0.0025 - 40.959375 seconds. //| :param float window: the duration (in seconds) to scan a single BLE channel. //| window must be <= interval. -//| :returns: advertising packets found -//| :rtype: list of :py:class:`bleio.ScanEntry` +//| :returns: an iterable of `bleio.ScanEntry` objects +//| :rtype: iterable //| STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_timeout, ARG_interval, ARG_window }; @@ -110,9 +110,7 @@ STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_m mp_raise_ValueError(translate("window must be <= interval")); } - common_hal_bleio_scanner_scan(self, timeout, interval, window); - - return common_hal_bleio_scanner_get_scan_entries(self); + return common_hal_bleio_scanner_scan(self, timeout, interval, window); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan); diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index 1bbab78f4f..3a0ce7eae4 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -34,8 +34,7 @@ extern const mp_obj_type_t bleio_scanner_type; extern void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self); -extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); +extern mp_obj_t common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self); -extern mp_obj_t common_hal_bleio_scanner_get_scan_entries(bleio_scanner_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index af215c6a50..db06069913 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -166,13 +166,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_service_locals_dict, bleio_service_locals_dict STATIC void bleio_service_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "Service("); if (self->uuid) { + mp_printf(print, "Service("); bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + mp_printf(print, ")"); } else { - mp_printf(print, "unregistered UUID"); + mp_printf(print, ""); } - mp_printf(print, ")"); } const mp_obj_type_t bleio_service_type = { diff --git a/shared-module/bleio/AdvertisementData.h b/shared-module/bleio/AdvertisementData.h deleted file mode 100644 index 89cdfb0700..0000000000 --- a/shared-module/bleio/AdvertisementData.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Dan Halbert for Adafruit Industries - * Copyright (c) 2018 Artur Pacholec - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H -#define MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H - -#include "py/obj.h" - -// Taken from https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile -enum { - AdFlags = 0x01, - AdIncompleteListOf16BitServiceClassUUIDs = 0x02, - AdCompleteListOf16BitServiceClassUUIDs = 0x03, - AdIncompleteListOf32BitServiceClassUUIDs = 0x04, - AdCompleteListOf32BitServiceClassUUIDs = 0x05, - AdIncompleteListOf128BitServiceClassUUIDs = 0x06, - AdCompleteListOf128BitServiceClassUUIDs = 0x07, - AdShortenedLocalName = 0x08, - AdCompleteLocalName = 0x09, - AdTxPowerLevel = 0x0A, - AdClassOfDevice = 0x0D, - AdSimplePairingHashC = 0x0E, - AdSimplePairingRandomizerR = 0x0F, - AdSecurityManagerTKValue = 0x10, - AdSecurityManagerOOBFlags = 0x11, - AdSlaveConnectionIntervalRange = 0x12, - AdListOf16BitServiceSolicitationUUIDs = 0x14, - AdListOf128BitServiceSolicitationUUIDs = 0x15, - AdServiceData = 0x16, - AdPublicTargetAddress = 0x17, - AdRandomTargetAddress = 0x18, - AdAppearance = 0x19, - AdAdvertisingInterval = 0x1A, - AdLEBluetoothDeviceAddress = 0x1B, - AdLERole = 0x1C, - AdSimplePairingHashC256 = 0x1D, - AdSimplePairingRandomizerR256 = 0x1E, - AdListOf32BitServiceSolicitationUUIDs = 0x1F, - AdServiceData32BitUUID = 0x20, - AdServiceData128BitUUID = 0x21, - AdLESecureConnectionsConfirmationValue = 0x22, - AdLESecureConnectionsRandomValue = 0x23, - AdURI = 0x24, - AdIndoorPositioning = 0x25, - AdTransportDiscoveryData = 0x26, - AdLESupportedFeatures = 0x27, - AdChannelMapUpdateIndication = 0x28, - AdPBADV = 0x29, - AdMeshMessage = 0x2A, - AdMeshBeacon = 0x2B, - Ad3DInformationData = 0x3D, - AdManufacturerSpecificData = 0xFF, -}; - -#endif // MICROPY_INCLUDED_SHARED_MODULE_BLEIO_ADVERTISEMENTDATA_H From 1c31cf5f6a6d9cff6f086114f6e0a03b5247c623 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 16 Jul 2019 21:03:36 -0400 Subject: [PATCH 52/61] sphinx fix --- shared-bindings/bleio/Scanner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index 712425c25f..269c42591d 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -75,7 +75,7 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, //| Must be in the range 0.0025 - 40.959375 seconds. //| :param float window: the duration (in seconds) to scan a single BLE channel. //| window must be <= interval. -//| :returns: an iterable of `bleio.ScanEntry` objects +//| :returns: an iterable of `ScanEntry` objects //| :rtype: iterable //| STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { From 724ce4acba1c710f898fcb06c9ba2b575a367bc2 Mon Sep 17 00:00:00 2001 From: Tavish Naruka Date: Fri, 19 Jul 2019 18:48:08 +0530 Subject: [PATCH 53/61] enable libraries needed by BlipBoy Shield --- ports/nrf/boards/electronut_labs_blip/mpconfigboard.mk | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ports/nrf/boards/electronut_labs_blip/mpconfigboard.mk b/ports/nrf/boards/electronut_labs_blip/mpconfigboard.mk index bf82400d18..9cddd96eeb 100644 --- a/ports/nrf/boards/electronut_labs_blip/mpconfigboard.mk +++ b/ports/nrf/boards/electronut_labs_blip/mpconfigboard.mk @@ -19,4 +19,12 @@ else CIRCUITPY_BLEIO = 1 endif -NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 \ No newline at end of file +NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 + +QSPI_FLASH_FILESYSTEM = 0 +INTERNAL_FLASH_FILESYSTEM = 1 +CIRCUITPY_AUDIOIO = 0 +CIRCUITPY_DISPLAYIO = 1 +CIRCUITPY_GAMEPAD = 1 +CIRCUITPY_STAGE = 1 + From 6797ec6ed396f65916fe816f8b2b49114253dd86 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 5 Jul 2019 19:01:54 -0700 Subject: [PATCH 54/61] Add support for grayscale displays that are < 8 bit depth. This also improves Palette so it stores the original RGB888 colors. Lastly, it adds I2CDisplay as a display bus to talk over I2C. Particularly useful for the SSD1306. Fixes #1828. Fixes #1956 --- .../boards/hallowing_m0_express/board.c | 3 + ports/atmel-samd/boards/pybadge/board.c | 3 + .../atmel-samd/boards/pybadge_airlift/board.c | 3 + ports/atmel-samd/boards/pygamer/board.c | 3 + .../atmel-samd/boards/pygamer_advance/board.c | 3 + ports/atmel-samd/boards/pyportal/board.c | 5 +- ports/atmel-samd/boards/ugame10/board.c | 3 + ports/atmel-samd/common-hal/busio/I2C.c | 9 + ports/atmel-samd/common-hal/busio/SPI.h | 1 + .../common-hal/displayio/ParallelBus.c | 17 +- ports/nrf/common-hal/busio/I2C.c | 17 ++ ports/nrf/common-hal/busio/SPI.c | 2 +- py/circuitpy_defns.mk | 1 + shared-bindings/_stage/__init__.c | 7 +- shared-bindings/busio/I2C.h | 3 + shared-bindings/displayio/ColorConverter.c | 6 +- shared-bindings/displayio/ColorConverter.h | 4 +- shared-bindings/displayio/Display.c | 16 +- shared-bindings/displayio/Display.h | 6 +- shared-bindings/displayio/I2CDisplay.c | 138 ++++++++++++++ shared-bindings/displayio/I2CDisplay.h | 46 +++++ shared-bindings/displayio/Palette.c | 27 ++- shared-bindings/displayio/Palette.h | 2 + shared-bindings/displayio/__init__.c | 3 + shared-module/displayio/ColorConverter.c | 35 +++- shared-module/displayio/ColorConverter.h | 4 + shared-module/displayio/Display.c | 179 +++++++++++++----- shared-module/displayio/Display.h | 4 +- shared-module/displayio/FourWire.c | 23 ++- shared-module/displayio/FourWire.h | 6 +- shared-module/displayio/Group.c | 6 +- shared-module/displayio/Group.h | 3 +- shared-module/displayio/I2CDisplay.c | 105 ++++++++++ shared-module/displayio/I2CDisplay.h | 41 ++++ shared-module/displayio/Palette.c | 50 ++--- shared-module/displayio/Palette.h | 19 +- shared-module/displayio/TileGrid.c | 50 +++-- shared-module/displayio/TileGrid.h | 3 +- shared-module/displayio/__init__.c | 137 +++++++++----- shared-module/displayio/__init__.h | 2 + shared-module/terminalio/Terminal.c | 2 + supervisor/shared/display.c | 49 ++++- tools/gen_display_resources.py | 17 +- 43 files changed, 860 insertions(+), 203 deletions(-) create mode 100644 shared-bindings/displayio/I2CDisplay.c create mode 100644 shared-bindings/displayio/I2CDisplay.h create mode 100644 shared-module/displayio/I2CDisplay.c create mode 100644 shared-module/displayio/I2CDisplay.h diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index a0e160757d..1bbbfbaf81 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -91,6 +91,8 @@ void board_init(void) { 1, // row start 0, // rotation 16, // Color depth + false, // Grayscale + false, // Pixels in a byte share a row. Only used for depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -98,6 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, + 0x100, // Brightness command. Only available when <= 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 38902315aa..7e6c11dd49 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -93,6 +93,8 @@ void board_init(void) { 0, // row start 270, // rotation 16, // Color depth + false, // grayscale + false, // pixels in byte share row. only used for depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -100,6 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // no brightness command 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge_airlift/board.c b/ports/atmel-samd/boards/pybadge_airlift/board.c index a1f778df1c..d7f291d7dc 100644 --- a/ports/atmel-samd/boards/pybadge_airlift/board.c +++ b/ports/atmel-samd/boards/pybadge_airlift/board.c @@ -71,6 +71,8 @@ void board_init(void) { 0, // row start 90, // rotation 16, // Color depth + false, // grayscale + false, // pixels in byte share row. Only used for depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -78,6 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // brightness command, only valid <= 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index 7b54b6fb53..e59b7c458e 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -93,6 +93,8 @@ void board_init(void) { 0, // row start 270, // rotation 16, // Color depth + false, // Grayscale + false, // pixels in a byte share a row. Only valid for depths < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -100,6 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // Brightness command. Only available when < 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer_advance/board.c b/ports/atmel-samd/boards/pygamer_advance/board.c index d1c5edc999..b23353998c 100644 --- a/ports/atmel-samd/boards/pygamer_advance/board.c +++ b/ports/atmel-samd/boards/pygamer_advance/board.c @@ -71,6 +71,8 @@ void board_init(void) { 0, // row start 90, // rotation 16, // Color depth + false, // Grayscale + false, // pixels in a byte share a row. Only valid for depths < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -78,6 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin + 0x100, // Brightness command. Only available when < 0xff 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index bb80c5b489..7fffb764f5 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -83,13 +83,16 @@ void board_init(void) { 0, // row start 0, // rotation 16, // Color depth + false, // grayscale + false, // pixels_in_byte_share_row (unused for depths > 8) MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command 0x37, // Set vertical scroll command display_init_sequence, sizeof(display_init_sequence), - &pin_PB31, + &pin_PB31, // Backlight pin + 0x100, // Brightness command > 0xff is none s 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index 828f0c87d2..27a03ad919 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -91,6 +91,8 @@ void board_init(void) { 2, // row start 0, // rotation 16, // Color depth + false, // grayscale + false, // pixels in byte share row. Only used with depth < 8 MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command @@ -98,6 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), NULL, + 0x100, // brightness command. Only valid <=0xff 1.0f, // brightness false, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/common-hal/busio/I2C.c b/ports/atmel-samd/common-hal/busio/I2C.c index a0c04d65da..cdc616bbc8 100644 --- a/ports/atmel-samd/common-hal/busio/I2C.c +++ b/ports/atmel-samd/common-hal/busio/I2C.c @@ -36,6 +36,8 @@ #include "shared-bindings/microcontroller/__init__.h" #include "supervisor/shared/translate.h" +#include "common-hal/busio/SPI.h" // for never_reset_sercom + // Number of times to try to send packet if failed. #define ATTEMPTS 2 @@ -225,3 +227,10 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, } return MP_EIO; } + +void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { + never_reset_sercom(self->i2c_desc.device.hw); + + never_reset_pin_number(self->scl_pin); + never_reset_pin_number(self->sda_pin); +} diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index 56d163a9d8..a1c0e15179 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -43,6 +43,7 @@ typedef struct { } busio_spi_obj_t; void reset_sercoms(void); +void never_reset_sercom(Sercom* sercom); #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/atmel-samd/common-hal/displayio/ParallelBus.c b/ports/atmel-samd/common-hal/displayio/ParallelBus.c index 7a5f61448a..c370f7e52a 100644 --- a/ports/atmel-samd/common-hal/displayio/ParallelBus.c +++ b/ports/atmel-samd/common-hal/displayio/ParallelBus.c @@ -31,6 +31,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/runtime.h" #include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/__init__.h" #include "tick.h" @@ -66,10 +67,6 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel common_hal_digitalio_digitalinout_construct(&self->chip_select, chip_select); common_hal_digitalio_digitalinout_switch_to_output(&self->chip_select, true, DRIVE_MODE_PUSH_PULL); - self->reset.base.type = &digitalio_digitalinout_type; - common_hal_digitalio_digitalinout_construct(&self->reset, reset); - common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); - self->write.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->write, write); common_hal_digitalio_digitalinout_switch_to_output(&self->write, true, DRIVE_MODE_PUSH_PULL); @@ -82,11 +79,21 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel self->write_group = &PORT->Group[write->number / 32]; self->write_mask = 1 << (write->number % 32); + if (reset != NULL) { + self->reset.base.type = &digitalio_digitalinout_type; + common_hal_digitalio_digitalinout_construct(&self->reset, reset); + common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); + never_reset_pin_number(reset->number); + + common_hal_digitalio_digitalinout_set_value(&self->reset, false); + common_hal_mcu_delay_us(4); + common_hal_digitalio_digitalinout_set_value(&self->reset, true); + } + never_reset_pin_number(command->number); never_reset_pin_number(chip_select->number); never_reset_pin_number(write->number); never_reset_pin_number(read->number); - never_reset_pin_number(reset->number); for (uint8_t i = 0; i < 8; i++) { never_reset_pin_number(data_pin + i); } diff --git a/ports/nrf/common-hal/busio/I2C.c b/ports/nrf/common-hal/busio/I2C.c index 538c87f2da..71835d16ad 100644 --- a/ports/nrf/common-hal/busio/I2C.c +++ b/ports/nrf/common-hal/busio/I2C.c @@ -57,13 +57,30 @@ STATIC twim_peripheral_t twim_peripherals[] = { #endif }; +STATIC bool never_reset[MP_ARRAY_SIZE(twim_peripherals)]; + void i2c_reset(void) { for (size_t i = 0 ; i < MP_ARRAY_SIZE(twim_peripherals); i++) { + if (never_reset[i]) { + continue; + } nrf_twim_disable(twim_peripherals[i].twim.p_twim); twim_peripherals[i].in_use = false; } } +void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { + for (size_t i = 0 ; i < MP_ARRAY_SIZE(twim_peripherals); i++) { + if (self->twim_peripheral == &twim_peripherals[i]) { + never_reset[i] = true; + + never_reset_pin_number(self->scl_pin_number); + never_reset_pin_number(self->sda_pin_number); + break; + } + } +} + static uint8_t twi_error_to_mp(const nrfx_err_t err) { switch (err) { case NRFX_ERROR_DRV_TWI_ERR_ANACK: diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index 6ab6d9493b..5f1aac1934 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -61,7 +61,7 @@ STATIC spim_peripheral_t spim_peripherals[] = { #endif }; -STATIC bool never_reset[4]; +STATIC bool never_reset[MP_ARRAY_SIZE(spim_peripherals)]; void spi_reset(void) { for (size_t i = 0 ; i < MP_ARRAY_SIZE(spim_peripherals); i++) { diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 782314fc70..93ca4deb98 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -317,6 +317,7 @@ $(filter $(SRC_PATTERNS), \ displayio/Display.c \ displayio/FourWire.c \ displayio/Group.c \ + displayio/I2CDisplay.c \ displayio/OnDiskBitmap.c \ displayio/Palette.c \ displayio/Shape.c \ diff --git a/shared-bindings/_stage/__init__.c b/shared-bindings/_stage/__init__.c index 03775b1ded..9f3f894627 100644 --- a/shared-bindings/_stage/__init__.c +++ b/shared-bindings/_stage/__init__.c @@ -95,7 +95,12 @@ STATIC mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) { MICROPY_VM_HOOK_LOOP ; #endif } - displayio_display_set_region_to_update(display, x0, y0, x1, y1); + displayio_area_t area; + area.x1 = x0; + area.y1 = y0; + area.x2 = x1; + area.y2 = y1; + displayio_display_set_region_to_update(display, &area); render_stage(x0, y0, x1, y1, layers, layers_size, buffer, buffer_size, display); displayio_display_end_transaction(display); diff --git a/shared-bindings/busio/I2C.h b/shared-bindings/busio/I2C.h index 739732e97b..a2d5dbf507 100644 --- a/shared-bindings/busio/I2C.h +++ b/shared-bindings/busio/I2C.h @@ -69,4 +69,7 @@ extern uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addres extern uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t address, uint8_t * data, size_t len); +// This is used by the supervisor to claim I2C devices indefinitely. +extern void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_H diff --git a/shared-bindings/displayio/ColorConverter.c b/shared-bindings/displayio/ColorConverter.c index 561883810f..e170e0340c 100644 --- a/shared-bindings/displayio/ColorConverter.c +++ b/shared-bindings/displayio/ColorConverter.c @@ -69,8 +69,10 @@ STATIC mp_obj_t displayio_colorconverter_obj_convert(mp_obj_t self_in, mp_obj_t if (!mp_obj_get_int_maybe(color_obj, &color)) { mp_raise_ValueError(translate("color should be an int")); } - uint16_t output_color; - common_hal_displayio_colorconverter_convert(self, color, &output_color); + _displayio_colorspace_t colorspace; + colorspace.depth = 16; + uint32_t output_color; + common_hal_displayio_colorconverter_convert(self, &colorspace, color, &output_color); return MP_OBJ_NEW_SMALL_INT(output_color); } MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_convert_obj, displayio_colorconverter_obj_convert); diff --git a/shared-bindings/displayio/ColorConverter.h b/shared-bindings/displayio/ColorConverter.h index 71be7f5430..8f61e6642f 100644 --- a/shared-bindings/displayio/ColorConverter.h +++ b/shared-bindings/displayio/ColorConverter.h @@ -29,9 +29,11 @@ #include "shared-module/displayio/ColorConverter.h" +#include "shared-module/displayio/Palette.h" + extern const mp_obj_type_t displayio_colorconverter_type; void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self); -bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *colorconverter, uint32_t input_color, uint16_t* output_color); +bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *colorconverter, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_COLORCONVERTER_H diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 1a36872a6e..2586e562f5 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -51,7 +51,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum. //| -//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False) +//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness_command=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False) //| //| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`). //| @@ -88,18 +88,21 @@ //| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270) //| :param int color_depth: The number of bits of color per pixel transmitted. (Some displays //| support 18 bit but 16 is easier to transmit. The last bit is extrapolated.) +//| :param bool grayscale: True if the display only shows a single color. +//| :param bool pixels_in_byte_share_row: True when pixels are less than a byte and a byte includes pixels from the same row of the display. When False, pixels share a column. //| :param int set_column_command: Command used to set the start and end columns to update //| :param int set_row_command: Command used so set the start and end rows to update -//| :param int write_ram_command: Command used to write pixels values into the update region +//| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set. //| :param int set_vertical_scroll: Command used to set the first row to show //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight +//| :param int brightness_command: Command to set display brightness. Usually available in OLED controllers. //| :param bool brightness: Initial display brightness. This value is ignored if auto_brightness is True. //| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism. //| :param bool single_byte_bounds: Display column and row commands use single bytes //| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this. //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands }; + enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -109,11 +112,14 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_rowstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_rotation, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_color_depth, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, + { MP_QSTR_grayscale, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + { MP_QSTR_pixels_in_byte_share_row, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, { MP_QSTR_set_column_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2a} }, { MP_QSTR_set_row_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2b} }, { MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} }, { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + { MP_QSTR_brightness_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x100} }, { MP_QSTR_brightness, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} }, { MP_QSTR_auto_brightness, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, @@ -157,11 +163,13 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a common_hal_displayio_display_construct( self, display_bus, args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_colstart].u_int, args[ARG_rowstart].u_int, rotation, - args[ARG_color_depth].u_int, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int, + args[ARG_color_depth].u_int, args[ARG_grayscale].u_bool, args[ARG_pixels_in_byte_share_row].u_bool, + args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int, args[ARG_write_ram_command].u_int, args[ARG_set_vertical_scroll].u_int, bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin), + args[ARG_brightness_command].u_int, brightness, args[ARG_auto_brightness].u_bool, args[ARG_single_byte_bounds].u_bool, diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index 5a027561b8..a60a0cf5a1 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -38,9 +38,9 @@ extern const mp_obj_type_t displayio_display_type; void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, - int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, + int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, - uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, + uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command, mp_float_t brightness, bool auto_brightness, bool single_byte_bounds, bool data_as_commands); @@ -54,7 +54,7 @@ bool displayio_display_begin_transaction(displayio_display_obj_t* self); void displayio_display_end_transaction(displayio_display_obj_t* self); // The second point of the region is exclusive. -void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1); +void displayio_display_set_region_to_update(displayio_display_obj_t* self, displayio_area_t* area); bool displayio_display_frame_queued(displayio_display_obj_t* self); bool displayio_display_refresh_queued(displayio_display_obj_t* self); diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c new file mode 100644 index 0000000000..2aac49b4d1 --- /dev/null +++ b/shared-bindings/displayio/I2CDisplay.c @@ -0,0 +1,138 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/displayio/I2CDisplay.h" + +#include +#include + +#include "lib/utils/context_manager_helpers.h" +#include "py/binary.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/util.h" +#include "shared-module/displayio/__init__.h" +#include "supervisor/shared/translate.h" + +//| .. currentmodule:: displayio +//| +//| :class:`I2CDisplay` -- Manage updating a display over I2C +//| ========================================================================== +//| +//| Manage updating a display over I2C in the background while Python code runs. +//| It doesn't handle display initialization. +//| +//| .. class:: I2CDisplay(i2c_bus, *, device_address, reset=None) +//| +//| Create a I2CDisplay object associated with the given I2C bus and reset pin. +//| +//| The I2C bus and pins are then in use by the display until `displayio.release_displays()` is +//| called even after a reload. (It does this so CircuitPython can use the display after your code +//| is done.) So, the first time you initialize a display bus in code.py you should call +//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run. +//| +//| :param busio.I2C i2c_bus: The I2C bus that make up the clock and data lines +//| :param int device_address: The I2C address of the device +//| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used +//| +STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_i2c_bus, ARG_device_address, ARG_reset }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_i2c_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_device_address, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, + { MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_obj_t reset = args[ARG_reset].u_obj; + if (reset != mp_const_none) { + assert_pin_free(reset); + } else { + reset = NULL; + } + + displayio_i2cdisplay_obj_t* self = NULL; + mp_obj_t i2c = args[ARG_i2c_bus].u_obj; + for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { + if (displays[i].i2cdisplay_bus.base.type == NULL || + displays[i].i2cdisplay_bus.base.type == &mp_type_NoneType) { + self = &displays[i].i2cdisplay_bus; + self->base.type = &displayio_i2cdisplay_type; + break; + } + } + if (self == NULL) { + mp_raise_RuntimeError(translate("Too many display busses")); + } + + common_hal_displayio_i2cdisplay_construct(self, + MP_OBJ_TO_PTR(i2c), args[ARG_device_address].u_int, reset); + return self; +} + +//| .. method:: send(command, data) +//| +//| Sends the given command value followed by the full set of data. Display state, such as +//| vertical scroll, set via ``send`` may or may not be reset once the code is done. +//| +STATIC mp_obj_t displayio_i2cdisplay_obj_send(mp_obj_t self, mp_obj_t command_obj, mp_obj_t data_obj) { + mp_int_t command_int = MP_OBJ_SMALL_INT_VALUE(command_obj); + if (!MP_OBJ_IS_SMALL_INT(command_obj) || command_int > 255 || command_int < 0) { + mp_raise_ValueError(translate("Command must be an int between 0 and 255")); + } + uint8_t command = command_int; + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(data_obj, &bufinfo, MP_BUFFER_READ); + + // Wait for display bus to be available. + while (!common_hal_displayio_i2cdisplay_begin_transaction(self)) { +#ifdef MICROPY_VM_HOOK_LOOP + MICROPY_VM_HOOK_LOOP ; +#endif + } + uint8_t full_command[bufinfo.len + 1]; + full_command[0] = command; + memcpy(full_command + 1, ((uint8_t*) bufinfo.buf), bufinfo.len); + common_hal_displayio_i2cdisplay_send(self, true, full_command, bufinfo.len + 1); + common_hal_displayio_i2cdisplay_end_transaction(self); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_3(displayio_i2cdisplay_send_obj, displayio_i2cdisplay_obj_send); + +STATIC const mp_rom_map_elem_t displayio_i2cdisplay_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_i2cdisplay_send_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(displayio_i2cdisplay_locals_dict, displayio_i2cdisplay_locals_dict_table); + +const mp_obj_type_t displayio_i2cdisplay_type = { + { &mp_type_type }, + .name = MP_QSTR_I2CDisplay, + .make_new = displayio_i2cdisplay_make_new, + .locals_dict = (mp_obj_dict_t*)&displayio_i2cdisplay_locals_dict, +}; diff --git a/shared-bindings/displayio/I2CDisplay.h b/shared-bindings/displayio/I2CDisplay.h new file mode 100644 index 0000000000..cc41628000 --- /dev/null +++ b/shared-bindings/displayio/I2CDisplay.h @@ -0,0 +1,46 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_I2CDISPLAY_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_I2CDISPLAY_H + +#include "shared-module/displayio/I2CDisplay.h" +#include "common-hal/microcontroller/Pin.h" + +extern const mp_obj_type_t displayio_i2cdisplay_type; + +void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self, + busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset); + +void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self); + +bool common_hal_displayio_i2cdisplay_begin_transaction(mp_obj_t self); + +void common_hal_displayio_i2cdisplay_send(mp_obj_t self, bool command, uint8_t *data, uint32_t data_length); + +void common_hal_displayio_i2cdisplay_end_transaction(mp_obj_t self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_I2CDISPLAY_H diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 11c2f677ce..974cadb025 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -66,11 +66,26 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a return MP_OBJ_FROM_PTR(self); } + +//| .. method:: __len__() +//| +//| Returns the number of colors in a Palette +//| +STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { + displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); + switch (op) { + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(true); + case MP_UNARY_OP_LEN: + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_palette_get_len(self)); + default: return MP_OBJ_NULL; // op not supported + } +} + //| .. method:: __setitem__(index, value) //| //| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1. //| -//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value). +//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value). //| Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), or bytearray. //| //| This allows you to:: @@ -89,12 +104,12 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { return MP_OBJ_NULL; } - // index read is not supported - if (value == MP_OBJ_SENTINEL) { - return MP_OBJ_NULL; - } displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); size_t index = mp_get_index(&displayio_palette_type, self->color_count, index_in, false); + // index read + if (value == MP_OBJ_SENTINEL) { + return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_palette_get_color(self, index)); + } uint32_t color; mp_int_t int_value; @@ -160,5 +175,7 @@ const mp_obj_type_t displayio_palette_type = { .name = MP_QSTR_Palette, .make_new = displayio_palette_make_new, .subscr = palette_subscr, + .unary_op = group_unary_op, + .getiter = mp_obj_new_generic_iterator, .locals_dict = (mp_obj_dict_t*)&displayio_palette_locals_dict, }; diff --git a/shared-bindings/displayio/Palette.h b/shared-bindings/displayio/Palette.h index 767fc7b636..8c9fe11e38 100644 --- a/shared-bindings/displayio/Palette.h +++ b/shared-bindings/displayio/Palette.h @@ -33,6 +33,8 @@ extern const mp_obj_type_t displayio_palette_type; void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t color_count); void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t palette_index, uint32_t color); +uint32_t common_hal_displayio_palette_get_color(displayio_palette_t* self, uint32_t palette_index); +uint32_t common_hal_displayio_palette_get_len(displayio_palette_t* self); void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t palette_index); void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t palette_index); diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index 9dc17103b4..fd3dc42333 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -35,6 +35,7 @@ #include "shared-bindings/displayio/Display.h" #include "shared-bindings/displayio/FourWire.h" #include "shared-bindings/displayio/Group.h" +#include "shared-bindings/displayio/I2CDisplay.h" #include "shared-bindings/displayio/OnDiskBitmap.h" #include "shared-bindings/displayio/Palette.h" #include "shared-bindings/displayio/ParallelBus.h" @@ -61,6 +62,7 @@ //| Display //| FourWire //| Group +//| I2CDisplay //| OnDiskBitmap //| Palette //| ParallelBus @@ -96,6 +98,7 @@ STATIC const mp_rom_map_elem_t displayio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_TileGrid), MP_ROM_PTR(&displayio_tilegrid_type) }, { MP_ROM_QSTR(MP_QSTR_FourWire), MP_ROM_PTR(&displayio_fourwire_type) }, + { MP_ROM_QSTR(MP_QSTR_I2CDisplay), MP_ROM_PTR(&displayio_i2cdisplay_type) }, { MP_ROM_QSTR(MP_QSTR_ParallelBus), MP_ROM_PTR(&displayio_parallelbus_type) }, { MP_ROM_QSTR(MP_QSTR_release_displays), MP_ROM_PTR(&displayio_release_displays_obj) }, diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c index 3928e115ab..563d40c510 100644 --- a/shared-module/displayio/ColorConverter.c +++ b/shared-module/displayio/ColorConverter.c @@ -29,15 +29,36 @@ void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self) { } -bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, uint32_t input_color, uint16_t* output_color) { - // TODO(tannewt): Validate the color input against the input format. - uint32_t r5 = (input_color >> 19); - uint32_t g6 = (input_color >> 10) & 0x3f; - uint32_t b5 = (input_color >> 3) & 0x1f; +uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888) { + uint32_t r5 = (color_rgb888 >> 19); + uint32_t g6 = (color_rgb888 >> 10) & 0x3f; + uint32_t b5 = (color_rgb888 >> 3) & 0x1f; uint32_t packed = r5 << 11 | g6 << 5 | b5; // swap bytes - *output_color = __builtin_bswap16(packed); - return true; + return __builtin_bswap16(packed); +} + +uint8_t displayio_colorconverter_compute_luma(uint32_t color_rgb888) { + uint32_t r8 = (color_rgb888 >> 16); + uint32_t g8 = (color_rgb888 >> 8) & 0xff; + uint32_t b8 = color_rgb888 & 0xff; + return (r8 * 19) / 255 + (g8 * 182) / 255 + (b8 + 54) / 255; +} + +bool displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color) { + if (colorspace->depth == 16) { + *output_color = displayio_colorconverter_compute_rgb565(input_color); + return true; + } else if (colorspace->grayscale && colorspace->depth <= 8) { + uint8_t luma = displayio_colorconverter_compute_luma(input_color); + *output_color = luma >> (8 - colorspace->depth); + return true; + } + return false; +} + +bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color) { + return displayio_colorconverter_convert(self, colorspace, input_color, output_color); } // Currently no refresh logic is needed for a ColorConverter. diff --git a/shared-module/displayio/ColorConverter.h b/shared-module/displayio/ColorConverter.h index 7f3c1a0a03..c48b98e6dc 100644 --- a/shared-module/displayio/ColorConverter.h +++ b/shared-module/displayio/ColorConverter.h @@ -31,6 +31,7 @@ #include #include "py/obj.h" +#include "shared-module/displayio/Palette.h" typedef struct { mp_obj_base_t base; @@ -38,5 +39,8 @@ typedef struct { bool displayio_colorconverter_needs_refresh(displayio_colorconverter_t *self); void displayio_colorconverter_finish_refresh(displayio_colorconverter_t *self); +bool displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color); +uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888); +uint8_t displayio_colorconverter_compute_luma(uint32_t color_rgb888); #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_COLORCONVERTER_H diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 0ae88300aa..9aee70e32a 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -28,6 +28,7 @@ #include "py/runtime.h" #include "shared-bindings/displayio/FourWire.h" +#include "shared-bindings/displayio/I2CDisplay.h" #include "shared-bindings/displayio/ParallelBus.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/time/__init__.h" @@ -35,6 +36,7 @@ #include "supervisor/shared/display.h" #include +#include #include "tick.h" @@ -42,11 +44,14 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, - uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command, + uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, + uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, - const mcu_pin_obj_t* backlight_pin, mp_float_t brightness, bool auto_brightness, + const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command, mp_float_t brightness, bool auto_brightness, bool single_byte_bounds, bool data_as_commands) { - self->color_depth = color_depth; + self->colorspace.depth = color_depth; + self->colorspace.grayscale = grayscale; + self->colorspace.pixels_in_byte_share_row = pixels_in_byte_share_row; self->set_column_command = set_column_command; self->set_row_command = set_row_command; self->write_ram_command = write_ram_command; @@ -54,6 +59,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->current_group = NULL; self->colstart = colstart; self->rowstart = rowstart; + self->brightness_command = brightness_command; self->auto_brightness = auto_brightness; self->data_as_commands = data_as_commands; self->single_byte_bounds = single_byte_bounds; @@ -66,6 +72,10 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->begin_transaction = common_hal_displayio_fourwire_begin_transaction; self->send = common_hal_displayio_fourwire_send; self->end_transaction = common_hal_displayio_fourwire_end_transaction; + } else if (MP_OBJ_IS_TYPE(bus, &displayio_i2cdisplay_type)) { + self->begin_transaction = common_hal_displayio_i2cdisplay_begin_transaction; + self->send = common_hal_displayio_i2cdisplay_send; + self->end_transaction = common_hal_displayio_i2cdisplay_end_transaction; } else { mp_raise_ValueError(translate("Unsupported display bus type")); } @@ -83,13 +93,13 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, bool delay = (data_size & DELAY) != 0; data_size &= ~DELAY; uint8_t *data = cmd + 2; - self->send(self->bus, true, cmd, 1); if (self->data_as_commands) { - // Loop through each parameter to force a CS toggle - for (uint32_t j=0; j < data_size; j++) { - self->send(self->bus, true, data + j, 1); - } + uint8_t full_command[data_size + 1]; + full_command[0] = cmd[0]; + memcpy(full_command + 1, data, data_size); + self->send(self->bus, true, full_command, data_size + 1); } else { + self->send(self->bus, true, cmd, 1); self->send(self->bus, false, data, data_size); } uint16_t delay_length_ms = 10; @@ -141,11 +151,13 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, } else { self->backlight_pwm.base.type = &pulseio_pwmout_type; common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm); - if (!self->auto_brightness) { - common_hal_displayio_display_set_brightness(self, brightness); - } } } + if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType || brightness_command <= 0xff)) { + common_hal_displayio_display_set_brightness(self, brightness); + } else { + self->current_brightness = -1.0; + } self->area.x1 = 0; self->area.y1 = 0; @@ -234,17 +246,7 @@ void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* s } mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t* self) { - if (self->backlight_pwm.base.type == &pulseio_pwmout_type) { - uint16_t duty_cycle = common_hal_pulseio_pwmout_get_duty_cycle(&self->backlight_pwm); - return duty_cycle / ((mp_float_t) 0xffff); - } else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) { - if (common_hal_digitalio_digitalinout_get_value(&self->backlight_inout)) { - return 1.0; - } else { - return 0.0; - } - } - return -1.0; + return self->current_brightness; } bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, mp_float_t brightness) { @@ -256,8 +258,26 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, } else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) { common_hal_digitalio_digitalinout_set_value(&self->backlight_inout, brightness > 0.99); ok = true; + } else if (self->brightness_command < 0x100) { + ok = self->begin_transaction(self->bus); + if (ok) { + if (self->data_as_commands) { + uint8_t set_brightness[2] = {self->brightness_command, (uint8_t) (0xff * brightness)}; + self->send(self->bus, true, set_brightness, 2); + } else { + uint8_t command = self->brightness_command; + uint8_t hex_brightness = 0xff * brightness; + self->send(self->bus, true, &command, 1); + self->send(self->bus, false, &hex_brightness, 1); + } + self->end_transaction(self->bus); + } + } self->updating_backlight = false; + if (ok) { + self->current_brightness = brightness; + } return ok; } @@ -269,35 +289,67 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) { self->end_transaction(self->bus); } -void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - self->send(self->bus, true, &self->set_column_command, 1); - bool isCommand = self->data_as_commands; - if (self->single_byte_bounds) { - uint8_t data[2]; - data[0] = x0 + self->colstart; - data[1] = x1 - 1 + self->colstart; - self->send(self->bus, isCommand, (uint8_t*) data, 2); - } else { - uint16_t data[2]; - data[0] = __builtin_bswap16(x0 + self->colstart); - data[1] = __builtin_bswap16(x1 - 1 + self->colstart); - self->send(self->bus, isCommand, (uint8_t*) data, 4); - } - self->send(self->bus, true, &self->set_row_command, 1); - if (self->single_byte_bounds) { - uint8_t data[2]; - data[0] = y0 + self->rowstart; - data[1] = y1 - 1 + self->rowstart; - self->send(self->bus, isCommand, (uint8_t*) data, 2); - } else { - uint16_t data[2]; - data[0] = __builtin_bswap16(y0 + self->rowstart); - data[1] = __builtin_bswap16(y1 - 1 + self->rowstart); - self->send(self->bus, isCommand, (uint8_t*) data, 4); +void displayio_display_set_region_to_update(displayio_display_obj_t* self, displayio_area_t* area) { + uint16_t x1 = area->x1; + uint16_t x2 = area->x2; + uint16_t y1 = area->y1; + uint16_t y2 = area->y2; + // Collapse down the dimension where multiple pixels are in a byte. + if (self->colorspace.depth < 8) { + uint8_t pixels_per_byte = 8 / self->colorspace.depth; + if (self->colorspace.pixels_in_byte_share_row) { + x1 /= pixels_per_byte; + x2 /= pixels_per_byte; + } else { + y1 /= pixels_per_byte; + y2 /= pixels_per_byte; + } } + + // Set column. + uint8_t data[5]; + data[0] = self->set_column_command; + uint8_t data_length = 1; if (!self->data_as_commands) { - self->send(self->bus, true, &self->write_ram_command, 1); + self->send(self->bus, true, data, 1); + data_length = 0; } + if (self->single_byte_bounds) { + data[data_length] = x1 + self->colstart; + data[data_length + 1] = x2 - 1 + self->colstart; + data_length += 2; + } else { + x1 += self->colstart; + x2 += self->colstart - 1; + data[data_length] = x1 >> 8; + data[data_length + 1] = x1 & 0xff; + data[data_length + 2] = x2 >> 8; + data[data_length + 3] = x2 & 0xff; + data_length += 4; + } + self->send(self->bus, self->data_as_commands, data, data_length); + + // Set row. + data[0] = self->set_row_command; + data_length = 1; + if (!self->data_as_commands) { + self->send(self->bus, true, data, 1); + data_length = 0; + } + if (self->single_byte_bounds) { + data[data_length] = y1 + self->rowstart; + data[data_length + 1] = y2 - 1 + self->rowstart; + data_length += 2; + } else { + y1 += self->rowstart; + y2 += self->rowstart - 1; + data[data_length] = y1 >> 8; + data[data_length + 1] = y1 & 0xff; + data[data_length + 2] = y2 >> 8; + data[data_length + 3] = y2 & 0xff; + data_length += 4; + } + self->send(self->bus, self->data_as_commands, data, data_length); } void displayio_display_start_refresh(displayio_display_obj_t* self) { @@ -322,6 +374,9 @@ void displayio_display_finish_refresh(displayio_display_obj_t* self) { } void displayio_display_send_pixels(displayio_display_obj_t* self, uint8_t* pixels, uint32_t length) { + if (!self->data_as_commands) { + self->send(self->bus, true, &self->write_ram_command, 1); + } self->send(self->bus, false, pixels, length); } @@ -349,9 +404,33 @@ void release_display(displayio_display_obj_t* self) { } bool displayio_display_fill_area(displayio_display_obj_t *self, displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { - return displayio_group_fill_area(self->current_group, area, mask, buffer); + return displayio_group_fill_area(self->current_group, &self->colorspace, area, mask, buffer); } bool displayio_display_clip_area(displayio_display_obj_t *self, const displayio_area_t* area, displayio_area_t* clipped) { - return displayio_area_compute_overlap(&self->area, area, clipped); + bool overlaps = displayio_area_compute_overlap(&self->area, area, clipped); + if (!overlaps) { + return false; + } + // Expand the area if we have multiple pixels per byte and we need to byte + // align the bounds. + if (self->colorspace.depth < 8) { + uint8_t pixels_per_byte = 8 / self->colorspace.depth; + if (self->colorspace.pixels_in_byte_share_row) { + if (clipped->x1 % pixels_per_byte != 0) { + clipped->x1 -= clipped->x1 % pixels_per_byte; + } + if (clipped->x2 % pixels_per_byte != 0) { + clipped->x2 += pixels_per_byte - clipped->x2 % pixels_per_byte; + } + } else { + if (clipped->y1 % pixels_per_byte != 0) { + clipped->y1 -= clipped->y1 % pixels_per_byte; + } + if (clipped->y2 % pixels_per_byte != 0) { + clipped->y2 += pixels_per_byte - clipped->y2 % pixels_per_byte; + } + } + } + return true; } diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index fa8902ceda..96d1c06d57 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -52,11 +52,13 @@ typedef struct { uint64_t last_backlight_refresh; displayio_buffer_transform_t transform; displayio_area_t area; + mp_float_t current_brightness; uint16_t width; uint16_t height; - uint16_t color_depth; + _displayio_colorspace_t colorspace; int16_t colstart; int16_t rowstart; + uint16_t brightness_command; uint8_t set_column_command; uint8_t set_row_command; uint8_t write_ram_command; diff --git a/shared-module/displayio/FourWire.c b/shared-module/displayio/FourWire.c index d38da56fc0..913635db86 100644 --- a/shared-module/displayio/FourWire.c +++ b/shared-module/displayio/FourWire.c @@ -59,6 +59,11 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self, common_hal_digitalio_digitalinout_construct(&self->reset, reset); common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); never_reset_pin_number(reset->number); + + common_hal_digitalio_digitalinout_set_value(&self->reset, false); + common_hal_mcu_delay_us(10); + common_hal_digitalio_digitalinout_set_value(&self->reset, true); + common_hal_mcu_delay_us(10); } never_reset_pin_number(command->number); @@ -88,13 +93,19 @@ bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t obj) { void common_hal_displayio_fourwire_send(mp_obj_t obj, bool command, uint8_t *data, uint32_t data_length) { displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj); - if (command) { - common_hal_digitalio_digitalinout_set_value(&self->chip_select, true); - common_hal_mcu_delay_us(1); - common_hal_digitalio_digitalinout_set_value(&self->chip_select, false); - } common_hal_digitalio_digitalinout_set_value(&self->command, !command); - common_hal_busio_spi_write(self->bus, data, data_length); + if (command) { + // Toggle chip select after each command byte in case the display driver + // IC latches commands based on it. + for (size_t i = 0; i < data_length; i++) { + common_hal_busio_spi_write(self->bus, &data[i], 1); + common_hal_digitalio_digitalinout_set_value(&self->chip_select, true); + common_hal_mcu_delay_us(1); + common_hal_digitalio_digitalinout_set_value(&self->chip_select, false); + } + } else { + common_hal_busio_spi_write(self->bus, data, data_length); + } } void common_hal_displayio_fourwire_end_transaction(mp_obj_t obj) { diff --git a/shared-module/displayio/FourWire.h b/shared-module/displayio/FourWire.h index 743139e627..a4260a3ac5 100644 --- a/shared-module/displayio/FourWire.h +++ b/shared-module/displayio/FourWire.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H -#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H +#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FOURWIRE_H +#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FOURWIRE_H #include "common-hal/busio/SPI.h" #include "common-hal/digitalio/DigitalInOut.h" @@ -43,4 +43,4 @@ typedef struct { uint8_t phase; } displayio_fourwire_obj_t; -#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H +#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FOURWIRE_H diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index 15060e87b6..38418a0299 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -270,19 +270,19 @@ void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* self->in_group = false; } -bool displayio_group_fill_area(displayio_group_t *self, const displayio_area_t* area, uint32_t* mask, uint32_t* buffer) { +bool displayio_group_fill_area(displayio_group_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t* buffer) { // Track if any of the layers finishes filling in the given area. We can ignore any remaining // layers at that point. bool full_coverage = false; for (int32_t i = self->size - 1; i >= 0 ; i--) { mp_obj_t layer = self->children[i].native; if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { - if (displayio_tilegrid_fill_area(layer, area, mask, buffer)) { + if (displayio_tilegrid_fill_area(layer, colorspace, area, mask, buffer)) { full_coverage = true; break; } } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { - if (displayio_group_fill_area(layer, area, mask, buffer)) { + if (displayio_group_fill_area(layer, colorspace, area, mask, buffer)) { full_coverage = true; break; } diff --git a/shared-module/displayio/Group.h b/shared-module/displayio/Group.h index 7ce19a4cdb..4e2308e565 100644 --- a/shared-module/displayio/Group.h +++ b/shared-module/displayio/Group.h @@ -32,6 +32,7 @@ #include "py/obj.h" #include "shared-module/displayio/area.h" +#include "shared-module/displayio/Palette.h" typedef struct { mp_obj_t native; @@ -54,7 +55,7 @@ typedef struct { void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); bool displayio_group_get_previous_area(displayio_group_t *group, displayio_area_t* area); -bool displayio_group_fill_area(displayio_group_t *group, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); +bool displayio_group_fill_area(displayio_group_t *group, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); void displayio_group_update_transform(displayio_group_t *group, const displayio_buffer_transform_t* parent_transform); void displayio_group_finish_refresh(displayio_group_t *self); displayio_area_t* displayio_group_get_refresh_areas(displayio_group_t *self, displayio_area_t* tail); diff --git a/shared-module/displayio/I2CDisplay.c b/shared-module/displayio/I2CDisplay.c new file mode 100644 index 0000000000..9d89495287 --- /dev/null +++ b/shared-module/displayio/I2CDisplay.c @@ -0,0 +1,105 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/displayio/I2CDisplay.h" + +#include +#include + +#include "py/gc.h" +#include "py/runtime.h" +#include "shared-bindings/busio/I2C.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/time/__init__.h" + +#include "tick.h" + +void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self, + busio_i2c_obj_t* i2c, uint16_t device_address, const mcu_pin_obj_t* reset) { + + // Probe the bus to see if a device acknowledges the given address. + if (!common_hal_busio_i2c_probe(i2c, device_address)) { + mp_raise_ValueError_varg(translate("Unable to find I2C Display at %x"), device_address); + } + + // Write to the device and return 0 on success or an appropriate error code from mperrno.h + self->bus = i2c; + common_hal_busio_i2c_never_reset(self->bus); + // Our object is statically allocated off the heap so make sure the bus object lives to the end + // of the heap as well. + gc_never_free(self->bus); + + self->address = device_address; + + if (reset != NULL) { + common_hal_digitalio_digitalinout_construct(&self->reset, reset); + common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL); + never_reset_pin_number(reset->number); + + common_hal_digitalio_digitalinout_set_value(&self->reset, false); + common_hal_mcu_delay_us(1); + common_hal_digitalio_digitalinout_set_value(&self->reset, true); + } +} + +void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self) { + if (self->bus == &self->inline_bus) { + common_hal_busio_i2c_deinit(self->bus); + } + + reset_pin_number(self->reset.pin->number); +} + +bool common_hal_displayio_i2cdisplay_begin_transaction(mp_obj_t obj) { + displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj); + if (!common_hal_busio_i2c_try_lock(self->bus)) { + return false; + } + return true; +} + +void common_hal_displayio_i2cdisplay_send(mp_obj_t obj, bool command, uint8_t *data, uint32_t data_length) { + displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj); + if (command) { + uint8_t command_bytes[2 * data_length]; + for (uint32_t i = 0; i < data_length; i++) { + command_bytes[2 * i] = 0x80; + command_bytes[2 * i + 1] = data[i]; + } + common_hal_busio_i2c_write(self->bus, self->address, command_bytes, 2 * data_length, true); + } else { + uint8_t data_bytes[data_length + 1]; + data_bytes[0] = 0x40; + memcpy(data_bytes + 1, data, data_length); + common_hal_busio_i2c_write(self->bus, self->address, data_bytes, data_length + 1, true); + } +} + +void common_hal_displayio_i2cdisplay_end_transaction(mp_obj_t obj) { + displayio_i2cdisplay_obj_t* self = MP_OBJ_TO_PTR(obj); + common_hal_busio_i2c_unlock(self->bus); +} diff --git a/shared-module/displayio/I2CDisplay.h b/shared-module/displayio/I2CDisplay.h new file mode 100644 index 0000000000..4636c3f73a --- /dev/null +++ b/shared-module/displayio/I2CDisplay.h @@ -0,0 +1,41 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_I2CDISPLAY_H +#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_I2CDISPLAY_H + +#include "common-hal/busio/I2C.h" +#include "common-hal/digitalio/DigitalInOut.h" + +typedef struct { + mp_obj_base_t base; + busio_i2c_obj_t* bus; + busio_i2c_obj_t inline_bus; + digitalio_digitalinout_obj_t reset; + uint16_t address; +} displayio_i2cdisplay_obj_t; + +#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_I2CDISPLAY_H diff --git a/shared-module/displayio/Palette.c b/shared-module/displayio/Palette.c index 8dc6e766bd..444151b3c0 100644 --- a/shared-module/displayio/Palette.c +++ b/shared-module/displayio/Palette.c @@ -26,49 +26,49 @@ #include "shared-bindings/displayio/Palette.h" +#include "shared-module/displayio/ColorConverter.h" + void common_hal_displayio_palette_construct(displayio_palette_t* self, uint16_t color_count) { self->color_count = color_count; - self->colors = (uint32_t *) m_malloc(color_count * sizeof(uint16_t), false); - uint32_t opaque_byte_count = color_count / 8; - if (color_count % 8 > 0) { - opaque_byte_count += 1; - } - self->opaque = (uint32_t *) m_malloc(opaque_byte_count, false); + self->colors = (_displayio_color_t *) m_malloc(color_count * sizeof(_displayio_color_t), false); } void common_hal_displayio_palette_make_opaque(displayio_palette_t* self, uint32_t palette_index) { - self->opaque[palette_index / 32] &= ~(0x1 << (palette_index % 32)); + self->colors[palette_index].transparent = false; } void common_hal_displayio_palette_make_transparent(displayio_palette_t* self, uint32_t palette_index) { - self->opaque[palette_index / 32] |= (0x1 << (palette_index % 32)); + self->colors[palette_index].transparent = true; +} + +uint32_t common_hal_displayio_palette_get_len(displayio_palette_t* self) { + return self->color_count; } void common_hal_displayio_palette_set_color(displayio_palette_t* self, uint32_t palette_index, uint32_t color) { - uint32_t shift = (palette_index % 2) * 16; - uint32_t masked = self->colors[palette_index / 2] & ~(0xffff << shift); - uint32_t r5 = (color >> 19); - uint32_t g6 = (color >> 10) & 0x3f; - uint32_t b5 = (color >> 3) & 0x1f; - uint32_t packed = r5 << 11 | g6 << 5 | b5; - // swap bytes - packed = __builtin_bswap16(packed); - uint32_t final_color = masked | packed << shift; - if (self->colors[palette_index / 2] == final_color) { + if (self->colors[palette_index].rgb888 == color) { return; } - self->colors[palette_index / 2] = final_color; + self->colors[palette_index].rgb888 = color; + self->colors[palette_index].luma = displayio_colorconverter_compute_luma(color); + self->colors[palette_index].rgb565 = displayio_colorconverter_compute_rgb565(color); self->needs_refresh = true; } -bool displayio_palette_get_color(displayio_palette_t *self, uint32_t palette_index, uint16_t* color) { - if (palette_index > self->color_count) { - return false; +uint32_t common_hal_displayio_palette_get_color(displayio_palette_t* self, uint32_t palette_index) { + return self->colors[palette_index].rgb888; +} + +bool displayio_palette_get_color(displayio_palette_t *self, const _displayio_colorspace_t* colorspace, uint32_t palette_index, uint32_t* color) { + if (palette_index > self->color_count || self->colors[palette_index].transparent) { + return false; // returns opaque } - if ((self->opaque[palette_index / 32] & (0x1 << (palette_index % 32))) != 0) { - return false; + + if (colorspace->grayscale) { + *color = self->colors[palette_index].luma >> (8 - colorspace->depth); + } else { + *color = self->colors[palette_index].rgb565; } - *color = (self->colors[palette_index / 2] >> (16 * (palette_index % 2))) & 0xffff; return true; } diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h index 3813e8bddf..6f5e2774cf 100644 --- a/shared-module/displayio/Palette.h +++ b/shared-module/displayio/Palette.h @@ -32,15 +32,28 @@ #include "py/obj.h" +typedef struct { + uint8_t depth; + bool grayscale; + bool pixels_in_byte_share_row; + uint8_t hue; +} _displayio_colorspace_t; + +typedef struct { + uint32_t rgb888; + uint16_t rgb565; + uint8_t luma; + bool transparent; // This may have additional bits added later for blending. +} _displayio_color_t; + typedef struct { mp_obj_base_t base; - uint32_t* opaque; - uint32_t* colors; + _displayio_color_t* colors; uint32_t color_count; bool needs_refresh; } displayio_palette_t; -bool displayio_palette_get_color(displayio_palette_t *palette, uint32_t palette_index, uint16_t* color); +bool displayio_palette_get_color(displayio_palette_t *palette, const _displayio_colorspace_t* colorspace, uint32_t palette_index, uint32_t* color); bool displayio_palette_needs_refresh(displayio_palette_t *self); void displayio_palette_finish_refresh(displayio_palette_t *self); diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 0cd00e0ce6..77e6daf6fd 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -291,7 +291,7 @@ void common_hal_displayio_tilegrid_set_top_left(displayio_tilegrid_t *self, uint self->full_change = true; } -bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { +bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer) { // If no tiles are present we have no impact. uint8_t* tiles = self->tiles; if (self->inline_tiles) { @@ -371,12 +371,13 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_ar y_shift = temp_shift; } + uint8_t pixels_per_byte = 8 / colorspace->depth; for (int16_t y = start_y; y < end_y; y++) { - int16_t row_start = start + (y - start_y + y_shift) * y_stride; + int16_t row_start = start + (y - start_y + y_shift) * y_stride; // in pixels int16_t local_y = y / self->absolute_transform->scale; for (int16_t x = start_x; x < end_x; x++) { // Compute the destination pixel in the buffer and mask based on the transformations. - int16_t offset = row_start + (x - start_x + x_shift) * x_stride; + int16_t offset = row_start + (x - start_x + x_shift) * x_stride; // in pixels // This is super useful for debugging out range accesses. Uncomment to use. // if (offset < 0 || offset >= (int32_t) displayio_area_size(area)) { @@ -404,23 +405,38 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_ar value = common_hal_displayio_ondiskbitmap_get_pixel(self->bitmap, tile_x, tile_y); } - uint16_t* pixel = ((uint16_t*) buffer) + offset; + uint32_t pixel; + bool opaque = true; if (self->pixel_shader == mp_const_none) { - *pixel = value; - return true; + pixel = value; } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type)) { - if (!displayio_palette_get_color(self->pixel_shader, value, pixel)) { - // A pixel is transparent so we haven't fully covered the area ourselves. - full_coverage = false; - } else { - mask[offset / 32] |= 1 << (offset % 32); - } + opaque = displayio_palette_get_color(self->pixel_shader, colorspace, value, &pixel); } else if (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type)) { - if (!common_hal_displayio_colorconverter_convert(self->pixel_shader, value, pixel)) { - // A pixel is transparent so we haven't fully covered the area ourselves. - full_coverage = false; - } else { - mask[offset / 32] |= 1 << (offset % 32); + opaque = displayio_colorconverter_convert(self->pixel_shader, colorspace, value, &pixel); + } + if (!opaque) { + // A pixel is transparent so we haven't fully covered the area ourselves. + full_coverage = false; + } else { + mask[offset / 32] |= 1 << (offset % 32); + if (colorspace->depth == 16) { + *(((uint16_t*) buffer) + offset) = pixel; + } else if (colorspace->depth == 8) { + *(((uint8_t*) buffer) + offset) = pixel; + } else if (colorspace->depth < 8) { + // Reorder the offsets to pack multiple rows into a byte (meaning they share a column). + if (!colorspace->pixels_in_byte_share_row) { + uint16_t width = displayio_area_width(area); + uint16_t row = offset / width; + uint16_t col = offset % width; + // Dividing by pixels_per_byte does truncated division even if we multiply it back out. + offset = col * pixels_per_byte + (row / pixels_per_byte) * pixels_per_byte * width + row % pixels_per_byte; + // Also useful for validating that the bitpacking worked correctly. + // if (offset > displayio_area_size(area)) { + // asm("bkpt"); + // } + } + ((uint8_t*)buffer)[offset / pixels_per_byte] |= pixel << ((offset % pixels_per_byte) * colorspace->depth); } } } diff --git a/shared-module/displayio/TileGrid.h b/shared-module/displayio/TileGrid.h index 4d97eccc2b..fb6033e9c7 100644 --- a/shared-module/displayio/TileGrid.h +++ b/shared-module/displayio/TileGrid.h @@ -32,6 +32,7 @@ #include "py/obj.h" #include "shared-module/displayio/area.h" +#include "shared-module/displayio/Palette.h" typedef struct { mp_obj_base_t base; @@ -71,7 +72,7 @@ displayio_area_t* displayio_tilegrid_get_refresh_areas(displayio_tilegrid_t *sel // Area is always in absolute screen coordinates. Update transform is used to inform TileGrids how // they relate to it. -bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); +bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); void displayio_tilegrid_update_transform(displayio_tilegrid_t *group, const displayio_buffer_transform_t* parent_transform); // Fills in area with the maximum bounds of all related pixels in the last rendered frame. Returns diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index b6709e0eb7..97060aaebe 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -19,9 +19,10 @@ #include "supervisor/usb.h" primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT]; +uint32_t frame_count = 0; bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area) { - uint16_t buffer_size = 512; + uint16_t buffer_size = 128; // In uint32_ts displayio_area_t clipped; // Clip the area to the display by overlapping the areas. If there is no overlap then we're done. @@ -30,15 +31,36 @@ bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area } uint16_t subrectangles = 1; uint16_t rows_per_buffer = displayio_area_height(&clipped); - if (displayio_area_size(area) > buffer_size) { - rows_per_buffer = buffer_size / displayio_area_width(&clipped); + uint8_t pixels_per_word = (sizeof(uint32_t) * 8) / display->colorspace.depth; + uint16_t pixels_per_buffer = displayio_area_size(&clipped); + if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) { + rows_per_buffer = buffer_size * pixels_per_word / displayio_area_width(&clipped); + if (rows_per_buffer == 0) { + rows_per_buffer = 1; + } + // If pixels are packed by column then ensure rows_per_buffer is on a byte boundary. + if (display->colorspace.depth < 8 && !display->colorspace.pixels_in_byte_share_row) { + uint8_t pixels_per_byte = 8 / display->colorspace.depth; + if (rows_per_buffer % pixels_per_byte != 0) { + rows_per_buffer -= rows_per_buffer % pixels_per_byte; + } + } subrectangles = displayio_area_height(&clipped) / rows_per_buffer; if (displayio_area_height(&clipped) % rows_per_buffer != 0) { subrectangles++; } - buffer_size = rows_per_buffer * displayio_area_width(&clipped); + pixels_per_buffer = rows_per_buffer * displayio_area_width(&clipped); + buffer_size = pixels_per_buffer / pixels_per_word; + if (pixels_per_buffer % pixels_per_word) { + buffer_size += 1; + } } - uint32_t buffer[buffer_size / 2]; + + // Allocated and shared as a uint32_t array so the compiler knows the + // alignment everywhere. + uint32_t buffer[buffer_size]; + volatile uint32_t mask_length = (pixels_per_buffer / 32) + 1; + uint32_t mask[mask_length]; uint16_t remaining_rows = displayio_area_height(&clipped); for (uint16_t j = 0; j < subrectangles; j++) { @@ -54,37 +76,30 @@ bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area remaining_rows -= rows_per_buffer; displayio_display_begin_transaction(display); - displayio_display_set_region_to_update(display, subrectangle.x1, subrectangle.y1, - subrectangle.x2, subrectangle.y2); + displayio_display_set_region_to_update(display, &subrectangle); displayio_display_end_transaction(display); - uint32_t mask[(buffer_size / 32) + 1]; - for (uint16_t k = 0; k < (buffer_size / 32) + 1; k++) { - mask[k] = 0x00000000; + uint16_t subrectangle_size_bytes; + if (display->colorspace.depth >= 8) { + subrectangle_size_bytes = displayio_area_size(&subrectangle) * (display->colorspace.depth / 8); + } else { + subrectangle_size_bytes = displayio_area_size(&subrectangle) / (8 / display->colorspace.depth); } - bool full_coverage = displayio_display_fill_area(display, &subrectangle, mask, buffer); - if (!full_coverage) { - uint32_t index = 0; - uint32_t current_mask = 0; - for (int16_t y = subrectangle.y1; y < subrectangle.y2; y++) { - for (int16_t x = subrectangle.x1; x < subrectangle.x2; x++) { - if (index % 32 == 0) { - current_mask = mask[index / 32]; - } - if ((current_mask & (1 << (index % 32))) == 0) { - ((uint16_t*) buffer)[index] = 0x0000; - } - index++; - } - } + for (uint16_t k = 0; k < mask_length; k++) { + mask[k] = 0x00000000; } + for (uint16_t k = 0; k < buffer_size; k++) { + buffer[k] = 0x00000000; + } + + displayio_display_fill_area(display, &subrectangle, mask, buffer); if (!displayio_display_begin_transaction(display)) { // Can't acquire display bus; skip the rest of the data. Try next display. return false; } - displayio_display_send_pixels(display, (uint8_t*) buffer, displayio_area_size(&subrectangle) * sizeof(uint16_t)); + displayio_display_send_pixels(display, (uint8_t*) buffer, subrectangle_size_bytes); displayio_display_end_transaction(display); // TODO(tannewt): Make refresh displays faster so we don't starve other @@ -96,7 +111,6 @@ bool refresh_area(displayio_display_obj_t* display, const displayio_area_t* area // Check for recursive calls to displayio_refresh_displays. bool refresh_displays_in_progress = false; -uint32_t frame_count = 0; void displayio_refresh_displays(void) { if (mp_hal_is_interrupted()) { @@ -153,6 +167,8 @@ void common_hal_displayio_release_displays(void) { continue; } else if (bus_type == &displayio_fourwire_type) { common_hal_displayio_fourwire_deinit(&displays[i].fourwire_bus); + } else if (bus_type == &displayio_i2cdisplay_type) { + common_hal_displayio_i2cdisplay_deinit(&displays[i].i2cdisplay_bus); } else if (bus_type == &displayio_parallelbus_type) { common_hal_displayio_parallelbus_deinit(&displays[i].parallel_bus); } @@ -169,30 +185,53 @@ void common_hal_displayio_release_displays(void) { void reset_displays(void) { // The SPI buses used by FourWires may be allocated on the heap so we need to move them inline. for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - if (displays[i].fourwire_bus.base.type != &displayio_fourwire_type) { - continue; - } - displayio_fourwire_obj_t* fourwire = &displays[i].fourwire_bus; - if (((uint32_t) fourwire->bus) < ((uint32_t) &displays) || - ((uint32_t) fourwire->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { - busio_spi_obj_t* original_spi = fourwire->bus; - #if BOARD_SPI - // We don't need to move original_spi if it is the board.SPI object because it is - // statically allocated already. (Doing so would also make it impossible to reference in - // a subsequent VM run.) - if (original_spi == common_hal_board_get_spi()) { - continue; - } - #endif - memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t)); - fourwire->bus = &fourwire->inline_bus; - // Check for other displays that use the same spi bus and swap them too. - for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { - if (displays[i].fourwire_bus.bus == original_spi) { - displays[i].fourwire_bus.bus = &fourwire->inline_bus; + if (displays[i].fourwire_bus.base.type == &displayio_fourwire_type) { + displayio_fourwire_obj_t* fourwire = &displays[i].fourwire_bus; + if (((uint32_t) fourwire->bus) < ((uint32_t) &displays) || + ((uint32_t) fourwire->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { + busio_spi_obj_t* original_spi = fourwire->bus; + #if BOARD_SPI + // We don't need to move original_spi if it is the board.SPI object because it is + // statically allocated already. (Doing so would also make it impossible to reference in + // a subsequent VM run.) + if (original_spi == common_hal_board_get_spi()) { + continue; + } + #endif + memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t)); + fourwire->bus = &fourwire->inline_bus; + // Check for other displays that use the same spi bus and swap them too. + for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { + if (displays[i].fourwire_bus.base.type == &displayio_fourwire_type && + displays[i].fourwire_bus.bus == original_spi) { + displays[i].fourwire_bus.bus = &fourwire->inline_bus; + } + } + } + } else if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type) { + displayio_i2cdisplay_obj_t* i2c = &displays[i].i2cdisplay_bus; + if (((uint32_t) i2c->bus) < ((uint32_t) &displays) || + ((uint32_t) i2c->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { + busio_i2c_obj_t* original_i2c = i2c->bus; + #if BOARD_I2C + // We don't need to move original_i2c if it is the board.SPI object because it is + // statically allocated already. (Doing so would also make it impossible to reference in + // a subsequent VM run.) + if (original_i2c == common_hal_board_get_i2c()) { + continue; + } + #endif + memcpy(&i2c->inline_bus, original_i2c, sizeof(busio_i2c_obj_t)); + i2c->bus = &i2c->inline_bus; + // Check for other displays that use the same i2c bus and swap them too. + for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { + if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type && + displays[i].i2cdisplay_bus.bus == original_i2c) { + displays[i].i2cdisplay_bus.bus = &i2c->inline_bus; + } + } } } - } } for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h index 18c1a4f4a9..caa5ce36d8 100644 --- a/shared-module/displayio/__init__.h +++ b/shared-module/displayio/__init__.h @@ -30,11 +30,13 @@ #include "shared-bindings/displayio/Display.h" #include "shared-bindings/displayio/FourWire.h" #include "shared-bindings/displayio/Group.h" +#include "shared-bindings/displayio/I2CDisplay.h" #include "shared-bindings/displayio/ParallelBus.h" typedef struct { union { displayio_fourwire_obj_t fourwire_bus; + displayio_i2cdisplay_obj_t i2cdisplay_bus; displayio_parallelbus_obj_t parallel_bus; }; displayio_display_obj_t display; diff --git a/shared-module/terminalio/Terminal.c b/shared-module/terminalio/Terminal.c index 7adf9d0328..86c3e903e1 100644 --- a/shared-module/terminalio/Terminal.c +++ b/shared-module/terminalio/Terminal.c @@ -35,6 +35,8 @@ void common_hal_terminalio_terminal_construct(terminalio_terminal_obj_t *self, d self->font = font; self->tilegrid = tilegrid; self->first_row = 0; + + common_hal_displayio_tilegrid_set_top_left(self->tilegrid, 0, 1); } size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, const byte *data, size_t len, int *errcode) { diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index 414f850344..6a39cbe8e0 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -82,8 +82,7 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { grid->pixel_height = height_in_tiles * grid->tile_height; grid->tiles = tiles; - supervisor_terminal.cursor_x = 0; - supervisor_terminal.cursor_y = 0; + common_hal_terminalio_terminal_construct(&supervisor_terminal, grid, &supervisor_terminal_font); } void supervisor_stop_terminal(void) { @@ -147,17 +146,49 @@ displayio_bitmap_t blinka_bitmap = { .read_only = true }; -uint32_t blinka_transparency[1] = {0x80000000}; - -// These colors are RGB 565 with the bytes swapped. -uint32_t blinka_colors[8] = {0x78890000, 0x9F86B8FC, 0xffff0D5A, 0x0000f501, - 0x00000000, 0x00000000, 0x00000000, 0x00000000}; +_displayio_color_t blinka_colors[7] = { + { + .rgb888 = 0x000000, + .rgb565 = 0x0000, + .luma = 0x00, + .transparent = true + }, + { + .rgb888 = 0x8428bc, + .rgb565 = 0x7889, + .luma = 0xff // We cheat the luma here. It is actually 0x60 + }, + { + .rgb888 = 0xff89bc, + .rgb565 = 0xB8FC, + .luma = 0xb5 + }, + { + .rgb888 = 0x7beffe, + .rgb565 = 0x9F86, + .luma = 0xe0 + }, + { + .rgb888 = 0x51395f, + .rgb565 = 0x0D5A, + .luma = 0x47 + }, + { + .rgb888 = 0xffffff, + .rgb565 = 0xffff, + .luma = 0xff + }, + { + .rgb888 = 0x0736a0, + .rgb565 = 0xf501, + .luma = 0x44 + }, +}; displayio_palette_t blinka_palette = { .base = {.type = &displayio_palette_type }, - .opaque = blinka_transparency, .colors = blinka_colors, - .color_count = 16, + .color_count = 7, .needs_refresh = false }; diff --git a/tools/gen_display_resources.py b/tools/gen_display_resources.py index 2c674c8ebd..a731cbd9cb 100644 --- a/tools/gen_display_resources.py +++ b/tools/gen_display_resources.py @@ -98,14 +98,21 @@ c_file.write("""\ """) c_file.write("""\ -uint32_t terminal_transparency[1] = {0x00000000}; - -// These colors are RGB 565 with the bytes swapped. -uint32_t terminal_colors[1] = {0xffff0000}; +_displayio_color_t terminal_colors[2] = { + { + .rgb888 = 0x000000, + .rgb565 = 0x0000, + .luma = 0x00 + }, + { + .rgb888 = 0xffffff, + .rgb565 = 0xffff, + .luma = 0xff + }, +}; displayio_palette_t supervisor_terminal_color = { .base = {.type = &displayio_palette_type }, - .opaque = terminal_transparency, .colors = terminal_colors, .color_count = 2, .needs_refresh = false From e4611b6e3eced6587db9e3cd757b9b40b798f744 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 17 Jul 2019 12:00:58 -0700 Subject: [PATCH 55/61] Update translations --- locale/ID.po | 13 ++++++++++--- locale/circuitpython.pot | 13 ++++++++++--- locale/de_DE.po | 13 ++++++++++--- locale/en_US.po | 13 ++++++++++--- locale/en_x_pirate.po | 13 ++++++++++--- locale/es.po | 13 ++++++++++--- locale/fil.po | 13 ++++++++++--- locale/fr.po | 13 ++++++++++--- locale/it_IT.po | 13 ++++++++++--- locale/pl.po | 13 ++++++++++--- locale/pt_BR.po | 13 ++++++++++--- locale/zh_Latn_pinyin.po | 13 ++++++++++--- 12 files changed, 120 insertions(+), 36 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 33e63bd2ce..5e555a025a 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -443,7 +443,8 @@ msgstr "Clock unit sedang digunakan" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -1171,7 +1172,8 @@ msgstr "Untuk keluar, silahkan reset board tanpa " msgid "Too many channels in sample." msgstr "Terlalu banyak channel dalam sampel" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "" @@ -1212,6 +1214,11 @@ msgstr "" msgid "Unable to allocate buffers for signed conversion" msgstr "Tidak dapat mengalokasikan buffer untuk signed conversion" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 2ad3316c7f..67271258a0 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-11 18:42-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -433,7 +433,8 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -1148,7 +1149,8 @@ msgstr "" msgid "Too many channels in sample." msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "" @@ -1189,6 +1191,11 @@ msgstr "" msgid "Unable to allocate buffers for signed conversion" msgstr "" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/de_DE.po b/locale/de_DE.po index cf115716fb..b0ebf9bcb2 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -437,7 +437,8 @@ msgstr "Clock unit wird benutzt" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Der Befehl muss ein int zwischen 0 und 255 sein" @@ -1177,7 +1178,8 @@ msgstr "Zum beenden, resette bitte das board ohne " msgid "Too many channels in sample." msgstr "Zu viele Kanäle im sample" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "" @@ -1218,6 +1220,11 @@ msgstr "Der UUID-Wert ist kein str-, int- oder Byte-Puffer" msgid "Unable to allocate buffers for signed conversion" msgstr "Konnte keine Buffer für Vorzeichenumwandlung allozieren" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/en_US.po b/locale/en_US.po index ab1776aa24..91fd15ac87 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -433,7 +433,8 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -1148,7 +1149,8 @@ msgstr "" msgid "Too many channels in sample." msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "" @@ -1189,6 +1191,11 @@ msgstr "" msgid "Unable to allocate buffers for signed conversion" msgstr "" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 550966a943..5f0ab319f9 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -437,7 +437,8 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" @@ -1152,7 +1153,8 @@ msgstr "" msgid "Too many channels in sample." msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "" @@ -1193,6 +1195,11 @@ msgstr "" msgid "Unable to allocate buffers for signed conversion" msgstr "" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/es.po b/locale/es.po index a1e90b0eb9..ff44238df3 100644 --- a/locale/es.po +++ b/locale/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:07-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -441,7 +441,8 @@ msgstr "Clock unit está siendo utilizado" msgid "Column entry must be digitalio.DigitalInOut" msgstr "Entrada de columna debe ser digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Command debe estar entre 0 y 255." @@ -1188,7 +1189,8 @@ msgstr "Para salir, por favor reinicia la tarjeta sin " msgid "Too many channels in sample." msgstr "Demasiados canales en sample." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "Demasiados buses de pantalla" @@ -1229,6 +1231,11 @@ msgstr "UUID valor no es un str, int o byte buffer" msgid "Unable to allocate buffers for signed conversion" msgstr "No se pudieron asignar buffers para la conversión con signo" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/fil.po b/locale/fil.po index 29e969566d..4693cde646 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -441,7 +441,8 @@ msgstr "Clock unit ginagamit" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Sa gitna ng 0 o 255 dapat ang bytes." @@ -1191,7 +1192,8 @@ msgstr "Para lumabas, paki-reset ang board na wala ang " msgid "Too many channels in sample." msgstr "Sobra ang channels sa sample." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "" @@ -1232,6 +1234,11 @@ msgstr "" msgid "Unable to allocate buffers for signed conversion" msgstr "Hindi ma-allocate ang buffers para sa naka-sign na conversion" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/fr.po b/locale/fr.po index 3a4c418d48..db2b659dd7 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -447,7 +447,8 @@ msgstr "Horloge en cours d'utilisation" msgid "Column entry must be digitalio.DigitalInOut" msgstr "L'entrée 'Column' doit être un digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "La commande doit être un entier entre 0 et 255" @@ -1212,7 +1213,8 @@ msgstr "Pour quitter, redémarrez la carte SVP sans " msgid "Too many channels in sample." msgstr "Trop de canaux dans l'échantillon." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "Trop de bus d'affichage" @@ -1256,6 +1258,11 @@ msgstr "" msgid "Unable to allocate buffers for signed conversion" msgstr "Impossible d'allouer des tampons pour une conversion signée" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/it_IT.po b/locale/it_IT.po index 7504fb1575..0e717f15b2 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -442,7 +442,8 @@ msgstr "Unità di clock in uso" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "I byte devono essere compresi tra 0 e 255" @@ -1190,7 +1191,8 @@ msgstr "Per uscire resettare la scheda senza " msgid "Too many channels in sample." msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "" @@ -1231,6 +1233,11 @@ msgstr "" msgid "Unable to allocate buffers for signed conversion" msgstr "Ipossibilitato ad allocare buffer per la conversione con segno" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/pl.po b/locale/pl.po index dd4cf7db4a..2bc1a75574 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -436,7 +436,8 @@ msgstr "Jednostka zegara w użyciu" msgid "Column entry must be digitalio.DigitalInOut" msgstr "Kolumny muszą być typu digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Komenda musi być int pomiędzy 0 a 255" @@ -1168,7 +1169,8 @@ msgstr "By wyjść, proszę zresetować płytkę bez " msgid "Too many channels in sample." msgstr "Zbyt wiele kanałów." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "Zbyt wiele magistrali" @@ -1209,6 +1211,11 @@ msgstr "UUID nie jest typu str, int lub bytes" msgid "Unable to allocate buffers for signed conversion" msgstr "Nie udała się alokacja buforów do konwersji ze znakiem" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 8b74349faa..7af2e3d604 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -438,7 +438,8 @@ msgstr "Unidade de Clock em uso" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Os bytes devem estar entre 0 e 255." @@ -1168,7 +1169,8 @@ msgstr "Para sair, por favor, reinicie a placa sem " msgid "Too many channels in sample." msgstr "Muitos canais na amostra." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "" @@ -1209,6 +1211,11 @@ msgstr "" msgid "Unable to allocate buffers for signed conversion" msgstr "Não é possível alocar buffers para conversão assinada" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index d8d11cd858..7f6e80236d 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-09 09:06-0400\n" +"POT-Creation-Date: 2019-07-19 16:09-0700\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -437,7 +437,8 @@ msgstr "Shǐyòng shízhōng dānwèi" msgid "Column entry must be digitalio.DigitalInOut" msgstr "Liè tiáomù bìxū shì digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Mìnglìng bìxū shì 0 dào 255 zhī jiān de int" @@ -1173,7 +1174,8 @@ msgstr "Yào tuìchū, qǐng chóng zhì bǎnkuài ér bùyòng " msgid "Too many channels in sample." msgstr "Chōuyàng zhōng de píndào tài duō." -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c +#: shared-bindings/displayio/ParallelBus.c msgid "Too many display busses" msgstr "Xiǎnshì zǒngxiàn tài duōle" @@ -1214,6 +1216,11 @@ msgstr "UUID zhí bùshì str,int huò zì jié huǎnchōng qū" msgid "Unable to allocate buffers for signed conversion" msgstr "Wúfǎ fēnpèi huǎnchōng qū yòng yú qiānmíng zhuǎnhuàn" +#: shared-module/displayio/I2CDisplay.c +#, c-format +msgid "Unable to find I2C Display at %x" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Unable to find free GCLK" From cdfc169ab67dec10ffa46c995be5fb1503fd5a4c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 17 Jul 2019 12:02:15 -0700 Subject: [PATCH 56/61] Correct typo in line meant to turn off frequencyio on M0 which saves 2k code space. --- ports/atmel-samd/mpconfigport.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 66ee92e6be..4ddd097f02 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -17,7 +17,7 @@ endif # Put samd21-only choices here. ifeq ($(CHIP_FAMILY),samd21) # frequencyio not yet verified as working on SAMD21. -CIRCUITPY_FRQUENCYIO = 0 +CIRCUITPY_FREQUENCYIO = 0 endif # Put samd51-only choices here. From b9b9ef227fae5f383374d483ee78bc659a9ac9b8 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 17 Jul 2019 14:03:00 -0700 Subject: [PATCH 57/61] Turn off bitbanging on Hallowing to save code space. --- ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk index 8dfc741e5a..92374721f8 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk @@ -16,6 +16,7 @@ LONGINT_IMPL = MPZ CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_AUDIOBUSIO = 0 +CIRCUITPY_BITBANGIO = 0 SUPEROPT_GC = 0 # Include these Python libraries in firmware. From 1d1b8703b6c108b72a1abda9312646895f542672 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 19 Jul 2019 16:05:13 -0700 Subject: [PATCH 58/61] Review feedback including NO_BRIGHTNESS_COMMAND macro --- locale/ID.po | 13 ++++++-- locale/circuitpython.pot | 13 ++++++-- locale/de_DE.po | 13 ++++++-- locale/en_US.po | 13 ++++++-- locale/en_x_pirate.po | 13 ++++++-- locale/es.po | 13 ++++++-- locale/fil.po | 13 ++++++-- locale/fr.po | 13 ++++++-- locale/it_IT.po | 13 ++++++-- locale/pl.po | 13 ++++++-- locale/pt_BR.po | 13 ++++++-- locale/zh_Latn_pinyin.po | 13 ++++++-- .../boards/hallowing_m0_express/board.c | 2 +- ports/atmel-samd/boards/pybadge/board.c | 2 +- .../atmel-samd/boards/pybadge_airlift/board.c | 2 +- ports/atmel-samd/boards/pygamer/board.c | 2 +- .../atmel-samd/boards/pygamer_advance/board.c | 2 +- ports/atmel-samd/boards/pyportal/board.c | 2 +- ports/atmel-samd/boards/ugame10/board.c | 2 +- shared-bindings/displayio/ColorConverter.c | 2 ++ shared-bindings/displayio/ColorConverter.h | 2 +- shared-bindings/displayio/Display.c | 10 ++++-- shared-bindings/displayio/Display.h | 2 ++ shared-bindings/displayio/I2CDisplay.c | 2 +- shared-bindings/displayio/Palette.c | 2 +- shared-module/displayio/ColorConverter.c | 4 +-- shared-module/displayio/Display.c | 32 +++++++++---------- shared-module/displayio/Palette.h | 2 ++ shared-module/displayio/TileGrid.c | 2 +- 29 files changed, 161 insertions(+), 69 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 5e555a025a..b211d53794 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -312,6 +312,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "Kedua pin harus mendukung hardware interrut" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -443,8 +447,11 @@ msgstr "Clock unit sedang digunakan" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 67271258a0..d91e2b3aca 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -308,6 +308,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -433,8 +437,11 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index b0ebf9bcb2..7488331476 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Pascal Deneaux\n" "Language-Team: Sebastian Plamauer, Pascal Deneaux\n" @@ -312,6 +312,10 @@ msgstr "Bit depth muss ein Vielfaches von 8 sein." msgid "Both pins must support hardware interrupts" msgstr "Beide pins müssen Hardware Interrupts unterstützen" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "Die Helligkeit muss zwischen 0 und 255 liegen" @@ -437,8 +441,11 @@ msgstr "Clock unit wird benutzt" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Der Befehl muss ein int zwischen 0 und 255 sein" diff --git a/locale/en_US.po b/locale/en_US.po index 91fd15ac87..38074de988 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -308,6 +308,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -433,8 +437,11 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 5f0ab319f9..9bee12d2a2 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: @sommersoft, @MrCertainly\n" @@ -312,6 +312,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "" @@ -437,8 +441,11 @@ msgstr "" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "" diff --git a/locale/es.po b/locale/es.po index ff44238df3..33cdfe348a 100644 --- a/locale/es.po +++ b/locale/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -316,6 +316,10 @@ msgstr "Bits depth debe ser múltiplo de 8." msgid "Both pins must support hardware interrupts" msgstr "Ambos pines deben soportar interrupciones por hardware" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "El brillo debe estar entro 0 y 255" @@ -441,8 +445,11 @@ msgstr "Clock unit está siendo utilizado" msgid "Column entry must be digitalio.DigitalInOut" msgstr "Entrada de columna debe ser digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Command debe estar entre 0 y 255." diff --git a/locale/fil.po b/locale/fil.po index 4693cde646..4f05812f79 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -314,6 +314,10 @@ msgstr "Bit depth ay dapat multiple ng 8." msgid "Both pins must support hardware interrupts" msgstr "Ang parehong mga pin ay dapat na sumusuporta sa hardware interrupts" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "Ang liwanag ay dapat sa gitna ng 0 o 255" @@ -441,8 +445,11 @@ msgstr "Clock unit ginagamit" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Sa gitna ng 0 o 255 dapat ang bytes." diff --git a/locale/fr.po b/locale/fr.po index db2b659dd7..a948630ee1 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2019-04-14 20:05+0100\n" "Last-Translator: Pierrick Couturier \n" "Language-Team: fr\n" @@ -319,6 +319,10 @@ msgstr "La profondeur de bit doit être un multiple de 8." msgid "Both pins must support hardware interrupts" msgstr "Les deux entrées doivent supporter les interruptions matérielles" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "La luminosité doit être entre 0 et 255" @@ -447,8 +451,11 @@ msgstr "Horloge en cours d'utilisation" msgid "Column entry must be digitalio.DigitalInOut" msgstr "L'entrée 'Column' doit être un digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "La commande doit être un entier entre 0 et 255" diff --git a/locale/it_IT.po b/locale/it_IT.po index 0e717f15b2..40a685f759 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -314,6 +314,10 @@ msgstr "La profondità di bit deve essere multipla di 8." msgid "Both pins must support hardware interrupts" msgstr "Entrambi i pin devono supportare gli interrupt hardware" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "La luminosità deve essere compreso tra 0 e 255" @@ -442,8 +446,11 @@ msgstr "Unità di clock in uso" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "I byte devono essere compresi tra 0 e 255" diff --git a/locale/pl.po b/locale/pl.po index 2bc1a75574..8967851269 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -311,6 +311,10 @@ msgstr "Głębia musi być wielokrotnością 8." msgid "Both pins must support hardware interrupts" msgstr "Obie nóżki muszą wspierać przerwania sprzętowe" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "Jasność musi być pomiędzy 0 a 255" @@ -436,8 +440,11 @@ msgstr "Jednostka zegara w użyciu" msgid "Column entry must be digitalio.DigitalInOut" msgstr "Kolumny muszą być typu digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Komenda musi być int pomiędzy 0 a 255" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 7af2e3d604..7e052bfb71 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -311,6 +311,10 @@ msgstr "" msgid "Both pins must support hardware interrupts" msgstr "Ambos os pinos devem suportar interrupções de hardware" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "O brilho deve estar entre 0 e 255" @@ -438,8 +442,11 @@ msgstr "Unidade de Clock em uso" msgid "Column entry must be digitalio.DigitalInOut" msgstr "" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c #, fuzzy msgid "Command must be an int between 0 and 255" msgstr "Os bytes devem estar entre 0 e 255." diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 7f6e80236d..258a4d3df8 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-19 16:09-0700\n" +"POT-Creation-Date: 2019-07-19 16:10-0700\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -312,6 +312,10 @@ msgstr "Bǐtè shēndù bìxū shì 8 bèi yǐshàng." msgid "Both pins must support hardware interrupts" msgstr "Liǎng gè yǐn jiǎo dōu bìxū zhīchí yìngjiàn zhōngduàn" +#: shared-bindings/displayio/Display.c +msgid "Brightness must be 0-1.0" +msgstr "" + #: shared-bindings/supervisor/__init__.c msgid "Brightness must be between 0 and 255" msgstr "Liàngdù bìxū jiè yú 0 dào 255 zhī jiān" @@ -437,8 +441,11 @@ msgstr "Shǐyòng shízhōng dānwèi" msgid "Column entry must be digitalio.DigitalInOut" msgstr "Liè tiáomù bìxū shì digitalio.DigitalInOut" -#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/I2CDisplay.c -#: shared-bindings/displayio/ParallelBus.c +#: shared-bindings/displayio/I2CDisplay.c +msgid "Command must be 0-255" +msgstr "" + +#: shared-bindings/displayio/FourWire.c shared-bindings/displayio/ParallelBus.c msgid "Command must be an int between 0 and 255" msgstr "Mìnglìng bìxū shì 0 dào 255 zhī jiān de int" diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 1bbbfbaf81..be1741c87e 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -100,7 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA00, - 0x100, // Brightness command. Only available when <= 0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 7e6c11dd49..c9dca0329a 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -102,7 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin - 0x100, // no brightness command + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pybadge_airlift/board.c b/ports/atmel-samd/boards/pybadge_airlift/board.c index d7f291d7dc..eeab3f2b2c 100644 --- a/ports/atmel-samd/boards/pybadge_airlift/board.c +++ b/ports/atmel-samd/boards/pybadge_airlift/board.c @@ -80,7 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin - 0x100, // brightness command, only valid <= 0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index e59b7c458e..d413c8e341 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -102,7 +102,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin - 0x100, // Brightness command. Only available when < 0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pygamer_advance/board.c b/ports/atmel-samd/boards/pygamer_advance/board.c index b23353998c..498a29db2c 100644 --- a/ports/atmel-samd/boards/pygamer_advance/board.c +++ b/ports/atmel-samd/boards/pygamer_advance/board.c @@ -80,7 +80,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PA01, // backlight pin - 0x100, // Brightness command. Only available when < 0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index 7fffb764f5..938072158e 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -92,7 +92,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), &pin_PB31, // Backlight pin - 0x100, // Brightness command > 0xff is none s + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index 27a03ad919..15e22a72ca 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -100,7 +100,7 @@ void board_init(void) { display_init_sequence, sizeof(display_init_sequence), NULL, - 0x100, // brightness command. Only valid <=0xff + NO_BRIGHTNESS_COMMAND, 1.0f, // brightness false, // auto_brightness false, // single_byte_bounds diff --git a/shared-bindings/displayio/ColorConverter.c b/shared-bindings/displayio/ColorConverter.c index e170e0340c..d9524870dc 100644 --- a/shared-bindings/displayio/ColorConverter.c +++ b/shared-bindings/displayio/ColorConverter.c @@ -62,6 +62,8 @@ STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, siz //| .. method:: convert(color) //| +//| Converts the given RGB888 color to RGB565 +//| STATIC mp_obj_t displayio_colorconverter_obj_convert(mp_obj_t self_in, mp_obj_t color_obj) { displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-bindings/displayio/ColorConverter.h b/shared-bindings/displayio/ColorConverter.h index 8f61e6642f..24895500e8 100644 --- a/shared-bindings/displayio/ColorConverter.h +++ b/shared-bindings/displayio/ColorConverter.h @@ -34,6 +34,6 @@ extern const mp_obj_type_t displayio_colorconverter_type; void common_hal_displayio_colorconverter_construct(displayio_colorconverter_t* self); -bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *colorconverter, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color); +void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *colorconverter, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_COLORCONVERTER_H diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 2586e562f5..361a37ece1 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -119,7 +119,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} }, { MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} }, { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, - { MP_QSTR_brightness_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x100} }, + { MP_QSTR_brightness_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = NO_BRIGHTNESS_COMMAND} }, { MP_QSTR_brightness, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} }, { MP_QSTR_auto_brightness, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, @@ -242,10 +242,14 @@ STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_brightness_obj, displayio_display_obj_get_brightness); -STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness) { +STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness_obj) { displayio_display_obj_t *self = native_display(self_in); common_hal_displayio_display_set_auto_brightness(self, false); - bool ok = common_hal_displayio_display_set_brightness(self, mp_obj_get_float(brightness)); + mp_float_t brightness = mp_obj_get_float(brightness_obj); + if (brightness < 0 || brightness > 1.0) { + mp_raise_ValueError(translate("Brightness must be 0-1.0")); + } + bool ok = common_hal_displayio_display_set_brightness(self, brightness); if (!ok) { mp_raise_RuntimeError(translate("Brightness not adjustable")); } diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index a60a0cf5a1..e765e6f256 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -36,6 +36,8 @@ extern const mp_obj_type_t displayio_display_type; #define DELAY 0x80 +#define NO_BRIGHTNESS_COMMAND 0x100 + void common_hal_displayio_display_construct(displayio_display_obj_t* self, mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c index 2aac49b4d1..1f74e8c9ec 100644 --- a/shared-bindings/displayio/I2CDisplay.c +++ b/shared-bindings/displayio/I2CDisplay.c @@ -103,7 +103,7 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t STATIC mp_obj_t displayio_i2cdisplay_obj_send(mp_obj_t self, mp_obj_t command_obj, mp_obj_t data_obj) { mp_int_t command_int = MP_OBJ_SMALL_INT_VALUE(command_obj); if (!MP_OBJ_IS_SMALL_INT(command_obj) || command_int > 255 || command_int < 0) { - mp_raise_ValueError(translate("Command must be an int between 0 and 255")); + mp_raise_ValueError(translate("Command must be 0-255")); } uint8_t command = command_int; mp_buffer_info_t bufinfo; diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 974cadb025..dda58e3c53 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -74,7 +74,7 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) { displayio_palette_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { - case MP_UNARY_OP_BOOL: return mp_obj_new_bool(true); + case MP_UNARY_OP_BOOL: return mp_const_true; case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_palette_get_len(self)); default: return MP_OBJ_NULL; // op not supported diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c index 563d40c510..6b9bd5840b 100644 --- a/shared-module/displayio/ColorConverter.c +++ b/shared-module/displayio/ColorConverter.c @@ -57,8 +57,8 @@ bool displayio_colorconverter_convert(displayio_colorconverter_t *self, const _d return false; } -bool common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color) { - return displayio_colorconverter_convert(self, colorspace, input_color, output_color); +void common_hal_displayio_colorconverter_convert(displayio_colorconverter_t *self, const _displayio_colorspace_t* colorspace, uint32_t input_color, uint32_t* output_color) { + displayio_colorconverter_convert(self, colorspace, input_color, output_color); } // Currently no refresh logic is needed for a ColorConverter. diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 9aee70e32a..a8515b9e58 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -153,7 +153,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm); } } - if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType || brightness_command <= 0xff)) { + if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType || + brightness_command != NO_BRIGHTNESS_COMMAND)) { common_hal_displayio_display_set_brightness(self, brightness); } else { self->current_brightness = -1.0; @@ -258,7 +259,7 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, } else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) { common_hal_digitalio_digitalinout_set_value(&self->backlight_inout, brightness > 0.99); ok = true; - } else if (self->brightness_command < 0x100) { + } else if (self->brightness_command != NO_BRIGHTNESS_COMMAND) { ok = self->begin_transaction(self->bus); if (ok) { if (self->data_as_commands) { @@ -315,17 +316,16 @@ void displayio_display_set_region_to_update(displayio_display_obj_t* self, displ data_length = 0; } if (self->single_byte_bounds) { - data[data_length] = x1 + self->colstart; - data[data_length + 1] = x2 - 1 + self->colstart; + data[data_length++] = x1 + self->colstart; + data[data_length++] = x2 - 1 + self->colstart; data_length += 2; } else { x1 += self->colstart; x2 += self->colstart - 1; - data[data_length] = x1 >> 8; - data[data_length + 1] = x1 & 0xff; - data[data_length + 2] = x2 >> 8; - data[data_length + 3] = x2 & 0xff; - data_length += 4; + data[data_length++] = x1 >> 8; + data[data_length++] = x1 & 0xff; + data[data_length++] = x2 >> 8; + data[data_length++] = x2 & 0xff; } self->send(self->bus, self->data_as_commands, data, data_length); @@ -337,17 +337,15 @@ void displayio_display_set_region_to_update(displayio_display_obj_t* self, displ data_length = 0; } if (self->single_byte_bounds) { - data[data_length] = y1 + self->rowstart; - data[data_length + 1] = y2 - 1 + self->rowstart; - data_length += 2; + data[data_length++] = y1 + self->rowstart; + data[data_length++] = y2 - 1 + self->rowstart; } else { y1 += self->rowstart; y2 += self->rowstart - 1; - data[data_length] = y1 >> 8; - data[data_length + 1] = y1 & 0xff; - data[data_length + 2] = y2 >> 8; - data[data_length + 3] = y2 & 0xff; - data_length += 4; + data[data_length++] = y1 >> 8; + data[data_length++] = y1 & 0xff; + data[data_length++] = y2 >> 8; + data[data_length++] = y2 & 0xff; } self->send(self->bus, self->data_as_commands, data, data_length); } diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h index 6f5e2774cf..19c05baf5c 100644 --- a/shared-module/displayio/Palette.h +++ b/shared-module/displayio/Palette.h @@ -53,6 +53,8 @@ typedef struct { bool needs_refresh; } displayio_palette_t; +// Returns false if color fetch did not succeed (out of range or transparent). +// Returns true if color is opaque, and sets color. bool displayio_palette_get_color(displayio_palette_t *palette, const _displayio_colorspace_t* colorspace, uint32_t palette_index, uint32_t* color); bool displayio_palette_needs_refresh(displayio_palette_t *self); void displayio_palette_finish_refresh(displayio_palette_t *self); diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index 77e6daf6fd..88873d3a9f 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -379,7 +379,7 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, const _displayio_c // Compute the destination pixel in the buffer and mask based on the transformations. int16_t offset = row_start + (x - start_x + x_shift) * x_stride; // in pixels - // This is super useful for debugging out range accesses. Uncomment to use. + // This is super useful for debugging out of range accesses. Uncomment to use. // if (offset < 0 || offset >= (int32_t) displayio_area_size(area)) { // asm("bkpt"); // } From e4d92a3aad4833bd027d809bb2b99d36e1d6bc97 Mon Sep 17 00:00:00 2001 From: Tavish Naruka Date: Mon, 22 Jul 2019 20:07:05 +0530 Subject: [PATCH 59/61] Fix incorrect preprocessor define NRFX_TIMER3/4 Should be NRF_TIMER3 and NRF_TIMER4 --- ports/nrf/nrfx_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/nrf/nrfx_config.h b/ports/nrf/nrfx_config.h index d51739fac2..a2b48065dd 100644 --- a/ports/nrf/nrfx_config.h +++ b/ports/nrf/nrfx_config.h @@ -81,13 +81,13 @@ #define NRFX_TIMER1_ENABLED 1 #define NRFX_TIMER2_ENABLED 1 -#ifdef NRFX_TIMER3 +#ifdef NRF_TIMER3 #define NRFX_TIMER3_ENABLED 1 #else #define NRFX_TIMER3_ENABLED 0 #endif -#ifdef NRFX_TIMER4 +#ifdef NRF_TIMER4 #define NRFX_TIMER4_ENABLED 1 #else #define NRFX_TIMER4_ENABLED 0 From c921f6637f55936726a880f225812302a3fdf0d1 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 24 Jul 2019 16:46:31 +0700 Subject: [PATCH 60/61] update tinyusb lib to 0.5.x --- lib/tinyusb | 2 +- ports/nrf/Makefile | 1 + shared-module/usb_hid/Device.c | 10 +-- shared-module/usb_midi/PortOut.c | 2 +- supervisor/shared/usb/tusb_config.h | 2 +- supervisor/shared/usb/usb_desc.c | 43 +++++++----- supervisor/shared/usb/usb_desc.h | 43 ------------ supervisor/shared/usb/usb_msc_flash.c | 96 +++++++++++++++------------ 8 files changed, 90 insertions(+), 109 deletions(-) delete mode 100644 supervisor/shared/usb/usb_desc.h diff --git a/lib/tinyusb b/lib/tinyusb index 0848c462b3..1ee9ef4f2b 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 0848c462b3e431a9da42e96537d2b597a4579636 +Subproject commit 1ee9ef4f2b7c6acfab6c398a4f57ca22036958f7 diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 83f87536bd..9da2c498d0 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -81,6 +81,7 @@ INC += -I./nrfx INC += -I./nrfx/hal INC += -I./nrfx/mdk INC += -I./nrfx/drivers/include +INC += -I./nrfx/drivers/src INC += -I./bluetooth INC += -I./peripherals INC += -I../../lib/mp-readline diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c index 0e256cb5e4..a5a57419c7 100644 --- a/shared-module/usb_hid/Device.c +++ b/shared-module/usb_hid/Device.c @@ -47,15 +47,15 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t* // Wait until interface is ready, timeout = 2 seconds uint64_t end_ticks = ticks_ms + 2000; - while ( (ticks_ms < end_ticks) && !tud_hid_generic_ready() ) { } + while ( (ticks_ms < end_ticks) && !tud_hid_ready() ) { } - if ( !tud_hid_generic_ready() ) { + if ( !tud_hid_ready() ) { mp_raise_msg(&mp_type_OSError, translate("USB Busy")); } memcpy(self->report_buffer, report, len); - if ( !tud_hid_generic_report(self->report_id, self->report_buffer, len) ) { + if ( !tud_hid_report(self->report_id, self->report_buffer, len) ) { mp_raise_msg(&mp_type_OSError, translate("USB Error")); } } @@ -70,7 +70,7 @@ static usb_hid_device_obj_t* get_hid_device(uint8_t report_id) { } // Callbacks invoked when receive Get_Report request through control endpoint -uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { +uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { // only support Input Report if ( report_type != HID_REPORT_TYPE_INPUT ) return 0; @@ -80,7 +80,7 @@ uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t repo } // Callbacks invoked when receive Set_Report request through control endpoint -void tud_hid_generic_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { +void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { usb_hid_device_obj_t* hid_device = get_hid_device(report_id); if ( report_type == HID_REPORT_TYPE_OUTPUT ) { diff --git a/shared-module/usb_midi/PortOut.c b/shared-module/usb_midi/PortOut.c index 99a4fad438..0b37dcfd41 100644 --- a/shared-module/usb_midi/PortOut.c +++ b/shared-module/usb_midi/PortOut.c @@ -33,5 +33,5 @@ size_t common_hal_usb_midi_portout_write(usb_midi_portout_obj_t *self, const uin } bool common_hal_usb_midi_portout_ready_to_tx(usb_midi_portout_obj_t *self) { - return tud_midi_connected(); + return tud_midi_mounted(); } diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index 301805275a..ad5825b6c9 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -107,7 +107,7 @@ // USB RAM PLACEMENT //--------------------------------------------------------------------+ #define CFG_TUSB_ATTR_USBRAM -#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) +#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) #ifdef __cplusplus diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 5a0de1ffc8..48f2da3d36 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -24,23 +24,36 @@ * THE SOFTWARE. */ -#include "supervisor/shared/usb/usb_desc.h" +#include "lib/tinyusb/src/tusb.h" #include "shared-module/usb_hid/Device.h" #include "genhdr/autogen_usb_descriptor.h" -// tud_desc_set is required by tinyusb stack -tud_desc_set_t tud_desc_set = -{ - .device = &usb_desc_dev, - .config = &usb_desc_cfg, - .string_arr = (uint8_t const **) string_desc_arr, - .string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]), +// Invoked when received GET DEVICE DESCRIPTOR +// Application return pointer to descriptor +uint8_t const * tud_descriptor_device_cb(void) { + return usb_desc_dev; +} - .hid_report = - { - .generic = hid_report_descriptor, - .boot_keyboard = NULL, - .boot_mouse = NULL - } -}; +// Invoked when received GET CONFIGURATION DESCRIPTOR +// Application return pointer to descriptor +// Descriptor contents must exist long enough for transfer to complete +uint8_t const * tud_descriptor_configuration_cb(uint8_t index) { + (void) index; // for multiple configurations + return usb_desc_cfg; +} + + +// Invoked when received GET HID REPORT DESCRIPTOR +// Application return pointer to descriptor +// Descriptor contents must exist long enough for transfer to complete +uint8_t const * tud_hid_descriptor_report_cb(void) { + return hid_report_descriptor; +} + +// Invoked when received GET STRING DESCRIPTOR request +// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete +uint16_t const* tud_descriptor_string_cb(uint8_t index) { + uint8_t const max_index = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]); + return (index < max_index) ? string_desc_arr[index] : NULL; +} diff --git a/supervisor/shared/usb/usb_desc.h b/supervisor/shared/usb/usb_desc.h deleted file mode 100644 index 250147aa66..0000000000 --- a/supervisor/shared/usb/usb_desc.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 hathach for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef USB_DESC_H_ -#define USB_DESC_H_ - -#include "lib/tinyusb/src/tusb.h" - -#ifdef __cplusplus - extern "C" { -#endif - -// Descriptors set used by tinyusb stack -extern tud_desc_set_t tud_desc_set; - -#ifdef __cplusplus - } -#endif - -#endif /* USB_DESC_H_ */ diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c index f6f0fa9c34..205cb7b500 100644 --- a/supervisor/shared/usb/usb_msc_flash.c +++ b/supervisor/shared/usb/usb_msc_flash.c @@ -59,59 +59,18 @@ static fs_user_mount_t* get_vfs(int lun) { } // Callback invoked when received an SCSI command not in built-in list below -// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE +// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, TEST_UNIT_READY, START_STOP_UNIT, MODE_SENSE6, REQUEST_SENSE // - READ10 and WRITE10 have their own callbacks int32_t tud_msc_scsi_cb (uint8_t lun, const uint8_t scsi_cmd[16], void* buffer, uint16_t bufsize) { const void* response = NULL; int32_t resplen = 0; switch ( scsi_cmd[0] ) { - case SCSI_CMD_TEST_UNIT_READY: - // Command that host uses to check our readiness before sending other commands - resplen = 0; - if (lun > 1) { - resplen = -1; - } else { - fs_user_mount_t* current_mount = get_vfs(lun); - if (current_mount == NULL) { - resplen = -1; - } - if (ejected[lun]) { - resplen = -1; - } - } - break; - case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: // Host is about to read/write etc ... better not to disconnect disk resplen = 0; break; - case SCSI_CMD_START_STOP_UNIT: - { - // Host try to eject/safe remove/poweroff us. We could safely disconnect with disk storage, or go into lower power - const scsi_start_stop_unit_t* start_stop = (const scsi_start_stop_unit_t*) scsi_cmd; - // Start bit = 0 : low power mode, if load_eject = 1 : unmount disk storage as well - // Start bit = 1 : Ready mode, if load_eject = 1 : mount disk storage - resplen = 0; - if (start_stop->load_eject == 1) { - if (lun > 1) { - resplen = -1; - } else { - fs_user_mount_t* current_mount = get_vfs(lun); - if (current_mount == NULL) { - resplen = -1; - } - if (disk_ioctl(current_mount, CTRL_SYNC, NULL) != RES_OK) { - resplen = -1; - } else { - ejected[lun] = true; - } - } - } - } - break; - default: // Set Sense = Invalid Command Operation tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); @@ -127,7 +86,7 @@ int32_t tud_msc_scsi_cb (uint8_t lun, const uint8_t scsi_cmd[16], void* buffer, } // copy response to stack's buffer if any - if ( response && resplen ) { + if ( response && (resplen > 0) ) { memcpy(buffer, response, resplen); } @@ -206,3 +165,54 @@ void tud_msc_write10_complete_cb (uint8_t lun) { // This write is complete, start the autoreload clock. autoreload_start(); } + +// Invoked when received SCSI_CMD_INQUIRY +// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively +void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) { + (void) lun; + + memcpy(vendor_id , CFG_TUD_MSC_VENDOR , strlen(CFG_TUD_MSC_VENDOR)); + memcpy(product_id , CFG_TUD_MSC_PRODUCT , strlen(CFG_TUD_MSC_PRODUCT)); + memcpy(product_rev, CFG_TUD_MSC_PRODUCT_REV, strlen(CFG_TUD_MSC_PRODUCT_REV)); +} + +// Invoked when received Test Unit Ready command. +// return true allowing host to read/write this LUN e.g SD card inserted +bool tud_msc_test_unit_ready_cb(uint8_t lun) { + if (lun > 1) { + return false; + } + + fs_user_mount_t* current_mount = get_vfs(lun); + if (current_mount == NULL) { + return false; + } + if (ejected[lun]) { + return false; + } + + return true; +} + +// Invoked when received Start Stop Unit command +// - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage +// - Start = 1 : active mode, if load_eject = 1 : load disk storage +bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) { + if (load_eject) { + if (lun > 1) { + return false; + } else { + fs_user_mount_t* current_mount = get_vfs(lun); + if (current_mount == NULL) { + return false; + } + if (disk_ioctl(current_mount, CTRL_SYNC, NULL) != RES_OK) { + return false; + } else { + ejected[lun] = true; + } + } + } + + return true; +} From 5d03cda01ade5a81d3096f9af0ac5e89a31be099 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 24 Jul 2019 16:49:13 +0700 Subject: [PATCH 61/61] whitespace --- supervisor/shared/usb/usb_desc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 48f2da3d36..9b333d6fea 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -43,7 +43,6 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index) { return usb_desc_cfg; } - // Invoked when received GET HID REPORT DESCRIPTOR // Application return pointer to descriptor // Descriptor contents must exist long enough for transfer to complete