Touch pt. 1
This commit is contained in:
parent
22982db966
commit
46a5748e75
22 changed files with 3528 additions and 613 deletions
|
@ -24,6 +24,31 @@ void MainLoop()
|
|||
m.Loop();
|
||||
}
|
||||
|
||||
#define CMD_X_READ 0b10010000
|
||||
#define CMD_Y_READ 0b11010000
|
||||
|
||||
|
||||
uint8_t SpiIo(SPI_TypeDef *spi, uint8_t data)
|
||||
{
|
||||
while(!LL_SPI_IsActiveFlag_TXE(spi));
|
||||
LL_SPI_TransmitData8(spi, data);
|
||||
while(!LL_SPI_IsActiveFlag_RXNE(spi));
|
||||
return LL_SPI_ReceiveData8(spi);
|
||||
}
|
||||
|
||||
uint16_t ReadTouch(SPI_TypeDef *spi, bool x)
|
||||
{
|
||||
uint16_t tmp;
|
||||
|
||||
LL_GPIO_ResetOutputPin(TOUCH_CS_GPIO_Port, TOUCH_CS_Pin);
|
||||
SpiIo(spi, x ? CMD_X_READ: CMD_Y_READ);
|
||||
tmp = (uint16_t)SpiIo(spi, 0) << 8;
|
||||
tmp |= SpiIo(spi, 0);
|
||||
LL_GPIO_SetOutputPin(TOUCH_CS_GPIO_Port, TOUCH_CS_Pin);
|
||||
|
||||
return tmp >> 3;
|
||||
}
|
||||
|
||||
Application::Application()
|
||||
: GlobalsInitializer(&m_console)
|
||||
, m_console(USART1, DMA2, LL_DMA_STREAM_2, LL_DMA_STREAM_7, this, nullptr)
|
||||
|
@ -32,18 +57,18 @@ Application::Application()
|
|||
|
||||
void Application::Loop()
|
||||
{
|
||||
char buffer[32];
|
||||
char buffer[128];
|
||||
|
||||
Ili9341Fsmc &lcd(Ili9341Fsmc::Init(nullptr, nullptr, DMA2, LL_DMA_STREAM_4, false));
|
||||
lcd.SetScrollMode(true);
|
||||
|
||||
lcd.FillRect(Ili9341Fsmc::ILI9341_BLACK, false);
|
||||
|
||||
for(uint32_t l = 0; l < 100; ++l) {
|
||||
uitodec(buffer, l);
|
||||
lcd.Print(buffer);
|
||||
lcd.Print("\r\n");
|
||||
}
|
||||
LL_SPI_Enable(SPI2);
|
||||
|
||||
for(int i = 0; i < 100; ++i) {
|
||||
m_console.SendLine("Lofasz a seggedbe!\r\n");
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
if(m_received && m_transmitted) {
|
||||
|
@ -55,6 +80,22 @@ void Application::Loop()
|
|||
m_received = false;
|
||||
m_rcvdBuffer->busy = false;
|
||||
}
|
||||
|
||||
if(LL_GPIO_IsInputPinSet(PENIRQ_GPIO_Port, PENIRQ_Pin))
|
||||
LL_GPIO_SetOutputPin(LED1_GPIO_Port, LED1_Pin);
|
||||
else {
|
||||
LL_GPIO_ResetOutputPin(LED1_GPIO_Port, LED1_Pin);
|
||||
|
||||
uint16_t x = ReadTouch(SPI2, true);
|
||||
uint16_t y = ReadTouch(SPI2, false);
|
||||
unsigned len = strcpy_ex(buffer, "X: ");
|
||||
len += uitodec(buffer+len, x);
|
||||
len += strcpy_ex(buffer + len, ", Y: ");
|
||||
len += uitodec(buffer + len, y);
|
||||
len += strcpy_ex(buffer + len, "\r\n");
|
||||
lcd.Print(buffer, len);
|
||||
m_console.SendLine(buffer, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue