Commit Graph

43 Commits

Author SHA1 Message Date
Jeff Epler 32a29ffdff shared-bindings: Change docstrings with '\x...' chars to raw strings
Closes: #3032
2020-06-14 13:05:08 -05:00
Sean Cross 34f91f01c6 bleio: adapter: add advertising timeout and status
Add a field to allow specifying a timeout when initiating advertising.
As part of this, add a new property to determine if the device is still
advertising.

Additionally, have the `anonymous` property require a timeout, and set
the timeout to the maximum possible value if no timeout is specified.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-19 15:01:19 +08:00
Sean Cross cfe65742a3 _bleio: support anonymous advertising
Add a new parameter to the `start_advertising()` function to enable
anonymous advertising.  This forces a call to `sd_ble_gap_privacy_set()`
with `privacy_mode` set to `BLE_GAP_PRIVACY_MODE_DEVICE_PRIVACY` and
`private_addr_type` set to
`BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE`.

With this, addresses will cycle at a predefined rate (currently once
every 15 minutes).

Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-19 15:01:18 +08:00
Scott Shawcroft 4e8de3c554
Swap sphinx to autoapi and the inline stubs 2020-05-12 17:28:24 -07:00
dherrada c534a872a2
Merge branch 'master' into master 2020-05-12 12:26:02 -04:00
Dan Halbert e1366d78b1 trivial change to force rebuild 2020-05-04 23:05:47 -04:00
Dan Halbert b7836aeac6 address review comments 2020-05-04 19:51:08 -04:00
Dan Halbert d6c6f9f4f0 add PacketBuffer .incoming_ and .outgoing_packet_length 2020-05-04 15:59:45 -04:00
dherrada 0e465e63b9
Did audiopwmio, bitbangio, and _bleio 2020-05-01 18:23:27 -04:00
Dan Halbert 46298ddcb4 PacketBuffer doc fixes 2020-04-30 00:36:01 -04:00
Dan Halbert f3078511a6 further cleanup and bug fixing 2020-04-29 23:18:08 -04:00
Dan Halbert 3d62f87e29 back to '.packet_size' for compatiblity 2020-04-29 22:10:56 -04:00
Dan Halbert 84cee1ab8d rename and improve PacketBuffer packet length property 2020-04-29 17:49:31 -04:00
Dan Halbert 38ec3bc574 further ringbuf cleanup 2020-04-21 17:38:20 -04:00
Scott Shawcroft 8a5d3cd6c4
Add exception on small buffer and fix Connecion WRITE handling 2020-03-25 17:41:47 -07:00
Dan Halbert e31ac710be Enable _bleio adapter when _bleio is imported 2020-02-20 21:55:04 -05:00
Dan Halbert e21580b67f PacketBuffer.packet_size was returning bool instead of int 2020-01-27 17:10:56 -05:00
Dan Halbert 2a75196aa3 merge from adafruit/circuitpython 2020-01-13 18:15:32 -05:00
Dan Halbert 9e7f8743c2 fix CCCD bonding store; avoid excessive bonding writes 2020-01-12 23:32:51 -05:00
Dan Halbert 346ce3b73b wip: HID bonding works! 2020-01-10 23:55:45 -05:00
Dan Halbert 9c167af17a wip; redid flash writing to be compatible with SD 2020-01-09 17:40:02 -05:00
Scott Shawcroft 82fb761c0f
Add PacketBuffer and MTU negotiation support.
PacketBuffer facilitates packet oriented BLE protocols such as BLE
MIDI and the Apple Media Service.

This also adds PHY, MTU and connection event extension negotiation
to speed up data transfer when possible.
2020-01-03 17:29:54 -08:00
Scott Shawcroft 9a3d45e7d0
Add extended, connectable and scannable error.
Related to https://github.com/adafruit/Adafruit_CircuitPython_BLE/issues/44
2019-12-12 13:46:59 -08:00
Scott Shawcroft 19ac8aea8c
Merge pull request #2353 from jepler/audiosample-protocol
Convert audiosamples to use micropython "protocols" (safely)
2019-12-09 14:50:16 -08:00
Dan Halbert f5e913101c
Merge pull request #2301 from tannewt/support_extended_advertising
Add support for extended (>31 byte) BLE advertisements.
2019-12-06 23:51:05 -05:00
Scott Shawcroft da0ea979ff
Check connection validity after service discovery.
Fixes #2347
2019-12-06 16:03:14 -08:00
Dan Halbert 559ce6a949
Merge pull request #2356 from tannewt/central_pairing
Add connection interval and debugging
2019-12-06 15:19:40 -05:00
Dan Halbert e30dde0afc Make _bleio.Connection.disconnect() idempotent 2019-12-05 08:40:53 -05:00
Scott Shawcroft 17c8356b8c
Add connection interval and debugging
This also sets TinyUSB to master and to not include its submodules.

It also fixes an old displayio example comment and retries gattc
reads.
2019-12-04 14:39:02 -08:00
Jeff Epler 238e121236 protocols: Allow them to be (optionally) type-safe
Protocols are nice, but there is no way for C code to verify whether
a type's "protocol" structure actually implements some particular
protocol.  As a result, you can pass an object that implements the
"vfs" protocol to one that expects the "stream" protocol, and the
opposite of awesomeness ensues.

This patch adds an OPTIONAL (but enabled by default) protocol identifier
as the first member of any protocol structure.  This identifier is
simply a unique QSTR chosen by the protocol designer and used by each
protocol implementer.  When checking for protocol support, instead of
just checking whether the object's type has a non-NULL protocol field,
use `mp_proto_get` which implements the protocol check when possible.

The existing protocols are now named:
    protocol_framebuf
    protocol_i2c
    protocol_pin
    protocol_stream
    protocol_spi
    protocol_vfs
(most of these are unused in CP and are just inherited from MP; vfs and
stream are definitely used though)

I did not find any crashing examples, but here's one to give a flavor of what
is improved, using `micropython_coverage`.  Before the change,
the vfs "ioctl" protocol is invoked, and the result is not intelligible
as json (but it could have resulted in a hard fault, potentially):

    >>> import uos, ujson
    >>> u = uos.VfsPosix('/tmp')
    >>> ujson.load(u)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: syntax error in JSON

After the change, the vfs object is correctly detected as not supporting
the stream protocol:
    >>> ujson.load(p)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: stream operation not supported
2019-12-04 09:29:57 -06:00
Scott Shawcroft 3fc58cee38
Merge remote-tracking branch 'adafruit/master' into support_extended_advertising 2019-11-26 13:12:43 -08:00
Scott Shawcroft 743bc829ab
Clean up debug changes 2019-11-21 16:39:57 -08:00
Scott Shawcroft 39f4046f70
Fix pairing when peripheral. Central untested. 2019-11-21 16:32:42 -08:00
Scott Shawcroft 98e55eb577
Only add module when printing exception. 2019-11-21 12:26:25 -08:00
Scott Shawcroft 521c7531bc
Improve printing to include _bleio. prefix for type. 2019-11-21 11:04:17 -08:00
Scott Shawcroft 5e857fdb67
Use BluetoothError in _bleio
This better differentiates errors than using OSError everywhere.
2019-11-20 14:02:15 -08:00
Scott Shawcroft 11c2c3443f
Add support for extended (>31 byte) BLE advertisements. 2019-11-19 13:55:58 -08:00
Dan Halbert 8584c1e824 Fix start_scan timeout default value 2019-11-13 21:34:20 -05:00
Scott Shawcroft 47e50e5659
Merge remote-tracking branch 'adafruit/master' into bleio_tweaks 2019-11-01 13:20:58 -07:00
Jeff Epler 978cec0316 pixelbuf: correct trivial typos 2019-10-27 16:41:56 -05:00
Scott Shawcroft 91c9d519ae
Refine comments and switch prefix_len to size_t 2019-10-22 23:09:56 -07:00
Scott Shawcroft ae30a1e5aa
Refine _bleio
This PR refines the _bleio API. It was originally motivated by
the addition of a new CircuitPython service that enables reading
and modifying files on the device. Moving the BLE lifecycle outside
of the VM motivated a number of changes to remove heap allocations
in some APIs.

It also motivated unifying connection initiation to the Adapter class
rather than the Central and Peripheral classes which have been removed.
Adapter now handles the GAP portion of BLE including advertising, which
has moved but is largely unchanged, and scanning, which has been enhanced
to return an iterator of filtered results.

Once a connection is created (either by us (aka Central) or a remote
device (aka Peripheral)) it is represented by a new Connection class.
This class knows the current connection state and can discover and
instantiate remote Services along with their Characteristics and
Descriptors.

Relates to #586
2019-10-21 18:57:03 -07:00
Dan Halbert 7a64af9280 rename bleio module to _bleio 2019-08-29 18:44:27 -04:00