Skip to content

Commit 6163539

Browse files
circup libs and fix mqtt recv issues
Ref: adafruit/Adafruit_CircuitPython_MiniMQTT#54
1 parent 78f8995 commit 6163539

File tree

89 files changed

+7755
-0
lines changed

Some content is hidden

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

89 files changed

+7755
-0
lines changed

boot_out.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adafruit CircuitPython 6.0.1 on 2020-12-28; Adafruit PyPortal with samd51j20

lib/adafruit_adt7410.mpy

100644100755
File mode changed.

lib/adafruit_bitmap_font/__init__.py

100644100755
File mode changed.

lib/adafruit_bitmap_font/bdf.mpy

100644100755
0 Bytes
Binary file not shown.

lib/adafruit_bitmap_font/bitmap_font.mpy

100644100755
0 Bytes
Binary file not shown.

lib/adafruit_bitmap_font/glyph_cache.mpy

100644100755
0 Bytes
Binary file not shown.

lib/adafruit_bitmap_font/pcf.mpy

100644100755
28 Bytes
Binary file not shown.

lib/adafruit_bitmap_font/ttf.mpy

100644100755
File mode changed.

lib/adafruit_bus_device/__init__.py

100644100755
File mode changed.
-1.9 KB
Binary file not shown.

lib/adafruit_bus_device/i2c_device.py

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
23+
"""
24+
`adafruit_bus_device.i2c_device` - I2C Bus Device
25+
====================================================
26+
"""
27+
28+
__version__ = "5.0.3"
29+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git"
30+
31+
32+
class I2CDevice:
33+
"""
34+
Represents a single I2C device and manages locking the bus and the device
35+
address.
36+
37+
:param ~busio.I2C i2c: The I2C bus the device is on
38+
:param int device_address: The 7 bit device address
39+
:param bool probe: Probe for the device upon object creation, default is true
40+
41+
.. note:: This class is **NOT** built into CircuitPython. See
42+
:ref:`here for install instructions <bus_device_installation>`.
43+
44+
Example:
45+
46+
.. code-block:: python
47+
48+
import busio
49+
from board import *
50+
from adafruit_bus_device.i2c_device import I2CDevice
51+
52+
with busio.I2C(SCL, SDA) as i2c:
53+
device = I2CDevice(i2c, 0x70)
54+
bytes_read = bytearray(4)
55+
with device:
56+
device.readinto(bytes_read)
57+
# A second transaction
58+
with device:
59+
device.write(bytes_read)
60+
"""
61+
62+
def __init__(self, i2c, device_address, probe=True):
63+
64+
self.i2c = i2c
65+
self.device_address = device_address
66+
67+
if probe:
68+
self.__probe_for_device()
69+
70+
def readinto(self, buf, *, start=0, end=None):
71+
"""
72+
Read into ``buf`` from the device. The number of bytes read will be the
73+
length of ``buf``.
74+
75+
If ``start`` or ``end`` is provided, then the buffer will be sliced
76+
as if ``buf[start:end]``. This will not cause an allocation like
77+
``buf[start:end]`` will so it saves memory.
78+
79+
:param bytearray buffer: buffer to write into
80+
:param int start: Index to start writing at
81+
:param int end: Index to write up to but not include; if None, use ``len(buf)``
82+
"""
83+
if end is None:
84+
end = len(buf)
85+
self.i2c.readfrom_into(self.device_address, buf, start=start, end=end)
86+
87+
def write(self, buf, *, start=0, end=None):
88+
"""
89+
Write the bytes from ``buffer`` to the device, then transmit a stop
90+
bit.
91+
92+
If ``start`` or ``end`` is provided, then the buffer will be sliced
93+
as if ``buffer[start:end]``. This will not cause an allocation like
94+
``buffer[start:end]`` will so it saves memory.
95+
96+
:param bytearray buffer: buffer containing the bytes to write
97+
:param int start: Index to start writing from
98+
:param int end: Index to read up to but not include; if None, use ``len(buf)``
99+
"""
100+
if end is None:
101+
end = len(buf)
102+
self.i2c.writeto(self.device_address, buf, start=start, end=end)
103+
104+
# pylint: disable-msg=too-many-arguments
105+
def write_then_readinto(
106+
self,
107+
out_buffer,
108+
in_buffer,
109+
*,
110+
out_start=0,
111+
out_end=None,
112+
in_start=0,
113+
in_end=None
114+
):
115+
"""
116+
Write the bytes from ``out_buffer`` to the device, then immediately
117+
reads into ``in_buffer`` from the device. The number of bytes read
118+
will be the length of ``in_buffer``.
119+
120+
If ``out_start`` or ``out_end`` is provided, then the output buffer
121+
will be sliced as if ``out_buffer[out_start:out_end]``. This will
122+
not cause an allocation like ``buffer[out_start:out_end]`` will so
123+
it saves memory.
124+
125+
If ``in_start`` or ``in_end`` is provided, then the input buffer
126+
will be sliced as if ``in_buffer[in_start:in_end]``. This will not
127+
cause an allocation like ``in_buffer[in_start:in_end]`` will so
128+
it saves memory.
129+
130+
:param bytearray out_buffer: buffer containing the bytes to write
131+
:param bytearray in_buffer: buffer containing the bytes to read into
132+
:param int out_start: Index to start writing from
133+
:param int out_end: Index to read up to but not include; if None, use ``len(out_buffer)``
134+
:param int in_start: Index to start writing at
135+
:param int in_end: Index to write up to but not include; if None, use ``len(in_buffer)``
136+
"""
137+
if out_end is None:
138+
out_end = len(out_buffer)
139+
if in_end is None:
140+
in_end = len(in_buffer)
141+
142+
self.i2c.writeto_then_readfrom(
143+
self.device_address,
144+
out_buffer,
145+
in_buffer,
146+
out_start=out_start,
147+
out_end=out_end,
148+
in_start=in_start,
149+
in_end=in_end,
150+
)
151+
152+
# pylint: enable-msg=too-many-arguments
153+
154+
def __enter__(self):
155+
while not self.i2c.try_lock():
156+
pass
157+
return self
158+
159+
def __exit__(self, exc_type, exc_val, exc_tb):
160+
self.i2c.unlock()
161+
return False
162+
163+
def __probe_for_device(self):
164+
"""
165+
Try to read a byte from an address,
166+
if you get an OSError it means the device is not there
167+
or that the device does not support these means of probing
168+
"""
169+
while not self.i2c.try_lock():
170+
pass
171+
try:
172+
self.i2c.writeto(self.device_address, b"")
173+
except OSError:
174+
# some OS's dont like writing an empty bytesting...
175+
# Retry by reading a byte
176+
try:
177+
result = bytearray(1)
178+
self.i2c.readfrom_into(self.device_address, result)
179+
except OSError:
180+
# pylint: disable=raise-missing-from
181+
raise ValueError("No I2C device at address: 0x%x" % self.device_address)
182+
# pylint: enable=raise-missing-from
183+
finally:
184+
self.i2c.unlock()
-1.24 KB
Binary file not shown.

lib/adafruit_bus_device/spi_device.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
# pylint: disable=too-few-public-methods
23+
24+
"""
25+
`adafruit_bus_device.spi_device` - SPI Bus Device
26+
====================================================
27+
"""
28+
29+
__version__ = "5.0.3"
30+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BusDevice.git"
31+
32+
33+
class SPIDevice:
34+
"""
35+
Represents a single SPI device and manages locking the bus and the device
36+
address.
37+
38+
:param ~busio.SPI spi: The SPI bus the device is on
39+
:param ~digitalio.DigitalInOut chip_select: The chip select pin object that implements the
40+
DigitalInOut API.
41+
:param int extra_clocks: The minimum number of clock cycles to cycle the bus after CS is high.
42+
(Used for SD cards.)
43+
44+
.. note:: This class is **NOT** built into CircuitPython. See
45+
:ref:`here for install instructions <bus_device_installation>`.
46+
47+
Example:
48+
49+
.. code-block:: python
50+
51+
import busio
52+
import digitalio
53+
from board import *
54+
from adafruit_bus_device.spi_device import SPIDevice
55+
56+
with busio.SPI(SCK, MOSI, MISO) as spi_bus:
57+
cs = digitalio.DigitalInOut(D10)
58+
device = SPIDevice(spi_bus, cs)
59+
bytes_read = bytearray(4)
60+
# The object assigned to spi in the with statements below
61+
# is the original spi_bus object. We are using the busio.SPI
62+
# operations busio.SPI.readinto() and busio.SPI.write().
63+
with device as spi:
64+
spi.readinto(bytes_read)
65+
# A second transaction
66+
with device as spi:
67+
spi.write(bytes_read)
68+
"""
69+
70+
def __init__(
71+
self,
72+
spi,
73+
chip_select=None,
74+
*,
75+
baudrate=100000,
76+
polarity=0,
77+
phase=0,
78+
extra_clocks=0
79+
):
80+
self.spi = spi
81+
self.baudrate = baudrate
82+
self.polarity = polarity
83+
self.phase = phase
84+
self.extra_clocks = extra_clocks
85+
self.chip_select = chip_select
86+
if self.chip_select:
87+
self.chip_select.switch_to_output(value=True)
88+
89+
def __enter__(self):
90+
while not self.spi.try_lock():
91+
pass
92+
self.spi.configure(
93+
baudrate=self.baudrate, polarity=self.polarity, phase=self.phase
94+
)
95+
if self.chip_select:
96+
self.chip_select.value = False
97+
return self.spi
98+
99+
def __exit__(self, exc_type, exc_val, exc_tb):
100+
if self.chip_select:
101+
self.chip_select.value = True
102+
if self.extra_clocks > 0:
103+
buf = bytearray(1)
104+
buf[0] = 0xFF
105+
clocks = self.extra_clocks // 8
106+
if self.extra_clocks % 8 != 0:
107+
clocks += 1
108+
for _ in range(clocks):
109+
self.spi.write(buf)
110+
self.spi.unlock()
111+
return False

lib/adafruit_button.mpy

100644100755
File mode changed.
-651 Bytes
Binary file not shown.

lib/adafruit_display_shapes/circle.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`circle`
7+
================================================================================
8+
9+
Various common shapes for use with displayio - Circle shape!
10+
11+
12+
* Author(s): Limor Fried
13+
14+
Implementation Notes
15+
--------------------
16+
17+
**Software and Dependencies:**
18+
19+
* Adafruit CircuitPython firmware for the supported boards:
20+
https://github.com/adafruit/circuitpython/releases
21+
22+
"""
23+
24+
from adafruit_display_shapes.roundrect import RoundRect
25+
26+
__version__ = "2.0.4"
27+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes.git"
28+
29+
30+
class Circle(RoundRect):
31+
# pylint: disable=too-few-public-methods, invalid-name
32+
"""A circle.
33+
34+
:param x0: The x-position of the center.
35+
:param y0: The y-position of the center..
36+
:param r: The radius of the circle.
37+
:param fill: The color to fill the rounded-corner rectangle. Can be a hex value for a color or
38+
``None`` for transparent.
39+
:param outline: The outline of the rounded-corner rectangle. Can be a hex value for a color or
40+
``None`` for no outline.
41+
:param stroke: Used for the outline. Will not change the radius.
42+
43+
"""
44+
45+
def __init__(self, x0, y0, r, *, fill=None, outline=None, stroke=1):
46+
super().__init__(
47+
x0 - r,
48+
y0 - r,
49+
2 * r + 1,
50+
2 * r + 1,
51+
r,
52+
fill=fill,
53+
outline=outline,
54+
stroke=stroke,
55+
)

lib/adafruit_display_shapes/line.mpy

-548 Bytes
Binary file not shown.

lib/adafruit_display_shapes/line.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`line`
7+
================================================================================
8+
9+
Various common shapes for use with displayio - Line shape!
10+
11+
12+
* Author(s): Melissa LeBlanc-Williams
13+
14+
Implementation Notes
15+
--------------------
16+
17+
**Software and Dependencies:**
18+
19+
* Adafruit CircuitPython firmware for the supported boards:
20+
https://github.com/adafruit/circuitpython/releases
21+
22+
"""
23+
24+
from adafruit_display_shapes.polygon import Polygon
25+
26+
__version__ = "2.0.4"
27+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes.git"
28+
29+
30+
class Line(Polygon):
31+
# pylint: disable=too-many-arguments,invalid-name, too-few-public-methods
32+
"""A line.
33+
34+
:param x0: The x-position of the first vertex.
35+
:param y0: The y-position of the first vertex.
36+
:param x1: The x-position of the second vertex.
37+
:param y1: The y-position of the second vertex.
38+
:param color: The color of the line.
39+
"""
40+
41+
def __init__(self, x0, y0, x1, y1, color):
42+
super().__init__([(x0, y0), (x1, y1)], outline=color)
-1.67 KB
Binary file not shown.

0 commit comments

Comments
 (0)