rt-thread-official/bsp/nuvoton/numaker-m2354/board/board_dev.c

128 lines
3.3 KiB
C

/**************************************************************************//**
*
* @copyright (C) 2019 Nuvoton Technology Corp. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-1-16 Wayne First version
*
******************************************************************************/
#include <rtdevice.h>
#include <drv_gpio.h>
#if defined(BOARD_USING_ESP8266)
static int rt_hw_esp8266_port(void)
{
rt_base_t esp_rst_pin = NU_GET_PININDEX(NU_PC, 13);
rt_base_t esp_fwupdate_pin = NU_GET_PININDEX(NU_PD, 12);
/* ESP8266 reset pin PC.13 */
rt_pin_mode(esp_rst_pin, PIN_MODE_OUTPUT);
rt_pin_write(esp_rst_pin, 1);
/* ESP8266 reset pin PD.12 */
rt_pin_mode(esp_fwupdate_pin, PIN_MODE_OUTPUT);
rt_pin_write(esp_fwupdate_pin, 1);
return 0;
}
INIT_APP_EXPORT(rt_hw_esp8266_port);
#endif /* BOARD_USING_ESP8266 */
#if defined(BOARD_USING_LCD_ILI9341) && defined(NU_PKG_USING_ILI9341_SPI)
#if defined(NU_PKG_USING_ADC_TOUCH_SW)
#include "adc_touch.h"
#include "touch_sw.h"
#include "NuMicro.h"
#define NU_MFP_POS(PIN) ((PIN % 8) * 4)
#define NU_MFP_MSK(PIN) (0xful << NU_MFP_POS(PIN))
S_CALIBRATION_MATRIX g_sCalMat = { 52, 6247, -2804852, 4917, 47, -2309716, 65536 };
static void nu_pin_func(rt_base_t pin, int data)
{
uint32_t pin_index = NU_GET_PINS(pin);
uint32_t port_index = NU_GET_PORT(pin);
__IO uint32_t *GPx_MFPx = ((__IO uint32_t *) &SYS->GPA_MFPL) + port_index * 2 + (pin_index / 8);
uint32_t MFP_Msk = NU_MFP_MSK(pin_index);
*GPx_MFPx = (*GPx_MFPx & (~MFP_Msk)) | data;
}
static void tp_switch_to_analog(rt_base_t pin)
{
GPIO_T *port = (GPIO_T *)(GPIOA_BASE + (0x40) * NU_GET_PORT(pin));
if (pin == NU_GET_PININDEX(NU_PB, 11))
nu_pin_func(pin, SYS_GPB_MFPH_PB11MFP_EADC0_CH11);
else if (pin == NU_GET_PININDEX(NU_PB, 8))
nu_pin_func(pin, SYS_GPB_MFPH_PB8MFP_EADC0_CH8);
GPIO_DISABLE_DIGITAL_PATH(port, NU_GET_PIN_MASK(NU_GET_PINS(pin)));
}
static void tp_switch_to_digital(rt_base_t pin)
{
GPIO_T *port = (GPIO_T *)(GPIOA_BASE + (0x40) * NU_GET_PORT(pin));
nu_pin_func(pin, 0);
/* Enable digital path on these EADC pins */
GPIO_ENABLE_DIGITAL_PATH(port, NU_GET_PIN_MASK(NU_GET_PINS(pin)));
}
static S_TOUCH_SW sADCTP =
{
.adc_name = "eadc0",
.i32ADCChnYU = 11,
.i32ADCChnXR = 8,
.pin =
{
NU_GET_PININDEX(NU_PB, 10), // XL
NU_GET_PININDEX(NU_PB, 11), // YU
NU_GET_PININDEX(NU_PB, 8), // XR
NU_GET_PININDEX(NU_PB, 9), // YD
},
.switch_to_analog = tp_switch_to_analog,
.switch_to_digital = tp_switch_to_digital,
};
#endif
#include <lcd_ili9341.h>
#if defined(PKG_USING_GUIENGINE)
#include <rtgui/driver.h>
#endif
int rt_hw_ili9341_port(void)
{
if (rt_hw_lcd_ili9341_spi_init("spi1", RT_NULL) != RT_EOK)
return -1;
rt_hw_lcd_ili9341_init();
#if defined(PKG_USING_GUIENGINE)
rt_device_t lcd_ili9341;
lcd_ili9341 = rt_device_find("lcd");
if (lcd_ili9341)
{
rtgui_graphic_set_device(lcd_ili9341);
}
#endif
#if defined(NU_PKG_USING_ADC_TOUCH_SW)
nu_adc_touch_sw_register(&sADCTP);
#endif
return 0;
}
INIT_COMPONENT_EXPORT(rt_hw_ili9341_port);
#endif /* BOARD_USING_LCD_ILI9341 */