Skip to content

Commit

Permalink
Version 3 (#49)
Browse files Browse the repository at this point in the history
- Returns card type (mifare 1k, 4k, ...) based on SAK
- Functions for reading/writing from/to memory on MIFARE Classic cards
- Sector Trailer block protection (write prevented by default,
configurable via menuconfig)
- Hard reset via RST pin (optional, auto switch to soft if hard fails)
- Firing events when picc changes state (all states described in 14443
iso are supported)
- Added examples
  - Basic for getting UID and type of the card
  - Dump whole card memory content
  - Reading and writing from/to card memory
- Unit tests
- CI
  - Run unit tests
  - Build examples 
- Returns UID length, and UID is now in the form of a byte array
  - resolves #41
  - resolves #23
- Rewritten read_write test. Using PCD fifo buffer now to test if the
library can read/write multiple bytes
  - resolves #37 (hopefully)
- Firing event when card disappears from the scanner field
- Additional affected issues:
  - closes #40
- closes #25 because library is fully rewritten, and this should be
tried again (feel free to reopen the issue if you are facing the same
issue in the new version)
  • Loading branch information
abobija authored Sep 20, 2024
1 parent 1f0bbcb commit 7ac343e
Show file tree
Hide file tree
Showing 55 changed files with 4,426 additions and 1,103 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Language: Cpp
BasedOnStyle: WebKit
AlignConsecutiveBitFields: true
AlignConsecutiveMacros: true
AlignEscapedNewlines: Left
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
Expand Down Expand Up @@ -40,7 +40,7 @@ BraceWrapping:
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
ColumnLimit: 120
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/clang-format-check.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Assign author to PR

on:
pull_request_target:
types: [opened, reopened]
types: [ opened, reopened ]

permissions:
pull-requests: write
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
name: Publish component
name: Publish ESP-IDF Component

on:
release:
types: [published]
types: [ published ]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Upload component to the registry
uses: espressif/upload-components-ci-action@v1
with:
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Validate

on:
pull_request:
push:
branches:
- main
schedule:
- cron: "0 0 * * 6"

jobs:
format_check:
name: "Check formatting"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: 'clang-format check'
uses: jidicula/[email protected]
with:
clang-format-version: 18

unit_test:
name: "Unit test"
runs-on: ubuntu-latest

needs:
- format_check

steps:
- uses: actions/checkout@v4
with:
path: rc522

- name: "Unit test"
uses: espressif/esp-idf-ci-action@v1
with:
path: rc522/test
esp_idf_version: release-v5.3
target: linux
command: idf.py build && ./build/test.elf

build_examples:
name: "Build example"
runs-on: ubuntu-latest

needs:
- unit_test

strategy:
matrix:
example:
- basic
- basic_i2c
- memory_dump
- read_write
idf_ver:
- release-v5.0
- release-v5.1
- release-v5.2
- release-v5.3
idf_target:
- esp32

steps:
- uses: actions/checkout@v4
with:
path: rc522

- name: Build
uses: espressif/esp-idf-ci-action@v1
with:
path: rc522/examples/${{ matrix.example }}
esp_idf_version: ${{ matrix.idf_ver }}
target: ${{ matrix.idf_target }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
sdkconfig.old
sdkconfig
.vscode
/examples/**/dependencies.lock
dependencies.lock
37 changes: 34 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
idf_component_register(
INCLUDE_DIRS include
SRCS src/rc522.c
REQUIRES esp_event driver
INCLUDE_DIRS
include
PRIV_INCLUDE_DIRS
private_include
SRCS
src/rc522.c
src/rc522_helpers.c
src/rc522_pcd.c
src/rc522_picc.c
src/picc/rc522_mifare.c
src/rc522_driver.c
src/driver/rc522_spi.c
src/driver/rc522_i2c.c
REQUIRES
esp_event
# esp_driver_spi # introduced in esp-idf 5.3, autoincluded in 'driver' component
driver # required for i2c, TODO: migrate to the new API
)

target_compile_options(${COMPONENT_LIB} PRIVATE
-Werror # Warning as error
#-pedantic
-Wextra
-Wall
-Wshadow
-Wcast-qual
-Wswitch-default
#-Wswitch-enum
#-Wconversion
-Wunreachable-code
-Wuninitialized
-Winit-self
-Wpointer-arith
-Werror-implicit-function-declaration
)
14 changes: 14 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
menu "RC522"

config RC522_PREVENT_SECTOR_TRAILER_WRITE
bool "Prevent writing to the Sector Trailer block"
default y
help
The Sector Trailer block stores authentication keys
and access bits. Enabling this option prevents writing
to the Trailer block. This is enabled by default to protect
inexperienced users from accidentally overwriting keys or
writing incorrect access bits, which could render the sector
unusable.

endmenu
Loading

0 comments on commit 7ac343e

Please sign in to comment.