Skip to content

Commit c35ec75

Browse files
committed
Merge remote-tracking branch 'adafruit/9.0.x' into 9.0.4-update
2 parents c978768 + c2caae7 commit c35ec75

File tree

9 files changed

+287
-66
lines changed

9 files changed

+287
-66
lines changed

conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
autoapi_python_class_content = "both"
111111
autoapi_python_use_implicit_namespaces = True
112112
autoapi_root = "shared-bindings"
113+
114+
# Suppress cache warnings to prevent "unpickable" [sic] warning
115+
# about autoapi_prepare_jinja_env() from sphinx >= 7.3.0.
116+
# See https://github.com/sphinx-doc/sphinx/issues/12300
117+
suppress_warnings = ["config.cache"]
118+
113119
def autoapi_prepare_jinja_env(jinja_env):
114120
jinja_env.globals['support_matrix_reverse'] = modules_support_matrix_reverse
115121

ports/nordic/common-hal/analogio/AnalogIn.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
7676
// Something else might have used the ADC in a different way,
7777
// so we completely re-initialize it.
7878

79-
nrf_saadc_value_t value = -1;
79+
nrf_saadc_value_t value = 0;
8080

8181
const nrf_saadc_channel_config_t config = {
8282
.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
@@ -120,6 +120,17 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
120120

121121
nrf_saadc_disable(NRF_SAADC);
122122

123+
// Adding the "asm volatile" memory fence here or anywhere after the declaration of `value`
124+
// fixes an issue with gcc13 which causes `value` to always be zero.
125+
// Compiling with gcc10 or gcc12 is fine.
126+
// It can also be fixed by declaring `value` to be static.
127+
// I think I'd like to declare `value` as volatile, but that causes type errors.
128+
asm volatile ("" : : : "memory");
129+
130+
// Disconnect ADC from pin.
131+
nrf_saadc_channel_input_set(NRF_SAADC, CHANNEL_NO, NRF_SAADC_INPUT_DISABLED, NRF_SAADC_INPUT_DISABLED);
132+
133+
// value is signed and might be (slightly) < 0, even on single-ended conversions, so force to 0.
123134
if (value < 0) {
124135
value = 0;
125136
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "supervisor/board.h"
2+
3+
4+
#include "mpconfigboard.h"
5+
#include "shared-module/displayio/__init__.h"
6+
#include "shared-module/displayio/mipi_constants.h"
7+
#include "shared-bindings/board/__init__.h"
8+
9+
#define DELAY 0x80
10+
11+
fourwire_fourwire_obj_t board_display_obj;
12+
13+
// display init sequence according to https://github.com/adafruit/Adafruit_CircuitPython_ST7789
14+
uint8_t display_init_sequence[] = {
15+
0x01, 0 | DELAY, 0x96, // _SWRESET and Delay 150ms
16+
0x11, 0 | DELAY, 0xFF, // _SLPOUT and Delay 500ms
17+
0x3A, 0x81, 0x55, 0x0A, // _COLMOD and Delay 10ms
18+
0x36, 0x01, 0x08, // _MADCTL
19+
0x21, 0 | DELAY, 0x0A, // _INVON Hack and Delay 10ms
20+
0x13, 0 | DELAY, 0x0A, // _NORON and Delay 10ms
21+
0x36, 0x01, 0xC0, // _MADCTL
22+
0x29, 0 | DELAY, 0xFF, // _DISPON and Delay 500ms
23+
};
24+
25+
static void display_init(void) {
26+
27+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
28+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
29+
30+
bus->base.type = &fourwire_fourwire_type;
31+
32+
common_hal_fourwire_fourwire_construct(
33+
bus,
34+
spi,
35+
&pin_GPIO8, // TFT_DC
36+
&pin_GPIO9, // TFT_CS
37+
&pin_GPIO12, // TFT_RST
38+
50000000, // Baudrate
39+
0, // Polarity
40+
0 // Phase
41+
42+
);
43+
44+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
45+
display->base.type = &busdisplay_busdisplay_type;
46+
47+
common_hal_busdisplay_busdisplay_construct(
48+
display,
49+
bus,
50+
240, // Width
51+
135, // Height
52+
53, // column start
53+
40, // row start
54+
270, // rotation
55+
16, // Color depth
56+
false, // Grayscale
57+
false, // Pixels in a byte share a row
58+
1, // bytes per cell
59+
false, // reverse_pixels_in_byte
60+
true, // reverse_pixels_in_word
61+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
62+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
63+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
64+
display_init_sequence,
65+
sizeof(display_init_sequence),
66+
&pin_GPIO25, // backlight pin
67+
NO_BRIGHTNESS_COMMAND,
68+
1.0f, // brightness
69+
false, // single_byte_bounds
70+
false, // data_as_commands
71+
true, // auto_refresh
72+
60, // native_frames_per_second
73+
true, // backlight_on_high
74+
false, // SH1107_addressing
75+
1000 // backlight pwm frequency
76+
);
77+
}
78+
79+
void board_init(void) {
80+
display_init();
81+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 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+
// Micropython setup
28+
#define MICROPY_HW_BOARD_NAME "Waveshare RP2040-GEEK"
29+
#define MICROPY_HW_MCU_NAME "rp2040"
30+
31+
#define CIRCUITPY_BOARD_I2C (1)
32+
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO29, .sda = &pin_GPIO28}}
33+
34+
#define CIRCUITPY_BOARD_SPI (2)
35+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO10, .mosi = &pin_GPIO11}, \
36+
{.clock = &pin_GPIO18, .mosi = &pin_GPIO19, .miso = &pin_GPIO20}}
37+
38+
#define CIRCUITPY_BOARD_UART (1)
39+
#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO4, .rx = &pin_GPIO5}}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
USB_VID = 0x2E8A
2+
USB_PID = 0x1056
3+
USB_PRODUCT = "RP2040-GEEK"
4+
USB_MANUFACTURER = "Waveshare Electronics"
5+
6+
CHIP_VARIANT = RP2040
7+
CHIP_FAMILY = rp2
8+
9+
EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ"
10+
11+
CIRCUITPY__EVE = 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Put board-specific pico-sdk definitions here. This file must exist.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
3+
4+
CIRCUITPY_BOARD_BUS_SINGLETON(sd_spi, spi, 1)
5+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
6+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
7+
8+
// 2-3 DEBUG
9+
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
10+
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
11+
// 4-5 UART
12+
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
13+
{ MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) },
14+
// 8-12 LCD
15+
{ MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) },
16+
{ MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) },
17+
{ MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) },
18+
{ MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) },
19+
{ MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) },
20+
// 16-17 I2C
21+
{ MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) },
22+
{ MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) },
23+
// 18-23 SD Card
24+
{ MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) },
25+
{ MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) },
26+
{ MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) },
27+
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
28+
{ MP_ROM_QSTR(MP_QSTR_IO22), MP_ROM_PTR(&pin_GPIO22) },
29+
{ MP_ROM_QSTR(MP_QSTR_IO23), MP_ROM_PTR(&pin_GPIO23) },
30+
// 25 LCD Backlight
31+
{ MP_ROM_QSTR(MP_QSTR_IO25), MP_ROM_PTR(&pin_GPIO25) },
32+
// 28-29 I2C
33+
{ MP_ROM_QSTR(MP_QSTR_IO28), MP_ROM_PTR(&pin_GPIO28) },
34+
{ MP_ROM_QSTR(MP_QSTR_IO29), MP_ROM_PTR(&pin_GPIO29) },
35+
36+
// UART
37+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO4) },
38+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO5) },
39+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
40+
41+
// I2C
42+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO29) },
43+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO28) },
44+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
45+
46+
// SPI SD Card
47+
{ MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO18)},
48+
{ MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO19)},
49+
{ MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO20)},
50+
{ MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO23)},
51+
{ MP_ROM_QSTR(MP_QSTR_SD_SPI), MP_ROM_PTR(&board_sd_spi_obj) },
52+
53+
// SDIO SD Card
54+
{ MP_ROM_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_GPIO18)},
55+
{ MP_ROM_QSTR(MP_QSTR_SDIO_COMMAND), MP_ROM_PTR(&pin_GPIO19)},
56+
{ MP_ROM_QSTR(MP_QSTR_SDIO_DATA0), MP_ROM_PTR(&pin_GPIO20)},
57+
{ MP_ROM_QSTR(MP_QSTR_SDIO_DATA1), MP_ROM_PTR(&pin_GPIO21)},
58+
{ MP_ROM_QSTR(MP_QSTR_SDIO_DATA2), MP_ROM_PTR(&pin_GPIO22)},
59+
{ MP_ROM_QSTR(MP_QSTR_SDIO_DATA3), MP_ROM_PTR(&pin_GPIO23)},
60+
61+
// LCD
62+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO8) },
63+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO9) },
64+
{ MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO10) },
65+
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO11) },
66+
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO12) },
67+
{ MP_ROM_QSTR(MP_QSTR_LCD_BACKLIGHT), MP_ROM_PTR(&pin_GPIO25) },
68+
{ MP_ROM_QSTR(MP_QSTR_LCD_SPI), MP_ROM_PTR(&board_spi_obj) },
69+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) },
70+
71+
};
72+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)