From ce7fff1e7b55d42f0376e23ba861b16f3f756eca Mon Sep 17 00:00:00 2001 From: Alija Bobija Date: Mon, 9 Sep 2024 10:27:12 +0200 Subject: [PATCH] Added basic example --- examples/basic/CMakeLists.txt | 8 +++++++ examples/basic/main/CMakeLists.txt | 2 ++ examples/basic/main/basic.c | 33 +++++++++++++++++++++++++++ examples/basic/main/idf_component.yml | 4 ++++ 4 files changed, 47 insertions(+) create mode 100644 examples/basic/CMakeLists.txt create mode 100644 examples/basic/main/CMakeLists.txt create mode 100644 examples/basic/main/basic.c create mode 100644 examples/basic/main/idf_component.yml diff --git a/examples/basic/CMakeLists.txt b/examples/basic/CMakeLists.txt new file mode 100644 index 00000000..42ebffe4 --- /dev/null +++ b/examples/basic/CMakeLists.txt @@ -0,0 +1,8 @@ +# For more information about build system see +# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html +# The following five 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(basic) diff --git a/examples/basic/main/CMakeLists.txt b/examples/basic/main/CMakeLists.txt new file mode 100644 index 00000000..bb45756a --- /dev/null +++ b/examples/basic/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "basic.c" + INCLUDE_DIRS ".") diff --git a/examples/basic/main/basic.c b/examples/basic/main/basic.c new file mode 100644 index 00000000..2594e93b --- /dev/null +++ b/examples/basic/main/basic.c @@ -0,0 +1,33 @@ +#include +#include +#include "rc522.h" + +static const char *TAG = "rc522-demo"; +static rc522_handle_t scanner; + +static void rc522_handler(void *arg, esp_event_base_t base, int32_t event_id, void *event_data) +{ + rc522_event_data_t *data = (rc522_event_data_t *)event_data; + + switch (event_id) { + case RC522_EVENT_TAG_SCANNED: { + rc522_tag_t *tag = (rc522_tag_t *)data->ptr; + ESP_LOGI(TAG, "Tag scanned (sn: %" PRIu64 ")", tag->serial_number); + } break; + } +} + +void app_main() +{ + rc522_config_t config = { + .spi.host = VSPI_HOST, + .spi.miso_gpio = 25, + .spi.mosi_gpio = 23, + .spi.sck_gpio = 19, + .spi.sda_gpio = 22, + }; + + rc522_create(&config, &scanner); + rc522_register_events(scanner, RC522_EVENT_ANY, rc522_handler, NULL); + rc522_start(scanner); +} diff --git a/examples/basic/main/idf_component.yml b/examples/basic/main/idf_component.yml new file mode 100644 index 00000000..14f5723e --- /dev/null +++ b/examples/basic/main/idf_component.yml @@ -0,0 +1,4 @@ +dependencies: + abobija/rc522: + version: "*" + override_path: '../../../'