Skip to content

Commit

Permalink
Update pewpew_lcd to version 4.1
Browse files Browse the repository at this point in the history
It now uses st7745 display and physical buttons
  • Loading branch information
deshipu committed Feb 20, 2024
1 parent edbbed0 commit 5f0ac68
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 52 deletions.
80 changes: 51 additions & 29 deletions ports/atmel-samd/boards/pewpew_lcd/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries, 2020 Radomir
* Dopieralski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,24 +26,45 @@
*/

#include "supervisor/board.h"

#include "shared-bindings/board/__init__.h"
#include "shared-bindings/fourwire/FourWire.h"
#include "hal/include/hal_gpio.h"
#include "shared-bindings/busio/SPI.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-bindings/busio/SPI.h"

fourwire_fourwire_obj_t board_display_obj;

#define DELAY 0x80

uint8_t display_init_sequence[] = {
0xe2, 0, // reset
0x2f, 0, // power on
0x80, 0, // contrast 0
0xa4, 0, // display normal
0xaf, 0, // display on
0x40, 0, // start line 0
0x01, 0 | DELAY, 150, // SWRESET
0x11, 0 | DELAY, 255, // SLPOUT
0xb1, 3, 0x01, 0x2C, 0x2D, // _FRMCTR1
0xb2, 3, 0x01, 0x2C, 0x2D, //
0xb3, 6, 0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D,
0xb4, 1, 0x07, // _INVCTR line inversion
0xc0, 3, 0xa2, 0x02, 0x84, // _PWCTR1 GVDD = 4.7V, 1.0uA
0xc1, 1, 0xc5, // _PWCTR2 VGH=14.7V, VGL=-7.35V
0xc2, 2, 0x0a, 0x00, // _PWCTR3 Opamp current small, Boost frequency
0xc3, 2, 0x8a, 0x2a,
0xc4, 2, 0x8a, 0xee,
0xc5, 1, 0x0e, // _VMCTR1 VCOMH = 4V, VOML = -1.1V
0x2a, 0, // _INVOFF
0x36, 1, 0xa0, // _MADCTL
// 1 clk cycle nonoverlap, 2 cycle gate rise, 3 cycle osc equalie,
// fix on VTL
0x3a, 1, 0x05, // COLMOD - 16bit color
0xe0, 16, 0x02, 0x1c, 0x07, 0x12, // _GMCTRP1 Gamma
0x37, 0x32, 0x29, 0x2d,
0x29, 0x25, 0x2B, 0x39,
0x00, 0x01, 0x03, 0x10,
0xe1, 16, 0x03, 0x1d, 0x07, 0x06, // _GMCTRN1
0x2E, 0x2C, 0x29, 0x2D,
0x2E, 0x2E, 0x37, 0x3F,
0x00, 0x00, 0x02, 0x10,
0x13, 0 | DELAY, 10, // _NORON
0x29, 0 | DELAY, 100, // _DISPON
};

void board_init(void) {
Expand All @@ -54,42 +76,42 @@ void board_init(void) {
bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
spi,
NULL, // Command or data
&pin_PA19, // Chip select
&pin_PA18, // Reset
40000000LL, // Baudrate
&pin_PA19, // TFT_DC Command or data
&pin_PA17, // TFT_CS Chip select
&pin_PA18, // TFT_RST Reset
60000000, // Baudrate
0, // Polarity
0); // Phase

busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
display->base.type = &busdisplay_busdisplay_type;
common_hal_busdisplay_busdisplay_construct(display,
bus,
96, // Width
68, // Height
160, // Width (after rotation)
128, // Height (after rotation)
0, // column start
0, // row start
180, // rotation
1, // Color depth
true, // grayscale
false, // pixels in byte share row. Only used with depth < 8
0, // rotation
16, // Color depth
false, // grayscale
false, // pixels in byte share row. only used for depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
false, // reverse_pixels_in_word
0, // Set column command
0, // Set row command
0, // Write memory command
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
display_init_sequence,
sizeof(display_init_sequence),
NULL, // &pin_PA17, // brightness pin
NULL, // backlight pin
NO_BRIGHTNESS_COMMAND,
0.0f, // brightness
1.0f, // brightness
false, // single_byte_bounds
true, // data as commands
true, // auto_refresh
2, // native_frames_per_second
false, // data_as_commands
false, // auto_refresh
20, // native_frames_per_second
true, // backlight_on_high
true, // SH1107_addressing
false, // SH1107_addressing
50000); // backlight pwm frequency
}

Expand Down
24 changes: 17 additions & 7 deletions ports/atmel-samd/boards/pewpew_lcd/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@ LONGINT_IMPL = NONE

CIRCUITPY_FULL_BUILD = 0

# required
CIRCUITPY_DISPLAYIO = 1
CIRCUITPY_TOUCHIO = 1
CIRCUITPY_PWMIO = 1
CIRCUITPY_MATH = 0
CIRCUITPY_BUSDISPLAY = 1
CIRCUITPY_KEYPAD = 1
CIRCUITPY_KEYPAD_KEYS = 1
CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS = 0
CIRCUITPY_KEYPAD_KEYMATRIX = 0

CIRCUITPY_ANALOGIO = 0
# bonus, can be disabled if needed
CIRCUITPY_MATH = 1
CIRCUITPY_ANALOGIO = 1
CIRCUITPY_NEOPIXEL_WRITE = 1
CIRCUITPY_SAMD = 1

CIRCUITPY_EPAPERDISPLAY = 0
CIRCUITPY_I2CDISPLAYBUS = 0
CIRCUITPY_STAGE = 0
CIRCUITPY_PWMIO = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOBUSIO_I2SOUT = 0
CIRCUITPY_AUDIOCORE = 0
Expand All @@ -35,16 +48,13 @@ CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CTARGET = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0
CIRCUITPY_PIXELBUF = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_PULSEIO = 0
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0
CIRCUITPY_SAMD = 0
CIRCUITPY_ULAB = 0
CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_MIDI = 0
Expand Down
32 changes: 16 additions & 16 deletions ports/atmel-samd/boards/pewpew_lcd/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
#include "shared-module/displayio/__init__.h"

STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR__SCK), MP_ROM_PTR(&pin_PA23) },
{ MP_ROM_QSTR(MP_QSTR__MOSI), MP_ROM_PTR(&pin_PA22) },
{ MP_ROM_QSTR(MP_QSTR__CS), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR__RST), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR__BL), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA23) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA22) },
{ MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_RST), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR_DC), MP_ROM_PTR(&pin_PA19) },

{ MP_ROM_QSTR(MP_QSTR__UP), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR__DOWN), MP_ROM_PTR(&pin_PA05) },
{ MP_ROM_QSTR(MP_QSTR__LEFT), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR__RIGHT), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR__O), MP_ROM_PTR(&pin_PA06) },
{ MP_ROM_QSTR(MP_QSTR__X), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_UP), MP_ROM_PTR(&pin_PA14) },
{ MP_ROM_QSTR(MP_QSTR_DOWN), MP_ROM_PTR(&pin_PA10) },
{ MP_ROM_QSTR(MP_QSTR_LEFT), MP_ROM_PTR(&pin_PA11) },
{ MP_ROM_QSTR(MP_QSTR_RIGHT), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_O), MP_ROM_PTR(&pin_PA16) },
{ MP_ROM_QSTR(MP_QSTR_X), MP_ROM_PTR(&pin_PA15) },

{ MP_ROM_QSTR(MP_QSTR_P1), MP_ROM_PTR(&pin_PA30) },
{ MP_ROM_QSTR(MP_QSTR_P2), MP_ROM_PTR(&pin_PA31) },
{ MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_P4), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_P5), MP_ROM_PTR(&pin_PA10) },
{ MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_PA11) },
{ MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_PA14) },
{ MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_P4), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_P5), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_PA04) },

{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
};
Expand Down

0 comments on commit 5f0ac68

Please sign in to comment.