提交 59ea0e16 编写于 作者: T tanek liang

[bsp] add LCD and touch driver, and update configuration

上级 f1c6dc1a
...@@ -93,11 +93,11 @@ CONFIG_RT_USING_DFS_ELMFAT=y ...@@ -93,11 +93,11 @@ CONFIG_RT_USING_DFS_ELMFAT=y
# #
CONFIG_RT_DFS_ELM_CODE_PAGE=437 CONFIG_RT_DFS_ELM_CODE_PAGE=437
CONFIG_RT_DFS_ELM_WORD_ACCESS=y CONFIG_RT_DFS_ELM_WORD_ACCESS=y
CONFIG_RT_DFS_ELM_USE_LFN_0=y # CONFIG_RT_DFS_ELM_USE_LFN_0 is not set
# CONFIG_RT_DFS_ELM_USE_LFN_1 is not set # CONFIG_RT_DFS_ELM_USE_LFN_1 is not set
# CONFIG_RT_DFS_ELM_USE_LFN_2 is not set # CONFIG_RT_DFS_ELM_USE_LFN_2 is not set
# CONFIG_RT_DFS_ELM_USE_LFN_3 is not set CONFIG_RT_DFS_ELM_USE_LFN_3=y
CONFIG_RT_DFS_ELM_USE_LFN=0 CONFIG_RT_DFS_ELM_USE_LFN=3
CONFIG_RT_DFS_ELM_MAX_LFN=255 CONFIG_RT_DFS_ELM_MAX_LFN=255
CONFIG_RT_DFS_ELM_DRIVES=2 CONFIG_RT_DFS_ELM_DRIVES=2
CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512 CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512
...@@ -117,7 +117,8 @@ CONFIG_RT_USING_DEVICE_IPC=y ...@@ -117,7 +117,8 @@ CONFIG_RT_USING_DEVICE_IPC=y
CONFIG_RT_USING_SERIAL=y CONFIG_RT_USING_SERIAL=y
# CONFIG_RT_USING_CAN is not set # CONFIG_RT_USING_CAN is not set
# CONFIG_RT_USING_HWTIMER is not set # CONFIG_RT_USING_HWTIMER is not set
# CONFIG_RT_USING_I2C is not set CONFIG_RT_USING_I2C=y
CONFIG_RT_USING_I2C_BITOPS=y
# CONFIG_RT_USING_PIN is not set # CONFIG_RT_USING_PIN is not set
# CONFIG_RT_USING_MTD_NOR is not set # CONFIG_RT_USING_MTD_NOR is not set
# CONFIG_RT_USING_MTD_NAND is not set # CONFIG_RT_USING_MTD_NAND is not set
...@@ -157,7 +158,6 @@ CONFIG_RT_LWIP_DNS=y ...@@ -157,7 +158,6 @@ CONFIG_RT_LWIP_DNS=y
CONFIG_RT_LWIP_DHCP=y CONFIG_RT_LWIP_DHCP=y
CONFIG_IP_SOF_BROADCAST=1 CONFIG_IP_SOF_BROADCAST=1
CONFIG_IP_SOF_BROADCAST_RECV=1 CONFIG_IP_SOF_BROADCAST_RECV=1
# CONFIG_LWIP_USING_DHCPD is not set
# #
# Static IPv4 Address # Static IPv4 Address
...@@ -169,8 +169,7 @@ CONFIG_RT_LWIP_UDP=y ...@@ -169,8 +169,7 @@ CONFIG_RT_LWIP_UDP=y
CONFIG_RT_LWIP_TCP=y CONFIG_RT_LWIP_TCP=y
# CONFIG_RT_LWIP_RAW is not set # CONFIG_RT_LWIP_RAW is not set
# CONFIG_RT_LWIP_PPP is not set # CONFIG_RT_LWIP_PPP is not set
# CONFIG_RT_LWIP_PPPOE is not set CONFIG_RT_MEMP_NUM_NETCONN=8
# CONFIG_RT_LWIP_PPPOS is not set
CONFIG_RT_LWIP_PBUF_NUM=16 CONFIG_RT_LWIP_PBUF_NUM=16
CONFIG_RT_LWIP_RAW_PCB_NUM=4 CONFIG_RT_LWIP_RAW_PCB_NUM=4
CONFIG_RT_LWIP_UDP_PCB_NUM=4 CONFIG_RT_LWIP_UDP_PCB_NUM=4
...@@ -195,12 +194,29 @@ CONFIG_LWIP_SO_RCVBUF=1 ...@@ -195,12 +194,29 @@ CONFIG_LWIP_SO_RCVBUF=1
# Modbus master and slave stack # Modbus master and slave stack
# #
# CONFIG_RT_USING_MODBUS is not set # CONFIG_RT_USING_MODBUS is not set
# CONFIG_LWIP_USING_DHCPD is not set
# CONFIG_RT_USING_NETUTILS is not set # CONFIG_RT_USING_NETUTILS is not set
# #
# RT-Thread UI Engine # RT-Thread UI Engine
# #
# CONFIG_RT_USING_GUIENGINE is not set CONFIG_RT_USING_GUIENGINE=y
CONFIG_RTGUI_NAME_MAX=16
CONFIG_RTGUI_USING_TTF=y
CONFIG_UTF8_TO_UNICODE=y
CONFIG_RTGUI_USING_FONT16=y
CONFIG_RTGUI_USING_FONT12=y
# CONFIG_RTGUI_USING_FONTHZ is not set
# CONFIG_RTGUI_IMAGE_XPM is not set
CONFIG_RTGUI_IMAGE_JPEG_NONE=y
# CONFIG_RTGUI_IMAGE_JPEG is not set
# CONFIG_RTGUI_IMAGE_TJPGD is not set
# CONFIG_RTGUI_IMAGE_PNG_NONE is not set
# CONFIG_RTGUI_IMAGE_PNG is not set
CONFIG_RTGUI_IMAGE_LODEPNG=y
# CONFIG_RTGUI_IMAGE_BMP is not set
CONFIG_RTGUI_IMAGE_CONTAINER=y
# CONFIG_RTGUI_USING_DEMO is not set
# #
# VBUS(Virtual Software BUS) # VBUS(Virtual Software BUS)
...@@ -240,6 +256,7 @@ CONFIG_LWIP_SO_RCVBUF=1 ...@@ -240,6 +256,7 @@ CONFIG_LWIP_SO_RCVBUF=1
# #
# CONFIG_PKG_USING_MBEDTLS is not set # CONFIG_PKG_USING_MBEDTLS is not set
# CONFIG_PKG_USING_libsodium is not set # CONFIG_PKG_USING_libsodium is not set
# CONFIG_PKG_USING_TINYCRYPT is not set
# #
# language packages # language packages
...@@ -250,6 +267,7 @@ CONFIG_LWIP_SO_RCVBUF=1 ...@@ -250,6 +267,7 @@ CONFIG_LWIP_SO_RCVBUF=1
# #
# multimedia packages # multimedia packages
# #
# CONFIG_PKG_USING_OPENMV is not set
# #
# tools packages # tools packages
...@@ -257,6 +275,7 @@ CONFIG_LWIP_SO_RCVBUF=1 ...@@ -257,6 +275,7 @@ CONFIG_LWIP_SO_RCVBUF=1
# CONFIG_PKG_USING_CMBACKTRACE is not set # CONFIG_PKG_USING_CMBACKTRACE is not set
# CONFIG_PKG_USING_EASYLOGGER is not set # CONFIG_PKG_USING_EASYLOGGER is not set
# CONFIG_PKG_USING_SYSTEMVIEW is not set # CONFIG_PKG_USING_SYSTEMVIEW is not set
# CONFIG_PKG_USING_IPERF is not set
# #
# miscellaneous packages # miscellaneous packages
......
...@@ -22,6 +22,9 @@ if GetDepend('RT_USING_LWIP'): ...@@ -22,6 +22,9 @@ if GetDepend('RT_USING_LWIP'):
if GetDepend('RT_USING_SDIO'): if GetDepend('RT_USING_SDIO'):
src += ['drv_sdio.c'] src += ['drv_sdio.c']
if GetDepend('RT_USING_RTGUI') or GetDepend('RT_USING_GUIENGINE'):
src += ['drv_lcd.c', 'drv_ft5406.c', 'drv_i2c.c']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES) group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
Return('group') Return('group')
...@@ -173,7 +173,6 @@ void rt_hw_board_init() ...@@ -173,7 +173,6 @@ void rt_hw_board_init()
{ {
BOARD_BootClockRUN(); BOARD_BootClockRUN();
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
#ifdef RT_USING_COMPONENTS_INIT #ifdef RT_USING_COMPONENTS_INIT
...@@ -193,4 +192,24 @@ void rt_hw_board_init() ...@@ -193,4 +192,24 @@ void rt_hw_board_init()
#endif #endif
} }
#ifdef RT_USING_GUIENGINE
#include <rtgui/driver.h>
#include "drv_lcd.h"
/* initialize for gui driver */
int rtgui_lcd_init(void)
{
rt_device_t device;
imxrt_hw_lcd_init();
device = rt_device_find("lcd");
/* set graphic device */
rtgui_graphic_set_device(device);
return 0;
}
INIT_DEVICE_EXPORT(rtgui_lcd_init);
#endif
/*@}*/ /*@}*/
/*
* File : drv_ft5406.c
* FT5406 touch driver
* COPYRIGHT (C) 2006 - 2017, 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.
*
* Change Logs:
* Date Author Notes
* 2017-08-08 Yang the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <finsh.h>
#define RT_USING_RTGUI
#ifdef RT_USING_RTGUI
#include <rtgui/event.h>
#include <rtgui/rtgui_server.h>
#endif
#include "board.h"
#include "fsl_gpio.h"
#include "fsl_lpi2c.h"
#define BSP_TOUCH_SAMPLE_HZ 30
#define I2CBUS_NAME "i2c0"
#if 0
#define FTDEBUG rt_kprintf
#else
#define FTDEBUG(...)
#endif
#define TOUCH_SLP_TIME (RT_TICK_PER_SECOND * 5)
#define FT5206_TS_ADDR 0x38
#define TP_MAX_TOUCH_POINT 2
enum ft5x0x_ts_regs
{
FT5X0X_REG_THGROUP = 0x80,
FT5X0X_REG_THPEAK = 0x81,
FT5X0X_REG_THCAL = 0x82,
FT5X0X_REG_THWATER = 0x83,
FT5X0X_REG_THTEMP = 0x84,
FT5X0X_REG_THDIFF = 0x85,
FT5X0X_REG_CTRL = 0x86,
FT5X0X_REG_TIMEENTERMONITOR = 0x87,
FT5X0X_REG_PERIODACTIVE = 0x88,
FT5X0X_REG_PERIODMONITOR = 0x89,
FT5X0X_REG_HEIGHT_B = 0x8a,
FT5X0X_REG_MAX_FRAME = 0x8b,
FT5X0X_REG_DIST_MOVE = 0x8c,
FT5X0X_REG_DIST_POINT = 0x8d,
FT5X0X_REG_FEG_FRAME = 0x8e,
FT5X0X_REG_SINGLE_CLICK_OFFSET = 0x8f,
FT5X0X_REG_DOUBLE_CLICK_TIME_MIN = 0x90,
FT5X0X_REG_SINGLE_CLICK_TIME = 0x91,
FT5X0X_REG_LEFT_RIGHT_OFFSET = 0x92,
FT5X0X_REG_UP_DOWN_OFFSET = 0x93,
FT5X0X_REG_DISTANCE_LEFT_RIGHT = 0x94,
FT5X0X_REG_DISTANCE_UP_DOWN = 0x95,
FT5X0X_REG_ZOOM_DIS_SQR = 0x96,
FT5X0X_REG_RADIAN_VALUE = 0x97,
FT5X0X_REG_MAX_X_HIGH = 0x98,
FT5X0X_REG_MAX_X_LOW = 0x99,
FT5X0X_REG_MAX_Y_HIGH = 0x9a,
FT5X0X_REG_MAX_Y_LOW = 0x9b,
FT5X0X_REG_K_X_HIGH = 0x9c,
FT5X0X_REG_K_X_LOW = 0x9d,
FT5X0X_REG_K_Y_HIGH = 0x9e,
FT5X0X_REG_K_Y_LOW = 0x9f,
FT5X0X_REG_AUTO_CLB_MODE = 0xa0,
FT5X0X_REG_LIB_VERSION_H = 0xa1,
FT5X0X_REG_LIB_VERSION_L = 0xa2,
FT5X0X_REG_CIPHER = 0xa3,
FT5X0X_REG_G_MODE = 0xa4,
FT5X0X_REG_PMODE = 0xa5, /* Power Consume Mode */
FT5X0X_REG_FIRMID = 0xa6,
FT5X0X_REG_STATE = 0xa7,
FT5X0X_REG_VENDID = 0xa8,
FT5X0X_REG_ERR = 0xa9,
FT5X0X_REG_CLB = 0xaa,
};
#define CTRL_NOAUTO_MONITOR 0x00
#define CTRL_AUTO_MONITOR 0x01
#define PMODE_ACTIVE 0x00
#define PMODE_MONITOR 0x01
#define PMODE_STANDBY 0x02
#define PMODE_HIBERNATE 0x03
#define G_MODE_POLLING 0x00
#define G_MODE_TRIGGER 0x01
typedef enum _touch_event
{
kTouch_Down = 0, /*!< The state changed to touched. */
kTouch_Up = 1, /*!< The state changed to not touched. */
kTouch_Contact = 2, /*!< There is a continuous touch being detected. */
kTouch_Reserved = 3 /*!< No touch information available. */
} touch_event_t;
typedef struct _touch_point
{
touch_event_t TOUCH_EVENT; /*!< Indicates the state or event of the touch point. */
uint8_t TOUCH_ID; /*!< Id of the touch point. This numeric value stays constant between down and up event. */
uint16_t TOUCH_X; /*!< X coordinate of the touch point */
uint16_t TOUCH_Y; /*!< Y coordinate of the touch point */
} touch_point_t;
typedef struct _ft5406_touch_point
{
uint8_t XH;
uint8_t XL;
uint8_t YH;
uint8_t YL;
uint8_t RESERVED[2];
} ft5406_touch_point_t;
typedef struct _ft5406_touch_data
{
uint8_t DEVIDE_MODE;
uint8_t GEST_ID;
uint8_t TD_STATUS;
ft5406_touch_point_t TOUCH;
} ft5406_touch_data_t;
#define TOUCH_POINT_GET_EVENT(T) ((touch_event_t)((T).XH >> 6))
#define TOUCH_POINT_GET_ID(T) ((T).YH >> 4)
#define TOUCH_POINT_GET_X(T) ((((T).XH & 0x0f) << 8) | (T).XL)
#define TOUCH_POINT_GET_Y(T) ((((T).YH & 0x0f) << 8) | (T).YL)
static struct rt_i2c_bus_device *_i2c_bus;
static struct rt_semaphore _tp_sem;
static int _ft5406_read(unsigned char cmd,
void *buf,
size_t len)
{
struct rt_i2c_msg msgs[2];
msgs[0].addr = FT5206_TS_ADDR;
msgs[0].flags = RT_I2C_WR;
msgs[0].buf = &cmd;
msgs[0].len = sizeof(cmd);
msgs[1].addr = FT5206_TS_ADDR;
msgs[1].flags = RT_I2C_RD;
msgs[1].buf = buf;
msgs[1].len = len;
if (rt_i2c_transfer(_i2c_bus, msgs, 2) == 2)
return len;
else
return -1;
}
static int ft5406_read_touch(touch_point_t *dp)
{
ft5406_touch_data_t touch_data;
_ft5406_read(0, &touch_data, sizeof(ft5406_touch_data_t));
FTDEBUG("GEST_ID: %02x, TD_STATUS: %02x\n", touch_data.GEST_ID, touch_data.TD_STATUS);
FTDEBUG("XH: %02x, XL: %02x, XH: %02x, XH: %02x, XH: %02x, RESERVED[0]: %02x, RESERVED[1]: %02x\n",
touch_data.TOUCH.XH, touch_data.TOUCH.XL,
touch_data.TOUCH.YH, touch_data.TOUCH.YL,
touch_data.TOUCH.RESERVED[0], touch_data.TOUCH.RESERVED[1]);
dp->TOUCH_X = TOUCH_POINT_GET_Y(touch_data.TOUCH);
dp->TOUCH_Y = TOUCH_POINT_GET_X(touch_data.TOUCH);
FTDEBUG(" ==> status : %d (%d, %d)\n", touch_data.TD_STATUS, dp->TOUCH_X, dp->TOUCH_Y);
if (touch_data.TD_STATUS != 0)
return 0;
else
return -1;
}
static void _touch_session()
{
touch_point_t tpd;
#ifdef RT_USING_RTGUI
struct rtgui_event_mouse emouse;
#endif
ft5406_read_touch(&tpd);
#ifdef RT_USING_RTGUI
emouse.parent.sender = RT_NULL;
emouse.wid = RT_NULL;
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN;
emouse.x = tpd.TOUCH_X;
emouse.y = tpd.TOUCH_Y;
emouse.ts = rt_tick_get();
emouse.id = emouse.ts;
if (emouse.id == 0) emouse.id = 1;
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#endif
do
{
rt_thread_delay(RT_TICK_PER_SECOND / BSP_TOUCH_SAMPLE_HZ);
if (ft5406_read_touch(&tpd) != 0)
break;
#ifdef RT_USING_RTGUI
emouse.parent.type = RTGUI_EVENT_MOUSE_MOTION;
emouse.x = tpd.TOUCH_X;
emouse.y = tpd.TOUCH_Y;
emouse.ts = rt_tick_get();
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#endif
}
while (1);
#ifdef RT_USING_RTGUI
/* Always send touch up event. */
emouse.parent.type = RTGUI_EVENT_MOUSE_BUTTON;
emouse.button = RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP;
emouse.x = tpd.TOUCH_X;
emouse.y = tpd.TOUCH_Y;
emouse.ts = rt_tick_get();
rtgui_server_post_event(&emouse.parent, sizeof(emouse));
#endif
//} while (rt_sem_take(&_tp_sem, TOUCH_SLP_TIME) == RT_EOK);
}
void touch_down(void)
{
rt_sem_release(&_tp_sem);
}
static void _touch(void *p)
{
int io_s;
gpio_pin_config_t pin_config =
{
kGPIO_DigitalInput, 0,
};
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_11_GPIO1_IO11, 0U);
/* Enable touch panel controller */
GPIO_PinInit(GPIO1, 11, &pin_config);
while(1)
{
rt_thread_delay(RT_TICK_PER_SECOND / 60);
io_s = GPIO_ReadPinInput(GPIO1, 11);
if (io_s == 0)
{
_touch_session();
}
else
continue;
}
}
static rt_device_t _i2c_find(const char *name)
{
rt_device_t dev;
dev = rt_device_find(name);
if (!dev)
{
rt_kprintf("search device failed: %s\n", name);
return RT_NULL;
}
if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
{
rt_kprintf("open device failed: %s\n", name);
return RT_NULL;
}
rt_kprintf("open i2c bus: %s\n", name);
return dev;
}
static void ft5406_hw_reset(void)
{
gpio_pin_config_t pin_config =
{
kGPIO_DigitalOutput, 0,
};
CLOCK_EnableClock(kCLOCK_Gpio1);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_02_GPIO1_IO02, 0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_02_GPIO1_IO02, 0x10B0u);
/* Enable touch panel controller */
GPIO_PinInit(GPIO1, 2, &pin_config);
GPIO_WritePinOutput(GPIO1, 2, 1);
rt_thread_delay(RT_TICK_PER_SECOND / 20);
GPIO_WritePinOutput(GPIO1, 2, 0);
rt_thread_delay(RT_TICK_PER_SECOND / 20);
GPIO_WritePinOutput(GPIO1, 2, 1);
}
int ft5406_hw_init(void)
{
rt_thread_t tid;
rt_device_t dev = _i2c_find(I2CBUS_NAME);
if (dev == RT_NULL)
{
FTDEBUG("search i2c device faild: %s\n", I2CBUS_NAME);
return -1;
}
else
{
FTDEBUG("ft5406 set i2c bus to %s\n", I2CBUS_NAME);
_i2c_bus = (struct rt_i2c_bus_device *)dev;
}
ft5406_hw_reset();
rt_sem_init(&_tp_sem, "touch", 0, RT_IPC_FLAG_FIFO);
tid = rt_thread_create("touch", _touch, RT_NULL, 2048, 10, 20);
if (!tid)
{
rt_device_close(dev);
return -1;
}
rt_thread_startup(tid);
return 0;
}
INIT_APP_EXPORT(ft5406_hw_init);
/*
* File : drv_i2c.c
* COPYRIGHT (C) 2006 - 2017, 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.
*
* Change Logs:
* Date Author Notes
* 2017-08-08 Yang the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "fsl_gpio.h"
#include "fsl_lpi2c.h"
//#define DRV_I2C_DEBUG
#ifdef RT_USING_I2C
#ifdef RT_USING_I2C_BITOPS
#define I2CBUS_NAME "i2c0"
struct stm32_i2c_bit_data
{
struct
{
GPIO_Type *base;
uint32_t pin;
} scl, sda;
};
static void gpio_udelay(rt_uint32_t us)
{
volatile rt_int32_t i;
for (; us > 0; us--)
{
i = 1000;
while (i--);
}
}
static void gpio_set_input(GPIO_Type* base, uint32_t pin)
{
if (base->GDIR & (1 << pin)) //output mode
{
base->GDIR &= ~(1 << pin);
gpio_udelay(5);
}
}
static void gpio_set_output(GPIO_Type* base, uint32_t pin)
{
if (!(base->GDIR & (1 << pin))) //input mode
{
base->GDIR |= (1 << pin);
gpio_udelay(5);
}
}
static void gpio_set_sda(void *data, rt_int32_t state)
{
struct stm32_i2c_bit_data *bd = data;
gpio_set_output(bd->sda.base, bd->sda.pin);
GPIO_PinWrite(bd->sda.base, bd->sda.pin, !!state);
}
static void gpio_set_scl(void *data, rt_int32_t state)
{
struct stm32_i2c_bit_data *bd = data;
gpio_set_output(bd->scl.base, bd->scl.pin);
GPIO_PinWrite(bd->scl.base, bd->scl.pin, !!state);
}
static rt_int32_t gpio_get_sda(void *data)
{
struct stm32_i2c_bit_data *bd = data;
gpio_set_input(bd->sda.base, bd->sda.pin);
return GPIO_ReadPinInput(bd->sda.base, bd->sda.pin);
}
static rt_int32_t gpio_get_scl(void *data)
{
struct stm32_i2c_bit_data *bd = data;
gpio_set_input(bd->scl.base, bd->scl.pin);
return GPIO_ReadPinInput(bd->scl.base, bd->scl.pin);
}
#else /* RT_USING_I2C_BITOPS */
// todo : add hardware i2c
#endif /* RT_USING_I2C_BITOPS */
int rt_hw_i2c_init(void)
{
#ifdef RT_USING_I2C_BITOPS
/* register I2C1: SCL/P0_20 SDA/P0_19 */
{
static struct rt_i2c_bus_device i2c_device;
static const struct stm32_i2c_bit_data _i2c_bdata =
{
/* SCL */ {GPIO1, 16},
/* SDA */ {GPIO1, 17},
};
static const struct rt_i2c_bit_ops _i2c_bit_ops =
{
(void*)&_i2c_bdata,
gpio_set_sda,
gpio_set_scl,
gpio_get_sda,
gpio_get_scl,
gpio_udelay,
50,
1000
};
gpio_pin_config_t pin_config = {
kGPIO_DigitalOutput, 0,
};
CLOCK_EnableClock(kCLOCK_Iomuxc);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_00_GPIO1_IO16, 1U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B1_00_GPIO1_IO16,
0xD8B0u); /* Slew Rate Field: Slow Slew Rate
Drive Strength Field: R0/6
Speed Field: medium(100MHz)
Open Drain Enable Field: Open Drain Enabled
Pull / Keep Enable Field: Pull/Keeper Enabled
Pull / Keep Select Field: Keeper
Pull Up / Down Config. Field: 22K Ohm Pull Up
Hyst. Enable Field: Hysteresis Disabled */
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_01_GPIO1_IO17, 1U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B1_01_GPIO1_IO17,
0xD8B0u); /* Slew Rate Field: Slow Slew Rate
Drive Strength Field: R0/6
Speed Field: medium(100MHz)
Open Drain Enable Field: Open Drain Enabled
Pull / Keep Enable Field: Pull/Keeper Enabled
Pull / Keep Select Field: Keeper
Pull Up / Down Config. Field: 22K Ohm Pull Up
Hyst. Enable Field: Hysteresis Disabled */
/* Enable touch panel controller */
GPIO_PinInit(_i2c_bdata.sda.base, _i2c_bdata.sda.pin, &pin_config);
GPIO_PinInit(_i2c_bdata.scl.base, _i2c_bdata.scl.pin, &pin_config);
GPIO_PortSet(_i2c_bdata.sda.base, _i2c_bdata.sda.pin);
GPIO_PortSet(_i2c_bdata.scl.base, _i2c_bdata.scl.pin);
//RT_ASSERT(gpio_get_scl(&_i2c_bdata) != 0);
//RT_ASSERT(gpio_get_sda(&_i2c_bdata) != 0);
i2c_device.priv = (void *)&_i2c_bit_ops;
rt_i2c_bit_add_bus(&i2c_device, I2CBUS_NAME);
} /* register I2C */
#else /* RT_USING_I2C_BITOPS */
// Todo : add hardware i2c
#endif /* RT_USING_I2C_BITOPS */
return 0;
}
INIT_DEVICE_EXPORT(rt_hw_i2c_init);
#if defined(RT_USING_FINSH) && defined(DRV_I2C_DEBUG)
#include <finsh.h>
static rt_device_t _i2c_find(const char *name)
{
rt_device_t dev;
dev = rt_device_find(name);
if (!dev)
{
rt_kprintf("search device failed: %s\n", name);
return RT_NULL;
}
if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) != RT_EOK)
{
rt_kprintf("open device failed: %s\n", name);
return RT_NULL;
}
rt_kprintf("open i2c bus: %s\n", name);
return dev;
}
static void _search_i2c_device(rt_device_t dev, uint8_t cmd)
{
int count = 0;
struct rt_i2c_msg msgs[2];
uint8_t buf = 0;
msgs[0].flags = RT_I2C_WR;
msgs[0].buf = &cmd;
msgs[0].len = sizeof(cmd);
msgs[1].flags = RT_I2C_RD;
msgs[1].buf = &buf;
msgs[1].len = 1;
for (int i = 0; i <= 0x7f; i++)
{
int len;
msgs[0].addr = i;
msgs[1].addr = i;
len = rt_i2c_transfer(dev, msgs, 2);
if (len == 2)
{
count++;
rt_kprintf("add:%02X transfer success, id: %02X\n", i, buf);
}
}
rt_kprintf("i2c device: %d\n", count);
}
static int i2c_test(const char *name, uint8_t cmd)
{
rt_device_t dev = _i2c_find(name);
if (dev == RT_NULL)
{
rt_kprintf("search i2c device faild\n");
return -1;
}
_search_i2c_device(dev, cmd);
rt_device_close(dev);
return 0;
}
FINSH_FUNCTION_EXPORT(i2c_test, e.g: i2c_test("i2c0", 0xA3));
#endif
#endif /* RT_USING_I2C */
此差异已折叠。
/*
* File : drv_i2c.c
* COPYRIGHT (C) 2006 - 2017, 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.
*
* Change Logs:
* Date Author Notes
* 2017-12-15 Tanek the first version
*/
#ifndef __DRV_LCD_H__
#define __DRV_LCD_H__
extern int imxrt_hw_lcd_init(void);
#endif
...@@ -85,11 +85,11 @@ ...@@ -85,11 +85,11 @@
#define RT_DFS_ELM_CODE_PAGE 437 #define RT_DFS_ELM_CODE_PAGE 437
#define RT_DFS_ELM_WORD_ACCESS #define RT_DFS_ELM_WORD_ACCESS
#define RT_DFS_ELM_USE_LFN_0 /* RT_DFS_ELM_USE_LFN_0 is not set */
/* RT_DFS_ELM_USE_LFN_1 is not set */ /* RT_DFS_ELM_USE_LFN_1 is not set */
/* RT_DFS_ELM_USE_LFN_2 is not set */ /* RT_DFS_ELM_USE_LFN_2 is not set */
/* RT_DFS_ELM_USE_LFN_3 is not set */ #define RT_DFS_ELM_USE_LFN_3
#define RT_DFS_ELM_USE_LFN 0 #define RT_DFS_ELM_USE_LFN 3
#define RT_DFS_ELM_MAX_LFN 255 #define RT_DFS_ELM_MAX_LFN 255
#define RT_DFS_ELM_DRIVES 2 #define RT_DFS_ELM_DRIVES 2
#define RT_DFS_ELM_MAX_SECTOR_SIZE 512 #define RT_DFS_ELM_MAX_SECTOR_SIZE 512
...@@ -108,7 +108,8 @@ ...@@ -108,7 +108,8 @@
#define RT_USING_SERIAL #define RT_USING_SERIAL
/* RT_USING_CAN is not set */ /* RT_USING_CAN is not set */
/* RT_USING_HWTIMER is not set */ /* RT_USING_HWTIMER is not set */
/* RT_USING_I2C is not set */ #define RT_USING_I2C
#define RT_USING_I2C_BITOPS
/* RT_USING_PIN is not set */ /* RT_USING_PIN is not set */
/* RT_USING_MTD_NOR is not set */ /* RT_USING_MTD_NOR is not set */
/* RT_USING_MTD_NAND is not set */ /* RT_USING_MTD_NAND is not set */
...@@ -143,7 +144,6 @@ ...@@ -143,7 +144,6 @@
#define RT_LWIP_DHCP #define RT_LWIP_DHCP
#define IP_SOF_BROADCAST 1 #define IP_SOF_BROADCAST 1
#define IP_SOF_BROADCAST_RECV 1 #define IP_SOF_BROADCAST_RECV 1
/* LWIP_USING_DHCPD is not set */
/* Static IPv4 Address */ /* Static IPv4 Address */
...@@ -154,8 +154,7 @@ ...@@ -154,8 +154,7 @@
#define RT_LWIP_TCP #define RT_LWIP_TCP
/* RT_LWIP_RAW is not set */ /* RT_LWIP_RAW is not set */
/* RT_LWIP_PPP is not set */ /* RT_LWIP_PPP is not set */
/* RT_LWIP_PPPOE is not set */ #define RT_MEMP_NUM_NETCONN 8
/* RT_LWIP_PPPOS is not set */
#define RT_LWIP_PBUF_NUM 16 #define RT_LWIP_PBUF_NUM 16
#define RT_LWIP_RAW_PCB_NUM 4 #define RT_LWIP_RAW_PCB_NUM 4
#define RT_LWIP_UDP_PCB_NUM 4 #define RT_LWIP_UDP_PCB_NUM 4
...@@ -179,11 +178,28 @@ ...@@ -179,11 +178,28 @@
/* Modbus master and slave stack */ /* Modbus master and slave stack */
/* RT_USING_MODBUS is not set */ /* RT_USING_MODBUS is not set */
/* LWIP_USING_DHCPD is not set */
/* RT_USING_NETUTILS is not set */ /* RT_USING_NETUTILS is not set */
/* RT-Thread UI Engine */ /* RT-Thread UI Engine */
/* RT_USING_GUIENGINE is not set */ #define RT_USING_GUIENGINE
#define RTGUI_NAME_MAX 16
#define RTGUI_USING_TTF
#define UTF8_TO_UNICODE
#define RTGUI_USING_FONT16
#define RTGUI_USING_FONT12
/* RTGUI_USING_FONTHZ is not set */
/* RTGUI_IMAGE_XPM is not set */
#define RTGUI_IMAGE_JPEG_NONE
/* RTGUI_IMAGE_JPEG is not set */
/* RTGUI_IMAGE_TJPGD is not set */
/* RTGUI_IMAGE_PNG_NONE is not set */
/* RTGUI_IMAGE_PNG is not set */
#define RTGUI_IMAGE_LODEPNG
/* RTGUI_IMAGE_BMP is not set */
#define RTGUI_IMAGE_CONTAINER
/* RTGUI_USING_DEMO is not set */
/* VBUS(Virtual Software BUS) */ /* VBUS(Virtual Software BUS) */
...@@ -216,6 +232,7 @@ ...@@ -216,6 +232,7 @@
/* PKG_USING_MBEDTLS is not set */ /* PKG_USING_MBEDTLS is not set */
/* PKG_USING_libsodium is not set */ /* PKG_USING_libsodium is not set */
/* PKG_USING_TINYCRYPT is not set */
/* language packages */ /* language packages */
...@@ -224,11 +241,14 @@ ...@@ -224,11 +241,14 @@
/* multimedia packages */ /* multimedia packages */
/* PKG_USING_OPENMV is not set */
/* tools packages */ /* tools packages */
/* PKG_USING_CMBACKTRACE is not set */ /* PKG_USING_CMBACKTRACE is not set */
/* PKG_USING_EASYLOGGER is not set */ /* PKG_USING_EASYLOGGER is not set */
/* PKG_USING_SYSTEMVIEW is not set */ /* PKG_USING_SYSTEMVIEW is not set */
/* PKG_USING_IPERF is not set */
/* miscellaneous packages */ /* miscellaneous packages */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册