diff --git a/.gitmodules b/.gitmodules index 0177e5a2ea..e0d0a262ca 100644 --- a/.gitmodules +++ b/.gitmodules @@ -307,3 +307,6 @@ [submodule "frozen/circuitpython_picoed"] path = frozen/circuitpython_picoed url = https://github.com/elecfreaks/circuitpython_picoed.git +[submodule "ports/espressif/esp32-camera"] + path = ports/espressif/esp32-camera + url = https://github.com/adafruit/esp32-camera/ diff --git a/conf.py b/conf.py index b7e2f29914..ad35596d7a 100644 --- a/conf.py +++ b/conf.py @@ -199,6 +199,7 @@ exclude_patterns = ["**/build*", "ports/cxd56/spresense-exported-sdk", "ports/espressif/certificates", "ports/espressif/esp-idf", + "ports/espressif/esp32-camera", "ports/espressif/.idf_tools", "ports/espressif/peripherals", "ports/litex/hw", diff --git a/docs/porting.rst b/docs/porting.rst index 07a2b1e9c4..f4ed2ab4cc 100644 --- a/docs/porting.rst +++ b/docs/porting.rst @@ -71,7 +71,7 @@ as a natural "TODO" list. An example minimal build list is shown below: CIRCUITPY_SDCARDIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FREQUENCYIO = 0 - CIRCUITPY_I2CPERIPHERAL = 0 + CIRCUITPY_I2CTARGET = 0 # Requires SPI, PulseIO (stub ok): CIRCUITPY_DISPLAYIO = 0 diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage index f993d5fac6..9a8338b3bd 160000 --- a/frozen/circuitpython-stage +++ b/frozen/circuitpython-stage @@ -1 +1 @@ -Subproject commit f993d5fac69f3a0cfa33988268666c462b72c0ec +Subproject commit 9a8338b3bdaeac9eeb5b74d147107c67db33fdac diff --git a/locale/ID.po b/locale/ID.po index c58e3e5532..ba3fc8e0b0 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -404,12 +404,14 @@ msgstr "Alamat harus sepanjang %d byte" msgid "All CAN peripherals are in use" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Semua perangkat I2C sedang digunakan" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1609,7 +1611,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2350,11 +2352,11 @@ msgstr "__new__ arg harus berupa user-type" msgid "a bytes-like object is required" msgstr "sebuah objek menyerupai byte (bytes-like) dibutuhkan" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "alamat di luar batas" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "alamatnya kosong" @@ -2546,7 +2548,7 @@ msgstr "tidak dapat menetapkan ke ekspresi" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3283,6 +3285,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "micropython decorator tidak valid" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "" @@ -3538,7 +3544,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 549a7b54ed..c69ea7bdfa 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -398,12 +398,14 @@ msgstr "" msgid "All CAN peripherals are in use" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1589,7 +1591,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2319,11 +2321,11 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "" @@ -2515,7 +2517,7 @@ msgstr "" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3252,6 +3254,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "" @@ -3507,7 +3513,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "" diff --git a/locale/cs.po b/locale/cs.po index 4916a78c97..4e114549e5 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -405,12 +405,14 @@ msgstr "Adresa musí být %d bajtů dlouhá" msgid "All CAN peripherals are in use" msgstr "Všechny CAN periferie jsou používány" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Všechny I2C periferie jsou používány" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1605,7 +1607,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2337,11 +2339,11 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "" @@ -2533,7 +2535,7 @@ msgstr "" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3270,6 +3272,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "" @@ -3525,7 +3531,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 853406c8b3..2ce09bd00f 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -407,12 +407,14 @@ msgstr "Die Adresse muss %d Bytes lang sein" msgid "All CAN peripherals are in use" msgstr "Alle CAN-Schnittstellen sind in Benutzung" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Alle I2C-Peripheriegeräte sind in Benutzung" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1624,7 +1626,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Nur ein TouchAlarm kann in Deep Sleep gesetzt werden." -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "Nur eine Adresse ist erlaubt" @@ -2389,11 +2391,11 @@ msgstr "__new__ arg muss user-type sein" msgid "a bytes-like object is required" msgstr "ein Byte-ähnliches Objekt ist erforderlich" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "Adresse außerhalb der Grenzen" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "addresses ist leer" @@ -2587,7 +2589,7 @@ msgstr "kann keinem Ausdruck zuweisen" msgid "can't cancel self" msgstr "kann self nicht abbrechen" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "kann %q nicht zu %q konvertieren" @@ -3336,6 +3338,10 @@ msgstr "ungültiger Hostname" msgid "invalid micropython decorator" msgstr "ungültiger micropython decorator" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "ungültiger Schritt (step)" @@ -3597,7 +3603,7 @@ msgstr "kein Reset Pin verfügbar" msgid "no response from SD card" msgstr "keine Antwort von der SD-Karte" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "kein solches Attribut" diff --git a/locale/el.po b/locale/el.po index 892eb0a935..84f75edf1e 100644 --- a/locale/el.po +++ b/locale/el.po @@ -398,12 +398,14 @@ msgstr "" msgid "All CAN peripherals are in use" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1589,7 +1591,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2319,11 +2321,11 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "" @@ -2515,7 +2517,7 @@ msgstr "" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3252,6 +3254,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "" @@ -3507,7 +3513,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index d981a5fba9..4c1dcfb22a 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -408,12 +408,14 @@ msgstr "Address must be %d bytes long" msgid "All CAN peripherals are in use" msgstr "All CAN peripherals are in use" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "All I2C peripherals are in use" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1609,7 +1611,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Only one TouchAlarm can be set in deep sleep." -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2353,11 +2355,11 @@ msgstr "__new__ arg must be a user-type" msgid "a bytes-like object is required" msgstr "a bytes-like object is required" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "address out of bounds" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "addresses is empty" @@ -2549,7 +2551,7 @@ msgstr "Can't assign to expression" msgid "can't cancel self" msgstr "can't cancel self" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "Can't convert %q to %q" @@ -3289,6 +3291,10 @@ msgstr "invalid hostname" msgid "invalid micropython decorator" msgstr "invalid micropython decorator" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "invalid step" @@ -3544,7 +3550,7 @@ msgstr "no reset pin available" msgid "no response from SD card" msgstr "no response from SD card" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "no such attribute" diff --git a/locale/es.po b/locale/es.po index bd70f95beb..f2d7c65570 100644 --- a/locale/es.po +++ b/locale/es.po @@ -407,12 +407,14 @@ msgstr "La dirección debe tener %d bytes de largo" msgid "All CAN peripherals are in use" msgstr "Todos los periféricos CAN están en uso" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Todos los periféricos I2C están siendo usados" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1630,7 +1632,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Solamente una TouchAlarm puede ser configurada durante deep sleep." -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2386,11 +2388,11 @@ msgstr "__new__ arg debe ser un user-type" msgid "a bytes-like object is required" msgstr "se requiere un objeto bytes-like" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "address fuera de límites" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "addresses esta vacío" @@ -2582,7 +2584,7 @@ msgstr "no se puede asignar a la expresión" msgid "can't cancel self" msgstr "no se puede cancelar a si mismo" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "no puede convertir %q a %q" @@ -3326,6 +3328,10 @@ msgstr "hostname inválido" msgid "invalid micropython decorator" msgstr "decorador de micropython inválido" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "paso inválido" @@ -3585,7 +3591,7 @@ msgstr "no hay pin de reinicio disponible" msgid "no response from SD card" msgstr "no hay respuesta de la tarjeta SD" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "no hay tal atributo" diff --git a/locale/fil.po b/locale/fil.po index 1a2ac694e4..3f59a2b674 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -401,12 +401,14 @@ msgstr "ang palette ay dapat 32 bytes ang haba" msgid "All CAN peripherals are in use" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Lahat ng I2C peripherals ginagamit" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1605,7 +1607,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2339,11 +2341,11 @@ msgstr "__new__ arg ay dapat na user-type" msgid "a bytes-like object is required" msgstr "a bytes-like object ay kailangan" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "wala sa sakop ang address" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "walang laman ang address" @@ -2537,7 +2539,7 @@ msgstr "hindi ma i-assign sa expression" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3285,6 +3287,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "mali ang micropython decorator" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "mali ang step" @@ -3544,7 +3550,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "walang ganoon na attribute" diff --git a/locale/fr.po b/locale/fr.po index 7ca525f341..95c03542cb 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -410,12 +410,14 @@ msgstr "L'adresse doit être longue de %d octets" msgid "All CAN peripherals are in use" msgstr "Tous les périphériques CAN sont utilisés" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Tous les périphériques I2C sont utilisés" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1653,7 +1655,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Seulement une TouchAlarm peu être réglée en sommeil profond." -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "Seulement une adresse est autorisée" @@ -2420,11 +2422,11 @@ msgstr "l'argument __new__ doit être d'un type défini par l'utilisateur" msgid "a bytes-like object is required" msgstr "un objet 'bytes-like' est requis" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "adresse hors limites" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "adresses vides" @@ -2617,7 +2619,7 @@ msgstr "ne peut pas assigner à une expression" msgid "can't cancel self" msgstr "ne peut pas s'annuler soi-même" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "impossible de convertir %q en %q" @@ -3368,6 +3370,10 @@ msgstr "hostname incorrect" msgid "invalid micropython decorator" msgstr "décorateur micropython invalide" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "pas invalide" @@ -3628,7 +3634,7 @@ msgstr "pas de broche de réinitialisation disponible" msgid "no response from SD card" msgstr "pas de réponse de la carte SD" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "pas de tel attribut" diff --git a/locale/hi.po b/locale/hi.po index e8aedf1c8a..44db3cbb48 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -398,12 +398,14 @@ msgstr "" msgid "All CAN peripherals are in use" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1589,7 +1591,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2319,11 +2321,11 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "" @@ -2515,7 +2517,7 @@ msgstr "" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3252,6 +3254,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "" @@ -3507,7 +3513,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index c86e14d912..0d3619b91e 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -407,12 +407,14 @@ msgstr "L'indirizzo deve essere lungo %d byte" msgid "All CAN peripherals are in use" msgstr "Tutte le periferiche CAN sono in uso" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Tutte le periferiche I2C sono in uso" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1612,7 +1614,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2349,11 +2351,11 @@ msgstr "" msgid "a bytes-like object is required" msgstr "un oggetto byte-like è richiesto" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "indirizzo fuori limite" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "gli indirizzi sono vuoti" @@ -2549,7 +2551,7 @@ msgstr "impossibile assegnare all'espressione" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3293,6 +3295,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "decoratore non valido in micropython" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "step non valida" @@ -3553,7 +3559,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "attributo inesistente" diff --git a/locale/ja.po b/locale/ja.po index 17f5d3b84d..5377492685 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -403,12 +403,14 @@ msgstr "アドレスは、%dバイト長でなければなりません" msgid "All CAN peripherals are in use" msgstr "全てのCAN周辺機器が使用中" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "全てのI2C周辺機器が使用中" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1602,7 +1604,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2333,11 +2335,11 @@ msgstr "__new__の引数はユーザ型でなければなりません" msgid "a bytes-like object is required" msgstr "bytes-likeオブジェクトが必要" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "アドレスが範囲外" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "" @@ -2529,7 +2531,7 @@ msgstr "式には代入できません" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "%qを%qに変換できません" @@ -3271,6 +3273,10 @@ msgstr "不正なホスト名" msgid "invalid micropython decorator" msgstr "不正なmicropythonデコレータ" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "不正なステップ" @@ -3526,7 +3532,7 @@ msgstr "利用可能なリセットピンがありません" msgid "no response from SD card" msgstr "SDカードからの応答がありません" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "指定の属性はありません" diff --git a/locale/ko.po b/locale/ko.po index 27ce6030d6..ad4c0a9fdc 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -399,12 +399,14 @@ msgstr "" msgid "All CAN peripherals are in use" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "사용중인 모든 I2C주변 기기" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1592,7 +1594,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2323,11 +2325,11 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "" @@ -2519,7 +2521,7 @@ msgstr "" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3256,6 +3258,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "단계(step)가 유효하지 않습니다" @@ -3511,7 +3517,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "" diff --git a/locale/nl.po b/locale/nl.po index 795ef4542b..dafe2449f8 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -401,12 +401,14 @@ msgstr "Adres moet %d bytes lang zijn" msgid "All CAN peripherals are in use" msgstr "Alle CAN-peripherals zijn in gebruik" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Alle I2C peripherals zijn in gebruik" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1606,7 +1608,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2349,11 +2351,11 @@ msgstr "__new__ arg moet een user-type zijn" msgid "a bytes-like object is required" msgstr "een bytes-achtig object is vereist" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "adres buiten bereik" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "adressen zijn leeg" @@ -2546,7 +2548,7 @@ msgstr "kan niet toewijzen aan expressie" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "kan %q niet naar %q converteren" @@ -3286,6 +3288,10 @@ msgstr "onjuiste hostnaam" msgid "invalid micropython decorator" msgstr "ongeldige micropython decorator" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "ongeldige stap" @@ -3544,7 +3550,7 @@ msgstr "geen reset pin beschikbaar" msgid "no response from SD card" msgstr "geen antwoord van SD kaart" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "niet zo'n attribuut" diff --git a/locale/pl.po b/locale/pl.po index a49b8bdd52..9662f16597 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -403,12 +403,14 @@ msgstr "Adres musi mieć %d bajtów" msgid "All CAN peripherals are in use" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Wszystkie peryferia I2C w użyciu" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1600,7 +1602,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2330,11 +2332,11 @@ msgstr "Argument __new__ musi być typu użytkownika" msgid "a bytes-like object is required" msgstr "wymagany obiekt typu bytes" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "adres poza zakresem" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "adres jest pusty" @@ -2526,7 +2528,7 @@ msgstr "przypisanie do wyrażenia" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "nie można dokonać konwersji %q na %q" @@ -3264,6 +3266,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "zły dekorator micropythona" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "zły krok" @@ -3519,7 +3525,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "nie ma takiego atrybutu" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 40c5ec8c71..231750f4c6 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2022-08-07 15:16+0000\n" +"PO-Revision-Date: 2022-08-10 07:18+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -411,12 +411,14 @@ msgstr "O endereço deve ter %d bytes de comprimento" msgid "All CAN peripherals are in use" msgstr "Todos os periféricos CAN estão em uso" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Todos os periféricos I2C estão em uso" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "Todos os alvos I2C já estão em uso" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1635,7 +1637,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Apenas um TouchAlarm pode ser colocado em deep sleep." -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "Apenas um endereço é permitido" @@ -2402,11 +2404,11 @@ msgstr "O argumento __new__ deve ser um tipo usuário" msgid "a bytes-like object is required" msgstr "é necessário objetos tipo bytes" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "endereço fora dos limites" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "os endereços estão vazios" @@ -2598,7 +2600,7 @@ msgstr "a expressão não pode ser atribuída" msgid "can't cancel self" msgstr "não é possível cancelar a si mesmo" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "não é possível converter %q para %q" @@ -3345,6 +3347,10 @@ msgstr "o nome do host é inválido" msgid "invalid micropython decorator" msgstr "o decorador micropython é inválido" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "configuração inválida" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "passo inválido" @@ -3605,7 +3611,7 @@ msgstr "nenhum pino de redefinição está disponível" msgid "no response from SD card" msgstr "não houve resposta do cartão SD" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "não há tal atributo" diff --git a/locale/ru.po b/locale/ru.po index ba339d07db..6e2d65cc81 100644 --- a/locale/ru.po +++ b/locale/ru.po @@ -406,12 +406,14 @@ msgstr "Адрес должен быть длиной %d байт" msgid "All CAN peripherals are in use" msgstr "Все периферийные устройства CAN уже используются" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Все периферийные устройства I2C уже используются" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1631,7 +1633,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2368,11 +2370,11 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "" @@ -2564,7 +2566,7 @@ msgstr "" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3301,6 +3303,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "" @@ -3556,7 +3562,7 @@ msgstr "нет доступного контакта сброса" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "" diff --git a/locale/sv.po b/locale/sv.po index 33680a2354..20724e40bf 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -406,12 +406,14 @@ msgstr "Adressen måste vara %d byte lång" msgid "All CAN peripherals are in use" msgstr "All I2C-kringutrustning används" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "All I2C-kringutrustning används" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1615,7 +1617,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Endast ett TouchAlarm kan ställas in för djupsömn." -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "Endast en adress är tillåten" @@ -2372,11 +2374,11 @@ msgstr "__new__ arg måste vara en användartyp" msgid "a bytes-like object is required" msgstr "ett bytesliknande objekt krävs" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "adress utanför gränsen" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "adresserna är tomma" @@ -2568,7 +2570,7 @@ msgstr "kan inte tilldela uttryck" msgid "can't cancel self" msgstr "kan inte avbryta sig själv" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "kan inte konvertera %q till %q" @@ -3310,6 +3312,10 @@ msgstr "Ogiltigt värdnamn" msgid "invalid micropython decorator" msgstr "ogiltig mikropython-dekorator" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "ogiltigt steg" @@ -3568,7 +3574,7 @@ msgstr "ingen reset-pinne tillgänglig" msgid "no response from SD card" msgstr "inget svar från SD-kort" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "inget sådant attribut" diff --git a/locale/tr.po b/locale/tr.po index e2b1718a7b..987ef716b6 100644 --- a/locale/tr.po +++ b/locale/tr.po @@ -412,12 +412,14 @@ msgstr "Adres %d byte uzunluğunda olmalıdır" msgid "All CAN peripherals are in use" msgstr "Tüm CAN çevre birimleri kullanımda" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "Tüm I2C çevre birimleri kullanımda" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1606,7 +1608,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "" @@ -2339,11 +2341,11 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "" @@ -2535,7 +2537,7 @@ msgstr "" msgid "can't cancel self" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -3272,6 +3274,10 @@ msgstr "" msgid "invalid micropython decorator" msgstr "" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "" @@ -3527,7 +3533,7 @@ msgstr "" msgid "no response from SD card" msgstr "" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 142941392e..2edd1eef17 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -409,12 +409,14 @@ msgstr "dìzhǐ chángdù bìxū shì %d zìjié" msgid "All CAN peripherals are in use" msgstr "suǒyǒu CAN wàishè dōu zài shǐyòng zhōng" -#: ports/espressif/common-hal/busio/I2C.c -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c -#: ports/nrf/common-hal/busio/I2C.c +#: ports/espressif/common-hal/busio/I2C.c ports/nrf/common-hal/busio/I2C.c msgid "All I2C peripherals are in use" msgstr "suǒyǒu I2C wàishè dōu zài shǐyòng zhōng" +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c +msgid "All I2C targets are in use" +msgstr "" + #: ports/espressif/common-hal/countio/Counter.c #: ports/espressif/common-hal/frequencyio/FrequencyIn.c #: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -1630,7 +1632,7 @@ msgstr "" msgid "Only one TouchAlarm can be set in deep sleep." msgstr "zhǐ yǒu yí gè chù mō bì kě yǐ shè zhì zài shēn dù shuì mián." -#: ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +#: ports/espressif/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" msgstr "zhǐ yǔn xǔ yí gè dì zhǐ" @@ -2384,11 +2386,11 @@ msgstr "__new__ cānshù bìxū shì yònghù lèixíng" msgid "a bytes-like object is required" msgstr "xūyào yīgè zì jié lèi duìxiàng" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "address out of bounds" msgstr "dìzhǐ chāochū biānjiè" -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: shared-bindings/i2ctarget/I2CTarget.c msgid "addresses is empty" msgstr "dìzhǐ wèi kōng" @@ -2580,7 +2582,7 @@ msgstr "bùnéng fēnpèi dào biǎodá shì" msgid "can't cancel self" msgstr "bù néng qǔ xiāo zì wǒ" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2ctarget/I2CTarget.c #: shared-module/adafruit_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "Wúfǎ jiāng %q zhuǎnhuàn wèi %q" @@ -3323,6 +3325,10 @@ msgstr "wú xiào zhǔ jī míng" msgid "invalid micropython decorator" msgstr "wúxiào de MicroPython zhuāngshì qì" +#: ports/espressif/common-hal/esp32_camera/Camera.c +msgid "invalid setting" +msgstr "" + #: shared-bindings/random/__init__.c msgid "invalid step" msgstr "wúxiào bùzhòu" @@ -3579,7 +3585,7 @@ msgstr "Méiyǒu kěyòng de fùwèi yǐn jiǎo" msgid "no response from SD card" msgstr "SD kǎ wú huíyīng" -#: py/objobject.c py/runtime.c +#: ports/espressif/common-hal/esp32_camera/Camera.c py/objobject.c py/runtime.c msgid "no such attribute" msgstr "méiyǒu cǐ shǔxìng" diff --git a/main.c b/main.c index f17731950f..12de1b6c0e 100644 --- a/main.c +++ b/main.c @@ -213,8 +213,9 @@ void supervisor_execution_status(void) { if (_current_executing_filename != NULL) { serial_write(_current_executing_filename); } else if ((_exec_result.return_code & PYEXEC_EXCEPTION) != 0 && + _exec_result.exception_line > 0 && exception != NULL) { - mp_printf(&mp_plat_print, "@%d %q", _exec_result.exception_line, exception->base.type->name); + mp_printf(&mp_plat_print, "%d@%s %q", _exec_result.exception_line, _exec_result.exception_filename, exception->base.type->name); } else { serial_write_compressed(translate("Done")); } diff --git a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk index a347b70a63..cf64b05bcf 100644 --- a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk @@ -11,5 +11,3 @@ CIRCUITPY_BUILD_EXTENSIONS = bin,uf2 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -CIRCUITPY_ONEWIREIO = 0 diff --git a/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk b/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk index f0857ce6d2..1a8cddfda7 100644 --- a/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk +++ b/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk @@ -9,5 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "MX25L51245G","GD25S512MD" LONGINT_IMPL = MPZ - -CIRCUITPY_ONEWIREIO = 0 diff --git a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk index 975d892b9a..c108a90250 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk @@ -15,7 +15,6 @@ LONGINT_IMPL = NONE CIRCUITPY_BUSDEVICE = 1 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_KEYPAD = 0 -CIRCUITPY_ONEWIREIO = 0 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground/frozen_cpx diff --git a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk index 4338fe3e1e..cc125e1ffb 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk @@ -12,7 +12,6 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C" # Turn off features and optimizations for displayio build to make room for additional frozen libs. LONGINT_IMPL = NONE CIRCUITPY_KEYPAD = 0 -CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_PIXELBUF = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 diff --git a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk index 9636c195dc..811336885b 100644 --- a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk @@ -9,5 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "S25FL064L" LONGINT_IMPL = MPZ - -CIRCUITPY_ONEWIREIO = 0 diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index 5a6b43e475..102701a295 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -104,8 +104,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_PA00, NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/hallowing_m4_express/board.c b/ports/atmel-samd/boards/hallowing_m4_express/board.c index d17835d0f8..add1844fcb 100644 --- a/ports/atmel-samd/boards/hallowing_m4_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m4_express/board.c @@ -84,8 +84,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_PB14, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/monster_m4sk/board.c b/ports/atmel-samd/boards/monster_m4sk/board.c index e42721dee7..dd8244e003 100644 --- a/ports/atmel-samd/boards/monster_m4sk/board.c +++ b/ports/atmel-samd/boards/monster_m4sk/board.c @@ -85,8 +85,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_PA23, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/pewpew_lcd/board.c b/ports/atmel-samd/boards/pewpew_lcd/board.c index 7f5cac5241..10c657aee8 100644 --- a/ports/atmel-samd/boards/pewpew_lcd/board.c +++ b/ports/atmel-samd/boards/pewpew_lcd/board.c @@ -84,7 +84,6 @@ void board_init(void) { NULL, // &pin_PA17, // brightness pin NO_BRIGHTNESS_COMMAND, 0.0f, // brightness - false, // auto_brightness false, // single_byte_bounds true, // data as commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/pewpew_lcd/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew_lcd/mpconfigboard.mk index 2bf4992e25..94d0530ce2 100644 --- a/ports/atmel-samd/boards/pewpew_lcd/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew_lcd/mpconfigboard.mk @@ -33,7 +33,7 @@ CIRCUITPY_BLEIO = 0 CIRCUITPY_BUSDEVICE = 0 CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_MSGPACK = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NVM = 0 diff --git a/ports/atmel-samd/boards/pewpew_m4/board.c b/ports/atmel-samd/boards/pewpew_m4/board.c index 331056fb9f..0dc8c9f4c5 100644 --- a/ports/atmel-samd/boards/pewpew_m4/board.c +++ b/ports/atmel-samd/boards/pewpew_m4/board.c @@ -137,8 +137,7 @@ void board_init(void) { sizeof(display_init_sequence), NULL, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands false, // auto_refresh diff --git a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk index 06346b43de..bcf3e132d3 100644 --- a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk @@ -18,7 +18,7 @@ CIRCUITPY_AUDIOPWMIO = 0 CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANG_APA102 = 0 CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PIXELBUF = 0 diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 17b7b180ed..9160b0260c 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -105,8 +105,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_PA01, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index a9041de305..e324999a87 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -107,8 +107,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_PA01, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index 8176d363c9..676461c7f5 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -94,8 +94,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_PB31, // Backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/pyportal_titano/board.c b/ports/atmel-samd/boards/pyportal_titano/board.c index fcf8c5f44d..635025396d 100644 --- a/ports/atmel-samd/boards/pyportal_titano/board.c +++ b/ports/atmel-samd/boards/pyportal_titano/board.c @@ -111,8 +111,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_PB31, // Backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c index 4a25ed64ec..ac357401f5 100644 --- a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c +++ b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c @@ -102,8 +102,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_PC05, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/seeeduino_xiao_kb/mpconfigboard.mk b/ports/atmel-samd/boards/seeeduino_xiao_kb/mpconfigboard.mk index 7a67048e0b..d0ff1fa05c 100644 --- a/ports/atmel-samd/boards/seeeduino_xiao_kb/mpconfigboard.mk +++ b/ports/atmel-samd/boards/seeeduino_xiao_kb/mpconfigboard.mk @@ -22,8 +22,8 @@ CIRCUITPY_RTC = 0 CIRCUITPY_MATH = 0 #CIRCUITPY_RANDOM = 0 CIRCUITPY_ONEWIREIO = 0 -#CIRCUITPY_NEOPIXEL_WRITE = 1 # Needed fo RGB LEDs -#CIRCUITPY_RAINBOWIO = 1 # Needed fo RGB LEDs +CIRCUITPY_NEOPIXEL_WRITE = 1 # Needed for RGB LEDs +CIRCUITPY_RAINBOWIO = 1 # Needed for RGB LEDs # These are used in a keyboard or computer input device. CIRCUITPY_ROTARYIO = 1 CIRCUITPY_KEYPAD = 1 diff --git a/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk b/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk index 0fc15cb321..37c869e972 100644 --- a/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk @@ -11,5 +11,4 @@ LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 # There are many pin definitions on this board; it doesn't quite fit on very large translations. -CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_USB_MIDI = 0 diff --git a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk index 7b97822bda..70ece9b9fc 100755 --- a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk @@ -9,5 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q32FV" LONGINT_IMPL = MPZ - -CIRCUITPY_ONEWIREIO = 0 diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk index d65be3f800..1088ca1e8d 100644 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk @@ -9,5 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q64JVxQ" LONGINT_IMPL = MPZ - -CIRCUITPY_ONEWIREIO = 0 diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index 53bc613088..371a1cabb3 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -105,7 +105,6 @@ void board_init(void) { NULL, NO_BRIGHTNESS_COMMAND, 1.0f, // brightness - false, // auto_brightness false, // single_byte_bounds false, // data as commands true, // auto_refresh diff --git a/ports/atmel-samd/boards/ugame10/mpconfigboard.mk b/ports/atmel-samd/boards/ugame10/mpconfigboard.mk index f942490f29..7eb0ec8412 100644 --- a/ports/atmel-samd/boards/ugame10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/ugame10/mpconfigboard.mk @@ -22,7 +22,7 @@ CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PIXELBUF = 0 diff --git a/ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk index 5bf70a9668..00b9b64a33 100644 --- a/ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk +++ b/ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk @@ -23,7 +23,7 @@ CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_BLEIO = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_KEYPAD = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_PS2IO = 0 diff --git a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk index 653d2e6ed5..17638a0ebd 100644 --- a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk +++ b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk @@ -22,7 +22,7 @@ CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_KEYPAD = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_PS2IO = 0 diff --git a/ports/atmel-samd/common-hal/i2cperipheral/__init__.c b/ports/atmel-samd/common-hal/i2cperipheral/__init__.c deleted file mode 100644 index c67511c536..0000000000 --- a/ports/atmel-samd/common-hal/i2cperipheral/__init__.c +++ /dev/null @@ -1 +0,0 @@ -// No i2cperipheral module functions. diff --git a/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c b/ports/atmel-samd/common-hal/i2ctarget/I2CTarget.c similarity index 83% rename from ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c rename to ports/atmel-samd/common-hal/i2ctarget/I2CTarget.c index ae118c1909..a687143281 100644 --- a/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c +++ b/ports/atmel-samd/common-hal/i2ctarget/I2CTarget.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "shared-bindings/i2cperipheral/I2CPeripheral.h" +#include "shared-bindings/i2ctarget/I2CTarget.h" #include "shared-bindings/microcontroller/Pin.h" #include "common-hal/busio/I2C.h" @@ -36,7 +36,7 @@ #include "hal/include/hal_gpio.h" #include "peripherals/samd/sercom.h" -void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_obj_t *self, +void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint8_t *addresses, unsigned int num_addresses, bool smbus) { uint8_t sercom_index; @@ -100,12 +100,12 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe sercom->I2CS.CTRLA.bit.ENABLE = 1; } -bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self) { +bool common_hal_i2ctarget_i2c_target_deinited(i2ctarget_i2c_target_obj_t *self) { return self->sda_pin == NO_PIN; } -void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self) { - if (common_hal_i2cperipheral_i2c_peripheral_deinited(self)) { +void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self) { + if (common_hal_i2ctarget_i2c_target_deinited(self)) { return; } @@ -117,7 +117,7 @@ void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral self->scl_pin = NO_PIN; } -static int i2c_peripheral_check_error(i2cperipheral_i2c_peripheral_obj_t *self, bool raise) { +static int i2c_target_check_error(i2ctarget_i2c_target_obj_t *self, bool raise) { if (!self->sercom->I2CS.INTFLAG.bit.ERROR) { return 0; } @@ -136,8 +136,8 @@ static int i2c_peripheral_check_error(i2cperipheral_i2c_peripheral_obj_t *self, return -err; } -int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) { - int err = i2c_peripheral_check_error(self, false); +int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) { + int err = i2c_target_check_error(self, false); if (err) { return err; } @@ -154,22 +154,22 @@ int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_perip for (unsigned int i = 0; i < self->num_addresses; i++) { if (*address == self->addresses[i]) { - common_hal_i2cperipheral_i2c_peripheral_ack(self, true); + common_hal_i2ctarget_i2c_target_ack(self, true); return 1; } } // This should clear AMATCH, but it doesn't... - common_hal_i2cperipheral_i2c_peripheral_ack(self, false); + common_hal_i2ctarget_i2c_target_ack(self, false); return 0; } -int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *data) { +int common_hal_i2ctarget_i2c_target_read_byte(i2ctarget_i2c_target_obj_t *self, uint8_t *data) { for (int t = 0; t < 100 && !self->sercom->I2CS.INTFLAG.reg; t++) { mp_hal_delay_us(10); } - i2c_peripheral_check_error(self, true); + i2c_target_check_error(self, true); if (!self->sercom->I2CS.INTFLAG.bit.DRDY || self->sercom->I2CS.INTFLAG.bit.PREC || @@ -181,12 +181,12 @@ int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripher return 1; } -int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t data) { +int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self, uint8_t data) { for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { mp_hal_delay_us(10); } - i2c_peripheral_check_error(self, true); + i2c_target_check_error(self, true); if (self->sercom->I2CS.INTFLAG.bit.PREC) { return 0; @@ -208,12 +208,12 @@ int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_periphe return 1; } -void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_obj_t *self, bool ack) { +void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack) { self->sercom->I2CS.CTRLB.bit.ACKACT = !ack; self->sercom->I2CS.CTRLB.bit.CMD = 0x03; } -void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_obj_t *self) { +void common_hal_i2ctarget_i2c_target_close(i2ctarget_i2c_target_obj_t *self) { for (int t = 0; !self->sercom->I2CS.INTFLAG.reg && t < 100; t++) { mp_hal_delay_us(10); } @@ -223,7 +223,7 @@ void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_ } if (!self->sercom->I2CS.STATUS.bit.DIR) { - common_hal_i2cperipheral_i2c_peripheral_ack(self, false); + common_hal_i2ctarget_i2c_target_ack(self, false); } else { int i = 0; while (self->sercom->I2CS.INTFLAG.reg == SERCOM_I2CS_INTFLAG_DRDY) { diff --git a/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.h b/ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h similarity index 85% rename from ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.h rename to ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h index 03ae3a2885..894961ab7b 100644 --- a/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.h +++ b/ports/atmel-samd/common-hal/i2ctarget/I2CTarget.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H -#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H #include "common-hal/microcontroller/Pin.h" #include "py/obj.h" @@ -40,6 +40,6 @@ typedef struct { uint8_t scl_pin; uint8_t sda_pin; bool writing; -} i2cperipheral_i2c_peripheral_obj_t; +} i2ctarget_i2c_target_obj_t; -#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H +#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_TARGET_H diff --git a/ports/atmel-samd/common-hal/i2ctarget/__init__.c b/ports/atmel-samd/common-hal/i2ctarget/__init__.c new file mode 100644 index 0000000000..4ec26465ad --- /dev/null +++ b/ports/atmel-samd/common-hal/i2ctarget/__init__.c @@ -0,0 +1 @@ +// No i2ctarget module functions. diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 56cde4964b..a03fc1d320 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -38,7 +38,7 @@ CIRCUITPY_FRAMEBUFFERIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_GETPASS ?= 0 CIRCUITPY_GIFIO ?= 0 -CIRCUITPY_I2CPERIPHERAL ?= 0 +CIRCUITPY_I2CTARGET ?= 0 CIRCUITPY_JSON ?= 0 CIRCUITPY_KEYPAD ?= 0 CIRCUITPY_MSGPACK ?= 0 diff --git a/ports/broadcom/mpconfigport.mk b/ports/broadcom/mpconfigport.mk index d0c6acf408..839ef00514 100644 --- a/ports/broadcom/mpconfigport.mk +++ b/ports/broadcom/mpconfigport.mk @@ -9,7 +9,7 @@ CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOIO = 0 CIRCUITPY_COUNTIO = 0 CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_NVM = 0 CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PULSEIO = 0 diff --git a/ports/cxd56/mpconfigport.mk b/ports/cxd56/mpconfigport.mk index 2f0cd90c7f..cb54233a07 100644 --- a/ports/cxd56/mpconfigport.mk +++ b/ports/cxd56/mpconfigport.mk @@ -15,7 +15,7 @@ CIRCUITPY_COUNTIO = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_GNSS = 1 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NVM = 0 diff --git a/ports/espressif/CMakeLists.txt b/ports/espressif/CMakeLists.txt index 1c79b448fe..d05af27539 100644 --- a/ports/espressif/CMakeLists.txt +++ b/ports/espressif/CMakeLists.txt @@ -8,6 +8,13 @@ set(ENV{IDF_PATH} ${CMAKE_SOURCE_DIR}/esp-idf) # can build. set(COMPONENTS esptool_py soc driver log main esp-tls mbedtls mdns esp_event esp_adc_cal esp_netif esp_wifi lwip wpa_supplicant freertos bt usb) +if("${CIRCUITPY_ESP32_CAMERA}") +message("Including esp32-camera") +set(EXTRA_COMPONENT_DIRS "esp32-camera") +list(APPEND COMPONENTS "esp32-camera") +message("COMPONENTS = ${COMPONENTS}") +endif() + include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(circuitpython) diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index e111fa3441..af1788d01e 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -261,7 +261,6 @@ SRC_C += \ peripherals/touch.c ifeq ($(IDF_TARGET),esp32s2) SRC_C += \ - cam.c \ i2s_lcd_esp32s2_driver.c endif endif @@ -283,6 +282,15 @@ endif SRC_C += $(wildcard common-hal/espidf/*.c) +ifneq ($(CIRCUITPY_ESP32_CAMERA),0) +SRC_CAMERA := \ + $(wildcard common-hal/esp32_camera/*.c) \ + $(wildcard bindings/esp32_camera/*.c) +SRC_C += $(SRC_CAMERA) +CFLAGS += -isystem esp32-camera/driver/include +CFLAGS += -isystem esp32-camera/conversions/include +endif + SRC_COMMON_HAL_EXPANDED = \ $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ @@ -341,8 +349,10 @@ ifneq ($(CIRCUITPY_BLEIO),0) SDKCONFIGS := esp-idf-config/sdkconfig-ble.defaults;$(SDKCONFIGS) endif # create the config headers -$(BUILD)/esp-idf/config/sdkconfig.h: boards/$(BOARD)/sdkconfig | $(BUILD)/esp-idf - IDF_PATH=$(IDF_PATH) cmake -S . -B $(BUILD)/esp-idf -DSDKCONFIG=$(BUILD)/esp-idf/sdkconfig -DSDKCONFIG_DEFAULTS="$(SDKCONFIGS)" -DCMAKE_TOOLCHAIN_FILE=$(IDF_PATH)/tools/cmake/toolchain-$(IDF_TARGET).cmake -DIDF_TARGET=$(IDF_TARGET) -GNinja +.PHONY: do-sdkconfig +do-sdkconfig: $(BUILD)/esp-idf/config/sdkconfig.h +$(BUILD)/esp-idf/config/sdkconfig.h: boards/$(BOARD)/sdkconfig CMakeLists.txt | $(BUILD)/esp-idf + IDF_PATH=$(IDF_PATH) cmake -S . -B $(BUILD)/esp-idf -DSDKCONFIG=$(BUILD)/esp-idf/sdkconfig -DSDKCONFIG_DEFAULTS="$(SDKCONFIGS)" -DCMAKE_TOOLCHAIN_FILE=$(IDF_PATH)/tools/cmake/toolchain-$(IDF_TARGET).cmake -DIDF_TARGET=$(IDF_TARGET) -GNinja -DCIRCUITPY_ESP32_CAMERA=$(CIRCUITPY_ESP32_CAMERA) # build a lib # Adding -d explain -j 1 -v to the ninja line will output debug info @@ -391,6 +401,11 @@ BINARY_BLOBS += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a ESP_IDF_COMPONENTS_EXPANDED += esp-idf/components/xtensa/$(IDF_TARGET)/libxt_hal.a endif +ifneq ($(CIRCUITPY_ESP32_CAMERA),0) +ESP_IDF_COMPONENTS_EXPANDED += $(BUILD)/esp-idf/esp-idf/esp32-camera/libesp32-camera.a +#$(error $(ESP_IDF_COMPONENTS_EXPANDED)) +endif + # BOOTLOADER_OFFSET is determined by chip type, based on the ROM bootloader, and is not changeable. ifeq ($(IDF_TARGET),esp32) BOOTLOADER_OFFSET = 0x1000 diff --git a/ports/espressif/bindings/esp32_camera/Camera.c b/ports/espressif/bindings/esp32_camera/Camera.c new file mode 100644 index 0000000000..08bf48bc9b --- /dev/null +++ b/ports/espressif/bindings/esp32_camera/Camera.c @@ -0,0 +1,1030 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Jeff Epler for Adafruit Industries + * + * 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. + */ + +#include + +#include "py/mphal.h" +#include "py/obj.h" +#include "py/objproperty.h" +#include "py/runtime.h" + +#include "bindings/esp32_camera/__init__.h" +#include "bindings/esp32_camera/Camera.h" +#include "common-hal/esp32_camera/Camera.h" + +#include "shared-bindings/displayio/Bitmap.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/util.h" +#include "esp_camera.h" +#include "sensor.h" + +//| class Camera: +//| def __init__( +//| self, +//| *, +//| data_pins: List[microcontroller.Pin], +//| pixel_clock: microcontroller.Pin, +//| vsync: microcontroller.Pin, +//| href: microcontroller.Pin, +//| i2c: busio.I2C, +//| external_clock_pin: microcontroller.Pin, +//| external_clock_frequency: int, +//| powerdown_pin: Optional[microcontroller.Pin] = None, +//| reset_pin: Optional[microcontroller.Pin] = None, +//| pixel_format: PixelFormat=PixelFormat.RGB565, +//| frame_size: FrameSize=FrameSize.QQVGA, +//| jpeg_quality: int=15, +//| framebuffer_count: int = 1, +//| grab_mode: GrabMode = GrabMode.WHEN_EMPTY, +//| ) -> None: +//| """ +//| Configure and initialize a camera with the given properties +//| +//| This driver requires that the ``CIRCUITPY_RESERVED_PSRAM`` in ``/.env`` be large enough to hold the camera frambuffer(s). Generally, boards with built-in cameras will have a default setting that is large enough. If the constructor raises a MemoryError, this probably indicates the setting is too small and should be increased. +//| +//| +//| .. important:: +//| +//| Not all supported sensors have all +//| of the properties listed below. For instance, the +//| OV5640 supports `denoise`, but the +//| OV2640 does not. The underlying esp32-camera +//| library does not provide a reliable API to check +//| which settings are supported. CircuitPython makes +//| a best effort to determine when an unsupported +//| property is set and will raise an exception in +//| that case. +//| +//| :param data_pins: The 8 data data_pins used for image data transfer from the camera module, least significant bit first +//| :param pixel_clock: The pixel clock output from the camera module +//| :param vsync: The vertical sync pulse output from the camera module +//| :param href: The horizontal reference output from the camera module +//| :param i2c: The I2C bus connected to the camera module +//| :param external_clock_frequency: The frequency generated on the external clock pin +//| :param external_clock_pin: The pin on which to generate the external clock +//| :param powerdown_pin: The powerdown input to the camera module +//| :param reset_pin: The reset input to the camera module +//| :param pixel_format: The pixel format of the captured image +//| :param frame_size: The size of captured image +//| :param jpeg_quality: For `PixelFormat.JPEG`, the quality. Higher numbers increase quality. If the quality is too high, the JPEG data will be larger than the availalble buffer size and the image will be unusable or truncated. The exact range of appropriate values depends on the sensor and must be determined empirically. +//| :param framebuffer_count: The number of framebuffers (1 for single-buffered and 2 for double-buffered) +//| :param grab_mode: When to grab a new frame +//| """ +//| +STATIC mp_obj_t esp32_camera_camera_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_data_pins, ARG_pixel_clock_pin, ARG_vsync_pin, ARG_href_pin, ARG_i2c, ARG_external_clock_pin, ARG_external_clock_frequency, ARG_powerdown_pin, ARG_reset_pin, ARG_pixel_format, ARG_frame_size, ARG_jpeg_quality, ARG_framebuffer_count, ARG_grab_mode, NUM_ARGS }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_data_pins, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, + { MP_QSTR_pixel_clock_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, + { MP_QSTR_vsync_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, + { MP_QSTR_href_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, + { MP_QSTR_i2c, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, + { MP_QSTR_external_clock_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY }, + { MP_QSTR_external_clock_frequency, MP_ARG_INT | MP_ARG_REQUIRED }, + { MP_QSTR_powerdown_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = MP_ROM_NONE } }, + { MP_QSTR_reset_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = MP_ROM_NONE } }, + { MP_QSTR_pixel_format, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = MP_ROM_PTR((void *)&pixel_format_RGB565_obj) } }, + { MP_QSTR_frame_size, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = MP_ROM_PTR((void *)&frame_size_QQVGA_obj) } }, + { MP_QSTR_jpeg_quality, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 15 } }, + { MP_QSTR_framebuffer_count, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 1 } }, + { MP_QSTR_grab_mode, MP_ARG_OBJ | MP_ARG_KW_ONLY, { .u_obj = MP_ROM_PTR((void *)&grab_mode_WHEN_EMPTY_obj) } }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + uint8_t data_pins[8]; + uint8_t data_pin_count; + validate_pins(MP_QSTR_data_pins, data_pins, MP_ARRAY_SIZE(data_pins), args[ARG_data_pins].u_obj, &data_pin_count); + mp_arg_validate_length(data_pin_count, 8, MP_QSTR_data_pins); + + const mcu_pin_obj_t *pixel_clock_pin = validate_obj_is_free_pin(args[ARG_pixel_clock_pin].u_obj); + const mcu_pin_obj_t *vsync_pin = validate_obj_is_free_pin(args[ARG_vsync_pin].u_obj); + const mcu_pin_obj_t *href_pin = validate_obj_is_free_pin(args[ARG_href_pin].u_obj); + const busio_i2c_obj_t *i2c = MP_OBJ_TO_PTR(mp_arg_validate_type(args[ARG_i2c].u_obj, &busio_i2c_type, MP_QSTR_i2c)); + const mcu_pin_obj_t *external_clock_pin = validate_obj_is_free_pin(args[ARG_external_clock_pin].u_obj); + const mcu_pin_obj_t *powerdown_pin = validate_obj_is_free_pin_or_none(args[ARG_powerdown_pin].u_obj); + const mcu_pin_obj_t *reset_pin = validate_obj_is_free_pin_or_none(args[ARG_reset_pin].u_obj); + const mp_int_t external_clock_frequency = mp_arg_validate_int_range(args[ARG_external_clock_frequency].u_int, 0, 40000000, MP_QSTR_clock_frequency); + + camera_grab_mode_t grab_mode = validate_grab_mode(args[ARG_grab_mode].u_obj, MP_QSTR_grab_mode); + framesize_t frame_size = validate_frame_size(args[ARG_frame_size].u_obj, MP_QSTR_frame_size); + pixformat_t pixel_format = validate_pixel_format(args[ARG_pixel_format].u_obj, MP_QSTR_pixel_format); + mp_int_t jpeg_quality = mp_arg_validate_int_range(args[ARG_jpeg_quality].u_int, 2, 55, MP_QSTR_jpeg_quality); + mp_int_t framebuffer_count = mp_arg_validate_int_range(args[ARG_framebuffer_count].u_int, 1, 2, MP_QSTR_framebuffer_count); + + esp32_camera_camera_obj_t *self = m_new_obj(esp32_camera_camera_obj_t); + self->base.type = &esp32_camera_camera_type; + common_hal_esp32_camera_camera_construct( + self, + data_pins, + external_clock_pin, + pixel_clock_pin, + vsync_pin, + href_pin, + powerdown_pin, + reset_pin, + i2c, + external_clock_frequency, + pixel_format, + frame_size, + jpeg_quality, + framebuffer_count, + grab_mode); + return MP_OBJ_FROM_PTR(self); +} + +//| def deinit(self) -> None: +//| """Deinitialises the camera and releases all memory resources for reuse.""" +//| ... +//| +STATIC mp_obj_t esp32_camera_camera_deinit(mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_esp32_camera_camera_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_deinit_obj, esp32_camera_camera_deinit); + +STATIC void check_for_deinit(esp32_camera_camera_obj_t *self) { + if (common_hal_esp32_camera_camera_deinited(self)) { + raise_deinited_error(); + } +} + +//| def __enter__(self) -> Camera: +//| """No-op used by Context Managers.""" +//| ... +//| +// Provided by context manager helper. + +//| def __exit__(self) -> None: +//| """Automatically deinitializes the hardware when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info.""" +//| ... +//| +STATIC mp_obj_t esp32_camera_camera_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + return esp32_camera_camera_deinit(args[0]); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_camera_camera___exit___obj, 4, 4, esp32_camera_camera_obj___exit__); + +//| frame_available: bool +//| """True if a frame is available, False otherwise""" + +STATIC mp_obj_t esp32_camera_camera_frame_available_get(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(esp_camera_fb_available()); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_frame_available_get_obj, esp32_camera_camera_frame_available_get); + +MP_PROPERTY_GETTER(esp32_camera_camera_frame_available_obj, + (mp_obj_t)&esp32_camera_camera_frame_available_get_obj); + +//| def take(self, timeout: Optional[float]=0.25) -> Optional[displayio.Bitmap | ReadableBuffer]: +//| """Record a frame. Wait up to 'timeout' seconds for a frame to be captured. +//| +//| In the case of timeout, `None` is returned. +//| If `pixel_format` is `PixelFormat.JPEG`, the returned value is a read-only `memoryview`. +//| Otherwise, the returned value is a read-only `displayio.Bitmap`. +//| """ +//| +STATIC mp_obj_t esp32_camera_camera_take(size_t n_args, const mp_obj_t *args) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(args[0]); + mp_float_t timeout = n_args < 2 ? MICROPY_FLOAT_CONST(0.25) : mp_obj_get_float(args[1]); + check_for_deinit(self); + camera_fb_t *result = common_hal_esp32_camera_camera_take(self, (int)MICROPY_FLOAT_C_FUN(round)(timeout * 1000)); + if (!result) { + return mp_const_none; + } + pixformat_t format = common_hal_esp32_camera_camera_get_pixel_format(self); + if (format == PIXFORMAT_JPEG) { + return mp_obj_new_memoryview('b', result->len, result->buf); + } else { + int width = common_hal_esp32_camera_camera_get_width(self); + int height = common_hal_esp32_camera_camera_get_height(self); + displayio_bitmap_t *bitmap = m_new_obj(displayio_bitmap_t); + bitmap->base.type = &displayio_bitmap_type; + common_hal_displayio_bitmap_construct_from_buffer(bitmap, width, height, (format == PIXFORMAT_RGB565) ? 16 : 8, (uint32_t *)(void *)result->buf, true); + return bitmap; + } +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp32_camera_camera_take_obj, 1, 2, esp32_camera_camera_take); + + +//| def reconfigure( +//| self, +//| frame_size: Optional[FrameSize] = None, +//| pixel_format: Optional[PixelFormat] = None, +//| grab_mode: Optional[GrabMode] = None, +//| framebuffer_count: Optional[int] = None, +//| ) -> None: +//| """Change multiple related camera settings simultaneously +//| +//| Because these settings interact in complex ways, and take longer than +//| the other properties to set, they are set together in a single function call. +//| +//| If an argument is unspecified or None, then the setting is unchanged.""" +//| + +STATIC mp_obj_t esp32_camera_camera_reconfigure(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); + + enum { ARG_frame_size, ARG_pixel_format, ARG_grab_mode, ARG_framebuffer_count }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_frame_size, MP_ARG_OBJ, {.u_obj = MP_ROM_NONE} }, + { MP_QSTR_pixel_format, MP_ARG_OBJ, {.u_obj = MP_ROM_NONE} }, + { MP_QSTR_grab_mode, MP_ARG_OBJ, {.u_obj = MP_ROM_NONE} }, + { MP_QSTR_framebuffer_count, MP_ARG_OBJ, {.u_obj = MP_ROM_NONE} }, + }; + + 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); + + framesize_t frame_size = + args[ARG_frame_size].u_obj != MP_ROM_NONE + ? validate_frame_size(args[ARG_frame_size].u_obj, MP_QSTR_frame_size) + : common_hal_esp32_camera_camera_get_frame_size(self); + pixformat_t pixel_format = + args[ARG_pixel_format].u_obj != MP_ROM_NONE + ? validate_pixel_format(args[ARG_pixel_format].u_obj, MP_QSTR_pixel_format) + : common_hal_esp32_camera_camera_get_pixel_format(self); + camera_grab_mode_t grab_mode = + args[ARG_grab_mode].u_obj != MP_ROM_NONE + ? validate_grab_mode(args[ARG_grab_mode].u_obj, MP_QSTR_grab_mode) + : common_hal_esp32_camera_camera_get_grab_mode(self); + bool framebuffer_count = + args[ARG_framebuffer_count].u_obj != MP_ROM_NONE + ? mp_obj_get_int(args[ARG_framebuffer_count].u_obj) + : common_hal_esp32_camera_camera_get_framebuffer_count(self); + + common_hal_esp32_camera_camera_reconfigure(self, frame_size, pixel_format, grab_mode, framebuffer_count); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(esp32_camera_camera_reconfigure_obj, 1, esp32_camera_camera_reconfigure); + +//| pixel_format: PixelFormat +//| """The pixel format of captured frames""" + +STATIC mp_obj_t esp32_camera_camera_get_pixel_format(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return cp_enum_find(&esp32_camera_pixel_format_type, common_hal_esp32_camera_camera_get_pixel_format(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_pixel_format_obj, esp32_camera_camera_get_pixel_format); + +MP_PROPERTY_GETTER(esp32_camera_camera_pixel_format_obj, + (mp_obj_t)&esp32_camera_camera_get_pixel_format_obj); + + +//| frame_size: FrameSize +//| """The size of captured frames""" + +STATIC mp_obj_t esp32_camera_camera_get_frame_size(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return cp_enum_find(&esp32_camera_frame_size_type, common_hal_esp32_camera_camera_get_frame_size(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_frame_size_obj, esp32_camera_camera_get_frame_size); + +MP_PROPERTY_GETTER(esp32_camera_camera_frame_size_obj, + (mp_obj_t)&esp32_camera_camera_get_frame_size_obj); + +//| contrast: int +//| """The sensor contrast. Positive values increase contrast, negative values lower it. The total range is device-specific but is often from -2 to +2 inclusive.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_contrast(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_contrast(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_contrast_obj, esp32_camera_camera_get_contrast); + +STATIC mp_obj_t esp32_camera_camera_set_contrast(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_contrast(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_contrast_obj, esp32_camera_camera_set_contrast); +MP_PROPERTY_GETSET(esp32_camera_camera_contrast_obj, + (mp_obj_t)&esp32_camera_camera_get_contrast_obj, + (mp_obj_t)&esp32_camera_camera_set_contrast_obj); + +//| brightness: int +//| """The sensor brightness. Positive values increase brightness, negative values lower it. The total range is device-specific but is often from -2 to +2 inclusive.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_brightness(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_brightness(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_brightness_obj, esp32_camera_camera_get_brightness); + +STATIC mp_obj_t esp32_camera_camera_set_brightness(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_brightness(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_brightness_obj, esp32_camera_camera_set_brightness); +MP_PROPERTY_GETSET(esp32_camera_camera_brightness_obj, + (mp_obj_t)&esp32_camera_camera_get_brightness_obj, + (mp_obj_t)&esp32_camera_camera_set_brightness_obj); + +//| saturation: int +//| """The sensor saturation. Positive values increase saturation (more vibrant colors), negative values lower it (more muted colors). The total range is device-specific but the value is often from -2 to +2 inclusive.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_saturation(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_saturation(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_saturation_obj, esp32_camera_camera_get_saturation); + +STATIC mp_obj_t esp32_camera_camera_set_saturation(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_saturation(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_saturation_obj, esp32_camera_camera_set_saturation); +MP_PROPERTY_GETSET(esp32_camera_camera_saturation_obj, + (mp_obj_t)&esp32_camera_camera_get_saturation_obj, + (mp_obj_t)&esp32_camera_camera_set_saturation_obj); + +//| sharpness: int +//| """The sensor sharpness. Positive values increase sharpness (more defined edges), negative values lower it (softer edges). The total range is device-specific but the value is often from -2 to +2 inclusive.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_sharpness(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_sharpness(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_sharpness_obj, esp32_camera_camera_get_sharpness); + +STATIC mp_obj_t esp32_camera_camera_set_sharpness(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_sharpness(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_sharpness_obj, esp32_camera_camera_set_sharpness); +MP_PROPERTY_GETSET(esp32_camera_camera_sharpness_obj, + (mp_obj_t)&esp32_camera_camera_get_sharpness_obj, + (mp_obj_t)&esp32_camera_camera_set_sharpness_obj); + +//| denoise: int +//| """The sensor 'denoise' setting. Any camera sensor has inherent 'noise', especially in low brightness environments. Software algorithms can decrease noise at the expense of fine detail. A larger value increases the amount of software noise removal. The total range is device-specific but the value is often from 0 to 10.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_denoise(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_denoise(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_denoise_obj, esp32_camera_camera_get_denoise); + +STATIC mp_obj_t esp32_camera_camera_set_denoise(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_denoise(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_denoise_obj, esp32_camera_camera_set_denoise); +MP_PROPERTY_GETSET(esp32_camera_camera_denoise_obj, + (mp_obj_t)&esp32_camera_camera_get_denoise_obj, + (mp_obj_t)&esp32_camera_camera_set_denoise_obj); + +//| gain_ceiling: GainCeiling +//| """The sensor 'gain ceiling' setting. "Gain" is an analog multiplier applied to the raw sensor data. The 'ceiling' is the maximum gain value that the sensor will use. A higher gain means that the sensor has a greater response to light, but also makes sensor noise more visible.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_gain_ceiling(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return cp_enum_find(&esp32_camera_gain_ceiling_type, common_hal_esp32_camera_camera_get_gainceiling(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_gain_ceiling_obj, esp32_camera_camera_get_gain_ceiling); + +STATIC mp_obj_t esp32_camera_camera_set_gain_ceiling(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_gainceiling(self, validate_gain_ceiling(arg, MP_QSTR_gain_ceiling)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_gain_ceiling_obj, esp32_camera_camera_set_gain_ceiling); +MP_PROPERTY_GETSET(esp32_camera_camera_gain_ceiling_obj, + (mp_obj_t)&esp32_camera_camera_get_gain_ceiling_obj, + (mp_obj_t)&esp32_camera_camera_set_gain_ceiling_obj); + +//| quality: int +//| """The 'quality' setting when capturing JPEG images. This is similar to the quality setting when exporting a jpeg image from photo editing software. Typical values range from 5 to 40, with higher numbers leading to larger image sizes and better overall image quality. However, when the quality is set to a high number, the total size of the JPEG data can exceed the size of an internal buffer, causing image capture to fail.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_quality(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_quality(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_quality_obj, esp32_camera_camera_get_quality); + +STATIC mp_obj_t esp32_camera_camera_set_quality(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_quality(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_quality_obj, esp32_camera_camera_set_quality); +MP_PROPERTY_GETSET(esp32_camera_camera_quality_obj, + (mp_obj_t)&esp32_camera_camera_get_quality_obj, + (mp_obj_t)&esp32_camera_camera_set_quality_obj); + +//| colorbar: bool +//| """When `True`, a test pattern image is captured and the real sensor data is not used.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_colorbar(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_colorbar(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_colorbar_obj, esp32_camera_camera_get_colorbar); + +STATIC mp_obj_t esp32_camera_camera_set_colorbar(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_colorbar(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_colorbar_obj, esp32_camera_camera_set_colorbar); +MP_PROPERTY_GETSET(esp32_camera_camera_colorbar_obj, + (mp_obj_t)&esp32_camera_camera_get_colorbar_obj, + (mp_obj_t)&esp32_camera_camera_set_colorbar_obj); + +//| whitebal: bool +//| """When `True`, the camera attempts to automatically control white balance. When `False`, the `wb_mode` setting is used instead.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_whitebal(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_whitebal(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_whitebal_obj, esp32_camera_camera_get_whitebal); + +STATIC mp_obj_t esp32_camera_camera_set_whitebal(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_whitebal(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_whitebal_obj, esp32_camera_camera_set_whitebal); +MP_PROPERTY_GETSET(esp32_camera_camera_whitebal_obj, + (mp_obj_t)&esp32_camera_camera_get_whitebal_obj, + (mp_obj_t)&esp32_camera_camera_set_whitebal_obj); + +//| gain_ctrl: bool +//| """When `True`, the camera attempts to automatically control the sensor gain, up to the value in the `gain_ceiling` property. When `False`, the `agc_gain` setting is used instead.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_gain_ctrl(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_gain_ctrl(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_gain_ctrl_obj, esp32_camera_camera_get_gain_ctrl); + +STATIC mp_obj_t esp32_camera_camera_set_gain_ctrl(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_gain_ctrl(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_gain_ctrl_obj, esp32_camera_camera_set_gain_ctrl); +MP_PROPERTY_GETSET(esp32_camera_camera_gain_ctrl_obj, + (mp_obj_t)&esp32_camera_camera_get_gain_ctrl_obj, + (mp_obj_t)&esp32_camera_camera_set_gain_ctrl_obj); + +//| exposure_ctrl: bool +//| """When `True` the camera attempts to automatically control the exposure. When `False`, the `aec_value` setting is used instead.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_exposure_ctrl(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_exposure_ctrl(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_exposure_ctrl_obj, esp32_camera_camera_get_exposure_ctrl); + +STATIC mp_obj_t esp32_camera_camera_set_exposure_ctrl(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_exposure_ctrl(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_exposure_ctrl_obj, esp32_camera_camera_set_exposure_ctrl); +MP_PROPERTY_GETSET(esp32_camera_camera_exposure_ctrl_obj, + (mp_obj_t)&esp32_camera_camera_get_exposure_ctrl_obj, + (mp_obj_t)&esp32_camera_camera_set_exposure_ctrl_obj); + +//| hmirror: bool +//| """When `True` the camera image is mirrored left-to-right""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_hmirror(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_hmirror(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_hmirror_obj, esp32_camera_camera_get_hmirror); + +STATIC mp_obj_t esp32_camera_camera_set_hmirror(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_hmirror(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_hmirror_obj, esp32_camera_camera_set_hmirror); +MP_PROPERTY_GETSET(esp32_camera_camera_hmirror_obj, + (mp_obj_t)&esp32_camera_camera_get_hmirror_obj, + (mp_obj_t)&esp32_camera_camera_set_hmirror_obj); + +//| vflip: bool +//| """When `True` the camera image is flipped top-to-bottom""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_vflip(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_vflip(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_vflip_obj, esp32_camera_camera_get_vflip); + +STATIC mp_obj_t esp32_camera_camera_set_vflip(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_vflip(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_vflip_obj, esp32_camera_camera_set_vflip); +MP_PROPERTY_GETSET(esp32_camera_camera_vflip_obj, + (mp_obj_t)&esp32_camera_camera_get_vflip_obj, + (mp_obj_t)&esp32_camera_camera_set_vflip_obj); + +//| aec2: bool +//| """When `True` the sensor's "night mode" is enabled, extending the range of automatic gain control.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_aec2(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_aec2(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_aec2_obj, esp32_camera_camera_get_aec2); + +STATIC mp_obj_t esp32_camera_camera_set_aec2(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_aec2(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_aec2_obj, esp32_camera_camera_set_aec2); +MP_PROPERTY_GETSET(esp32_camera_camera_aec2_obj, + (mp_obj_t)&esp32_camera_camera_get_aec2_obj, + (mp_obj_t)&esp32_camera_camera_set_aec2_obj); + +//| awb_gain: bool +//| """Access the awb_gain property of the camera sensor""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_awb_gain(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_awb_gain(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_awb_gain_obj, esp32_camera_camera_get_awb_gain); + +STATIC mp_obj_t esp32_camera_camera_set_awb_gain(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_awb_gain(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_awb_gain_obj, esp32_camera_camera_set_awb_gain); +MP_PROPERTY_GETSET(esp32_camera_camera_awb_gain_obj, + (mp_obj_t)&esp32_camera_camera_get_awb_gain_obj, + (mp_obj_t)&esp32_camera_camera_set_awb_gain_obj); + +//| agc_gain: int +//| """Access the gain level of the sensor. Higher values produce brighter images. Typical settings range from 0 to 30. """ +//| + +STATIC mp_obj_t esp32_camera_camera_get_agc_gain(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_agc_gain(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_agc_gain_obj, esp32_camera_camera_get_agc_gain); + +STATIC mp_obj_t esp32_camera_camera_set_agc_gain(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_agc_gain(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_agc_gain_obj, esp32_camera_camera_set_agc_gain); +MP_PROPERTY_GETSET(esp32_camera_camera_agc_gain_obj, + (mp_obj_t)&esp32_camera_camera_get_agc_gain_obj, + (mp_obj_t)&esp32_camera_camera_set_agc_gain_obj); + +//| aec_value: int +//| """Access the exposure value of the camera. Higher values produce brighter images. Typical settings range from 0 to 1200.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_aec_value(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_aec_value(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_aec_value_obj, esp32_camera_camera_get_aec_value); + +STATIC mp_obj_t esp32_camera_camera_set_aec_value(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_aec_value(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_aec_value_obj, esp32_camera_camera_set_aec_value); +MP_PROPERTY_GETSET(esp32_camera_camera_aec_value_obj, + (mp_obj_t)&esp32_camera_camera_get_aec_value_obj, + (mp_obj_t)&esp32_camera_camera_set_aec_value_obj); + +//| special_effect: int +//| """Enable a "special effect". Zero is no special effect. On OV5640, special effects range from 0 to 6 inclusive and select various color modes.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_special_effect(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_special_effect(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_special_effect_obj, esp32_camera_camera_get_special_effect); + +STATIC mp_obj_t esp32_camera_camera_set_special_effect(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_special_effect(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_special_effect_obj, esp32_camera_camera_set_special_effect); +MP_PROPERTY_GETSET(esp32_camera_camera_special_effect_obj, + (mp_obj_t)&esp32_camera_camera_get_special_effect_obj, + (mp_obj_t)&esp32_camera_camera_set_special_effect_obj); + +//| wb_mode: int +//| """The white balance mode. 0 is automatic white balance. Typical values range from 0 to 4 inclusive.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_wb_mode(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_wb_mode(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_wb_mode_obj, esp32_camera_camera_get_wb_mode); + +STATIC mp_obj_t esp32_camera_camera_set_wb_mode(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_wb_mode(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_wb_mode_obj, esp32_camera_camera_set_wb_mode); +MP_PROPERTY_GETSET(esp32_camera_camera_wb_mode_obj, + (mp_obj_t)&esp32_camera_camera_get_wb_mode_obj, + (mp_obj_t)&esp32_camera_camera_set_wb_mode_obj); + +//| ae_level: int +//| """The exposure offset for automatic exposure. Typical values range from -2 to +2.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_ae_level(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_ae_level(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_ae_level_obj, esp32_camera_camera_get_ae_level); + +STATIC mp_obj_t esp32_camera_camera_set_ae_level(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_ae_level(self, mp_obj_get_int(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_ae_level_obj, esp32_camera_camera_set_ae_level); +MP_PROPERTY_GETSET(esp32_camera_camera_ae_level_obj, + (mp_obj_t)&esp32_camera_camera_get_ae_level_obj, + (mp_obj_t)&esp32_camera_camera_set_ae_level_obj); + +//| dcw: bool +//| """When `True` an advanced white balance mode is selected.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_dcw(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_dcw(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_dcw_obj, esp32_camera_camera_get_dcw); + +STATIC mp_obj_t esp32_camera_camera_set_dcw(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_dcw(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_dcw_obj, esp32_camera_camera_set_dcw); +MP_PROPERTY_GETSET(esp32_camera_camera_dcw_obj, + (mp_obj_t)&esp32_camera_camera_get_dcw_obj, + (mp_obj_t)&esp32_camera_camera_set_dcw_obj); + +//| bpc: bool +//| """When `True`, "black point compensation" is enabled. This can make black parts of the image darker.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_bpc(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_bpc(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_bpc_obj, esp32_camera_camera_get_bpc); + +STATIC mp_obj_t esp32_camera_camera_set_bpc(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_bpc(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_bpc_obj, esp32_camera_camera_set_bpc); +MP_PROPERTY_GETSET(esp32_camera_camera_bpc_obj, + (mp_obj_t)&esp32_camera_camera_get_bpc_obj, + (mp_obj_t)&esp32_camera_camera_set_bpc_obj); + +//| wpc: bool +//| """When `True`, "white point compensation" is enabled. This can make white parts of the image whiter.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_wpc(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_wpc(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_wpc_obj, esp32_camera_camera_get_wpc); + +STATIC mp_obj_t esp32_camera_camera_set_wpc(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_wpc(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_wpc_obj, esp32_camera_camera_set_wpc); +MP_PROPERTY_GETSET(esp32_camera_camera_wpc_obj, + (mp_obj_t)&esp32_camera_camera_get_wpc_obj, + (mp_obj_t)&esp32_camera_camera_set_wpc_obj); + +//| raw_gma: bool +//| """When `True`, raw gamma mode is enabled.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_raw_gma(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_raw_gma(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_raw_gma_obj, esp32_camera_camera_get_raw_gma); + +STATIC mp_obj_t esp32_camera_camera_set_raw_gma(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_raw_gma(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_raw_gma_obj, esp32_camera_camera_set_raw_gma); +MP_PROPERTY_GETSET(esp32_camera_camera_raw_gma_obj, + (mp_obj_t)&esp32_camera_camera_get_raw_gma_obj, + (mp_obj_t)&esp32_camera_camera_set_raw_gma_obj); + +//| lenc: bool +//| """Enable "lens correction". This can help compensate for light fall-off at the edge of the sensor area.""" +//| + +STATIC mp_obj_t esp32_camera_camera_get_lenc(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_lenc(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_lenc_obj, esp32_camera_camera_get_lenc); + +STATIC mp_obj_t esp32_camera_camera_set_lenc(const mp_obj_t self_in, const mp_obj_t arg) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_esp32_camera_camera_set_lenc(self, mp_obj_is_true(arg)); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(esp32_camera_camera_set_lenc_obj, esp32_camera_camera_set_lenc); +MP_PROPERTY_GETSET(esp32_camera_camera_lenc_obj, + (mp_obj_t)&esp32_camera_camera_get_lenc_obj, + (mp_obj_t)&esp32_camera_camera_set_lenc_obj); + +//| max_frame_size: FrameSize +//| """The maximum frame size that can be captured""" +//| +STATIC mp_obj_t esp32_camera_camera_get_max_frame_size(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return cp_enum_find(&esp32_camera_frame_size_type, common_hal_esp32_camera_camera_get_max_frame_size(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_max_frame_size_obj, esp32_camera_camera_get_max_frame_size); + +MP_PROPERTY_GETTER(esp32_camera_camera_max_frame_size_obj, + (mp_obj_t)&esp32_camera_camera_get_max_frame_size_obj); + + +//| address: int +//| """The I2C (SCCB) address of the sensor""" +//| +STATIC mp_obj_t esp32_camera_camera_get_address(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_address(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_address_obj, esp32_camera_camera_get_address); + +MP_PROPERTY_GETTER(esp32_camera_camera_address_obj, + (mp_obj_t)&esp32_camera_camera_get_address_obj); + + +//| sensor_name: str +//| """The name of the sensor""" +//| +STATIC mp_obj_t esp32_camera_camera_get_sensor_name(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + const char *sensor_name = common_hal_esp32_camera_camera_get_sensor_name(self); + return mp_obj_new_str(sensor_name, strlen(sensor_name)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_sensor_name_obj, esp32_camera_camera_get_sensor_name); + +MP_PROPERTY_GETTER(esp32_camera_camera_sensor_name_obj, + (mp_obj_t)&esp32_camera_camera_get_sensor_name_obj); + + +//| supports_jpeg: bool +//| """True if the sensor can capture images in JPEG format""" +//| +STATIC mp_obj_t esp32_camera_camera_get_supports_jpeg(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_esp32_camera_camera_get_supports_jpeg(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_supports_jpeg_obj, esp32_camera_camera_get_supports_jpeg); + +MP_PROPERTY_GETTER(esp32_camera_camera_supports_jpeg_obj, + (mp_obj_t)&esp32_camera_camera_get_supports_jpeg_obj); + +//| height: int +//| """The height of the image being captured""" +//| +STATIC mp_obj_t esp32_camera_camera_get_height(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_height(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_height_obj, esp32_camera_camera_get_height); + +MP_PROPERTY_GETTER(esp32_camera_camera_height_obj, + (mp_obj_t)&esp32_camera_camera_get_height_obj); + +//| width: int +//| """The width of the image being captured""" +//| +STATIC mp_obj_t esp32_camera_camera_get_width(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_width(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_width_obj, esp32_camera_camera_get_width); + +MP_PROPERTY_GETTER(esp32_camera_camera_width_obj, + (mp_obj_t)&esp32_camera_camera_get_width_obj); + +//| grab_mode: GrabMode +//| """The grab mode of the camera""" +//| +STATIC mp_obj_t esp32_camera_camera_get_grab_mode(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return cp_enum_find(&esp32_camera_grab_mode_type, common_hal_esp32_camera_camera_get_grab_mode(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_grab_mode_obj, esp32_camera_camera_get_grab_mode); + +MP_PROPERTY_GETTER(esp32_camera_camera_grab_mode_obj, + (mp_obj_t)&esp32_camera_camera_get_grab_mode_obj); + + +//| framebuffer_count: int +//| """True if double buffering is used""" +//| +STATIC mp_obj_t esp32_camera_camera_get_framebuffer_count(const mp_obj_t self_in) { + esp32_camera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_esp32_camera_camera_get_framebuffer_count(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_camera_camera_get_framebuffer_count_obj, esp32_camera_camera_get_framebuffer_count); + +MP_PROPERTY_GETTER(esp32_camera_camera_framebuffer_count_obj, + (mp_obj_t)&esp32_camera_camera_get_framebuffer_count_obj); + + +STATIC const mp_rom_map_elem_t esp32_camera_camera_locals_table[] = { + { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&esp32_camera_camera_address_obj) }, + { MP_ROM_QSTR(MP_QSTR_aec2), MP_ROM_PTR(&esp32_camera_camera_aec2_obj) }, + { MP_ROM_QSTR(MP_QSTR_aec_value), MP_ROM_PTR(&esp32_camera_camera_aec_value_obj) }, + { MP_ROM_QSTR(MP_QSTR_ae_level), MP_ROM_PTR(&esp32_camera_camera_ae_level_obj) }, + { MP_ROM_QSTR(MP_QSTR_agc_gain), MP_ROM_PTR(&esp32_camera_camera_agc_gain_obj) }, + { MP_ROM_QSTR(MP_QSTR_awb_gain), MP_ROM_PTR(&esp32_camera_camera_awb_gain_obj) }, + { MP_ROM_QSTR(MP_QSTR_bpc), MP_ROM_PTR(&esp32_camera_camera_bpc_obj) }, + { MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&esp32_camera_camera_brightness_obj) }, + { MP_ROM_QSTR(MP_QSTR_colorbar), MP_ROM_PTR(&esp32_camera_camera_colorbar_obj) }, + { MP_ROM_QSTR(MP_QSTR_contrast), MP_ROM_PTR(&esp32_camera_camera_contrast_obj) }, + { MP_ROM_QSTR(MP_QSTR_dcw), MP_ROM_PTR(&esp32_camera_camera_dcw_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&esp32_camera_camera_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_denoise), MP_ROM_PTR(&esp32_camera_camera_denoise_obj) }, + { MP_ROM_QSTR(MP_QSTR_framebuffer_count), MP_ROM_PTR(&esp32_camera_camera_framebuffer_count_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&esp32_camera_camera___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_exposure_ctrl), MP_ROM_PTR(&esp32_camera_camera_exposure_ctrl_obj) }, + { MP_ROM_QSTR(MP_QSTR_frame_available), MP_ROM_PTR(&esp32_camera_camera_frame_available_obj) }, + { MP_ROM_QSTR(MP_QSTR_frame_size), MP_ROM_PTR(&esp32_camera_camera_frame_size_obj) }, + { MP_ROM_QSTR(MP_QSTR_gain_ceiling), MP_ROM_PTR(&esp32_camera_camera_gain_ceiling_obj) }, + { MP_ROM_QSTR(MP_QSTR_gain_ctrl), MP_ROM_PTR(&esp32_camera_camera_gain_ctrl_obj) }, + { MP_ROM_QSTR(MP_QSTR_grab_mode), MP_ROM_PTR(&esp32_camera_camera_grab_mode_obj) }, + { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&esp32_camera_camera_height_obj) }, + { MP_ROM_QSTR(MP_QSTR_hmirror), MP_ROM_PTR(&esp32_camera_camera_hmirror_obj) }, + { MP_ROM_QSTR(MP_QSTR_lenc), MP_ROM_PTR(&esp32_camera_camera_lenc_obj) }, + { MP_ROM_QSTR(MP_QSTR_max_frame_size), MP_ROM_PTR(&esp32_camera_camera_max_frame_size_obj) }, + { MP_ROM_QSTR(MP_QSTR_pixel_format), MP_ROM_PTR(&esp32_camera_camera_pixel_format_obj) }, + { MP_ROM_QSTR(MP_QSTR_quality), MP_ROM_PTR(&esp32_camera_camera_quality_obj) }, + { MP_ROM_QSTR(MP_QSTR_raw_gma), MP_ROM_PTR(&esp32_camera_camera_raw_gma_obj) }, + { MP_ROM_QSTR(MP_QSTR_reconfigure), MP_ROM_PTR(&esp32_camera_camera_reconfigure_obj) }, + { MP_ROM_QSTR(MP_QSTR_saturation), MP_ROM_PTR(&esp32_camera_camera_saturation_obj) }, + { MP_ROM_QSTR(MP_QSTR_sensor_name), MP_ROM_PTR(&esp32_camera_camera_sensor_name_obj) }, + { MP_ROM_QSTR(MP_QSTR_sharpness), MP_ROM_PTR(&esp32_camera_camera_sharpness_obj) }, + { MP_ROM_QSTR(MP_QSTR_special_effect), MP_ROM_PTR(&esp32_camera_camera_special_effect_obj) }, + { MP_ROM_QSTR(MP_QSTR_supports_jpeg), MP_ROM_PTR(&esp32_camera_camera_supports_jpeg_obj) }, + { MP_ROM_QSTR(MP_QSTR_take), MP_ROM_PTR(&esp32_camera_camera_take_obj) }, + { MP_ROM_QSTR(MP_QSTR_vflip), MP_ROM_PTR(&esp32_camera_camera_vflip_obj) }, + { MP_ROM_QSTR(MP_QSTR_wb_mode), MP_ROM_PTR(&esp32_camera_camera_wb_mode_obj) }, + { MP_ROM_QSTR(MP_QSTR_whitebal), MP_ROM_PTR(&esp32_camera_camera_whitebal_obj) }, + { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&esp32_camera_camera_width_obj) }, + { MP_ROM_QSTR(MP_QSTR_wpc), MP_ROM_PTR(&esp32_camera_camera_wpc_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(esp32_camera_camera_locals_dict, esp32_camera_camera_locals_table); + +const mp_obj_type_t esp32_camera_camera_type = { + .base = { &mp_type_type }, + .name = MP_QSTR_Camera, + .make_new = esp32_camera_camera_make_new, + .locals_dict = (mp_obj_t)&esp32_camera_camera_locals_dict, +}; diff --git a/ports/espressif/bindings/esp32_camera/Camera.h b/ports/espressif/bindings/esp32_camera/Camera.h new file mode 100644 index 0000000000..146cd0da05 --- /dev/null +++ b/ports/espressif/bindings/esp32_camera/Camera.h @@ -0,0 +1,116 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Jeff Epler for Adafruit Industries + * + * 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. + */ + +#pragma once + +#include "py/enum.h" +#include "py/obj.h" + +#include "esp_camera.h" + +#include "shared-bindings/busio/I2C.h" + +extern const mp_obj_type_t esp32_camera_camera_type; +typedef struct esp32_camera_camera_obj esp32_camera_camera_obj_t; + +extern void common_hal_esp32_camera_camera_construct( + esp32_camera_camera_obj_t *self, + uint8_t data_pins[8], + const mcu_pin_obj_t *external_clock_pin, + const mcu_pin_obj_t *pixel_clock_pin, + const mcu_pin_obj_t *vsync_pin, + const mcu_pin_obj_t *href_pin, + const mcu_pin_obj_t *powerdown_pin, + const mcu_pin_obj_t *reset_pin, + const busio_i2c_obj_t *i2c, + mp_int_t external_clock_frequency, + pixformat_t pixel_format, + framesize_t frame_size, + mp_int_t jpeg_quality, + mp_int_t framebuffer_count, + camera_grab_mode_t grab_mode); + +extern void common_hal_esp32_camera_camera_deinit(esp32_camera_camera_obj_t *self); +extern bool common_hal_esp32_camera_camera_deinited(esp32_camera_camera_obj_t *self); +extern bool common_hal_esp32_camera_camera_available(esp32_camera_camera_obj_t *self); +extern camera_fb_t *common_hal_esp32_camera_camera_take(esp32_camera_camera_obj_t *self, int timeout_ms); +extern void common_hal_esp32_camera_camera_reconfigure(esp32_camera_camera_obj_t *self, framesize_t frame_size, pixformat_t pixel_format, camera_grab_mode_t grab_mode, mp_int_t framebuffer_count); + +#define DECLARE_SENSOR_GETSET(type, name, field_name, setter_function_name) \ + DECLARE_SENSOR_GET(type, name, field_name, setter_function_name) \ + DECLARE_SENSOR_SET(type, name, setter_function_name) + +#define DECLARE_SENSOR_STATUS_GETSET(type, name, status_field_name, setter_function_name) \ + DECLARE_SENSOR_GETSET(type, name, status.status_field_name, setter_function_name) + +#define DECLARE_SENSOR_STATUS_GET(type, name, status_field_name, setter_function_name) \ + DECLARE_SENSOR_GET(type, name, status.status_field_name, setter_function_name) + +#define DECLARE_SENSOR_GET(type, name, status_field_name, setter_function_name) \ + extern type common_hal_esp32_camera_camera_get_##name(esp32_camera_camera_obj_t * self); + +#define DECLARE_SENSOR_SET(type, name, setter_function_name) \ + extern void common_hal_esp32_camera_camera_set_##name(esp32_camera_camera_obj_t * self, type value); + +DECLARE_SENSOR_GET(pixformat_t, pixel_format, pixformat, set_pixformat) +DECLARE_SENSOR_STATUS_GET(framesize_t, frame_size, framesize, set_framesize) +DECLARE_SENSOR_STATUS_GETSET(int, contrast, contrast, set_contrast); +DECLARE_SENSOR_STATUS_GETSET(int, brightness, brightness, set_brightness); +DECLARE_SENSOR_STATUS_GETSET(int, saturation, saturation, set_saturation); +DECLARE_SENSOR_STATUS_GETSET(int, sharpness, sharpness, set_sharpness); +DECLARE_SENSOR_STATUS_GETSET(int, denoise, denoise, set_denoise); +DECLARE_SENSOR_STATUS_GETSET(gainceiling_t, gainceiling, gainceiling, set_gainceiling); +DECLARE_SENSOR_STATUS_GETSET(int, quality, quality, set_quality); +DECLARE_SENSOR_STATUS_GETSET(bool, colorbar, colorbar, set_colorbar); +DECLARE_SENSOR_STATUS_GETSET(bool, whitebal, whitebal, set_whitebal); +DECLARE_SENSOR_STATUS_GETSET(bool, gain_ctrl, gain_ctrl, set_gain_ctrl); +DECLARE_SENSOR_STATUS_GETSET(bool, exposure_ctrl, exposure_ctrl, set_exposure_ctrl); +DECLARE_SENSOR_STATUS_GETSET(bool, hmirror, hmirror, set_hmirror); +DECLARE_SENSOR_STATUS_GETSET(bool, vflip, vflip, set_vflip); +DECLARE_SENSOR_STATUS_GETSET(bool, aec2, aec2, set_aec2); +DECLARE_SENSOR_STATUS_GETSET(bool, awb_gain, awb_gain, set_awb_gain); +DECLARE_SENSOR_STATUS_GETSET(int, agc_gain, agc_gain, set_agc_gain); +DECLARE_SENSOR_STATUS_GETSET(int, aec_value, aec_value, set_aec_value); +DECLARE_SENSOR_STATUS_GETSET(int, special_effect, special_effect, set_special_effect); +DECLARE_SENSOR_STATUS_GETSET(int, wb_mode, wb_mode, set_wb_mode); +DECLARE_SENSOR_STATUS_GETSET(int, ae_level, ae_level, set_ae_level); +DECLARE_SENSOR_STATUS_GETSET(bool, dcw, dcw, set_dcw); +DECLARE_SENSOR_STATUS_GETSET(bool, bpc, bpc, set_bpc); +DECLARE_SENSOR_STATUS_GETSET(bool, wpc, wpc, set_wpc); +DECLARE_SENSOR_STATUS_GETSET(bool, raw_gma, raw_gma, set_raw_gma); +DECLARE_SENSOR_STATUS_GETSET(bool, lenc, lenc, set_lenc); + +// From settings +extern camera_grab_mode_t common_hal_esp32_camera_camera_get_grab_mode(esp32_camera_camera_obj_t *self); +extern int common_hal_esp32_camera_camera_get_framebuffer_count(esp32_camera_camera_obj_t *self); + +// From camera_sensor_info_t +extern int common_hal_esp32_camera_camera_get_address(esp32_camera_camera_obj_t *self); +extern const char *common_hal_esp32_camera_camera_get_sensor_name(esp32_camera_camera_obj_t *self); +extern const bool common_hal_esp32_camera_camera_get_supports_jpeg(esp32_camera_camera_obj_t *self); +extern framesize_t common_hal_esp32_camera_camera_get_max_frame_size(esp32_camera_camera_obj_t *self); +extern int common_hal_esp32_camera_camera_get_width(esp32_camera_camera_obj_t *self); +extern int common_hal_esp32_camera_camera_get_height(esp32_camera_camera_obj_t *self); diff --git a/ports/espressif/bindings/esp32_camera/__init__.c b/ports/espressif/bindings/esp32_camera/__init__.c new file mode 100644 index 0000000000..f1ee4b6891 --- /dev/null +++ b/ports/espressif/bindings/esp32_camera/__init__.c @@ -0,0 +1,287 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Jeff Epler for Adafruit Industries + * + * 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. + */ + +#include "py/obj.h" +#include "py/runtime.h" +#include "py/mphal.h" + +#include "bindings/espidf/__init__.h" +#include "bindings/esp32_camera/__init__.h" +#include "bindings/esp32_camera/Camera.h" + +#include "esp_camera.h" +#include "sensor.h" + +//| """Wrapper for the esp32_camera library +//| +//| This library enables access to any camera sensor supported by the library, +//| including OV5640 and OV2640. +//| +//| .. seealso:: +//| +//| Non-Espressif microcontrollers use the `imagecapture` module together with wrapper libraries such as `adafruit_ov5640 `_. +//| +//| """ + +//| class GrabMode: +//| """Controls when a new frame is grabbed.""" +//| +//| WHEN_EMPTY: GrabMode +//| """Fills buffers when they are empty. Less resources but first ``fb_count`` frames might be old""" +//| +//| LATEST: GrabMode +//| """Except when 1 frame buffer is used, queue will always contain the last ``fb_count`` frames""" +//| + +MAKE_ENUM_VALUE(esp32_camera_grab_mode_type, grab_mode, WHEN_EMPTY, CAMERA_GRAB_WHEN_EMPTY); +MAKE_ENUM_VALUE(esp32_camera_grab_mode_type, grab_mode, LATEST, CAMERA_GRAB_LATEST); + +MAKE_ENUM_MAP(esp32_camera_grab_mode) { + MAKE_ENUM_MAP_ENTRY(grab_mode, WHEN_EMPTY), + MAKE_ENUM_MAP_ENTRY(grab_mode, LATEST), +}; + +STATIC MP_DEFINE_CONST_DICT(esp32_camera_grab_mode_locals_dict, esp32_camera_grab_mode_locals_table); +MAKE_PRINTER(esp32_camera, esp32_camera_grab_mode); +MAKE_ENUM_TYPE(esp32_camera, GrabMode, esp32_camera_grab_mode); + +camera_grab_mode_t validate_grab_mode(mp_obj_t obj, qstr arg_name) { + return cp_enum_value(&esp32_camera_grab_mode_type, mp_arg_validate_type(obj, &esp32_camera_grab_mode_type, arg_name)); +} + +//| class PixelFormat: +//| """Format of data in the captured frames""" +//| +//| RGB565: PixelFormat +//| """A 16-bit format with 5 bits of Red and Blue and 6 bits of Green""" +//| +//| GRAYSCALE: PixelFormat +//| """An 8-bit format with 8-bits of luminance""" +//| +//| JPEG: PixelFormat +//| """A compressed format""" +//| + +MAKE_ENUM_VALUE(esp32_camera_pixel_format_type, pixel_format, RGB565, PIXFORMAT_RGB565); +MAKE_ENUM_VALUE(esp32_camera_pixel_format_type, pixel_format, GRAYSCALE, PIXFORMAT_GRAYSCALE); +MAKE_ENUM_VALUE(esp32_camera_pixel_format_type, pixel_format, JPEG, PIXFORMAT_JPEG); + +MAKE_ENUM_MAP(esp32_camera_pixel_format) { + MAKE_ENUM_MAP_ENTRY(pixel_format, RGB565), + MAKE_ENUM_MAP_ENTRY(pixel_format, GRAYSCALE), + MAKE_ENUM_MAP_ENTRY(pixel_format, JPEG), +}; + +STATIC MP_DEFINE_CONST_DICT(esp32_camera_pixel_format_locals_dict, esp32_camera_pixel_format_locals_table); +MAKE_PRINTER(esp32_camera, esp32_camera_pixel_format); +MAKE_ENUM_TYPE(esp32_camera, PixelFormat, esp32_camera_pixel_format); + +pixformat_t validate_pixel_format(mp_obj_t obj, qstr arg_name) { + return cp_enum_value(&esp32_camera_pixel_format_type, mp_arg_validate_type(obj, &esp32_camera_pixel_format_type, arg_name)); +} + +//| class FrameSize: +//| """The pixel size of the captured frames""" +//| +//| R96X96: FrameSize +//| """96x96""" +//| +//| QQVGA: FrameSize +//| """160x120""" +//| +//| QCIF: FrameSize +//| """176x144""" +//| +//| HQVGA: FrameSize +//| """240x176""" +//| +//| R240X240: FrameSize +//| """240x240""" +//| +//| QVGA: FrameSize +//| """320x240 """ +//| +//| CIF: FrameSize +//| """400x296""" +//| +//| HVGA: FrameSize +//| """480x320""" +//| +//| VGA: FrameSize +//| """640x480""" +//| +//| SVGA: FrameSize +//| """800x600""" +//| +//| XGA: FrameSize +//| """1024x768""" +//| +//| HD: FrameSize +//| """1280x720""" +//| +//| SXGA: FrameSize +//| """1280x1024""" +//| +//| UXGA: FrameSize +//| """1600x1200""" +//| +//| FHD: FrameSize +//| """1920x1080""" +//| +//| P_HD: FrameSize +//| """ 720x1280""" +//| +//| P_3MP: FrameSize +//| """ 864x1536""" +//| +//| QXGA: FrameSize +//| """2048x1536""" +//| +//| QHD: FrameSize +//| """2560x1440""" +//| +//| WQXGA: FrameSize +//| """2560x1600""" +//| +//| P_FHD: FrameSize +//| """1080x1920""" +//| +//| QSXGA: FrameSize +//| """2560x1920""" +//| + +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, R96X96, FRAMESIZE_96X96); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, R240X240, FRAMESIZE_240X240); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, QQVGA, FRAMESIZE_QQVGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, QCIF, FRAMESIZE_QCIF); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, HQVGA, FRAMESIZE_HQVGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, QVGA, FRAMESIZE_QVGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, CIF, FRAMESIZE_CIF); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, HVGA, FRAMESIZE_HVGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, VGA, FRAMESIZE_VGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, SVGA, FRAMESIZE_SVGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, XGA, FRAMESIZE_XGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, HD, FRAMESIZE_HD); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, SXGA, FRAMESIZE_SXGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, UXGA, FRAMESIZE_UXGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, FHD, FRAMESIZE_FHD); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, P_HD, FRAMESIZE_P_HD); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, P_3MP, FRAMESIZE_P_3MP); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, QXGA, FRAMESIZE_QXGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, QHD, FRAMESIZE_QHD); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, WQXGA, FRAMESIZE_WQXGA); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, P_FHD, FRAMESIZE_P_FHD); +MAKE_ENUM_VALUE(esp32_camera_frame_size_type, frame_size, QSXGA, FRAMESIZE_QSXGA); +MAKE_ENUM_MAP(esp32_camera_frame_size) { + MAKE_ENUM_MAP_ENTRY(frame_size, R96X96), + MAKE_ENUM_MAP_ENTRY(frame_size, R240X240), + MAKE_ENUM_MAP_ENTRY(frame_size, QQVGA), + MAKE_ENUM_MAP_ENTRY(frame_size, QCIF), + MAKE_ENUM_MAP_ENTRY(frame_size, HQVGA), + MAKE_ENUM_MAP_ENTRY(frame_size, QVGA), + MAKE_ENUM_MAP_ENTRY(frame_size, CIF), + MAKE_ENUM_MAP_ENTRY(frame_size, HVGA), + MAKE_ENUM_MAP_ENTRY(frame_size, VGA), + MAKE_ENUM_MAP_ENTRY(frame_size, SVGA), + MAKE_ENUM_MAP_ENTRY(frame_size, XGA), + MAKE_ENUM_MAP_ENTRY(frame_size, HD), + MAKE_ENUM_MAP_ENTRY(frame_size, SXGA), + MAKE_ENUM_MAP_ENTRY(frame_size, UXGA), + MAKE_ENUM_MAP_ENTRY(frame_size, FHD), + MAKE_ENUM_MAP_ENTRY(frame_size, P_HD), + MAKE_ENUM_MAP_ENTRY(frame_size, P_3MP), + MAKE_ENUM_MAP_ENTRY(frame_size, QXGA), + MAKE_ENUM_MAP_ENTRY(frame_size, QHD), + MAKE_ENUM_MAP_ENTRY(frame_size, WQXGA), + MAKE_ENUM_MAP_ENTRY(frame_size, P_FHD), + MAKE_ENUM_MAP_ENTRY(frame_size, QSXGA), +}; + +STATIC MP_DEFINE_CONST_DICT(esp32_camera_frame_size_locals_dict, esp32_camera_frame_size_locals_table); +MAKE_PRINTER(esp32_camera, esp32_camera_frame_size); +MAKE_ENUM_TYPE(esp32_camera, FrameSize, esp32_camera_frame_size); + +framesize_t validate_frame_size(mp_obj_t obj, qstr arg_name) { + return cp_enum_value(&esp32_camera_frame_size_type, mp_arg_validate_type(obj, &esp32_camera_frame_size_type, arg_name)); +} + +//| class GainCeiling: +//| """The maximum amount of gain applied to raw sensor data. +//| +//| Higher values are useful in darker conditions, but increase image noise.""" +//| +//| GAIN_2X: GainCeiling +//| GAIN_4X: GainCeiling +//| GAIN_8X: GainCeiling +//| GAIN_16X: GainCeiling +//| GAIN_32X: GainCeiling +//| GAIN_64X: GainCeiling +//| GAIN_128X: GainCeiling +//| + +MAKE_ENUM_VALUE(esp32_camera_gain_ceiling_type, gain_ceiling, GAIN_2X, GAINCEILING_2X); +MAKE_ENUM_VALUE(esp32_camera_gain_ceiling_type, gain_ceiling, GAIN_4X, GAINCEILING_4X); +MAKE_ENUM_VALUE(esp32_camera_gain_ceiling_type, gain_ceiling, GAIN_8X, GAINCEILING_8X); +MAKE_ENUM_VALUE(esp32_camera_gain_ceiling_type, gain_ceiling, GAIN_16X, GAINCEILING_16X); +MAKE_ENUM_VALUE(esp32_camera_gain_ceiling_type, gain_ceiling, GAIN_32X, GAINCEILING_32X); +MAKE_ENUM_VALUE(esp32_camera_gain_ceiling_type, gain_ceiling, GAIN_64X, GAINCEILING_64X); +MAKE_ENUM_VALUE(esp32_camera_gain_ceiling_type, gain_ceiling, GAIN_128X, GAINCEILING_128X); + +MAKE_ENUM_MAP(esp32_camera_gain_ceiling) { + MAKE_ENUM_MAP_ENTRY(gain_ceiling, GAIN_2X), + MAKE_ENUM_MAP_ENTRY(gain_ceiling, GAIN_4X), + MAKE_ENUM_MAP_ENTRY(gain_ceiling, GAIN_8X), + MAKE_ENUM_MAP_ENTRY(gain_ceiling, GAIN_16X), + MAKE_ENUM_MAP_ENTRY(gain_ceiling, GAIN_32X), + MAKE_ENUM_MAP_ENTRY(gain_ceiling, GAIN_64X), + MAKE_ENUM_MAP_ENTRY(gain_ceiling, GAIN_128X) +}; + +STATIC MP_DEFINE_CONST_DICT(esp32_camera_gain_ceiling_locals_dict, esp32_camera_gain_ceiling_locals_table); +MAKE_PRINTER(esp32_camera, esp32_camera_gain_ceiling); +MAKE_ENUM_TYPE(esp32_camera, GainCeiling, esp32_camera_gain_ceiling); + +gainceiling_t validate_gain_ceiling(mp_obj_t obj, qstr arg_name) { + return cp_enum_value(&esp32_camera_gain_ceiling_type, mp_arg_validate_type(obj, &esp32_camera_gain_ceiling_type, arg_name)); +} + +STATIC const mp_rom_map_elem_t esp32_camera_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp32_camera) }, + { MP_ROM_QSTR(MP_QSTR_Camera), MP_ROM_PTR(&esp32_camera_camera_type), }, + { MP_ROM_QSTR(MP_QSTR_FrameSize), &esp32_camera_frame_size_type }, + { MP_ROM_QSTR(MP_QSTR_GainCeiling), &esp32_camera_gain_ceiling_type }, + { MP_ROM_QSTR(MP_QSTR_GrabMode), &esp32_camera_grab_mode_type }, + { MP_ROM_QSTR(MP_QSTR_PixelFormat), &esp32_camera_pixel_format_type }, +}; + +STATIC MP_DEFINE_CONST_DICT(esp32_camera_module_globals, esp32_camera_module_globals_table); + +const mp_obj_module_t esp32_camera_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&esp32_camera_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_esp32_camera, esp32_camera_module, CIRCUITPY_ESP32_CAMERA); diff --git a/ports/espressif/bindings/esp32_camera/__init__.h b/ports/espressif/bindings/esp32_camera/__init__.h new file mode 100644 index 0000000000..a0e7290ff9 --- /dev/null +++ b/ports/espressif/bindings/esp32_camera/__init__.h @@ -0,0 +1,45 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Jeff Epler for Adafruit Industries + * + * 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. + */ + +#pragma once + +#include "py/enum.h" +#include "py/obj.h" + +#include "esp_camera.h" + +extern const mp_obj_type_t esp32_camera_grab_mode_type; +extern const cp_enum_obj_t grab_mode_WHEN_EMPTY_obj; +extern const mp_obj_type_t esp32_camera_pixel_format_type; +extern const cp_enum_obj_t pixel_format_RGB565_obj; +extern const mp_obj_type_t esp32_camera_frame_size_type; +extern const cp_enum_obj_t frame_size_QQVGA_obj; +extern const mp_obj_type_t esp32_camera_gain_ceiling_type; + +extern camera_grab_mode_t validate_grab_mode(mp_obj_t obj, qstr arg_name); +extern pixformat_t validate_pixel_format(mp_obj_t obj, qstr arg_name); +extern framesize_t validate_frame_size(mp_obj_t obj, qstr arg_name); +extern gainceiling_t validate_gain_ceiling(mp_obj_t obj, qstr arg_name); diff --git a/ports/espressif/boards/adafruit_esp32s2_camera/board.c b/ports/espressif/boards/adafruit_esp32s2_camera/board.c index 23a2eb7a34..8e7c62ed37 100644 --- a/ports/espressif/boards/adafruit_esp32s2_camera/board.c +++ b/ports/espressif/boards/adafruit_esp32s2_camera/board.c @@ -89,8 +89,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO38, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c b/ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c index aab7fbc608..68505d37d7 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c +++ b/ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c @@ -95,7 +95,7 @@ void board_init(void) { display->base.type = &displayio_display_type; // workaround as board_init() is called before reset_port() in main.c - pwmout_reset(); +/// pwmout_reset(); common_hal_displayio_display_construct( display, @@ -118,8 +118,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO45, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - false, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh @@ -128,8 +127,6 @@ void board_init(void) { false, // SH1107_addressing 50000 // backlight pwm frequency ); - - common_hal_never_reset_pin(&pin_GPIO45); // backlight pin } bool board_requests_safe_mode(void) { @@ -144,6 +141,18 @@ bool espressif_board_reset_pin_number(gpio_num_t pin_number) { gpio_set_level(21, true); return true; } + // Pull LED down on reset rather than the default up + if (pin_number == 13) { + gpio_config_t cfg = { + .pin_bit_mask = BIT64(pin_number), + .mode = GPIO_MODE_DISABLE, + .pull_up_en = false, + .pull_down_en = true, + .intr_type = GPIO_INTR_DISABLE, + }; + gpio_config(&cfg); + return true; + } return false; } diff --git a/ports/espressif/boards/adafruit_feather_esp32s2_tftback_nopsram/board.c b/ports/espressif/boards/adafruit_feather_esp32s2_tftback_nopsram/board.c index 04b6a46779..bd64046296 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s2_tftback_nopsram/board.c +++ b/ports/espressif/boards/adafruit_feather_esp32s2_tftback_nopsram/board.c @@ -94,8 +94,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO7, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/mpconfigboard.mk b/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/mpconfigboard.mk index 1b4c4015f5..b8bea2c02c 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/mpconfigboard.mk @@ -17,3 +17,4 @@ CIRCUITPY_ESP_FLASH_FREQ = 40m CIRCUITPY_ESP_FLASH_SIZE = 4MB OPTIMIZATION_FLAGS = -Os +CIRCUITPY_ESP32_CAMERA = 0 diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_tft/board.c b/ports/espressif/boards/adafruit_feather_esp32s3_tft/board.c index aab7fbc608..eca89b6291 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_tft/board.c +++ b/ports/espressif/boards/adafruit_feather_esp32s3_tft/board.c @@ -118,8 +118,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO45, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - false, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk index dcbd2f9c7a..380423ba10 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk @@ -18,3 +18,4 @@ CIRCUITPY_ESP_FLASH_FREQ = 40m CIRCUITPY_ESP_FLASH_SIZE = 4MB OPTIMIZATION_FLAGS = -Os +CIRCUITPY_ESP32_CAMERA = 0 diff --git a/ports/espressif/boards/adafruit_funhouse/board.c b/ports/espressif/boards/adafruit_funhouse/board.c index 8b4adc5fa9..742d629a2c 100644 --- a/ports/espressif/boards/adafruit_funhouse/board.c +++ b/ports/espressif/boards/adafruit_funhouse/board.c @@ -97,8 +97,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO21, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/adafruit_funhouse/mpconfigboard.mk b/ports/espressif/boards/adafruit_funhouse/mpconfigboard.mk index 531627d5a6..4962806178 100644 --- a/ports/espressif/boards/adafruit_funhouse/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_funhouse/mpconfigboard.mk @@ -16,6 +16,8 @@ CIRCUITPY_ESP_FLASH_MODE = dio CIRCUITPY_ESP_FLASH_FREQ = 40m CIRCUITPY_ESP_FLASH_SIZE = 4MB +CIRCUITPY_ESP32_CAMERA = 0 + # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_PortalBase FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests diff --git a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.mk b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.mk index e1bd4997b7..2df1532535 100644 --- a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.mk @@ -16,6 +16,8 @@ CIRCUITPY_ESP_FLASH_MODE = dio CIRCUITPY_ESP_FLASH_FREQ = 40m CIRCUITPY_ESP_FLASH_SIZE = 4MB +CIRCUITPY_ESP32_CAMERA = 0 + # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_PortalBase FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests diff --git a/ports/espressif/boards/espressif_esp32_eye/board.c b/ports/espressif/boards/espressif_esp32_eye/board.c new file mode 100644 index 0000000000..d66ab9e5f1 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32_eye/board.c @@ -0,0 +1,46 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "components/driver/include/driver/gpio.h" +#include "components/hal/include/hal/gpio_hal.h" +#include "common-hal/microcontroller/Pin.h" + +void board_init(void) { + reset_board(); +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} + +void board_deinit(void) { +} diff --git a/ports/espressif/boards/espressif_esp32_eye/mpconfigboard.h b/ports/espressif/boards/espressif_esp32_eye/mpconfigboard.h new file mode 100644 index 0000000000..63a6f2307e --- /dev/null +++ b/ports/espressif/boards/espressif_esp32_eye/mpconfigboard.h @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Dan Halbert for Adafruit Industries + * + * 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. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "Espressif ESP32-EYE" +#define MICROPY_HW_MCU_NAME "ESP32" + +#define CIRCUITPY_BOARD_I2C (1) +#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO23, .sda = &pin_GPIO18}} + +// UART pins attached to the USB-serial converter chip +#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1) +#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3) + +#define DEFAULT_RESERVED_PSRAM (1048576) diff --git a/ports/espressif/boards/espressif_esp32_eye/mpconfigboard.mk b/ports/espressif/boards/espressif_esp32_eye/mpconfigboard.mk new file mode 100644 index 0000000000..4bd091d723 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32_eye/mpconfigboard.mk @@ -0,0 +1,11 @@ +CIRCUITPY_CREATOR_ID = 0x000C303A +CIRCUITPY_CREATION_ID = 0x00320001 + +IDF_TARGET = esp32 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = MPZ + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 40m +CIRCUITPY_ESP_FLASH_SIZE = 4MB diff --git a/ports/espressif/boards/espressif_esp32_eye/pins.c b/ports/espressif/boards/espressif_esp32_eye/pins.c new file mode 100644 index 0000000000..1824ba1cc0 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32_eye/pins.c @@ -0,0 +1,40 @@ +#include "py/objtuple.h" +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_obj_tuple_t camera_data_tuple = { + {&mp_type_tuple}, + 8, + { + MP_ROM_PTR(&pin_GPIO34), + MP_ROM_PTR(&pin_GPIO13), + MP_ROM_PTR(&pin_GPIO14), + MP_ROM_PTR(&pin_GPIO35), + MP_ROM_PTR(&pin_GPIO39), // "S_VN" + MP_ROM_PTR(&pin_GPIO38), + MP_ROM_PTR(&pin_GPIO37), + MP_ROM_PTR(&pin_GPIO36), // "S_VP" + } +}; + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_I2S_SCK), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_I2S_WS), MP_ROM_PTR(&pin_GPIO32) }, + { MP_ROM_QSTR(MP_QSTR_I2S_SDO), MP_ROM_PTR(&pin_GPIO32) }, + + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO15) }, + + { MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_LED_WHITE), MP_ROM_PTR(&pin_GPIO22) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + + { MP_ROM_QSTR(MP_QSTR_CAMERA_DATA), MP_ROM_PTR(&camera_data_tuple) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_VSYNC), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_HREF), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_PCLK), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_XCLK), MP_ROM_PTR(&pin_GPIO4) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/espressif_esp32_eye/sdkconfig b/ports/espressif/boards/espressif_esp32_eye/sdkconfig new file mode 100644 index 0000000000..a73d92e0a2 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32_eye/sdkconfig @@ -0,0 +1,72 @@ +# Automatically generated file. DO NOT EDIT. +# Espressif IoT Development Framework (ESP-IDF) Project Configuration +# +# +# Component config +# +# +# ESP32-specific +# +CONFIG_ESP32_SPIRAM_SUPPORT=y +# +# SPI RAM config +# +CONFIG_SPIRAM_TYPE_AUTO=y +# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set +CONFIG_SPIRAM_SIZE=-1 +CONFIG_SPIRAM_SPEED_40M=y +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +CONFIG_SPIRAM_IGNORE_NOTFOUND=y +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set +# CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY is not set +CONFIG_SPIRAM_CACHE_WORKAROUND=y +# CONFIG_SPIRAM_BANKSWITCH_ENABLE is not set +# end of SPI RAM config + +# end of ESP32-specific + +# +# NVS +# +# CONFIG_NVS_ASSERT_ERROR_CHECK is not set +# end of NVS + +# +# Camera configuration +# +CONFIG_OV7670_SUPPORT=y +CONFIG_OV7725_SUPPORT=y +CONFIG_NT99141_SUPPORT=y +CONFIG_OV2640_SUPPORT=y +CONFIG_OV3660_SUPPORT=y +CONFIG_OV5640_SUPPORT=y +CONFIG_GC2145_SUPPORT=y +CONFIG_GC032A_SUPPORT=y +CONFIG_GC0308_SUPPORT=y +CONFIG_BF3005_SUPPORT=y +CONFIG_BF20A6_SUPPORT=y +# CONFIG_SC101IOT_SUPPORT is not set +CONFIG_SC030IOT_SUPPORT=y +# CONFIG_SCCB_HARDWARE_I2C_PORT0 is not set +CONFIG_SCCB_HARDWARE_I2C_PORT1=y +CONFIG_SCCB_CLK_FREQ=100000 +# CONFIG_GC_SENSOR_WINDOWING_MODE is not set +CONFIG_GC_SENSOR_SUBSAMPLE_MODE=y +CONFIG_CAMERA_CORE0=y +# CONFIG_CAMERA_CORE1 is not set +# CONFIG_CAMERA_NO_AFFINITY is not set +CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX=32768 +# end of Camera configuration + +# end of Component config +# +CONFIG_ESP_CONSOLE_UART_TX_GPIO=1 +CONFIG_ESP_CONSOLE_UART_RX_GPIO=3 + diff --git a/ports/espressif/boards/espressif_esp32s3_box/board.c b/ports/espressif/boards/espressif_esp32s3_box/board.c index 7eb4c6b20c..e9f4bb2a66 100644 --- a/ports/espressif/boards/espressif_esp32s3_box/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box/board.c @@ -80,8 +80,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO45, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c index 71659f4b0e..48f69d63b2 100644 --- a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c @@ -81,8 +81,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO45, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/espressif_esp32s3_eye/board.c b/ports/espressif/boards/espressif_esp32s3_eye/board.c new file mode 100644 index 0000000000..230d8b40b6 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32s3_eye/board.c @@ -0,0 +1,137 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/displayio/FourWire.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-module/displayio/__init__.h" +#include "shared-module/displayio/mipi_constants.h" +#include "shared-bindings/board/__init__.h" + +displayio_fourwire_obj_t board_display_obj; + +#define DELAY 0x80 + +// display init sequence according to LilyGO example app +uint8_t display_init_sequence[] = { + // sw reset + 0x01, 0 | DELAY, 150, + // sleep out + 0x11, 0 | DELAY, 255, + // normal display mode on + 0x13, 0, + // display and color format settings + 0x36, 1, 0x08, + 0xB6, 2, 0x0A, 0x82, + 0x3A, 1 | DELAY, 0x55, 10, + // ST7789V frame rate setting + 0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33, + // voltages: VGH / VGL + 0xB7, 1, 0x35, + // ST7789V power setting + 0xBB, 1, 0x28, + 0xC0, 1, 0x0C, + 0xC2, 2, 0x01, 0xFF, + 0xC3, 1, 0x10, + 0xC4, 1, 0x20, + 0xC6, 1, 0x0F, + 0xD0, 2, 0xA4, 0xA1, + // ST7789V gamma setting + 0xE0, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17, + 0xE1, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E, + 0x21, 0, + // display on + 0x29, 0 | DELAY, 255, +}; + +void board_init(void) { + busio_spi_obj_t *spi = common_hal_board_create_spi(0); + displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + bus->base.type = &displayio_fourwire_type; + + common_hal_displayio_fourwire_construct( + bus, + spi, + &pin_GPIO43, // DC + &pin_GPIO44, // CS + NULL, // no reset pin + 40000000, // baudrate + 0, // polarity + 0 // phase + ); + displayio_display_obj_t *display = &displays[0].display; + display->base.type = &displayio_display_type; + + // workaround as board_init() is called before reset_port() in main.c + pwmout_reset(); + + common_hal_displayio_display_construct( + display, + bus, + 240, // width (after rotation) + 240, // height (after rotation) + 0, // column start + 0, // row start + 0, // rotation + 16, // color depth + false, // grayscale + false, // pixels in a byte share a row. Only valid for depths < 8 + 1, // bytes per cell. Only valid for depths < 8 + false, // reverse_pixels_in_byte. Only valid for depths < 8 + true, // reverse_pixels_in_word + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command + display_init_sequence, + sizeof(display_init_sequence), + &pin_GPIO48, // backlight pin + NO_BRIGHTNESS_COMMAND, + 1.0f, // brightness + false, // single_byte_bounds + false, // data_as_commands + true, // auto_refresh + 60, // native_frames_per_second + false, // backlight_on_high + false, // SH1107_addressing + 50000 // backlight pwm frequency + ); + + common_hal_never_reset_pin(&pin_GPIO48); // backlight pin + // Debug UART +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} + +void board_deinit(void) { +} diff --git a/ports/espressif/boards/espressif_esp32s3_eye/mpconfigboard.h b/ports/espressif/boards/espressif_esp32s3_eye/mpconfigboard.h new file mode 100644 index 0000000000..43ade4f6c8 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32s3_eye/mpconfigboard.h @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "ESP32-S3-EYE" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +// Shared by the camera and accelerometer +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO4) +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO5) + +// This is the SD card connection, not the LCD +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO39) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO40) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO38) + +#define CIRCUITPY_BOARD_SPI (2) +#define CIRCUITPY_BOARD_SPI_PIN { \ + {.clock = &pin_GPIO21, .mosi = &pin_GPIO47, .miso = NULL}, \ + {.clock = &pin_GPIO39, .mosi = &pin_GPIO40, .miso = &pin_GPIO38}, \ +} + +#define DEFAULT_RESERVED_PSRAM (1048576) diff --git a/ports/espressif/boards/espressif_esp32s3_eye/mpconfigboard.mk b/ports/espressif/boards/espressif_esp32s3_eye/mpconfigboard.mk new file mode 100644 index 0000000000..bf9464353f --- /dev/null +++ b/ports/espressif/boards/espressif_esp32s3_eye/mpconfigboard.mk @@ -0,0 +1,17 @@ +USB_VID = 0x303A +USB_PID = 0x700F +USB_PRODUCT = "ESP32-S3-EYE" +USB_MANUFACTURER = "Espressif" + +IDF_TARGET = esp32s3 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = MPZ + +# The default queue depth of 16 overflows on release builds, +# so increase it to 32. +CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32 + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 8MB diff --git a/ports/espressif/boards/espressif_esp32s3_eye/pins.c b/ports/espressif/boards/espressif_esp32s3_eye/pins.c new file mode 100644 index 0000000000..defa4e9c52 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32s3_eye/pins.c @@ -0,0 +1,56 @@ +#include "py/objtuple.h" +#include "shared-bindings/board/__init__.h" +#include "shared-module/displayio/__init__.h" + +STATIC const mp_rom_obj_tuple_t camera_data_tuple = { + {&mp_type_tuple}, + 8, + { + MP_ROM_PTR(&pin_GPIO11), + MP_ROM_PTR(&pin_GPIO9), + MP_ROM_PTR(&pin_GPIO8), + MP_ROM_PTR(&pin_GPIO10), + MP_ROM_PTR(&pin_GPIO12), + MP_ROM_PTR(&pin_GPIO18), + MP_ROM_PTR(&pin_GPIO17), + MP_ROM_PTR(&pin_GPIO16), + } +}; + + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_BUTTONS), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_MIC_SDO), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, // LCD + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_DATA), MP_ROM_PTR(&camera_data_tuple) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_VSYNC), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_HREF), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_PCLK), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_XCLK), MP_ROM_PTR(&pin_GPIO15) }, + + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_MISO1), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_MOSI1), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_SCK1), MP_ROM_PTR(&pin_GPIO39) }, + + { MP_ROM_QSTR(MP_QSTR_MIC_SCK), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_MIC_WS), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_BACKLIGHT), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO48) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + + { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig b/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig new file mode 100644 index 0000000000..1a24832767 --- /dev/null +++ b/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig @@ -0,0 +1,34 @@ +CONFIG_ESP32S3_SPIRAM_SUPPORT=y +# +# SPI RAM config +# +# CONFIG_SPIRAM_MODE_QUAD is not set +CONFIG_SPIRAM_MODE_OCT=y +# CONFIG_SPIRAM_TYPE_AUTO is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=8388608 +# end of SPI RAM config + +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +# +# PSRAM Clock and CS IO for ESP32S3 +# +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM Clock and CS IO for ESP32S3 + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +CONFIG_SPIRAM_SPEED_80M=y +# CONFIG_SPIRAM_SPEED_40M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-eye" +# end of LWIP diff --git a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c index f278c7ddbc..c2bfec465d 100644 --- a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c +++ b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c @@ -108,8 +108,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO9, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/espressif_kaluga_1.3/mpconfigboard.h b/ports/espressif/boards/espressif_kaluga_1.3/mpconfigboard.h index 8f89bfcbc4..459a5b3289 100644 --- a/ports/espressif/boards/espressif_kaluga_1.3/mpconfigboard.h +++ b/ports/espressif/boards/espressif_kaluga_1.3/mpconfigboard.h @@ -30,3 +30,6 @@ #define MICROPY_HW_MCU_NAME "ESP32S2" #define MICROPY_HW_NEOPIXEL (&pin_GPIO45) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO7) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8) diff --git a/ports/espressif/boards/espressif_kaluga_1.3/pins.c b/ports/espressif/boards/espressif_kaluga_1.3/pins.c index dff98ceeb9..caa7ecd064 100644 --- a/ports/espressif/boards/espressif_kaluga_1.3/pins.c +++ b/ports/espressif/boards/espressif_kaluga_1.3/pins.c @@ -140,5 +140,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S1_LRCK_DAC1), MP_ROM_PTR(&pin_GPIO17) }, { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S1_BCLK_DAC2), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/hardkernel_odroid_go/board.c b/ports/espressif/boards/hardkernel_odroid_go/board.c index 2249adeacd..c161fa9e59 100644 --- a/ports/espressif/boards/hardkernel_odroid_go/board.c +++ b/ports/espressif/boards/hardkernel_odroid_go/board.c @@ -100,8 +100,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO14, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/hexky_s2/board.c b/ports/espressif/boards/hexky_s2/board.c index 584253488b..a4a2f02e60 100644 --- a/ports/espressif/boards/hexky_s2/board.c +++ b/ports/espressif/boards/hexky_s2/board.c @@ -112,8 +112,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO45, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - false, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/hiibot_iots2/board.c b/ports/espressif/boards/hiibot_iots2/board.c index e65401deda..245d0206ac 100644 --- a/ports/espressif/boards/hiibot_iots2/board.c +++ b/ports/espressif/boards/hiibot_iots2/board.c @@ -117,8 +117,7 @@ static void display_init(void) { sizeof(display_init_sequence), &pin_GPIO38, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - false, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c index 8f0d01fe79..24d847744d 100644 --- a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c +++ b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c @@ -117,8 +117,7 @@ static void display_init(void) { sizeof(display_init_sequence), &pin_GPIO33, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - false, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/mixgo_ce_serial/mpconfigboard.mk b/ports/espressif/boards/mixgo_ce_serial/mpconfigboard.mk index 31955af81f..b6d165b82d 100644 --- a/ports/espressif/boards/mixgo_ce_serial/mpconfigboard.mk +++ b/ports/espressif/boards/mixgo_ce_serial/mpconfigboard.mk @@ -16,6 +16,8 @@ CIRCUITPY_ESP_FLASH_MODE = dio CIRCUITPY_ESP_FLASH_FREQ = 40m CIRCUITPY_ESP_FLASH_SIZE = 4MB +CIRCUITPY_ESP32_CAMERA = 0 + FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel FROZEN_MPY_DIRS += $(TOP)/frozen/mixgo_cp_lib/mixgoce_lib diff --git a/ports/espressif/boards/mixgo_ce_udisk/mpconfigboard.mk b/ports/espressif/boards/mixgo_ce_udisk/mpconfigboard.mk index 4b8fe6846c..5d6fc8368f 100644 --- a/ports/espressif/boards/mixgo_ce_udisk/mpconfigboard.mk +++ b/ports/espressif/boards/mixgo_ce_udisk/mpconfigboard.mk @@ -16,6 +16,8 @@ CIRCUITPY_ESP_FLASH_MODE = dio CIRCUITPY_ESP_FLASH_FREQ = 40m CIRCUITPY_ESP_FLASH_SIZE = 4MB +CIRCUITPY_ESP32_CAMERA = 0 + FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel FROZEN_MPY_DIRS += $(TOP)/frozen/mixgo_cp_lib/mixgoce_lib diff --git a/ports/espressif/boards/morpheans_morphesp-240/board.c b/ports/espressif/boards/morpheans_morphesp-240/board.c index 54e83eaaab..7deff5998c 100644 --- a/ports/espressif/boards/morpheans_morphesp-240/board.c +++ b/ports/espressif/boards/morpheans_morphesp-240/board.c @@ -198,8 +198,7 @@ void board_init(void) { sizeof(display_init_sequence), NULL, // There is no backlight pin, defined for now. NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/espressif/boards/smartbeedesigns_bee_motion_s3/board.c b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/board.c new file mode 100644 index 0000000000..0432485111 --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/board.c @@ -0,0 +1,48 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif /* DEBUG */ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} + +void board_deinit(void) { +} diff --git a/ports/espressif/boards/smartbeedesigns_bee_motion_s3/mpconfigboard.h b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/mpconfigboard.h new file mode 100644 index 0000000000..11e2449e9b --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/mpconfigboard.h @@ -0,0 +1,41 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "Bee-Motion-S3" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO48) +#define DEFAULT_UART_BUS_RX (&pin_GPIO44) +#define DEFAULT_UART_BUS_TX (&pin_GPIO43) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO36) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO37) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO17) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO15) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO16) diff --git a/ports/espressif/boards/smartbeedesigns_bee_motion_s3/mpconfigboard.mk b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/mpconfigboard.mk new file mode 100644 index 0000000000..67a0ab21e8 --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/mpconfigboard.mk @@ -0,0 +1,20 @@ +USB_VID = 0x303A +USB_PID = 0x8114 +USB_PRODUCT = "Bee-Motion-S3" +USB_MANUFACTURER = "Smart Bee Designs" + +IDF_TARGET = esp32s3 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = MPZ + +# The default queue depth of 16 overflows on release builds, +# so increase it to 32. +CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32 + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 8MB + + +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/espressif/boards/smartbeedesigns_bee_motion_s3/pins.c b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/pins.c new file mode 100644 index 0000000000..e6c02d59d5 --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/pins.c @@ -0,0 +1,102 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) }, + + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) }, + + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_A8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) }, + + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_A9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) }, + + { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_A11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) }, + + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_A12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) }, + + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_A12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) }, + + { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_A13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_A14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) }, + + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_A15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) }, + + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16) }, + + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) }, + + + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_D35), MP_ROM_PTR(&pin_GPIO35) }, + + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_D36), MP_ROM_PTR(&pin_GPIO36) }, + + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_D37), MP_ROM_PTR(&pin_GPIO37) }, + + { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO34) }, + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_D43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44)}, + { MP_ROM_QSTR(MP_QSTR_D44), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_BOOT_BTN), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_VBAT), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_VBAT_SENSE), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_LIGHT), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_LIGHT_SENSOR), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_PIR), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_PIR_SENSOR), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_), MP_ROM_PTR(&pin_GPIO34) }, + + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig new file mode 100644 index 0000000000..84cf45aa83 --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig @@ -0,0 +1,6 @@ +# CONFIG_ESP32S3_SPIRAM_SUPPORT is not set +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_motion_s3" +# end of LWIP diff --git a/ports/espressif/boards/smartbeedesigns_bee_s3/board.c b/ports/espressif/boards/smartbeedesigns_bee_s3/board.c new file mode 100644 index 0000000000..0432485111 --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_s3/board.c @@ -0,0 +1,48 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif /* DEBUG */ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} + +void board_deinit(void) { +} diff --git a/ports/espressif/boards/smartbeedesigns_bee_s3/mpconfigboard.h b/ports/espressif/boards/smartbeedesigns_bee_s3/mpconfigboard.h new file mode 100644 index 0000000000..1a17770fb7 --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_s3/mpconfigboard.h @@ -0,0 +1,41 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "Bee-S3" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO48) +#define DEFAULT_UART_BUS_RX (&pin_GPIO44) +#define DEFAULT_UART_BUS_TX (&pin_GPIO43) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO36) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO37) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO39) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO38) diff --git a/ports/espressif/boards/smartbeedesigns_bee_s3/mpconfigboard.mk b/ports/espressif/boards/smartbeedesigns_bee_s3/mpconfigboard.mk new file mode 100644 index 0000000000..dee105df1b --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_s3/mpconfigboard.mk @@ -0,0 +1,20 @@ +USB_VID = 0x303A +USB_PID = 0x8111 +USB_PRODUCT = "Bee-S3" +USB_MANUFACTURER = "Smart Bee Designs" + +IDF_TARGET = esp32s3 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = MPZ + +# The default queue depth of 16 overflows on release builds, +# so increase it to 32. +CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32 + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 8MB + + +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/espressif/boards/smartbeedesigns_bee_s3/pins.c b/ports/espressif/boards/smartbeedesigns_bee_s3/pins.c new file mode 100644 index 0000000000..189899fa49 --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_s3/pins.c @@ -0,0 +1,79 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) }, + + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) }, + + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_A8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) }, + + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_A9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) }, + + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_D35), MP_ROM_PTR(&pin_GPIO35) }, + + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_D36), MP_ROM_PTR(&pin_GPIO36) }, + + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_D37), MP_ROM_PTR(&pin_GPIO37) }, + + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_D38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO38) }, + + { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_D39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO39) }, + + { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO48) }, + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_D43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44)}, + { MP_ROM_QSTR(MP_QSTR_D44), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_VBAT), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_VBAT_SENSE), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO34) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig b/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig new file mode 100644 index 0000000000..b7bb11fdd5 --- /dev/null +++ b/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig @@ -0,0 +1,6 @@ +# CONFIG_ESP32S3_SPIRAM_SUPPORT is not set +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_s3" +# end of LWIP diff --git a/ports/espressif/common-hal/esp32_camera/Camera.c b/ports/espressif/common-hal/esp32_camera/Camera.c new file mode 100644 index 0000000000..af1d20542a --- /dev/null +++ b/ports/espressif/common-hal/esp32_camera/Camera.c @@ -0,0 +1,279 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Jeff Epler for Adafruit Industries + * + * 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. + */ + +#include "py/runtime.h" + +#include "bindings/esp32_camera/Camera.h" +#include "bindings/espidf/__init__.h" +#include "common-hal/esp32_camera/Camera.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "common-hal/microcontroller/Pin.h" + +#include "esp32-camera/driver/private_include/cam_hal.h" + +static void maybe_claim_pin(const mcu_pin_obj_t *pin) { + if (pin) { + claim_pin(pin); + } +} + +void common_hal_esp32_camera_camera_construct( + esp32_camera_camera_obj_t *self, + uint8_t data_pins[8], + const mcu_pin_obj_t *external_clock_pin, + const mcu_pin_obj_t *pixel_clock_pin, + const mcu_pin_obj_t *vsync_pin, + const mcu_pin_obj_t *href_pin, + const mcu_pin_obj_t *powerdown_pin, + const mcu_pin_obj_t *reset_pin, + const busio_i2c_obj_t *i2c, + mp_int_t external_clock_frequency, + pixformat_t pixel_format, + framesize_t frame_size, + mp_int_t jpeg_quality, + mp_int_t framebuffer_count, + camera_grab_mode_t grab_mode) { + + for (int i = 0; i < 8; i++) { + claim_pin_number(data_pins[i]); + } + claim_pin(external_clock_pin); + claim_pin(pixel_clock_pin); + claim_pin(vsync_pin); + claim_pin(href_pin); + maybe_claim_pin(powerdown_pin); + maybe_claim_pin(reset_pin); + + common_hal_pwmio_pwmout_construct(&self->pwm, external_clock_pin, 1, external_clock_frequency, true); + + self->camera_config.pin_pwdn = common_hal_mcu_pin_number(powerdown_pin); + self->camera_config.pin_reset = common_hal_mcu_pin_number(reset_pin); + self->camera_config.pin_xclk = common_hal_mcu_pin_number(external_clock_pin); + + self->camera_config.pin_sccb_sda = NO_PIN; + self->camera_config.pin_sccb_scl = NO_PIN; + /* sccb i2c port set below */ + + self->camera_config.pin_d7 = data_pins[7]; + self->camera_config.pin_d6 = data_pins[6]; + self->camera_config.pin_d5 = data_pins[5]; + self->camera_config.pin_d4 = data_pins[4]; + self->camera_config.pin_d3 = data_pins[3]; + self->camera_config.pin_d2 = data_pins[2]; + self->camera_config.pin_d1 = data_pins[1]; + self->camera_config.pin_d0 = data_pins[0]; + + self->camera_config.pin_vsync = common_hal_mcu_pin_number(vsync_pin); + self->camera_config.pin_href = common_hal_mcu_pin_number(href_pin); + self->camera_config.pin_pclk = common_hal_mcu_pin_number(pixel_clock_pin); + + self->camera_config.xclk_freq_hz = external_clock_frequency; + + self->camera_config.ledc_timer = self->pwm.tim_handle.timer_num; + self->camera_config.ledc_channel = self->pwm.chan_handle.channel; + + self->camera_config.pixel_format = pixel_format; + self->camera_config.frame_size = frame_size; + self->camera_config.jpeg_quality = jpeg_quality; + self->camera_config.fb_count = framebuffer_count; + self->camera_config.grab_mode = grab_mode; + + self->camera_config.sccb_i2c_port = i2c->i2c_num; + + CHECK_ESP_RESULT(esp_camera_init(&self->camera_config)); +} + +extern void common_hal_esp32_camera_camera_deinit(esp32_camera_camera_obj_t *self) { + if (common_hal_esp32_camera_camera_deinited(self)) { + return; + } + + common_hal_pwmio_pwmout_deinit(&self->pwm); + + reset_pin_number(self->camera_config.pin_pwdn); + reset_pin_number(self->camera_config.pin_reset); + reset_pin_number(self->camera_config.pin_xclk); + + reset_pin_number(self->camera_config.pin_d7); + reset_pin_number(self->camera_config.pin_d6); + reset_pin_number(self->camera_config.pin_d5); + reset_pin_number(self->camera_config.pin_d4); + reset_pin_number(self->camera_config.pin_d3); + reset_pin_number(self->camera_config.pin_d2); + reset_pin_number(self->camera_config.pin_d1); + reset_pin_number(self->camera_config.pin_d0); + + esp_camera_deinit(); + + self->camera_config.xclk_freq_hz = 0; +} + +bool common_hal_esp32_camera_camera_deinited(esp32_camera_camera_obj_t *self) { + return !self->camera_config.xclk_freq_hz; +} + +bool common_hal_esp32_camera_camera_available(esp32_camera_camera_obj_t *self) { + return esp_camera_fb_available(); +} + +camera_fb_t *common_hal_esp32_camera_camera_take(esp32_camera_camera_obj_t *self, int timeout_ms) { + if (self->buffer_to_return) { + esp_camera_fb_return(self->buffer_to_return); + self->buffer_to_return = NULL; + } + return self->buffer_to_return = esp_camera_fb_get_timeout(timeout_ms); +} + +#define SENSOR_GETSET(type, name, field_name, setter_function_name) \ + SENSOR_GET(type, name, field_name, setter_function_name) \ + SENSOR_SET(type, name, setter_function_name) + +#define SENSOR_STATUS_GETSET(type, name, status_field_name, setter_function_name) \ + SENSOR_GETSET(type, name, status.status_field_name, setter_function_name) + +#define SENSOR_GET(type, name, status_field_name, setter_function_name) \ + type common_hal_esp32_camera_camera_get_##name(esp32_camera_camera_obj_t * self) { \ + sensor_t *sensor = esp_camera_sensor_get(); \ + if (!sensor->setter_function_name) { \ + mp_raise_AttributeError(translate("no such attribute")); \ + } \ + return sensor->status_field_name; \ + } + +#define SENSOR_SET(type, name, setter_function_name) \ + void common_hal_esp32_camera_camera_set_##name(esp32_camera_camera_obj_t * self, type value) { \ + sensor_t *sensor = esp_camera_sensor_get(); \ + if (!sensor->setter_function_name) { \ + mp_raise_AttributeError(translate("no such attribute")); \ + } \ + if (sensor->setter_function_name(sensor, value) < 0) { \ + mp_raise_ValueError(translate("invalid setting")); \ + } \ + } + +pixformat_t common_hal_esp32_camera_camera_get_pixel_format(esp32_camera_camera_obj_t *self) { + return self->camera_config.pixel_format; +} + +framesize_t common_hal_esp32_camera_camera_get_frame_size(esp32_camera_camera_obj_t *self) { + return self->camera_config.frame_size; +} + +#include "esp_log.h" + +void common_hal_esp32_camera_camera_reconfigure(esp32_camera_camera_obj_t *self, framesize_t frame_size, pixformat_t pixel_format, camera_grab_mode_t grab_mode, mp_int_t framebuffer_count) { + sensor_t *sensor = esp_camera_sensor_get(); + camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&sensor->id); + + if (PIXFORMAT_JPEG == pixel_format && (!sensor_info->support_jpeg)) { + raise_esp_error(ESP_ERR_NOT_SUPPORTED); + } + + if (frame_size > sensor_info->max_size) { + frame_size = sensor_info->max_size; + } + + cam_deinit(); + self->camera_config.pixel_format = pixel_format; + self->camera_config.frame_size = frame_size; + self->camera_config.grab_mode = grab_mode; + self->camera_config.fb_count = framebuffer_count; + sensor->set_pixformat(sensor, self->camera_config.pixel_format); + sensor->set_framesize(sensor, self->camera_config.frame_size); + cam_init(&self->camera_config); + cam_config(&self->camera_config, frame_size, sensor_info->pid); + cam_start(); +} + +SENSOR_STATUS_GETSET(int, contrast, contrast, set_contrast); +SENSOR_STATUS_GETSET(int, brightness, brightness, set_brightness); +SENSOR_STATUS_GETSET(int, saturation, saturation, set_saturation); +SENSOR_STATUS_GETSET(int, sharpness, sharpness, set_sharpness); +SENSOR_STATUS_GETSET(int, denoise, denoise, set_denoise); +SENSOR_STATUS_GETSET(gainceiling_t, gainceiling, gainceiling, set_gainceiling); +SENSOR_STATUS_GETSET(int, quality, quality, set_quality); +SENSOR_STATUS_GETSET(bool, colorbar, colorbar, set_colorbar); +SENSOR_STATUS_GETSET(bool, whitebal, awb, set_whitebal); +SENSOR_STATUS_GETSET(bool, gain_ctrl, agc, set_gain_ctrl); +SENSOR_STATUS_GETSET(bool, exposure_ctrl, aec, set_exposure_ctrl); +SENSOR_STATUS_GETSET(bool, hmirror, hmirror, set_hmirror); +SENSOR_STATUS_GETSET(bool, vflip, vflip, set_vflip); +SENSOR_STATUS_GETSET(bool, aec2, aec2, set_aec2); +SENSOR_STATUS_GETSET(bool, awb_gain, awb_gain, set_awb_gain); +SENSOR_STATUS_GETSET(int, agc_gain, agc_gain, set_agc_gain); +SENSOR_STATUS_GETSET(int, aec_value, aec_value, set_aec_value); +SENSOR_STATUS_GETSET(int, special_effect, special_effect, set_special_effect); +SENSOR_STATUS_GETSET(int, wb_mode, wb_mode, set_wb_mode); +SENSOR_STATUS_GETSET(int, ae_level, ae_level, set_ae_level); +SENSOR_STATUS_GETSET(bool, dcw, dcw, set_dcw); +SENSOR_STATUS_GETSET(bool, bpc, bpc, set_bpc); +SENSOR_STATUS_GETSET(bool, wpc, wpc, set_wpc); +SENSOR_STATUS_GETSET(bool, raw_gma, raw_gma, set_raw_gma); +SENSOR_STATUS_GETSET(bool, lenc, lenc, set_lenc); + +const char *common_hal_esp32_camera_camera_get_sensor_name(esp32_camera_camera_obj_t *self) { + sensor_t *sensor = esp_camera_sensor_get(); + camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&sensor->id); + return sensor_info->name; +} + +const bool common_hal_esp32_camera_camera_get_supports_jpeg(esp32_camera_camera_obj_t *self) { + sensor_t *sensor = esp_camera_sensor_get(); + camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&sensor->id); + return sensor_info->support_jpeg; +} + +const framesize_t common_hal_esp32_camera_camera_get_max_frame_size(esp32_camera_camera_obj_t *self) { + sensor_t *sensor = esp_camera_sensor_get(); + camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&sensor->id); + return sensor_info->max_size; +} + +const int common_hal_esp32_camera_camera_get_address(esp32_camera_camera_obj_t *self) { + sensor_t *sensor = esp_camera_sensor_get(); + camera_sensor_info_t *sensor_info = esp_camera_sensor_get_info(&sensor->id); + return sensor_info->sccb_addr; +} + +const int common_hal_esp32_camera_camera_get_width(esp32_camera_camera_obj_t *self) { + sensor_t *sensor = esp_camera_sensor_get(); + framesize_t framesize = sensor->status.framesize; + return resolution[framesize].width; +} + +const int common_hal_esp32_camera_camera_get_height(esp32_camera_camera_obj_t *self) { + sensor_t *sensor = esp_camera_sensor_get(); + framesize_t framesize = sensor->status.framesize; + return resolution[framesize].height; +} + +const camera_grab_mode_t common_hal_esp32_camera_camera_get_grab_mode(esp32_camera_camera_obj_t *self) { + return self->camera_config.grab_mode; +} + +const int common_hal_esp32_camera_camera_get_framebuffer_count(esp32_camera_camera_obj_t *self) { + return self->camera_config.fb_count; +} diff --git a/ports/espressif/common-hal/esp32_camera/Camera.h b/ports/espressif/common-hal/esp32_camera/Camera.h new file mode 100644 index 0000000000..9c21f81b16 --- /dev/null +++ b/ports/espressif/common-hal/esp32_camera/Camera.h @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Jeff Epler for Adafruit Industries + * + * 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. + */ + +#pragma once + +#include "py/obj.h" +#include "esp_camera.h" +#include "shared-bindings/pwmio/PWMOut.h" + +typedef struct esp32_camera_camera_obj { + mp_obj_base_t base; + camera_config_t camera_config; + camera_fb_t *buffer_to_return; + pwmio_pwmout_obj_t pwm; +} esp32_camera_obj_t; diff --git a/ports/espressif/common-hal/i2cperipheral/__init__.c b/ports/espressif/common-hal/i2cperipheral/__init__.c deleted file mode 100644 index c67511c536..0000000000 --- a/ports/espressif/common-hal/i2cperipheral/__init__.c +++ /dev/null @@ -1 +0,0 @@ -// No i2cperipheral module functions. diff --git a/ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c b/ports/espressif/common-hal/i2ctarget/I2CTarget.c similarity index 76% rename from ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c rename to ports/espressif/common-hal/i2ctarget/I2CTarget.c index 6bd71cc797..ad0d09967a 100644 --- a/ports/espressif/common-hal/i2cperipheral/I2CPeripheral.c +++ b/ports/espressif/common-hal/i2ctarget/I2CTarget.c @@ -24,15 +24,15 @@ * THE SOFTWARE. */ -#include "shared-bindings/i2cperipheral/I2CPeripheral.h" +#include "shared-bindings/i2ctarget/I2CTarget.h" #include "py/mperrno.h" #include "py/runtime.h" -#include "common-hal/i2cperipheral/I2CPeripheral.h" +#include "common-hal/i2ctarget/I2CTarget.h" #include "shared-bindings/microcontroller/Pin.h" -void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_obj_t *self, +void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint8_t *addresses, unsigned int num_addresses, bool smbus) { // Pins 45 and 46 are "strapping" pins that impact start up behavior. They usually need to @@ -73,7 +73,7 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe if (err == ESP_FAIL) { mp_raise_OSError(MP_EIO); } else { - mp_arg_error_invalid(MP_QSTR_I2CPeripheral); + mp_arg_error_invalid(MP_QSTR_I2CTarget); } } @@ -81,12 +81,12 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe claim_pin(scl); } -bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self) { +bool common_hal_i2ctarget_i2c_target_deinited(i2ctarget_i2c_target_obj_t *self) { return self->sda_pin == NULL; } -void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self) { - if (common_hal_i2cperipheral_i2c_peripheral_deinited(self)) { +void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self) { + if (common_hal_i2ctarget_i2c_target_deinited(self)) { return; } @@ -98,7 +98,7 @@ void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral self->scl_pin = NULL; } -int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, +int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) { *address = self->addresses[0]; *is_read = true; @@ -106,21 +106,21 @@ int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_perip return 1; } -int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *data) { +int common_hal_i2ctarget_i2c_target_read_byte(i2ctarget_i2c_target_obj_t *self, uint8_t *data) { i2c_slave_read_buffer(self->i2c_num, data, 128, 0); return 1; } -int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t data) { +int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self, uint8_t data) { i2c_reset_tx_fifo(self->i2c_num); i2c_slave_write_buffer(self->i2c_num, &data, 128, 0); return 1; } -void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_obj_t *self, bool ack) { +void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack) { } -void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_obj_t *self) { +void common_hal_i2ctarget_i2c_target_close(i2ctarget_i2c_target_obj_t *self) { } diff --git a/ports/espressif/common-hal/i2cperipheral/I2CPeripheral.h b/ports/espressif/common-hal/i2ctarget/I2CTarget.h similarity index 85% rename from ports/espressif/common-hal/i2cperipheral/I2CPeripheral.h rename to ports/espressif/common-hal/i2ctarget/I2CTarget.h index d3b324b39a..422bd720eb 100644 --- a/ports/espressif/common-hal/i2cperipheral/I2CPeripheral.h +++ b/ports/espressif/common-hal/i2ctarget/I2CTarget.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H -#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H +#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_TARGET_H +#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_TARGET_H #include "py/obj.h" #include "peripherals/i2c.h" @@ -38,6 +38,6 @@ typedef struct { uint8_t num_addresses; const mcu_pin_obj_t *scl_pin; const mcu_pin_obj_t *sda_pin; -} i2cperipheral_i2c_peripheral_obj_t; +} i2ctarget_i2c_target_obj_t; -#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_PERIPHERAL_H +#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BUSIO_I2C_TARGET_H diff --git a/ports/espressif/common-hal/i2ctarget/__init__.c b/ports/espressif/common-hal/i2ctarget/__init__.c new file mode 100644 index 0000000000..4ec26465ad --- /dev/null +++ b/ports/espressif/common-hal/i2ctarget/__init__.c @@ -0,0 +1 @@ +// No i2ctarget module functions. diff --git a/ports/espressif/common-hal/microcontroller/Pin.c b/ports/espressif/common-hal/microcontroller/Pin.c index 4ac98c7927..8a09c98d74 100644 --- a/ports/espressif/common-hal/microcontroller/Pin.c +++ b/ports/espressif/common-hal/microcontroller/Pin.c @@ -100,7 +100,9 @@ static const uint64_t pin_mask_reset_forbidden = void never_reset_pin_number(gpio_num_t pin_number) { - if (pin_number == NO_PIN) { + // Some CircuitPython APIs deal in uint8_t pin numbers, but NO_PIN is -1. + // Also allow pin 255 to be treated as NO_PIN to avoid crashes + if (pin_number == NO_PIN || pin_number == (uint8_t)NO_PIN) { return; } never_reset_pins |= PIN_BIT(pin_number); @@ -141,7 +143,9 @@ STATIC void _reset_pin(gpio_num_t pin_number) { // Mark pin as free and return it to a quiescent state. void reset_pin_number(gpio_num_t pin_number) { - if (pin_number == NO_PIN) { + // Some CircuitPython APIs deal in uint8_t pin numbers, but NO_PIN is -1. + // Also allow pin 255 to be treated as NO_PIN to avoid crashes + if (pin_number == NO_PIN || pin_number == (uint8_t)NO_PIN) { return; } never_reset_pins &= ~PIN_BIT(pin_number); @@ -174,7 +178,9 @@ void reset_all_pins(void) { } void claim_pin_number(gpio_num_t pin_number) { - if (pin_number == NO_PIN) { + // Some CircuitPython APIs deal in uint8_t pin numbers, but NO_PIN is -1. + // Also allow pin 255 to be treated as NO_PIN to avoid crashes + if (pin_number == NO_PIN || pin_number == (uint8_t)NO_PIN) { return; } in_use |= PIN_BIT(pin_number); diff --git a/ports/espressif/esp-idf-config/sdkconfig-esp32.defaults b/ports/espressif/esp-idf-config/sdkconfig-esp32.defaults index c60941afdf..62e35a32e2 100644 --- a/ports/espressif/esp-idf-config/sdkconfig-esp32.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig-esp32.defaults @@ -463,7 +463,6 @@ CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y # CONFIG_ESP_MAIN_TASK_AFFINITY_CPU1 is not set # CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set @@ -1104,17 +1103,10 @@ CONFIG_ESP32S2_PANIC_PRINT_HALT=y # CONFIG_ESP32S2_PANIC_GDBSTUB is not set CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_MAIN_TASK_STACK_SIZE=8192 # CONFIG_CONSOLE_UART_DEFAULT is not set -CONFIG_CONSOLE_UART_CUSTOM=y -# CONFIG_ESP_CONSOLE_UART_NONE is not set -CONFIG_CONSOLE_UART=y -CONFIG_CONSOLE_UART_CUSTOM_NUM_0=y -# CONFIG_CONSOLE_UART_CUSTOM_NUM_1 is not set -CONFIG_CONSOLE_UART_NUM=0 -CONFIG_CONSOLE_UART_TX_GPIO=8 -CONFIG_CONSOLE_UART_RX_GPIO=7 -CONFIG_CONSOLE_UART_BAUDRATE=115200 +# CONFIG_CONSOLE_UART_CUSTOM is not set +CONFIG_ESP_CONSOLE_UART_NONE=y +CONFIG_CONSOLE_UART_NUM=-1 CONFIG_INT_WDT=y CONFIG_INT_WDT_TIMEOUT_MS=300 CONFIG_INT_WDT_CHECK_CPU1=y diff --git a/ports/espressif/esp-idf-config/sdkconfig-esp32s3.defaults b/ports/espressif/esp-idf-config/sdkconfig-esp32s3.defaults index bfb867d923..ce0d9f8d62 100644 --- a/ports/espressif/esp-idf-config/sdkconfig-esp32s3.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig-esp32s3.defaults @@ -191,3 +191,31 @@ CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY=y CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT=-1 CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread" # end of Deprecated options for backward compatibility + +# +# Camera configuration +# +CONFIG_OV7670_SUPPORT=y +# CONFIG_OV7725_SUPPORT is not set +# CONFIG_NT99141_SUPPORT is not set +CONFIG_OV2640_SUPPORT=y +CONFIG_OV3660_SUPPORT=y +CONFIG_OV5640_SUPPORT=y +# CONFIG_GC2145_SUPPORT is not set +# CONFIG_GC032A_SUPPORT is not set +# CONFIG_GC0308_SUPPORT is not set +# CONFIG_BF3005_SUPPORT is not set +# CONFIG_BF20A6_SUPPORT is not set +# CONFIG_SC101IOT_SUPPORT is not set +# CONFIG_SC030IOT_SUPPORT is not set +# CONFIG_SCCB_HARDWARE_I2C_PORT0 is not set +CONFIG_SCCB_HARDWARE_I2C_PORT1=y +CONFIG_SCCB_CLK_FREQ=100000 +CONFIG_CAMERA_CORE0=y +# CONFIG_CAMERA_CORE1 is not set +# CONFIG_CAMERA_NO_AFFINITY is not set +CONFIG_CAMERA_DMA_BUFFER_SIZE_MAX=32768 +# CONFIG_CAMERA_CONVERTER_ENABLED is not set +# end of Camera configuration +# end of Component config + diff --git a/ports/espressif/esp-idf-config/sdkconfig.defaults b/ports/espressif/esp-idf-config/sdkconfig.defaults index f30e8c1109..21ac590698 100644 --- a/ports/espressif/esp-idf-config/sdkconfig.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig.defaults @@ -294,7 +294,7 @@ CONFIG_ESP_SYSTEM_RTC_FAST_MEM_AS_HEAP_DEPCHECK=y CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP=y CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304 -CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=16384 CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048 CONFIG_ESP_INT_WDT=y CONFIG_ESP_INT_WDT_TIMEOUT_MS=300 diff --git a/ports/espressif/esp32-camera b/ports/espressif/esp32-camera new file mode 160000 index 0000000000..28804391c0 --- /dev/null +++ b/ports/espressif/esp32-camera @@ -0,0 +1 @@ +Subproject commit 28804391c002f6a3ea5ce6a55aee3b191be3ecde diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index f390cbb21a..c2949ccbab 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -20,8 +20,8 @@ CIRCUITPY_DUALBANK ?= 1 CIRCUITPY_FRAMEBUFFERIO ?= 1 CIRCUITPY_FREQUENCYIO ?= 1 CIRCUITPY_HASHLIB ?= 1 -CIRCUITPY_IMAGECAPTURE ?= 1 -CIRCUITPY_I2CPERIPHERAL ?= 1 +CIRCUITPY_IMAGECAPTURE ?= 0 +CIRCUITPY_I2CTARGET ?= 1 CIRCUITPY_RGBMATRIX ?= 1 CIRCUITPY_ROTARYIO ?= 1 CIRCUITPY_NVM ?= 1 @@ -35,12 +35,12 @@ CIRCUITPY_ESPIDF ?= 1 ifeq ($(IDF_TARGET),esp32) CIRCUITPY_BLEIO = 0 CIRCUITPY_BLEIO_HCI = 0 -CIRCUITPY_IMAGECAPTURE = 0 CIRCUITPY_PARALLELDISPLAY = 0 # Protomatter needs to support ESP32. CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_USB = 0 CIRCUITPY_BUILD_EXTENSIONS ?= bin +CIRCUITPY_ESP32_CAMERA ?= 1 else ifeq ($(IDF_TARGET),esp32c3) CIRCUITPY_AESIO = 0 @@ -51,7 +51,6 @@ CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_COUNTIO = 0 CIRCUITPY_DUALBANK = 0 CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_IMAGECAPTURE = 0 CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PS2IO = 0 CIRCUITPY_ROTARYIO = 0 @@ -63,15 +62,16 @@ CIRCUITPY_BUILD_EXTENSIONS ?= bin else ifeq ($(IDF_TARGET),esp32s3) CIRCUITPY_BLEIO = 1 CIRCUITPY_BLEIO_HCI = 0 -CIRCUITPY_IMAGECAPTURE = 0 CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_BUILD_EXTENSIONS ?= bin,uf2 +CIRCUITPY_ESP32_CAMERA ?= 1 else ifeq ($(IDF_TARGET),esp32s2) # No BLE on S2 CIRCUITPY_BLEIO = 0 CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_BUILD_EXTENSIONS ?= bin,uf2 +CIRCUITPY_ESP32_CAMERA ?= 1 endif # From ESP32-S2/S3 Technical Reference Manual: @@ -85,3 +85,7 @@ endif # only if something else is turned off, such as HID. USB_NUM_ENDPOINT_PAIRS = 7 USB_NUM_IN_ENDPOINTS = 5 + +CIRCUITPY_ESP32_CAMERA ?= 0 +CIRCUITPY_GIFIO ?= $(CIRCUITPY_ESP32_CAMERA) +CIRCUITPY_QRIO ?= $(CIRCUITPY_ESP32_CAMERA) diff --git a/ports/espressif/supervisor/port.c b/ports/espressif/supervisor/port.c index 65bdf00901..1bb8999274 100644 --- a/ports/espressif/supervisor/port.c +++ b/ports/espressif/supervisor/port.c @@ -76,8 +76,8 @@ #include "shared-bindings/_bleio/__init__.h" #endif -#if CIRCUITPY_IMAGECAPTURE -#include "cam.h" +#if CIRCUITPY_ESP32_CAMERA +#include "esp_camera.h" #endif #ifndef CONFIG_IDF_TARGET_ESP32 @@ -338,8 +338,9 @@ safe_mode_t port_init(void) { } void reset_port(void) { - #if CIRCUITPY_IMAGECAPTURE - cam_deinit(); + // TODO deinit for esp32-camera + #if CIRCUITPY_ESP32_CAMERA + esp_camera_deinit(); #endif reset_all_pins(); diff --git a/ports/litex/mpconfigport.mk b/ports/litex/mpconfigport.mk index 2e342db47d..d8dc4eef1e 100644 --- a/ports/litex/mpconfigport.mk +++ b/ports/litex/mpconfigport.mk @@ -18,7 +18,7 @@ CIRCUITPY_BUSIO = 0 CIRCUITPY_COUNTIO = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_NVM = 0 CIRCUITPY_PWMIO = 0 CIRCUITPY_PULSEIO = 0 diff --git a/ports/mimxrt10xx/mpconfigport.mk b/ports/mimxrt10xx/mpconfigport.mk index 5ffec18cfb..cee2d9a698 100644 --- a/ports/mimxrt10xx/mpconfigport.mk +++ b/ports/mimxrt10xx/mpconfigport.mk @@ -14,7 +14,7 @@ CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_BUSDEVICE = 1 CIRCUITPY_COUNTIO = 0 CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_NVM = 0 CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PULSEIO = 0 diff --git a/ports/nrf/boards/clue_nrf52840_express/board.c b/ports/nrf/boards/clue_nrf52840_express/board.c index 18757cdc06..5079aa9433 100644 --- a/ports/nrf/boards/clue_nrf52840_express/board.c +++ b/ports/nrf/boards/clue_nrf52840_express/board.c @@ -84,8 +84,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_P1_05, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/nrf/boards/hiibot_bluefi/board.c b/ports/nrf/boards/hiibot_bluefi/board.c index 6ee4292e70..50f235280d 100644 --- a/ports/nrf/boards/hiibot_bluefi/board.c +++ b/ports/nrf/boards/hiibot_bluefi/board.c @@ -85,8 +85,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_P1_13, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c index db65ecbbd2..1513b2182d 100644 --- a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c +++ b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c @@ -85,8 +85,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_P0_20, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/nrf/boards/ohs2020_badge/board.c b/ports/nrf/boards/ohs2020_badge/board.c index 14f1467c79..a4704e26c3 100644 --- a/ports/nrf/boards/ohs2020_badge/board.c +++ b/ports/nrf/boards/ohs2020_badge/board.c @@ -84,8 +84,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_P0_02, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk index c1d3dce6e5..04c4f3bce6 100644 --- a/ports/nrf/mpconfigport.mk +++ b/ports/nrf/mpconfigport.mk @@ -27,7 +27,7 @@ CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_BLEIO ?= 1 # No I2CPeripheral implementation -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_RTC ?= 1 diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c index 7aa9feee1b..49ace5e72a 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c @@ -97,7 +97,6 @@ void board_init(void) { NULL, 0x81, 1.0f, // brightness - false, // auto_brightness true, // single_byte_bounds true, // data as commands true, // auto_refresh diff --git a/ports/raspberrypi/boards/pimoroni_picosystem/board.c b/ports/raspberrypi/boards/pimoroni_picosystem/board.c index 0a07f3b0dd..ebfa38446a 100644 --- a/ports/raspberrypi/boards/pimoroni_picosystem/board.c +++ b/ports/raspberrypi/boards/pimoroni_picosystem/board.c @@ -101,8 +101,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_GPIO12, // backlight pin NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - true, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index 65e39ee99d..1c4de50c00 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -20,7 +20,7 @@ CIRCUITPY_ROTARYIO_SOFTENCODER = 1 # Things that need to be implemented. # Use PWM interally CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 CIRCUITPY_NVM = 1 # Use PIO interally CIRCUITPY_PULSEIO ?= 1 diff --git a/ports/stm/boards/meowbit_v121/board.c b/ports/stm/boards/meowbit_v121/board.c index 95d9139998..5c959b4fad 100644 --- a/ports/stm/boards/meowbit_v121/board.c +++ b/ports/stm/boards/meowbit_v121/board.c @@ -104,8 +104,7 @@ void board_init(void) { sizeof(display_init_sequence), &pin_PB03, NO_BRIGHTNESS_COMMAND, - 1.0f, // brightness (ignored) - false, // auto_brightness + 1.0f, // brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/stm/boards/pyb_nano_v2/mpconfigboard.mk b/ports/stm/boards/pyb_nano_v2/mpconfigboard.mk index 3ba45e0c5b..c8b548c50f 100644 --- a/ports/stm/boards/pyb_nano_v2/mpconfigboard.mk +++ b/ports/stm/boards/pyb_nano_v2/mpconfigboard.mk @@ -16,10 +16,4 @@ LD_FILE = boards/STM32F411_fs.ld # Too big for the flash CIRCUITPY_AUDIOCORE = 0 CIRCUITPY_AUDIOPWMIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BLEIO_HCI = 0 -CIRCUITPY_BUSDEVICE = 0 -CIRCUITPY_GIFIO = 0 -CIRCUITPY_KEYPAD = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_ONEWIREIO = 0 diff --git a/ports/stm/boards/swan_r5/mpconfigboard.mk b/ports/stm/boards/swan_r5/mpconfigboard.mk index ee17f65f7c..2ebaa9c23f 100644 --- a/ports/stm/boards/swan_r5/mpconfigboard.mk +++ b/ports/stm/boards/swan_r5/mpconfigboard.mk @@ -42,7 +42,7 @@ CIRCUITPY_PWMIO = 1 CIRCUITPY_AUDIOPWMIO = 1 CIRCUITPY_CANIO = 0 CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_I2CTARGET = 0 # Requires SPI, PulseIO (stub ok): CIRCUITPY_DISPLAYIO = 0 diff --git a/ports/stm/boards/thunderpack_v12/mpconfigboard.mk b/ports/stm/boards/thunderpack_v12/mpconfigboard.mk index f7905f6945..526415ca30 100644 --- a/ports/stm/boards/thunderpack_v12/mpconfigboard.mk +++ b/ports/stm/boards/thunderpack_v12/mpconfigboard.mk @@ -14,7 +14,6 @@ EXTERNAL_FLASH_DEVICES = GD25Q16C CIRCUITPY_NVM = 1 CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BLEIO_HCI = 0 -CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_ZLIB = 0 MCU_SERIES = F4 diff --git a/ports/stm/mpconfigport.mk b/ports/stm/mpconfigport.mk index 9705dcd0a0..cb578e76e2 100644 --- a/ports/stm/mpconfigport.mk +++ b/ports/stm/mpconfigport.mk @@ -24,7 +24,7 @@ ifeq ($(MCU_SERIES),F4) CIRCUITPY_AUDIOBUSIO ?= 0 CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0 - CIRCUITPY_I2CPERIPHERAL ?= 0 + CIRCUITPY_I2CTARGET ?= 0 CIRCUITPY_NVM ?= 0 CIRCUITPY_ROTARYIO ?= 0 CIRCUITPY_RTC ?= 1 @@ -39,7 +39,7 @@ ifeq ($(MCU_SERIES),H7) CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0 - CIRCUITPY_I2CPERIPHERAL ?= 0 + CIRCUITPY_I2CTARGET ?= 0 CIRCUITPY_NEOPIXEL_WRITE ?= 0 CIRCUITPY_NVM ?= 0 CIRCUITPY_PULSEIO ?= 0 @@ -58,7 +58,7 @@ ifeq ($(MCU_SERIES),F7) CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0 - CIRCUITPY_I2CPERIPHERAL ?= 0 + CIRCUITPY_I2CTARGET ?= 0 CIRCUITPY_NEOPIXEL_WRITE ?= 0 CIRCUITPY_NVM ?= 0 CIRCUITPY_ROTARYIO ?= 0 @@ -75,7 +75,7 @@ ifeq ($(MCU_SERIES),L4) CIRCUITPY_AUDIOIO ?= 0 CIRCUITPY_COUNTIO ?= 0 CIRCUITPY_FREQUENCYIO ?= 0 - CIRCUITPY_I2CPERIPHERAL ?= 0 + CIRCUITPY_I2CTARGET ?= 0 CIRCUITPY_NEOPIXEL_WRITE ?= 0 CIRCUITPY_NVM ?= 0 CIRCUITPY_ROTARYIO ?= 0 diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index af49c876ba..f22a96853e 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -210,8 +210,8 @@ endif ifeq ($(CIRCUITPY_HASHLIB),1) SRC_PATTERNS += hashlib/% endif -ifeq ($(CIRCUITPY_I2CPERIPHERAL),1) -SRC_PATTERNS += i2cperipheral/% +ifeq ($(CIRCUITPY_I2CTARGET),1) +SRC_PATTERNS += i2ctarget/% endif ifeq ($(CIRCUITPY_IMAGECAPTURE),1) SRC_PATTERNS += imagecapture/% @@ -424,8 +424,8 @@ SRC_COMMON_HAL_ALL = \ gnss/SatelliteSystem.c \ hashlib/__init__.c \ hashlib/Hash.c \ - i2cperipheral/I2CPeripheral.c \ - i2cperipheral/__init__.c \ + i2ctarget/I2CTarget.c \ + i2ctarget/__init__.c \ microcontroller/Pin.c \ microcontroller/Processor.c \ microcontroller/__init__.c \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 6b6f629e18..90bf0ce9e8 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -214,6 +214,9 @@ CFLAGS += -DCIRCUITPY_ERRNO=$(CIRCUITPY_ERRNO) CIRCUITPY_ESPIDF ?= 0 CFLAGS += -DCIRCUITPY_ESPIDF=$(CIRCUITPY_ESPIDF) +CIRCUITPY_ESP32_CAMERA ?= 0 +CFLAGS += -DCIRCUITPY_ESP32_CAMERA=$(CIRCUITPY_ESP32_CAMERA) + CIRCUITPY__EVE ?= 0 CFLAGS += -DCIRCUITPY__EVE=$(CIRCUITPY__EVE) @@ -242,8 +245,8 @@ CFLAGS += -DCIRCUITPY_GNSS=$(CIRCUITPY_GNSS) CIRCUITPY_HASHLIB ?= $(CIRCUITPY_WEB_WORKFLOW) CFLAGS += -DCIRCUITPY_HASHLIB=$(CIRCUITPY_HASHLIB) -CIRCUITPY_I2CPERIPHERAL ?= $(CIRCUITPY_FULL_BUILD) -CFLAGS += -DCIRCUITPY_I2CPERIPHERAL=$(CIRCUITPY_I2CPERIPHERAL) +CIRCUITPY_I2CTARGET ?= $(CIRCUITPY_FULL_BUILD) +CFLAGS += -DCIRCUITPY_I2CTARGET=$(CIRCUITPY_I2CTARGET) CIRCUITPY_IMAGECAPTURE ?= 0 CFLAGS += -DCIRCUITPY_IMAGECAPTURE=$(CIRCUITPY_IMAGECAPTURE) diff --git a/py/formatfloat.c b/py/formatfloat.c index 06775167c0..d75cfc6658 100644 --- a/py/formatfloat.c +++ b/py/formatfloat.c @@ -25,6 +25,7 @@ */ #include "py/mpconfig.h" +#include "py/misc.h" #if MICROPY_FLOAT_IMPL != MICROPY_FLOAT_IMPL_NONE #include @@ -96,7 +97,16 @@ static inline int fp_isless1(float x) { #define fp_iszero(x) (x == 0) #define fp_isless1(x) (x < 1.0) -#endif +#endif // MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT/DOUBLE + +static inline int fp_ge_eps(FPTYPE x, FPTYPE y) { + mp_float_union_t fb_y = {y}; + // Back off 2 eps. + // This is valid for almost all values, but in practice + // it's only used when y = 1eX for X>=0. + fb_y.i -= 2; + return x >= fb_y.f; +} static const FPTYPE g_pos_pow[] = { #if FPDECEXP > 32 @@ -173,6 +183,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch int num_digits = 0; const FPTYPE *pos_pow = g_pos_pow; const FPTYPE *neg_pow = g_neg_pow; + int signed_e = 0; if (fp_iszero(f)) { e = 0; @@ -192,31 +203,24 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch } } } else if (fp_isless1(f)) { - // We need to figure out what an integer digit will be used - // in case 'f' is used (or we revert other format to it below). - // As we just tested number to be <1, this is obviously 0, - // but we can round it up to 1 below. - char first_dig = '0'; - if (f >= FPROUND_TO_ONE) { - first_dig = '1'; - } - + FPTYPE f_mod = f; // Build negative exponent for (e = 0, e1 = FPDECEXP; e1; e1 >>= 1, pos_pow++, neg_pow++) { - if (*neg_pow > f) { + if (*neg_pow > f_mod) { e += e1; - f *= *pos_pow; + f_mod *= *pos_pow; } } + char e_sign_char = '-'; - if (fp_isless1(f) && f >= FPROUND_TO_ONE) { - f = FPCONST(1.0); + if (fp_isless1(f_mod) && f_mod >= FPROUND_TO_ONE) { + f_mod = FPCONST(1.0); if (e == 0) { e_sign_char = '+'; } - } else if (fp_isless1(f)) { + } else if (fp_isless1(f_mod)) { e++; - f *= FPCONST(10.0); + f_mod *= FPCONST(10.0); } // If the user specified 'g' format, and e is <= 4, then we'll switch @@ -224,8 +228,7 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch if (fmt == 'f' || (fmt == 'g' && e <= 4)) { fmt = 'f'; - dec = -1; - *s++ = first_dig; + dec = 0; if (org_fmt == 'g') { prec += (e - 1); @@ -237,13 +240,8 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch } num_digits = prec; - if (num_digits) { - *s++ = '.'; - while (--e && num_digits) { - *s++ = '0'; - num_digits--; - } - } + signed_e = 0; + ++num_digits; } else { // For e & g formats, we'll be printing the exponent, so set the // sign. @@ -256,22 +254,29 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch prec++; } } + signed_e = -e; } } else { - // Build positive exponent - for (e = 0, e1 = FPDECEXP; e1; e1 >>= 1, pos_pow++, neg_pow++) { - if (*pos_pow <= f) { + // Build positive exponent. + // We don't modify f at this point to avoid innaccuracies from + // scaling it. Instead, we find the product of powers of 10 + // that is not greater than it, and use that to start the + // mantissa. + FPTYPE u_base = FPCONST(1.0); + for (e = 0, e1 = FPDECEXP; e1; e1 >>= 1, pos_pow++) { + FPTYPE next_u = u_base * *pos_pow; + // fp_ge_eps performs "f >= (next_u - 2eps)" so that if, for + // numerical reasons, f is very close to a power of ten but + // not strictly equal, we still treat it as that power of 10. + // The comparison was failing for maybe 10% of 1eX values, but + // although rounding fixed many of them, there were still some + // rendering as 9.99999998e(X-1). + if (fp_ge_eps(f, next_u)) { + u_base = next_u; e += e1; - f *= *neg_pow; } } - // It can be that f was right on the edge of an entry in pos_pow needs to be reduced - if ((int)f >= 10) { - e += 1; - f *= FPCONST(0.1); - } - // If the user specified fixed format (fmt == 'f') and e makes the // number too big to fit into the available buffer, then we'll // switch to the 'e' format. @@ -310,15 +315,15 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch } else { e_sign = '+'; } + signed_e = e; } if (prec < 0) { // This can happen when the prec is trimmed to prevent buffer overflow prec = 0; } - // We now have num.f as a floating point number between >= 1 and < 10 - // (or equal to zero), and e contains the absolute value of the power of - // 10 exponent. and (dec + 1) == the number of dgits before the decimal. + // At this point e contains the absolute value of the power of 10 exponent. + // (dec + 1) == the number of dgits before the decimal. // For e, prec is # digits after the decimal // For f, prec is # digits after the decimal @@ -336,25 +341,63 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch num_digits = prec; } - // Print the digits of the mantissa - for (int i = 0; i < num_digits; ++i, --dec) { - int32_t d = (int32_t)f; - if (d < 0) { - *s++ = '0'; - } else { - *s++ = '0' + d; + if (signed_e < 0) { + // The algorithm below treats numbers smaller than 1 by scaling them + // repeatedly by 10 to bring the new digit to the top. Our input number + // was smaller than 1, so scale it up to be 1 <= f < 10. + FPTYPE u_base = FPCONST(1.0); + const FPTYPE *pow_u = g_pos_pow; + for (int m = FPDECEXP; m; m >>= 1, pow_u++) { + if (m & e) { + u_base *= *pow_u; + } } - if (dec == 0 && prec > 0) { - *s++ = '.'; - } - f -= (FPTYPE)d; - f *= FPCONST(10.0); + f *= u_base; } - // Round - // If we print non-exponential format (i.e. 'f'), but a digit we're going - // to round by (e) is too far away, then there's nothing to round. - if ((org_fmt != 'f' || e <= num_digits) && f >= FPCONST(5.0)) { + int d = 0; + int num_digits_left = num_digits; + for (int digit_index = signed_e; num_digits_left >= 0; --digit_index) { + FPTYPE u_base = FPCONST(1.0); + if (digit_index > 0) { + // Generate 10^digit_index for positive digit_index. + const FPTYPE *pow_u = g_pos_pow; + int target_index = digit_index; + for (int m = FPDECEXP; m; m >>= 1, pow_u++) { + if (m & target_index) { + u_base *= *pow_u; + } + } + } + for (d = 0; d < 9; ++d) { + // This is essentially "if (f < u_base)", but with 2eps margin + // so that if f is just a tiny bit smaller, we treat it as + // equal (and accept the additional digit value). + if (!fp_ge_eps(f, u_base)) { + break; + } + f -= u_base; + } + // We calculate one more digit than we display, to use in rounding + // below. So only emit the digit if it's one that we display. + if (num_digits_left > 0) { + // Emit this number (the leading digit). + *s++ = '0' + d; + if (dec == 0 && prec > 0) { + *s++ = '.'; + } + } + --dec; + --num_digits_left; + if (digit_index <= 0) { + // Once we get below 1.0, we scale up f instead of calculting + // negative powers of 10 in u_base. This provides better + // renditions of exact decimals like 1/16 etc. + f *= FPCONST(10.0); + } + } + // Rounding. If the next digit to print is >= 5, round up. + if (d >= 5) { char *rs = s; rs--; while (1) { @@ -394,7 +437,10 @@ int mp_format_float(FPTYPE f, char *buf, size_t buf_size, char fmt, int prec, ch } } else { // Need at extra digit at the end to make room for the leading '1' - s++; + // but if we're at the buffer size limit, just drop the final digit. + if ((size_t)(s + 1 - buf) < buf_size) { + s++; + } } char *ss = s; while (ss > rs) { diff --git a/requirements-doc.txt b/requirements-doc.txt index 2eaf513d3d..40ab2ad4ac 100644 --- a/requirements-doc.txt +++ b/requirements-doc.txt @@ -5,7 +5,7 @@ isort twine wheel astroid -setuptools +setuptools>=45 setuptools_scm # For sphinx diff --git a/shared-bindings/_bleio/ScanEntry.c b/shared-bindings/_bleio/ScanEntry.c index d9434f39cf..a5009088a5 100644 --- a/shared-bindings/_bleio/ScanEntry.c +++ b/shared-bindings/_bleio/ScanEntry.c @@ -48,25 +48,22 @@ //| def matches(self, prefixes: ScanEntry, *, match_all: bool = True) -> bool: //| """Returns True if the ScanEntry matches all prefixes when ``match_all`` is True. This is stricter //| than the scan filtering which accepts any advertisements that match any of the prefixes -//| where ``match_all`` is False. -//| -//| ``all`` also works for ``match_all`` but will be removed in CircuitPython 8.""" +//| where ``match_all`` is False.""" //| ... //| STATIC mp_obj_t bleio_scanentry_matches(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_prefixes, ARG_all, ARG_match_all }; + enum { ARG_prefixes, ARG_match_all }; static const mp_arg_t allowed_args[] = { { MP_QSTR_prefixes, MP_ARG_OBJ | MP_ARG_REQUIRED }, - { MP_QSTR_all, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, { MP_QSTR_match_all, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, }; 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); - bool match_all = args[ARG_all].u_bool && args[ARG_match_all].u_bool; + bool match_all = args[ARG_match_all].u_bool; mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[ARG_prefixes].u_obj, &bufinfo, MP_BUFFER_READ); diff --git a/shared-bindings/countio/Edge.h b/shared-bindings/countio/Edge.h index ca4cddbef3..86112fb4a3 100644 --- a/shared-bindings/countio/Edge.h +++ b/shared-bindings/countio/Edge.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2021 an Halbertfor Adafruit Industries + * Copyright (c) 2021 Dan Halbert for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h index 458047510a..074f7dfa5c 100644 --- a/shared-bindings/displayio/Bitmap.h +++ b/shared-bindings/displayio/Bitmap.h @@ -33,6 +33,8 @@ extern const mp_obj_type_t displayio_bitmap_type; void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t width, uint32_t height, uint32_t bits_per_value); +void common_hal_displayio_bitmap_construct_from_buffer(displayio_bitmap_t *self, uint32_t width, + uint32_t height, uint32_t bits_per_value, uint32_t *data, bool read_only); void common_hal_displayio_bitmap_load_row(displayio_bitmap_t *self, uint16_t y, uint8_t *data, uint16_t len); diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 070793415d..b01de20cf8 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -54,7 +54,7 @@ //| Most people should not use this class directly. Use a specific display driver instead that will //| contain the initialization sequence at minimum.""" //| -//| def __init__(self, display_bus: _DisplayBus, init_sequence: ReadableBuffer, *, width: int, height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, color_depth: int = 16, grayscale: bool = False, pixels_in_byte_share_row: bool = True, bytes_per_cell: int = 1, reverse_pixels_in_byte: bool = False, set_column_command: int = 0x2a, set_row_command: int = 0x2b, write_ram_command: int = 0x2c, backlight_pin: Optional[microcontroller.Pin] = None, brightness_command: Optional[int] = None, brightness: float = 1.0, auto_brightness: bool = False, single_byte_bounds: bool = False, data_as_commands: bool = False, auto_refresh: bool = True, native_frames_per_second: int = 60, backlight_on_high: bool = True, SH1107_addressing: bool = False) -> None: +//| def __init__(self, display_bus: _DisplayBus, init_sequence: ReadableBuffer, *, width: int, height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, color_depth: int = 16, grayscale: bool = False, pixels_in_byte_share_row: bool = True, bytes_per_cell: int = 1, reverse_pixels_in_byte: bool = False, set_column_command: int = 0x2a, set_row_command: int = 0x2b, write_ram_command: int = 0x2c, backlight_pin: Optional[microcontroller.Pin] = None, brightness_command: Optional[int] = None, brightness: float = 1.0, single_byte_bounds: bool = False, data_as_commands: bool = False, auto_refresh: bool = True, native_frames_per_second: int = 60, backlight_on_high: bool = True, SH1107_addressing: bool = False) -> None: //| r"""Create a Display object on the given display bus (`FourWire`, `ParallelBus` or `I2CDisplay`). //| //| The ``init_sequence`` is bitpacked to minimize the ram impact. Every command begins with a @@ -102,8 +102,7 @@ //| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set. //| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight //| :param int brightness_command: Command to set display brightness. Usually available in OLED controllers. -//| :param float brightness: Initial display brightness. This value is ignored if auto_brightness is True. -//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism. +//| :param float brightness: Initial display brightness. //| :param bool single_byte_bounds: Display column and row commands use single bytes //| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this. //| :param bool auto_refresh: Automatically refresh the screen @@ -122,7 +121,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, - ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, + ARG_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high, ARG_SH1107_addressing, ARG_backlight_pwm_frequency }; static const mp_arg_t allowed_args[] = { @@ -146,7 +145,6 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, { MP_QSTR_brightness_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = NO_BRIGHTNESS_COMMAND} }, { MP_QSTR_brightness, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(1)} }, - { MP_QSTR_auto_brightness, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_data_as_commands, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, @@ -196,7 +194,6 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a MP_OBJ_TO_PTR(backlight_pin), args[ARG_brightness_command].u_int, brightness, - args[ARG_auto_brightness].u_bool, args[ARG_single_byte_bounds].u_bool, args[ARG_data_as_commands].u_bool, args[ARG_auto_refresh].u_bool, @@ -311,9 +308,7 @@ MP_PROPERTY_GETSET(displayio_display_auto_refresh_obj, (mp_obj_t)&displayio_display_set_auto_refresh_obj); //| brightness: float -//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When -//| `auto_brightness` is True, the value of `brightness` will change automatically. -//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False.""" +//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness.""" //| STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) { displayio_display_obj_t *self = native_display(self_in); @@ -327,7 +322,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_brightness_obj, displayio_displa STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness_obj) { displayio_display_obj_t *self = native_display(self_in); - common_hal_displayio_display_set_auto_brightness(self, false); mp_float_t brightness = mp_obj_get_float(brightness_obj); if (brightness < 0 || brightness > 1.0) { mp_raise_ValueError(translate("Brightness must be 0-1.0")); @@ -344,34 +338,6 @@ MP_PROPERTY_GETSET(displayio_display_brightness_obj, (mp_obj_t)&displayio_display_get_brightness_obj, (mp_obj_t)&displayio_display_set_brightness_obj); -//| auto_brightness: bool -//| """True when the display brightness is adjusted automatically, based on an ambient -//| light sensor or other method. Note that some displays may have this set to True by default, -//| but not actually implement automatic brightness adjustment. `auto_brightness` is set to False -//| if `brightness` is set manually.""" -//| -STATIC mp_obj_t displayio_display_obj_get_auto_brightness(mp_obj_t self_in) { - displayio_display_obj_t *self = native_display(self_in); - return mp_obj_new_bool(common_hal_displayio_display_get_auto_brightness(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_auto_brightness_obj, displayio_display_obj_get_auto_brightness); - -STATIC mp_obj_t displayio_display_obj_set_auto_brightness(mp_obj_t self_in, mp_obj_t auto_brightness) { - displayio_display_obj_t *self = native_display(self_in); - - common_hal_displayio_display_set_auto_brightness(self, mp_obj_is_true(auto_brightness)); - - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_set_auto_brightness_obj, displayio_display_obj_set_auto_brightness); - -MP_PROPERTY_GETSET(displayio_display_auto_brightness_obj, - (mp_obj_t)&displayio_display_get_auto_brightness_obj, - (mp_obj_t)&displayio_display_set_auto_brightness_obj); - - - - //| width: int //| """Gets the width of the board""" //| @@ -509,7 +475,6 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_auto_refresh), MP_ROM_PTR(&displayio_display_auto_refresh_obj) }, { MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&displayio_display_brightness_obj) }, - { MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&displayio_display_auto_brightness_obj) }, { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_display_width_obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_display_height_obj) }, diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index adc8623a69..35ba0d479a 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -42,7 +42,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t *init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t *backlight_pin, uint16_t brightness_command, - mp_float_t brightness, bool auto_brightness, + mp_float_t brightness, bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high, bool SH1107_addressing, uint16_t backlight_pwm_frequency); @@ -59,9 +59,6 @@ uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t *self); uint16_t common_hal_displayio_display_get_rotation(displayio_display_obj_t *self); void common_hal_displayio_display_set_rotation(displayio_display_obj_t *self, int rotation); -bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t *self); -void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t *self, bool auto_brightness); - bool common_hal_displayio_display_get_dither(displayio_display_obj_t *self); void common_hal_displayio_display_set_dither(displayio_display_obj_t *self, bool dither); diff --git a/shared-bindings/displayio/OnDiskBitmap.c b/shared-bindings/displayio/OnDiskBitmap.c index 02c370c3c4..f71c3cfe82 100644 --- a/shared-bindings/displayio/OnDiskBitmap.c +++ b/shared-bindings/displayio/OnDiskBitmap.c @@ -48,7 +48,6 @@ //| import time //| import pulseio //| -//| board.DISPLAY.auto_brightness = False //| board.DISPLAY.brightness = 0 //| splash = displayio.Group() //| board.DISPLAY.show(splash) diff --git a/shared-bindings/floppyio/__init__.c b/shared-bindings/floppyio/__init__.c index 3ef58b2f66..a6b041c4a0 100644 --- a/shared-bindings/floppyio/__init__.c +++ b/shared-bindings/floppyio/__init__.c @@ -31,7 +31,6 @@ #include #include "py/binary.h" -#include "py/enum.h" #include "py/obj.h" #include "py/runtime.h" diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index e999ac9bc1..00adef62a6 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -173,9 +173,7 @@ MP_PROPERTY_GETSET(framebufferio_framebufferdisplay_auto_refresh_obj, (mp_obj_t)&framebufferio_framebufferdisplay_set_auto_refresh_obj); //| brightness: float -//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When -//| `auto_brightness` is True, the value of `brightness` will change automatically. -//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False.""" +//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness.""" //| STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_brightness(mp_obj_t self_in) { framebufferio_framebufferdisplay_obj_t *self = native_display(self_in); @@ -189,7 +187,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_brightness_obj, f STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness_obj) { framebufferio_framebufferdisplay_obj_t *self = native_display(self_in); - common_hal_framebufferio_framebufferdisplay_set_auto_brightness(self, false); mp_float_t brightness = mp_obj_get_float(brightness_obj); if (brightness < 0.0f || brightness > 1.0f) { mp_raise_ValueError(translate("Brightness must be 0-1.0")); @@ -206,34 +203,6 @@ MP_PROPERTY_GETSET(framebufferio_framebufferdisplay_brightness_obj, (mp_obj_t)&framebufferio_framebufferdisplay_get_brightness_obj, (mp_obj_t)&framebufferio_framebufferdisplay_set_brightness_obj); -//| auto_brightness: bool -//| """True when the display brightness is adjusted automatically, based on an ambient -//| light sensor or other method. Note that some displays may have this set to True by default, -//| but not actually implement automatic brightness adjustment. `auto_brightness` is set to False -//| if `brightness` is set manually.""" -//| -STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_auto_brightness(mp_obj_t self_in) { - framebufferio_framebufferdisplay_obj_t *self = native_display(self_in); - return mp_obj_new_bool(common_hal_framebufferio_framebufferdisplay_get_auto_brightness(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(framebufferio_framebufferdisplay_get_auto_brightness_obj, framebufferio_framebufferdisplay_obj_get_auto_brightness); - -STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_auto_brightness(mp_obj_t self_in, mp_obj_t auto_brightness) { - framebufferio_framebufferdisplay_obj_t *self = native_display(self_in); - - bool ok = common_hal_framebufferio_framebufferdisplay_set_auto_brightness(self, mp_obj_is_true(auto_brightness)); - if (!ok) { - mp_raise_RuntimeError(translate("Brightness not adjustable")); - } - - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_set_auto_brightness_obj, framebufferio_framebufferdisplay_obj_set_auto_brightness); - -MP_PROPERTY_GETSET(framebufferio_framebufferdisplay_auto_brightness_obj, - (mp_obj_t)&framebufferio_framebufferdisplay_get_auto_brightness_obj, - (mp_obj_t)&framebufferio_framebufferdisplay_set_auto_brightness_obj); - //| width: int //| """Gets the width of the framebuffer""" //| @@ -374,7 +343,6 @@ STATIC const mp_rom_map_elem_t framebufferio_framebufferdisplay_locals_dict_tabl { MP_ROM_QSTR(MP_QSTR_auto_refresh), MP_ROM_PTR(&framebufferio_framebufferdisplay_auto_refresh_obj) }, { MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&framebufferio_framebufferdisplay_brightness_obj) }, - { MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&framebufferio_framebufferdisplay_auto_brightness_obj) }, { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&framebufferio_framebufferdisplay_width_obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&framebufferio_framebufferdisplay_height_obj) }, diff --git a/shared-bindings/framebufferio/FramebufferDisplay.h b/shared-bindings/framebufferio/FramebufferDisplay.h index 8b262cf727..7c63587df7 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.h +++ b/shared-bindings/framebufferio/FramebufferDisplay.h @@ -55,9 +55,6 @@ uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_fr uint16_t common_hal_framebufferio_framebufferdisplay_get_rotation(framebufferio_framebufferdisplay_obj_t *self); void common_hal_framebufferio_framebufferdisplay_set_rotation(framebufferio_framebufferdisplay_obj_t *self, int rotation); -bool common_hal_framebufferio_framebufferdisplay_get_auto_brightness(framebufferio_framebufferdisplay_obj_t *self); -bool common_hal_framebufferio_framebufferdisplay_set_auto_brightness(framebufferio_framebufferdisplay_obj_t *self, bool auto_brightness); - mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness(framebufferio_framebufferdisplay_obj_t *self); bool common_hal_framebufferio_framebufferdisplay_set_brightness(framebufferio_framebufferdisplay_obj_t *self, mp_float_t brightness); diff --git a/shared-bindings/i2cperipheral/I2CPeripheral.c b/shared-bindings/i2ctarget/I2CTarget.c similarity index 51% rename from shared-bindings/i2cperipheral/I2CPeripheral.c rename to shared-bindings/i2ctarget/I2CTarget.c index b63e8a891b..1680585ba5 100644 --- a/shared-bindings/i2cperipheral/I2CPeripheral.c +++ b/shared-bindings/i2ctarget/I2CTarget.c @@ -25,7 +25,7 @@ */ #include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/i2cperipheral/I2CPeripheral.h" +#include "shared-bindings/i2ctarget/I2CTarget.h" #include "shared-bindings/time/__init__.h" #include "shared-bindings/util.h" @@ -39,33 +39,33 @@ #include "py/objproperty.h" #include "py/runtime.h" -STATIC mp_obj_t mp_obj_new_i2cperipheral_i2c_peripheral_request(i2cperipheral_i2c_peripheral_obj_t *peripheral, uint8_t address, bool is_read, bool is_restart) { - i2cperipheral_i2c_peripheral_request_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_request_obj_t); - self->base.type = &i2cperipheral_i2c_peripheral_request_type; - self->peripheral = peripheral; +STATIC mp_obj_t mp_obj_new_i2ctarget_i2c_target_request(i2ctarget_i2c_target_obj_t *target, uint8_t address, bool is_read, bool is_restart) { + i2ctarget_i2c_target_request_obj_t *self = m_new_obj(i2ctarget_i2c_target_request_obj_t); + self->base.type = &i2ctarget_i2c_target_request_type; + self->target = target; self->address = address; self->is_read = is_read; self->is_restart = is_restart; return (mp_obj_t)self; } -//| class I2CPeripheral: -//| """Two wire serial protocol peripheral""" +//| class I2CTarget: +//| """Two wire serial protocol target""" //| //| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, addresses: Sequence[int], smbus: bool = False) -> None: //| """I2C is a two-wire protocol for communicating between devices. -//| This implements the peripheral (sensor, secondary) side. +//| This implements the target (peripheral, sensor, secondary) side. //| //| :param ~microcontroller.Pin scl: The clock pin //| :param ~microcontroller.Pin sda: The data pin -//| :param addresses: The I2C addresses to respond to (how many is hw dependent). +//| :param addresses: The I2C addresses to respond to (how many is hardware dependent). //| :type addresses: list[int] //| :param bool smbus: Use SMBUS timings if the hardware supports it""" //| ... //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - i2cperipheral_i2c_peripheral_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_obj_t); - self->base.type = &i2cperipheral_i2c_peripheral_type; +STATIC mp_obj_t i2ctarget_i2c_target_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + i2ctarget_i2c_target_obj_t *self = m_new_obj(i2ctarget_i2c_target_obj_t); + self->base.type = &i2ctarget_i2c_target_type; enum { ARG_scl, ARG_sda, ARG_addresses, ARG_smbus }; static const mp_arg_t allowed_args[] = { { MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -99,7 +99,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, mp_raise_ValueError(translate("addresses is empty")); } - common_hal_i2cperipheral_i2c_peripheral_construct(self, scl, sda, addresses, i, args[ARG_smbus].u_bool); + common_hal_i2ctarget_i2c_target_construct(self, scl, sda, addresses, i, args[ARG_smbus].u_bool); return (mp_obj_t)self; } @@ -107,15 +107,15 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, //| """Releases control of the underlying hardware so other classes can use it.""" //| ... //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj_deinit(mp_obj_t self_in) { - mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_type)); - i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_i2cperipheral_i2c_peripheral_deinit(self); +STATIC mp_obj_t i2ctarget_i2c_target_obj_deinit(mp_obj_t self_in) { + mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_type)); + i2ctarget_i2c_target_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_i2ctarget_i2c_target_deinit(self); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_deinit_obj, i2cperipheral_i2c_peripheral_obj_deinit); +MP_DEFINE_CONST_FUN_OBJ_1(i2ctarget_i2c_target_deinit_obj, i2ctarget_i2c_target_obj_deinit); -//| def __enter__(self) -> I2CPeripheral: +//| def __enter__(self) -> I2CTarget: //| """No-op used in Context Managers.""" //| ... //| @@ -126,25 +126,25 @@ MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_deinit_obj, i2cperipheral //| :ref:`lifetime-and-contextmanagers` for more info.""" //| ... //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj___exit__(size_t n_args, const mp_obj_t *args) { - mp_check_self(mp_obj_is_type(args[0], &i2cperipheral_i2c_peripheral_type)); - i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(args[0]); - common_hal_i2cperipheral_i2c_peripheral_deinit(self); +STATIC mp_obj_t i2ctarget_i2c_target_obj___exit__(size_t n_args, const mp_obj_t *args) { + mp_check_self(mp_obj_is_type(args[0], &i2ctarget_i2c_target_type)); + i2ctarget_i2c_target_obj_t *self = MP_OBJ_TO_PTR(args[0]); + common_hal_i2ctarget_i2c_target_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_obj___exit__); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2ctarget_i2c_target___exit___obj, 4, 4, i2ctarget_i2c_target_obj___exit__); -//| def request(self, timeout: float = -1) -> I2CPeripheralRequest: +//| def request(self, timeout: float = -1) -> I2CTargetRequest: //| """Wait for an I2C request. //| //| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once -//| :return: I2C Slave Request or None if timeout=-1 and there's no request -//| :rtype: ~i2cperipheral.I2CPeripheralRequest""" +//| :return: I2CTargetRequest or None if timeout=-1 and there's no request +//| :rtype: ~i2ctarget.I2CTargetRequest""" //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_check_self(mp_obj_is_type(pos_args[0], &i2cperipheral_i2c_peripheral_type)); - i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - if (common_hal_i2cperipheral_i2c_peripheral_deinited(self)) { +STATIC mp_obj_t i2ctarget_i2c_target_request(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_check_self(mp_obj_is_type(pos_args[0], &i2ctarget_i2c_target_type)); + i2ctarget_i2c_target_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + if (common_hal_i2ctarget_i2c_target_deinited(self)) { raise_deinited_error(); } enum { ARG_timeout }; @@ -181,7 +181,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj return mp_const_none; } - int status = common_hal_i2cperipheral_i2c_peripheral_is_addressed(self, &address, &is_read, &is_restart); + int status = common_hal_i2ctarget_i2c_target_is_addressed(self, &address, &is_read, &is_restart); if (status < 0) { // On error try one more time before bailing out if (last_error) { @@ -199,7 +199,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj continue; } - return mp_obj_new_i2cperipheral_i2c_peripheral_request(self, address, is_read, is_restart); + return mp_obj_new_i2ctarget_i2c_target_request(self, address, is_read, is_restart); } while (forever || common_hal_time_monotonic_ms() < timeout_end); if (timeout_ms > 0) { @@ -207,42 +207,42 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_obj, 1, i2cperipheral_i2c_peripheral_request); +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(i2ctarget_i2c_target_request_obj, 1, i2ctarget_i2c_target_request); -STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_deinit_obj) }, +STATIC const mp_rom_map_elem_t i2ctarget_i2c_target_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&i2ctarget_i2c_target_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral___exit___obj) }, - { MP_ROM_QSTR(MP_QSTR_request), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2ctarget_i2c_target___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_request), MP_ROM_PTR(&i2ctarget_i2c_target_request_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_locals_dict, i2cperipheral_i2c_peripheral_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(i2ctarget_i2c_target_locals_dict, i2ctarget_i2c_target_locals_dict_table); -const mp_obj_type_t i2cperipheral_i2c_peripheral_type = { +const mp_obj_type_t i2ctarget_i2c_target_type = { { &mp_type_type }, - .name = MP_QSTR_I2CPeripheral, - .make_new = i2cperipheral_i2c_peripheral_make_new, - .locals_dict = (mp_obj_dict_t *)&i2cperipheral_i2c_peripheral_locals_dict, + .name = MP_QSTR_I2CTarget, + .make_new = i2ctarget_i2c_target_make_new, + .locals_dict = (mp_obj_dict_t *)&i2ctarget_i2c_target_locals_dict, }; -//| class I2CPeripheralRequest: +//| class I2CTargetRequest: //| -//| def __init__(self, peripheral: i2cperipheral.I2CPeripheral, address: int, is_read: bool, is_restart: bool) -> None: +//| def __init__(self, target: i2ctarget.I2CTarget, address: int, is_read: bool, is_restart: bool) -> None: //| """Information about an I2C transfer request -//| This cannot be instantiated directly, but is returned by :py:meth:`I2CPeripheral.request`. +//| This cannot be instantiated directly, but is returned by :py:meth:`I2CTarget.request`. //| -//| :param peripheral: The I2CPeripheral object receiving this request +//| :param target: The I2CTarget object receiving this request //| :param address: I2C address -//| :param is_read: True if the main peripheral is requesting data +//| :param is_read: True if the main target is requesting data //| :param is_restart: Repeated Start Condition""" //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_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 i2ctarget_i2c_target_request_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 4, 4, false); - return mp_obj_new_i2cperipheral_i2c_peripheral_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3])); + return mp_obj_new_i2ctarget_i2c_target_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3])); } -//| def __enter__(self) -> I2CPeripheralRequest: +//| def __enter__(self) -> I2CTargetRequest: //| """No-op used in Context Managers.""" //| ... //| @@ -252,56 +252,56 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_make_new(const mp_obj_type_ //| """Close the request.""" //| ... //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_obj___exit__(size_t n_args, const mp_obj_t *args) { - mp_check_self(mp_obj_is_type(args[0], &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); - common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral); +STATIC mp_obj_t i2ctarget_i2c_target_request_obj___exit__(size_t n_args, const mp_obj_t *args) { + mp_check_self(mp_obj_is_type(args[0], &i2ctarget_i2c_target_request_type)); + i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); + common_hal_i2ctarget_i2c_target_close(self->target); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_request_obj___exit__); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2ctarget_i2c_target_request___exit___obj, 4, 4, i2ctarget_i2c_target_request_obj___exit__); //| address: int //| """The I2C address of the request.""" //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_address(mp_obj_t self_in) { - mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t i2ctarget_i2c_target_request_get_address(mp_obj_t self_in) { + mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type)); + i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int(self->address); } -MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_address_obj, i2cperipheral_i2c_peripheral_request_get_address); +MP_DEFINE_CONST_PROP_GET(i2ctarget_i2c_target_request_address_obj, i2ctarget_i2c_target_request_get_address); //| is_read: bool -//| """The I2C main controller is reading from this peripheral.""" +//| """The I2C main controller is reading from this target.""" //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_read(mp_obj_t self_in) { - mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t i2ctarget_i2c_target_request_get_is_read(mp_obj_t self_in) { + mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type)); + i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(self->is_read); } -MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_read_obj, i2cperipheral_i2c_peripheral_request_get_is_read); +MP_DEFINE_CONST_PROP_GET(i2ctarget_i2c_target_request_is_read_obj, i2ctarget_i2c_target_request_get_is_read); //| is_restart: bool //| """Is Repeated Start Condition.""" //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_restart(mp_obj_t self_in) { - mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t i2ctarget_i2c_target_request_get_is_restart(mp_obj_t self_in) { + mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type)); + i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(self->is_restart); } -MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_restart_obj, i2cperipheral_i2c_peripheral_request_get_is_restart); +MP_DEFINE_CONST_PROP_GET(i2ctarget_i2c_target_request_is_restart_obj, i2ctarget_i2c_target_request_get_is_restart); //| def read(self, n: int = -1, ack: bool = True) -> bytearray: //| """Read data. -//| If ack=False, the caller is responsible for calling :py:meth:`I2CPeripheralRequest.ack`. +//| If ack=False, the caller is responsible for calling :py:meth:`I2CTargetRequest.ack`. //| //| :param n: Number of bytes to read (negative means all) //| :param ack: Whether or not to send an ACK after the n'th byte //| :return: Bytes read""" //| ... //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_check_self(mp_obj_is_type(pos_args[0], &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); +STATIC mp_obj_t i2ctarget_i2c_target_request_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_check_self(mp_obj_is_type(pos_args[0], &i2ctarget_i2c_target_request_type)); + i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); enum { ARG_n, ARG_ack }; static const mp_arg_t allowed_args[] = { { MP_QSTR_n, MP_ARG_INT, {.u_int = -1} }, @@ -330,7 +330,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_read(size_t n_args, const m } uint8_t data; - int num = common_hal_i2cperipheral_i2c_peripheral_read_byte(self->peripheral, &data); + int num = common_hal_i2ctarget_i2c_target_read_byte(self->target, &data); if (num == 0) { break; } @@ -339,16 +339,16 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_read(size_t n_args, const m buffer[i++] = data; if (i == n) { if (ack) { - common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true); + common_hal_i2ctarget_i2c_target_ack(self->target, true); } break; } - common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true); + common_hal_i2ctarget_i2c_target_ack(self->target, true); } return mp_obj_new_bytearray(i, buffer); } -MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_read_obj, 1, i2cperipheral_i2c_peripheral_request_read); +MP_DEFINE_CONST_FUN_OBJ_KW(i2ctarget_i2c_target_request_read_obj, 1, i2ctarget_i2c_target_request_read); //| def write(self, buffer: ReadableBuffer) -> int: //| """Write the data contained in buffer. @@ -357,9 +357,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_read_obj, 1, i2c //| :return: Number of bytes written""" //| ... //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_write(mp_obj_t self_in, mp_obj_t buf_in) { - mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t i2ctarget_i2c_target_request_write(mp_obj_t self_in, mp_obj_t buf_in) { + mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type)); + i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in); if (!self->is_read) { mp_raise_OSError(MP_EACCES); @@ -374,7 +374,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_write(mp_obj_t self_in, mp_ break; } - int num = common_hal_i2cperipheral_i2c_peripheral_write_byte(self->peripheral, ((uint8_t *)(bufinfo.buf))[i]); + int num = common_hal_i2ctarget_i2c_target_write_byte(self->target, ((uint8_t *)(bufinfo.buf))[i]); if (num == 0) { return mp_obj_new_int(i); } @@ -382,55 +382,55 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_write(mp_obj_t self_in, mp_ return mp_obj_new_int(bufinfo.len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2cperipheral_i2c_peripheral_request_write_obj, i2cperipheral_i2c_peripheral_request_write); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2ctarget_i2c_target_request_write_obj, i2ctarget_i2c_target_request_write); //| def ack(self, ack: bool = True) -> None: //| """Acknowledge or Not Acknowledge last byte received. -//| Use together with :py:meth:`I2CPeripheralRequest.read` ack=False. +//| Use together with :py:meth:`I2CTargetRequest.read` ack=False. //| //| :param ack: Whether to send an ACK or NACK""" //| ... //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_ack(uint n_args, const mp_obj_t *args) { - mp_check_self(mp_obj_is_type(args[0], &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); +STATIC mp_obj_t i2ctarget_i2c_target_request_ack(uint n_args, const mp_obj_t *args) { + mp_check_self(mp_obj_is_type(args[0], &i2ctarget_i2c_target_request_type)); + i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); bool ack = (n_args == 1) ? true : mp_obj_is_true(args[1]); if (self->is_read) { mp_raise_OSError(MP_EACCES); } - common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, ack); + common_hal_i2ctarget_i2c_target_ack(self->target, ack); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request_ack_obj, 1, 2, i2cperipheral_i2c_peripheral_request_ack); +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2ctarget_i2c_target_request_ack_obj, 1, 2, i2ctarget_i2c_target_request_ack); -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_close(mp_obj_t self_in) { - mp_check_self(mp_obj_is_type(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t i2ctarget_i2c_target_request_close(mp_obj_t self_in) { + mp_check_self(mp_obj_is_type(self_in, &i2ctarget_i2c_target_request_type)); + i2ctarget_i2c_target_request_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral); + common_hal_i2ctarget_i2c_target_close(self->target); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_request_close_obj, i2cperipheral_i2c_peripheral_request_close); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(i2ctarget_i2c_target_request_close_obj, i2ctarget_i2c_target_request_close); -STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_request_locals_dict_table[] = { +STATIC const mp_rom_map_elem_t i2ctarget_i2c_target_request_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request___exit___obj) }, - { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_address_obj) }, - { MP_ROM_QSTR(MP_QSTR_is_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_read_obj) }, - { MP_ROM_QSTR(MP_QSTR_is_restart), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_restart_obj) }, - { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_read_obj) }, - { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_write_obj) }, - { MP_ROM_QSTR(MP_QSTR_ack), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_ack_obj) }, - { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_close_obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2ctarget_i2c_target_request___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&i2ctarget_i2c_target_request_address_obj) }, + { MP_ROM_QSTR(MP_QSTR_is_read), MP_ROM_PTR(&i2ctarget_i2c_target_request_is_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_is_restart), MP_ROM_PTR(&i2ctarget_i2c_target_request_is_restart_obj) }, + { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&i2ctarget_i2c_target_request_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&i2ctarget_i2c_target_request_write_obj) }, + { MP_ROM_QSTR(MP_QSTR_ack), MP_ROM_PTR(&i2ctarget_i2c_target_request_ack_obj) }, + { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&i2ctarget_i2c_target_request_close_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_request_locals_dict, i2cperipheral_i2c_peripheral_request_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(i2ctarget_i2c_target_request_locals_dict, i2ctarget_i2c_target_request_locals_dict_table); -const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type = { +const mp_obj_type_t i2ctarget_i2c_target_request_type = { { &mp_type_type }, - .name = MP_QSTR_I2CPeripheralRequest, - .make_new = i2cperipheral_i2c_peripheral_request_make_new, - .locals_dict = (mp_obj_dict_t *)&i2cperipheral_i2c_peripheral_request_locals_dict, + .name = MP_QSTR_I2CTargetRequest, + .make_new = i2ctarget_i2c_target_request_make_new, + .locals_dict = (mp_obj_dict_t *)&i2ctarget_i2c_target_request_locals_dict, }; diff --git a/shared-bindings/i2cperipheral/I2CPeripheral.h b/shared-bindings/i2ctarget/I2CTarget.h similarity index 54% rename from shared-bindings/i2cperipheral/I2CPeripheral.h rename to shared-bindings/i2ctarget/I2CTarget.h index d3db1b96c9..e9c9714dee 100644 --- a/shared-bindings/i2cperipheral/I2CPeripheral.h +++ b/shared-bindings/i2ctarget/I2CTarget.h @@ -24,37 +24,37 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_TARGET_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_TARGET_H #include "py/obj.h" #include "common-hal/microcontroller/Pin.h" -#include "common-hal/i2cperipheral/I2CPeripheral.h" +#include "common-hal/i2ctarget/I2CTarget.h" typedef struct { mp_obj_base_t base; - i2cperipheral_i2c_peripheral_obj_t *peripheral; + i2ctarget_i2c_target_obj_t *target; uint16_t address; bool is_read; bool is_restart; -} i2cperipheral_i2c_peripheral_request_obj_t; +} i2ctarget_i2c_target_request_obj_t; -extern const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type; +extern const mp_obj_type_t i2ctarget_i2c_target_request_type; -extern const mp_obj_type_t i2cperipheral_i2c_peripheral_type; +extern const mp_obj_type_t i2ctarget_i2c_target_type; -extern void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_obj_t *self, +extern void common_hal_i2ctarget_i2c_target_construct(i2ctarget_i2c_target_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint8_t *addresses, unsigned int num_addresses, bool smbus); -extern void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self); -extern bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self); +extern void common_hal_i2ctarget_i2c_target_deinit(i2ctarget_i2c_target_obj_t *self); +extern bool common_hal_i2ctarget_i2c_target_deinited(i2ctarget_i2c_target_obj_t *self); -extern int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, +extern int common_hal_i2ctarget_i2c_target_is_addressed(i2ctarget_i2c_target_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart); -extern int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *data); -extern int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t data); -extern void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_obj_t *self, bool ack); -extern void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_obj_t *self); +extern int common_hal_i2ctarget_i2c_target_read_byte(i2ctarget_i2c_target_obj_t *self, uint8_t *data); +extern int common_hal_i2ctarget_i2c_target_write_byte(i2ctarget_i2c_target_obj_t *self, uint8_t data); +extern void common_hal_i2ctarget_i2c_target_ack(i2ctarget_i2c_target_obj_t *self, bool ack); +extern void common_hal_i2ctarget_i2c_target_close(i2ctarget_i2c_target_obj_t *self); -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_TARGET_H diff --git a/shared-bindings/i2cperipheral/__init__.c b/shared-bindings/i2ctarget/__init__.c similarity index 73% rename from shared-bindings/i2cperipheral/__init__.c rename to shared-bindings/i2ctarget/__init__.c index fde7002daf..70c4707597 100644 --- a/shared-bindings/i2cperipheral/__init__.c +++ b/shared-bindings/i2ctarget/__init__.c @@ -30,24 +30,24 @@ #include "py/runtime.h" #include "shared-bindings/microcontroller/Pin.h" -// #include "shared-bindings/i2cperipheral/__init__.h" -#include "shared-bindings/i2cperipheral/I2CPeripheral.h" +// #include "shared-bindings/i2ctarget/__init__.h" +#include "shared-bindings/i2ctarget/I2CTarget.h" #include "py/runtime.h" -//| """Two wire serial protocol peripheral +//| """Two wire serial protocol target //| -//| The `i2cperipheral` module contains classes to support an I2C peripheral. +//| The `i2ctarget` module contains classes to support an I2C target. //| -//| Example emulating a peripheral with 2 addresses (read and write):: +//| Example emulating a target with 2 addresses (read and write):: //| //| import board -//| from i2cperipheral import I2CPeripheral +//| from i2ctarget import I2CTarget //| //| regs = [0] * 16 //| index = 0 //| -//| with I2CPeripheral(board.SCL, board.SDA, (0x40, 0x41)) as device: +//| with I2CTarget(board.SCL, board.SDA, (0x40, 0x41)) as device: //| while True: //| r = device.request() //| if not r: @@ -84,7 +84,7 @@ //| 0xaa //| //| .. warning:: -//| I2CPeripheral makes use of clock stretching in order to slow down +//| I2CTarget makes use of clock stretching in order to slow down //| the host. //| Make sure the I2C host supports this. //| @@ -93,16 +93,21 @@ //| Since the RPi firmware uses the hw i2c, it's not possible to emulate a HAT eeprom.""" //| -STATIC const mp_rom_map_elem_t i2cperipheral_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_i2cperipheral) }, - { MP_ROM_QSTR(MP_QSTR_I2CPeripheral), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_type) }, +STATIC const mp_rom_map_elem_t i2ctarget_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_i2ctarget) }, + { MP_ROM_QSTR(MP_QSTR_I2CTarget), MP_ROM_PTR(&i2ctarget_i2c_target_type) }, + // TODO: Remove for CircuitPython 9.0.0 + { MP_ROM_QSTR(MP_QSTR_I2CPeripheral), MP_ROM_PTR(&i2ctarget_i2c_target_type) }, }; -STATIC MP_DEFINE_CONST_DICT(i2cperipheral_module_globals, i2cperipheral_module_globals_table); +STATIC MP_DEFINE_CONST_DICT(i2ctarget_module_globals, i2ctarget_module_globals_table); -const mp_obj_module_t i2cperipheral_module = { +const mp_obj_module_t i2ctarget_module = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&i2cperipheral_module_globals, + .globals = (mp_obj_dict_t *)&i2ctarget_module_globals, }; -MP_REGISTER_MODULE(MP_QSTR_i2cperipheral, i2cperipheral_module, CIRCUITPY_I2CPERIPHERAL); +MP_REGISTER_MODULE(MP_QSTR_i2ctarget, i2ctarget_module, CIRCUITPY_I2CTARGET); + +// TODO: Remove for CircuitPython 9.0.0 +MP_REGISTER_MODULE(MP_QSTR_i2cperipheral, i2ctarget_module, CIRCUITPY_I2CTARGET); diff --git a/shared-bindings/imagecapture/ParallelImageCapture.c b/shared-bindings/imagecapture/ParallelImageCapture.c index 7f90f0923b..bbe96026bf 100644 --- a/shared-bindings/imagecapture/ParallelImageCapture.c +++ b/shared-bindings/imagecapture/ParallelImageCapture.c @@ -47,6 +47,8 @@ //| ) -> None: //| """Create a parallel image capture object //| +//| This object is usually used with a camera-specific wrapper library such as `adafruit_ov5640 `_. +//| //| :param List[microcontroller.Pin] data_pins: The data pins. //| :param microcontroller.Pin clock: The pixel clock input. //| :param microcontroller.Pin vsync: The vertical sync input, which has a negative-going pulse at the beginning of each frame. diff --git a/shared-bindings/imagecapture/__init__.c b/shared-bindings/imagecapture/__init__.c index 0e5092aee8..fdd4424114 100644 --- a/shared-bindings/imagecapture/__init__.c +++ b/shared-bindings/imagecapture/__init__.c @@ -31,9 +31,13 @@ #include "shared-bindings/imagecapture/ParallelImageCapture.h" -//| """Support for "Parallel capture" interfaces""" +//| """Support for "Parallel capture" interfaces //| - +//| .. seealso:: +//| +//| Espressif microcontrollers use the `esp32_camera` module together. +//| +//| """ STATIC const mp_rom_map_elem_t imagecapture_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_imagecapture) }, { MP_ROM_QSTR(MP_QSTR_ParallelImageCapture), MP_ROM_PTR(&imagecapture_parallelimagecapture_type) }, diff --git a/shared-bindings/keypad/EventQueue.c b/shared-bindings/keypad/EventQueue.c index 8e45f7ad1d..ed182033dc 100644 --- a/shared-bindings/keypad/EventQueue.c +++ b/shared-bindings/keypad/EventQueue.c @@ -24,8 +24,11 @@ * THE SOFTWARE. */ +#include "py/ioctl.h" +#include "py/mperrno.h" #include "py/objproperty.h" #include "py/runtime.h" +#include "py/stream.h" #include "shared-bindings/keypad/Event.h" #include "shared-bindings/keypad/EventQueue.h" @@ -141,12 +144,41 @@ STATIC const mp_rom_map_elem_t keypad_eventqueue_locals_dict_table[] = { STATIC MP_DEFINE_CONST_DICT(keypad_eventqueue_locals_dict, keypad_eventqueue_locals_dict_table); +#if MICROPY_PY_USELECT +STATIC mp_uint_t eventqueue_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { + (void)errcode; + keypad_eventqueue_obj_t *self = MP_OBJ_TO_PTR(self_in); + switch (request) { + case MP_STREAM_POLL: { + mp_uint_t flags = arg; + mp_uint_t ret = 0; + if ((flags & MP_IOCTL_POLL_RD) && common_hal_keypad_eventqueue_get_length(self)) { + ret |= MP_IOCTL_POLL_RD; + } + return ret; + } + default: + *errcode = MP_EINVAL; + return MP_STREAM_ERROR; + } +} + +STATIC const mp_stream_p_t eventqueue_p = { + MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream) + .ioctl = eventqueue_ioctl, +}; +#endif + + const mp_obj_type_t keypad_eventqueue_type = { { &mp_type_type }, .flags = MP_TYPE_FLAG_EXTENDED, .name = MP_QSTR_EventQueue, MP_TYPE_EXTENDED_FIELDS( .unary_op = keypad_eventqueue_unary_op, + #if MICROPY_PY_USELECT + .protocol = &eventqueue_p, + #endif ), .locals_dict = (mp_obj_t)&keypad_eventqueue_locals_dict, }; diff --git a/shared-bindings/onewireio/OneWire.c b/shared-bindings/onewireio/OneWire.c index a167c86cc8..6ce5b659e7 100644 --- a/shared-bindings/onewireio/OneWire.c +++ b/shared-bindings/onewireio/OneWire.c @@ -42,9 +42,6 @@ //| //| :param ~microcontroller.Pin pin: Pin connected to the OneWire bus //| -//| .. note:: The OneWire class is available on `busio` and `bitbangio` in CircuitPython -//| 7.x for backwards compatibility but will be removed in CircuitPython 8.0.0. -//| //| Read a short series of pulses:: //| //| import onewireio diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 3de2176ffc..f812043e13 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -48,9 +48,6 @@ //| :param int frequency: Carrier signal frequency in Hertz //| :param int duty_cycle: 16-bit duty cycle of carrier frequency (0 - 65536) //| -//| For backwards compatibility, ``pin`` may be a PWMOut object used as the carrier. This -//| compatibility will be removed in CircuitPython 8.0.0. -//| //| Send a short series of pulses:: //| //| import array @@ -82,14 +79,6 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar const mcu_pin_obj_t *pin = args[ARG_pin].u_obj; mp_int_t frequency = args[ARG_frequency].u_int; mp_int_t duty_cycle = args[ARG_duty_cycle].u_int; - if (mp_obj_is_type(args[ARG_pin].u_obj, &pwmio_pwmout_type)) { - pwmio_pwmout_obj_t *pwmout = args[ARG_pin].u_obj; - duty_cycle = common_hal_pwmio_pwmout_get_duty_cycle(pwmout); - frequency = common_hal_pwmio_pwmout_get_frequency(pwmout); - pin = common_hal_pwmio_pwmout_get_pin(pwmout); - // Deinit the pin so we can use it. - common_hal_pwmio_pwmout_deinit(pwmout); - } validate_obj_is_free_pin(MP_OBJ_FROM_PTR(pin)); pulseio_pulseout_obj_t *self = m_new_obj(pulseio_pulseout_obj_t); self->base.type = &pulseio_pulseout_type; diff --git a/shared-bindings/qrio/PixelPolicy.c b/shared-bindings/qrio/PixelPolicy.c index 6887081b24..deb164d02d 100644 --- a/shared-bindings/qrio/PixelPolicy.c +++ b/shared-bindings/qrio/PixelPolicy.c @@ -34,18 +34,28 @@ //| """The input buffer to `QRDecoder.decode` consists of greyscale values in every byte""" //| //| EVEN_BYTES: PixelPolicy -//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 0, 2, …, and ignored bytes in positions 1, 3, …. This can decode directly from YUV images where the even bytes hold the Y (luminance) data.""" +//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 0, 2, …, and ignored bytes in positions 1, 3, …. This can decode directly from YUV images where the even bytes hold the Y (luminance) data.""" //| //| ODD_BYTES: PixelPolicy -//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 1, 3, …, and ignored bytes in positions 0, 2, …. This can decode directly from YUV images where the odd bytes hold the Y (luminance) data""" +//| """The input buffer to `QRDecoder.decode` consists of greyscale values in positions 1, 3, …, and ignored bytes in positions 0, 2, …. This can decode directly from YUV images where the odd bytes hold the Y (luminance) data""" +//| +//| RGB565_SWAPPED: PixelPolicy +//| """The input buffer to `QRDecoder.decode` consists of RGB565 values in byte-swapped order. Most cameras produce data in byte-swapped order. The green component is used.""" +//| +//| RGB565: PixelPolicy +//| """The input buffer to `QRDecoder.decode` consists of RGB565 values in native order. The green component is used.""" //| MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVERY_BYTE, QRIO_EVERY_BYTE); +MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, RGB565, QRIO_RGB565); +MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, RGB565_SWAPPED, QRIO_RGB565_SWAPPED); MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, EVEN_BYTES, QRIO_EVEN_BYTES); MAKE_ENUM_VALUE(qrio_pixel_policy_type, qrio_pixel_policy, ODD_BYTES, QRIO_EVEN_BYTES); MAKE_ENUM_MAP(qrio_pixel_policy) { MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVERY_BYTE), + MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, RGB565), + MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, RGB565_SWAPPED), MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, EVEN_BYTES), MAKE_ENUM_MAP_ENTRY(qrio_pixel_policy, ODD_BYTES), }; diff --git a/shared-bindings/qrio/PixelPolicy.h b/shared-bindings/qrio/PixelPolicy.h index 8be5dde1cc..36c1d271fd 100644 --- a/shared-bindings/qrio/PixelPolicy.h +++ b/shared-bindings/qrio/PixelPolicy.h @@ -33,7 +33,7 @@ extern const mp_obj_type_t qrio_pixel_policy_type; typedef enum { - QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES + QRIO_EVERY_BYTE, QRIO_EVEN_BYTES, QRIO_ODD_BYTES, QRIO_RGB565, QRIO_RGB565_SWAPPED } qrio_pixel_policy_t; extern const cp_enum_obj_t qrio_pixel_policy_EVERY_BYTE_obj; diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index 933d3a8227..676aec2186 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -30,20 +30,29 @@ #include "py/runtime.h" -void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t width, - uint32_t height, uint32_t bits_per_value) { +enum { align_bits = 8 * sizeof(uint32_t) }; + +static int stride(uint32_t width, uint32_t bits_per_value) { uint32_t row_width = width * bits_per_value; // align to uint32_t - uint8_t align_bits = 8 * sizeof(uint32_t); - if (row_width % align_bits != 0) { - self->stride = (row_width / align_bits + 1); - } else { - self->stride = row_width / align_bits; - } + return (row_width + align_bits - 1) / align_bits; +} + +void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t width, + uint32_t height, uint32_t bits_per_value) { + common_hal_displayio_bitmap_construct_from_buffer(self, width, height, bits_per_value, NULL, false); +} + +void common_hal_displayio_bitmap_construct_from_buffer(displayio_bitmap_t *self, uint32_t width, + uint32_t height, uint32_t bits_per_value, uint32_t *data, bool read_only) { self->width = width; self->height = height; - self->data = m_malloc(self->stride * height * sizeof(uint32_t), false); - self->read_only = false; + self->stride = stride(width, bits_per_value); + if (!data) { + data = m_malloc(self->stride * height * sizeof(uint32_t), false); + } + self->data = data; + self->read_only = read_only; self->bits_per_value = bits_per_value; if (bits_per_value > 8 && bits_per_value != 16 && bits_per_value != 32) { @@ -70,6 +79,7 @@ void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t wi self->dirty_area.y2 = height; } + uint16_t common_hal_displayio_bitmap_get_height(displayio_bitmap_t *self) { return self->height; } diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 9523d068ac..59aa843aca 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -51,7 +51,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t *init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t *backlight_pin, - uint16_t brightness_command, mp_float_t brightness, bool auto_brightness, + uint16_t brightness_command, mp_float_t brightness, bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high, bool SH1107_addressing, uint16_t backlight_pwm_frequency) { @@ -70,7 +70,6 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self, self->set_row_command = set_row_command; self->write_ram_command = write_ram_command; self->brightness_command = brightness_command; - self->auto_brightness = auto_brightness; self->first_manual_refresh = !auto_refresh; self->data_as_commands = data_as_commands; self->backlight_on_high = backlight_on_high; @@ -132,12 +131,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self, common_hal_never_reset_pin(backlight_pin); #endif } - if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType || - brightness_command != NO_BRIGHTNESS_COMMAND)) { - common_hal_displayio_display_set_brightness(self, brightness); - } else { - self->current_brightness = -1.0; - } + + common_hal_displayio_display_set_brightness(self, brightness); // Set the group after initialization otherwise we may send pixels while we delay in // initialization. @@ -157,20 +152,11 @@ uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t *self) return displayio_display_core_get_height(&self->core); } -bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t *self) { - return self->auto_brightness; -} - -void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t *self, bool auto_brightness) { - self->auto_brightness = auto_brightness; -} - mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t *self) { return self->current_brightness; } bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, mp_float_t brightness) { - self->updating_backlight = true; if (!self->backlight_on_high) { brightness = 1.0 - brightness; } @@ -209,7 +195,6 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, } } - self->updating_backlight = false; if (ok) { self->current_brightness = brightness; } @@ -413,23 +398,8 @@ void common_hal_displayio_display_set_auto_refresh(displayio_display_obj_t *self self->auto_refresh = auto_refresh; } -STATIC void _update_backlight(displayio_display_obj_t *self) { - if (!self->auto_brightness || self->updating_backlight) { - return; - } - if (supervisor_ticks_ms64() - self->last_backlight_refresh < 100) { - return; - } - // TODO(tannewt): Fade the backlight based on its existing value and a target value. The target - // should account for ambient light when possible. - common_hal_displayio_display_set_brightness(self, 1.0); - - self->last_backlight_refresh = supervisor_ticks_ms64(); -} - void displayio_display_background(displayio_display_obj_t *self) { - _update_backlight(self); - + common_hal_displayio_display_set_brightness(self, 1.0); if (self->auto_refresh && (supervisor_ticks_ms64() - self->core.last_refresh) > self->native_ms_per_frame) { _refresh_display(self); } @@ -452,7 +422,6 @@ void release_display(displayio_display_obj_t *self) { void reset_display(displayio_display_obj_t *self) { common_hal_displayio_display_set_auto_refresh(self, true); - self->auto_brightness = true; common_hal_displayio_display_show(self, NULL); } diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index a0049f00c0..f513a9d462 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -45,7 +45,6 @@ typedef struct { pwmio_pwmout_obj_t backlight_pwm; #endif }; - uint64_t last_backlight_refresh; uint64_t last_refresh_call; mp_float_t current_brightness; uint16_t brightness_command; @@ -57,8 +56,6 @@ typedef struct { bool auto_refresh; bool first_manual_refresh; bool data_as_commands; - bool auto_brightness; - bool updating_backlight; bool backlight_on_high; // new quirk for sh1107 bool SH1107_addressing; diff --git a/shared-module/framebufferio/FramebufferDisplay.c b/shared-module/framebufferio/FramebufferDisplay.c index 6f9d9ec6ad..e2e7d11106 100644 --- a/shared-module/framebufferio/FramebufferDisplay.c +++ b/shared-module/framebufferio/FramebufferDisplay.c @@ -113,20 +113,6 @@ uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_fr return displayio_display_core_get_height(&self->core); } -bool common_hal_framebufferio_framebufferdisplay_get_auto_brightness(framebufferio_framebufferdisplay_obj_t *self) { - if (self->framebuffer_protocol->get_auto_brightness) { - return self->framebuffer_protocol->get_auto_brightness(self->framebuffer); - } - return true; -} - -bool common_hal_framebufferio_framebufferdisplay_set_auto_brightness(framebufferio_framebufferdisplay_obj_t *self, bool auto_brightness) { - if (self->framebuffer_protocol->set_auto_brightness) { - return self->framebuffer_protocol->set_auto_brightness(self->framebuffer, auto_brightness); - } - return false; -} - mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness(framebufferio_framebufferdisplay_obj_t *self) { if (self->framebuffer_protocol->get_brightness) { return self->framebuffer_protocol->get_brightness(self->framebuffer); diff --git a/shared-module/framebufferio/FramebufferDisplay.h b/shared-module/framebufferio/FramebufferDisplay.h index b6138e2202..b53461aad5 100644 --- a/shared-module/framebufferio/FramebufferDisplay.h +++ b/shared-module/framebufferio/FramebufferDisplay.h @@ -43,7 +43,6 @@ typedef struct { mp_obj_t framebuffer; const struct _framebuffer_p_t *framebuffer_protocol; mp_buffer_info_t bufinfo; - uint64_t last_backlight_refresh; uint64_t last_refresh_call; uint16_t native_frames_per_second; uint16_t native_ms_per_frame; @@ -61,10 +60,8 @@ void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisp mp_obj_t common_hal_framebufferio_framebufferdisplay_get_framebuffer(framebufferio_framebufferdisplay_obj_t *self); -typedef bool (*framebuffer_get_auto_brightness_fun)(mp_obj_t); typedef bool (*framebuffer_get_reverse_pixels_in_byte_fun)(mp_obj_t); typedef bool (*framebuffer_get_reverse_pixels_in_word_fun)(mp_obj_t); -typedef bool (*framebuffer_set_auto_brightness_fun)(mp_obj_t, bool); typedef bool (*framebuffer_set_brightness_fun)(mp_obj_t, mp_float_t); typedef int (*framebuffer_get_bytes_per_cell_fun)(mp_obj_t); typedef int (*framebuffer_get_color_depth_fun)(mp_obj_t); @@ -105,9 +102,6 @@ typedef struct _framebuffer_p_t { framebuffer_get_brightness_fun get_brightness; framebuffer_set_brightness_fun set_brightness; - // Optional -- default is no automatic brightness control - framebuffer_get_auto_brightness_fun get_auto_brightness; - framebuffer_set_auto_brightness_fun set_auto_brightness; } framebuffer_p_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_FRAMEBUFFERDISPLAY_H diff --git a/shared-module/qrio/QRDecoder.c b/shared-module/qrio/QRDecoder.c index 26a609f215..f7b25362e4 100644 --- a/shared-module/qrio/QRDecoder.c +++ b/shared-module/qrio/QRDecoder.c @@ -104,6 +104,20 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co uint8_t *src = bufinfo->buf; switch (policy) { + case QRIO_RGB565: { + uint16_t *src16 = bufinfo->buf; + for (int i = 0; i < width * height; i++) { + framebuffer[i] = (src16[i] >> 3) & 0xfc; + } + break; + } + case QRIO_RGB565_SWAPPED: { + uint16_t *src16 = bufinfo->buf; + for (int i = 0; i < width * height; i++) { + framebuffer[i] = (__builtin_bswap16(src16[i]) >> 3) & 0xfc; + } + break; + } case QRIO_EVERY_BYTE: memcpy(framebuffer, src, width * height); break; @@ -116,6 +130,7 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co for (int i = 0; i < width * height; i++) { framebuffer[i] = src[2 * i]; } + break; } quirc_end(self->quirc); diff --git a/shared-module/touchio/TouchIn.c b/shared-module/touchio/TouchIn.c index 840c14571d..35dd56a6e4 100644 --- a/shared-module/touchio/TouchIn.c +++ b/shared-module/touchio/TouchIn.c @@ -78,6 +78,7 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self, const mcu uint16_t raw_reading = get_raw_reading(self); if (raw_reading == TIMEOUT_TICKS) { + common_hal_touchio_touchin_deinit(self); mp_raise_ValueError(translate("No pulldown on pin; 1Mohm recommended")); } self->threshold = raw_reading * 1.05 + 100; diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c index b1f94db5e5..72714b9a2b 100644 --- a/shared/runtime/pyexec.c +++ b/shared/runtime/pyexec.c @@ -199,7 +199,9 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input size_t n, *values; mp_obj_exception_get_traceback(return_value, &n, &values); if (values != NULL) { - result->exception_line = values[n - 2]; + result->exception_line = values[1]; + result->exception_filename[sizeof(result->exception_filename) - 1] = '\0'; + strncpy(result->exception_filename, qstr_str(values[0]), sizeof(result->exception_filename) - 1); } } } diff --git a/shared/runtime/pyexec.h b/shared/runtime/pyexec.h index d31a7fe816..411426eaaa 100644 --- a/shared/runtime/pyexec.h +++ b/shared/runtime/pyexec.h @@ -37,6 +37,9 @@ typedef struct { int return_code; mp_obj_t exception; int exception_line; + // Only store the first 32 characters of the filename. It is very unlikely that they can all be + // seen. + char exception_filename[33]; } pyexec_result_t; extern pyexec_mode_kind_t pyexec_mode_kind; diff --git a/supervisor/shared/web_workflow/static/directory.html b/supervisor/shared/web_workflow/static/directory.html index b88e74684b..5551410d73 100644 --- a/supervisor/shared/web_workflow/static/directory.html +++ b/supervisor/shared/web_workflow/static/directory.html @@ -9,7 +9,7 @@

 

- + @@ -18,5 +18,5 @@

- +🗀  + +📁  diff --git a/supervisor/shared/web_workflow/static/directory.js b/supervisor/shared/web_workflow/static/directory.js index 91389343d6..981d95f68c 100644 --- a/supervisor/shared/web_workflow/static/directory.js +++ b/supervisor/shared/web_workflow/static/directory.js @@ -6,6 +6,15 @@ var current_path; var editable = undefined; async function refresh_list() { + + function compareValues(a, b) { + if (a.directory == b.directory && a.name.toLowerCase() === b.name.toLowerCase()) { + return 0; + } else { + return a.directory.toString().substring(3,4)+a.name.toLowerCase() < b.directory.toString().substring(3,4)+b.name.toLowerCase() ? -1 : 1; + } + } + current_path = window.location.hash.substr(1); if (current_path == "") { current_path = "/"; @@ -46,7 +55,7 @@ async function refresh_list() { if (window.location.path != "/fs/") { var clone = template.content.cloneNode(true); var td = clone.querySelectorAll("td"); - td[0].textContent = "🗀"; + td[0].textContent = "📁"; var path = clone.querySelector("a"); let parent = new URL("..", "file://" + current_path); path.href = "#" + parent.pathname; @@ -56,11 +65,13 @@ async function refresh_list() { new_children.push(clone); } + data.sort(compareValues); + for (const f of data) { // Clone the new row and insert it into the table var clone = template.content.cloneNode(true); var td = clone.querySelectorAll("td"); - var icon = "⬇"; + var icon = "⬇️"; var file_path = current_path + f.name; let api_url = new URL("/fs" + file_path, url_base); let edit_url = "/edit/#" + file_path; @@ -72,12 +83,12 @@ async function refresh_list() { } if (f.directory) { - icon = "🗀"; + icon = "📁"; } else if(f.name.endsWith(".txt") || f.name.endsWith(".py") || f.name.endsWith(".js") || f.name.endsWith(".json")) { - icon = "🖹"; + icon = "📄"; } else if (f.name.endsWith(".html")) { icon = "🌐"; } @@ -92,9 +103,11 @@ async function refresh_list() { delete_button.disabled = !editable; delete_button.onclick = del; - edit_url = new URL(edit_url, url_base); - let edit_link = clone.querySelector(".edit_link"); - edit_link.href = edit_url + if (editable && !f.directory) { + edit_url = new URL(edit_url, url_base); + let edit_link = clone.querySelector(".edit_link"); + edit_link.href = edit_url + } new_children.push(clone); } @@ -149,10 +162,10 @@ async function upload(e) { ) if (response.ok) { refresh_list(); - files.value = ""; - upload_button.disabled = true; } } + files.value = ""; + upload_button.disabled = true; } async function del(e) { diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index bc76112ed3..770b0276fd 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -659,13 +659,13 @@ static void _reply_with_file(socketpool_socket_obj_t *socket, _request *request, mp_printf(&_socket_print, "Content-Length: %d\r\n", total_length); // TODO: Make this a table to save space. if (_endswith(filename, ".txt") || _endswith(filename, ".py")) { - _send_str(socket, "Content-Type: text/plain\r\n"); + _send_strs(socket, "Content-Type: text/plain", ";charset=UTF-8\r\n", NULL); } else if (_endswith(filename, ".js")) { - _send_str(socket, "Content-Type: text/javascript\r\n"); + _send_strs(socket, "Content-Type: text/javascript", ";charset=UTF-8\r\n", NULL); } else if (_endswith(filename, ".html")) { - _send_str(socket, "Content-Type: text/html\r\n"); + _send_strs(socket, "Content-Type: text/html", ";charset=UTF-8\r\n", NULL); } else if (_endswith(filename, ".json")) { - _send_str(socket, "Content-Type: application/json\r\n"); + _send_strs(socket, "Content-Type: application/json", ";charset=UTF-8\r\n", NULL); } else { _send_str(socket, "Content-Type: application/octet-stream\r\n"); } @@ -966,6 +966,16 @@ static void _reply_websocket_upgrade(socketpool_socket_obj_t *socket, _request * // socket is now closed and "disconnected". } +static uint8_t _hex2nibble(char h) { + if ('0' <= h && h <= '9') { + return h - '0'; + } else if ('A' <= h && h <= 'F') { + return h - 'A' + 0xa; + } + // Shouldn't usually use lower case. + return h - 'a' + 0xa; +} + static bool _reply(socketpool_socket_obj_t *socket, _request *request) { if (request->redirect) { _reply_redirect(socket, request, request->path); @@ -983,6 +993,26 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { _reply_forbidden(socket, request); } } else { + // Decode any percent encoded bytes so that we're left with UTF-8. + // We only do this on /fs/ paths and after redirect so that any + // path echoing we do stays encoded. + size_t o = 0; + size_t i = 0; + while (i < strlen(request->path)) { + if (request->path[i] == '%') { + request->path[o] = _hex2nibble(request->path[i + 1]) << 4 | _hex2nibble(request->path[i + 2]); + i += 3; + } else { + if (i != o) { + request->path[o] = request->path[i]; + } + i += 1; + } + o += 1; + } + if (o < i) { + request->path[o] = '\0'; + } char *path = request->path + 3; size_t pathlen = strlen(path); FATFS *fs = filesystem_circuitpy(); @@ -1350,6 +1380,8 @@ void supervisor_web_workflow_background(void) { // Close the active socket if it is no longer connected. common_hal_socketpool_socket_close(&active); } + + websocket_background(); } void supervisor_stop_web_workflow(void) { diff --git a/supervisor/shared/web_workflow/websocket.c b/supervisor/shared/web_workflow/websocket.c index 5a42eefb35..bb5f5b43d0 100644 --- a/supervisor/shared/web_workflow/websocket.c +++ b/supervisor/shared/web_workflow/websocket.c @@ -26,6 +26,9 @@ #include "supervisor/shared/web_workflow/websocket.h" +#include "py/ringbuf.h" +#include "py/runtime.h" +#include "shared/runtime/interrupt_char.h" #include "supervisor/shared/title_bar.h" // TODO: Remove ESP specific stuff. For now, it is useful as we refine the server. @@ -43,6 +46,11 @@ typedef struct { size_t payload_remaining; } _websocket; +// Buffer the incoming serial data in the background so that we can look for the +// interrupt character. +STATIC ringbuf_t _incoming_ringbuf; +STATIC uint8_t _buf[16]; + static _websocket cp_serial; static const char *TAG = "CP websocket"; @@ -50,6 +58,8 @@ static const char *TAG = "CP websocket"; void websocket_init(void) { cp_serial.socket.num = -1; cp_serial.socket.connected = false; + + ringbuf_init(&_incoming_ringbuf, _buf, sizeof(_buf) - 1); } void websocket_handoff(socketpool_socket_obj_t *socket) { @@ -193,16 +203,16 @@ bool websocket_available(void) { if (!websocket_connected()) { return false; } - _read_next_frame_header(); - return cp_serial.payload_remaining > 0 && cp_serial.frame_index >= cp_serial.frame_len; + websocket_background(); + return ringbuf_num_filled(&_incoming_ringbuf) > 0; } char websocket_read_char(void) { - uint8_t c; - if (!_read_next_payload_byte(&c)) { - c = -1; + websocket_background(); + if (ringbuf_num_filled(&_incoming_ringbuf) > 0) { + return ringbuf_get(&_incoming_ringbuf); } - return c; + return -1; } static void _websocket_send(_websocket *ws, const char *text, size_t len) { @@ -246,3 +256,15 @@ static void _websocket_send(_websocket *ws, const char *text, size_t len) { void websocket_write(const char *text, size_t len) { _websocket_send(&cp_serial, text, len); } + +void websocket_background(void) { + uint8_t c; + while (ringbuf_num_empty(&_incoming_ringbuf) > 0 && + _read_next_payload_byte(&c)) { + if (c == mp_interrupt_char) { + mp_sched_keyboard_interrupt(); + continue; + } + ringbuf_put(&_incoming_ringbuf, c); + } +} diff --git a/supervisor/shared/web_workflow/websocket.h b/supervisor/shared/web_workflow/websocket.h index c5c5114586..c3db2bf05c 100644 --- a/supervisor/shared/web_workflow/websocket.h +++ b/supervisor/shared/web_workflow/websocket.h @@ -35,4 +35,5 @@ void websocket_handoff(socketpool_socket_obj_t *socket); bool websocket_connected(void); bool websocket_available(void); char websocket_read_char(void); +void websocket_background(void); void websocket_write(const char *text, size_t len); diff --git a/tests/float/float_format_ftoe.py b/tests/float/float_format_ftoe.py new file mode 100644 index 0000000000..bc4e5a4a53 --- /dev/null +++ b/tests/float/float_format_ftoe.py @@ -0,0 +1,4 @@ +# check a case where rounding was suppressed inappropriately when "f" was +# promoted to "e" for large numbers. +v = 8.888e32 +print("%.2f" % v) # '%.2f' format with e32 becomes '%.2e', expect 8.89e+32. diff --git a/tests/float/float_format_ftoe.py.exp b/tests/float/float_format_ftoe.py.exp new file mode 100644 index 0000000000..f8b1deb3ec --- /dev/null +++ b/tests/float/float_format_ftoe.py.exp @@ -0,0 +1 @@ +8.89e+32 diff --git a/tests/float/float_format_ints.py b/tests/float/float_format_ints.py new file mode 100644 index 0000000000..0bf4baf12d --- /dev/null +++ b/tests/float/float_format_ints.py @@ -0,0 +1,31 @@ +# Test that integers format to exact values. + +for b in [13, 123, 457, 23456]: + for r in range(1, 10): + e_fmt = "{:." + str(r) + "e}" + f_fmt = "{:." + str(r) + "f}" + g_fmt = "{:." + str(r) + "g}" + for e in range(0, 5): + f = b * (10**e) + title = str(b) + " x 10^" + str(e) + print(title, "with format", e_fmt, "gives", e_fmt.format(f)) + print(title, "with format", f_fmt, "gives", f_fmt.format(f)) + print(title, "with format", g_fmt, "gives", g_fmt.format(f)) + +# Check that powers of 10 (that fit in float32) format correctly. +for i in range(31): + # It works to 12 digits on all platforms *except* qemu-arm, where + # 10^11 comes out as 10000000820 or something. + print("{:.7g}".format(float("1e" + str(i)))) + +# 16777215 is 2^24 - 1, the largest integer that can be completely held +# in a float32. +print("{:f}".format(16777215)) +# 4294967040 = 16777215 * 128 is the largest integer that is exactly +# represented by a float32 and that will also fit within a (signed) int32. +# The upper bound of our integer-handling code is actually double this, +# but that constant might cause trouble on systems using 32 bit ints. +print("{:f}".format(2147483520)) +# Very large positive integers can be a test for precision and resolution. +# This is a weird way to represent 1e38 (largest power of 10 for float32). +print("{:.6e}".format(float("9" * 30 + "e8"))) diff --git a/tests/float/float_format_ints_doubleprec.py b/tests/float/float_format_ints_doubleprec.py new file mode 100644 index 0000000000..57899d6d65 --- /dev/null +++ b/tests/float/float_format_ints_doubleprec.py @@ -0,0 +1,15 @@ +# Test formatting of very large ints. +# Relies on double-precision floats. + +import array +import sys + +# Challenging way to express 1e200 and 1e100. +print("{:.12e}".format(float("9" * 400 + "e-200"))) +print("{:.12e}".format(float("9" * 400 + "e-300"))) + +# These correspond to the binary representation of 1e200 in float64s: +v1 = 0x54B249AD2594C37D # 1e100 +v2 = 0x6974E718D7D7625A # 1e200 +print("{:.12e}".format(array.array("d", v1.to_bytes(8, sys.byteorder))[0])) +print("{:.12e}".format(array.array("d", v2.to_bytes(8, sys.byteorder))[0])) diff --git a/tests/run-tests.py b/tests/run-tests.py index a6d08aabb3..751b70886a 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -426,6 +426,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if upy_float_precision < 64: skip_tests.add("float/float_divmod.py") # tested by float/float_divmod_relaxed.py instead skip_tests.add("float/float2int_doubleprec_intbig.py") + skip_tests.add("float/float_format_ints_doubleprec.py") skip_tests.add("float/float_parse_doubleprec.py") if not has_complex: diff --git a/tools/tinytest-codegen.py b/tools/tinytest-codegen.py index 5c14bf2d5b..79b03f1383 100755 --- a/tools/tinytest-codegen.py +++ b/tools/tinytest-codegen.py @@ -100,6 +100,7 @@ exclude_tests = ( "float/float_divmod.py", # requires double precision floating point to work "float/float2int_doubleprec_intbig.py", + "float/float_format_ints_doubleprec.py", "float/float_parse_doubleprec.py", # inline asm FP tests (require Cortex-M4) "inlineasm/asmfpaddsub.py",
TypeSizePathModified