drv_enc28j60.c 884 B

12345678910111213141516171819202122232425262728293031323334
  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. * 2018-08-27 ZYLX the first version
  9. */
  10. #include <drivers/pin.h>
  11. #include <enc28j60.h>
  12. #include "drv_spi.h"
  13. #include "board.h"
  14. #define PIN_NRF_IRQ GET_PIN(E,2)
  15. #define PIN_SPI_CS GET_PIN(A,4)
  16. int enc28j60_init(void)
  17. {
  18. __HAL_RCC_GPIOD_CLK_ENABLE();
  19. rt_hw_spi_device_attach("spi1", "spi11", PIN_SPI_CS);
  20. /* attach enc28j60 to spi. spi11 cs - PA4 */
  21. enc28j60_attach("spi11");
  22. /* init interrupt pin */
  23. rt_pin_mode(PIN_NRF_IRQ, PIN_MODE_INPUT_PULLUP);
  24. rt_pin_attach_irq(PIN_NRF_IRQ, PIN_IRQ_MODE_FALLING, (void(*)(void*))enc28j60_isr, RT_NULL);
  25. rt_pin_irq_enable(PIN_NRF_IRQ, PIN_IRQ_ENABLE);
  26. return 0;
  27. }
  28. INIT_COMPONENT_EXPORT(enc28j60_init);