1 #include <twr_ls013b7dh03.h>
4 #define _TWR_LS013B7DH03_VCOM_PERIOD 15000
6 #define _TWR_LS013B7DH03_LINE_INCREMENT (TWR_LS013B7DH03_WIDTH / 8 + 2)
8 static void _twr_ls013b7dh03_task(
void *param);
9 static bool _twr_ls013b7dh03_spi_transfer(
twr_ls013b7dh03_t *
self, uint8_t *buffer,
size_t length);
10 static void _twr_ls013b7dh03_spi_event_handler(
twr_spi_event_t event,
void *event_param);
11 static inline uint8_t _twr_ls013b7dh03_reverse(uint8_t b);
15 memset(
self, 0xff,
sizeof(*
self));
18 self->_pin_cs_set = pin_cs_set;
25 for (line = 0x01, offs = 1; line <= TWR_LS013B7DH03_HEIGHT; line++, offs += _TWR_LS013B7DH03_LINE_INCREMENT)
28 self->_framebuffer[offs] = _twr_ls013b7dh03_reverse(line);
40 static const twr_gfx_caps_t caps = { .width = TWR_LS013B7DH03_WIDTH, .height = TWR_LS013B7DH03_HEIGHT };
57 for (line = 0x01, offs = 2; line <= TWR_LS013B7DH03_HEIGHT; line++, offs += _TWR_LS013B7DH03_LINE_INCREMENT)
59 for (col = 0; col < (TWR_LS013B7DH03_WIDTH / 8); col++)
61 self->_framebuffer[offs + col] = 0xff;
69 uint32_t byteIndex = 2;
71 byteIndex += y * _TWR_LS013B7DH03_LINE_INCREMENT;
75 uint8_t bitMask = 1 << (7 - (x % 8));
79 self->_framebuffer[byteIndex] |= bitMask;
83 self->_framebuffer[byteIndex] &= ~bitMask;
90 uint32_t byteIndex = 2;
92 byteIndex += y * _TWR_LS013B7DH03_LINE_INCREMENT;
96 return (self->_framebuffer[byteIndex] >> (7 - (x % 8))) & 1 ? 0 : 1;
112 if (!self->_pin_cs_set(0))
117 self->_framebuffer[0] = 0x80 |
self->_vcom;
119 if (!
twr_spi_async_transfer(self->_framebuffer, NULL, TWR_LS013B7DH03_FRAMEBUFFER_SIZE, _twr_ls013b7dh03_spi_event_handler,
self))
121 self->_pin_cs_set(1);
153 uint8_t spi_data[2] = { 0x20, 0x00 };
155 return _twr_ls013b7dh03_spi_transfer(
self, spi_data,
sizeof(spi_data));
158 static void _twr_ls013b7dh03_task(
void *param)
162 uint8_t spi_data[2] = {
self->_vcom, 0x00};
164 if (_twr_ls013b7dh03_spi_transfer(
self, spi_data,
sizeof(spi_data)))
172 static bool _twr_ls013b7dh03_spi_transfer(
twr_ls013b7dh03_t *
self, uint8_t *buffer,
size_t length)
179 if (!self->_pin_cs_set(0))
186 self->_pin_cs_set(1);
191 static void _twr_ls013b7dh03_spi_event_handler(
twr_spi_event_t event,
void *event_param)
197 self->_pin_cs_set(1);
201 static inline uint8_t _twr_ls013b7dh03_reverse(uint8_t b)
203 b = (b & 0xf0) >> 4 | (b & 0x0f) << 4;
204 b = (b & 0xcc) >> 2 | (b & 0x33) << 2;
205 b = (b & 0xaa) >> 1 | (b & 0x55) << 1;
bool twr_ls013b7dh03_is_ready(twr_ls013b7dh03_t *self)
Check if lcd is ready for commands.
twr_gfx_caps_t twr_ls013b7dh03_get_caps(twr_ls013b7dh03_t *self)
Get capabilities.
const twr_gfx_driver_t * twr_ls013b7dh03_get_driver(void)
Get Lcd driver.
bool twr_ls013b7dh03_clear_memory_command(twr_ls013b7dh03_t *self)
Send Lcd clear memory command.
uint32_t twr_ls013b7dh03_get_pixel(twr_ls013b7dh03_t *self, int x, int y)
Lcd get pixel.
void twr_ls013b7dh03_clear(twr_ls013b7dh03_t *self)
Clear.
bool twr_ls013b7dh03_update(twr_ls013b7dh03_t *self)
Lcd update, send data.
void twr_ls013b7dh03_draw_pixel(twr_ls013b7dh03_t *self, int x, int y, uint32_t color)
Lcd draw pixel.
void twr_ls013b7dh03_init(twr_ls013b7dh03_t *self, bool(*pin_cs_set)(bool state))
Initialize lcd driver.
void twr_scheduler_plan_current_from_now(twr_tick_t tick)
Schedule current task to tick relative from now.
void twr_scheduler_plan_relative(twr_scheduler_task_id_t task_id, twr_tick_t tick)
Schedule specified task to tick relative from current spin.
twr_scheduler_task_id_t twr_scheduler_register(void(*task)(void *), void *param, twr_tick_t tick)
Register task in scheduler.
bool twr_spi_is_ready(void)
Check if is ready for transfer.
bool twr_spi_async_transfer(const void *source, void *destination, size_t length, void(*event_handler)(twr_spi_event_t event, void *event_param), void(*event_param))
Execute async SPI transfer.
bool twr_spi_transfer(const void *source, void *destination, size_t length)
Execute SPI transfer.
void twr_spi_init(twr_spi_speed_t speed, twr_spi_mode_t mode)
Initialize SPI channel.
twr_spi_event_t
SPI event.
@ TWR_SPI_SPEED_1_MHZ
SPI communication speed is 1 MHz.
@ TWR_SPI_MODE_0
SPI mode of operation is 0 (CPOL = 0, CPHA = 0)
@ TWR_SPI_EVENT_DONE
SPI event is completed.
Display driver interface.