WIP, ui_menu

This commit is contained in:
Sheikah
2023-02-05 00:52:46 +08:00
parent a6d091a7e5
commit 30ece44ea4
20 changed files with 443 additions and 77 deletions

View File

@ -77,7 +77,7 @@ static const uint8_t
ST7735_DISPON, DELAY, // 4: Main screen turn on, no args w/delay
100}; // 100 ms delay
static void ST7735_Select()
void ST7735_Select()
{
HAL_GPIO_WritePin(ST7735_CS_GPIO_Port, ST7735_CS_Pin, GPIO_PIN_RESET);
}
@ -87,21 +87,21 @@ void ST7735_Unselect()
HAL_GPIO_WritePin(ST7735_CS_GPIO_Port, ST7735_CS_Pin, GPIO_PIN_SET);
}
static void ST7735_Reset()
void ST7735_Reset()
{
HAL_GPIO_WritePin(ST7735_RES_GPIO_Port, ST7735_RES_Pin, GPIO_PIN_RESET);
HAL_Delay(5);
HAL_GPIO_WritePin(ST7735_RES_GPIO_Port, ST7735_RES_Pin, GPIO_PIN_SET);
}
static void ST7735_WriteCommand(uint8_t cmd)
void ST7735_WriteCommand(uint8_t cmd)
{
HAL_GPIO_WritePin(ST7735_DC_GPIO_Port, ST7735_DC_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(&ST7735_SPI_PORT, &cmd, sizeof(cmd), HAL_MAX_DELAY);
// SPI_Write(&cmd, sizeof(cmd));
}
static void ST7735_WriteData(uint8_t *buff, size_t buff_size)
void ST7735_WriteData(uint8_t *buff, size_t buff_size)
{
HAL_GPIO_WritePin(ST7735_DC_GPIO_Port, ST7735_DC_Pin, GPIO_PIN_SET);
HAL_SPI_Transmit(&ST7735_SPI_PORT, buff, buff_size, HAL_MAX_DELAY);
@ -139,7 +139,7 @@ static void ST7735_ExecuteCommandList(const uint8_t *addr)
}
}
static void ST7735_SetAddressWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
void ST7735_SetAddressWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
{
// column address set
ST7735_WriteCommand(ST7735_CASET);
@ -178,54 +178,61 @@ void ST7735_DrawPixel(uint16_t x, uint16_t y, uint16_t color) //画点
ST7735_Unselect();
}
void ST7735_DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,uint16_t color) //画线
void ST7735_DrawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2,uint16_t color)
{
int16_t temp;
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
temp = x0;
x0 = y0;
y0 = temp;
temp = x1;
x0 = y1;
y1 = temp;
}
if (x0 > x1) {
temp = x1;
x1 = x0;
x0 = temp;
temp = y1;
y1 = y0;
y0 = temp;
}
int16_t dx, dy;
dx = x1 - x0;
dy = abs(y1 - y0);
int16_t err = dx / 2;
int16_t ystep;
if (y0 < y1) {
ystep = 1;
int16_t dx = x2 - x1;
int16_t sx;
if (dx > 0) {
sx = 1;
} else {
ystep = -1;
dx = -dx;
sx = -1;
}
for (; x0 <= x1; x0++) {
int16_t dy = y2 - y1;
int16_t sy;
if (dy > 0) {
sy = 1;
} else {
dy = -dy;
sy = -1;
}
uint8_t steep;
if (dy > dx) {
int16_t temp;
temp = x1;
x1 = y1;
y1 = temp;
temp = dx;
dx = dy;
dy = temp;
temp = sx;
sx = sy;
sy = temp;
steep = 1;
} else {
steep = 0;
}
int16_t e = 2 * dy - dx;
int16_t i;
for (i = 0; i < dx; ++i) {
if (steep) {
ST7735_DrawPixel(y0, x0, color);
if (0 <= y1 && y1 < ST7735_WIDTH && 0 <= x1 && x1 < ST7735_HEIGHT) {
ST7735_DrawPixel(y1, x1, color);
}
} else {
ST7735_DrawPixel(x0, y0, color);
if (0 <= x1 && x1 < ST7735_WIDTH && 0 <= y1 && y1 < ST7735_HEIGHT) {
ST7735_DrawPixel(x1, y1, color);
}
}
err -= dy;
if (err < 0) {
y0 += ystep;
err += dx;
while (e >= 0) {
y1 += sy;
e -= 2 * dx;
}
x1 += sx;
e += 2 * dy;
}
if (0 <= x2 && x2 < ST7735_WIDTH && 0 <= y2 && y2 < ST7735_HEIGHT) {
ST7735_DrawPixel(x2, y2, color);
}
}

View File

@ -237,6 +237,11 @@ extern SPI_HandleTypeDef ST7735_SPI_PORT;
// call before initializing any SPI devices
void ST7735_Unselect(void);
void ST7735_Select(void);
void ST7735_Reset(void);
void ST7735_WriteCommand(uint8_t cmd);
void ST7735_WriteData(uint8_t *buff, size_t buff_size);
void ST7735_SetAddressWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
void ST7735_Init(void);
void ST7735_DrawPixel(uint16_t x, uint16_t y, uint16_t color);