|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2021 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 | + |
| 30 | +#include "shared-bindings/busio/SPI.h" |
| 31 | +#include "shared-bindings/fourwire/FourWire.h" |
| 32 | +#include "shared-bindings/microcontroller/Pin.h" |
| 33 | +#include "shared-module/displayio/__init__.h" |
| 34 | +#include "shared-module/displayio/mipi_constants.h" |
| 35 | +#include "shared-bindings/board/__init__.h" |
| 36 | + |
| 37 | +fourwire_fourwire_obj_t board_display_obj; |
| 38 | + |
| 39 | +#define DELAY 0x80 |
| 40 | + |
| 41 | +uint8_t display_init_sequence[] = { |
| 42 | + 0x01, 0 | DELAY, 120, // SWRESET |
| 43 | + 0x11, 0 | DELAY, 5, // SLPOUT |
| 44 | + 0x36, 1, 0b10100000, // _MADCTL for rotation 0 |
| 45 | + 0x3a, 1, 0x55, // COLMOD - 16bit color |
| 46 | + 0x21, 0, // _INVON |
| 47 | + 0x13, 0, // _NORON |
| 48 | + 0x29, 0 | DELAY, 5, // _DISPON |
| 49 | +}; |
| 50 | + |
| 51 | + |
| 52 | +void board_init(void) { |
| 53 | + busio_spi_obj_t *spi = common_hal_board_create_spi(0); |
| 54 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 55 | + bus->base.type = &fourwire_fourwire_type; |
| 56 | + common_hal_fourwire_fourwire_construct(bus, |
| 57 | + spi, |
| 58 | + &pin_GPIO25, // TFT_DC Command or data |
| 59 | + &pin_GPIO29, // TFT_CS Chip select |
| 60 | + NULL, // TFT_RESET Reset |
| 61 | + 40000000, // Baudrate |
| 62 | + 0, // Polarity |
| 63 | + 0); // Phase |
| 64 | + |
| 65 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 66 | + display->base.type = &busdisplay_busdisplay_type; |
| 67 | + common_hal_busdisplay_busdisplay_construct( |
| 68 | + display, |
| 69 | + bus, |
| 70 | + 240, // Width (after rotation) |
| 71 | + 240, // Height (after rotation) |
| 72 | + 80, // column start |
| 73 | + 0, // row start |
| 74 | + 0, // rotation |
| 75 | + 16, // Color depth |
| 76 | + false, // Grayscale |
| 77 | + false, // Pixels in a byte share a row. Only used for depth < 8 |
| 78 | + 1, // bytes per cell. Only valid for depths < 8 |
| 79 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 80 | + true, // reverse_pixels_in_word |
| 81 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command |
| 82 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command |
| 83 | + MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command |
| 84 | + display_init_sequence, |
| 85 | + sizeof(display_init_sequence), |
| 86 | + &pin_GPIO28, // backlight pin |
| 87 | + NO_BRIGHTNESS_COMMAND, |
| 88 | + 1.0f, // brightness |
| 89 | + false, // single_byte_bounds |
| 90 | + false, // data_as_commands |
| 91 | + true, // auto_refresh |
| 92 | + 60, // native_frames_per_second |
| 93 | + true, // backlight_on_high |
| 94 | + false, // not SH1107 |
| 95 | + 50000); // backlight pwm frequency |
| 96 | +} |
| 97 | + |
| 98 | +void board_deinit(void) { |
| 99 | + common_hal_displayio_release_displays(); |
| 100 | +} |
| 101 | + |
| 102 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments