|
| 1 | +#include "supervisor/board.h" |
| 2 | +#include "mpconfigboard.h" |
| 3 | +#include "shared-bindings/busio/SPI.h" |
| 4 | +#include "shared-bindings/fourwire/FourWire.h" |
| 5 | +#include "shared-module/displayio/__init__.h" |
| 6 | +#include "shared-module/displayio/mipi_constants.h" |
| 7 | + |
| 8 | +#include "common-hal/microcontroller/Pin.h" |
| 9 | + |
| 10 | +// reference: lv_micropython ili9XXX.py |
| 11 | +// reference: ILI9488 datasheet |
| 12 | + |
| 13 | +#define DELAY_FLAG 0x80 |
| 14 | + |
| 15 | +#define COLORMODE_BGR 0b00001000 |
| 16 | +#define ROTATION_Y_FLIP 0b10000000 |
| 17 | +#define ROTATION_X_FLIP 0b01000000 |
| 18 | +#define ROTATION_MV 0b00100000 |
| 19 | + |
| 20 | +// DBI type C (SPI) only has 3bit and 18bit format support, 3bit = 2 pixels per byte, 18bit = one color per byte |
| 21 | +#define COLORFORMAT_3BIT 0b00000001 |
| 22 | +#define COLORFORMAT_16BIT 0b00000101 |
| 23 | +#define COLORFORMAT_18BIT 0b00000110 |
| 24 | +#define COLORFORMAT_24BIT 0b00000111 |
| 25 | + |
| 26 | +static uint8_t display_init_sequence[] = { |
| 27 | + 0x01, DELAY_FLAG | 0, 200, // Software Reset |
| 28 | + 0x11, DELAY_FLAG | 0, 120, // Exit Sleep Mode |
| 29 | + 0xE0, 15, 0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F, // Positive Gamma Control |
| 30 | + 0xE1, 15, 0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F, // Negative Gamma Control |
| 31 | + 0xC0, 2, 0x17, 0x15, // Power Control 1 |
| 32 | + 0xC1, 1, 0x41, // Power Control 2 |
| 33 | + 0xC2, 1, 0x44, // Power Control 3 / Normal Mode |
| 34 | + 0xC5, 3, 0x00, 0x12, 0x80, // VCOM Control |
| 35 | + 0x36, 1, ROTATION_Y_FLIP, // Colormode & Rotation |
| 36 | + 0x3A, 1, COLORFORMAT_18BIT, // Interface pixel format |
| 37 | + 0xB0, 1, 0x00, // Interface mode control |
| 38 | + 0xB1, 1, 0xA0, // Frame Rate Control |
| 39 | + 0xB4, 1, 0x02, // Display Inversion Control |
| 40 | + 0xB6, 2, 0x02, 0x02, // Display Function Control |
| 41 | + 0xE9, 1, 0x00, // Set Image Function |
| 42 | + 0x53, 1, 0x28, // CTRL Display Value |
| 43 | + 0x51, 1, 0x7F, // Display Brightness |
| 44 | + 0xF7, 4, 0xA9, 0x51, 0x2C, 0x02, // Adjust Control 3 |
| 45 | + 0x29, DELAY_FLAG | 0, 25 // Display ON |
| 46 | +}; |
| 47 | + |
| 48 | +void board_init(void) { |
| 49 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 50 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 51 | + common_hal_busio_spi_construct(spi, &pin_GPIO14, &pin_GPIO13, NULL, false); |
| 52 | + common_hal_busio_spi_never_reset(spi); |
| 53 | + |
| 54 | + bus->base.type = &fourwire_fourwire_type; |
| 55 | + common_hal_fourwire_fourwire_construct(bus, |
| 56 | + spi, |
| 57 | + &pin_GPIO2, // TFT_DC Command or data |
| 58 | + &pin_GPIO15, // TFT_CS Chip select |
| 59 | + NULL, // TFT_RST Reset |
| 60 | + 20000000, // Baudrate |
| 61 | + 0, // Polarity |
| 62 | + 0); // Phase |
| 63 | + |
| 64 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 65 | + display->base.type = &busdisplay_busdisplay_type; |
| 66 | + common_hal_busdisplay_busdisplay_construct(display, |
| 67 | + bus, |
| 68 | + 320, // Width (after rotation) |
| 69 | + 480, // Height (after rotation) |
| 70 | + 0, // column start |
| 71 | + 0, // row start |
| 72 | + 0, // rotation |
| 73 | + 24, // Color depth |
| 74 | + false, // grayscale |
| 75 | + false, // pixels in byte share row. only used for depth < 8 |
| 76 | + 1, // bytes per cell. Only valid for depths < 8 |
| 77 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 78 | + true, // reverse_pixels_in_word |
| 79 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command |
| 80 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command |
| 81 | + MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command |
| 82 | + display_init_sequence, |
| 83 | + sizeof(display_init_sequence), |
| 84 | + &pin_GPIO27, // backlight pin |
| 85 | + 0x51, // cmd to write brightness |
| 86 | + 0.5f, // brightness |
| 87 | + false, // single_byte_bounds |
| 88 | + false, // data_as_commands |
| 89 | + true, // auto_refresh |
| 90 | + 60, // native_frames_per_second |
| 91 | + true, // backlight_on_high |
| 92 | + false, // SH1107_addressing |
| 93 | + 50000); // backlight pwm frequency |
| 94 | +} |
| 95 | + |
| 96 | +void board_deinit(void) { |
| 97 | + common_hal_displayio_release_displays(); |
| 98 | +} |
| 99 | + |
| 100 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments