pin.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * File : pin.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2015, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2015-01-20 Bernard the first version
  23. */
  24. #ifndef PIN_H__
  25. #define PIN_H__
  26. #include <rtthread.h>
  27. #include <rtdevice.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* pin device and operations for RT-Thread */
  32. struct rt_device_pin
  33. {
  34. struct rt_device parent;
  35. const struct rt_pin_ops *ops;
  36. };
  37. #define PIN_LOW 0x00
  38. #define PIN_HIGH 0x01
  39. #define PIN_MODE_OUTPUT 0x00
  40. #define PIN_MODE_INPUT 0x01
  41. #define PIN_MODE_INPUT_PULLUP 0x02
  42. struct rt_device_pin_mode
  43. {
  44. rt_uint16_t pin;
  45. rt_uint16_t mode;
  46. };
  47. struct rt_device_pin_status
  48. {
  49. rt_uint16_t pin;
  50. rt_uint16_t status;
  51. };
  52. struct rt_pin_ops
  53. {
  54. void (*pin_mode)(struct rt_device *device, rt_base_t pin, rt_base_t mode);
  55. void (*pin_write)(struct rt_device *device, rt_base_t pin, rt_base_t value);
  56. int (*pin_read)(struct rt_device *device, rt_base_t pin);
  57. /* TODO: add GPIO interrupt */
  58. };
  59. int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data);
  60. void rt_pin_mode(rt_base_t pin, rt_base_t mode);
  61. void rt_pin_write(rt_base_t pin, rt_base_t value);
  62. int rt_pin_read(rt_base_t pin);
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif