board_dev.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**************************************************************************//**
  2. *
  3. * @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2020-1-16 Wayne First version
  10. *
  11. ******************************************************************************/
  12. #include <rtdevice.h>
  13. #include <drv_gpio.h>
  14. #if defined(BOARD_USING_ESP8266)
  15. static int rt_hw_esp8266_port(void)
  16. {
  17. rt_base_t esp_rst_pin = NU_GET_PININDEX(NU_PC, 13);
  18. rt_base_t esp_fwupdate_pin = NU_GET_PININDEX(NU_PD, 12);
  19. /* ESP8266 reset pin PC.13 */
  20. rt_pin_mode(esp_rst_pin, PIN_MODE_OUTPUT);
  21. rt_pin_write(esp_rst_pin, 1);
  22. /* ESP8266 reset pin PD.12 */
  23. rt_pin_mode(esp_fwupdate_pin, PIN_MODE_OUTPUT);
  24. rt_pin_write(esp_fwupdate_pin, 1);
  25. return 0;
  26. }
  27. INIT_APP_EXPORT(rt_hw_esp8266_port);
  28. #endif /* BOARD_USING_ESP8266 */
  29. #if defined(BOARD_USING_LCD_ILI9341) && defined(NU_PKG_USING_ILI9341_SPI)
  30. #if defined(NU_PKG_USING_ADC_TOUCH_SW)
  31. #include "adc_touch.h"
  32. #include "touch_sw.h"
  33. #include "NuMicro.h"
  34. #define NU_MFP_POS(PIN) ((PIN % 8) * 4)
  35. #define NU_MFP_MSK(PIN) (0xful << NU_MFP_POS(PIN))
  36. S_CALIBRATION_MATRIX g_sCalMat = { 52, 6247, -2804852, 4917, 47, -2309716, 65536 };
  37. static void nu_pin_func(rt_base_t pin, int data)
  38. {
  39. uint32_t pin_index = NU_GET_PINS(pin);
  40. uint32_t port_index = NU_GET_PORT(pin);
  41. __IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8);
  42. uint32_t MFP_Msk = NU_MFP_MSK(pin_index);
  43. *GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data;
  44. }
  45. static void tp_switch_to_analog(rt_base_t pin)
  46. {
  47. GPIO_T *port = (GPIO_T *)(GPIOA_BASE + (0x40) * NU_GET_PORT(pin));
  48. if (pin == NU_GET_PININDEX(NU_PB, 11))
  49. nu_pin_func(pin, SYS_GPB_MFPH_PB11MFP_EADC0_CH11);
  50. else if (pin == NU_GET_PININDEX(NU_PB, 8))
  51. nu_pin_func(pin, SYS_GPB_MFPH_PB8MFP_EADC0_CH8);
  52. GPIO_DISABLE_DIGITAL_PATH(port, NU_GET_PIN_MASK(NU_GET_PINS(pin)));
  53. }
  54. static void tp_switch_to_digital(rt_base_t pin)
  55. {
  56. GPIO_T *port = (GPIO_T *)(GPIOA_BASE + (0x40) * NU_GET_PORT(pin));
  57. nu_pin_func(pin, 0);
  58. /* Enable digital path on these EADC pins */
  59. GPIO_ENABLE_DIGITAL_PATH(port, NU_GET_PIN_MASK(NU_GET_PINS(pin)));
  60. }
  61. static S_TOUCH_SW sADCTP =
  62. {
  63. .adc_name = "eadc0",
  64. .i32ADCChnYU = 11,
  65. .i32ADCChnXR = 8,
  66. .pin =
  67. {
  68. NU_GET_PININDEX(NU_PB, 10), // XL
  69. NU_GET_PININDEX(NU_PB, 11), // YU
  70. NU_GET_PININDEX(NU_PB, 8), // XR
  71. NU_GET_PININDEX(NU_PB, 9), // YD
  72. },
  73. .switch_to_analog = tp_switch_to_analog,
  74. .switch_to_digital = tp_switch_to_digital,
  75. };
  76. #endif
  77. #include <lcd_ili9341.h>
  78. #if defined(PKG_USING_GUIENGINE)
  79. #include <rtgui/driver.h>
  80. #endif
  81. int rt_hw_ili9341_port(void)
  82. {
  83. if (rt_hw_lcd_ili9341_spi_init("spi1", RT_NULL) != RT_EOK)
  84. return -1;
  85. rt_hw_lcd_ili9341_init();
  86. #if defined(PKG_USING_GUIENGINE)
  87. rt_device_t lcd_ili9341;
  88. lcd_ili9341 = rt_device_find("lcd");
  89. if (lcd_ili9341)
  90. {
  91. rtgui_graphic_set_device(lcd_ili9341);
  92. }
  93. #endif
  94. #if defined(NU_PKG_USING_ADC_TOUCH_SW)
  95. nu_adc_touch_sw_register(&sADCTP);
  96. #endif
  97. return 0;
  98. }
  99. INIT_COMPONENT_EXPORT(rt_hw_ili9341_port);
  100. #endif /* BOARD_USING_LCD_ILI9341 */