Skip to content

Commit 2888a54

Browse files
committed
Merge remote-tracking branch 'upstream/master' into doc-ja
# Conflicts: # lib/lwip
2 parents 84bca06 + a1ee42c commit 2888a54

File tree

282 files changed

+7268
-3326
lines changed

Some content is hidden

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

282 files changed

+7268
-3326
lines changed

.github/workflows/ruff.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v4
10-
# ruff version should be kept in sync with .pre-commit-config.yaml
11-
- run: pipx install ruff==0.9.6
10+
# ruff version should be kept in sync with .pre-commit-config.yaml & also micropython-lib
11+
- run: pipx install ruff==0.11.6
1212
- run: ruff check --output-format=github .
1313
- run: ruff format --diff .

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ repos:
1212
verbose: true
1313
stages: [commit-msg]
1414
- repo: https://github.com/charliermarsh/ruff-pre-commit
15-
# Version should be kept in sync with .github/workflows/ruff.yml
16-
rev: v0.9.6
15+
# Version should be kept in sync with .github/workflows/ruff.yml & also micropython-lib
16+
rev: v0.11.6
1717
hooks:
1818
- id: ruff
1919
- id: ruff-format

CODECONVENTIONS.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,33 +206,65 @@ adhere to the existing style and use `tools/codeformat.py` to check any changes.
206206
The main conventions, and things not enforceable via the auto-formatter, are
207207
described below.
208208

209-
White space:
209+
As the MicroPython code base is over ten years old, not every source file
210+
conforms fully to these conventions. If making small changes to existing code,
211+
then it's usually acceptable to follow the existing code's style. New code or
212+
major changes should follow the conventions described here.
213+
214+
## White space
215+
210216
- Expand tabs to 4 spaces.
211217
- Don't leave trailing whitespace at the end of a line.
212218
- For control blocks (if, for, while), put 1 space between the
213219
keyword and the opening parenthesis.
214220
- Put 1 space after a comma, and 1 space around operators.
215221

216-
Braces:
222+
## Braces
223+
217224
- Use braces for all blocks, even no-line and single-line pieces of
218225
code.
219226
- Put opening braces on the end of the line it belongs to, not on
220227
a new line.
221228
- For else-statements, put the else on the same line as the previous
222229
closing brace.
223230

224-
Header files:
231+
## Header files
232+
225233
- Header files should be protected from multiple inclusion with #if
226234
directives. See an existing header for naming convention.
227235

228-
Names:
236+
## Names
237+
229238
- Use underscore_case, not camelCase for all names.
230239
- Use CAPS_WITH_UNDERSCORE for enums and macros.
231240
- When defining a type use underscore_case and put '_t' after it.
232241

233-
Integer types: MicroPython runs on 16, 32, and 64 bit machines, so it's
234-
important to use the correctly-sized (and signed) integer types. The
235-
general guidelines are:
242+
### Public names (declared in headers)
243+
244+
- MicroPython-specific names (especially any declared in `py/` and `extmod/`
245+
directories) should generally start with `mp_` or `MP_`.
246+
- Functions and variables declared in a header should generally share a longer
247+
common prefix. Usually the prefix matches the file name (i.e. items defined in
248+
`py/obj.c` are declared in `py/obj.h` and should be prefixed `mp_obj_`). There
249+
are exceptions, for example where one header file contains declarations
250+
implemented in multiple source files for expediency.
251+
252+
### Private names (specific to a single .c file)
253+
254+
- For static functions and variables exposed to Python (i.e. a static C function
255+
that is wrapped in `MP_DEFINE_CONST_FUN_...` and attached to a module), use
256+
the file-level shared common prefix, i.e. name them as if the function or
257+
variable was not static.
258+
- Other static definitions in source files (i.e. functions or variables defined
259+
in a .c file that are only used within that .c file) don't need any prefix
260+
(specifically: no `s_` or `_` prefix, and generally avoid adding the
261+
file-level common prefix).
262+
263+
## Integer types
264+
265+
MicroPython runs on 16, 32, and 64 bit machines, so it's important to use the
266+
correctly-sized (and signed) integer types. The general guidelines are:
267+
236268
- For most cases use mp_int_t for signed and mp_uint_t for unsigned
237269
integer values. These are guaranteed to be machine-word sized and
238270
therefore big enough to hold the value from a MicroPython small-int
@@ -241,11 +273,13 @@ general guidelines are:
241273
- You can use int/uint, but remember that they may be 16-bits wide.
242274
- If in doubt, use mp_int_t/mp_uint_t.
243275

244-
Comments:
276+
## Comments
277+
245278
- Be concise and only write comments for things that are not obvious.
246279
- Use `// ` prefix, NOT `/* ... */`. No extra fluff.
247280

248-
Memory allocation:
281+
## Memory allocation
282+
249283
- Use m_new, m_renew, m_del (and friends) to allocate and free heap memory.
250284
These macros are defined in py/misc.h.
251285

docs/esp32/quickref.rst

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Required keyword arguments for the constructor:
148148
- ``mdc`` and ``mdio`` - :class:`machine.Pin` objects (or integers) specifying
149149
the MDC and MDIO pins.
150150
- ``phy_type`` - Select the PHY device type. Supported devices are
151+
``PHY_GENERIC``,
151152
``PHY_LAN8710``, ``PHY_LAN8720``, ``PHY_IP101``, ``PHY_RTL8201``,
152153
``PHY_DP83848``, ``PHY_KSZ8041`` and ``PHY_KSZ8081``. These values are all
153154
constants defined in the ``network`` module.
@@ -383,7 +384,7 @@ for more details.
383384

384385
Use the :ref:`machine.PWM <machine.PWM>` class::
385386

386-
from machine import Pin, PWM
387+
from machine import Pin, PWM, lightsleep
387388

388389
pwm0 = PWM(Pin(0), freq=5000, duty_u16=32768) # create PWM object from a pin
389390
freq = pwm0.freq() # get current frequency
@@ -393,7 +394,7 @@ Use the :ref:`machine.PWM <machine.PWM>` class::
393394
pwm0.duty(256) # set duty cycle from 0 to 1023 as a ratio duty/1023, (now 25%)
394395

395396
duty_u16 = pwm0.duty_u16() # get current duty cycle, range 0-65535
396-
pwm0.duty_u16(2**16*3//4) # set duty cycle from 0 to 65535 as a ratio duty_u16/65535, (now 75%)
397+
pwm0.duty_u16(65536*3//4) # set duty cycle from 0 to 65535 as a ratio duty_u16/65535, (now 75%)
397398

398399
duty_ns = pwm0.duty_ns() # get current pulse width in ns
399400
pwm0.duty_ns(250_000) # set pulse width in nanoseconds from 0 to 1_000_000_000/freq, (now 25%)
@@ -402,19 +403,35 @@ Use the :ref:`machine.PWM <machine.PWM>` class::
402403

403404
pwm2 = PWM(Pin(2), freq=20000, duty=512) # create and configure in one go
404405
print(pwm2) # view PWM settings
406+
pwm2.deinit() # turn off PWM on the pin
407+
408+
pwm0 = PWM(Pin(0), duty_u16=16384) # The output is at a high level 25% of the time.
409+
pwm2 = PWM(Pin(2), duty_u16=16384, invert=1) # The output is at a low level 25% of the time.
410+
411+
pwm4 = PWM(Pin(4), lightsleep=True) # Allow PWM during light sleep mode
412+
413+
lightsleep(10*1000) # pwm0, pwm2 goes off, pwm4 stays on during 10s light sleep
414+
# pwm0, pwm2, pwm4 on after 10s light sleep
405415

406416
ESP chips have different hardware peripherals:
407417

408-
===================================================== ======== ======== ========
409-
Hardware specification ESP32 ESP32-S2 ESP32-C3
410-
----------------------------------------------------- -------- -------- --------
411-
Number of groups (speed modes) 2 1 1
412-
Number of timers per group 4 4 4
413-
Number of channels per group 8 8 6
414-
----------------------------------------------------- -------- -------- --------
415-
Different PWM frequencies (groups * timers) 8 4 4
416-
Total PWM channels (Pins, duties) (groups * channels) 16 8 6
417-
===================================================== ======== ======== ========
418+
======================================================= ======== ========= ==========
419+
Hardware specification ESP32 ESP32-S2, ESP32-C2,
420+
ESP32-S3, ESP32-C3,
421+
ESP32-P4 ESP32-C5,
422+
ESP32-C6,
423+
ESP32-H2
424+
------------------------------------------------------- -------- --------- ----------
425+
Number of groups (speed modes) 2 1 1
426+
Number of timers per group 4 4 4
427+
Number of channels per group 8 8 6
428+
------------------------------------------------------- -------- --------- ----------
429+
Different PWM frequencies = (groups * timers) 8 4 4
430+
Total PWM channels (Pins, duties) = (groups * channels) 16 8 6
431+
======================================================= ======== ========= ==========
432+
433+
In light sleep, the ESP32 PWM can only operate in low speed mode, so only 4 timers and
434+
8 channels are available.
418435

419436
A maximum number of PWM channels (Pins) are available on the ESP32 - 16 channels,
420437
but only 8 different PWM frequencies are available, the remaining 8 channels must

0 commit comments

Comments
 (0)