diff options
| author | Anson Bridges <bridges.anson@gmail.com> | 2026-02-17 11:24:06 -0800 |
|---|---|---|
| committer | Anson Bridges <bridges.anson@gmail.com> | 2026-02-17 11:24:06 -0800 |
| commit | 6e952fe110c2a48204c8cb0a836309ab97e5979a (patch) | |
| tree | 64f87be87311dc3d62fb06da4fe23059a55de195 /code_refs/sharpmem.c | |
added files
Diffstat (limited to 'code_refs/sharpmem.c')
| -rw-r--r-- | code_refs/sharpmem.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/code_refs/sharpmem.c b/code_refs/sharpmem.c new file mode 100644 index 0000000..4e0040a --- /dev/null +++ b/code_refs/sharpmem.c @@ -0,0 +1,87 @@ +#include "sharpmem.h" + +void SHARPMEM_TOGGLEVCOM(SharpMemDisplay_t *display) { + display->_sharpmem_vcom = display->_sharpmem_vcom ? 0x00 : SHARPMEM_BIT_VCOM; +} + +void SHARPMEM_draw_pixel(SharpMemDisplay_t *display, uint16_t x, uint16_t y, bool white) { + if ((x < 0) || (x >= display->width) || (y < 0) || (y >= display->height)) + return; + + if (black) { + display->buffer[(y * WIDTH + x) / 8] |= (0x1 << (x & 7)); //potentially expensive when run many times, use lookup from adafruit lib + } else { + display->buffer[(y * WIDTH + x) / 8] &= ~(0x1 << (x & 7)); + } +} + +void SHARPMEM_draw_line(SharpMemDisplay_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool white, uint8_t thickness) { + +} + +void SHARPMEM_draw_circle(SharpMemDisplay_t *display, uint16_t x, uint16_t y, uint8_t r, bool filled) { + +} + +void SHARPMEM_draw_rect(SharpMemDisplay_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, bool filled) { + +} + +uint8_t SHARPMEM_get_pixel(SharpMemDisplay_t *display, uint16_t x, uint16_t y) { + +} + +void SHARPMEM_clear_display(SharpMemDisplay_t *display) { + memset(display->_buffer, 0xff, (display->width * display->height) / 8); + + // Send the clear screen command rather than doing a HW refresh (quicker) + + uint8_t clear_data[2] = {(uint8_t)(display->_sharpmem_vcom | SHARPMEM_BIT_CLEAR), + 0x00}; + + HAL_GPIO_WritePin(display->cs_pin_bank, display->cs_pin, GPIO_PIN_SET); + HAL_SPI_Transmit(&display->spidev, clear_data, 2); + HAL_GPIO_WritePin(display->cs_pin_bank, display->cs_pin, GPIO_PIN_RESET); + + SHARPMEM_TOGGLEVCOM(display); +} + +void SHARPMEM_refresh_display(SharpMemDisplay_t *display) { + uint16_t i, currentline; + + spidev->beginTransaction(); + // Send the write command + HAL_GPIO_WritePin(display->cs_pin_bank, display->cs_pin, GPIO_PIN_SET); + + HAL_SPI_Transmit(&display->spidev, (_sharpmem_vcom | SHARPMEM_BIT_WRITECMD), 1); + SHARPMEM_TOGGLEVCOM(display);; + + uint8_t bytes_per_line = display->width / 8; + uint16_t totalbytes = (display->width * display->height) / 8; + + for (i = 0; i < totalbytes; i += bytes_per_line) { + uint8_t line[bytes_per_line + 2]; + + // Send address byte + currentline = ((i + 1) / (WIDTH / 8)) + 1; + line[0] = currentline; + // copy over this line + memcpy(line + 1, display->_buffer + i, bytes_per_line); + // Send end of line + line[bytes_per_line + 1] = 0x00; + // send it! + HAL_SPI_Transmit(&display->spidev, line, bytes_per_line + 2); + } + + // Send another trailing 8 bits for the last line + HAL_SPI_Transmit(&display->spidev, (0x00), 1); + HAL_GPIO_WritePin(display->cs_pin_bank, display->cs_pin, GPIO_PIN_RESET); +} + +void SHARPMEM_clear_display_buffer(SharpMemDisplay_t *display) { + +} + +uint8_t *SHARPMEM_get_buffer(SharpMemDisplay_t *display) { + +}
\ No newline at end of file |
