/arm9/source/gamecart/card_spi.h

https://github.com/d0k3/GodMode9 · C Header · 86 lines · 53 code · 14 blank · 19 comment · 0 complexity · b4f9295671e454c6424f1afb647e5ef4 MD5 · raw file

  1. /*
  2. * This file is based on SPI.h from TWLSaveTool. Its copyright notice is
  3. * reproduced below.
  4. *
  5. * Copyright (C) 2015-2016 TuxSH
  6. *
  7. * TWLSaveTool is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. */
  20. #pragma once
  21. #include "common.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. typedef struct CardSPITypeData CardSPITypeData;
  26. typedef struct {
  27. const CardSPITypeData *chip;
  28. bool infrared;
  29. } CardSPIType;
  30. struct CardSPITypeData {
  31. int (*enableWriting) (CardSPIType type);
  32. int (*readSaveData) (CardSPIType type, u32 offset, void* data, u32 size);
  33. int (*writeSaveData) (CardSPIType type, u32 offset, const void* data, u32 size);
  34. int (*eraseSector) (CardSPIType type, u32 offset);
  35. u32 jedecId;
  36. u32 capacity;
  37. u32 eraseSize;
  38. u32 pageSize;
  39. u32 writeSize;
  40. u8 writeCommand;
  41. u8 programCommand;
  42. u8 eraseCommand;
  43. };
  44. #define NO_CHIP NULL
  45. extern const CardSPITypeData * const EEPROM_512B;
  46. extern const CardSPITypeData * const EEPROM_8KB;
  47. extern const CardSPITypeData * const EEPROM_64KB;
  48. extern const CardSPITypeData * const EEPROM_128KB;
  49. extern const CardSPITypeData * const FLASH_256KB_1;
  50. extern const CardSPITypeData * const FLASH_256KB_2;
  51. extern const CardSPITypeData * const FLASH_512KB_1;
  52. extern const CardSPITypeData * const FLASH_512KB_2;
  53. extern const CardSPITypeData * const FLASH_1MB;
  54. extern const CardSPITypeData * const FLASH_8MB;
  55. extern const CardSPITypeData * const FLASH_128KB_CTR; // Most common, including Ocarina of time 3D
  56. extern const CardSPITypeData * const FLASH_512KB_CTR; // Also common, including Detective Pikachu
  57. extern const CardSPITypeData * const FLASH_1MB_CTR; // For example Pokemon Ultra Sun
  58. int CardSPIWriteRead(CardSPIType type, const void* cmd, u32 cmdSize, void* answer, u32 answerSize, const void* data, u32 dataSize);
  59. int CardSPIWaitWriteEnd(CardSPIType type, u32 timeout);
  60. int CardSPIEnableWriting(CardSPIType type);
  61. int CardSPIReadJEDECIDAndStatusReg(CardSPIType type, u32* id, u8* statusReg);
  62. int CardSPIGetCardSPIType(CardSPIType* type, bool infrared);
  63. u32 CardSPIGetPageSize(CardSPIType type);
  64. u32 CardSPIGetCapacity(CardSPIType type);
  65. u32 CardSPIGetEraseSize(CardSPIType type);
  66. int CardSPIWriteSaveData(CardSPIType type, u32 offset, const void* data, u32 size);
  67. int CardSPIReadSaveData(CardSPIType type, u32 offset, void* data, u32 size);
  68. int CardSPIEraseSector(CardSPIType type, u32 offset);
  69. int CardSPIErase(CardSPIType type);
  70. #ifdef __cplusplus
  71. }
  72. #endif