|
32 | 32 | #include "shared-module/displayio/__init__.h"
|
33 | 33 | #include "shared-module/displayio/mipi_constants.h"
|
34 | 34 |
|
35 |
| -/* |
36 | 35 | displayio_fourwire_obj_t board_display_obj;
|
37 | 36 |
|
38 | 37 | #define DELAY 0x80
|
39 | 38 |
|
| 39 | +// display init sequence according to LilyGO example app |
40 | 40 | uint8_t display_init_sequence[] = {
|
41 |
| - 0x01, 0 | DELAY, 150, // SWRESET |
42 |
| - 0x11, 0 | DELAY, 255, // SLPOUT |
43 |
| - 0x36, 1, 0x00, // _MADCTL bottom to top refresh in vsync aligned order. |
44 |
| - 0x3a, 1, 0x55, // COLMOD - 16bit color |
45 |
| - 0x21, 0 | DELAY, 10, // _INVON |
46 |
| - 0x13, 0 | DELAY, 10, // _NORON |
47 |
| - 0x29, 0 | DELAY, 255, // _DISPON |
| 41 | + // sw reset |
| 42 | + 0x01, 0 | DELAY, 150, |
| 43 | + // sleep out |
| 44 | + 0x11, 0 | DELAY, 255, |
| 45 | + // normal display mode on |
| 46 | + 0x13, 0, |
| 47 | + // display and color format settings |
| 48 | + 0x36, 1, 0x08, |
| 49 | + 0xB6, 2, 0x0A, 0x82, |
| 50 | + 0x3A, 1 | DELAY, 0x55, 10, |
| 51 | + // ST7789V frame rate setting |
| 52 | + 0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33, |
| 53 | + // voltages: VGH / VGL |
| 54 | + 0xB7, 1, 0x35, |
| 55 | + // ST7789V power setting |
| 56 | + 0xBB, 1, 0x28, |
| 57 | + 0xC0, 1, 0x0C, |
| 58 | + 0xC2, 2, 0x01, 0xFF, |
| 59 | + 0xC3, 1, 0x10, |
| 60 | + 0xC4, 1, 0x20, |
| 61 | + 0xC6, 1, 0x0F, |
| 62 | + 0xD0, 2, 0xA4, 0xA1, |
| 63 | + // ST7789V gamma setting |
| 64 | + 0xE0, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17, |
| 65 | + 0xE1, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E, |
| 66 | + 0x21, 0, |
| 67 | + // display on |
| 68 | + 0x29, 0 | DELAY, 255, |
48 | 69 | };
|
49 | 70 |
|
50 |
| -*/ |
51 | 71 |
|
52 | 72 | void board_init(void) {
|
53 | 73 | // USB
|
54 | 74 | common_hal_never_reset_pin(&pin_GPIO19);
|
55 | 75 | common_hal_never_reset_pin(&pin_GPIO20);
|
56 | 76 |
|
57 | 77 |
|
58 |
| - /* |
59 |
| - busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; |
60 |
| - common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL); |
| 78 | + busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; |
| 79 | + |
| 80 | + common_hal_busio_spi_construct( |
| 81 | + spi, |
| 82 | + &pin_GPIO36, // CLK |
| 83 | + &pin_GPIO35, // MOSI |
| 84 | + NULL // MISO not connected |
| 85 | + ); |
| 86 | + |
61 | 87 | common_hal_busio_spi_never_reset(spi);
|
62 | 88 |
|
63 | 89 | displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
64 | 90 | bus->base.type = &displayio_fourwire_type;
|
65 |
| - common_hal_displayio_fourwire_construct(bus, |
66 |
| - spi, |
67 |
| - &pin_GPIO40, // TFT_DC Command or data |
68 |
| - &pin_GPIO42, // TFT_CS Chip select |
69 |
| - &pin_GPIO41, // TFT_RST Reset |
70 |
| - 4000000, // Baudrate |
71 |
| - 0, // Polarity |
72 |
| - 0); // Phase |
73 | 91 |
|
| 92 | + common_hal_displayio_fourwire_construct( |
| 93 | + bus, |
| 94 | + spi, |
| 95 | + &pin_GPIO39, // DC |
| 96 | + &pin_GPIO21, // CS |
| 97 | + &pin_GPIO40, // RST |
| 98 | + 40000000, // baudrate |
| 99 | + 0, // polarity |
| 100 | + 0 // phase |
| 101 | + ); |
74 | 102 | displayio_display_obj_t* display = &displays[0].display;
|
75 | 103 | display->base.type = &displayio_display_type;
|
76 |
| - common_hal_displayio_display_construct(display, |
| 104 | + |
| 105 | + // workaround as board_init() is called before reset_port() in main.c |
| 106 | + pwmout_reset(); |
| 107 | + |
| 108 | + |
| 109 | + common_hal_displayio_display_construct( |
| 110 | + display, |
77 | 111 | bus,
|
78 |
| - 240, // Width (after rotation) |
79 |
| - 135, // Height (after rotation) |
80 |
| - 0, // column start |
81 |
| - 0, // row start |
82 |
| - 0, // rotation |
83 |
| - 16, // Color depth |
84 |
| - false, // Grayscale |
85 |
| - false, // Pixels in a byte share a row. Only used for depth < 8 |
86 |
| - 1, // bytes per cell. Only valid for depths < 8 |
87 |
| - false, // reverse_pixels_in_byte. Only valid for depths < 8 |
88 |
| - true, // reverse_pixels_in_word |
89 |
| - MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command |
90 |
| - MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command |
91 |
| - MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command |
| 112 | + 240, // width (after rotation) |
| 113 | + 135, // height (after rotation) |
| 114 | + 52, // column start |
| 115 | + 40, // row start |
| 116 | + 90, // rotation |
| 117 | + 16, // color depth |
| 118 | + false, // grayscale |
| 119 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 120 | + 1, // bytes per cell. Only valid for depths < 8 |
| 121 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 122 | + true, // reverse_pixels_in_word |
| 123 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command |
| 124 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command |
| 125 | + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command |
92 | 126 | display_init_sequence,
|
93 | 127 | sizeof(display_init_sequence),
|
94 |
| - &pin_GPIO7, // backlight pin |
| 128 | + &pin_GPIO45, // backlight pin |
95 | 129 | NO_BRIGHTNESS_COMMAND,
|
96 |
| - 1.0f, // brightness (ignored) |
97 |
| - true, // auto_brightness |
98 |
| - false, // single_byte_bounds |
99 |
| - false, // data_as_commands |
100 |
| - true, // auto_refresh |
101 |
| - 60, // native_frames_per_second |
102 |
| - true, // backlight_on_high |
103 |
| - false); // not SH1107 |
104 |
| - */ |
| 130 | + 1.0f, // brightness (ignored) |
| 131 | + false, // auto_brightness |
| 132 | + false, // single_byte_bounds |
| 133 | + false, // data_as_commands |
| 134 | + true, // auto_refresh |
| 135 | + 60, // native_frames_per_second |
| 136 | + true, // backlight_on_high |
| 137 | + false // SH1107_addressing |
| 138 | + ); |
| 139 | + |
| 140 | + common_hal_never_reset_pin(&pin_GPIO45); // backlight pin |
105 | 141 | }
|
106 | 142 |
|
107 | 143 | bool board_requests_safe_mode(void) {
|
|
0 commit comments