Первая рабочая программа с рисовальщиком. Тач откалиброван
This commit is contained in:
1464
Core/Src/Lcd/Fonts/font12.c
Normal file
1464
Core/Src/Lcd/Fonts/font12.c
Normal file
File diff suppressed because it is too large
Load Diff
1844
Core/Src/Lcd/Fonts/font16.c
Normal file
1844
Core/Src/Lcd/Fonts/font16.c
Normal file
File diff suppressed because it is too large
Load Diff
2223
Core/Src/Lcd/Fonts/font20.c
Normal file
2223
Core/Src/Lcd/Fonts/font20.c
Normal file
File diff suppressed because it is too large
Load Diff
2600
Core/Src/Lcd/Fonts/font24.c
Normal file
2600
Core/Src/Lcd/Fonts/font24.c
Normal file
File diff suppressed because it is too large
Load Diff
1084
Core/Src/Lcd/Fonts/font8.c
Normal file
1084
Core/Src/Lcd/Fonts/font8.c
Normal file
File diff suppressed because it is too large
Load Diff
134
Core/Src/Lcd/Fonts/fonts.h
Normal file
134
Core/Src/Lcd/Fonts/fonts.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file fonts.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief Header for fonts.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __FONTS_H
|
||||
#define __FONTS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
/** @addtogroup Utilities
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32_EVAL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Common
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup FONTS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup FONTS_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
typedef struct _tFont
|
||||
{
|
||||
const uint8_t *table;
|
||||
uint16_t Width;
|
||||
uint16_t Height;
|
||||
|
||||
} sFONT;
|
||||
|
||||
extern sFONT Font24;
|
||||
extern sFONT Font20;
|
||||
extern sFONT Font16;
|
||||
extern sFONT Font12;
|
||||
extern sFONT Font8;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup FONTS_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
#define LINE(x) ((x) * (((sFONT *)BSP_LCD_GetFont())->Height))
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup FONTS_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup FONTS_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FONTS_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
42
Core/Src/Lcd/bmp.h
Normal file
42
Core/Src/Lcd/bmp.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* bmp.h
|
||||
*
|
||||
* Created on: 2019. febr. 17.
|
||||
* Author: Benjami
|
||||
*/
|
||||
|
||||
#ifndef __BMP_H_
|
||||
#define __BMP_H_
|
||||
|
||||
typedef struct __attribute__((packed)) tagBITMAPFILEHEADER {
|
||||
uint16_t bfType;
|
||||
uint32_t bfSize;
|
||||
uint16_t bfReserved1;
|
||||
uint16_t bfReserved2;
|
||||
uint32_t bfOffBits;
|
||||
} BITMAPFILEHEADER; // size is 14 bytes
|
||||
|
||||
typedef struct __attribute__((packed)) tagBITMAPINFOHEADER {
|
||||
uint32_t biSize;
|
||||
uint32_t biWidth;
|
||||
uint32_t biHeight;
|
||||
uint16_t biPlanes;
|
||||
uint16_t biBitCount;
|
||||
uint32_t biCompression;
|
||||
uint32_t biSizeImage;
|
||||
uint32_t biXPelsPerMeter;
|
||||
uint32_t biYPelsPerMeter;
|
||||
uint32_t biClrUsed;
|
||||
uint32_t biClrImportant;
|
||||
} BITMAPINFOHEADER; // size is 40 bytes
|
||||
|
||||
typedef struct __attribute__((packed)) tagBITMAPSTRUCT {
|
||||
// offset 0, size 14
|
||||
BITMAPFILEHEADER fileHeader;
|
||||
// offset 14, size 40
|
||||
BITMAPINFOHEADER infoHeader;
|
||||
// offset 54, size X * Y words
|
||||
uint16_t data[];
|
||||
} BITMAPSTRUCT;
|
||||
|
||||
#endif /* __BMP_H_ */
|
||||
699
Core/Src/Lcd/ili9488.c
Normal file
699
Core/Src/Lcd/ili9488.c
Normal file
@@ -0,0 +1,699 @@
|
||||
#include "main.h"
|
||||
#include "lcd.h"
|
||||
#include "lcd_io.h"
|
||||
#include "ili9488.h"
|
||||
|
||||
void ili9488_Init(void);
|
||||
uint32_t ili9488_ReadID(void);
|
||||
void ili9488_DisplayOn(void);
|
||||
void ili9488_DisplayOff(void);
|
||||
void ili9488_SetCursor(uint16_t Xpos, uint16_t Ypos);
|
||||
void ili9488_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code);
|
||||
uint16_t ili9488_ReadPixel(uint16_t Xpos, uint16_t Ypos);
|
||||
void ili9488_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
|
||||
void ili9488_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
|
||||
void ili9488_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length);
|
||||
uint16_t ili9488_GetLcdPixelWidth(void);
|
||||
uint16_t ili9488_GetLcdPixelHeight(void);
|
||||
void ili9488_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp);
|
||||
void ili9488_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint16_t *pData);
|
||||
void ili9488_ReadRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint16_t *pData);
|
||||
void ili9488_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint16_t RGBCode);
|
||||
void ili9488_Scroll(int16_t Scroll, uint16_t TopFix, uint16_t BottonFix);
|
||||
void ili9488_UserCommand(uint16_t Command, uint8_t * pData, uint32_t Size, uint8_t Mode);
|
||||
|
||||
LCD_DrvTypeDef ili9488_drv =
|
||||
{
|
||||
ili9488_Init,
|
||||
ili9488_ReadID,
|
||||
ili9488_DisplayOn,
|
||||
ili9488_DisplayOff,
|
||||
ili9488_SetCursor,
|
||||
ili9488_WritePixel,
|
||||
ili9488_ReadPixel,
|
||||
ili9488_SetDisplayWindow,
|
||||
ili9488_DrawHLine,
|
||||
ili9488_DrawVLine,
|
||||
ili9488_GetLcdPixelWidth,
|
||||
ili9488_GetLcdPixelHeight,
|
||||
ili9488_DrawBitmap,
|
||||
ili9488_DrawRGBImage,
|
||||
ili9488_FillRect,
|
||||
ili9488_ReadRGBImage,
|
||||
ili9488_Scroll,
|
||||
ili9488_UserCommand
|
||||
};
|
||||
|
||||
LCD_DrvTypeDef *lcd_drv = &ili9488_drv;
|
||||
|
||||
/* transaction data */
|
||||
#define TRANSDATAMAXSIZE 4
|
||||
union
|
||||
{
|
||||
char c[TRANSDATAMAXSIZE];
|
||||
uint8_t d8[TRANSDATAMAXSIZE];
|
||||
uint16_t d16[TRANSDATAMAXSIZE / 2];
|
||||
}transdata;
|
||||
|
||||
#define ILI9488_NOP 0x00
|
||||
#define ILI9488_SWRESET 0x01
|
||||
#define ILI9488_RDDID 0x04
|
||||
#define ILI9488_RDDST 0x09
|
||||
|
||||
#define ILI9488_SLPIN 0x10
|
||||
#define ILI9488_SLPOUT 0x11
|
||||
#define ILI9488_PTLON 0x12
|
||||
#define ILI9488_NORON 0x13
|
||||
|
||||
#define ILI9488_RDMODE 0x0A
|
||||
#define ILI9488_RDMADCTL 0x0B
|
||||
#define ILI9488_RDPIXFMT 0x0C
|
||||
#define ILI9488_RDIMGFMT 0x0D
|
||||
#define ILI9488_RDSELFDIAG 0x0F
|
||||
|
||||
#define ILI9488_INVOFF 0x20
|
||||
#define ILI9488_INVON 0x21
|
||||
#define ILI9488_GAMMASET 0x26
|
||||
#define ILI9488_DISPOFF 0x28
|
||||
#define ILI9488_DISPON 0x29
|
||||
|
||||
#define ILI9488_CASET 0x2A
|
||||
#define ILI9488_PASET 0x2B
|
||||
#define ILI9488_RAMWR 0x2C
|
||||
#define ILI9488_RAMRD 0x2E
|
||||
|
||||
#define ILI9488_PTLAR 0x30
|
||||
#define ILI9488_VSCRDEF 0x33
|
||||
#define ILI9488_MADCTL 0x36
|
||||
#define ILI9488_VSCRSADD 0x37
|
||||
#define ILI9488_PIXFMT 0x3A
|
||||
#define ILI9488_RAMWRCONT 0x3C
|
||||
#define ILI9488_RAMRDCONT 0x3E
|
||||
|
||||
#define ILI9488_IMCTR 0xB0
|
||||
#define ILI9488_FRMCTR1 0xB1
|
||||
#define ILI9488_FRMCTR2 0xB2
|
||||
#define ILI9488_FRMCTR3 0xB3
|
||||
#define ILI9488_INVCTR 0xB4
|
||||
#define ILI9488_DFUNCTR 0xB6
|
||||
|
||||
#define ILI9488_PWCTR1 0xC0
|
||||
#define ILI9488_PWCTR2 0xC1
|
||||
#define ILI9488_PWCTR3 0xC2
|
||||
#define ILI9488_PWCTR4 0xC3
|
||||
#define ILI9488_PWCTR5 0xC4
|
||||
#define ILI9488_VMCTR1 0xC5
|
||||
#define ILI9488_VMCTR2 0xC7
|
||||
|
||||
#define ILI9488_RDID1 0xDA
|
||||
#define ILI9488_RDID2 0xDB
|
||||
#define ILI9488_RDID3 0xDC
|
||||
#define ILI9488_RDID4 0xDD
|
||||
|
||||
#define ILI9488_GMCTRP1 0xE0
|
||||
#define ILI9488_GMCTRN1 0xE1
|
||||
#define ILI9488_IMGFUNCT 0xE9
|
||||
|
||||
#define ILI9488_ADJCTR3 0xF7
|
||||
|
||||
#define ILI9488_MAD_RGB 0x00
|
||||
#define ILI9488_MAD_BGR 0x08
|
||||
#define ILI9488_MAD_VREFRORD 0x10
|
||||
#define ILI9488_MAD_HREFRORD 0x04
|
||||
|
||||
#define ILI9488_MAD_VERTICAL 0x20
|
||||
#define ILI9488_MAD_X_LEFT 0x00
|
||||
#define ILI9488_MAD_X_RIGHT 0x40
|
||||
#define ILI9488_MAD_Y_UP 0x80
|
||||
#define ILI9488_MAD_Y_DOWN 0x00
|
||||
|
||||
#if ILI9488_COLORMODE == 0
|
||||
#define ILI9488_MAD_COLORMODE ILI9488_MAD_RGB
|
||||
#elif ILI9488_COLORMODE == 1
|
||||
#define ILI9488_MAD_COLORMODE ILI9488_MAD_BGR
|
||||
#endif
|
||||
|
||||
#define ILI9488_SETWINDOW(x1, x2, y1, y2) \
|
||||
{ transdata.d16[0] = x1; transdata.d16[1] = x2; LCD_IO_WriteCmd8MultipleData16(ILI9488_CASET, (uint16_t *)&transdata, 2); \
|
||||
transdata.d16[0] = y1; transdata.d16[1] = y2; LCD_IO_WriteCmd8MultipleData16(ILI9488_PASET, (uint16_t *)&transdata, 2); }
|
||||
|
||||
#define ILI9488_SETCURSOR(x, y) \
|
||||
{ transdata.d16[0] = x; transdata.d16[1] = transdata.d16[0]; LCD_IO_WriteCmd8MultipleData16(ILI9488_CASET, (uint16_t *)&transdata, 2); \
|
||||
transdata.d16[0] = y; transdata.d16[1] = transdata.d16[0]; LCD_IO_WriteCmd8MultipleData16(ILI9488_PASET, (uint16_t *)&transdata, 2); }
|
||||
|
||||
/* the drawing directions of the 4 orientations */
|
||||
#if ILI9488_ORIENTATION == 0
|
||||
#define ILI9488_MAX_X (ILI9488_LCD_PIXEL_WIDTH - 1)
|
||||
#define ILI9488_MAX_Y (ILI9488_LCD_PIXEL_HEIGHT - 1)
|
||||
#define ILI9488_MAD_DATA_RIGHT_THEN_UP (ILI9488_MAD_COLORMODE | ILI9488_MAD_X_RIGHT | ILI9488_MAD_Y_UP)
|
||||
#define ILI9488_MAD_DATA_RIGHT_THEN_DOWN (ILI9488_MAD_COLORMODE | ILI9488_MAD_X_RIGHT | ILI9488_MAD_Y_DOWN)
|
||||
#elif ILI9488_ORIENTATION == 1
|
||||
#define ILI9488_MAX_X (ILI9488_LCD_PIXEL_HEIGHT - 1)
|
||||
#define ILI9488_MAX_Y (ILI9488_LCD_PIXEL_WIDTH - 1)
|
||||
#define ILI9488_MAD_DATA_RIGHT_THEN_UP (ILI9488_MAD_COLORMODE | ILI9488_MAD_X_RIGHT | ILI9488_MAD_Y_DOWN | ILI9488_MAD_VERTICAL)
|
||||
#define ILI9488_MAD_DATA_RIGHT_THEN_DOWN (ILI9488_MAD_COLORMODE | ILI9488_MAD_X_LEFT | ILI9488_MAD_Y_DOWN | ILI9488_MAD_VERTICAL)
|
||||
#elif ILI9488_ORIENTATION == 2
|
||||
#define ILI9488_MAX_X (ILI9488_LCD_PIXEL_WIDTH - 1)
|
||||
#define ILI9488_MAX_Y (ILI9488_LCD_PIXEL_HEIGHT - 1)
|
||||
#define ILI9488_MAD_DATA_RIGHT_THEN_UP (ILI9488_MAD_COLORMODE | ILI9488_MAD_X_LEFT | ILI9488_MAD_Y_DOWN)
|
||||
#define ILI9488_MAD_DATA_RIGHT_THEN_DOWN (ILI9488_MAD_COLORMODE | ILI9488_MAD_X_LEFT | ILI9488_MAD_Y_UP)
|
||||
#elif ILI9488_ORIENTATION == 3
|
||||
#define ILI9488_MAX_X (ILI9488_LCD_PIXEL_HEIGHT - 1)
|
||||
#define ILI9488_MAX_Y (ILI9488_LCD_PIXEL_WIDTH - 1)
|
||||
#define ILI9488_MAD_DATA_RIGHT_THEN_UP (ILI9488_MAD_COLORMODE | ILI9488_MAD_X_LEFT | ILI9488_MAD_Y_UP | ILI9488_MAD_VERTICAL)
|
||||
#define ILI9488_MAD_DATA_RIGHT_THEN_DOWN (ILI9488_MAD_COLORMODE | ILI9488_MAD_X_RIGHT | ILI9488_MAD_Y_UP | ILI9488_MAD_VERTICAL)
|
||||
#endif
|
||||
|
||||
#if ILI9488_INTERFACE == 0 || ILI9488_INTERFACE == 1
|
||||
static uint16_t yStart, yEnd;
|
||||
|
||||
#define SETWINDOW(x1, x2, y1, y2) ILI9488_SETWINDOW(x1, x2, y1, y2)
|
||||
#define SETCURSOR(x, y) ILI9488_SETCURSOR(x, y)
|
||||
|
||||
#elif ILI9488_INTERFACE == 2
|
||||
#if ILI9488_ORIENTATION == 0
|
||||
#define SETWINDOW(x1, x2, y1, y2) ILI9488_SETWINDOW(ILI9488_MAX_X - (x2), ILI9488_MAX_X - (x1), y1, y2)
|
||||
#define SETCURSOR(x, y) ILI9488_SETCURSOR(ILI9488_MAX_X - (x), y)
|
||||
#elif ILI9488_ORIENTATION == 1
|
||||
#define SETWINDOW(x1, x2, y1, y2) ILI9488_SETWINDOW(x1, x2, y1, y2)
|
||||
#define SETCURSOR(x, y) ILI9488_SETCURSOR(x, y)
|
||||
#elif ILI9488_ORIENTATION == 2
|
||||
#define SETWINDOW(x1, x2, y1, y2) ILI9488_SETWINDOW(x1, x2, ILI9488_MAX_Y - (y2), ILI9488_MAX_Y - (y1))
|
||||
#define SETCURSOR(x, y) ILI9488_SETCURSOR(x, ILI9488_MAX_Y - (y))
|
||||
#elif ILI9488_ORIENTATION == 3
|
||||
#define SETWINDOW(x1, x2, y1, y2) ILI9488_SETWINDOW(ILI9488_MAX_X - (x2), ILI9488_MAX_X - (x1), ILI9488_MAX_Y - (y2), ILI9488_MAX_Y - (y1))
|
||||
#define SETCURSOR(x, y) ILI9488_SETCURSOR(ILI9488_MAX_X - (x), ILI9488_MAX_Y - (y))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef LCD_REVERSE16
|
||||
#define LCD_REVERSE16 0
|
||||
#endif
|
||||
|
||||
#define ILI9488_LCD_INITIALIZED 0x01
|
||||
#define ILI9488_IO_INITIALIZED 0x02
|
||||
static uint8_t Is_ili9488_Initialized = 0;
|
||||
|
||||
const uint8_t EntryRightThenUp = ILI9488_MAD_DATA_RIGHT_THEN_UP;
|
||||
const uint8_t EntryRightThenDown = ILI9488_MAD_DATA_RIGHT_THEN_DOWN;
|
||||
|
||||
/* the last set drawing direction is stored here */
|
||||
uint8_t LastEntry = ILI9488_MAD_DATA_RIGHT_THEN_DOWN;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Pixel draw and read functions */
|
||||
|
||||
#if ILI9488_WRITEBITDEPTH == ILI9488_READBITDEPTH
|
||||
/* 16/16 and 24/24 bit, no need to change bitdepth data */
|
||||
#define SetWriteDir()
|
||||
#define SetReadDir()
|
||||
#else /* #if ILI9488_WRITEBITDEPTH == ILI9488_READBITDEPTH */
|
||||
uint8_t lastdir = 0;
|
||||
#if ILI9488_WRITEBITDEPTH == 16
|
||||
/* 16/24 bit */
|
||||
#define SetWriteDir() { \
|
||||
if(lastdir != 0) \
|
||||
{ \
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_PIXFMT, "\55", 1); \
|
||||
lastdir = 0; \
|
||||
} }
|
||||
#define SetReadDir() { \
|
||||
if(lastdir == 0) \
|
||||
{ \
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_PIXFMT, "\66", 1); \
|
||||
lastdir = 1; \
|
||||
} }
|
||||
#elif ILI9488_WRITEBITDEPTH == 24
|
||||
/* 24/16 bit */
|
||||
#define SetWriteDir() { \
|
||||
if(lastdir != 0) \
|
||||
{ \
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_PIXFMT, "\66", 1); \
|
||||
lastdir = 0; \
|
||||
} }
|
||||
#define SetReadDir() { \
|
||||
if(lastdir == 0) \
|
||||
{ \
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_PIXFMT, "\55", 1); \
|
||||
lastdir = 1; \
|
||||
} }
|
||||
#endif /* #elif ILI9488_WRITEBITDEPTH == 24 */
|
||||
#endif /* #else ILI9488_WRITEBITDEPTH == ILI9488_READBITDEPTH */
|
||||
|
||||
#if ILI9488_WRITEBITDEPTH == 16
|
||||
#if LCD_REVERSE16 == 0
|
||||
#define LCD_IO_DrawFill(Color, Size) { \
|
||||
SetWriteDir(); \
|
||||
LCD_IO_WriteCmd8DataFill16(ILI9488_RAMWR, Color, Size); } /* Fill 16 bit pixel(s) */
|
||||
#define LCD_IO_DrawBitmap(pData, Size) { \
|
||||
SetWriteDir(); \
|
||||
LCD_IO_WriteCmd8MultipleData16(ILI9488_RAMWR, pData, Size); } /* Draw 16 bit bitmap */
|
||||
#elif LCD_REVERSE16 == 1
|
||||
#define LCD_IO_DrawFill(Color, Size) { \
|
||||
SetWriteDir(); \
|
||||
LCD_IO_WriteCmd8DataFill16r(ILI9488_RAMWR, Color, Size); } /* Fill 16 bit pixel(s) */
|
||||
#define LCD_IO_DrawBitmap(pData, Size) { \
|
||||
SetWriteDir(); \
|
||||
LCD_IO_WriteCmd8MultipleData16r(ILI9488_RAMWR, pData, Size); } /* Draw 16 bit bitmap */
|
||||
#endif /* #else LCD_REVERSE16 == 0 */
|
||||
#elif ILI9488_WRITEBITDEPTH == 24
|
||||
#define LCD_IO_DrawFill(Color, Size) { \
|
||||
SetWriteDir(); \
|
||||
LCD_IO_WriteCmd8DataFill16to24(ILI9488_RAMWR, Color, Size); } /* Fill 24 bit pixel(s) from 16 bit color code */
|
||||
#define LCD_IO_DrawBitmap(pData, Size) { \
|
||||
SetWriteDir(); \
|
||||
LCD_IO_WriteCmd8MultipleData16to24(ILI9488_RAMWR, pData, Size); } /* Draw 24 bit Lcd bitmap from 16 bit bitmap data */
|
||||
#endif /* #elif ILI9488_WRITEBITDEPTH == 24 */
|
||||
|
||||
#if ILI9488_READBITDEPTH == 16
|
||||
#if LCD_REVERSE16 == 0
|
||||
#define LCD_IO_ReadBitmap(pData, Size) { \
|
||||
SetReadDir(); \
|
||||
LCD_IO_ReadCmd8MultipleData16(ILI9488_RAMRD, pData, Size, 1); } /* Read 16 bit LCD */
|
||||
#elif LCD_REVERSE16 == 1
|
||||
#define LCD_IO_ReadBitmap(pData, Size) { \
|
||||
SetReadDir(); \
|
||||
LCD_IO_ReadCmd8MultipleData16r(ILI9488_RAMRD, pData, Size, 1); } /* Read 16 bit LCD */
|
||||
#endif /* #else LCD_REVERSE16 == 0 */
|
||||
#elif ILI9488_READBITDEPTH == 24
|
||||
#define LCD_IO_ReadBitmap(pData, Size) { \
|
||||
SetReadDir(); \
|
||||
LCD_IO_ReadCmd8MultipleData24to16(ILI9488_RAMRD, pData, Size, 1); } /* Read 24 bit Lcd and convert to 16 bit bitmap */
|
||||
#endif /* #elif ILI9488_READBITDEPTH == 24 */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void ili9488_Init(void)
|
||||
{
|
||||
if((Is_ili9488_Initialized & ILI9488_LCD_INITIALIZED) == 0)
|
||||
{
|
||||
Is_ili9488_Initialized |= ILI9488_LCD_INITIALIZED;
|
||||
if((Is_ili9488_Initialized & ILI9488_IO_INITIALIZED) == 0)
|
||||
LCD_IO_Init();
|
||||
Is_ili9488_Initialized |= ILI9488_IO_INITIALIZED;
|
||||
}
|
||||
|
||||
LCD_Delay(105);
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_SWRESET, NULL, 0);
|
||||
LCD_Delay(5);
|
||||
// positive gamma control
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_GMCTRP1, (uint8_t *)"\x00\x01\x02\x04\x14\x09\x3F\x57\x4D\x05\x0B\x09\x1A\x1D\x0F", 15);
|
||||
// negative gamma control
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_GMCTRN1, (uint8_t *)"\x00\x1D\x20\x02\x0E\x03\x35\x12\x47\x02\x0D\x0C\x38\x39\x0F", 15);
|
||||
// Power Control 1 (Vreg1out, Verg2out)
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_PWCTR1, (uint8_t *)"\x17\x15", 2);
|
||||
LCD_Delay(5);
|
||||
// Power Control 2 (VGH,VGL)
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_PWCTR2, (uint8_t *)"\x41", 1);
|
||||
LCD_Delay(5);
|
||||
// Power Control 3 (Vcom)
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_VMCTR1, (uint8_t *)"\x00\x12\x80", 3);
|
||||
LCD_Delay(5);
|
||||
#if ILI9488_WRITEBITDEPTH == 16
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_PIXFMT, (uint8_t *)"\x55", 1); // Interface Pixel Format (16 bit)
|
||||
#elif ILI9488_WRITEBITDEPTH == 24
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_PIXFMT, (uint8_t *)"\x66", 1); // Interface Pixel Format (24 bit)
|
||||
#endif
|
||||
#if ILI9488_INTERFACE == 0
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_IMCTR, (uint8_t *)"\x80", 1); // Interface Mode Control (SDO NOT USE)
|
||||
#elif ILI9488_INTERFACE == 1
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_IMCTR, (uint8_t *)"\x00", 1); // Interface Mode Control (SDO USE)
|
||||
#endif
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_FRMCTR1, (uint8_t *)"\xA0", 1); // Frame rate (60Hz)
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_INVCTR, (uint8_t *)"\x02", 1); // Display Inversion Control (2-dot)
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_DFUNCTR, (uint8_t *)"\x02\x02", 2); // Display Function Control RGB/MCU Interface Control
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_IMGFUNCT, (uint8_t *)"\x01", 1); // Set Image Functio (Disable 24 bit data)
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_ADJCTR3, (uint8_t *)"\xA9\x51\x2C\x82", 4); // Adjust Control (D7 stream, loose)
|
||||
LCD_Delay(5);
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_SLPOUT, NULL, 0); // Exit Sleep
|
||||
LCD_Delay(120);
|
||||
#if ILI9488_INITCLEAR == 1
|
||||
ili9488_FillRect(0, 0, ILI9488_MAX_X + 1, ILI9488_MAX_Y + 1, 0x0000);
|
||||
LCD_Delay(1);
|
||||
#endif
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_DISPON, NULL, 0); // Display on
|
||||
LCD_Delay(5);
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_MADCTL, &EntryRightThenDown, 1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Enables the Display.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_DisplayOn(void)
|
||||
{
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_SLPOUT, NULL, 0); // Exit Sleep
|
||||
LCD_IO_Bl_OnOff(1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Disables the Display.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_DisplayOff(void)
|
||||
{
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_SLPIN, NULL, 0); // Sleep
|
||||
LCD_IO_Bl_OnOff(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Get the LCD pixel Width.
|
||||
* @param None
|
||||
* @retval The Lcd Pixel Width
|
||||
*/
|
||||
uint16_t ili9488_GetLcdPixelWidth(void)
|
||||
{
|
||||
return ILI9488_MAX_X + 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Get the LCD pixel Height.
|
||||
* @param None
|
||||
* @retval The Lcd Pixel Height
|
||||
*/
|
||||
uint16_t ili9488_GetLcdPixelHeight(void)
|
||||
{
|
||||
return ILI9488_MAX_Y + 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Get the ILI9488 ID.
|
||||
* @param None
|
||||
* @retval The ILI9488 ID
|
||||
*/
|
||||
uint32_t ili9488_ReadID(void)
|
||||
{
|
||||
uint32_t id = 0;
|
||||
|
||||
if(Is_ili9488_Initialized == 0)
|
||||
{
|
||||
ili9488_Init();
|
||||
}
|
||||
LCD_IO_ReadCmd8MultipleData8(0x04, (uint8_t *)&id, 3, 1);
|
||||
return id;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Set Cursor position.
|
||||
* @param Xpos: specifies the X position.
|
||||
* @param Ypos: specifies the Y position.
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_SetCursor(uint16_t Xpos, uint16_t Ypos)
|
||||
{
|
||||
SETCURSOR(Xpos, Ypos);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Write pixel.
|
||||
* @param Xpos: specifies the X position.
|
||||
* @param Ypos: specifies the Y position.
|
||||
* @param RGBCode: the RGB pixel color
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
|
||||
{
|
||||
if(LastEntry != ILI9488_MAD_DATA_RIGHT_THEN_DOWN)
|
||||
{
|
||||
LastEntry = ILI9488_MAD_DATA_RIGHT_THEN_DOWN;
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_MADCTL, &EntryRightThenDown, 1);
|
||||
}
|
||||
SETCURSOR(Xpos, Ypos);
|
||||
LCD_IO_DrawFill(RGBCode, 1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Read pixel.
|
||||
* @param None
|
||||
* @retval the RGB pixel color
|
||||
*/
|
||||
uint16_t ili9488_ReadPixel(uint16_t Xpos, uint16_t Ypos)
|
||||
{
|
||||
uint16_t ret;
|
||||
if(LastEntry != ILI9488_MAD_DATA_RIGHT_THEN_DOWN)
|
||||
{
|
||||
LastEntry = ILI9488_MAD_DATA_RIGHT_THEN_DOWN;
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_MADCTL, &EntryRightThenDown, 1);
|
||||
}
|
||||
SETCURSOR(Xpos, Ypos);
|
||||
LCD_IO_ReadBitmap(&ret, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Sets a display window
|
||||
* @param Xpos: specifies the X bottom left position.
|
||||
* @param Ypos: specifies the Y bottom left position.
|
||||
* @param Height: display window height.
|
||||
* @param Width: display window width.
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
|
||||
{
|
||||
#if ILI9488_INTERFACE == 0 || ILI9488_INTERFACE == 1
|
||||
yStart = Ypos; yEnd = Ypos + Height - 1;
|
||||
#endif
|
||||
SETWINDOW(Xpos, Xpos + Width - 1, Ypos, Ypos + Height - 1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Draw vertical line.
|
||||
* @param RGBCode: Specifies the RGB color
|
||||
* @param Xpos: specifies the X position.
|
||||
* @param Ypos: specifies the Y position.
|
||||
* @param Length: specifies the Line length.
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
|
||||
{
|
||||
if(LastEntry != ILI9488_MAD_DATA_RIGHT_THEN_DOWN)
|
||||
{
|
||||
LastEntry = ILI9488_MAD_DATA_RIGHT_THEN_DOWN;
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_MADCTL, &EntryRightThenDown, 1);
|
||||
}
|
||||
ili9488_FillRect(Xpos, Ypos, Length, 1, RGBCode);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Draw vertical line.
|
||||
* @param RGBCode: Specifies the RGB color
|
||||
* @param Xpos: specifies the X position.
|
||||
* @param Ypos: specifies the Y position.
|
||||
* @param Length: specifies the Line length.
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
|
||||
{
|
||||
if(LastEntry != ILI9488_MAD_DATA_RIGHT_THEN_DOWN)
|
||||
{
|
||||
LastEntry = ILI9488_MAD_DATA_RIGHT_THEN_DOWN;
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_MADCTL, &EntryRightThenDown, 1);
|
||||
}
|
||||
ili9488_FillRect(Xpos, Ypos, 1, Length, RGBCode);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Draw Filled rectangle
|
||||
* @param Xpos: specifies the X position.
|
||||
* @param Ypos: specifies the Y position.
|
||||
* @param Xsize: specifies the X size
|
||||
* @param Ysize: specifies the Y size
|
||||
* @param RGBCode: specifies the RGB color
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint16_t RGBCode)
|
||||
{
|
||||
if(LastEntry != ILI9488_MAD_DATA_RIGHT_THEN_DOWN)
|
||||
{
|
||||
LastEntry = ILI9488_MAD_DATA_RIGHT_THEN_DOWN;
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_MADCTL, &EntryRightThenDown, 1);
|
||||
}
|
||||
ili9488_SetDisplayWindow(Xpos, Ypos, Xsize, Ysize);
|
||||
LCD_IO_DrawFill(RGBCode, Xsize * Ysize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Displays a 16bit bitmap picture..
|
||||
* @param BmpAddress: Bmp picture address.
|
||||
* @param Xpos: Bmp X position in the LCD
|
||||
* @param Ypos: Bmp Y position in the LCD
|
||||
* @retval None
|
||||
* @brief Draw direction: right then up
|
||||
*/
|
||||
void ili9488_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
|
||||
{
|
||||
uint32_t index = 0, size = 0;
|
||||
/* Read bitmap size */
|
||||
Ypos += pbmp[22] + (pbmp[23] << 8) - 1;
|
||||
size = *(volatile uint16_t *) (pbmp + 2);
|
||||
size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
|
||||
/* Get bitmap data address offset */
|
||||
index = *(volatile uint16_t *) (pbmp + 10);
|
||||
index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
|
||||
size = (size - index)/2;
|
||||
pbmp += index;
|
||||
|
||||
if(LastEntry != ILI9488_MAD_DATA_RIGHT_THEN_UP)
|
||||
{
|
||||
LastEntry = ILI9488_MAD_DATA_RIGHT_THEN_UP;
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_MADCTL, &EntryRightThenUp, 1);
|
||||
}
|
||||
#if ILI9488_INTERFACE == 0 || ILI9488_INTERFACE == 1
|
||||
transdata.d16[0] = ILI9488_MAX_Y - yEnd;
|
||||
transdata.d16[1] = ILI9488_MAX_Y - yStart;
|
||||
LCD_IO_WriteCmd8MultipleData16(ILI9488_PASET, &transdata, 2);
|
||||
LCD_IO_DrawBitmap(pbmp, size);
|
||||
#elif ILI9488_INTERFACE == 2
|
||||
LCD_IO_DrawBitmap(pbmp, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Displays 16bit/pixel picture..
|
||||
* @param pdata: picture address.
|
||||
* @param Xpos: Image X position in the LCD
|
||||
* @param Ypos: Image Y position in the LCD
|
||||
* @param Xsize: Image X size in the LCD
|
||||
* @param Ysize: Image Y size in the LCD
|
||||
* @retval None
|
||||
* @brief Draw direction: right then down
|
||||
*/
|
||||
void ili9488_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint16_t *pData)
|
||||
{
|
||||
if(LastEntry != ILI9488_MAD_DATA_RIGHT_THEN_DOWN)
|
||||
{
|
||||
LastEntry = ILI9488_MAD_DATA_RIGHT_THEN_DOWN;
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_MADCTL, &EntryRightThenDown, 1);
|
||||
}
|
||||
ili9488_SetDisplayWindow(Xpos, Ypos, Xsize, Ysize);
|
||||
LCD_IO_DrawBitmap(pData, Xsize * Ysize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Read 16bit/pixel vitmap from Lcd..
|
||||
* @param pdata: picture address.
|
||||
* @param Xpos: Image X position in the LCD
|
||||
* @param Ypos: Image Y position in the LCD
|
||||
* @param Xsize: Image X size in the LCD
|
||||
* @param Ysize: Image Y size in the LCD
|
||||
* @retval None
|
||||
* @brief Draw direction: right then down
|
||||
*/
|
||||
void ili9488_ReadRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint16_t *pData)
|
||||
{
|
||||
if(LastEntry != ILI9488_MAD_DATA_RIGHT_THEN_DOWN)
|
||||
{
|
||||
LastEntry = ILI9488_MAD_DATA_RIGHT_THEN_DOWN;
|
||||
LCD_IO_WriteCmd8MultipleData8(ILI9488_MADCTL, &EntryRightThenDown, 1);
|
||||
}
|
||||
ili9488_SetDisplayWindow(Xpos, Ypos, Xsize, Ysize);
|
||||
LCD_IO_ReadBitmap(pData, Xsize * Ysize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Set display scroll parameters
|
||||
* @param Scroll : Scroll size [pixel]
|
||||
* @param TopFix : Top fix size [pixel]
|
||||
* @param BottonFix : Botton fix size [pixel]
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_Scroll(int16_t Scroll, uint16_t TopFix, uint16_t BottonFix)
|
||||
{
|
||||
static uint16_t scrparam[4] = {0, 0, 0, 0};
|
||||
#if (ILI9488_ORIENTATION == 0)
|
||||
if((TopFix != scrparam[1]) || (BottonFix != scrparam[3]))
|
||||
{
|
||||
scrparam[1] = TopFix;
|
||||
scrparam[3] = BottonFix;
|
||||
scrparam[2] = ILI9488_LCD_PIXEL_HEIGHT - TopFix - BottonFix;
|
||||
LCD_IO_WriteCmd8MultipleData16(ILI9488_VSCRDEF, &scrparam[1], 3);
|
||||
}
|
||||
Scroll = (0 - Scroll) % scrparam[2];
|
||||
if(Scroll < 0)
|
||||
Scroll = scrparam[2] + Scroll + scrparam[1];
|
||||
else
|
||||
Scroll = Scroll + scrparam[1];
|
||||
#elif (ILI9488_ORIENTATION == 1)
|
||||
if((TopFix != scrparam[1]) || (BottonFix != scrparam[3]))
|
||||
{
|
||||
scrparam[1] = TopFix;
|
||||
scrparam[3] = BottonFix;
|
||||
scrparam[2] = ILI9488_LCD_PIXEL_HEIGHT - TopFix - BottonFix;
|
||||
LCD_IO_WriteCmd8MultipleData16(ILI9488_VSCRDEF, &scrparam[1], 3);
|
||||
}
|
||||
Scroll = (0 - Scroll) % scrparam[2];
|
||||
if(Scroll < 0)
|
||||
Scroll = scrparam[2] + Scroll + scrparam[1];
|
||||
else
|
||||
Scroll = Scroll + scrparam[1];
|
||||
#elif (ILI9488_ORIENTATION == 2)
|
||||
if((TopFix != scrparam[3]) || (BottonFix != scrparam[1]))
|
||||
{
|
||||
scrparam[3] = TopFix;
|
||||
scrparam[1] = BottonFix;
|
||||
scrparam[2] = ILI9488_LCD_PIXEL_HEIGHT - TopFix - BottonFix;
|
||||
LCD_IO_WriteCmd8MultipleData16(ILI9488_VSCRDEF, &scrparam[1], 3);
|
||||
}
|
||||
Scroll %= scrparam[2];
|
||||
if(Scroll < 0)
|
||||
Scroll = scrparam[2] + Scroll + scrparam[1];
|
||||
else
|
||||
Scroll = Scroll + scrparam[1];
|
||||
#elif (ILI9488_ORIENTATION == 3)
|
||||
if((TopFix != scrparam[3]) || (BottonFix != scrparam[1]))
|
||||
{
|
||||
scrparam[3] = TopFix;
|
||||
scrparam[1] = BottonFix;
|
||||
scrparam[2] = ILI9488_LCD_PIXEL_HEIGHT - TopFix - BottonFix;
|
||||
LCD_IO_WriteCmd8MultipleData16(ILI9488_VSCRDEF, &scrparam[1], 3);
|
||||
}
|
||||
Scroll %= scrparam[2];
|
||||
if(Scroll < 0)
|
||||
Scroll = scrparam[2] + Scroll + scrparam[1];
|
||||
else
|
||||
Scroll = Scroll + scrparam[1];
|
||||
#endif
|
||||
if(Scroll != scrparam[0])
|
||||
{
|
||||
scrparam[0] = Scroll;
|
||||
LCD_IO_WriteCmd8DataFill16(ILI9488_VSCRSADD, scrparam[0], 1);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief User command
|
||||
* @param Command : Lcd command
|
||||
* @param pData : data pointer
|
||||
* @param Size : data number
|
||||
* @param Mode : 0=write 8bits datas, 1=0=write 16bits datas, 2=read 8bits datas, 3=read 16bits datas
|
||||
* @retval None
|
||||
*/
|
||||
void ili9488_UserCommand(uint16_t Command, uint8_t* pData, uint32_t Size, uint8_t Mode)
|
||||
{
|
||||
if(Mode == 0)
|
||||
LCD_IO_WriteCmd8MultipleData8((uint8_t)Command, pData, Size);
|
||||
else if(Mode == 1)
|
||||
LCD_IO_WriteCmd8MultipleData16((uint8_t)Command, pData, Size);
|
||||
else if(Mode == 2)
|
||||
LCD_IO_ReadCmd8MultipleData8((uint8_t)Command, pData, Size, 1);
|
||||
else if(Mode == 3)
|
||||
LCD_IO_ReadCmd8MultipleData16((uint8_t)Command, pData, Size, 1);
|
||||
}
|
||||
32
Core/Src/Lcd/ili9488.h
Normal file
32
Core/Src/Lcd/ili9488.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* LCD interface type
|
||||
- 0: SPI half duplex (the mosi pin is bidirectional mode)
|
||||
- 1: SPI full duplex (write = mosi pin, read = miso pin)
|
||||
- 2: paralell 8 bit interface */
|
||||
#define ILI9488_INTERFACE 1
|
||||
|
||||
/* Orientation:
|
||||
- 0: 320x480 micro-sd in the top (portrait)
|
||||
- 1: 480x320 micro-sd in the left (landscape)
|
||||
- 2: 320x480 micro-sd in the bottom (portrait)
|
||||
- 3: 480x320 micro-sd in the right (landscape) */
|
||||
#define ILI9488_ORIENTATION 2
|
||||
|
||||
/* To clear the screen before display turning on ?
|
||||
- 0: does not clear
|
||||
- 1: clear */
|
||||
#define ILI9488_INITCLEAR 1
|
||||
|
||||
/* Color order
|
||||
- 0: RGB
|
||||
- 1: BGR */
|
||||
#define ILI9488_COLORMODE 1
|
||||
|
||||
/* Draw and read bitdeph (16: RGB565, 24: RGB888)
|
||||
note: my SPI ILI9488 LCD can only work in 24/24 bit depth
|
||||
my paralell 8 bit ILI9488 LCD can work in 16/16, 16/24, 24/16, 24/24 bit depth */
|
||||
#define ILI9488_WRITEBITDEPTH 24
|
||||
#define ILI9488_READBITDEPTH 24
|
||||
|
||||
/* ILI9488 Size (physical resolution in default orientation) */
|
||||
#define ILI9488_LCD_PIXEL_WIDTH 320
|
||||
#define ILI9488_LCD_PIXEL_HEIGHT 480
|
||||
101
Core/Src/Lcd/lcd.h
Normal file
101
Core/Src/Lcd/lcd.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file lcd.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.1
|
||||
* @date 21-July-2015
|
||||
* @brief This file contains all the functions prototypes for the LCD driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modify:
|
||||
- ReadID return type: uint16_t to uint32_t (there is a display that has a 24-bit ID)
|
||||
- Add the LCD_REVERSE16 macro (so that dma can be used on the fsmc 8-bit interface for bitmap drawing)
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __LCD_H
|
||||
#define __LCD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
/* Setting section (please set the necessary things in this section) */
|
||||
|
||||
/* 16bit/pixel data byte order
|
||||
- 0: no change (default)
|
||||
- 1: change
|
||||
note: Enter a value of 1 only if you use an 8-bit fmsc IO driver and want to use DMA to draw bitmap images.
|
||||
The filling operation is DMA capable even with a value of 0.
|
||||
attention: the byte order should also be in reverse order in memory blocks containing images,
|
||||
because the displayed image will be incorrect. This is necessary because DMA can only write to the
|
||||
fsmc 8-bit peripheral in ascending byte order, but the LCD display requires reverse pixel byte order. */
|
||||
#define LCD_REVERSE16 0
|
||||
|
||||
//=============================================================================
|
||||
/* Interface section */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void (*Init)(void);
|
||||
uint32_t (*ReadID)(void);
|
||||
void (*DisplayOn)(void);
|
||||
void (*DisplayOff)(void);
|
||||
void (*SetCursor)(uint16_t, uint16_t);
|
||||
void (*WritePixel)(uint16_t, uint16_t, uint16_t);
|
||||
uint16_t (*ReadPixel)(uint16_t, uint16_t);
|
||||
|
||||
void (*SetDisplayWindow)(uint16_t, uint16_t, uint16_t, uint16_t);
|
||||
void (*DrawHLine)(uint16_t, uint16_t, uint16_t, uint16_t);
|
||||
void (*DrawVLine)(uint16_t, uint16_t, uint16_t, uint16_t);
|
||||
|
||||
uint16_t (*GetLcdPixelWidth)(void);
|
||||
uint16_t (*GetLcdPixelHeight)(void);
|
||||
void (*DrawBitmap)(uint16_t, uint16_t, uint8_t*);
|
||||
void (*DrawRGBImage)(uint16_t, uint16_t, uint16_t, uint16_t, uint16_t*);
|
||||
void (*FillRect)(uint16_t, uint16_t, uint16_t, uint16_t, uint16_t);
|
||||
void (*ReadRGBImage)(uint16_t, uint16_t, uint16_t, uint16_t, uint16_t*);
|
||||
void (*Scroll)(int16_t, uint16_t, uint16_t);
|
||||
void (*UserCommand)(uint16_t, uint8_t*, uint32_t, uint8_t);
|
||||
}LCD_DrvTypeDef;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __LCD_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
119
Core/Src/Lcd/lcd_io.h
Normal file
119
Core/Src/Lcd/lcd_io.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* lcd_io.h
|
||||
*
|
||||
* Created on: 2022.11
|
||||
* Author: Benjami
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __LCD_IO_H
|
||||
#define __LCD_IO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lcd.h"
|
||||
|
||||
//=============================================================================
|
||||
/* Interface section */
|
||||
|
||||
/* Mode bits */
|
||||
#define LCD_IO_CMD8 (1 << 0)
|
||||
#define LCD_IO_CMD16 (1 << 1)
|
||||
|
||||
#define LCD_IO_WRITE (1 << 2)
|
||||
#define LCD_IO_READ (1 << 3)
|
||||
|
||||
#define LCD_IO_DATA8 (1 << 4)
|
||||
#define LCD_IO_DATA16 (1 << 5)
|
||||
#define LCD_IO_DATA24TO16 (1 << 6) /* at read */
|
||||
#define LCD_IO_DATA16TO24 (1 << 6) /* at write */
|
||||
|
||||
#define LCD_IO_MULTIDATA (1 << 7)
|
||||
#define LCD_IO_FILL (1 << 8)
|
||||
|
||||
#define LCD_IO_REVERSE16 (1 << 9)
|
||||
/* LCD_IO_REVERSE16 only FMC/FSMC 8 bit IO interface
|
||||
note: DMA on the 8-bit FMC interface is only possible in low byte->high byte order.
|
||||
The displays, on the other hand, request it in order high byte->low byte.
|
||||
If we still want to use DMA, the color codes must be stored in reverse byte order in the bitmap memory.
|
||||
With this switch, we can signal LCD_IO to do a color code transaction in reverse order,
|
||||
so it can also use DMA for bitmap drawing. */
|
||||
|
||||
/* Link function for LCD peripheral */
|
||||
void LCD_Delay (uint32_t delay);
|
||||
void LCD_IO_Init(void);
|
||||
void LCD_IO_Bl_OnOff(uint8_t Bl);
|
||||
void LCD_IO_Transaction(uint16_t Cmd, uint8_t *pData, uint32_t Size, uint32_t DummySize, uint32_t Mode);
|
||||
|
||||
/* 8 bit write commands */
|
||||
#define LCD_IO_WriteCmd8DataFill16(Cmd, Data, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)&Data, Size, 0, LCD_IO_CMD8 | LCD_IO_WRITE | LCD_IO_DATA16 | LCD_IO_FILL)
|
||||
#define LCD_IO_WriteCmd8DataFill16to24(Cmd, Data, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)&Data, Size, 0, LCD_IO_CMD8 | LCD_IO_WRITE | LCD_IO_DATA16TO24 | LCD_IO_FILL)
|
||||
#define LCD_IO_WriteCmd8MultipleData8(Cmd, pData, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, 0, LCD_IO_CMD8 | LCD_IO_WRITE | LCD_IO_DATA8 | LCD_IO_MULTIDATA)
|
||||
#define LCD_IO_WriteCmd8MultipleData16(Cmd, pData, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, 0, LCD_IO_CMD8 | LCD_IO_WRITE | LCD_IO_DATA16 | LCD_IO_MULTIDATA)
|
||||
#define LCD_IO_WriteCmd8MultipleData16to24(Cmd, pData, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, 0, LCD_IO_CMD8 | LCD_IO_WRITE | LCD_IO_DATA16TO24 | LCD_IO_MULTIDATA)
|
||||
|
||||
/* 16 bit write commands */
|
||||
#define LCD_IO_WriteCmd16DataFill16(Cmd, Data, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)&Data, Size, 0, LCD_IO_CMD16 | LCD_IO_WRITE | LCD_IO_DATA16 | LCD_IO_FILL)
|
||||
#define LCD_IO_WriteCmd16DataFill16to24(Cmd, Data, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)&Data, Size, 0, LCD_IO_CMD16 | LCD_IO_WRITE | LCD_IO_DATA16TO24 | LCD_IO_FILL)
|
||||
#define LCD_IO_WriteCmd16MultipleData8(Cmd, pData, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, 0, LCD_IO_CMD16 | LCD_IO_WRITE | LCD_IO_DATA8 | LCD_IO_MULTIDATA)
|
||||
#define LCD_IO_WriteCmd16MultipleData16(Cmd, pData, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, 0, LCD_IO_CMD16 | LCD_IO_WRITE | LCD_IO_DATA16 | LCD_IO_MULTIDATA)
|
||||
#define LCD_IO_WriteCmd16MultipleData16to24(Cmd, pData, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, 0, LCD_IO_CMD16 | LCD_IO_WRITE | LCD_IO_DATA16TO24 | LCD_IO_MULTIDATA)
|
||||
|
||||
/* 8 bit read commands */
|
||||
#define LCD_IO_ReadCmd8MultipleData8(Cmd, pData, Size, DummySize) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, DummySize, LCD_IO_CMD8 | LCD_IO_READ | LCD_IO_DATA8 | LCD_IO_MULTIDATA)
|
||||
#define LCD_IO_ReadCmd8MultipleData16(Cmd, pData, Size, DummySize) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, DummySize, LCD_IO_CMD8 | LCD_IO_READ | LCD_IO_DATA16 | LCD_IO_MULTIDATA)
|
||||
#define LCD_IO_ReadCmd8MultipleData24to16(Cmd, pData, Size, DummySize) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, DummySize, LCD_IO_CMD8 | LCD_IO_READ | LCD_IO_DATA24TO16 | LCD_IO_MULTIDATA)
|
||||
|
||||
/* 16 bit read commands */
|
||||
#define LCD_IO_ReadCmd16MultipleData8(Cmd, pData, Size, DummySize) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, DummySize, LCD_IO_CMD16 | LCD_IO_READ | LCD_IO_DATA8 | LCD_IO_MULTIDATA)
|
||||
#define LCD_IO_ReadCmd16MultipleData16(Cmd, pData, Size, DummySize) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, DummySize, LCD_IO_CMD16 | LCD_IO_READ | LCD_IO_DATA16 | LCD_IO_MULTIDATA)
|
||||
#define LCD_IO_ReadCmd16MultipleData24to16(Cmd, pData, Size, DummySize) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, DummySize, LCD_IO_CMD16 | LCD_IO_READ | LCD_IO_DATA24TO16 | LCD_IO_MULTIDATA)
|
||||
|
||||
/* 8 and 16 bit write and read commands with reverse byte order 16 bit data (only 16bitdepth pixel data in FSMC 8 bit io interface) */
|
||||
/* 8 bit write commands */
|
||||
#define LCD_IO_WriteCmd8DataFill16r(Cmd, Data, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)&Data, Size, 0, LCD_IO_CMD8 | LCD_IO_WRITE | LCD_IO_DATA16 | LCD_IO_FILL | LCD_IO_REVERSE16)
|
||||
#define LCD_IO_WriteCmd8DataFill16to24r(Cmd, Data, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)&Data, Size, 0, LCD_IO_CMD8 | LCD_IO_WRITE | LCD_IO_DATA16TO24 | LCD_IO_FILL | LCD_IO_REVERSE16)
|
||||
#define LCD_IO_WriteCmd8MultipleData16r(Cmd, pData, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, 0, LCD_IO_CMD8 | LCD_IO_WRITE | LCD_IO_DATA16 | LCD_IO_MULTIDATA | LCD_IO_REVERSE16)
|
||||
#define LCD_IO_WriteCmd8MultipleData16to24r(Cmd, pData, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, 0, LCD_IO_CMD8 | LCD_IO_WRITE | LCD_IO_DATA16TO24 | LCD_IO_MULTIDATA | LCD_IO_REVERSE16)
|
||||
|
||||
/* 16 bit write commands */
|
||||
#define LCD_IO_WriteCmd16DataFill16r(Cmd, Data, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)&Data, Size, 0, LCD_IO_CMD16 | LCD_IO_WRITE | LCD_IO_DATA16 | LCD_IO_FILL | LCD_IO_REVERSE16)
|
||||
#define LCD_IO_WriteCmd16MultipleData16r(Cmd, pData, Size) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, 0, LCD_IO_CMD16 | LCD_IO_WRITE | LCD_IO_DATA16 | LCD_IO_MULTIDATA | LCD_IO_REVERSE16)
|
||||
|
||||
/* 8 bit read commands */
|
||||
#define LCD_IO_ReadCmd8MultipleData16r(Cmd, pData, Size, DummySize) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, DummySize, LCD_IO_CMD8 | LCD_IO_READ | LCD_IO_DATA16 | LCD_IO_MULTIDATA | LCD_IO_REVERSE16)
|
||||
|
||||
/* 16 bit read commands */
|
||||
#define LCD_IO_ReadCmd16MultipleData16r(Cmd, pData, Size, DummySize) \
|
||||
LCD_IO_Transaction((uint16_t)Cmd, (uint8_t *)pData, Size, DummySize, LCD_IO_CMD16 | LCD_IO_READ | LCD_IO_DATA16 | LCD_IO_MULTIDATA | LCD_IO_REVERSE16)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SRC_LCD_LCD_IO_H_ */
|
||||
946
Core/Src/Lcd/lcd_io_spi_hal.c
Normal file
946
Core/Src/Lcd/lcd_io_spi_hal.c
Normal file
@@ -0,0 +1,946 @@
|
||||
/*
|
||||
* SPI HAL LCD driver for all stm32 family
|
||||
* author: Roberto Benjami
|
||||
* v.2023.04
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <stdio.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "lcd.h"
|
||||
#include "lcd_io.h"
|
||||
#include "lcd_io_spi_hal.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#define DMA_MINSIZE 0x0010
|
||||
#define DMA_MAXSIZE 0xFFFE
|
||||
/* note:
|
||||
- DMA_MINSIZE: if the transacion Size < DMA_MINSIZE -> not use the DMA for transaction
|
||||
- DMA_MAXSIZE: if the transacion Size > DMA_MAXSIZE -> multiple DMA transactions (because DMA transaction size register is 16bit) */
|
||||
|
||||
#define LCD_SPI_TIMEOUT HAL_MAX_DELAY
|
||||
/* note:
|
||||
- LCD_SPI_TIMEOUT: HAL_SPI_Transmit and HAL_SPI_Receive timeout value */
|
||||
|
||||
/* SPI clock pin default state */
|
||||
#define LCD_SPI_DEFSTATE 0
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Bitdepth convert macros */
|
||||
#if LCD_RGB24_ORDER == 0
|
||||
#define RGB565TO888(c16) ((c16 & 0xF800) << 8) | ((c16 & 0x07E0) << 5) | ((c16 & 0x001F) << 3)
|
||||
#define RGB888TO565(c24) ((c24 & 0XF80000) >> 8 | (c24 & 0xFC00) >> 5 | (c24 & 0xF8 ) >> 3)
|
||||
#elif LCD_RGB24_ORDER == 1
|
||||
#define RGB565TO888(c16) ((c16 & 0xF800) >> 8) | ((c16 & 0x07E0) << 5) | ((c16 & 0x001F) << 19)
|
||||
#define RGB888TO565(c24) ((c24 & 0XF80000) >> 19 | (c24 & 0xFC00) >> 5 | (c24 & 0xF8 ) << 8)
|
||||
#endif
|
||||
|
||||
/* processor family dependent things */
|
||||
#if defined(STM32C0)
|
||||
#include "stm32c0xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32F0)
|
||||
#include "stm32f0xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32F1)
|
||||
#include "stm32f1xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) hlcdspi.Instance->CR1 &= ~SPI_CR1_DFF
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) hlcdspi.Instance->CR1 |= SPI_CR1_DFF
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32F2)
|
||||
#include "stm32f2xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) hlcdspi.Instance->CR1 &= ~SPI_CR1_DFF
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) hlcdspi.Instance->CR1 |= SPI_CR1_DFF
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32F3)
|
||||
#include "stm32f3xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32F4)
|
||||
#include "stm32f4xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) hlcdspi.Instance->CR1 &= ~SPI_CR1_DFF
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) hlcdspi.Instance->CR1 |= SPI_CR1_DFF
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32F7)
|
||||
#include "stm32f7xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32H5)
|
||||
#include "stm32h5xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CFG1, SPI_CFG1_DSIZE, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CFG1, SPI_CFG1_DSIZE, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CFG1, SPI_CFG1_MBR, br << SPI_CFG1_MBR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXP) dummy = hlcdspi.Instance->RXDR
|
||||
#elif defined(STM32H7)
|
||||
#include "stm32h7xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CFG1, SPI_CFG1_DSIZE, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CFG1, SPI_CFG1_DSIZE, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CFG1, SPI_CFG1_MBR, br << SPI_CFG1_MBR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXP) dummy = hlcdspi.Instance->RXDR
|
||||
#elif defined(STM32G0)
|
||||
#include "stm32g0xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32G4)
|
||||
#include "stm32g4xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32L0)
|
||||
#include "stm32l0xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) hlcdspi.Instance->CR1 &= ~SPI_CR1_DFF
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) hlcdspi.Instance->CR1 |= SPI_CR1_DFF
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32L1)
|
||||
#include "stm32l1xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) hlcdspi.Instance->CR1 &= ~SPI_CR1_DFF
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) hlcdspi.Instance->CR1 |= SPI_CR1_DFF
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32L4)
|
||||
#include "stm32l4xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32L5)
|
||||
#include "stm32l5xx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32WB)
|
||||
#include "stm32wbxx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#elif defined(STM32WBA)
|
||||
#include "stm32wbaxx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CFG1, SPI_CFG1_DSIZE, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CFG1, SPI_CFG1_DSIZE, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CFG1, SPI_CFG1_MBR, br << SPI_CFG1_MBR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXP) dummy = hlcdspi.Instance->RXDR
|
||||
#elif defined(STM32WL)
|
||||
#include "stm32wlxx_ll_gpio.h"
|
||||
#define LCD_SPI_SETDATASIZE_8BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_8BIT)
|
||||
#define LCD_SPI_SETDATASIZE_16BIT(hlcdspi) MODIFY_REG(hlcdspi.Instance->CR2, SPI_CR2_DS, SPI_DATASIZE_16BIT)
|
||||
#define LCD_SPI_SETBAUDRATE(hlcdspi, br) MODIFY_REG(hlcdspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#define LCD_SPI_RXFIFOCLEAR(hlcdspi, dummy) while(hlcdspi.Instance->SR & SPI_SR_RXNE) dummy = hlcdspi.Instance->DR
|
||||
#else
|
||||
#error unknown processor family
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
extern SPI_HandleTypeDef LCD_SPI_HANDLE;
|
||||
|
||||
#if LCD_RGB24_BUFFSIZE < DMA_MINSIZE
|
||||
#undef LCD_RGB24_BUFFSIZE
|
||||
#define LCD_RGB24_BUFFSIZE 0
|
||||
#else
|
||||
uint8_t lcd_rgb24_buffer[LCD_RGB24_BUFFSIZE * 3 + 1];
|
||||
#endif /* #else LCD_RGB24_DMA_BUFFERSIZE < DMA_MINSIZE */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#if LCD_SPI_MODE == 0
|
||||
/* Transmit only mode */
|
||||
|
||||
#define LcdDirRead()
|
||||
#define LcdDirWrite()
|
||||
|
||||
#elif (LCD_SPI_MODE == 1) || (LCD_SPI_MODE == 2)
|
||||
/* Half duplex and full duplex mode */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Switch from SPI write mode to SPI read mode, read the dummy bits, modify the SPI speed */
|
||||
void LcdDirRead(uint32_t DummySize)
|
||||
{
|
||||
uint32_t RxDummy __attribute__((unused));
|
||||
__HAL_SPI_DISABLE(&LCD_SPI_HANDLE); /* stop SPI */
|
||||
#if LCD_SPI_MODE == 1
|
||||
SPI_1LINE_RX(&LCD_SPI_HANDLE); /* if half duplex -> change MOSI data direction */
|
||||
#endif
|
||||
LL_GPIO_SetPinMode(LCD_SCK_GPIO_Port, LCD_SCK_Pin, LL_GPIO_MODE_OUTPUT); /* GPIO mode = output */
|
||||
while(DummySize--)
|
||||
{ /* Dummy pulses */
|
||||
HAL_GPIO_WritePin(LCD_SCK_GPIO_Port, LCD_SCK_Pin, 1 - LCD_SPI_DEFSTATE);
|
||||
HAL_GPIO_WritePin(LCD_SCK_GPIO_Port, LCD_SCK_Pin, LCD_SPI_DEFSTATE);
|
||||
}
|
||||
LL_GPIO_SetPinMode(LCD_SCK_GPIO_Port, LCD_SCK_Pin, LL_GPIO_MODE_ALTERNATE); /* GPIO mode = alternative */
|
||||
#if defined(LCD_SPI_SPD_WRITE) && defined(LCD_SPI_SPD_READ) && (LCD_SPI_SPD_WRITE != LCD_SPI_SPD_READ)
|
||||
LCD_SPI_SETBAUDRATE(LCD_SPI_HANDLE, LCD_SPI_SPD_READ); /* speed change */
|
||||
#endif
|
||||
LCD_SPI_RXFIFOCLEAR(LCD_SPI_HANDLE, RxDummy); /* RX fifo clear */
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Switch from SPI read mode to SPI write mode, modify the SPI speed */
|
||||
void LcdDirWrite(void)
|
||||
{
|
||||
__HAL_SPI_DISABLE(&LCD_SPI_HANDLE); /* stop SPI */
|
||||
#if defined(LCD_SPI_SPD_WRITE) && defined(LCD_SPI_SPD_READ) && (LCD_SPI_SPD_WRITE != LCD_SPI_SPD_READ)
|
||||
LCD_SPI_SETBAUDRATE(LCD_SPI_HANDLE, LCD_SPI_SPD_WRITE); /* speed change */
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* LCD_SPI_MODE */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Set SPI 8bit mode without HAL_SPI_Init */
|
||||
static inline void LcdSpiMode8(void)
|
||||
{
|
||||
LCD_SPI_SETDATASIZE_8BIT(LCD_SPI_HANDLE);
|
||||
LCD_SPI_HANDLE.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
}
|
||||
|
||||
/* Set SPI 16bit mode without HAL_SPI_Init */
|
||||
static inline void LcdSpiMode16(void)
|
||||
{
|
||||
LCD_SPI_SETDATASIZE_16BIT(LCD_SPI_HANDLE);
|
||||
LCD_SPI_HANDLE.Init.DataSize = SPI_DATASIZE_16BIT;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#if LCD_DMA_TX == 0 && LCD_DMA_RX == 0
|
||||
/* DMA off mode */
|
||||
|
||||
#define LcdTransInit()
|
||||
#define LcdTransStart()
|
||||
#define LcdTransEnd()
|
||||
|
||||
uint32_t LCD_IO_DmaBusy(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* #if LCD_DMA_TX == 0 && LCD_DMA_RX == 0 */
|
||||
/* DMA on mode */
|
||||
|
||||
#define DMA_STATUS_FREE 0
|
||||
#define DMA_STATUS_FILL (1 << 0)
|
||||
#define DMA_STATUS_MULTIDATA (1 << 1)
|
||||
#define DMA_STATUS_8BIT (1 << 2)
|
||||
#define DMA_STATUS_16BIT (1 << 3)
|
||||
#define DMA_STATUS_24BIT (1 << 4)
|
||||
|
||||
struct
|
||||
{
|
||||
volatile uint32_t status; /* DMA status (0=free, other: see the DMA_STATUS... macros) */
|
||||
uint32_t size; /* all transactions data size */
|
||||
uint32_t trsize; /* actual DMA transaction data size */
|
||||
uint32_t maxtrsize; /* max size / one DMA transaction */
|
||||
uint32_t ptr; /* data pointer for DMA */
|
||||
uint16_t data; /* fill operation data for DMA */
|
||||
}volatile dmastatus;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef osCMSIS
|
||||
/* DMA mode on, Freertos off mode */
|
||||
|
||||
#define LcdTransInit()
|
||||
|
||||
#if LCD_DMA_ENDWAIT == 0
|
||||
#define LcdTransStart() {while(dmastatus.status);}
|
||||
#define LcdDmaWaitEnd(d)
|
||||
#elif LCD_DMA_ENDWAIT == 1
|
||||
#define LcdTransStart() {while(dmastatus.status);}
|
||||
#define LcdDmaWaitEnd(d) {if(d) while(dmastatus.status);}
|
||||
#elif LCD_DMA_ENDWAIT == 2
|
||||
#define LcdTransStart()
|
||||
#define LcdDmaWaitEnd(d) {while(dmastatus.status);}
|
||||
#endif /* #elif LCD_DMA_ENDWAIT == 2 */
|
||||
|
||||
#define LcdTransEnd()
|
||||
|
||||
#define LcdDmaTransEnd() {dmastatus.status = 0;}
|
||||
|
||||
#else /* #ifndef osCMSIS */
|
||||
/* Freertos mode */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#if osCMSIS < 0x20000
|
||||
/* DMA on, Freertos 1 mode */
|
||||
|
||||
osSemaphoreId LcdSemIdHandle;
|
||||
osSemaphoreDef(LcdSemId);
|
||||
#define LcdSemNew0 LcdSemIdHandle = osSemaphoreCreate(osSemaphore(LcdSemId), 1); osSemaphoreWait(LcdSemIdHandle, 0)
|
||||
#define LcdSemNew1 LcdSemIdHandle = osSemaphoreCreate(osSemaphore(LcdSemId), 1)
|
||||
#define LcdSemWait osSemaphoreWait(LcdSemIdHandle, osWaitForever)
|
||||
#define LcdSemSet osSemaphoreRelease(LcdSemIdHandle)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#else /* #if osCMSIS < 0x20000 */
|
||||
/* DMA on, Freertos 2 mode */
|
||||
|
||||
osSemaphoreId_t LcdSemId;
|
||||
#define LcdSemNew0 LcdSemId = osSemaphoreNew(1, 0, 0)
|
||||
#define LcdSemNew1 LcdSemId = osSemaphoreNew(1, 1, 0)
|
||||
#define LcdSemWait osSemaphoreAcquire(LcdSemId, osWaitForever)
|
||||
#define LcdSemSet osSemaphoreRelease(LcdSemId)
|
||||
|
||||
#endif /* #else osCMSIS < 0x20000 */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* DMA on, Freertos 1 and 2 mode */
|
||||
|
||||
#if LCD_DMA_ENDWAIT == 0
|
||||
#define LcdTransInit() {LcdSemNew1;}
|
||||
#define LcdTransStart() {LcdSemWait;}
|
||||
#define LcdTransEnd() {LcdSemSet;}
|
||||
#define LcdDmaWaitEnd(d)
|
||||
#elif LCD_DMA_ENDWAIT == 1
|
||||
#define LcdTransInit() {LcdSemNew1;}
|
||||
#define LcdTransStart() {LcdSemWait;}
|
||||
#define LcdTransEnd() {LcdSemSet;}
|
||||
#define LcdDmaWaitEnd(d) {if(d) {LcdSemWait; LcdSemSet;}}
|
||||
#elif LCD_DMA_ENDWAIT == 2
|
||||
#define LcdTransInit() {LcdSemNew0;}
|
||||
#define LcdTransStart()
|
||||
#define LcdTransEnd()
|
||||
#define LcdDmaWaitEnd(d) {LcdSemWait;}
|
||||
#endif /* elif LCD_DMA_ENDWAIT == 2 */
|
||||
|
||||
#define LcdDmaTransEnd() {dmastatus.status = 0; LcdSemSet;}
|
||||
|
||||
#endif /* #else osCMSIS */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Get the DMA operation status (0=DMA is free, 1=DMA is busy) */
|
||||
uint32_t LCD_IO_DmaBusy(void)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
if(dmastatus.status != DMA_STATUS_FREE)
|
||||
ret = 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* #else LCD_DMA_TX == 0 && LCD_DMA_RX == 0 */
|
||||
|
||||
//=============================================================================
|
||||
/* Fill 24bit bitmap from 16bit color
|
||||
- color : 16 bit (RGB565) color
|
||||
- tg : 24 bit (RGB888) color target bitmap pointer
|
||||
- Size : number of pixel */
|
||||
void FillConvert16to24(uint16_t color, uint8_t * tg, uint32_t Size)
|
||||
{
|
||||
uint32_t c24;
|
||||
c24 = RGB565TO888(color);
|
||||
while(Size--)
|
||||
{
|
||||
*(uint32_t *)tg = c24;
|
||||
tg += 3;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Convert from 16bit bitmnap to 24bit bitmap
|
||||
- src : 16 bit (RGB565) color source bitmap pointer
|
||||
- tg : 24 bit (RGB888) color target bitmap pointer
|
||||
- Size : number of pixel */
|
||||
void BitmapConvert16to24(uint16_t * src, uint8_t * tg, uint32_t Size)
|
||||
{
|
||||
while(Size--)
|
||||
{
|
||||
*(uint32_t *)tg = RGB565TO888(*src);
|
||||
src++;
|
||||
tg += 3;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Convert from 16bit bitmnap to 24bit bitmap
|
||||
- src : 24 bit (RGB888) color source bitmap pointer
|
||||
- tg : 16 bit (RGB565) color target bitmap pointer
|
||||
- Size : number of pixel */
|
||||
void BitmapConvert24to16(uint8_t * src, uint16_t * tg, uint32_t Size)
|
||||
{
|
||||
uint32_t c24;
|
||||
while(Size--)
|
||||
{
|
||||
c24 = *(uint32_t *)src;
|
||||
*tg = RGB888TO565(c24);
|
||||
src += 3;
|
||||
tg++;
|
||||
}
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
/* TX DMA */
|
||||
#if LCD_DMA_TX == 1
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* DMA operation end callback function prototype */
|
||||
__weak void LCD_IO_DmaTxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
UNUSED(hspi);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* SPI DMA operation interrupt */
|
||||
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
if(hspi == &LCD_SPI_HANDLE)
|
||||
{
|
||||
if(dmastatus.size > dmastatus.trsize)
|
||||
{ /* dma operation is still required */
|
||||
|
||||
if(dmastatus.status == (DMA_STATUS_MULTIDATA | DMA_STATUS_8BIT))
|
||||
dmastatus.ptr += dmastatus.trsize; /* 8bit multidata */
|
||||
else if(dmastatus.status == (DMA_STATUS_MULTIDATA | DMA_STATUS_16BIT))
|
||||
dmastatus.ptr += dmastatus.trsize << 1; /* 16bit multidata */
|
||||
else if(dmastatus.status == (DMA_STATUS_MULTIDATA | DMA_STATUS_24BIT))
|
||||
dmastatus.ptr += dmastatus.trsize << 1; /* 24bit multidata */
|
||||
|
||||
dmastatus.size -= dmastatus.trsize;
|
||||
if(dmastatus.size <= dmastatus.maxtrsize)
|
||||
dmastatus.trsize = dmastatus.size;
|
||||
|
||||
#if LCD_RGB24_BUFFSIZE == 0
|
||||
HAL_SPI_Transmit_DMA(&LCD_SPI_HANDLE, (uint8_t *)dmastatus.ptr, dmastatus.trsize);
|
||||
#else
|
||||
if(dmastatus.status == (DMA_STATUS_MULTIDATA | DMA_STATUS_24BIT))
|
||||
{
|
||||
BitmapConvert16to24((uint16_t *)dmastatus.ptr, lcd_rgb24_buffer, dmastatus.trsize);
|
||||
HAL_SPI_Transmit_DMA(&LCD_SPI_HANDLE, (uint8_t *)lcd_rgb24_buffer, dmastatus.trsize * 3);
|
||||
}
|
||||
else if(dmastatus.status == (DMA_STATUS_FILL | DMA_STATUS_24BIT))
|
||||
HAL_SPI_Transmit_DMA(&LCD_SPI_HANDLE, (uint8_t *)lcd_rgb24_buffer, dmastatus.trsize * 3);
|
||||
else
|
||||
HAL_SPI_Transmit_DMA(&LCD_SPI_HANDLE, (uint8_t *)dmastatus.ptr, dmastatus.trsize);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{ /* dma operations have ended */
|
||||
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
|
||||
LcdDmaTransEnd();
|
||||
LCD_IO_DmaTxCpltCallback(hspi);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* #if LCD_DMA_TX == 1 */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Wrtite fill and multi data to Lcd (8 and 16 bit mode)
|
||||
- pData: 8 or 16 bits data pointer
|
||||
- Size: data number
|
||||
- Mode: 8 or 16 or 24 bit mode, write or read, fill or multidata (see the LCD_IO_... defines in lcd_io.h file) */
|
||||
void LCDWriteFillMultiData8and16(uint8_t * pData, uint32_t Size, uint32_t Mode)
|
||||
{
|
||||
if(Mode & LCD_IO_DATA8)
|
||||
LcdSpiMode8();
|
||||
else
|
||||
LcdSpiMode16();
|
||||
|
||||
#if LCD_DMA_TX == 1
|
||||
if((Size > DMA_MINSIZE) && (!LCD_DMA_UNABLE((uint32_t)pData)))
|
||||
{ /* DMA mode */
|
||||
if(Mode & LCD_IO_DATA8)
|
||||
{ /* 8bit DMA */
|
||||
LCD_SPI_HANDLE.hdmatx->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
LCD_SPI_HANDLE.hdmatx->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
dmastatus.status = DMA_STATUS_8BIT;
|
||||
}
|
||||
else
|
||||
{ /* 16bit DMA */
|
||||
LCD_SPI_HANDLE.hdmatx->Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
|
||||
LCD_SPI_HANDLE.hdmatx->Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
|
||||
dmastatus.status = DMA_STATUS_16BIT;
|
||||
}
|
||||
|
||||
if(Mode & LCD_IO_FILL)
|
||||
{ /* fill */
|
||||
LCD_SPI_HANDLE.hdmatx->Init.MemInc = DMA_MINC_DISABLE;
|
||||
dmastatus.status |= DMA_STATUS_FILL;
|
||||
dmastatus.data = *(uint16_t *)pData;
|
||||
dmastatus.ptr = (uint32_t)&dmastatus.data;
|
||||
}
|
||||
else
|
||||
{ /* multidata */
|
||||
LCD_SPI_HANDLE.hdmatx->Init.MemInc = DMA_MINC_ENABLE;
|
||||
dmastatus.status |= DMA_STATUS_MULTIDATA;
|
||||
dmastatus.ptr = (uint32_t)pData;
|
||||
}
|
||||
|
||||
dmastatus.size = Size;
|
||||
dmastatus.maxtrsize = DMA_MAXSIZE;
|
||||
|
||||
if(Size > DMA_MAXSIZE)
|
||||
dmastatus.trsize = DMA_MAXSIZE;
|
||||
else /* the transaction can be performed with one DMA operation */
|
||||
dmastatus.trsize = Size;
|
||||
|
||||
__HAL_DMA_DISABLE(LCD_SPI_HANDLE.hdmatx);
|
||||
HAL_DMA_Init(LCD_SPI_HANDLE.hdmatx);
|
||||
HAL_SPI_Transmit_DMA(&LCD_SPI_HANDLE, (uint8_t *)dmastatus.ptr, dmastatus.trsize);
|
||||
LcdDmaWaitEnd(Mode & LCD_IO_MULTIDATA);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{ /* not DMA mode */
|
||||
if(Mode & LCD_IO_FILL)
|
||||
{ /* fill */
|
||||
while(Size--) /* fill 8 and 16bit */
|
||||
HAL_SPI_Transmit(&LCD_SPI_HANDLE, (uint8_t *)pData, 1, LCD_SPI_TIMEOUT);
|
||||
}
|
||||
else
|
||||
{ /* multidata */
|
||||
uint32_t trsize;
|
||||
while(Size)
|
||||
{
|
||||
if(Size > DMA_MAXSIZE)
|
||||
{
|
||||
trsize = DMA_MAXSIZE;
|
||||
Size -= DMA_MAXSIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
trsize = Size;
|
||||
Size = 0;
|
||||
}
|
||||
HAL_SPI_Transmit(&LCD_SPI_HANDLE, pData, trsize, LCD_SPI_TIMEOUT);
|
||||
if(Mode & LCD_IO_DATA8)
|
||||
pData += trsize;
|
||||
else
|
||||
pData += (trsize << 1);
|
||||
}
|
||||
}
|
||||
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
|
||||
LcdTransEnd();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Wrtite fill and multi data to Lcd (convert RGB16 bit (5-6-5) to RGB24 bit (8-8-8) mode, no dma capability)
|
||||
- pData: RGB 16 bits data pointer
|
||||
- Size: data number
|
||||
- Mode: 8 or 16 or 24 bit mode, write or read, fill or multidata (see the LCD_IO_... defines in lcd_io.h file) */
|
||||
void LCDWriteFillMultiData16to24(uint8_t * pData, uint32_t Size, uint32_t Mode)
|
||||
{
|
||||
LcdSpiMode8();
|
||||
|
||||
#if LCD_DMA_TX == 1 && LCD_RGB24_BUFFSIZE > 0
|
||||
if(Size > DMA_MINSIZE)
|
||||
{ /* DMA mode */
|
||||
LCD_SPI_HANDLE.hdmatx->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
LCD_SPI_HANDLE.hdmatx->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
LCD_SPI_HANDLE.hdmatx->Init.MemInc = DMA_MINC_ENABLE;
|
||||
__HAL_DMA_DISABLE(LCD_SPI_HANDLE.hdmatx);
|
||||
HAL_DMA_Init(LCD_SPI_HANDLE.hdmatx);
|
||||
|
||||
dmastatus.maxtrsize = LCD_RGB24_BUFFSIZE;
|
||||
dmastatus.size = Size;
|
||||
|
||||
if(Size > LCD_RGB24_BUFFSIZE)
|
||||
dmastatus.trsize = LCD_RGB24_BUFFSIZE;
|
||||
else
|
||||
dmastatus.trsize = Size;
|
||||
|
||||
if(Mode & LCD_IO_FILL)
|
||||
{ /* fill 16bit to 24bit */
|
||||
dmastatus.status = DMA_STATUS_FILL | DMA_STATUS_24BIT;
|
||||
FillConvert16to24(*(uint16_t *)pData, lcd_rgb24_buffer, dmastatus.trsize);
|
||||
}
|
||||
else
|
||||
{ /* multidata 16bit to 24bit */
|
||||
dmastatus.status = DMA_STATUS_MULTIDATA | DMA_STATUS_24BIT;
|
||||
dmastatus.ptr = (uint32_t)pData;
|
||||
BitmapConvert16to24((uint16_t *)pData, lcd_rgb24_buffer, dmastatus.trsize);
|
||||
}
|
||||
|
||||
HAL_SPI_Transmit_DMA(&LCD_SPI_HANDLE, lcd_rgb24_buffer, dmastatus.trsize * 3);
|
||||
LcdDmaWaitEnd(Mode & LCD_IO_MULTIDATA);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{ /* not DMA mode */
|
||||
#if LCD_RGB24_BUFFSIZE == 0
|
||||
uint32_t rgb888;
|
||||
if(Mode & LCD_IO_FILL)
|
||||
{ /* fill 16bit to 24bit */
|
||||
rgb888 = RGB565TO888(*(uint16_t *)pData);
|
||||
while(Size--)
|
||||
HAL_SPI_Transmit(&LCD_SPI_HANDLE, (uint8_t *)&rgb888, 3, LCD_SPI_TIMEOUT);
|
||||
}
|
||||
else
|
||||
{ /* multidata 16bit to 24bit */
|
||||
while(Size--)
|
||||
{
|
||||
rgb888 = RGB565TO888(*(uint16_t *)pData);
|
||||
HAL_SPI_Transmit(&LCD_SPI_HANDLE, (uint8_t *)&rgb888, 3, LCD_SPI_TIMEOUT);
|
||||
pData+=2;
|
||||
}
|
||||
}
|
||||
#elif LCD_RGB24_BUFFSIZE > 0
|
||||
uint32_t trsize;
|
||||
if(Mode & LCD_IO_FILL)
|
||||
{ /* fill */
|
||||
if(Size > LCD_RGB24_BUFFSIZE)
|
||||
trsize = LCD_RGB24_BUFFSIZE;
|
||||
else
|
||||
trsize = Size;
|
||||
FillConvert16to24(*(uint16_t *)pData, lcd_rgb24_buffer, trsize);
|
||||
while(Size)
|
||||
{
|
||||
if(Size > LCD_RGB24_BUFFSIZE)
|
||||
{
|
||||
trsize = LCD_RGB24_BUFFSIZE;
|
||||
Size -= LCD_RGB24_BUFFSIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
trsize = Size;
|
||||
Size = 0;
|
||||
}
|
||||
HAL_SPI_Transmit(&LCD_SPI_HANDLE, lcd_rgb24_buffer, trsize * 3, LCD_SPI_TIMEOUT);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* bitmap */
|
||||
while(Size)
|
||||
{
|
||||
if(Size > LCD_RGB24_BUFFSIZE)
|
||||
{
|
||||
trsize = LCD_RGB24_BUFFSIZE;
|
||||
Size -= LCD_RGB24_BUFFSIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
trsize = Size;
|
||||
Size = 0;
|
||||
}
|
||||
BitmapConvert16to24((uint16_t *)pData, lcd_rgb24_buffer, trsize);
|
||||
HAL_SPI_Transmit(&LCD_SPI_HANDLE, lcd_rgb24_buffer, trsize * 3, LCD_SPI_TIMEOUT);
|
||||
pData += trsize << 1;
|
||||
}
|
||||
}
|
||||
#endif /* #elif LCD_RGB24_BUFFSIZE > 0 */
|
||||
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
|
||||
LcdTransEnd();
|
||||
}
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
/* Read */
|
||||
|
||||
#if LCD_SPI_MODE != 0
|
||||
|
||||
/* RX DMA */
|
||||
#if LCD_DMA_RX == 1
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* DMA operation end callback function prototype */
|
||||
__weak void LCD_IO_DmaRxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
UNUSED(hspi);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* SPI DMA operation interrupt */
|
||||
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
|
||||
{
|
||||
uint32_t dma_status = dmastatus.status;
|
||||
if(hspi == &LCD_SPI_HANDLE)
|
||||
{
|
||||
#if LCD_RGB24_BUFFSIZE > 0
|
||||
if(dma_status == (DMA_STATUS_MULTIDATA | DMA_STATUS_24BIT))
|
||||
{
|
||||
BitmapConvert24to16(lcd_rgb24_buffer, (uint16_t *)dmastatus.ptr, dmastatus.trsize);
|
||||
dmastatus.ptr += dmastatus.trsize << 1; /* 24bit multidata */
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if(dma_status == (DMA_STATUS_MULTIDATA | DMA_STATUS_8BIT))
|
||||
dmastatus.ptr += dmastatus.trsize; /* 8bit multidata */
|
||||
else if(dma_status == (DMA_STATUS_MULTIDATA | DMA_STATUS_16BIT))
|
||||
dmastatus.ptr += dmastatus.trsize << 1; /* 16bit multidata */
|
||||
}
|
||||
|
||||
if(dmastatus.size > dmastatus.trsize)
|
||||
{ /* dma operation is still required */
|
||||
dmastatus.size -= dmastatus.trsize;
|
||||
if(dmastatus.size <= dmastatus.maxtrsize)
|
||||
dmastatus.trsize = dmastatus.size;
|
||||
|
||||
#if LCD_RGB24_BUFFSIZE > 0
|
||||
if(dma_status == (DMA_STATUS_MULTIDATA | DMA_STATUS_24BIT))
|
||||
HAL_SPI_Receive_DMA(&LCD_SPI_HANDLE, lcd_rgb24_buffer, dmastatus.trsize * 3);
|
||||
else
|
||||
#endif
|
||||
HAL_SPI_Receive_DMA(&LCD_SPI_HANDLE, (uint8_t *)dmastatus.ptr, dmastatus.trsize);
|
||||
}
|
||||
else
|
||||
{ /* dma operations have ended */
|
||||
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
|
||||
LcdDirWrite();
|
||||
LcdDmaTransEnd();
|
||||
LCD_IO_DmaRxCpltCallback(hspi);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* #if LCD_DMA_RX == 1 */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Read data from Lcd
|
||||
- pData: 8 or 16 bits data pointer
|
||||
- Size: data number
|
||||
- Mode: 8 or 16 or 24 bit mode, write or read, fill or multidata (see the LCD_IO_... defines in lcd_io.h file) */
|
||||
void LCDReadMultiData8and16(uint8_t * pData, uint32_t Size, uint32_t Mode)
|
||||
{
|
||||
if(Mode & LCD_IO_DATA8)
|
||||
LcdSpiMode8();
|
||||
else
|
||||
LcdSpiMode16();
|
||||
|
||||
#if LCD_DMA_RX == 1
|
||||
if((Size > DMA_MINSIZE) && (!LCD_DMA_UNABLE((uint32_t)pData)))
|
||||
{ /* DMA mode */
|
||||
/* SPI RX DMA setting (8bit, multidata) */
|
||||
if(Mode & LCD_IO_DATA8)
|
||||
{
|
||||
LCD_SPI_HANDLE.hdmarx->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
LCD_SPI_HANDLE.hdmarx->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
dmastatus.status = DMA_STATUS_MULTIDATA | DMA_STATUS_8BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
LCD_SPI_HANDLE.hdmarx->Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
|
||||
LCD_SPI_HANDLE.hdmarx->Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
|
||||
dmastatus.status = DMA_STATUS_MULTIDATA | DMA_STATUS_16BIT;
|
||||
}
|
||||
LCD_SPI_HANDLE.hdmarx->Init.MemInc = DMA_MINC_ENABLE;
|
||||
|
||||
__HAL_DMA_DISABLE(LCD_SPI_HANDLE.hdmarx);
|
||||
HAL_DMA_Init(LCD_SPI_HANDLE.hdmarx);
|
||||
|
||||
dmastatus.maxtrsize = DMA_MAXSIZE;
|
||||
dmastatus.size = Size;
|
||||
|
||||
if(Size > DMA_MAXSIZE)
|
||||
dmastatus.trsize = DMA_MAXSIZE;
|
||||
else
|
||||
dmastatus.trsize = Size;
|
||||
|
||||
dmastatus.ptr = (uint32_t)pData;
|
||||
|
||||
HAL_SPI_Receive_DMA(&LCD_SPI_HANDLE, pData, dmastatus.trsize);
|
||||
LcdDmaWaitEnd(1);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{ /* not DMA mode */
|
||||
uint32_t trsize;
|
||||
while(Size)
|
||||
{
|
||||
if(Size > DMA_MAXSIZE)
|
||||
{
|
||||
trsize = DMA_MAXSIZE;
|
||||
Size -= DMA_MAXSIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
trsize = Size;
|
||||
Size = 0;
|
||||
}
|
||||
HAL_SPI_Receive(&LCD_SPI_HANDLE, pData, trsize, LCD_SPI_TIMEOUT);
|
||||
if(Mode & LCD_IO_DATA8)
|
||||
pData += trsize;
|
||||
else
|
||||
pData += (trsize << 1);
|
||||
}
|
||||
LcdDirWrite();
|
||||
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
|
||||
LcdTransEnd();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Read 24bit (8-8-8) RGB data from LCD, and convert to 16bit (5-6-5) RGB data
|
||||
- pData: 16 bits RGB data pointer
|
||||
- Size: pixel number
|
||||
- Mode: 8 or 16 or 24 bit mode, write or read, fill or multidata (see the LCD_IO_... defines in lcd_io.h file) */
|
||||
void LCDReadMultiData24to16(uint8_t * pData, uint32_t Size, uint32_t Mode)
|
||||
{
|
||||
LcdSpiMode8();
|
||||
#if LCD_DMA_RX == 1 && LCD_RGB24_BUFFSIZE > 0
|
||||
if(Size > DMA_MINSIZE)
|
||||
{ /* DMA mode */
|
||||
/* SPI RX DMA setting (8bit, multidata) */
|
||||
LCD_SPI_HANDLE.hdmarx->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
LCD_SPI_HANDLE.hdmarx->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
LCD_SPI_HANDLE.hdmarx->Init.MemInc = DMA_MINC_ENABLE;
|
||||
__HAL_DMA_DISABLE(LCD_SPI_HANDLE.hdmarx);
|
||||
HAL_DMA_Init(LCD_SPI_HANDLE.hdmarx);
|
||||
|
||||
dmastatus.maxtrsize = LCD_RGB24_BUFFSIZE;
|
||||
dmastatus.size = Size;
|
||||
|
||||
if(Size > LCD_RGB24_BUFFSIZE)
|
||||
dmastatus.trsize = LCD_RGB24_BUFFSIZE;
|
||||
else
|
||||
dmastatus.trsize = Size;
|
||||
|
||||
dmastatus.status = DMA_STATUS_MULTIDATA | DMA_STATUS_24BIT;
|
||||
dmastatus.ptr = (uint32_t)pData;
|
||||
|
||||
HAL_SPI_Receive_DMA(&LCD_SPI_HANDLE, lcd_rgb24_buffer, dmastatus.trsize * 3);
|
||||
LcdDmaWaitEnd(1);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{ /* not DMA mode */
|
||||
#if LCD_RGB24_BUFFSIZE == 0
|
||||
uint32_t rgb888;
|
||||
while(Size--)
|
||||
{
|
||||
HAL_SPI_Receive(&LCD_SPI_HANDLE, (uint8_t *)&rgb888, 3, LCD_SPI_TIMEOUT);
|
||||
*(uint16_t *)pData = RGB888TO565(rgb888);
|
||||
pData += 2;
|
||||
}
|
||||
#elif LCD_RGB24_BUFFSIZE > 0
|
||||
uint32_t trsize;
|
||||
while(Size)
|
||||
{
|
||||
if(Size > LCD_RGB24_BUFFSIZE)
|
||||
{
|
||||
trsize = LCD_RGB24_BUFFSIZE;
|
||||
Size -= LCD_RGB24_BUFFSIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
trsize = Size;
|
||||
Size = 0;
|
||||
}
|
||||
HAL_SPI_Receive(&LCD_SPI_HANDLE, lcd_rgb24_buffer, trsize * 3, LCD_SPI_TIMEOUT);
|
||||
BitmapConvert24to16(lcd_rgb24_buffer, (uint16_t *)pData, trsize);
|
||||
pData += (trsize << 1);
|
||||
}
|
||||
#endif
|
||||
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
|
||||
LcdDirWrite();
|
||||
LcdTransEnd();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* #if LCD_SPI_MODE != 0 */
|
||||
|
||||
//=============================================================================
|
||||
/* Public functions */
|
||||
|
||||
/* n millisec delay */
|
||||
void LCD_Delay(uint32_t Delay)
|
||||
{
|
||||
#ifndef osCMSIS
|
||||
HAL_Delay(Delay);
|
||||
#else
|
||||
osDelay(Delay);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Backlight on-off (Bl=0 -> off, Bl=1 -> on) */
|
||||
//-----------------------------------------------------------------------------
|
||||
void LCD_IO_Bl_OnOff(uint8_t Bl)
|
||||
{
|
||||
#if defined(LCD_BL_GPIO_Port) && defined (LCD_BL_Pin)
|
||||
if(Bl)
|
||||
#if LCD_BLON == 0
|
||||
HAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_RESET);
|
||||
#elif LCD_BLON == 1
|
||||
HAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_SET);
|
||||
#endif
|
||||
else
|
||||
#if LCD_BLON == 0
|
||||
HAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_SET);
|
||||
#elif LCD_BLON == 1
|
||||
HAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_RESET);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Lcd IO init, reset, spi speed init, get the freertos task id */
|
||||
void LCD_IO_Init(void)
|
||||
{
|
||||
#if defined(LCD_RST_GPIO_Port) && defined (LCD_RST_Pin)
|
||||
LCD_Delay(50);
|
||||
HAL_GPIO_WritePin(LCD_RST_GPIO_Port, LCD_RST_Pin, GPIO_PIN_RESET);
|
||||
LCD_Delay(50);
|
||||
HAL_GPIO_WritePin(LCD_RST_GPIO_Port, LCD_RST_Pin, GPIO_PIN_SET);
|
||||
#endif
|
||||
LCD_Delay(10);
|
||||
#if defined(LCD_SPI_SPD_WRITE)
|
||||
LCD_SPI_SETBAUDRATE(LCD_SPI_HANDLE, LCD_SPI_SPD_WRITE);
|
||||
#endif
|
||||
LcdTransInit();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Lcd IO transaction
|
||||
- Cmd: 8 or 16 bits command
|
||||
- pData: 8 or 16 bits data pointer
|
||||
- Size: data number
|
||||
- DummySize: dummy byte number at read
|
||||
- Mode: 8 or 16 or 24 bit mode, write or read, fill or multidata (see the LCD_IO_... defines in lcd_io.h file) */
|
||||
void LCD_IO_Transaction(uint16_t Cmd, uint8_t *pData, uint32_t Size, uint32_t DummySize, uint32_t Mode)
|
||||
{
|
||||
#if LCD_SPI_MODE == 0 /* only TX mode */
|
||||
if(Mode & LCD_IO_READ)
|
||||
return;
|
||||
#endif
|
||||
|
||||
LcdTransStart();
|
||||
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/* Command write */
|
||||
if(Mode & LCD_IO_CMD8)
|
||||
LcdSpiMode8();
|
||||
else if(Mode & LCD_IO_CMD16)
|
||||
LcdSpiMode16();
|
||||
HAL_GPIO_WritePin(LCD_RS_GPIO_Port, LCD_RS_Pin, GPIO_PIN_RESET);
|
||||
HAL_SPI_Transmit(&LCD_SPI_HANDLE, (uint8_t *)&Cmd, 1, LCD_SPI_TIMEOUT); /* CMD write */
|
||||
HAL_GPIO_WritePin(LCD_RS_GPIO_Port, LCD_RS_Pin, GPIO_PIN_SET);
|
||||
|
||||
if(Size == 0)
|
||||
{ /* only command byte or word */
|
||||
HAL_GPIO_WritePin(LCD_CS_GPIO_Port, LCD_CS_Pin, GPIO_PIN_SET);
|
||||
LcdTransEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Datas write or read */
|
||||
if(Mode & LCD_IO_WRITE)
|
||||
{ /* Write Lcd */
|
||||
if(Mode & LCD_IO_DATA16TO24)
|
||||
LCDWriteFillMultiData16to24(pData, Size, Mode);
|
||||
else
|
||||
LCDWriteFillMultiData8and16(pData, Size, Mode);
|
||||
}
|
||||
#if LCD_SPI_MODE != 0
|
||||
else if(Mode & LCD_IO_READ)
|
||||
{ /* Read LCD */
|
||||
LcdDirRead((DummySize << 3) + LCD_SCK_EXTRACLK);
|
||||
if(Mode & LCD_IO_DATA24TO16)
|
||||
LCDReadMultiData24to16(pData, Size, Mode);
|
||||
else
|
||||
LCDReadMultiData8and16(pData, Size, Mode);
|
||||
}
|
||||
#endif /* #if LCD_SPI_MODE != 0 */
|
||||
}
|
||||
158
Core/Src/Lcd/lcd_io_spi_hal.h
Normal file
158
Core/Src/Lcd/lcd_io_spi_hal.h
Normal file
@@ -0,0 +1,158 @@
|
||||
//=============================================================================
|
||||
/* Information section */
|
||||
|
||||
/*
|
||||
* SPI HAL LCD driver for all stm32 family
|
||||
* author: Roberto Benjami
|
||||
* v.2022.11
|
||||
*/
|
||||
|
||||
/* Features:
|
||||
- only hardware SPI
|
||||
- write function 8 and 16bit without DMA or with DMA (in both fill and bitmap mode)
|
||||
- write function with bitdepth convert (16bit RGB565 to 24bit RGB888) without DMA or with DMA
|
||||
- all writing functions are possible in both fill and bitmap mode
|
||||
- read function 8 and 16bit only without DMA or with DMA
|
||||
- read function with bitdepth convert (24bit RGB888 to 16bit RGB565) without DMA or with DMA */
|
||||
|
||||
/* Settings in CUBEIDE or CUBEMX
|
||||
SPI Parameter Settings
|
||||
- Mode: "Full duplex master" or "Half duplex master" os "Transmit only master"
|
||||
- Hardware NSS signal: disabled
|
||||
- Frame format: Motorola
|
||||
- Data Size: 8 bits
|
||||
- First bit: MSB first
|
||||
- Prescaler: it doesn't matter, the speed needs to be specified elsewhere
|
||||
- Clock Polarity: Low
|
||||
- Clock Phase: 1 Edge
|
||||
note: if the selected SPI pin is not good, change it in the pinout view
|
||||
SPI DMA Settings (if necessary)
|
||||
- Add DMA Request SPIn_TX, left at the default value (if necessary)
|
||||
- Add DMA Request SPIn_RX, left at the default value (if necessary)
|
||||
GPIO
|
||||
- Lcd chip select:
|
||||
- output level: High
|
||||
- mode: Output Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: LCD_CS
|
||||
- Lcd RS
|
||||
- output level: Low
|
||||
- mode: Output Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: LCD_RS
|
||||
- Lcd SCK
|
||||
- output level: n/a
|
||||
- mode: Alternate Function Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: LCD_SCK
|
||||
- Lcd MOSI
|
||||
- output level: n/a
|
||||
- mode: Alternate Function Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: LCD_MOSI
|
||||
- Lcd MISO
|
||||
- output level: n/a
|
||||
- mode: Alternate Function Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: LCD_MISO
|
||||
- Lcd reset pin (only when connected)
|
||||
- output level: High
|
||||
- mode: Output Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Low
|
||||
- User Label: LCD_RST
|
||||
- Lcd back light pin (only when connected)
|
||||
- output level: Low or High
|
||||
- mode: Output Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Low
|
||||
- User Label: LCD_BL
|
||||
|
||||
Settings in main.h:
|
||||
- If you use freertos, add this line the main.h file
|
||||
#include "cmsis_os.h"
|
||||
(note: then the driver will also use the rtos signal to wait for the end of the dma transaction)
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
/* Interface section */
|
||||
|
||||
/* Queries whether a DMA operation is in progress
|
||||
- 0: not in progress
|
||||
- 1: in progress */
|
||||
uint32_t LCD_IO_DmaBusy(void);
|
||||
|
||||
/* If we want to know when the LCD DMA operation is finished, let's create a function in our program:
|
||||
This function is called by the driver at the end of DMA operations. */
|
||||
void LCD_IO_DmaTxCpltCallback(SPI_HandleTypeDef *hspi);
|
||||
void LCD_IO_DmaRxCpltCallback(SPI_HandleTypeDef *hspi);
|
||||
|
||||
//=============================================================================
|
||||
/* Setting section (please set the necessary things in this section) */
|
||||
|
||||
#ifndef __LCD_IO_SPI_HAL_H__
|
||||
#define __LCD_IO_SPI_HAL_H__
|
||||
|
||||
/* SPI handle select (see in main.c file, default: hspi1, hspi2 ... hspi6) */
|
||||
#define LCD_SPI_HANDLE hspi1
|
||||
|
||||
/* SPI mode
|
||||
- 0: only TX (write on MOSI pin, no MISO pin)
|
||||
- 1: half duplex (MOSI pin is bidirectional)
|
||||
- 2: full duplex (write on MOSI pin, read on MISO pin) */
|
||||
#define LCD_SPI_MODE 2
|
||||
|
||||
/* SPI write and read speed (if deleted -> setting in CUBE)
|
||||
- hardware SPI clock div fPCLK: 0=/2, 1=/4, 2=/8, 3=/16, 4=/32, 5=/64, 6=/128, 7=/256 */
|
||||
#define LCD_SPI_SPD_WRITE 1
|
||||
#define LCD_SPI_SPD_READ 4
|
||||
|
||||
/* Backlight control (the logical level of the active state) */
|
||||
#define LCD_BLON 0
|
||||
|
||||
/* When data direction change (OUT->IN) there is a display that requires extra clock
|
||||
example ST7735: 1, ILI9341: 0, ILI9488: 0 */
|
||||
#define LCD_SCK_EXTRACLK 0
|
||||
|
||||
/* DMA TX/RX enable/disable
|
||||
- 0: DMA disable
|
||||
- 1: DMA enable */
|
||||
#define LCD_DMA_TX 1
|
||||
#define LCD_DMA_RX 0
|
||||
|
||||
/* In dma mode the bitmap drawing function is completed before the actual drawing.
|
||||
When should we wait for the previous DMA operation to complete? (see the readme.me file)
|
||||
- 0: DMA check and wait at drawing function start
|
||||
- 1: DMA check and wait at drawing function start + bitmap drawing function end wait on (default mode)
|
||||
- 2: DMA wait at drawing function end */
|
||||
#define LCD_DMA_ENDWAIT 1
|
||||
|
||||
/* Because there are DMA capable and DMA unable memory regions
|
||||
here we can set what is the DMA unable region condition
|
||||
note: where the condition is true, it is considered a DMA-unable region
|
||||
Default (all memory used for bitmap drawing is DMA capable):
|
||||
#define LCD_DMA_UNABLE(addr) 0
|
||||
Example stm32f407 and stm32f429 with CCMRAM (the CCMRAM is not DMA capable):
|
||||
#define LCD_DMA_UNABLE(addr) ((addr < 0x20000000) && (addr >= 0x10000000))
|
||||
Example stm32h743 (the DTCMRAM and ITCMRAM are not DMA capable):
|
||||
#define LCD_DMA_UNABLE(addr) (((addr < 0x24000000) && (addr >= 0x20000000)) || (addr < 0x08000000))
|
||||
Note: if we ensure that we do not draw a bitmap from a DMA-capable memory area, it is not necessary to set it (leave it that way) */
|
||||
#define LCD_DMA_UNABLE(addr) 0
|
||||
|
||||
/* RGB565 to RGB888 and RGB888 to RGB565 convert byte order
|
||||
- 0: forward direction
|
||||
- 1: back direction
|
||||
(warning: the SPI DMA order is from low address to hight address step byte)
|
||||
note: If the red and blue colors are reversed and used 24bit mode, change this value */
|
||||
#define LCD_RGB24_ORDER 0
|
||||
|
||||
/* Pixel buffer size for DMA bitdepth conversion (buffer size [byte] = 3 * pixel buffer size)
|
||||
note: if 0 -> does not use DMA for 24-bit drawing and reading */
|
||||
#define LCD_RGB24_BUFFSIZE 0
|
||||
|
||||
#endif
|
||||
1153
Core/Src/Lcd/stm32_adafruit_lcd.c
Normal file
1153
Core/Src/Lcd/stm32_adafruit_lcd.c
Normal file
File diff suppressed because it is too large
Load Diff
203
Core/Src/Lcd/stm32_adafruit_lcd.h
Normal file
203
Core/Src/Lcd/stm32_adafruit_lcd.h
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
- 2019.05 Add BSP_LCD_ReadID fuction
|
||||
- 2019.05 Add BSP_LCD_ReadPixel fuction
|
||||
- 2019.05 Add BSP_LCD_DrawRGB16Image fuction
|
||||
- 2019.05 Add BSP_LCD_ReadRGB16Image fuction
|
||||
- 2019.11 Add BSP_LCD_FillTriangle
|
||||
- 2019.12 Add LCD_DEFAULT_FONT, LCD_DEFAULT_BACKCOLOR, LCD_DEFAULT_TEXTCOLOR, LCD_INIT_CLEAR
|
||||
- 2020.05 Add BSP_LCD_Scroll function
|
||||
- 2022.11 Modify ReadID return type: uint16_t to uint32_t
|
||||
- 2023.03 Add BSP_LCD_DisplayMultilayerChar function (mainly for drawing icons and buttons)
|
||||
- 2023.03 Add BSP_LCD_DisplayStringOnMultilayerChar function (mainly for drawing texticons and textbuttons)
|
||||
*/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32_adafruit_lcd.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the stm32_adafruit_lcd.c driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32_ADAFRUIT_LCD_H
|
||||
#define __STM32_ADAFRUIT_LCD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "lcd.h"
|
||||
#include "Fonts/fonts.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Config section (you can change this defines) */
|
||||
|
||||
/* LCD default font (Font8 or Font12 or Font16 or Font20 or Font24) */
|
||||
#define LCD_DEFAULT_FONT Font12
|
||||
|
||||
/* Font bitmap buffer size (even for the largest font size, at least one line should fit in it) */
|
||||
#define FONTBITMAPBUFSIZE 24 * 16
|
||||
|
||||
/* BSP_LCD_DisplayMultilayerChar max layer */
|
||||
#define MAX_CHAR_LAYER 12
|
||||
|
||||
/* LCD default colors */
|
||||
#define LCD_DEFAULT_BACKCOLOR LCD_COLOR_BLACK
|
||||
#define LCD_DEFAULT_TEXTCOLOR LCD_COLOR_WHITE
|
||||
|
||||
/* LCD clear with LCD_DEFAULT_BACKCOLOR in the BSP_LCD_Init (0:diasble, 1:enable) */
|
||||
#define LCD_INIT_CLEAR 0
|
||||
|
||||
/* some colors */
|
||||
#define LCD_COLOR_BLACK LCD_COLOR(0, 0, 0)
|
||||
#define LCD_COLOR_GRAY LCD_COLOR(192, 192, 192)
|
||||
#define LCD_COLOR_BLUE LCD_COLOR(0, 0, 255)
|
||||
#define LCD_COLOR_RED LCD_COLOR(255, 0, 0)
|
||||
#define LCD_COLOR_GREEN LCD_COLOR(0, 255, 0)
|
||||
#define LCD_COLOR_CYAN LCD_COLOR(0, 255, 255)
|
||||
#define LCD_COLOR_MAGENTA LCD_COLOR(255, 0, 255)
|
||||
#define LCD_COLOR_YELLOW LCD_COLOR(255, 255, 0)
|
||||
#define LCD_COLOR_WHITE LCD_COLOR(255, 255, 255)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Interface section (no modify) */
|
||||
|
||||
/**
|
||||
* @brief Draw Properties structures definition
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t TextColor;
|
||||
uint32_t BackColor;
|
||||
sFONT *pFont;
|
||||
}LCD_DrawPropTypeDef;
|
||||
|
||||
/**
|
||||
* @brief Point structures definition
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int16_t X;
|
||||
int16_t Y;
|
||||
}Point, * pPoint;
|
||||
|
||||
/**
|
||||
* @brief Line mode structures definition
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CENTER_MODE = 0x01, /*!< Center mode */
|
||||
RIGHT_MODE = 0x02, /*!< Right mode */
|
||||
LEFT_MODE = 0x03 /*!< Left mode */
|
||||
}Line_ModeTypdef;
|
||||
|
||||
#define __IO volatile
|
||||
|
||||
/**
|
||||
* @brief LCD status structure definition
|
||||
*/
|
||||
#define LCD_OK 0x00
|
||||
#define LCD_ERROR 0x01
|
||||
#define LCD_TIMEOUT 0x02
|
||||
|
||||
#if LCD_REVERSE16 == 1
|
||||
#define RC(a) ((((a) & 0xFF) << 8) | (((a) & 0xFF00) >> 8))
|
||||
#else
|
||||
#define RC(a) a
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief LCD color
|
||||
*/
|
||||
#define LCD_COLOR(r, g, b) (RC((r & 0xF8) << 8 | (g & 0xFC) << 3 | (b & 0xF8) >> 3))
|
||||
#define LCD_COLOR16(rgb16) (RC(rgb16))
|
||||
|
||||
/** @defgroup STM32_ADAFRUIT_LCD_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_LCD_Init(void);
|
||||
uint16_t BSP_LCD_GetXSize(void);
|
||||
uint16_t BSP_LCD_GetYSize(void);
|
||||
|
||||
uint16_t BSP_LCD_GetTextColor(void);
|
||||
uint16_t BSP_LCD_GetBackColor(void);
|
||||
void BSP_LCD_SetTextColor(__IO uint16_t Color);
|
||||
void BSP_LCD_SetBackColor(__IO uint16_t Color);
|
||||
void BSP_LCD_SetFont(sFONT *fonts);
|
||||
sFONT *BSP_LCD_GetFont(void);
|
||||
|
||||
void BSP_LCD_Clear(uint16_t Color);
|
||||
void BSP_LCD_ClearStringLine(uint16_t Line);
|
||||
void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr);
|
||||
void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Line_ModeTypdef Mode);
|
||||
void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii);
|
||||
void BSP_LCD_DisplayStringOnMultilayerChar(uint16_t Xpos, uint16_t Ypos, uint8_t *Chars, uint16_t *Colors, sFONT *sf,
|
||||
uint16_t onX, uint16_t onY, uint8_t *onChars);
|
||||
|
||||
void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code);
|
||||
void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
|
||||
void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
|
||||
void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
|
||||
void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
|
||||
void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount);
|
||||
void BSP_LCD_DrawEllipse(uint16_t Xpos, uint16_t Ypos, uint16_t XRadius, uint16_t YRadius);
|
||||
void BSP_LCD_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pBmp);
|
||||
void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
|
||||
void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
|
||||
void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount);
|
||||
void BSP_LCD_FillEllipse(uint16_t Xpos, uint16_t Ypos, uint16_t XRadius, uint16_t YRadius);
|
||||
void BSP_LCD_FillTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3);
|
||||
|
||||
void BSP_LCD_DisplayOff(void);
|
||||
void BSP_LCD_DisplayOn(void);
|
||||
|
||||
uint32_t BSP_LCD_ReadID(void);
|
||||
uint16_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos);
|
||||
void BSP_LCD_DrawRGB16Image(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint16_t *pData);
|
||||
void BSP_LCD_ReadRGB16Image(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint16_t *pData);
|
||||
void BSP_LCD_Scroll(int16_t Scroll, uint16_t TopFix, uint16_t BottonFix);
|
||||
|
||||
/* User direct Lcd data write and read */
|
||||
void BSP_LCD_DataWrite8(uint16_t Cmd, uint8_t *ptr, uint32_t Size);
|
||||
void BSP_LCD_DataWrite16(uint16_t Cmd, uint16_t *ptr, uint32_t Size);
|
||||
void BSP_LCD_DataRead8(uint16_t Cmd, uint8_t *ptr, uint32_t Size);
|
||||
void BSP_LCD_DataRead16(uint16_t Cmd, uint16_t *ptr, uint32_t Size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32_ADAFRUIT_LCD_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
181
Core/Src/Lcd/stm32_adafruit_ts.c
Normal file
181
Core/Src/Lcd/stm32_adafruit_ts.c
Normal file
@@ -0,0 +1,181 @@
|
||||
#include "main.h"
|
||||
#include "ts.h"
|
||||
#include "stm32_adafruit_ts.h"
|
||||
|
||||
extern TS_DrvTypeDef *ts_drv;
|
||||
|
||||
uint16_t TsXBoundary, TsYBoundary;
|
||||
|
||||
#define MAXCINT1245 262144
|
||||
#define MAXCINT36 1073741824
|
||||
|
||||
ts_cindex cindex = TS_CINDEX;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void BSP_TS_CalibCalc(ts_three_points * tp, ts_three_points * dp, ts_cindex * ci)
|
||||
{
|
||||
long long int i0, i1, i2, i3, i4, i5, i6, i1t, i2t, i3t, i4t, i5t, i6t;
|
||||
int idv = 1, d;
|
||||
|
||||
if(ci == NULL)
|
||||
ci = &cindex;
|
||||
|
||||
i0 = (tp->x0 - tp->x2) * (tp->y1 - tp->y2) - (tp->x1 - tp->x2) * (tp->y0 - tp->y2);
|
||||
i1 = (dp->x0 - dp->x2) * (tp->y1 - tp->y2) - (dp->x1 - dp->x2) * (tp->y0 - tp->y2);
|
||||
i2 = (tp->x0 - tp->x2) * (dp->x1 - dp->x2) - (dp->x0 - dp->x2) * (tp->x1 - tp->x2);
|
||||
i3 = (long long int)tp->y0 * (tp->x2 * dp->x1 - tp->x1 * dp->x2) +
|
||||
(long long int)tp->y1 * (tp->x0 * dp->x2 - tp->x2 * dp->x0) +
|
||||
(long long int)tp->y2 * (tp->x1 * dp->x0 - tp->x0 * dp->x1);
|
||||
i4 = (dp->y0 - dp->y2) * (tp->y1 - tp->y2) - (dp->y1 - dp->y2) * (tp->y0 - tp->y2);
|
||||
i5 = (tp->x0 - tp->x2) * (dp->y1 - dp->y2) - (dp->y0 - dp->y2) * (tp->x1 - tp->x2);
|
||||
i6 = (long long int)tp->y0 * (tp->x2 * dp->y1 - tp->x1 * dp->y2) +
|
||||
(long long int)tp->y1 * (tp->x0 * dp->y2 - tp->x2 * dp->y0) +
|
||||
(long long int)tp->y2 * (tp->x1 * dp->y0 - tp->x0 * dp->y1);
|
||||
i1t = i1; i2t = i2; i3t = i3; i4t = i4; i5t = i5; i6t = i6;
|
||||
do
|
||||
{
|
||||
d = 0;
|
||||
if((i1t >= MAXCINT1245) || (i1t < -MAXCINT1245))
|
||||
{
|
||||
d = 1;
|
||||
i1t /= 2;
|
||||
}
|
||||
if((i2t >= MAXCINT1245) || (i2t < -MAXCINT1245))
|
||||
{
|
||||
d = 1;
|
||||
i2t /= 2;
|
||||
}
|
||||
if((i4t >= MAXCINT1245) || (i4t < -MAXCINT1245))
|
||||
{
|
||||
d = 1;
|
||||
i4t /= 2;
|
||||
}
|
||||
if((i5t >= MAXCINT1245) || (i5t < -MAXCINT1245))
|
||||
{
|
||||
d = 1;
|
||||
i5t /= 2;
|
||||
}
|
||||
if((i3t >= MAXCINT36) || (i3t < -MAXCINT36))
|
||||
{
|
||||
d = 1;
|
||||
i3t /= 2;
|
||||
}
|
||||
if((i6t >= MAXCINT36) || (i6t < -MAXCINT36))
|
||||
{
|
||||
d = 1;
|
||||
i6t /= 2;
|
||||
}
|
||||
if(d)
|
||||
idv *= 2;
|
||||
}while(d);
|
||||
|
||||
if(idv > 1)
|
||||
{
|
||||
i0 /= idv; i1 /= idv; i2 /= idv; i3 /= idv; i4 /= idv; i5 /= idv; i6 /= idv;
|
||||
}
|
||||
|
||||
(*ci)[0] = (int32_t)i0;
|
||||
(*ci)[1] = (int32_t)i1;
|
||||
(*ci)[2] = (int32_t)i2;
|
||||
(*ci)[3] = (int32_t)i3;
|
||||
(*ci)[4] = (int32_t)i4;
|
||||
(*ci)[5] = (int32_t)i5;
|
||||
(*ci)[6] = (int32_t)i6;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* calculate display coordinate from touchscreen coordinate and cindex
|
||||
param:
|
||||
- tx : touchscreen X coordinate
|
||||
- ty : touchscreen Y coordinate
|
||||
- dx* : pointer to display X coordinate
|
||||
- dy* : pointer to display Y coordinate
|
||||
- mx : max display X coordinate
|
||||
- my : max display Y coordinate
|
||||
return: dx, dy */
|
||||
void BSP_TS_DisplaycoordCalc(uint16_t tx, uint16_t ty, uint16_t * dx, uint16_t * dy, uint16_t mx, uint16_t my)
|
||||
{
|
||||
int32_t x, y;
|
||||
x = (cindex[1] * tx + cindex[2] * ty + cindex[3]) / cindex[0];
|
||||
y = (cindex[4] * tx + cindex[5] * ty + cindex[6]) / cindex[0];
|
||||
|
||||
if(x < 0)
|
||||
x = 0;
|
||||
else if(x > mx)
|
||||
x = mx;
|
||||
|
||||
if(y < 0)
|
||||
y = 0;
|
||||
else if(y > my)
|
||||
y = my;
|
||||
|
||||
*dx = x;
|
||||
*dy = y;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Set the cindex values
|
||||
param:
|
||||
- ci: pointer to cindex array */
|
||||
void BSP_TS_SetCindex(ts_cindex * ci)
|
||||
{
|
||||
for(uint32_t i = 0; i < 7; i++)
|
||||
cindex[i] = (*ci)[i];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* Get the cindex values
|
||||
param:
|
||||
- ci: pointer to cindex array */
|
||||
void BSP_TS_GetCindex(ts_cindex * ci)
|
||||
{
|
||||
for(uint32_t i = 0; i < 7; i++)
|
||||
(*ci)[i] = cindex[i];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Initializes and configures the touch screen functionalities and
|
||||
* configures all necessary hardware resources (GPIOs, clocks..).
|
||||
* @param XSize: The maximum X size of the TS area on LCD
|
||||
* @param YSize: The maximum Y size of the TS area on LCD
|
||||
* @retval TS_OK: if all initializations are OK. Other value if error.
|
||||
*/
|
||||
uint8_t BSP_TS_Init(uint16_t XSize, uint16_t YSize)
|
||||
{
|
||||
uint8_t ret = TS_ERROR;
|
||||
|
||||
/* Initialize x and y positions boundaries */
|
||||
TsXBoundary = XSize;
|
||||
TsYBoundary = YSize;
|
||||
|
||||
if(ts_drv)
|
||||
ret = TS_OK;
|
||||
|
||||
if(ret == TS_OK)
|
||||
{
|
||||
/* Initialize the LL TS Driver */
|
||||
ts_drv->Init(0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief Returns status and positions of the touch screen.
|
||||
* @param TsState: Pointer to touch screen current state structure
|
||||
*/
|
||||
void BSP_TS_GetState(TS_StateTypeDef* TsState)
|
||||
{
|
||||
uint16_t tx, ty, dx, dy;
|
||||
|
||||
TsState->TouchDetected = ts_drv->DetectTouch(0);
|
||||
if(TsState->TouchDetected)
|
||||
{
|
||||
ts_drv->GetXY(0, &tx, &ty);
|
||||
BSP_TS_DisplaycoordCalc(tx, ty, &dx, &dy, TsXBoundary-1, TsYBoundary-1);
|
||||
TsState->X = dx;
|
||||
TsState->Y = dy;
|
||||
}
|
||||
}
|
||||
62
Core/Src/Lcd/stm32_adafruit_ts.h
Normal file
62
Core/Src/Lcd/stm32_adafruit_ts.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32_ADAFRUIT_TS_H
|
||||
#define __STM32_ADAFRUIT_TS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
/* Setting section (please set the necessary things in this section) */
|
||||
|
||||
/* These values can be created using appTouchCalib */
|
||||
#define TS_CINDEX {2023493, -178832, -1974, 692966059, 1107, 259356, -49493813}
|
||||
//{-1350650, -134489, 521, 71073115, 348, -104248, 44767250}
|
||||
|
||||
//=============================================================================
|
||||
/* Interface section */
|
||||
|
||||
typedef int32_t ts_cindex[7];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int32_t x0, y0, x1, y1, x2, y2;
|
||||
}ts_three_points;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t TouchDetected;
|
||||
uint16_t X;
|
||||
uint16_t Y;
|
||||
uint16_t Z;
|
||||
}TS_StateTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TS_OK = 0x00,
|
||||
TS_ERROR = 0x01,
|
||||
TS_TIMEOUT = 0x02
|
||||
}TS_StatusTypeDef;
|
||||
|
||||
uint8_t BSP_TS_Init(uint16_t XSize, uint16_t YSize);
|
||||
void BSP_TS_GetState(TS_StateTypeDef *TsState);
|
||||
|
||||
/* Touchscreen calibration (calculates cindex array values from three touchscreen point coordinates)
|
||||
param:
|
||||
- tp : source pointer to three touchscreen coordinates
|
||||
- dp : source pointer to three display coordinates
|
||||
- ci : result pointer to cindex array (if NULL -> puts it in the current cindex)
|
||||
return; cindex values */
|
||||
void BSP_TS_CalibCalc(ts_three_points * tp, ts_three_points * dp, ts_cindex * ci);
|
||||
|
||||
/* Set the current cindex */
|
||||
void BSP_TS_SetCindex(ts_cindex * ci);
|
||||
|
||||
/* Get for current cindex */
|
||||
void BSP_TS_GetCindex(ts_cindex * ci);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32_ADAFRUIT_TS_H */
|
||||
107
Core/Src/Lcd/ts.h
Normal file
107
Core/Src/Lcd/ts.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file ts.h
|
||||
* @author MCD Application Team
|
||||
* @version V4.0.1
|
||||
* @date 21-July-2015
|
||||
* @brief This file contains all the functions prototypes for the Touch Screen driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __TS_H
|
||||
#define __TS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup Components
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup TS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup TS_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup TS_Driver_structure Touch Sensor Driver structure
|
||||
* @{
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
void (*Init)(uint16_t);
|
||||
uint16_t (*ReadID)(uint16_t);
|
||||
void (*Reset)(uint16_t);
|
||||
void (*Start)(uint16_t);
|
||||
uint8_t (*DetectTouch)(uint16_t);
|
||||
void (*GetXY)(uint16_t, uint16_t*, uint16_t*);
|
||||
void (*EnableIT)(uint16_t);
|
||||
void (*ClearIT)(uint16_t);
|
||||
uint8_t (*GetITStatus)(uint16_t);
|
||||
void (*DisableIT)(uint16_t);
|
||||
}TS_DrvTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TS_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
229
Core/Src/Lcd/ts_xpt2046.c
Normal file
229
Core/Src/Lcd/ts_xpt2046.c
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* XPT2046 HAL touch driver
|
||||
* author: Roberto Benjami
|
||||
* v.2023.04
|
||||
*
|
||||
* - software and hardware SPI
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "main.h"
|
||||
#include "lcd.h"
|
||||
#include "ts.h"
|
||||
#include "ts_xpt2046.h"
|
||||
|
||||
#if defined(STM32H5) || defined(STM32H7) || defined(STM32WBA)
|
||||
#define TS_SPI_SETBAUDRATE(htsspi, br) MODIFY_REG(htsspi.Instance->CFG1, SPI_CFG1_MBR, br << SPI_CFG1_MBR_Pos)
|
||||
#else
|
||||
#define TS_SPI_SETBAUDRATE(htsspi, br) MODIFY_REG(htsspi.Instance->CR1, SPI_CR1_BR, br << SPI_CR1_BR_Pos)
|
||||
#endif
|
||||
|
||||
#if !defined(TS_SPI_HANDLE) || TS_SPI_HANDLE == -1 || TS_CS_MODE == 0
|
||||
#define TS_CS_ON HAL_GPIO_WritePin(TS_CS_GPIO_Port, TS_CS_Pin, GPIO_PIN_RESET)
|
||||
#define TS_CS_OFF HAL_GPIO_WritePin(TS_CS_GPIO_Port, TS_CS_Pin, GPIO_PIN_SET)
|
||||
#elif TS_CS_MODE == 1
|
||||
#define TS_CS_ON
|
||||
#define TS_CS_OFF
|
||||
#endif
|
||||
|
||||
//=============================================================================
|
||||
|
||||
/* if not used the TS_IRQ pin -> Z1-Z2 touch sensitivy */
|
||||
#define TS_ZSENS 128
|
||||
|
||||
#define TS_SPI_TIMEOUT HAL_MAX_DELAY
|
||||
|
||||
#define XPT2046_MODE 0
|
||||
#define XPT2046_SER 0
|
||||
#define XPT2046_PD 0
|
||||
#define XPT2046_CMD_GETTEMP ((1 << 7) | (0 << 4) | (XPT2046_MODE << 3) | (XPT2046_SER << 2) | XPT2046_PD)
|
||||
#define XPT2046_CMD_GETTVBAT ((1 << 7) | (2 << 4) | (XPT2046_MODE << 3) | (XPT2046_SER << 2) | XPT2046_PD)
|
||||
#define XPT2046_CMD_GETX ((1 << 7) | (5 << 4) | (XPT2046_MODE << 3) | (XPT2046_SER << 2) | XPT2046_PD)
|
||||
#define XPT2046_CMD_GETY ((1 << 7) | (1 << 4) | (XPT2046_MODE << 3) | (XPT2046_SER << 2) | XPT2046_PD)
|
||||
#define XPT2046_CMD_GETZ1 ((1 << 7) | (3 << 4) | (XPT2046_MODE << 3) | (XPT2046_SER << 2) | XPT2046_PD)
|
||||
#define XPT2046_CMD_GETZ2 ((1 << 7) | (4 << 4) | (XPT2046_MODE << 3) | (XPT2046_SER << 2) | XPT2046_PD)
|
||||
|
||||
#define ABS(N) (((N)<0) ? (-(N)) : (N))
|
||||
|
||||
//=============================================================================
|
||||
|
||||
static uint16_t tx, ty;
|
||||
|
||||
//=============================================================================
|
||||
/* TS chip select pin set */
|
||||
void xpt2046_ts_Init(uint16_t DeviceAddr);
|
||||
uint8_t xpt2046_ts_DetectTouch(uint16_t DeviceAddr);
|
||||
void xpt2046_ts_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
|
||||
|
||||
//=============================================================================
|
||||
#if defined(__CC_ARM)
|
||||
#pragma push
|
||||
#pragma O0
|
||||
#elif defined(__GNUC__)
|
||||
#pragma GCC push_options
|
||||
#pragma GCC optimize("O0")
|
||||
#endif
|
||||
void TS_IO_Delay(uint32_t c)
|
||||
{
|
||||
while(c--);
|
||||
}
|
||||
#if defined(__CC_ARM)
|
||||
#pragma pop
|
||||
#elif defined(__GNUC__)
|
||||
#pragma GCC pop_options
|
||||
#endif
|
||||
|
||||
#if !defined(TS_SPI_HANDLE) || TS_SPI_HANDLE == -1
|
||||
|
||||
#if TS_SPI_SPD > 0
|
||||
#define TS_CLK_DELAY TS_IO_Delay(TS_SPI_SPD);
|
||||
#else
|
||||
#define TS_CLK_DELAY
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
uint16_t TS_IO_Transaction(uint8_t cmd)
|
||||
{
|
||||
uint16_t ret = 0;
|
||||
uint32_t i;
|
||||
TS_CS_ON;
|
||||
for(i=0; i<8; i++)
|
||||
{
|
||||
HAL_GPIO_WritePin(TS_MOSI_GPIO_Port, TS_MOSI_Pin, cmd & 0x80);
|
||||
TS_CLK_DELAY;
|
||||
HAL_GPIO_WritePin(TS_SCK_GPIO_Port, TS_SCK_Pin, GPIO_PIN_SET);
|
||||
TS_CLK_DELAY;
|
||||
HAL_GPIO_WritePin(TS_SCK_GPIO_Port, TS_SCK_Pin, GPIO_PIN_RESET);
|
||||
cmd <<= 1;
|
||||
}
|
||||
|
||||
#if XPT2046_READDELAY > 0
|
||||
TS_IO_Delay(XPT2046_READDELAY);
|
||||
#endif
|
||||
|
||||
HAL_GPIO_WritePin(TS_MOSI_GPIO_Port, TS_MOSI_Pin, GPIO_PIN_RESET);
|
||||
for(i=0; i<16; i++)
|
||||
{
|
||||
ret <<= 1;
|
||||
TS_CLK_DELAY;
|
||||
HAL_GPIO_WritePin(TS_SCK_GPIO_Port, TS_SCK_Pin, GPIO_PIN_SET);
|
||||
if(HAL_GPIO_ReadPin(TS_MISO_GPIO_Port, TS_MISO_Pin))
|
||||
ret |= 1;
|
||||
TS_CLK_DELAY;
|
||||
HAL_GPIO_WritePin(TS_SCK_GPIO_Port, TS_SCK_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
TS_CS_OFF;
|
||||
return ((ret & 0x7FFF) >> 3);
|
||||
}
|
||||
#else
|
||||
|
||||
extern SPI_HandleTypeDef TS_SPI_HANDLE;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
uint16_t TS_IO_Transaction(uint8_t cmd)
|
||||
{
|
||||
const uint16_t d = 0;
|
||||
uint16_t ret;
|
||||
TS_CS_ON;
|
||||
HAL_SPI_Transmit(&TS_SPI_HANDLE, (uint8_t *)&cmd, 1, TS_SPI_TIMEOUT);
|
||||
#if XPT2046_READDELAY > 0
|
||||
TS_IO_Delay(XPT2046_READDELAY);
|
||||
#endif
|
||||
HAL_SPI_TransmitReceive(&TS_SPI_HANDLE, (uint8_t *)&d, (uint8_t *)&ret, 2, TS_SPI_TIMEOUT);
|
||||
TS_CS_OFF;
|
||||
ret = __REVSH(ret);
|
||||
return ((ret & 0x7FFF) >> 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/* return:
|
||||
- 0 : touchscreen is not pressed
|
||||
- 1 : touchscreen is pressed */
|
||||
uint8_t TS_IO_DetectToch(void)
|
||||
{
|
||||
uint8_t ret;
|
||||
#if defined(TS_IRQ_GPIO_Port) && defined (TS_IRQ_Pin)
|
||||
if(HAL_GPIO_ReadPin(TS_IRQ_GPIO_Port, TS_IRQ_Pin))
|
||||
ret = 0;
|
||||
else
|
||||
ret = 1;
|
||||
#else
|
||||
if((TS_IO_Transaction(XPT2046_CMD_GETZ1) > TS_ZSENS) || (TS_IO_Transaction(XPT2046_CMD_GETZ2) < (4095 - TS_ZSENS)))
|
||||
ret = 1;
|
||||
else
|
||||
ret = 0;
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
TS_DrvTypeDef xpt2046_ts_drv =
|
||||
{
|
||||
xpt2046_ts_Init,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
xpt2046_ts_DetectTouch,
|
||||
xpt2046_ts_GetXY,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
TS_DrvTypeDef *ts_drv = &xpt2046_ts_drv;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void xpt2046_ts_Init(uint16_t DeviceAddr)
|
||||
{
|
||||
#if TS_SPI_HANDLE != -1 && defined(TS_SPI_SPD) && TS_SPI_SPD >= 0 && TS_SPI_SPD <= 7
|
||||
TS_SPI_SETBAUDRATE(TS_SPI_HANDLE, TS_SPI_SPD);
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
uint8_t xpt2046_ts_DetectTouch(uint16_t DeviceAddr)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
int32_t x1, x2, y1, y2, i;
|
||||
|
||||
if(TS_IO_DetectToch())
|
||||
{
|
||||
x1 = TS_IO_Transaction(XPT2046_CMD_GETX); /* Get X */
|
||||
y1 = TS_IO_Transaction(XPT2046_CMD_GETY); /* Get Y */
|
||||
i = TOUCH_MAXREPEAT;
|
||||
while(i--)
|
||||
{
|
||||
x2 = TS_IO_Transaction(XPT2046_CMD_GETX); /* Get X */
|
||||
y2 = TS_IO_Transaction(XPT2046_CMD_GETY); /* Get Y */
|
||||
if((ABS(x1 - x2) < TOUCH_FILTER) && (ABS(y1 - y2) < TOUCH_FILTER))
|
||||
{
|
||||
x1 = (x1 + x2) >> 1;
|
||||
y1 = (y1 + y2) >> 1;
|
||||
i = 0;
|
||||
if(TS_IO_DetectToch())
|
||||
{
|
||||
tx = x1;
|
||||
ty = y1;
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void xpt2046_ts_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
|
||||
{
|
||||
*X = tx,
|
||||
*Y = ty;
|
||||
}
|
||||
117
Core/Src/Lcd/ts_xpt2046.h
Normal file
117
Core/Src/Lcd/ts_xpt2046.h
Normal file
@@ -0,0 +1,117 @@
|
||||
//=============================================================================
|
||||
/* Information section */
|
||||
|
||||
/*
|
||||
* XPT2046 touch driver
|
||||
* author: Roberto Benjami
|
||||
* v.2023.03
|
||||
*/
|
||||
|
||||
/* Settings in CUBEIDE or CUBEMX
|
||||
|
||||
If software SPI
|
||||
GPIO
|
||||
- Touchscreen SCK
|
||||
- output level: Low
|
||||
- mode: Output Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: TS_SCK
|
||||
- Touchscreen MOSI
|
||||
- output level: Low
|
||||
- mode: Output Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: TS_MOSI
|
||||
- Touchscreen MISO
|
||||
- output level: n/a
|
||||
- mode: Input mode
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: n/a
|
||||
- User Label: TS_MISO
|
||||
- Touchscreen chip select:
|
||||
- output level: High
|
||||
- mode: Output Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: TS_CS
|
||||
|
||||
If hardvare SPI
|
||||
SPI Parameter Settings
|
||||
- Mode: "Full duplex master"
|
||||
- Hardware NSS signal: disabled or enabled (see the Touchscreen chip select GPIO setting)
|
||||
- Frame format: Motorola
|
||||
- Data Size: 8 bits
|
||||
- First bit: MSB first
|
||||
- Prescaler: 64 (you can experiment with higher speeds)
|
||||
- Clock Polarity: Low
|
||||
- Clock Phase: 1 Edge
|
||||
note: if the selected SPI pin is not good, change it in the pinout view
|
||||
GPIO
|
||||
- Touchscreen SCK
|
||||
- output level: n/a
|
||||
- mode: Alternate Function Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: TS_SCK
|
||||
- Touchscreen MOSI
|
||||
- output level: n/a
|
||||
- mode: Alternate Function Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: TS_MOSI
|
||||
- Touchscreen MISO
|
||||
- output level: n/a
|
||||
- mode: Alternate Function Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: TS_MISO
|
||||
- Touchscreen chip select (if hardware NSS signal == disabled)
|
||||
- output level: High
|
||||
- mode: Output Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: TS_CS
|
||||
- Touchscreen chip select (if hardware NSS signal == enabled)
|
||||
- output level: n/a
|
||||
- mode: Alternate Function Push Pull
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: Very High
|
||||
- User Label: TS_CS
|
||||
|
||||
Software and hardware SPI
|
||||
GPIO
|
||||
- Touchscreen IRQ (only when connected)
|
||||
- output level: n/a
|
||||
- mode: Input mode
|
||||
- Pull-up/Pull-down: No pull-up and no pull-down
|
||||
- Max output speed: n/a
|
||||
- User Label: TS_IRQ
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
/* Setting section (please set the necessary things in this section) */
|
||||
|
||||
/* SPI handle select
|
||||
- software SPI (set this macro value: -1, set in CUBEMX the TS_CS, TS_SCK, TS_MISO, TS_MOSI, TS_IRQ pin)
|
||||
- hardware SPI handle: see in main.c file (default: hspi1, hspi2 ... hspi6) */
|
||||
#define TS_SPI_HANDLE hspi2
|
||||
|
||||
/* SPI CS mode (only hardware SPI)
|
||||
- 0: software CS operation (hardware NSS signal: disabled)
|
||||
- 1: hardware CS operation (hardware NSS signal: enabled) */
|
||||
#define TS_CS_MODE 1
|
||||
|
||||
/* SPI write and read speed (if deleted and hardware SPI -> setting in CUBEMX)
|
||||
- software SPI: TS_SCK clock delay (see the TS_IO_Delay function)
|
||||
- hardware SPI: clock div fPCLK: 0=/2, 1=/4, 2=/8, 3=/16, 4=/32, 5=/64, 6=/128, 7=/256 */
|
||||
#define TS_SPI_SPD 5
|
||||
|
||||
/* Wait time before reading xpt2046 (see: TS_IO_Transaction and TS_IO_Delay dunctions) */
|
||||
#define XPT2046_READDELAY 0
|
||||
|
||||
/* The touch value that it still accepts as the same value */
|
||||
#define TOUCH_FILTER 40
|
||||
|
||||
/* This is how many times it tries to read the same value */
|
||||
#define TOUCH_MAXREPEAT 8
|
||||
Reference in New Issue
Block a user