From 1dad73405d74546abc59d0ef03e63b66bb00f3a7 Mon Sep 17 00:00:00 2001 From: Beslan Date: Mon, 24 Jan 2022 10:12:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B8=D0=BF=20=D0=BF=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D1=82=D0=B5=D1=80=D0=B0=20=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE?= =?UTF-8?q?=D0=BB=D1=87=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ili9341.cpp | 31 +++++++++---------------------- ili9341.h | 6 +++++- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/ili9341.cpp b/ili9341.cpp index b3d6dc5..8a0489d 100644 --- a/ili9341.cpp +++ b/ili9341.cpp @@ -3,10 +3,7 @@ #include "stm32f7xx_ll_spi.h" ILI9341::ILI9341(PinName MOSI, PinName MISO, PinName SCK, PinName DC, PinName RST) - : dispPort(MOSI, MISO, SCK) - , rst(RST) - , dc(DC) -{ + : dispPort(MOSI, MISO, SCK), rst(RST), dc(DC) { // dispPort = new SPI(MOSI, MISO, SCK); dispPort.frequency(27000000); dispPort.format(8, 3); @@ -69,6 +66,7 @@ ILI9341::ILI9341(PinName MOSI, PinName MISO, PinName SCK, PinName DC, PinName RS // LCD_WR_Data(0x28); //Поворот экрана на 180 градусов LCD_WR_REG(0x3a); // pixel format set LCD_WR_Data(0x55); //16bit /pixel + //----------------- frame rate------------------------------ LCD_WR_REG(0xb1); // frame rate @@ -147,19 +145,18 @@ ILI9341::ILI9341(PinName MOSI, PinName MISO, PinName SCK, PinName DC, PinName RS LCD_WR_REG(0x29); // display on } -void ILI9341::LCD_WR_Data(uint8_t Data) -{ +void ILI9341::LCD_WR_Data(uint8_t Data) { dc = 1; dispPort.write(Data); } -void ILI9341::LCD_WR_REG(uint8_t Reg) -{ +void ILI9341::LCD_WR_REG(uint8_t Reg) { dc = 0; dispPort.write(Reg); } -void ILI9341::LCD_setaddress(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) //set coordinate for print or other function +void +ILI9341::LCD_setaddress(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) //set coordinate for print or other function { LCD_WR_REG(0x2A); LCD_WR_Data(x1 >> 8); @@ -176,30 +173,20 @@ void ILI9341::LCD_setaddress(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) LCD_WR_REG(0x2C); //memory write } -void ILI9341::transmitData(const uint8_t* pixels, uint16_t x, uint16_t y, uint16_t w, uint16_t h) -{ +void ILI9341::transmitData(const uint8_t *pixels, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { uint32_t n_bytes = w * h; - // uint8_t lo = 0, hi = 0; - LCD_setaddress(x, y, x + w - 1, y + h - 1); - - // while (LL_SPI_IsActiveFlag_BSY(SPI1)) { - // } + LCD_setaddress(x, y, x + w - 1U, y + h - 1U); dc = 1; - - // LL_SPI_SetDataWidth((SPI_TypeDef*)SPIx, LL_SPI_DATAWIDTH_16BIT); dispPort.format(16, 3); while (n_bytes) { uint8_t lo = *pixels++; uint8_t hi = *pixels++; - // dispPort->write(hi << 8 | lo); - // dispPort->write(lo); while (!LL_SPI_IsActiveFlag_TXE(SPI1)) { } - LL_SPI_TransmitData16((SPI_TypeDef*)SPIx, hi << 8 | lo); + LL_SPI_TransmitData16(reinterpret_cast(SPIx), hi << 8 | lo); n_bytes--; } - // LL_SPI_SetDataWidth((SPI_TypeDef*)SPIx, LL_SPI_DATAWIDTH_8BIT); dispPort.format(8, 3); } diff --git a/ili9341.h b/ili9341.h index 1e5a941..b012309 100644 --- a/ili9341.h +++ b/ili9341.h @@ -6,13 +6,17 @@ class ILI9341 { public: ILI9341(PinName MOSI, PinName MISO, PinName SCK, PinName DC, PinName RST); - void transmitData(const uint8_t* pixels, uint16_t x, uint16_t y, uint16_t w, uint16_t h); + + void transmitData(const uint8_t *pixels, uint16_t x, uint16_t y, uint16_t w, uint16_t h); private: SPI dispPort; SPIName SPIx; + void LCD_WR_Data(uint8_t Data); + void LCD_WR_REG(uint8_t Reg); + void LCD_setaddress(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); DigitalOut rst; //(PB_1);