Migrate library to MicroPython compatibility
Changes include adapting codebases for I2C, SPI, and UART modules to work with MicroPython's machine library. Removed references to CircuitPython-specific libraries and updated configurations for Pin and UART initialization. Simplified import statements and replaced ReadableBuffer type hints with MicroPython's bytes and bytearray types. This migration targets increased accessibility for MicroPython users, ensuring broader hardware support while maintaining core RFID/NFC functionalities. Adjustments also involve file structure and documentation revisions to reflect the MicroPython focus.
This commit is contained in:
parent
8c121f7a54
commit
ef5c8c4a1d
19 changed files with 63 additions and 887 deletions
|
@ -1,13 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2021 Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs
|
|
||||||
|
|
||||||
Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code
|
|
||||||
|
|
||||||
Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues.
|
|
14
.github/workflows/build.yml
vendored
14
.github/workflows/build.yml
vendored
|
@ -1,14 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
name: Build CI
|
|
||||||
|
|
||||||
on: [pull_request, push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Run Build CI workflow
|
|
||||||
uses: adafruit/workflows-circuitpython-libs/build@main
|
|
19
.github/workflows/failure-help-text.yml
vendored
19
.github/workflows/failure-help-text.yml
vendored
|
@ -1,19 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
name: Failure help text
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_run:
|
|
||||||
workflows: ["Build CI"]
|
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
post-help:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }}
|
|
||||||
steps:
|
|
||||||
- name: Post comment to help
|
|
||||||
uses: adafruit/circuitpython-action-library-ci-failed@v1
|
|
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 }}
|
|
|
@ -1,42 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Unlicense
|
|
||||||
|
|
||||||
repos:
|
|
||||||
- repo: https://github.com/python/black
|
|
||||||
rev: 23.3.0
|
|
||||||
hooks:
|
|
||||||
- id: black
|
|
||||||
- repo: https://github.com/fsfe/reuse-tool
|
|
||||||
rev: v1.1.2
|
|
||||||
hooks:
|
|
||||||
- id: reuse
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
||||||
rev: v4.4.0
|
|
||||||
hooks:
|
|
||||||
- id: check-yaml
|
|
||||||
- id: end-of-file-fixer
|
|
||||||
- id: trailing-whitespace
|
|
||||||
- repo: https://github.com/pycqa/pylint
|
|
||||||
rev: v2.17.4
|
|
||||||
hooks:
|
|
||||||
- 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)
|
|
||||||
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)
|
|
||||||
description: Run pylint rules on "tests/*.py" files
|
|
||||||
types: [python]
|
|
||||||
files: "^tests/"
|
|
||||||
args:
|
|
||||||
- --disable=missing-docstring,consider-using-f-string,duplicate-code
|
|
399
.pylintrc
399
.pylintrc
|
@ -1,399 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Unlicense
|
|
||||||
|
|
||||||
[MASTER]
|
|
||||||
|
|
||||||
# A comma-separated list of package or module names from where C extensions may
|
|
||||||
# be loaded. Extensions are loading into the active Python interpreter and may
|
|
||||||
# run arbitrary code
|
|
||||||
extension-pkg-whitelist=
|
|
||||||
|
|
||||||
# Add files or directories to the ignore-list. They should be base names, not
|
|
||||||
# paths.
|
|
||||||
ignore=CVS
|
|
||||||
|
|
||||||
# Add files or directories matching the regex patterns to the ignore-list. The
|
|
||||||
# regex matches against base names, not paths.
|
|
||||||
ignore-patterns=
|
|
||||||
|
|
||||||
# Python code to execute, usually for sys.path manipulation such as
|
|
||||||
# pygtk.require().
|
|
||||||
#init-hook=
|
|
||||||
|
|
||||||
# Use multiple processes to speed up Pylint.
|
|
||||||
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
|
|
||||||
|
|
||||||
# Pickle collected data for later comparisons.
|
|
||||||
persistent=yes
|
|
||||||
|
|
||||||
# Specify a configuration file.
|
|
||||||
#rcfile=
|
|
||||||
|
|
||||||
# Allow loading of arbitrary C extensions. Extensions are imported into the
|
|
||||||
# active Python interpreter and may run arbitrary code.
|
|
||||||
unsafe-load-any-extension=no
|
|
||||||
|
|
||||||
|
|
||||||
[MESSAGES CONTROL]
|
|
||||||
|
|
||||||
# Only show warnings with the listed confidence levels. Leave empty to show
|
|
||||||
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
|
|
||||||
confidence=
|
|
||||||
|
|
||||||
# Disable the message, report, category or checker with the given id(s). You
|
|
||||||
# can either give multiple identifiers separated by comma (,) or put this
|
|
||||||
# option multiple times (only on the command line, not in the configuration
|
|
||||||
# file where it should appear only once).You can also use "--disable=all" to
|
|
||||||
# disable everything first and then reenable specific checks. For example, if
|
|
||||||
# you want to run only the similarities checker, you can use "--disable=all
|
|
||||||
# --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
|
|
||||||
|
|
||||||
# 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
|
|
||||||
# multiple time (only on the command line, not in the configuration file where
|
|
||||||
# it should appear only once). See also the "--disable" option for examples.
|
|
||||||
enable=
|
|
||||||
|
|
||||||
|
|
||||||
[REPORTS]
|
|
||||||
|
|
||||||
# Python expression which should return a note less than 10 (10 is the highest
|
|
||||||
# note). You have access to the variables errors warning, statement which
|
|
||||||
# respectively contain the number of errors / warnings messages and the total
|
|
||||||
# number of statements analyzed. This is used by the global evaluation report
|
|
||||||
# (RP0004).
|
|
||||||
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
|
|
||||||
|
|
||||||
# Template used to display messages. This is a python new-style format string
|
|
||||||
# used to format the message information. See doc for all details
|
|
||||||
#msg-template=
|
|
||||||
|
|
||||||
# Set the output format. Available formats are text, parseable, colorized, json
|
|
||||||
# and msvs (visual studio).You can also give a reporter class, eg
|
|
||||||
# mypackage.mymodule.MyReporterClass.
|
|
||||||
output-format=text
|
|
||||||
|
|
||||||
# Tells whether to display a full report or only the messages
|
|
||||||
reports=no
|
|
||||||
|
|
||||||
# Activate the evaluation score.
|
|
||||||
score=yes
|
|
||||||
|
|
||||||
|
|
||||||
[REFACTORING]
|
|
||||||
|
|
||||||
# Maximum number of nested blocks for function / method body
|
|
||||||
max-nested-blocks=5
|
|
||||||
|
|
||||||
|
|
||||||
[LOGGING]
|
|
||||||
|
|
||||||
# Logging modules to check that the string format arguments are in logging
|
|
||||||
# function parameter format
|
|
||||||
logging-modules=logging
|
|
||||||
|
|
||||||
|
|
||||||
[SPELLING]
|
|
||||||
|
|
||||||
# Spelling dictionary name. Available dictionaries: none. To make it working
|
|
||||||
# install python-enchant package.
|
|
||||||
spelling-dict=
|
|
||||||
|
|
||||||
# List of comma separated words that should not be checked.
|
|
||||||
spelling-ignore-words=
|
|
||||||
|
|
||||||
# A path to a file that contains private dictionary; one word per line.
|
|
||||||
spelling-private-dict-file=
|
|
||||||
|
|
||||||
# Tells whether to store unknown words to indicated private dictionary in
|
|
||||||
# --spelling-private-dict-file option instead of raising a message.
|
|
||||||
spelling-store-unknown-words=no
|
|
||||||
|
|
||||||
|
|
||||||
[MISCELLANEOUS]
|
|
||||||
|
|
||||||
# List of note tags to take in consideration, separated by a comma.
|
|
||||||
# notes=FIXME,XXX,TODO
|
|
||||||
notes=FIXME,XXX
|
|
||||||
|
|
||||||
|
|
||||||
[TYPECHECK]
|
|
||||||
|
|
||||||
# List of decorators that produce context managers, such as
|
|
||||||
# contextlib.contextmanager. Add to this list to register other decorators that
|
|
||||||
# produce valid context managers.
|
|
||||||
contextmanager-decorators=contextlib.contextmanager
|
|
||||||
|
|
||||||
# List of members which are set dynamically and missed by pylint inference
|
|
||||||
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
|
||||||
# expressions are accepted.
|
|
||||||
generated-members=
|
|
||||||
|
|
||||||
# Tells whether missing members accessed in mixin class should be ignored. A
|
|
||||||
# mixin class is detected if its name ends with "mixin" (case insensitive).
|
|
||||||
ignore-mixin-members=yes
|
|
||||||
|
|
||||||
# This flag controls whether pylint should warn about no-member and similar
|
|
||||||
# checks whenever an opaque object is returned when inferring. The inference
|
|
||||||
# can return multiple potential results while evaluating a Python object, but
|
|
||||||
# some branches might not be evaluated, which results in partial inference. In
|
|
||||||
# that case, it might be useful to still emit no-member and other checks for
|
|
||||||
# the rest of the inferred objects.
|
|
||||||
ignore-on-opaque-inference=yes
|
|
||||||
|
|
||||||
# List of class names for which member attributes should not be checked (useful
|
|
||||||
# for classes with dynamically set attributes). This supports the use of
|
|
||||||
# qualified names.
|
|
||||||
ignored-classes=optparse.Values,thread._local,_thread._local
|
|
||||||
|
|
||||||
# List of module names for which member attributes should not be checked
|
|
||||||
# (useful for modules/projects where namespaces are manipulated during runtime
|
|
||||||
# and thus existing member attributes cannot be deduced by static analysis. It
|
|
||||||
# supports qualified module names, as well as Unix pattern matching.
|
|
||||||
ignored-modules=board
|
|
||||||
|
|
||||||
# Show a hint with possible names when a member name was not found. The aspect
|
|
||||||
# of finding the hint is based on edit distance.
|
|
||||||
missing-member-hint=yes
|
|
||||||
|
|
||||||
# The minimum edit distance a name should have in order to be considered a
|
|
||||||
# similar match for a missing member name.
|
|
||||||
missing-member-hint-distance=1
|
|
||||||
|
|
||||||
# The total number of similar names that should be taken in consideration when
|
|
||||||
# showing a hint for a missing member.
|
|
||||||
missing-member-max-choices=1
|
|
||||||
|
|
||||||
|
|
||||||
[VARIABLES]
|
|
||||||
|
|
||||||
# List of additional names supposed to be defined in builtins. Remember that
|
|
||||||
# you should avoid to define new builtins when possible.
|
|
||||||
additional-builtins=
|
|
||||||
|
|
||||||
# Tells whether unused global variables should be treated as a violation.
|
|
||||||
allow-global-unused-variables=yes
|
|
||||||
|
|
||||||
# List of strings which can identify a callback function by name. A callback
|
|
||||||
# name must start or end with one of those strings.
|
|
||||||
callbacks=cb_,_cb
|
|
||||||
|
|
||||||
# A regular expression matching the name of dummy variables (i.e. expectedly
|
|
||||||
# not used).
|
|
||||||
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
|
|
||||||
|
|
||||||
# Argument names that match this expression will be ignored. Default to name
|
|
||||||
# with leading underscore
|
|
||||||
ignored-argument-names=_.*|^ignored_|^unused_
|
|
||||||
|
|
||||||
# Tells whether we should check for unused import in __init__ files.
|
|
||||||
init-import=no
|
|
||||||
|
|
||||||
# List of qualified module names which can have objects that can redefine
|
|
||||||
# builtins.
|
|
||||||
redefining-builtins-modules=six.moves,future.builtins
|
|
||||||
|
|
||||||
|
|
||||||
[FORMAT]
|
|
||||||
|
|
||||||
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
|
|
||||||
# expected-line-ending-format=
|
|
||||||
expected-line-ending-format=LF
|
|
||||||
|
|
||||||
# Regexp for a line that is allowed to be longer than the limit.
|
|
||||||
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
|
|
||||||
|
|
||||||
# Number of spaces of indent required inside a hanging or continued line.
|
|
||||||
indent-after-paren=4
|
|
||||||
|
|
||||||
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
|
||||||
# tab).
|
|
||||||
indent-string=' '
|
|
||||||
|
|
||||||
# Maximum number of characters on a single line.
|
|
||||||
max-line-length=100
|
|
||||||
|
|
||||||
# Maximum number of lines in a module
|
|
||||||
max-module-lines=1000
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Allow the body of an if to be on the same line as the test if there is no
|
|
||||||
# else.
|
|
||||||
single-line-if-stmt=no
|
|
||||||
|
|
||||||
|
|
||||||
[SIMILARITIES]
|
|
||||||
|
|
||||||
# Ignore comments when computing similarities.
|
|
||||||
ignore-comments=yes
|
|
||||||
|
|
||||||
# Ignore docstrings when computing similarities.
|
|
||||||
ignore-docstrings=yes
|
|
||||||
|
|
||||||
# Ignore imports when computing similarities.
|
|
||||||
ignore-imports=yes
|
|
||||||
|
|
||||||
# Minimum lines number of a similarity.
|
|
||||||
min-similarity-lines=12
|
|
||||||
|
|
||||||
|
|
||||||
[BASIC]
|
|
||||||
|
|
||||||
# Regular expression matching correct argument names
|
|
||||||
argument-rgx=(([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
|
|
||||||
|
|
||||||
# Regular expression matching correct class attribute names
|
|
||||||
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
|
||||||
|
|
||||||
# Regular expression matching correct class names
|
|
||||||
# class-rgx=[A-Z_][a-zA-Z0-9]+$
|
|
||||||
class-rgx=[A-Z_][a-zA-Z0-9_]+$
|
|
||||||
|
|
||||||
# Regular expression matching correct constant names
|
|
||||||
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
|
||||||
|
|
||||||
# Minimum line length for functions/classes that require docstrings, shorter
|
|
||||||
# ones are exempt.
|
|
||||||
docstring-min-length=-1
|
|
||||||
|
|
||||||
# Regular expression matching correct function names
|
|
||||||
function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Good variable names which should always be accepted, separated by a comma
|
|
||||||
# good-names=i,j,k,ex,Run,_
|
|
||||||
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
|
|
||||||
|
|
||||||
# Regular expression matching correct inline iteration names
|
|
||||||
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
|
|
||||||
|
|
||||||
# Regular expression matching correct method names
|
|
||||||
method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
# Regular expression matching correct module names
|
|
||||||
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
|
||||||
|
|
||||||
# Colon-delimited sets of names that determine each other's naming style when
|
|
||||||
# the name regexes allow several styles.
|
|
||||||
name-group=
|
|
||||||
|
|
||||||
# Regular expression which should only match function or class names that do
|
|
||||||
# not require a docstring.
|
|
||||||
no-docstring-rgx=^_
|
|
||||||
|
|
||||||
# List of decorators that produce properties, such as abc.abstractproperty. Add
|
|
||||||
# to this list to register other decorators that produce valid properties.
|
|
||||||
property-classes=abc.abstractproperty
|
|
||||||
|
|
||||||
# Regular expression matching correct variable names
|
|
||||||
variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
|
||||||
|
|
||||||
|
|
||||||
[IMPORTS]
|
|
||||||
|
|
||||||
# Allow wildcard imports from modules that define __all__.
|
|
||||||
allow-wildcard-with-all=no
|
|
||||||
|
|
||||||
# Analyse import fallback blocks. This can be used to support both Python 2 and
|
|
||||||
# 3 compatible code, which means that the block might have code that exists
|
|
||||||
# only in one or another interpreter, leading to false positives when analysed.
|
|
||||||
analyse-fallback-blocks=no
|
|
||||||
|
|
||||||
# Deprecated modules which should not be used, separated by a comma
|
|
||||||
deprecated-modules=optparse,tkinter.tix
|
|
||||||
|
|
||||||
# Create a graph of external dependencies in the given file (report RP0402 must
|
|
||||||
# not be disabled)
|
|
||||||
ext-import-graph=
|
|
||||||
|
|
||||||
# Create a graph of every (i.e. internal and external) dependencies in the
|
|
||||||
# given file (report RP0402 must not be disabled)
|
|
||||||
import-graph=
|
|
||||||
|
|
||||||
# Create a graph of internal dependencies in the given file (report RP0402 must
|
|
||||||
# not be disabled)
|
|
||||||
int-import-graph=
|
|
||||||
|
|
||||||
# Force import order to recognize a module as part of the standard
|
|
||||||
# compatibility libraries.
|
|
||||||
known-standard-library=
|
|
||||||
|
|
||||||
# Force import order to recognize a module as part of a third party library.
|
|
||||||
known-third-party=enchant
|
|
||||||
|
|
||||||
|
|
||||||
[CLASSES]
|
|
||||||
|
|
||||||
# List of method names used to declare (i.e. assign) instance attributes.
|
|
||||||
defining-attr-methods=__init__,__new__,setUp
|
|
||||||
|
|
||||||
# List of member names, which should be excluded from the protected access
|
|
||||||
# warning.
|
|
||||||
exclude-protected=_asdict,_fields,_replace,_source,_make
|
|
||||||
|
|
||||||
# List of valid names for the first argument in a class method.
|
|
||||||
valid-classmethod-first-arg=cls
|
|
||||||
|
|
||||||
# List of valid names for the first argument in a metaclass class method.
|
|
||||||
valid-metaclass-classmethod-first-arg=mcs
|
|
||||||
|
|
||||||
|
|
||||||
[DESIGN]
|
|
||||||
|
|
||||||
# Maximum number of arguments for function / method
|
|
||||||
max-args=5
|
|
||||||
|
|
||||||
# Maximum number of attributes for a class (see R0902).
|
|
||||||
# max-attributes=7
|
|
||||||
max-attributes=11
|
|
||||||
|
|
||||||
# Maximum number of boolean expressions in a if statement
|
|
||||||
max-bool-expr=5
|
|
||||||
|
|
||||||
# Maximum number of branch for function / method body
|
|
||||||
max-branches=12
|
|
||||||
|
|
||||||
# Maximum number of locals for function / method body
|
|
||||||
max-locals=15
|
|
||||||
|
|
||||||
# Maximum number of parents for a class (see R0901).
|
|
||||||
max-parents=7
|
|
||||||
|
|
||||||
# Maximum number of public methods for a class (see R0904).
|
|
||||||
max-public-methods=20
|
|
||||||
|
|
||||||
# Maximum number of return / yield for function / method body
|
|
||||||
max-returns=6
|
|
||||||
|
|
||||||
# Maximum number of statements in function / method body
|
|
||||||
max-statements=50
|
|
||||||
|
|
||||||
# Minimum number of public methods for a class (see R0903).
|
|
||||||
min-public-methods=1
|
|
||||||
|
|
||||||
|
|
||||||
[EXCEPTIONS]
|
|
||||||
|
|
||||||
# Exceptions that will emit a warning when being caught. Defaults to
|
|
||||||
# "Exception"
|
|
||||||
overgeneral-exceptions=builtins.Exception
|
|
|
@ -1,19 +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
|
|
||||||
|
|
||||||
build:
|
|
||||||
os: ubuntu-20.04
|
|
||||||
tools:
|
|
||||||
python: "3"
|
|
||||||
|
|
||||||
python:
|
|
||||||
install:
|
|
||||||
- requirements: docs/requirements.txt
|
|
||||||
- requirements: requirements.txt
|
|
|
@ -1,135 +0,0 @@
|
||||||
<!--
|
|
||||||
SPDX-FileCopyrightText: 2014 Coraline Ada Ehmke
|
|
||||||
SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries
|
|
||||||
SPDX-License-Identifier: CC-BY-4.0
|
|
||||||
-->
|
|
||||||
|
|
||||||
# Adafruit Community Code of Conduct
|
|
||||||
|
|
||||||
## Our Pledge
|
|
||||||
|
|
||||||
In the interest of fostering an open and welcoming environment, we as
|
|
||||||
contributors and leaders pledge to making participation in our project and
|
|
||||||
our community a harassment-free experience for everyone, regardless of age, body
|
|
||||||
size, disability, ethnicity, gender identity and expression, level or type of
|
|
||||||
experience, education, socio-economic status, nationality, personal appearance,
|
|
||||||
race, religion, or sexual identity and orientation.
|
|
||||||
|
|
||||||
## Our Standards
|
|
||||||
|
|
||||||
We are committed to providing a friendly, safe and welcoming environment for
|
|
||||||
all.
|
|
||||||
|
|
||||||
Examples of behavior that contributes to creating a positive environment
|
|
||||||
include:
|
|
||||||
|
|
||||||
* Be kind and courteous to others
|
|
||||||
* Using welcoming and inclusive language
|
|
||||||
* Being respectful of differing viewpoints and experiences
|
|
||||||
* Collaborating with other community members
|
|
||||||
* Gracefully accepting constructive criticism
|
|
||||||
* Focusing on what is best for the community
|
|
||||||
* Showing empathy towards other community members
|
|
||||||
|
|
||||||
Examples of unacceptable behavior by participants include:
|
|
||||||
|
|
||||||
* The use of sexualized language or imagery and sexual attention or advances
|
|
||||||
* The use of inappropriate images, including in a community member's avatar
|
|
||||||
* The use of inappropriate language, including in a community member's nickname
|
|
||||||
* Any spamming, flaming, baiting or other attention-stealing behavior
|
|
||||||
* Excessive or unwelcome helping; answering outside the scope of the question
|
|
||||||
asked
|
|
||||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
||||||
* Promoting or spreading disinformation, lies, or conspiracy theories against
|
|
||||||
a person, group, organisation, project, or community
|
|
||||||
* Public or private harassment
|
|
||||||
* Publishing others' private information, such as a physical or electronic
|
|
||||||
address, without explicit permission
|
|
||||||
* Other conduct which could reasonably be considered inappropriate
|
|
||||||
|
|
||||||
The goal of the standards and moderation guidelines outlined here is to build
|
|
||||||
and maintain a respectful community. We ask that you don’t just aim to be
|
|
||||||
"technically unimpeachable", but rather try to be your best self.
|
|
||||||
|
|
||||||
We value many things beyond technical expertise, including collaboration and
|
|
||||||
supporting others within our community. Providing a positive experience for
|
|
||||||
other community members can have a much more significant impact than simply
|
|
||||||
providing the correct answer.
|
|
||||||
|
|
||||||
## Our Responsibilities
|
|
||||||
|
|
||||||
Project leaders are responsible for clarifying the standards of acceptable
|
|
||||||
behavior and are expected to take appropriate and fair corrective action in
|
|
||||||
response to any instances of unacceptable behavior.
|
|
||||||
|
|
||||||
Project leaders have the right and responsibility to remove, edit, or
|
|
||||||
reject messages, comments, commits, code, issues, and other contributions
|
|
||||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
||||||
permanently any community member for other behaviors that they deem
|
|
||||||
inappropriate, threatening, offensive, or harmful.
|
|
||||||
|
|
||||||
## Moderation
|
|
||||||
|
|
||||||
Instances of behaviors that violate the Adafruit Community Code of Conduct
|
|
||||||
may be reported by any member of the community. Community members are
|
|
||||||
encouraged to report these situations, including situations they witness
|
|
||||||
involving other community members.
|
|
||||||
|
|
||||||
You may report in the following ways:
|
|
||||||
|
|
||||||
In any situation, you may send an email to <support@adafruit.com>.
|
|
||||||
|
|
||||||
On the Adafruit Discord, you may send an open message from any channel
|
|
||||||
to all Community Moderators by tagging @community moderators. You may
|
|
||||||
also send an open message from any channel, or a direct message to
|
|
||||||
@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442,
|
|
||||||
@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175.
|
|
||||||
|
|
||||||
Email and direct message reports will be kept confidential.
|
|
||||||
|
|
||||||
In situations on Discord where the issue is particularly egregious, possibly
|
|
||||||
illegal, requires immediate action, or violates the Discord terms of service,
|
|
||||||
you should also report the message directly to Discord.
|
|
||||||
|
|
||||||
These are the steps for upholding our community’s standards of conduct.
|
|
||||||
|
|
||||||
1. Any member of the community may report any situation that violates the
|
|
||||||
Adafruit Community Code of Conduct. All reports will be reviewed and
|
|
||||||
investigated.
|
|
||||||
2. If the behavior is an egregious violation, the community member who
|
|
||||||
committed the violation may be banned immediately, without warning.
|
|
||||||
3. Otherwise, moderators will first respond to such behavior with a warning.
|
|
||||||
4. Moderators follow a soft "three strikes" policy - the community member may
|
|
||||||
be given another chance, if they are receptive to the warning and change their
|
|
||||||
behavior.
|
|
||||||
5. If the community member is unreceptive or unreasonable when warned by a
|
|
||||||
moderator, or the warning goes unheeded, they may be banned for a first or
|
|
||||||
second offense. Repeated offenses will result in the community member being
|
|
||||||
banned.
|
|
||||||
|
|
||||||
## Scope
|
|
||||||
|
|
||||||
This Code of Conduct and the enforcement policies listed above apply to all
|
|
||||||
Adafruit Community venues. This includes but is not limited to any community
|
|
||||||
spaces (both public and private), the entire Adafruit Discord server, and
|
|
||||||
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
|
|
||||||
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
|
|
||||||
interaction at a conference.
|
|
||||||
|
|
||||||
This Code of Conduct applies both within project spaces and in public spaces
|
|
||||||
when an individual is representing the project or its community. As a community
|
|
||||||
member, you are representing our community, and are expected to behave
|
|
||||||
accordingly.
|
|
||||||
|
|
||||||
## Attribution
|
|
||||||
|
|
||||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
||||||
version 1.4, available at
|
|
||||||
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
|
|
||||||
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
|
|
||||||
|
|
||||||
For other projects adopting the Adafruit Community Code of
|
|
||||||
Conduct, please contact the maintainers of those projects for enforcement.
|
|
||||||
If you wish to use this code of conduct for your own project, consider
|
|
||||||
explicitly mentioning your moderation policy or making a copy with your
|
|
||||||
own moderation policy so as to avoid confusion.
|
|
69
README.rst
69
README.rst
|
@ -1,75 +1,14 @@
|
||||||
Introduction
|
Introduction
|
||||||
============
|
============
|
||||||
|
|
||||||
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-pn532/badge/?version=latest
|
MicroPython driver for the `PN532 NFC/RFID Breakout/Shield`. This is a fork of the
|
||||||
:target: https://docs.circuitpython.org/projects/pn532/en/latest/
|
`Adafruit CircuitPython PN532 <https://github.com/adafruit/Adafruit_CircuitPython_PN532>`_
|
||||||
:alt: Documentation Status
|
library.
|
||||||
|
|
||||||
.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg
|
It is not thoroughly tested, so expect bugs. Please report them.
|
||||||
:target: https://adafru.it/discord
|
|
||||||
:alt: Discord
|
|
||||||
|
|
||||||
.. image:: https://github.com/adafruit/Adafruit_CircuitPython_PN532/workflows/Build%20CI/badge.svg
|
|
||||||
:target: https://github.com/adafruit/Adafruit_CircuitPython_PN532/actions/
|
|
||||||
:alt: Build Status
|
|
||||||
|
|
||||||
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
|
|
||||||
:target: https://github.com/psf/black
|
|
||||||
:alt: Code Style: Black
|
|
||||||
|
|
||||||
CircuitPython driver for the `PN532 NFC/RFID Breakout <https://www.adafruit.com/product/364>`_ and `PN532 NFC/RFID Shield <https://www.adafruit.com/product/789>`_
|
|
||||||
|
|
||||||
Dependencies
|
|
||||||
=============
|
|
||||||
This driver depends on:
|
|
||||||
|
|
||||||
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
|
|
||||||
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
|
|
||||||
|
|
||||||
Please ensure all dependencies are available on the CircuitPython filesystem.
|
|
||||||
This is easily achieved by downloading
|
|
||||||
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
|
|
||||||
|
|
||||||
Installing from PyPI
|
|
||||||
--------------------
|
|
||||||
|
|
||||||
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
|
|
||||||
PyPI <https://pypi.org/project/adafruit-circuitpython-pn532/>`_. To install for current user:
|
|
||||||
|
|
||||||
.. code-block:: shell
|
|
||||||
|
|
||||||
pip3 install adafruit-circuitpython-pn532
|
|
||||||
|
|
||||||
To install system-wide (this may be required in some cases):
|
|
||||||
|
|
||||||
.. code-block:: shell
|
|
||||||
|
|
||||||
sudo pip3 install adafruit-circuitpython-pn532
|
|
||||||
|
|
||||||
To install in a virtual environment in your current project:
|
|
||||||
|
|
||||||
.. code-block:: shell
|
|
||||||
|
|
||||||
mkdir project-name && cd project-name
|
|
||||||
python3 -m venv .venv
|
|
||||||
source .venv/bin/activate
|
|
||||||
pip3 install adafruit-circuitpython-pn532
|
|
||||||
|
|
||||||
Usage Example
|
Usage Example
|
||||||
=============
|
=============
|
||||||
|
|
||||||
Check examples/pn532_simpletest.py for usage example
|
Check examples/pn532_simpletest.py for usage example
|
||||||
|
|
||||||
Documentation
|
|
||||||
=============
|
|
||||||
|
|
||||||
API documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/pn532/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_PN532/blob/main/CODE_OF_CONDUCT.md>`_
|
|
||||||
before contributing to help this project stay welcoming.
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Unlicense
|
|
4
pn532/__init__.py
Normal file
4
pn532/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
from .pn532 import PN532
|
||||||
|
from .spi import PN532_SPI
|
||||||
|
from .i2c import PN532_I2C
|
||||||
|
from .uart import PN532_UART
|
|
@ -18,15 +18,12 @@ __version__ = "0.0.0+auto.0"
|
||||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PN532.git"
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PN532.git"
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from adafruit_bus_device import i2c_device
|
from machine import I2C, Pin
|
||||||
from digitalio import Direction
|
|
||||||
from micropython import const
|
from micropython import const
|
||||||
from adafruit_pn532.adafruit_pn532 import PN532, BusyError
|
from pn532.pn532 import PN532, BusyError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from typing import Optional
|
from typing import Optional, Union
|
||||||
from digitalio import DigitalInOut # pylint: disable=ungrouped-imports
|
|
||||||
from busio import I2C
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -62,23 +59,12 @@ class PN532_I2C(PN532):
|
||||||
Here is an example of using the :class:`PN532_I2C` class.
|
Here is an example of using the :class:`PN532_I2C` class.
|
||||||
First you will need to import the libraries to use the sensor
|
First you will need to import the libraries to use the sensor
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
import board
|
|
||||||
import busio
|
|
||||||
from digitalio import DigitalInOut
|
|
||||||
from adafruit_pn532.i2c import PN532_I2C
|
|
||||||
|
|
||||||
Once this is done you can define your `board.I2C` object and define your object
|
Once this is done you can define your `board.I2C` object and define your object
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
i2c = busio.I2C(board.SCL, board.SDA)
|
i2c = machine.I2C(0, scl=SCL_PIN, sda=SDA_PIN)
|
||||||
reset_pin = DigitalInOut(board.D6)
|
pn532 = PN532_I2C(i2c, debug=False, reset=RESET_PIN, req=REQ_PIN)
|
||||||
# On Raspberry Pi, you must also connect a pin to P32 "H_Request" for hardware
|
|
||||||
# wakeup! this means we don't need to do the I2C clock-stretch thing
|
|
||||||
req_pin = DigitalInOut(board.D12)
|
|
||||||
pn532 = PN532_I2C(i2c, debug=False, reset=reset_pin, req=req_pin)
|
|
||||||
# Configure PN532 to communicate with MiFare cards
|
# Configure PN532 to communicate with MiFare cards
|
||||||
pn532.SAM_configuration()
|
pn532.SAM_configuration()
|
||||||
|
|
||||||
|
@ -92,7 +78,7 @@ class PN532_I2C(PN532):
|
||||||
"""
|
"""
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self._req = req
|
self._req = req
|
||||||
self._i2c = i2c_device.I2CDevice(i2c, address)
|
self._i2c = i2c
|
||||||
super().__init__(debug=debug, irq=irq, reset=reset)
|
super().__init__(debug=debug, irq=irq, reset=reset)
|
||||||
|
|
||||||
def _wakeup(self) -> None:
|
def _wakeup(self) -> None:
|
||||||
|
@ -102,9 +88,9 @@ class PN532_I2C(PN532):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
if self._req:
|
if self._req:
|
||||||
self._req.direction = Direction.OUTPUT
|
self._req.direction = Direction.OUTPUT
|
||||||
self._req.value = False
|
self._req.value(False)
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
self._req.value = True
|
self._req.value(True)
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
self.low_power = False
|
self.low_power = False
|
||||||
self.SAM_configuration() # Put the PN532 back in normal mode
|
self.SAM_configuration() # Put the PN532 back in normal mode
|
||||||
|
@ -116,7 +102,7 @@ class PN532_I2C(PN532):
|
||||||
while (time.monotonic() - timestamp) < timeout:
|
while (time.monotonic() - timestamp) < timeout:
|
||||||
try:
|
try:
|
||||||
with self._i2c:
|
with self._i2c:
|
||||||
self._i2c.readinto(status)
|
self._i2c.readfrom_into(address, status)
|
||||||
except OSError:
|
except OSError:
|
||||||
continue
|
continue
|
||||||
if status == b"\x01":
|
if status == b"\x01":
|
||||||
|
@ -130,10 +116,10 @@ class PN532_I2C(PN532):
|
||||||
# Build a read request frame.
|
# Build a read request frame.
|
||||||
frame = bytearray(count + 1)
|
frame = bytearray(count + 1)
|
||||||
with self._i2c as i2c:
|
with self._i2c as i2c:
|
||||||
i2c.readinto(frame, end=1) # read status byte!
|
i2c.readfrom_into(address, frame, stop=1) # read status byte!
|
||||||
if frame[0] != 0x01: # not ready
|
if frame[0] != 0x01: # not ready
|
||||||
raise BusyError
|
raise BusyError
|
||||||
i2c.readinto(frame) # ok get the data, plus statusbyte
|
i2c.readfrom_into(address, frame) # ok get the data, plus statusbyte
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print("Reading: ", [hex(i) for i in frame[1:]])
|
print("Reading: ", [hex(i) for i in frame[1:]])
|
||||||
return frame[1:] # don't return the status byte
|
return frame[1:] # don't return the status byte
|
||||||
|
@ -141,4 +127,4 @@ class PN532_I2C(PN532):
|
||||||
def _write_data(self, framebytes: bytes) -> None:
|
def _write_data(self, framebytes: bytes) -> None:
|
||||||
"""Write a specified count of bytes to the PN532"""
|
"""Write a specified count of bytes to the PN532"""
|
||||||
with self._i2c as i2c:
|
with self._i2c as i2c:
|
||||||
i2c.write(framebytes)
|
i2c.writeto(address, framebytes)
|
|
@ -28,19 +28,17 @@ Implementation Notes
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import struct
|
import struct
|
||||||
from digitalio import Direction
|
|
||||||
from micropython import const
|
from micropython import const
|
||||||
|
from machine import Pin
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from typing import Optional, Tuple, Union
|
from typing import Optional, Tuple, Union
|
||||||
from typing_extensions import Literal
|
from typing_extensions import Literal
|
||||||
from circuitpython_typing import ReadableBuffer
|
|
||||||
from digitalio import DigitalInOut # pylint: disable=ungrouped-imports
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
__version__ = "0.0.0+auto.0"
|
__version__ = "0.0.0+micropython.0"
|
||||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PN532.git"
|
__repo__ = "https://kumig.it/kumitterer/MicroPython_PN532"
|
||||||
|
|
||||||
_PREAMBLE = const(0x00)
|
_PREAMBLE = const(0x00)
|
||||||
_STARTCODE1 = const(0x00)
|
_STARTCODE1 = const(0x00)
|
||||||
|
@ -163,14 +161,14 @@ class PN532:
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
debug: bool = False,
|
debug: bool = False,
|
||||||
irq: Optional[DigitalInOut] = None,
|
irq: int = None,
|
||||||
reset: Optional[DigitalInOut] = None,
|
reset: int = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create an instance of the PN532 class"""
|
"""Create an instance of the PN532 class"""
|
||||||
self.low_power = True
|
self.low_power = True
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self._irq = irq
|
self._irq = Pin(irq, Pin.IN) if irq else None
|
||||||
self._reset_pin = reset
|
self._reset_pin = Pin(reset, Pin.OUT) if reset else None
|
||||||
self.reset()
|
self.reset()
|
||||||
_ = self.firmware_version
|
_ = self.firmware_version
|
||||||
|
|
||||||
|
@ -198,10 +196,10 @@ class PN532:
|
||||||
if self._reset_pin:
|
if self._reset_pin:
|
||||||
if self.debug:
|
if self.debug:
|
||||||
print("Resetting")
|
print("Resetting")
|
||||||
self._reset_pin.direction = Direction.OUTPUT
|
|
||||||
self._reset_pin.value = False
|
self._reset_pin.value(False)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
self._reset_pin.value = True
|
self._reset_pin.value(True)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
self._wakeup()
|
self._wakeup()
|
||||||
|
|
||||||
|
@ -274,7 +272,7 @@ class PN532:
|
||||||
self,
|
self,
|
||||||
command: int,
|
command: int,
|
||||||
response_length: int = 0,
|
response_length: int = 0,
|
||||||
params: ReadableBuffer = b"",
|
params: Union[bytes, bytearray] = b"",
|
||||||
timeout: float = 1,
|
timeout: float = 1,
|
||||||
) -> Optional[Union[bytes, bytearray]]:
|
) -> Optional[Union[bytes, bytearray]]:
|
||||||
"""Send specified command to the PN532 and expect up to response_length
|
"""Send specified command to the PN532 and expect up to response_length
|
||||||
|
@ -291,7 +289,7 @@ class PN532:
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_command(
|
def send_command(
|
||||||
self, command: int, params: ReadableBuffer = b"", timeout: float = 1
|
self, command: int, params: Union[bytes, bytearray] = b"", timeout: float = 1
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Send specified command to the PN532 and wait for an acknowledgment.
|
"""Send specified command to the PN532 and wait for an acknowledgment.
|
||||||
Will wait up to timeout seconds for the acknowledgment and return True.
|
Will wait up to timeout seconds for the acknowledgment and return True.
|
||||||
|
@ -343,7 +341,7 @@ class PN532:
|
||||||
instead. Returns True if the PN532 was powered down successfully or
|
instead. Returns True if the PN532 was powered down successfully or
|
||||||
False if not."""
|
False if not."""
|
||||||
if self._reset_pin: # Hard Power Down if the reset pin is connected
|
if self._reset_pin: # Hard Power Down if the reset pin is connected
|
||||||
self._reset_pin.value = False
|
self._reset_pin.value(False)
|
||||||
self.low_power = True
|
self.low_power = True
|
||||||
else:
|
else:
|
||||||
# Soft Power Down otherwise. Enable wakeup on I2C, SPI, UART
|
# Soft Power Down otherwise. Enable wakeup on I2C, SPI, UART
|
||||||
|
@ -432,10 +430,10 @@ class PN532:
|
||||||
|
|
||||||
def mifare_classic_authenticate_block( # pylint: disable=invalid-name
|
def mifare_classic_authenticate_block( # pylint: disable=invalid-name
|
||||||
self,
|
self,
|
||||||
uid: ReadableBuffer,
|
uid: Union[bytes, bytearray],
|
||||||
block_number: int,
|
block_number: int,
|
||||||
key_number: Literal[0x60, 0x61],
|
key_number: Literal[0x60, 0x61],
|
||||||
key: ReadableBuffer,
|
key: Union[bytes, bytearray],
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Authenticate specified block number for a MiFare classic card. Uid
|
"""Authenticate specified block number for a MiFare classic card. Uid
|
||||||
should be a byte array with the UID of the card, block number should be
|
should be a byte array with the UID of the card, block number should be
|
||||||
|
@ -480,7 +478,7 @@ class PN532:
|
||||||
return response[1:]
|
return response[1:]
|
||||||
|
|
||||||
def mifare_classic_write_block(
|
def mifare_classic_write_block(
|
||||||
self, block_number: int, data: ReadableBuffer
|
self, block_number: int, data: Union[bytes, bytearray]
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Write a block of data to the card. Block number should be the block
|
"""Write a block of data to the card. Block number should be the block
|
||||||
to write and data should be a byte array of length 16 with the data to
|
to write and data should be a byte array of length 16 with the data to
|
||||||
|
@ -597,7 +595,9 @@ class PN532:
|
||||||
|
|
||||||
return self.mifare_classic_write_block(block_number, data)
|
return self.mifare_classic_write_block(block_number, data)
|
||||||
|
|
||||||
def ntag2xx_write_block(self, block_number: int, data: ReadableBuffer) -> bool:
|
def ntag2xx_write_block(
|
||||||
|
self, block_number: int, data: Union[bytes, bytearray]
|
||||||
|
) -> bool:
|
||||||
"""Write a block of data to the card. Block number should be the block
|
"""Write a block of data to the card. Block number should be the block
|
||||||
to write and data should be a byte array of length 4 with the data to
|
to write and data should be a byte array of length 4 with the data to
|
||||||
write. If the data is successfully written then True is returned,
|
write. If the data is successfully written then True is returned,
|
|
@ -14,22 +14,20 @@ using SPI.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
from machine import Pin, SPI
|
||||||
|
from micropython import const
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from typing import Optional
|
from typing import Optional, Union
|
||||||
from circuitpython_typing import ReadableBuffer
|
|
||||||
from digitalio import DigitalInOut
|
|
||||||
from busio import SPI
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
from pn532 import PN532
|
||||||
|
|
||||||
__version__ = "0.0.0+auto.0"
|
__version__ = "0.0.0+auto.0"
|
||||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PN532.git"
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PN532.git"
|
||||||
|
|
||||||
import time
|
|
||||||
from adafruit_bus_device import spi_device
|
|
||||||
from micropython import const
|
|
||||||
from adafruit_pn532.adafruit_pn532 import PN532
|
|
||||||
|
|
||||||
_SPI_STATREAD = const(0x02)
|
_SPI_STATREAD = const(0x02)
|
||||||
_SPI_DATAWRITE = const(0x01)
|
_SPI_DATAWRITE = const(0x01)
|
||||||
_SPI_DATAREAD = const(0x03)
|
_SPI_DATAREAD = const(0x03)
|
||||||
|
@ -55,10 +53,10 @@ class PN532_SPI(PN532):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
spi: SPI,
|
spi: SPI,
|
||||||
cs_pin: DigitalInOut,
|
cs_pin: int,
|
||||||
*,
|
*,
|
||||||
irq: Optional[DigitalInOut] = None,
|
irq: Optional[int] = None,
|
||||||
reset: Optional[DigitalInOut] = None,
|
reset: Optional[int] = None,
|
||||||
debug: bool = False
|
debug: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create an instance of the PN532 class using SPI
|
"""Create an instance of the PN532 class using SPI
|
||||||
|
@ -75,19 +73,12 @@ class PN532_SPI(PN532):
|
||||||
Here is an example of using the :class:`PN532_SPI` class.
|
Here is an example of using the :class:`PN532_SPI` class.
|
||||||
First you will need to import the libraries to use the sensor
|
First you will need to import the libraries to use the sensor
|
||||||
|
|
||||||
.. code-block:: python
|
Once this is done you can define your `machine.SPI` object and define your PN532 object
|
||||||
|
|
||||||
import board
|
|
||||||
import busio
|
|
||||||
from digitalio import DigitalInOut
|
|
||||||
from adafruit_pn532.spi import PN532_SPI
|
|
||||||
|
|
||||||
Once this is done you can define your `busio.SPI` object and define your PN532 object
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
spi = machine.SoftSPI(sck=board.SCK, mosi=board.MOSI, miso=board.MISO)
|
||||||
cs_pin = DigitalInOut(board.D5)
|
cs_pin = 23 # probably not 23...
|
||||||
pn532 = PN532_SPI(spi, cs_pin, debug=False)
|
pn532 = PN532_SPI(spi, cs_pin, debug=False)
|
||||||
|
|
||||||
Now you have access to the attributes and functions of the PN532 RFID/NFC
|
Now you have access to the attributes and functions of the PN532 RFID/NFC
|
||||||
|
@ -105,7 +96,7 @@ class PN532_SPI(PN532):
|
||||||
def _wakeup(self) -> None:
|
def _wakeup(self) -> None:
|
||||||
"""Send any special commands/data to wake up PN532"""
|
"""Send any special commands/data to wake up PN532"""
|
||||||
if self._reset_pin:
|
if self._reset_pin:
|
||||||
self._reset_pin.value = True
|
self._reset_pin.value(True)
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
with self._spi as spi:
|
with self._spi as spi:
|
||||||
spi.write(bytearray([0x00])) # pylint: disable=no-member
|
spi.write(bytearray([0x00])) # pylint: disable=no-member
|
||||||
|
@ -144,7 +135,7 @@ class PN532_SPI(PN532):
|
||||||
print("Reading: ", [hex(i) for i in frame[1:]])
|
print("Reading: ", [hex(i) for i in frame[1:]])
|
||||||
return frame[1:]
|
return frame[1:]
|
||||||
|
|
||||||
def _write_data(self, framebytes: ReadableBuffer) -> None:
|
def _write_data(self, framebytes: Union[bytes, bytearray]) -> None:
|
||||||
"""Write a specified count of bytes to the PN532"""
|
"""Write a specified count of bytes to the PN532"""
|
||||||
# start by making a frame with data write in front,
|
# start by making a frame with data write in front,
|
||||||
# then rest of bytes, and LSBify it
|
# then rest of bytes, and LSBify it
|
|
@ -17,23 +17,22 @@ using UART.
|
||||||
__version__ = "0.0.0+auto.0"
|
__version__ = "0.0.0+auto.0"
|
||||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PN532.git"
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PN532.git"
|
||||||
|
|
||||||
|
from machine import UART, Pin
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from typing import Optional
|
from typing import Optional, Union
|
||||||
from circuitpython_typing import ReadableBuffer
|
|
||||||
from digitalio import DigitalInOut
|
|
||||||
from busio import UART
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from adafruit_pn532.adafruit_pn532 import PN532, BusyError
|
from pn532.pn532 import PN532, BusyError
|
||||||
|
|
||||||
|
|
||||||
class PN532_UART(PN532):
|
class PN532_UART(PN532):
|
||||||
"""Driver for the PN532 connected over Serial UART"""
|
"""Driver for the PN532 connected over Serial UART"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, uart: UART, *, reset: Optional[DigitalInOut] = None, debug: bool = False
|
self, uart: UART, *, reset: Optional[int] = None, debug: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create an instance of the PN532 class using Serial connection.
|
"""Create an instance of the PN532 class using Serial connection.
|
||||||
Optional reset pin and debugging output.
|
Optional reset pin and debugging output.
|
||||||
|
@ -47,18 +46,12 @@ class PN532_UART(PN532):
|
||||||
Here is an example of using the :class:`PN532_I2C` class.
|
Here is an example of using the :class:`PN532_I2C` class.
|
||||||
First you will need to import the libraries to use the sensor
|
First you will need to import the libraries to use the sensor
|
||||||
|
|
||||||
.. code-block:: python
|
Once this is done you can define your `machine.UART` object and define your PN532 object
|
||||||
|
|
||||||
import board
|
|
||||||
import busio
|
|
||||||
from digitalio import DigitalInOut
|
|
||||||
from adafruit_pn532.uart import PN532_UART
|
|
||||||
|
|
||||||
Once this is done you can define your `busio.UART` object and define your PN532 object
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0.1)
|
uart = machine.UART(0)
|
||||||
|
uart.init(baudrate=115200, bits=8, parity=None, stop=1, tx=0, rx=1)
|
||||||
pn532 = PN532_UART(uart, debug=False)
|
pn532 = PN532_UART(uart, debug=False)
|
||||||
|
|
||||||
Now you have access to the attributes and functions of the PN532 RFID/NFC
|
Now you have access to the attributes and functions of the PN532 RFID/NFC
|
||||||
|
@ -103,7 +96,7 @@ class PN532_UART(PN532):
|
||||||
print("Reading: ", [hex(i) for i in frame])
|
print("Reading: ", [hex(i) for i in frame])
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
def _write_data(self, framebytes: ReadableBuffer) -> None:
|
def _write_data(self, framebytes: Union[bytes, bytearray]) -> None:
|
||||||
"""Write a specified count of bytes to the PN532"""
|
"""Write a specified count of bytes to the PN532"""
|
||||||
self._uart.reset_input_buffer()
|
self._uart.reset_input_buffer()
|
||||||
self._uart.write(framebytes)
|
self._uart.write(framebytes)
|
|
@ -1,46 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = [
|
|
||||||
"setuptools",
|
|
||||||
"wheel",
|
|
||||||
"setuptools-scm",
|
|
||||||
]
|
|
||||||
|
|
||||||
[project]
|
|
||||||
name = "adafruit-circuitpython-pn532"
|
|
||||||
description = "CircuitPython library for controlling PN532 RFID/NFC reader-writer."
|
|
||||||
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_PN532"}
|
|
||||||
keywords = [
|
|
||||||
"adafruit",
|
|
||||||
"pn532",
|
|
||||||
"rfid",
|
|
||||||
"nfc",
|
|
||||||
"hardware",
|
|
||||||
"micropython",
|
|
||||||
"circuitpython",
|
|
||||||
]
|
|
||||||
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_pn532"]
|
|
||||||
|
|
||||||
[tool.setuptools.dynamic]
|
|
||||||
dependencies = {file = ["requirements.txt"]}
|
|
||||||
optional-dependencies = {optional = {file = ["optional_requirements.txt"]}}
|
|
|
@ -1,9 +0,0 @@
|
||||||
# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: Unlicense
|
|
||||||
|
|
||||||
Adafruit-Blinka
|
|
||||||
adafruit-circuitpython-busdevice
|
|
||||||
adafruit-circuitpython-typing
|
|
||||||
pyserial
|
|
||||||
typing-extensions~=4.0
|
|
Loading…
Reference in a new issue