vgpio.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-12-21 stackRyan first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #define DBG_TAG VDEVICE_PIN_NAME
  13. #define DBG_LVL DBG_LOG
  14. #include <rtdbg.h>
  15. #ifdef VDEVICE_USING_PIN
  16. static void _pin_mode(struct rt_device *device, rt_base_t pin, rt_base_t mode)
  17. {
  18. /* Todo:set pin mode */
  19. LOG_D("pin_mode: pin_%d,mode_%d", pin, mode);
  20. }
  21. static void _pin_write(struct rt_device *device, rt_base_t pin, rt_base_t value)
  22. {
  23. /* Todo:set pin low or high */
  24. LOG_D("pin_write: pin_%d,value_%d", pin, value);
  25. }
  26. static int _pin_read(struct rt_device *device, rt_base_t pin)
  27. {
  28. /* Todo:get pin status and return status value */
  29. LOG_D("pin_read: pin_%d,value_0");
  30. return 0;
  31. }
  32. static rt_err_t _pin_attach_irq(struct rt_device *device, rt_int32_t pin,
  33. rt_uint32_t mode, void (*hdr)(void *args), void *args)
  34. {
  35. rt_err_t ret = RT_EOK;
  36. /* Todo:attach hdr to pin ISR */
  37. LOG_D("pin_attach_irq: pin_%d,mode_%d", pin, mode);
  38. return ret;
  39. }
  40. static rt_err_t _pin_detach_irq(struct rt_device *device, rt_int32_t pin)
  41. {
  42. rt_err_t ret = RT_EOK;
  43. /* Todo:detach hdr from pin ISR */
  44. LOG_D("pin_detach_irq: pin_%d", pin);
  45. return ret;
  46. }
  47. static rt_err_t _pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_uint32_t enabled)
  48. {
  49. rt_err_t ret = RT_EOK;
  50. /* Todo:enable pin ISR */
  51. LOG_D("pin_irq_enable: pin_%d,Enabled:%d", pin, enabled);
  52. return ret;
  53. }
  54. const static struct rt_pin_ops _pin_ops =
  55. {
  56. _pin_mode,
  57. _pin_write,
  58. _pin_read,
  59. _pin_attach_irq,
  60. _pin_detach_irq,
  61. _pin_irq_enable
  62. };
  63. int rt_hw_pin_init(void)
  64. {
  65. rt_err_t ret = RT_EOK;
  66. ret = rt_device_pin_register(VDEVICE_PIN_NAME, &_pin_ops, RT_NULL);
  67. LOG_D("rt_hw_pin_init succeed!");
  68. return ret;
  69. }
  70. INIT_DEVICE_EXPORT(rt_hw_pin_init);
  71. #endif /* PKG_USING_PIN */