[bsp][ls1c] add uart3 driver; fix net driver for lwip2.1.0; fix drv_t ouch driver; fix display driver; fix can driver.

This commit is contained in:
sundm75 2019-04-26 21:00:20 +08:00
parent ba99d95d56
commit 7ae6627465
8 changed files with 442 additions and 490 deletions

View File

@ -30,6 +30,9 @@ config RT_USING_UART2
config RT_USING_UART1
bool "Using RT_USING_UART1"
default y
config RT_USING_UART3
bool "Using RT_USING_UART3"
default n
config RT_UART_RX_BUFFER_SIZE
int "The rx buffer size"

View File

@ -41,8 +41,12 @@ struct vga_struct vga_mode[] =
{/*"1440x900_67.00"*/ 120280, 1440, 1528, 1680, 1920, 900, 901, 904, 935, },
};
static volatile int fb_index = 0;
ALIGN(16)
volatile rt_uint16_t _rt_framebuffer[FB_YSIZE][FB_XSIZE];
volatile rt_uint16_t _rt_framebuffer0[FB_YSIZE][FB_XSIZE];
volatile rt_uint16_t _rt_framebuffer1[FB_YSIZE][FB_XSIZE];
static struct rt_device_graphic_info _dc_info;
static void pwminit(void)
@ -130,13 +134,11 @@ static rt_err_t rt_dc_init(rt_device_t dev)
if (mode<0)
{
rt_kprintf("\n\n\nunsupported framebuffer resolution\n\n\n");
return;
return RT_ERROR;
}
DC_FB_CONFIG = 0x0;
DC_FB_CONFIG = 0x3; // // framebuffer configuration RGB565
DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer - 0x80000000;
DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer - 0x80000000;
DC_DITHER_CONFIG = 0x0; //颜色抖动配置寄存器
DC_DITHER_TABLE_LOW = 0x0; //颜色抖动查找表低位寄存器
DC_DITHER_TABLE_HIGH = 0x0; //颜色抖动查找表高位寄存器
@ -175,7 +177,25 @@ static rt_err_t rt_dc_control(rt_device_t dev, int cmd, void *args)
switch (cmd)
{
case RTGRAPHIC_CTRL_RECT_UPDATE:
{
if (fb_index == 0)
{
DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer1 - 0x80000000;
DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer1 - 0x80000000;
rt_memcpy((void *)_rt_framebuffer1, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer));
rt_memcpy((void *)_rt_framebuffer1, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer));
fb_index =1;
}
else
{
DC_FB_BUFFER_ADDR0 = (rt_uint32_t)_rt_framebuffer0 - 0x80000000;
DC_FB_BUFFER_ADDR1 = (rt_uint32_t)_rt_framebuffer0 - 0x80000000;
rt_memcpy((void *)_rt_framebuffer0, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer));
rt_memcpy((void *)_rt_framebuffer0, (const void *)_rt_framebuffer, sizeof(_rt_framebuffer));
fb_index =0;
}
break;
}
case RTGRAPHIC_CTRL_POWERON:
break;
case RTGRAPHIC_CTRL_POWEROFF:
@ -200,7 +220,7 @@ void rt_hw_dc_init(void)
}
_dc_info.bits_per_pixel = 16;
_dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
_dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
_dc_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR;
_dc_info.width = FB_XSIZE;
_dc_info.height = FB_YSIZE;

View File

@ -229,10 +229,10 @@ static void bxcan0_hw_init(void)
#ifdef USING_BXCAN1
static void bxcan1_hw_init(void)
{
pin_set_purpose(56, PIN_PURPOSE_GPIO);
pin_set_purpose(57, PIN_PURPOSE_GPIO);
pin_set_remap(56, PIN_REMAP_DEFAULT);
pin_set_remap(57, PIN_REMAP_DEFAULT);
pin_set_purpose(56, PIN_PURPOSE_OTHER);
pin_set_purpose(57, PIN_PURPOSE_OTHER);
pin_set_remap(56, PIN_REMAP_THIRD);
pin_set_remap(57, PIN_REMAP_THIRD);
}
#endif

View File

@ -6,34 +6,41 @@
* Change Logs:
* Date Author Notes
* 2018-02-08 Zhangyihong the first version
* 2018-10-29 XY
* 2019-04-11 sundm75 modify for ls1c300 & RTGUI
*/
#include <rtthread.h>
#include <drivers/pin.h>
#include <rthw.h>
#include "drv_touch.h"
#define TOUCH_I2C_NAME "i2c1"
#ifndef TOUCH_SAMPLE_HZ
#define TOUCH_SAMPLE_HZ (50)
#endif
#ifndef TOUCH_I2C_NAME
#error "Please define touch i2c name!"
#endif
#ifdef TINA_USING_TOUCH
#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
#include <rtgui/event.h>
#include <rtgui/rtgui_server.h>
#endif
#define BSP_TOUCH_SAMPLE_HZ (50)
static rt_list_t driver_list;
extern void touch_down(void);
extern void touch_mo(void);
extern void touch_up(void);
#if 0
#define TPDEBUG rt_kprintf
#else
#define TPDEBUG(...)
#endif
void rt_touch_drivers_register(touch_drv_t drv)
{
rt_list_insert_before(&driver_list, &drv->list);
}
static rt_slist_t _driver_list;
static struct rt_i2c_bus_device *i2c_bus = RT_NULL;
static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_uint32_t id)
{
#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
rt_err_t result;
struct rtgui_event_mouse emouse;
emouse.parent.sender = RT_NULL;
@ -45,15 +52,28 @@ static void post_down_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
emouse.y = y;
#ifdef PKG_USING_GUIENGINE
emouse.ts = rt_tick_get();
emouse.id = ts;
emouse.id = id;
#endif
#ifdef PKG_USING_GUIENGINE
do
{
result = rtgui_server_post_event(&emouse.parent, sizeof(emouse));
if (result != RT_EOK)
{
rt_thread_delay(RT_TICK_PER_SECOND / TOUCH_SAMPLE_HZ);
}
}
while (result != RT_EOK);
#else
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
rt_kprintf("touch down x:%d,y%d,id:%d\r\n", x, y, ts);
touch_down();
#endif
TPDEBUG("[TP] touch down [%d, %d]\n", emouse.x, emouse.y);
#endif
}
static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_uint32_t id)
{
#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
struct rtgui_event_mouse emouse;
@ -67,17 +87,17 @@ static void post_motion_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
emouse.y = y;
#ifdef PKG_USING_GUIENGINE
emouse.ts = rt_tick_get();
emouse.id = ts;
emouse.id = id;
#endif
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
rt_kprintf("touch motion x:%d,y%d,id:%d\r\n", x, y, ts);
touch_mo();
TPDEBUG("[TP] touch motion [%d, %d]\n", emouse.x, emouse.y);
#endif
}
static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_uint32_t id)
{
#if (defined PKG_USING_GUIENGINE) || (defined RT_USING_RTGUI)
rt_err_t result;
struct rtgui_event_mouse emouse;
emouse.parent.sender = RT_NULL;
@ -89,114 +109,162 @@ static void post_up_event(rt_uint16_t x, rt_uint16_t y, rt_tick_t ts)
emouse.y = y;
#ifdef PKG_USING_GUIENGINE
emouse.ts = rt_tick_get();
emouse.id = ts;
emouse.id = id;
#endif
#ifdef PKG_USING_GUIENGINE
do
{
result = rtgui_server_post_event(&emouse.parent, sizeof(emouse));
if (result != RT_EOK)
{
rt_thread_delay(RT_TICK_PER_SECOND / TOUCH_SAMPLE_HZ);
}
}
while (result != RT_EOK);
#else
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
rt_kprintf("touch up x:%d,y%d,id:%d\r\n", x, y, ts);
touch_up();
#endif
TPDEBUG("[TP] touch up [%d, %d]\n", emouse.x, emouse.y);
#endif
}
static void touch_thread_entry(void *parameter)
static void touch_run(void* parameter)
{
touch_drv_t touch = (touch_drv_t)parameter;
struct touch_message msg;
rt_tick_t emouse_id = 0;
touch->ops->isr_enable(RT_TRUE);
struct touch_message msg;
rt_slist_t *driver_list = NULL;
struct touch_driver *current_driver = RT_NULL;
i2c_bus = rt_i2c_bus_device_find(TOUCH_I2C_NAME);
RT_ASSERT(i2c_bus);
if(rt_device_open(&i2c_bus->parent, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
{
return;
}
rt_slist_for_each(driver_list, &_driver_list)
{
current_driver = (struct touch_driver *)driver_list;
if(current_driver->probe(i2c_bus) == RT_TRUE)
{
break;
}
current_driver = RT_NULL;
}
if(current_driver == RT_NULL)
{
rt_kprintf("[TP] No touch pad or driver.\n");
rt_device_close((rt_device_t)i2c_bus);
return;
}
current_driver->ops->init(i2c_bus);
while (1)
{
if (rt_sem_take(current_driver->isr_sem, RT_WAITING_FOREVER) != RT_EOK)
{
continue;
}
if (rt_sem_take(touch->isr_sem, RT_WAITING_FOREVER) != RT_EOK)
if (current_driver->ops->read_point(&msg) != RT_EOK)
{
continue;
}
if (touch->ops->read_point(&msg) != RT_EOK)
{
touch->ops->isr_enable(RT_TRUE);
continue;
}
switch (msg.event)
{
case TOUCH_EVENT_UP:
post_up_event(msg.x, msg.y, emouse_id);
case TOUCH_EVENT_MOVE:
post_motion_event(msg.x, msg.y, emouse_id);
break;
case TOUCH_EVENT_DOWN:
emouse_id = rt_tick_get();
post_down_event(msg.x, msg.y, emouse_id);
break;
case TOUCH_EVENT_MOVE:
post_motion_event(msg.x, msg.y, emouse_id);
case TOUCH_EVENT_UP:
post_up_event(msg.x, msg.y, emouse_id);
break;
default:
break;
}
rt_thread_delay(RT_TICK_PER_SECOND / BSP_TOUCH_SAMPLE_HZ);
touch->ops->isr_enable(RT_TRUE);
rt_thread_delay(RT_TICK_PER_SECOND / TOUCH_SAMPLE_HZ);
}
}
int rt_touch_driver_init(void)
rt_err_t rt_touch_drivers_register(touch_driver_t drv)
{
rt_kprintf("\r\n%s \r\n", __FUNCTION__);
rt_list_init(&driver_list);
return 0;
}
INIT_BOARD_EXPORT(rt_touch_driver_init);
RT_ASSERT(drv != RT_NULL);
RT_ASSERT(drv->ops != RT_NULL);
RT_ASSERT(drv->probe != RT_NULL);
static struct rt_i2c_bus_device *i2c_bus = RT_NULL;
static int rt_touch_thread_init(void)
rt_slist_append(&_driver_list, &drv->list);
return RT_EOK;
}
static int rt_touch_list_init(void)
{
rt_list_t *l;
touch_drv_t current_driver;
rt_thread_t tid = RT_NULL;
i2c_bus = (struct rt_i2c_bus_device *)rt_device_find("i2c1");
RT_ASSERT(i2c_bus);
current_driver = RT_NULL;
if (rt_device_open((rt_device_t)i2c_bus, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
return -1;
for (l = driver_list.next; l != &driver_list; l = l->next)
{
if (rt_list_entry(l, struct touch_drivers, list)->probe(i2c_bus))
{
current_driver = rt_list_entry(l, struct touch_drivers, list);
break;
}
}
if (current_driver == RT_NULL)
{
rt_kprintf("no touch screen or do not have driver\r\n");
rt_device_close((rt_device_t)i2c_bus);
return -1;
}
current_driver->ops->init(i2c_bus);
rt_kprintf("touch screen found driver\r\n");
tid = rt_thread_create("touch", touch_thread_entry, current_driver, 2048, 27, 20);
if (tid == RT_NULL)
{
current_driver->ops->deinit();
rt_device_close((rt_device_t)i2c_bus);
return -1;
}
rt_thread_startup(tid);
return 0;
}
rt_slist_init(&_driver_list);
static void touch_init_thread_entry(void *parameter)
return RT_EOK;
}
INIT_BOARD_EXPORT(rt_touch_list_init);
static int rt_touch_init(void)
{
rt_touch_thread_init();
}
static int touc_bg_init(void)
{
rt_thread_t tid = RT_NULL;
tid = rt_thread_create("touchi", touch_init_thread_entry, RT_NULL, 2048, 28, 20);
if (tid == RT_NULL)
rt_thread_t thread = RT_NULL;
thread = rt_thread_create("touch", touch_run, RT_NULL, 2048, 28, 20);
if(thread)
{
return -1;
return rt_thread_startup(thread);
}
rt_thread_startup(tid);
return 0;
return RT_ERROR;
}
INIT_APP_EXPORT(touc_bg_init);
INIT_APP_EXPORT(rt_touch_init);
int rt_touch_read(rt_uint16_t addr, void *cmd_buf, size_t cmd_len, void *data_buf, size_t data_len)
{
struct rt_i2c_msg msgs[2];
msgs[0].addr = addr;
msgs[0].flags = RT_I2C_WR;
msgs[0].buf = cmd_buf;
msgs[0].len = cmd_len;
msgs[1].addr = addr;
msgs[1].flags = RT_I2C_RD;
msgs[1].buf = data_buf;
msgs[1].len = data_len;
if (rt_i2c_transfer(i2c_bus, msgs, 2) == 2)
return 0;
else
return -1;
}
int rt_touch_write(rt_uint16_t addr, void *data_buf, size_t data_len)
{
struct rt_i2c_msg msgs[1];
msgs[0].addr = addr;
msgs[0].flags = RT_I2C_WR;
msgs[0].buf = data_buf;
msgs[0].len = data_len;
if (rt_i2c_transfer(i2c_bus, msgs, 1) == 1)
return 0;
else
return -1;
}
#endif

View File

@ -6,7 +6,9 @@
* Change Logs:
* Date Author Notes
* 2018-02-08 Zhangyihong the first version
* 2018-10-29 XY
*/
#ifndef __DRV_TOUCH_H__
#define __DRV_TOUCH_H__
@ -24,28 +26,29 @@ struct touch_message
rt_uint16_t y;
rt_uint8_t event;
};
typedef struct touch_message *touch_msg_t;
typedef struct touch_message *touch_message_t;
struct touch_ops
{
void (* isr_enable)(rt_bool_t);
rt_err_t (* read_point)(touch_msg_t);
void (* init)(struct rt_i2c_bus_device *);
void (* deinit)(void);
void (*init)(struct rt_i2c_bus_device *);
void (*deinit)(void);
rt_err_t (*read_point)(touch_message_t);
};
typedef struct touch_ops *touch_ops_t;
struct touch_drivers
struct touch_driver
{
rt_list_t list;
unsigned char address;
rt_slist_t list;
rt_bool_t (*probe)(struct rt_i2c_bus_device *i2c_bus);
rt_sem_t isr_sem;
touch_ops_t ops;
void *user_data;
void *user_data;
};
typedef struct touch_drivers *touch_drv_t;
typedef struct touch_driver *touch_driver_t;
extern void rt_touch_drivers_register(touch_drv_t drv);
rt_err_t rt_touch_drivers_register(touch_driver_t drv);
int rt_touch_read(rt_uint16_t addr, void *cmd_buf, size_t cmd_len, void *data_buf, size_t data_len);
int rt_touch_write(rt_uint16_t addr, void *data_buf, size_t data_len);
#endif

View File

@ -1,408 +1,234 @@
/*
* File : drv_touch_gt9xx.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017, RT-Thread Development Team
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-02-08 Zhangyihong the first version
* 2018-04-03 XY gt9xx for 1024 * 600
* 2018-10-11 sundm75 ls1c for 480 * 272
* 2018-04-14 liu2guang optimize int and rst to pin framework
* 2017-08-08 XY imxrt1052
* 2018-10-29 XY
*/
#include "rtthread.h"
#include "drv_touch.h"
#include "string.h"
#include "ls1c_gpio.h"
#include "ls1c.h"
#include "ls1c_pin.h"
#ifdef TINA_USING_TOUCH
#define TP_INT_PIN (89)
#define TP_RESET_PIN (87)
#define LED_PIN (52)
#define TP_INT_PIN 89
#define TP_RST_PIN 87
#ifndef TP_INT_PIN
#error "Please config touch panel INT pin."
#endif
#ifndef TP_RST_PIN
#error "Please config touch panel RST pin."
#endif
#define gt9xx_READ_XY_REG 0x814E /* 坐标寄存器 当前检测到的触摸情况 */
#define gt9xx_CLEARBUF_REG 0x814E /* 清除坐标寄存器 */
#define gt9xx_CONFIG_REG 0x8047 /* 配置参数寄存器 */
#define gt9xx_COMMAND_REG 0x8040 /* 实时命令 */
#define gt9xx_PRODUCT_ID_REG 0x8140 /* productid */
#define gt9xx_VENDOR_ID_REG 0x814A /* 当前模组选项信息 */
#define gt9xx_CONFIG_VERSION_REG 0x8047 /* 配置文件版本号 */
#define gt9xx_CONFIG_CHECKSUM_REG 0x80FF /* 配置文件校验码 */
#define gt9xx_FIRMWARE_VERSION_REG 0x8144 /* 固件版本号 */
#ifndef IIC_RETRY_NUM
#define IIC_RETRY_NUM 2
#endif
#define IIC_RETRY_NUM 1
#define GT9xx_TS_ADDR (0x5D)
void touch_down(void);
void touch_mo(void);
void touch_up(void);
#define gt9xx_READ_XY_REG (0x814E) /* 坐标寄存器 */
#define gt9xx_CLEARBUF_REG (0x814E) /* 清除坐标寄存器 */
#define gt9xx_CONFIG_REG (0x8047) /* 配置参数寄存器 */
#define gt9xx_COMMAND_REG (0x8040) /* 实时命令 */
#define gt9xx_PRODUCT_ID_REG (0x8140) /* 产品ID */
#define gt9xx_VENDOR_ID_REG (0x814A) /* 当前模组选项信息 */
#define gt9xx_CONFIG_VERSION_REG (0x8047) /* 配置文件版本号 */
#define gt9xx_CONFIG_CHECKSUM_REG (0x80FF) /* 配置文件校验码 */
#define gt9xx_FIRMWARE_VERSION_REG (0x8144) /* 固件版本号 */
static struct rt_i2c_bus_device *gt9xx_i2c_bus;
static void gt9xx_isr_enable(rt_bool_t enable);
static rt_err_t gt9xx_read_point(touch_msg_t msg);
static void gt9xx_init(struct rt_i2c_bus_device *i2c_bus);
static void gt9xx_deinit(void);
static int gt9xx_read_xy(void);
#if 0
#define TPDEBUG rt_kprintf
#else
#define TPDEBUG(...)
#endif
static gpio_direction_output( int pin, int level)
static struct touch_driver gt9xx_driver;
void gt9xx_hw_reset(rt_uint8_t address)
{
gpio_init(pin, gpio_mode_output);
gpio_set(pin, level);
}
static gpio_direction_input(int pin)
{
gpio_init(pin, gpio_mode_input);
}
static gpio_irq_enable( int pin)
{
int touch_irq = LS1C_GPIO_TO_IRQ(TP_INT_PIN);
rt_hw_interrupt_umask(touch_irq);
}
static gpio_irq_disable(int pin)
{
int touch_irq = LS1C_GPIO_TO_IRQ(TP_INT_PIN);
rt_hw_interrupt_mask(touch_irq);
}
static gpio_set_value(int pin, int level)
{
gpio_set(pin, level);
}
struct touch_ops gt9xx_ops =
{
gt9xx_isr_enable,
gt9xx_read_point,
gt9xx_init,
gt9xx_deinit,
};
rt_tick_t delay = rt_tick_from_millisecond(30);
static struct touch_drivers gt9xx_driver;
extern struct lcd_config lcd_config;
rt_pin_mode(TP_RST_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(TP_INT_PIN, PIN_MODE_OUTPUT);
static rt_uint8_t gt9xx_config[186];
static int gt9xx_read(struct rt_i2c_bus_device *i2c_bus, rt_uint16_t addr, rt_uint8_t *buffer, rt_size_t length)
{
int ret = -1;
int retries = 0;
rt_uint8_t tmp_buf[2];
struct rt_i2c_msg msgs[] =
{
{
.addr = gt9xx_driver.address,
.flags = RT_I2C_WR,
.len = 2,
.buf = tmp_buf,
},
{
.addr = gt9xx_driver.address,
.flags = RT_I2C_RD,
.len = length,
.buf = buffer,
},
};
tmp_buf[0] = (rt_uint8_t)(addr >> 8);
tmp_buf[1] = (rt_uint8_t)(addr);
while (retries < IIC_RETRY_NUM)
{
ret = rt_i2c_transfer(i2c_bus, msgs, 2);
ret = rt_i2c_transfer(i2c_bus, msgs, 2);
ret = rt_i2c_transfer(i2c_bus, msgs, 2);
ret = rt_i2c_transfer(i2c_bus, msgs, 2);
if (ret == 2)break;
retries++;
}
if (retries >= IIC_RETRY_NUM)
{
rt_kprintf("%s i2c read error: %d\n", __func__, ret);
return -1;
}
return ret;
}
static void gt9xx_write(struct rt_i2c_bus_device *i2c_bus, rt_uint16_t addr, rt_uint8_t *buffer, rt_size_t length)
{
rt_uint8_t *send_buffer = rt_malloc(length + 2);
RT_ASSERT(send_buffer);
send_buffer[0] = (rt_uint8_t)(addr >> 8);
send_buffer[1] = (rt_uint8_t)(addr);
memcpy(send_buffer + 2, buffer, length);
struct rt_i2c_msg msgs[] =
{
{
.addr = gt9xx_driver.address,
.flags = RT_I2C_WR,
.len = length + 2,
.buf = send_buffer,
}
};
length = rt_i2c_transfer(i2c_bus, msgs, 1);
rt_free(send_buffer);
send_buffer = RT_NULL;
}
static void gt9xx_isr_enable(rt_bool_t enable)
{
if (enable)
{
gpio_irq_enable( TP_INT_PIN);
}
else
{
gpio_irq_disable( TP_INT_PIN);
}
}
static rt_err_t gt9xx_read_point(touch_msg_t msg)
{
rt_uint8_t buf[8];
rt_uint8_t clean = 0;
static rt_uint8_t s_tp_down = 0;
gt9xx_read(gt9xx_i2c_bus, gt9xx_READ_XY_REG, buf, 8);
gt9xx_write(gt9xx_i2c_bus, gt9xx_CLEARBUF_REG, &clean, 1);
if ((buf[0] & 0x80) == 0)
{
if (s_tp_down)
{
s_tp_down = 0;
msg->event = TOUCH_EVENT_UP;
return RT_EOK;
}
msg->event = TOUCH_EVENT_NONE;
return RT_EOK;
}
msg->x = ((rt_uint16_t)buf[3] << 8) | buf[2];
msg->y = ((rt_uint16_t)buf[5] << 8) | buf[4];
if (s_tp_down)
{
msg->event = TOUCH_EVENT_MOVE;
return RT_EOK;
}
msg->event = TOUCH_EVENT_DOWN;
s_tp_down = 1;
return RT_EOK;
}
void gt9xx_touch_isr(int irq, void *param)
{
gpio_irq_disable(TP_INT_PIN);
rt_sem_release(gt9xx_driver.isr_sem);
}
static void gt9xx_set_address(rt_uint8_t address)
{
pin_set_purpose(TP_INT_PIN, PIN_PURPOSE_OTHER);
pin_set_purpose(TP_RESET_PIN, PIN_PURPOSE_OTHER);
gpio_direction_output( TP_INT_PIN, 0);
gpio_direction_output( TP_RESET_PIN, 0);
if (address == 0x5D)
{
rt_thread_delay(30);
gpio_set_value( TP_RESET_PIN, 1);
rt_thread_delay(300);
pin_set_purpose(TP_INT_PIN, PIN_PURPOSE_OTHER);
gpio_direction_input(TP_INT_PIN);
rt_thread_delay(10);
rt_pin_write(TP_RST_PIN, PIN_LOW);
rt_pin_write(TP_INT_PIN, PIN_LOW);
rt_thread_delay(delay);
rt_pin_write(TP_RST_PIN, PIN_HIGH);
rt_pin_write(TP_INT_PIN, PIN_LOW);
rt_thread_delay(delay);
rt_pin_write(TP_INT_PIN, PIN_LOW);
rt_thread_delay(delay);
rt_pin_write(TP_INT_PIN, PIN_HIGH);
}
else
{
gpio_set_value( TP_INT_PIN, 1);
gpio_set_value( TP_RESET_PIN, 0);
rt_thread_delay(30);
gpio_set_value( TP_RESET_PIN, 1);
gpio_set_value( TP_INT_PIN, 1);
rt_thread_delay(30);
gpio_set_value( TP_INT_PIN, 0);
rt_thread_delay(30);
gpio_set_value( TP_INT_PIN, 1);
rt_pin_write(TP_RST_PIN, PIN_LOW);
rt_pin_write(TP_INT_PIN, PIN_HIGH);
rt_thread_delay(delay);
rt_pin_write(TP_RST_PIN, PIN_HIGH);
rt_pin_write(TP_INT_PIN, PIN_HIGH);
rt_thread_delay(delay);
rt_pin_write(TP_INT_PIN, PIN_LOW);
rt_thread_delay(delay);
rt_pin_write(TP_INT_PIN, PIN_HIGH);
}
}
static void gt9xx_soft_reset(struct rt_i2c_bus_device *i2c_bus)
{
rt_uint8_t buf = 2;
gt9xx_write(i2c_bus, gt9xx_COMMAND_REG, &buf, 1);
}
rt_uint8_t buf[3];
static void gt9xx_init(struct rt_i2c_bus_device *i2c_bus)
{
rt_uint8_t id = 0;
int touch_irq = LS1C_GPIO_TO_IRQ(TP_INT_PIN);
gt9xx_driver.isr_sem = rt_sem_create("gt9xx", 0, RT_IPC_FLAG_FIFO);
RT_ASSERT(gt9xx_driver.isr_sem);
gt9xx_i2c_bus = i2c_bus;
gt9xx_set_address(gt9xx_driver.address);
gt9xx_read(i2c_bus, gt9xx_CONFIG_VERSION_REG, &id, 1);
rt_kprintf("\r\nGT9xx Config version:0x%02X\r\n", id);
gt9xx_read(i2c_bus, gt9xx_VENDOR_ID_REG, &id, 1);
rt_kprintf("\r\nGT9xx sensor id:0x%02X\r\n", id);
gpio_set_irq_type( TP_INT_PIN, IRQ_TYPE_EDGE_RISING);
gpio_irq_disable( TP_INT_PIN);
rt_hw_interrupt_install(touch_irq, gt9xx_touch_isr, RT_NULL, "touch");
rt_thread_delay(RT_TICK_PER_SECOND / 5);
gpio_init(LED_PIN, gpio_mode_output);
buf[0] = (rt_uint8_t)((gt9xx_COMMAND_REG >> 8) & 0xFF);
buf[1] = (rt_uint8_t)(gt9xx_COMMAND_REG & 0xFF);
buf[2] = 0x02;
rt_touch_write(GT9xx_TS_ADDR, buf, 3);
}
static int gt9xx_write_config(void)
{
int i;
rt_uint8_t config_checksum = 0;
gt9xx_set_address(gt9xx_driver.address);
//Add sth...
gt9xx_config[5] = 0x05;
gt9xx_config[6] = 0x0C;
for (i = 0; i < sizeof(gt9xx_config) - 2; i++)
{
config_checksum += gt9xx_config[i];
}
gt9xx_config[184] = (~config_checksum) + 1;
gt9xx_config[185] = 0x01;
gt9xx_write(gt9xx_i2c_bus, gt9xx_CONFIG_REG, gt9xx_config, sizeof(gt9xx_config));
return 0;
}
MSH_CMD_EXPORT(gt9xx_write_config,please read first);
static int gt9xx_read_config(void)
{
int i;
rt_uint8_t buf[8];
rt_uint8_t clean = 0;
gt9xx_read(gt9xx_i2c_bus, gt9xx_CONFIG_VERSION_REG, gt9xx_config, sizeof(gt9xx_config));
gt9xx_config[sizeof(gt9xx_config)-1] = 1;
rt_kprintf("\n");
for(i = 0; i < sizeof(gt9xx_config); i++)
{
rt_kprintf("0x%02X,",gt9xx_config[i]);
if((i+1)%8 == 0)
{
rt_kprintf("\n");
}
}
rt_kprintf("\n");
return 0;
}
MSH_CMD_EXPORT(gt9xx_read_config,read gt9xx config);
static int gt9xx_read_xy(void)
{
int i;
rt_uint8_t buf[8];
rt_uint8_t clean = 0;
rt_uint16_t x,y;
gt9xx_read(gt9xx_i2c_bus, gt9xx_READ_XY_REG, buf, 8);
gt9xx_write(gt9xx_i2c_bus, gt9xx_CLEARBUF_REG, &clean, 1);
x = ((rt_uint16_t)buf[3] << 8) | buf[2];
y = ((rt_uint16_t)buf[5] << 8) | buf[4];
rt_kprintf("\n814e= 0x%02x; 814f= 0x%02x;\n x1 : %d, y1 : %d\n", buf[0], buf[1], x, y);
rt_kprintf("\n");
return 0;
}
MSH_CMD_EXPORT(gt9xx_read_xy,read gt9xx xy);
static rt_bool_t gt9xx_probe(struct rt_i2c_bus_device *i2c_bus)
{
rt_uint8_t buffer[5] = { 0 };
rt_uint8_t cmd[2];
rt_uint8_t buffer[5] = {0};
gt9xx_hw_reset(GT9xx_TS_ADDR);
//gt9xx_soft_reset(i2c_bus);
rt_thread_delay(RT_TICK_PER_SECOND / 5);
cmd[0] = (rt_uint8_t)((gt9xx_PRODUCT_ID_REG >> 8) & 0xFF);
cmd[1] = (rt_uint8_t)(gt9xx_PRODUCT_ID_REG & 0xFF);
if (rt_touch_read(GT9xx_TS_ADDR, &cmd, 2, buffer, 4) != 0)
{
TPDEBUG("[TP] %s failed!\n", __func__);
return RT_FALSE;
}
gt9xx_set_address(gt9xx_driver.address);
gt9xx_soft_reset(i2c_bus);
rt_thread_delay(10);
gt9xx_read(i2c_bus, gt9xx_PRODUCT_ID_REG, buffer, 4);
buffer[4] = '\0';
if (buffer[0] == '9' && buffer[1] == '1' && buffer[2] == '1')
TPDEBUG("%#X %#X %#X %#X %#X\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]);
if(!rt_strcmp((const char*)buffer, "911"))
{
rt_kprintf("Found chip gt911\r\n");
rt_kprintf("[TP] Found chip gt911\n");
return RT_TRUE;
}
else if (buffer[0] == '9' && buffer[1] == '1' && buffer[2] == '4' && buffer[3] == '7')
else if(!rt_strcmp((const char*)buffer, "9147"))
{
rt_kprintf("Found chip gt9147\r\n");
rt_kprintf("[TP] Found chip gt9147\n");
return RT_TRUE;
}
else if (buffer[0] == '9' && buffer[1] == '1' && buffer[2] == '5' && buffer[3] == '7')
else if(!rt_strcmp((const char*)buffer, "9157"))
{
rt_kprintf("Found chip gt9157\r\n");
rt_kprintf("[TP] Found chip gt9157\n");
return RT_TRUE;
}
else
{
rt_kprintf("Uknow chip :");
rt_kprintf("%d%d%d%d\r\n",buffer[0], buffer[1] , buffer[2], buffer[3]);
return RT_TRUE;
rt_kprintf("[TP] Uknow chip gt9xx device: [%s]\n", buffer);
}
return RT_FALSE;
}
static void gt9xx_init(struct rt_i2c_bus_device *i2c_bus)
{
rt_uint8_t buf = 0;
rt_uint8_t cmd[2];
gt9xx_driver.isr_sem = rt_sem_create("gt9xx", 0, RT_IPC_FLAG_FIFO);
RT_ASSERT(gt9xx_driver.isr_sem);
cmd[0] = (rt_uint8_t)((gt9xx_CONFIG_VERSION_REG >> 8) & 0xFF);
cmd[1] = (rt_uint8_t)(gt9xx_CONFIG_VERSION_REG & 0xFF);
rt_touch_read(GT9xx_TS_ADDR, &cmd, 2, &buf, 1);
rt_kprintf("[TP] GT9xx Config version: 0x%02X\n", buf);
cmd[0] = (rt_uint8_t)((gt9xx_VENDOR_ID_REG >> 8) & 0xFF);
cmd[1] = (rt_uint8_t)(gt9xx_VENDOR_ID_REG & 0xFF);
rt_touch_read(GT9xx_TS_ADDR, &cmd, 2, &buf, 1);
rt_kprintf("[TP] GT9xx Sensor id: 0x%02X\n", buf);
rt_sem_release(gt9xx_driver.isr_sem);
}
static void gt9xx_deinit(void)
{
rt_sem_delete(gt9xx_driver.isr_sem);
}
static rt_err_t gt9xx_read_point(touch_message_t msg)
{
rt_uint8_t cmd[2];
rt_uint8_t buf[8] = {0};
static rt_uint8_t s_tp_down = 0;
cmd[0] = (rt_uint8_t)((gt9xx_READ_XY_REG >> 8) & 0xFF);
cmd[1] = (rt_uint8_t)(gt9xx_READ_XY_REG & 0xFF);
rt_touch_read(GT9xx_TS_ADDR, &cmd, 2, buf, 8);
if((buf[0] & 0x01) == 0)
{
if(s_tp_down)
{
s_tp_down = 0;
msg->event = TOUCH_EVENT_UP;
}
else
{
msg->event = TOUCH_EVENT_NONE;
}
}
else
{
msg->x = ((rt_uint16_t)buf[3] << 8) | buf[2];
msg->y = ((rt_uint16_t)buf[5] << 8) | buf[4];
if(s_tp_down)
{
msg->event = TOUCH_EVENT_MOVE;
}
else
{
msg->event = TOUCH_EVENT_DOWN;
s_tp_down = 1;
}
}
buf[0] = ((gt9xx_CLEARBUF_REG >> 8) & 0xFF);
buf[1] = (gt9xx_CLEARBUF_REG & 0xFF);
buf[2] = 0x00;
rt_touch_write(GT9xx_TS_ADDR, buf, 3);
rt_sem_release(gt9xx_driver.isr_sem);
return RT_EOK;
}
struct touch_ops gt9xx_ops =
{
.init = gt9xx_init,
.deinit = gt9xx_deinit,
.read_point = gt9xx_read_point,
};
static int gt9xx_driver_register(void)
{
rt_kprintf("\r\n%s \r\n", __FUNCTION__);
gt9xx_driver.address = 0x5D;
gt9xx_driver.probe = gt9xx_probe;
gt9xx_driver.ops = &gt9xx_ops;
gt9xx_driver.probe = gt9xx_probe;
gt9xx_driver.ops = &gt9xx_ops;
gt9xx_driver.user_data = RT_NULL;
rt_touch_drivers_register(&gt9xx_driver);
return 0;
return RT_EOK;
}
INIT_ENV_EXPORT(gt9xx_driver_register);
void touch_down(void)
{
gpio_set(LED_PIN, gpio_level_low);
}
void touch_mo(void)
{
if (0 == (gpio_get(LED_PIN)))
gpio_set(LED_PIN, gpio_level_high);
else
gpio_set(LED_PIN, gpio_level_low);
}
void touch_up(void)
{
gpio_set(LED_PIN, gpio_level_high);
}
#endif

View File

@ -143,6 +143,15 @@ struct rt_uart_ls1c uart1 =
struct rt_serial_device serial1;
#endif /* RT_USING_UART1 */
#if defined(RT_USING_UART3)
struct rt_uart_ls1c uart3 =
{
LS1C_UART3,
LS1C_UART3_IRQ,
};
struct rt_serial_device serial3;
#endif /* RT_USING_UART3 */
void rt_hw_uart_init(void)
{
struct rt_uart_ls1c *uart;
@ -190,5 +199,26 @@ void rt_hw_uart_init(void)
uart);
#endif /* RT_USING_UART1 */
#ifdef RT_USING_UART3
uart = &uart3;
serial3.ops = &ls1c_uart_ops;
serial3.config = config;
pin_set_purpose(0, PIN_PURPOSE_OTHER);
pin_set_purpose(1, PIN_PURPOSE_OTHER);
pin_set_remap(0, PIN_REMAP_FOURTH);
pin_set_remap(1, PIN_REMAP_FOURTH);
rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial3, "UART3");
/* register UART1 device */
rt_hw_serial_register(&serial3,
"uart3",
//RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX,
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
#endif /* RT_USING_UART3 */
}

View File

@ -572,47 +572,47 @@ struct pbuf *rt_eth_rx(rt_device_t device)
}
/*Handle the Receive Descriptors*/
// do{
desc_index = synopGMAC_get_rx_qptr(gmacdev, &status, &dma_addr1, NULL, &data1, &dma_addr2, NULL, &data2);
if (desc_index >= 0 && data1 != 0)
do
{
DEBUG_MES("Received Data at Rx Descriptor %d for skb 0x%08x whose status is %08x\n", desc_index, dma_addr1, status);
desc_index = synopGMAC_get_rx_qptr(gmacdev, &status, &dma_addr1, NULL, &data1, &dma_addr2, NULL, &data2);
if (synopGMAC_is_rx_desc_valid(status) || SYNOP_PHY_LOOPBACK)
if (desc_index >= 0 && data1 != 0)
{
pbuf = pbuf_alloc(PBUF_LINK, MAX_ETHERNET_PAYLOAD, PBUF_RAM);
if (pbuf == 0) rt_kprintf("===error in pbuf_alloc\n");
DEBUG_MES("Received Data at Rx Descriptor %d for skb 0x%08x whose status is %08x\n", desc_index, dma_addr1, status);
if (synopGMAC_is_rx_desc_valid(status) || SYNOP_PHY_LOOPBACK)
{
pbuf = pbuf_alloc(PBUF_LINK, MAX_ETHERNET_PAYLOAD, PBUF_RAM);
if (pbuf == 0) rt_kprintf("===error in pbuf_alloc\n");
dma_addr1 = plat_dma_map_single(gmacdev, (void *)data1, RX_BUF_SIZE);
len = synopGMAC_get_rx_desc_frame_length(status); //Not interested in Ethernet CRC bytes
rt_memcpy(pbuf->payload, (char *)data1, len);
DEBUG_MES("==get pkg len: %d\n", len);
dma_addr1 = plat_dma_map_single(gmacdev, (void *)data1, RX_BUF_SIZE);
len = synopGMAC_get_rx_desc_frame_length(status); //Not interested in Ethernet CRC bytes
rt_memcpy(pbuf->payload, (char *)data1, len);
DEBUG_MES("==get pkg len: %d\n", len);
}
else
{
rt_kprintf("s: %08x\n", status);
adapter->synopGMACNetStats.rx_errors++;
adapter->synopGMACNetStats.collisions += synopGMAC_is_rx_frame_collision(status);
adapter->synopGMACNetStats.rx_crc_errors += synopGMAC_is_rx_crc(status);
adapter->synopGMACNetStats.rx_frame_errors += synopGMAC_is_frame_dribbling_errors(status);
adapter->synopGMACNetStats.rx_length_errors += synopGMAC_is_rx_frame_length_errors(status);
}
desc_index = synopGMAC_set_rx_qptr(gmacdev, dma_addr1, RX_BUF_SIZE, (u32)data1, 0, 0, 0);
if (desc_index < 0)
{
#if SYNOP_RX_DEBUG
rt_kprintf("Cannot set Rx Descriptor for data1 %08x\n", (u32)data1);
#endif
plat_free_memory((void *)data1);
}
}
else
{
rt_kprintf("s: %08x\n", status);
adapter->synopGMACNetStats.rx_errors++;
adapter->synopGMACNetStats.collisions += synopGMAC_is_rx_frame_collision(status);
adapter->synopGMACNetStats.rx_crc_errors += synopGMAC_is_rx_crc(status);
adapter->synopGMACNetStats.rx_frame_errors += synopGMAC_is_frame_dribbling_errors(status);
adapter->synopGMACNetStats.rx_length_errors += synopGMAC_is_rx_frame_length_errors(status);
}
desc_index = synopGMAC_set_rx_qptr(gmacdev, dma_addr1, RX_BUF_SIZE, (u32)data1, 0, 0, 0);
if (desc_index < 0)
{
#if SYNOP_RX_DEBUG
rt_kprintf("Cannot set Rx Descriptor for data1 %08x\n", (u32)data1);
#endif
plat_free_memory((void *)data1);
}
}
// }while(desc_index >= 0);
}while(desc_index >= 0);
rt_sem_release(&sem_lock);
DEBUG_MES("%s : before return \n", __FUNCTION__);
return pbuf;
@ -965,6 +965,8 @@ int rt_hw_eth_init(void)
eth_device_init(&(eth_dev.parent), "e0");
eth_device_linkchange(&eth_dev.parent, RT_TRUE); //linkup the e0 for lwip to check
return 0;
}