mirror of
https://github.com/whowechina/aic_pico.git
synced 2024-11-28 07:20:49 +01:00
NFC module version display
This commit is contained in:
parent
a4ed1f5419
commit
07b0807a1b
@ -60,6 +60,7 @@ nfc_card_t nfc_detect_card_ex(bool mifare, bool felica, bool vicinity);
|
||||
void display_card(const nfc_card_t *card);
|
||||
|
||||
const char *nfc_module_name();
|
||||
const char *nfc_module_version();
|
||||
|
||||
bool nfc_mifare_auth(const uint8_t uid[4], uint8_t block_id, uint8_t key_id, const uint8_t *key);
|
||||
bool nfc_mifare_read(uint8_t block_id, uint8_t block_data[16]);
|
||||
|
@ -23,7 +23,7 @@
|
||||
#define LED_DEF { 25, 22, 13, 15 }
|
||||
|
||||
#define KEYPAD_DEF { 6, 7, 8, 3, 4, 5, 0, 1, 2, 9, 10, 11 }
|
||||
#define KEYPAD_EN 14
|
||||
#define AIC_TOUCH_EN 14
|
||||
|
||||
/* HID Keycode: https://github.com/hathach/tinyusb/blob/master/src/class/hid/hid.h */
|
||||
// Numpad: 1234567890-.
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include "save.h"
|
||||
#include "cli.h"
|
||||
|
||||
#include "keypad.h"
|
||||
|
||||
#include "aime.h"
|
||||
#include "bana.h"
|
||||
#include "nfc.h"
|
||||
@ -35,13 +37,13 @@ void fps_count(int core)
|
||||
static void handle_display()
|
||||
{
|
||||
printf("[NFC Module]\n");
|
||||
printf(" %s\n", nfc_module_name());
|
||||
printf(" %s (%s)\n", nfc_module_name(), nfc_module_version());
|
||||
printf("[Config]\n");
|
||||
printf(" Light: RGB-%s LED-%s\n",
|
||||
aic_cfg->light.rgb ? "ON" : "OFF",
|
||||
aic_cfg->light.led ? "ON" : "OFF");
|
||||
printf(" Level: [%d ~ %d]\n", aic_cfg->light.min, aic_cfg->light.max);
|
||||
printf("[Reader]]\n");
|
||||
printf("[Reader]\n");
|
||||
printf(" Virtual AIC: %s\n", aic_cfg->virtual_aic ? "ON" : "OFF");
|
||||
|
||||
printf(" Mode: %s\n", mode_name(aic_cfg->mode));
|
||||
@ -51,6 +53,10 @@ static void handle_display()
|
||||
if ((aic_runtime.mode == MODE_AIME0) || (aic_runtime.mode == MODE_AIME1)) {
|
||||
printf(" AIME Pattern: %s\n", aime_get_mode_string());
|
||||
}
|
||||
if (keypad_is_stuck()) {
|
||||
printf("\n Warning: Keypad disabled due to key STUCK!\n");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_save()
|
||||
|
@ -25,6 +25,7 @@ typedef struct __attribute__((packed)) {
|
||||
|
||||
typedef volatile struct {
|
||||
bool debug;
|
||||
bool touch;
|
||||
reader_mode_t mode;
|
||||
} aic_runtime_t;
|
||||
|
||||
|
@ -51,6 +51,7 @@ const char *nfc_card_name(nfc_card_type card_type)
|
||||
|
||||
#define func_null NULL
|
||||
struct {
|
||||
const char *(*firmware_ver)();
|
||||
bool (*poll_mifare)(uint8_t uid[7], int *len);
|
||||
bool (*poll_felica)(uint8_t uid[8], uint8_t pmm[8], uint8_t syscode[2], bool from_cache);
|
||||
bool (*poll_vicinity)(uint8_t uid[8]);
|
||||
@ -63,6 +64,7 @@ struct {
|
||||
void (*deselect)();
|
||||
} api[3] = {
|
||||
{
|
||||
pn532_firmware_ver,
|
||||
pn532_poll_mifare, pn532_poll_felica, func_null,
|
||||
pn532_rf_field,
|
||||
pn532_mifare_auth, pn532_mifare_read,
|
||||
@ -72,6 +74,7 @@ struct {
|
||||
NULL,
|
||||
},
|
||||
{
|
||||
pn5180_firmware_ver,
|
||||
pn5180_poll_mifare, pn5180_poll_felica, pn5180_poll_vicinity,
|
||||
pn5180_rf_field,
|
||||
pn5180_mifare_auth, pn5180_mifare_read,
|
||||
@ -121,7 +124,7 @@ void nfc_attach_spi(spi_inst_t *port, uint8_t rst, uint8_t nss, uint8_t busy)
|
||||
void nfc_init_spi(spi_inst_t *port, uint8_t miso, uint8_t sck, uint8_t mosi,
|
||||
uint8_t rst, uint8_t nss, uint8_t busy)
|
||||
{
|
||||
spi_init(port, 8000 * 1000);
|
||||
spi_init(port, 8 * 1000 * 1000);
|
||||
spi_set_format(port, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
|
||||
|
||||
gpio_set_function(miso, GPIO_FUNC_SPI);
|
||||
@ -154,6 +157,14 @@ void nfc_set_wait_loop(nfc_wait_loop_t loop)
|
||||
api[nfc_module].set_wait_loop(loop);
|
||||
}
|
||||
|
||||
const char *nfc_module_version()
|
||||
{
|
||||
if (!api[nfc_module].firmware_ver) {
|
||||
return 0;
|
||||
}
|
||||
return api[nfc_module].firmware_ver();
|
||||
}
|
||||
|
||||
static bool nfc_detect_mifare(nfc_card_t *card)
|
||||
{
|
||||
uint8_t id[20] = { 0 };
|
||||
|
@ -13,9 +13,10 @@
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/spi.h"
|
||||
|
||||
#include "nfc.h"
|
||||
#include "pn5180.h"
|
||||
|
||||
#define DEBUG(...) { if (0) printf(__VA_ARGS__); }
|
||||
#define DEBUG(...) { if (nfc_runtime.debug) printf(__VA_ARGS__); }
|
||||
|
||||
#define IO_TIMEOUT_US 1000
|
||||
#define PN5180_I2C_ADDRESS 0x24
|
||||
@ -38,6 +39,7 @@ static spi_inst_t *spi_port;
|
||||
static uint8_t gpio_rst;
|
||||
static uint8_t gpio_nss;
|
||||
static uint8_t gpio_busy;
|
||||
static uint8_t version[2];
|
||||
|
||||
bool pn5180_init(spi_inst_t *port, uint8_t rst, uint8_t nss, uint8_t busy)
|
||||
{
|
||||
@ -56,9 +58,15 @@ bool pn5180_init(spi_inst_t *port, uint8_t rst, uint8_t nss, uint8_t busy)
|
||||
gpio_nss = nss;
|
||||
gpio_busy = busy;
|
||||
|
||||
uint8_t buf[2];
|
||||
pn5180_read_eeprom(0x12, buf, sizeof(buf));
|
||||
return (buf[0] <= 15) && (buf[1] >= 2) && (buf[1] <= 15);
|
||||
pn5180_read_eeprom(0x12, version, sizeof(version));
|
||||
return (version[0] <= 15) && (version[1] >= 2) && (version[1] <= 15);
|
||||
}
|
||||
|
||||
const char *pn5180_firmware_ver()
|
||||
{
|
||||
static char ver_str[8];
|
||||
sprintf(ver_str, "%d.%d", version[1], version[0]);
|
||||
return ver_str;
|
||||
}
|
||||
|
||||
static pn5180_wait_loop_t wait_loop = NULL;
|
||||
@ -283,6 +291,7 @@ static void poll_mifare_2()
|
||||
|
||||
bool pn5180_poll_mifare(uint8_t uid[7], int *len)
|
||||
{
|
||||
DEBUG("pn5180_poll_mifare\n");
|
||||
poll_mifare_1();
|
||||
poll_mifare_2();
|
||||
|
||||
@ -295,6 +304,7 @@ static uint8_t idm_cache[8] = {0};
|
||||
|
||||
bool pn5180_poll_felica(uint8_t uid[8], uint8_t pmm[8], uint8_t syscode[2], bool from_cache)
|
||||
{
|
||||
DEBUG("pn5180_poll_mifare\n");
|
||||
pn5180_reset();
|
||||
pn5180_load_rf_config(0x09, 0x89);
|
||||
pn5180_rf_field(true);
|
||||
@ -329,6 +339,7 @@ bool pn5180_poll_felica(uint8_t uid[8], uint8_t pmm[8], uint8_t syscode[2], bool
|
||||
|
||||
bool pn5180_poll_vicinity(uint8_t uid[8])
|
||||
{
|
||||
DEBUG("pn5180_poll_mifare\n");
|
||||
pn5180_reset();
|
||||
pn5180_load_rf_config(0x0d, 0x8d);
|
||||
pn5180_rf_field(true);
|
||||
|
@ -24,7 +24,7 @@ typedef void (*pn5180_wait_loop_t)();
|
||||
void pn5180_set_wait_loop(pn5180_wait_loop_t loop);
|
||||
|
||||
bool pn5180_init(spi_inst_t *port, uint8_t rst, uint8_t nss, uint8_t busy);
|
||||
|
||||
const char *pn5180_firmware_ver();
|
||||
void pn5180_write_reg(uint8_t reg, uint32_t v32);
|
||||
void pn5180_or_reg(uint8_t reg, uint32_t mask);
|
||||
void pn5180_and_reg(uint8_t reg, uint32_t mask);
|
||||
|
@ -27,13 +27,24 @@
|
||||
#define PN532_PN532TOHOST 0xd5
|
||||
|
||||
static i2c_inst_t *i2c_port = i2c0;
|
||||
static uint32_t version = 0;
|
||||
|
||||
static uint32_t read_firmware_ver()
|
||||
{
|
||||
uint8_t buf[4];
|
||||
if ((pn532_write_command(0x02, NULL, 0) >= 0) &&
|
||||
(pn532_read_response(0x02, buf, sizeof(buf)) == 4)) {
|
||||
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool pn532_init(i2c_inst_t *i2c)
|
||||
{
|
||||
i2c_port = i2c;
|
||||
version = read_firmware_ver();
|
||||
|
||||
uint32_t ver = pn532_firmware_ver();
|
||||
return (ver > 0) && (ver < 0x7fffffff);
|
||||
return (version > 0) && (version < 0x7fffffff);
|
||||
}
|
||||
|
||||
static pn532_wait_loop_t wait_loop = NULL;
|
||||
@ -237,25 +248,11 @@ int pn532_read_response(uint8_t cmd, uint8_t *resp, uint8_t len)
|
||||
return data_len;
|
||||
}
|
||||
|
||||
uint32_t pn532_firmware_ver()
|
||||
const char *pn532_firmware_ver()
|
||||
{
|
||||
int ret = pn532_write_command(0x02, NULL, 0);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t ver[4];
|
||||
int result = pn532_read_response(0x02, ver, sizeof(ver));
|
||||
if (result < 4) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t version = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
version <<= 8;
|
||||
version |= ver[i];
|
||||
}
|
||||
return version;
|
||||
static char ver_str[16];
|
||||
sprintf(ver_str, "%08lX", version);
|
||||
return ver_str;
|
||||
}
|
||||
|
||||
bool pn532_config_rf()
|
||||
|
@ -19,7 +19,7 @@ bool pn532_init(i2c_inst_t *i2c);
|
||||
int pn532_write_command(uint8_t cmd, const uint8_t *param, uint8_t len);
|
||||
int pn532_read_response(uint8_t cmd, uint8_t *resp, uint8_t len);
|
||||
|
||||
uint32_t pn532_firmware_ver();
|
||||
const char *pn532_firmware_ver();
|
||||
|
||||
bool pn532_config_sam();
|
||||
bool pn532_config_rf();
|
||||
|
Loading…
Reference in New Issue
Block a user