Skip to content

Commit

Permalink
Added basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
abobija committed Sep 9, 2024
1 parent 8aee590 commit ce7fff1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions examples/basic/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
idf_component_register(SRCS "basic.c"
INCLUDE_DIRS ".")
33 changes: 33 additions & 0 deletions examples/basic/main/basic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <esp_log.h>
#include <inttypes.h>
#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);
}
4 changes: 4 additions & 0 deletions examples/basic/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies:
abobija/rc522:
version: "*"
override_path: '../../../'

0 comments on commit ce7fff1

Please sign in to comment.