pin_map.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "pin_map.h"
  2. #include "eagle_soc.h"
  3. #include "osapi.h"
  4. uint32_t pin_mux[GPIO_PIN_NUM];
  5. uint8_t pin_num[GPIO_PIN_NUM];
  6. uint8_t pin_func[GPIO_PIN_NUM];
  7. #ifdef GPIO_INTERRUPT_ENABLE
  8. uint8_t pin_num_inv[GPIO_PIN_NUM_INV];
  9. uint8_t pin_int_type[GPIO_PIN_NUM];
  10. #endif
  11. typedef struct {
  12. int8 mux;
  13. uint8 num;
  14. uint8 func;
  15. uint8 intr_type;
  16. } pin_rec;
  17. #define DECLARE_PIN(n,p) { (PERIPHS_IO_MUX_##p##_U - PERIPHS_IO_MUX), n, FUNC_GPIO##n, GPIO_PIN_INTR_DISABLE}
  18. #if defined(__ESP8266__)
  19. static const pin_rec pin_map[] = {
  20. {PAD_XPD_DCDC_CONF - PERIPHS_IO_MUX, 16, 0, GPIO_PIN_INTR_DISABLE},
  21. DECLARE_PIN( 5, GPIO5),
  22. DECLARE_PIN( 4, GPIO4),
  23. DECLARE_PIN( 0, GPIO0),
  24. DECLARE_PIN( 2, GPIO2),
  25. DECLARE_PIN(14, MTMS),
  26. DECLARE_PIN(12, MTDI),
  27. DECLARE_PIN(13, MTCK),
  28. DECLARE_PIN(15, MTDO),
  29. DECLARE_PIN( 3, U0RXD),
  30. DECLARE_PIN( 1, U0TXD),
  31. DECLARE_PIN( 9, SD_DATA2),
  32. DECLARE_PIN(10, SD_DATA3)
  33. };
  34. #elif defined(__ESP32__)
  35. // FIXME: fill in
  36. static const pin_rec pin_map[] = {};
  37. #endif
  38. void get_pin_map(void) {
  39. /*
  40. * Flash copy of the pin map. This has to be copied to RAM to be accessible from the ISR.
  41. * Note that the mux field is a signed offset from PERIPHS_IO_MUX to allow the whole struct
  42. * to be stored in a single 32-bit record.
  43. */
  44. int i;
  45. /* Take temporary stack copy to avoid unaligned exceptions on Flash version */
  46. pin_rec pin[GPIO_PIN_NUM];
  47. os_memcpy(pin, pin_map, sizeof(pin_map) );
  48. for (i=0; i<GPIO_PIN_NUM; i++) {
  49. pin_mux[i] = pin[i].mux + PERIPHS_IO_MUX;
  50. pin_func[i] = pin[i].func;
  51. pin_num[i] = pin[i].num;
  52. #ifdef GPIO_INTERRUPT_ENABLE
  53. pin_num_inv[pin_num[i]] = i;
  54. pin_int_type[i] = pin[i].intr_type;
  55. #endif
  56. }
  57. }