Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
fe97465d4c |
|
|
@ -50,63 +50,116 @@ void TestTouch(void)
|
|||
|
||||
#elif defined ADD_XIZI_FETURES
|
||||
|
||||
int lcd_fd, touch_fd, pin_fd;
|
||||
|
||||
void DrawTouchPoint(struct TouchDataStandard *touch_pixel){
|
||||
// draw text
|
||||
uint16 color_select[LCD_SIZE];
|
||||
memset(color_select,0xff,sizeof(color_select));
|
||||
|
||||
LcdWriteParam graph_param;
|
||||
graph_param.type = LCD_DOT_TYPE;
|
||||
graph_param.pixel_info.pixel_color = &color_select;
|
||||
|
||||
printf("touch pixel position x:%d,y:%d\n",touch_pixel->x,touch_pixel->y);
|
||||
graph_param.pixel_info.x_startpos = touch_pixel->x-10>0?touch_pixel->x-10:0;
|
||||
graph_param.pixel_info.y_startpos = touch_pixel->y;
|
||||
graph_param.pixel_info.x_endpos = touch_pixel->x+10;
|
||||
graph_param.pixel_info.y_endpos = touch_pixel->y;
|
||||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
|
||||
graph_param.pixel_info.x_startpos = touch_pixel->x;
|
||||
graph_param.pixel_info.y_startpos = touch_pixel->y-10>0?touch_pixel->y-10:0;
|
||||
graph_param.pixel_info.x_endpos = touch_pixel->x;
|
||||
graph_param.pixel_info.y_endpos = touch_pixel->y+10;
|
||||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
|
||||
}
|
||||
|
||||
void ReadTouchData(void* pram){
|
||||
// printf("in touch int");
|
||||
struct TouchDataStandard *touch_data;
|
||||
memset(touch_data, 0, sizeof(touch_data));
|
||||
touch_data = malloc(sizeof(struct TouchDataStandard));
|
||||
if(0 > PrivRead(touch_fd, touch_data, NULL_PARAMETER)){
|
||||
printf("read touch error\n");
|
||||
return;
|
||||
}
|
||||
if(touch_data->x && touch_data->y)
|
||||
DrawTouchPoint(touch_data);
|
||||
free(touch_data);
|
||||
}
|
||||
|
||||
void TestTouch(void)
|
||||
{
|
||||
int touch_fd = PrivOpen(TOUCH_DEV_DRIVER, O_RDWR);
|
||||
touch_fd = PrivOpen(TOUCH_DEV_DRIVER, O_RDWR);
|
||||
if (touch_fd < 0)
|
||||
{
|
||||
printf("open touch fd error:%d\n", touch_fd);
|
||||
return;
|
||||
}
|
||||
int lcd_fd = PrivOpen(TOUCH_LCD_DEV_DRIVER, O_RDWR);
|
||||
lcd_fd = PrivOpen(TOUCH_LCD_DEV_DRIVER, O_RDWR);
|
||||
if (lcd_fd < 0)
|
||||
{
|
||||
printf("open lcd fd error:%d\n", lcd_fd);
|
||||
return;
|
||||
}
|
||||
pin_fd = PrivOpen(GPIO_DEV_DRIVER, O_RDWR);
|
||||
if(pin_fd < 0) {
|
||||
printf("open pin fd error:%d\n",pin_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
// //config touch int pin in board
|
||||
// struct PinParam parameter;
|
||||
// parameter.cmd = GPIO_CONFIG_MODE;
|
||||
// parameter.pin = BSP_TOUCH_TP_INT;
|
||||
// parameter.mode = GPIO_CFG_INPUT;
|
||||
// struct PrivIoctlCfg ioctl_cfg;
|
||||
// ioctl_cfg.ioctl_driver_type = PIN_TYPE;
|
||||
// ioctl_cfg.args = (void *)¶meter;
|
||||
// if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) {
|
||||
// printf("ioctl config touch int pin error %d\n", pin_fd);
|
||||
// PrivClose(pin_fd);
|
||||
// return;
|
||||
// }
|
||||
// // register touch irq
|
||||
// parameter.cmd = GPIO_IRQ_REGISTER;
|
||||
// parameter.pin = BSP_TOUCH_TP_INT;
|
||||
// parameter.irq_set.irq_mode = GPIO_IRQ_EDGE_FALLING;
|
||||
// parameter.irq_set.hdr = ReadTouchData;
|
||||
// parameter.irq_set.args = NULL;
|
||||
// if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) {
|
||||
// printf("ioctl pin register touch irq error %d\n", pin_fd);
|
||||
// PrivClose(pin_fd);
|
||||
// return;
|
||||
// }
|
||||
// //enable irq
|
||||
// parameter.cmd = GPIO_IRQ_ENABLE;
|
||||
// parameter.pin = BSP_TOUCH_TP_INT;
|
||||
// if (0 != PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg)) {
|
||||
// printf("ioctl pin enable irq error %d\n", pin_fd);
|
||||
// PrivClose(pin_fd);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// draw text
|
||||
struct TouchDataStandard touch_pixel;
|
||||
memset(&touch_pixel,0,sizeof(touch_pixel));
|
||||
LcdWriteParam graph_param;
|
||||
|
||||
|
||||
graph_param.type = LCD_DOT_TYPE;
|
||||
|
||||
uint16_t back_color[LCD_SIZE];
|
||||
|
||||
graph_param.type = LCD_DOT_TYPE;
|
||||
memset(back_color,0x00,sizeof(back_color));
|
||||
for (int i = 0; i < LCD_SIZE; i++)
|
||||
{
|
||||
for (int i = 0; i < LCD_SIZE; i++){
|
||||
graph_param.pixel_info.pixel_color = &back_color;
|
||||
graph_param.pixel_info.x_startpos = 0;
|
||||
graph_param.pixel_info.y_startpos = i;
|
||||
graph_param.pixel_info.x_endpos = LCD_SIZE -1;
|
||||
graph_param.pixel_info.x_endpos = LCD_SIZE - 1;
|
||||
graph_param.pixel_info.y_endpos = i;
|
||||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
|
||||
}
|
||||
|
||||
uint16 color_select[LCD_SIZE];
|
||||
memset(color_select,0xff,sizeof(color_select));
|
||||
graph_param.pixel_info.pixel_color = &color_select;
|
||||
while(1){
|
||||
if(0 > PrivRead(touch_fd, &touch_pixel, NULL_PARAMETER)){
|
||||
printf("read touch error\n");
|
||||
return;
|
||||
}
|
||||
printf("touch pixel position x:%d,y:%d\n",touch_pixel.x,touch_pixel.y);
|
||||
graph_param.pixel_info.x_startpos = touch_pixel.x-10>0?touch_pixel.x-10:0;
|
||||
graph_param.pixel_info.y_startpos = touch_pixel.y;
|
||||
graph_param.pixel_info.x_endpos = touch_pixel.x+10;
|
||||
graph_param.pixel_info.y_endpos = touch_pixel.y;
|
||||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
|
||||
graph_param.pixel_info.x_startpos = touch_pixel.x;
|
||||
graph_param.pixel_info.y_startpos = touch_pixel.y-10>0?touch_pixel.y-10:0;
|
||||
graph_param.pixel_info.x_endpos = touch_pixel.x;
|
||||
graph_param.pixel_info.y_endpos = touch_pixel.y+10;
|
||||
PrivWrite(lcd_fd, &graph_param, NULL_PARAMETER);
|
||||
MdelayKTask(100);
|
||||
ReadTouchData(NULL);
|
||||
}
|
||||
|
||||
PrivClose(lcd_fd);
|
||||
PrivClose(touch_fd);
|
||||
}
|
||||
|
||||
PRIV_SHELL_CMD_FUNCTION(TestTouch, a touch test sample, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
|
|
|||
|
|
@ -64,6 +64,16 @@ extern "C" {
|
|||
#define GPIO_CFG_OUTPUT_OD 0x04
|
||||
|
||||
#define GPIO_CONFIG_MODE 0xffffffff
|
||||
#define GPIO_IRQ_REGISTER 0xfffffffe
|
||||
#define GPIO_IRQ_FREE 0xfffffffd
|
||||
#define GPIO_IRQ_DISABLE 0xfffffffc
|
||||
#define GPIO_IRQ_ENABLE 0xfffffffb
|
||||
|
||||
#define GPIO_IRQ_EDGE_RISING 0x00
|
||||
#define GPIO_IRQ_EDGE_FALLING 0x01
|
||||
#define GPIO_IRQ_EDGE_BOTH 0x02
|
||||
#define GPIO_IRQ_LEVEL_HIGH 0x03
|
||||
#define GPIO_IRQ_LEVEL_LOW 0x04
|
||||
|
||||
/********************SERIAL define*******************/
|
||||
#define BAUD_RATE_2400 2400
|
||||
|
|
|
|||
|
|
@ -198,21 +198,29 @@ static void I2cStop(struct I2cHalDrvDone *done)
|
|||
I2cDelay2(done);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2cWaitack
|
||||
* @param done
|
||||
* @retval 1:ack
|
||||
* @retval 0:nack
|
||||
* @retval -2:timeout
|
||||
*/
|
||||
static __inline x_bool I2cWaitack(struct I2cHalDrvDone *done)
|
||||
{
|
||||
x_bool ack;
|
||||
done->delay_us = 20u;
|
||||
|
||||
SdaHigh(done);
|
||||
GET_SDA(done);
|
||||
GET_SDA(done);
|
||||
I2cDelay(done);
|
||||
done->delay_us = 1u;
|
||||
|
||||
if (SclHigh(done) < 0) {
|
||||
KPrintf("wait ack timeout");
|
||||
KPrintf("scl high timeout");
|
||||
return -ETIMEOUT;
|
||||
}
|
||||
|
||||
ack = !GET_SDA(done);
|
||||
|
||||
SclLow(done);
|
||||
|
||||
return ack;
|
||||
|
|
@ -275,7 +283,7 @@ static int32 I2cReadb(struct I2cBus *bus)
|
|||
static x_size_t I2cSendBytes(struct I2cBus *bus, struct I2cDataStandard *msg)
|
||||
{
|
||||
int32 ret;
|
||||
x_size_t bytes = 0;
|
||||
x_size_t bytes_sent = 0;
|
||||
const uint8 *ptr = msg->buf;
|
||||
int32 count = msg->len;
|
||||
uint16 ignore_nack = msg->flags & I2C_IGNORE_NACK;
|
||||
|
|
@ -283,20 +291,20 @@ static x_size_t I2cSendBytes(struct I2cBus *bus, struct I2cDataStandard *msg)
|
|||
while (count > 0) {
|
||||
ret = I2cWriteb(bus, *ptr);
|
||||
|
||||
if ((ret > 0) || (ignore_nack && (ret == 0))) {
|
||||
count --;
|
||||
ptr ++;
|
||||
bytes ++;
|
||||
if ((ret == 1) || (ignore_nack && (ret == 0))) {
|
||||
count--;
|
||||
ptr++;
|
||||
bytes_sent++;
|
||||
} else if (ret == 0) {
|
||||
KPrintf("Sent Byte%d but No ACK\n", bytes_sent + 1);
|
||||
return 0;
|
||||
} else {
|
||||
KPrintf("send bytes: error %d", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
return bytes_sent;
|
||||
}
|
||||
|
||||
static x_err_t I2cSendAckOrNack(struct I2cBus *bus, int ack)
|
||||
|
|
@ -308,7 +316,6 @@ static x_err_t I2cSendAckOrNack(struct I2cBus *bus, int ack)
|
|||
I2cDelay(done);
|
||||
if (SclHigh(done) < 0) {
|
||||
KPrintf("ACK or NACK timeout.");
|
||||
|
||||
return -ETIMEOUT;
|
||||
}
|
||||
SclLow(done);
|
||||
|
|
@ -319,7 +326,7 @@ static x_err_t I2cSendAckOrNack(struct I2cBus *bus, int ack)
|
|||
static x_size_t I2cRecvBytes(struct I2cBus *bus, struct I2cDataStandard *msg)
|
||||
{
|
||||
int32 val;
|
||||
int32 bytes = 0;
|
||||
int32 bytes_recv = 0;
|
||||
uint8 *ptr = msg->buf;
|
||||
int32 count = msg->len;
|
||||
const uint32 flags = msg->flags;
|
||||
|
|
@ -328,7 +335,7 @@ static x_size_t I2cRecvBytes(struct I2cBus *bus, struct I2cDataStandard *msg)
|
|||
val = I2cReadb(bus);
|
||||
if (val >= 0) {
|
||||
*ptr = val;
|
||||
bytes ++;
|
||||
bytes_recv ++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
|
@ -343,7 +350,7 @@ static x_size_t I2cRecvBytes(struct I2cBus *bus, struct I2cDataStandard *msg)
|
|||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
return bytes_recv;
|
||||
}
|
||||
|
||||
static int32 I2cSendAddress(struct I2cBus *bus, uint8 addr, int32 retries)
|
||||
|
|
@ -353,17 +360,31 @@ static int32 I2cSendAddress(struct I2cBus *bus, uint8 addr, int32 retries)
|
|||
x_err_t ret = 0;
|
||||
|
||||
for (i = 0; i <= retries; i++) {
|
||||
if(i) printf("Retry%d ",i);
|
||||
ret = I2cWriteb(bus, addr);
|
||||
if (ret == 1 || i == retries)
|
||||
if (ret != 1)
|
||||
printf("\nI2cSendAddress ret:%d ", ret);
|
||||
if (ret == 1 || i == retries){
|
||||
if(ret == 1 && i > 0) printf("OK\n");
|
||||
if(ret != 1) printf("ERR\n");
|
||||
break;
|
||||
}
|
||||
I2cStop(done);
|
||||
I2cDelay2(done);
|
||||
MdelayKTask(100);
|
||||
I2cStart(done);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param bus
|
||||
* @param msg
|
||||
* @retval 0:EOK
|
||||
* @retval -8:ERR
|
||||
*/
|
||||
static x_err_t I2cBitSendAddress(struct I2cBus *bus, struct I2cDataStandard *msg)
|
||||
{
|
||||
uint16 flags = msg->flags;
|
||||
|
|
@ -422,13 +443,10 @@ static uint32 I2cWriteData(struct I2cHardwareDevice *i2c_dev, struct I2cDataStan
|
|||
int32 i = 0;
|
||||
uint16 ignore_nack;
|
||||
|
||||
I2cStart(done);
|
||||
while (NONE != msg) {
|
||||
ignore_nack = msg->flags & I2C_IGNORE_NACK;
|
||||
if (!(msg->flags & I2C_NO_START)) {
|
||||
if (i) {
|
||||
I2cRestart(done);
|
||||
}
|
||||
I2cRestart(done);
|
||||
ret = I2cBitSendAddress(bus, msg);
|
||||
if ((ret != EOK) && !ignore_nack) {
|
||||
goto out;
|
||||
|
|
@ -437,8 +455,6 @@ static uint32 I2cWriteData(struct I2cHardwareDevice *i2c_dev, struct I2cDataStan
|
|||
|
||||
if (msg->flags == I2C_WR) {
|
||||
ret = I2cSendBytes(bus, msg);
|
||||
if (ret >= 1)
|
||||
//KPrintf("write %d byte%s", ret, ret == 1 ? "" : "s");
|
||||
if (ret < msg->len) {
|
||||
if (ret >= 0)
|
||||
ret = -ERROR;
|
||||
|
|
@ -481,8 +497,6 @@ static uint32 I2cReadData(struct I2cHardwareDevice *i2c_dev, struct I2cDataStand
|
|||
|
||||
if (msg->flags & I2C_RD) {
|
||||
ret = I2cRecvBytes(bus, msg);
|
||||
if (ret >= 1)
|
||||
//KPrintf("read %d byte%s", ret, ret == 1 ? "" : "s");
|
||||
if (ret < msg->len) {
|
||||
if (ret >= 0)
|
||||
ret = -EPIO;
|
||||
|
|
@ -599,7 +613,7 @@ static int BoardI2cDevBend(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*KD233 BOARD I2C INIT*/
|
||||
/*K210 BOARD I2C INIT*/
|
||||
int HwI2cInit(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* Copyright (c) 2020 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-04-25 weety first version
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file connect_i2c.c
|
||||
* @brief support kd233-board i2c function and register to bus framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-10-17
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: connect_i2c.c
|
||||
Description: support edu-riscv64-board i2c configure and i2c bus register function
|
||||
Others: take RT-Thread v4.0.2/components/drivers/i2c/i2c-bit-ops.c for references
|
||||
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
|
||||
History:
|
||||
1. Date: 2022-10-17
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. support edu-riscv64-board i2c bit configure, write and read
|
||||
2. support edu-riscv64-board i2c bus device and driver register
|
||||
*************************************************/
|
||||
|
||||
#include <board.h>
|
||||
#include "gpio_common.h"
|
||||
#include"fpioa.h"
|
||||
#include "connect_i2c.h"
|
||||
#include "hardware_i2c.h"
|
||||
#include <sleep.h>
|
||||
#include "sysctl.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#ifndef BSP_USING_I2C1
|
||||
#define BSP_USING_I2C1
|
||||
#endif
|
||||
|
||||
void I2cGpioInit()
|
||||
{
|
||||
gpio_init ();
|
||||
FpioaSetFunction(BSP_I2C_SDA , FUNC_I2C1_SDA );
|
||||
FpioaSetFunction(BSP_I2C_SCL , FUNC_I2C1_SCLK );
|
||||
}
|
||||
|
||||
static uint32 I2cWriteData(struct I2cHardwareDevice *i2c_dev, struct I2cDataStandard *msg)
|
||||
{
|
||||
int retry = 5, res = 0;
|
||||
do{
|
||||
res = i2c_send_data(I2C_DEVICE_1, msg->buf, msg->len);
|
||||
retry--;
|
||||
if (res) MdelayKTask(10);
|
||||
}while(res != 0 && retry > 0);
|
||||
if (res != 0)
|
||||
printf("I2cWriteData res:0x%016x\n", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
static uint32 I2cReadData(struct I2cHardwareDevice *i2c_dev, struct I2cDataStandard *msg)
|
||||
{
|
||||
uint8 reg = 0x80;
|
||||
int res = i2c_recv_data(I2C_DEVICE_1, NULL, 0, msg->buf, msg->len);
|
||||
if (res != 0)
|
||||
printf("I2cReadData res0x:%016x\n", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info)
|
||||
{
|
||||
NULL_PARAM_CHECK(drv);
|
||||
NULL_PARAM_CHECK(configure_info);
|
||||
|
||||
x_err_t ret = EOK;
|
||||
struct I2cDriver *i2c_drv = (struct I2cDriver *)drv;
|
||||
|
||||
switch (configure_info->configure_cmd)
|
||||
{
|
||||
case OPE_INT:
|
||||
i2c_init(I2C_DEVICE_1, (uint32_t)(*((uint16*)configure_info->private_data)), 7, 10000);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*manage the i2c device operations*/
|
||||
static const struct I2cDevDone i2c_dev_done =
|
||||
{
|
||||
.dev_open = NONE,
|
||||
.dev_close = NONE,
|
||||
.dev_write = I2cWriteData,
|
||||
.dev_read = I2cReadData,
|
||||
};
|
||||
|
||||
/*Init i2c bus*/
|
||||
static int BoardI2cBusInit(struct I2cBus *i2c_bus, struct I2cDriver *i2c_driver)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
|
||||
/*Init the i2c bus */
|
||||
i2c_bus->private_data = NULL;
|
||||
ret = I2cBusInit(i2c_bus, I2C_BUS_NAME_1);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_init I2cBusInit error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/*Init the i2c driver*/
|
||||
i2c_driver->private_data = NULL;
|
||||
ret = I2cDriverInit(i2c_driver, I2C_DRV_NAME_1);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_init I2cDriverInit error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/*Attach the i2c driver to the i2c bus*/
|
||||
ret = I2cDriverAttachToBus(I2C_DRV_NAME_1, I2C_BUS_NAME_1);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_init I2cDriverAttachToBus error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*Attach the i2c device to the i2c bus*/
|
||||
static int BoardI2cDevBend(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
static struct I2cHardwareDevice i2c_device0;
|
||||
memset(&i2c_device0, 0, sizeof(struct I2cHardwareDevice));
|
||||
|
||||
i2c_device0.i2c_dev_done = &i2c_dev_done;
|
||||
|
||||
ret = I2cDeviceRegister(&i2c_device0, NONE, I2C_1_DEVICE_NAME_0);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_init I2cDeviceInit device %s error %d\n", I2C_1_DEVICE_NAME_0, ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = I2cDeviceAttachToBus(I2C_1_DEVICE_NAME_0, I2C_BUS_NAME_1);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_init I2cDeviceAttachToBus device %s error %d\n", I2C_1_DEVICE_NAME_0, ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*K210 BOARD I2C INIT*/
|
||||
int HwI2cInit(void)
|
||||
{
|
||||
x_err_t ret = EOK;
|
||||
static struct I2cBus i2c_bus;
|
||||
memset(&i2c_bus, 0, sizeof(struct I2cBus));
|
||||
|
||||
static struct I2cDriver i2c_driver;
|
||||
memset(&i2c_driver, 0, sizeof(struct I2cDriver));
|
||||
|
||||
#ifdef BSP_USING_I2C1
|
||||
I2cGpioInit();
|
||||
i2c_driver.configure = I2cDrvConfigure;
|
||||
|
||||
ret = BoardI2cBusInit(&i2c_bus, &i2c_driver);
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_Init error ret %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = BoardI2cDevBend();
|
||||
if (EOK != ret) {
|
||||
KPrintf("board_i2c_Init error ret %u\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -157,17 +157,14 @@ int i2c_send_data(i2c_device_number_t i2c_num, const uint8_t *SendBuf, size_t se
|
|||
{
|
||||
fifo_len = 8 - i2c_adapter->txflr;
|
||||
fifo_len = send_buf_len < fifo_len ? send_buf_len : fifo_len;
|
||||
for (index = 0; index < fifo_len; index++)
|
||||
for (index = 0; index < fifo_len; index++){
|
||||
i2c_adapter->data_cmd = I2C_DATA_CMD_DATA(*SendBuf++);
|
||||
if (i2c_adapter->tx_abrt_source != 0)
|
||||
return 1;
|
||||
|
||||
if (i2c_adapter->tx_abrt_source & 0xffff != 0)
|
||||
return i2c_adapter->tx_abrt_source;
|
||||
}
|
||||
send_buf_len -= fifo_len;
|
||||
}
|
||||
while ((i2c_adapter->status & I2C_STATUS_ACTIVITY) || !(i2c_adapter->status & I2C_STATUS_TFE))
|
||||
;
|
||||
|
||||
if (i2c_adapter->tx_abrt_source != 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include <gpiohs.h>
|
||||
#include <fpioa.h>
|
||||
#include "gsl2038firmware.h"
|
||||
#include "gpio.h"
|
||||
|
||||
|
||||
struct Finger {
|
||||
|
|
@ -75,15 +76,15 @@ static x_err_t ReadRegs(struct HardwareDev* dev, uint8 len, uint8* buf)
|
|||
}
|
||||
|
||||
// not used in polling mode
|
||||
static void touch_pin_irqhandler(void* arg)
|
||||
{
|
||||
//KPrintf("int hdr working.\n");
|
||||
if (!SemReleaseFlag)
|
||||
{
|
||||
KSemaphoreAbandon(touch_sem);
|
||||
SemReleaseFlag = true;
|
||||
}
|
||||
}
|
||||
// static void touch_pin_irqhandler(void* arg)
|
||||
// {
|
||||
// //KPrintf("int hdr working.\n");
|
||||
// if (!SemReleaseFlag)
|
||||
// {
|
||||
// KSemaphoreAbandon(touch_sem);
|
||||
// SemReleaseFlag = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
int32_t touch_irq_init()
|
||||
{
|
||||
|
|
@ -105,33 +106,33 @@ int32_t touch_irq_init()
|
|||
return -ERROR;
|
||||
}
|
||||
|
||||
pin_param.cmd = GPIO_IRQ_REGISTER;
|
||||
pin_param.pin = BSP_TOUCH_TP_INT;
|
||||
pin_param.irq_set.irq_mode = GPIO_IRQ_EDGE_BOTH;
|
||||
pin_param.irq_set.hdr = touch_pin_irqhandler;
|
||||
pin_param.irq_set.args = NONE;
|
||||
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||
if (ret != EOK) {
|
||||
KPrintf("register pin_param %d irq failed!\n", pin_param.pin);
|
||||
return -ERROR;
|
||||
}
|
||||
// pin_param.cmd = GPIO_IRQ_REGISTER;
|
||||
// pin_param.pin = BSP_TOUCH_TP_INT;
|
||||
// pin_param.irq_set.irq_mode = GPIO_IRQ_EDGE_BOTH;
|
||||
// pin_param.irq_set.hdr = touch_pin_irqhandler;
|
||||
// pin_param.irq_set.args = NONE;
|
||||
// ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||
// if (ret != EOK) {
|
||||
// KPrintf("register pin_param %d irq failed!\n", pin_param.pin);
|
||||
// return -ERROR;
|
||||
// }
|
||||
|
||||
pin_param.cmd = GPIO_IRQ_DISABLE;
|
||||
pin_param.pin = BSP_TOUCH_TP_INT;
|
||||
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||
if (ret != EOK) {
|
||||
KPrintf("disable pin_param %d irq failed!\n", pin_param.pin);
|
||||
return -ERROR;
|
||||
}
|
||||
// pin_param.cmd = GPIO_IRQ_DISABLE;
|
||||
// pin_param.pin = BSP_TOUCH_TP_INT;
|
||||
// ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||
// if (ret != EOK) {
|
||||
// KPrintf("disable pin_param %d irq failed!\n", pin_param.pin);
|
||||
// return -ERROR;
|
||||
// }
|
||||
|
||||
// 4. enable interuption
|
||||
pin_param.cmd = GPIO_IRQ_ENABLE;
|
||||
pin_param.pin = BSP_TOUCH_TP_INT;
|
||||
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||
if (ret != EOK) {
|
||||
KPrintf("enable pin_param %d irq failed!\n", pin_param.pin);
|
||||
return -ERROR;
|
||||
}
|
||||
// // 4. enable interuption
|
||||
// pin_param.cmd = GPIO_IRQ_ENABLE;
|
||||
// pin_param.pin = BSP_TOUCH_TP_INT;
|
||||
// ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||
// if (ret != EOK) {
|
||||
// KPrintf("enable pin_param %d irq failed!\n", pin_param.pin);
|
||||
// return -ERROR;
|
||||
// }
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
|
@ -164,33 +165,40 @@ int32_t I2cTouchInit() {
|
|||
}
|
||||
struct BusConfigureInfo i2c_configure_info;
|
||||
|
||||
// memset(&i2c_configure_info, 0, sizeof(struct BusConfigureInfo));
|
||||
i2c_configure_info.configure_cmd = OPE_INT;
|
||||
uint16 i2c_address = TOUCH_ADDRESS;
|
||||
i2c_configure_info.private_data = (void*)&i2c_address;
|
||||
BusDrvConfigure(i2c_bus->owner_driver, &i2c_configure_info);
|
||||
|
||||
// 3. init interruption
|
||||
return touch_irq_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void loadfw(struct HardwareDev *dev)
|
||||
{
|
||||
uint8_t addr;
|
||||
uint8_t addr[2] = {0xf0,0x00};
|
||||
uint8_t Wrbuf[5];
|
||||
size_t source_len = sizeof(GSL2038_FW) / sizeof(struct fw_data);
|
||||
|
||||
printf("Loading Touch Firmware");
|
||||
for (size_t source_line = 0; source_line < source_len; source_line++) {
|
||||
// addr = GSL2038_FW[source_line].offset;
|
||||
memset(Wrbuf, 0 , 5);
|
||||
Wrbuf[0] = GSL2038_FW[source_line].offset;
|
||||
Wrbuf[1] = (char)(GSL2038_FW[source_line].val & 0x000000ff);
|
||||
Wrbuf[2] = (char)((GSL2038_FW[source_line].val & 0x0000ff00) >> 8);
|
||||
Wrbuf[3] = (char)((GSL2038_FW[source_line].val & 0x00ff0000) >> 16);
|
||||
Wrbuf[4] = (char)((GSL2038_FW[source_line].val & 0xff000000) >> 24);
|
||||
|
||||
WriteReg(dev, Wrbuf,5);
|
||||
if(GSL2038_FW[source_line].offset == 0xf0){
|
||||
addr[1] = GSL2038_FW[source_line].val;
|
||||
WriteReg(dev, addr, 2);
|
||||
printf("\n0x%02x", addr[1]);
|
||||
}else {
|
||||
memset(Wrbuf, 0 , 5);
|
||||
Wrbuf[0] = GSL2038_FW[source_line].offset;
|
||||
Wrbuf[1] = (char)(GSL2038_FW[source_line].val & 0x000000ff);
|
||||
Wrbuf[2] = (char)((GSL2038_FW[source_line].val & 0x0000ff00) >> 8);
|
||||
Wrbuf[3] = (char)((GSL2038_FW[source_line].val & 0x00ff0000) >> 16);
|
||||
Wrbuf[4] = (char)((GSL2038_FW[source_line].val & 0xff000000) >> 24);
|
||||
WriteReg(dev, Wrbuf, 5);
|
||||
}
|
||||
MdelayKTask(1);
|
||||
printf(".");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void reset()
|
||||
|
|
@ -199,16 +207,17 @@ void reset()
|
|||
uint8_t DATA[6] = {0x88, 0x04, 0x00, 0x00, 0x00, 0x00};
|
||||
char reg_data[2];
|
||||
|
||||
printf("touch reset");
|
||||
int i;
|
||||
for (i = 0; i < sizeof(REG); ++i)
|
||||
{
|
||||
// WriteReg(i2c_bus->owner_haldev, ®[i],1);
|
||||
// WriteReg(i2c_bus->owner_haldev, &DATA[i],1);
|
||||
reg_data[0] = REG[i];
|
||||
reg_data[1] = DATA[i];
|
||||
WriteReg(i2c_bus->owner_haldev, reg_data,2);
|
||||
MdelayKTask(10);
|
||||
printf(".");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void startchip()
|
||||
|
|
@ -216,6 +225,8 @@ void startchip()
|
|||
char reg_data[] = {0xE0, 0x00};
|
||||
|
||||
WriteReg(i2c_bus->owner_haldev, reg_data,2); // Registre
|
||||
|
||||
printf("touch startchip\n");
|
||||
}
|
||||
|
||||
static uint32 TouchOpen(void* dev)
|
||||
|
|
@ -223,10 +234,42 @@ static uint32 TouchOpen(void* dev)
|
|||
int32_t ret = 0;
|
||||
|
||||
I2cTouchInit();
|
||||
FpioaSetFunction(35, FUNC_GPIOHS5);
|
||||
FpioaSetFunction(BSP_TOUCH_TP_INT, FUNC_GPIOHS6);
|
||||
gpiohs_set_drive_mode(5, GPIO_DM_OUTPUT);
|
||||
gpiohs_set_drive_mode(6, GPIO_DM_OUTPUT);
|
||||
|
||||
gpiohs_set_pin(5 , GPIO_PV_HIGH);
|
||||
gpiohs_set_pin(6 , GPIO_PV_HIGH);
|
||||
|
||||
reset();
|
||||
reset();//reset();reset();reset();reset();reset();
|
||||
loadfw(i2c_bus->owner_haldev);
|
||||
reset();
|
||||
//startchip();
|
||||
//reset();
|
||||
|
||||
// 禁用芯片(将 IOCTNL 设置为 0)
|
||||
gpiohs_set_pin(5 , GPIO_PV_LOW);
|
||||
gpiohs_set_pin(6 , GPIO_PV_LOW);
|
||||
MdelayKTask(500);
|
||||
// 等待 50 毫秒
|
||||
// 启用芯片(将 IOCTNL 设置为 1)
|
||||
gpiohs_set_pin(5 , GPIO_PV_HIGH);
|
||||
gpiohs_set_pin(6 , GPIO_PV_HIGH);
|
||||
MdelayKTask(500);
|
||||
// 等待 30 毫秒
|
||||
// 禁用芯片(将 IOCTNL 设置为 0)
|
||||
gpiohs_set_pin(5 , GPIO_PV_LOW);
|
||||
gpiohs_set_pin(6 , GPIO_PV_LOW);
|
||||
MdelayKTask(500);
|
||||
// 等待 5 毫秒
|
||||
// 启用芯片(将 IOCTNL 设置为 1)
|
||||
gpiohs_set_pin(5 , GPIO_PV_HIGH);
|
||||
gpiohs_set_pin(6 , GPIO_PV_HIGH);
|
||||
MdelayKTask(500);
|
||||
// 等待 20 毫秒
|
||||
|
||||
MdelayKTask(100);
|
||||
//reset();
|
||||
startchip();
|
||||
|
||||
touch_sem = KSemaphoreCreate(0);
|
||||
|
|
@ -275,17 +318,20 @@ static uint32 TouchRead(void* dev, struct BusBlockReadParam* read_param)
|
|||
uint8_t TOUCHRECDATA[24] = {0};
|
||||
struct Touch_event ts_event;
|
||||
char status_reg = 0x80;
|
||||
|
||||
struct TouchDataStandard* data = (struct TouchDataStandard*)read_param->buffer;
|
||||
|
||||
result = KSemaphoreObtain(touch_sem, 100);
|
||||
// if (EOK == result)
|
||||
// {
|
||||
memset(TOUCHRECDATA, 0, 24);
|
||||
memset(TOUCHRECDATA, 0x00, 24);
|
||||
memset(&ts_event, 0, sizeof(struct Touch_event));
|
||||
|
||||
WriteReg(i2c_bus->owner_haldev, &status_reg, 1);
|
||||
ReadRegs(i2c_bus->owner_haldev, 24, TOUCHRECDATA);
|
||||
MdelayKTask(1);
|
||||
ret = ReadRegs(i2c_bus->owner_haldev, 24, TOUCHRECDATA);
|
||||
for(int i = 0; i < 24; i++)
|
||||
printf("%02x", TOUCHRECDATA[i]);
|
||||
printf("\n");
|
||||
ts_event.NBfingers = TOUCHRECDATA[0];
|
||||
|
||||
for (int i = 0; i < ts_event.NBfingers; i++)
|
||||
|
|
@ -296,15 +342,13 @@ static uint32 TouchRead(void* dev, struct BusBlockReadParam* read_param)
|
|||
ts_event.fingers[i].x = ts_event.fingers[i].y *LCD_SIZE/TOUCH_HEIGHT>6?ts_event.fingers[i].y *LCD_SIZE/TOUCH_HEIGHT-6:0;
|
||||
ts_event.fingers[i].y = pos_y;
|
||||
ts_event.fingers[i].fingerID = (uint32_t)TOUCHRECDATA[(i * 4) + 7] >> 4; // finger that did the touch
|
||||
// printf("fingers[%d] x %d y %d id %d\n",i,ts_event.fingers[i].x,ts_event.fingers[i].y,ts_event.fingers[i].fingerID);
|
||||
printf("fingers[%d] x %d y %d id %d\n",i,ts_event.fingers[i].x,ts_event.fingers[i].y,ts_event.fingers[i].fingerID);
|
||||
}
|
||||
|
||||
data->x = ts_event.fingers[ts_event.NBfingers - 1].x;
|
||||
data->y = ts_event.fingers[ts_event.NBfingers - 1].y;
|
||||
data->x = ts_event.fingers[0].x;
|
||||
data->y = ts_event.fingers[0].y;
|
||||
read_param->read_length = ts_event.NBfingers;
|
||||
SemReleaseFlag = 0;
|
||||
// }
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,14 +64,14 @@ static uint32 I2cDeviceRead(void *dev, struct BusBlockReadParam *read_param)
|
|||
struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)dev;
|
||||
struct I2cDataStandard i2c_msg_write, i2c_msg_read;
|
||||
|
||||
i2c_msg_write.addr = i2c_dev->i2c_dev_addr;
|
||||
i2c_msg_write.flags = I2C_WR;
|
||||
i2c_msg_write.buf = NONE;
|
||||
i2c_msg_write.len = 0;
|
||||
i2c_msg_write.retries = 10;
|
||||
i2c_msg_write.next = NONE;
|
||||
// i2c_msg_write.addr = i2c_dev->i2c_dev_addr;
|
||||
// i2c_msg_write.flags = I2C_WR;
|
||||
// i2c_msg_write.buf = NONE;
|
||||
// i2c_msg_write.len = 0;
|
||||
// i2c_msg_write.retries = 10;
|
||||
// i2c_msg_write.next = NONE;
|
||||
|
||||
i2c_dev->i2c_dev_done->dev_write(i2c_dev, &i2c_msg_write);
|
||||
// i2c_dev->i2c_dev_done->dev_write(i2c_dev, &i2c_msg_write);
|
||||
|
||||
i2c_msg_read.addr = i2c_dev->i2c_dev_addr;
|
||||
i2c_msg_read.flags = I2C_RD;
|
||||
|
|
|
|||
Loading…
Reference in New Issue