|
| 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/busio/SPI.h" |
| 30 | +#include "shared-bindings/fourwire/FourWire.h" |
| 31 | +#include "shared-bindings/microcontroller/Pin.h" |
| 32 | +#include "shared-module/displayio/__init__.h" |
| 33 | +#include "shared-module/displayio/mipi_constants.h" |
| 34 | +#include "shared-bindings/board/__init__.h" |
| 35 | + |
| 36 | +fourwire_fourwire_obj_t board_display_obj; |
| 37 | + |
| 38 | +uint8_t display_init_sequence[] = { |
| 39 | + 0xFE, 0x00, // Inter Register Enable1 (FEh) |
| 40 | + 0xEF, 0x00, // Inter Register Enable2 (EFh) |
| 41 | + 0xB6, 0x02, 0x00, 0x00, // Display Function Control (B6h) [S1→S360 source, G1→G32 gate] |
| 42 | + 0x36, 0x01, 0x48, // Memory Access Control(36h) [Invert Row order, invert vertical scan order] |
| 43 | + 0x3a, 0x01, 0x55, // COLMOD: Pixel Format Set (3Ah) [16 bits / pixel] |
| 44 | + 0xC3, 0x01, 0x13, // Power Control 2 (C3h) [VREG1A = 5.06, VREG1B = 0.68] |
| 45 | + 0xC4, 0x01, 0x13, // Power Control 3 (C4h) [VREG2A = -3.7, VREG2B = 0.68] |
| 46 | + 0xC9, 0x01, 0x22, // Power Control 4 (C9h) |
| 47 | + 0xF0, 0x06, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2a, // SET_GAMMA1 (F0h) |
| 48 | + 0xF1, 0x06, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6f, // SET_GAMMA2 (F1h) |
| 49 | + 0xF2, 0x06, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2a, // SET_GAMMA3 (F2h) |
| 50 | + 0xF3, 0x06, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6f, // SET_GAMMA4 (F3h) |
| 51 | + |
| 52 | + 0x66, 0x0a, 0x3c, 0x00, 0xcd, 0x67, 0x45, 0x45, 0x10, 0x00, 0x00, 0x00, |
| 53 | + 0x67, 0x0a, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x01, 0x54, 0x10, 0x32, 0x98, |
| 54 | + 0x74, 0x07, 0x10, 0x85, 0x80, 0x00, 0x00, 0x4e, 0x00, |
| 55 | + 0x98, 0x02, 0x3e, 0x07, |
| 56 | + |
| 57 | + 0x35, 0x00, // Tearing Effect Line ON (35h) [both V-blanking and H-blanking] |
| 58 | + 0x21, 0x00, // Display Inversion ON (21h) |
| 59 | + 0x11, 0x80, 0x78, // Sleep Out Mode (11h) and delay(120) |
| 60 | + 0x29, 0x80, 0x14, // Display ON (29h) and delay(20) |
| 61 | + 0x2a, 0x04, 0x00, 0x00, 0x00, 239, // Column Address Set (2Ah) [Start col = 0, end col = 239] |
| 62 | + 0x2b, 0x04, 0x00, 0x00, 0x00, 239, // Row Address Set (2Bh) [Start row = 0, end row = 239] |
| 63 | +}; |
| 64 | + |
| 65 | +void board_init(void) { |
| 66 | + busio_spi_obj_t *spi = common_hal_board_create_spi(0); |
| 67 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 68 | + bus->base.type = &fourwire_fourwire_type; |
| 69 | + |
| 70 | + common_hal_fourwire_fourwire_construct( |
| 71 | + bus, |
| 72 | + spi, |
| 73 | + &pin_GPIO4, // DC |
| 74 | + &pin_GPIO7, // CS |
| 75 | + &pin_GPIO8, // RST |
| 76 | + 40000000, // baudrate |
| 77 | + 0, // polarity |
| 78 | + 0 // phase |
| 79 | + ); |
| 80 | + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; |
| 81 | + display->base.type = &busdisplay_busdisplay_type; |
| 82 | + |
| 83 | + common_hal_busdisplay_busdisplay_construct( |
| 84 | + display, |
| 85 | + bus, |
| 86 | + 240, // width (after rotation) |
| 87 | + 240, // height (after rotation) |
| 88 | + 0, // column start |
| 89 | + 0, // row start |
| 90 | + 0, // rotation |
| 91 | + 16, // color depth |
| 92 | + false, // grayscale |
| 93 | + false, // pixels in a byte share a row. Only valid for depths < 8 |
| 94 | + 1, // bytes per cell. Only valid for depths < 8 |
| 95 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 96 | + true, // reverse_pixels_in_word |
| 97 | + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command |
| 98 | + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command |
| 99 | + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command |
| 100 | + display_init_sequence, |
| 101 | + sizeof(display_init_sequence), |
| 102 | + &pin_GPIO9, // backlight pin |
| 103 | + NO_BRIGHTNESS_COMMAND, |
| 104 | + 0.8f, // brightness |
| 105 | + false, // single_byte_bounds |
| 106 | + false, // data_as_commands |
| 107 | + true, // auto_refresh |
| 108 | + 60, // native_frames_per_second |
| 109 | + true, // backlight_on_high |
| 110 | + false, // SH1107_addressing |
| 111 | + 50000 // backlight pwm frequency |
| 112 | + ); |
| 113 | +} |
| 114 | + |
| 115 | +bool espressif_board_reset_pin_number(gpio_num_t pin_number) { |
| 116 | + // Hold pind must be set high to avoid a power off when battery powered |
| 117 | + if (pin_number == 46) { |
| 118 | + // Turn on hold output |
| 119 | + gpio_set_direction(46, GPIO_MODE_DEF_OUTPUT); |
| 120 | + gpio_set_level(46, true); |
| 121 | + return true; |
| 122 | + } |
| 123 | + return false; |
| 124 | +} |
| 125 | + |
| 126 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
| 127 | + |
| 128 | +// TODO: Should we turn off the display when asleep, in board_deinit() ? |
0 commit comments