w25qxx.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _W25QXX_H
  2. #define _W25QXX_H
  3. /*
  4. Author: Nima Askari
  5. WebSite: http://www.github.com/NimaLTD
  6. Instagram: http://instagram.com/github.NimaLTD
  7. Youtube: https://www.youtube.com/channel/UCUhY7qY1klJm1d2kulr9ckw
  8. Version: 1.1.1
  9. Reversion History:
  10. (1.1.1)
  11. Fix some errors.
  12. (1.1.0)
  13. Fix some errors.
  14. (1.0.0)
  15. First release.
  16. */
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include <stdbool.h>
  21. #include "stdint.h"
  22. typedef enum
  23. {
  24. W25Q10=1,
  25. W25Q20,
  26. W25Q40,
  27. W25Q80,
  28. W25Q16,
  29. W25Q32,
  30. W25Q64,
  31. W25Q128,
  32. W25Q256,
  33. W25Q512,
  34. }W25QXX_ID_t;
  35. typedef struct
  36. {
  37. W25QXX_ID_t ID;
  38. uint8_t UniqID[8];
  39. uint16_t PageSize;
  40. uint32_t PageCount;
  41. uint32_t SectorSize;
  42. uint32_t SectorCount;
  43. uint32_t BlockSize;
  44. uint32_t BlockCount;
  45. uint32_t CapacityInKiloByte;
  46. uint8_t StatusRegister1;
  47. uint8_t StatusRegister2;
  48. uint8_t StatusRegister3;
  49. uint8_t Lock;
  50. }w25qxx_t;
  51. extern w25qxx_t w25qxx;
  52. //############################################################################
  53. // in Page,Sector and block read/write functions, can put 0 to read maximum bytes
  54. //############################################################################
  55. bool W25qxx_Init(void);
  56. void W25qxx_EraseChip(void);
  57. void W25qxx_EraseSector(uint32_t SectorAddr);
  58. void W25qxx_EraseBlock(uint32_t BlockAddr);
  59. uint32_t W25qxx_PageToSector(uint32_t PageAddress);
  60. uint32_t W25qxx_PageToBlock(uint32_t PageAddress);
  61. uint32_t W25qxx_SectorToBlock(uint32_t SectorAddress);
  62. uint32_t W25qxx_SectorToPage(uint32_t SectorAddress);
  63. uint32_t W25qxx_BlockToPage(uint32_t BlockAddress);
  64. bool W25qxx_IsEmptyPage(uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToCheck_up_to_PageSize);
  65. bool W25qxx_IsEmptySector(uint32_t Sector_Address, uint32_t OffsetInByte, uint32_t NumByteToCheck_up_to_SectorSize);
  66. bool W25qxx_IsEmptyBlock(uint32_t Block_Address, uint32_t OffsetInByte, uint32_t NumByteToCheck_up_to_BlockSize);
  67. void W25qxx_WriteByte(uint8_t pBuffer, uint32_t Bytes_Address);
  68. void W25qxx_WritePage(uint8_t *pBuffer, uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_PageSize);
  69. void W25qxx_WriteSector(uint8_t *pBuffer, uint32_t Sector_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_SectorSize);
  70. void W25qxx_WriteBlock(uint8_t* pBuffer, uint32_t Block_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_BlockSize);
  71. void W25qxx_ReadByte(uint8_t *pBuffer, uint32_t Bytes_Address);
  72. void W25qxx_ReadBytes(uint8_t *pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead);
  73. void W25qxx_ReadPage(uint8_t *pBuffer, uint32_t Page_Address,uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_PageSize);
  74. void W25qxx_ReadSector(uint8_t *pBuffer, uint32_t Sector_Address,uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_SectorSize);
  75. void W25qxx_ReadBlock(uint8_t* pBuffer, uint32_t Block_Address, uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_BlockSize);
  76. void W25qxx_SelfTest(void);
  77. void W25qxx_EraseBlock(uint32_t Block_Address);
  78. //############################################################################
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif