Skip to content

Commit

Permalink
Remove buffers from hline and vline
Browse files Browse the repository at this point in the history
For some reason this is around 50% slower atm:

50178 -> 24871 vertical lines per second
63583 -> 34266 horizontal lines per second
  • Loading branch information
tuupola committed Mar 11, 2023
1 parent eea43cf commit c0bef1b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
19 changes: 2 additions & 17 deletions hagl_hal_single.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,13 @@ blit(void *self, int16_t x0, int16_t y0, hagl_bitmap_t *src)
static void
hline(void *self, int16_t x0, int16_t y0, uint16_t width, hagl_color_t color)
{
static hagl_color_t line[HAGL_PICO_MIPI_DISPLAY_WIDTH];
const uint16_t height = 1;

for (uint16_t x = 0; x < width; x++) {
line[x] = color;

}

mipi_display_write(x0, y0, width, height, (uint8_t *) line);
mipi_display_fill(x0, y0, width, 1, &color);
}

static void
vline(void *self, int16_t x0, int16_t y0, uint16_t height, hagl_color_t color)
{
static hagl_color_t line[HAGL_PICO_MIPI_DISPLAY_HEIGHT];
const uint16_t width = 1;

for (uint16_t y = 0; y < height; y++) {
line[y] = color;
}

mipi_display_write(x0, y0, width, height, (uint8_t *) line);
mipi_display_fill(x0, y0, 1, height, &color);
}

void
Expand Down
1 change: 1 addition & 0 deletions include/mipi_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern "C" {

void mipi_display_init();
size_t mipi_display_write(uint16_t x1, uint16_t y1, uint16_t w, uint16_t h, uint8_t *buffer);
size_t mipi_display_fill(uint16_t x1, uint16_t y1, uint16_t w, uint16_t h, void *color);
void mipi_display_ioctl(uint8_t command, uint8_t *data, size_t size);
void mipi_display_close();

Expand Down
29 changes: 29 additions & 0 deletions mipi_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,35 @@ void mipi_display_init()
#endif /* HAGL_HAS_HAL_BACK_BUFFER */
}

size_t mipi_display_fill(uint16_t x1, uint16_t y1, uint16_t w, uint16_t h, void *color)
{
if (0 == w || 0 == h) {
return 0;
}

int32_t x2 = x1 + w - 1;
int32_t y2 = y1 + h - 1;
size_t size = w * h;
uint8_t *c = color;

mipi_display_set_address(x1, y1, x2, y2);

/* Set DC high to denote incoming data. */
gpio_put(MIPI_DISPLAY_PIN_DC, 1);

/* Set CS low to reserve the SPI bus. */
gpio_put(MIPI_DISPLAY_PIN_CS, 0);

while (size--) {
spi_write_blocking(MIPI_DISPLAY_SPI_PORT, color, MIPI_DISPLAY_DEPTH / 8);
}

/* Set CS high to ignore any traffic on SPI bus. */
gpio_put(MIPI_DISPLAY_PIN_CS, 1);

return size;
}

size_t mipi_display_write(uint16_t x1, uint16_t y1, uint16_t w, uint16_t h, uint8_t *buffer)
{
if (0 == w || 0 == h) {
Expand Down

0 comments on commit c0bef1b

Please sign in to comment.