[QP] Add support for OLED, variable framebuffer bpp (#19997)
Co-authored-by: Pablo Martínez <58857054+elpekenin@users.noreply.github.com> Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com> Fixup delta frame coordinates after #20296.
This commit is contained in:
parent
48d9140cfc
commit
8e614250b4
51 changed files with 1610 additions and 497 deletions
34
drivers/painter/comms/qp_comms_dummy.c
Normal file
34
drivers/painter/comms/qp_comms_dummy.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2023 Nick Brassel (@tzarc)
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#ifdef QUANTUM_PAINTER_DUMMY_COMMS_ENABLE
|
||||
|
||||
# include "qp_comms_dummy.h"
|
||||
|
||||
static bool dummy_comms_init(painter_device_t device) {
|
||||
// No-op.
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool dummy_comms_start(painter_device_t device) {
|
||||
// No-op.
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dummy_comms_stop(painter_device_t device) {
|
||||
// No-op.
|
||||
}
|
||||
|
||||
uint32_t dummy_comms_send(painter_device_t device, const void *data, uint32_t byte_count) {
|
||||
// No-op.
|
||||
return byte_count;
|
||||
}
|
||||
|
||||
painter_comms_vtable_t dummy_comms_vtable = {
|
||||
// These are all effective no-op's because they're not actually needed.
|
||||
.comms_init = dummy_comms_init,
|
||||
.comms_start = dummy_comms_start,
|
||||
.comms_stop = dummy_comms_stop,
|
||||
.comms_send = dummy_comms_send};
|
||||
|
||||
#endif // QUANTUM_PAINTER_DUMMY_COMMS_ENABLE
|
11
drivers/painter/comms/qp_comms_dummy.h
Normal file
11
drivers/painter/comms/qp_comms_dummy.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2023 Nick Brassel (@tzarc)
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
|
||||
#ifdef QUANTUM_PAINTER_DUMMY_COMMS_ENABLE
|
||||
|
||||
# include "qp_internal.h"
|
||||
|
||||
extern painter_comms_vtable_t dummy_comms_vtable;
|
||||
|
||||
#endif // QUANTUM_PAINTER_DUMMY_COMMS_ENABLE
|
94
drivers/painter/comms/qp_comms_i2c.c
Normal file
94
drivers/painter/comms/qp_comms_i2c.c
Normal file
|
@ -0,0 +1,94 @@
|
|||
// Copyright 2022 Nick Brassel (@tzarc)
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#ifdef QUANTUM_PAINTER_I2C_ENABLE
|
||||
|
||||
# include "i2c_master.h"
|
||||
# include "qp_comms_i2c.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Helpers
|
||||
|
||||
static uint32_t qp_comms_i2c_send_raw(painter_device_t device, const void *data, uint32_t byte_count) {
|
||||
painter_driver_t * driver = (painter_driver_t *)device;
|
||||
qp_comms_i2c_config_t *comms_config = (qp_comms_i2c_config_t *)driver->comms_config;
|
||||
i2c_status_t res = i2c_transmit(comms_config->chip_address << 1, data, byte_count, I2C_TIMEOUT);
|
||||
if (res < 0) {
|
||||
return 0;
|
||||
}
|
||||
return byte_count;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Base I2C support
|
||||
|
||||
bool qp_comms_i2c_init(painter_device_t device) {
|
||||
i2c_init();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool qp_comms_i2c_start(painter_device_t device) {
|
||||
painter_driver_t * driver = (painter_driver_t *)device;
|
||||
qp_comms_i2c_config_t *comms_config = (qp_comms_i2c_config_t *)driver->comms_config;
|
||||
return i2c_start(comms_config->chip_address << 1) == I2C_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t qp_comms_i2c_send_data(painter_device_t device, const void *data, uint32_t byte_count) {
|
||||
return qp_comms_i2c_send_raw(device, data, byte_count);
|
||||
}
|
||||
|
||||
void qp_comms_i2c_stop(painter_device_t device) {
|
||||
i2c_stop();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Command+Data I2C support
|
||||
|
||||
static const uint8_t cmd_byte = 0x00;
|
||||
static const uint8_t data_byte = 0x40;
|
||||
|
||||
void qp_comms_i2c_cmddata_send_command(painter_device_t device, uint8_t cmd) {
|
||||
uint8_t buf[2] = {cmd_byte, cmd};
|
||||
qp_comms_i2c_send_raw(device, &buf, 2);
|
||||
}
|
||||
|
||||
uint32_t qp_comms_i2c_cmddata_send_data(painter_device_t device, const void *data, uint32_t byte_count) {
|
||||
uint8_t buf[1 + byte_count];
|
||||
buf[0] = data_byte;
|
||||
memcpy(&buf[1], data, byte_count);
|
||||
if (qp_comms_i2c_send_raw(device, buf, sizeof(buf)) != sizeof(buf)) {
|
||||
return 0;
|
||||
}
|
||||
return byte_count;
|
||||
}
|
||||
|
||||
void qp_comms_i2c_bulk_command_sequence(painter_device_t device, const uint8_t *sequence, size_t sequence_len) {
|
||||
uint8_t buf[32];
|
||||
for (size_t i = 0; i < sequence_len;) {
|
||||
uint8_t command = sequence[i];
|
||||
uint8_t delay = sequence[i + 1];
|
||||
uint8_t num_bytes = sequence[i + 2];
|
||||
buf[0] = cmd_byte;
|
||||
buf[1] = command;
|
||||
memcpy(&buf[2], &sequence[i + 3], num_bytes);
|
||||
qp_comms_i2c_send_raw(device, buf, num_bytes + 2);
|
||||
if (delay > 0) {
|
||||
wait_ms(delay);
|
||||
}
|
||||
i += (3 + num_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
const painter_comms_with_command_vtable_t i2c_comms_cmddata_vtable = {
|
||||
.base =
|
||||
{
|
||||
.comms_init = qp_comms_i2c_init,
|
||||
.comms_start = qp_comms_i2c_start,
|
||||
.comms_send = qp_comms_i2c_cmddata_send_data,
|
||||
.comms_stop = qp_comms_i2c_stop,
|
||||
},
|
||||
.send_command = qp_comms_i2c_cmddata_send_command,
|
||||
.bulk_command_sequence = qp_comms_i2c_bulk_command_sequence,
|
||||
};
|
||||
|
||||
#endif // QUANTUM_PAINTER_I2C_ENABLE
|
28
drivers/painter/comms/qp_comms_i2c.h
Normal file
28
drivers/painter/comms/qp_comms_i2c.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2022 Nick Brassel (@tzarc)
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
|
||||
#ifdef QUANTUM_PAINTER_I2C_ENABLE
|
||||
|
||||
# include <stdint.h>
|
||||
|
||||
# include "gpio.h"
|
||||
# include "qp_internal.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Base I2C support
|
||||
|
||||
typedef struct qp_comms_i2c_config_t {
|
||||
uint8_t chip_address;
|
||||
} qp_comms_i2c_config_t;
|
||||
|
||||
bool qp_comms_i2c_init(painter_device_t device);
|
||||
bool qp_comms_i2c_start(painter_device_t device);
|
||||
uint32_t qp_comms_i2c_send_data(painter_device_t device, const void* data, uint32_t byte_count);
|
||||
void qp_comms_i2c_stop(painter_device_t device);
|
||||
|
||||
extern const painter_comms_with_command_vtable_t i2c_comms_cmddata_vtable;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // QUANTUM_PAINTER_I2C_ENABLE
|
|
@ -105,13 +105,21 @@ void qp_comms_spi_dc_reset_send_command(painter_device_t device, uint8_t cmd) {
|
|||
}
|
||||
|
||||
void qp_comms_spi_dc_reset_bulk_command_sequence(painter_device_t device, const uint8_t *sequence, size_t sequence_len) {
|
||||
painter_driver_t * driver = (painter_driver_t *)device;
|
||||
qp_comms_spi_dc_reset_config_t *comms_config = (qp_comms_spi_dc_reset_config_t *)driver->comms_config;
|
||||
for (size_t i = 0; i < sequence_len;) {
|
||||
uint8_t command = sequence[i];
|
||||
uint8_t delay = sequence[i + 1];
|
||||
uint8_t num_bytes = sequence[i + 2];
|
||||
qp_comms_spi_dc_reset_send_command(device, command);
|
||||
if (num_bytes > 0) {
|
||||
qp_comms_spi_dc_reset_send_data(device, &sequence[i + 3], num_bytes);
|
||||
if (comms_config->command_params_uses_command_pin) {
|
||||
for (uint8_t j = 0; j < num_bytes; j++) {
|
||||
qp_comms_spi_dc_reset_send_command(device, sequence[i + 3 + j]);
|
||||
}
|
||||
} else {
|
||||
qp_comms_spi_dc_reset_send_data(device, &sequence[i + 3], num_bytes);
|
||||
}
|
||||
}
|
||||
if (delay > 0) {
|
||||
wait_ms(delay);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2021 Nick Brassel (@tzarc)
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef QUANTUM_PAINTER_SPI_ENABLE
|
||||
|
@ -36,6 +35,7 @@ typedef struct qp_comms_spi_dc_reset_config_t {
|
|||
qp_comms_spi_config_t spi_config;
|
||||
pin_t dc_pin;
|
||||
pin_t reset_pin;
|
||||
bool command_params_uses_command_pin; // keep D/C held low when sending command sequences for data bytes
|
||||
} qp_comms_spi_dc_reset_config_t;
|
||||
|
||||
void qp_comms_spi_dc_reset_send_command(painter_device_t device, uint8_t cmd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue