我尝试使用FSMC将STM32F1与LCD连接。我试图做双缓冲动画,并将帧缓冲阵列复制到LCD缓冲区。问题在于编写如下的阻塞代码时,由于接口等原因,它会占用CPU很多等待周期。还有其他想法或解决方法吗?
void LCD_Flip(void) {
// LCD_SetCursor(0x00, 0x0000);
static u8 s_chState = 0;
switch (s_chState) {
case LCD_FLIP_START:
s_chState = LCD_FLIP_INIT;
break;
case LCD_FLIP_INIT:
s_chState = LCD_FLIP_REFRESH;
break;
case LCD_FLIP_REFRESH:
LCD_WriteRegister(32, 0);
LCD_WriteRegister(33, 0);
LCD_WriteRegister(0x0050,0x00);//GRAM horizontal start position
LCD_WriteRegister(0x0051,fbWidth - 1);//GRAM horizontal end position
LCD_WriteRegister(0x0052,0);//Vertical GRAM Start position
LCD_WriteRegister(0x0053,fbHeight - 1);//Vertical GRAM end position
LCD_WriteIndex(0x0022);
for (uint16_t pixel = 0; pixel < fbHeight * fbWidth; pixel++) {
*(__IO uint16_t *) (Bank1_LCD_D) = frameBuffer[pixel];
}
break;
}
}
我尝试用一个简单的计数器编写一个小型FSM,该计数器用于超级循环main,它保持递增,直到你到达帧缓冲区的末尾,然后你停止复制,但似乎操作是如此之快,LCD控制器可以处理。
类似的东西:
case LCD_FLIP_REFRESH:
LCD_WriteRegister(32, 0);
LCD_WriteRegister(33, 0);
LCD_WriteRegister(0x0050,0x00);//GRAM horizontal start position
LCD_WriteRegister(0x0051,fbWidth - 1);//GRAM horizontal end position
LCD_WriteRegister(0x0052,0);//Vertical GRAM Start position
LCD_WriteRegister(0x0053,fbHeight - 1);//Vertical GRAM end position
LCD_WriteIndex(0x0022);
static int pixel = 0;
if ( pixel > fbWidth*fbHeight )
{
pixel = 0;
}
*(__IO uint16_t *) (Bank1_LCD_D) = frameBuffer[pixel];
pixel++;
break;
}