Skip to content

Commit 430e258

Browse files
Merge branch 'micropython:master' into patch-1
2 parents 6b5c60b + 567540d commit 430e258

File tree

75 files changed

+474
-133
lines changed

Some content is hidden

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

75 files changed

+474
-133
lines changed

.github/workflows/build_packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
if: vars.MICROPY_PUBLISH_MIP_INDEX && github.event_name == 'push' && ! github.event.deleted
2424
run: source tools/ci.sh && ci_push_package_index
2525
- name: Upload packages as artifact
26-
uses: actions/upload-artifact@v3
26+
uses: actions/upload-artifact@v4
2727
with:
2828
name: packages-${{ github.sha }}
2929
path: ${{ env.PACKAGE_INDEX_PATH }}

.github/workflows/ruff.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66
runs-on: ubuntu-latest
77
steps:
88
- uses: actions/checkout@v4
9-
- run: pip install --user ruff==0.1.2
9+
# Version should be kept in sync with .pre-commit_config.yaml & also micropython
10+
- run: pip install --user ruff==0.11.6
1011
- run: ruff check --output-format=github .
1112
- run: ruff format --diff .

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ repos:
88
verbose: true
99
stages: [commit-msg]
1010
- repo: https://github.com/charliermarsh/ruff-pre-commit
11-
rev: v0.1.2
11+
# Version should be kept in sync with .github/workflows/ruff.yml & also micropython
12+
rev: v0.11.6
1213
hooks:
1314
- id: ruff
1415
id: ruff-format

micropython/aioespnow/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ A small async server example::
5555
import asyncio
5656

5757
# A WLAN interface must be active to send()/recv()
58-
network.WLAN(network.STA_IF).active(True)
58+
network.WLAN(network.WLAN.IF_STA).active(True)
5959

6060
e = aioespnow.AIOESPNow() # Returns AIOESPNow enhanced with async support
6161
e.active(True)

micropython/aiorepl/aiorepl.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async def task(g=None, prompt="--> "):
132132
continue
133133
if curs:
134134
# move cursor to end of the line
135-
sys.stdout.write("\x1B[{}C".format(curs))
135+
sys.stdout.write("\x1b[{}C".format(curs))
136136
curs = 0
137137
sys.stdout.write("\n")
138138
if cmd:
@@ -153,10 +153,10 @@ async def task(g=None, prompt="--> "):
153153
if curs:
154154
cmd = "".join((cmd[: -curs - 1], cmd[-curs:]))
155155
sys.stdout.write(
156-
"\x08\x1B[K"
156+
"\x08\x1b[K"
157157
) # move cursor back, erase to end of line
158158
sys.stdout.write(cmd[-curs:]) # redraw line
159-
sys.stdout.write("\x1B[{}D".format(curs)) # reset cursor location
159+
sys.stdout.write("\x1b[{}D".format(curs)) # reset cursor location
160160
else:
161161
cmd = cmd[:-1]
162162
sys.stdout.write("\x08 \x08")
@@ -207,21 +207,21 @@ async def task(g=None, prompt="--> "):
207207
elif key == "[D": # left
208208
if curs < len(cmd) - 1:
209209
curs += 1
210-
sys.stdout.write("\x1B")
210+
sys.stdout.write("\x1b")
211211
sys.stdout.write(key)
212212
elif key == "[C": # right
213213
if curs:
214214
curs -= 1
215-
sys.stdout.write("\x1B")
215+
sys.stdout.write("\x1b")
216216
sys.stdout.write(key)
217217
elif key == "[H": # home
218218
pcurs = curs
219219
curs = len(cmd)
220-
sys.stdout.write("\x1B[{}D".format(curs - pcurs)) # move cursor left
220+
sys.stdout.write("\x1b[{}D".format(curs - pcurs)) # move cursor left
221221
elif key == "[F": # end
222222
pcurs = curs
223223
curs = 0
224-
sys.stdout.write("\x1B[{}C".format(pcurs)) # move cursor right
224+
sys.stdout.write("\x1b[{}C".format(pcurs)) # move cursor right
225225
else:
226226
# sys.stdout.write("\\x")
227227
# sys.stdout.write(hex(c))
@@ -231,7 +231,7 @@ async def task(g=None, prompt="--> "):
231231
# inserting into middle of line
232232
cmd = "".join((cmd[:-curs], b, cmd[-curs:]))
233233
sys.stdout.write(cmd[-curs - 1 :]) # redraw line to end
234-
sys.stdout.write("\x1B[{}D".format(curs)) # reset cursor location
234+
sys.stdout.write("\x1b[{}D".format(curs)) # reset cursor location
235235
else:
236236
sys.stdout.write(b)
237237
cmd += b

micropython/bluetooth/aioble-central/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.2.2")
1+
metadata(version="0.3.0")
22

33
require("aioble-core")
44

micropython/bluetooth/aioble-core/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.3.0")
1+
metadata(version="0.4.0")
22

33
package(
44
"aioble",

micropython/bluetooth/aioble/aioble/central.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ async def _cancel_pending():
104104

105105
# Start connecting to a peripheral.
106106
# Call device.connect() rather than using method directly.
107-
async def _connect(connection, timeout_ms):
107+
async def _connect(
108+
connection, timeout_ms, scan_duration_ms, min_conn_interval_us, max_conn_interval_us
109+
):
108110
device = connection.device
109111
if device in _connecting:
110112
return
@@ -122,7 +124,13 @@ async def _connect(connection, timeout_ms):
122124

123125
try:
124126
with DeviceTimeout(None, timeout_ms):
125-
ble.gap_connect(device.addr_type, device.addr)
127+
ble.gap_connect(
128+
device.addr_type,
129+
device.addr,
130+
scan_duration_ms,
131+
min_conn_interval_us,
132+
max_conn_interval_us,
133+
)
126134

127135
# Wait for the connected IRQ.
128136
await connection._event.wait()

micropython/bluetooth/aioble/aioble/device.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,26 @@ def __str__(self):
132132
def addr_hex(self):
133133
return binascii.hexlify(self.addr, ":").decode()
134134

135-
async def connect(self, timeout_ms=10000):
135+
async def connect(
136+
self,
137+
timeout_ms=10000,
138+
scan_duration_ms=None,
139+
min_conn_interval_us=None,
140+
max_conn_interval_us=None,
141+
):
136142
if self._connection:
137143
return self._connection
138144

139145
# Forward to implementation in central.py.
140146
from .central import _connect
141147

142-
await _connect(DeviceConnection(self), timeout_ms)
148+
await _connect(
149+
DeviceConnection(self),
150+
timeout_ms,
151+
scan_duration_ms,
152+
min_conn_interval_us,
153+
max_conn_interval_us,
154+
)
143155

144156
# Start the device task that will clean up after disconnection.
145157
self._connection._run_task()

micropython/bluetooth/aioble/examples/l2cap_file_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def download(self, path, dest):
8888

8989
await self._command(_COMMAND_SEND, path.encode())
9090

91-
with open(dest, "wb") as f: # noqa: ASYNC101
91+
with open(dest, "wb") as f: # noqa: ASYNC230
9292
total = 0
9393
buf = bytearray(self._channel.our_mtu)
9494
mv = memoryview(buf)

micropython/bluetooth/aioble/examples/l2cap_file_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def l2cap_task(connection):
8383

8484
if send_file:
8585
print("Sending:", send_file)
86-
with open(send_file, "rb") as f: # noqa: ASYNC101
86+
with open(send_file, "rb") as f: # noqa: ASYNC230
8787
buf = bytearray(channel.peer_mtu)
8888
mv = memoryview(buf)
8989
while n := f.readinto(buf):

micropython/bluetooth/aioble/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# code. This allows (for development purposes) all the files to live in the
44
# one directory.
55

6-
metadata(version="0.5.2")
6+
metadata(version="0.6.0")
77

88
# Default installation gives you everything. Install the individual
99
# components (or a combination of them) if you want a more minimal install.

micropython/drivers/codec/wm8960/wm8960.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ def __init__(
331331
sysclk = 11289600
332332
else:
333333
sysclk = 12288000
334-
if sysclk < sample_rate * 256:
335-
sysclk = sample_rate * 256
334+
sysclk = max(sysclk, sample_rate * 256)
336335
if mclk_freq is None:
337336
mclk_freq = sysclk
338337
else: # sysclk_source == SYSCLK_MCLK
@@ -691,10 +690,8 @@ def alc_mode(self, channel, mode=ALC_MODE):
691690
def alc_gain(self, target=-12, max_gain=30, min_gain=-17.25, noise_gate=-78):
692691
def limit(value, minval, maxval):
693692
value = int(value)
694-
if value < minval:
695-
value = minval
696-
if value > maxval:
697-
value = maxval
693+
value = max(value, minval)
694+
value = min(value, maxval)
698695
return value
699696

700697
target = limit((16 + (target * 2) // 3), 0, 15)
@@ -718,8 +715,7 @@ def logb(value, limit):
718715
while value > 1:
719716
value >>= 1
720717
lb += 1
721-
if lb > limit:
722-
lb = limit
718+
lb = min(lb, limit)
723719
return lb
724720

725721
attack = logb(attack / 6, 7)

micropython/drivers/display/lcd160cr/lcd160cr.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,8 @@ def clip_line(c, w, h):
189189
c[3] = h - 1
190190
else:
191191
if c[0] == c[2]:
192-
if c[1] < 0:
193-
c[1] = 0
194-
if c[3] < 0:
195-
c[3] = 0
192+
c[1] = max(c[1], 0)
193+
c[3] = max(c[3], 0)
196194
else:
197195
if c[3] < c[1]:
198196
c[0], c[2] = c[2], c[0]

micropython/drivers/imu/lsm9ds1/lsm9ds1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
print("")
4444
time.sleep_ms(100)
4545
"""
46+
4647
import array
4748
from micropython import const
4849

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(description="nrf24l01 2.4GHz radio driver.", version="0.1.0")
1+
metadata(description="nrf24l01 2.4GHz radio driver.", version="0.2.0")
22

33
module("nrf24l01.py", opt=3)

micropython/drivers/radio/nrf24l01/nrf24l01.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""NRF24L01 driver for MicroPython
2-
"""
1+
"""NRF24L01 driver for MicroPython"""
32

43
from micropython import const
54
import utime
@@ -130,6 +129,13 @@ def reg_write(self, reg, value):
130129
self.cs(1)
131130
return ret
132131

132+
def read_status(self):
133+
self.cs(0)
134+
# STATUS register is always shifted during command transmit
135+
self.spi.readinto(self.buf, NOP)
136+
self.cs(1)
137+
return self.buf[0]
138+
133139
def flush_rx(self):
134140
self.cs(0)
135141
self.spi.readinto(self.buf, FLUSH_RX)
@@ -220,14 +226,21 @@ def send(self, buf, timeout=500):
220226
result = None
221227
while result is None and utime.ticks_diff(utime.ticks_ms(), start) < timeout:
222228
result = self.send_done() # 1 == success, 2 == fail
229+
230+
if result is None:
231+
# timed out, cancel sending and power down the module
232+
self.flush_tx()
233+
self.reg_write(CONFIG, self.reg_read(CONFIG) & ~PWR_UP)
234+
raise OSError("timed out")
235+
223236
if result == 2:
224237
raise OSError("send failed")
225238

226239
# non-blocking tx
227240
def send_start(self, buf):
228241
# power up
229242
self.reg_write(CONFIG, (self.reg_read(CONFIG) | PWR_UP) & ~PRIM_RX)
230-
utime.sleep_us(150)
243+
utime.sleep_us(1500) # needs to be 1.5ms
231244
# send the data
232245
self.cs(0)
233246
self.spi.readinto(self.buf, W_TX_PAYLOAD)
@@ -243,7 +256,8 @@ def send_start(self, buf):
243256

244257
# returns None if send still in progress, 1 for success, 2 for fail
245258
def send_done(self):
246-
if not (self.reg_read(STATUS) & (TX_DS | MAX_RT)):
259+
status = self.read_status()
260+
if not (status & (TX_DS | MAX_RT)):
247261
return None # tx not finished
248262

249263
# either finished or failed: get and clear status flags, power down

micropython/drivers/sensor/hts221/hts221.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, i2c, data_rate=1, address=0x5F):
5252

5353
# Set configuration register
5454
# Humidity and temperature average configuration
55-
self.bus.writeto_mem(self.slv_addr, 0x10, b"\x1B")
55+
self.bus.writeto_mem(self.slv_addr, 0x10, b"\x1b")
5656

5757
# Set control register
5858
# PD | BDU | ODR

micropython/drivers/sensor/lps22h/lps22h.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
print("Pressure: %.2f hPa Temperature: %.2f C"%(lps.pressure(), lps.temperature()))
3838
time.sleep_ms(10)
3939
"""
40+
4041
import machine
4142
from micropython import const
4243

micropython/espflash/espflash.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,22 @@ def _poll_reg(self, addr, flag, retry=10, delay=0.050):
113113
raise Exception(f"Register poll timeout. Addr: 0x{addr:02X} Flag: 0x{flag:02X}.")
114114

115115
def _write_slip(self, pkt):
116-
pkt = pkt.replace(b"\xDB", b"\xdb\xdd").replace(b"\xc0", b"\xdb\xdc")
117-
self.uart.write(b"\xC0" + pkt + b"\xC0")
116+
pkt = pkt.replace(b"\xdb", b"\xdb\xdd").replace(b"\xc0", b"\xdb\xdc")
117+
self.uart.write(b"\xc0" + pkt + b"\xc0")
118118
self._log(pkt)
119119

120120
def _read_slip(self):
121121
pkt = None
122122
# Find the packet start.
123-
if self.uart.read(1) == b"\xC0":
123+
if self.uart.read(1) == b"\xc0":
124124
pkt = bytearray()
125125
while True:
126126
b = self.uart.read(1)
127-
if b is None or b == b"\xC0":
127+
if b is None or b == b"\xc0":
128128
break
129129
pkt += b
130-
pkt = pkt.replace(b"\xDB\xDD", b"\xDB").replace(b"\xDB\xDC", b"\xC0")
131-
self._log(b"\xC0" + pkt + b"\xC0", False)
130+
pkt = pkt.replace(b"\xdb\xdd", b"\xdb").replace(b"\xdb\xdc", b"\xc0")
131+
self._log(b"\xc0" + pkt + b"\xc0", False)
132132
return pkt
133133

134134
def _strerror(self, err):
@@ -230,7 +230,7 @@ def flash_read_size(self):
230230
raise Exception(f"Unexpected flash size bits: 0x{flash_bits:02X}.")
231231

232232
flash_size = 2**flash_bits
233-
print(f"Flash size {flash_size/1024/1024} MBytes")
233+
print(f"Flash size {flash_size / 1024 / 1024} MBytes")
234234
return flash_size
235235

236236
def flash_attach(self):
@@ -265,7 +265,7 @@ def flash_write_file(self, path, blksize=0x1000):
265265
self.md5sum.update(buf)
266266
# The last data block should be padded to the block size with 0xFF bytes.
267267
if len(buf) < blksize:
268-
buf += b"\xFF" * (blksize - len(buf))
268+
buf += b"\xff" * (blksize - len(buf))
269269
checksum = self._checksum(buf)
270270
if seq % erase_blocks == 0:
271271
# print(f"Erasing {seq} -> {seq+erase_blocks}...")

micropython/lora/examples/reliable_delivery/sender.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def send(self, sensor_data, adjust_output_power=True):
149149
delta = time.ticks_diff(maybe_ack.ticks_ms, sent_at)
150150
print(
151151
f"ACKed with RSSI {rssi}, {delta}ms after sent "
152-
+ f"(skew {delta-ACK_DELAY_MS-ack_packet_ms}ms)"
152+
+ f"(skew {delta - ACK_DELAY_MS - ack_packet_ms}ms)"
153153
)
154154

155155
if adjust_output_power:

micropython/lora/examples/reliable_delivery/sender_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async def send(self, sensor_data, adjust_output_power=True):
141141
delta = time.ticks_diff(maybe_ack.ticks_ms, sent_at)
142142
print(
143143
f"ACKed with RSSI {rssi}, {delta}ms after sent "
144-
+ f"(skew {delta-ACK_DELAY_MS-ack_packet_ms}ms)"
144+
+ f"(skew {delta - ACK_DELAY_MS - ack_packet_ms}ms)"
145145
)
146146

147147
if adjust_output_power:

0 commit comments

Comments
 (0)