完善触摸和SPI_FLASH驱动

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@448 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
wuyangyong 2010-02-25 14:42:39 +00:00
parent fb7ecf70e9
commit db6aa746f6
3 changed files with 269 additions and 253 deletions

View File

@ -313,7 +313,7 @@ void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
ili9325_SetCursor(x,y); ili9325_SetCursor(x,y);
ili9325_WriteRAM_Prepare(); ili9325_WriteRAM_Prepare();
ili9325_WriteRAM(p); ili9325_RAM = p ;
} }
/* »ñÈ¡ÏñËصãÑÕÉ« */ /* »ñÈ¡ÏñËصãÑÕÉ« */
@ -339,7 +339,7 @@ void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_
ili9325_WriteRAM_Prepare(); /* Prepare to write GRAM */ ili9325_WriteRAM_Prepare(); /* Prepare to write GRAM */
while (x1 < x2) while (x1 < x2)
{ {
ili9325_WriteRAM(p); ili9325_RAM = p ;
x1++; x1++;
} }
} }
@ -359,7 +359,7 @@ void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t
ili9325_WriteRAM_Prepare(); /* Prepare to write GRAM */ ili9325_WriteRAM_Prepare(); /* Prepare to write GRAM */
while (y1 < y2) while (y1 < y2)
{ {
ili9325_WriteRAM(p); ili9325_RAM = p ;
y1++; y1++;
} }
} }
@ -379,7 +379,7 @@ void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt
ili9325_WriteRAM_Prepare(); /* Prepare to write GRAM */ ili9325_WriteRAM_Prepare(); /* Prepare to write GRAM */
while (x1 < x2) while (x1 < x2)
{ {
ili9325_WriteRAM( *ptr ); ili9325_RAM = *ptr ;
x1 ++; x1 ++;
ptr ++; ptr ++;
} }
@ -414,7 +414,7 @@ rt_err_t rt_hw_lcd_init(void)
ili9325_WriteRAM_Prepare(); ili9325_WriteRAM_Prepare();
for(test_y=0; test_y<76800; test_y++) for(test_y=0; test_y<76800; test_y++)
{ {
ili9325_WriteRAM(temp++); ili9325_RAM = temp++ ;
} }
/* read */ /* read */

View File

@ -31,7 +31,19 @@ static void GPIO_Configuration(void)
static unsigned char SPI_HostReadByte(void) static unsigned char SPI_HostReadByte(void)
{ {
return SPI_WriteByte(0x00); //return SPI_WriteByte(0x00);
//Wait until the transmit buffer is empty
//while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
while( (SPI1->SR & SPI_I2S_FLAG_TXE) == RESET);
// Send the byte
SPI_I2S_SendData(SPI1, 0);
//Wait until a data is received
//while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
while( (SPI1->SR & SPI_I2S_FLAG_RXNE) == RESET);
// Get the received data
return SPI_I2S_ReceiveData(SPI1);
} }
static void SPI_HostWriteByte(unsigned char wByte) static void SPI_HostWriteByte(unsigned char wByte)

View File

@ -1,15 +1,8 @@
#include "stm32f10x.h" #include "stm32f10x.h"
#include "rtthread.h" #include "rtthread.h"
#include "board.h"
static void Delay_Nus(unsigned int dt) #if (LCD_VERSION == 2)
{
volatile unsigned int a;
while (--dt)
{
for (a=0; a<5000; a++);
}
}
/* /*
MISO PA6 MISO PA6
MOSI PA7 MOSI PA7
@ -24,8 +17,8 @@ CS PC4
7 6 - 4 3 2 1-0 7 6 - 4 3 2 1-0
s A2-A0 MODE SER/DFR PD1-PD0 s A2-A0 MODE SER/DFR PD1-PD0
*/ */
#define TOUCH_MSR_X 0x90 //读X轴坐标指令 addr:1 #define TOUCH_MSR_Y 0x90 //读X轴坐标指令 addr:1
#define TOUCH_MSR_Y 0xD0 //读Y轴坐标指令 addr:3 #define TOUCH_MSR_X 0xD0 //读Y轴坐标指令 addr:3
extern unsigned char SPI_WriteByte(unsigned char data); extern unsigned char SPI_WriteByte(unsigned char data);
@ -36,15 +29,6 @@ static void WriteDataTo7843(unsigned char num)
SPI_WriteByte(num); SPI_WriteByte(num);
} }
//SPI 读数据
static unsigned int ReadDataFrom7843(void)
{
unsigned int temp;
temp = SPI_WriteByte(0x00)<<4;
temp |= ( (SPI_WriteByte(0x00)>>4)&0x0F );
return temp;
}
//´¥Ãþ´¦Àí //´¥Ãþ´¦Àí
void Go_Touch(void) void Go_Touch(void)
{ {
@ -52,12 +36,11 @@ void Go_Touch(void)
unsigned int Y; unsigned int Y;
CS_0(); CS_0();
WriteDataTo7843(TOUCH_MSR_X); //送控制字 10010000 即用差分方式读X坐标 详细请见有关资料 WriteDataTo7843(TOUCH_MSR_X | 1); /* 发送读X坐标命令并关闭中断 */
Delay_Nus(100); X = SPI_WriteByte(0x00)<<4; /* 读取第一字节MSB */
Y = ReadDataFrom7843(); //读X轴坐标 X |= ((SPI_WriteByte(TOUCH_MSR_Y | 1)>>4)&0x0F );/* 读取第二字节 同时发送读Y轴坐标命令行*/
WriteDataTo7843(TOUCH_MSR_Y); //送控制字 11010000 即用差分方式读Y坐标 详细请见有关资料 Y = SPI_WriteByte(0x00)<<4; /* 读取第一字节MSB */
Delay_Nus(50); Y |= ((SPI_WriteByte(1<<7)>>4)&0x0F ); /* 读取第二字节并重新打开中断 */
X = ReadDataFrom7843(); //读Y轴坐标
CS_1(); CS_1();
rt_kprintf("\r\nX: %04d Y: %04d",X,Y); rt_kprintf("\r\nX: %04d Y: %04d",X,Y);
@ -80,6 +63,15 @@ static void exti_int_config(void)
EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitTypeDef EXTI_InitStructure;
/* PB1 touch INT */ /* PB1 touch INT */
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource1); GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource1);
@ -96,10 +88,31 @@ static void exti_int_config(void)
#include <finsh.h> #include <finsh.h>
void touch_test(void) void touch_test(void)
{ {
SPI_InitTypeDef SPI_InitStructure;
rt_kprintf("\r\ntouch testing....\r\n"); rt_kprintf("\r\ntouch testing....\r\n");
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
/* Enable SPI_MASTER */
SPI_Cmd(SPI1, DISABLE);
/*------------------------ SPI1 configuration ------------------------*/
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;/* 72M/64=1.125M */
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_I2S_DeInit(SPI1);
SPI_Init(SPI1, &SPI_InitStructure);
/* Enable SPI_MASTER */
SPI_Cmd(SPI1, ENABLE);
NVIC_Configuration(); NVIC_Configuration();
exti_int_config(); exti_int_config();
@ -109,12 +122,6 @@ void touch_test(void)
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
@ -122,10 +129,8 @@ void touch_test(void)
GPIO_Init(GPIOC,&GPIO_InitStructure); GPIO_Init(GPIOC,&GPIO_InitStructure);
CS_1(); CS_1();
} }
Delay_Nus( 500 );
CS_0(); CS_0();
WriteDataTo7843(0x00); WriteDataTo7843( 1<<7 ); /* 打开中断 */
CS_1(); CS_1();
} }
FINSH_FUNCTION_EXPORT(touch_test, touch_test) FINSH_FUNCTION_EXPORT(touch_test, touch_test)
@ -135,5 +140,4 @@ void EXTI1_IRQHandler(void)
EXTI_ClearITPendingBit(EXTI_Line1); EXTI_ClearITPendingBit(EXTI_Line1);
Go_Touch(); Go_Touch();
} }
#endif
/******************* (C) COPYRIGHT 2008 STMicroelectronics */