circuitpython/py
Jeff Epler a8614a61dc ParallelImageCapture: Add continuous capture on espressif
By having a pair of buffers, the capture hardware can fill one buffer while
Python code (including displayio, etc) operates on the other buffer.  This
increases the responsiveness of camera-using code.

On the Kaluga it makes the following improvements:
 * 320x240 viewfinder at 30fps instead of 15fps using directio
 * 240x240 animated gif capture at 10fps instead of 7.5fps

As discussed at length on Discord, the "usual end user" code will look like
this:

    camera = ...

    with camera.continuous_capture(buffer1, buffer2) as capture:
        for frame in capture:
            # Do something with frame

However, rather than presenting a context manager, the core code consists of
three new functions to start & stop continuous capture, and to get the next
frame.  The reason is twofold.  First, it's simply easier to implement the
context manager object in pure Python.  Second, for more advanced usage, the
context manager may be too limiting, and it's easier to iterate on the right
design in Python code.  In particular, I noticed that adapting the
JPEG-capturing programs to use continuous capture mode needed a change in
program structure.

The camera app was structured as
```python
while True:
    if shutter button was just pressed:
        capture a jpeg frame
    else:
        update the viewfinder
```

However, "capture a jpeg frame" needs to (A) switch the camera settings and (B)
capture into a different, larger buffer then (C) return to the earlier
settings. This can't be done during continuous capture mode. So just
restructuring it as follows isn't going to work:

```python
with camera.continuous_capture(buffer1, buffer2) as capture:
    for frame in capture:
        if shutter button was just pressed:
            capture a jpeg frame, without disturbing continuous capture mode
        else:
            update the viewfinder
```

The continuous mode is only implemented in the espressif port; others
will throw an exception if the associated methods are invoked.  It's not
impossible to implement there, just not a priority, since these micros don't
have enough RAM for two framebuffer copies at any resonable sizes.

The capture code, including single-shot capture, now take mp_obj_t in the
common-hal layer, instead of a buffer & length.  This was done for the
continuous capture mode because it has to identify & return to the user the
proper Python object representing the original buffer.  In the Espressif port,
it was convenient to implement single capture in terms of a multi-capture,
which is why I changed the singleshot routine's signature too.
2021-11-03 11:02:46 -05:00
..
argcheck.c Merge pull request #5466 from jepler/merge-1.17 2021-10-15 23:34:31 -04:00
asmarm.c Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
asmarm.h Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
asmbase.c Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
asmbase.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
asmthumb.c Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
asmthumb.h Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
asmx64.c py/asmx64: Support use of top 8 regs in src_r64 argument. 2021-05-20 23:43:25 +10:00
asmx64.h Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
asmx86.c Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
asmx86.h Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
asmxtensa.c Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
asmxtensa.h Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
bc0.h Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
bc.c Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
bc.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
binary.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
binary.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
builtin.h Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
builtinevex.c Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
builtinhelp.c Update help() to have circuitpython.org 2021-10-21 18:07:07 -04:00
builtinimport.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
circuitpy_defns.mk ParallelImageCapture: Add continuous capture on espressif 2021-11-03 11:02:46 -05:00
circuitpy_mpconfig.h core: Enable new performance optimizations 2021-10-15 10:39:47 -05:00
circuitpy_mpconfig.mk core: Enable new performance optimizations 2021-10-15 10:39:47 -05:00
compile.c Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
compile.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
dynruntime.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
dynruntime.mk Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
emit.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
emitbc.c Merge MicroPython v1.15 into CircuitPython 2021-05-12 17:51:42 -07:00
emitcommon.c Merge MicroPython 1.10 into CircuitPython 2021-04-21 15:59:17 -07:00
emitglue.c fix compile error on boards with inline asm 2021-06-18 16:59:48 -05:00
emitglue.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
emitinlinethumb.c Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
emitinlinextensa.c Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
emitnarm.c py/emitnative: Add support for return/break/continue in try and with. 2018-09-04 14:31:28 +10:00
emitnative.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
emitnthumb.c py/emitnative: Add support for return/break/continue in try and with. 2018-09-04 14:31:28 +10:00
emitnx64.c py/emitnative: Add support for return/break/continue in try and with. 2018-09-04 14:31:28 +10:00
emitnx86.c Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
emitnxtensa.c py/emitnative: Add support for return/break/continue in try and with. 2018-09-04 14:31:28 +10:00
emitnxtensawin.c Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
enum.c Fix board builds and use MP_ERROR_TEXT in py and extmod 2021-05-05 17:51:52 -07:00
enum.h run code formatting script 2021-03-15 19:27:36 +05:30
formatfloat.c Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
formatfloat.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
frozenmod.c codeformat 2021-04-19 22:22:44 -07:00
frozenmod.h Merge MicroPython v1.11 into CircuitPython 2021-04-26 15:47:41 -07:00
gc_long_lived.c Merge MicroPython v1.11 into CircuitPython 2021-04-26 15:47:41 -07:00
gc_long_lived.h Introduce a long lived section of the heap. 2018-01-24 10:33:46 -08:00
gc.c Clear the buffer byte between ATB and FTB 2021-09-14 16:24:37 -07:00
gc.h Merge MicroPython v1.15 into CircuitPython 2021-05-12 17:51:42 -07:00
genlast.py Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
grammar.h Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
ioctl.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
lexer.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
lexer.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
makecompresseddata.py py/makecompresseddata.py: Make compression deterministic. 2020-04-20 10:32:49 +10:00
makemoduledefs.py codeformat: Fix handling of ** 2021-04-30 15:30:13 -05:00
makeqstrdata.py Compress word offset table 2021-08-07 09:23:35 -05:00
makeqstrdefs.py Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
makeversionhdr.py main: redesign boot_out.txt writing 2021-11-01 23:05:34 -05:00
malloc.c Merge MicroPython 1.10 into CircuitPython 2021-04-21 15:59:17 -07:00
map.c Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
misc.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
mkenv.mk Always use python3 2021-10-15 15:11:21 -05:00
mkrules.cmake py/mkrules: Automatically build mpy-cross if it doesn't exist. 2021-08-07 20:25:32 +10:00
mkrules.mk Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
modarray.c Merge MicroPython v1.11 into CircuitPython 2021-04-26 15:47:41 -07:00
modbuiltins.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
modcmath.c Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
modcollections.c codeformat 2021-04-19 22:22:44 -07:00
modgc.c codeformat 2021-04-19 22:22:44 -07:00
modio.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
modmath.c Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
modmicropython.c Shrink builds by defining advanced micropython API 2021-08-19 16:49:33 -07:00
modstruct.c Fix board builds and use MP_ERROR_TEXT in py and extmod 2021-05-05 17:51:52 -07:00
modsys.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
modthread.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
moduerrno.c Convert all modules to use MP_REGISTER_MODULE 2021-10-05 18:45:44 +05:30
mpconfig.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
mperrno.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
mphal.h Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
mpprint.c Make %p include the 0x prefix 2021-08-29 11:36:29 -05:00
mpprint.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
mpstate.c Add license to some obvious files. 2020-07-06 19:16:25 +01:00
mpstate.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
mpthread.h Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
mpz.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
mpz.h Fix format (expand tab) 2021-06-02 12:10:41 +09:00
nativeglue.c Fix up all natmod examples 2021-05-08 20:17:16 -05:00
nativeglue.h Fix up all natmod examples 2021-05-08 20:17:16 -05:00
nlr.c codeformat 2021-04-19 22:22:44 -07:00
nlr.h Merge MicroPython v1.15 into CircuitPython 2021-05-12 17:51:42 -07:00
nlraarch64.c Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
nlrpowerpc.c Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
nlrsetjmp.c Add license to some obvious files. 2020-07-06 19:16:25 +01:00
nlrthumb.c Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
nlrx64.c Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
nlrx86.c Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
nlrxtensa.c codeformat 2021-04-19 22:22:44 -07:00
obj.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
obj.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objarray.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objarray.h Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
objattrtuple.c Rename EXTENDED_FIELDS -> MP_TYPE_EXTENDED_FIELDS 2021-07-12 06:57:59 -05:00
objbool.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objboundmeth.c Rename EXTENDED_FIELDS -> MP_TYPE_EXTENDED_FIELDS 2021-07-12 06:57:59 -05:00
objcell.c codeformat 2021-04-19 22:22:44 -07:00
objclosure.c Rename EXTENDED_FIELDS -> MP_TYPE_EXTENDED_FIELDS 2021-07-12 06:57:59 -05:00
objcomplex.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objdeque.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objdict.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objenumerate.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objexcept.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objexcept.h add traceback object 2021-08-04 12:10:57 +05:30
objfilter.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objfloat.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objfun.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objfun.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
objgenerator.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objgenerator.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
objgetitemiter.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objint_longlong.c Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
objint_mpz.c Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
objint.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objint.h Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
objlist.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objlist.h Separate out mp_obj_list_insert for use in display.Group 2021-02-27 21:13:55 +01:00
objmap.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objmodule.c Don't double-list modules that MP_REGISTER_MODULE 2021-08-16 08:50:57 -05:00
objmodule.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
objnamedtuple.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objnamedtuple.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objnone.c Rename EXTENDED_FIELDS -> MP_TYPE_EXTENDED_FIELDS 2021-07-12 06:57:59 -05:00
objobject.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objpolyiter.c Rename EXTENDED_FIELDS -> MP_TYPE_EXTENDED_FIELDS 2021-07-12 06:57:59 -05:00
objproperty.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objproperty.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
objrange.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objreversed.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objset.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objsingleton.c Rename EXTENDED_FIELDS -> MP_TYPE_EXTENDED_FIELDS 2021-07-12 06:57:59 -05:00
objslice.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objstr.c str_modulo_format: Make error better match standard python 2021-10-19 10:52:14 -05:00
objstr.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objstringio.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objstringio.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
objstrunicode.c Turn on unicode for FATFS 2021-08-17 17:41:59 -07:00
objtraceback.c objtraceback: merge with an existing message in objtype 2021-08-23 20:23:23 -05:00
objtraceback.h add traceback object 2021-08-04 12:10:57 +05:30
objtuple.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objtuple.h codeformat 2021-04-19 22:22:44 -07:00
objtype.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objtype.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
objzip.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
opmethods.c Rename mp_type_binary_op -> mp_type_get_binary_op_slot 2021-07-12 07:03:52 -05:00
pairheap.c py/pairheap: Properly unlink node on pop and delete. 2020-03-26 01:21:04 +11:00
pairheap.h py/pairheap: Add helper function to initialise a new node. 2020-03-26 01:21:04 +11:00
parse.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
parse.h Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
parsenum.c Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
parsenum.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
parsenumbase.c codeformat 2021-04-19 22:22:44 -07:00
parsenumbase.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
persistentcode.c Update comment in persistentcode.c 2021-05-23 08:57:41 +01:00
persistentcode.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
profile.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
profile.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
proto.c Rename mp_type_protocol -> mp_type_get_protocol_slot 2021-07-12 07:04:04 -05:00
proto.h Rename mp_type_protocol -> mp_type_get_protocol_slot 2021-07-12 07:04:04 -05:00
py.cmake add traceback object 2021-08-04 12:10:57 +05:30
py.mk Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
pystack.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
pystack.h codeformat 2021-04-19 22:22:44 -07:00
qstr.c Fix mpy-cross by providing default 2021-08-31 13:38:37 -07:00
qstr.h Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
qstrdefs.h Merge MicroPython 1.10 into CircuitPython 2021-04-21 15:59:17 -07:00
reader.c Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
reader.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
reload.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
reload.h run code formatting script 2021-03-15 19:27:36 +05:30
repl.c restore a redundant NULL-comparison, it silences compiler diagnostics 2021-06-18 11:24:39 -05:00
repl.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
ringbuf.c Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
ringbuf.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
runtime0.h Merge MicroPython 1.12 into CircuitPython 2021-05-03 14:01:18 -07:00
runtime_utils.c WIP: after merge; before testing 2018-07-11 16:45:30 -04:00
runtime.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
runtime.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
scheduler.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
scope.c Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
scope.h Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
sequence.c Fix board builds and use MP_ERROR_TEXT in py and extmod 2021-05-05 17:51:52 -07:00
showbc.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
smallint.c Add license to some obvious files. 2020-07-06 19:16:25 +01:00
smallint.h Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
stackctrl.c codeformat 2021-04-19 22:22:44 -07:00
stackctrl.h Merge tag 'v1.16' 2021-06-18 10:54:19 -05:00
stream.c Fix board builds and use MP_ERROR_TEXT in py and extmod 2021-05-05 17:51:52 -07:00
stream.h Move mp_get_stream non-inline 2021-05-05 11:00:35 -05:00
unicode.c Merge MicroPython 1.13 into CircuitPython 2021-05-04 18:06:33 -07:00
unicode.h Add license to some obvious files. 2020-07-06 19:16:25 +01:00
usermod.cmake rp2: Add support for USER_C_MODULES to CMake build system. 2021-03-31 00:26:01 +11:00
vm.c Merge tag 'v1.17' into merge-1.17 2021-10-15 08:20:54 -05:00
vmentrytable.h Merge MicroPython 1.14 into CircuitPython 2021-05-11 15:07:40 -07:00
vstr.c Merge MicroPython v1.11 into CircuitPython 2021-04-26 15:47:41 -07:00
warning.c Merge MicroPython v1.11 into CircuitPython 2021-04-26 15:47:41 -07:00