Compare commits
7 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f33a3a656e | ||
|
|
ab3c5809ae | ||
|
|
dd3d3e4117 | ||
|
|
4464ea41e3 | ||
|
|
934c6e5190 | ||
|
|
ee91db69c5 | ||
|
|
e75648fa5e |
29 changed files with 555 additions and 1512 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
Thank you for contributing! Before you submit a pull request, please read the following.
|
||||
|
||||
Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html
|
||||
Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html
|
||||
|
||||
If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs
|
||||
|
||||
|
|
|
|||
70
.github/workflows/build.yml
vendored
70
.github/workflows/build.yml
vendored
|
|
@ -10,5 +10,71 @@ jobs:
|
|||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Run Build CI workflow
|
||||
uses: adafruit/workflows-circuitpython-libs/build@main
|
||||
- name: Dump GitHub context
|
||||
env:
|
||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
||||
run: echo "$GITHUB_CONTEXT"
|
||||
- name: Translate Repo Name For Build Tools filename_prefix
|
||||
id: repo-name
|
||||
run: |
|
||||
echo ::set-output name=repo-name::$(
|
||||
echo ${{ github.repository }} |
|
||||
awk -F '\/' '{ print tolower($2) }' |
|
||||
tr '_' '-'
|
||||
)
|
||||
- name: Set up Python 3.7
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.7
|
||||
- name: Versions
|
||||
run: |
|
||||
python3 --version
|
||||
- name: Checkout Current Repo
|
||||
uses: actions/checkout@v1
|
||||
with:
|
||||
submodules: true
|
||||
- name: Checkout tools repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: adafruit/actions-ci-circuitpython-libs
|
||||
path: actions-ci
|
||||
- name: Install dependencies
|
||||
# (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.)
|
||||
run: |
|
||||
source actions-ci/install.sh
|
||||
- name: Pip install pylint, Sphinx, pre-commit
|
||||
run: |
|
||||
pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit
|
||||
- name: Library version
|
||||
run: git describe --dirty --always --tags
|
||||
- name: Setup problem matchers
|
||||
uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1
|
||||
- name: Pre-commit hooks
|
||||
run: |
|
||||
pre-commit run --all-files
|
||||
- name: Build assets
|
||||
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
|
||||
- name: Archive bundles
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: bundles
|
||||
path: ${{ github.workspace }}/bundles/
|
||||
- name: Check For docs folder
|
||||
id: need-docs
|
||||
run: |
|
||||
echo ::set-output name=docs::$( find . -wholename './docs' )
|
||||
- name: Build docs
|
||||
if: contains(steps.need-docs.outputs.docs, 'docs')
|
||||
working-directory: docs
|
||||
run: sphinx-build -E -W -b html . _build/html
|
||||
- name: Check For setup.py
|
||||
id: need-pypi
|
||||
run: |
|
||||
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
|
||||
- name: Build Python package
|
||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
||||
run: |
|
||||
pip install --upgrade setuptools wheel twine readme_renderer testresources
|
||||
python setup.py sdist
|
||||
python setup.py bdist_wheel --universal
|
||||
twine check dist/*
|
||||
|
|
|
|||
88
.github/workflows/release.yml
vendored
Normal file
88
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
name: Release Actions
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
upload-release-assets:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Dump GitHub context
|
||||
env:
|
||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
||||
run: echo "$GITHUB_CONTEXT"
|
||||
- name: Translate Repo Name For Build Tools filename_prefix
|
||||
id: repo-name
|
||||
run: |
|
||||
echo ::set-output name=repo-name::$(
|
||||
echo ${{ github.repository }} |
|
||||
awk -F '\/' '{ print tolower($2) }' |
|
||||
tr '_' '-'
|
||||
)
|
||||
- name: Set up Python 3.6
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.6
|
||||
- name: Versions
|
||||
run: |
|
||||
python3 --version
|
||||
- name: Checkout Current Repo
|
||||
uses: actions/checkout@v1
|
||||
with:
|
||||
submodules: true
|
||||
- name: Checkout tools repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: adafruit/actions-ci-circuitpython-libs
|
||||
path: actions-ci
|
||||
- name: Install deps
|
||||
run: |
|
||||
source actions-ci/install.sh
|
||||
- name: Build assets
|
||||
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
|
||||
- name: Upload Release Assets
|
||||
# the 'official' actions version does not yet support dynamically
|
||||
# supplying asset names to upload. @csexton's version chosen based on
|
||||
# discussion in the issue below, as its the simplest to implement and
|
||||
# allows for selecting files with a pattern.
|
||||
# https://github.com/actions/upload-release-asset/issues/4
|
||||
#uses: actions/upload-release-asset@v1.0.1
|
||||
uses: csexton/release-asset-action@master
|
||||
with:
|
||||
pattern: "bundles/*"
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
upload-pypi:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Check For setup.py
|
||||
id: need-pypi
|
||||
run: |
|
||||
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
|
||||
- name: Set up Python
|
||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- name: Install dependencies
|
||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install setuptools wheel twine
|
||||
- name: Build and publish
|
||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
||||
env:
|
||||
TWINE_USERNAME: ${{ secrets.pypi_username }}
|
||||
TWINE_PASSWORD: ${{ secrets.pypi_password }}
|
||||
run: |
|
||||
for file in $(find -not -path "./.*" -not -path "./docs*" -name "*.py"); do
|
||||
sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file;
|
||||
done;
|
||||
python setup.py sdist
|
||||
twine upload dist/*
|
||||
19
.github/workflows/release_gh.yml
vendored
19
.github/workflows/release_gh.yml
vendored
|
|
@ -1,19 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
name: GitHub Release Actions
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
upload-release-assets:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Run GitHub Release CI workflow
|
||||
uses: adafruit/workflows-circuitpython-libs/release-gh@main
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
upload-url: ${{ github.event.release.upload_url }}
|
||||
19
.github/workflows/release_pypi.yml
vendored
19
.github/workflows/release_pypi.yml
vendored
|
|
@ -1,19 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
name: PyPI Release Actions
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
upload-release-assets:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Run PyPI Release CI workflow
|
||||
uses: adafruit/workflows-circuitpython-libs/release-pypi@main
|
||||
with:
|
||||
pypi-username: ${{ secrets.pypi_username }}
|
||||
pypi-password: ${{ secrets.pypi_password }}
|
||||
56
.gitignore
vendored
56
.gitignore
vendored
|
|
@ -1,48 +1,18 @@
|
|||
# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
# Do not include files and directories created by your personal work environment, such as the IDE
|
||||
# you use, except for those already listed here. Pull requests including changes to this file will
|
||||
# not be accepted.
|
||||
|
||||
# This .gitignore file contains rules for files generated by working with CircuitPython libraries,
|
||||
# including building Sphinx, testing with pip, and creating a virual environment, as well as the
|
||||
# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs.
|
||||
|
||||
# If you find that there are files being generated on your machine that should not be included in
|
||||
# your git commit, you should create a .gitignore_global file on your computer to include the
|
||||
# files created by your personal setup. To do so, follow the two steps below.
|
||||
|
||||
# First, create a file called .gitignore_global somewhere convenient for you, and add rules for
|
||||
# the files you want to exclude from git commits.
|
||||
|
||||
# Second, configure Git to use the exclude file for all Git repositories by running the
|
||||
# following via commandline, replacing "path/to/your/" with the actual path to your newly created
|
||||
# .gitignore_global file:
|
||||
# git config --global core.excludesfile path/to/your/.gitignore_global
|
||||
|
||||
# CircuitPython-specific files
|
||||
*.mpy
|
||||
|
||||
# Python-specific files
|
||||
__pycache__
|
||||
*.pyc
|
||||
|
||||
# Sphinx build-specific files
|
||||
_build
|
||||
|
||||
# This file results from running `pip -e install .` in a local repository
|
||||
*.egg-info
|
||||
|
||||
# Virtual environment-specific files
|
||||
.env
|
||||
.venv
|
||||
|
||||
# MacOS-specific files
|
||||
*.DS_Store
|
||||
|
||||
# IDE-specific files
|
||||
.idea
|
||||
__pycache__
|
||||
_build
|
||||
*.pyc
|
||||
.env
|
||||
.python-version
|
||||
build*/
|
||||
bundles
|
||||
*.DS_Store
|
||||
.eggs
|
||||
dist
|
||||
**/*.egg-info
|
||||
.vscode
|
||||
*~
|
||||
|
|
|
|||
|
|
@ -3,40 +3,38 @@
|
|||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/python/black
|
||||
rev: 23.3.0
|
||||
- repo: https://github.com/python/black
|
||||
rev: 20.8b1
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: https://github.com/fsfe/reuse-tool
|
||||
rev: v1.1.2
|
||||
- id: black
|
||||
- repo: https://github.com/fsfe/reuse-tool
|
||||
rev: v0.12.1
|
||||
hooks:
|
||||
- id: reuse
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
- id: reuse
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.3.0
|
||||
hooks:
|
||||
- id: check-yaml
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/pycqa/pylint
|
||||
rev: v2.17.4
|
||||
- id: check-yaml
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/pycqa/pylint
|
||||
rev: pylint-2.7.1
|
||||
hooks:
|
||||
- id: pylint
|
||||
- id: pylint
|
||||
name: pylint (library code)
|
||||
types: [python]
|
||||
args:
|
||||
- --disable=consider-using-f-string
|
||||
exclude: "^(docs/|examples/|tests/|setup.py$)"
|
||||
- id: pylint
|
||||
name: pylint (example code)
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: pylint_examples
|
||||
name: pylint (examples code)
|
||||
description: Run pylint rules on "examples/*.py" files
|
||||
types: [python]
|
||||
files: "^examples/"
|
||||
args:
|
||||
- --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code
|
||||
- id: pylint
|
||||
name: pylint (test code)
|
||||
entry: /usr/bin/env bash -c
|
||||
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)']
|
||||
language: system
|
||||
- id: pylint_tests
|
||||
name: pylint (tests code)
|
||||
description: Run pylint rules on "tests/*.py" files
|
||||
types: [python]
|
||||
files: "^tests/"
|
||||
args:
|
||||
- --disable=missing-docstring,consider-using-f-string,duplicate-code
|
||||
entry: /usr/bin/env bash -c
|
||||
args: ['([[ ! -d "tests" ]] || for test in $(find . -path "./tests/*.py"); do pylint --disable=missing-docstring $test; done)']
|
||||
language: system
|
||||
|
|
|
|||
45
.pylintrc
45
.pylintrc
|
|
@ -26,7 +26,7 @@ jobs=1
|
|||
|
||||
# List of plugins (as comma separated values of python modules names) to load,
|
||||
# usually to register additional checkers.
|
||||
load-plugins=pylint.extensions.no_self_use
|
||||
load-plugins=
|
||||
|
||||
# Pickle collected data for later comparisons.
|
||||
persistent=yes
|
||||
|
|
@ -54,8 +54,8 @@ confidence=
|
|||
# --enable=similarities". If you want to run only the classes checker, but have
|
||||
# no Warning level messages displayed, use"--disable=all --enable=classes
|
||||
# --disable=W"
|
||||
# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call
|
||||
disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding
|
||||
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
|
||||
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,pointless-string-statement
|
||||
|
||||
# Enable the message, report, category or checker with the given id(s). You can
|
||||
# either give multiple identifier separated by comma (,) or put this option
|
||||
|
|
@ -225,6 +225,12 @@ max-line-length=100
|
|||
# Maximum number of lines in a module
|
||||
max-module-lines=1000
|
||||
|
||||
# List of optional constructs for which whitespace checking is disabled. `dict-
|
||||
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
|
||||
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
|
||||
# `empty-line` allows space-only lines.
|
||||
no-space-check=trailing-comma,dict-separator
|
||||
|
||||
# Allow the body of a class to be on the same line as the declaration if body
|
||||
# contains single statement.
|
||||
single-line-class-stmt=no
|
||||
|
|
@ -251,22 +257,38 @@ min-similarity-lines=12
|
|||
|
||||
[BASIC]
|
||||
|
||||
# Naming hint for argument names
|
||||
argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct argument names
|
||||
argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Naming hint for attribute names
|
||||
attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct attribute names
|
||||
attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Bad variable names which should always be refused, separated by a comma
|
||||
bad-names=foo,bar,baz,toto,tutu,tata
|
||||
|
||||
# Naming hint for class attribute names
|
||||
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
||||
|
||||
# Regular expression matching correct class attribute names
|
||||
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
||||
|
||||
# Naming hint for class names
|
||||
# class-name-hint=[A-Z_][a-zA-Z0-9]+$
|
||||
class-name-hint=[A-Z_][a-zA-Z0-9_]+$
|
||||
|
||||
# Regular expression matching correct class names
|
||||
# class-rgx=[A-Z_][a-zA-Z0-9]+$
|
||||
class-rgx=[A-Z_][a-zA-Z0-9_]+$
|
||||
|
||||
# Naming hint for constant names
|
||||
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
||||
|
||||
# Regular expression matching correct constant names
|
||||
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
||||
|
||||
|
|
@ -274,6 +296,9 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
|||
# ones are exempt.
|
||||
docstring-min-length=-1
|
||||
|
||||
# Naming hint for function names
|
||||
function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct function names
|
||||
function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
|
|
@ -284,12 +309,21 @@ good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_
|
|||
# Include a hint for the correct naming format with invalid-name
|
||||
include-naming-hint=no
|
||||
|
||||
# Naming hint for inline iteration names
|
||||
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
|
||||
|
||||
# Regular expression matching correct inline iteration names
|
||||
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
|
||||
|
||||
# Naming hint for method names
|
||||
method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct method names
|
||||
method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Naming hint for module names
|
||||
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
||||
|
||||
# Regular expression matching correct module names
|
||||
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
||||
|
||||
|
|
@ -305,6 +339,9 @@ no-docstring-rgx=^_
|
|||
# to this list to register other decorators that produce valid properties.
|
||||
property-classes=abc.abstractproperty
|
||||
|
||||
# Naming hint for variable names
|
||||
variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct variable names
|
||||
variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
|
|
@ -396,4 +433,4 @@ min-public-methods=1
|
|||
|
||||
# Exceptions that will emit a warning when being caught. Defaults to
|
||||
# "Exception"
|
||||
overgeneral-exceptions=builtins.Exception
|
||||
overgeneral-exceptions=Exception
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
# Read the Docs configuration file
|
||||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||
|
||||
# Required
|
||||
version: 2
|
||||
|
||||
sphinx:
|
||||
configuration: docs/conf.py
|
||||
|
||||
build:
|
||||
os: ubuntu-20.04
|
||||
tools:
|
||||
python: "3"
|
||||
|
||||
python:
|
||||
install:
|
||||
- requirements: docs/requirements.txt
|
||||
- requirements: requirements.txt
|
||||
7
.readthedocs.yml
Normal file
7
.readthedocs.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
python:
|
||||
version: 3
|
||||
requirements_file: requirements.txt
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice
|
||||
20
README.rst
20
README.rst
|
|
@ -3,11 +3,11 @@ Introduction
|
|||
|
||||
|
||||
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-ov5640/badge/?version=latest
|
||||
:target: https://docs.circuitpython.org/projects/ov5640/en/latest/
|
||||
:target: https://circuitpython.readthedocs.io/projects/ov5640/en/latest/
|
||||
:alt: Documentation Status
|
||||
|
||||
|
||||
.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg
|
||||
.. image:: https://img.shields.io/discord/327254708534116352.svg
|
||||
:target: https://adafru.it/discord
|
||||
:alt: Discord
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ following command to install:
|
|||
|
||||
.. code-block:: shell
|
||||
|
||||
circup install adafruit_ov5640
|
||||
circup install ov5640
|
||||
|
||||
Or the following command to update an existing version:
|
||||
|
||||
|
|
@ -121,17 +121,15 @@ Usage Example
|
|||
sys.stdout.write("\033[J")
|
||||
time.sleep(0.05)
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
API documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/ov5640/en/latest/>`_.
|
||||
|
||||
For information on building library documentation, please check out
|
||||
`this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
|
||||
|
||||
Contributing
|
||||
============
|
||||
|
||||
Contributions are welcome! Please read our `Code of Conduct
|
||||
<https://github.com/adafruit/Adafruit_CircuitPython_ov5640/blob/HEAD/CODE_OF_CONDUCT.md>`_
|
||||
before contributing to help this project stay welcoming.
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
For information on building library documentation, please check out
|
||||
`this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
|
||||
|
|
|
|||
|
|
@ -25,22 +25,15 @@ Implementation Notes
|
|||
"""
|
||||
|
||||
# pylint: disable=too-many-lines
|
||||
# pylint: disable=too-many-public-methods
|
||||
|
||||
# imports
|
||||
import time
|
||||
import imagecapture
|
||||
import pwmio
|
||||
import digitalio
|
||||
from adafruit_bus_device.i2c_device import I2CDevice
|
||||
|
||||
try:
|
||||
from typing import Optional, Sequence, List, Union
|
||||
from busio import I2C
|
||||
from microcontroller import Pin
|
||||
from digitalio import DigitalInOut
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
__version__ = "0.0.0+auto.0"
|
||||
__version__ = "0.0.0-auto.0"
|
||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ov5640.git"
|
||||
|
||||
from micropython import const
|
||||
|
|
@ -51,37 +44,6 @@ OV5640_COLOR_GRAYSCALE = 2
|
|||
OV5640_COLOR_JPEG = 3
|
||||
|
||||
# fmt: off
|
||||
|
||||
_SYSTEM_RESET00 = const(0x3000) # Reset for Individual Block
|
||||
# (0: enable block; 1: reset block)
|
||||
# Bit[7]: Reset BIST
|
||||
# Bit[6]: Reset MCU program memory
|
||||
# Bit[5]: Reset MCU
|
||||
# Bit[4]: Reset OTP
|
||||
# Bit[3]: Reset STB
|
||||
# Bit[2]: Reset d5060
|
||||
# Bit[1]: Reset timing control
|
||||
# Bit[0]: Reset array control
|
||||
|
||||
_SYSTEM_RESET02 = const(0x3002) # Reset for Individual Block
|
||||
# (0: enable block; 1: reset block)
|
||||
# Bit[7]: Reset VFIFO
|
||||
# Bit[5]: Reset format
|
||||
# Bit[4]: Reset JFIFO
|
||||
# Bit[3]: Reset SFIFO
|
||||
# Bit[2]: Reset JPG
|
||||
# Bit[1]: Reset format MUX
|
||||
# Bit[0]: Reset average
|
||||
|
||||
_CLOCK_ENABLE02 = const(0x3006) # Clock Enable Control
|
||||
# (0: disable clock; 1: enable clock)
|
||||
# Bit[7]: Enable PSRAM clock
|
||||
# Bit[6]: Enable FMT clock
|
||||
# Bit[5]: Enable JPEG 2x clock
|
||||
# Bit[3]: Enable JPEG clock
|
||||
# Bit[1]: Enable format MUX clock
|
||||
# Bit[0]: Enable average clock
|
||||
|
||||
_SYSTEM_CTROL0 = const(0x3008)
|
||||
# Bit[7]: Software reset
|
||||
# Bit[6]: Software power down
|
||||
|
|
@ -137,6 +99,21 @@ _AEC_PK_MANUAL = const(0x3503)
|
|||
|
||||
# gain = {0x350A[1:0], 0x350B[7:0]} / 16
|
||||
|
||||
_STROBE_CTRL = const(0x3b00)
|
||||
_FREX_MODE = const(0x3b07)
|
||||
_FREX_REQUEST = const(0x3B08)
|
||||
_PAD_OUTPUT_ENABLE00 = const(0x3016)
|
||||
_PAD_OUTPUT_VALUE00 = const(0x3019)
|
||||
_PAD_SELECT00 = const(0x301C)
|
||||
|
||||
FREX_MODE_0 = 1
|
||||
FREX_MODE_1 = 2
|
||||
FREX_MODE_ROLL = 3
|
||||
|
||||
STROBE_MODE_XENON = 0
|
||||
STROBE_MODE_LED1 = 1
|
||||
STROBE_MODE_LED2 = 2
|
||||
STROBE_MODE_LED3 = 3
|
||||
|
||||
_X_ADDR_ST_H = const(0x3800)
|
||||
# Bit[3:0]: X address start[11:8]
|
||||
|
|
@ -414,28 +391,6 @@ _pll_pclk_root_div_factors = [1,2,4,8]
|
|||
_REG_DLY = const(0xFFFF)
|
||||
_REGLIST_TAIL = const(0x0000)
|
||||
|
||||
_OV5640_STAT_FIRMWAREBAD = const(0x7F)
|
||||
_OV5640_STAT_STARTUP = const(0x7E)
|
||||
_OV5640_STAT_IDLE = const(0x70)
|
||||
_OV5640_STAT_FOCUSING = const(0x00)
|
||||
_OV5640_STAT_FOCUSED = const(0x10)
|
||||
|
||||
_OV5640_CMD_TRIGGER_AUTOFOCUS = const(0x03)
|
||||
_OV5640_CMD_AUTO_AUTOFOCUS = const(0x04)
|
||||
_OV5640_CMD_RELEASE_FOCUS = const(0x08)
|
||||
_OV5640_CMD_AF_SET_VCM_STEP = const(0x1A)
|
||||
_OV5640_CMD_AF_GET_VCM_STEP = const(0x1B)
|
||||
|
||||
_OV5640_CMD_MAIN = const(0x3022)
|
||||
_OV5640_CMD_ACK = const(0x3023)
|
||||
_OV5640_CMD_PARA0 = const(0x3024)
|
||||
_OV5640_CMD_PARA1 = const(0x3025)
|
||||
_OV5640_CMD_PARA2 = const(0x3026)
|
||||
_OV5640_CMD_PARA3 = const(0x3027)
|
||||
_OV5640_CMD_PARA4 = const(0x3028)
|
||||
_OV5640_CMD_FW_STATUS = const(0x3029)
|
||||
|
||||
|
||||
_sensor_default_regs = [
|
||||
_SYSTEM_CTROL0, 0x82, # software reset
|
||||
_REG_DLY, 10, # delay 10ms
|
||||
|
|
@ -450,11 +405,11 @@ _sensor_default_regs = [
|
|||
0x4713, 0x02, # jpg mode select
|
||||
_ISP_CONTROL_01, 0x83, # turn color matrix, awb and SDE
|
||||
# sys reset
|
||||
_SYSTEM_RESET00, 0x00, # enable all blocks
|
||||
_SYSTEM_RESET02, 0x1C, # reset jfifo, sfifo, jpg, fmux, avg
|
||||
0x3000, 0x00,
|
||||
0x3002, 0x1C,
|
||||
# clock enable
|
||||
0x3004, 0xFF,
|
||||
_CLOCK_ENABLE02, 0xC3,
|
||||
0x3006, 0xC3,
|
||||
# isp control
|
||||
0x5000, 0xA7,
|
||||
_ISP_CONTROL_01, 0xA3, # +scaling?
|
||||
|
|
@ -590,156 +545,14 @@ _sensor_default_regs = [
|
|||
0x3008, 0x02,
|
||||
# 50Hz
|
||||
0x3C00, 0x04,
|
||||
#_REG_DLY, 300,
|
||||
_REG_DLY, 300,
|
||||
]
|
||||
|
||||
|
||||
|
||||
_reset_awb = [
|
||||
_ISP_CONTROL_01, 0x83, # turn color matrix, awb and SDE
|
||||
# sys reset
|
||||
_SYSTEM_RESET00, 0x00, # enable all blocks
|
||||
_SYSTEM_RESET02, 0x1C, # reset jfifo, sfifo, jpg, fmux, avg
|
||||
# clock enable
|
||||
#0x3004, 0xFF,
|
||||
#_CLOCK_ENABLE02, 0xC3,
|
||||
# isp control
|
||||
0x5000, 0xA7,
|
||||
_ISP_CONTROL_01, 0xA3, # +scaling?
|
||||
0x5003, 0x08, # special_effect
|
||||
# unknown
|
||||
0x370C, 0x02, #!!IMPORTANT
|
||||
0x3634, 0x40, #!!IMPORTANT
|
||||
# AEC/AGC
|
||||
0x3A02, 0x03,
|
||||
0x3A03, 0xD8,
|
||||
0x3A08, 0x01,
|
||||
0x3A09, 0x27,
|
||||
0x3A0A, 0x00,
|
||||
0x3A0B, 0xF6,
|
||||
0x3A0D, 0x04,
|
||||
0x3A0E, 0x03,
|
||||
0x3A0F, 0x30, # ae_level
|
||||
0x3A10, 0x28, # ae_level
|
||||
0x3A11, 0x60, # ae_level
|
||||
0x3A13, 0x43,
|
||||
0x3A14, 0x03,
|
||||
0x3A15, 0xD8,
|
||||
0x3A18, 0x00, # gainceiling
|
||||
0x3A19, 0xF8, # gainceiling
|
||||
0x3A1B, 0x30, # ae_level
|
||||
0x3A1E, 0x26, # ae_level
|
||||
0x3A1F, 0x14, # ae_level
|
||||
# vcm debug
|
||||
0x3600, 0x08,
|
||||
0x3601, 0x33,
|
||||
# 50/60Hz
|
||||
0x3C01, 0xA4,
|
||||
0x3C04, 0x28,
|
||||
0x3C05, 0x98,
|
||||
0x3C06, 0x00,
|
||||
0x3C07, 0x08,
|
||||
0x3C08, 0x00,
|
||||
0x3C09, 0x1C,
|
||||
0x3C0A, 0x9C,
|
||||
0x3C0B, 0x40,
|
||||
0x460C, 0x22, # disable jpeg footer
|
||||
# BLC
|
||||
0x4001, 0x02,
|
||||
0x4004, 0x02,
|
||||
# AWB
|
||||
0x5180, 0xFF,
|
||||
0x5181, 0xF2,
|
||||
0x5182, 0x00,
|
||||
0x5183, 0x14,
|
||||
0x5184, 0x25,
|
||||
0x5185, 0x24,
|
||||
0x5186, 0x09,
|
||||
0x5187, 0x09,
|
||||
0x5188, 0x09,
|
||||
0x5189, 0x75,
|
||||
0x518A, 0x54,
|
||||
0x518B, 0xE0,
|
||||
0x518C, 0xB2,
|
||||
0x518D, 0x42,
|
||||
0x518E, 0x3D,
|
||||
0x518F, 0x56,
|
||||
0x5190, 0x46,
|
||||
0x5191, 0xF8,
|
||||
0x5192, 0x04,
|
||||
0x5193, 0x70,
|
||||
0x5194, 0xF0,
|
||||
0x5195, 0xF0,
|
||||
0x5196, 0x03,
|
||||
0x5197, 0x01,
|
||||
0x5198, 0x04,
|
||||
0x5199, 0x12,
|
||||
0x519A, 0x04,
|
||||
0x519B, 0x00,
|
||||
0x519C, 0x06,
|
||||
0x519D, 0x82,
|
||||
0x519E, 0x38,
|
||||
# color matrix (Saturation)
|
||||
0x5381, 0x1E,
|
||||
0x5382, 0x5B,
|
||||
0x5383, 0x08,
|
||||
0x5384, 0x0A,
|
||||
0x5385, 0x7E,
|
||||
0x5386, 0x88,
|
||||
0x5387, 0x7C,
|
||||
0x5388, 0x6C,
|
||||
0x5389, 0x10,
|
||||
0x538A, 0x01,
|
||||
0x538B, 0x98,
|
||||
# CIP control (Sharpness)
|
||||
0x5300, 0x10, # sharpness
|
||||
0x5301, 0x10, # sharpness
|
||||
0x5302, 0x18, # sharpness
|
||||
0x5303, 0x19, # sharpness
|
||||
0x5304, 0x10,
|
||||
0x5305, 0x10,
|
||||
0x5306, 0x08, # denoise
|
||||
0x5307, 0x16,
|
||||
0x5308, 0x40,
|
||||
0x5309, 0x10, # sharpness
|
||||
0x530A, 0x10, # sharpness
|
||||
0x530B, 0x04, # sharpness
|
||||
0x530C, 0x06, # sharpness
|
||||
# GAMMA
|
||||
0x5480, 0x01,
|
||||
0x5481, 0x00,
|
||||
0x5482, 0x1E,
|
||||
0x5483, 0x3B,
|
||||
0x5484, 0x58,
|
||||
0x5485, 0x66,
|
||||
0x5486, 0x71,
|
||||
0x5487, 0x7D,
|
||||
0x5488, 0x83,
|
||||
0x5489, 0x8F,
|
||||
0x548A, 0x98,
|
||||
0x548B, 0xA6,
|
||||
0x548C, 0xB8,
|
||||
0x548D, 0xCA,
|
||||
0x548E, 0xD7,
|
||||
0x548F, 0xE3,
|
||||
0x5490, 0x1D,
|
||||
# Special Digital Effects (SDE) (UV adjust)
|
||||
0x5580, 0x06, # enable brightness and contrast
|
||||
0x5583, 0x40, # special_effect
|
||||
0x5584, 0x10, # special_effect
|
||||
0x5586, 0x20, # contrast
|
||||
0x5587, 0x00, # brightness
|
||||
0x5588, 0x00, # brightness
|
||||
0x5589, 0x10,
|
||||
0x558A, 0x00,
|
||||
0x558B, 0xF8,
|
||||
0x501D, 0x40, # enable manual offset of contrast
|
||||
]
|
||||
_sensor_format_jpeg = [
|
||||
_FORMAT_CTRL, 0x00, # YUV422
|
||||
_FORMAT_CTRL00, 0x30, # YUYV
|
||||
_SYSTEM_RESET02, 0x00, # enable everything
|
||||
_CLOCK_ENABLE02, 0xFF, # enable all clocks
|
||||
0x3002, 0x00, # 0x1c to 0x00 !!!
|
||||
0x3006, 0xFF, # 0xc3 to 0xff !!!
|
||||
0x471C, 0x50, # 0xd0 to 0x50 !!!
|
||||
]
|
||||
|
||||
|
|
@ -761,9 +574,6 @@ _sensor_format_yuv422 = [
|
|||
_sensor_format_rgb565 = [
|
||||
_FORMAT_CTRL, 0x01, # RGB
|
||||
_FORMAT_CTRL00, 0x61, # RGB565 (BGR)
|
||||
_SYSTEM_RESET02, 0x1C, # reset jfifo, sfifo, jpg, fmux, avg
|
||||
_CLOCK_ENABLE02, 0xC3, # reset to how it was before (no jpg clock)
|
||||
|
||||
]
|
||||
|
||||
_ov5640_color_settings = {
|
||||
|
|
@ -912,20 +722,39 @@ sensor_regs_awb0 = [
|
|||
0x519D, 0x82,
|
||||
0x519E, 0x38,
|
||||
]
|
||||
|
||||
_autofocus_firmware_load = (
|
||||
0x3022, 0x00,
|
||||
0x3023, 0x00,
|
||||
0x3024, 0x00,
|
||||
0x3025, 0x00,
|
||||
0x3026, 0x00,
|
||||
0x3027, 0x00,
|
||||
0x3028, 0x00,
|
||||
0x3029, 0x7f,
|
||||
0x3000, 0x00,
|
||||
)
|
||||
|
||||
AUTOFOCUS_STAT_FIRMWAREBAD = 0x7F
|
||||
AUTOFOCUS_STAT_STARTUP = 0x7E
|
||||
AUTOFOCUS_STAT_IDLE = 0x70
|
||||
AUTOFOCUS_STAT_FOCUSING = 0x00
|
||||
AUTOFOCUS_STAT_FOCUSED = 0x10
|
||||
|
||||
# fmt: on
|
||||
|
||||
|
||||
class _RegBits:
|
||||
def __init__(self, reg: int, shift: int, mask: int) -> None:
|
||||
def __init__(self, reg, shift, mask):
|
||||
self.reg = reg
|
||||
self.shift = shift
|
||||
self.mask = mask
|
||||
|
||||
def __get__(self, obj: "OV5640", objtype: Optional[type] = None) -> int:
|
||||
def __get__(self, obj, objtype=None):
|
||||
reg_value = obj._read_register(self.reg)
|
||||
return (reg_value >> self.shift) & self.mask
|
||||
|
||||
def __set__(self, obj: "OV5640", value: int) -> None:
|
||||
def __set__(self, obj, value):
|
||||
if value & ~self.mask:
|
||||
raise ValueError(
|
||||
f"Value 0x{value:02x} does not fit in mask 0x{self.mask:02x}"
|
||||
|
|
@ -937,16 +766,16 @@ class _RegBits:
|
|||
|
||||
|
||||
class _RegBits16:
|
||||
def __init__(self, reg: int, shift: int, mask: int) -> None:
|
||||
def __init__(self, reg, shift, mask):
|
||||
self.reg = reg
|
||||
self.shift = shift
|
||||
self.mask = mask
|
||||
|
||||
def __get__(self, obj: "OV5640", objtype: Optional[type] = None) -> int:
|
||||
def __get__(self, obj, objtype=None):
|
||||
reg_value = obj._read_register16(self.reg)
|
||||
return (reg_value >> self.shift) & self.mask
|
||||
|
||||
def __set__(self, obj: "OV5640", value: int) -> None:
|
||||
def __set__(self, obj, value):
|
||||
if value & ~self.mask:
|
||||
raise ValueError(
|
||||
f"Value 0x{value:02x} does not fit in mask 0x{self.mask:02x}"
|
||||
|
|
@ -958,32 +787,11 @@ class _RegBits16:
|
|||
|
||||
|
||||
class _SCCB16CameraBase: # pylint: disable=too-few-public-methods
|
||||
_finalize_firmware_load = (
|
||||
0x3022,
|
||||
0x00,
|
||||
0x3023,
|
||||
0x00,
|
||||
0x3024,
|
||||
0x00,
|
||||
0x3025,
|
||||
0x00,
|
||||
0x3026,
|
||||
0x00,
|
||||
0x3027,
|
||||
0x00,
|
||||
0x3028,
|
||||
0x00,
|
||||
0x3029,
|
||||
0x7F,
|
||||
0x3000,
|
||||
0x00,
|
||||
)
|
||||
|
||||
def __init__(self, i2c_bus: I2C, i2c_address: int) -> None:
|
||||
def __init__(self, i2c_bus, i2c_address):
|
||||
self._i2c_device = I2CDevice(i2c_bus, i2c_address)
|
||||
self._bank = None
|
||||
|
||||
def _write_register(self, reg: int, value: int) -> None:
|
||||
def _write_register(self, reg, value):
|
||||
b = bytearray(3)
|
||||
b[0] = reg >> 8
|
||||
b[1] = reg & 0xFF
|
||||
|
|
@ -991,15 +799,15 @@ class _SCCB16CameraBase: # pylint: disable=too-few-public-methods
|
|||
with self._i2c_device as i2c:
|
||||
i2c.write(b)
|
||||
|
||||
def _write_addr_reg(self, reg: int, x_value: int, y_value: int) -> None:
|
||||
def _write_addr_reg(self, reg, x_value, y_value):
|
||||
self._write_register16(reg, x_value)
|
||||
self._write_register16(reg + 2, y_value)
|
||||
|
||||
def _write_register16(self, reg: int, value: int) -> None:
|
||||
def _write_register16(self, reg, value):
|
||||
self._write_register(reg, value >> 8)
|
||||
self._write_register(reg + 1, value & 0xFF)
|
||||
|
||||
def _read_register(self, reg: int) -> int:
|
||||
def _read_register(self, reg):
|
||||
b = bytearray(2)
|
||||
b[0] = reg >> 8
|
||||
b[1] = reg & 0xFF
|
||||
|
|
@ -1008,12 +816,12 @@ class _SCCB16CameraBase: # pylint: disable=too-few-public-methods
|
|||
i2c.readinto(b, end=1)
|
||||
return b[0]
|
||||
|
||||
def _read_register16(self, reg: int) -> int:
|
||||
def _read_register16(self, reg):
|
||||
high = self._read_register(reg)
|
||||
low = self._read_register(reg + 1)
|
||||
return (high << 8) | low
|
||||
|
||||
def _write_list(self, reg_list: Sequence[int]) -> None:
|
||||
def _write_list(self, reg_list):
|
||||
for i in range(0, len(reg_list), 2):
|
||||
register = reg_list[i]
|
||||
value = reg_list[i + 1]
|
||||
|
|
@ -1022,8 +830,8 @@ class _SCCB16CameraBase: # pylint: disable=too-few-public-methods
|
|||
else:
|
||||
self._write_register(register, value)
|
||||
|
||||
def _write_reg_bits(self, reg: int, mask: int, enable: bool) -> None:
|
||||
val = val = self._read_register(reg)
|
||||
def _write_reg_bits(self, reg, mask, enable):
|
||||
val = self._read_register(reg)
|
||||
if enable:
|
||||
val |= mask
|
||||
else:
|
||||
|
|
@ -1036,18 +844,17 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
i2c_bus: I2C,
|
||||
data_pins: List[Pin],
|
||||
clock: Pin,
|
||||
vsync: Pin,
|
||||
href: Pin,
|
||||
shutdown: Optional[DigitalInOut] = None,
|
||||
reset: Optional[DigitalInOut] = None,
|
||||
mclk: Optional[Pin] = None,
|
||||
mclk_frequency: int = 20_000_000,
|
||||
i2c_address: int = 0x3C,
|
||||
size: int = OV5640_SIZE_QQVGA,
|
||||
init_autofocus: bool = True,
|
||||
i2c_bus,
|
||||
data_pins,
|
||||
clock,
|
||||
vsync,
|
||||
href,
|
||||
shutdown=None,
|
||||
reset=None,
|
||||
mclk=None,
|
||||
mclk_frequency=20_000_000,
|
||||
i2c_address=0x3C,
|
||||
size=OV5640_SIZE_QQVGA,
|
||||
): # pylint: disable=too-many-arguments
|
||||
"""
|
||||
Args:
|
||||
|
|
@ -1057,9 +864,9 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
vsync (microcontroller.Pin): The vsync signal from the OV5640.
|
||||
href (microcontroller.Pin): The href signal from the OV5640, \
|
||||
sometimes inaccurately called hsync.
|
||||
shutdown (Optional[digitalio.DigitalInOut]): If not None, the shutdown
|
||||
shutdown (Optional[microcontroller.Pin]): If not None, the shutdown
|
||||
signal to the camera, also called the powerdown or enable pin.
|
||||
reset (Optional[digitalio.DigitalInOut]): If not None, the reset signal
|
||||
reset (Optional[microcontroller.Pin]): If not None, the reset signal
|
||||
to the camera.
|
||||
mclk (Optional[microcontroller.Pin]): The pin on which to create a
|
||||
master clock signal, or None if the master clock signal is
|
||||
|
|
@ -1071,10 +878,23 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
work reliably. On the ESP32-S2, a 20MHz clock can be generated
|
||||
with sufficiently low jitter.
|
||||
i2c_address (int): The I2C address of the camera.
|
||||
size (int): The captured image size
|
||||
init_autofocus (bool): initialize autofocus
|
||||
"""
|
||||
|
||||
# we're supposed to go into shutdown if we can, first
|
||||
if shutdown:
|
||||
self._shutdown = digitalio.DigitalInOut(shutdown)
|
||||
self._shutdown.switch_to_output(True)
|
||||
else:
|
||||
self._shutdown = None
|
||||
|
||||
if reset:
|
||||
self._reset = digitalio.DigitalInOut(reset)
|
||||
self._reset.switch_to_output(False)
|
||||
else:
|
||||
self._reset = None
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
# Initialize the master clock
|
||||
if mclk:
|
||||
self._mclk_pwm = pwmio.PWMOut(mclk, frequency=mclk_frequency)
|
||||
|
|
@ -1082,24 +902,15 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
else:
|
||||
self._mclk_pwm = None
|
||||
|
||||
if reset:
|
||||
self._reset = reset
|
||||
self._reset.switch_to_output(False)
|
||||
else:
|
||||
self._reset = None
|
||||
|
||||
if shutdown:
|
||||
self._shutdown = shutdown
|
||||
self._shutdown.switch_to_output(True)
|
||||
time.sleep(0.005) # t2, 5ms stability
|
||||
if self._shutdown:
|
||||
self._shutdown.switch_to_output(False)
|
||||
else:
|
||||
self._shutdown = None
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
if self._reset:
|
||||
time.sleep(0.001) # t3, 1ms delay from pwdn
|
||||
self._reset.switch_to_output(True)
|
||||
time.sleep(0.02)
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
# Now that the master clock is running, we can initialize i2c comms
|
||||
super().__init__(i2c_bus, i2c_address)
|
||||
|
|
@ -1122,102 +933,11 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
self._ev = 0
|
||||
self._white_balance = 0
|
||||
self.size = size
|
||||
|
||||
if init_autofocus:
|
||||
self.autofocus_init()
|
||||
self._strobe_enabled = False
|
||||
|
||||
chip_id = _RegBits16(_CHIP_ID_HIGH, 0, 0xFFFF)
|
||||
|
||||
def autofocus_init_from_file(self, filename):
|
||||
"""Initialize the autofocus engine from a .bin file"""
|
||||
with open(filename, mode="rb") as file:
|
||||
firmware = file.read()
|
||||
self.autofocus_init_from_bitstream(firmware)
|
||||
|
||||
def autofocus_init_from_bitstream(self, firmware: bytes):
|
||||
"""Initialize the autofocus engine from a bytestring"""
|
||||
self._write_register(0x3000, 0x20) # reset autofocus coprocessor
|
||||
time.sleep(0.01)
|
||||
|
||||
arr = bytearray(256)
|
||||
with self._i2c_device as i2c:
|
||||
for offset in range(0, len(firmware), 254):
|
||||
num_firmware_bytes = min(254, len(firmware) - offset)
|
||||
reg = offset + 0x8000
|
||||
arr[0] = reg >> 8
|
||||
arr[1] = reg & 0xFF
|
||||
arr[2 : 2 + num_firmware_bytes] = firmware[
|
||||
offset : offset + num_firmware_bytes
|
||||
]
|
||||
i2c.write(arr, end=2 + num_firmware_bytes)
|
||||
|
||||
self._write_list(self._finalize_firmware_load)
|
||||
for _ in range(100):
|
||||
if self.autofocus_status == _OV5640_STAT_IDLE:
|
||||
break
|
||||
time.sleep(0.01)
|
||||
else:
|
||||
raise RuntimeError("Timed out after trying to load autofocus firmware")
|
||||
|
||||
def autofocus_init(self):
|
||||
"""Initialize the autofocus engine from ov5640_autofocus.bin"""
|
||||
if "/" in __file__:
|
||||
binfile = (
|
||||
__file__.rsplit("/", 1)[0].rsplit(".", 1)[0] + "/ov5640_autofocus.bin"
|
||||
)
|
||||
else:
|
||||
binfile = "ov5640_autofocus.bin"
|
||||
print(binfile)
|
||||
return self.autofocus_init_from_file(binfile)
|
||||
|
||||
@property
|
||||
def autofocus_status(self):
|
||||
"""Read the camera autofocus status register"""
|
||||
return self._read_register(_OV5640_CMD_FW_STATUS)
|
||||
|
||||
def _send_autofocus_command(self, command, msg): # pylint: disable=unused-argument
|
||||
self._write_register(_OV5640_CMD_ACK, 0x01) # clear command ack
|
||||
self._write_register(_OV5640_CMD_MAIN, command) # send command
|
||||
for _ in range(1000):
|
||||
if self._read_register(_OV5640_CMD_ACK) == 0x0: # command is finished
|
||||
return True
|
||||
time.sleep(0.01)
|
||||
return False
|
||||
|
||||
def autofocus(self) -> list[int]:
|
||||
"""Perform an autofocus operation.
|
||||
|
||||
If all elements of the list are 0, the autofocus operation failed. Otherwise,
|
||||
if at least one element is nonzero, the operation succeeded.
|
||||
|
||||
In principle the elements correspond to 5 autofocus regions, if configured."""
|
||||
if not self._send_autofocus_command(_OV5640_CMD_RELEASE_FOCUS, "release focus"):
|
||||
return [False] * 5
|
||||
if not self._send_autofocus_command(_OV5640_CMD_TRIGGER_AUTOFOCUS, "autofocus"):
|
||||
return [False] * 5
|
||||
zone_focus = [self._read_register(_OV5640_CMD_PARA0 + i) for i in range(5)]
|
||||
print(f"zones focused: {zone_focus}")
|
||||
return zone_focus
|
||||
|
||||
@property
|
||||
def autofocus_vcm_step(self):
|
||||
"""Get the voice coil motor step location"""
|
||||
if not self._send_autofocus_command(
|
||||
_OV5640_CMD_AF_GET_VCM_STEP, "get vcm step"
|
||||
):
|
||||
return None
|
||||
return self._read_register(_OV5640_CMD_PARA4)
|
||||
|
||||
@autofocus_vcm_step.setter
|
||||
def autofocus_vcm_step(self, step):
|
||||
"""Get the voice coil motor step location, from 0 to 255"""
|
||||
if not 0 <= step <= 255:
|
||||
raise RuntimeError("VCM step must be 0 to 255")
|
||||
self._write_register(_OV5640_CMD_PARA3, 0x00)
|
||||
self._write_register(_OV5640_CMD_PARA4, step)
|
||||
self._send_autofocus_command(_OV5640_CMD_AF_SET_VCM_STEP, "set vcm step")
|
||||
|
||||
def capture(self, buf: Union[bytearray, memoryview]) -> None:
|
||||
def capture(self, buf):
|
||||
"""Capture an image into the buffer.
|
||||
|
||||
Args:
|
||||
|
|
@ -1233,42 +953,40 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
return None
|
||||
|
||||
@property
|
||||
def capture_buffer_size(self) -> int:
|
||||
def capture_buffer_size(self):
|
||||
"""Return the size of capture buffer to use with current resolution & colorspace settings"""
|
||||
if self.colorspace == OV5640_COLOR_JPEG:
|
||||
# This is somewhat arbirary but seems to work for a wide range of JPEG images
|
||||
# the user can chose to further scale the buffer in the user code if necessary
|
||||
return 2 * (self.width * self.height // self.quality)
|
||||
return self.width * self.height // self.quality
|
||||
if self.colorspace == OV5640_COLOR_GRAYSCALE:
|
||||
return self.width * self.height
|
||||
return self.width * self.height * 2
|
||||
|
||||
@property
|
||||
def mclk_frequency(self) -> Optional[int]:
|
||||
def mclk_frequency(self):
|
||||
"""Get the actual frequency the generated mclk, or None"""
|
||||
return self._mclk_pwm.frequency if self._mclk_pwm else None
|
||||
|
||||
@property
|
||||
def width(self) -> int:
|
||||
def width(self):
|
||||
"""Get the image width in pixels."""
|
||||
return self._w
|
||||
|
||||
@property
|
||||
def height(self) -> int:
|
||||
def height(self):
|
||||
"""Get the image height in pixels."""
|
||||
return self._h
|
||||
|
||||
@property
|
||||
def colorspace(self) -> int:
|
||||
def colorspace(self):
|
||||
"""Get or set the colorspace, one of the ``OV5640_COLOR_`` constants."""
|
||||
return self._colorspace
|
||||
|
||||
@colorspace.setter
|
||||
def colorspace(self, colorspace: int) -> None:
|
||||
def colorspace(self, colorspace):
|
||||
self._colorspace = colorspace
|
||||
self._set_size_and_colorspace()
|
||||
|
||||
def _set_image_options(self) -> None: # pylint: disable=too-many-branches
|
||||
def _set_image_options(self): # pylint: disable=too-many-branches
|
||||
reg20 = reg21 = reg4514 = reg4514_test = 0
|
||||
if self.colorspace == OV5640_COLOR_JPEG:
|
||||
reg21 |= 0x20
|
||||
|
|
@ -1318,13 +1036,13 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
self._write_register(_X_INCREMENT, 0x11)
|
||||
self._write_register(_Y_INCREMENT, 0x11)
|
||||
|
||||
def _set_colorspace(self) -> None:
|
||||
def _set_colorspace(self):
|
||||
colorspace = self._colorspace
|
||||
settings = _ov5640_color_settings[colorspace]
|
||||
|
||||
self._write_list(settings)
|
||||
|
||||
def deinit(self) -> None:
|
||||
def deinit(self):
|
||||
"""Deinitialize the camera"""
|
||||
self._imagecapture.deinit()
|
||||
if self._mclk_pwm:
|
||||
|
|
@ -1333,13 +1051,14 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
self._shutdown.deinit()
|
||||
if self._reset:
|
||||
self._reset.deinit()
|
||||
self.powerdown = True
|
||||
|
||||
@property
|
||||
def size(self) -> int:
|
||||
def size(self):
|
||||
"""Get or set the captured image size, one of the ``OV5640_SIZE_`` constants."""
|
||||
return self._size
|
||||
|
||||
def _set_size_and_colorspace(self) -> None: # pylint: disable=too-many-locals
|
||||
def _set_size_and_colorspace(self): # pylint: disable=too-many-locals
|
||||
size = self._size
|
||||
width, height, ratio = _resolution_info[size]
|
||||
self._w = width
|
||||
|
|
@ -1395,15 +1114,15 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
|
||||
def _set_pll( # pylint: disable=too-many-arguments
|
||||
self,
|
||||
bypass: bool,
|
||||
multiplier: int,
|
||||
sys_div: int,
|
||||
pre_div: int,
|
||||
root_2x: bool,
|
||||
pclk_root_div: int,
|
||||
pclk_manual: bool,
|
||||
pclk_div: int,
|
||||
) -> None:
|
||||
bypass,
|
||||
multiplier,
|
||||
sys_div,
|
||||
pre_div,
|
||||
root_2x,
|
||||
pclk_root_div,
|
||||
pclk_manual,
|
||||
pclk_div,
|
||||
):
|
||||
if ( # pylint: disable=too-many-boolean-expressions
|
||||
multiplier > 252
|
||||
or multiplier < 4
|
||||
|
|
@ -1425,47 +1144,50 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
self._write_register(0x3103, 0x13)
|
||||
|
||||
@size.setter
|
||||
def size(self, size: int) -> None:
|
||||
def size(self, size):
|
||||
self._size = size
|
||||
self._set_size_and_colorspace()
|
||||
|
||||
@property
|
||||
def flip_x(self) -> bool:
|
||||
def flip_x(self):
|
||||
"""Get or set the X-flip flag"""
|
||||
return self._flip_x
|
||||
|
||||
@flip_x.setter
|
||||
def flip_x(self, value: bool) -> None:
|
||||
def flip_x(self, value):
|
||||
self._flip_x = bool(value)
|
||||
self._set_image_options()
|
||||
|
||||
@property
|
||||
def flip_y(self) -> bool:
|
||||
def flip_y(self):
|
||||
"""Get or set the Y-flip flag"""
|
||||
return self._flip_y
|
||||
|
||||
@flip_y.setter
|
||||
def flip_y(self, value: bool) -> None:
|
||||
def flip_y(self, value):
|
||||
self._flip_y = bool(value)
|
||||
self._set_image_options()
|
||||
|
||||
@property
|
||||
def test_pattern(self) -> bool:
|
||||
def test_pattern(self):
|
||||
"""Set to True to enable a test pattern, False to enable normal image capture"""
|
||||
return self._test_pattern
|
||||
|
||||
@test_pattern.setter
|
||||
def test_pattern(self, value: bool) -> None:
|
||||
def test_pattern(self, value) -> None:
|
||||
if type(value) is bool:
|
||||
self._write_register(_PRE_ISP_TEST_SETTING_1, value << 7)
|
||||
else:
|
||||
self._write_register(_PRE_ISP_TEST_SETTING_1, 1 << 7 | value)
|
||||
self._test_pattern = value
|
||||
self._write_register(_PRE_ISP_TEST_SETTING_1, value << 7)
|
||||
|
||||
@property
|
||||
def saturation(self) -> int:
|
||||
def saturation(self):
|
||||
"""Get or set the saturation value, from -4 to +4."""
|
||||
return self._saturation
|
||||
|
||||
@saturation.setter
|
||||
def saturation(self, value: int) -> None:
|
||||
def saturation(self, value):
|
||||
if not -4 <= value <= 4:
|
||||
raise ValueError(
|
||||
"Invalid saturation {value}, use a value from -4..4 inclusive"
|
||||
|
|
@ -1475,12 +1197,12 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
self._saturation = value
|
||||
|
||||
@property
|
||||
def effect(self) -> int:
|
||||
def effect(self):
|
||||
"""Get or set the special effect, one of the ``OV5640_SPECIAL_EFFECT_`` constants"""
|
||||
return self._effect
|
||||
|
||||
@effect.setter
|
||||
def effect(self, value: int) -> None:
|
||||
def effect(self, value):
|
||||
for reg_addr, reg_value in zip(
|
||||
(0x5580, 0x5583, 0x5584, 0x5003), _sensor_special_effects[value]
|
||||
):
|
||||
|
|
@ -1488,12 +1210,12 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
self._effect = value
|
||||
|
||||
@property
|
||||
def quality(self) -> int:
|
||||
def quality(self):
|
||||
"""Controls the JPEG quality. Valid range is from 2..55 inclusive"""
|
||||
return self._read_register(_COMPRESSION_CTRL07) & 0x3F
|
||||
|
||||
@quality.setter
|
||||
def quality(self, value: int) -> None:
|
||||
def quality(self, value: int):
|
||||
if not 2 <= value < 55:
|
||||
raise ValueError(
|
||||
f"Invalid quality value {value}, use a value from 2..55 inclusive"
|
||||
|
|
@ -1507,7 +1229,7 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
self._write_register(0x3212, 0xA3) # launch group 3
|
||||
|
||||
@property
|
||||
def brightness(self) -> int:
|
||||
def brightness(self):
|
||||
"""Sensor brightness adjustment, from -4 to 4 inclusive"""
|
||||
brightness_abs = self._read_register(0x5587) >> 4
|
||||
brightness_neg = self._read_register(0x5588) & 8
|
||||
|
|
@ -1516,7 +1238,7 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
return brightness_abs
|
||||
|
||||
@brightness.setter
|
||||
def brightness(self, value: int) -> None:
|
||||
def brightness(self, value):
|
||||
if not -4 <= value <= 4:
|
||||
raise ValueError(
|
||||
"Invalid brightness value {value}, use a value from -4..4 inclusive"
|
||||
|
|
@ -1526,7 +1248,7 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
)
|
||||
|
||||
@property
|
||||
def contrast(self) -> int:
|
||||
def contrast(self):
|
||||
"""Sensor contrast adjustment, from -4 to 4 inclusive"""
|
||||
contrast_abs = self._read_register(0x5587) >> 4
|
||||
contrast_neg = self._read_register(0x5588) & 8
|
||||
|
|
@ -1535,7 +1257,7 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
return contrast_abs
|
||||
|
||||
@contrast.setter
|
||||
def contrast(self, value: int) -> None:
|
||||
def contrast(self, value):
|
||||
if not -3 <= value <= 3:
|
||||
raise ValueError(
|
||||
"Invalid contrast value {value}, use a value from -3..3 inclusive"
|
||||
|
|
@ -1544,33 +1266,31 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
self._write_group_3_settings([0x5586, setting[0], 0x5585, setting[1]])
|
||||
|
||||
@property
|
||||
def exposure_value(self) -> int:
|
||||
"""Sensor exposure (EV) adjustment, from -3 to 3 inclusive"""
|
||||
def exposure_value(self):
|
||||
"""Sensor exposure (EV) adjustment, from -4 to 4 inclusive"""
|
||||
return self._ev
|
||||
|
||||
@exposure_value.setter
|
||||
def exposure_value(self, value: int) -> None:
|
||||
def exposure_value(self, value):
|
||||
if not -3 <= value <= 3:
|
||||
raise ValueError(
|
||||
"Invalid exposure value (EV) {value}, use a value from -3..3 inclusive"
|
||||
"Invalid exposure value (EV) {value}, use a value from -4..4 inclusive"
|
||||
)
|
||||
self._ev = value
|
||||
for offset, reg_value in enumerate(_sensor_ev_levels[value]):
|
||||
self._write_register(0x5381 + offset, reg_value)
|
||||
|
||||
@property
|
||||
def white_balance(self) -> int:
|
||||
def white_balance(self):
|
||||
"""The white balance setting, one of the ``OV5640_WHITE_BALANCE_*`` constants"""
|
||||
return self._white_balance
|
||||
|
||||
@white_balance.setter
|
||||
def white_balance(self, value: int) -> None:
|
||||
def white_balance(self, value):
|
||||
if not OV5640_WHITE_BALANCE_AUTO <= value <= OV5640_WHITE_BALANCE_INCANDESCENT:
|
||||
raise ValueError(
|
||||
"Invalid exposure value (EV) {value}, "
|
||||
"use one of the OV5640_WHITE_BALANCE_* constants"
|
||||
)
|
||||
self._white_balance = value
|
||||
self._write_register(0x3212, 0x3) # start group 3
|
||||
for reg_addr, reg_value in zip(_light_registers, _light_modes[value]):
|
||||
self._write_register(reg_addr, reg_value)
|
||||
|
|
@ -1578,10 +1298,96 @@ class OV5640(_SCCB16CameraBase): # pylint: disable=too-many-instance-attributes
|
|||
self._write_register(0x3212, 0xA3) # launch group 3
|
||||
|
||||
@property
|
||||
def night_mode(self) -> bool:
|
||||
def night_mode(self):
|
||||
"""Enable or disable the night mode setting of the sensor"""
|
||||
return bool(self._read_register(0x3A00) & 0x04)
|
||||
|
||||
@night_mode.setter
|
||||
def night_mode(self, value: bool) -> None:
|
||||
def night_mode(self, value):
|
||||
self._write_reg_bits(0x3A00, 0x04, value)
|
||||
|
||||
@property
|
||||
def powerdown(self):
|
||||
return bool(self._read_register(_SYSTEM_CTROL0) & 0x40)
|
||||
|
||||
@powerdown.setter
|
||||
def powerdown(self, value):
|
||||
self._write_reg_bits(_SYSTEM_CTROL0, 0x40, bool(value))
|
||||
|
||||
def strobe_config(self, enabled, pulse_invert, frex_mode, strobe_mode):
|
||||
# set the FREX mode rolling
|
||||
if frex_mode not in (FREX_MODE_0, FREX_MODE_1, FREX_MODE_ROLL):
|
||||
raise ValueError("Frex mode must be 0, 1 or 2 (rolling)")
|
||||
self._write_register(_FREX_MODE, frex_mode)
|
||||
# set the output pin
|
||||
self._write_register(_PAD_OUTPUT_ENABLE00, 0x2)
|
||||
# set the pulse invert, mode and enable
|
||||
if strobe_mode not in (STROBE_MODE_XENON, STROBE_MODE_LED1, STROBE_MODE_LED2, STROBE_MODE_LED3):
|
||||
raise ValueError("Strobe mode must be 0~3")
|
||||
self._write_register(_STROBE_CTRL,
|
||||
(bool(enabled) << 7) |
|
||||
(bool(pulse_invert) << 6) |
|
||||
(strobe_mode & 0x3))
|
||||
|
||||
#print("strobe reg: ", hex(self._read_register(_STROBE_CTRL)))
|
||||
#print("pad00 reg: ", hex(self._read_register(_PAD_OUTPUT_ENABLE00)))
|
||||
#print("clock00 reg: ", hex(self._read_register(0x3004)))
|
||||
|
||||
@property
|
||||
def strobe_request(self):
|
||||
return bool(self._read_register(_FREX_REQUEST))
|
||||
|
||||
@strobe_request.setter
|
||||
def strobe_request(self, value):
|
||||
self._write_register(_FREX_REQUEST, bool(value))
|
||||
|
||||
@property
|
||||
def strobe_pin(self):
|
||||
return bool(self._read_register(_PAD_OUTPUT_VALUE00))
|
||||
|
||||
@strobe_pin.setter
|
||||
def strobe_pin(self, value):
|
||||
self._write_register(_PAD_OUTPUT_ENABLE00, 0x02)
|
||||
self._write_register(_PAD_SELECT00, 0x02)
|
||||
self._write_register(_PAD_OUTPUT_VALUE00, bool(value) << 1)
|
||||
|
||||
def autofocus_init(self, firmfilename):
|
||||
self._write_register(0x3000, 0x20) # reset
|
||||
with open(firmfilename, mode='rb') as file:
|
||||
firmware = file.read()
|
||||
for addr,val in enumerate(firmware):
|
||||
self._write_register(0x8000+addr, val)
|
||||
|
||||
self._write_list(_autofocus_firmware_load)
|
||||
for _ in range(100):
|
||||
if self.autofocus_status == AUTOFOCUS_STAT_IDLE:
|
||||
break
|
||||
time.sleep(0.01)
|
||||
else:
|
||||
raise RuntimeError("Timed out after trying to load autofocus firmware")
|
||||
return True
|
||||
|
||||
@property
|
||||
def autofocus_status(self):
|
||||
return self._read_register(0x3029)
|
||||
|
||||
def autofocus(self):
|
||||
self._write_register(0x3023, 0x01) # clear command ack
|
||||
self._write_register(0x3022, 0x08) # release focus
|
||||
for _ in range(100):
|
||||
if self._read_register(0x3032) == 0x0: # command is finished
|
||||
break
|
||||
time.sleep(0.01)
|
||||
else:
|
||||
raise RuntimeError("Timed out trying to run autofocus")
|
||||
|
||||
self._write_register(0x3023, 0x01)
|
||||
self._write_register(0x3022, 0x04)
|
||||
for _ in range(100):
|
||||
if self._read_register(0x3032) == 0x0: # command is finished
|
||||
break
|
||||
time.sleep(0.01)
|
||||
else:
|
||||
raise RuntimeError("Timed out trying to run autofocus")
|
||||
|
||||
return True
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
SPDX-FileCopyrightText: 2023 Unknown
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-only
|
||||
33
docs/conf.py
33
docs/conf.py
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
import datetime
|
||||
|
||||
sys.path.insert(0, os.path.abspath(".."))
|
||||
|
||||
|
|
@ -17,7 +16,6 @@ sys.path.insert(0, os.path.abspath(".."))
|
|||
# ones.
|
||||
extensions = [
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinxcontrib.jquery",
|
||||
"sphinx.ext.intersphinx",
|
||||
"sphinx.ext.napoleon",
|
||||
"sphinx.ext.todo",
|
||||
|
|
@ -38,12 +36,12 @@ autodoc_mock_imports = [
|
|||
|
||||
|
||||
intersphinx_mapping = {
|
||||
"python": ("https://docs.python.org/3", None),
|
||||
"python": ("https://docs.python.org/3.4", None),
|
||||
"BusDevice": (
|
||||
"https://docs.circuitpython.org/projects/busdevice/en/latest/",
|
||||
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
|
||||
None,
|
||||
),
|
||||
"CircuitPython": ("https://docs.circuitpython.org/en/latest/", None),
|
||||
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
|
||||
}
|
||||
|
||||
# Show the docstring from both the class and its __init__() method.
|
||||
|
|
@ -59,14 +57,7 @@ master_doc = "index"
|
|||
|
||||
# General information about the project.
|
||||
project = "Adafruit CircuitPython ov5640 Library"
|
||||
creation_year = "2021"
|
||||
current_year = str(datetime.datetime.now().year)
|
||||
year_duration = (
|
||||
current_year
|
||||
if current_year == creation_year
|
||||
else creation_year + " - " + current_year
|
||||
)
|
||||
copyright = year_duration + " Jeff Epler"
|
||||
copyright = "2021 Jeff Epler"
|
||||
author = "Jeff Epler"
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
|
|
@ -83,7 +74,7 @@ release = "1.0"
|
|||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
language = "en"
|
||||
language = None
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
|
|
@ -121,9 +112,19 @@ napoleon_numpy_docstring = False
|
|||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
import sphinx_rtd_theme
|
||||
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
|
||||
|
||||
html_theme = "sphinx_rtd_theme"
|
||||
if not on_rtd: # only import and set the theme if we're building docs locally
|
||||
try:
|
||||
import sphinx_rtd_theme
|
||||
|
||||
html_theme = "sphinx_rtd_theme"
|
||||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
|
||||
except:
|
||||
html_theme = "default"
|
||||
html_theme_path = ["."]
|
||||
else:
|
||||
html_theme_path = ["."]
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
|
|
|
|||
|
|
@ -6,42 +6,3 @@ Ensure your device works with this simple test.
|
|||
.. literalinclude:: ../examples/ov5640_simpletest.py
|
||||
:caption: examples/ov5640_simpletest.py
|
||||
:linenos:
|
||||
|
||||
Directio
|
||||
--------
|
||||
Use an LCD as a viewfinder, bypassing displayio
|
||||
|
||||
.. literalinclude:: ../examples/ov5640_directio_kaluga1_3_ili9341.py
|
||||
:caption: examples/ov5640_directio_kaluga1_3_ili9341.py
|
||||
:linenos:
|
||||
|
||||
JPEG (internal storage)
|
||||
-----------------------
|
||||
Record JPEG images onto internal storage. Requires use of ov5640_jpeg_kaluga1_3_boot.py (below) as boot.py.
|
||||
|
||||
.. literalinclude:: ../examples/ov5640_jpeg_kaluga1_3.py
|
||||
:caption: examples/ov5640_jpeg_kaluga1_3.py
|
||||
:linenos:
|
||||
|
||||
Use with above example as boot.py
|
||||
|
||||
.. literalinclude:: ../examples/ov5640_jpeg_kaluga1_3_boot.py
|
||||
:caption: examples/ov5640_jpeg_kaluga1_3_boot.py
|
||||
:linenos:
|
||||
|
||||
JPEG (SD card)
|
||||
--------------
|
||||
Record JPEG images to an SD card.
|
||||
|
||||
.. literalinclude:: ../examples/ov5640_sdcard_kaluga_1_3.py
|
||||
:caption: examples/ov5640_sdcard_kaluga_1_3.py
|
||||
:linenos:
|
||||
|
||||
GIF (SD card)
|
||||
-------------
|
||||
|
||||
Record stop-motion GIF images to an SD card.
|
||||
|
||||
.. literalinclude:: ../examples/ov5640_stopmotion_kaluga1_3.py
|
||||
:caption: examples/ov5640_stopmotion_kaluga1_3.py
|
||||
:linenos:
|
||||
|
|
|
|||
|
|
@ -34,9 +34,8 @@ Table of Contents
|
|||
.. toctree::
|
||||
:caption: Other Links
|
||||
|
||||
Download from GitHub <https://github.com/adafruit/Adafruit_CircuitPython_ov5640/releases/latest>
|
||||
Download Library Bundle <https://circuitpython.org/libraries>
|
||||
CircuitPython Reference Documentation <https://docs.circuitpython.org>
|
||||
Download <https://github.com/adafruit/Adafruit_CircuitPython_ov5640/releases/latest>
|
||||
CircuitPython Reference Documentation <https://circuitpython.readthedocs.io>
|
||||
CircuitPython Support Forum <https://forums.adafruit.com/viewforum.php?f=60>
|
||||
Discord Chat <https://adafru.it/discord>
|
||||
Adafruit Learning System <https://learn.adafruit.com>
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
sphinx
|
||||
sphinxcontrib-jquery
|
||||
sphinx-rtd-theme
|
||||
|
|
@ -22,8 +22,8 @@ import board
|
|||
import busio
|
||||
import digitalio
|
||||
import displayio
|
||||
from adafruit_ticks import ticks_ms, ticks_less
|
||||
import adafruit_ov5640
|
||||
from adafruit_ticks import ticks_ms, ticks_add, ticks_less
|
||||
|
||||
# Set to True to enable the various effects & exposure modes to be tested
|
||||
test_effects = False
|
||||
|
|
@ -93,8 +93,8 @@ print(len(memoryview(bitmap)))
|
|||
display.auto_refresh = False
|
||||
|
||||
|
||||
def special_modes(cam_obj):
|
||||
def effect_modes(cam_obj):
|
||||
def special_modes(cam):
|
||||
def effect_modes(cam):
|
||||
for i in [
|
||||
"NONE",
|
||||
"NEGATIVE",
|
||||
|
|
@ -105,80 +105,75 @@ def special_modes(cam_obj):
|
|||
"SEPIA",
|
||||
]:
|
||||
print(f"Effect {i}")
|
||||
cam_obj.effect = getattr(adafruit_ov5640, f"OV5640_SPECIAL_EFFECT_{i}")
|
||||
cam.effect = getattr(adafruit_ov5640, f"OV5640_SPECIAL_EFFECT_{i}")
|
||||
yield
|
||||
cam_obj.effect = adafruit_ov5640.OV5640_SPECIAL_EFFECT_NONE
|
||||
cam.effect = adafruit_ov5640.OV5640_SPECIAL_EFFECT_NONE
|
||||
|
||||
def saturation_modes(cam_obj):
|
||||
def saturation_modes(cam):
|
||||
for i in range(-4, 5):
|
||||
print(f"Saturation {i}")
|
||||
cam_obj.saturation = i
|
||||
cam.saturation = i
|
||||
yield
|
||||
cam_obj.saturation = 0
|
||||
cam.saturation = 0
|
||||
|
||||
def brightness_modes(cam_obj):
|
||||
def brightness_modes(cam):
|
||||
for i in range(-4, 5):
|
||||
print(f"Brightness {i}")
|
||||
cam_obj.brightness = i
|
||||
cam.brightness = i
|
||||
yield
|
||||
cam_obj.brightness = 0
|
||||
cam.brightness = 0
|
||||
|
||||
def contrast_modes(cam_obj):
|
||||
def contrast_modes(cam):
|
||||
for i in range(-3, 4):
|
||||
print(f"Contrast {i}")
|
||||
cam_obj.contrast = i
|
||||
cam.contrast = i
|
||||
yield
|
||||
cam_obj.contrast = 0
|
||||
cam.contrast = 0
|
||||
|
||||
def white_balance_modes(cam_obj): # pylint: disable=unused-variable
|
||||
def white_balance_modes(cam):
|
||||
for i in ["AUTO", "SUNNY", "FLUORESCENT", "CLOUDY", "INCANDESCENT"]:
|
||||
print(f"White Balance {i}")
|
||||
cam_obj.white_balance = getattr(
|
||||
adafruit_ov5640, f"OV5640_WHITE_BALANCE_{i}"
|
||||
)
|
||||
cam.white_balance = getattr(adafruit_ov5640, f"OV5640_WHITE_BALANCE_{i}")
|
||||
yield
|
||||
cam_obj.white_balance = adafruit_ov5640.OV5640_WHITE_BALANCE_AUTO
|
||||
cam.white_balance = adafruit_ov5640.OV5640_WHITE_BALANCE_AUTO
|
||||
|
||||
def exposure_value_modes(cam_obj): # pylint: disable=unused-variable
|
||||
def exposure_value_modes(cam):
|
||||
for i in range(-3, 4):
|
||||
print(f"EV {i}")
|
||||
cam_obj.exposure_value = i
|
||||
cam.exposure_value = i
|
||||
yield
|
||||
cam_obj.exposure_value = 0
|
||||
cam.exposure_value = 0
|
||||
|
||||
def nite_modes(cam_obj): # pylint: disable=unused-variable
|
||||
print("Night Mode On")
|
||||
cam_obj.night_mode = True
|
||||
print(cam_obj.night_mode)
|
||||
def nite_modes(cam):
|
||||
print(f"Night Mode On")
|
||||
cam.night_mode = True
|
||||
print(cam.night_mode)
|
||||
yield
|
||||
print("Night Mode Off")
|
||||
cam_obj.night_mode = False
|
||||
print(cam_obj.night_mode)
|
||||
print(f"Night Mode Off")
|
||||
cam.night_mode = False
|
||||
print(cam.night_mode)
|
||||
yield
|
||||
|
||||
def test_modes(cam_obj):
|
||||
def test_modes(cam):
|
||||
print("Test pattern On")
|
||||
cam_obj.test_pattern = True
|
||||
cam.test_pattern = True
|
||||
yield
|
||||
print("Test pattern Off")
|
||||
cam_obj.test_pattern = False
|
||||
cam.test_pattern = False
|
||||
yield
|
||||
|
||||
while True:
|
||||
yield from test_modes(cam_obj)
|
||||
yield from contrast_modes(cam_obj)
|
||||
yield from effect_modes(cam_obj)
|
||||
yield from saturation_modes(cam_obj)
|
||||
yield from brightness_modes(cam_obj)
|
||||
yield from test_modes(cam)
|
||||
yield from contrast_modes(cam)
|
||||
yield from effect_modes(cam)
|
||||
yield from saturation_modes(cam)
|
||||
yield from brightness_modes(cam)
|
||||
# These don't work right (yet)
|
||||
# yield from exposure_value_modes(cam_obj) # Issue #8
|
||||
# yield from nite_modes(cam_obj) # Issue #6
|
||||
# yield from exposure_value_modes(cam) # Issue #8
|
||||
# yield from nite_modes(cam) # Issue #6
|
||||
|
||||
|
||||
def main():
|
||||
deadline = 0
|
||||
effects = iter((None,))
|
||||
|
||||
display.auto_refresh = False
|
||||
display_bus.send(42, struct.pack(">hh", 0, bitmap.width - 1))
|
||||
display_bus.send(43, struct.pack(">hh", 0, bitmap.height - 1))
|
||||
|
|
|
|||
|
|
@ -1,105 +0,0 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2023 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
This demo is designed for the Raspberry Pi Pico and Camera PiCowbell
|
||||
When the shutter is pressed the camera is autofocussed before capturing
|
||||
an image andsaving it to the microSD card.
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import busio
|
||||
import board
|
||||
import digitalio
|
||||
import keypad
|
||||
import sdcardio
|
||||
import storage
|
||||
import adafruit_ov5640
|
||||
|
||||
print("Initializing SD card")
|
||||
sd_spi = busio.SPI(clock=board.GP18, MOSI=board.GP19, MISO=board.GP16)
|
||||
sd_cs = board.GP17
|
||||
sdcard = sdcardio.SDCard(sd_spi, sd_cs)
|
||||
vfs = storage.VfsFat(sdcard)
|
||||
storage.mount(vfs, "/sd")
|
||||
|
||||
print("construct bus")
|
||||
i2c = busio.I2C(board.GP5, board.GP4)
|
||||
print("construct camera")
|
||||
reset = digitalio.DigitalInOut(board.GP14)
|
||||
cam = adafruit_ov5640.OV5640(
|
||||
i2c,
|
||||
data_pins=(
|
||||
board.GP6,
|
||||
board.GP7,
|
||||
board.GP8,
|
||||
board.GP9,
|
||||
board.GP10,
|
||||
board.GP11,
|
||||
board.GP12,
|
||||
board.GP13,
|
||||
),
|
||||
clock=board.GP3,
|
||||
vsync=board.GP0,
|
||||
href=board.GP2,
|
||||
mclk=None,
|
||||
shutdown=None,
|
||||
reset=reset,
|
||||
size=adafruit_ov5640.OV5640_SIZE_VGA,
|
||||
)
|
||||
print("print chip id")
|
||||
print(cam.chip_id)
|
||||
|
||||
keys = keypad.Keys((board.GP22,), value_when_pressed=False, pull=True)
|
||||
|
||||
|
||||
def exists(filename):
|
||||
try:
|
||||
os.stat(filename)
|
||||
return True
|
||||
except OSError as _:
|
||||
return False
|
||||
|
||||
|
||||
_image_counter = 0
|
||||
|
||||
|
||||
def open_next_image():
|
||||
global _image_counter # pylint: disable=global-statement
|
||||
while True:
|
||||
filename = f"/sd/img{_image_counter:04d}.jpg"
|
||||
_image_counter += 1
|
||||
if exists(filename):
|
||||
continue
|
||||
print("# writing to", filename)
|
||||
return open(filename, "wb")
|
||||
|
||||
|
||||
cam.colorspace = adafruit_ov5640.OV5640_COLOR_JPEG
|
||||
cam.quality = 3
|
||||
b = bytearray(cam.capture_buffer_size)
|
||||
|
||||
cam.autofocus()
|
||||
print("AF Status: ", cam.autofocus_status, cam.autofocus_vcm_step)
|
||||
|
||||
jpeg = cam.capture(b)
|
||||
|
||||
while True:
|
||||
shutter = keys.events.get()
|
||||
# event will be None if nothing has happened.
|
||||
if shutter:
|
||||
if shutter.pressed:
|
||||
cam.autofocus()
|
||||
print("AF Status: ", cam.autofocus_status, cam.autofocus_vcm_step)
|
||||
time.sleep(0.01)
|
||||
jpeg = cam.capture(b)
|
||||
print(f"Captured {len(jpeg)} bytes of jpeg data")
|
||||
print(f" (had allocated {cam.capture_buffer_size} bytes")
|
||||
print(f"Resolution {cam.width}x{cam.height}")
|
||||
try:
|
||||
with open_next_image() as f:
|
||||
f.write(jpeg)
|
||||
print("# Wrote image")
|
||||
except OSError as e:
|
||||
print(e)
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2023 Limor Fried for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
"""
|
||||
This demo is designed for the Raspberry Pi Pico and Camera PiCowbell
|
||||
When the shutter is pressed, a prompt is given to enter a step
|
||||
for the focus. Enter a value 0-255 to set the focus or
|
||||
enter a value >255 to execute an autofocus.
|
||||
After the value is input, an image is captured and saved
|
||||
to the microSD card.
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import busio
|
||||
import board
|
||||
import digitalio
|
||||
import keypad
|
||||
import sdcardio
|
||||
import storage
|
||||
import adafruit_ov5640
|
||||
|
||||
print("Initializing SD card")
|
||||
sd_spi = busio.SPI(clock=board.GP18, MOSI=board.GP19, MISO=board.GP16)
|
||||
sd_cs = board.GP17
|
||||
sdcard = sdcardio.SDCard(sd_spi, sd_cs)
|
||||
vfs = storage.VfsFat(sdcard)
|
||||
storage.mount(vfs, "/sd")
|
||||
|
||||
print("construct bus")
|
||||
i2c = busio.I2C(board.GP5, board.GP4)
|
||||
print("construct camera")
|
||||
reset = digitalio.DigitalInOut(board.GP14)
|
||||
cam = adafruit_ov5640.OV5640(
|
||||
i2c,
|
||||
data_pins=(
|
||||
board.GP6,
|
||||
board.GP7,
|
||||
board.GP8,
|
||||
board.GP9,
|
||||
board.GP10,
|
||||
board.GP11,
|
||||
board.GP12,
|
||||
board.GP13,
|
||||
),
|
||||
clock=board.GP3,
|
||||
vsync=board.GP0,
|
||||
href=board.GP2,
|
||||
mclk=None,
|
||||
shutdown=None,
|
||||
reset=reset,
|
||||
size=adafruit_ov5640.OV5640_SIZE_VGA,
|
||||
)
|
||||
print("print chip id")
|
||||
print(cam.chip_id)
|
||||
|
||||
keys = keypad.Keys((board.GP22,), value_when_pressed=False, pull=True)
|
||||
|
||||
|
||||
def exists(filename):
|
||||
try:
|
||||
os.stat(filename)
|
||||
return True
|
||||
except OSError as _:
|
||||
return False
|
||||
|
||||
|
||||
_image_counter = 0
|
||||
|
||||
|
||||
def open_next_image():
|
||||
global _image_counter # pylint: disable=global-statement
|
||||
while True:
|
||||
filename = f"/sd/img{_image_counter:04d}.jpg"
|
||||
_image_counter += 1
|
||||
if exists(filename):
|
||||
continue
|
||||
print("# writing to", filename)
|
||||
return open(filename, "wb")
|
||||
|
||||
|
||||
cam.colorspace = adafruit_ov5640.OV5640_COLOR_JPEG
|
||||
cam.quality = 3
|
||||
b = bytearray(cam.capture_buffer_size)
|
||||
|
||||
cam.autofocus()
|
||||
print("AF Status: ", cam.autofocus_status, cam.autofocus_vcm_step)
|
||||
|
||||
jpeg = cam.capture(b)
|
||||
|
||||
while True:
|
||||
shutter = keys.events.get()
|
||||
# event will be None if nothing has happened.
|
||||
if shutter:
|
||||
if shutter.pressed:
|
||||
"""Captures an image and send it to Adafruit IO."""
|
||||
step = int(input("enter AF step:"))
|
||||
if step > 255:
|
||||
# Force autofocus and capture a JPEG image
|
||||
cam.autofocus()
|
||||
print("AF Status: ", cam.autofocus_status, cam.autofocus_vcm_step)
|
||||
else:
|
||||
cam.autofocus_vcm_step = step
|
||||
print("AF Status: ", cam.autofocus_status, cam.autofocus_vcm_step)
|
||||
time.sleep(0.01)
|
||||
jpeg = cam.capture(b)
|
||||
print(f"Captured {len(jpeg)} bytes of jpeg data")
|
||||
print(f" (had allocated {cam.capture_buffer_size} bytes")
|
||||
print(f"Resolution {cam.width}x{cam.height}")
|
||||
try:
|
||||
with open_next_image() as f:
|
||||
f.write(jpeg)
|
||||
print("# Wrote image")
|
||||
except OSError as e:
|
||||
print(e)
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2023 Lady Ada for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
"""Capture an image from the camera and display it as ASCII art.
|
||||
|
||||
This demo is designed to run on the Raspberry Pi Pico, but you can adapt it
|
||||
to other boards by changing the constructors for `bus` and `cam`
|
||||
appropriately.
|
||||
|
||||
The camera is placed in YUV mode, so the top 8 bits of each color
|
||||
value can be treated as "greyscale".
|
||||
|
||||
It's important that you use a terminal program that can interpret
|
||||
"ANSI" escape sequences. The demo uses them to "paint" each frame
|
||||
on top of the previous one, rather than scrolling.
|
||||
|
||||
Remember to take the lens cap off!
|
||||
"""
|
||||
import sys
|
||||
import time
|
||||
import busio
|
||||
import board
|
||||
import digitalio
|
||||
import adafruit_ov5640
|
||||
|
||||
print("construct bus")
|
||||
bus = busio.I2C(board.GP9, board.GP8)
|
||||
print("construct camera")
|
||||
reset = digitalio.DigitalInOut(board.GP10)
|
||||
cam = adafruit_ov5640.OV5640(
|
||||
bus,
|
||||
data_pins=(
|
||||
board.GP12,
|
||||
board.GP13,
|
||||
board.GP14,
|
||||
board.GP15,
|
||||
board.GP16,
|
||||
board.GP17,
|
||||
board.GP18,
|
||||
board.GP19,
|
||||
), # [16] [org]
|
||||
clock=board.GP11, # [15] [blk]
|
||||
vsync=board.GP7, # [10] [brn]
|
||||
href=board.GP21, # [27/o14] [red]
|
||||
mclk=board.GP20, # [16/o15]
|
||||
shutdown=None,
|
||||
reset=reset,
|
||||
size=adafruit_ov5640.OV5640_SIZE_QQVGA,
|
||||
)
|
||||
print("print chip id")
|
||||
print(cam.chip_id)
|
||||
|
||||
|
||||
cam.colorspace = adafruit_ov5640.OV5640_COLOR_YUV
|
||||
cam.flip_y = True
|
||||
cam.flip_x = True
|
||||
cam.test_pattern = False
|
||||
|
||||
buf = bytearray(cam.capture_buffer_size)
|
||||
chars = b" .':-+=*%$#"
|
||||
remap = [chars[i * (len(chars) - 1) // 255] for i in range(256)]
|
||||
|
||||
width = cam.width
|
||||
row = bytearray(width)
|
||||
|
||||
print("capturing")
|
||||
cam.capture(buf)
|
||||
print("capture complete")
|
||||
|
||||
sys.stdout.write("\033[2J")
|
||||
while True:
|
||||
cam.capture(buf)
|
||||
for j in range(0, cam.height, 2):
|
||||
sys.stdout.write(f"\033[{j//2}H")
|
||||
for i in range(cam.width):
|
||||
row[i] = remap[buf[2 * (width * j + i)]]
|
||||
sys.stdout.write(row)
|
||||
sys.stdout.write("\033[K")
|
||||
sys.stdout.write("\033[J")
|
||||
time.sleep(0.1)
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2023 Lady Ada for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
"""Capture an images from the camera and display on a ST7789 with
|
||||
displayio.
|
||||
|
||||
This demo is designed to run on the Raspberry Pi Pico, but you can adapt it
|
||||
to other boards by changing the constructors for `bus` and `cam`
|
||||
appropriately.
|
||||
|
||||
Remember to take the lens cap off!
|
||||
"""
|
||||
import time
|
||||
from adafruit_ov7670 import OV7670, OV7670_SIZE_DIV1, OV7670_SIZE_DIV16
|
||||
from displayio import (
|
||||
Bitmap,
|
||||
Group,
|
||||
TileGrid,
|
||||
FourWire,
|
||||
release_displays,
|
||||
ColorConverter,
|
||||
Colorspace,
|
||||
)
|
||||
from adafruit_st7789 import ST7789
|
||||
import board
|
||||
import busio
|
||||
import digitalio
|
||||
|
||||
# Set up the display (You must customize this block for your display!)
|
||||
release_displays()
|
||||
spi = busio.SPI(clock=board.GP2, MOSI=board.GP3)
|
||||
display_bus = FourWire(spi, command=board.GP0, chip_select=board.GP1, reset=None)
|
||||
display = ST7789(display_bus, width=240, height=240, rowstart=80, rotation=270)
|
||||
|
||||
|
||||
# Ensure the camera is shut down, so that it releases the SDA/SCL lines,
|
||||
# then create the configuration I2C bus
|
||||
|
||||
with digitalio.DigitalInOut(board.GP10) as reset:
|
||||
reset.switch_to_output(False)
|
||||
time.sleep(0.001)
|
||||
bus = busio.I2C(board.GP9, board.GP8)
|
||||
|
||||
# Set up the camera (you must customize this for your board!)
|
||||
cam = OV7670(
|
||||
bus,
|
||||
data0=board.GP12, # [16] [org]
|
||||
clock=board.GP11, # [15] [blk]
|
||||
vsync=board.GP7, # [10] [brn]
|
||||
href=board.GP21, # [27/o14] [red]
|
||||
mclk=board.GP20, # [16/o15]
|
||||
shutdown=None,
|
||||
reset=board.GP10,
|
||||
) # [14]
|
||||
|
||||
width = display.width
|
||||
height = display.height
|
||||
|
||||
# cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR_FADE
|
||||
bitmap = None
|
||||
# Select the biggest size for which we can allocate a bitmap successfully, and
|
||||
# which is not bigger than the display
|
||||
for size in range(OV7670_SIZE_DIV1, OV7670_SIZE_DIV16 + 1):
|
||||
cam.size = size
|
||||
if cam.width > width:
|
||||
continue
|
||||
if cam.height > height:
|
||||
continue
|
||||
try:
|
||||
bitmap = Bitmap(cam.width, cam.height, 65535)
|
||||
break
|
||||
except MemoryError:
|
||||
continue
|
||||
|
||||
print(width, height, cam.width, cam.height)
|
||||
if bitmap is None:
|
||||
raise SystemExit("Could not allocate a bitmap")
|
||||
|
||||
g = Group(scale=1, x=(width - cam.width) // 2, y=(height - cam.height) // 2)
|
||||
tg = TileGrid(
|
||||
bitmap, pixel_shader=ColorConverter(input_colorspace=Colorspace.RGB565_SWAPPED)
|
||||
)
|
||||
g.append(tg)
|
||||
display.root_group = g
|
||||
|
||||
t0 = time.monotonic_ns()
|
||||
display.auto_refresh = False
|
||||
while True:
|
||||
cam.capture(bitmap)
|
||||
bitmap.dirty()
|
||||
display.refresh(minimum_frames_per_second=0)
|
||||
t1 = time.monotonic_ns()
|
||||
print("fps", 1e9 / (t1 - t0))
|
||||
t0 = t1
|
||||
|
|
@ -1,268 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
"""
|
||||
Take a 10-frame stop motion GIF image.
|
||||
|
||||
This example requires:
|
||||
* `Espressif Kaluga v1.3 <https://www.adafruit.com/product/4729>`_ with compatible LCD display
|
||||
* `MicroSD card breakout board + <https://www.adafruit.com/product/254>`_ connected as follows:
|
||||
* CLK to board.IO18
|
||||
* DI to board.IO14
|
||||
* DO to board.IO17
|
||||
* CS to IO12
|
||||
* GND to GND
|
||||
* 5V to 5V
|
||||
* A compatible SD card inserted in the SD card slot
|
||||
* A compatible OV5640 camera module connected to the camera header
|
||||
|
||||
To use:
|
||||
|
||||
Insert an SD card and power on.
|
||||
|
||||
Set up the first frame using the viewfinder. Click the REC button to take a frame.
|
||||
|
||||
Set up the next frame using the viewfinder. The previous and current frames are
|
||||
blended together on the display, which is called an "onionskin". Click the REC
|
||||
button to take the next frame.
|
||||
|
||||
After 10 frames are recorded, the GIF is complete and you can begin recording another.
|
||||
|
||||
|
||||
About the Kaluga development kit:
|
||||
|
||||
The Kaluga development kit comes in two versions (v1.2 and v1.3); this demo is
|
||||
tested on v1.3.
|
||||
|
||||
The audio board must be mounted between the Kaluga and the LCD, it provides the
|
||||
I2C pull-ups(!)
|
||||
|
||||
The v1.3 development kit's LCD can have one of two chips, the ili9341 or
|
||||
st7789. Furthermore, there are at least 2 ILI9341 variants, which differ
|
||||
by rotation. This example is written for one if the ILI9341 variants,
|
||||
the one which usually uses rotation=90 to get a landscape display.
|
||||
"""
|
||||
|
||||
import os
|
||||
import struct
|
||||
|
||||
import analogio
|
||||
import bitmaptools
|
||||
import board
|
||||
import busio
|
||||
import displayio
|
||||
import gifio
|
||||
import sdcardio
|
||||
import storage
|
||||
|
||||
import adafruit_ov5640
|
||||
|
||||
V_RECORD = int(2.41 * 65536 / 3.3)
|
||||
V_FUZZ = 2000
|
||||
|
||||
a = analogio.AnalogIn(board.IO6)
|
||||
|
||||
|
||||
def record_pressed():
|
||||
value = a.value
|
||||
return abs(value - V_RECORD) < V_FUZZ
|
||||
|
||||
|
||||
displayio.release_displays()
|
||||
spi = busio.SPI(MOSI=board.LCD_MOSI, clock=board.LCD_CLK)
|
||||
display_bus = displayio.FourWire(
|
||||
spi,
|
||||
command=board.LCD_D_C,
|
||||
chip_select=board.LCD_CS,
|
||||
reset=board.LCD_RST,
|
||||
baudrate=80_000_000,
|
||||
)
|
||||
_INIT_SEQUENCE = (
|
||||
b"\x01\x80\x80" # Software reset then delay 0x80 (128ms)
|
||||
b"\xEF\x03\x03\x80\x02"
|
||||
b"\xCF\x03\x00\xC1\x30"
|
||||
b"\xED\x04\x64\x03\x12\x81"
|
||||
b"\xE8\x03\x85\x00\x78"
|
||||
b"\xCB\x05\x39\x2C\x00\x34\x02"
|
||||
b"\xF7\x01\x20"
|
||||
b"\xEA\x02\x00\x00"
|
||||
b"\xc0\x01\x23" # Power control VRH[5:0]
|
||||
b"\xc1\x01\x10" # Power control SAP[2:0];BT[3:0]
|
||||
b"\xc5\x02\x3e\x28" # VCM control
|
||||
b"\xc7\x01\x86" # VCM control2
|
||||
b"\x36\x01\x40" # Memory Access Control
|
||||
b"\x37\x01\x00" # Vertical scroll zero
|
||||
b"\x3a\x01\x55" # COLMOD: Pixel Format Set
|
||||
b"\xb1\x02\x00\x18" # Frame Rate Control (In Normal Mode/Full Colors)
|
||||
b"\xb6\x03\x08\x82\x27" # Display Function Control
|
||||
b"\xF2\x01\x00" # 3Gamma Function Disable
|
||||
b"\x26\x01\x01" # Gamma curve selected
|
||||
b"\xe0\x0f\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00" # Set Gamma
|
||||
b"\xe1\x0f\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F" # Set Gamma
|
||||
b"\x11\x80\x78" # Exit Sleep then delay 0x78 (120ms)
|
||||
b"\x29\x80\x78" # Display on then delay 0x78 (120ms)
|
||||
)
|
||||
|
||||
display = displayio.Display(display_bus, _INIT_SEQUENCE, width=320, height=240)
|
||||
|
||||
sd_spi = busio.SPI(clock=board.IO18, MOSI=board.IO14, MISO=board.IO17)
|
||||
sd_cs = board.IO12
|
||||
sdcard = sdcardio.SDCard(sd_spi, sd_cs, baudrate=24_000_000)
|
||||
vfs = storage.VfsFat(sdcard)
|
||||
storage.mount(vfs, "/sd")
|
||||
|
||||
bus = busio.I2C(scl=board.CAMERA_SIOC, sda=board.CAMERA_SIOD)
|
||||
cam = adafruit_ov5640.OV5640(
|
||||
bus,
|
||||
data_pins=board.CAMERA_DATA,
|
||||
clock=board.CAMERA_PCLK,
|
||||
vsync=board.CAMERA_VSYNC,
|
||||
href=board.CAMERA_HREF,
|
||||
mclk=board.CAMERA_XCLK,
|
||||
size=adafruit_ov5640.OV5640_SIZE_240X240,
|
||||
)
|
||||
|
||||
|
||||
def exists(filename):
|
||||
try:
|
||||
os.stat(filename)
|
||||
return True
|
||||
except OSError as _:
|
||||
return False
|
||||
|
||||
|
||||
_image_counter = 0
|
||||
|
||||
|
||||
def next_filename(extension="jpg"):
|
||||
global _image_counter # pylint: disable=global-statement
|
||||
while True:
|
||||
filename = f"/sd/img{_image_counter:04d}.{extension}"
|
||||
if exists(filename):
|
||||
print(f"File exists: {filename}", end="\r")
|
||||
_image_counter += 1
|
||||
continue
|
||||
print()
|
||||
return filename
|
||||
|
||||
|
||||
# Pre-cache the next image number
|
||||
next_filename("gif")
|
||||
|
||||
# Blank the whole display, we'll draw what we want with directio
|
||||
empty_group = displayio.Group()
|
||||
display.root_group = empty_group
|
||||
display.auto_refresh = False
|
||||
display.refresh()
|
||||
|
||||
|
||||
def open_next_image(extension="jpg"):
|
||||
while True:
|
||||
filename = next_filename(extension)
|
||||
print("# writing to", filename)
|
||||
return open(filename, "wb")
|
||||
|
||||
|
||||
cam.flip_x = False
|
||||
cam.flip_y = False
|
||||
chip_id = cam.chip_id
|
||||
print(f"Detected 0x{chip_id:x}")
|
||||
cam.test_pattern = False
|
||||
cam.effect = adafruit_ov5640.OV5640_SPECIAL_EFFECT_NONE
|
||||
cam.saturation = 3
|
||||
|
||||
# Alternately recording to these two bitmaps
|
||||
rec1 = displayio.Bitmap(cam.width, cam.height, 65536)
|
||||
rec2 = displayio.Bitmap(cam.width, cam.height, 65536)
|
||||
# Prior frame kept here
|
||||
old_frame = displayio.Bitmap(cam.width, cam.height, 65536)
|
||||
# Displayed (onion skinned) frame here
|
||||
onionskin = displayio.Bitmap(cam.width, cam.height, 65536)
|
||||
|
||||
ow = (display.width - onionskin.width) // 2
|
||||
oh = (display.height - onionskin.height) // 2
|
||||
display_bus.send(42, struct.pack(">hh", ow, onionskin.width + ow - 1))
|
||||
display_bus.send(43, struct.pack(">hh", oh, onionskin.height + ow - 1))
|
||||
|
||||
|
||||
class ContinuousCapture:
|
||||
def __init__(self, camera, buffer1, buffer2):
|
||||
camera = getattr(camera, "_imagecapture", camera)
|
||||
self._camera = camera
|
||||
print("buffer1", buffer1)
|
||||
print("buffer2", buffer2)
|
||||
camera.continuous_capture_start(buffer1, buffer2)
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self._camera.continuous_capture_stop()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def get_frame(self):
|
||||
return self._camera.continuous_capture_get_frame()
|
||||
|
||||
__next__ = get_frame
|
||||
|
||||
|
||||
def wait_record_pressed_update_display(first_frame, cap):
|
||||
while record_pressed():
|
||||
pass
|
||||
while True:
|
||||
frame = cap.get_frame()
|
||||
if record_pressed():
|
||||
return frame
|
||||
|
||||
if first_frame:
|
||||
# First frame -- display as-is
|
||||
display_bus.send(44, frame)
|
||||
else:
|
||||
bitmaptools.alphablend(
|
||||
onionskin, old_frame, frame, displayio.Colorspace.RGB565_SWAPPED
|
||||
)
|
||||
display_bus.send(44, onionskin)
|
||||
|
||||
|
||||
def take_stop_motion_gif(n_frames=10, replay_frame_time=0.3):
|
||||
print(f"0/{n_frames}")
|
||||
with ContinuousCapture(cam, rec1, rec2) as cap:
|
||||
frame = wait_record_pressed_update_display(True, cap)
|
||||
with open_next_image("gif") as f, gifio.GifWriter(
|
||||
f, cam.width, cam.height, displayio.Colorspace.RGB565_SWAPPED, dither=True
|
||||
) as g:
|
||||
g.add_frame(frame, replay_frame_time)
|
||||
for i in range(1, n_frames):
|
||||
print(f"{i}/{n_frames}")
|
||||
|
||||
# CircuitPython Versions <= 8.2.0
|
||||
if hasattr(old_frame, "blit"):
|
||||
old_frame.blit(
|
||||
0, 0, frame, x1=0, y1=0, x2=frame.width, y2=frame.height
|
||||
)
|
||||
|
||||
# CircuitPython Versions >= 9.0.0
|
||||
else:
|
||||
bitmaptools.blit(
|
||||
old_frame,
|
||||
frame,
|
||||
0,
|
||||
0,
|
||||
x1=0,
|
||||
y1=0,
|
||||
x2=frame.width,
|
||||
y2=frame.height,
|
||||
)
|
||||
|
||||
frame = wait_record_pressed_update_display(False, cap)
|
||||
g.add_frame(frame, replay_frame_time)
|
||||
print("done")
|
||||
|
||||
|
||||
est_frame_size = cam.width * cam.height * 128 // 126 + 1
|
||||
est_hdr_size = 1000
|
||||
|
||||
dither = True
|
||||
while True:
|
||||
take_stop_motion_gif()
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
|
@ -1,45 +1,6 @@
|
|||
# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
[build-system]
|
||||
requires = [
|
||||
"setuptools",
|
||||
"wheel",
|
||||
"setuptools-scm",
|
||||
]
|
||||
|
||||
[project]
|
||||
name = "adafruit-circuitpython-ov5640"
|
||||
description = "CircuitPython driver for OV5640 Camera"
|
||||
version = "0.0.0+auto.0"
|
||||
readme = "README.rst"
|
||||
authors = [
|
||||
{name = "Adafruit Industries", email = "circuitpython@adafruit.com"}
|
||||
]
|
||||
urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_OV5640"}
|
||||
keywords = [
|
||||
"adafruit",
|
||||
"ov5640",
|
||||
"camera",
|
||||
"breakout",
|
||||
"hardware",
|
||||
"micropythoncircuitpython",
|
||||
]
|
||||
license = {text = "MIT"}
|
||||
classifiers = [
|
||||
"Intended Audience :: Developers",
|
||||
"Topic :: Software Development :: Libraries",
|
||||
"Topic :: Software Development :: Embedded Systems",
|
||||
"Topic :: System :: Hardware",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Programming Language :: Python :: 3",
|
||||
]
|
||||
dynamic = ["dependencies", "optional-dependencies"]
|
||||
|
||||
[tool.setuptools]
|
||||
packages = ["adafruit_ov5640"]
|
||||
|
||||
[tool.setuptools.dynamic]
|
||||
dependencies = {file = ["requirements.txt"]}
|
||||
optional-dependencies = {optional = {file = ["optional_requirements.txt"]}}
|
||||
[tool.black]
|
||||
target-version = ['py35']
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
Adafruit-Blinka
|
||||
adafruit-circuitpython-busdevice
|
||||
|
|
|
|||
9
setup.py.disabled
Normal file
9
setup.py.disabled
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
||||
# SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""
|
||||
This library is not deployed to PyPI. It is either a board-specific helper library, or
|
||||
does not make sense for use on or is incompatible with single board computers and Linux.
|
||||
"""
|
||||
Loading…
Reference in a new issue