|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2017 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 "boards/board.h" |
| 28 | + #include "mpconfigboard.h" |
| 29 | + #include "hal/include/hal_gpio.h" |
| 30 | + #include "shared-bindings/busio/SPI.h" |
| 31 | + #include "shared-bindings/displayio/FourWire.h" |
| 32 | + #include "shared-module/displayio/__init__.h" |
| 33 | + #include "shared-module/displayio/mipi_constants.h" |
| 34 | + #include "tick.h" |
| 35 | + |
| 36 | + displayio_fourwire_obj_t board_display_obj; |
| 37 | + |
| 38 | + #define DELAY 0x80 |
| 39 | + |
| 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 |
| 48 | + }; |
| 49 | + |
| 50 | + void board_init(void) { |
| 51 | + busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; |
| 52 | + common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL); |
| 53 | + common_hal_busio_spi_never_reset(spi); |
| 54 | + |
| 55 | + displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; |
| 56 | + bus->base.type = &displayio_fourwire_type; |
| 57 | + common_hal_displayio_fourwire_construct(bus, |
| 58 | + spi, |
| 59 | + &pin_PB31, // TFT_DC Command or data |
| 60 | + &pin_PA27, // TFT_CS Chip select |
| 61 | + &pin_PB30, // TFT_RST Reset |
| 62 | + 60000000); |
| 63 | + |
| 64 | + displayio_display_obj_t* display = &displays[0].display; |
| 65 | + display->base.type = &displayio_display_type; |
| 66 | + common_hal_displayio_display_construct(display, |
| 67 | + bus, |
| 68 | + 240, // Width (after rotation) |
| 69 | + 240, // Height (after rotation) |
| 70 | + 0, // column start
57AE
|
| 71 | + 0, // row start |
| 72 | + 180, // rotation |
| 73 | + 16, // Color depth |
| 74 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command |
| 75 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command |
| 76 | + MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command |
| 77 | + 0x37, // set vertical scroll command |
| 78 | + display_init_sequence, |
| 79 | + sizeof(display_init_sequence), |
| 80 | + &pin_PB14, // backlight pin |
| 81 | + 1.0f, // brightness (ignored) |
| 82 | + true, // auto_brightness |
| 83 | + false, // single_byte_bounds |
| 84 | + false); // data_as_commands |
| 85 | + } |
| 86 | + |
| 87 | + bool board_requests_safe_mode(void) { |
| 88 | + return false; |
| 89 | + } |
| 90 | + |
| 91 | + void reset_board(void) { |
| 92 | + } |
0 commit comments