Skip to content

Commit 4bd2a4b

Browse files
update
1 parent 6215dcd commit 4bd2a4b

File tree

2,684 files changed

+363150
-3416
lines changed

Some content is hidden

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

2,684 files changed

+363150
-3416
lines changed

CODECONVENTIONS.md

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -206,65 +206,33 @@ 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-
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-
209+
White space:
216210
- Expand tabs to 4 spaces.
217211
- Don't leave trailing whitespace at the end of a line.
218212
- For control blocks (if, for, while), put 1 space between the
219213
keyword and the opening parenthesis.
220214
- Put 1 space after a comma, and 1 space around operators.
221215

222-
## Braces
223-
216+
Braces:
224217
- Use braces for all blocks, even no-line and single-line pieces of
225218
code.
226219
- Put opening braces on the end of the line it belongs to, not on
227220
a new line.
228221
- For else-statements, put the else on the same line as the previous
229222
closing brace.
230223

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

236-
## Names
237-
228+
Names:
238229
- Use underscore_case, not camelCase for all names.
239230
- Use CAPS_WITH_UNDERSCORE for enums and macros.
240231
- When defining a type use underscore_case and put '_t' after it.
241232

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-
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:
268236
- For most cases use mp_int_t for signed and mp_uint_t for unsigned
269237
integer values. These are guaranteed to be machine-word sized and
270238
therefore big enough to hold the value from a MicroPython small-int
@@ -273,13 +241,11 @@ correctly-sized (and signed) integer types. The general guidelines are:
273241
- You can use int/uint, but remember that they may be 16-bits wide.
274242
- If in doubt, use mp_int_t/mp_uint_t.
275243

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

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

docs/esp32/quickref.rst

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ 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``,
152151
``PHY_LAN8710``, ``PHY_LAN8720``, ``PHY_IP101``, ``PHY_RTL8201``,
153152
``PHY_DP83848``, ``PHY_KSZ8041`` and ``PHY_KSZ8081``. These values are all
154153
constants defined in the ``network`` module.
@@ -384,7 +383,7 @@ for more details.
384383

385384
Use the :ref:`machine.PWM <machine.PWM>` class::
386385

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

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

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

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

404403
pwm2 = PWM(Pin(2), freq=20000, duty=512) # create and configure in one go
405404
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
415405

416406
ESP chips have different hardware peripherals:
417407

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.
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+
===================================================== ======== ======== ========
435418

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

0 commit comments

Comments
 (0)