Skip to content

Commit c395e1f

Browse files
authored
Merge pull request #8332 from pypewpew/ugame22
Add new board uGame22
2 parents ed76e48 + b9b04fc commit c395e1f

File tree

7 files changed

+181
-2
lines changed

7 files changed

+181
-2
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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 "shared-bindings/microcontroller/Pin.h"
30+
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
31+
32+
#include "shared-bindings/busio/SPI.h"
33+
#include "shared-bindings/displayio/FourWire.h"
34+
#include "shared-module/displayio/__init__.h"
35+
#include "shared-module/displayio/mipi_constants.h"
36+
37+
38+
uint8_t display_init_sequence[] = {
39+
0x01, 0x80, 0x80, // Software reset then delay 0x80 (128ms)
40+
0xEF, 0x03, 0x03, 0x80, 0x02,
41+
0xCF, 0x03, 0x00, 0xC1, 0x30,
42+
0xED, 0x04, 0x64, 0x03, 0x12, 0x81,
43+
0xE8, 0x03, 0x85, 0x00, 0x78,
44+
0xCB, 0x05, 0x39, 0x2C, 0x00, 0x34, 0x02,
45+
0xF7, 0x01, 0x20,
46+
0xEA, 0x02, 0x00, 0x00,
47+
0xc0, 0x01, 0x23, // Power control VRH[5:0]
48+
0xc1, 0x01, 0x10, // Power control SAP[2:0];BT[3:0]
49+
0xc5, 0x02, 0x3e, 0x28, // VCM control
50+
0xc7, 0x01, 0x86, // VCM control2
51+
0x36, 0x01, 0x38, // Memory Access Control
52+
0x37, 0x01, 0x00, // Vertical scroll zero
53+
0x3a, 0x01, 0x55, // COLMOD: Pixel Format Set
54+
0xb1, 0x02, 0x00, 0x18, // Frame Rate Control (In Normal Mode/Full Colors)
55+
0xb6, 0x03, 0x08, 0x82, 0x27, // Display Function Control
56+
0xF2, 0x01, 0x00, // 3Gamma Function Disable
57+
0x26, 0x01, 0x01, // Gamma curve selected
58+
0xe0, 0x0f, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07,
59+
0x10, 0x03, 0x0E, 0x09, 0x00, // Set Gamma
60+
0xe1, 0x0f, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08,
61+
0x0F, 0x0C, 0x31, 0x36, 0x0F, // Set Gamma
62+
0x11, 0x80, 0x78, // Exit Sleep then delay 0x78 (120ms)
63+
0x29, 0x80, 0x78, // Display on then delay 0x78 (120ms)
64+
};
65+
66+
void board_init(void) {
67+
displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
68+
busio_spi_obj_t *spi = &bus->inline_bus;
69+
common_hal_busio_spi_construct(spi, &pin_GPIO2, &pin_GPIO3, NULL, false);
70+
common_hal_busio_spi_never_reset(spi);
71+
72+
bus->base.type = &displayio_fourwire_type;
73+
common_hal_displayio_fourwire_construct(bus,
74+
spi,
75+
&pin_GPIO4, // TFT_DC Command or data
76+
&pin_GPIO5, // TFT_CS Chip select
77+
&pin_GPIO1, // TFT_RST Reset
78+
80000000L, // Baudrate
79+
0, // Polarity
80+
0); // Phase
81+
82+
displayio_display_obj_t *display = &allocate_display()->display;
83+
display->base.type = &displayio_display_type;
84+
common_hal_displayio_display_construct(display,
85+
bus,
86+
320, // Width (after rotation)
87+
240, // Height (after rotation)
88+
0, // column start
89+
0, // row start
90+
0, // rotation
91+
16, // Color depth
92+
false, // grayscale
93+
false, // pixels in byte share row. only used for depth < 8
94+
1, // bytes per cell. Only valid for depths < 8
95+
false, // reverse_pixels_in_byte. Only valid for depths < 8
96+
true, // reverse_pixels_in_word
97+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
98+
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
99+
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
100+
display_init_sequence,
101+
sizeof(display_init_sequence),
102+
NULL, // backlight pin
103+
NO_BRIGHTNESS_COMMAND,
104+
1.0f, // brightness
105+
false, // single_byte_bounds
106+
false, // data_as_commands
107+
false, // auto_refresh
108+
20, // native_frames_per_second
109+
true, // backlight_on_high
110+
false, // SH1107_addressing
111+
50000); // backlight pwm frequency
112+
}
113+
114+
bool board_requests_safe_mode(void) {
115+
return false;
116+
}
117+
118+
void reset_board(void) {
119+
}
120+
121+
void board_deinit(void) {
122+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define MICROPY_HW_BOARD_NAME "uGame22"
2+
#define MICROPY_HW_MCU_NAME "rp2040"
3+
4+
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO14)
5+
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO15)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
USB_VID = 0x1209
2+
USB_PID = 0xD1B6
3+
USB_PRODUCT = "uGame22"
4+
USB_MANUFACTURER = "Radomir Dopieralski"
5+
6+
CHIP_VARIANT = RP2040
7+
CHIP_FAMILY = rp2
8+
9+
EXTERNAL_FLASH_DEVICES = "W25Q16JVxM"
10+
11+
CIRCUITPY_STAGE = 1
12+
CIRCUITPY_AUDIOIO = 1
13+
CIRCUITPY_AUDIOPWMIO = 1
14+
CIRCUITPY_KEYPAD = 1
15+
16+
FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/ugame22
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Put board-specific pico-sdk definitions here. This file must exist.
2+
3+
// Allow extra time for xosc to start.
4+
#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
3+
4+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
5+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
6+
7+
{ MP_ROM_QSTR(MP_QSTR_TFT_RST), MP_ROM_PTR(&pin_GPIO1) },
8+
{ MP_ROM_QSTR(MP_QSTR_TFT_SCK), MP_ROM_PTR(&pin_GPIO2) },
9+
{ MP_ROM_QSTR(MP_QSTR_TFT_MOSI), MP_ROM_PTR(&pin_GPIO3) },
10+
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO4) },
11+
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO5) },
12+
13+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_Z), MP_ROM_PTR(&pin_GPIO0) },
14+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_X), MP_ROM_PTR(&pin_GPIO6) },
15+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_DOWN), MP_ROM_PTR(&pin_GPIO7) },
16+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_O), MP_ROM_PTR(&pin_GPIO8) },
17+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_RIGHT), MP_ROM_PTR(&pin_GPIO9) },
18+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_UP), MP_ROM_PTR(&pin_GPIO10) },
19+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_LEFT), MP_ROM_PTR(&pin_GPIO11) },
20+
21+
{ MP_ROM_QSTR(MP_QSTR_GAIN), MP_ROM_PTR(&pin_GPIO22) },
22+
{ MP_ROM_QSTR(MP_QSTR_I2S_DIN), MP_ROM_PTR(&pin_GPIO23) },
23+
{ MP_ROM_QSTR(MP_QSTR_I2S_BCLK), MP_ROM_PTR(&pin_GPIO24) },
24+
{ MP_ROM_QSTR(MP_QSTR_I2S_LRCLK), MP_ROM_PTR(&pin_GPIO25) },
25+
26+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO14) },
27+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO15) },
28+
29+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
30+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
31+
};
32+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)