gpio.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2013 Semtech
  8. Description: Generic GPIO driver implementation
  9. Comment: Relies on the specific board GPIO implementation as well as on
  10. IO expander driver implementation if one is available on the target
  11. board.
  12. License: Revised BSD License, see LICENSE.TXT file include in the project
  13. Maintainer: Miguel Luis and Gregory Cristian
  14. */
  15. #include "board.h"
  16. #include "gpio-board.h"
  17. #if defined( BOARD_IOE_EXT )
  18. #include "gpio-ioe.h"
  19. #endif
  20. void GpioInit( Gpio_t *obj, PinNames pin, PinModes mode, PinConfigs config, PinTypes type, uint32_t value )
  21. {
  22. if( ( uint32_t )( pin >> 4 ) <= 6 )
  23. {
  24. GpioMcuInit( obj, pin, mode, config, type, value );
  25. }
  26. else
  27. {
  28. #if defined( BOARD_IOE_EXT )
  29. // IOExt Pin
  30. GpioIoeInit( obj, pin, mode, config, type, value );
  31. #endif
  32. }
  33. }
  34. void GpioSetInterrupt( Gpio_t *obj, IrqModes irqMode, IrqPriorities irqPriority, GpioIrqHandler *irqHandler )
  35. {
  36. if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
  37. {
  38. GpioMcuSetInterrupt( obj, irqMode, irqPriority, irqHandler );
  39. }
  40. else
  41. {
  42. #if defined( BOARD_IOE_EXT )
  43. // IOExt Pin
  44. GpioIoeSetInterrupt( obj, irqMode, irqPriority, irqHandler );
  45. #endif
  46. }
  47. }
  48. void GpioRemoveInterrupt( Gpio_t *obj )
  49. {
  50. if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
  51. {
  52. //GpioMcuRemoveInterrupt( obj );
  53. }
  54. else
  55. {
  56. #if defined( BOARD_IOE_EXT )
  57. // IOExt Pin
  58. //GpioIoeRemoveInterrupt( obj );
  59. #endif
  60. }
  61. }
  62. void GpioWrite( Gpio_t *obj, uint32_t value )
  63. {
  64. if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
  65. {
  66. GpioMcuWrite( obj, value );
  67. }
  68. else
  69. {
  70. #if defined( BOARD_IOE_EXT )
  71. // IOExt Pin
  72. GpioIoeWrite( obj, value );
  73. #endif
  74. }
  75. }
  76. uint32_t GpioRead( Gpio_t *obj )
  77. {
  78. if( ( uint32_t )( obj->pin >> 4 ) <= 6 )
  79. {
  80. return GpioMcuRead( obj );
  81. }
  82. else
  83. {
  84. #if defined( BOARD_IOE_EXT )
  85. // IOExt Pin
  86. return GpioIoeRead( obj );
  87. #else
  88. return 0;
  89. #endif
  90. }
  91. }