Skip to content

Commit

Permalink
Add shared SPI bus support
Browse files Browse the repository at this point in the history
  • Loading branch information
saawsm committed Jun 13, 2023
1 parent 4630e89 commit cdc5bd4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ config MIPI_DISPLAY_SPI_HOST
default 0x02 if ESP32S3_SPI3_SELECTED
endif

config MIPI_DISPLAY_EXCLUSIVE_BUS
bool "Exclusive SPI Bus"
default y
help
Display uses SPI Host exclusively. No other devices share the same SPI bus.

config MIPI_DISPLAY_PIN_MISO
int "MISO pin number"
default -1
Expand Down
1 change: 1 addition & 0 deletions include/mipi_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extern "C" {
void mipi_display_init(spi_device_handle_t *spi);
size_t mipi_display_write(spi_device_handle_t spi, uint16_t x1, uint16_t y1, uint16_t w, uint16_t h, uint8_t *buffer);
void mipi_display_ioctl(spi_device_handle_t spi, uint8_t command, uint8_t *data, size_t size);
void mipi_display_open(spi_device_handle_t spi);
void mipi_display_close(spi_device_handle_t spi);

#ifdef __cplusplus
Expand Down
9 changes: 7 additions & 2 deletions src/hagl_hal_double.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,21 @@ static const char *TAG = "hagl_esp_mipi";
static size_t
flush(void *self)
{
#ifdef CONFIG_HAGL_HAL_LOCK_WHEN_FLUSHING
size_t size = 0;
#ifdef CONFIG_HAGL_HAL_LOCK_WHEN_FLUSHING
/* Flush the whole back buffer with locking. */
xSemaphoreTake(mutex, portMAX_DELAY);
mipi_display_open(spi);
size = mipi_display_write(spi, 0, 0, bb.width, bb.height, (uint8_t *) bb.buffer);
mipi_display_close(spi);
xSemaphoreGive(mutex);
return size;
#else
/* Flush the whole back buffer. */
return mipi_display_write(spi, 0, 0, bb.width, bb.height, (uint8_t *) bb.buffer);
mipi_display_open(spi);
size = mipi_display_write(spi, 0, 0, bb.width, bb.height, (uint8_t *) bb.buffer);
mipi_display_close(spi);
return size;
#endif /* CONFIG_HAGL_HAL_LOCK_WHEN_FLUSHING */
}

Expand Down
14 changes: 14 additions & 0 deletions src/hagl_hal_single.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ vline(void *self, int16_t x0, int16_t y0, uint16_t height, hagl_color_t color)
mipi_display_write(spi, x0, y0, width, height, (uint8_t *) line);
}

static void
begin(void *self)
{
mipi_display_open(spi);
}

static void
end(void *self)
{
mipi_display_close(spi);
}

void
hagl_hal_init(hagl_backend_t *backend)
{
Expand All @@ -111,5 +123,7 @@ hagl_hal_init(hagl_backend_t *backend)
backend->hline = hline;
backend->vline = vline;
backend->blit = blit;
backend->begin = begin;
backend->end = end;
}
#endif /* CONFIG_HAGL_HAL_NO_BUFFERING */
5 changes: 4 additions & 1 deletion src/hagl_hal_triple.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ flush(void *self)
} else {
bb.buffer = buffer1;
}
return mipi_display_write(spi, 0, 0, bb.width, bb.height, (uint8_t *) buffer);
mipi_display_open(spi);
size_t size = mipi_display_write(spi, 0, 0, bb.width, bb.height, (uint8_t *) buffer);
mipi_display_close(spi);
return size;
}

static void
Expand Down
11 changes: 11 additions & 0 deletions src/mipi_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ void mipi_display_init(spi_device_handle_t *spi)

ESP_LOGI(TAG, "Display initialized.");

#ifdef CONFIG_MIPI_DISPLAY_EXCLUSIVE_BUS
spi_device_acquire_bus(*spi, portMAX_DELAY);
#endif
}

void mipi_display_ioctl(spi_device_handle_t spi, const uint8_t command, uint8_t *data, size_t size)
Expand Down Expand Up @@ -317,7 +319,16 @@ void mipi_display_ioctl(spi_device_handle_t spi, const uint8_t command, uint8_t
xSemaphoreGive(mutex);
}

void mipi_display_open(spi_device_handle_t spi)
{
#ifndef CONFIG_MIPI_DISPLAY_EXCLUSIVE_BUS
spi_device_acquire_bus(spi, portMAX_DELAY);
#endif
}

void mipi_display_close(spi_device_handle_t spi)
{
#ifndef CONFIG_MIPI_DISPLAY_EXCLUSIVE_BUS
spi_device_release_bus(spi);
#endif
}

0 comments on commit cdc5bd4

Please sign in to comment.