gpio.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * copyright (c) Espressif System 2010
  3. *
  4. */
  5. #ifndef _GPIO_H_
  6. #define _GPIO_H_
  7. #define GPIO_PIN_ADDR(i) (GPIO_PIN0_ADDRESS + i*4)
  8. #define GPIO_ID_IS_PIN_REGISTER(reg_id) \
  9. ((reg_id >= GPIO_ID_PIN0) && (reg_id <= GPIO_ID_PIN(GPIO_PIN_COUNT-1)))
  10. #define GPIO_REGID_TO_PINIDX(reg_id) ((reg_id) - GPIO_ID_PIN0)
  11. typedef enum {
  12. GPIO_PIN_INTR_DISABLE = 0,
  13. GPIO_PIN_INTR_POSEDGE = 1,
  14. GPIO_PIN_INTR_NEGEDGE = 2,
  15. GPIO_PIN_INTR_ANYEGDE = 3,
  16. GPIO_PIN_INTR_LOLEVEL = 4,
  17. GPIO_PIN_INTR_HILEVEL = 5
  18. } GPIO_INT_TYPE;
  19. #define GPIO_OUTPUT_SET(gpio_no, bit_value) \
  20. gpio_output_set(bit_value<<gpio_no, ((~bit_value)&0x01)<<gpio_no, 1<<gpio_no,0)
  21. #define GPIO_DIS_OUTPUT(gpio_no) gpio_output_set(0,0,0, 1<<gpio_no)
  22. #define GPIO_INPUT_GET(gpio_no) ((gpio_input_get()>>gpio_no)&BIT0)
  23. /* GPIO interrupt handler, registered through gpio_intr_handler_register */
  24. typedef void (* gpio_intr_handler_fn_t)(uint32 intr_mask, void *arg);
  25. /*
  26. * Initialize GPIO. This includes reading the GPIO Configuration DataSet
  27. * to initialize "output enables" and pin configurations for each gpio pin.
  28. * Must be called once during startup.
  29. */
  30. void gpio_init(void);
  31. /*
  32. * Change GPIO pin output by setting, clearing, or disabling pins.
  33. * In general, it is expected that a bit will be set in at most one
  34. * of these masks. If a bit is clear in all masks, the output state
  35. * remains unchanged.
  36. *
  37. * There is no particular ordering guaranteed; so if the order of
  38. * writes is significant, calling code should divide a single call
  39. * into multiple calls.
  40. */
  41. void gpio_output_set(uint32 set_mask,
  42. uint32 clear_mask,
  43. uint32 enable_mask,
  44. uint32 disable_mask);
  45. /*
  46. * Sample the value of GPIO input pins and returns a bitmask.
  47. */
  48. uint32 gpio_input_get(void);
  49. /*
  50. * Set the specified GPIO register to the specified value.
  51. * This is a very general and powerful interface that is not
  52. * expected to be used during normal operation. It is intended
  53. * mainly for debug, or for unusual requirements.
  54. */
  55. void gpio_register_set(uint32 reg_id, uint32 value);
  56. /* Get the current value of the specified GPIO register. */
  57. uint32 gpio_register_get(uint32 reg_id);
  58. /*
  59. * Register an application-specific interrupt handler for GPIO pin
  60. * interrupts. Once the interrupt handler is called, it will not
  61. * be called again until after a call to gpio_intr_ack. Any GPIO
  62. * interrupts that occur during the interim are masked.
  63. *
  64. * The application-specific handler is called with a mask of
  65. * pending GPIO interrupts. After processing pin interrupts, the
  66. * application-specific handler may wish to use gpio_intr_pending
  67. * to check for any additional pending interrupts before it returns.
  68. */
  69. void gpio_intr_handler_register(gpio_intr_handler_fn_t fn, void *arg);
  70. /* Determine which GPIO interrupts are pending. */
  71. uint32 gpio_intr_pending(void);
  72. /*
  73. * Acknowledge GPIO interrupts.
  74. * Intended to be called from the gpio_intr_handler_fn.
  75. */
  76. void gpio_intr_ack(uint32 ack_mask);
  77. void gpio_pin_wakeup_enable(uint32 i, GPIO_INT_TYPE intr_state);
  78. void gpio_pin_wakeup_disable();
  79. void gpio_pin_intr_state_set(uint32 i, GPIO_INT_TYPE intr_state);
  80. #endif // _GPIO_H_