Wykres commitów

68 Commity (master)

Autor SHA1 Wiadomość Data
Damien George bfc3dde2c9 extmod/modmachine: Add MICROPY_PY_MACHINE_RESET configuration option.
Disabled by default, but enabled on all boards that previously had
`MICROPY_PY_MACHINE_BARE_METAL_FUNCS` enabled.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-15 12:04:37 +11:00
Angus Gratton 73879734d9 esp8266: Update port to use new event functions.
This is necessary to avoid watchdog timeout in long i2c.scan(), as
previously machine_i2c.c would call MICROPY_EVENT_POLL_HOOK if
MICROPY_EVENT_POLL_HOOK_FAST was not available.

Compared to previous implementation, this implementation removes the
ets_event_poll() function and calls the SDK function ets_loop_iter() from
MICROPY_INTERNAL_EVENT_HOOK instead.  This allows using the port-agnostic
functions in more places.

There is a small behaviour change, which is that the event loop gets
iterated in a few more places (i.e. anywhere that mp_event_handle_nowait()
is called).  However, this looks like maybe only modselect.c - and is
probably good to process Wi-Fi events in that polling loop.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-12-08 12:50:38 +11:00
Damien George ad806df857 ports: Move definitions of ATOMIC_SECTION macros to mphalport.h.
Also move MICROPY_PY_PENDSV_ENTER/REENTER/EXIT to mphalport.h, for ports
where these are not already there.

This helps separate the hardware implementation of these macros from the
MicroPython configuration (eg for renesas-ra and stm32, the IRQ static
inline helper functions can now be moved to irq.h).

Signed-off-by: Damien George <damien@micropython.org>
2023-12-01 14:37:48 +11:00
Damien George cc8fc450a6 esp8266/modmachine: Use common implementation of disable/enable_irq.
Now that the MICROPY_BEGIN_ATOMIC_SECTION/MICROPY_END_ATOMIC_SECTION macros
act the same as disable_irq/enable_irq, it's possible to use the common
extmod implementation of these machine functions.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 39d4153a8d esp8266/esp_mphal: Make atomic section more atomic.
By disabling ets_loop_iter when the atomic section is active.

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George e1ec6af654 extmod/modmachine: Provide common bindings for 6 bare-metal functions.
Minor changes for consistency are:
- nrf gains: unique_id(), freq() [they do nothing]
- samd: deepsleep() now resets after calling lightsleep()
- esp32: lightsleep()/deepsleep() no longer take kw arg "sleep", instead
  it's positional to match others.  also, passing 0 here will now do a 0ms
  sleep instead of acting like nothing was passed.
  reset_cause() no longer takes any args (before it would just ignore them)
- mimxrt: freq() with an argument and lightsleep() both raise
  NotImplementedError

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 7d39db2503 extmod/modmachine: Factor ports' machine module dict to common code.
This is a code factoring to have the dict for the machine module in one
location, and all the ports use that same dict.  The machine.soft_reset()
function implementation is also factored because it's the same for all
ports that did already implement it.  Eventually more functions/bindings
can be factored.

All ports remain functionally the same, except:
- cc3200 port: gains soft_reset, mem8, mem16, mem32, Signal; loses POWER_ON
  (which was a legacy constant, replaced long ago by PWRON_RESET)
- nrf port: gains Signal
- qemu-arm port: gains soft_reset
- unix port: gains soft_reset
- zephyr port: gains soft_reset, mem8, mem16, mem32

Signed-off-by: Damien George <damien@micropython.org>
2023-11-30 16:11:11 +11:00
Damien George 5b4a2baff6 extmod/machine_uart: Factor ports' UART Python bindings to common code.
This is a code factoring to have the Python bindings in one location, and
all the ports use those same bindings.  For all ports except the two listed
below there is no functional change.

The nrf port has UART.sendbreak() removed, but this method previously did
nothing.

The zephyr port has the following methods added:
- UART.init(): supports setting timeout and timeout_char.
- UART.deinit(): does nothing, just returns None.
- UART.flush(): raises OSError(EINVAL) because it's not implemented.
- UART.any() and UART.txdone(): raise NotImplementedError.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-26 10:46:42 +11:00
Damien George 95d8b5fd55 extmod/machine_adc: Factor ports' ADC Python bindings to common code.
No functional change, just code factoring to have the Python bindings in
one location, and all the ports use those same bindings.

Signed-off-by: Damien George <damien@micropython.org>
2023-10-23 17:16:45 +11:00
Damien George 60929ec7e2 extmod/machine_wdt: Factor ports' WDT Python bindings to common code.
There are currently 7 ports that implement machine.WDT and a lot of code is
duplicated across these implementations.  This commit factors the common
parts of all these implementations to a single location in
extmod/machine_wdt.c.  This common code provides the top-level Python
bindings (class and method wrappers), and then each port implements the
back end specific to that port.

With this refactor the ports remain functionally the same except for:

- The esp8266 WDT constructor now takes keyword arguments, and accepts the
  "timeout" argument but raises an exception if it's not the default value
  (this port doesn't support changing the timeout).

- The mimxrt and samd ports now interpret the argument to WDT.timeout_ms()
  as signed and if it's negative truncate it to the minimum timeout (rather
  than it being unsigned and a negative value truncating to the maximum
  timeout).

Signed-off-by: Damien George <damien@micropython.org>
2023-10-20 15:36:09 +11:00
Jim Mussared 7d2ee8aed0 py/mpconfig: Enable module delegation if sys needs it.
Otherwise you can get into the confusing state where e.g. sys.ps1 is
enabled in config (via `MICROPY_PY_SYS_PS1_PS2`) but still doesn't actually
get enabled.

Also verify that the required delegation options are enabled in modsys.c.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:24 +10:00
Jim Mussared 45ac651d1a all: Rename *umodule*.c to remove the "u" prefix.
Updates any includes, and references from Makefiles/CMake.

This essentially reverts what was done long ago in commit
136b5cbd76

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:17 +10:00
Jim Mussared f5f9edf645 all: Rename UMODULE to MODULE in preprocessor/Makefile vars.
This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08 17:54:11 +10:00
robert-hh 73cc6b750e ports: Enable os.sync() for esp32, esp8266, rp2, mimxrt, samd51.
These have by default FAT support.  The SAMD21 build does not support FAT.
The nrf port also implements os.sync(), but has it's own copy of moduos.c.

Code size increases seen: 40 to 56 bytes.

Signed-off-by: robert-hh <robert@hammelrath.com>
2023-06-01 11:39:01 +10:00
Damien George 38243cd8e0 extmod/machine_pwm: Remove PWM_INIT and PWM_DUTY_U16_NS config options.
All ports that enable MICROPY_PY_MACHINE_PWM now enable these two
sub-options, so remove these sub-options altogether to force consistency in
new ports that implement machine.PWM.

Signed-off-by: Damien George <damien@micropython.org>
2023-05-04 13:19:19 +10:00
robert-hh 2ac643c15b esp8266/machine_pwm: Implement duty_u16() and duty_ns() for consistency.
Also adds these keyword arguments to the constructor and init method.
2023-05-04 13:17:55 +10:00
Damien George 4a4046d825 esp8266/modutime: Use extmod version of time module.
No API or functional change.

Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 15:11:51 +10:00
Jim Mussared 6207b605ce esp8266: Use extmod/modnetwork.c instead of port-specific version.
Rather than duplicating the implementation of `network`, this allows
ESP8266 to use the shared one in extmod.  In particular this gains access
to network.hostname and network.country.

Other than adding these two methods, there is no other user-visible change.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-01 01:27:06 +11:00
Damien George 8f4c108025 all: Remove MICROPY_PY_IO_FILEIO config option.
Since commit e65d1e69e8 there is no longer an
io.FileIO class, so this option is no longer needed.

This option also controlled whether or not files supported being opened in
binary mode (eg 'rb'), and could, if disabled, lead to confusion as to why
opening a file in binary mode silently did the wrong thing (it would just
open in text mode if MICROPY_PY_IO_FILEIO was disabled).

The various VFS implementations (POSIX, FAT, LFS) were the only places
where enabling this option made a difference, and in almost all cases where
one of these filesystems were enabled, MICROPY_PY_IO_FILEIO was also
enabled.  So it makes sense to just unconditionally enable this feature
(ability to open a file in binary mode) in all cases, and so just remove
this config option altogether.  That makes configuration simpler and means
binary file support always exists (and opening a file in binary mode is
arguably more fundamental than opening in text mode, so if anything should
be configurable then it should be the ability to open in text mode).

Signed-off-by: Damien George <damien@micropython.org>
2022-08-18 11:54:17 +10:00
Jim Mussared 092784da19 ports: Remove unused mp_type_{fileio/textio} macros in mpconfigport.h.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-07-26 18:07:22 +10:00
David Lechner e2d4db96da esp8266: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register all port-specific root
pointers in the esp2866 port.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:50:34 +10:00
David Lechner 81dbea1ce3 shared/readline: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register the readline_history root
pointer array used by shared/readline.c and removes the registration from
all mpconfigport.h files.

This also required adding a new MICROPY_READLINE_HISTORY_SIZE config option
since not all ports used the same sized array.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:48:49 +10:00
Damien George 9f8087b448 esp8266/boards: Enable reverse-special-methods on GENERIC board.
It increases the firmware size by 292 bytes.

Addresses issue #5897.

Signed-off-by: Damien George <damien@micropython.org>
2022-07-08 23:06:16 +10:00
Damien George 226b2d77ee esp8266/mpconfigport: Disable MICROPY_PY_UTIMEQ.
This is no longer needed with new uasyncio v3, and disabling it saves 900
bytes.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-23 13:07:54 +10:00
Damien George ad7b98c829 esp8266/mpconfigport: Switch to ROM feature level configuration.
This is a no-op in terms of board configuration.

Signed-off-by: Damien George <damien@micropython.org>
2022-06-23 13:07:39 +10:00
Damien George 6e71cde6aa ports: Use default VFS config for import_stat and builtin_open.
For ports with MICROPY_VFS and MICROPY_PY_IO enabled their configuration
can now be simplified to use the defaults for mp_import_stat and
mp_builtin_open.

This commit makes no functional change, except for the following minor
points:
- the built-in "open" is removed from the minimal port (it previously did
  nothing)
- the duplicate built-in "input" is removed from the esp32 port
- qemu-arm now delegates to VFS import/open

Signed-off-by: Damien George <damien@micropython.org>
2022-05-25 13:04:45 +10:00
Jim Mussared 4274b34d6b esp8266: Make port-specific modules use MP_REGISTER_MODULE.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-18 20:56:30 +10:00
Jim Mussared bb794f05b7 extmod: Make port-included extmod modules use MP_REGISTER_MODULES.
_onewire, socket, and network were previously added by the port rather
than objmodule.c.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-05-18 20:49:12 +10:00
Damien George 65be5e072f esp8266/mpconfigport.h: Remove config values that are the defaults.
This commit is a no-op in terms of functionality.

Signed-off-by: Damien George <damien@micropython.org>
2022-03-22 11:03:15 +11:00
Damien George ade2720e55 esp8266/moduos: Convert module to use extmod version.
Signed-off-by: Damien George <damien@micropython.org>
2022-03-09 10:03:23 +11:00
Damien George fbd47fc46c ports: Consolidate inclusion of umachine module in built-ins.
The inclusion of `umachine` in the list of built-in modules is now done
centrally in py/objmodule.c.  Enabling MICROPY_PY_MACHINE will include this
module.

As part of this, all ports now have `umachine` as the core module name
(previously some had only `machine` as the name).

Signed-off-by: Damien George <damien@micropython.org>
2022-02-03 10:08:54 +11:00
Damien George af64c2ddbd extmod/machine_pwm: Factor out machine.PWM bindings to common code.
This commit refactors machine.PWM and creates extmod/machine_pwm.c.  The
esp8266, esp32 and rp2 ports all use this and provide implementations of
the required PWM functionality.  This helps to reduce code duplication and
keep the same Python API across ports.

This commit does not make any functional changes.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-04 16:31:17 +10:00
Damien George d41f6dde56 extmod/modonewire: Make _onewire module configurable via macro option.
Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Damien George afe0634c98 extmod/machine_spi: Make SoftSPI configurable via macro option.
Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Damien George 122d901ef1 extmod/machine_i2c: Make SoftI2C configurable via macro option.
The zephyr port doesn't support SoftI2C so it's not enabled, and the legacy
I2C constructor check can be removed.

Signed-off-by: Damien George <damien@micropython.org>
2021-09-02 13:11:23 +10:00
Jim Mussared 39e9c0788f esp8266: Replace esp.neopixel with machine.bitstream.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-19 22:50:32 +10:00
Roberto Colistete Jr b099db4426 esp8266/Makefile: Add more libm files to build.
Allows MICROPY_PY_MATH_SPECIAL_FUNCTIONS to be enabled, and for ulab to be
built as a user C module.
2021-07-22 23:55:31 +10:00
Damien George e9e9c76ddf all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt.
To match mp_sched_exception() and mp_sched_schedule().

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:13:43 +10:00
Damien George 7cbf826a95 py/scheduler: Add mp_sched_exception() to schedule a pending exception.
This helper is added to properly set a pending exception, to mirror
mp_sched_schedule(), which schedules a function.

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:13:43 +10:00
Damien George 7c44354592 ports: Remove def of MP_PLAT_PRINT_STRN if it's the same as the default.
To simplify config, there's no need to specify MP_PLAT_PRINT_STRN if it's
the same as the default definition in py/mpconfig.h.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-04 22:39:17 +11:00
robert 057193e855 esp8266/mpconfigport.h: Seed the urandom module on import.
For seeding, the hardware RNG of the esp8266 is used.
2020-10-29 14:12:44 +11:00
Damien George 9e0533b9e1 extmod/machine_spi: Remove "id" arg in SoftSPI constructor.
The SoftSPI constructor is now used soley to create SoftSPI instances, it
can no longer delegate to create a hardware-based SPI instance.

Signed-off-by: Damien George <damien@micropython.org>
2020-10-01 12:57:10 +10:00
Damien George 419d1aa617 esp8266/mpconfigport.h: Add definitions for BEGIN/END_ATOMIC_SECTION.
These are needed to ensure correct operation of the MicroPython scheduler.
2020-04-30 23:47:11 +10:00
Damien George 0bd58a5613 esp8266/machine_pin: Move pin_intr_handler to iRAM, de-support hard IRQ.
GPIO interrupts can occur when the flash ROM cache is in use and so the
GPIO interrupt handler must be in iRAM.  This commit moves the handler to
iRAM, and also moves mp_sched_schedule to iRAM which is called by
pin_intr_handler.

As part of this fix the Pin class can no longer support hard=True in the
Pin.irq() method, because the VM and runtime are too big to put in iRAM.

Fixes #5714.
2020-04-30 23:47:11 +10:00
Damien George 69661f3343 all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28 10:33:03 +11:00
Damien George 8d0421c3cf esp8266: Put mp_keyboard_interrupt in IRAM.
It was originally in IRAM due to the linker script specification, but
since the function moved from lib/utils/interrupt_char.c to py/scheduler.c
it needs to be put back in IRAM.
2020-02-07 16:08:31 +11:00
Damien George b47e155bd0 py/persistentcode: Add ability to relocate loaded native code.
Implements text, rodata and bss generalised relocations, as well as generic
qstr-object linking.  This allows importing dynamic native modules on all
supported architectures in a unified way.
2019-12-12 20:15:28 +11:00
Damien George cea9209e0f esp8266/moduos: Add optional support for VfsLfs1 and VfsLfs2.
With this commit an esp8266-based board can now be built with littlefs
support via, eg "make MICROPY_VFS_LFS2=1".
2019-11-07 18:44:16 +11:00
Damien George d2384efa80 py: Automatically provide weak links from "foo" to "ufoo" module name.
This commit implements automatic module weak links for all built-in
modules, by searching for "ufoo" in the built-in module list if "foo"
cannot be found.  This means that all modules named "ufoo" are always
available as "foo".  Also, a port can no longer add any other weak links,
which makes strict the definition of a weak link.

It saves some code size (about 100-200 bytes) on ports that previously had
lots of weak links.

Some changes from the previous behaviour:
- It doesn't intern the non-u module names (eg "foo" is not interned),
  which saves code size, but will mean that "import foo" creates a new qstr
  (namely "foo") in RAM (unless the importing module is frozen).
- help('modules') no longer lists non-u module names, only the u-variants;
  this reduces duplication in the help listing.

Weak links are effectively the same as having a set of symbolic links on
the filesystem that is searched last.  So an "import foo" will search
built-in modules first, then all paths in sys.path, then weak links last,
importing "ufoo" if it exists.  Thus a file called "foo.py" somewhere in
sys.path will still have precedence over the weak link of "foo" to "ufoo".

See issues: #1740, #4449, #5229, #5241.
2019-10-22 15:30:52 +11:00
Jim Mussared df7f632fd7 esp8266: Allow building without a manifest. 2019-10-21 23:21:14 +11:00