My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

W25Qxx.h 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include <stdint.h>
  24. #define W25X_WriteEnable 0x06
  25. #define W25X_WriteDisable 0x04
  26. #define W25X_ReadStatusReg 0x05
  27. #define W25X_WriteStatusReg 0x01
  28. #define W25X_ReadData 0x03
  29. #define W25X_FastReadData 0x0B
  30. #define W25X_FastReadDual 0x3B
  31. #define W25X_PageProgram 0x02
  32. #define W25X_BlockErase 0xD8
  33. #define W25X_SectorErase 0x20
  34. #define W25X_ChipErase 0xC7
  35. #define W25X_PowerDown 0xB9
  36. #define W25X_ReleasePowerDown 0xAB
  37. #define W25X_DeviceID 0xAB
  38. #define W25X_ManufactDeviceID 0x90
  39. #define W25X_JedecDeviceID 0x9F
  40. #define WIP_Flag 0x01 /* Write In Progress (WIP) flag */
  41. #define Dummy_Byte 0xA5
  42. #define SPI_FLASH_SectorSize 4096
  43. #define SPI_FLASH_PageSize 256
  44. #define SPI_FLASH_PerWritePageSize 256
  45. class W25QXXFlash {
  46. public:
  47. void init(uint8_t spiRate);
  48. static uint8_t spi_flash_Rec();
  49. static uint8_t spi_flash_read_write_byte(uint8_t data);
  50. static void spi_flash_Read(uint8_t* buf, uint16_t nbyte);
  51. static void spi_flash_Send(uint8_t b);
  52. static void spi_flash_SendBlock(uint8_t token, const uint8_t* buf);
  53. static uint16_t W25QXX_ReadID(void);
  54. static void SPI_FLASH_WriteEnable(void);
  55. static void SPI_FLASH_WaitForWriteEnd(void);
  56. static void SPI_FLASH_SectorErase(uint32_t SectorAddr);
  57. static void SPI_FLASH_BlockErase(uint32_t BlockAddr);
  58. static void SPI_FLASH_BulkErase(void);
  59. static void SPI_FLASH_PageWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
  60. static void SPI_FLASH_BufferWrite(uint8_t* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite);
  61. static void SPI_FLASH_BufferRead(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
  62. };
  63. extern W25QXXFlash W25QXX;