mirror of
https://github.com/DuRuofu/ESP32-Guide.git
synced 2026-02-05 22:52:22 +08:00
code: rc522
This commit is contained in:
1
code/10.practice/common_modules/rc522/.gitignore
vendored
Normal file
1
code/10.practice/common_modules/rc522/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
managed_components/
|
||||
6
code/10.practice/common_modules/rc522/CMakeLists.txt
Normal file
6
code/10.practice/common_modules/rc522/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
# The following lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(hello_world)
|
||||
21
code/10.practice/common_modules/rc522/dependencies.lock
Normal file
21
code/10.practice/common_modules/rc522/dependencies.lock
Normal file
@@ -0,0 +1,21 @@
|
||||
dependencies:
|
||||
abobija/rc522:
|
||||
component_hash: 0186675032931158602686994c975ec8937a328880d8fb3c44fbf5630195f201
|
||||
dependencies:
|
||||
- name: idf
|
||||
require: private
|
||||
version: ^5.0
|
||||
source:
|
||||
registry_url: https://components.espressif.com/
|
||||
type: service
|
||||
version: 3.3.2
|
||||
idf:
|
||||
source:
|
||||
type: idf
|
||||
version: 5.4.1
|
||||
direct_dependencies:
|
||||
- abobija/rc522
|
||||
- idf
|
||||
manifest_hash: f0cca0d4e3c8a6cf205b2e5319f6f85dee2685a51486835b8e35f292652c2fc3
|
||||
target: esp32
|
||||
version: 2.0.0
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "main.c"
|
||||
INCLUDE_DIRS "")
|
||||
17
code/10.practice/common_modules/rc522/main/idf_component.yml
Normal file
17
code/10.practice/common_modules/rc522/main/idf_component.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: '>=4.1.0'
|
||||
# # Put list of dependencies here
|
||||
# # For components maintained by Espressif:
|
||||
# component: "~1.0.0"
|
||||
# # For 3rd party components:
|
||||
# username/component: ">=1.0.0,<2.0.0"
|
||||
# username2/component2:
|
||||
# version: "~1.0.0"
|
||||
# # For transient dependencies `public` flag can be set.
|
||||
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||
# # All dependencies of `main` are public by default.
|
||||
# public: true
|
||||
abobija/rc522: ^3.3.2
|
||||
55
code/10.practice/common_modules/rc522/main/main.c
Normal file
55
code/10.practice/common_modules/rc522/main/main.c
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <esp_log.h>
|
||||
#include "rc522.h"
|
||||
#include "driver/rc522_spi.h"
|
||||
#include "rc522_picc.h"
|
||||
|
||||
static const char *TAG = "rc522-basic-example";
|
||||
|
||||
#define RC522_SPI_BUS_GPIO_MISO (25)
|
||||
#define RC522_SPI_BUS_GPIO_MOSI (23)
|
||||
#define RC522_SPI_BUS_GPIO_SCLK (19)
|
||||
#define RC522_SPI_SCANNER_GPIO_SDA (22)
|
||||
#define RC522_SCANNER_GPIO_RST (-1) // soft-reset
|
||||
|
||||
static rc522_spi_config_t driver_config = {
|
||||
.host_id = SPI3_HOST,
|
||||
.bus_config = &(spi_bus_config_t){
|
||||
.miso_io_num = RC522_SPI_BUS_GPIO_MISO,
|
||||
.mosi_io_num = RC522_SPI_BUS_GPIO_MOSI,
|
||||
.sclk_io_num = RC522_SPI_BUS_GPIO_SCLK,
|
||||
},
|
||||
.dev_config = {
|
||||
.spics_io_num = RC522_SPI_SCANNER_GPIO_SDA,
|
||||
},
|
||||
.rst_io_num = RC522_SCANNER_GPIO_RST,
|
||||
};
|
||||
|
||||
static rc522_driver_handle_t driver;
|
||||
static rc522_handle_t scanner;
|
||||
|
||||
static void on_picc_state_changed(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
rc522_picc_state_changed_event_t *event = (rc522_picc_state_changed_event_t *)data;
|
||||
rc522_picc_t *picc = event->picc;
|
||||
|
||||
if (picc->state == RC522_PICC_STATE_ACTIVE) {
|
||||
rc522_picc_print(picc);
|
||||
}
|
||||
else if (picc->state == RC522_PICC_STATE_IDLE && event->old_state >= RC522_PICC_STATE_ACTIVE) {
|
||||
ESP_LOGI(TAG, "Card has been removed");
|
||||
}
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
rc522_spi_create(&driver_config, &driver);
|
||||
rc522_driver_install(driver);
|
||||
|
||||
rc522_config_t scanner_config = {
|
||||
.driver = driver,
|
||||
};
|
||||
|
||||
rc522_create(&scanner_config, &scanner);
|
||||
rc522_register_events(scanner, RC522_EVENT_PICC_STATE_CHANGED, on_picc_state_changed, NULL);
|
||||
rc522_start(scanner);
|
||||
}
|
||||
Reference in New Issue
Block a user