Skip to content

Commit 5c72828

Browse files
authored
Merge pull request #7760 from Neradoc/01space-042-oled-c3
Adding 01space OLED 0.42 C3
2 parents cd69e1c + b45d128 commit 5c72828

File tree

5 files changed

+224
-0
lines changed

5 files changed

+224
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2023 Neradoc
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+
// Board setup
28+
#define MICROPY_HW_BOARD_NAME "01Space 0.42 OLED ESP32C3"
29+
#define MICROPY_HW_MCU_NAME "ESP32-C3FH4"
30+
31+
// Status LED
32+
#define MICROPY_HW_NEOPIXEL (&pin_GPIO2)
33+
34+
#define CIRCUITPY_BOARD_I2C (1)
35+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO6, .sda = &pin_GPIO5}}
36+
37+
// For entering safe mode
38+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)
39+
40+
#define CIRCUITPY_ESP_USB_SERIAL_JTAG (1)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CIRCUITPY_CREATOR_ID = 0x01011ACE
2+
CIRCUITPY_CREATION_ID = 0x00C30042
3+
4+
IDF_TARGET = esp32c3
5+
6+
CIRCUITPY_ESP_FLASH_MODE = dio
7+
CIRCUITPY_ESP_FLASH_FREQ = 80m
8+
CIRCUITPY_ESP_FLASH_SIZE = 4MB
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2023 Neradoc
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 "shared-bindings/board/__init__.h"
28+
#include "shared-module/displayio/__init__.h"
29+
30+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
31+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
32+
33+
{ MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) },
34+
35+
{ MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) },
36+
37+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO2) },
38+
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
39+
40+
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
41+
42+
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
43+
44+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO5) },
45+
{ MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) },
46+
47+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO6) },
48+
{ MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) },
49+
50+
{ MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) },
51+
52+
{ MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) },
53+
54+
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO9) },
55+
{ MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) },
56+
57+
{ MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) },
58+
59+
{ MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) },
60+
61+
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
62+
63+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
64+
{ MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) },
65+
66+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
67+
};
68+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# chip is ESP32-C3 FH4
2+
#
3+
# LWIP
4+
#
5+
CONFIG_LWIP_LOCAL_HOSTNAME="01Space-LCD042-ESP32C3"
6+
# end of LWIP

0 commit comments

Comments
 (0)