1
0
mirror of synced 2024-09-23 18:08:20 +02:00

更新开发板适配情况

This commit is contained in:
Sucareto 2024-03-05 04:02:13 +08:00
parent f7384b6443
commit e09b376eb1
4 changed files with 71 additions and 53 deletions

View File

@ -1,24 +1,44 @@
#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_ZERO)
#pragma message "当前的开发板是 ATmega32U4 或 SAMD_ZERO"
#if defined(__AVR_ATmega32U4__)
#pragma message "当前的开发板是 ATmega32U4"
#define SerialDevice SerialUSB
#define LED_PIN A3
#define PN532_SPI_SS 10
#define LED_PIN A3
#elif defined(ESP8266)
#pragma message "当前的开发板是 ESP8266"
#define SerialDevice Serial
#define PN532_SPI_SS D4
#define LED_PIN D5
#elif defined(ESP32)
#pragma message "当前的开发板是 ESP32"
#define SerialDevice Serial
#define LED_PIN 13
#define PN532_SPI_SS 5
#define LED_PIN 13
#else
#error "未经测试的开发板,请检查串口和针脚定义"
#endif
#if defined(PN532_SPI_SS)
#pragma message "使用 SPI 连接 PN532"
#include <PN532_SPI.h>
PN532_SPI pn532(SPI, PN532_SPI_SS);
#elif defined(PN532_HSU_Device)
#pragma message "使用 HSU 连接 PN532"
#include <PN532_HSU.h>
PN532_HSU pn532(PN532_HSU_Device);
#else
#pragma message "使用 I2C 连接 PN532"
#include <PN532_I2C.h>
PN532_I2C pn532(Wire);
#endif
#include "PN532.h"
PN532 nfc(pn532);
#ifdef high_baudrate
#pragma message "high_baudrate 已启用"
#define baudrate 115200
@ -39,20 +59,6 @@
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];
#if defined(PN532_SPI_SS)
#pragma message "使用 SPI 连接 PN532"
#include <SPI.h>
#include <PN532_SPI.h>
PN532_SPI pn532(SPI, PN532_SPI_SS);
#else
#pragma message "使用 I2C 连接 PN532"
#include <Wire.h>
#include <PN532_I2C.h>
PN532_I2C pn532(Wire);
#endif
#include "PN532.h"
PN532 nfc(pn532);
uint8_t KeyA[6], KeyB[6];
enum {

View File

@ -2,7 +2,7 @@
#include "Aime_Reader.h"
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(50);
FastLED.showColor(0);
nfc.begin();

View File

@ -1,7 +1,5 @@
# Arduino-Aime-Reader
使用 Arduino + PN532 制作的 Aime 兼容读卡器。
**当前更新内容未经过长时间测试,如果遇到问题可以回滚到[稳定的 v1.0 版本](https://github.com/Sucareto/Arduino-Aime-Reader/tree/v1.0)**
English: [lawliuwuu/Arduino-Aime-Reader](https://github.com/lawliuwuu/Arduino-Aime-Reader)
使用 Arduino + PN532 制作的 Aime 兼容读卡器。
- 支持卡片类型: [FeliCa](https://zh.wikipedia.org/wiki/FeliCa)Amusement IC、Suica、八达通等和 [MIFARE](https://zh.wikipedia.org/wiki/MIFARE)AimeBanapassport
- 逻辑实现是通过对官方读卡器串口数据进行分析猜测出来的,并非逆向,不保证正确实现
@ -10,18 +8,17 @@ English: [lawliuwuu/Arduino-Aime-Reader](https://github.com/lawliuwuu/Arduino-Ai
### 使用方法:
1. 按照 [PN532](https://github.com/elechouse/PN532) 的提示安装库
2. 按照使用方式,在 Arduino 和 PN532 接好连接线I2C 或 SPI并调整 PN532 上的拨码开关
1. 按照 [PN532](https://github.com/elechouse/PN532) 或 [Aime_Reader_PN532](https://github.com/Sucareto/Aime_Reader_PN532) 的提示安装库
2. 按照使用方式,在 Arduino 和 PN532 接好连接线I2C 或 SPI 或 HSU),并调整 PN532 上的拨码开关
3. 接上 WS2812B 灯条(可选,不会影响正常读卡功能)
4. 上传 [ReaderTest](tools/ReaderTest/ReaderTest.ino) 测试硬件是否工作正常
5. 若读卡正常,可按照支持列表打开设备管理器设置 COM 端口号
5. 若读卡正常,可按照游戏支持列表打开设备管理器设置 COM 端口号
6. 按照游戏的波特率设置代码的`high_baudrate`选项,`115200`是`true``38400`是`false`
7. 如果有使用 [Segatools](https://github.com/djhackersdev/segatools),参考 [segatools.ini 设置教程](https://github.com/djhackersdev/segatools/blob/master/doc/config/common.md#enable) 关闭 Aime 模拟读卡器
7. 如果有使用 [Segatools](https://github.com/djhackersdev/segatools),参考 [segatools.ini 设置教程](https://github.com/djhackersdev/segatools/blob/master/doc/config/common.md#aime) 关闭 Aime 模拟功能
8. 上传程序打开游戏测试
如果需要自定义 Aime 卡,安装 [MifareClassicTool](https://github.com/ikarus23/MifareClassicTool),修改 [Aime 卡示例](doc/aime示例.mct) 后写入空白 MIFARE UID/CUID 卡,即可刷卡使用。
关于自定义 Aime 卡的写入和读取问题,请参考 [SAK88->08](https://github.com/Sucareto/Arduino-Aime-Reader/pull/17)的讨论。
某些 Arduino 可能需要在游戏主程序连接前给串口以正确的波特率发送 DTR/RTS需要先打开一次 Arduino 串口监视器再启动主程序。
如果需要自定义 Aime 卡,安装 [MifareClassicTool](https://github.com/ikarus23/MifareClassicTool) 或其他同样效果的软件,修改 [Aime 卡示例](doc/aime示例.mct) 后写入空白 MIFARE UID/CUID 卡,即可刷卡使用。关于自定义 Aime 卡的写入和读取问题,请参考 [SAK88->08](https://github.com/Sucareto/Arduino-Aime-Reader/pull/17)的讨论。
某些 Arduino 可能需要在游戏主程序连接前给串口以正确的波特率发送 DTR/RTS需要先打开一次 Arduino 串口监视器再启动游戏程序。
### 支持游戏列表:
@ -34,18 +31,17 @@ English: [lawliuwuu/Arduino-Aime-Reader](https://github.com/lawliuwuu/Arduino-Ai
| SDBT | COM12 | FeliCa,MIFARE | 38400 |
- 如果读卡器没有正常工作,可以切换波特率试下
- 有使用 amdaemon 的,可以参考 config_common.json 内 aime > unit > port 确认端口号
- 如果 `"high_baudrate" : true` 则波特率是`115200`,否则就是`38400`
- 在 `"high_baudrate" : true` 的情况下,本读卡器程序支持 emoney 功能,端末认证和刷卡支付均正常(需要游戏和服务器支持)
- 有使用 amdaemon 的,可以参考 config_common.json 内 aime > unit > port 确认端口号
如果 `"high_baudrate" : true` 则波特率是`115200`,否则就是`38400`
- 在游戏和服务器支持的情况下,本读卡器程序可正常使用 emoney 端末认证和刷卡支付功能
### 开发板适配情况:
| 开发板名 | 主控 | 备注 |
| - | - | - |
| SparkFun Pro Micro | ATmega32U4 | 需要发送 DTR/RTS未完全测试 |
| SparkFun SAMD21 Dev Breakout | ATSAMD21G18 | 未完全测试 |
| NodeMCU 1.0 | ESP-12E + CP2102 & CH340 | SDA=D2SCL=D1 |
| NodeMCU-32S | ESP32-S + CH340 | 主要适配环境 |
| [SparkFun Pro Micro](https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide#hardware-overview-pro-micro) | ATmega32U4 | 需要发送 DTR/RTS |
| [NodeMCU 1.0](https://github.com/nodemcu/nodemcu-devkit-v1.0?tab=readme-ov-file#pin-map) | ESP-12E + CH340 | |
| [NodeMCU-32S](https://docs.ai-thinker.com/esp32/boards/nodemcu_32s) | ESP32-S + CH340 | 主要适配环境 |
| Arduino Uno | ATmega328P + CH340 | 未实际测试,据反馈不可用 |
@ -53,10 +49,13 @@ English: [lawliuwuu/Arduino-Aime-Reader](https://github.com/lawliuwuu/Arduino-Ai
- 在 NDA_08 命令的写入 Felica 操作没有实现,因为未确认是否会影响卡片后续使用
- 未确定`res.status`错误码的定义,因此`res.status`的值可能是错误的
- 因为 PN532 库不支持同时读取多张卡片,所以未实现`mifare_select_tag`,只会读到最先识别的卡片
- 默认仅允许 SAK=0x08 的卡片,如果需要解除限制,可以自行修改源码
- 如果遇到问题可以回滚到[稳定的 v1.0 版本](https://github.com/Sucareto/Arduino-Aime-Reader/tree/v1.0)
### 引用库:
### 引用库:
- 驱动 WS2812B[FastLED](https://github.com/FastLED/FastLED)
- 驱动 PN532[PN532](https://github.com/elechouse/PN532) 或 [Aime_Reader_PN532](https://github.com/Sucareto/Aime_Reader_PN532)
- 读取 FeliCa 参考:[PN532を使ってArduinoでFeliCa学生証を読む方法](https://qiita.com/gpioblink/items/91597a5275862f7ffb3c)
- 读取 FeliCa 数据的程序:[NFC TagInfo](https://play.google.com/store/apps/details?id=at.mroland.android.apps.nfctaginfo)[NFC TagInfo by NXP](https://play.google.com/store/apps/details?id=com.nxp.taginfolite)
- MIFARE 读写卡,数据分析:[MifareClassicTool](https://github.com/ikarus23/MifareClassicTool)[MifareOneTool](https://github.com/xcicode/MifareOneTool)

View File

@ -1,28 +1,41 @@
#if defined(__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_ZERO)
#pragma message "当前的开发板是 ATmega32U4 或 SAMD_ZERO"
#if defined(__AVR_ATmega32U4__)
#pragma message "当前的开发板是 ATmega32U4"
#define SerialDevice SerialUSB
#define PN532_SPI_SS 10 //32U4 不使用 SPI 时,执行 ReadWithoutEncryption 会失败
#define PN532_SPI_SS 10
// #define PN532_HSU_Device Serial1
// 32U4 使用 I2C 时,执行 ReadWithoutEncryption 会失败
// 需要修改 Wire BUFFER_LENGTH 和 TWI_BUFFER_LENGTH 为 64
#elif defined(ARDUINO_ESP8266_NODEMCU_ESP12E)
#pragma message "当前的开发板是 NODEMCU_ESP12E"
#elif defined(ESP8266)
#pragma message "当前的开发板是 ESP8266"
#define SerialDevice Serial
#define PN532_SPI_SS D4
// ESP8266 没有完整的 Serial1无法使用 HSU
// I2C SDA=D2 SCL=D1
#elif defined(ARDUINO_NodeMCU_32S)
#pragma message "当前的开发板是 NodeMCU_32S"
#elif defined(ESP32)
#pragma message "当前的开发板是 ESP32"
#define SerialDevice Serial
#define PN532_SPI_SS 5
// #define PN532_HSU_Device Serial2 // RX=16 TX=17
// ESP32 使用 I2C 时响应太慢,无法正常使用
#else
#error "未经测试的开发板,请检查串口和脚定义"
#error "未经测试的开发板,请检查串口和脚定义"
#endif
#if defined(PN532_SPI_SS)
#pragma message "使用 SPI 连接 PN532"
#include <SPI.h>
#include <PN532_SPI.h>
PN532_SPI pn532(SPI, PN532_SPI_SS);
#elif defined(PN532_HSU_Device)
#pragma message "使用 HSU 连接 PN532"
#include <PN532_HSU.h>
PN532_HSU pn532(PN532_HSU_Device);
#else
#include <Wire.h>
#pragma message "使用 I2C 连接 PN532"
#include <PN532_I2C.h>
PN532_I2C pn532(Wire);
#endif
@ -43,12 +56,12 @@ typedef union {
} Card;
Card card;
uint8_t AimeKey[6] = {0x57, 0x43, 0x43, 0x46, 0x76, 0x32};
uint8_t BanaKey[6] = {0x60, 0x90, 0xD0, 0x06, 0x32, 0xF5};
uint8_t MifareKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
#define M2F_B 1
uint16_t blockList[4] = {0x8080, 0x8081, 0x8082, 0x8083};
uint16_t serviceCodeList[1] = {0x000B};
uint8_t AimeKey[6] = { 0x57, 0x43, 0x43, 0x46, 0x76, 0x32 };
uint8_t BanaKey[6] = { 0x60, 0x90, 0xD0, 0x06, 0x32, 0xF5 };
uint8_t MifareKey[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
#define M2F_B 1 // 指定作为 Access Code 读取的 block 序号
uint16_t blockList[4] = { 0x8080, 0x8081, 0x8082, 0x8083 };
uint16_t serviceCodeList[1] = { 0x000B };
uint8_t blockData[1][16];
void setup() {