Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
f904497e1f
|
@ -24,3 +24,5 @@ numer
|
|||
arithmetics
|
||||
ftbfs
|
||||
straightaway
|
||||
ftbs
|
||||
ftb
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#all: Reformat remaining C code that doesn't have a space after a comma.
|
||||
# top: Update Python formatting to black "2023 stable style".
|
||||
8b2748269244304854b3462cb8902952b4dcb892
|
||||
|
||||
# all: Reformat remaining C code that doesn't have a space after a comma.
|
||||
5b700b0af90591d6b1a2c087bb8de6b7f1bfdd2d
|
||||
|
||||
# ports: Reformat more C and Python source code.
|
||||
|
|
|
@ -5,6 +5,9 @@ inputs:
|
|||
required: false
|
||||
default: true
|
||||
type: boolean
|
||||
cp-version:
|
||||
required: true
|
||||
type: string
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
|
@ -16,17 +19,19 @@ runs:
|
|||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: mpy-cross
|
||||
path: mpy-cross
|
||||
path: mpy-cross/build
|
||||
|
||||
- name: Make mpy-cross executable
|
||||
if: inputs.download == 'true' && steps.download-mpy-cross.outcome == 'success'
|
||||
run: sudo chmod +x mpy-cross/mpy-cross
|
||||
run: sudo chmod +x mpy-cross/build/mpy-cross
|
||||
shell: bash
|
||||
|
||||
- name: Build mpy-cross
|
||||
if: inputs.download == 'false' || steps.download-mpy-cross.outcome == 'failure'
|
||||
run: make -C mpy-cross -j2
|
||||
shell: bash
|
||||
env:
|
||||
CP_VERSION: ${{ inputs.cp-version }}
|
||||
|
||||
- name: Upload mpy-cross
|
||||
if: inputs.download == 'false' || steps.download-mpy-cross.outcome == 'failure'
|
||||
|
@ -34,4 +39,4 @@ runs:
|
|||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: mpy-cross
|
||||
path: mpy-cross/mpy-cross
|
||||
path: mpy-cross/build/mpy-cross
|
||||
|
|
|
@ -49,6 +49,8 @@ jobs:
|
|||
- name: Set up mpy-cross
|
||||
if: steps.set-up-submodules.outputs.frozen == 'True'
|
||||
uses: ./.github/actions/mpy_cross
|
||||
with:
|
||||
cp-version: ${{ inputs.cp-version }}
|
||||
|
||||
- name: Versions
|
||||
run: |
|
||||
|
|
|
@ -64,11 +64,11 @@ jobs:
|
|||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: mpy-cross.${{ env.EX }}
|
||||
path: mpy-cross/mpy-cross.${{ env.EX }}
|
||||
path: mpy-cross/build-${{ env.EX}}/mpy-cross.${{ env.EX }}
|
||||
- name: Upload to S3
|
||||
uses: ./.github/actions/upload_aws
|
||||
with:
|
||||
source: mpy-cross/mpy-cross.${{ env.EX }}
|
||||
source: mpy-cross/build-${{ env.EX}}/mpy-cross.${{ env.EX }}
|
||||
destination: mpy-cross/${{ env.OS }}/mpy-cross-${{ env.OS }}-${{ env.CP_VERSION }}.${{ env.EX }}
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
|
|
|
@ -51,6 +51,7 @@ jobs:
|
|||
- name: Set up mpy-cross
|
||||
uses: ./.github/actions/mpy_cross
|
||||
with:
|
||||
cp-version: ${{ steps.set-up-submodules.outputs.version }}
|
||||
download: false
|
||||
- name: Get last commit with checks
|
||||
id: get-last-commit-with-checks
|
||||
|
@ -127,15 +128,15 @@ jobs:
|
|||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: mpy-cross-macos-11-x64
|
||||
path: mpy-cross/mpy-cross
|
||||
path: mpy-cross/build/mpy-cross
|
||||
- name: Build mpy-cross (arm64)
|
||||
run: make -C mpy-cross -j2 -f Makefile.m1 V=2
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: mpy-cross-macos-11-arm64
|
||||
path: mpy-cross/mpy-cross-arm64
|
||||
path: mpy-cross/build-arm64/mpy-cross-arm64
|
||||
- name: Make universal binary
|
||||
run: lipo -create -output mpy-cross-macos-universal mpy-cross/mpy-cross mpy-cross/mpy-cross-arm64
|
||||
run: lipo -create -output mpy-cross-macos-universal mpy-cross/build/mpy-cross mpy-cross/build-arm64/mpy-cross-arm64
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
|
|
|
@ -65,6 +65,7 @@ jobs:
|
|||
if: steps.set-up-submodules.outputs.frozen == 'True'
|
||||
uses: ./.github/actions/mpy_cross
|
||||
with:
|
||||
cp-version: ${{ steps.set-up-submodules.outputs.version }}
|
||||
download: false
|
||||
- name: Versions
|
||||
run: |
|
||||
|
|
|
@ -17,7 +17,7 @@ jobs:
|
|||
env:
|
||||
CP_VERSION: ${{ inputs.cp-version }}
|
||||
MICROPY_CPYTHON3: python3.8
|
||||
MICROPY_MICROPYTHON: ../ports/unix/micropython-coverage
|
||||
MICROPY_MICROPYTHON: ../ports/unix/build-coverage/micropython
|
||||
TEST_all:
|
||||
TEST_mpy: --via-mpy -d basics float micropython
|
||||
TEST_native: --emit native
|
||||
|
@ -41,6 +41,8 @@ jobs:
|
|||
uses: ./.github/actions/deps/external
|
||||
- name: Set up mpy-cross
|
||||
uses: ./.github/actions/mpy_cross
|
||||
with:
|
||||
cp-version: ${{ inputs.cp-version }}
|
||||
- name: Build unix port
|
||||
run: make -C ports/unix VARIANT=coverage -j2
|
||||
- name: Run tests
|
||||
|
|
|
@ -345,6 +345,9 @@
|
|||
path = ports/raspberrypi/lib/Pico-PIO-USB
|
||||
url = https://github.com/sekigon-gonnoc/Pico-PIO-USB.git
|
||||
branch = main
|
||||
[submodule "lib/micropython-lib"]
|
||||
path = lib/micropython-lib
|
||||
url = https://github.com/micropython/micropython-lib.git
|
||||
[submodule "lib/certificates"]
|
||||
path = lib/certificates
|
||||
url = https://github.com/adafruit/certificates
|
||||
|
|
|
@ -19,7 +19,10 @@ repos:
|
|||
exclude: |
|
||||
(?x)^(
|
||||
locale/|
|
||||
lib/
|
||||
lib/|
|
||||
tests/unicode/data/utf-8_invalid.txt|
|
||||
tests/extmod/data/qr.pgm|
|
||||
tests/basics/bytearray_byte_operations.py
|
||||
)
|
||||
- repo: local
|
||||
hooks:
|
||||
|
|
8
LICENSE
8
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2022 Damien P. George and others
|
||||
Copyright (c) 2013-2023 Damien P. George
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -9,8 +9,8 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
|
|
3
conf.py
3
conf.py
|
@ -202,7 +202,8 @@ exclude_patterns = ["**/build*",
|
|||
"ports/cxd56/spresense-exported-sdk",
|
||||
"ports/espressif/certificates",
|
||||
"ports/espressif/esp-idf",
|
||||
"ports/espressif/esp32-camera",
|
||||
"ports/espressif/esp-camera",
|
||||
"ports/espressif/esp-protocols",
|
||||
"ports/espressif/.idf_tools",
|
||||
"ports/espressif/peripherals",
|
||||
"ports/litex/hw",
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "shared-bindings/_bleio/Service.h"
|
||||
#include "shared-bindings/_bleio/UUID.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
STATIC uint16_t max_mtu = BT_ATT_DEFAULT_LE_MTU; // 23
|
||||
STATIC unsigned long timeout = 5000;
|
||||
|
|
|
@ -33,7 +33,6 @@ Full Table of Contents
|
|||
design_guide
|
||||
porting
|
||||
common_hal
|
||||
reference/mpyfiles.rst
|
||||
reference/glossary.rst
|
||||
|
||||
.. toctree::
|
||||
|
|
|
@ -27,3 +27,55 @@ Classes
|
|||
|
||||
Append new elements as contained in `iterable` to the end of
|
||||
array, growing it.
|
||||
|
||||
.. method:: __getitem__(index)
|
||||
|
||||
Indexed read of the array, called as ``a[index]`` (where ``a`` is an ``array``).
|
||||
Returns a value if *index* is an ``int`` and an ``array`` if *index* is a slice.
|
||||
Negative indices count from the end and ``IndexError`` is thrown if the index is
|
||||
out of range.
|
||||
|
||||
**Note:** ``__getitem__`` cannot be called directly (``a.__getitem__(index)`` fails) and
|
||||
is not present in ``__dict__``, however ``a[index]`` does work.
|
||||
|
||||
.. method:: __setitem__(index, value)
|
||||
|
||||
Indexed write into the array, called as ``a[index] = value`` (where ``a`` is an ``array``).
|
||||
``value`` is a single value if *index* is an ``int`` and an ``array`` if *index* is a slice.
|
||||
Negative indices count from the end and ``IndexError`` is thrown if the index is out of range.
|
||||
|
||||
**Note:** ``__setitem__`` cannot be called directly (``a.__setitem__(index, value)`` fails) and
|
||||
is not present in ``__dict__``, however ``a[index] = value`` does work.
|
||||
|
||||
.. method:: __len__()
|
||||
|
||||
Returns the number of items in the array, called as ``len(a)`` (where ``a`` is an ``array``).
|
||||
|
||||
**Note:** ``__len__`` cannot be called directly (``a.__len__()`` fails) and the
|
||||
method is not present in ``__dict__``, however ``len(a)`` does work.
|
||||
|
||||
.. method:: __add__(other)
|
||||
|
||||
Return a new ``array`` that is the concatenation of the array with *other*, called as
|
||||
``a + other`` (where ``a`` and *other* are both ``arrays``).
|
||||
|
||||
**Note:** ``__add__`` cannot be called directly (``a.__add__(other)`` fails) and
|
||||
is not present in ``__dict__``, however ``a + other`` does work.
|
||||
|
||||
.. method:: __iadd__(other)
|
||||
|
||||
Concatenates the array with *other* in-place, called as ``a += other`` (where ``a`` and *other*
|
||||
are both ``arrays``). Equivalent to ``extend(other)``.
|
||||
|
||||
**Note:** ``__iadd__`` cannot be called directly (``a.__iadd__(other)`` fails) and
|
||||
is not present in ``__dict__``, however ``a += other`` does work.
|
||||
|
||||
.. method:: __repr__()
|
||||
|
||||
Returns the string representation of the array, called as ``str(a)`` or ``repr(a)```
|
||||
(where ``a`` is an ``array``). Returns the string ``"array(<type>, [<elements>])"``,
|
||||
where ``<type>`` is the type code letter for the array and ``<elements>`` is a comma
|
||||
separated list of the elements of the array.
|
||||
|
||||
**Note:** ``__repr__`` cannot be called directly (``a.__repr__()`` fails) and
|
||||
is not present in ``__dict__``, however ``str(a)`` and ``repr(a)`` both work.
|
||||
|
|
|
@ -52,7 +52,7 @@ Glossary
|
|||
cross-compiler
|
||||
Also known as ``mpy-cross``. This tool runs on your PC and converts a
|
||||
:term:`.py file` containing MicroPython code into a :term:`.mpy file`
|
||||
containing MicroPython bytecode. This means it loads faster (the board
|
||||
containing MicroPython :term:`bytecode`. This means it loads faster (the board
|
||||
doesn't have to compile the code), and uses less space on flash (the
|
||||
bytecode is more space efficient).
|
||||
|
||||
|
@ -112,6 +112,24 @@ Glossary
|
|||
require much less power. MicroPython is designed to be small and
|
||||
optimized enough to run on an average modern microcontroller.
|
||||
|
||||
micropython-lib
|
||||
MicroPython is (usually) distributed as a single executable/binary
|
||||
file with just few builtin modules. There is no extensive standard
|
||||
library comparable with :term:`CPython`'s. Instead, there is a related,
|
||||
but separate project `micropython-lib
|
||||
<https://github.com/micropython/micropython-lib>`_ which provides
|
||||
implementations for many modules from CPython's standard library.
|
||||
|
||||
Some of the modules are are implemented in pure Python, and are able to
|
||||
be used on all ports. However, the majority of these modules use
|
||||
:term:`FFI` to access operating system functionality, and as such can
|
||||
only be used on the :term:`MicroPython Unix port` (with limited support
|
||||
for Windows).
|
||||
|
||||
Unlike the :term:`CPython` stdlib, micropython-lib modules are
|
||||
intended to be installed individually - either using manual copying or
|
||||
using :term:`mip`.
|
||||
|
||||
MicroPython port
|
||||
MicroPython supports different :term:`boards <board>`, RTOSes, and
|
||||
OSes, and can be relatively easily adapted to new systems. MicroPython
|
||||
|
@ -133,16 +151,26 @@ Glossary
|
|||
machine-independent features. It can also function in a similar way to
|
||||
:term:`CPython`'s ``python`` executable.
|
||||
|
||||
mip
|
||||
A package installer for MicroPython (mip - "mip installs packages"). It
|
||||
installs MicroPython packages either from :term:`micropython-lib`,
|
||||
GitHub, or arbitrary URLs. mip can be used on-device on
|
||||
network-capable boards, and internally by tools such
|
||||
as :term:`mpremote`.
|
||||
|
||||
mpremote
|
||||
A tool for interacting with a MicroPython device.
|
||||
|
||||
.mpy file
|
||||
The output of the :term:`cross-compiler`. A compiled form of a
|
||||
:term:`.py file` that contains MicroPython bytecode instead of Python
|
||||
source code.
|
||||
:term:`.py file` that contains MicroPython :term:`bytecode` instead of
|
||||
Python source code.
|
||||
|
||||
native
|
||||
Usually refers to "native code", i.e. machine code for the target
|
||||
microcontroller (such as ARM Thumb, Xtensa, x86/x64). The ``@native``
|
||||
decorator can be applied to a MicroPython function to generate native
|
||||
code instead of bytecode for that function, which will likely be
|
||||
code instead of :term:`bytecode` for that function, which will likely be
|
||||
faster but use more RAM.
|
||||
|
||||
port
|
||||
|
@ -173,3 +201,12 @@ Glossary
|
|||
peripheral that sends data over a pair of pins (TX & RX). Many boards
|
||||
include a way to make at least one of the UARTs available to a host PC
|
||||
as a serial port over USB.
|
||||
|
||||
upip
|
||||
A now-obsolete package manager for MicroPython, inspired
|
||||
by :term:`CPython`'s pip, but much smaller and with reduced
|
||||
functionality. See its replacement, :term:`mip`.
|
||||
|
||||
webrepl
|
||||
A way of connecting to the REPL (and transferring files) on a device
|
||||
over the internet from a browser. See https://micropython.org/webrepl
|
||||
|
|
|
@ -1,199 +0,0 @@
|
|||
.. _mpy_files:
|
||||
|
||||
MicroPython .mpy files
|
||||
======================
|
||||
|
||||
MicroPython defines the concept of an .mpy file which is a binary container
|
||||
file format that holds precompiled code, and which can be imported like a
|
||||
normal .py module. The file ``foo.mpy`` can be imported via ``import foo``,
|
||||
as long as ``foo.mpy`` can be found in the usual way by the import machinery.
|
||||
Usually, each directory listed in ``sys.path`` is searched in order. When
|
||||
searching a particular directory ``foo.py`` is looked for first and if that
|
||||
is not found then ``foo.mpy`` is looked for, then the search continues in the
|
||||
next directory if neither is found. As such, ``foo.py`` will take precedence
|
||||
over ``foo.mpy``.
|
||||
|
||||
These .mpy files can contain bytecode which is usually generated from Python
|
||||
source files (.py files) via the ``mpy-cross`` program. For some architectures
|
||||
an .mpy file can also contain native machine code, which can be generated in
|
||||
a variety of ways, most notably from C source code.
|
||||
|
||||
Versioning and compatibility of .mpy files
|
||||
------------------------------------------
|
||||
|
||||
A given .mpy file may or may not be compatible with a given MicroPython system.
|
||||
Compatibility is based on the following:
|
||||
|
||||
* Version of the .mpy file: the version of the file must match the version
|
||||
supported by the system loading it.
|
||||
|
||||
* Sub-version of the .mpy file: if the .mpy file contains native machine code
|
||||
then the sub-version of the file must match the version support by the
|
||||
system loading it. Otherwise, if there is no native machine code in the .mpy
|
||||
file, then the sub-version is ignored when loading.
|
||||
|
||||
* Small integer bits: the .mpy file will require a minimum number of bits in
|
||||
a small integer and the system loading it must support at least this many
|
||||
bits.
|
||||
|
||||
* Native architecture: if the .mpy file contains native machine code then
|
||||
it will specify the architecture of that machine code and the system
|
||||
loading it must support execution of that architecture's code.
|
||||
|
||||
If a MicroPython system supports importing .mpy files then the
|
||||
``sys.implementation._mpy`` field will exist and return an integer which
|
||||
encodes the version (lower 8 bits), features and native architecture.
|
||||
|
||||
Trying to import an .mpy file that fails one of the first four tests will
|
||||
raise ``ValueError('incompatible .mpy file')``. Trying to import an .mpy
|
||||
file that fails the native architecture test (if it contains native machine
|
||||
code) will raise ``ValueError('incompatible .mpy arch')``.
|
||||
|
||||
If importing an .mpy file fails then try the following:
|
||||
|
||||
* Determine the .mpy version and flags supported by your MicroPython system
|
||||
by executing::
|
||||
|
||||
import sys
|
||||
sys_mpy = sys.implementation._mpy
|
||||
arch = [None, 'x86', 'x64',
|
||||
'armv6', 'armv6m', 'armv7m', 'armv7em', 'armv7emsp', 'armv7emdp',
|
||||
'xtensa', 'xtensawin'][sys_mpy >> 10]
|
||||
print('mpy version:', sys_mpy & 0xff)
|
||||
print('mpy flags:', end='')
|
||||
if arch:
|
||||
print(' -march=' + arch, end='')
|
||||
print()
|
||||
|
||||
* Check the validity of the .mpy file by inspecting the first two bytes of
|
||||
the file. The first byte should be an uppercase 'C' and the second byte
|
||||
will be the version number, which should match the system version from above.
|
||||
If it doesn't match then rebuild the .mpy file.
|
||||
|
||||
* Check if the system .mpy version matches the version emitted by ``mpy-cross``
|
||||
that was used to build the .mpy file, found by ``mpy-cross --version``.
|
||||
If it doesn't match then recompile ``mpy-cross`` from the Git repository
|
||||
checked out at the tag (or hash) reported by ``mpy-cross --version``.
|
||||
|
||||
* Make sure you are using the correct ``mpy-cross`` flags, found by the code
|
||||
above, or by inspecting the ``MPY_CROSS_FLAGS`` Makefile variable for the
|
||||
port that you are using.
|
||||
|
||||
The following table shows the correspondence between MicroPython release
|
||||
and .mpy version.
|
||||
|
||||
=================== ============
|
||||
MicroPython release .mpy version
|
||||
=================== ============
|
||||
v1.19 and up 6
|
||||
v1.12 - v1.18 5
|
||||
v1.11 4
|
||||
v1.9.3 - v1.10 3
|
||||
v1.9 - v1.9.2 2
|
||||
v1.5.1 - v1.8.7 0
|
||||
=================== ============
|
||||
|
||||
For completeness, the next table shows the Git commit of the main
|
||||
MicroPython repository at which the .mpy version was changed.
|
||||
|
||||
=================== ========================================
|
||||
.mpy version change Git commit
|
||||
=================== ========================================
|
||||
5 to 6 f2040bfc7ee033e48acef9f289790f3b4e6b74e5
|
||||
4 to 5 5716c5cf65e9b2cb46c2906f40302401bdd27517
|
||||
3 to 4 9a5f92ea72754c01cc03e5efcdfe94021120531e
|
||||
2 to 3 ff93fd4f50321c6190e1659b19e64fef3045a484
|
||||
1 to 2 dd11af209d226b7d18d5148b239662e30ed60bad
|
||||
0 to 1 6a11048af1d01c78bdacddadd1b72dc7ba7c6478
|
||||
initial version 0 d8c834c95d506db979ec871417de90b7951edc30
|
||||
=================== ========================================
|
||||
|
||||
Binary encoding of .mpy files
|
||||
-----------------------------
|
||||
|
||||
MicroPython .mpy files are a binary container format with code objects (bytecode
|
||||
and native machine code) stored internally in a nested hierarchy. The code for
|
||||
the outer module is stored first, and then its children follow. Each child may
|
||||
have further children, for example in the case of a class having methods, or a
|
||||
function defining a lambda or comprehension. To keep files small while still
|
||||
providing a large range of possible values it uses the concept of a
|
||||
variably-encoded-unsigned-integer (vuint) in many places. Similar to utf-8
|
||||
encoding, this encoding stores 7 bits per byte with the 8th bit (MSB) set
|
||||
if one or more bytes follow. The bits of the unsigned integer are stored
|
||||
in the vuint in LSB form.
|
||||
|
||||
The top-level of an .mpy file consists of three parts:
|
||||
|
||||
* The header.
|
||||
|
||||
* The global qstr and constant tables.
|
||||
|
||||
* The raw-code for the outer scope of the module.
|
||||
This outer scope is executed when the .mpy file is imported.
|
||||
|
||||
You can inspect the contents of a .mpy file by using ``mpy-tool.py``, for
|
||||
example (run from the root of the main MicroPython repository)::
|
||||
|
||||
$ ./tools/mpy-tool.py -xd myfile.mpy
|
||||
|
||||
The header
|
||||
~~~~~~~~~~
|
||||
|
||||
The .mpy header is:
|
||||
|
||||
====== ================================
|
||||
size field
|
||||
====== ================================
|
||||
byte value 0x43 (ASCII 'C')
|
||||
byte .mpy version number
|
||||
byte feature flags
|
||||
byte number of bits in a small int
|
||||
====== ================================
|
||||
|
||||
The global qstr and constant tables
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
An .mpy file contains a single qstr table, and a single constant object table.
|
||||
These are global to the .mpy file, they are referenced by all nested raw-code
|
||||
objects. The qstr table maps internal qstr number (internal to the .mpy file)
|
||||
to the resolved qstr number of the runtime that the .mpy file is imported into.
|
||||
This links the .mpy file with the rest of the system that it executes within.
|
||||
The constant object table is populated with references to all constant objects
|
||||
that the .mpy file needs.
|
||||
|
||||
====== ================================
|
||||
size field
|
||||
====== ================================
|
||||
vuint number of qstrs
|
||||
vuint number of constant objects
|
||||
... qstr data
|
||||
... encoded constant objects
|
||||
====== ================================
|
||||
|
||||
Raw code elements
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
A raw-code element contains code, either bytecode or native machine code. Its
|
||||
contents are:
|
||||
|
||||
====== ================================
|
||||
size field
|
||||
====== ================================
|
||||
vuint type, size and whether there are sub-raw-code elements
|
||||
... code (bytecode or machine code)
|
||||
vuint number of sub-raw-code elements (only if non-zero)
|
||||
... sub-raw-code elements
|
||||
====== ================================
|
||||
|
||||
The first vuint in a raw-code element encodes the type of code stored in this
|
||||
element (the two least-significant bits), whether this raw-code has any
|
||||
children (the third least-significant bit), and the length of the code that
|
||||
follows (the amount of RAM to allocate for it).
|
||||
|
||||
Following the vuint comes the code itself. Unless the code type is viper code
|
||||
with relocations, this code is constant data and does not need to be modified.
|
||||
|
||||
If this raw-code has any children (as indicated by a bit in the first vuint),
|
||||
following the code comes a vuint counting the number of sub-raw-code elements.
|
||||
|
||||
Finally any sub-raw-code elements are stored, recursively.
|
|
@ -0,0 +1,5 @@
|
|||
/* Workaround to force Sphinx to render tables to 100% and wordwrap */
|
||||
/* See https://stackoverflow.com/questions/69359978/grid-table-does-not-word-wrap for more details */
|
||||
.wy-table-responsive table td, .wy-table-responsive table th {
|
||||
white-space: inherit;
|
||||
}
|
|
@ -32,8 +32,8 @@ void *memmove(void *dest, const void *src, size_t n) {
|
|||
return mp_fun_table.memmove_(dest, src, n);
|
||||
}
|
||||
|
||||
mp_obj_type_t match_type;
|
||||
mp_obj_type_t re_type;
|
||||
mp_obj_full_type_t match_type;
|
||||
mp_obj_full_type_t re_type;
|
||||
|
||||
#include "extmod/modure.c"
|
||||
|
||||
|
@ -54,21 +54,21 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a
|
|||
|
||||
match_type.base.type = (void*)&mp_fun_table.type_type;
|
||||
match_type.name = MP_QSTR_match;
|
||||
match_type.print = match_print;
|
||||
MP_OBJ_TYPE_SET_SLOT(&match_type, print, match_print, 0);
|
||||
match_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_group), MP_OBJ_FROM_PTR(&match_group_obj) };
|
||||
match_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_groups), MP_OBJ_FROM_PTR(&match_groups_obj) };
|
||||
match_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_span), MP_OBJ_FROM_PTR(&match_span_obj) };
|
||||
match_locals_dict_table[3] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_start), MP_OBJ_FROM_PTR(&match_start_obj) };
|
||||
match_locals_dict_table[4] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_end), MP_OBJ_FROM_PTR(&match_end_obj) };
|
||||
match_type.locals_dict = (void*)&match_locals_dict;
|
||||
MP_OBJ_TYPE_SET_SLOT(&match_type, locals_dict, (void*)&match_locals_dict, 1);
|
||||
|
||||
re_type.base.type = (void*)&mp_fun_table.type_type;
|
||||
re_type.name = MP_QSTR_ure;
|
||||
re_type.print = re_print;
|
||||
MP_OBJ_TYPE_SET_SLOT(&re_type, print, re_print, 0);
|
||||
re_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_match), MP_OBJ_FROM_PTR(&re_match_obj) };
|
||||
re_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_search), MP_OBJ_FROM_PTR(&re_search_obj) };
|
||||
re_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_split), MP_OBJ_FROM_PTR(&re_split_obj) };
|
||||
re_type.locals_dict = (void*)&re_locals_dict;
|
||||
MP_OBJ_TYPE_SET_SLOT(&re_type, locals_dict, (void*)&re_locals_dict, 1);
|
||||
|
||||
mp_store_global(MP_QSTR_compile, MP_OBJ_FROM_PTR(&mod_re_compile_obj));
|
||||
mp_store_global(MP_QSTR_match, MP_OBJ_FROM_PTR(&re_match_obj));
|
||||
|
|
|
@ -9,7 +9,6 @@ void *memset(void *s, int c, size_t n) {
|
|||
#endif
|
||||
|
||||
mp_obj_full_type_t decompio_type;
|
||||
mp_stream_p_t decompio_stream_p;
|
||||
|
||||
#include "extmod/moduzlib.c"
|
||||
|
||||
|
@ -19,18 +18,14 @@ STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table);
|
|||
mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
|
||||
MP_DYNRUNTIME_INIT_ENTRY
|
||||
|
||||
decompio_stream_p.name = MP_QSTR_protocol_stream;
|
||||
decompio_stream_p.read = decompio_read;
|
||||
|
||||
decompio_type.base.type = mp_fun_table.type_type;
|
||||
decompio_type.flags = MP_TYPE_FLAG_EXTENDED;
|
||||
decompio_type.name = MP_QSTR_DecompIO;
|
||||
decompio_type.make_new = decompio_make_new;
|
||||
decompio_type.ext[0].protocol = &decompio_stream_p;
|
||||
MP_OBJ_TYPE_SET_SLOT(&decompio_type, make_new, &decompio_make_new, 0);
|
||||
MP_OBJ_TYPE_SET_SLOT(&decompio_type, protocol, &decompio_stream_p, 1);
|
||||
decompio_locals_dict_table[0] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_read), MP_OBJ_FROM_PTR(&mp_stream_read_obj) };
|
||||
decompio_locals_dict_table[1] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_readinto), MP_OBJ_FROM_PTR(&mp_stream_readinto_obj) };
|
||||
decompio_locals_dict_table[2] = (mp_map_elem_t){ MP_OBJ_NEW_QSTR(MP_QSTR_readline), MP_OBJ_FROM_PTR(&mp_stream_unbuffered_readline_obj) };
|
||||
decompio_type.locals_dict = (void*)&decompio_locals_dict;
|
||||
MP_OBJ_TYPE_SET_SLOT(&decompio_type, locals_dict, (void*)&decompio_locals_dict, 2);
|
||||
|
||||
mp_store_global(MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR_uzlib));
|
||||
mp_store_global(MP_QSTR_decompress, MP_OBJ_FROM_PTR(&mod_uzlib_decompress_obj));
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
// Include MicroPython API.
|
||||
#include "py/runtime.h"
|
||||
|
||||
// Used to get the time in the Timer class example.
|
||||
#include "py/mphal.h"
|
||||
|
||||
// This is the function which will be called from Python as cexample.add_ints(a, b).
|
||||
STATIC mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) {
|
||||
// Extract the ints from the micropython input objects.
|
||||
|
@ -13,6 +16,58 @@ STATIC mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) {
|
|||
// Define a Python reference to the function above.
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints);
|
||||
|
||||
// This structure represents Timer instance objects.
|
||||
typedef struct _example_Timer_obj_t {
|
||||
// All objects start with the base.
|
||||
mp_obj_base_t base;
|
||||
// Everything below can be thought of as instance attributes, but they
|
||||
// cannot be accessed by MicroPython code directly. In this example we
|
||||
// store the time at which the object was created.
|
||||
mp_uint_t start_time;
|
||||
} example_Timer_obj_t;
|
||||
|
||||
// This is the Timer.time() method. After creating a Timer object, this
|
||||
// can be called to get the time elapsed since creating the Timer.
|
||||
STATIC mp_obj_t example_Timer_time(mp_obj_t self_in) {
|
||||
// The first argument is self. It is cast to the *example_Timer_obj_t
|
||||
// type so we can read its attributes.
|
||||
example_Timer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
// Get the elapsed time and return it as a MicroPython integer.
|
||||
mp_uint_t elapsed = mp_hal_ticks_ms() - self->start_time;
|
||||
return mp_obj_new_int_from_uint(elapsed);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(example_Timer_time_obj, example_Timer_time);
|
||||
|
||||
// This represents Timer.__new__ and Timer.__init__, which is called when
|
||||
// the user instantiates a Timer object.
|
||||
STATIC mp_obj_t example_Timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// Allocates the new object and sets the type.
|
||||
example_Timer_obj_t *self = mp_obj_malloc(example_Timer_obj_t, type);
|
||||
|
||||
// Initializes the time for this Timer instance.
|
||||
self->start_time = mp_hal_ticks_ms();
|
||||
|
||||
// The make_new function always returns self.
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
// This collects all methods and other static class attributes of the Timer.
|
||||
// The table structure is similar to the module table, as detailed below.
|
||||
STATIC const mp_rom_map_elem_t example_Timer_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&example_Timer_time_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(example_Timer_locals_dict, example_Timer_locals_dict_table);
|
||||
|
||||
// This defines the type(Timer) object.
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
example_type_Timer,
|
||||
MP_QSTR_Timer,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, example_Timer_make_new,
|
||||
locals_dict, &example_Timer_locals_dict
|
||||
);
|
||||
|
||||
// Define all properties of the module.
|
||||
// Table entries are key/value pairs of the attribute name (a string)
|
||||
// and the MicroPython object reference.
|
||||
|
@ -21,6 +76,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints);
|
|||
STATIC const mp_rom_map_elem_t example_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cexample) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_add_ints), MP_ROM_PTR(&example_add_ints_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&example_type_Timer) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table);
|
||||
|
||||
|
|
160
extmod/extmod.mk
160
extmod/extmod.mk
|
@ -1,4 +1,41 @@
|
|||
# This makefile fragment provides rules to build 3rd-party components for extmod modules
|
||||
# This makefile fragment adds the source code files for the core extmod modules
|
||||
# and provides rules to build 3rd-party components for extmod modules.
|
||||
|
||||
SRC_EXTMOD_C += \
|
||||
extmod/moduasyncio.c \
|
||||
extmod/modubinascii.c \
|
||||
extmod/moductypes.c \
|
||||
extmod/moduhashlib.c \
|
||||
extmod/moduheapq.c \
|
||||
extmod/modujson.c \
|
||||
extmod/moduos.c \
|
||||
extmod/moduplatform.c\
|
||||
extmod/modurandom.c \
|
||||
extmod/modure.c \
|
||||
extmod/moduselect.c \
|
||||
extmod/moduzlib.c \
|
||||
extmod/utime_mphal.c \
|
||||
extmod/vfs.c \
|
||||
extmod/vfs_blockdev.c \
|
||||
extmod/vfs_fat.c \
|
||||
extmod/vfs_fat_diskio.c \
|
||||
extmod/vfs_fat_file.c \
|
||||
extmod/vfs_lfs.c \
|
||||
extmod/vfs_posix.c \
|
||||
extmod/vfs_posix_file.c \
|
||||
extmod/vfs_reader.c \
|
||||
extmod/virtpin.c \
|
||||
shared/libc/abort_.c \
|
||||
shared/libc/printf.c \
|
||||
|
||||
SRC_THIRDPARTY_C += \
|
||||
|
||||
PY_O += $(addprefix $(BUILD)/, $(SRC_EXTMOD_C:.c=.o))
|
||||
PY_O += $(addprefix $(BUILD)/, $(SRC_THIRDPARTY_C:.c=.o))
|
||||
SRC_QSTR += $(SRC_EXTMOD_C)
|
||||
|
||||
CFLAGS += $(CFLAGS_EXTMOD) $(CFLAGS_THIRDPARTY)
|
||||
LDFLAGS += $(LDFLAGS_EXTMOD) $(LDFLAGS_THIRDPARTY)
|
||||
|
||||
################################################################################
|
||||
# VFS FAT FS
|
||||
|
@ -6,11 +43,11 @@
|
|||
OOFATFS_DIR = lib/oofatfs
|
||||
|
||||
# this sets the config file for FatFs
|
||||
CFLAGS_MOD += -DFFCONF_H=\"$(OOFATFS_DIR)/ffconf.h\"
|
||||
CFLAGS_THIRDPARTY += -DFFCONF_H=\"$(OOFATFS_DIR)/ffconf.h\"
|
||||
|
||||
ifeq ($(MICROPY_VFS_FAT),1)
|
||||
CFLAGS_MOD += -DMICROPY_VFS_FAT=1
|
||||
SRC_MOD += $(addprefix $(OOFATFS_DIR)/,\
|
||||
CFLAGS_EXTMOD += -DMICROPY_VFS_FAT=1
|
||||
SRC_THIRDPARTY_C += $(addprefix $(OOFATFS_DIR)/,\
|
||||
ff.c \
|
||||
ffunicode.c \
|
||||
)
|
||||
|
@ -22,18 +59,18 @@ endif
|
|||
LITTLEFS_DIR = lib/littlefs
|
||||
|
||||
ifeq ($(MICROPY_VFS_LFS1),1)
|
||||
CFLAGS_MOD += -DMICROPY_VFS_LFS1=1
|
||||
CFLAGS_MOD += -DLFS1_NO_MALLOC -DLFS1_NO_DEBUG -DLFS1_NO_WARN -DLFS1_NO_ERROR -DLFS1_NO_ASSERT
|
||||
SRC_MOD += $(addprefix $(LITTLEFS_DIR)/,\
|
||||
CFLAGS_EXTMOD += -DMICROPY_VFS_LFS1=1
|
||||
CFLAGS_THIRDPARTY += -DLFS1_NO_MALLOC -DLFS1_NO_DEBUG -DLFS1_NO_WARN -DLFS1_NO_ERROR -DLFS1_NO_ASSERT
|
||||
SRC_THIRDPARTY_C += $(addprefix $(LITTLEFS_DIR)/,\
|
||||
lfs1.c \
|
||||
lfs1_util.c \
|
||||
)
|
||||
endif
|
||||
|
||||
ifeq ($(MICROPY_VFS_LFS2),1)
|
||||
CFLAGS_MOD += -DMICROPY_VFS_LFS2=1
|
||||
CFLAGS_MOD += -DLFS2_NO_MALLOC -DLFS2_NO_DEBUG -DLFS2_NO_WARN -DLFS2_NO_ERROR -DLFS2_NO_ASSERT
|
||||
SRC_MOD += $(addprefix $(LITTLEFS_DIR)/,\
|
||||
CFLAGS_EXTMOD += -DMICROPY_VFS_LFS2=1
|
||||
CFLAGS_THIRDPARTY += -DLFS2_NO_MALLOC -DLFS2_NO_DEBUG -DLFS2_NO_WARN -DLFS2_NO_ERROR -DLFS2_NO_ASSERT
|
||||
SRC_THIRDPARTY_C += $(addprefix $(LITTLEFS_DIR)/,\
|
||||
lfs2.c \
|
||||
lfs2_util.c \
|
||||
)
|
||||
|
@ -45,12 +82,14 @@ endif
|
|||
# ussl
|
||||
|
||||
ifeq ($(MICROPY_PY_USSL),1)
|
||||
CFLAGS_MOD += -DMICROPY_PY_USSL=1
|
||||
CFLAGS_EXTMOD += -DMICROPY_PY_USSL=1
|
||||
ifeq ($(MICROPY_SSL_AXTLS),1)
|
||||
CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I$(TOP)/lib/axtls/ssl -I$(TOP)/lib/axtls/crypto -I$(TOP)/extmod/axtls-include
|
||||
AXTLS_DIR = lib/axtls
|
||||
GIT_SUBMODULES += $(AXTLS_DIR)
|
||||
CFLAGS_EXTMOD += -DMICROPY_SSL_AXTLS=1 -I$(TOP)/lib/axtls/ssl -I$(TOP)/lib/axtls/crypto -I$(TOP)/extmod/axtls-include
|
||||
$(BUILD)/$(AXTLS_DIR)/%.o: CFLAGS += -Wno-all -Wno-unused-parameter -Wno-uninitialized -Wno-sign-compare -Wno-old-style-definition -Dmp_stream_errno=errno $(AXTLS_DEFS_EXTRA)
|
||||
SRC_MOD += $(addprefix $(AXTLS_DIR)/,\
|
||||
SRC_THIRDPARTY_C += $(addprefix $(AXTLS_DIR)/,\
|
||||
ssl/asn1.c \
|
||||
ssl/loader.c \
|
||||
ssl/tls1.c \
|
||||
|
@ -67,8 +106,12 @@ SRC_MOD += $(addprefix $(AXTLS_DIR)/,\
|
|||
)
|
||||
else ifeq ($(MICROPY_SSL_MBEDTLS),1)
|
||||
MBEDTLS_DIR = lib/mbedtls
|
||||
CFLAGS_MOD += -DMICROPY_SSL_MBEDTLS=1 -I$(TOP)/$(MBEDTLS_DIR)/include
|
||||
SRC_MOD += $(addprefix $(MBEDTLS_DIR)/library/,\
|
||||
MBEDTLS_CONFIG_FILE ?= \"mbedtls/mbedtls_config.h\"
|
||||
GIT_SUBMODULES += $(MBEDTLS_DIR)
|
||||
CFLAGS_EXTMOD += -DMBEDTLS_CONFIG_FILE=$(MBEDTLS_CONFIG_FILE)
|
||||
CFLAGS_EXTMOD += -DMICROPY_SSL_MBEDTLS=1 -I$(TOP)/$(MBEDTLS_DIR)/include
|
||||
SRC_THIRDPARTY_C += lib/mbedtls_errors/mp_mbedtls_errors.c
|
||||
SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\
|
||||
aes.c \
|
||||
aesni.c \
|
||||
arc4.c \
|
||||
|
@ -96,7 +139,6 @@ SRC_MOD += $(addprefix $(MBEDTLS_DIR)/library/,\
|
|||
ecp_curves.c \
|
||||
entropy.c \
|
||||
entropy_poll.c \
|
||||
error.c \
|
||||
gcm.c \
|
||||
havege.c \
|
||||
hmac_drbg.c \
|
||||
|
@ -148,13 +190,14 @@ endif
|
|||
# lwip
|
||||
|
||||
ifeq ($(MICROPY_PY_LWIP),1)
|
||||
GIT_SUBMODULES += lib/lwip
|
||||
# A port should add an include path where lwipopts.h can be found (eg extmod/lwip-include)
|
||||
LWIP_DIR = lib/lwip/src
|
||||
INC += -I$(TOP)/$(LWIP_DIR)/include
|
||||
CFLAGS_MOD += -DMICROPY_PY_LWIP=1
|
||||
$(BUILD)/$(LWIP_DIR)/core/ipv4/dhcp.o: CFLAGS_MOD += -Wno-address
|
||||
SRC_MOD += extmod/modlwip.c shared/netutils/netutils.c
|
||||
SRC_MOD += $(addprefix $(LWIP_DIR)/,\
|
||||
CFLAGS_EXTMOD += -DMICROPY_PY_LWIP=1
|
||||
$(BUILD)/$(LWIP_DIR)/core/ipv4/dhcp.o: CFLAGS += -Wno-address
|
||||
SRC_THIRDPARTY_C += shared/netutils/netutils.c
|
||||
SRC_THIRDPARTY_C += $(addprefix $(LWIP_DIR)/,\
|
||||
apps/mdns/mdns.c \
|
||||
core/def.c \
|
||||
core/dns.c \
|
||||
|
@ -193,8 +236,8 @@ SRC_MOD += $(addprefix $(LWIP_DIR)/,\
|
|||
netif/ethernet.c \
|
||||
)
|
||||
ifeq ($(MICROPY_PY_LWIP_SLIP),1)
|
||||
CFLAGS_MOD += -DMICROPY_PY_LWIP_SLIP=1
|
||||
SRC_MOD += $(LWIP_DIR)/netif/slipif.c
|
||||
CFLAGS_EXTMOD += -DMICROPY_PY_LWIP_SLIP=1
|
||||
SRC_THIRDPARTY_C += $(LWIP_DIR)/netif/slipif.c
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -205,8 +248,7 @@ ifeq ($(MICROPY_PY_BTREE),1)
|
|||
BTREE_DIR = lib/berkeley-db-1.xx
|
||||
BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA)
|
||||
INC += -I$(TOP)/$(BTREE_DIR)/PORT/include
|
||||
SRC_MOD += extmod/modbtree.c
|
||||
SRC_MOD += $(addprefix $(BTREE_DIR)/,\
|
||||
SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\
|
||||
btree/bt_close.c \
|
||||
btree/bt_conv.c \
|
||||
btree/bt_debug.c \
|
||||
|
@ -222,9 +264,79 @@ SRC_MOD += $(addprefix $(BTREE_DIR)/,\
|
|||
btree/bt_utils.c \
|
||||
mpool/mpool.c \
|
||||
)
|
||||
CFLAGS_MOD += -DMICROPY_PY_BTREE=1
|
||||
CFLAGS_EXTMOD += -DMICROPY_PY_BTREE=1
|
||||
# we need to suppress certain warnings to get berkeley-db to compile cleanly
|
||||
# and we have separate BTREE_DEFS so the definitions don't interfere with other source code
|
||||
$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter $(BTREE_DEFS)
|
||||
$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS)
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
# networking
|
||||
|
||||
ifeq ($(MICROPY_PY_NETWORK_CYW43),1)
|
||||
CYW43_DIR = lib/cyw43-driver
|
||||
GIT_SUBMODULES += $(CYW43_DIR)
|
||||
CFLAGS_EXTMOD += -DMICROPY_PY_NETWORK_CYW43=1
|
||||
SRC_THIRDPARTY_C += $(addprefix $(CYW43_DIR)/src/,\
|
||||
cyw43_ctrl.c \
|
||||
cyw43_lwip.c \
|
||||
cyw43_ll.c \
|
||||
cyw43_sdio.c \
|
||||
cyw43_stats.c \
|
||||
)
|
||||
ifeq ($(MICROPY_PY_BLUETOOTH),1)
|
||||
DRIVERS_SRC_C += drivers/cyw43/cywbt.c
|
||||
endif
|
||||
|
||||
$(BUILD)/$(CYW43_DIR)/src/cyw43_%.o: CFLAGS += -std=c11
|
||||
endif # MICROPY_PY_NETWORK_CYW43
|
||||
|
||||
ifneq ($(MICROPY_PY_NETWORK_WIZNET5K),)
|
||||
ifneq ($(MICROPY_PY_NETWORK_WIZNET5K),0)
|
||||
WIZNET5K_DIR=lib/wiznet5k
|
||||
GIT_SUBMODULES += lib/wiznet5k
|
||||
INC += -I$(TOP)/$(WIZNET5K_DIR) -I$(TOP)/$(WIZNET5K_DIR)/Ethernet
|
||||
CFLAGS += -DMICROPY_PY_NETWORK_WIZNET5K=$(MICROPY_PY_NETWORK_WIZNET5K) -D_WIZCHIP_=$(MICROPY_PY_NETWORK_WIZNET5K)
|
||||
CFLAGS_THIRDPARTY += -DWIZCHIP_PREFIXED_EXPORTS=1
|
||||
ifeq ($(MICROPY_PY_LWIP),1)
|
||||
# When using MACRAW mode (with lwIP), maximum buffer space must be used for the raw socket
|
||||
CFLAGS_THIRDPARTY += -DWIZCHIP_USE_MAX_BUFFER
|
||||
endif
|
||||
SRC_THIRDPARTY_C += $(addprefix $(WIZNET5K_DIR)/,\
|
||||
Ethernet/W$(MICROPY_PY_NETWORK_WIZNET5K)/w$(MICROPY_PY_NETWORK_WIZNET5K).c \
|
||||
Ethernet/wizchip_conf.c \
|
||||
Ethernet/socket.c \
|
||||
Internet/DNS/dns.c \
|
||||
Internet/DHCP/dhcp.c \
|
||||
)
|
||||
endif
|
||||
endif
|
||||
|
||||
################################################################################
|
||||
# bluetooth
|
||||
|
||||
ifeq ($(MICROPY_PY_BLUETOOTH),1)
|
||||
CFLAGS_EXTMOD += -DMICROPY_PY_BLUETOOTH=1
|
||||
|
||||
ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1)
|
||||
ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
|
||||
$(error Cannot enable both NimBLE and BTstack at the same time)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(MICROPY_BLUETOOTH_NIMBLE),1)
|
||||
ifneq ($(MICROPY_BLUETOOTH_BTSTACK),1)
|
||||
$(error Must enable one of MICROPY_BLUETOOTH_NIMBLE or MICROPY_BLUETOOTH_BTSTACK)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1)
|
||||
include $(TOP)/extmod/nimble/nimble.mk
|
||||
endif
|
||||
|
||||
ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1)
|
||||
include $(TOP)/extmod/btstack/btstack.mk
|
||||
endif
|
||||
|
||||
endif
|
||||
|
|
|
@ -35,8 +35,6 @@
|
|||
#include "shared-bindings/supervisor/__init__.h"
|
||||
#endif
|
||||
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
// Used when task cannot be guaranteed to be non-NULL.
|
||||
#define TASK_PAIRHEAP(task) ((task) ? &(task)->pairheap : NULL)
|
||||
|
||||
|
@ -65,32 +63,19 @@ STATIC const mp_obj_type_t task_queue_type;
|
|||
STATIC const mp_obj_type_t task_type;
|
||||
|
||||
STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
|
||||
|
||||
/******************************************************************************/
|
||||
// Ticks for task ordering in pairing heap
|
||||
|
||||
// CIRCUITPY-style ticks
|
||||
#define _TICKS_PERIOD (1lu << 29)
|
||||
#define _TICKS_MAX (_TICKS_PERIOD - 1)
|
||||
#define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1)
|
||||
#if !CIRCUITPY || (defined(__unix__) || defined(__APPLE__))
|
||||
STATIC mp_obj_t ticks(void) {
|
||||
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & _TICKS_MAX);
|
||||
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
|
||||
}
|
||||
#else
|
||||
// We don't share the implementation above because our supervisor_ticks_ms
|
||||
// starts the epoch about 65 seconds before the first overflow (see
|
||||
// shared-bindings/supervisor/__init__.c). We assume/require that
|
||||
// supervisor.ticks_ms is picked as the ticks implementation under
|
||||
// CircuitPython for the Python-coded bits of asyncio.
|
||||
#define ticks() supervisor_ticks_ms()
|
||||
#endif
|
||||
|
||||
STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
|
||||
mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in);
|
||||
mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in);
|
||||
mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD;
|
||||
mp_int_t diff = ((t1 - t0 + MICROPY_PY_UTIME_TICKS_PERIOD / 2) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1))
|
||||
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
|
||||
return diff;
|
||||
}
|
||||
|
||||
|
@ -161,19 +146,20 @@ STATIC const mp_rom_map_elem_t task_queue_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&task_queue_pop_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&task_queue_remove_obj) },
|
||||
|
||||
// CIRCUITPYTHON: remove these after the bundle need not support 8.x
|
||||
// CIRCUITPYTHON: Remove these in CircuitPython 10.0.0
|
||||
{ MP_ROM_QSTR(MP_QSTR_push_head), MP_ROM_PTR(&task_queue_push_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_push_sorted), MP_ROM_PTR(&task_queue_push_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pop_head), MP_ROM_PTR(&task_queue_pop_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(task_queue_locals_dict, task_queue_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t task_queue_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_TaskQueue,
|
||||
.make_new = task_queue_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&task_queue_locals_dict,
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
task_queue_type,
|
||||
MP_QSTR_TaskQueue,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, task_queue_make_new,
|
||||
locals_dict, &task_queue_locals_dict
|
||||
);
|
||||
|
||||
/******************************************************************************/
|
||||
// Task class
|
||||
|
@ -248,6 +234,8 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) {
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel);
|
||||
|
||||
// CIRCUITPY provides __await__().
|
||||
STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
|
||||
|
||||
STATIC mp_obj_t task_await(mp_obj_t self_in) {
|
||||
return task_getiter(self_in, NULL);
|
||||
}
|
||||
|
@ -271,7 +259,6 @@ STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
|||
dest[1] = self_in;
|
||||
} else if (attr == MP_QSTR_ph_key) {
|
||||
dest[0] = self->ph_key;
|
||||
// CIRCUITPY provides __await__().
|
||||
} else if (attr == MP_QSTR___await__) {
|
||||
dest[0] = MP_OBJ_FROM_PTR(&task_await_obj);
|
||||
dest[1] = self_in;
|
||||
|
@ -307,7 +294,6 @@ STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) {
|
|||
STATIC mp_obj_t task_iternext(mp_obj_t self_in) {
|
||||
mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (TASK_IS_DONE(self)) {
|
||||
// CIRCUITPY
|
||||
if (self->data == mp_const_none) {
|
||||
// Task finished but has already been sent to the loop's exception handler.
|
||||
mp_raise_StopIteration(MP_OBJ_NULL);
|
||||
|
@ -326,27 +312,25 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC const mp_obj_type_t task_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Task,
|
||||
.make_new = task_make_new,
|
||||
.attr = task_attr,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = task_getiter,
|
||||
.iternext = task_iternext,
|
||||
),
|
||||
STATIC const mp_getiter_iternext_custom_t task_getiter_iternext = {
|
||||
.getiter = task_getiter,
|
||||
.iternext = task_iternext,
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
task_type,
|
||||
MP_QSTR_Task,
|
||||
MP_TYPE_FLAG_ITER_IS_CUSTOM,
|
||||
make_new, task_make_new,
|
||||
attr, task_attr,
|
||||
iter, &task_getiter_iternext
|
||||
);
|
||||
|
||||
/******************************************************************************/
|
||||
// C-level uasyncio module
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_uasyncio_globals_table[] = {
|
||||
#if CIRCUITPY
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__asyncio) },
|
||||
#else
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__uasyncio) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_TaskQueue), MP_ROM_PTR(&task_queue_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&task_type) },
|
||||
};
|
||||
|
|
|
@ -30,8 +30,9 @@
|
|||
|
||||
#include "py/runtime.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/objstr.h"
|
||||
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
#include "lib/uzlib/tinf.h"
|
||||
|
||||
#if MICROPY_PY_UBINASCII
|
||||
|
||||
|
@ -42,76 +43,19 @@ static void check_not_unicode(const mp_obj_t arg) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
STATIC mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args) {
|
||||
// First argument is the data to convert.
|
||||
// Second argument is an optional separator to be used between values.
|
||||
const char *sep = NULL;
|
||||
mp_buffer_info_t bufinfo;
|
||||
check_not_unicode(args[0]);
|
||||
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
|
||||
|
||||
// Code below assumes non-zero buffer length when computing size with
|
||||
// separator, so handle the zero-length case here.
|
||||
if (bufinfo.len == 0) {
|
||||
return mp_const_empty_bytes;
|
||||
}
|
||||
|
||||
vstr_t vstr;
|
||||
size_t out_len = bufinfo.len * 2;
|
||||
if (n_args > 1) {
|
||||
// 1-char separator between hex numbers
|
||||
out_len += bufinfo.len - 1;
|
||||
sep = mp_obj_str_get_str(args[1]);
|
||||
}
|
||||
vstr_init_len(&vstr, out_len);
|
||||
byte *in = bufinfo.buf, *out = (byte *)vstr.buf;
|
||||
for (mp_uint_t i = bufinfo.len; i--;) {
|
||||
byte d = (*in >> 4);
|
||||
if (d > 9) {
|
||||
d += 'a' - '9' - 1;
|
||||
}
|
||||
*out++ = d + '0';
|
||||
d = (*in++ & 0xf);
|
||||
if (d > 9) {
|
||||
d += 'a' - '9' - 1;
|
||||
}
|
||||
*out++ = d + '0';
|
||||
if (sep != NULL && i != 0) {
|
||||
*out++ = *sep;
|
||||
}
|
||||
}
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
#if MICROPY_PY_BUILTINS_BYTES_HEX
|
||||
STATIC mp_obj_t bytes_hex_as_bytes(size_t n_args, const mp_obj_t *args) {
|
||||
return mp_obj_bytes_hex(n_args, args, &mp_type_bytes);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_hexlify_obj, 1, 2, mod_binascii_hexlify);
|
||||
|
||||
STATIC mp_obj_t mod_binascii_unhexlify(mp_obj_t data) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_hex_as_bytes_obj, 1, 2, bytes_hex_as_bytes);
|
||||
|
||||
if ((bufinfo.len & 1) != 0) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("odd-length string"));
|
||||
}
|
||||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, bufinfo.len / 2);
|
||||
byte *in = bufinfo.buf, *out = (byte *)vstr.buf;
|
||||
byte hex_byte = 0;
|
||||
for (mp_uint_t i = bufinfo.len; i--;) {
|
||||
byte hex_ch = *in++;
|
||||
if (unichar_isxdigit(hex_ch)) {
|
||||
hex_byte += unichar_xdigit_value(hex_ch);
|
||||
} else {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("non-hex digit found"));
|
||||
}
|
||||
if (i & 1) {
|
||||
hex_byte <<= 4;
|
||||
} else {
|
||||
*out++ = hex_byte;
|
||||
hex_byte = 0;
|
||||
}
|
||||
}
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
STATIC mp_obj_t bytes_fromhex_bytes(mp_obj_t data) {
|
||||
return mp_obj_bytes_fromhex(MP_OBJ_FROM_PTR(&mp_type_bytes), data);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_unhexlify_obj, mod_binascii_unhexlify);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bytes_fromhex_obj, bytes_fromhex_bytes);
|
||||
#endif
|
||||
|
||||
// If ch is a character in the base64 alphabet, and is not a pad character, then
|
||||
// the corresponding integer between 0 and 63, inclusively, is returned.
|
||||
|
@ -171,7 +115,7 @@ STATIC mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) {
|
|||
mp_raise_ValueError(MP_ERROR_TEXT("incorrect padding"));
|
||||
}
|
||||
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj, mod_binascii_a2b_base64);
|
||||
|
||||
|
@ -184,6 +128,7 @@ STATIC mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args,
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
uint8_t newline = args[ARG_newline].u_bool;
|
||||
// CIRCUITPY
|
||||
check_not_unicode(pos_args[0]);
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(pos_args[0], &bufinfo, MP_BUFFER_READ);
|
||||
|
@ -234,7 +179,7 @@ STATIC mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args,
|
|||
if (newline) {
|
||||
*out = '\n';
|
||||
}
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b2a_base64);
|
||||
|
||||
|
@ -274,53 +219,30 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b
|
|||
* any source distribution.
|
||||
*/
|
||||
|
||||
/*
|
||||
* CRC32 algorithm taken from the zlib source, which is
|
||||
* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
|
||||
*/
|
||||
|
||||
|
||||
static const unsigned int tinf_crc32tab[16] = {
|
||||
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190,
|
||||
0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344,
|
||||
0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278,
|
||||
0xbdbdf21c
|
||||
};
|
||||
|
||||
/* crc is previous value for incremental computation, 0xffffffff initially */
|
||||
static uint32_t from_uzlib_crc32(const void *data, unsigned int length, uint32_t crc) {
|
||||
const unsigned char *buf = (const unsigned char *)data;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < length; ++i)
|
||||
{
|
||||
crc ^= buf[i];
|
||||
crc = tinf_crc32tab[crc & 0x0f] ^ (crc >> 4);
|
||||
crc = tinf_crc32tab[crc & 0x0f] ^ (crc >> 4);
|
||||
}
|
||||
|
||||
// return value suitable for passing in next time, for final value invert it
|
||||
return crc /* ^ 0xffffffff*/;
|
||||
}
|
||||
|
||||
#if MICROPY_PY_UBINASCII_CRC32
|
||||
STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
// CIRCUITPY
|
||||
check_not_unicode(args[0]);
|
||||
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
|
||||
uint32_t crc = (n_args > 1) ? mp_obj_get_int_truncated(args[1]) : 0;
|
||||
crc = from_uzlib_crc32(bufinfo.buf, bufinfo.len, crc ^ 0xffffffff);
|
||||
crc = uzlib_crc32(bufinfo.buf, bufinfo.len, crc ^ 0xffffffff);
|
||||
return mp_obj_new_int_from_uint(crc ^ 0xffffffff);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj, 1, 2, mod_binascii_crc32);
|
||||
|
||||
#endif
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_binascii) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_hexlify), MP_ROM_PTR(&mod_binascii_hexlify_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_unhexlify), MP_ROM_PTR(&mod_binascii_unhexlify_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ubinascii) },
|
||||
#if MICROPY_PY_BUILTINS_BYTES_HEX
|
||||
{ MP_ROM_QSTR(MP_QSTR_hexlify), MP_ROM_PTR(&bytes_hex_as_bytes_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_unhexlify), MP_ROM_PTR(&bytes_fromhex_obj) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_a2b_base64), MP_ROM_PTR(&mod_binascii_a2b_base64_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_b2a_base64), MP_ROM_PTR(&mod_binascii_b2a_base64_obj) },
|
||||
#if MICROPY_PY_UBINASCII_CRC32
|
||||
{ MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_binascii_crc32_obj) },
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table);
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
#include "py/objtuple.h"
|
||||
#include "py/binary.h"
|
||||
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#if MICROPY_PY_UCTYPES
|
||||
|
||||
// The uctypes module allows defining the layout of a raw data structure (using
|
||||
|
@ -192,7 +190,7 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_
|
|||
// but scalar structure field is lowered into native Python int, so all
|
||||
// type info is lost. So, we cannot say if it's scalar type description,
|
||||
// or such lowered scalar.
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("cannot unambiguously get sizeof scalar"));
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("can't unambiguously get sizeof scalar"));
|
||||
}
|
||||
syntax_error();
|
||||
}
|
||||
|
@ -504,8 +502,8 @@ STATIC void uctypes_struct_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
|||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t base_in, mp_obj_t index_in, mp_obj_t value) {
|
||||
mp_obj_uctypes_struct_t *self = mp_obj_cast_to_native_base(base_in, &uctypes_struct_type);
|
||||
STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
|
||||
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (value == MP_OBJ_NULL) {
|
||||
// delete
|
||||
|
@ -561,7 +559,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t base_in, mp_obj_t index_in, mp_ob
|
|||
}
|
||||
|
||||
} else if (agg_type == PTR) {
|
||||
byte *p = *(void **)(void *)self->addr;
|
||||
byte *p = *(void **)self->addr;
|
||||
if (mp_obj_is_small_int(t->items[1])) {
|
||||
uint val_type = GET_TYPE(MP_OBJ_SMALL_INT_VALUE(t->items[1]), VAL_TYPE_BITS);
|
||||
return get_aligned(val_type, p, index);
|
||||
|
@ -590,7 +588,7 @@ STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
|||
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
|
||||
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
|
||||
if (agg_type == PTR) {
|
||||
byte *p = *(void **)(void *)self->addr;
|
||||
byte *p = *(void **)self->addr;
|
||||
return mp_obj_new_int((mp_int_t)(uintptr_t)p);
|
||||
}
|
||||
}
|
||||
|
@ -636,19 +634,17 @@ STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);
|
||||
|
||||
STATIC const mp_obj_type_t uctypes_struct_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_struct,
|
||||
.print = uctypes_struct_print,
|
||||
.make_new = uctypes_struct_make_new,
|
||||
.attr = uctypes_struct_attr,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = uctypes_struct_subscr,
|
||||
.unary_op = uctypes_struct_unary_op,
|
||||
.buffer_p = { .get_buffer = uctypes_get_buffer },
|
||||
),
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
uctypes_struct_type,
|
||||
MP_QSTR_struct,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, uctypes_struct_make_new,
|
||||
print, uctypes_struct_print,
|
||||
attr, uctypes_struct_attr,
|
||||
subscr, uctypes_struct_subscr,
|
||||
unary_op, uctypes_struct_unary_op,
|
||||
buffer, uctypes_get_buffer
|
||||
);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uctypes) },
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#if MICROPY_PY_UHASHLIB
|
||||
|
||||
#if MICROPY_SSL_MBEDTLS
|
||||
|
@ -111,7 +109,7 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
|||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, 32);
|
||||
mbedtls_sha256_finish_ret((mbedtls_sha256_context *)&self->state, (unsigned char *)vstr.buf);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -154,7 +152,7 @@ STATIC mp_obj_t uhashlib_sha256_digest(mp_obj_t self_in) {
|
|||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
|
||||
sha256_final((CRYAL_SHA256_CTX *)self->state, (byte *)vstr.buf);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -168,12 +166,13 @@ STATIC const mp_rom_map_elem_t uhashlib_sha256_locals_dict_table[] = {
|
|||
|
||||
STATIC MP_DEFINE_CONST_DICT(uhashlib_sha256_locals_dict, uhashlib_sha256_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t uhashlib_sha256_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_sha256,
|
||||
.make_new = uhashlib_sha256_make_new,
|
||||
.locals_dict = (void *)&uhashlib_sha256_locals_dict,
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
uhashlib_sha256_type,
|
||||
MP_QSTR_sha256,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, uhashlib_sha256_make_new,
|
||||
locals_dict, &uhashlib_sha256_locals_dict
|
||||
);
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_UHASHLIB_SHA1
|
||||
|
@ -207,7 +206,7 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
|||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, SHA1_SIZE);
|
||||
SHA1_Final((byte *)vstr.buf, (SHA1_CTX *)self->state);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -248,7 +247,7 @@ STATIC mp_obj_t uhashlib_sha1_digest(mp_obj_t self_in) {
|
|||
vstr_init_len(&vstr, 20);
|
||||
mbedtls_sha1_finish_ret((mbedtls_sha1_context *)self->state, (byte *)vstr.buf);
|
||||
mbedtls_sha1_free((mbedtls_sha1_context *)self->state);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -261,12 +260,13 @@ STATIC const mp_rom_map_elem_t uhashlib_sha1_locals_dict_table[] = {
|
|||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(uhashlib_sha1_locals_dict, uhashlib_sha1_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t uhashlib_sha1_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_sha1,
|
||||
.make_new = uhashlib_sha1_make_new,
|
||||
.locals_dict = (void *)&uhashlib_sha1_locals_dict,
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
uhashlib_sha1_type,
|
||||
MP_QSTR_sha1,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, uhashlib_sha1_make_new,
|
||||
locals_dict, &uhashlib_sha1_locals_dict
|
||||
);
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_UHASHLIB_MD5
|
||||
|
@ -300,7 +300,7 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {
|
|||
vstr_t vstr;
|
||||
vstr_init_len(&vstr, MD5_SIZE);
|
||||
MD5_Final((byte *)vstr.buf, (MD5_CTX *)self->state);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
#endif // MICROPY_SSL_AXTLS
|
||||
|
||||
|
@ -341,7 +341,7 @@ STATIC mp_obj_t uhashlib_md5_digest(mp_obj_t self_in) {
|
|||
vstr_init_len(&vstr, 16);
|
||||
mbedtls_md5_finish_ret((mbedtls_md5_context *)self->state, (byte *)vstr.buf);
|
||||
mbedtls_md5_free((mbedtls_md5_context *)self->state);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||
return mp_obj_new_bytes_from_vstr(&vstr);
|
||||
}
|
||||
#endif // MICROPY_SSL_MBEDTLS
|
||||
|
||||
|
@ -354,12 +354,13 @@ STATIC const mp_rom_map_elem_t uhashlib_md5_locals_dict_table[] = {
|
|||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(uhashlib_md5_locals_dict, uhashlib_md5_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t uhashlib_md5_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_md5,
|
||||
.make_new = uhashlib_md5_make_new,
|
||||
.locals_dict = (void *)&uhashlib_md5_locals_dict,
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
uhashlib_md5_type,
|
||||
MP_QSTR_md5,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, uhashlib_md5_make_new,
|
||||
locals_dict, &uhashlib_md5_locals_dict
|
||||
);
|
||||
#endif // MICROPY_PY_UHASHLIB_MD5
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_uhashlib_globals_table[] = {
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
#include "py/objlist.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#if MICROPY_PY_UHEAPQ
|
||||
|
||||
// the algorithm here is modelled on CPython's heapq.py
|
||||
|
|
|
@ -34,8 +34,6 @@
|
|||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#if MICROPY_PY_UJSON
|
||||
|
||||
#if MICROPY_PY_UJSON_SEPARATORS
|
||||
|
@ -71,7 +69,7 @@ STATIC mp_obj_t mod_ujson_dump_helper(size_t n_args, const mp_obj_t *pos_args, m
|
|||
vstr_t vstr;
|
||||
vstr_init_print(&vstr, 8, &print_ext.base);
|
||||
mp_obj_print_helper(&print_ext.base, pos_args[0], PRINT_JSON);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
|
||||
return mp_obj_new_str_from_utf8_vstr(&vstr);
|
||||
} else {
|
||||
// dump(obj, stream)
|
||||
print_ext.base.data = MP_OBJ_TO_PTR(pos_args[1]);
|
||||
|
@ -107,7 +105,7 @@ STATIC mp_obj_t mod_ujson_dumps(mp_obj_t obj) {
|
|||
mp_print_t print;
|
||||
vstr_init_print(&vstr, 8, &print);
|
||||
mp_obj_print_helper(&print, obj, PRINT_JSON);
|
||||
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
|
||||
return mp_obj_new_str_from_utf8_vstr(&vstr);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps);
|
||||
#endif
|
||||
|
@ -178,6 +176,9 @@ STATIC mp_uint_t ujson_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size,
|
|||
}
|
||||
s->start = 0;
|
||||
s->end = mp_obj_get_int(ret);
|
||||
if (s->end == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
*((uint8_t *)buf) = ((uint8_t *)s->bytearray_obj.items)[s->start];
|
||||
|
@ -332,7 +333,7 @@ STATIC mp_obj_t _mod_ujson_load(mp_obj_t stream_obj, bool return_first_json) {
|
|||
S_NEXT(s);
|
||||
}
|
||||
if (flt) {
|
||||
next = mp_parse_num_decimal(vstr.buf, vstr.len, false, false, NULL);
|
||||
next = mp_parse_num_float(vstr.buf, vstr.len, false, NULL);
|
||||
} else {
|
||||
next = mp_parse_num_integer(vstr.buf, vstr.len, 10, NULL);
|
||||
}
|
||||
|
|
|
@ -37,11 +37,11 @@
|
|||
|
||||
#if defined(__ARM_ARCH)
|
||||
#define MICROPY_PLATFORM_ARCH "arm"
|
||||
#elif defined(__x86_64__) || defined(_WIN64)
|
||||
#elif defined(__x86_64__) || defined(_M_X64)
|
||||
#define MICROPY_PLATFORM_ARCH "x86_64"
|
||||
#elif defined(__i386__) || defined(_M_IX86)
|
||||
#define MICROPY_PLATFORM_ARCH "x86"
|
||||
#elif defined(__xtensa__) || defined(_M_IX86)
|
||||
#elif defined(__xtensa__)
|
||||
#define MICROPY_PLATFORM_ARCH "xtensa"
|
||||
#else
|
||||
#define MICROPY_PLATFORM_ARCH ""
|
||||
|
|
|
@ -33,16 +33,17 @@
|
|||
#include "py/objstr.h"
|
||||
#include "py/stackctrl.h"
|
||||
|
||||
#if MICROPY_PY_BUILTINS_STR_UNICODE
|
||||
#include "py/unicode.h"
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_URE
|
||||
|
||||
#define re1_5_stack_chk() MP_STACK_CHECK()
|
||||
|
||||
#include "lib/re1.5/re1.5.h"
|
||||
|
||||
// CIRCUITPY
|
||||
#if MICROPY_PY_URE_DEBUG
|
||||
#define FLAG_DEBUG 0x1000
|
||||
#endif
|
||||
|
||||
typedef struct _mp_obj_re_t {
|
||||
mp_obj_base_t base;
|
||||
|
@ -124,6 +125,18 @@ STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span
|
|||
e = self->caps[no * 2 + 1] - begin;
|
||||
}
|
||||
|
||||
#if MICROPY_PY_BUILTINS_STR_UNICODE
|
||||
if (mp_obj_get_type(self->str) == &mp_type_str) {
|
||||
const byte *begin = (const byte *)mp_obj_str_get_str(self->str);
|
||||
if (s != -1) {
|
||||
s = utf8_ptr_to_index(begin, begin + s);
|
||||
}
|
||||
if (e != -1) {
|
||||
e = utf8_ptr_to_index(begin, begin + e);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
span[0] = mp_obj_new_int(s);
|
||||
span[1] = mp_obj_new_int(e);
|
||||
}
|
||||
|
@ -166,12 +179,13 @@ STATIC const mp_rom_map_elem_t match_locals_dict_table[] = {
|
|||
|
||||
STATIC MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t match_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_match,
|
||||
.print = match_print,
|
||||
.locals_dict = (void *)&match_locals_dict,
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
match_type,
|
||||
MP_QSTR_match,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
print, match_print,
|
||||
locals_dict, &match_locals_dict
|
||||
);
|
||||
#endif
|
||||
|
||||
STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
|
@ -183,7 +197,7 @@ STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
|||
STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
mp_obj_re_t *self;
|
||||
if (mp_obj_is_type(args[0], &re_type)) {
|
||||
if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) {
|
||||
self = MP_OBJ_TO_PTR(args[0]);
|
||||
} else {
|
||||
self = MP_OBJ_TO_PTR(mod_re_compile(1, args));
|
||||
|
@ -232,7 +246,7 @@ STATIC mp_obj_t ure_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
match->base.type = &match_type;
|
||||
match->base.type = (mp_obj_type_t *)&match_type;
|
||||
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
|
||||
match->str = args[1];
|
||||
return MP_OBJ_FROM_PTR(match);
|
||||
|
@ -277,7 +291,7 @@ STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) {
|
|||
mp_obj_t s = mp_obj_new_str_of_type(str_type, (const byte *)subj.begin, caps[0] - subj.begin);
|
||||
mp_obj_list_append(retval, s);
|
||||
if (self->re.sub > 0) {
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("Splitting with sub-captures"));
|
||||
mp_raise_NotImplementedError(MP_ERROR_TEXT("splitting with sub-captures"));
|
||||
}
|
||||
subj.begin = caps[1];
|
||||
if (maxsplit > 0 && --maxsplit == 0) {
|
||||
|
@ -297,7 +311,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_split_obj, 2, 3, re_split);
|
|||
|
||||
STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_re_t *self;
|
||||
if (mp_obj_is_type(args[0], &re_type)) {
|
||||
if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) {
|
||||
self = MP_OBJ_TO_PTR(args[0]);
|
||||
} else {
|
||||
self = MP_OBJ_TO_PTR(mod_re_compile(1, args));
|
||||
|
@ -320,7 +334,7 @@ STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) {
|
|||
vstr_t vstr_return;
|
||||
vstr_return.buf = NULL; // We'll init the vstr after the first match
|
||||
mp_obj_match_t *match = mp_local_alloc(sizeof(mp_obj_match_t) + caps_num * sizeof(char *));
|
||||
match->base.type = &match_type;
|
||||
match->base.type = (mp_obj_type_t *)&match_type;
|
||||
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
|
||||
match->str = where;
|
||||
|
||||
|
@ -405,7 +419,11 @@ STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) {
|
|||
// Add post-match string
|
||||
vstr_add_strn(&vstr_return, subj.begin, subj.end - subj.begin);
|
||||
|
||||
return mp_obj_new_str_from_vstr(mp_obj_get_type(where), &vstr_return);
|
||||
if (mp_obj_get_type(where) == &mp_type_str) {
|
||||
return mp_obj_new_str_from_utf8_vstr(&vstr_return);
|
||||
} else {
|
||||
return mp_obj_new_bytes_from_vstr(&vstr_return);
|
||||
}
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_sub_obj, 3, 5, re_sub_helper);
|
||||
|
@ -424,16 +442,17 @@ STATIC const mp_rom_map_elem_t re_locals_dict_table[] = {
|
|||
|
||||
STATIC MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t re_type = {
|
||||
{ &mp_type_type },
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
re_type,
|
||||
#if CIRCUITPY
|
||||
.name = MP_QSTR_re,
|
||||
MP_QSTR_re,
|
||||
#else
|
||||
.name = MP_QSTR_ure,
|
||||
MP_QSTR_ure,
|
||||
#endif
|
||||
.print = re_print,
|
||||
.locals_dict = (void *)&re_locals_dict,
|
||||
};
|
||||
MP_TYPE_FLAG_NONE,
|
||||
print, re_print,
|
||||
locals_dict, &re_locals_dict
|
||||
);
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
|
||||
|
@ -443,14 +462,12 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
|
|||
if (size == -1) {
|
||||
goto error;
|
||||
}
|
||||
mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, char, size, &re_type);
|
||||
mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, char, size, (mp_obj_type_t *)&re_type);
|
||||
#if MICROPY_PY_URE_DEBUG
|
||||
int flags = 0;
|
||||
if (n_args > 1) {
|
||||
flags = mp_obj_get_int(args[1]);
|
||||
}
|
||||
#else
|
||||
(void)n_args;
|
||||
#endif
|
||||
int error = re1_5_compilecode(&o->re, re_str);
|
||||
if (error != 0) {
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "py/stream.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/objlist.h"
|
||||
|
@ -343,16 +342,13 @@ STATIC const mp_rom_map_elem_t poll_locals_dict_table[] = {
|
|||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t mp_type_poll = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_poll,
|
||||
.locals_dict = (void *)&poll_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = poll_iternext,
|
||||
),
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
mp_type_poll,
|
||||
MP_QSTR_poll,
|
||||
MP_TYPE_FLAG_ITER_IS_ITERNEXT,
|
||||
iter, poll_iternext,
|
||||
locals_dict, &poll_locals_dict
|
||||
);
|
||||
|
||||
// poll()
|
||||
STATIC mp_obj_t select_poll(void) {
|
||||
|
|
|
@ -31,8 +31,6 @@
|
|||
#include "py/stream.h"
|
||||
#include "py/mperrno.h"
|
||||
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#if MICROPY_PY_UZLIB
|
||||
|
||||
#define UZLIB_CONF_PARANOID_CHECKS (1)
|
||||
|
@ -138,22 +136,19 @@ STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = {
|
|||
STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table);
|
||||
#endif
|
||||
|
||||
#if !MICROPY_ENABLE_DYNRUNTIME
|
||||
STATIC const mp_stream_p_t decompio_stream_p = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
||||
.read = decompio_read,
|
||||
};
|
||||
|
||||
STATIC const mp_obj_type_t decompio_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_DecompIO,
|
||||
.make_new = decompio_make_new,
|
||||
.locals_dict = (void *)&decompio_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &decompio_stream_p,
|
||||
),
|
||||
};
|
||||
#if !MICROPY_ENABLE_DYNRUNTIME
|
||||
STATIC MP_DEFINE_CONST_OBJ_TYPE(
|
||||
decompio_type,
|
||||
MP_QSTR_DecompIO,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, decompio_make_new,
|
||||
protocol, &decompio_stream_p,
|
||||
locals_dict, &decompio_locals_dict
|
||||
);
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 84f99f17fc02b03c13f99485d9cf68bc9d17c600
|
||||
Subproject commit 2df210f87a79deedc9003b1bbd6015a2fea7c03e
|
|
@ -95,6 +95,19 @@ STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) {
|
|||
// we assume that first argument come from ticks_xx so is small int
|
||||
mp_uint_t ticks = MP_OBJ_SMALL_INT_VALUE(ticks_in);
|
||||
mp_uint_t delta = mp_obj_get_int(delta_in);
|
||||
|
||||
// Check that delta does not overflow the range that ticks_diff can handle.
|
||||
// This ensures the following:
|
||||
// - ticks_diff(ticks_add(T, delta), T) == delta
|
||||
// - ticks_diff(T, ticks_add(T, delta)) == -delta
|
||||
// The latter requires excluding delta=-TICKS_PERIOD/2.
|
||||
//
|
||||
// This unsigned comparison is equivalent to a signed comparison of:
|
||||
// delta <= -TICKS_PERIOD/2 || delta >= TICKS_PERIOD/2
|
||||
if (delta + MICROPY_PY_UTIME_TICKS_PERIOD / 2 - 1 >= MICROPY_PY_UTIME_TICKS_PERIOD - 1) {
|
||||
mp_raise_msg(&mp_type_OverflowError, MP_ERROR_TEXT("ticks interval overflow"));
|
||||
}
|
||||
|
||||
return MP_OBJ_NEW_SMALL_INT((ticks + delta) & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mp_utime_ticks_add_obj, time_ticks_add);
|
||||
|
|
24
extmod/vfs.c
24
extmod/vfs.c
|
@ -96,11 +96,12 @@ mp_vfs_mount_t *mp_vfs_lookup_path(const char *path, const char **path_out) {
|
|||
STATIC mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) {
|
||||
const char *path = mp_obj_str_get_str(path_in);
|
||||
const char *p_out;
|
||||
*path_out = mp_const_none;
|
||||
mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out);
|
||||
if (vfs != MP_VFS_NONE && vfs != MP_VFS_ROOT) {
|
||||
*path_out = mp_obj_new_str_of_type(mp_obj_get_type(path_in),
|
||||
(const byte *)p_out, strlen(p_out));
|
||||
} else {
|
||||
*path_out = MP_OBJ_NULL;
|
||||
}
|
||||
return vfs;
|
||||
}
|
||||
|
@ -131,8 +132,9 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
|
|||
}
|
||||
|
||||
// If the mounted object has the VFS protocol, call its import_stat helper
|
||||
const mp_vfs_proto_t *proto = (mp_vfs_proto_t *)mp_proto_get(MP_QSTR_protocol_vfs, vfs->obj);
|
||||
if (proto != NULL) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(vfs->obj);
|
||||
if (MP_OBJ_TYPE_HAS_SLOT(type, protocol)) {
|
||||
const mp_vfs_proto_t *proto = MP_OBJ_TYPE_GET_SLOT(type, protocol);
|
||||
return proto->import_stat(MP_OBJ_TO_PTR(vfs->obj), path_out);
|
||||
}
|
||||
|
||||
|
@ -171,7 +173,7 @@ STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) {
|
|||
#if MICROPY_VFS_LFS1
|
||||
if (memcmp(&buf[32], "littlefs", 8) == 0) {
|
||||
// LFS1
|
||||
mp_obj_t vfs = mp_type_vfs_lfs1.make_new(&mp_type_vfs_lfs1, 1, 0, &bdev_obj);
|
||||
mp_obj_t vfs = MP_OBJ_TYPE_GET_SLOT(&mp_type_vfs_lfs1, make_new)(&mp_type_vfs_lfs1, 1, 0, &bdev_obj);
|
||||
nlr_pop();
|
||||
return vfs;
|
||||
}
|
||||
|
@ -179,7 +181,7 @@ STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) {
|
|||
#if MICROPY_VFS_LFS2
|
||||
if (memcmp(&buf[0], "littlefs", 8) == 0) {
|
||||
// LFS2
|
||||
mp_obj_t vfs = mp_type_vfs_lfs2.make_new(&mp_type_vfs_lfs2, 1, 0, &bdev_obj);
|
||||
mp_obj_t vfs = MP_OBJ_TYPE_GET_SLOT(&mp_type_vfs_lfs2, make_new)(&mp_type_vfs_lfs2, 1, 0, &bdev_obj);
|
||||
nlr_pop();
|
||||
return vfs;
|
||||
}
|
||||
|
@ -192,7 +194,7 @@ STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) {
|
|||
#endif
|
||||
|
||||
#if MICROPY_VFS_FAT
|
||||
return mp_fat_vfs_type.make_new(&mp_fat_vfs_type, 1, 0, &bdev_obj);
|
||||
return MP_OBJ_TYPE_GET_SLOT(&mp_fat_vfs_type, make_new)(&mp_fat_vfs_type, 1, 0, &bdev_obj);
|
||||
#endif
|
||||
|
||||
// no filesystem found
|
||||
|
@ -311,7 +313,7 @@ mp_obj_t mp_vfs_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||
#if defined(MICROPY_VFS_POSIX) && MICROPY_VFS_POSIX
|
||||
// If the file is an integer then delegate straight to the POSIX handler
|
||||
if (mp_obj_is_small_int(args[ARG_file].u_obj)) {
|
||||
return mp_vfs_posix_file_open(&mp_type_textio, args[ARG_file].u_obj, args[ARG_mode].u_obj);
|
||||
return mp_vfs_posix_file_open(&mp_type_vfs_posix_textio, args[ARG_file].u_obj, args[ARG_mode].u_obj);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -359,10 +361,11 @@ mp_obj_t mp_vfs_getcwd(void) {
|
|||
if (!(cwd[0] == '/' && cwd[1] == 0)) {
|
||||
vstr_add_str(&vstr, cwd);
|
||||
}
|
||||
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
|
||||
return mp_obj_new_str_from_vstr(&vstr);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(mp_vfs_getcwd_obj, mp_vfs_getcwd);
|
||||
|
||||
// CIRCUITPY: accessible from shared-module/os/__init__.c
|
||||
mp_obj_t mp_vfs_ilistdir_it_iternext(mp_obj_t self_in) {
|
||||
mp_vfs_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (self->is_iter) {
|
||||
|
@ -402,7 +405,7 @@ mp_obj_t mp_vfs_ilistdir(size_t n_args, const mp_obj_t *args) {
|
|||
path_in = MP_OBJ_NEW_QSTR(MP_QSTR_);
|
||||
}
|
||||
|
||||
mp_obj_t path_out = mp_const_none;
|
||||
mp_obj_t path_out;
|
||||
mp_vfs_mount_t *vfs = lookup_path(path_in, &path_out);
|
||||
|
||||
if (vfs == MP_VFS_ROOT) {
|
||||
|
@ -535,4 +538,7 @@ int mp_vfs_mount_and_chdir_protected(mp_obj_t bdev, mp_obj_t mount_point) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
MP_REGISTER_ROOT_POINTER(struct _mp_vfs_mount_t *vfs_cur);
|
||||
MP_REGISTER_ROOT_POINTER(struct _mp_vfs_mount_t *vfs_mount_table);
|
||||
|
||||
#endif // MICROPY_VFS
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
#include "py/mpconfig.h"
|
||||
#if MICROPY_VFS_FAT
|
||||
|
||||
#if !MICROPY_ENABLE_FINALISER
|
||||
#error "MICROPY_VFS_FAT requires MICROPY_ENABLE_FINALISER"
|
||||
#endif
|
||||
|
||||
#if !MICROPY_VFS
|
||||
#error "with MICROPY_VFS_FAT enabled, must also enable MICROPY_VFS"
|
||||
#endif
|
||||
|
@ -41,7 +45,6 @@
|
|||
#include "extmod/vfs_fat.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
#include "supervisor/filesystem.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#if FF_MAX_SS == FF_MIN_SS
|
||||
#define SECSIZE(fs) (FF_MIN_SS)
|
||||
|
@ -133,6 +136,7 @@ STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(fat_vfs_mkfs_obj, MP_ROM_PTR(&fat_vfs_mk
|
|||
typedef struct _mp_vfs_fat_ilistdir_it_t {
|
||||
mp_obj_base_t base;
|
||||
mp_fun_1_t iternext;
|
||||
mp_fun_1_t finaliser;
|
||||
bool is_str;
|
||||
FF_DIR dir;
|
||||
} mp_vfs_fat_ilistdir_it_t;
|
||||
|
@ -177,6 +181,13 @@ STATIC mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) {
|
|||
return MP_OBJ_STOP_ITERATION;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_vfs_fat_ilistdir_it_del(mp_obj_t self_in) {
|
||||
mp_vfs_fat_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
// ignore result / error because we may be closing a second time.
|
||||
f_closedir(&self->dir);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
bool is_str_type = true;
|
||||
|
@ -191,8 +202,10 @@ STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
|
||||
// Create a new iterator object to list the dir
|
||||
mp_vfs_fat_ilistdir_it_t *iter = mp_obj_malloc(mp_vfs_fat_ilistdir_it_t, &mp_type_polymorph_iter);
|
||||
mp_vfs_fat_ilistdir_it_t *iter = m_new_obj_with_finaliser(mp_vfs_fat_ilistdir_it_t);
|
||||
iter->base.type = &mp_type_polymorph_iter_with_finaliser;
|
||||
iter->iternext = mp_vfs_fat_ilistdir_it_iternext;
|
||||
iter->finaliser = mp_vfs_fat_ilistdir_it_del;
|
||||
iter->is_str = is_str_type;
|
||||
FRESULT res = f_opendir(&self->fatfs, &iter->dir, path);
|
||||
if (res != FR_OK) {
|
||||
|
@ -524,16 +537,13 @@ STATIC const mp_vfs_proto_t fat_vfs_proto = {
|
|||
.import_stat = fat_vfs_import_stat,
|
||||
};
|
||||
|
||||
const mp_obj_type_t mp_fat_vfs_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_VfsFat,
|
||||
.make_new = fat_vfs_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&fat_vfs_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &fat_vfs_proto,
|
||||
),
|
||||
|
||||
};
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
mp_fat_vfs_type,
|
||||
MP_QSTR_VfsFat,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, fat_vfs_make_new,
|
||||
protocol, &fat_vfs_proto,
|
||||
locals_dict, &fat_vfs_locals_dict
|
||||
);
|
||||
|
||||
#endif // MICROPY_VFS_FAT
|
||||
|
|
|
@ -148,19 +148,64 @@ STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
|
|||
}
|
||||
}
|
||||
|
||||
// Note: encoding is ignored for now; it's also not a valid kwarg for CPython's FileIO,
|
||||
// but by adding it here we can use one single mp_arg_t array for open() and FileIO's constructor
|
||||
STATIC const mp_arg_t file_open_args[] = {
|
||||
{ MP_QSTR_file, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE} },
|
||||
{ MP_QSTR_mode, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_QSTR(MP_QSTR_r)} },
|
||||
{ MP_QSTR_encoding, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
|
||||
// TODO gc hook to close the file if not already closed
|
||||
|
||||
STATIC const mp_rom_map_elem_t vfs_fat_rawfile_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readlines), MP_ROM_PTR(&mp_stream_unbuffered_readlines_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_seek), MP_ROM_PTR(&mp_stream_seek_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_tell), MP_ROM_PTR(&mp_stream_tell_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&file_obj___exit___obj) },
|
||||
};
|
||||
#define FILE_OPEN_NUM_ARGS MP_ARRAY_SIZE(file_open_args)
|
||||
|
||||
// CIRCUITPY is more careful about validating the open mode.
|
||||
STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_arg_val_t *args) {
|
||||
STATIC MP_DEFINE_CONST_DICT(vfs_fat_rawfile_locals_dict, vfs_fat_rawfile_locals_dict_table);
|
||||
|
||||
STATIC const mp_stream_p_t vfs_fat_fileio_stream_p = {
|
||||
.read = file_obj_read,
|
||||
.write = file_obj_write,
|
||||
.ioctl = file_obj_ioctl,
|
||||
};
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
mp_type_vfs_fat_fileio,
|
||||
MP_QSTR_FileIO,
|
||||
MP_TYPE_FLAG_ITER_IS_STREAM,
|
||||
print, file_obj_print,
|
||||
protocol, &vfs_fat_fileio_stream_p,
|
||||
locals_dict, &vfs_fat_rawfile_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_stream_p_t vfs_fat_textio_stream_p = {
|
||||
.read = file_obj_read,
|
||||
.write = file_obj_write,
|
||||
.ioctl = file_obj_ioctl,
|
||||
.is_text = true,
|
||||
};
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
mp_type_vfs_fat_textio,
|
||||
MP_QSTR_TextIOWrapper,
|
||||
MP_TYPE_FLAG_ITER_IS_STREAM,
|
||||
print, file_obj_print,
|
||||
protocol, &vfs_fat_textio_stream_p,
|
||||
locals_dict, &vfs_fat_rawfile_locals_dict
|
||||
);
|
||||
|
||||
// Factory function for I/O stream classes
|
||||
STATIC mp_obj_t fat_vfs_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) {
|
||||
fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
const mp_obj_type_t *type = &mp_type_vfs_fat_textio;
|
||||
int mode = 0;
|
||||
const char *mode_s = mp_obj_str_get_str(args[1].u_obj);
|
||||
const char *mode_s = mp_obj_str_get_str(mode_in);
|
||||
uint32_t rwxa_count = 0;
|
||||
uint32_t bt_count = 0;
|
||||
uint32_t plus_count = 0;
|
||||
|
@ -187,12 +232,10 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
|
|||
mode |= FA_READ | FA_WRITE;
|
||||
plus_count++;
|
||||
break;
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
case 'b':
|
||||
bt_count++;
|
||||
type = &mp_type_vfs_fat_fileio;
|
||||
break;
|
||||
#endif
|
||||
case 't':
|
||||
bt_count++;
|
||||
type = &mp_type_vfs_fat_textio;
|
||||
|
@ -207,8 +250,8 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
|
|||
mp_arg_error_invalid(MP_QSTR_mode);
|
||||
}
|
||||
|
||||
assert(vfs != NULL);
|
||||
if ((mode & FA_WRITE) != 0 && !filesystem_is_writable_by_python(vfs)) {
|
||||
assert(self != NULL);
|
||||
if ((mode & FA_WRITE) != 0 && !filesystem_is_writable_by_python(self)) {
|
||||
mp_raise_OSError(MP_EROFS);
|
||||
}
|
||||
|
||||
|
@ -216,12 +259,13 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
|
|||
pyb_file_obj_t *o = m_new_obj_with_finaliser(pyb_file_obj_t);
|
||||
o->base.type = type;
|
||||
|
||||
const char *fname = mp_obj_str_get_str(args[0].u_obj);
|
||||
FRESULT res = f_open(&vfs->fatfs, &o->fp, fname, mode);
|
||||
const char *fname = mp_obj_str_get_str(path_in);
|
||||
FRESULT res = f_open(&self->fatfs, &o->fp, fname, mode);
|
||||
if (res != FR_OK) {
|
||||
m_del_obj(pyb_file_obj_t, o);
|
||||
mp_raise_OSError_errno_str(fresult_to_errno_table[res], args[0].u_obj);
|
||||
mp_raise_OSError_errno_str(fresult_to_errno_table[res], path_in);
|
||||
}
|
||||
// CIRCUITPY does fast seek.
|
||||
// If we're reading, turn on fast seek.
|
||||
if (mode == FA_READ) {
|
||||
// One call to determine how much space we need.
|
||||
|
@ -249,87 +293,6 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
|
|||
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t file_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals);
|
||||
return file_open(NULL, type, arg_vals);
|
||||
}
|
||||
|
||||
// TODO gc hook to close the file if not already closed
|
||||
|
||||
STATIC const mp_rom_map_elem_t vfs_fat_rawfile_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_readlines), MP_ROM_PTR(&mp_stream_unbuffered_readlines_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_seek), MP_ROM_PTR(&mp_stream_seek_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_tell), MP_ROM_PTR(&mp_stream_tell_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&file_obj___exit___obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(vfs_fat_rawfile_locals_dict, vfs_fat_rawfile_locals_dict_table);
|
||||
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
STATIC const mp_stream_p_t vfs_fat_fileio_stream_p = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
||||
.read = file_obj_read,
|
||||
.write = file_obj_write,
|
||||
.ioctl = file_obj_ioctl,
|
||||
};
|
||||
|
||||
const mp_obj_type_t mp_type_vfs_fat_fileio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_FileIO,
|
||||
.print = file_obj_print,
|
||||
.make_new = file_obj_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_fat_rawfile_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_fat_fileio_stream_p,
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
STATIC const mp_stream_p_t vfs_fat_textio_stream_p = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
||||
.read = file_obj_read,
|
||||
.write = file_obj_write,
|
||||
.ioctl = file_obj_ioctl,
|
||||
.is_text = true,
|
||||
};
|
||||
|
||||
const mp_obj_type_t mp_type_vfs_fat_textio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_TextIOWrapper,
|
||||
.print = file_obj_print,
|
||||
.make_new = file_obj_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_fat_rawfile_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_fat_textio_stream_p,
|
||||
),
|
||||
};
|
||||
|
||||
// Factory function for I/O stream classes
|
||||
STATIC mp_obj_t fatfs_builtin_open_self(mp_obj_t self_in, mp_obj_t path, mp_obj_t mode) {
|
||||
// TODO: analyze buffering args and instantiate appropriate type
|
||||
fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS];
|
||||
arg_vals[0].u_obj = path;
|
||||
arg_vals[1].u_obj = mode;
|
||||
arg_vals[2].u_obj = mp_const_none;
|
||||
return file_open(self, &mp_type_vfs_fat_textio, arg_vals);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_open_obj, fatfs_builtin_open_self);
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_open_obj, fat_vfs_open);
|
||||
|
||||
#endif // MICROPY_VFS && MICROPY_VFS_FAT
|
||||
|
|
|
@ -26,12 +26,13 @@
|
|||
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
|
||||
#if MICROPY_VFS && (MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2)
|
||||
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
#include "extmod/vfs.h"
|
||||
#include "extmod/vfs_lfs.h"
|
||||
|
||||
#if MICROPY_VFS && (MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2)
|
||||
|
||||
enum { LFS_MAKE_ARG_bdev, LFS_MAKE_ARG_readsize, LFS_MAKE_ARG_progsize, LFS_MAKE_ARG_lookahead, LFS_MAKE_ARG_mtime };
|
||||
|
||||
static const mp_arg_t lfs_make_allowed_args[] = {
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// This file should be compiled when included from vfs_lfs.c.
|
||||
#if defined(LFS_BUILD_VERSION)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -36,6 +39,10 @@
|
|||
#include "extmod/vfs.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
|
||||
#if !MICROPY_ENABLE_FINALISER
|
||||
#error "MICROPY_VFS_LFS requires MICROPY_ENABLE_FINALISER"
|
||||
#endif
|
||||
|
||||
STATIC int MP_VFS_LFSx(dev_ioctl)(const struct LFSx_API (config) * c, int cmd, int arg, bool must_return_int) {
|
||||
mp_obj_t ret = mp_vfs_blockdev_ioctl(c->context, cmd, arg);
|
||||
int ret_i = 0;
|
||||
|
@ -155,6 +162,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(open_obj), MP_VFS_LFSx(file_open));
|
|||
typedef struct MP_VFS_LFSx (_ilistdir_it_t) {
|
||||
mp_obj_base_t base;
|
||||
mp_fun_1_t iternext;
|
||||
mp_fun_1_t finaliser;
|
||||
bool is_str;
|
||||
MP_OBJ_VFS_LFSx *vfs;
|
||||
LFSx_API(dir_t) dir;
|
||||
|
@ -163,11 +171,16 @@ typedef struct MP_VFS_LFSx (_ilistdir_it_t) {
|
|||
STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) {
|
||||
MP_VFS_LFSx(ilistdir_it_t) * self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (self->vfs == NULL) {
|
||||
return MP_OBJ_STOP_ITERATION;
|
||||
}
|
||||
|
||||
struct LFSx_API (info) info;
|
||||
for (;;) {
|
||||
int ret = LFSx_API(dir_read)(&self->vfs->lfs, &self->dir, &info);
|
||||
if (ret == 0) {
|
||||
LFSx_API(dir_close)(&self->vfs->lfs, &self->dir);
|
||||
self->vfs = NULL;
|
||||
return MP_OBJ_STOP_ITERATION;
|
||||
}
|
||||
if (!(info.name[0] == '.' && (info.name[1] == '\0'
|
||||
|
@ -190,6 +203,14 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) {
|
|||
return MP_OBJ_FROM_PTR(t);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_del)(mp_obj_t self_in) {
|
||||
MP_VFS_LFSx(ilistdir_it_t) * self = MP_OBJ_TO_PTR(self_in);
|
||||
if (self->vfs != NULL) {
|
||||
LFSx_API(dir_close)(&self->vfs->lfs, &self->dir);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args) {
|
||||
MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(args[0]);
|
||||
bool is_str_type = true;
|
||||
|
@ -203,14 +224,17 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args)
|
|||
path = vstr_null_terminated_str(&self->cur_dir);
|
||||
}
|
||||
|
||||
MP_VFS_LFSx(ilistdir_it_t) * iter = mp_obj_malloc(MP_VFS_LFSx(ilistdir_it_t), &mp_type_polymorph_iter);
|
||||
MP_VFS_LFSx(ilistdir_it_t) * iter = m_new_obj_with_finaliser(MP_VFS_LFSx(ilistdir_it_t));
|
||||
iter->base.type = &mp_type_polymorph_iter_with_finaliser;
|
||||
|
||||
iter->iternext = MP_VFS_LFSx(ilistdir_it_iternext);
|
||||
iter->finaliser = MP_VFS_LFSx(ilistdir_it_del);
|
||||
iter->is_str = is_str_type;
|
||||
iter->vfs = self;
|
||||
int ret = LFSx_API(dir_open)(&self->lfs, &iter->dir, path);
|
||||
if (ret < 0) {
|
||||
mp_raise_OSError(-ret);
|
||||
}
|
||||
iter->vfs = self;
|
||||
return MP_OBJ_FROM_PTR(iter);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(MP_VFS_LFSx(ilistdir_obj), 1, 2, MP_VFS_LFSx(ilistdir_func));
|
||||
|
@ -481,17 +505,21 @@ STATIC const mp_vfs_proto_t MP_VFS_LFSx(proto) = {
|
|||
.import_stat = MP_VFS_LFSx(import_stat),
|
||||
};
|
||||
|
||||
const mp_obj_type_t MP_TYPE_VFS_LFSx = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
#if LFS_BUILD_VERSION == 1
|
||||
.name = MP_QSTR_VfsLfs1,
|
||||
#else
|
||||
.name = MP_QSTR_VfsLfs2,
|
||||
#endif
|
||||
.make_new = MP_VFS_LFSx(make_new),
|
||||
.locals_dict = (mp_obj_dict_t *)&MP_VFS_LFSx(locals_dict),
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &MP_VFS_LFSx(proto),
|
||||
),
|
||||
};
|
||||
#if LFS_BUILD_VERSION == 1
|
||||
#define VFS_LFSx_QSTR MP_QSTR_VfsLfs1
|
||||
#else
|
||||
#define VFS_LFSx_QSTR MP_QSTR_VfsLfs2
|
||||
#endif
|
||||
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
MP_TYPE_VFS_LFSx,
|
||||
VFS_LFSx_QSTR,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, MP_VFS_LFSx(make_new),
|
||||
protocol, &MP_VFS_LFSx(proto),
|
||||
locals_dict, &MP_VFS_LFSx(locals_dict)
|
||||
);
|
||||
|
||||
#undef VFS_LFSx_QSTR
|
||||
|
||||
#endif // defined(LFS_BUILD_VERSION)
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// This file should be compiled when included from vfs_lfs.c.
|
||||
#if defined(LFS_BUILD_VERSION)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -68,11 +71,9 @@ mp_obj_t MP_VFS_LFSx(file_open)(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mod
|
|||
case '+':
|
||||
flags |= LFSx_MACRO(_O_RDWR);
|
||||
break;
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
case 'b':
|
||||
type = &MP_TYPE_VFS_LFSx_(_fileio);
|
||||
break;
|
||||
#endif
|
||||
case 't':
|
||||
type = &MP_TYPE_VFS_LFSx_(_textio);
|
||||
break;
|
||||
|
@ -216,45 +217,35 @@ STATIC const mp_rom_map_elem_t MP_VFS_LFSx(file_locals_dict_table)[] = {
|
|||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(MP_VFS_LFSx(file_locals_dict), MP_VFS_LFSx(file_locals_dict_table));
|
||||
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
STATIC const mp_stream_p_t MP_VFS_LFSx(fileio_stream_p) = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
||||
.read = MP_VFS_LFSx(file_read),
|
||||
.write = MP_VFS_LFSx(file_write),
|
||||
.ioctl = MP_VFS_LFSx(file_ioctl),
|
||||
};
|
||||
|
||||
const mp_obj_type_t MP_TYPE_VFS_LFSx_(_fileio) = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_FileIO,
|
||||
.print = MP_VFS_LFSx(file_print),
|
||||
.locals_dict = (mp_obj_dict_t *)&MP_VFS_LFSx(file_locals_dict),
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &MP_VFS_LFSx(fileio_stream_p),
|
||||
),
|
||||
};
|
||||
#endif
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
MP_TYPE_VFS_LFSx_(_fileio),
|
||||
MP_QSTR_FileIO,
|
||||
MP_TYPE_FLAG_ITER_IS_STREAM,
|
||||
print, MP_VFS_LFSx(file_print),
|
||||
protocol, &MP_VFS_LFSx(fileio_stream_p),
|
||||
locals_dict, &MP_VFS_LFSx(file_locals_dict)
|
||||
);
|
||||
|
||||
STATIC const mp_stream_p_t MP_VFS_LFSx(textio_stream_p) = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
||||
.read = MP_VFS_LFSx(file_read),
|
||||
.write = MP_VFS_LFSx(file_write),
|
||||
.ioctl = MP_VFS_LFSx(file_ioctl),
|
||||
.is_text = true,
|
||||
};
|
||||
|
||||
const mp_obj_type_t MP_TYPE_VFS_LFSx_(_textio) = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_TextIOWrapper,
|
||||
.print = MP_VFS_LFSx(file_print),
|
||||
.locals_dict = (mp_obj_dict_t *)&MP_VFS_LFSx(file_locals_dict),
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &MP_VFS_LFSx(textio_stream_p),
|
||||
),
|
||||
};
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
MP_TYPE_VFS_LFSx_(_textio),
|
||||
MP_QSTR_TextIOWrapper,
|
||||
MP_TYPE_FLAG_ITER_IS_STREAM,
|
||||
print, MP_VFS_LFSx(file_print),
|
||||
protocol, &MP_VFS_LFSx(textio_stream_p),
|
||||
locals_dict, &MP_VFS_LFSx(file_locals_dict)
|
||||
);
|
||||
|
||||
#endif // defined(LFS_BUILD_VERSION)
|
||||
|
|
|
@ -31,11 +31,17 @@
|
|||
#include "extmod/vfs.h"
|
||||
#include "extmod/vfs_posix.h"
|
||||
|
||||
#if defined(MICROPY_VFS_POSIX) && MICROPY_VFS_POSIX
|
||||
#if MICROPY_VFS_POSIX
|
||||
|
||||
#if !MICROPY_ENABLE_FINALISER
|
||||
#error "MICROPY_VFS_POSIX requires MICROPY_ENABLE_FINALISER"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#ifdef _MSC_VER
|
||||
#include <direct.h> // For mkdir etc.
|
||||
|
@ -138,7 +144,7 @@ STATIC mp_obj_t vfs_posix_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode
|
|||
if (!mp_obj_is_small_int(path_in)) {
|
||||
path_in = vfs_posix_get_path_obj(self, path_in);
|
||||
}
|
||||
return mp_vfs_posix_file_open(&mp_type_textio, path_in, mode_in);
|
||||
return mp_vfs_posix_file_open(&mp_type_vfs_posix_textio, path_in, mode_in);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_open_obj, vfs_posix_open);
|
||||
|
||||
|
@ -162,6 +168,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_getcwd_obj, vfs_posix_getcwd);
|
|||
typedef struct _vfs_posix_ilistdir_it_t {
|
||||
mp_obj_base_t base;
|
||||
mp_fun_1_t iternext;
|
||||
mp_fun_1_t finaliser;
|
||||
bool is_str;
|
||||
DIR *dir;
|
||||
} vfs_posix_ilistdir_it_t;
|
||||
|
@ -185,7 +192,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) {
|
|||
MP_THREAD_GIL_ENTER();
|
||||
const char *fn = dirent->d_name;
|
||||
|
||||
if (fn[0] == '.' && (fn[1] == 0 || fn[1] == '.')) {
|
||||
if (fn[0] == '.' && (fn[1] == 0 || (fn[1] == '.' && fn[2] == 0))) {
|
||||
// skip . and ..
|
||||
continue;
|
||||
}
|
||||
|
@ -226,10 +233,22 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) {
|
|||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) {
|
||||
vfs_posix_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (self->dir != NULL) {
|
||||
MP_THREAD_GIL_EXIT();
|
||||
closedir(self->dir);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) {
|
||||
mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
vfs_posix_ilistdir_it_t *iter = mp_obj_malloc(vfs_posix_ilistdir_it_t, &mp_type_polymorph_iter);
|
||||
vfs_posix_ilistdir_it_t *iter = m_new_obj_with_finaliser(vfs_posix_ilistdir_it_t);
|
||||
iter->base.type = &mp_type_polymorph_iter_with_finaliser;
|
||||
iter->iternext = vfs_posix_ilistdir_it_iternext;
|
||||
iter->finaliser = vfs_posix_ilistdir_it_del;
|
||||
iter->is_str = mp_obj_get_type(path_in) == &mp_type_str;
|
||||
const char *path = vfs_posix_get_path_str(self, path_in);
|
||||
if (path[0] == '\0') {
|
||||
|
@ -378,19 +397,16 @@ STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = {
|
|||
STATIC MP_DEFINE_CONST_DICT(vfs_posix_locals_dict, vfs_posix_locals_dict_table);
|
||||
|
||||
STATIC const mp_vfs_proto_t vfs_posix_proto = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_vfs)
|
||||
.import_stat = mp_vfs_posix_import_stat,
|
||||
};
|
||||
|
||||
const mp_obj_type_t mp_type_vfs_posix = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_VfsPosix,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_posix_locals_dict,
|
||||
.make_new = vfs_posix_make_new,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &vfs_posix_proto,
|
||||
),
|
||||
};
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
mp_type_vfs_posix,
|
||||
MP_QSTR_VfsPosix,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
make_new, vfs_posix_make_new,
|
||||
protocol, &vfs_posix_proto,
|
||||
locals_dict, &vfs_posix_locals_dict
|
||||
);
|
||||
|
||||
#endif // MICROPY_VFS_POSIX
|
||||
|
|
|
@ -29,9 +29,8 @@
|
|||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "extmod/vfs_posix.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#if (defined(MICROPY_VFS_POSIX) && MICROPY_VFS_POSIX) || (defined(MICROPY_VFS_POSIX_FILE) && MICROPY_VFS_POSIX_FILE)
|
||||
#if MICROPY_VFS_POSIX
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
@ -47,7 +46,7 @@ typedef struct _mp_obj_vfs_posix_file_t {
|
|||
int fd;
|
||||
} mp_obj_vfs_posix_file_t;
|
||||
|
||||
#ifdef MICROPY_CPYTHON_COMPAT
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) {
|
||||
if (o->fd < 0) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file"));
|
||||
|
@ -60,11 +59,11 @@ STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) {
|
|||
STATIC void vfs_posix_file_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
mp_obj_vfs_posix_file_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "<io.%q %d>", mp_obj_get_type_qstr(self_in), self->fd);
|
||||
mp_printf(print, "<io.%s %d>", mp_obj_get_type_str(self_in), self->fd);
|
||||
}
|
||||
|
||||
mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_obj_t mode_in) {
|
||||
mp_obj_vfs_posix_file_t *o = m_new_obj(mp_obj_vfs_posix_file_t);
|
||||
mp_obj_vfs_posix_file_t *o = m_new_obj_with_finaliser(mp_obj_vfs_posix_file_t);
|
||||
const char *mode_s = mp_obj_str_get_str(mode_in);
|
||||
|
||||
int mode_rw = 0, mode_x = 0;
|
||||
|
@ -84,15 +83,12 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
|
|||
case '+':
|
||||
mode_rw = O_RDWR;
|
||||
break;
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
// If we don't have io.FileIO, then files are in text mode implicitly
|
||||
case 'b':
|
||||
type = &mp_type_vfs_posix_fileio;
|
||||
break;
|
||||
case 't':
|
||||
type = &mp_type_vfs_posix_textio;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,17 +108,6 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_
|
|||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t vfs_posix_file_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_file, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE} },
|
||||
{ MP_QSTR_mode, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_QSTR(MP_QSTR_r)} },
|
||||
};
|
||||
|
||||
mp_arg_val_t arg_vals[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, arg_vals);
|
||||
return mp_vfs_posix_file_open(type, arg_vals[0].u_obj, arg_vals[1].u_obj);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t vfs_posix_file_fileno(mp_obj_t self_in) {
|
||||
mp_obj_vfs_posix_file_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_fd_is_open(self);
|
||||
|
@ -150,6 +135,12 @@ STATIC mp_uint_t vfs_posix_file_read(mp_obj_t o_in, void *buf, mp_uint_t size, i
|
|||
STATIC mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
|
||||
mp_obj_vfs_posix_file_t *o = MP_OBJ_TO_PTR(o_in);
|
||||
check_fd_is_open(o);
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
if (o->fd <= STDERR_FILENO) {
|
||||
mp_hal_stdout_tx_strn(buf, size);
|
||||
return size;
|
||||
}
|
||||
#endif
|
||||
ssize_t r;
|
||||
MP_HAL_RETRY_SYSCALL(r, write(o->fd, buf, size), {
|
||||
*errcode = err;
|
||||
|
@ -194,12 +185,12 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_
|
|||
return 0;
|
||||
}
|
||||
case MP_STREAM_CLOSE:
|
||||
MP_THREAD_GIL_EXIT();
|
||||
close(o->fd);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
#ifdef MICROPY_CPYTHON_COMPAT
|
||||
if (o->fd >= 0) {
|
||||
MP_THREAD_GIL_EXIT();
|
||||
close(o->fd);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
}
|
||||
o->fd = -1;
|
||||
#endif
|
||||
return 0;
|
||||
case MP_STREAM_GET_FILENO:
|
||||
return o->fd;
|
||||
|
@ -246,59 +237,46 @@ STATIC const mp_rom_map_elem_t vfs_posix_rawfile_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_tell), MP_ROM_PTR(&mp_stream_tell_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&vfs_posix_file___exit___obj) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(vfs_posix_rawfile_locals_dict, vfs_posix_rawfile_locals_dict_table);
|
||||
|
||||
#if MICROPY_PY_IO_FILEIO
|
||||
STATIC const mp_stream_p_t vfs_posix_fileio_stream_p = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
||||
.read = vfs_posix_file_read,
|
||||
.write = vfs_posix_file_write,
|
||||
.ioctl = vfs_posix_file_ioctl,
|
||||
};
|
||||
|
||||
const mp_obj_type_t mp_type_vfs_posix_fileio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_FileIO,
|
||||
.print = vfs_posix_file_print,
|
||||
.make_new = vfs_posix_file_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_posix_rawfile_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_posix_fileio_stream_p,
|
||||
),
|
||||
};
|
||||
#endif
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
mp_type_vfs_posix_fileio,
|
||||
MP_QSTR_FileIO,
|
||||
MP_TYPE_FLAG_ITER_IS_STREAM,
|
||||
print, vfs_posix_file_print,
|
||||
protocol, &vfs_posix_fileio_stream_p,
|
||||
locals_dict, &vfs_posix_rawfile_locals_dict
|
||||
);
|
||||
|
||||
STATIC const mp_stream_p_t vfs_posix_textio_stream_p = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
|
||||
.read = vfs_posix_file_read,
|
||||
.write = vfs_posix_file_write,
|
||||
.ioctl = vfs_posix_file_ioctl,
|
||||
.is_text = true,
|
||||
};
|
||||
|
||||
const mp_obj_type_t mp_type_vfs_posix_textio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_TextIOWrapper,
|
||||
.print = vfs_posix_file_print,
|
||||
.make_new = vfs_posix_file_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_posix_rawfile_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_posix_textio_stream_p,
|
||||
),
|
||||
};
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
mp_type_vfs_posix_textio,
|
||||
MP_QSTR_TextIOWrapper,
|
||||
MP_TYPE_FLAG_ITER_IS_STREAM,
|
||||
print, vfs_posix_file_print,
|
||||
protocol, &vfs_posix_textio_stream_p,
|
||||
locals_dict, &vfs_posix_rawfile_locals_dict
|
||||
);
|
||||
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_textio}, STDIN_FILENO};
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_textio}, STDOUT_FILENO};
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_textio}, STDERR_FILENO};
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_vfs_posix_textio}, STDIN_FILENO};
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stdout_obj = {{&mp_type_vfs_posix_textio}, STDOUT_FILENO};
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stderr_obj = {{&mp_type_vfs_posix_textio}, STDERR_FILENO};
|
||||
|
||||
#endif // MICROPY_VFS_POSIX || MICROPY_VFS_POSIX_FILE
|
||||
#endif // MICROPY_VFS_POSIX
|
||||
|
|
|
@ -25,16 +25,15 @@
|
|||
*/
|
||||
|
||||
#include "extmod/virtpin.h"
|
||||
#include "py/proto.h"
|
||||
|
||||
int mp_virtual_pin_read(mp_obj_t pin) {
|
||||
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(pin);
|
||||
const mp_pin_p_t *pin_p = mp_proto_get(MP_QSTR_protocol_pin, s);
|
||||
mp_pin_p_t *pin_p = (mp_pin_p_t *)MP_OBJ_TYPE_GET_SLOT(s->type, protocol);
|
||||
return pin_p->ioctl(pin, MP_PIN_READ, 0, NULL);
|
||||
}
|
||||
|
||||
void mp_virtual_pin_write(mp_obj_t pin, int value) {
|
||||
mp_obj_base_t *s = (mp_obj_base_t *)MP_OBJ_TO_PTR(pin);
|
||||
const mp_pin_p_t *pin_p = mp_proto_get(MP_QSTR_protocol_pin, s);
|
||||
mp_pin_p_t *pin_p = (mp_pin_p_t *)MP_OBJ_TYPE_GET_SLOT(s->type, protocol);
|
||||
pin_p->ioctl(pin, MP_PIN_WRITE, value, NULL);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 7c25d09be04a2979bcfb43b801de57594112808d
|
||||
Subproject commit c277db5ae86805006f563b782e0a85832a5c3450
|
|
@ -3,7 +3,7 @@
|
|||
#include <math.h>
|
||||
|
||||
float sqrtf(float x) {
|
||||
asm volatile (
|
||||
__asm__ volatile (
|
||||
"vsqrt.f32 %[r], %[x]\n"
|
||||
: [r] "=t" (x)
|
||||
: [x] "t" (x));
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
double sqrt(double x) {
|
||||
double ret;
|
||||
asm volatile (
|
||||
__asm__ volatile (
|
||||
"vsqrt.f64 %P0, %P1\n"
|
||||
: "=w" (ret)
|
||||
: "w" (x));
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit e6b89eafa3b86d2e8e405450377d459600a30cd6
|
|
@ -72,8 +72,8 @@
|
|||
#define FF_USE_MKFS 1
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
#ifdef MICROPY_FF_MKFS_FAT32
|
||||
#define FF_MKFS_FAT32 MICROPY_FF_MKFS_FAT32
|
||||
#ifdef MICROPY_FATFS_MKFS_FAT32
|
||||
#define FF_MKFS_FAT32 MICROPY_FATFS_MKFS_FAT32
|
||||
#else
|
||||
#define FF_MKFS_FAT32 0
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,15 @@ int _re1_5_classmatch(const char *pc, const char *sp)
|
|||
int is_positive = (pc[-1] == Class);
|
||||
int cnt = *pc++;
|
||||
while (cnt--) {
|
||||
if (*sp >= *pc && *sp <= pc[1]) return is_positive;
|
||||
if (*pc == RE15_CLASS_NAMED_CLASS_INDICATOR) {
|
||||
if (_re1_5_namedclassmatch(pc + 1, sp)) {
|
||||
return is_positive;
|
||||
}
|
||||
} else {
|
||||
if (*sp >= *pc && *sp <= pc[1]) {
|
||||
return is_positive;
|
||||
}
|
||||
}
|
||||
pc += 2;
|
||||
}
|
||||
return !is_positive;
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
#include "re1.5.h"
|
||||
|
||||
// Matches: DSWdsw
|
||||
#define MATCH_NAMED_CLASS_CHAR(c) (((c) | 0x20) == 'd' || ((c) | 0x24) == 'w')
|
||||
|
||||
#define INSERT_CODE(at, num, pc) \
|
||||
((code ? memmove(code + at + num, code + at, pc - at) : 0), pc += num)
|
||||
#define REL(at, to) (to - at - 2)
|
||||
|
@ -32,7 +35,6 @@ static char unescape(char c) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void _emit_checked(int at, char *code, int val, bool *err) {
|
||||
*err |= val != (int8_t)val;
|
||||
if (code) {
|
||||
|
@ -54,7 +56,7 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
|
|||
re++;
|
||||
if (!*re) return NULL; // Trailing backslash
|
||||
term = PC;
|
||||
if ((*re | 0x20) == 'd' || (*re | 0x20) == 's' || (*re | 0x20) == 'w') {
|
||||
if (MATCH_NAMED_CLASS_CHAR(*re)) {
|
||||
EMIT(PC++, NamedClass);
|
||||
EMIT(PC++, *re);
|
||||
} else {
|
||||
|
@ -87,27 +89,24 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
|
|||
PC++; // Skip # of pair byte
|
||||
prog->len++;
|
||||
for (cnt = 0; *re != ']'; re++, cnt++) {
|
||||
if (!*re) return NULL;
|
||||
const char *b = re;
|
||||
if (*re == '\\') {
|
||||
re += 1;
|
||||
if (!*re) return NULL; // Trailing backslash
|
||||
EMIT(PC++, unescape(*re));
|
||||
} else {
|
||||
EMIT(PC++, *re);
|
||||
char c = *re;
|
||||
if (c == '\\') {
|
||||
++re;
|
||||
c = *re;
|
||||
if (MATCH_NAMED_CLASS_CHAR(c)) {
|
||||
c = RE15_CLASS_NAMED_CLASS_INDICATOR;
|
||||
goto emit_char_pair;
|
||||
} else {
|
||||
c = unescape(c);
|
||||
}
|
||||
}
|
||||
if (!c) return NULL;
|
||||
if (re[1] == '-' && re[2] != ']') {
|
||||
re += 2;
|
||||
} else {
|
||||
re = b;
|
||||
}
|
||||
if (*re == '\\') {
|
||||
re += 1;
|
||||
if (!*re) return NULL; // Trailing backslash
|
||||
EMIT(PC++, unescape(*re));
|
||||
} else {
|
||||
EMIT(PC++, *re);
|
||||
}
|
||||
emit_char_pair:
|
||||
EMIT(PC++, c);
|
||||
EMIT(PC++, *re);
|
||||
}
|
||||
EMIT_CHECKED(term + 1, cnt);
|
||||
break;
|
||||
|
@ -255,6 +254,7 @@ int re1_5_compilecode(ByteProg *prog, const char *re)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// CIRCUITPY debug as main program
|
||||
#if defined(DEBUG_COMPILECODE)
|
||||
#include <assert.h>
|
||||
void re1_5_fatal(char *x) {
|
||||
|
|
|
@ -140,6 +140,7 @@ struct Subject {
|
|||
|
||||
#define NON_ANCHORED_PREFIX 5
|
||||
#define HANDLE_ANCHORED(bytecode, is_anchored) ((is_anchored) ? (bytecode) + NON_ANCHORED_PREFIX : (bytecode))
|
||||
#define RE15_CLASS_NAMED_CLASS_INDICATOR 0
|
||||
|
||||
int re1_5_backtrack(ByteProg*, Subject*, const char**, int, int);
|
||||
int re1_5_pikevm(ByteProg*, Subject*, const char**, int, int);
|
||||
|
|
|
@ -139,7 +139,7 @@ msgstr ""
|
|||
msgid "%q in use"
|
||||
msgstr ""
|
||||
|
||||
#: py/objstr.c py/objstrunicode.c
|
||||
#: py/objstr.c
|
||||
msgid "%q index out of range"
|
||||
msgstr ""
|
||||
|
||||
|
@ -226,7 +226,7 @@ msgstr ""
|
|||
msgid "%q must be of type %q or %q, not %q"
|
||||
msgstr ""
|
||||
|
||||
#: py/argcheck.c py/objstrunicode.c shared-module/synthio/__init__.c
|
||||
#: py/argcheck.c shared-module/synthio/__init__.c
|
||||
msgid "%q must be of type %q, not %q"
|
||||
msgstr ""
|
||||
|
||||
|
@ -279,6 +279,11 @@ msgstr ""
|
|||
msgid "%q[%u] waits on input outside of count"
|
||||
msgstr ""
|
||||
|
||||
#: py/runtime.c
|
||||
#, c-format
|
||||
msgid "%s"
|
||||
msgstr ""
|
||||
|
||||
#: ports/espressif/common-hal/espidf/__init__.c
|
||||
#, c-format
|
||||
msgid "%s error 0x%x"
|
||||
|
@ -1954,10 +1959,6 @@ msgstr ""
|
|||
msgid "Specify exactly one of data0 or data_pins"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/modure.c
|
||||
msgid "Splitting with sub-captures"
|
||||
msgstr ""
|
||||
|
||||
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
|
||||
msgid "Stereo left must be on PWM channel A"
|
||||
msgstr ""
|
||||
|
@ -2394,7 +2395,8 @@ msgid "__init__() should return None"
|
|||
msgstr ""
|
||||
|
||||
#: py/objtype.c
|
||||
msgid "__init__() should return None, not '%q'"
|
||||
#, c-format
|
||||
msgid "__init__() should return None, not '%s'"
|
||||
msgstr ""
|
||||
|
||||
#: py/objobject.c
|
||||
|
@ -2484,7 +2486,7 @@ msgid "attempt to get argmin/argmax of an empty sequence"
|
|||
msgstr ""
|
||||
|
||||
#: py/objstr.c
|
||||
msgid "attributes not supported yet"
|
||||
msgid "attributes not supported"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/ulab/code/ulab_tools.c
|
||||
|
@ -2612,7 +2614,7 @@ msgstr ""
|
|||
msgid "can't cancel self"
|
||||
msgstr ""
|
||||
|
||||
#: py/objint.c py/runtime.c shared-module/adafruit_pixelbuf/PixelBuf.c
|
||||
#: py/runtime.c shared-module/adafruit_pixelbuf/PixelBuf.c
|
||||
msgid "can't convert %q to %q"
|
||||
msgstr ""
|
||||
|
||||
|
@ -2630,10 +2632,18 @@ msgstr ""
|
|||
msgid "can't convert '%q' object to %q implicitly"
|
||||
msgstr ""
|
||||
|
||||
#: py/objint.c
|
||||
msgid "can't convert NaN to int"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/ulab/code/numpy/vector.c
|
||||
msgid "can't convert complex to float"
|
||||
msgstr ""
|
||||
|
||||
#: py/objint.c
|
||||
msgid "can't convert inf to int"
|
||||
msgstr ""
|
||||
|
||||
#: py/obj.c
|
||||
msgid "can't convert to complex"
|
||||
msgstr ""
|
||||
|
@ -2662,14 +2672,14 @@ msgstr ""
|
|||
msgid "can't do binary op between '%q' and '%q'"
|
||||
msgstr ""
|
||||
|
||||
#: py/objcomplex.c
|
||||
msgid "can't do truncated division of a complex number"
|
||||
msgstr ""
|
||||
|
||||
#: py/emitnative.c
|
||||
msgid "can't implicitly convert '%q' to 'bool'"
|
||||
msgstr ""
|
||||
|
||||
#: py/runtime.c
|
||||
msgid "can't import name %q"
|
||||
msgstr ""
|
||||
|
||||
#: py/emitnative.c
|
||||
msgid "can't load from '%q'"
|
||||
msgstr ""
|
||||
|
@ -2720,6 +2730,14 @@ msgid ""
|
|||
"can't switch from manual field specification to automatic field numbering"
|
||||
msgstr ""
|
||||
|
||||
#: py/objcomplex.c
|
||||
msgid "can't truncate-divide a complex number"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/moductypes.c
|
||||
msgid "can't unambiguously get sizeof scalar"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/moduasyncio.c
|
||||
msgid "can't wait"
|
||||
msgstr ""
|
||||
|
@ -2752,18 +2770,10 @@ msgstr ""
|
|||
msgid "cannot delete array elements"
|
||||
msgstr ""
|
||||
|
||||
#: py/runtime.c
|
||||
msgid "cannot import name %q"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/ulab/code/ndarray.c
|
||||
msgid "cannot reshape array"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/moductypes.c
|
||||
msgid "cannot unambiguously get sizeof scalar"
|
||||
msgstr ""
|
||||
|
||||
#: py/emitnative.c
|
||||
msgid "casting"
|
||||
msgstr ""
|
||||
|
@ -2812,6 +2822,10 @@ msgstr ""
|
|||
msgid "comparison of int and uint"
|
||||
msgstr ""
|
||||
|
||||
#: py/objcomplex.c
|
||||
msgid "complex divide by zero"
|
||||
msgstr ""
|
||||
|
||||
#: py/objfloat.c py/parsenum.c
|
||||
msgid "complex values not supported"
|
||||
msgstr ""
|
||||
|
@ -3384,7 +3398,7 @@ msgid "join expects a list of str/bytes objects consistent with self object"
|
|||
msgstr ""
|
||||
|
||||
#: py/argcheck.c
|
||||
msgid "keyword argument(s) not yet implemented - use normal args instead"
|
||||
msgid "keyword argument(s) not implemented - use normal args instead"
|
||||
msgstr ""
|
||||
|
||||
#: py/emitinlinethumb.c py/emitinlinextensa.c
|
||||
|
@ -3395,10 +3409,6 @@ msgstr ""
|
|||
msgid "label redefined"
|
||||
msgstr ""
|
||||
|
||||
#: py/stream.c
|
||||
msgid "length argument not allowed for this type"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/audiomixer/MixerVoice.c
|
||||
msgid "level must be between 0 and 1"
|
||||
msgstr ""
|
||||
|
@ -3485,6 +3495,10 @@ msgstr ""
|
|||
msgid "memory allocation failed, heap is locked"
|
||||
msgstr ""
|
||||
|
||||
#: py/objarray.c
|
||||
msgid "memoryview offset too large"
|
||||
msgstr ""
|
||||
|
||||
#: py/objarray.c
|
||||
msgid "memoryview: length is not a multiple of itemsize"
|
||||
msgstr ""
|
||||
|
@ -3533,6 +3547,10 @@ msgstr ""
|
|||
msgid "name not defined"
|
||||
msgstr ""
|
||||
|
||||
#: py/persistentcode.c
|
||||
msgid "native code in .mpy unsupported"
|
||||
msgstr ""
|
||||
|
||||
#: py/asmthumb.c
|
||||
msgid "native method too big"
|
||||
msgstr ""
|
||||
|
@ -3607,7 +3625,7 @@ msgstr ""
|
|||
msgid "non-default argument follows default argument"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/modubinascii.c
|
||||
#: py/objstr.c
|
||||
msgid "non-hex digit found"
|
||||
msgstr ""
|
||||
|
||||
|
@ -3697,7 +3715,7 @@ msgstr ""
|
|||
msgid "object with buffer protocol required"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/modubinascii.c
|
||||
#: py/objstr.c
|
||||
msgid "odd-length string"
|
||||
msgstr ""
|
||||
|
||||
|
@ -3717,10 +3735,6 @@ msgstr ""
|
|||
msgid "offset must be non-negative and no greater than buffer length"
|
||||
msgstr ""
|
||||
|
||||
#: py/objstr.c py/objstrunicode.c
|
||||
msgid "offset out of bounds"
|
||||
msgstr ""
|
||||
|
||||
#: ports/nrf/common-hal/audiobusio/PDMIn.c
|
||||
#: ports/stm/common-hal/audiobusio/PDMIn.c
|
||||
msgid "only bit_depth=16 is supported"
|
||||
|
@ -3969,10 +3983,6 @@ msgstr ""
|
|||
msgid "sleep length must be non-negative"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/ulab/code/ndarray.c
|
||||
msgid "slice step can't be zero"
|
||||
msgstr ""
|
||||
|
||||
#: py/nativeglue.c
|
||||
msgid "slice unsupported"
|
||||
msgstr ""
|
||||
|
@ -4017,6 +4027,10 @@ msgstr ""
|
|||
msgid "source_bitmap must have value_count of 8"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/modure.c
|
||||
msgid "splitting with sub-captures"
|
||||
msgstr ""
|
||||
|
||||
#: py/objstr.c
|
||||
msgid "start/end indices"
|
||||
msgstr ""
|
||||
|
@ -4029,8 +4043,17 @@ msgstr ""
|
|||
msgid "stream operation not supported"
|
||||
msgstr ""
|
||||
|
||||
#: py/stream.c
|
||||
msgid "string not supported; use bytes or bytearray"
|
||||
#: py/objarray.c py/objstr.c
|
||||
msgid "string argument without an encoding"
|
||||
msgstr ""
|
||||
|
||||
#: py/objstrunicode.c
|
||||
msgid "string index out of range"
|
||||
msgstr ""
|
||||
|
||||
#: py/objstrunicode.c
|
||||
#, c-format
|
||||
msgid "string indices must be integers, not %s"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/moductypes.c
|
||||
|
@ -4061,6 +4084,10 @@ msgstr ""
|
|||
msgid "syntax error in uctypes descriptor"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/utime_mphal.c
|
||||
msgid "ticks interval overflow"
|
||||
msgstr ""
|
||||
|
||||
#: ports/nrf/common-hal/watchdog/WatchDogTimer.c
|
||||
msgid "timeout duration exceeded the maximum supported value"
|
||||
msgstr ""
|
||||
|
|
1
main.c
1
main.c
|
@ -58,7 +58,6 @@
|
|||
#include "supervisor/shared/status_leds.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
#include "supervisor/shared/traceback.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
#include "supervisor/shared/workflow.h"
|
||||
#include "supervisor/usb.h"
|
||||
#include "supervisor/workflow.h"
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
/build-*
|
||||
/mpy-cross
|
||||
/mpy-cross.static
|
||||
/mpy-cross.static.exe
|
||||
/mpy-cross.static-raspbian
|
||||
/mpy-cross.fuzz
|
||||
/pitools
|
|
@ -1,24 +1,68 @@
|
|||
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
include ../py/mkenv.mk
|
||||
|
||||
# The following is a temporary hack to forefully undefine vars that might have
|
||||
# be defined by a calling Makefile (from recursive make).
|
||||
# TODO: Find a better way to be able to call this Makefile recursively.
|
||||
ifneq ($(findstring undefine,$(.FEATURES)),)
|
||||
override undefine COPT
|
||||
override undefine CFLAGS_EXTRA
|
||||
override undefine LDFLAGS_EXTRA
|
||||
override undefine MICROPY_FORCE_32BIT
|
||||
override undefine CROSS_COMPILE
|
||||
override undefine FROZEN_DIR
|
||||
override undefine FROZEN_MPY_DIR
|
||||
override undefine USER_C_MODULES
|
||||
override undefine SRC_MOD
|
||||
override undefine BUILD
|
||||
override undefine PROG
|
||||
# define main target
|
||||
PROG ?= mpy-cross
|
||||
|
||||
# qstr definitions (must come before including py.mk)
|
||||
QSTR_DEFS = qstrdefsport.h
|
||||
|
||||
# OS name, for simple autoconfig
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
# include py core make definitions
|
||||
include $(TOP)/py/py.mk
|
||||
|
||||
INC += -I.
|
||||
INC += -I$(BUILD)
|
||||
INC += -I$(TOP)
|
||||
|
||||
# compiler settings
|
||||
CWARN = -Wall -Werror
|
||||
CWARN += -Wextra -Wno-unused-parameter -Wpointer-arith
|
||||
CFLAGS += $(INC) $(CWARN) -std=gnu99 $(COPT) $(CFLAGS_EXTRA)
|
||||
CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables
|
||||
CFLAGS += -DCIRCUITPY
|
||||
|
||||
# Debugging/Optimization
|
||||
ifdef DEBUG
|
||||
CFLAGS += -g
|
||||
COPT = -O0
|
||||
else
|
||||
COPT = -Os #-DNDEBUG
|
||||
endif
|
||||
|
||||
include mpy-cross.mk
|
||||
CFLAGS += -g
|
||||
STRIP = :
|
||||
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
|
||||
# The unix port of MicroPython on OSX must be compiled with clang,
|
||||
# while cross-compile ports require gcc, so we test here for OSX and
|
||||
# if necessary override the value of 'CC' set in py/mkenv.mk
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
CC = clang
|
||||
# Use clang syntax for map file
|
||||
LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
|
||||
else
|
||||
# Use gcc syntax for map file
|
||||
LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections
|
||||
endif
|
||||
LDFLAGS += $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
|
||||
|
||||
# source files
|
||||
SRC_C = \
|
||||
main.c \
|
||||
gccollect.c \
|
||||
shared/runtime/gchelper_generic.c \
|
||||
supervisor/stub/safe_mode.c \
|
||||
supervisor/stub/stack.c \
|
||||
supervisor/shared/translate/translate.c
|
||||
|
||||
# Add fmode when compiling with mingw gcc
|
||||
COMPILER_TARGET := $(shell $(CC) -dumpmachine)
|
||||
ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
|
||||
SRC_C += windows-fmode.c
|
||||
endif
|
||||
|
||||
OBJ = $(PY_CORE_O)
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
||||
|
||||
$(BUILD)/supervisor/shared/translate/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/compressed_translations.generated.h
|
||||
|
||||
include $(TOP)/py/mkrules.mk
|
||||
|
|
|
@ -6,4 +6,4 @@ PROG=mpy-cross.fuzz
|
|||
BUILD=build-static
|
||||
STATIC_BUILD=1
|
||||
CC=afl-clang-fast
|
||||
include mpy-cross.mk
|
||||
include Makefile
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
PROG=mpy-cross-arm64
|
||||
BUILD=build-arm64
|
||||
|
||||
include mpy-cross.mk
|
||||
include Makefile
|
||||
# Because mpy-cross.mk unconditionally overwrites CC for Darwin, we must set it BELOW the inclusion
|
||||
CC := $(shell xcrun --find clang) -isysroot $(shell xcrun --show-sdk-path) -target arm64-apple-macos11
|
||||
|
|
|
@ -6,4 +6,4 @@ PROG=mpy-cross.static
|
|||
BUILD=build-static
|
||||
STATIC_BUILD=1
|
||||
|
||||
include mpy-cross.mk
|
||||
include Makefile
|
||||
|
|
|
@ -7,4 +7,4 @@ BUILD=build-static-aarch64
|
|||
STATIC_BUILD=1
|
||||
|
||||
CROSS_COMPILE = aarch64-linux-gnu-
|
||||
include mpy-cross.mk
|
||||
include Makefile
|
||||
|
|
|
@ -7,4 +7,4 @@ CROSS_COMPILE = x86_64-w64-mingw32-
|
|||
BUILD=build-static-mingw
|
||||
STATIC_BUILD=1
|
||||
|
||||
include mpy-cross.mk
|
||||
include Makefile
|
||||
|
|
|
@ -8,4 +8,4 @@ STATIC_BUILD=1
|
|||
|
||||
$(shell if ! [ -d pitools ]; then echo 1>&2 "Fetching pi build tools. This may take awhile."; git clone -q https://github.com/raspberrypi/tools.git --depth=1 pitools; fi)
|
||||
CROSS_COMPILE = pitools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-
|
||||
include mpy-cross.mk
|
||||
include Makefile
|
||||
|
|
|
@ -73,8 +73,9 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha
|
|||
#endif
|
||||
|
||||
mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT);
|
||||
mp_module_context_t *ctx = m_new_obj(mp_module_context_t);
|
||||
mp_compiled_module_t cm = mp_compile_to_raw_code(&parse_tree, source_name, false, ctx);
|
||||
mp_compiled_module_t cm;
|
||||
cm.context = m_new_obj(mp_module_context_t);
|
||||
mp_compile_to_raw_code(&parse_tree, source_name, false, &cm);
|
||||
|
||||
vstr_t vstr;
|
||||
vstr_init(&vstr, 16);
|
||||
|
@ -181,6 +182,15 @@ STATIC void pre_process_options(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
STATIC char *backslash_to_forwardslash(char *path) {
|
||||
for (char *p = path; p != NULL && *p != '\0'; ++p) {
|
||||
if (*p == '\\') {
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
MP_NOINLINE int main_(int argc, char **argv) {
|
||||
mp_stack_set_limit(40000 * (sizeof(void *) / 4));
|
||||
|
||||
|
@ -203,19 +213,9 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
|
||||
// set default compiler configuration
|
||||
mp_dynamic_compiler.small_int_bits = 31;
|
||||
#if defined(__i386__)
|
||||
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X86;
|
||||
mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_X86;
|
||||
#elif defined(__x86_64__)
|
||||
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X64;
|
||||
mp_dynamic_compiler.nlr_buf_num_regs = MAX(MICROPY_NLR_NUM_REGS_X64, MICROPY_NLR_NUM_REGS_X64_WIN);
|
||||
#elif defined(__arm__) && !defined(__thumb2__)
|
||||
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV6;
|
||||
mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP;
|
||||
#else
|
||||
// don't support native emitter unless -march is specified
|
||||
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_NONE;
|
||||
mp_dynamic_compiler.nlr_buf_num_regs = 0;
|
||||
#endif
|
||||
|
||||
const char *input_file = NULL;
|
||||
const char *output_file = NULL;
|
||||
|
@ -228,7 +228,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
a += 1;
|
||||
} else if (strcmp(argv[a], "--version") == 0) {
|
||||
printf("CircuitPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
|
||||
"; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "-CircuitPython\n");
|
||||
"; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "." MP_STRINGIFY(MPY_SUB_VERSION) "\n");
|
||||
return 0;
|
||||
} else if (strcmp(argv[a], "-v") == 0) {
|
||||
mp_verbose_flag++;
|
||||
|
@ -251,7 +251,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
exit(usage(argv));
|
||||
}
|
||||
a += 1;
|
||||
source_file = argv[a];
|
||||
source_file = backslash_to_forwardslash(argv[a]);
|
||||
} else if (strncmp(argv[a], "-msmall-int-bits=", sizeof("-msmall-int-bits=") - 1) == 0) {
|
||||
char *end;
|
||||
mp_dynamic_compiler.small_int_bits =
|
||||
|
@ -292,6 +292,20 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
} else if (strcmp(arch, "xtensawin") == 0) {
|
||||
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_XTENSAWIN;
|
||||
mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_XTENSAWIN;
|
||||
} else if (strcmp(arch, "host") == 0) {
|
||||
#if defined(__i386__) || defined(_M_IX86)
|
||||
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X86;
|
||||
mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_X86;
|
||||
#elif defined(__x86_64__) || defined(_M_X64)
|
||||
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_X64;
|
||||
mp_dynamic_compiler.nlr_buf_num_regs = MAX(MICROPY_NLR_NUM_REGS_X64, MICROPY_NLR_NUM_REGS_X64_WIN);
|
||||
#elif defined(__arm__) && !defined(__thumb2__)
|
||||
mp_dynamic_compiler.native_arch = MP_NATIVE_ARCH_ARMV6;
|
||||
mp_dynamic_compiler.nlr_buf_num_regs = MICROPY_NLR_NUM_REGS_ARM_THUMB_FP;
|
||||
#else
|
||||
mp_printf(&mp_stderr_print, "unable to determine host architecture for -march=host\n");
|
||||
exit(1);
|
||||
#endif
|
||||
} else {
|
||||
return usage(argv);
|
||||
}
|
||||
|
@ -303,7 +317,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
mp_printf(&mp_stderr_print, "multiple input files\n");
|
||||
exit(1);
|
||||
}
|
||||
input_file = argv[a];
|
||||
input_file = backslash_to_forwardslash(argv[a]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,7 +353,3 @@ void nlr_jump_fail(void *val) {
|
|||
fprintf(stderr, "FATAL: uncaught NLR %p\n", val);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void serial_write(const char *text) {
|
||||
printf("%s", text);
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ typedef long mp_off_t;
|
|||
#define MP_PLAT_PRINT_STRN(str, len) (void)0
|
||||
|
||||
// We need to provide a declaration/definition of alloca()
|
||||
#ifdef __FreeBSD__
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
#include <stdlib.h>
|
||||
#elif defined(_WIN32)
|
||||
#include <malloc.h>
|
||||
|
@ -182,6 +182,7 @@ typedef long mp_off_t;
|
|||
#define MP_ENDIANNESS_LITTLE (1)
|
||||
#define NORETURN __declspec(noreturn)
|
||||
#define MP_NOINLINE __declspec(noinline)
|
||||
#define MP_ALWAYSINLINE __forceinline
|
||||
#define MP_LIKELY(x) (x)
|
||||
#define MP_UNLIKELY(x) (x)
|
||||
#define MICROPY_PORT_CONSTANTS { MP_ROM_QSTR(MP_QSTR_dummy), MP_ROM_PTR(NULL) }
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
include ../py/mkenv.mk
|
||||
|
||||
# define main target
|
||||
|
||||
PROG ?= mpy-cross
|
||||
|
||||
# qstr definitions (must come before including py.mk)
|
||||
QSTR_DEFS = qstrdefsport.h
|
||||
|
||||
# OS name, for simple autoconfig
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
# include py core make definitions
|
||||
include $(TOP)/py/py.mk
|
||||
|
||||
INC += -I.
|
||||
INC += -I$(TOP)
|
||||
INC += -I$(BUILD)
|
||||
|
||||
# compiler settings
|
||||
CWARN = -Wall -Werror
|
||||
CWARN += -Wpointer-arith -Wuninitialized
|
||||
CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
|
||||
CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables
|
||||
|
||||
# Build a static executable.
|
||||
# Useful for Windows builds, etc., that must run on multiple operating system versions.
|
||||
ifdef STATIC_BUILD
|
||||
CFLAGS += -static -static-libgcc -static-libstdc++
|
||||
endif
|
||||
|
||||
|
||||
# Debugging/Optimization
|
||||
ifdef DEBUG
|
||||
CFLAGS += -g
|
||||
COPT = -O0
|
||||
else
|
||||
COPT = -Os #-DNDEBUG
|
||||
endif
|
||||
|
||||
# On OSX, 'gcc' is a symlink to clang unless a real gcc is installed.
|
||||
# The unix port of MicroPython on OSX must be compiled with clang,
|
||||
# while cross-compile ports require gcc, so we test here for OSX and
|
||||
# if necessary override the value of 'CC' set in py/mkenv.mk
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
CC = clang
|
||||
# Use clang syntax for map file
|
||||
LDFLAGS_ARCH = -Wl,-map,$@.map -Wl,-dead_strip
|
||||
else
|
||||
# Use gcc syntax for map file
|
||||
LDFLAGS_ARCH = -Wl,-Map=$@.map,--cref -Wl,--gc-sections
|
||||
endif
|
||||
LDFLAGS = $(LDFLAGS_MOD) $(LDFLAGS_ARCH) -lm $(LDFLAGS_EXTRA)
|
||||
|
||||
ifdef STATIC_BUILD
|
||||
LDFLAGS += -static -static-libgcc -static-libstdc++
|
||||
endif
|
||||
|
||||
CFLAGS += -DCIRCUITPY=1
|
||||
|
||||
# source files
|
||||
SRC_C += \
|
||||
main.c \
|
||||
gccollect.c \
|
||||
shared/runtime/gchelper_generic.c \
|
||||
supervisor/stub/safe_mode.c \
|
||||
supervisor/stub/stack.c \
|
||||
supervisor/shared/translate/translate.c
|
||||
|
||||
# Add fmode when compiling with mingw gcc
|
||||
COMPILER_TARGET := $(shell $(CC) -dumpmachine)
|
||||
ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
|
||||
SRC_C += fmode.c
|
||||
endif
|
||||
|
||||
OBJ = $(PY_CORE_O)
|
||||
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
|
||||
|
||||
$(BUILD)/supervisor/shared/translate/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/compressed_translations.generated.h
|
||||
|
||||
include $(TOP)/py/mkrules.mk
|
|
@ -24,7 +24,6 @@
|
|||
<PyBuildingMpyCross>True</PyBuildingMpyCross>
|
||||
<PyBuildDir>$(MSBuildThisFileDirectory)build\</PyBuildDir>
|
||||
<PyIncDirs>$(MSBuildThisFileDirectory)</PyIncDirs>
|
||||
<PyTargetDir>$(MSBuildThisFileDirectory)</PyTargetDir>
|
||||
<PyMsvcDir>$(MSBuildThisFileDirectory)..\ports\windows\msvc\</PyMsvcDir>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# This file is part of the MicroPython project, http://micropython.org/
|
||||
#
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2022 Andrew Leech
|
||||
# Copyright (c) 2022 Jim Mussared
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
import subprocess
|
||||
|
||||
NATIVE_ARCHS = {
|
||||
"NATIVE_ARCH_NONE": "",
|
||||
"NATIVE_ARCH_X86": "x86",
|
||||
"NATIVE_ARCH_X64": "x64",
|
||||
"NATIVE_ARCH_ARMV6": "armv6",
|
||||
"NATIVE_ARCH_ARMV6M": "armv6m",
|
||||
"NATIVE_ARCH_ARMV7M": "armv7m",
|
||||
"NATIVE_ARCH_ARMV7EM": "armv7em",
|
||||
"NATIVE_ARCH_ARMV7EMSP": "armv7emsp",
|
||||
"NATIVE_ARCH_ARMV7EMDP": "armv7emdp",
|
||||
"NATIVE_ARCH_XTENSA": "xtensa",
|
||||
"NATIVE_ARCH_XTENSAWIN": "xtensawin",
|
||||
}
|
||||
|
||||
globals().update(NATIVE_ARCHS)
|
||||
|
||||
__all__ = ["version", "compile", "run", "CrossCompileError"] + list(NATIVE_ARCHS.keys())
|
||||
|
||||
|
||||
class CrossCompileError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
_VERSION_RE = re.compile("mpy-cross emitting mpy v([0-9]+)(?:.([0-9]+))?")
|
||||
|
||||
|
||||
def _find_mpy_cross_binary(mpy_cross):
|
||||
if mpy_cross:
|
||||
return mpy_cross
|
||||
return os.path.abspath(os.path.join(os.path.dirname(__file__), "../build/mpy-cross"))
|
||||
|
||||
|
||||
def mpy_version(mpy_cross=None):
|
||||
"""
|
||||
Get the version and sub-version of the .mpy file format generated by this version of mpy-cross.
|
||||
|
||||
Returns: A tuple of `(mpy_version, mpy_sub_version)`
|
||||
Optional keyword arguments:
|
||||
- mpy_cross: Specific mpy-cross binary to use
|
||||
"""
|
||||
version_info = run(["--version"], mpy_cross=mpy_cross)
|
||||
match = re.search(_VERSION_RE, version_info)
|
||||
mpy_version, mpy_sub_version = int(match.group(1)), int(match.group(2) or "0")
|
||||
return (
|
||||
mpy_version,
|
||||
mpy_sub_version,
|
||||
)
|
||||
|
||||
|
||||
def compile(src, dest=None, src_path=None, opt=None, march=None, mpy_cross=None, extra_args=None):
|
||||
"""
|
||||
Compile the specified .py file with mpy-cross.
|
||||
|
||||
Returns: Standard output from mpy-cross as a string.
|
||||
|
||||
Required arguments:
|
||||
- src: The path to the .py file
|
||||
|
||||
Optional keyword arguments:
|
||||
- dest: The output .mpy file. Defaults to `src` (with .mpy extension)
|
||||
- src_path: The path to embed in the .mpy file (defaults to `src`)
|
||||
- opt: Optimisation level (0-3, default 0)
|
||||
- march: One of the `NATIVE_ARCH_*` constants (defaults to NATIVE_ARCH_NONE)
|
||||
- mpy_cross: Specific mpy-cross binary to use
|
||||
- extra_args: Additional arguments to pass to mpy-cross (e.g. `["-X", "emit=native"]`)
|
||||
"""
|
||||
if not src:
|
||||
raise ValueError("src is required")
|
||||
if not os.path.exists(src):
|
||||
raise CrossCompileError("Input .py file not found: {}.".format(src_py))
|
||||
|
||||
args = []
|
||||
|
||||
if src_path:
|
||||
args += ["-s", src_path]
|
||||
|
||||
if dest:
|
||||
args += ["-o", dest]
|
||||
|
||||
if march:
|
||||
args += ["-march=" + march]
|
||||
|
||||
if opt is not None:
|
||||
args += ["-O{}".format(opt)]
|
||||
|
||||
if extra_args:
|
||||
args += extra_args
|
||||
|
||||
args += [src]
|
||||
|
||||
run(args, mpy_cross)
|
||||
|
||||
|
||||
def run(args, mpy_cross=None):
|
||||
"""
|
||||
Run mpy-cross with the specified command line arguments.
|
||||
Prefer to use `compile()` instead.
|
||||
|
||||
Returns: Standard output from mpy-cross as a string.
|
||||
|
||||
Optional keyword arguments:
|
||||
- mpy_cross: Specific mpy-cross binary to use
|
||||
"""
|
||||
mpy_cross = _find_mpy_cross_binary(mpy_cross)
|
||||
|
||||
if not os.path.exists(mpy_cross):
|
||||
raise CrossCompileError("mpy-cross binary not found at {}.".format(mpy_cross))
|
||||
|
||||
try:
|
||||
st = os.stat(mpy_cross)
|
||||
os.chmod(mpy_cross, st.st_mode | stat.S_IEXEC)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
try:
|
||||
return subprocess.check_output([mpy_cross] + args, stderr=subprocess.STDOUT).decode()
|
||||
except subprocess.CalledProcessError as er:
|
||||
raise CrossCompileError(er.output.decode())
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# This file is part of the MicroPython project, http://micropython.org/
|
||||
#
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2022 Andrew Leech
|
||||
# Copyright (c) 2022 Jim Mussared
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
from __future__ import print_function
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from . import run, CrossCompileError
|
||||
|
||||
try:
|
||||
print(run(sys.argv[1:]))
|
||||
except CrossCompileError as er:
|
||||
print(er.args[0], file=sys.stderr)
|
||||
raise SystemExit(1)
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright 2019 Sony Semiconductor Solutions Corporation
|
||||
* Copyright (c) 2013-2016 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -23,9 +23,27 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef MICROPY_INCLUDED_CXD56_INTERNAL_FLASH_ROOT_POINTERS_H
|
||||
#define MICROPY_INCLUDED_CXD56_INTERNAL_FLASH_ROOT_POINTERS_H
|
||||
|
||||
#define FLASH_ROOT_POINTERS
|
||||
#include "fmode.h"
|
||||
#include "py/mpconfig.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#endif // MICROPY_INCLUDED_CXD56_INTERNAL_FLASH_ROOT_POINTERS_H
|
||||
// Workaround for setting file translation mode: we must distinguish toolsets
|
||||
// since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect
|
||||
STATIC int set_fmode_impl(int mode) {
|
||||
#ifndef _MSC_VER
|
||||
_fmode = mode;
|
||||
return 0;
|
||||
#else
|
||||
return _set_fmode(mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_fmode_binary(void) {
|
||||
set_fmode_impl(O_BINARY);
|
||||
}
|
||||
|
||||
void set_fmode_text(void) {
|
||||
set_fmode_impl(O_TEXT);
|
||||
}
|
|
@ -362,7 +362,7 @@ OBJ_EXTRA_ORDER_DEPS += $(HEADER_BUILD)/candata.h
|
|||
$(HEADER_BUILD)/candata.h: tools/mkcandata.py | $(HEADER_BUILD)
|
||||
$(Q)$(PYTHON) $< > $@
|
||||
|
||||
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
|
||||
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) $(SRC_CIRCUITPY_COMMON)
|
||||
# Sources that only hold QSTRs after pre-processing.
|
||||
SRC_QSTR_PREPROCESSOR += peripherals/samd/$(PERIPHERALS_CHIP_FAMILY)/clocks.c
|
||||
|
||||
|
|
|
@ -432,4 +432,6 @@ void audio_dma_evsys_handler(void) {
|
|||
}
|
||||
}
|
||||
|
||||
MP_REGISTER_ROOT_POINTER(mp_obj_t playing_audio[AUDIO_DMA_CHANNEL_COUNT]);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -128,12 +128,13 @@ STATIC const mp_rom_map_elem_t samd_clock_locals_dict_table[] = {
|
|||
|
||||
STATIC MP_DEFINE_CONST_DICT(samd_clock_locals_dict, samd_clock_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t samd_clock_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Clock,
|
||||
.print = samd_clock_print,
|
||||
.locals_dict = (mp_obj_t)&samd_clock_locals_dict,
|
||||
};
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
samd_clock_type,
|
||||
MP_QSTR_Clock,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
print, samd_clock_print,
|
||||
locals_dict, &samd_clock_locals_dict
|
||||
);
|
||||
|
||||
#ifdef SAMD21
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "shared-bindings/util.h"
|
||||
#include "samd/timers.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
#include "timer_handler.h"
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include "samd/adc.h"
|
||||
#include "shared-bindings/analogio/AnalogIn.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "atmel_start_pins.h"
|
||||
#include "hal/include/hal_adc_sync.h"
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include "shared-bindings/analogio/AnalogOut.h"
|
||||
#include "shared-bindings/audioio/AudioOut.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "atmel_start_pins.h"
|
||||
#include "hal/include/hal_dac_sync.h"
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include "shared-bindings/audiobusio/I2SOut.h"
|
||||
#include "shared-bindings/audiocore/RawSample.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "atmel_start_pins.h"
|
||||
#include "hal/include/hal_gpio.h"
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include "shared-bindings/audiobusio/PDMIn.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "atmel_start_pins.h"
|
||||
#include "hal/include/hal_gpio.h"
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "shared-bindings/audioio/AudioOut.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "atmel_start_pins.h"
|
||||
#include "hal/include/hal_gpio.h"
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "samd/sercom.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "common-hal/busio/__init__.h"
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include "peripheral_clk_config.h"
|
||||
|
||||
#include "supervisor/board.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
#include "common-hal/busio/__init__.h"
|
||||
|
||||
#include "hal/include/hal_gpio.h"
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "py/mperrno.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
|
||||
#include "hpl_sercom_config.h"
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "eic_handler.h"
|
||||
#include "samd/external_interrupts.h"
|
||||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
void common_hal_countio_counter_construct(countio_counter_obj_t *self,
|
||||
const mcu_pin_obj_t *pin, countio_edge_t edge, digitalio_pull_t pull) {
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
digitalinout_result_t common_hal_digitalio_digitalinout_construct(
|
||||
digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) {
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/time/__init__.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#ifdef SAMD21
|
||||
#include "hpl/gclk/hpl_gclk_base.h"
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "atmel_start_pins.h"
|
||||
#include "hal/include/hal_gpio.h"
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/microcontroller/Processor.h"
|
||||
#include "supervisor/shared/safe_mode.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
void common_hal_mcu_delay_us(uint32_t delay) {
|
||||
mp_hal_delay_us(delay);
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/ps2io/Ps2.h"
|
||||
#include "supervisor/port.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#define STATE_IDLE 0
|
||||
#define STATE_RECV 1
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/pulseio/PulseIn.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
#include "supervisor/port.h"
|
||||
|
||||
// This timer is shared amongst all PulseIn objects as a higher resolution clock.
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#include "py/gc.h"
|
||||
#include "py/runtime.h"
|
||||
#include "shared-bindings/pulseio/PulseOut.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
#include "timer_handler.h"
|
||||
|
||||
// This timer is shared amongst all PulseOut objects under the assumption that
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
#include "hal/utils/include/utils_repeat_macro.h"
|
||||
#include "samd/pins.h"
|
||||
#include "samd/timers.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#undef ENABLE
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include "eic_handler.h"
|
||||
#include "samd/external_interrupts.h"
|
||||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t *self,
|
||||
const mcu_pin_obj_t *pin_a, const mcu_pin_obj_t *pin_b) {
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include "shared-bindings/rtc/__init__.h"
|
||||
#include "shared-bindings/rtc/RTC.h"
|
||||
#include "supervisor/port.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
// This is the time in seconds since 2000 that the RTC was started.
|
||||
// TODO: Change the offset to ticks so that it can be a subsecond adjustment.
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
#include "shared-bindings/sdioio/SDCard.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "genhdr/sdiodata.h"
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include "py/mphal.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/touchio/TouchIn.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
// Native touchio only exists for SAMD21
|
||||
#ifdef SAMD21
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
|
||||
#define MICROPY_FATFS_EXFAT (0)
|
||||
// FAT32 mkfs takes about 500 bytes.
|
||||
#define MICROPY_FF_MKFS_FAT32 (0)
|
||||
#define MICROPY_FATFS_MKFS_FAT32 (0)
|
||||
|
||||
// Only support simpler HID descriptors on SAMD21.
|
||||
#define CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR (1)
|
||||
|
@ -270,13 +270,4 @@
|
|||
|
||||
#include "peripherals/samd/dma.h"
|
||||
|
||||
#if CIRCUITPY_AUDIOCORE
|
||||
#define MICROPY_PORT_ROOT_POINTERS \
|
||||
CIRCUITPY_COMMON_ROOT_POINTERS \
|
||||
mp_obj_t playing_audio[AUDIO_DMA_CHANNEL_COUNT];
|
||||
#else
|
||||
#define MICROPY_PORT_ROOT_POINTERS \
|
||||
CIRCUITPY_COMMON_ROOT_POINTERS
|
||||
#endif
|
||||
|
||||
#endif // __INCLUDED_MPCONFIGPORT_H
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_INTERNAL_FLASH_ROOT_POINTERS_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_INTERNAL_FLASH_ROOT_POINTERS_H
|
||||
|
||||
#define FLASH_ROOT_POINTERS
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_INTERNAL_FLASH_ROOT_POINTERS_H
|
|
@ -128,7 +128,7 @@ endif
|
|||
CFLAGS += $(INC) -Wall -Werror -std=gnu11 $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS)
|
||||
|
||||
|
||||
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
|
||||
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) $(SRC_CIRCUITPY_COMMON)
|
||||
|
||||
LDFLAGS += $(CFLAGS) -T peripherals/broadcom/link$(SUFFIX).ld -Wl,--gc-sections -Wl,-Map=$@.map # -Wl,--cref
|
||||
|
||||
|
|
|
@ -169,14 +169,12 @@ STATIC const framebuffer_p_t videocore_framebuffer_proto = {
|
|||
.deinit = videocore_framebuffer_deinit_proto,
|
||||
};
|
||||
|
||||
const mp_obj_type_t videocore_framebuffer_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Framebuffer,
|
||||
.locals_dict = (mp_obj_dict_t *)&videocore_framebuffer_locals_dict,
|
||||
.make_new = videocore_framebuffer_make_new,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.buffer_p = { .get_buffer = common_hal_videocore_framebuffer_get_buffer, },
|
||||
.protocol = &videocore_framebuffer_proto,
|
||||
),
|
||||
};
|
||||
MP_DEFINE_CONST_OBJ_TYPE(
|
||||
videocore_framebuffer_type,
|
||||
MP_QSTR_Framebuffer,
|
||||
MP_TYPE_FLAG_NONE,
|
||||
locals_dict, (mp_obj_dict_t *)&videocore_framebuffer_locals_dict,
|
||||
make_new, videocore_framebuffer_make_new,
|
||||
buffer, common_hal_videocore_framebuffer_get_buffer,
|
||||
protocol, &videocore_framebuffer_proto
|
||||
);
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "peripherals/broadcom/gpio.h"
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "supervisor/port.h"
|
||||
#include "supervisor/shared/translate/translate.h"
|
||||
|
||||
#include "peripherals/broadcom/cpu.h"
|
||||
#include "peripherals/broadcom/defines.h"
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
#define CIRCUITPY_DISPLAY_AREA_BUFFER_SIZE (1920)
|
||||
#define CIRCUITPY_PROCESSOR_COUNT (4)
|
||||
|
||||
#define MICROPY_FF_MKFS_FAT32 (1)
|
||||
#define MICROPY_FATFS_EXFAT (1)
|
||||
#define MICROPY_FATFS_MKFS_FAT32 (1)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -57,7 +57,4 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define MICROPY_PORT_ROOT_POINTERS \
|
||||
CIRCUITPY_COMMON_ROOT_POINTERS
|
||||
|
||||
#endif // __INCLUDED_MPCONFIGPORT_H
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue