gpio_api.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /** \addtogroup hal */
  2. /** @{*/
  3. /* mbed Microcontroller Library
  4. * Copyright (c) 2006-2013 ARM Limited
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef MBED_GPIO_API_H
  19. #define MBED_GPIO_API_H
  20. #include <stdint.h>
  21. #include "device.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /**
  26. * \defgroup hal_gpio GPIO HAL functions
  27. * @{
  28. */
  29. /** Set the given pin as GPIO
  30. *
  31. * @param pin The pin to be set as GPIO
  32. * @return The GPIO port mask for this pin
  33. **/
  34. uint32_t gpio_set(PinName pin);
  35. /* Checks if gpio object is connected (pin was not initialized with NC)
  36. * @param pin The pin to be set as GPIO
  37. * @return 0 if port is initialized with NC
  38. **/
  39. int gpio_is_connected(const gpio_t *obj);
  40. /** Initialize the GPIO pin
  41. *
  42. * @param obj The GPIO object to initialize
  43. * @param pin The GPIO pin to initialize
  44. */
  45. void gpio_init(gpio_t *obj, PinName pin);
  46. /** Set the input pin mode
  47. *
  48. * @param obj The GPIO object
  49. * @param mode The pin mode to be set
  50. */
  51. void gpio_mode(gpio_t *obj, PinMode mode);
  52. /** Set the pin direction
  53. *
  54. * @param obj The GPIO object
  55. * @param direction The pin direction to be set
  56. */
  57. void gpio_dir(gpio_t *obj, PinDirection direction);
  58. /** Set the output value
  59. *
  60. * @param obj The GPIO object
  61. * @param value The value to be set
  62. */
  63. void gpio_write(gpio_t *obj, int value);
  64. /** Read the input value
  65. *
  66. * @param obj The GPIO object
  67. * @return An integer value 1 or 0
  68. */
  69. int gpio_read(gpio_t *obj);
  70. // the following functions are generic and implemented in the common gpio.c file
  71. // TODO: fix, will be moved to the common gpio header file
  72. /** Init the input pin and set mode to PullDefault
  73. *
  74. * @param gpio The GPIO object
  75. * @param pin The pin name
  76. */
  77. void gpio_init_in(gpio_t *gpio, PinName pin);
  78. /** Init the input pin and set the mode
  79. *
  80. * @param gpio The GPIO object
  81. * @param pin The pin name
  82. * @param mode The pin mode to be set
  83. */
  84. void gpio_init_in_ex(gpio_t *gpio, PinName pin, PinMode mode);
  85. /** Init the output pin as an output, with predefined output value 0
  86. *
  87. * @param gpio The GPIO object
  88. * @param pin The pin name
  89. * @return An integer value 1 or 0
  90. */
  91. void gpio_init_out(gpio_t *gpio, PinName pin);
  92. /** Init the pin as an output and set the output value
  93. *
  94. * @param gpio The GPIO object
  95. * @param pin The pin name
  96. * @param value The value to be set
  97. */
  98. void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value);
  99. /** Init the pin to be in/out
  100. *
  101. * @param gpio The GPIO object
  102. * @param pin The pin name
  103. * @param direction The pin direction to be set
  104. * @param mode The pin mode to be set
  105. * @param value The value to be set for an output pin
  106. */
  107. void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value);
  108. /**@}*/
  109. #ifdef __cplusplus
  110. }
  111. #endif
  112. #endif
  113. /** @}*/