|
27 | 27 | #include "supervisor/board.h"
|
28 | 28 | #include "mpconfigboard.h"
|
29 | 29 | #include "shared-bindings/microcontroller/Pin.h"
|
| 30 | +#include "shared-bindings/board/__init__.h" |
| 31 | +#include "shared-bindings/displayio/I2CDisplay.h" |
| 32 | +#include "shared-module/displayio/__init__.h" |
| 33 | +#include "shared-module/displayio/mipi_constants.h" |
| 34 | +#include "shared-bindings/busio/I2C.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, 0x1f, // Mux ratio is height-1 |
| 46 | + 0xd5, 1, 0x80, // Set divide ratio |
| 47 | + 0xd9, 1, 0xf1, // Set pre-charge period |
| 48 | + 0xda, 1, 0x02, // Set com configuration to 2 if height is 32 and width not 64 |
| 49 | + 0xdb, 1, 0x40, // Set vcom configuration |
| 50 | + 0x8d, 1, 0x14, // Enable charge pump |
| 51 | + 0xAF, 0, // DISPLAY_ON |
| 52 | +}; |
| 53 | + |
| 54 | +static void display_init(void) { |
| 55 | + busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0); |
| 56 | + |
| 57 | + displayio_i2cdisplay_obj_t *bus = &displays[0].i2cdisplay_bus; |
| 58 | + bus->base.type = &displayio_i2cdisplay_type; |
| 59 | + common_hal_displayio_i2cdisplay_construct(bus, |
| 60 | + i2c, |
| 61 | + 0x3c, |
| 62 | + &pin_GPIO18 // reset |
| 63 | + ); |
| 64 | + |
| 65 | + displayio_display_obj_t *display = &displays[0].display; |
| 66 | + display->base.type = &displayio_display_type; |
| 67 | + common_hal_displayio_display_construct(display, |
| 68 | + bus, |
| 69 | + 128, // Width |
| 70 | + 32, // Height |
| 71 | + 0, // column start |
| 72 | + 0, // row start |
| 73 | + 0, // rotation |
| 74 | + 1, // Color depth |
| 75 | + true, // grayscale |
| 76 | + false, // pixels in byte share row. Only used with depth < 8 |
| 77 | + 1, // bytes per cell. Only valid for depths < 8 |
| 78 | + false, // reverse_pixels_in_byte. Only valid for depths < 8 |
| 79 | + true, // reverse_pixels_in_word |
| 80 | + 0x21, // Set column command |
| 81 | + 0x22, // Set row command |
| 82 | + 44, // Write ram command |
| 83 | + display_init_sequence, |
| 84 | + sizeof(display_init_sequence), |
| 85 | + NULL, // no backlight pin |
| 86 | + 0x81, // brightness command |
| 87 | + 1.0f, // brightness |
| 88 | + true, // single_byte_bounds |
| 89 | + true, // data as commands |
| 90 | + true, // auto_refresh |
| 91 | + 60, // native_frames_per_second |
| 92 | + true, // backlight_on_high |
| 93 | + false, // SH1107_addressing |
| 94 | + 0); // backlight pwm frequency |
| 95 | +} |
30 | 96 |
|
31 | 97 | void board_init(void) {
|
| 98 | + // init display |
| 99 | + display_init(); |
32 | 100 | // Debug UART
|
33 | 101 | #ifdef DEBUG
|
34 | 102 | common_hal_never_reset_pin(&pin_GPIO43);
|
|
0 commit comments