未验证 提交 446bde64 编写于 作者: W Wayne 提交者: GitHub

[Nuvoton] Update drivers (#5501)

* Update drivers.

1. Improve LVGL avg FPS.
2. Sync configuration to 4.1.0.

* [Nuvoton] Update drivers.

1. Fix open-control order issue in CAN driver.
2. [N9H30] Improve N9H30 I2C busy-wait implementation.
3. [N9H30] Support 1024x600x32b LCD panel.
4. Move nu_packages menu into sub-menu of board.

* Update menu-option.

1. Set BOARD_USING_LCM is on by default.
2. Fix default value setting in choice-option.

* Fix control function in I2C driver.

* Add sdk_dist.py and ADC touching calibration function.
Co-authored-by: NWayne Lin <wclin@nuvoton.com>
上级 ebe9fc57
......@@ -90,7 +90,7 @@ static rt_err_t nu_i2c_bus_control(struct rt_i2c_bus_device *bus, rt_uint32_t u3
RT_ASSERT(bus != RT_NULL);
nu_i2c = (nu_i2c_bus_t *) bus;
switch (RT_I2C_DEV_CTRL_CLK)
switch (u32Cmd)
{
case RT_I2C_DEV_CTRL_CLK:
I2C_SetBusClockFreq(nu_i2c->I2C, u32Value);
......
......@@ -99,7 +99,7 @@ static rt_err_t nu_i2c_bus_control(struct rt_i2c_bus_device *bus, rt_uint32_t u3
RT_ASSERT(bus != RT_NULL);
nu_i2c = (nu_i2c_bus_t *) bus;
switch (RT_I2C_DEV_CTRL_CLK)
switch (u32Cmd)
{
case RT_I2C_DEV_CTRL_CLK:
I2C_SetBusClockFreq(nu_i2c->I2C, u32Value);
......
......@@ -10,7 +10,7 @@
#define __CAN_REG_H__
#if defined ( __CC_ARM )
#pragma anon_unions
#pragma anon_unions
#endif
/**
......@@ -586,8 +586,8 @@ typedef struct
#define CAN_BTIME_TSEG2_Pos (12) /*!< CAN_T::BTIME: TSeg2 Position */
#define CAN_BTIME_TSEG2_Msk (0x7ul << CAN_BTIME_TSEG2_Pos) /*!< CAN_T::BTIME: TSeg2 Mask */
#define CAN_IIDR_IntId_Pos (0) /*!< CAN_T::IIDR: IntId Position */
#define CAN_IIDR_IntId_Msk (0xfffful << CAN_IIDR_IntId_Pos) /*!< CAN_T::IIDR: IntId Mask */
#define CAN_IIDR_INTID_Pos (0) /*!< CAN_T::IIDR: IntId Position */
#define CAN_IIDR_INTID_Msk (0xfffful << CAN_IIDR_INTID_Pos) /*!< CAN_T::IIDR: IntId Mask */
#define CAN_TEST_BASIC_Pos (2) /*!< CAN_T::TEST: Basic Position */
#define CAN_TEST_BASIC_Msk (0x1ul << CAN_TEST_BASIC_Pos) /*!< CAN_T::TEST: Basic Mask */
......@@ -753,7 +753,7 @@ typedef struct
/**@}*/ /* end of REGISTER group */
#if defined ( __CC_ARM )
#pragma no_anon_unions
#pragma no_anon_unions
#endif
#endif /* __CAN_REG_H__ */
......@@ -99,7 +99,7 @@ static rt_err_t nu_i2c_bus_control(struct rt_i2c_bus_device *bus, rt_uint32_t u3
RT_ASSERT(bus != RT_NULL);
nu_i2c = (nu_i2c_bus_t *) bus;
switch (RT_I2C_DEV_CTRL_CLK)
switch (u32Cmd)
{
case RT_I2C_DEV_CTRL_CLK:
I2C_SetBusClockFreq(nu_i2c->I2C, u32Value);
......
......@@ -151,8 +151,8 @@ typedef struct
#define CAN_BTIME_TSEG2_Pos (12) /*!< CAN_T::BTIME: TSeg2 Position */
#define CAN_BTIME_TSEG2_Msk (0x7ul << CAN_BTIME_TSEG2_Pos) /*!< CAN_T::BTIME: TSeg2 Mask */
#define CAN_IIDR_IntId_Pos (0) /*!< CAN_T::IIDR: IntId Position */
#define CAN_IIDR_IntId_Msk (0xfffful << CAN_IIDR_IntId_Pos) /*!< CAN_T::IIDR: IntId Mask */
#define CAN_IIDR_INTID_Pos (0) /*!< CAN_T::IIDR: IntId Position */
#define CAN_IIDR_INTID_Msk (0xfffful << CAN_IIDR_INTID_Pos) /*!< CAN_T::IIDR: IntId Mask */
#define CAN_TEST_BASIC_Pos (2) /*!< CAN_T::TEST: Basic Position */
#define CAN_TEST_BASIC_Msk (0x1ul << CAN_TEST_BASIC_Pos) /*!< CAN_T::TEST: Basic Mask */
......
......@@ -171,11 +171,17 @@ typedef struct
uint32_t *pFrameBuffer; /*!< User input, The address of OSD source image */
} OSDFORMATEX;
#define DIS_PANEL_E50A2V1 0
#define DIS_PANEL_ILI9341_MPU80 1
#define DIS_LSA40AT9001 2
#define DIS_PANEL_FW070TFT 3
#define DIS_PANEL_FW043TFT 4
enum DIS_PANEL
{
DIS_PANEL_E50A2V1 = 0,
DIS_PANEL_ILI9341_MPU80,
DIS_LSA40AT9001,
DIS_PANEL_FW070TFT,
DIS_PANEL_FW043TFT,
DIS_PANEL_FW070TFT_WSVGA,
DIS_PANEL_CNT
};
typedef struct
{
uint32_t u32DevWidth; /*!< Panel width */
......
......@@ -770,4 +770,8 @@ void UART_SetLineConfig(UART_T *uart, uint32_t u32baudrate, uint32_t u32data_wid
/*@}*/ /* end of group N9H30_Device_Driver */
#ifdef __cplusplus
}
#endif
#endif
......@@ -168,9 +168,82 @@ static VPOST_T DEF_FW043TFT =
}
};
#define FW070TFT_WSVGA_WIDTH 1024 /*!< XRES */
#define FW070TFT_WSVGA_HEIGHT 600 /*!< YRES */
#define FW070TFT_WSVGA_MARGIN_LEFT 160 /*!< HBP (Horizontal Back Porch) */
#define FW070TFT_WSVGA_MARGIN_RIGHT 160 /*!< HFP (Horizontal Front Porch) */
#define FW070TFT_WSVGA_MARGIN_UPPER 12 /*!< VBP (Vertical Back Porch) */
#define FW070TFT_WSVGA_MARGIN_LOWER 23 /*!< VFP (Vertical Front Porch) */
#define FW070TFT_WSVGA_HSYNC_LEN 1 /*!< HPW (HSYNC plus width) */
#define FW070TFT_WSVGA_VSYNC_LEN 1 /*!< VPW (VSYNC width) */
static VPOST_T DEF_FW070TFT_WSVGA =
{
FW070TFT_WSVGA_WIDTH, /*!< Panel width */
FW070TFT_WSVGA_HEIGHT, /*!< Panel height */
0, /*!< MPU command line low indicator */
0, /*!< MPU command width */
0, /*!< MPU bus width */
VPOSTB_DATA16or18, /*!< Display bus width */
0, /*!< MPU mode */
VPOSTB_COLORTYPE_16M, /*!< Display colors */
VPOSTB_DEVICE_SYNC_HIGHCOLOR, /*!< Type of display panel */
.sCRTCSIZE =
{
/*!< Horizontal Total */
.HTT = FW070TFT_WSVGA_MARGIN_LEFT + FW070TFT_WSVGA_WIDTH + FW070TFT_WSVGA_MARGIN_RIGHT,
/*!< Vertical Total */
.VTT = FW070TFT_WSVGA_MARGIN_UPPER + FW070TFT_WSVGA_HEIGHT + FW070TFT_WSVGA_MARGIN_LOWER,
},
.sCRTCDEND =
{
/*!< Horizontal Display Enable End */
.HDEND = FW070TFT_WSVGA_WIDTH,
/*!< Vertical Display Enable End */
.VDEND = FW070TFT_WSVGA_HEIGHT,
},
.sCRTCHR =
{
/*!< Internal Horizontal Retrace Start Timing */
.HRS = FW070TFT_WSVGA_WIDTH + 1,
/*!< Internal Horizontal Retrace End Low */
.HRE = FW070TFT_WSVGA_WIDTH + 5,
},
.sCRTCHSYNC =
{
/*!< Horizontal Sync Start Timing */
.HSYNC_S = FW070TFT_WSVGA_WIDTH + FW070TFT_WSVGA_MARGIN_LEFT,
/*!< Horizontal Sync End Timing */
.HSYNC_E = FW070TFT_WSVGA_WIDTH + FW070TFT_WSVGA_MARGIN_LEFT + FW070TFT_WSVGA_HSYNC_LEN,
/*!< Hsync Signal Adjustment For Multi-Cycles Per Pixel Mode Of Sync-Based Unipac-LCD */
.HSYNC_SHIFT = 0,
},
.sCRTCVR =
{
/*!< Vertical Internal Retrace Start Timing */
.VRS = FW070TFT_WSVGA_HEIGHT + FW070TFT_WSVGA_MARGIN_UPPER,
/*!< Vertical Internal Retrace End Low */
.VRE = FW070TFT_WSVGA_HEIGHT + FW070TFT_WSVGA_MARGIN_UPPER + FW070TFT_WSVGA_VSYNC_LEN,
}
};
/* LCD build-in support list */
static VPOST_T *DisplayDevList[5] = {&DEF_E50A2V1, &DEF_ILI9341_MPU80, &DEF_LSA40AT9001, &DEF_FW070TFT, &DEF_FW043TFT};
static VPOST_T *DisplayDevList[DIS_PANEL_CNT] =
{
&DEF_E50A2V1,
&DEF_ILI9341_MPU80,
&DEF_LSA40AT9001,
&DEF_FW070TFT,
&DEF_FW043TFT,
&DEF_FW070TFT_WSVGA
};
static VPOST_T curDisplayDev;
static OSDFORMATEX curOSDDev = {0};
static LCDFORMATEX curVADev = {0};
......
......@@ -475,6 +475,9 @@ config SOC_SERIES_N9H30
config LCM_USING_FW043TFT
bool "LCM_FW043TFT(480x272-RGB888)"
config LCM_USING_FW070TFT_WSVGA
bool "LCM_USING_FW070TFT_WSVGA(1024x600-RGB888)"
endchoice
config VPOST_USING_LCD_IDX
......@@ -483,6 +486,7 @@ config SOC_SERIES_N9H30
default 2 if LCM_USING_LSA40AT9001
default 3 if LCM_USING_FW070TFT
default 4 if LCM_USING_FW043TFT
default 5 if LCM_USING_FW070TFT_WSVGA
config BSP_LCD_BPP
int
......@@ -490,6 +494,7 @@ config SOC_SERIES_N9H30
default 16 if LCM_USING_LSA40AT9001
default 32 if LCM_USING_FW070TFT
default 32 if LCM_USING_FW043TFT
default 32 if LCM_USING_FW070TFT_WSVGA
config BSP_LCD_WIDTH
int
......@@ -497,6 +502,7 @@ config SOC_SERIES_N9H30
default 800 if LCM_USING_LSA40AT9001
default 800 if LCM_USING_FW070TFT
default 480 if LCM_USING_FW043TFT
default 1024 if LCM_USING_FW070TFT_WSVGA
config BSP_LCD_HEIGHT
int
......@@ -504,6 +510,7 @@ config SOC_SERIES_N9H30
default 600 if LCM_USING_LSA40AT9001
default 480 if LCM_USING_FW070TFT
default 272 if LCM_USING_FW043TFT
default 600 if LCM_USING_FW070TFT_WSVGA
config BSP_USING_VPOST_OSD
bool "Enable VPOST OSD layer"
......
......@@ -35,24 +35,27 @@ struct nu_adc
uint32_t chn_mask;
rt_sem_t m_psSem;
#if defined(BSP_USING_ADC_TOUCH)
rt_touch_t psRtTouch;
rt_timer_t psRtTouchMenuTimer;
rt_mq_t m_pmqTouchXYZ;
#endif
nu_adc_cb m_isr[eAdc_ISR_CNT];
nu_adc_cb m_wkisr[eAdc_WKISR_CNT];
rt_mq_t m_pmqTouchXYZ;
};
typedef struct nu_adc *nu_adc_t;
#if defined(BSP_USING_ADC_TOUCH)
struct nu_adc_touch_data
{
uint16_t u16X;
uint16_t u16Y;
uint16_t u16Z0;
uint16_t u16Z1;
uint32_t u32X;
uint32_t u32Y;
uint32_t u32Z0;
uint32_t u32Z1;
};
typedef struct nu_adc_touch_data *nu_adc_touch_data_t;
#endif
/* Private functions ------------------------------------------------------------*/
static rt_err_t nu_adc_enabled(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled);
......@@ -134,44 +137,30 @@ static rt_err_t _nu_adc_init(rt_device_t dev)
return RT_EOK;
}
void nu_adc_touch_detect(rt_bool_t bStartDetect)
static int32_t AdcMenuStartCallback(uint32_t status, uint32_t userData)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
nu_adc_t psNuAdc = (nu_adc_t)userData;
if (bStartDetect)
{
/* Start detect PenDown */
_nu_adc_control((rt_device_t)psNuAdc, PEPOWER_ON, RT_NULL);
}
else
{
/* Stop detect PenDown */
_nu_adc_control((rt_device_t)psNuAdc, PEPOWER_OFF, RT_NULL);
}
}
#if defined(BSP_USING_ADC_TOUCH)
static int32_t AdcMenuStartCallback(uint32_t status, uint32_t userData)
{
static struct nu_adc_touch_data point;
static rt_bool_t bDrop = RT_FALSE;
static uint16_t u16LastZ0 = 0xfffful;
nu_adc_t psNuAdc = (nu_adc_t)userData;
static uint32_t u32LastZ0 = 0xffffu;
if (psNuAdc->psRtTouch != RT_NULL)
{
uint32_t value;
value = inpw(REG_ADC_XYDATA);
point.u16X = (uint16_t)(value & 0x0ffful);
point.u16Y = (uint16_t)((value >> 16) & 0x0ffful);
point.u32X = (value & 0x0ffful);
point.u32Y = ((value >> 16) & 0x0ffful);
value = inpw(REG_ADC_ZDATA);
point.u16Z0 = (uint16_t)(value & 0x0ffful);
point.u16Z1 = (uint16_t)((value >> 16) & 0x0ffful);
point.u32Z0 = (value & 0x0ffful);
point.u32Z1 = ((value >> 16) & 0x0ffful);
/* Trigger next or not. */
if (point.u16Z0 == 0)
if (point.u32Z0 == 0)
{
/* Stop sampling procedure. */
rt_timer_stop(g_sNuADC.psRtTouchMenuTimer);
......@@ -187,14 +176,15 @@ static int32_t AdcMenuStartCallback(uint32_t status, uint32_t userData)
}
/* Notify upper layer. */
if ((!bDrop || (u16LastZ0 != 0)) && rt_mq_send(psNuAdc->m_pmqTouchXYZ, (const void *)&point, sizeof(struct nu_adc_touch_data)) == RT_EOK)
if ((!bDrop || (u32LastZ0 != 0)) && rt_mq_send(psNuAdc->m_pmqTouchXYZ, (const void *)&point, sizeof(struct nu_adc_touch_data)) == RT_EOK)
{
rt_hw_touch_isr(psNuAdc->psRtTouch);
}
u16LastZ0 = point.u16Z0;
u32LastZ0 = point.u32Z0;
}
else
#endif
{
rt_err_t result = rt_sem_release(psNuAdc->m_psSem);
RT_ASSERT(result == RT_EOK);
......@@ -203,6 +193,23 @@ static int32_t AdcMenuStartCallback(uint32_t status, uint32_t userData)
return 0;
}
#if defined(BSP_USING_ADC_TOUCH)
void nu_adc_touch_detect(rt_bool_t bStartDetect)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
if (bStartDetect)
{
/* Start detect PenDown */
_nu_adc_control((rt_device_t)psNuAdc, PEPOWER_ON, RT_NULL);
}
else
{
/* Stop detect PenDown */
_nu_adc_control((rt_device_t)psNuAdc, PEPOWER_OFF, RT_NULL);
}
}
static int32_t PenDownCallback(uint32_t status, uint32_t userData)
{
......@@ -213,7 +220,7 @@ static int32_t PenDownCallback(uint32_t status, uint32_t userData)
return 0;
}
int32_t nu_adc_read_touch_xyz(uint16_t *bufX, uint16_t *bufY, uint16_t *bufZ0, uint16_t *bufZ1, int32_t dataCnt)
int32_t nu_adc_touch_read_xyz(uint32_t *bufX, uint32_t *bufY, uint32_t *bufZ0, uint32_t *bufZ1, int32_t dataCnt)
{
int i;
struct nu_adc_touch_data value;
......@@ -223,14 +230,71 @@ int32_t nu_adc_read_touch_xyz(uint16_t *bufX, uint16_t *bufY, uint16_t *bufZ0, u
if (rt_mq_recv(g_sNuADC.m_pmqTouchXYZ, (void *)&value, sizeof(struct nu_adc_touch_data), 0) == -RT_ETIMEOUT)
break;
bufX[i] = value.u16X;
bufY[i] = value.u16Y;
bufZ0[i] = value.u16Z0;
bufZ1[i] = value.u16Z1;
bufX[i] = value.u32X;
bufY[i] = value.u32Y;
bufZ0[i] = value.u32Z0;
bufZ1[i] = value.u32Z1;
}
return i;
}
void nu_adc_touch_start_conv(void)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
_nu_adc_control((rt_device_t)psNuAdc, START_MST, RT_NULL);
}
rt_err_t nu_adc_touch_enable(rt_touch_t psRtTouch)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
nu_adc_cb sNuAdcCb;
rt_adc_enable((rt_adc_device_t)psNuAdc, 4);
rt_adc_enable((rt_adc_device_t)psNuAdc, 5);
rt_adc_enable((rt_adc_device_t)psNuAdc, 6);
rt_adc_enable((rt_adc_device_t)psNuAdc, 7);
outpw(REG_ADC_CONF, (inpw(REG_ADC_CONF) & ~(0xfful << 24)) | 0xfful << 24);
/* Register touch device. */
psNuAdc->psRtTouch = psRtTouch;
/* Enable TouchXY. */
_nu_adc_control((rt_device_t)psNuAdc, T_ON, RT_NULL);
/* Enable TouchZZ. */
_nu_adc_control((rt_device_t)psNuAdc, Z_ON, RT_NULL);
/* Register PenDown callback. */
sNuAdcCb.cbfunc = PenDownCallback;
sNuAdcCb.private_data = (rt_uint32_t)psRtTouch;
_nu_adc_control((rt_device_t)psNuAdc, PEDEF_ON, (void *)&sNuAdcCb);
nu_adc_touch_detect(RT_TRUE);
return RT_EOK;
}
rt_err_t nu_adc_touch_disable(void)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
nu_adc_touch_detect(RT_FALSE);
_nu_adc_control((rt_device_t)psNuAdc, T_OFF, RT_NULL);
_nu_adc_control((rt_device_t)psNuAdc, Z_OFF, RT_NULL);
_nu_adc_control((rt_device_t)psNuAdc, PEDEF_OFF, RT_NULL);
rt_adc_disable((rt_adc_device_t)psNuAdc, 4);
rt_adc_disable((rt_adc_device_t)psNuAdc, 5);
rt_adc_disable((rt_adc_device_t)psNuAdc, 6);
rt_adc_disable((rt_adc_device_t)psNuAdc, 7);
return RT_EOK;
}
#endif
static rt_err_t _nu_adc_control(rt_device_t dev, int cmd, void *args)
{
rt_err_t ret = RT_EINVAL ;
......@@ -443,7 +507,9 @@ static rt_err_t _nu_adc_control(rt_device_t dev, int cmd, void *args)
case Z_OFF: /* Disable Press measure function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) & ~ADC_CONF_ZEN);
#if defined(BSP_USING_ADC_TOUCH)
rt_mq_control(psNuAdc->m_pmqTouchXYZ, RT_IPC_CMD_RESET, RT_NULL);
#endif
}
break;
......@@ -522,61 +588,6 @@ static rt_err_t _nu_adc_control(rt_device_t dev, int cmd, void *args)
return RT_EOK;
}
void nu_adc_touch_start_conv(void)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
_nu_adc_control((rt_device_t)psNuAdc, START_MST, RT_NULL);
}
rt_err_t nu_adc_touch_enable(rt_touch_t psRtTouch)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
nu_adc_cb sNuAdcCb;
rt_adc_enable((rt_adc_device_t)psNuAdc, 4);
rt_adc_enable((rt_adc_device_t)psNuAdc, 5);
rt_adc_enable((rt_adc_device_t)psNuAdc, 6);
rt_adc_enable((rt_adc_device_t)psNuAdc, 7);
outpw(REG_ADC_CONF, (inpw(REG_ADC_CONF) & ~(0xfful << 24)) | 0xfful << 24);
/* Register touch device. */
psNuAdc->psRtTouch = psRtTouch;
/* Enable TouchXY. */
_nu_adc_control((rt_device_t)psNuAdc, T_ON, RT_NULL);
/* Enable TouchZZ. */
_nu_adc_control((rt_device_t)psNuAdc, Z_ON, RT_NULL);
/* Register PenDown callback. */
sNuAdcCb.cbfunc = PenDownCallback;
sNuAdcCb.private_data = (rt_uint32_t)psRtTouch;
_nu_adc_control((rt_device_t)psNuAdc, PEDEF_ON, (void *)&sNuAdcCb);
nu_adc_touch_detect(RT_TRUE);
return RT_EOK;
}
rt_err_t nu_adc_touch_disable(void)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
nu_adc_touch_detect(RT_FALSE);
_nu_adc_control((rt_device_t)psNuAdc, T_OFF, RT_NULL);
_nu_adc_control((rt_device_t)psNuAdc, Z_OFF, RT_NULL);
_nu_adc_control((rt_device_t)psNuAdc, PEDEF_OFF, RT_NULL);
rt_adc_disable((rt_adc_device_t)psNuAdc, 4);
rt_adc_disable((rt_adc_device_t)psNuAdc, 5);
rt_adc_disable((rt_adc_device_t)psNuAdc, 6);
rt_adc_disable((rt_adc_device_t)psNuAdc, 7);
return RT_EOK;
}
static rt_err_t _nu_adc_open(rt_device_t dev, rt_uint16_t oflag)
{
nu_adc_t psNuAdc = (nu_adc_t)dev;
......@@ -709,11 +720,13 @@ int rt_hw_adc_init(void)
g_sNuADC.m_psSem = rt_sem_create("adc_mst_sem", 0, RT_IPC_FLAG_FIFO);
RT_ASSERT(g_sNuADC.m_psSem != RT_NULL);
#if defined(BSP_USING_ADC_TOUCH)
g_sNuADC.m_pmqTouchXYZ = rt_mq_create("ADC_TOUCH_XYZ", sizeof(struct nu_adc_touch_data), TOUCH_MQ_LENGTH, RT_IPC_FLAG_FIFO);
RT_ASSERT(g_sNuADC.m_pmqTouchXYZ != RT_NULL);
g_sNuADC.psRtTouchMenuTimer = rt_timer_create("TOUCH_SMPL_TIMER", nu_adc_touch_smpl, (void *)&g_sNuADC, DEF_ADC_TOUCH_SMPL_TICK, RT_TIMER_FLAG_PERIODIC);
RT_ASSERT(g_sNuADC.psRtTouchMenuTimer != RT_NULL);
#endif
rt_memset(&g_sNuADC.m_isr, 0, sizeof(g_sNuADC.m_isr));
rt_memset(&g_sNuADC.m_wkisr, 0, sizeof(g_sNuADC.m_wkisr));
......
......@@ -15,9 +15,13 @@
#include <rtthread.h>
#include "nu_adc.h"
#include "touch.h"
#if defined(BSP_USING_ADC_TOUCH)
#include "touch.h"
#endif
#define TOUCH_MQ_LENGTH 128
#define TOUCH_MQ_LENGTH 64
#define DEF_CAL_POINT_NUM 5
typedef enum
{
......@@ -52,13 +56,29 @@ typedef struct
typedef nu_adc_cb *nu_adc_cb_t;
int32_t nu_adc_read_touch_xyz(uint16_t *bufX, uint16_t *bufY, uint16_t *bufZ0, uint16_t *bufZ1, int32_t dataCnt);
#if defined(BSP_USING_ADC_TOUCH)
typedef struct
{
int32_t x;
int32_t y;
} S_COORDINATE_POINT;
typedef struct
{
int32_t a;
int32_t b;
int32_t c;
int32_t d;
int32_t e;
int32_t f;
int32_t div;
} S_CALIBRATION_MATRIX;
int32_t nu_adc_touch_read_xyz(uint32_t *bufX, uint32_t *bufY, uint32_t *bufZ0, uint32_t *bufZ1, int32_t dataCnt);
rt_err_t nu_adc_touch_enable(rt_touch_t psRtTouch);
rt_err_t nu_adc_touch_disable(void);
void nu_adc_touch_detect(rt_bool_t bStartDetect);
void nu_adc_touch_start_conv(void);
void nu_adc_touch_update_caldata(int *psi32NewValue);
void nu_adc_touch_reset_caldata(int *psi32NewValue);
#endif
#endif /* __DRV_ADC_H__ */
......@@ -58,6 +58,7 @@ struct nu_can
IRQn_Type irqn;
E_SYS_IPRST rstidx;
E_SYS_IPCLK clkidx;
uint32_t int_flag;
};
typedef struct nu_can *nu_can_t;
......@@ -106,16 +107,16 @@ static const struct can_configure nu_can_default_config = NU_CAN_CONFIG_DEFAULT;
/* Interrupt Handle Function ----------------------------------------------------*/
static void nu_can_isr(int vector, void *param)
{
uint32_t u32IIDRstatus;
nu_can_t psNuCAN = (nu_can_t)param;
/* Get base address of CAN register */
CAN_T *base = psNuCAN->base;
/* Get interrupt event */
u32IIDRstatus = CAN_GET_INT_PENDING_STATUS(base);
uint32_t u32IIDRstatus = CAN_GET_INT_PENDING_STATUS(base) & CAN_IIDR_INTID_Msk;
if (u32IIDRstatus == 0x00008000) /* Check Status Interrupt Flag (Error status Int and Status change Int) */
/* Check Status Interrupt Flag (Error status Int and Status change Int) */
if (u32IIDRstatus == 0x00008000)
{
/**************************/
/* Status Change interrupt*/
......@@ -123,20 +124,24 @@ static void nu_can_isr(int vector, void *param)
if (base->STATUS & CAN_STATUS_TXOK_Msk)
{
base->STATUS &= ~CAN_STATUS_TXOK_Msk; /* Clear Tx Ok status*/
//rt_kprintf("%s: TX\n", psNuCAN->name) ;
#ifndef RT_CAN_USING_HDR
/* Using as Lisen,Loopback,Loopback+Lisen mode*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_TX_DONE);
if (psNuCAN->int_flag & RT_DEVICE_FLAG_INT_TX)
{
/*Using as Lisen,Loopback,Loopback+Lisen mode*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_TX_DONE);
}
#endif
}
if (base->STATUS & CAN_STATUS_RXOK_Msk)
{
base->STATUS &= ~CAN_STATUS_RXOK_Msk; /* Clear Rx Ok status*/
//rt_kprintf("%s: RX\n", psNuCAN->name) ;
#ifndef RT_CAN_USING_HDR
/* Using as Lisen,Loopback,Loopback+Lisen mode*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_RX_IND);
if (psNuCAN->int_flag & RT_DEVICE_FLAG_INT_RX)
{
/*Using as Lisen,Loopback,Loopback+Lisen mode*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_RX_IND);
}
#endif
}
......@@ -145,17 +150,16 @@ static void nu_can_isr(int vector, void *param)
/**************************/
if (base->STATUS & CAN_STATUS_EWARN_Msk)
{
rt_kprintf("%s: EWARN\n", psNuCAN->name) ;
rt_kprintf("[%s]EWARN INT\n", psNuCAN->name) ;
}
if (base->STATUS & CAN_STATUS_BOFF_Msk)
{
rt_kprintf("%s: BUSOFF\n", psNuCAN->name) ;
rt_kprintf("[%s]BUSOFF INT\n", psNuCAN->name) ;
/* Do Init to release busoff pin */
base->CON = (CAN_CON_INIT_Msk | CAN_CON_CCE_Msk);
base->CON &= (~(CAN_CON_INIT_Msk | CAN_CON_CCE_Msk));
while (base->CON & CAN_CON_INIT_Msk);
/* To release busoff pin */
CAN_EnterInitMode(base, CAN_CON_INIT_Msk | CAN_CON_CCE_Msk);
CAN_LeaveInitMode(base);
}
if (base->STATUS & CAN_STATUS_LEC_Msk)
......@@ -168,66 +172,83 @@ static void nu_can_isr(int vector, void *param)
/*IntId: 0x0001-0x0020, Number of Message Object which caused the interrupt.*/
else if (u32IIDRstatus > 0 && u32IIDRstatus <= 32)
{
/*Message RAM 0~RX_MSG_ID_INDEX for CAN Tx using*/
if (u32IIDRstatus <= RX_MSG_ID_INDEX)
if ((psNuCAN->int_flag & RT_DEVICE_FLAG_INT_TX) &&
(u32IIDRstatus <= RX_MSG_ID_INDEX))
{
//rt_kprintf("[%s-Tx]IntId = %d\n", psNuCAN->name, u32IIDRstatus);
/*Message RAM 0~RX_MSG_ID_INDEX for CAN Tx using*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_TX_DONE);
}
else /*Message RAM RX_MSG_ID_INDEX~31 for CAN Rx using*/
else if (psNuCAN->int_flag & RT_DEVICE_FLAG_INT_RX)
{
//rt_kprintf("[%s-Rx]IntId = %d\n", psNuCAN->name, u32IIDRstatus);
/*Message RAM RX_MSG_ID_INDEX~31 for CAN Rx using*/
rt_hw_can_isr(&psNuCAN->dev, (RT_CAN_EVENT_RX_IND | ((u32IIDRstatus - 1) << 8)));
}
CAN_CLR_INT_PENDING_BIT(base, (u32IIDRstatus - 1)); /* Clear Interrupt Pending */
}
#endif
}
static void nu_can_ie(nu_can_t psNuCAN)
{
uint32_t u32CanIE = CAN_CON_IE_Msk;
if (psNuCAN->int_flag & (RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX))
{
u32CanIE |= CAN_CON_SIE_Msk;
}
else
{
u32CanIE &= ~CAN_CON_SIE_Msk;
}
if (psNuCAN->int_flag & RT_DEVICE_CAN_INT_ERR)
{
u32CanIE |= CAN_CON_EIE_Msk;
}
else
{
u32CanIE &= ~CAN_CON_EIE_Msk;
}
if (u32CanIE & (CAN_CON_SIE_Msk | CAN_CON_EIE_Msk))
{
CAN_EnableInt(psNuCAN->base, u32CanIE);
/* Enable interrupt. */
rt_hw_interrupt_umask(psNuCAN->irqn);
}
else
{
u32CanIE |= (CAN_CON_IE_Msk | CAN_CON_SIE_Msk);
CAN_DisableInt(psNuCAN->base, u32CanIE);
/* Disable interrupt. */
rt_hw_interrupt_mask(psNuCAN->irqn);
}
}
static rt_err_t nu_can_configure(struct rt_can_device *can, struct can_configure *cfg)
{
nu_can_t psNuCAN = (nu_can_t)can;
uint32_t u32CANMode;
RT_ASSERT(can != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
RT_ASSERT(can);
RT_ASSERT(cfg);
/* Get base address of CAN register */
CAN_T *base = psNuCAN->base;
RT_ASSERT(base != RT_NULL);
switch (cfg->mode)
{
/* CAN default Normal mode */
case RT_CAN_MODE_NORMAL:
can->config.mode = CAN_NORMAL_MODE;
break;
case RT_CAN_MODE_LISEN:
can->config.mode = RT_CAN_MODE_LISEN;
break;
case RT_CAN_MODE_LOOPBACK:
can->config.mode = RT_CAN_MODE_LOOPBACK;
break;
case RT_CAN_MODE_LOOPBACKANLISEN:
can->config.mode = RT_CAN_MODE_LOOPBACKANLISEN;
break;
default:
rt_kprintf("Unsupported Operating mode");
goto exit_nu_can_configure;
}
/* Reset this module */
nu_sys_ip_reset(psNuCAN->rstidx);
/*Set the CAN Bit Rate and Operating mode*/
if (CAN_Open(base, can->config.baud_rate, can->config.mode) < 1)
return -(RT_ERROR);
u32CANMode = (cfg->mode == RT_CAN_MODE_NORMAL) ? CAN_NORMAL_MODE : CAN_BASIC_MODE;
/*Set the CAN Bit Rate and Operating mode*/
if (CAN_Open(base, cfg->baud_rate, u32CANMode) != cfg->baud_rate)
goto exit_nu_can_configure;
switch (cfg->mode)
{
/* CAN default Normal mode */
case RT_CAN_MODE_NORMAL:
#ifdef RT_CAN_USING_HDR
CAN_LeaveTestMode(base);
......@@ -249,6 +270,7 @@ static rt_err_t nu_can_configure(struct rt_can_device *can, struct can_configure
goto exit_nu_can_configure;
}
nu_can_ie(psNuCAN);
return RT_EOK;
......@@ -261,73 +283,33 @@ exit_nu_can_configure:
static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
{
rt_uint32_t argval;
nu_can_t psNuCAN = (nu_can_t)can;
#ifdef RT_CAN_USING_HDR
struct rt_can_filter_config *filter_cfg;
#endif
/* Get base address of CAN register */
CAN_T *base = psNuCAN->base;
rt_uint32_t argval = (rt_uint32_t)arg;
nu_can_t psNuCAN = (nu_can_t)can;
RT_ASSERT(base != RT_NULL);
/* Check baud rate */
RT_ASSERT(can->config.baud_rate != 0);
RT_ASSERT(can);
switch (cmd)
{
case RT_DEVICE_CTRL_CLR_INT:
argval = (rt_uint32_t) arg;
if ((argval == RT_DEVICE_FLAG_INT_RX) || (argval == RT_DEVICE_FLAG_INT_TX))
{
/* Disable NVIC interrupt. */
rt_hw_interrupt_mask(psNuCAN->irqn);
/* Disable Status Change Interrupt */
CAN_DisableInt(base, CAN_CON_IE_Msk | CAN_CON_SIE_Msk);
}
else if (argval == RT_DEVICE_CAN_INT_ERR)
{
/* Disable interrupt. */
rt_hw_interrupt_mask(psNuCAN->irqn);
/* Disable Error Interrupt */
CAN_DisableInt(base, CAN_CON_EIE_Msk);
}
break;
case RT_DEVICE_CTRL_SET_INT:
argval = (rt_uint32_t) arg;
if (argval == RT_DEVICE_FLAG_INT_RX || (argval == RT_DEVICE_FLAG_INT_TX))
{
/* Enable Status Change Interrupt */
CAN_EnableInt(base, CAN_CON_IE_Msk | CAN_CON_SIE_Msk);
/* Enable interrupt. */
rt_hw_interrupt_umask(psNuCAN->irqn);
}
else if (argval == RT_DEVICE_CAN_INT_ERR)
{
/* Enable Error Status and Status Change Interrupt */
CAN_EnableInt(base, CAN_CON_IE_Msk | CAN_CON_SIE_Msk | CAN_CON_EIE_Msk);
psNuCAN->int_flag |= argval;
nu_can_ie(psNuCAN);
break;
/* Enable interrupt. */
rt_hw_interrupt_umask(psNuCAN->irqn);
}
case RT_DEVICE_CTRL_CLR_INT:
psNuCAN->int_flag &= ~argval;
nu_can_ie(psNuCAN);
break;
#ifdef RT_CAN_USING_HDR
case RT_CAN_CMD_SET_FILTER:
filter_cfg = (struct rt_can_filter_config *)arg;
{
struct rt_can_filter_config *filter_cfg = (struct rt_can_filter_config *)arg;
for (int i = 0; i < filter_cfg->count; i++)
{
/*set the filter message object*/
if (filter_cfg->items[i].mode == 1)
{
if (CAN_SetRxMsgObjAndMsk(base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
{
return -(RT_ERROR);
}
......@@ -335,46 +317,61 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
else
{
/*set the filter message object*/
if (CAN_SetRxMsgAndMsk(base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
{
return -(RT_ERROR);
}
}
}
break;
#endif
}
break;
case RT_CAN_CMD_SET_MODE:
argval = (rt_uint32_t) arg;
if (argval != RT_CAN_MODE_NORMAL && argval != RT_CAN_MODE_LISEN &&
argval != RT_CAN_MODE_LOOPBACK && argval != RT_CAN_MODE_LOOPBACKANLISEN)
if ((argval == RT_CAN_MODE_NORMAL) ||
(argval == RT_CAN_MODE_LISEN) ||
(argval == RT_CAN_MODE_LOOPBACK) ||
(argval == RT_CAN_MODE_LOOPBACKANLISEN))
{
return -(RT_ERROR);
if (argval != can->config.mode)
{
can->config.mode = argval;
return nu_can_configure(can, &can->config);
}
}
if (argval != can->config.mode)
else
{
can->config.mode = argval;
return nu_can_configure(can, &can->config);
return -(RT_ERROR);
}
break;
case RT_CAN_CMD_SET_BAUD:
argval = (rt_uint32_t) arg;
if (argval != CAN1MBaud && argval != CAN800kBaud && argval != CAN500kBaud && argval != CAN250kBaud &&
argval != CAN125kBaud && argval != CAN100kBaud && argval != CAN50kBaud && argval != CAN20kBaud && argval != CAN10kBaud)
{
if ((argval == CAN1MBaud) ||
(argval == CAN800kBaud) ||
(argval == CAN500kBaud) ||
(argval == CAN250kBaud) ||
(argval == CAN125kBaud) ||
(argval == CAN100kBaud) ||
(argval == CAN50kBaud) ||
(argval == CAN20kBaud) ||
(argval == CAN10kBaud))
{
return -(RT_ERROR);
if (argval != can->config.baud_rate)
{
can->config.baud_rate = argval;
return nu_can_configure(can, &can->config);
}
}
if (argval != can->config.baud_rate)
else
{
can->config.baud_rate = argval;
return nu_can_configure(can, &can->config);
return -(RT_ERROR);
}
break;
}
break;
case RT_CAN_CMD_SET_PRIV:
argval = (rt_uint32_t) arg;
if (argval != RT_CAN_MODE_PRIV && argval != RT_CAN_MODE_NOPRIV)
if (argval != RT_CAN_MODE_PRIV &&
argval != RT_CAN_MODE_NOPRIV)
{
return -(RT_ERROR);
}
......@@ -387,16 +384,23 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
case RT_CAN_CMD_GET_STATUS:
{
rt_uint32_t errtype;
errtype = base->ERR;
/*Receive Error Counter*/
rt_uint32_t errtype = psNuCAN->base->ERR;
RT_ASSERT(arg);
/*Receive Error Counter, return value is with Receive Error Passive.*/
can->status.rcverrcnt = (errtype >> 8);
/*Transmit Error Counter*/
can->status.snderrcnt = ((errtype >> 24) & 0xFF);
can->status.lasterrtype = CAN_GET_INT_STATUS(base) & 0x8000;
/*status error code*/
can->status.errcode = CAN_GET_INT_STATUS(base) & 0x07;
rt_memcpy(arg, &can->status, sizeof(can->status));
can->status.snderrcnt = (errtype & 0xFF);
/*Last Error Type*/
can->status.lasterrtype = CAN_GET_INT_STATUS(psNuCAN->base) & 0x8000;
/*Status error code*/
can->status.errcode = CAN_GET_INT_STATUS(psNuCAN->base) & 0x07;
rt_memcpy(arg, &can->status, sizeof(struct rt_can_status));
}
break;
......@@ -411,64 +415,91 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
static int nu_can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t boxno)
{
STR_CANMSG_T tMsg;
struct rt_can_msg *pmsg = (struct rt_can_msg *) buf;
/* Get base address of CAN register */
CAN_T *base = ((nu_can_t)can)->base;
struct rt_can_msg *pmsg;
nu_can_t psNuCAN = (nu_can_t)can;
RT_ASSERT(base != RT_NULL);
RT_ASSERT(buf != RT_NULL);
RT_ASSERT(can);
RT_ASSERT(buf);
/* Check the parameters */
RT_ASSERT(IS_CAN_DLC(pmsg->len));
pmsg = (struct rt_can_msg *) buf;
/* Standard ID (11 bits)*/
if (pmsg->ide == RT_CAN_STDID)
if (pmsg->ide == RT_CAN_STDID && IS_CAN_STDID(pmsg->id))
{
/* Standard ID (11 bits)*/
tMsg.IdType = CAN_STD_ID;
RT_ASSERT(IS_CAN_STDID(pmsg->id))
tMsg.Id = pmsg->id ;
}
else
else if (pmsg->ide == RT_CAN_EXTID && IS_CAN_EXTID(pmsg->id))
{
/* Extended ID (29 bits)*/
tMsg.IdType = CAN_EXT_ID;
RT_ASSERT(IS_CAN_EXTID(pmsg->id));
tMsg.Id = pmsg->id ;
}
else
{
goto exit_nu_can_sendmsg;
}
if (pmsg->rtr == RT_CAN_DTR)
{
/* Data frame */
tMsg.FrameType = CAN_DATA_FRAME;
}
else
else if (pmsg->rtr == RT_CAN_RTR)
{
/* Remote frame */
tMsg.FrameType = CAN_REMOTE_FRAME;
}
tMsg.DLC = pmsg->len;
rt_memcpy(tMsg.Data, pmsg->data, pmsg->len);
else
{
goto exit_nu_can_sendmsg;
}
if (CAN_Transmit(base, MSG(boxno), &tMsg) == FALSE) // Configure Msg RAM and send the Msg in the RAM
/* Check the parameters */
if (IS_CAN_DLC(pmsg->len))
{
return -(RT_ERROR);
tMsg.DLC = pmsg->len;
}
else
{
goto exit_nu_can_sendmsg;
}
if (pmsg->data && pmsg->len)
{
rt_memcpy(&tMsg.Data[0], pmsg->data, pmsg->len);
}
else
{
goto exit_nu_can_sendmsg;
}
/* Configure Msg RAM and send the Msg in the RAM. */
if (CAN_Transmit(psNuCAN->base, MSG(boxno), &tMsg) == FALSE)
{
goto exit_nu_can_sendmsg;
}
return RT_EOK;
exit_nu_can_sendmsg:
return -(RT_ERROR);
}
static int nu_can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t boxno)
{
STR_CANMSG_T tMsg;
struct rt_can_msg *pmsg = (struct rt_can_msg *) buf;
/* Get base address of CAN register */
CAN_T *base = ((nu_can_t)can)->base;
struct rt_can_msg *pmsg;
nu_can_t psNuCAN = (nu_can_t)can;
RT_ASSERT(can);
RT_ASSERT(buf);
RT_ASSERT(base != RT_NULL);
RT_ASSERT(buf != RT_NULL);
pmsg = (struct rt_can_msg *) buf;
/* get data */
if (CAN_Receive(base, boxno, &tMsg) == FALSE)
if (CAN_Receive(psNuCAN->base, boxno, &tMsg) == FALSE)
{
rt_kprintf("No available RX Msg.\n");
return -(RT_ERROR);
......@@ -480,32 +511,13 @@ static int nu_can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t boxn
can->hdr[pmsg->hdr].connected = 1;
#endif
/* Standard ID (11 bits)*/
if (tMsg.IdType == CAN_STD_ID)
{
pmsg->ide = RT_CAN_STDID;
pmsg->id = tMsg.Id;
}
else /* Extended ID (29 bits)*/
{
pmsg->ide = RT_CAN_EXTID;
pmsg->id = tMsg.Id;
}
if (tMsg.FrameType == CAN_DATA_FRAME)
{
/* Data frame */
pmsg->rtr = RT_CAN_DTR;
}
else
{
/* Remote frame */
pmsg->rtr = RT_CAN_RTR;
}
pmsg->ide = (tMsg.IdType == CAN_STD_ID) ? RT_CAN_STDID : RT_CAN_EXTID;
pmsg->rtr = (tMsg.FrameType == CAN_DATA_FRAME) ? RT_CAN_DTR : RT_CAN_RTR;
pmsg->id = tMsg.Id;
pmsg->len = tMsg.DLC ;
rt_memcpy(pmsg->data, tMsg.Data, pmsg->len);
if (pmsg->data && pmsg->len)
rt_memcpy(pmsg->data, &tMsg.Data[0], pmsg->len);
return RT_EOK;
}
......@@ -540,5 +552,4 @@ static int rt_hw_can_init(void)
return (int)ret;
}
INIT_DEVICE_EXPORT(rt_hw_can_init);
#endif //#if defined(BSP_USING_CAN)
......@@ -34,6 +34,8 @@
#define I2C_ENABLE(dev) I2C_REG_WRITE(dev, I2C_CSR, 0x3) /* Enable i2c core and interrupt */
#define I2C_ISBUSFREE(dev) (((I2C_REG_READ(dev, I2C_SWR) & 0x18) == 0x18 && (I2C_REG_READ(dev, I2C_CSR) & 0x0400) == 0) ? 1 : 0)
#define I2C_SIGNAL_TIMEOUT 5000
enum
{
I2C_START = -1,
......@@ -50,7 +52,7 @@ enum
typedef struct
{
int32_t base; /* i2c bus number */
int32_t state;
volatile int32_t state;
int32_t addr;
uint32_t last_error;
int32_t bNackValid;
......@@ -58,9 +60,11 @@ typedef struct
uint32_t subaddr;
int32_t subaddr_len;
uint8_t buffer[I2C_MAX_BUF_LEN];
uint32_t pos, len;
volatile uint32_t pos;
volatile uint32_t len;
uint8_t *buffer;
struct rt_completion signal;
} nu_i2c_dev;
typedef nu_i2c_dev *nu_i2c_dev_t;
......@@ -68,7 +72,6 @@ typedef struct
{
struct rt_i2c_bus_device parent;
char *name;
IRQn_Type irqn;
E_SYS_IPRST rstidx;
E_SYS_IPCLK clkidx;
......@@ -113,13 +116,13 @@ static nu_i2c_bus nu_i2c_arr [ ] =
* @brief Set i2c interface speed
* @param[in] dev i2c device structure pointer
* @param[in] sp i2c speed
* @return always 0
* @return 0 or I2C_ERR_NOTTY
*/
static int32_t nu_i2c_set_speed(nu_i2c_dev_t psNuI2cDev, int32_t sp)
{
uint32_t d;
if (sp != 100 && sp != 400)
if ((sp != 100) && (sp != 400))
return (I2C_ERR_NOTTY);
d = (sysGetClock(SYS_PCLK) * 1000) / (sp * 5) - 1;
......@@ -205,6 +208,7 @@ static void nu_i2c_isr(int vector, void *param)
psNuI2CDev->last_error = I2C_ERR_NACK;
nu_i2c_command(psNuI2CDev, I2C_CMD_STOP);
psNuI2CDev->state = I2C_STATE_NOP;
rt_completion_done(&psNuI2CDev->signal);
}
/* Arbitration lost */
else if (csr & 0x200)
......@@ -212,6 +216,7 @@ static void nu_i2c_isr(int vector, void *param)
rt_kprintf("Arbitration lost\n");
psNuI2CDev->last_error = I2C_ERR_LOSTARBITRATION;
psNuI2CDev->state = I2C_STATE_NOP;
rt_completion_done(&psNuI2CDev->signal);
}
/* Transmit complete */
else if (!(csr & 0x100))
......@@ -225,6 +230,7 @@ static void nu_i2c_isr(int vector, void *param)
}
else if (psNuI2CDev->state == I2C_STATE_READ)
{
/* Sub-address send over, begin restart a read command */
if (psNuI2CDev->pos == psNuI2CDev->subaddr_len + 1)
{
......@@ -246,6 +252,7 @@ static void nu_i2c_isr(int vector, void *param)
else
{
psNuI2CDev->state = I2C_STATE_NOP;
rt_completion_done(&psNuI2CDev->signal);
}
}
}
......@@ -270,12 +277,12 @@ static void nu_i2c_isr(int vector, void *param)
else
{
psNuI2CDev->state = I2C_STATE_NOP;
rt_completion_done(&psNuI2CDev->signal);
}
}
}
}
}
/**
* @brief Read data from I2C slave.
......@@ -294,6 +301,9 @@ static int32_t nu_i2c_read(nu_i2c_dev_t psNuI2cDev, struct rt_i2c_msg *pmsg)
uint8_t *buf = pmsg->buf;
uint32_t len = pmsg->len;
RT_ASSERT(len);
RT_ASSERT(buf);
if (len > I2C_MAX_BUF_LEN - 10)
len = I2C_MAX_BUF_LEN - 10;
......@@ -317,9 +327,22 @@ static int32_t nu_i2c_read(nu_i2c_dev_t psNuI2cDev, struct rt_i2c_msg *pmsg)
if (!I2C_ISBUSFREE(psNuI2cDev))
return (I2C_ERR_BUSY);
rt_completion_init(&psNuI2cDev->signal);
nu_i2c_command(psNuI2cDev, I2C_CMD_START | I2C_CMD_WRITE);
while (psNuI2cDev->state != I2C_STATE_NOP);
if ((RT_EOK == rt_completion_wait(&psNuI2cDev->signal, I2C_SIGNAL_TIMEOUT)))
{
rt_memcpy(buf, psNuI2cDev->buffer + psNuI2cDev->subaddr_len + 3, len);
psNuI2cDev->subaddr += len;
}
else
{
rt_kprintf("[%s]Wait signal timeout.\n", __func__);
len = 0;
}
/* Disable I2C-EN */
I2C_DISABLE(psNuI2cDev);
......@@ -327,10 +350,6 @@ static int32_t nu_i2c_read(nu_i2c_dev_t psNuI2cDev, struct rt_i2c_msg *pmsg)
if (psNuI2cDev->last_error)
return (psNuI2cDev->last_error);
rt_memcpy(buf, psNuI2cDev->buffer + psNuI2cDev->subaddr_len + 3, len);
psNuI2cDev->subaddr += len;
return len;
}
......@@ -351,6 +370,9 @@ static int32_t nu_i2c_write(nu_i2c_dev_t psNuI2cDev, struct rt_i2c_msg *pmsg)
uint8_t *buf = pmsg->buf;
uint32_t len = pmsg->len;
RT_ASSERT(len);
RT_ASSERT(buf);
if (len > I2C_MAX_BUF_LEN - 10)
len = I2C_MAX_BUF_LEN - 10;
......@@ -373,9 +395,20 @@ static int32_t nu_i2c_write(nu_i2c_dev_t psNuI2cDev, struct rt_i2c_msg *pmsg)
if (!I2C_ISBUSFREE(psNuI2cDev))
return (I2C_ERR_BUSY);
rt_completion_init(&psNuI2cDev->signal);
nu_i2c_command(psNuI2cDev, I2C_CMD_START | I2C_CMD_WRITE);
while (psNuI2cDev->state != I2C_STATE_NOP);
if ((RT_EOK == rt_completion_wait(&psNuI2cDev->signal, I2C_SIGNAL_TIMEOUT)))
{
psNuI2cDev->subaddr += len;
}
else
{
rt_kprintf("[%s]Wait signal timeout.\n", __func__);
len = 0;
}
/* Disable I2C-EN */
I2C_DISABLE(psNuI2cDev);
......@@ -383,8 +416,6 @@ static int32_t nu_i2c_write(nu_i2c_dev_t psNuI2cDev, struct rt_i2c_msg *pmsg)
if (psNuI2cDev->last_error)
return (psNuI2cDev->last_error);
psNuI2cDev->subaddr += len;
return len;
}
......@@ -405,16 +436,13 @@ static int32_t nu_i2c_ioctl(nu_i2c_dev_t psNuI2cDev, uint32_t cmd, uint32_t arg0
switch (cmd)
{
case I2C_IOC_SET_DEV_ADDRESS:
psNuI2cDev->addr = arg0;
break;
case I2C_IOC_SET_SPEED:
return (nu_i2c_set_speed(psNuI2cDev, (int32_t)arg0));
return nu_i2c_set_speed(psNuI2cDev, (int32_t)arg0);
case I2C_IOC_SET_SUB_ADDRESS:
if (arg1 > 4)
{
return (I2C_ERR_NOTTY);
......@@ -441,7 +469,8 @@ static rt_size_t nu_i2c_mst_xfer(struct rt_i2c_bus_device *bus,
rt_err_t ret;
struct rt_i2c_msg *pmsg;
RT_ASSERT(bus != RT_NULL);
RT_ASSERT(bus);
psNuI2cBus = (nu_i2c_bus_t) bus;
psNuI2cDev = &psNuI2cBus->dev;
......@@ -459,6 +488,7 @@ static rt_size_t nu_i2c_mst_xfer(struct rt_i2c_bus_device *bus,
/* Set device address */
nu_i2c_reset(psNuI2cDev);
nu_i2c_ioctl(psNuI2cDev, I2C_IOC_SET_DEV_ADDRESS, pmsg->addr, 0);
if (pmsg->flags & RT_I2C_RD)
......@@ -470,18 +500,39 @@ static rt_size_t nu_i2c_mst_xfer(struct rt_i2c_bus_device *bus,
ret = nu_i2c_write(psNuI2cDev, pmsg);
}
if (ret != pmsg->len) break;
}
return i;
}
static rt_err_t nu_i2c_bus_control(struct rt_i2c_bus_device *bus, rt_uint32_t u32Cmd, rt_uint32_t u32Value)
{
nu_i2c_bus_t psNuI2cBus;
nu_i2c_dev_t psNuI2cDev;
RT_ASSERT(bus);
psNuI2cBus = (nu_i2c_bus_t) bus;
psNuI2cDev = &psNuI2cBus->dev;
switch (u32Cmd)
{
case RT_I2C_DEV_CTRL_CLK:
nu_i2c_set_speed(psNuI2cDev, (int32_t)u32Value);
break;
default:
return -RT_EIO;
}
return RT_EOK;
}
static const struct rt_i2c_bus_device_ops nu_i2c_ops =
{
.master_xfer = nu_i2c_mst_xfer,
.slave_xfer = NULL,
.i2c_bus_control = NULL,
.i2c_bus_control = nu_i2c_bus_control,
};
......@@ -489,17 +540,17 @@ static const struct rt_i2c_bus_device_ops nu_i2c_ops =
int rt_hw_i2c_init(void)
{
int i;
rt_err_t ret = RT_EOK;
rt_err_t ret;
for (i = (I2C_START + 1); i < I2C_CNT; i++)
{
nu_i2c_dev_t psNuI2cDev = &nu_i2c_arr[i].dev;
ret = rt_i2c_bus_device_register(&nu_i2c_arr[i].parent, nu_i2c_arr[i].name);
RT_ASSERT(RT_EOK == ret);
nu_i2c_arr[i].parent.ops = &nu_i2c_ops;
psNuI2cDev->buffer = rt_malloc(I2C_MAX_BUF_LEN);
RT_ASSERT(psNuI2cDev->buffer);
/* Enable I2C engine clock and reset. */
nu_sys_ipclk_enable(nu_i2c_arr[i].clkidx);
nu_sys_ip_reset(nu_i2c_arr[i].rstidx);
......@@ -509,6 +560,9 @@ int rt_hw_i2c_init(void)
/* Register ISR and Respond IRQ. */
rt_hw_interrupt_install(nu_i2c_arr[i].irqn, nu_i2c_isr, &nu_i2c_arr[i], nu_i2c_arr[i].name);
rt_hw_interrupt_umask(nu_i2c_arr[i].irqn);
ret = rt_i2c_bus_device_register(&nu_i2c_arr[i].parent, nu_i2c_arr[i].name);
RT_ASSERT(RT_EOK == ret);
}
return 0;
......
......@@ -69,6 +69,9 @@ static struct nu_vpost nu_fbdev[eVpost_Cnt] =
#endif
};
RT_WEAK void nu_lcd_backlight_on(void) { }
RT_WEAK void nu_lcd_backlight_off(void) { }
static rt_err_t vpost_layer_open(rt_device_t dev, rt_uint16_t oflag)
{
nu_vpost_t psVpost = (nu_vpost_t)dev;
......@@ -149,6 +152,18 @@ static rt_err_t vpost_layer_control(rt_device_t dev, int cmd, void *args)
switch (cmd)
{
case RTGRAPHIC_CTRL_POWERON:
{
nu_lcd_backlight_on();
}
break;
case RTGRAPHIC_CTRL_POWEROFF:
{
nu_lcd_backlight_off();
}
break;
case RTGRAPHIC_CTRL_GET_INFO:
{
struct rt_device_graphic_info *info = (struct rt_device_graphic_info *) args;
......@@ -324,6 +339,11 @@ int rt_hw_vpost_init(void)
rt_kprintf("Fail to get VRAM buffer.\n");
RT_ASSERT(0);
}
else
{
uint32_t u32FBSize = psVpost->info.pitch * psVpostLcmInst->u32DevHeight;
rt_memset(psVpost->info.framebuffer, 0, u32FBSize);
}
/* Register member functions of lcd device */
psVpost->dev.type = RT_Device_Class_Graphic;
......
......@@ -27,6 +27,7 @@ static struct rt_device_graphic_info g_Ili9341Info =
.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565,
.framebuffer = RT_NULL,
.width = XSIZE_PHYS,
.pitch = XSIZE_PHYS * 2,
.height = YSIZE_PHYS
};
......@@ -324,7 +325,7 @@ int rt_hw_lcd_ili9341_init(void)
lcd_device.user_data = &ili9341_ops;
#if defined(NU_PKG_ILI9341_WITH_OFFSCREEN_FRAMEBUFFER)
g_Ili9341Info.framebuffer = rt_malloc_align((DEF_VRAM_BUFFER_NUMBER * g_Ili9341Info.width * g_Ili9341Info.height * (g_Ili9341Info.bits_per_pixel / 8)) + 32, 32);
g_Ili9341Info.framebuffer = rt_malloc_align((DEF_VRAM_BUFFER_NUMBER * g_Ili9341Info.pitch * g_Ili9341Info.height) + 32, 32);
RT_ASSERT(g_Ili9341Info.framebuffer != RT_NULL);
#endif
......
......@@ -38,7 +38,7 @@ menu "Nuvoton Packages Config"
bool "ILI9341 LCD Panel"
select BSP_USING_GPIO
default n
if NU_PKG_USING_ILI9341
choice
......@@ -62,8 +62,20 @@ menu "Nuvoton Packages Config"
default n
config NU_PKG_ILI9341_HORIZONTAL
bool "Set horizontal view. (320x240)"
default n
bool
default y
config BSP_LCD_BPP
int
default 16 if NU_PKG_USING_ILI9341
config BSP_LCD_WIDTH
int
default 320 if NU_PKG_ILI9341_HORIZONTAL
config BSP_LCD_HEIGHT
int
default 240 if NU_PKG_ILI9341_HORIZONTAL
endif
......
......@@ -35,51 +35,142 @@ extern "C"
#define ADC_ERR_CMD 2 /*!< The command is wrong */
/// @cond HIDDEN_SYMBOLS
typedef INT32(*ADC_CALLBACK)(UINT32 status, UINT32 userData);
typedef int32_t(*ADC_CALLBACK)(uint32_t status, uint32_t userData);
/// @endcond HIDDEN_SYMBOLS
/*---------------------------------------------------------------------------------------------------------*/
/* ADC_CTL constant definitions */
/*---------------------------------------------------------------------------------------------------------*/
#define ADC_CTL_ADEN 0x00000001 /*!< ADC Power Control */
#define ADC_CTL_VBGEN 0x00000002 /*!< ADC Internal Bandgap Power Control */
#define ADC_CTL_VBGEN 0x00000002 /*!< ADC Internal Bandgap Power Control */
#define ADC_CTL_PWKPEN 0x00000004 /*!< ADC Keypad Power Enable Control */
#define ADC_CTL_MST 0x00000100 /*!< Menu Start Conversion */
#define ADC_CTL_PEDEEN 0x00000200 /*!< Pen Down Event Enable */
#define ADC_CTL_WKPEN 0x00000400 /*!< Keypad Press Wake Up Enable */
#define ADC_CTL_WKTEN 0x00000800 /*!< Touch Wake Up Enable */
#define ADC_CTL_WMSWCH 0x00010000 /*!< Wire Mode Switch For 5-Wire/4-Wire Configuration */
/*---------------------------------------------------------------------------------------------------------*/
/* ADC_CONF constant definitions */
/*---------------------------------------------------------------------------------------------------------*/
#define ADC_CONF_TEN 0x00000001 /*!< Touch Enable */
#define ADC_CONF_ZEN 0x00000002 /*!< Press Enable */
#define ADC_CONF_NACEN 0x00000004 /*!< Normal AD Conversion Enable */
#define ADC_CONF_VBATEN 0x00000100 /*!< Voltage Battery Enable */
#define ADC_CONF_KPCEN 0x00000200 /*!< Keypad Press Conversion Enable */
#define ADC_CONF_SELFTEN 0x00000400 /*!< Selft Test Enable */
#define ADC_CONF_DISTMAVEN (1<<20) /*!< Display T Mean Average Enable */
#define ADC_CONF_DISZMAVEN (1<<21) /*!< Display Z Mean Average Enable */
#define ADC_CONF_HSPEED (1<<22) /*!< High Speed Enable */
#define ADC_CONF_CHSEL_Pos 12 /*!< Channel Selection Position */
#define ADC_CONF_CHSEL_Msk (0xF<<ADC_CONF_CHSEL_Pos) /*!< Channel Selection Mask */
#define ADC_CONF_REFSEL_Pos 6 /*!< Reference Selection Position */
#define ADC_CONF_REFSEL_Msk (3<<6) /*!< Reference Selection Mask */
#define ADC_CONF_REFSEL_VREF (0<<6) /*!< ADC reference select VREF input */
#define ADC_CONF_REFSEL_AVDD33 (3<<6) /*!< ADC reference select AGND33 vs AVDD33 */
#define ADC_CONF_CHSEL_Pos 3 /*!< Channel Selection Position */
#define ADC_CONF_CHSEL_Msk (7<<3) /*!< Channel Selection Mask */
#define ADC_CONF_CHSEL_VBT (0<<3) /*!< ADC input channel select VBT */
#define ADC_CONF_CHSEL_VHS (1<<3) /*!< ADC input channel select VHS */
#define ADC_CONF_CHSEL_A2 (2<<3) /*!< ADC input channel select A2 */
#define ADC_CONF_CHSEL_A3 (3<<3) /*!< ADC input channel select A3 */
#define ADC_CONF_CHSEL_YM (4<<3) /*!< ADC input channel select YM */
#define ADC_CONF_CHSEL_YP (5<<3) /*!< ADC input channel select YP */
#define ADC_CONF_CHSEL_XM (6<<3) /*!< ADC input channel select XM */
#define ADC_CONF_CHSEL_XP (7<<3) /*!< ADC input channel select XP */
#define ADC_CONF_REFSEL_Pos 6 /*!< Reference Selection Position */
#define ADC_CONF_REFSEL_Msk (3<<6) /*!< Reference Selection Mask */
#define ADC_CONF_REFSEL_VREF (0<<6) /*!< ADC reference select VREF input or 2.5v buffer output */
#define ADC_CONF_REFSEL_YMYP (1<<6) /*!< ADC reference select YM vs YP */
#define ADC_CONF_REFSEL_XMXP (2<<6) /*!< ADC reference select XM vs XP */
#define ADC_CONF_REFSEL_AVDD33 (3<<6) /*!< ADC reference select AGND33 vs AVDD33 */
/*---------------------------------------------------------------------------------------------------------*/
/* ADC_IER constant definitions */
/*---------------------------------------------------------------------------------------------------------*/
#define ADC_IER_MIEN 0x00000001 /*!< Menu Interrupt Enable */
#define ADC_IER_MIEN 0x00000001 /*!< Menu Interrupt Enable */
#define ADC_IER_KPEIEN 0x00000002 /*!< Keypad Press Event Interrupt Enable */
#define ADC_IER_PEDEIEN 0x00000004 /*!< Pen Down Even Interrupt Enable */
#define ADC_IER_WKTIEN 0x00000008 /*!< Wake Up Touch Interrupt Enable */
#define ADC_IER_WKPIEN 0x00000010 /*!< Wake Up Keypad Press Interrupt Enable */
#define ADC_IER_KPUEIEN 0x00000020 /*!< Keypad Press Up Event Interrupt Enable */
#define ADC_IER_PEUEIEN 0x00000040 /*!< Pen Up Event Interrupt Enable */
/*---------------------------------------------------------------------------------------------------------*/
/* ADC_ISR constant definitions */
/*---------------------------------------------------------------------------------------------------------*/
#define ADC_ISR_MF 0x00000001 /*!< Menu Complete Flag */
#define ADC_ISR_KPEF 0x00000002 /*!< Keypad Press Event Flag */
#define ADC_ISR_PEDEF 0x00000004 /*!< Pen Down Event Flag */
#define ADC_ISR_KPUEF 0x00000008 /*!< Keypad Press Up Event Flag */
#define ADC_ISR_PEUEF 0x00000010 /*!< Pen Up Event Flag */
#define ADC_ISR_TF 0x00000100 /*!< Touch Conversion Finish */
#define ADC_ISR_ZF 0x00000200 /*!< Press Conversion Finish */
#define ADC_ISR_NACF 0x00000400 /*!< Normal AD Conversion Finish */
#define ADC_ISR_VBF 0x00000800 /*!< Voltage Battery Conversion Finish */
#define ADC_ISR_KPCF 0x00001000 /*!< Keypad Press Conversion Finish */
#define ADC_ISR_SELFTF 0x00002000 /*!< Self-Test Conversion Finish */
#define ADC_ISR_INTKP 0x00010000 /*!< Interrupt Signal For Keypad Detection */
#define ADC_ISR_INTTC 0x00020000 /*!< Interrupt Signal For Touch Screen Touching Detection */
/*---------------------------------------------------------------------------------------------------------*/
/* ADC_WKISR constant definitions */
/*---------------------------------------------------------------------------------------------------------*/
#define ADC_WKISR_WKPEF 0x00000001 /*!< Wake Up Pen Down Event Flag */
#define ADC_WKISR_WPEDEF 0x00000002 /*!< Wake Up Keypad Press Event Flage */
/** \brief Structure type of ADC_CHAN
*/
typedef enum
{
AIN0 = ADC_CONF_CHSEL_VBT, /*!< ADC input channel select \ref ADC_CONF_CHSEL_VBT */
AIN1 = ADC_CONF_CHSEL_VHS, /*!< ADC input channel select \ref ADC_CONF_CHSEL_VHS */
AIN2 = ADC_CONF_CHSEL_A2, /*!< ADC input channel select \ref ADC_CONF_CHSEL_A2 */
AIN3 = ADC_CONF_CHSEL_A3, /*!< ADC input channel select \ref ADC_CONF_CHSEL_A3 */
AIN4 = ADC_CONF_CHSEL_YM, /*!< ADC input channel select \ref ADC_CONF_CHSEL_YM */
AIN5 = ADC_CONF_CHSEL_XP, /*!< ADC input channel select \ref ADC_CONF_CHSEL_XP */
AIN6 = ADC_CONF_CHSEL_XM, /*!< ADC input channel select \ref ADC_CONF_CHSEL_XM */
AIN7 = ADC_CONF_CHSEL_XP /*!< ADC input channel select \ref ADC_CONF_CHSEL_XP */
} ADC_CHAN;
/** \brief Structure type of ADC_CMD
*/
typedef enum
{
START_MST, /*!<Menu Start Conversion */
VBPOWER_ON, /*!<Enable ADC Internal Bandgap Power */
VBPOWER_OFF, /*!<Disable ADC Internal Bandgap Power */
NAC_ON, /*!<Enable Normal AD Conversion */
NAC_OFF, /*!<Disable Normal AD Conversion */
START_MST, /*!<Menu Start Conversion with interrupt */
START_MST_POLLING, /*!<Menu Start Conversion with polling */
VBPOWER_ON, /*!<Enable ADC Internal Bandgap Power */
VBPOWER_OFF, /*!<Disable ADC Internal Bandgap Power */
VBAT_ON, /*!<Enable Voltage Battery conversion function */
VBAT_OFF, /*!<Disable Voltage Battery conversion function */
KPPOWER_ON, /*!<Enable ADC Keypad power */
KPPOWER_OFF, /*!<Disable ADC Keypad power */
KPCONV_ON, /*!<Enable Keypad conversion function */
KPCONV_OFF, /*!<Disable Keypad conversion function */
KPPRESS_ON, /*!<Enable Keypad press event */
KPPRESS_OFF, /*!<Disable Keypad press event */
KPUP_ON, /*!<Enable Keypad up event */
KPUP_OFF, /*!<Disable Keypad up event */
PEPOWER_ON, /*!<Enable Pen Down Power ,It can control pen down event */
PEPOWER_OFF, /*!<Disable Pen Power */
PEDEF_ON, /*!<Enable Pen Down Event Flag */
PEDEF_OFF, /*!<Disable Pen Down Event Flag */
WKP_ON, /*!<Enable Keypad Press Wake Up */
WKP_OFF, /*!<Disable Keypad Press Wake Up */
WKT_ON, /*!<Enable Pen Down Wake Up */
WKT_OFF, /*!<Disable Pen Down Wake Up */
SWITCH_5WIRE_ON, /*!<Wire Mode Switch to 5-Wire Configuration */
SWITCH_5WIRE_OFF, /*!<Wire Mode Switch to 4-Wire Configuration */
T_ON, /*!<Enable Touch detection function */
T_OFF, /*!<Disable Touch detection function */
TAVG_ON, /*!<Enable Touch Mean average for X and Y function */
TAVG_OFF, /*!<Disable Touch Mean average for X and Y function */
Z_ON, /*!<Enable Press measure function */
Z_OFF, /*!<Disable Press measure function */
TZAVG_ON, /*!<Enable Pressure Mean average for Z1 and Z2 function */
TZAVG_OFF, /*!<Disable Pressure Mean average for Z1 and Z2 function */
NAC_ON, /*!<Enable Normal AD Conversion */
NAC_OFF, /*!<Disable Normal AD Conversion */
SWITCH_CH, /*!<Switch Channel */
} ADC_CMD;
......
......@@ -151,8 +151,8 @@ typedef struct
#define CAN_BTIME_TSEG2_Pos (12) /*!< CAN_T::BTIME: TSeg2 Position */
#define CAN_BTIME_TSEG2_Msk (0x7ul << CAN_BTIME_TSEG2_Pos) /*!< CAN_T::BTIME: TSeg2 Mask */
#define CAN_IIDR_IntId_Pos (0) /*!< CAN_T::IIDR: IntId Position */
#define CAN_IIDR_IntId_Msk (0xfffful << CAN_IIDR_IntId_Pos) /*!< CAN_T::IIDR: IntId Mask */
#define CAN_IIDR_INTID_Pos (0) /*!< CAN_T::IIDR: IntId Position */
#define CAN_IIDR_INTID_Msk (0xfffful << CAN_IIDR_INTID_Pos) /*!< CAN_T::IIDR: IntId Mask */
#define CAN_TEST_BASIC_Pos (2) /*!< CAN_T::TEST: Basic Position */
#define CAN_TEST_BASIC_Msk (0x1ul << CAN_TEST_BASIC_Pos) /*!< CAN_T::TEST: Basic Mask */
......
......@@ -1295,25 +1295,38 @@
#define REG_PWM0_PIER (PWM0_BA+0x3C) /*!< PWM Timer Interrupt Enable Register */
#define REG_PWM0_PIIR (PWM0_BA+0x40) /*!< PWM Timer Interrupt Identification Register */
#define REG_PWM1_PPR (PWM1_BA+0x00) /*!< PWM Pre-scale Register 0 */
#define REG_PWM1_CSR (PWM1_BA+0x04) /*!< PWM Clock Select Register */
#define REG_PWM1_PCR (PWM1_BA+0x08) /*!< PWM Control Register */
#define REG_PWM1_CNR0 (PWM1_BA+0x0C) /*!< PWM Counter Register 0 */
#define REG_PWM1_CMR0 (PWM1_BA+0x10) /*!< PWM Comparator Register 0 */
#define REG_PWM1_PDR0 (PWM1_BA+0x14) /*!< PWM Data Register 0 */
#define REG_PWM1_CNR1 (PWM1_BA+0x18) /*!< PWM Counter Register 1 */
#define REG_PWM1_CMR1 (PWM1_BA+0x1C) /*!< PWM Comparator Register 1 */
#define REG_PWM1_PDR1 (PWM1_BA+0x20) /*!< PWM Data Register 1 */
#define REG_PWM1_CNR2 (PWM1_BA+0x24) /*!< PWM Counter Register 2 */
#define REG_PWM1_CMR2 (PWM1_BA+0x28) /*!< PWM Comparator Register 2 */
#define REG_PWM1_PDR2 (PWM1_BA+0x2C) /*!< PWM Data Register 2 */
#define REG_PWM1_CNR3 (PWM1_BA+0x30) /*!< PWM Counter Register 3 */
#define REG_PWM1_CMR3 (PWM1_BA+0x34) /*!< PWM Comparator Register 3 */
#define REG_PWM1_PDR3 (PWM1_BA+0x38) /*!< PWM Data Register 3 */
#define REG_PWM1_PIER (PWM1_BA+0x3C) /*!< PWM Timer Interrupt Enable Register */
#define REG_PWM1_PIIR (PWM1_BA+0x40) /*!< PWM Timer Interrupt Identification Register */
/**@}*/ /* end of PWM register group */
/*---------------------- Analog to Digital Converter -------------------------*/
/**
@addtogroup ADC Analog to Digital Converter(ADC)
Memory Mapped Structure for ADC Controller
@{ */
#define REG_ADC_CTL (ADC_BA+0x000) /*!< ADC Contrl */
#define REG_ADC_CONF (ADC_BA+0x004) /*!< ADC Configure */
#define REG_ADC_IER (ADC_BA+0x008) /*!< ADC Interrupt Enable Register */
#define REG_ADC_ISR (ADC_BA+0x00C) /*!< ADC Interrupt Status Register */
#define REG_ADC_WKISR (ADC_BA+0x010) /*!< ADC Wake Up Interrupt Status Register */
#define REG_ADC_XYDATA (ADC_BA+0x020) /*!< ADC Touch XY Pressure Data */
#define REG_ADC_ZDATA (ADC_BA+0x024) /*!< ADC Touch Z Pressure Data */
#define REG_ADC_DATA (ADC_BA+0x028) /*!< ADC Normal Conversion Data */
#define REG_ADC_VBADATA (ADC_BA+0x02C) /*!< ADC Battery Detection Data */
#define REG_ADC_KPDATA (ADC_BA+0x030) /*!< ADC Key Pad Data */
#define REG_ADC_SELFDATA (ADC_BA+0x034) /*!< ADC Self-Test Data */
#define REG_ADC_XYSORT0 (ADC_BA+0x1F4) /*!< ADC Touch XY Position Mean Value Sort 0 */
#define REG_ADC_XYSORT1 (ADC_BA+0x1F8) /*!< ADC Touch XY Position Mean Value Sort 1 */
#define REG_ADC_XYSORT2 (ADC_BA+0x1FC) /*!< ADC Touch XY Position Mean Value Sort 2 */
#define REG_ADC_XYSORT3 (ADC_BA+0x200) /*!< ADC Touch XY Position Mean Value Sort 3 */
#define REG_ADC_ZSORT0 (ADC_BA+0x204) /*!< ADC Touch Z Pressure Mean Value Sort 0 */
#define REG_ADC_ZSORT1 (ADC_BA+0x208) /*!< ADC Touch Z Pressure Mean Value Sort 1 */
#define REG_ADC_ZSORT2 (ADC_BA+0x20C) /*!< ADC Touch Z Pressure Mean Value Sort 2 */
#define REG_ADC_ZSORT3 (ADC_BA+0x210) /*!< ADC Touch Z Pressure Mean Value Sort 3 */
#define REG_ADC_MTMULCK (ADC_BA+0x220) /*!< ADC Manual Test Mode Unlock */
#define REG_ADC_MTCONF (ADC_BA+0x224) /*!< ADC Manual Test Mode Configure */
#define REG_ADC_MTCON (ADC_BA+0x228) /*!< ADC Manual Test Mode Control */
#define REG_ADC_ADCAII (ADC_BA+0x22C) /*!< ADC Analog Interface Information */
#define REG_ADC_ADCAIIRLT (ADC_BA+0x230) /*!< ADC Analog Interface Information Result */
/**@}*/ /* end of ADC register group */
/*------------------ Capture Sensor Interface Controller ---------------------*/
......
......@@ -1129,7 +1129,7 @@ uint32_t EMAC_GetAvailRXBufSize(EMAC_MEMMGR_T *psMemMgr, uint8_t **ppuDataBuf)
* @note Application can only call this function once every time \ref EMAC_RecvPkt or \ref EMAC_RecvPktTS returns 1
* @note This function is without doing EMAC_TRIGGER_RX.
*/
EMAC_DESCRIPTOR_T * EMAC_RecvPktDoneWoRxTrigger(EMAC_MEMMGR_T *psMemMgr)
EMAC_DESCRIPTOR_T *EMAC_RecvPktDoneWoRxTrigger(EMAC_MEMMGR_T *psMemMgr)
{
/* Get Rx Frame Descriptor */
EMAC_DESCRIPTOR_T *desc = (EMAC_DESCRIPTOR_T *)psMemMgr->psCurrentRxDesc;
......@@ -1151,7 +1151,7 @@ EMAC_DESCRIPTOR_T * EMAC_RecvPktDoneWoRxTrigger(EMAC_MEMMGR_T *psMemMgr)
return ret;
}
void EMAC_RxTrigger(EMAC_MEMMGR_T *psMemMgr, EMAC_DESCRIPTOR_T * rx_desc)
void EMAC_RxTrigger(EMAC_MEMMGR_T *psMemMgr, EMAC_DESCRIPTOR_T *rx_desc)
{
EMAC_T *EMAC = psMemMgr->psEmac;
......
......@@ -70,6 +70,13 @@ config SOC_SERIES_NUC980
bool "Enable Analog-to-Digital Converter(ADC)"
select RT_USING_ADC
if BSP_USING_ADC
config BSP_USING_ADC_TOUCH
bool "Enable ADC Touching function"
select RT_USING_TOUCH
default n
endif
menuconfig BSP_USING_TMR
bool "Enable Timer Controller(TIMER)"
......
......@@ -15,9 +15,12 @@
#include <rtdevice.h>
#include "NuMicro.h"
#include <drv_sys.h>
#include "drv_sys.h"
#include "nu_bitutil.h"
#include "drv_adc.h"
/* Private define ---------------------------------------------------------------*/
#define DEF_ADC_TOUCH_SMPL_TICK 40
/* Private Typedef --------------------------------------------------------------*/
struct nu_adc
......@@ -31,12 +34,33 @@ struct nu_adc
int chn_num;
uint32_t chn_mask;
rt_sem_t m_psSem;
#if defined(BSP_USING_ADC_TOUCH)
rt_touch_t psRtTouch;
rt_timer_t psRtTouchMenuTimer;
rt_mq_t m_pmqTouchXYZ;
#endif
nu_adc_cb m_isr[eAdc_ISR_CNT];
nu_adc_cb m_wkisr[eAdc_WKISR_CNT];
};
typedef struct nu_adc *nu_adc_t;
#if defined(BSP_USING_ADC_TOUCH)
struct nu_adc_touch_data
{
uint32_t u32X;
uint32_t u32Y;
uint32_t u32Z0;
uint32_t u32Z1;
};
typedef struct nu_adc_touch_data *nu_adc_touch_data_t;
#endif
/* Private functions ------------------------------------------------------------*/
static rt_err_t nu_adc_enabled(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled);
static rt_err_t nu_adc_convert(struct rt_adc_device *device, rt_uint32_t channel, rt_uint32_t *value);
static rt_err_t _nu_adc_control(rt_device_t dev, int cmd, void *args);
/* Public functions ------------------------------------------------------------*/
int rt_hw_adc_init(void);
......@@ -56,24 +80,41 @@ static struct nu_adc g_sNuADC =
static void nu_adc_isr(int vector, void *param)
{
uint32_t isr, conf;
rt_int32_t isr, wkisr;
nu_adc_t psNuAdc = (nu_adc_t)param;
rt_int32_t irqidx;
conf = inpw(REG_ADC_CONF);
isr = inpw(REG_ADC_ISR);
wkisr = inpw(REG_ADC_WKISR);
if ((isr & ADC_ISR_NACF) && (conf & ADC_CONF_NACEN))
while ((irqidx = nu_ctz(isr)) < eAdc_ISR_CNT)
{
outpw(REG_ADC_ISR, ADC_ISR_NACF);
}
uint32_t u32IsrBitMask = 1 << irqidx ;
if (isr & ADC_ISR_MF)
if (psNuAdc->m_isr[irqidx].cbfunc != RT_NULL)
{
//rt_kprintf("[%s] %d %x\n", __func__, irqidx, psNuAdc->m_isr[irqidx].cbfunc);
psNuAdc->m_isr[irqidx].cbfunc(isr, psNuAdc->m_isr[irqidx].private_data);
}
/* Clear sent bit */
outpw(REG_ADC_ISR, u32IsrBitMask);
isr &= ~(u32IsrBitMask);
} //while
while ((irqidx = nu_ctz(wkisr)) < eAdc_WKISR_CNT)
{
rt_err_t result;
outpw(REG_ADC_ISR, ADC_ISR_MF);
result = rt_sem_release(psNuAdc->m_psSem);
RT_ASSERT(result == RT_EOK);
}
uint32_t u32IsrBitMask = 1 << irqidx ;
if (psNuAdc->m_wkisr[irqidx].cbfunc != RT_NULL)
{
psNuAdc->m_wkisr[irqidx].cbfunc(wkisr, psNuAdc->m_wkisr[irqidx].private_data);
}
/* Clear sent bit */
outpw(REG_ADC_WKISR, u32IsrBitMask);
wkisr &= ~(u32IsrBitMask);
} //while
}
static rt_err_t _nu_adc_init(rt_device_t dev)
......@@ -96,11 +137,171 @@ static rt_err_t _nu_adc_init(rt_device_t dev)
return RT_EOK;
}
static int32_t AdcMenuStartCallback(uint32_t status, uint32_t userData)
{
nu_adc_t psNuAdc = (nu_adc_t)userData;
#if defined(BSP_USING_ADC_TOUCH)
static struct nu_adc_touch_data point;
static rt_bool_t bDrop = RT_FALSE;
static uint32_t u32LastZ0 = 0xffffu;
if (psNuAdc->psRtTouch != RT_NULL)
{
uint32_t value;
value = inpw(REG_ADC_XYDATA);
point.u32X = (value & 0x0ffful);
point.u32Y = ((value >> 16) & 0x0ffful);
value = inpw(REG_ADC_ZDATA);
point.u32Z0 = (value & 0x0ffful);
point.u32Z1 = ((value >> 16) & 0x0ffful);
/* Trigger next or not. */
if (point.u32Z0 == 0)
{
/* Stop sampling procedure. */
rt_timer_stop(g_sNuADC.psRtTouchMenuTimer);
/* Re-start pendown detection */
nu_adc_touch_detect(RT_TRUE);
bDrop = RT_TRUE;
}
else
{
bDrop = RT_FALSE;
}
/* Notify upper layer. */
if ((!bDrop || (u32LastZ0 != 0)) && rt_mq_send(psNuAdc->m_pmqTouchXYZ, (const void *)&point, sizeof(struct nu_adc_touch_data)) == RT_EOK)
{
rt_hw_touch_isr(psNuAdc->psRtTouch);
}
u32LastZ0 = point.u32Z0;
}
else
#endif
{
rt_err_t result = rt_sem_release(psNuAdc->m_psSem);
RT_ASSERT(result == RT_EOK);
}
return 0;
}
#if defined(BSP_USING_ADC_TOUCH)
void nu_adc_touch_detect(rt_bool_t bStartDetect)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
if (bStartDetect)
{
/* Start detect PenDown */
_nu_adc_control((rt_device_t)psNuAdc, PEPOWER_ON, RT_NULL);
}
else
{
/* Stop detect PenDown */
_nu_adc_control((rt_device_t)psNuAdc, PEPOWER_OFF, RT_NULL);
}
}
static int32_t PenDownCallback(uint32_t status, uint32_t userData)
{
nu_adc_touch_detect(RT_FALSE);
rt_timer_start(g_sNuADC.psRtTouchMenuTimer);
return 0;
}
int32_t nu_adc_touch_read_xyz(uint32_t *bufX, uint32_t *bufY, uint32_t *bufZ0, uint32_t *bufZ1, int32_t dataCnt)
{
int i;
struct nu_adc_touch_data value;
for (i = 0 ; i < dataCnt; i++)
{
if (rt_mq_recv(g_sNuADC.m_pmqTouchXYZ, (void *)&value, sizeof(struct nu_adc_touch_data), 0) == -RT_ETIMEOUT)
break;
bufX[i] = value.u32X;
bufY[i] = value.u32Y;
bufZ0[i] = value.u32Z0;
bufZ1[i] = value.u32Z1;
}
return i;
}
void nu_adc_touch_start_conv(void)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
_nu_adc_control((rt_device_t)psNuAdc, START_MST, RT_NULL);
}
rt_err_t nu_adc_touch_enable(rt_touch_t psRtTouch)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
nu_adc_cb sNuAdcCb;
rt_adc_enable((rt_adc_device_t)psNuAdc, 4);
rt_adc_enable((rt_adc_device_t)psNuAdc, 5);
rt_adc_enable((rt_adc_device_t)psNuAdc, 6);
rt_adc_enable((rt_adc_device_t)psNuAdc, 7);
outpw(REG_ADC_CONF, (inpw(REG_ADC_CONF) & ~(0xfful << 24)) | 0xfful << 24);
/* Register touch device. */
psNuAdc->psRtTouch = psRtTouch;
/* Enable TouchXY. */
_nu_adc_control((rt_device_t)psNuAdc, T_ON, RT_NULL);
/* Enable TouchZZ. */
_nu_adc_control((rt_device_t)psNuAdc, Z_ON, RT_NULL);
/* Register PenDown callback. */
sNuAdcCb.cbfunc = PenDownCallback;
sNuAdcCb.private_data = (rt_uint32_t)psRtTouch;
_nu_adc_control((rt_device_t)psNuAdc, PEDEF_ON, (void *)&sNuAdcCb);
nu_adc_touch_detect(RT_TRUE);
return RT_EOK;
}
rt_err_t nu_adc_touch_disable(void)
{
nu_adc_t psNuAdc = (nu_adc_t)&g_sNuADC;
nu_adc_touch_detect(RT_FALSE);
_nu_adc_control((rt_device_t)psNuAdc, T_OFF, RT_NULL);
_nu_adc_control((rt_device_t)psNuAdc, Z_OFF, RT_NULL);
_nu_adc_control((rt_device_t)psNuAdc, PEDEF_OFF, RT_NULL);
rt_adc_disable((rt_adc_device_t)psNuAdc, 4);
rt_adc_disable((rt_adc_device_t)psNuAdc, 5);
rt_adc_disable((rt_adc_device_t)psNuAdc, 6);
rt_adc_disable((rt_adc_device_t)psNuAdc, 7);
return RT_EOK;
}
#endif
static rt_err_t _nu_adc_control(rt_device_t dev, int cmd, void *args)
{
rt_err_t ret = RT_EINVAL ;
nu_adc_t psNuAdc = (nu_adc_t)dev;
nu_adc_cb_t psAdcCb = (nu_adc_cb_t)args;
switch (cmd)
{
case START_MST: /* Menu Start Conversion */
......@@ -116,29 +317,259 @@ static rt_err_t _nu_adc_control(rt_device_t dev, int cmd, void *args)
RT_ASSERT(ret == RT_EOK);
/* Get data: valid data is 12-bit */
*((uint32_t *)args) = inpw(REG_ADC_DATA) & 0x00000FFF;
if (args != RT_NULL)
*((uint32_t *)args) = inpw(REG_ADC_DATA) & 0x00000FFF;
}
break;
/* case START_MST_POLLING: Not supported. */
case VBPOWER_ON: /* Enable ADC Internal Bandgap Power */
{
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) | ADC_CTL_VBGEN);
}
break;
case VBPOWER_OFF: /* Disable ADC Internal Bandgap Power */
{
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) & ~ADC_CTL_VBGEN);
}
break;
case KPPOWER_ON: /* Enable ADC Keypad Power */
{
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) | ADC_CTL_PWKPEN);
}
break;
case KPPOWER_OFF: /* Disable ADC Keypad Power */
{
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) & ~ADC_CTL_PWKPEN);
}
break;
case PEPOWER_ON: /* Enable Pen Power */
{
int retry = 100;
uint32_t treg = inpw(REG_ADC_IER);
outpw(REG_ADC_IER, treg & ~(ADC_IER_PEDEIEN | ADC_IER_PEUEIEN));
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) | ADC_CTL_PEDEEN);
do
{
outpw(REG_ADC_ISR, ADC_ISR_PEDEF | ADC_ISR_PEUEF);
rt_thread_mdelay(1);
if (retry-- == 0)
break;
}
while (inpw(REG_ADC_ISR) & (ADC_ISR_PEDEF | ADC_ISR_PEUEF));
outpw(REG_ADC_IER, treg);
}
break;
case PEPOWER_OFF: /* Disable Pen Power */
{
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) & ~ADC_CTL_PEDEEN);
}
break;
case KPPRESS_ON: /* Enable Keypad press event */
{
if (psAdcCb)
{
rt_memcpy(&psNuAdc->m_isr[eAdc_KPEF], psAdcCb, sizeof(nu_adc_cb));
}
outpw(REG_ADC_IER, inpw(REG_ADC_IER) | ADC_IER_KPEIEN);
}
break;
case KPPRESS_OFF: /* Disable Keypad press event */
{
outpw(REG_ADC_IER, inpw(REG_ADC_IER & ~ADC_IER_KPEIEN));
}
break;
case KPUP_ON: /* Enable Keypad up event */
{
if (psAdcCb)
{
rt_memcpy(&psNuAdc->m_isr[eAdc_KPUEF], psAdcCb, sizeof(nu_adc_cb));
}
outpw(REG_ADC_IER, inpw(REG_ADC_IER) | ADC_IER_KPUEIEN);
}
break;
case KPUP_OFF: /* Disable Keypad up event */
{
outpw(REG_ADC_IER, inpw(REG_ADC_IER) & ~ADC_IER_KPUEIEN);
}
break;
case PEDEF_ON: /* Enable Pen Down Event */
{
if (psAdcCb)
{
rt_memcpy(&psNuAdc->m_isr[eAdc_PEDEF], psAdcCb, sizeof(nu_adc_cb));
}
outpw(REG_ADC_IER, inpw(REG_ADC_IER) | ADC_IER_PEDEIEN);
}
break;
case PEDEF_OFF: /* Disable Pen Down Event */
{
outpw(REG_ADC_IER, inpw(REG_ADC_IER) & ~ADC_IER_PEDEIEN);
}
break;
case WKP_ON: /* Enable Keypad Press Wake Up */
{
if (psAdcCb)
{
rt_memcpy(&psNuAdc->m_wkisr[eAdc_WKPEF], psAdcCb, sizeof(nu_adc_cb));
}
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) | ADC_CTL_WKPEN);
outpw(REG_ADC_IER, inpw(REG_ADC_IER) | ADC_IER_WKPIEN);
//outpw(REG_SYS_WKUPSER, inpw(REG_SYS_WKUPSER) | (1 << 26));
}
break;
case WKP_OFF: /* Disable Keypad Press Wake Up */
{
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) & ~ADC_CTL_WKPEN);
outpw(REG_ADC_IER, inpw(REG_ADC_IER) & ~ADC_IER_WKPIEN);
//outpw(REG_SYS_WKUPSER, inpw(REG_SYS_WKUPSER) & ~(1 << 26));
}
break;
case WKT_ON: /* Enable Touch Wake Up */
{
if (psAdcCb)
{
rt_memcpy(&psNuAdc->m_wkisr[eAdc_WPEDEF], psAdcCb, sizeof(nu_adc_cb));
}
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) | ADC_CTL_WKTEN);
outpw(REG_ADC_IER, inpw(REG_ADC_IER) | ADC_IER_WKTIEN);
//outpw(REG_SYS_WKUPSER, inpw(REG_SYS_WKUPSER) | (1 << 26));
}
break;
case WKT_OFF: /* Disable Touch Wake Up */
{
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) & ~ADC_CTL_WKTEN);
outpw(REG_ADC_IER, inpw(REG_ADC_IER) & ~ADC_IER_WKTIEN);
//outpw(REG_SYS_WKUPSER, inpw(REG_SYS_WKUPSER) & ~(1 << 26));
}
break;
case SWITCH_5WIRE_ON: /* Wire Mode Switch to 5-Wire */
{
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) | ADC_CTL_WMSWCH);
}
break;
case SWITCH_5WIRE_OFF: /* Wire Mode Switch to 4-Wire */
{
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) & ~ADC_CTL_WMSWCH);
}
break;
case T_ON: /* Enable Touch detection function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) | ADC_CONF_TEN);
}
break;
case T_OFF: /* Disable Touch detection function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) & ~ADC_CONF_TEN);
}
break;
case TAVG_ON: /* Enable Touch Mean average for X and Y function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) | ADC_CONF_DISTMAVEN);
}
break;
case TAVG_OFF: /* Disable Touch Mean average for X and Y function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) & ~ADC_CONF_DISTMAVEN);
}
break;
case Z_ON: /* Enable Press measure function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) | ADC_CONF_ZEN);
}
break;
case Z_OFF: /* Disable Press measure function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) & ~ADC_CONF_ZEN);
#if defined(BSP_USING_ADC_TOUCH)
rt_mq_control(psNuAdc->m_pmqTouchXYZ, RT_IPC_CMD_RESET, RT_NULL);
#endif
}
break;
case TZAVG_ON: /* Enable Pressure Mean average for Z1 and Z2 function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) | ADC_CONF_DISZMAVEN);
}
break;
case TZAVG_OFF: /* Disable Pressure Mean average for Z1 and Z2 function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) & ~ADC_CONF_DISZMAVEN);
}
break;
case NAC_ON: /* Enable Normal AD Conversion */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) | ADC_CONF_NACEN | ADC_CONF_REFSEL_AVDD33);
}
break;
case NAC_OFF: /* Disable Normal AD Conversion */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) & ~ADC_CONF_NACEN);
}
break;
case VBAT_ON: /* Enable Voltage Battery Conversion */
{
if (psAdcCb)
{
rt_memcpy(&psNuAdc->m_isr[eAdc_VBF], psAdcCb, sizeof(nu_adc_cb));
}
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) | ADC_CONF_VBATEN);
}
break;
case VBAT_OFF: /* Disable Voltage Battery */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) & ~ADC_CONF_VBATEN);
}
break;
case KPCONV_ON: /* Enable Keypad conversion function */
{
if (psAdcCb)
{
rt_memcpy(&psNuAdc->m_isr[eAdc_KPCF], psAdcCb, sizeof(nu_adc_cb));
}
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) | ADC_CONF_KPCEN);
outpw(REG_ADC_IER, inpw(REG_ADC_IER) | ADC_IER_KPEIEN);
}
break;
case KPCONV_OFF: /* Disable Keypad conversion function */
{
outpw(REG_ADC_CONF, inpw(REG_ADC_CONF) & ~ADC_CONF_KPCEN);
}
break;
case SWITCH_CH:
{
int chn = (int)args;
......@@ -265,6 +696,16 @@ exit_nu_adc_convert:
return (-ret) ;
}
static void nu_adc_touch_smpl(void *p)
{
/* Enable interrupt */
outpw(REG_ADC_IER, inpw(REG_ADC_IER) | ADC_IER_MIEN);
/* Start conversion */
outpw(REG_ADC_CTL, inpw(REG_ADC_CTL) | ADC_CTL_MST);
}
int rt_hw_adc_init(void)
{
rt_err_t result = RT_ERROR;
......@@ -279,8 +720,22 @@ int rt_hw_adc_init(void)
g_sNuADC.m_psSem = rt_sem_create("adc_mst_sem", 0, RT_IPC_FLAG_FIFO);
RT_ASSERT(g_sNuADC.m_psSem != RT_NULL);
#if defined(BSP_USING_ADC_TOUCH)
g_sNuADC.m_pmqTouchXYZ = rt_mq_create("ADC_TOUCH_XYZ", sizeof(struct nu_adc_touch_data), TOUCH_MQ_LENGTH, RT_IPC_FLAG_FIFO);
RT_ASSERT(g_sNuADC.m_pmqTouchXYZ != RT_NULL);
g_sNuADC.psRtTouchMenuTimer = rt_timer_create("TOUCH_SMPL_TIMER", nu_adc_touch_smpl, (void *)&g_sNuADC, DEF_ADC_TOUCH_SMPL_TICK, RT_TIMER_FLAG_PERIODIC);
RT_ASSERT(g_sNuADC.psRtTouchMenuTimer != RT_NULL);
#endif
rt_memset(&g_sNuADC.m_isr, 0, sizeof(g_sNuADC.m_isr));
rt_memset(&g_sNuADC.m_wkisr, 0, sizeof(g_sNuADC.m_wkisr));
g_sNuADC.m_isr[eAdc_MF].cbfunc = AdcMenuStartCallback;
g_sNuADC.m_isr[eAdc_MF].private_data = (UINT32)&g_sNuADC;
return (int)result;
}
INIT_BOARD_EXPORT(rt_hw_adc_init);
#endif //#if defined(BSP_USING_EADC)
#endif //#if defined(BSP_USING_ADC)
/**************************************************************************//**
*
* @copyright (C) 2020 Nuvoton Technology Corp. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-4-7 Wayne First version
*
******************************************************************************/
#ifndef __DRV_ADC_H__
#define __DRV_ADC_H__
#include <rtthread.h>
#include "nu_adc.h"
#if defined(BSP_USING_ADC_TOUCH)
#include "touch.h"
#endif
#define TOUCH_MQ_LENGTH 64
#define DEF_CAL_POINT_NUM 5
typedef enum
{
eAdc_MF, //0
eAdc_KPEF, //1
eAdc_PEDEF, //2
eAdc_KPUEF, //3
eAdc_PEUEF, //4
eAdc_TF = 8, //8
eAdc_ZF, //9
eAdc_NACF, //10
eAdc_VBF, //11
eAdc_KPCF, //12
eAdc_SELFTF, //13
eAdc_INTKP = 16, //16
eAdc_INTTC, //17
eAdc_ISR_CNT //18
} E_ADC_ISR_EVENT;
typedef enum
{
eAdc_WKPEF,
eAdc_WPEDEF,
eAdc_WKISR_CNT
} E_ADC_WKISR_EVENT;
typedef struct
{
ADC_CALLBACK cbfunc;
uint32_t private_data;
} nu_adc_cb;
typedef nu_adc_cb *nu_adc_cb_t;
#if defined(BSP_USING_ADC_TOUCH)
typedef struct
{
int32_t x;
int32_t y;
} S_COORDINATE_POINT;
typedef struct
{
int32_t a;
int32_t b;
int32_t c;
int32_t d;
int32_t e;
int32_t f;
int32_t div;
} S_CALIBRATION_MATRIX;
int32_t nu_adc_touch_read_xyz(uint32_t *bufX, uint32_t *bufY, uint32_t *bufZ0, uint32_t *bufZ1, int32_t dataCnt);
rt_err_t nu_adc_touch_enable(rt_touch_t psRtTouch);
rt_err_t nu_adc_touch_disable(void);
void nu_adc_touch_detect(rt_bool_t bStartDetect);
void nu_adc_touch_start_conv(void);
#endif
#endif /* __DRV_ADC_H__ */
此差异已折叠。
......@@ -64,6 +64,7 @@ struct nu_can
IRQn_Type irqn;
E_SYS_IPRST rstidx;
E_SYS_IPCLK clkidx;
uint32_t int_flag;
};
typedef struct nu_can *nu_can_t;
......@@ -130,16 +131,16 @@ static const struct can_configure nu_can_default_config = NU_CAN_CONFIG_DEFAULT;
/* Interrupt Handle Function ----------------------------------------------------*/
static void nu_can_isr(int vector, void *param)
{
uint32_t u32IIDRstatus;
nu_can_t psNuCAN = (nu_can_t)param;
/* Get base address of CAN register */
CAN_T *base = psNuCAN->base;
/* Get interrupt event */
u32IIDRstatus = CAN_GET_INT_PENDING_STATUS(base);
uint32_t u32IIDRstatus = CAN_GET_INT_PENDING_STATUS(base) & CAN_IIDR_INTID_Msk;
if (u32IIDRstatus == 0x00008000) /* Check Status Interrupt Flag (Error status Int and Status change Int) */
/* Check Status Interrupt Flag (Error status Int and Status change Int) */
if (u32IIDRstatus == 0x00008000)
{
/**************************/
/* Status Change interrupt*/
......@@ -147,20 +148,24 @@ static void nu_can_isr(int vector, void *param)
if (base->STATUS & CAN_STATUS_TXOK_Msk)
{
base->STATUS &= ~CAN_STATUS_TXOK_Msk; /* Clear Tx Ok status*/
//rt_kprintf("%s: TX\n", psNuCAN->name) ;
#ifndef RT_CAN_USING_HDR
/* Using as Lisen,Loopback,Loopback+Lisen mode*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_TX_DONE);
if (psNuCAN->int_flag & RT_DEVICE_FLAG_INT_TX)
{
/*Using as Lisen,Loopback,Loopback+Lisen mode*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_TX_DONE);
}
#endif
}
if (base->STATUS & CAN_STATUS_RXOK_Msk)
{
base->STATUS &= ~CAN_STATUS_RXOK_Msk; /* Clear Rx Ok status*/
//rt_kprintf("%s: RX\n", psNuCAN->name) ;
#ifndef RT_CAN_USING_HDR
/* Using as Lisen,Loopback,Loopback+Lisen mode*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_RX_IND);
if (psNuCAN->int_flag & RT_DEVICE_FLAG_INT_RX)
{
/*Using as Lisen,Loopback,Loopback+Lisen mode*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_RX_IND);
}
#endif
}
......@@ -169,17 +174,16 @@ static void nu_can_isr(int vector, void *param)
/**************************/
if (base->STATUS & CAN_STATUS_EWARN_Msk)
{
rt_kprintf("%s: EWARN\n", psNuCAN->name) ;
rt_kprintf("[%s]EWARN INT\n", psNuCAN->name) ;
}
if (base->STATUS & CAN_STATUS_BOFF_Msk)
{
rt_kprintf("%s: BUSOFF\n", psNuCAN->name) ;
rt_kprintf("[%s]BUSOFF INT\n", psNuCAN->name) ;
/* Do Init to release busoff pin */
base->CON = (CAN_CON_INIT_Msk | CAN_CON_CCE_Msk);
base->CON &= (~(CAN_CON_INIT_Msk | CAN_CON_CCE_Msk));
while (base->CON & CAN_CON_INIT_Msk);
/* To release busoff pin */
CAN_EnterInitMode(base, CAN_CON_INIT_Msk | CAN_CON_CCE_Msk);
CAN_LeaveInitMode(base);
}
if (base->STATUS & CAN_STATUS_LEC_Msk)
......@@ -192,66 +196,83 @@ static void nu_can_isr(int vector, void *param)
/*IntId: 0x0001-0x0020, Number of Message Object which caused the interrupt.*/
else if (u32IIDRstatus > 0 && u32IIDRstatus <= 32)
{
/*Message RAM 0~RX_MSG_ID_INDEX for CAN Tx using*/
if (u32IIDRstatus <= RX_MSG_ID_INDEX)
if ((psNuCAN->int_flag & RT_DEVICE_FLAG_INT_TX) &&
(u32IIDRstatus <= RX_MSG_ID_INDEX))
{
//rt_kprintf("[%s-Tx]IntId = %d\n", psNuCAN->name, u32IIDRstatus);
/*Message RAM 0~RX_MSG_ID_INDEX for CAN Tx using*/
rt_hw_can_isr(&psNuCAN->dev, RT_CAN_EVENT_TX_DONE);
}
else /*Message RAM RX_MSG_ID_INDEX~31 for CAN Rx using*/
else if (psNuCAN->int_flag & RT_DEVICE_FLAG_INT_RX)
{
//rt_kprintf("[%s-Rx]IntId = %d\n", psNuCAN->name, u32IIDRstatus);
/*Message RAM RX_MSG_ID_INDEX~31 for CAN Rx using*/
rt_hw_can_isr(&psNuCAN->dev, (RT_CAN_EVENT_RX_IND | ((u32IIDRstatus - 1) << 8)));
}
CAN_CLR_INT_PENDING_BIT(base, (u32IIDRstatus - 1)); /* Clear Interrupt Pending */
}
#endif
}
static void nu_can_ie(nu_can_t psNuCAN)
{
uint32_t u32CanIE = CAN_CON_IE_Msk;
if (psNuCAN->int_flag & (RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX))
{
u32CanIE |= CAN_CON_SIE_Msk;
}
else
{
u32CanIE &= ~CAN_CON_SIE_Msk;
}
if (psNuCAN->int_flag & RT_DEVICE_CAN_INT_ERR)
{
u32CanIE |= CAN_CON_EIE_Msk;
}
else
{
u32CanIE &= ~CAN_CON_EIE_Msk;
}
if (u32CanIE & (CAN_CON_SIE_Msk | CAN_CON_EIE_Msk))
{
CAN_EnableInt(psNuCAN->base, u32CanIE);
/* Enable interrupt. */
rt_hw_interrupt_umask(psNuCAN->irqn);
}
else
{
u32CanIE |= (CAN_CON_IE_Msk | CAN_CON_SIE_Msk);
CAN_DisableInt(psNuCAN->base, u32CanIE);
/* Disable interrupt. */
rt_hw_interrupt_mask(psNuCAN->irqn);
}
}
static rt_err_t nu_can_configure(struct rt_can_device *can, struct can_configure *cfg)
{
nu_can_t psNuCAN = (nu_can_t)can;
uint32_t u32CANMode;
RT_ASSERT(can != RT_NULL);
RT_ASSERT(cfg != RT_NULL);
RT_ASSERT(can);
RT_ASSERT(cfg);
/* Get base address of CAN register */
CAN_T *base = psNuCAN->base;
RT_ASSERT(base != RT_NULL);
switch (cfg->mode)
{
/* CAN default Normal mode */
case RT_CAN_MODE_NORMAL:
can->config.mode = CAN_NORMAL_MODE;
break;
case RT_CAN_MODE_LISEN:
can->config.mode = RT_CAN_MODE_LISEN;
break;
case RT_CAN_MODE_LOOPBACK:
can->config.mode = RT_CAN_MODE_LOOPBACK;
break;
case RT_CAN_MODE_LOOPBACKANLISEN:
can->config.mode = RT_CAN_MODE_LOOPBACKANLISEN;
break;
default:
rt_kprintf("Unsupported Operating mode");
goto exit_nu_can_configure;
}
/* Reset this module */
nu_sys_ip_reset(psNuCAN->rstidx);
/*Set the CAN Bit Rate and Operating mode*/
if (CAN_Open(base, can->config.baud_rate, can->config.mode) < 1)
return -(RT_ERROR);
u32CANMode = (cfg->mode == RT_CAN_MODE_NORMAL) ? CAN_NORMAL_MODE : CAN_BASIC_MODE;
/*Set the CAN Bit Rate and Operating mode*/
if (CAN_Open(base, cfg->baud_rate, u32CANMode) != cfg->baud_rate)
goto exit_nu_can_configure;
switch (cfg->mode)
{
/* CAN default Normal mode */
case RT_CAN_MODE_NORMAL:
#ifdef RT_CAN_USING_HDR
CAN_LeaveTestMode(base);
......@@ -273,6 +294,7 @@ static rt_err_t nu_can_configure(struct rt_can_device *can, struct can_configure
goto exit_nu_can_configure;
}
nu_can_ie(psNuCAN);
return RT_EOK;
......@@ -285,73 +307,33 @@ exit_nu_can_configure:
static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
{
rt_uint32_t argval;
nu_can_t psNuCAN = (nu_can_t)can;
#ifdef RT_CAN_USING_HDR
struct rt_can_filter_config *filter_cfg;
#endif
/* Get base address of CAN register */
CAN_T *base = psNuCAN->base;
rt_uint32_t argval = (rt_uint32_t)arg;
nu_can_t psNuCAN = (nu_can_t)can;
RT_ASSERT(base != RT_NULL);
/* Check baud rate */
RT_ASSERT(can->config.baud_rate != 0);
RT_ASSERT(can);
switch (cmd)
{
case RT_DEVICE_CTRL_CLR_INT:
argval = (rt_uint32_t) arg;
if ((argval == RT_DEVICE_FLAG_INT_RX) || (argval == RT_DEVICE_FLAG_INT_TX))
{
/* Disable NVIC interrupt. */
rt_hw_interrupt_mask(psNuCAN->irqn);
/* Disable Status Change Interrupt */
CAN_DisableInt(base, CAN_CON_IE_Msk | CAN_CON_SIE_Msk);
}
else if (argval == RT_DEVICE_CAN_INT_ERR)
{
/* Disable interrupt. */
rt_hw_interrupt_mask(psNuCAN->irqn);
/* Disable Error Interrupt */
CAN_DisableInt(base, CAN_CON_EIE_Msk);
}
break;
case RT_DEVICE_CTRL_SET_INT:
argval = (rt_uint32_t) arg;
if (argval == RT_DEVICE_FLAG_INT_RX || (argval == RT_DEVICE_FLAG_INT_TX))
{
/* Enable Status Change Interrupt */
CAN_EnableInt(base, CAN_CON_IE_Msk | CAN_CON_SIE_Msk);
/* Enable interrupt. */
rt_hw_interrupt_umask(psNuCAN->irqn);
}
else if (argval == RT_DEVICE_CAN_INT_ERR)
{
/* Enable Error Status and Status Change Interrupt */
CAN_EnableInt(base, CAN_CON_IE_Msk | CAN_CON_SIE_Msk | CAN_CON_EIE_Msk);
psNuCAN->int_flag |= argval;
nu_can_ie(psNuCAN);
break;
/* Enable interrupt. */
rt_hw_interrupt_umask(psNuCAN->irqn);
}
case RT_DEVICE_CTRL_CLR_INT:
psNuCAN->int_flag &= ~argval;
nu_can_ie(psNuCAN);
break;
#ifdef RT_CAN_USING_HDR
case RT_CAN_CMD_SET_FILTER:
filter_cfg = (struct rt_can_filter_config *)arg;
{
struct rt_can_filter_config *filter_cfg = (struct rt_can_filter_config *)arg;
for (int i = 0; i < filter_cfg->count; i++)
{
/*set the filter message object*/
if (filter_cfg->items[i].mode == 1)
{
if (CAN_SetRxMsgObjAndMsk(base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
if (CAN_SetRxMsgObjAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask, FALSE) == FALSE)
{
return -(RT_ERROR);
}
......@@ -359,46 +341,61 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
else
{
/*set the filter message object*/
if (CAN_SetRxMsgAndMsk(base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
if (CAN_SetRxMsgAndMsk(psNuCAN->base, MSG(filter_cfg->items[i].hdr + RX_MSG_ID_INDEX), filter_cfg->items[i].ide, filter_cfg->items[i].id, filter_cfg->items[i].mask) == FALSE)
{
return -(RT_ERROR);
}
}
}
break;
#endif
}
break;
case RT_CAN_CMD_SET_MODE:
argval = (rt_uint32_t) arg;
if (argval != RT_CAN_MODE_NORMAL && argval != RT_CAN_MODE_LISEN &&
argval != RT_CAN_MODE_LOOPBACK && argval != RT_CAN_MODE_LOOPBACKANLISEN)
if ((argval == RT_CAN_MODE_NORMAL) ||
(argval == RT_CAN_MODE_LISEN) ||
(argval == RT_CAN_MODE_LOOPBACK) ||
(argval == RT_CAN_MODE_LOOPBACKANLISEN))
{
return -(RT_ERROR);
if (argval != can->config.mode)
{
can->config.mode = argval;
return nu_can_configure(can, &can->config);
}
}
if (argval != can->config.mode)
else
{
can->config.mode = argval;
return nu_can_configure(can, &can->config);
return -(RT_ERROR);
}
break;
case RT_CAN_CMD_SET_BAUD:
argval = (rt_uint32_t) arg;
if (argval != CAN1MBaud && argval != CAN800kBaud && argval != CAN500kBaud && argval != CAN250kBaud &&
argval != CAN125kBaud && argval != CAN100kBaud && argval != CAN50kBaud && argval != CAN20kBaud && argval != CAN10kBaud)
{
if ((argval == CAN1MBaud) ||
(argval == CAN800kBaud) ||
(argval == CAN500kBaud) ||
(argval == CAN250kBaud) ||
(argval == CAN125kBaud) ||
(argval == CAN100kBaud) ||
(argval == CAN50kBaud) ||
(argval == CAN20kBaud) ||
(argval == CAN10kBaud))
{
return -(RT_ERROR);
if (argval != can->config.baud_rate)
{
can->config.baud_rate = argval;
return nu_can_configure(can, &can->config);
}
}
if (argval != can->config.baud_rate)
else
{
can->config.baud_rate = argval;
return nu_can_configure(can, &can->config);
return -(RT_ERROR);
}
break;
}
break;
case RT_CAN_CMD_SET_PRIV:
argval = (rt_uint32_t) arg;
if (argval != RT_CAN_MODE_PRIV && argval != RT_CAN_MODE_NOPRIV)
if (argval != RT_CAN_MODE_PRIV &&
argval != RT_CAN_MODE_NOPRIV)
{
return -(RT_ERROR);
}
......@@ -411,16 +408,23 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
case RT_CAN_CMD_GET_STATUS:
{
rt_uint32_t errtype;
errtype = base->ERR;
/*Receive Error Counter*/
rt_uint32_t errtype = psNuCAN->base->ERR;
RT_ASSERT(arg);
/*Receive Error Counter, return value is with Receive Error Passive.*/
can->status.rcverrcnt = (errtype >> 8);
/*Transmit Error Counter*/
can->status.snderrcnt = ((errtype >> 24) & 0xFF);
can->status.lasterrtype = CAN_GET_INT_STATUS(base) & 0x8000;
/*status error code*/
can->status.errcode = CAN_GET_INT_STATUS(base) & 0x07;
rt_memcpy(arg, &can->status, sizeof(can->status));
can->status.snderrcnt = (errtype & 0xFF);
/*Last Error Type*/
can->status.lasterrtype = CAN_GET_INT_STATUS(psNuCAN->base) & 0x8000;
/*Status error code*/
can->status.errcode = CAN_GET_INT_STATUS(psNuCAN->base) & 0x07;
rt_memcpy(arg, &can->status, sizeof(struct rt_can_status));
}
break;
......@@ -435,64 +439,91 @@ static rt_err_t nu_can_control(struct rt_can_device *can, int cmd, void *arg)
static int nu_can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t boxno)
{
STR_CANMSG_T tMsg;
struct rt_can_msg *pmsg = (struct rt_can_msg *) buf;
/* Get base address of CAN register */
CAN_T *base = ((nu_can_t)can)->base;
struct rt_can_msg *pmsg;
nu_can_t psNuCAN = (nu_can_t)can;
RT_ASSERT(base != RT_NULL);
RT_ASSERT(buf != RT_NULL);
RT_ASSERT(can);
RT_ASSERT(buf);
/* Check the parameters */
RT_ASSERT(IS_CAN_DLC(pmsg->len));
pmsg = (struct rt_can_msg *) buf;
/* Standard ID (11 bits)*/
if (pmsg->ide == RT_CAN_STDID)
if (pmsg->ide == RT_CAN_STDID && IS_CAN_STDID(pmsg->id))
{
/* Standard ID (11 bits)*/
tMsg.IdType = CAN_STD_ID;
RT_ASSERT(IS_CAN_STDID(pmsg->id))
tMsg.Id = pmsg->id ;
}
else
else if (pmsg->ide == RT_CAN_EXTID && IS_CAN_EXTID(pmsg->id))
{
/* Extended ID (29 bits)*/
tMsg.IdType = CAN_EXT_ID;
RT_ASSERT(IS_CAN_EXTID(pmsg->id));
tMsg.Id = pmsg->id ;
}
else
{
goto exit_nu_can_sendmsg;
}
if (pmsg->rtr == RT_CAN_DTR)
{
/* Data frame */
tMsg.FrameType = CAN_DATA_FRAME;
}
else
else if (pmsg->rtr == RT_CAN_RTR)
{
/* Remote frame */
tMsg.FrameType = CAN_REMOTE_FRAME;
}
tMsg.DLC = pmsg->len;
rt_memcpy(tMsg.Data, pmsg->data, pmsg->len);
else
{
goto exit_nu_can_sendmsg;
}
if (CAN_Transmit(base, MSG(boxno), &tMsg) == FALSE) // Configure Msg RAM and send the Msg in the RAM
/* Check the parameters */
if (IS_CAN_DLC(pmsg->len))
{
return -(RT_ERROR);
tMsg.DLC = pmsg->len;
}
else
{
goto exit_nu_can_sendmsg;
}
if (pmsg->data && pmsg->len)
{
rt_memcpy(&tMsg.Data[0], pmsg->data, pmsg->len);
}
else
{
goto exit_nu_can_sendmsg;
}
/* Configure Msg RAM and send the Msg in the RAM. */
if (CAN_Transmit(psNuCAN->base, MSG(boxno), &tMsg) == FALSE)
{
goto exit_nu_can_sendmsg;
}
return RT_EOK;
exit_nu_can_sendmsg:
return -(RT_ERROR);
}
static int nu_can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t boxno)
{
STR_CANMSG_T tMsg;
struct rt_can_msg *pmsg = (struct rt_can_msg *) buf;
/* Get base address of CAN register */
CAN_T *base = ((nu_can_t)can)->base;
struct rt_can_msg *pmsg;
nu_can_t psNuCAN = (nu_can_t)can;
RT_ASSERT(can);
RT_ASSERT(buf);
RT_ASSERT(base != RT_NULL);
RT_ASSERT(buf != RT_NULL);
pmsg = (struct rt_can_msg *) buf;
/* get data */
if (CAN_Receive(base, boxno, &tMsg) == FALSE)
if (CAN_Receive(psNuCAN->base, boxno, &tMsg) == FALSE)
{
rt_kprintf("No available RX Msg.\n");
return -(RT_ERROR);
......@@ -504,32 +535,13 @@ static int nu_can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t boxn
can->hdr[pmsg->hdr].connected = 1;
#endif
/* Standard ID (11 bits)*/
if (tMsg.IdType == CAN_STD_ID)
{
pmsg->ide = RT_CAN_STDID;
pmsg->id = tMsg.Id;
}
else /* Extended ID (29 bits)*/
{
pmsg->ide = RT_CAN_EXTID;
pmsg->id = tMsg.Id;
}
if (tMsg.FrameType == CAN_DATA_FRAME)
{
/* Data frame */
pmsg->rtr = RT_CAN_DTR;
}
else
{
/* Remote frame */
pmsg->rtr = RT_CAN_RTR;
}
pmsg->ide = (tMsg.IdType == CAN_STD_ID) ? RT_CAN_STDID : RT_CAN_EXTID;
pmsg->rtr = (tMsg.FrameType == CAN_DATA_FRAME) ? RT_CAN_DTR : RT_CAN_RTR;
pmsg->id = tMsg.Id;
pmsg->len = tMsg.DLC ;
rt_memcpy(pmsg->data, tMsg.Data, pmsg->len);
if (pmsg->data && pmsg->len)
rt_memcpy(pmsg->data, &tMsg.Data[0], pmsg->len);
return RT_EOK;
}
......@@ -564,5 +576,4 @@ static int rt_hw_can_init(void)
return (int)ret;
}
INIT_DEVICE_EXPORT(rt_hw_can_init);
#endif //#if defined(BSP_USING_CAN)
......@@ -682,7 +682,7 @@ lwiperf_report(void *arg, enum lwiperf_report_type report_type,
(int)report_type, ipaddr_ntoa(remote_addr), (int)remote_port, bytes_transferred, ms_duration, bandwidth_kbitpsec);
}
void lwiperf_example_init(void)
void lwiperf_example_init(int argc, char **argv)
{
lwiperf_start_tcp_server_default(lwiperf_report, NULL);
}
......
......@@ -118,7 +118,7 @@ static rt_err_t nu_i2c_bus_control(struct rt_i2c_bus_device *bus, rt_uint32_t u3
RT_ASSERT(bus != RT_NULL);
nu_i2c = (nu_i2c_bus_t *) bus;
switch (RT_I2C_DEV_CTRL_CLK)
switch (u32Cmd)
{
case RT_I2C_DEV_CTRL_CLK:
I2C_SetBusClockFreq(nu_i2c->I2C, u32Value);
......
此差异已折叠。
......@@ -18,12 +18,6 @@ config PKGS_DIR
option env="PKGS_ROOT"
default "packages"
config NU_PKGS_DIR
string
option env="NU_PKGS_ROOT"
default "../libraries/nu_packages"
source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
source "$NU_PKGS_DIR/Kconfig"
source "$BSP_DIR/board/Kconfig"
......@@ -72,6 +72,7 @@ menu "Hardware Drivers Config"
config BOARD_USING_LCD_ILI9341
bool "LCD ILI9341 (over spi0)"
select RT_USING_TOUCH
select BSP_USING_ADC_TOUCH
select NU_PKG_USING_ILI9341
select NU_PKG_USING_ILI9341_SPI
select NU_PKG_ILI9341_WITH_OFFSCREEN_FRAMEBUFFER
......@@ -113,5 +114,6 @@ menu "Hardware Drivers Config"
endmenu
source "$BSP_DIR/../libraries/nu_packages/Kconfig"
endmenu
......@@ -57,8 +57,10 @@ static void nu_pin_i2c_init(void)
/* I2C0: PA[0, 1] */
outpw(REG_SYS_GPA_MFPL, (inpw(REG_SYS_GPA_MFPL) & ~0x000000FF) | 0x00000033);
#if !defined(BSP_USING_ADC_TOUCH)
/* I2C2: PB5, PB7 */
outpw(REG_SYS_GPB_MFPL, (inpw(REG_SYS_GPB_MFPL) & ~0xF0F00000) | 0x20200000);
#endif
}
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -85,4 +85,10 @@ elif PLATFORM == 'armcc':
CFLAGS += ' -O2'
POST_ACTION = 'fromelf --bin $TARGET --output ' + TARGET_NAME + ' \n'
POST_ACTION += 'fromelf -z $TARGET\n'
\ No newline at end of file
POST_ACTION += 'fromelf -z $TARGET\n'
def dist_handle(BSP_ROOT, dist_dir):
import sys
cwd_path = os.getcwd()
sys.path.append(os.path.join(os.path.dirname(BSP_ROOT), 'tools'))
from sdk_dist import dist_do_building
dist_do_building(BSP_ROOT, dist_dir)
此差异已折叠。
此差异已折叠。
......@@ -18,12 +18,6 @@ config PKGS_DIR
option env="PKGS_ROOT"
default "packages"
config NU_PKGS_DIR
string
option env="NU_PKGS_ROOT"
default "../libraries/nu_packages"
source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
source "$NU_PKGS_DIR/Kconfig"
source "$BSP_DIR/board/Kconfig"
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -974,3 +974,5 @@ CONFIG_BOARD_USING_USB0_DEVICE_HOST=y
# Board extended module drivers
#
CONFIG_BOARD_USING_IP101GR=y
CONFIG_BOARD_USE_UTEST=y
CONFIG_UTEST_CMD_PREFIX="bsp.nuvoton.nk-rtu980.test.utest."
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册