Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions hardware/st7735/st7735.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "st7735.h"
#include "time.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/sysinfo.h>
#include <sys/vfs.h>
Expand Down Expand Up @@ -40,25 +41,28 @@ void lcd_set_address_window(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
*/
void lcd_write_char(uint16_t x, uint16_t y, char ch, FontDef font, uint16_t color, uint16_t bgcolor)
{
uint32_t i, b, j;
size_t fbsize = font.height * font.width * sizeof(uint16_t);
uint16_t *buff;
uint32_t i, b, j, offset;

lcd_set_address_window(x, y, x + font.width - 1, y + font.height - 1);
/* Allocate a buffer to hold the screen data */
buff = malloc(fbsize);
if (!buff) return;

/* Render the character to the buffer */
for (i = 0; i < font.height; i++)
{
offset = i * font.width;
b = font.data[(ch - 32) * font.height + i];
for (j = 0; j < font.width; j++)
{
if ((b << j) & 0x8000)
{
i2c_write_data(color >> 8, color & 0xFF);
}
else
{
i2c_write_data(bgcolor >> 8, bgcolor & 0xFF);
}
buff[offset + j] = ((b << j) & 0x8000) ? color : bgcolor;
}
}

/* Push the image to the screen */
lcd_draw_image(x, y, font.width, font.height, (uint8_t*)buff);
free(buff);
}

void lcd_write_ch(uint16_t x, uint16_t y, char ch, FontType font, uint16_t color, uint16_t bgcolor)
Expand Down Expand Up @@ -106,7 +110,6 @@ void lcd_write_string(uint16_t x, uint16_t y, char *str, FontDef font, uint16_t
}

lcd_write_char(x, y, *str, font, color, bgcolor);
i2c_write_command(SYNC_REG, 0x00, 0x01);
x += font.width;
str++;
}
Expand Down Expand Up @@ -141,9 +144,9 @@ void lcd_fill_rectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t
// clipping
if ((x >= ST7735_WIDTH) || (y >= ST7735_HEIGHT))
return;
if ((x + w - 1) >= ST7735_WIDTH)
if ((x + w) >= ST7735_WIDTH)
w = ST7735_WIDTH - x;
if ((y + h - 1) >= ST7735_HEIGHT)
if ((y + h) >= ST7735_HEIGHT)
h = ST7735_HEIGHT - y;
lcd_set_address_window(x, y, x + w - 1, y + h - 1);

Expand All @@ -170,10 +173,8 @@ void lcd_fill_screen(uint16_t color)

void lcd_draw_image(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t *data)
{
uint16_t col = h - y;
uint16_t row = w - x;
lcd_set_address_window(x, y, x + w - 1, y + h - 1);
i2c_burst_transfer(data, sizeof(uint16_t) * col * row);
i2c_burst_transfer(data, sizeof(uint16_t) * w * h);
}

uint8_t lcd_begin(void)
Expand Down