|
1 | 1 | // This file is part of the CircuitPython project: https://circuitpython.org
|
2 | 2 | //
|
3 |
| -// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries |
| 3 | +// SPDX-FileCopyrightText: Copyright (c) 2020 Joey Castillo |
4 | 4 | //
|
5 | 5 | // SPDX-License-Identifier: MIT
|
6 | 6 |
|
7 | 7 | #include "supervisor/board.h"
|
| 8 | +#include "mpconfigboard.h" |
| 9 | +#include "hal/include/hal_gpio.h" |
| 10 | +#include "shared-bindings/busio/SPI.h" |
| 11 | +#include "shared-bindings/fourwire/FourWire.h" |
| 12 | +#include "shared-bindings/time/__init__.h" |
| 13 | +#include "shared-module/displayio/__init__.h" |
| 14 | +#include "shared-module/displayio/mipi_constants.h" |
8 | 15 |
|
9 |
| -// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
10 | 16 |
|
11 |
| -// TODO: |
| 17 | +#define DELAY 0x80 |
| 18 | +#define HEIGHT 300 |
| 19 | +#define WIDTH 400 |
| 20 | + |
| 21 | +uint8_t start_sequence[] = { |
| 22 | + 0x01, 0x04, 0x03, 0x00, 0x2b, 0x2b, // power setting |
| 23 | + 0x06, 0x03, 0x17, 0x17, 0x17, // booster soft start |
| 24 | + 0x04, 0x80, 0xc8, // power on and wait 200 ms |
| 25 | + 0x00, 0x01, 0x0f, // panel setting |
| 26 | + 0x61, 0x04, (HEIGHT >> 8) & 0xFF, HEIGHT & 0xFF, (WIDTH >> 8) & 0xFF, WIDTH & 0xFF // Resolution |
| 27 | +}; |
| 28 | + |
| 29 | +uint8_t stop_sequence[] = { |
| 30 | + 0x50, 0x01, 0xf7, // CDI setting |
| 31 | + 0x02, 0x80, 0xf0 // Power off |
| 32 | +}; |
| 33 | + |
| 34 | +uint8_t refresh_sequence[] = { |
| 35 | + 0x12, 0x00 |
| 36 | +}; |
| 37 | + |
| 38 | +void board_init(void) { |
| 39 | + fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; |
| 40 | + busio_spi_obj_t *spi = &bus->inline_bus; |
| 41 | + common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false); |
| 42 | + common_hal_busio_spi_never_reset(spi); |
| 43 | + |
| 44 | + bus->base.type = &fourwire_fourwire_type; |
| 45 | + common_hal_fourwire_fourwire_construct(bus, |
| 46 | + spi, |
| 47 | + &pin_GPIO46, // EPD_DC Command or data |
| 48 | + &pin_GPIO45, // EPD_CS Chip select |
| 49 | + &pin_GPIO47, // EPD_RST Reset |
| 50 | + 1000000, // Baudrate |
| 51 | + 0, // Polarity |
| 52 | + 0); // Phase |
| 53 | + |
| 54 | + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; |
| 55 | + display->base.type = &epaperdisplay_epaperdisplay_type; |
| 56 | + common_hal_epaperdisplay_epaperdisplay_construct(display, |
| 57 | + bus, |
| 58 | + start_sequence, |
| 59 | + sizeof(start_sequence), |
| 60 | + 0, // start up time |
| 61 | + stop_sequence, |
| 62 | + sizeof(stop_sequence), |
| 63 | + 400, // width |
| 64 | + 300, // height |
| 65 | + 400, // RAM width |
| 66 | + 300, // RAM height |
| 67 | + 0, // colstart |
| 68 | + 0, // rowstart |
| 69 | + 0, // rotation |
| 70 | + NO_COMMAND, // set_column_window_command |
| 71 | + NO_COMMAND, // set_row_window_command |
| 72 | + NO_COMMAND, // set_current_column_command |
| 73 | + NO_COMMAND, // set_current_row_command |
| 74 | + 0x13, // write_black_ram_command |
| 75 | + false, // black_bits_inverted |
| 76 | + NO_COMMAND, // write_color_ram_command (can add this for grayscale eventually) |
| 77 | + false, // color_bits_inverted |
| 78 | + 0x000000, // highlight_color |
| 79 | + refresh_sequence, // refresh_display_sequence |
| 80 | + sizeof(refresh_sequence), |
| 81 | + 40, // refresh_time |
| 82 | + &pin_GPIO48, // busy_pin |
| 83 | + false, // busy_state |
| 84 | + 5, // seconds_per_frame |
| 85 | + false, // chip_select (don't always toggle chip select) |
| 86 | + false, // grayscale |
| 87 | + false, // acep |
| 88 | + false, // two_byte_sequence_length |
| 89 | + false); // address_little_endian |
| 90 | +} |
| 91 | + |
| 92 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments