drv_gpio.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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-06-16 guohp1128 first version
  9. */
  10. #ifndef __DRV_GPIO_H__
  11. #define __DRV_GPIO_H__
  12. #include <board.h>
  13. #include <rtdevice.h>
  14. #include <nrf52840.h>
  15. #include <hal/nrf_gpio.h>
  16. #include <drivers/include/nrfx_gpiote.h>
  17. #define __NRF5X_PORT(port) NRF_P##port##_BASE
  18. #define GET_PIN(PORTx,PIN) (rt_base_t)((32 * ( ((rt_base_t)__NRF5X_PORT(PORTx) - (rt_base_t)NRF_P0_BASE)/(0x0300UL) )) + PIN)
  19. #define __NRF5X_PIN(index, gpio, gpio_index) \
  20. { \
  21. index, NRF_P##gpio, gpio_index \
  22. }
  23. #define __NRF5X_PIN_RESERVE \
  24. { \
  25. -1, 0, 0 \
  26. }
  27. /* nrf5x GPIO driver */
  28. struct pin_index
  29. {
  30. int index;
  31. NRF_GPIO_Type *gpio;//NRF_P0 or NRF_P1
  32. uint32_t pin;
  33. };
  34. static void nrf5x_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value);
  35. static int nrf5x_pin_read(rt_device_t dev, rt_base_t pin);
  36. static void nrf5x_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode);
  37. static rt_err_t nrf5x_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
  38. rt_uint32_t mode, void (*hdr)(void *args), void *args);
  39. static rt_err_t nrf5x_pin_dettach_irq(struct rt_device *device, rt_int32_t pin);
  40. static rt_err_t nrf5x_pin_irq_enable(struct rt_device *device, rt_base_t pin,
  41. rt_uint32_t enabled);
  42. int rt_hw_pin_init(void);
  43. #endif /* __DRV_GPIO_H__ */