Driver_GPIO.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2020 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef DRIVER_GPIO_H_
  8. #define DRIVER_GPIO_H_
  9. #ifdef __cplusplus
  10. extern "C"
  11. {
  12. #endif
  13. #include "Driver_Common.h"
  14. #define ARM_GPIO_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,0) /* API version */
  15. /*----- GPIO Logic Value -----*/
  16. #define ARM_GPIO_LOGIC_ZERO 0
  17. #define ARM_GPIO_LOGIC_ONE 1
  18. /*----- GPIO Interrupt Type -----*/
  19. #define ARM_GPIO_INTERRUPT_NONE 0x00U /* Disable Interrupt */
  20. #define ARM_GPIO_INTERRUPT_RISING_EDGE 0x01U /* Interrupt on Rising Edge */
  21. #define ARM_GPIO_INTERRUPT_FALLING_EDGE 0x02U /* Interrupt on Falling Edge */
  22. #define ARM_GPIO_INTERRUPT_RISING_FALLING_EDGE 0x03U /* Interrupt on Rising or Falling edge */
  23. #define ARM_GPIO_INTERRUPT_LOGIC_ONE 0x04U /* Interrupt on Logic Level One */
  24. #define ARM_GPIO_INTERRUPT_LOGIC_ZERO 0x05U /* Interrupt on Logic Level Zero */
  25. #define ARM_GPIO_INTERRUPT_MAX_CONFIG_PARA 0x06U /* Internal use and not used by user */
  26. /*----- GPIO Control Codes: Interrupt -----*/
  27. #define ARM_GPIO_CONTROL_INTERRUPT (0x01U)
  28. #define ARM_GPIO_INTERRUPT_DISABLE (0x00U)
  29. #define ARM_GPIO_INTERRUPT_ENABLE (0x01U)
  30. typedef void (*ARM_GPIO_SignalEvent_t) (uint32_t pin); ///< Pointer to \ref ARM_GPIO_SignalEvent : Signal GPIO Event.
  31. /**
  32. \brief GPIO Driver Capabilities.
  33. */
  34. typedef struct _ARM_GPIO_CAPABILITIES {
  35. uint32_t irq : 1; ///< supports IRQ
  36. uint32_t reserved : 31; ///< Reserved (must be zero)
  37. } ARM_GPIO_CAPABILITIES;
  38. /**
  39. \brief Access structure of the GPIO Driver.
  40. */
  41. typedef struct _ARM_DRIVER_GPIO {
  42. ARM_DRIVER_VERSION (*GetVersion) (void);
  43. ARM_GPIO_CAPABILITIES (*GetCapabilities)(void);
  44. int32_t (*Initialize) (void);
  45. int32_t (*Uninitialize) (void);
  46. int32_t (*PowerControl) (ARM_POWER_STATE state);
  47. /// Init Pin As Output
  48. int32_t (*InitPinAsOutput)(uint32_t pin, uint32_t output_logic);
  49. /// Init Pin as Input with or without interrupt enabled , with or without callback if interrupt is requested
  50. int32_t (*InitPinAsInput)(uint32_t pin, uint32_t irq_type, ARM_GPIO_SignalEvent_t cb_event);
  51. /// Write pin with ARM_GPIO_LOGIC_[ONE|ZERO]
  52. int32_t (*PinWrite) (uint32_t pin, uint32_t logic_value);
  53. /// Toggle specified Pin
  54. int32_t (*PinToggle) (uint32_t pin);
  55. /// Read Logic value from pin. false stands for logic zero, true stands for logic one.
  56. bool (*PinRead) (uint32_t pin);
  57. /// Write selected pins with logic one or zero. Example, pin0 and pin 4, ored_pins = (0x01U << 0U) | (0x01 << 4U)
  58. int32_t (*PortWrite) (uint32_t ored_pins, uint32_t logic_value);
  59. /// Toggle selected pins. Example, pin0 and pin 4, ored_pins = (0x01U << 0U) | (0x01 << 4U)
  60. int32_t (*PortToggle) (uint32_t ored_pins);
  61. /// Read all pins status for this GPIO interface. use (read_value & (0x01U << 4)) to decide whether pin4 is logic one or logic zero
  62. uint32_t (*PortRead)(void);
  63. /// Configuare the pin with field ARM_GPIO_CONTROL_[INTERRUPT] with value filled into arg. values are defined following the ARM_GPIO_CONTROL_XXX.
  64. int32_t (*Control)(uint32_t pin, uint32_t control, uint32_t arg);
  65. } const ARM_DRIVER_GPIO;
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif /* DRIVER_GPIO_H_ */