Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.jpg
.venv
.idea
222 changes: 222 additions & 0 deletions common/common_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
from micropython import const

OV2640_JPEG_INIT = (
(0xff, 0x00),
(0x2c, 0xff),
(0x2e, 0xdf),
(0xff, 0x01),
(0x3c, 0x32),
(0x11, 0x04),
(0x09, 0x02),
(0x04, 0x28),
(0x13, 0xe5),
(0x14, 0x48),
(0x2c, 0x0c),
(0x33, 0x78),
(0x3a, 0x33),
(0x3b, 0xfB),
(0x3e, 0x00),
(0x43, 0x11),
(0x16, 0x10),
(0x39, 0x92),
(0x35, 0xda),
(0x22, 0x1a),
(0x37, 0xc3),
(0x23, 0x00),
(0x34, 0xc0),
(0x36, 0x1a),
(0x06, 0x88),
(0x07, 0xc0),
(0x0d, 0x87),
(0x0e, 0x41),
(0x4c, 0x00),
(0x48, 0x00),
(0x5B, 0x00),
(0x42, 0x03),
(0x4a, 0x81),
(0x21, 0x99),
(0x24, 0x40),
(0x25, 0x38),
(0x26, 0x82),
(0x5c, 0x00),
(0x63, 0x00),
(0x61, 0x70),
(0x62, 0x80),
(0x7c, 0x05),
(0x20, 0x80),
(0x28, 0x30),
(0x6c, 0x00),
(0x6d, 0x80),
(0x6e, 0x00),
(0x70, 0x02),
(0x71, 0x94),
(0x73, 0xc1),
(0x12, 0x40),
(0x17, 0x11),
(0x18, 0x43),
(0x19, 0x00),
(0x1a, 0x4b),
(0x32, 0x09),
(0x37, 0xc0),
(0x4f, 0x60),
(0x50, 0xa8),
(0x6d, 0x00),
(0x3d, 0x38),
(0x46, 0x3f),
(0x4f, 0x60),
(0x0c, 0x3c),
(0xff, 0x00),
(0xe5, 0x7f),
(0xf9, 0xc0),
(0x41, 0x24),
(0xe0, 0x14),
(0x76, 0xff),
(0x33, 0xa0),
(0x42, 0x20),
(0x43, 0x18),
(0x4c, 0x00),
(0x87, 0xd5),
(0x88, 0x3f),
(0xd7, 0x03),
(0xd9, 0x10),
(0xd3, 0x82),
(0xc8, 0x08),
(0xc9, 0x80),
(0x7c, 0x00),
(0x7d, 0x00),
(0x7c, 0x03),
(0x7d, 0x48),
(0x7d, 0x48),
(0x7c, 0x08),
(0x7d, 0x20),
(0x7d, 0x10),
(0x7d, 0x0e),
(0x90, 0x00),
(0x91, 0x0e),
(0x91, 0x1a),
(0x91, 0x31),
(0x91, 0x5a),
(0x91, 0x69),
(0x91, 0x75),
(0x91, 0x7e),
(0x91, 0x88),
(0x91, 0x8f),
(0x91, 0x96),
(0x91, 0xa3),
(0x91, 0xaf),
(0x91, 0xc4),
(0x91, 0xd7),
(0x91, 0xe8),
(0x91, 0x20),
(0x92, 0x00),
(0x93, 0x06),
(0x93, 0xe3),
(0x93, 0x05),
(0x93, 0x05),
(0x93, 0x00),
(0x93, 0x04),
(0x93, 0x00),
(0x93, 0x00),
(0x93, 0x00),
(0x93, 0x00),
(0x93, 0x00),
(0x93, 0x00),
(0x93, 0x00),
(0x96, 0x00),
(0x97, 0x08),
(0x97, 0x19),
(0x97, 0x02),
(0x97, 0x0c),
(0x97, 0x24),
(0x97, 0x30),
(0x97, 0x28),
(0x97, 0x26),
(0x97, 0x02),
(0x97, 0x98),
(0x97, 0x80),
(0x97, 0x00),
(0x97, 0x00),
(0xc3, 0xed),
(0xa4, 0x00),
(0xa8, 0x00),
(0xc5, 0x11),
(0xc6, 0x51),
(0xbf, 0x80),
(0xc7, 0x10),
(0xb6, 0x66),
(0xb8, 0xA5),
(0xb7, 0x64),
(0xb9, 0x7C),
(0xb3, 0xaf),
(0xb4, 0x97),
(0xb5, 0xFF),
(0xb0, 0xC5),
(0xb1, 0x94),
(0xb2, 0x0f),
(0xc4, 0x5c),
(0xc0, 0x64),
(0xc1, 0x4B),
(0x8c, 0x00),
(0x86, 0x3D),
(0x50, 0x00),
(0x51, 0xC8),
(0x52, 0x96),
(0x53, 0x00),
(0x54, 0x00),
(0x55, 0x00),
(0x5a, 0xC8),
(0x5b, 0x96),
(0x5c, 0x00),
(0xd3, 0x00),
(0xc3, 0xed),
(0x7f, 0x00),
(0xda, 0x00),
(0xe5, 0x1f),
(0xe1, 0x67),
(0xe0, 0x00),
(0xdd, 0x7f),
(0x05, 0x00),
(0x12, 0x40),
(0xd3, 0x04),
(0xc0, 0x16),
(0xC1, 0x12),
(0x8c, 0x00),
(0x86, 0x3d),
(0x50, 0x00),
(0x51, 0x2C),
(0x52, 0x24),
(0x53, 0x00),
(0x54, 0x00),
(0x55, 0x00),
(0x5A, 0x2c),
(0x5b, 0x24),
(0x5c, 0x00),
(0xff, 0xff),
)

OV2640_YUV422 = (
(0xFF, 0x00),
(0x05, 0x00),
(0xDA, 0x10),
(0xD7, 0x03),
(0xDF, 0x00),
(0x33, 0x80),
(0x3C, 0x40),
(0xe1, 0x77),
(0x00, 0x00),
(0xff, 0xff),
)

OV2640_JPEG = (
(0xe0, 0x14),
(0xe1, 0x77),
(0xe5, 0x1f),
(0xd7, 0x03),
(0xda, 0x10),
(0xe0, 0x00),
(0xFF, 0x01),
(0x04, 0x08),
(0xff, 0xff),
)

SENSORADDR = const(0x30)
95 changes: 95 additions & 0 deletions rpi_pico/contextlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""Utilities for with-statement contexts. See PEP 343.
Original source code: https://hg.python.org/cpython/file/3.4/Lib/contextlib.py
Not implemented:
- redirect_stdout;
- ExitStack.
- closing
- supress
"""

class ContextDecorator(object):
"A base class or mixin that enables context managers to work as decorators."

def _recreate_cm(self):
"""Return a recreated instance of self.
Allows an otherwise one-shot context manager like
_GeneratorContextManager to support use as
a decorator via implicit recreation.
This is a private interface just for _GeneratorContextManager.
See issue #11647 for details.
"""
return self

def __call__(self, func):
def inner(*args, **kwds):
with self._recreate_cm():
return func(*args, **kwds)
return inner


class _GeneratorContextManager(ContextDecorator):
"""Helper for @contextmanager decorator."""

def __init__(self, func, *args, **kwds):
self.gen = func(*args, **kwds)
self.func, self.args, self.kwds = func, args, kwds

def _recreate_cm(self):
# _GCM instances are one-shot context managers, so the
# CM must be recreated each time a decorated function is
# called
return self.__class__(self.func, *self.args, **self.kwds)

def __enter__(self):
try:
return next(self.gen)
except StopIteration:
raise RuntimeError("generator didn't yield") from None

def __exit__(self, type, value, traceback):
if type is None:
try:
next(self.gen)
except StopIteration:
return
else:
raise RuntimeError("generator didn't stop")
else:
if value is None:
# Need to force instantiation so we can reliably
# tell if we get the same exception back
value = type()
try:
self.gen.throw(type, value, traceback)
raise RuntimeError("generator didn't stop after throw()")
except StopIteration as exc:
# Suppress the exception *unless* it's the same exception that
# was passed to throw(). This prevents a StopIteration
# raised inside the "with" statement from being suppressed
return exc is not value


def contextmanager(func):
"""@contextmanager decorator.
Typical usage:
@contextmanager
def some_generator(<arguments>):
<setup>
try:
yield <value>
finally:
<cleanup>
This makes this:
with some_generator(<arguments>) as <variable>:
<body>
equivalent to this:
<setup>
try:
<variable> = <value>
<body>
finally:
<cleanup>
"""
def helper(*args, **kwds):
return _GeneratorContextManager(func, *args, **kwds)
return helper
19 changes: 19 additions & 0 deletions rpi_pico/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ov2640
import gc
import time
import sys

FILE_NAME = 'image2.jpg'

def main():
print("initializing camera")
cam = ov2640.ov2640(resolution=ov2640.OV2640_320x240_JPEG)
# cam = ov2640.ov2640(resolution=ov2640.OV2640_1024x768_JPEG)
print(gc.mem_free())

image_length = cam.capture_to_file(FILE_NAME, True)
print("captured image is %d bytes" % image_length)
print("image is saved to %s" % FILE_NAME)

if __name__ == '__main__':
main()
Loading