Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 53 additions & 30 deletions ports/raspberrypi/boards/pimoroni_badger2350/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,51 @@ uint8_t _start_sequence[] = {
0x12, 0x80, 0x00, 0x14, // soft reset and wait 20ms
0x11, 0x00, 0x01, 0x03, // Ram data entry mode
0x3c, 0x00, 0x01, 0x03, // border color
0x2c, 0x00, 0x01, 0x28, // Set vcom voltage
0x2c, 0x00, 0x01, 0x20, // Set vcom voltage (Pimoroni: 0x28)
0x03, 0x00, 0x01, 0x17, // Set gate voltage
0x04, 0x00, 0x03, 0x41, 0xae, 0x32, // Set source voltage
0x4e, 0x00, 0x01, 0x00, // ram x count
0x4f, 0x00, 0x02, 0x00, 0x00, // ram y count
0x01, 0x00, 0x03, 0x07, 0x01, 0x00, // set display size
0x3f, 0x00, 0x01, 0x22, // EOPT normal (0x22)
0x32, 0x00, 0x99, // Update waveforms

// offset 44
0x40, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L0
0xA0, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L1
0xA8, 0x65, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L2
0xAA, 0x65, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L3
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L4

// offset 104
0x02, 0x00, 0x00, 0x05, 0x0A, 0x00, 0x03, // Group0 (with default speed==0)
// offset 111
0x19, 0x19, 0x00, 0x02, 0x00, 0x00, 0x03, // Group1 (with default speed==0)
// offset 118
0x05, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x03, // Group2 (with default speed==0)

// offset 125
// LUT-START: offset 48
// VS rows: only L0-L3 are swapped relative to GxEPD2_4G;
// L1 and L2 stay in place.
// Reason: CircuitPython luma maps 0 L0, 64-127 L2, 128-191 L1, 255 L3.
// GxEPD2 uses L0=white-driver, L3=black-driver
// (opposite of CircuitPython for extremes).
// GxEPD2 L1=lighter-gray, L2=darker-gray
// CircuitPython: L1=mid-bright, L2=mid-dark — same ordering.
// So: swap only L0-L3 (polarity);
// L1 and L2 keep their GxEPD2 positions (gradient preserved).
//
// Note: 0x48: VSH1/GND/VSL/GND alternating — better DC balance than
// 0x60 (VSH1/VSL/GND/GND)

// 5x12 = 60 bytes
// VS L0 (darkest/black) == GxEPD2 L3
0x20, 0x48, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// VS L1 (mid-light) == GxEPD2 L1 (luma 128-191 lighter)
0x08, 0x48, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// VS L2 (mid-dark) == GxEPD2 L2 (luma 64-127 darker)
0x02, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// VS L3 (lightest/white) == GxEPD2 L0
0x40, 0x48, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// VS L4 VCOM
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

// 12x7 = 84 (144 total)
// Timing groups — Good Display reference timing
// offset 108: Group0: 10+25 / 3+8 frames activation
0x0A, 0x19, 0x00, 0x03, 0x08, 0x00, 0x00,
// offset 115: Group1: 20+1 / 20+1 frames, RP=0 repeats
0x14, 0x01, 0x00, 0x14, 0x01, 0x00, 0x00,
// offset 122: Group2: 10+3 / 8+25 frames (mirror of G0)
0x0A, 0x03, 0x00, 0x08, 0x19, 0x00, 0x00,

// offset 129
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Group3
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Group4
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Group5
Expand All @@ -120,35 +142,37 @@ uint8_t _start_sequence[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Group9
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Group10
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Group11
0x44, 0x42, 0x22, 0x22, 0x23, 0x32, 0x00, // Config
0x00, 0x00, // FR, XON

// 12x0.5 = 6, (150 total)
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, // FR
// 3x1 = 3, (153 total)
0x00, 0x00, 0x00, // XON
// LUT-END: offset 201
0x22, 0x00, 0x01, 0xc7, // display update mode

};

const uint8_t _stop_sequence[] = {
0x10, 0x00, 0x01, 0x01 // DSM deep sleep mode 1
0x10, 0x80, 0x01, 0x01, 0x64 // DSM deep sleep mode 1
};

const uint8_t _refresh_sequence[] = {
0x20, 0x00, 0x00 // ADUS
};

// Change update speed. This changes the repeat-count in the LUTs
// Pimoroni uses: 0 == slow ... 3 == fast
// and calculates the LUT repeat count as 3-speed
// Change update speed.

// Pimoroni sets the repeat-count for Group0-Group2 and uses:
// speed=0 == slow ... 3 == fast and calculates the LUT repeat count as 3-speed

// This implementation only changes the repeat-count in the LUT-timing of Group1.
// Default is SPEED=3.

#define SPEED_OFFSET_1 110
#define SPEED_OFFSET_2 117
#define SPEED_OFFSET_3 124
#define RP_OFFSET 121

static mp_obj_t _set_update_speed(mp_obj_t speed_in) {
mp_int_t speed = mp_obj_get_int(speed_in);
uint8_t count = (uint8_t)3 - (uint8_t)(speed & 3);
_start_sequence[SPEED_OFFSET_1] = count;
_start_sequence[SPEED_OFFSET_2] = count;
_start_sequence[SPEED_OFFSET_3] = count;
_start_sequence[RP_OFFSET] = count;
return mp_const_none;
}

Expand Down Expand Up @@ -199,7 +223,6 @@ void board_init(void) {
args.set_current_row_command = 0x4f;
args.write_black_ram_command = 0x24;
args.write_color_ram_command = 0x26;
args.color_bits_inverted = true;
args.refresh_sequence = _refresh_sequence;
args.refresh_sequence_len = sizeof(_refresh_sequence);
args.refresh_time = 1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ CFLAGS += \
CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)'

FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-pcf85063a
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register
Loading