cpu_esp32.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef _CPU_ESP32_H_
  2. #define _CPU_ESP32_H_
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #include "user_config.h"
  6. #include <spi_flash.h>
  7. #include <eagle_soc.h>
  8. #include <gpio.h>
  9. #include <gpio/io_mux_reg.h>
  10. #include <gpio/gpio_reg.h>
  11. #include "flash_api.h"
  12. #include "pin_map.h"
  13. /* FIXME: real numbers here! */
  14. #define NUM_GPIO GPIO_PIN_NUM
  15. #define NUM_SPI 2
  16. #define NUM_UART 1
  17. #define NUM_PWM GPIO_PIN_NUM
  18. #define NUM_ADC 1
  19. #define NUM_CAN 0
  20. #define NUM_I2C 1
  21. #define NUM_OW GPIO_PIN_NUM
  22. #define NUM_TMR 7
  23. #if defined(FLASH_512K)
  24. # define FLASH_SEC_NUM 0x80 // 4MByte: 0x400, 2MByte: 0x200, 1MByte: 0x100, 512KByte: 0x80
  25. #elif defined(FLASH_1M)
  26. # define FLASH_SEC_NUM 0x100
  27. #elif defined(FLASH_2M)
  28. # define FLASH_SEC_NUM 0x200
  29. #elif defined(FLASH_4M)
  30. # define FLASH_SEC_NUM 0x400
  31. #elif defined(FLASH_8M)
  32. # define FLASH_SEC_NUM 0x800
  33. #elif defined(FLASH_16M)
  34. # define FLASH_SEC_NUM 0x1000
  35. #elif defined(FLASH_AUTOSIZE)
  36. # if defined(FLASH_SAFE_API)
  37. # define FLASH_SEC_NUM (flash_safe_get_sec_num())
  38. # else
  39. # define FLASH_SEC_NUM (flash_rom_get_sec_num())
  40. # endif // defined(FLASH_SAFE_API)
  41. #else
  42. # define FLASH_SEC_NUM 0x80
  43. #endif
  44. #define SYS_PARAM_SEC_NUM 4
  45. #define SYS_PARAM_SEC_START (FLASH_SEC_NUM - SYS_PARAM_SEC_NUM)
  46. #define INTERNAL_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE
  47. // #define INTERNAL_FLASH_SECTOR_ARRAY { 0x4000, 0x4000, 0x4000, 0x4000, 0x10000, 0x20000, 0x20000, 0x20000, 0x20000, 0x20000 }
  48. #define INTERNAL_FLASH_WRITE_UNIT_SIZE 4
  49. #define INTERNAL_FLASH_READ_UNIT_SIZE 4
  50. #define INTERNAL_FLASH_SIZE ( (SYS_PARAM_SEC_START) * INTERNAL_FLASH_SECTOR_SIZE )
  51. /* Note: technically irom0 starts at +0x10, but that's not a page boundary! */
  52. #define IROM0_START_MAPPED_ADDR 0x40080000
  53. #define IROM0_START_FLASH_ADDR 0x40000
  54. // TODO: might need to revamp all this once cache windows fully understood
  55. #define INTERNAL_FLASH_MAPPED_ADDRESS IROM0_START_MAPPED_ADDR
  56. #if defined(FLASH_SAFE_API)
  57. #define flash_write flash_safe_write
  58. #define flash_erase flash_safe_erase_sector
  59. #define flash_read flash_safe_read
  60. #else
  61. #define flash_write spi_flash_write
  62. #define flash_erase spi_flash_erase_sector
  63. #define flash_read spi_flash_read
  64. #endif // defined(FLASH_SAFE_API)
  65. #endif