?? mfcf31f.tmp
字號:
#include "HMI.h"
void HMI_Data_TX(uint8_t *DataBaseADD, uint16_t DataLen)
{
// DMA_DeInit(LCD_MASTER_DMA_CHN);
sta_DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)DataBaseADD;
sta_DMA_InitStructure.DMA_BufferSize = DataLen;
DMA_Init(LCD_MASTER_DMA_CHN, &sta_DMA_InitStructure);
DMA_Cmd(LCD_MASTER_DMA_CHN, ENABLE);
}
void HMI_Queue_Slot_Free(struct_HMI_Queue *HMI_Queue_Slot)
{
// First try to find if there is some malloced space in HMI_Queue_Slot->HMI_Func_Para
if (HMI_Queue_Slot->HMI_Func_Para != NULL)
{
switch (HMI_Queue_Slot->HMI_Function_Index)
{
case ENUM_HMI_CMD_STREAM:
if __IS_IN_HEAP(((struct_HMI_CMD_Para *)(HMI_Queue_Slot->HMI_Func_Para))->DataList)
{
free(((struct_HMI_CMD_Para *)(HMI_Queue_Slot->HMI_Func_Para))->DataList);
}
break;
default:
break;
}
// free HMI_Queue_Slot->HMI_Func_Para
free((struct_HMI_CMD_Para *)(HMI_Queue_Slot->HMI_Func_Para));
}
// Clear Function Index to NULL
HMI_Queue_Slot->HMI_Function_Index = ENUM_HMI_NULL;
}
__INLINE uint8_t ByteShift(uint8_t inputByte, int8_t shiftIndex, uint8_t *excreteByte)
{
if (shiftIndex > 0)
{
*excreteByte = inputByte >> (8 - shiftIndex);
return (inputByte << shiftIndex);
}
// else if (0 == shiftIndex)
// {// *excreteByte = 0;
// return inputByte;
// }
else
{
*excreteByte = inputByte << (8 + shiftIndex);
return (inputByte >> (-shiftIndex));
}
}
__INLINE uint8_t GRAM_ByteReplace(uint8_t *GRAMByte, uint8_t lastByte, uint8_t thisByte, uint8_t shiftIndex)
{
*GRAMByte = lastByte | (thisByte << shiftIndex);
return (thisByte >> (8 - shiftIndex));
}
__INLINE uint8_t GRAM_ByteOr(uint8_t *GRAMByte, uint8_t lastByte, uint8_t thisByte, uint8_t shiftIndex)
{
*GRAMByte |= lastByte | (thisByte << shiftIndex);
return (thisByte >> (8 - shiftIndex));
}
void HMI_Configuration()
{
SPI_InitTypeDef SPI_InitStructure;
/* LCD_SPI_MASTER configuration ------------------------------------------------------*/
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; // Only TX
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; // Master of course
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; // 8bit format
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // High in idle
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // Rising edge capture (TBD)
SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;
// 72M for APB2, 4M max reqirement for LCD IF, so divide 32 = 2.25M for SPI CLK
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // Accroding to LCD datasheet, first bit is MSB
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(LCD_MASTER_SPI, &SPI_InitStructure);
/* SPI_DMA_Channel configuration ---------------------------------------------*/
// Here only focus on some FIXED parameter, other parameter will be adjusted according to different event
// like send command or fill rectangle...
DMA_DeInit(LCD_MASTER_DMA_CHN);
sta_DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&(LCD_MASTER_SPI->DR));
sta_DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)sta_LCD_Graphic_BUF;
sta_DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
sta_DMA_InitStructure.DMA_BufferSize = 0x10; // Whatever
sta_DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
sta_DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
sta_DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
sta_DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
sta_DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
sta_DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
sta_DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(LCD_MASTER_DMA_CHN, &sta_DMA_InitStructure);
DMA_ITConfig(LCD_MASTER_DMA_CHN, DMA_IT_TC, ENABLE);
/* Enable SPI_MASTER NSS output for master mode */
SPI_SSOutputCmd(LCD_MASTER_SPI, ENABLE);
/* Enable SPI_MASTER */
SPI_Cmd(LCD_MASTER_SPI, ENABLE);
/* Enable LCD_SPI's TX DMA */
SPI_I2S_DMACmd(LCD_MASTER_SPI, SPI_I2S_DMAReq_Tx, ENABLE);
/* Enable DMA1 Channel4 */
//DMA_Cmd(LCD_MASTER_DMA_CHN, ENABLE);
}
ErrorStatus HMI_StartUp_Config(void)
{
struct_HMI_Queue *foundQueueSlot;
// Fill in the HMI to do list queue with configuration task
foundQueueSlot = HMI_Find_Queue_Slot(HMI_TASK_TYPE_BUS);
// sta_QueueIndex = foundQueueSlot - gHMI_Queue; // sta_QueueIndex should start at gHMI_Queue (0), but ...
foundQueueSlot->HMI_Func_Para = malloc(sizeof(struct_HMI_CMD_Para));
if (NULL != foundQueueSlot->HMI_Func_Para)
{
foundQueueSlot->HMI_Function_Index = ENUM_HMI_CMD_STREAM;
((struct_HMI_CMD_Para *)(foundQueueSlot->HMI_Func_Para))->DataList = (uint8_t *)const_HMI_Startup_Config;
((struct_HMI_CMD_Para *)(foundQueueSlot->HMI_Func_Para))->DataLen = sizeof(const_HMI_Startup_Config); //HMI_STARTUP_CONFIG_LEN;
}
else
{
FLAG_HEAP_FULL = SET;
return ERROR;
}
return SUCCESS;
}
struct_HMI_Queue *HMI_Find_Queue_Slot(TYPE_HMI_TASK_TYPE taskType)
{
uint8_t temp_QueueIndex;
if (HMI_TASK_TYPE_BUS == taskType)
{
if (NULL == (*(gHMI_Queue + sta_QueueIndex)).HMI_Function_Index)
{
return (gHMI_Queue + sta_QueueIndex);
}
else
{
temp_QueueIndex = sta_QueueIndex + 1;
while (temp_QueueIndex < HMI_QUEUE_LEN)
{
if (NULL == (*(gHMI_Queue + temp_QueueIndex)).HMI_Function_Index)
{
return (gHMI_Queue + temp_QueueIndex);
}
temp_QueueIndex++;
}
temp_QueueIndex = 0;
while (temp_QueueIndex < sta_QueueIndex)
{
if (NULL == (*(gHMI_Queue + temp_QueueIndex)).HMI_Function_Index)
{
return (gHMI_Queue + temp_QueueIndex);
}
temp_QueueIndex++;
}
return NULL;
}
}
else
{
if (NULL == (*(gHMI_Queue_NoBus + sta_QueueIndex_NoBus)).HMI_Function_Index)
{
return (gHMI_Queue_NoBus + sta_QueueIndex_NoBus);
}
else
{
temp_QueueIndex = sta_QueueIndex_NoBus + 1;
while (temp_QueueIndex < HMI_NO_BUS_QUEUE_LEN)
{
if (NULL == (*(gHMI_Queue_NoBus + temp_QueueIndex)).HMI_Function_Index)
{
return (gHMI_Queue_NoBus + temp_QueueIndex);
}
temp_QueueIndex++;
}
temp_QueueIndex = 0;
while (temp_QueueIndex < sta_QueueIndex_NoBus)
{
if (NULL == (*(gHMI_Queue_NoBus + temp_QueueIndex)).HMI_Function_Index)
{
return (gHMI_Queue_NoBus + temp_QueueIndex);
}
temp_QueueIndex++;
}
return NULL;
}
}
}
WorkingStatus HMI_CMD_Stream(void *HMI_CMD_Para)
{
GPIO_ResetBits(LCD_DC_PORT, LCD_DC_PIN); // Pull down D/_C to enter command mode
HMI_Data_TX(((struct_HMI_CMD_Para *)HMI_CMD_Para)->DataList, ((struct_HMI_CMD_Para *)HMI_CMD_Para)->DataLen);
return FINISHED;
}
// Functions WO "ex" is first write to STM32 internal RAM then flush to LCD, they will ONLY return "FINISHIED"
WorkingStatus HMI_Draw_Point_CMD(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_Point_Data(void *HMI_Draw_Para)
{
uint8_t tempStartRowIndex, tempRowRemain_Start;
tempStartRowIndex = ((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointY / HMI_ROW_WIDTH;
tempRowRemain_Start = ((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointY % HMI_ROW_WIDTH;
// Robust Check, make sure no out border
if (((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointX >= HMI_WIDTH_PIX)
{
((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointX = 0;
((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointY = ((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointY + 1;
}
if (((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointY >= HMI_HEIGHT_PIX)
{
((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointY = 0;
}
if (HMI_COLOR_WHITE == ((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->color)
{
sta_LCD_Graphic_BUF[tempStartRowIndex][((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointX] &= ~(1 << tempRowRemain_Start);
}
else
{
sta_LCD_Graphic_BUF[tempStartRowIndex][((struct_HMI_Draw_Para_Point *)HMI_Draw_Para)->pointX] |= (1 << tempRowRemain_Start);
}
HMI_Data_TX(sta_LCD_Graphic_BUF[0], MAX_DISPLAY_BUF);
return FINISHED;
}
WorkingStatus HMI_Draw_Line_CMD(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_Line_Data(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_Rect_CMD(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_Rect_Data(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_Char_CMD(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_Char_Data(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_String_CMD(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_String_Data(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_Pic_CMD(void *HMI_Draw_Para)
{
return FINISHED;
}
WorkingStatus HMI_Draw_Pic_Data(void *HMI_Draw_Para)
{ // There are 2 kinds of picture row:
// 1. Full row, just copy all data to RAM
// 2. Partial row, it ONLY can happen at the first and last row, OR logical is needed
uint8_t tempRowNUM, tempStartRowIndex, tempLastRowIndex, tempRowRemain_Start, tempRowRemain_End, temp_i, temp_n;
uint16_t temp_Column; // For not 8bits multiple calculation
uint8_t tempRow[HMI_WIDTH_PIX];
GPIO_SetBits(LCD_DC_PORT, LCD_DC_PIN); // Pull up D/_C to enter data mode
// Robust Check, make sure no out border
if (((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX >= HMI_WIDTH_PIX)
{
((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX = 0;
((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startY = ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startY + HMI_ROW_WIDTH;
}
if (((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startY >= HMI_HEIGHT_PIX)
{
((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startY = 0;
}
if ((((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX + ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->width) > HMI_WIDTH_PIX)
{
((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->width = HMI_WIDTH_PIX - ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX;
}
if ((((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startY + ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->height) > HMI_HEIGHT_PIX)
{
((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->height = HMI_HEIGHT_PIX - ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startY;
}
// In future may be I will also check if the demand to draw size is bigger than pic's size to prevent verflow
// But for now this will only cause some scatter image, will NOT induce program fault
tempStartRowIndex = ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startY / HMI_ROW_WIDTH;
tempRowRemain_Start = ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startY % HMI_ROW_WIDTH;
tempRowNUM = (((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->height - tempRowRemain_Start) / HMI_ROW_WIDTH;
tempLastRowIndex = tempStartRowIndex + tempRowNUM - 1;
tempRowRemain_End = (((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->height - tempRowRemain_Start) % HMI_ROW_WIDTH;
if (0 == tempRowRemain_Start)
{ // The first Row is full, suggest to use this way or a lot of calculation will be needed
// In this condition just fill all n-1 row and check last row
for (temp_i = tempStartRowIndex; temp_i <= tempLastRowIndex; temp_i++)
{
memcpy((sta_LCD_Graphic_BUF[temp_i] + ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX),
(const_HMI_Pic_Entr[((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->picID])[temp_i],
((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->width);
}
// Last remaind row (if it has)
if (0 != tempRowRemain_End)
{
memcpy((sta_LCD_Graphic_BUF[temp_i] + ((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->startX),
(const_HMI_Pic_Entr[((struct_HMI_Draw_Para_Pic *)HMI_Draw_Para)->picID])[temp_i],
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -