1
0
mirror of https://github.com/whowechina/aic_pico.git synced 2024-11-13 17:30:52 +01:00

PN5180 support for spicetools cardio

This commit is contained in:
whowe 2023-12-03 00:29:19 +08:00
parent 2688c10af2
commit 9f785ae0c0
5 changed files with 15 additions and 174 deletions

Binary file not shown.

View File

@ -147,156 +147,6 @@ static void handle_level(int argc, char *argv[])
handle_display();
}
static void handle_pnboot()
{
pn5180_reset();
}
static void handle_pnver()
{
uint8_t buf[6];
pn5180_read_eeprom(0x10, buf, sizeof(buf));
printf("Version: %02x %02x %02x %02x %02x %02x\n",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
pn5180_print_rf_cfg();
}
static void handle_pnread(int argc, char *argv[])
{
int reg = cli_extract_non_neg_int(argv[0], 0);
printf("%2d: %08lx\n", reg, pn5180_read_reg(reg));
}
static void handle_pnmifare()
{
pn5180_reset();
pn5180_load_rf_config(0x00, 0x80);
pn5180_rf_on();
pn5180_and_reg(PN5180_REG_CRC_TX_CONFIG, 0xfffffffe);
pn5180_and_reg(PN5180_REG_CRC_RX_CONFIG, 0xfffffffe);
pn5180_and_reg(PN5180_REG_IRQ_CLEAR, 0x000fffff);
pn5180_and_reg(PN5180_REG_SYSTEM_CONFIG, 0xfffffff8);
pn5180_or_reg(PN5180_REG_SYSTEM_CONFIG, 0x03);
uint8_t cmd[7] = {0x26};
pn5180_send_data(cmd, 1, 7);
uint8_t buf[32] = {0};
pn5180_read_data(buf, 2);
cmd[0] = 0x93;
cmd[1] = 0x20;
pn5180_send_data(cmd, 2, 0);
pn5180_read_data(cmd + 2, 5);
pn5180_or_reg(PN5180_REG_CRC_RX_CONFIG, 0x01);
pn5180_or_reg(PN5180_REG_CRC_TX_CONFIG, 0x01);
cmd[0] = 0x93;
cmd[1] = 0x70;
pn5180_send_data(cmd, 7, 0);
pn5180_read_data(buf + 2, 1); // sak
printf("SAK: %02x\n", buf[2]);
if ((buf[2] & 0x04) == 0) {
printf("UID: %02x %02x %02x %02x\n", cmd[2], cmd[3], cmd[4], cmd[5]);
} else {
if (cmd[2] != 0x88) {
return;
}
printf("UID: %02x %02x %02x", cmd[3], cmd[4], cmd[5]);
pn5180_and_reg(PN5180_REG_CRC_TX_CONFIG, 0xfffffffe);
pn5180_and_reg(PN5180_REG_CRC_RX_CONFIG, 0xfffffffe);
cmd[0] = 0x95;
cmd[1] = 0x20;
pn5180_send_data(cmd, 2, 0);
pn5180_read_data(cmd + 2, 5);
printf(" %02x %02x %02x %02x\n", cmd[2], cmd[3], cmd[4], cmd[5]);
pn5180_or_reg(PN5180_REG_CRC_RX_CONFIG, 0x01);
pn5180_or_reg(PN5180_REG_CRC_TX_CONFIG, 0x01);
cmd[0] = 0x95;
cmd[1] = 0x70;
pn5180_send_data(cmd, 7, 0);
pn5180_read_data(buf + 2, 1);
printf("SAK: %02x\n", buf[2]);
}
pn5180_rf_off();
}
static void handle_pnfeli()
{
pn5180_reset();
pn5180_load_rf_config(0x08, 0x88);
pn5180_rf_on();
pn5180_and_reg(PN5180_REG_SYSTEM_CONFIG, 0xffffffbf);
pn5180_or_reg(PN5180_REG_SYSTEM_CONFIG, 0x03);
uint8_t cmd[] = {0x06, 0x00, 0xff, 0xff, 0x01, 0x00};
pn5180_send_data(cmd, 6, 0x00);
sleep_ms(1);
uint8_t out[20] = {0};
pn5180_read_data(out, 20);
printf("FeliCa:");
if (out[1] == 0x01) {
for (int i = 0; i < 20; i++) {
printf(" %02x", out[i]);
}
}
printf("\n");
pn5180_rf_off();
}
static void handle_pninv()
{
pn5180_reset();
pn5180_load_rf_config(0x0d, 0x8d);
pn5180_rf_on();
pn5180_clear_irq(0x0fffff);
pn5180_and_reg(PN5180_REG_SYSTEM_CONFIG, 0xfffffff8);
pn5180_or_reg(PN5180_REG_SYSTEM_CONFIG, 0x03);
uint8_t cmd[] = {0x26, 0x01, 0x00};
pn5180_send_data(cmd, 3, 0);
sleep_ms(1);
if ((pn5180_get_irq() & 0x4000) == 0) {
printf("No card\n");
return;
}
while ((pn5180_get_irq() & 0x01) == 0) {
sleep_ms(10);
}
uint32_t rx = pn5180_get_rx();
printf("RX: %08lx\n", rx);
int len = rx & 0x1ff;
uint8_t buf[len];
pn5180_read_data(buf, len);
printf("uid:");
for (int i = 0; i < len; i++) {
printf(" %02x", buf[i]);
}
printf("\n");
}
void commands_init()
{
cli_register("display", handle_display, "Display all settings.");
@ -305,10 +155,4 @@ void commands_init()
cli_register("nfc", handle_nfc, "NFC debug.");
cli_register("light", handle_light, "Turn on/off lights.");
cli_register("level", handle_level, "Set light level.");
cli_register("pnboot", handle_pnboot, "PN5180 reboot");
cli_register("pnver", handle_pnver, "PN5180 version");
cli_register("pnread", handle_pnread, "PN5180 debug rf");
cli_register("pnmifare", handle_pnmifare, "PN5180 mifare");
cli_register("pnfeli", handle_pnfeli, "PN5180 felica");
cli_register("pninv", handle_pninv, "PN5180 15693");
}

View File

@ -164,7 +164,7 @@ void detect_card()
bool vicinity = false;
if (nfc_module == NFC_PN5180) {
vicinity = pn5180_poll_vicinity(id, &len);
vicinity = pn5180_poll_vicinity(id);
}
if (vicinity) {

View File

@ -255,7 +255,7 @@ static void anti_collision(uint8_t code, uint8_t uid[5], uint8_t *sak)
pn5180_read_data(sak, 1); // sak
}
bool pn5180_poll_mifare(uint8_t *uid, int *len)
bool pn5180_poll_mifare(uint8_t uid[7], int *len)
{
pn5180_reset();
pn5180_load_rf_config(0x00, 0x80);
@ -278,19 +278,15 @@ bool pn5180_poll_mifare(uint8_t *uid, int *len)
bool result = false;
if ((sak & 0x04) == 0) {
if (*len >= 4) {
*len = 4;
memmove(uid, buf, 4);
result = true;
}
memmove(uid, buf, 4);
*len = 4;
result = true;
} else if (sak == 0x88) {
memmove(uid, buf + 1, 3);
anti_collision(0x95, buf + 5, &sak);
memmove(uid + 3, buf, 4);
if (*len >= 7) {
*len = 7;
result = true;
}
*len = 7;
result = true;
}
pn5180_rf_off();
@ -330,7 +326,7 @@ bool pn5180_poll_felica(uint8_t uid[8], uint8_t pmm[8], uint8_t syscode[2], bool
return result;
}
bool pn5180_poll_vicinity(uint8_t *uid, int *len)
bool pn5180_poll_vicinity(uint8_t uid[8])
{
pn5180_reset();
pn5180_load_rf_config(0x0d, 0x8d);
@ -357,12 +353,13 @@ bool pn5180_poll_vicinity(uint8_t *uid, int *len)
sleep_ms(1);
}
int idlen = pn5180_get_rx() & 0x1ff;
int len = pn5180_get_rx() & 0x1ff;
bool result = false;
if (idlen <= *len) {
*len = idlen;
pn5180_read_data(uid, idlen);
if (len == 10) {
uint8_t id[10];
pn5180_read_data(id, len);
memmove(uid, id + 2, 8);
result = true;
}

View File

@ -43,9 +43,9 @@ uint32_t pn5180_get_rx();
void pn5180_reset();
bool pn5180_poll_mifare(uint8_t *uid, int *len);
bool pn5180_poll_mifare(uint8_t uid[7], int *len);
bool pn5180_poll_felica(uint8_t uid[8], uint8_t pmm[8], uint8_t syscode[2], bool from_cache);
bool pn5180_poll_vicinity(uint8_t *uid, int *len);
bool pn5180_poll_vicinity(uint8_t uid[8]);
void pn5180_print_rf_cfg();