|
| 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 | + |
| 29 | +#include "mpconfigboard.h" |
| 30 | +#include "shared-bindings/board/__init__.h" |
| 31 | +#include "shared-bindings/busio/SPI.h" |
| 32 | +#include "shared-bindings/fourwire/FourWire.h" |
| 33 | +#include "shared-bindings/microcontroller/Pin.h" |
| 34 | +#include "shared-bindings/time/__init__.h" |
| 35 | +#include "shared-module/displayio/__init__.h" |
| 36 | +#include "supervisor/shared/board.h" |
| 37 | + |
| 38 | +#define DELAY 0x80 |
| 39 | + |
| 40 | +// This is a 7.3" ACeP EInk. |
| 41 | + |
| 42 | +digitalio_digitalinout_obj_t enable_pin_obj; |
| 43 | + |
| 44 | +digitalio_digitalinout_obj_t sr_clock; |
| 45 | +digitalio_digitalinout_obj_t sr_data; |
| 46 | +digitalio_digitalinout_obj_t sr_latch; |
| 47 | + |
| 48 | +enum reg { |
| 49 | + PSR = 0x00, |
| 50 | + PWR = 0x01, |
| 51 | + POF = 0x02, |
| 52 | + PFS = 0x03, |
| 53 | + PON = 0x04, |
| 54 | + BTST1 = 0x05, |
| 55 | + BTST2 = 0x06, |
| 56 | + DSLP = 0x07, |
| 57 | + BTST3 = 0x08, |
| 58 | + DTM1 = 0x10, |
| 59 | + DSP = 0x11, |
| 60 | + DRF = 0x12, |
| 61 | + IPC = 0x13, |
| 62 | + PLL = 0x30, |
| 63 | + TSC = 0x40, |
| 64 | + TSE = 0x41, |
| 65 | + TSW = 0x42, |
| 66 | + TSR = 0x43, |
| 67 | + CDI = 0x50, |
| 68 | + LPD = 0x51, |
| 69 | + TCON = 0x60, |
| 70 | + TRES = 0x61, |
| 71 | + DAM = 0x65, |
| 72 | + REV = 0x70, |
| 73 | + FLG = 0x71, |
| 74 | + AMV = 0x80, |
| 75 | + VV = 0x81, |
| 76 | + VDCS = 0x82, |
| 77 | + T_VDCS = 0x84, |
| 78 | + AGID = 0x86, |
| 79 | + CMDH = 0xAA, |
| 80 | + CCSET =0xE0, |
| 81 | + PWS = 0xE3, |
| 82 | + TSSET = 0xE6 // E5 or E6 |
| 83 | +}; |
| 84 | + |
| 85 | +const uint8_t display_start_sequence[] = { |
| 86 | + CMDH, 6, 0x49, 0x55, 0x20, 0x08, 0x09, 0x18, |
| 87 | + PWR, 6, 0x3F, 0x00, 0x32, 0x2A, 0x0E, 0x2A, |
| 88 | + PSR, 2, 0x5F, 0x69, |
| 89 | + PFS, 4, 0x00, 0x54, 0x00, 0x44, |
| 90 | + BTST1, 4, 0x40, 0x1F, 0x1F, 0x2C, |
| 91 | + BTST2, 4, 0x6F, 0x1F, 0x16, 0x25, |
| 92 | + BTST3, 4, 0x6F, 0x1F, 0x1F, 0x22, |
| 93 | + IPC, 2, 0x00, 0x04, |
| 94 | + PLL, 1, 0x02, |
| 95 | + TSE, 1, 0x00, |
| 96 | + CDI, 1, 0x3F, |
| 97 | + TCON, 2, 0x02, 0x00, |
| 98 | + TRES, 4, 0x03, 0x20, 0x01, 0xE0, |
| 99 | + VDCS, 1, 0x1E, |
| 100 | + T_VDCS, 1, 0x00, |
| 101 | + AGID, 1, 0x00, |
| 102 | + PWS, 1, 0x2F, |
| 103 | + CCSET, 1, 0x00, |
| 104 | + TSSET, 1, 0x00, |
| 105 | + PON, DELAY, 0xc8, |
| 106 | +}; |
| 107 | + |
| 108 | +const uint8_t display_stop_sequence[] = { |
| 109 | + POF, 0, |
| 110 | +}; |
| 111 | + |
| 112 | +const uint8_t refresh_sequence[] = { |
| 113 | + DRF, 1, 0x00, |
| 114 | +}; |
| 115 | + |
| 116 | +void board_init(void) { |
| 117 | + // Drive the EN_3V3 pin high so the board stays awake on battery power |
| 118 | + enable_pin_obj.base.type = &digitalio_digitalinout_type; |
| 119 | + common_hal_digitalio_digitalinout_construct(&enable_pin_obj, &pin_GPIO2); |
| 120 | + common_hal_digitalio_digitalinout_switch_to_output(&enable_pin_obj, true, DRIVE_MODE_PUSH_PULL); |
| 121 | + |
| 122 | + // Never reset |
| 123 | + common_hal_digitalio_digitalinout_never_reset(&enable_pin_obj); |
| 124 | + |
| 125 | + common_hal_digitalio_digitalinout_construct(&sr_clock, &pin_GPIO8); |
| 126 | + common_hal_digitalio_digitalinout_switch_to_output(&sr_clock, false, DRIVE_MODE_PUSH_PULL); |
| 127 | + |
| 128 | + common_hal_digitalio_digitalinout_construct(&sr_data, &pin_GPIO10); |
| 129 | + common_hal_digitalio_digitalinout_switch_to_input(&sr_data, PULL_NONE); |
| 130 | + |
| 131 | + common_hal_digitalio_digitalinout_construct(&sr_latch, &pin_GPIO9); |
| 132 | + common_hal_digitalio_digitalinout_switch_to_output(&sr_latch, true, DRIVE_MODE_PUSH_PULL); |
| 133 | + |
| 134 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 135 | + busio_spi_obj_t *spi = common_hal_board_create_spi(0); |
| 136 | + |
| 137 | + bus->base.type = &fourwire_fourwire_type; |
| 138 | + common_hal_fourwire_fourwire_construct(bus, |
| 139 | + spi, |
| 140 | + &pin_GPIO28, // EPD_DC Command or data |
| 141 | + &pin_GPIO17, // EPD_CS Chip select |
| 142 | + &pin_GPIO27, // EPD_RST Reset |
| 143 | + 1000000, // Baudrate |
| 144 | + 0, // Polarity |
| 145 | + 0); // Phase |
| 146 | + |
| 147 | + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; |
| 148 | + display->base.type = &epaperdisplay_epaperdisplay_type; |
| 149 | + common_hal_epaperdisplay_epaperdisplay_construct( |
| 150 | + display, |
| 151 | + bus, |
| 152 | + display_start_sequence, sizeof(display_start_sequence), |
| 153 | + 1.0, // start up time |
| 154 | + display_stop_sequence, sizeof(display_stop_sequence), |
| 155 | + 800, // width |
| 156 | + 480, // height |
| 157 | + 800, // ram_width |
| 158 | + 480, // ram_height |
| 159 | + 0, // colstart |
| 160 | + 0, // rowstart |
| 161 | + 180, // rotation |
| 162 | + NO_COMMAND, // set_column_window_command |
| 163 | + NO_COMMAND, // set_row_window_command |
| 164 | + NO_COMMAND, // set_current_column_command |
| 165 | + NO_COMMAND, // set_current_row_command |
| 166 | + 0x10, // write_black_ram_command |
| 167 | + false, // black_bits_inverted |
| 168 | + NO_COMMAND, // write_color_ram_command |
| 169 | + false, // color_bits_inverted |
| 170 | + 0x000000, // highlight_color |
| 171 | + refresh_sequence, sizeof(refresh_sequence), |
| 172 | + 28.0, // refresh_time |
| 173 | + NULL, // busy_pin |
| 174 | + false, // busy_state |
| 175 | + 30.0, // seconds_per_frame |
| 176 | + false, // always_toggle_chip_select |
| 177 | + false, // grayscale |
| 178 | + true, // acep |
| 179 | + false, // two_byte_sequence_length |
| 180 | + false); // address_little_endian |
| 181 | +} |
| 182 | + |
| 183 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments