2010-02-22 21:35:47 +08:00
|
|
|
|
#include "stm32f10x.h"
|
|
|
|
|
#include "rtthread.h"
|
2010-02-25 22:42:39 +08:00
|
|
|
|
#include "board.h"
|
2010-02-22 21:35:47 +08:00
|
|
|
|
|
2010-02-25 22:42:39 +08:00
|
|
|
|
#if (LCD_VERSION == 2)
|
2010-02-22 21:35:47 +08:00
|
|
|
|
/*
|
|
|
|
|
MISO PA6
|
|
|
|
|
MOSI PA7
|
|
|
|
|
CLK PA5
|
|
|
|
|
CS PC4
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define CS_0() GPIO_ResetBits(GPIOC,GPIO_Pin_4)
|
|
|
|
|
#define CS_1() GPIO_SetBits(GPIOC,GPIO_Pin_4)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
7 6 - 4 3 2 1-0
|
|
|
|
|
s A2-A0 MODE SER/DFR PD1-PD0
|
|
|
|
|
*/
|
2010-02-25 22:42:39 +08:00
|
|
|
|
#define TOUCH_MSR_Y 0x90 //<2F><>X<EFBFBD><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8> addr:1
|
|
|
|
|
#define TOUCH_MSR_X 0xD0 //<2F><>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8> addr:3
|
2010-02-22 21:35:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern unsigned char SPI_WriteByte(unsigned char data);
|
|
|
|
|
|
|
|
|
|
//SPIд<49><D0B4><EFBFBD><EFBFBD>
|
|
|
|
|
static void WriteDataTo7843(unsigned char num)
|
|
|
|
|
{
|
|
|
|
|
SPI_WriteByte(num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void Go_Touch(void)
|
|
|
|
|
{
|
|
|
|
|
unsigned int X;
|
|
|
|
|
unsigned int Y;
|
|
|
|
|
|
|
|
|
|
CS_0();
|
2010-02-25 22:42:39 +08:00
|
|
|
|
WriteDataTo7843(TOUCH_MSR_X | 1); /* <20><><EFBFBD>Ͷ<EFBFBD>X<EFBFBD><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1>ж<EFBFBD> */
|
|
|
|
|
X = SPI_WriteByte(0x00)<<4; /* <20><>ȡ<EFBFBD><C8A1>һ<EFBFBD>ֽ<EFBFBD>MSB */
|
|
|
|
|
X |= ((SPI_WriteByte(TOUCH_MSR_Y | 1)>>4)&0x0F );/* <20><>ȡ<EFBFBD>ڶ<EFBFBD><DAB6>ֽ<EFBFBD> ͬʱ<CDAC><CAB1><EFBFBD>Ͷ<EFBFBD>Y<EFBFBD><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|
|
|
|
Y = SPI_WriteByte(0x00)<<4; /* <20><>ȡ<EFBFBD><C8A1>һ<EFBFBD>ֽ<EFBFBD>MSB */
|
|
|
|
|
Y |= ((SPI_WriteByte(1<<7)>>4)&0x0F ); /* <20><>ȡ<EFBFBD>ڶ<EFBFBD><DAB6>ֽڲ<D6BD><DAB2><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD>ж<EFBFBD> */
|
2010-02-22 21:35:47 +08:00
|
|
|
|
CS_1();
|
|
|
|
|
|
|
|
|
|
rt_kprintf("\r\nX: %04d Y: %04d",X,Y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void NVIC_Configuration(void)
|
|
|
|
|
{
|
|
|
|
|
NVIC_InitTypeDef NVIC_InitStructure;
|
|
|
|
|
|
|
|
|
|
/* Enable the EXTI0 Interrupt */
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
|
|
|
NVIC_Init(&NVIC_InitStructure);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void exti_int_config(void)
|
|
|
|
|
{
|
|
|
|
|
EXTI_InitTypeDef EXTI_InitStructure;
|
|
|
|
|
|
|
|
|
|
/* PB1 touch INT */
|
2010-02-25 22:42:39 +08:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
2010-02-22 21:35:47 +08:00
|
|
|
|
|
|
|
|
|
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource1);
|
|
|
|
|
|
|
|
|
|
/* Configure EXTI */
|
|
|
|
|
EXTI_InitStructure.EXTI_Line = EXTI_Line1;
|
|
|
|
|
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
|
|
|
|
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//Falling<6E>½<EFBFBD><C2BD><EFBFBD> Rising<6E><67><EFBFBD><EFBFBD>
|
|
|
|
|
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
|
|
|
|
EXTI_Init(&EXTI_InitStructure);
|
|
|
|
|
|
|
|
|
|
EXTI_ClearITPendingBit(EXTI_Line1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include <finsh.h>
|
|
|
|
|
void touch_test(void)
|
|
|
|
|
{
|
2010-02-25 22:42:39 +08:00
|
|
|
|
SPI_InitTypeDef SPI_InitStructure;
|
|
|
|
|
|
2010-02-22 21:35:47 +08:00
|
|
|
|
rt_kprintf("\r\ntouch testing....\r\n");
|
|
|
|
|
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
|
|
|
|
|
|
2010-02-25 22:42:39 +08:00
|
|
|
|
/* 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);
|
2010-02-22 21:35:47 +08:00
|
|
|
|
|
|
|
|
|
NVIC_Configuration();
|
|
|
|
|
exti_int_config();
|
|
|
|
|
|
|
|
|
|
/* PC4 touch CS */
|
|
|
|
|
{
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
|
|
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
|
|
|
|
|
GPIO_Init(GPIOC,&GPIO_InitStructure);
|
|
|
|
|
CS_1();
|
|
|
|
|
}
|
|
|
|
|
CS_0();
|
2010-02-25 22:42:39 +08:00
|
|
|
|
WriteDataTo7843( 1<<7 ); /* <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD> */
|
2010-02-22 21:35:47 +08:00
|
|
|
|
CS_1();
|
|
|
|
|
}
|
|
|
|
|
FINSH_FUNCTION_EXPORT(touch_test, touch_test)
|
|
|
|
|
|
|
|
|
|
void EXTI1_IRQHandler(void)
|
|
|
|
|
{
|
|
|
|
|
EXTI_ClearITPendingBit(EXTI_Line1);
|
|
|
|
|
Go_Touch();
|
|
|
|
|
}
|
2010-02-25 22:42:39 +08:00
|
|
|
|
#endif
|