qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

qp_oled_panel.h (3137B)


      1 // Copyright 2023 Nick Brassel (@tzarc)
      2 // SPDX-License-Identifier: GPL-2.0-or-later
      3 #pragma once
      4 
      5 #include "color.h"
      6 #include "qp_internal.h"
      7 #include "qp_surface_internal.h"
      8 
      9 #ifdef QUANTUM_PAINTER_SPI_ENABLE
     10 #    include "qp_comms_spi.h"
     11 #endif // QUANTUM_PAINTER_SPI_ENABLE
     12 
     13 #ifdef QUANTUM_PAINTER_I2C_ENABLE
     14 #    include "qp_comms_i2c.h"
     15 #endif // QUANTUM_PAINTER_I2C_ENABLE
     16 
     17 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     18 // Common OLED panel implementation
     19 
     20 // Driver vtable with extras
     21 typedef struct oled_panel_painter_driver_vtable_t {
     22     painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type
     23 
     24     // Opcodes for normal display operation
     25     struct {
     26         uint8_t display_on;
     27         uint8_t display_off;
     28         uint8_t set_page;
     29         uint8_t set_column_lsb;
     30         uint8_t set_column_msb;
     31     } opcodes;
     32 } oled_panel_painter_driver_vtable_t;
     33 
     34 // Device definition
     35 typedef struct oled_panel_painter_device_t {
     36     painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type
     37 
     38     union {
     39 #ifdef QUANTUM_PAINTER_SPI_ENABLE
     40         // SPI-based configurables
     41         qp_comms_spi_dc_reset_config_t spi_dc_reset_config;
     42 #endif // QUANTUM_PAINTER_SPI_ENABLE
     43 #ifdef QUANTUM_PAINTER_I2C_ENABLE
     44         // I2C-based configurables
     45         qp_comms_i2c_config_t i2c_config;
     46 #endif // QUANTUM_PAINTER_I2C_ENABLE
     47     };
     48 
     49     surface_painter_device_t surface;
     50 } oled_panel_painter_device_t;
     51 
     52 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     53 // Forward declarations for injecting into concrete driver vtables
     54 
     55 bool qp_oled_panel_power(painter_device_t device, bool power_on);
     56 bool qp_oled_panel_clear(painter_device_t device);
     57 
     58 bool qp_oled_panel_passthru_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count);
     59 bool qp_oled_panel_passthru_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom);
     60 bool qp_oled_panel_passthru_palette_convert(painter_device_t device, int16_t palette_size, qp_pixel_t *palette);
     61 bool qp_oled_panel_passthru_append_pixels(painter_device_t device, uint8_t *target_buffer, qp_pixel_t *palette, uint32_t pixel_offset, uint32_t pixel_count, uint8_t *palette_indices);
     62 bool qp_oled_panel_passthru_append_pixdata(painter_device_t device, uint8_t *target_buffer, uint32_t pixdata_offset, uint8_t pixdata_byte);
     63 
     64 // Helpers for flushing data from the dirty region to the correct location on the OLED
     65 void qp_oled_panel_page_column_flush_rot0(painter_device_t device, surface_dirty_data_t *dirty, const uint8_t *framebuffer);
     66 void qp_oled_panel_page_column_flush_rot90(painter_device_t device, surface_dirty_data_t *dirty, const uint8_t *framebuffer);
     67 void qp_oled_panel_page_column_flush_rot180(painter_device_t device, surface_dirty_data_t *dirty, const uint8_t *framebuffer);
     68 void qp_oled_panel_page_column_flush_rot270(painter_device_t device, surface_dirty_data_t *dirty, const uint8_t *framebuffer);