Skip to content

Commit

Permalink
- Add SD card CID register display.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 5, 2024
1 parent a36f889 commit 77cbf97
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cube/swiss/source/devices/deviceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef s32 (* _fn_setupFile)(file_handle*, file_handle*, ExecutableFile*, int);
typedef s32 (* _fn_deinit)(file_handle*);
typedef u32 (* _fn_emulated)(void);
typedef char* (* _fn_status)(file_handle*);
typedef char* (* _fn_details)(file_handle*);

// Device features
#define FEAT_READ 0x1
Expand Down Expand Up @@ -199,6 +200,7 @@ struct DEVICEHANDLER_STRUCT {
_fn_deinit deinit;
_fn_emulated emulated;
_fn_status status;
_fn_details details;
} ;

enum DEVICE_SLOTS {
Expand Down
27 changes: 27 additions & 0 deletions cube/swiss/source/devices/fat/deviceHandler-FAT.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,30 @@ char* deviceHandler_FAT_status(file_handle* file) {
}
}

char* deviceHandler_FAT_details(file_handle* file) {
char* deviceDetails = NULL;
int isSDCard = IS_SDCARD(file);
int slot = GET_SLOT(file);
if(isSDCard) {
if(sdgecko_readCID(slot) != CARDIO_ERROR_READY) return NULL;
asprintf(&deviceDetails,
"Manufacturer ID: %02X\n"
"OEM/Application ID: %.2s\n"
"Product name: %.5s\n"
"Product revision: %u.%02u\n"
"Product serial number: %08X\n"
"Manufacturing date: %u-%02u",
MANUFACTURER_ID(slot),
OEM_APPLICATION_ID(slot),
PRODUCT_NAME(slot),
PRODUCT_REVISION(slot) >> 4, PRODUCT_REVISION(slot) & 0xF,
PRODUCT_SERIAL_NUMBER(slot),
2000 + (MANUFACTURING_DATE(slot) >> 4), MANUFACTURING_DATE(slot) & 0xF
);
}
return deviceDetails;
}

DEVICEHANDLER_INTERFACE __device_sd_a = {
.deviceUniqueId = DEVICE_ID_1,
.hwName = "SD Card Adapter",
Expand All @@ -544,6 +568,7 @@ DEVICEHANDLER_INTERFACE __device_sd_a = {
.deinit = deviceHandler_FAT_deinit,
.emulated = deviceHandler_FAT_emulated_sd,
.status = deviceHandler_FAT_status,
.details = deviceHandler_FAT_details,
};

DEVICEHANDLER_INTERFACE __device_sd_b = {
Expand Down Expand Up @@ -571,6 +596,7 @@ DEVICEHANDLER_INTERFACE __device_sd_b = {
.deinit = deviceHandler_FAT_deinit,
.emulated = deviceHandler_FAT_emulated_sd,
.status = deviceHandler_FAT_status,
.details = deviceHandler_FAT_details,
};

DEVICEHANDLER_INTERFACE __device_ata_a = {
Expand Down Expand Up @@ -652,6 +678,7 @@ DEVICEHANDLER_INTERFACE __device_sd_c = {
.deinit = deviceHandler_FAT_deinit,
.emulated = deviceHandler_FAT_emulated_sd,
.status = deviceHandler_FAT_status,
.details = deviceHandler_FAT_details,
};

DEVICEHANDLER_INTERFACE __device_ata_c = {
Expand Down
20 changes: 17 additions & 3 deletions cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -2626,11 +2626,25 @@ void select_device(int type)
DrawAddChild(deviceSelectBox, exiSpeedLabel);
}
}
DrawPublish(deviceSelectBox);
if(allDevices[curDevice]->details) {
uiDrawObj_t *deviceDetailLabel = DrawStyledLabel(20, 385, "(Y) Show device details", 0.65f, false, deSelectedColor);
DrawAddChild(deviceSelectBox, deviceDetailLabel);
}
DrawPublish(deviceSelectBox);
while (!(padsButtonsHeld() &
(PAD_BUTTON_RIGHT|PAD_BUTTON_LEFT|PAD_BUTTON_B|PAD_BUTTON_A|PAD_BUTTON_X|PAD_TRIGGER_L|PAD_TRIGGER_R|PAD_TRIGGER_Z) ))
(PAD_BUTTON_RIGHT|PAD_BUTTON_LEFT|PAD_BUTTON_B|PAD_BUTTON_A|PAD_BUTTON_X|PAD_BUTTON_Y|PAD_TRIGGER_L|PAD_TRIGGER_R|PAD_TRIGGER_Z) ))
{ VIDEO_WaitVSync (); }
u16 btns = padsButtonsHeld();
if((btns & PAD_BUTTON_Y) && allDevices[curDevice]->details) {
char *deviceDetails = allDevices[curDevice]->details(allDevices[curDevice]->initial);
if(deviceDetails) {
uiDrawObj_t *deviceDetailBox = DrawPublish(DrawTooltip(deviceDetails));
while (padsButtonsHeld() & PAD_BUTTON_Y){ VIDEO_WaitVSync (); }
while (!((padsButtonsHeld() & PAD_BUTTON_Y) || (padsButtonsHeld() & PAD_BUTTON_B))){ VIDEO_WaitVSync (); }
DrawDispose(deviceDetailBox);
free(deviceDetails);
}
}
if((btns & PAD_BUTTON_X) && (allDevices[curDevice]->features & FEAT_EXI_SPEED))
inAdvanced ^= 1;
if(btns & PAD_TRIGGER_Z) {
Expand Down Expand Up @@ -2677,7 +2691,7 @@ void select_device(int type)
}
while ((padsButtonsHeld() &
(PAD_BUTTON_RIGHT|PAD_BUTTON_LEFT|PAD_BUTTON_B|PAD_BUTTON_A
|PAD_BUTTON_X|PAD_TRIGGER_L|PAD_TRIGGER_R|PAD_TRIGGER_Z) ))
|PAD_BUTTON_X|PAD_BUTTON_Y|PAD_TRIGGER_L|PAD_TRIGGER_R|PAD_TRIGGER_Z) ))
{ VIDEO_WaitVSync (); }
DrawDispose(deviceSelectBox);
}
Expand Down

0 comments on commit 77cbf97

Please sign in to comment.