|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2021 microDev |
| 7 | + * Copyright (c) 2021 skieast/Bruce Segal |
| 8 | + * |
| 9 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | + * of this software and associated documentation files (the "Software"), to deal |
| 11 | + * in the Software without restriction, including without limitation the rights |
| 12 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | + * copies of the Software, and to permit persons to whom the Software is |
| 14 | + * furnished to do so, subject to the following conditions: |
| 15 | + * |
| 16 | + * The above copyright notice and this permission notice shall be included in |
| 17 | + * all copies or substantial portions of the Software. |
| 18 | + * |
| 19 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 25 | + * THE SOFTWARE. |
| 26 | + */ |
| 27 | + |
| 28 | +#include "shared-bindings/board/__init__.h" |
| 29 | +#include "shared-bindings/displayio/I2CDisplay.h" |
| 30 | +#include "shared-module/displayio/__init__.h" |
| 31 | +#include "shared-module/displayio/mipi_constants.h" |
| 32 | +#include "shared-bindings/busio/I2C.h" |
| 33 | +#include "shared-bindings/microcontroller/Pin.h" |
| 34 | +#include "supervisor/board.h" |
| 35 | +#include "supervisor/shared/board.h" |
| 36 | +#include "shared-bindings/board/__init__.h" |
| 37 | + |
| 38 | +uint8_t display_init_sequence[] = { // SSD1306 |
| 39 | + 0xAE, 0, // DISPLAY_OFF |
| 40 | + 0x20, 1, 0x00, // Set memory addressing to horizontal mode. |
| 41 | + 0x81, 1, 0xcf, // set contrast control |
| 42 | + 0xA1, 0, // Column 127 is segment 0 |
| 43 | + 0xA6, 0, // Normal display |
| 44 | + 0xc8, 0, // Normal display |
| 45 | + 0xA8, 1, 0x3f, // Mux ratio is 1/64 |
| 46 | + 0xd5, 1, 0x80, // Set divide ratio |
| 47 | + 0xd9, 1, 0xf1, // Set pre-charge period |
| 48 | + 0xda, 1, 0x12, // Set com configuration |
| 49 | + 0xdb, 1, 0x40, // Set vcom configuration |
| 50 | + 0x8d, 1, 0x14, // Enable charge pump |
| 51 | + 0xAF, 0, // DISPLAY_ON |
| 52 | +}; |
| 53 | + |
| 54 | +void board_init(void) { |
| 55 | + busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0); |
| 56 | + |
| 57 | + // What we would do if it wasn't the shared board I2C: (for reference) |
| 58 | + // busio_i2c_obj_t *i2c = &displays[0].i2cdisplay_bus.inline_bus; |
| 59 | + // common_hal_busio_i2c_construct(i2c, &pin_GPIO23, &pin_GPIO22, 100000, 0); |
| 60 | + // common_hal_busio_i2c_never_reset(i2c); |
| 61 | + |
| 62 | + displayio_i2cdisplay_obj_t *bus = &displays[0].i2cdisplay_bus; |
| 63 | + bus->base.type = &displayio_i2cdisplay_type; |
| 64 | + common_hal_displayio_i2cdisplay_construct(bus, |
| 65 | + i2c, |
| 66 | + 0x3c, |
| 67 | + NULL |
| 68 | + ); |
| 69 | + |
| 70 | + displayio_display_obj_t *display = &displays[0].display; |
| 71 | + display->base.type = &displayio_display_type; |
| 72 | + common_hal_displayio_display_construct(display, |
| 73 | + bus, |
| 74 | + 72, // Width |
| 75 | + 40, // Height |
| 76 | + 28, // column start |
| 77 | + 28, // row start |
| 78 | + 0, // rotation |
| 79 | + 1, // Color depth |
| 80 | + true, // grayscale |
| 81 | + false, // pixels in byte share row. Only used with depth < 8 |
| 82 | + 1, // bytes per cell. Only valid for depths < 8 |
| 83 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 84 | + true, // reverse_pixels_in_word |
| 85 | + 0x21, // Set column command |
| 86 | + 0x22, // Set row command |
| 87 | + 44, // Write ram command |
| 88 | + display_init_sequence, |
| 89 | + sizeof(display_init_sequence), |
| 90 | + NULL, // no backlight pin |
| 91 | + 0x81, // brightness command |
| 92 | + 1.0f, // brightness |
| 93 | + true, // single_byte_bounds |
| 94 | + true, // data as commands |
| 95 | + true, // auto_refresh |
| 96 | + 60, // native_frames_per_second |
| 97 | + true, // backlight_on_high |
| 98 | + false, // SH1107_addressing |
| 99 | + 0); // backlight pwm frequency |
| 100 | +} |
| 101 | + |
| 102 | +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. |
0 commit comments