Thoughts & Cats

Simple life of Khaos

Adding 128x32 OLED Display Support for GP2040

Posted at — Dec 28, 2024

Recently, I want to add some feature into GP2040 project, which is a open source project for multi-platform gamepad.

The main feature I want to try is about the display. I have a ssd1306 of 128x32 oled with hand, and after I connectted it on the mcu, and i find the display is not good, because the firmware only support 128x64.

As a passionate contributor to the GP2040 open-source multi-platform gamepad project, I recently embarked on a challenging feature implementation involving display support. I had a 128x32 OLED display that I wanted to integrate, but quickly discovered some compatibility hurdles.

Initially, the firmware only fully supported 128x64 displays. Interestingly, while the project configuration allowed defining a 128x32 size, it didn’t function as expected. After diving deep into the codebase and leveraging some AI Tools, I successfully modified the firmware to support my 128x32 OLED.

Here are the key modifications I made:

  1. In ./headers/interfaces/i2c/ssd1306/tiny_ssd1306.h:
// Adjust the maximum screen height
static const uint16_t MAX_SCREEN_HEIGHT = 32; // Changed from 64
  1. In ./src/interfaces/i2c/ssd1306/tiny_ssd1306.cpp:
// Modify multiplex setting for row reuse
CommandOps::SET_MULTIPLEX,
0x1F, // Changed from 63

// Update COM pins configuration - a crucial setting I overlooked
CommandOps::SET_COM_PINS,
0x02, // Changed from 0x12

// Adjust page address calculation
sendCommand(CommandOps::PAGE_ADDRESS);
sendCommand(0x00);
sendCommand(0x03); // Changed from 0x07
  1. In your board configuration file (configs/{gp2040_board}/BoardConfig.h):
// Include the necessary header and define display size
#define DISPLAY_SIZE GPGFX_DisplaySize::SIZE_128x32

A word of caution: After implementing these changes, you’ll need to review and potentially adjust the UI rendering logic. The original display implementation was designed for 128x64, so some content might not display correctly on the smaller screen.

This modification was a rewarding challenge that demonstrates the flexibility of open-source projects and the importance of careful configuration.