Add support NFC-F(WIP)

This commit is contained in:
GOB
2025-11-27 19:30:15 +09:00
parent 6f6e2508b0
commit b4e2f0cb7d
18 changed files with 1501 additions and 235 deletions
@@ -0,0 +1,10 @@
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/*
Example using M5UnitUnified for M5Cardputer-ADV with HackerCap
Detect NFC-A PICC
*/
#include "main/Detect.cpp"
@@ -0,0 +1,95 @@
/*
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/*
Example using M5UnitUnified for M5Cardputer-ADV with HackerCap
Detect NFC-F PICC
*/
#include <M5Unified.h>
#include <M5UnitUnified.h>
#include <M5UnitUnifiedNFC.h>
#include <M5Utility.h>
#include <vector>
using namespace m5::nfc;
using namespace m5::nfc::f;
namespace {
auto& lcd = M5.Display;
m5::unit::UnitUnified Units;
m5::unit::CapST25R3916 cap; // ST25R3916 in the HackerCap
m5::unit::nfc::NFCLayerF nfc_f{cap};
} // namespace
void setup()
{
M5.begin();
auto cfg = cap.config();
cfg.mode = NFC::F;
cap.config(cfg);
#if 0
//// M5GFX 0.2.15 NG! with HackerCap
auto board = M5.getBoard();
if (board != lgfx::board_t::board_M5CardputerADV) {
M5_LOGE("This is NOT M5Cardputer-ADV %U/%XH", board, board);
lcd.fillScreen(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
#endif
if (!SPI.bus()) {
auto spi_sclk = M5.getPin(m5::pin_name_t::sd_spi_sclk);
auto spi_mosi = M5.getPin(m5::pin_name_t::sd_spi_mosi);
auto spi_miso = M5.getPin(m5::pin_name_t::sd_spi_miso);
M5_LOGI("getPin: %d,%d,%d", spi_sclk, spi_mosi, spi_miso);
SPI.begin(spi_sclk, spi_miso, spi_mosi /* SS is shared SD, CC1101, ST25R3916 */);
}
delay(1000);
SPISettings settings = {10000000, MSBFIRST, SPI_MODE1};
if (!Units.add(cap, SPI, settings) || !Units.begin()) {
M5_LOGE("Failed to begin");
lcd.fillScreen(TFT_RED);
while (true) {
m5::utility::delay(10000);
}
}
M5_LOGI("M5UnitUnified has been begun");
M5_LOGI("%s", Units.debugInfo().c_str());
if (lcd.width() < lcd.height()) {
lcd.setRotation(1);
}
lcd.setFont(&fonts::Font0);
lcd.fillScreen(0);
//
// cap.dumpRegister();
//
}
void loop()
{
M5.update();
Units.update();
std::vector<PICC> piccs;
// if (nfc_f.detect(piccs)) {
if (nfc_f.detect(piccs, 0x0003)) {
M5.Speaker.tone(3000, 10);
M5.Log.printf("%zu PICC\n", piccs.size());
for (auto&& picc : piccs) {
M5.Log.printf(" %s:%s %02X\n", picc.idmAsString().c_str(), picc.pmmAsString().c_str(), picc.format);
}
}
}