菜单支持,所有功能都测试成功
This commit is contained in:
@@ -125,6 +125,81 @@ void lcd_draw_string(uint16_t x, uint16_t y, const char *str, uint16_t color, ui
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:显示一个6x8 ASCII字符
|
||||
* 入口参数:x - 列坐标
|
||||
* y - 行坐标
|
||||
* ch - 字符 (ASCII 32-126)
|
||||
* color - 字符颜色 (RGB565)
|
||||
* bg_color - 背景颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:LCD_F6x8为列式存储(每字节一列,bit0=顶行,bit7=底行)
|
||||
* 框选6x8区域→逐行逐列取bit→发送color或bg_color
|
||||
*/
|
||||
void lcd_draw_char_6x8(uint16_t x, uint16_t y, char ch, uint16_t color, uint16_t bg_color)
|
||||
{
|
||||
uint8_t row;
|
||||
uint8_t col;
|
||||
uint8_t col_data;
|
||||
|
||||
if (ch < 32 || ch > 126) {
|
||||
ch = ' ';
|
||||
}
|
||||
|
||||
st7735s_set_window(x, y, x + 5, y + 7);
|
||||
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET);
|
||||
|
||||
for (row = 0; row < 8; row++) {
|
||||
for (col = 0; col < 6; col++) {
|
||||
col_data = LCD_F6x8[ch - 32][col];
|
||||
if (col_data & (1 << row)) {
|
||||
st7735s_spi_write_byte((uint8_t)(color >> 8));
|
||||
st7735s_spi_write_byte((uint8_t)(color & 0xFF));
|
||||
} else {
|
||||
st7735s_spi_write_byte((uint8_t)(bg_color >> 8));
|
||||
st7735s_spi_write_byte((uint8_t)(bg_color & 0xFF));
|
||||
}
|
||||
}
|
||||
}
|
||||
HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:显示字符串(6x8字体)
|
||||
* 入口参数:x - 列坐标
|
||||
* y - 行坐标
|
||||
* str - 字符串指针
|
||||
* color - 字符颜色 (RGB565)
|
||||
* bg_color - 背景颜色 (RGB565)
|
||||
* 返回值:无
|
||||
* 函数说明:连续显示6x8字符,自动换行
|
||||
*/
|
||||
void lcd_draw_string_6x8(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bg_color)
|
||||
{
|
||||
uint16_t start_x = x;
|
||||
|
||||
while (*str != '\0') {
|
||||
if (*str == '\n') {
|
||||
y += FONT_HEIGHT_8;
|
||||
x = start_x;
|
||||
str++;
|
||||
continue;
|
||||
}
|
||||
if (x + FONT_WIDTH_6 > s_lcd_width) {
|
||||
y += FONT_HEIGHT_8;
|
||||
x = start_x;
|
||||
}
|
||||
if (y + FONT_HEIGHT_8 > s_lcd_height) {
|
||||
break;
|
||||
}
|
||||
lcd_draw_char_6x8(x, y, *str, color, bg_color);
|
||||
x += FONT_WIDTH_6;
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:显示一个16x16 CJK汉字
|
||||
* 入口参数:x - 列坐标
|
||||
|
||||
Reference in New Issue
Block a user