mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 14:45:41 +12:00
Implement NFC::GetTagState
This commit is contained in:
parent
ceb3f05c7e
commit
80f1de728c
2 changed files with 28 additions and 4 deletions
|
@ -14,22 +14,34 @@ class NFCService {
|
|||
Kernel& kernel;
|
||||
MAKE_LOG_FUNCTION(log, nfcLogger)
|
||||
|
||||
enum class Old3DSAdapterStatus : s32 {
|
||||
enum class Old3DSAdapterStatus : u32 {
|
||||
Idle = 0,
|
||||
AttemptingToInitialize = 1,
|
||||
InitializationComplete = 2,
|
||||
// Other values are errors according to 3DBrew, set the not initialized error to -1 until we find out what it should be
|
||||
NotInitialized = -1,
|
||||
Active = 3,
|
||||
};
|
||||
|
||||
enum class TagStatus : u8 {
|
||||
NotInitialized = 0,
|
||||
Initialized = 1,
|
||||
Scanning = 2,
|
||||
InRange = 3,
|
||||
OutOfRange = 4,
|
||||
Loaded = 5,
|
||||
};
|
||||
|
||||
// Kernel events signaled when an NFC tag goes in and out of range respectively
|
||||
std::optional<Handle> tagInRangeEvent, tagOutOfRangeEvent;
|
||||
|
||||
Old3DSAdapterStatus adapterStatus;
|
||||
TagStatus tagStatus;
|
||||
|
||||
// Service commands
|
||||
void communicationGetStatus(u32 messagePointer);
|
||||
void initialize(u32 messagePointer);
|
||||
void getTagInRangeEvent(u32 messagePointer);
|
||||
void getTagOutOfRangeEvent(u32 messagePointer);
|
||||
void getTagState(u32 messagePointer);
|
||||
void stopCommunication(u32 messagePointer);
|
||||
|
||||
public:
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace NFCCommands {
|
|||
StopCommunication = 0x00040000,
|
||||
GetTagInRangeEvent = 0x000B0000,
|
||||
GetTagOutOfRangeEvent = 0x000C0000,
|
||||
GetTagState = 0x000D0000,
|
||||
CommunicationGetStatus = 0x000F0000,
|
||||
};
|
||||
}
|
||||
|
@ -16,7 +17,8 @@ void NFCService::reset() {
|
|||
tagInRangeEvent = std::nullopt;
|
||||
tagOutOfRangeEvent = std::nullopt;
|
||||
|
||||
adapterStatus = Old3DSAdapterStatus::NotInitialized;
|
||||
adapterStatus = Old3DSAdapterStatus::Idle;
|
||||
tagStatus = TagStatus::NotInitialized;
|
||||
}
|
||||
|
||||
void NFCService::handleSyncRequest(u32 messagePointer) {
|
||||
|
@ -26,6 +28,7 @@ void NFCService::handleSyncRequest(u32 messagePointer) {
|
|||
case NFCCommands::Initialize: initialize(messagePointer); break;
|
||||
case NFCCommands::GetTagInRangeEvent: getTagInRangeEvent(messagePointer); break;
|
||||
case NFCCommands::GetTagOutOfRangeEvent: getTagOutOfRangeEvent(messagePointer); break;
|
||||
case NFCCommands::GetTagState: getTagState(messagePointer); break;
|
||||
case NFCCommands::StopCommunication: stopCommunication(messagePointer); break;
|
||||
default: Helpers::panic("NFC service requested. Command: %08X\n", command);
|
||||
}
|
||||
|
@ -36,6 +39,7 @@ void NFCService::initialize(u32 messagePointer) {
|
|||
log("NFC::Initialize (type = %d)\n", type);
|
||||
|
||||
adapterStatus = Old3DSAdapterStatus::InitializationComplete;
|
||||
tagStatus = TagStatus::Initialized;
|
||||
// TODO: This should error if already initialized. Also sanitize type.
|
||||
mem.write32(messagePointer, IPC::responseHeader(0x1, 1, 0));
|
||||
mem.write32(messagePointer + 4, Result::Success);
|
||||
|
@ -76,6 +80,14 @@ void NFCService::getTagOutOfRangeEvent(u32 messagePointer) {
|
|||
mem.write32(messagePointer + 12, tagOutOfRangeEvent.value());
|
||||
}
|
||||
|
||||
void NFCService::getTagState(u32 messagePointer) {
|
||||
log("NFC::GetTagState");
|
||||
|
||||
mem.write32(messagePointer, IPC::responseHeader(0xD, 2, 0));
|
||||
mem.write32(messagePointer + 4, Result::Success);
|
||||
mem.write8(messagePointer + 8, static_cast<u8>(tagStatus));
|
||||
}
|
||||
|
||||
void NFCService::communicationGetStatus(u32 messagePointer) {
|
||||
log("NFC::CommunicationGetStatus");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue