2019-07-27 20:22:39 +02:00
|
|
|
/*
|
|
|
|
* This file is based on SPI.h from TWLSaveTool. Its copyright notice is
|
|
|
|
* reproduced below.
|
2020-08-24 21:27:19 -07:00
|
|
|
*
|
2019-07-27 20:22:39 +02:00
|
|
|
* Copyright (C) 2015-2016 TuxSH
|
|
|
|
*
|
|
|
|
* TWLSaveTool is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct CardSPITypeData CardSPITypeData;
|
|
|
|
|
2019-07-28 00:45:57 +02:00
|
|
|
typedef struct {
|
|
|
|
const CardSPITypeData *chip;
|
|
|
|
bool infrared;
|
|
|
|
} CardSPIType;
|
2019-07-27 20:22:39 +02:00
|
|
|
|
|
|
|
struct CardSPITypeData {
|
2019-07-27 20:32:26 +02:00
|
|
|
int (*enableWriting) (CardSPIType type);
|
|
|
|
int (*readSaveData) (CardSPIType type, u32 offset, void* data, u32 size);
|
|
|
|
int (*writeSaveData) (CardSPIType type, u32 offset, const void* data, u32 size);
|
|
|
|
int (*eraseSector) (CardSPIType type, u32 offset);
|
2021-01-31 20:26:27 +00:00
|
|
|
u16 jedecId;
|
2019-07-27 20:32:26 +02:00
|
|
|
u32 capacity;
|
|
|
|
u32 eraseSize;
|
|
|
|
u32 pageSize;
|
|
|
|
u32 writeSize;
|
|
|
|
u8 writeCommand;
|
|
|
|
u8 programCommand;
|
|
|
|
u8 eraseCommand;
|
2019-07-27 20:22:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NO_CHIP NULL
|
|
|
|
|
2020-06-01 17:13:30 -03:00
|
|
|
extern const CardSPITypeData * const EEPROM_512B;
|
2019-07-27 20:22:39 +02:00
|
|
|
|
2020-06-01 17:13:30 -03:00
|
|
|
extern const CardSPITypeData * const EEPROM_8KB;
|
|
|
|
extern const CardSPITypeData * const EEPROM_64KB;
|
|
|
|
extern const CardSPITypeData * const EEPROM_128KB;
|
2019-07-27 20:22:39 +02:00
|
|
|
|
2021-01-31 20:26:27 +00:00
|
|
|
extern const CardSPITypeData * const FLASH_NTR_GENERIC; // Most common flash chip in DS games, in 3 different sizes
|
|
|
|
extern const CardSPITypeData * const FLASH_256KB;
|
|
|
|
extern const CardSPITypeData * const FLASH_512KB;
|
2020-06-01 17:13:30 -03:00
|
|
|
extern const CardSPITypeData * const FLASH_8MB;
|
2021-02-23 23:12:01 +00:00
|
|
|
extern const CardSPITypeData * const FLASH_NTR_BOOTLEG; // Found in some DS bootlegs off of eBay (ST M25PE40VP in my case)
|
2019-07-27 20:22:39 +02:00
|
|
|
|
2021-01-31 20:26:27 +00:00
|
|
|
extern const CardSPITypeData * const FLASH_CTR_GENERIC; // Handles each 3ds cartridge the exact same
|
2019-07-27 20:22:39 +02:00
|
|
|
|
2021-02-03 21:48:32 +00:00
|
|
|
int CardSPIWriteRead(bool infrared, const void* cmd, u32 cmdSize, void* answer, u32 answerSize, const void* data, u32 dataSize);
|
|
|
|
int CardSPIWaitWriteEnd(bool infrared, u32 timeout);
|
2019-07-27 20:22:39 +02:00
|
|
|
int CardSPIEnableWriting(CardSPIType type);
|
2021-02-03 21:48:32 +00:00
|
|
|
int CardSPIReadJEDECIDAndStatusReg(bool infrared, u32* id, u8* statusReg);
|
|
|
|
CardSPIType CardSPIGetCardSPIType(bool infrared);
|
2019-07-27 20:22:39 +02:00
|
|
|
u32 CardSPIGetPageSize(CardSPIType type);
|
|
|
|
u32 CardSPIGetCapacity(CardSPIType type);
|
|
|
|
u32 CardSPIGetEraseSize(CardSPIType type);
|
|
|
|
|
|
|
|
int CardSPIWriteSaveData(CardSPIType type, u32 offset, const void* data, u32 size);
|
|
|
|
int CardSPIReadSaveData(CardSPIType type, u32 offset, void* data, u32 size);
|
|
|
|
|
|
|
|
int CardSPIEraseSector(CardSPIType type, u32 offset);
|
|
|
|
int CardSPIErase(CardSPIType type);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|