spi_overlap.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * ESPRSSIF MIT License
  3. *
  4. * Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
  5. *
  6. * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
  7. * it is free of charge, to any person obtaining a copy of this software and associated
  8. * documentation files (the "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
  11. * to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or
  14. * substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. */
  24. #ifndef SPI_OVERLAP_APP_H
  25. #define SPI_OVERLAP_APP_H
  26. #include "ets_sys.h"
  27. #include "spi_flash.h"
  28. #define HSPI_OVERLAP
  29. //#define NO_HSPI_DEVICE
  30. #define HOST_INF_SEL 0x3ff00028
  31. #define FUNC_SPI_CS2 1
  32. #define FUNC_SPI_CS1 1
  33. #define reg_cspi_overlap (BIT7)
  34. #define SPI_FLASH_BYTES_LEN 24
  35. #define IODATA_START_ADDR BIT0
  36. #define SPI_BUFF_BYTE_NUM 32
  37. #define PERIPHS_IO_MUX_BACKUP 0
  38. #define SPI_USER_BACKUP 1
  39. #define SPI_CTRL_BACKUP 2
  40. #define SPI_CLOCK_BACKUP 3
  41. #define SPI_USER1_BACKUP 4
  42. #define SPI_USER2_BACKUP 5
  43. #define SPI_CMD_BACKUP 6
  44. #define SPI_PIN_BACKUP 7
  45. #define SPI_SLAVE_BACKUP 8
  46. #define HSPI_CS_DEV 0
  47. #define SPI_CS1_DEV 1
  48. #define SPI_CS2_DEV 2
  49. #define SPI_CS0_FLASH 3
  50. #define HSPI_IDLE 4
  51. struct hspi_device_config{
  52. uint8 active:1;
  53. uint8 clk_polar:1;
  54. uint8 res:1;
  55. uint8 clk_div:5;
  56. };
  57. struct hspi_device_register{
  58. uint32 hspi_flash_reg_backup[9];
  59. uint32 hspi_dev_reg_backup[9];
  60. struct hspi_device_config hspi_dev_conf[4];
  61. uint8 selected_dev_num:3;
  62. uint8 spi_io_80m:1;
  63. uint8 hspi_reg_backup_flag:1;
  64. uint8 res:3;
  65. };
  66. void hspi_overlap_init(void);
  67. void hspi_overlap_deinit(void);
  68. void spi_reg_recover(uint8 spi_no,uint32* backup_mem);
  69. void spi_reg_backup(uint8 spi_no,uint32* backup_mem);
  70. void hspi_master_dev_init(uint8 dev_no,uint8 clk_polar,uint8 clk_div);
  71. void hspi_dev_sel(uint8 dev_no);
  72. void hspi_overlap_flash_init(void);
  73. SpiFlashOpResult hspi_overlap_read_flash_data(SpiFlashChip * spi, uint32 flash_addr, uint32 * addr_dest, uint32 byte_length);
  74. #endif