|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +#include "supervisor/board.h" |
| 28 | +#include "mpconfigboard.h" |
| 29 | +#include "shared-bindings/microcontroller/Pin.h" |
| 30 | + |
| 31 | +#include "shared-bindings/busio/SPI.h" |
| 32 | +#include "shared-bindings/displayio/FourWire.h" |
| 33 | +#include "shared-module/displayio/__init__.h" |
| 34 | +#include "shared-module/displayio/mipi_constants.h" |
| 35 | + |
| 36 | +uint8_t display_init_sequence[] = { |
| 37 | + 0x01, 0x80, 0x96, // _SWRESET and Delay 150ms |
| 38 | + 0x11, 0x80, 0xFF, // _SLPOUT and Delay 500ms |
| 39 | + 0x3A, 0x81, 0x55, 0x0A, // _COLMOD and Delay 10ms |
| 40 | + 0x21, 0x80, 0x0A, // _INVON |
| 41 | + 0x13, 0x80, 0x0A, // _NORON and Delay 10ms |
| 42 | + 0x36, 0x01, 0xA0, // _MADCTL |
| 43 | + 0x29, 0x80, 0xFF, // _DISPON and Delay 500ms |
| 44 | +}; |
| 45 | + |
| 46 | +void board_init(void) { |
| 47 | + busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; |
| 48 | + common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false); |
| 49 | + common_hal_busio_spi_never_reset(spi); |
| 50 | + |
| 51 | + displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; |
| 52 | + bus->base.type = &displayio_fourwire_type; |
| 53 | + common_hal_displayio_fourwire_construct(bus, |
| 54 | + spi, |
| 55 | + &pin_GPIO4, // TFT_DC Command or data |
| 56 | + &pin_GPIO5, // TFT_CS Chip select |
| 57 | + &pin_GPIO48, // TFT_RST Reset |
| 58 | + 60000000, // Baudrate |
| 59 | + 0, // Polarity |
| 60 | + 0); // Phase |
| 61 | + |
| 62 | + displayio_display_obj_t *display = &displays[0].display; |
| 63 | + display->base.type = &displayio_display_type; |
| 64 | + common_hal_displayio_display_construct(display, |
| 65 | + bus, |
| 66 | + 320, // Width |
| 67 | + 240, // Height |
| 68 | + 0, // column start |
| 69 | + 0, // row start |
| 70 | + 0, // rotation |
| 71 | + 16, // Color depth |
| 72 | + false, // Grayscale |
| 73 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 74 | + 1, // bytes per cell. Only valid for depths < 8 |
| 75 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 76 | + true, // reverse_pixels_in_word |
| 77 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command |
| 78 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command |
| 79 | + MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command |
| 80 | + display_init_sequence, |
| 81 | + sizeof(display_init_sequence), |
| 82 | + &pin_GPIO45, // backlight pin |
| 83 | + NO_BRIGHTNESS_COMMAND, |
| 84 | + 1.0f, // brightness (ignored) |
| 85 | + true, // auto_brightness |
| 86 | + false, // single_byte_bounds |
| 87 | + false, // data_as_commands |
| 88 | + true, // auto_refresh |
| 89 | + 60, // native_frames_per_second |
| 90 | + false, // backlight_on_high |
| 91 | + false, // SH1107_addressing |
| 92 | + 50000); // backlight pwm frequency |
| 93 | + |
| 94 | + // Debug UART |
| 95 | + #ifdef DEBUG |
| 96 | + common_hal_never_reset_pin(&pin_GPIO43); |
| 97 | + common_hal_never_reset_pin(&pin_GPIO44); |
| 98 | + #endif |
| 99 | +} |
| 100 | + |
| 101 | +bool board_requests_safe_mode(void) { |
| 102 | + return false; |
| 103 | +} |
| 104 | + |
| 105 | +void reset_board(void) { |
| 106 | + |
| 107 | +} |
| 108 | + |
| 109 | +void board_deinit(void) { |
| 110 | +} |
0 commit comments