Skip to content

Commit

Permalink
Merge pull request #9187 from dhalbert/9.0.4-update
Browse files Browse the repository at this point in the history
Merge latest changes from 9.0.x
  • Loading branch information
dhalbert authored Apr 18, 2024
2 parents e74a4e5 + c35ec75 commit 1d50915
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 66 deletions.
6 changes: 6 additions & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
autoapi_python_class_content = "both"
autoapi_python_use_implicit_namespaces = True
autoapi_root = "shared-bindings"

# Suppress cache warnings to prevent "unpickable" [sic] warning
# about autoapi_prepare_jinja_env() from sphinx >= 7.3.0.
# See https://github.com/sphinx-doc/sphinx/issues/12300
suppress_warnings = ["config.cache"]

def autoapi_prepare_jinja_env(jinja_env):
jinja_env.globals['support_matrix_reverse'] = modules_support_matrix_reverse

Expand Down
13 changes: 12 additions & 1 deletion ports/nordic/common-hal/analogio/AnalogIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
// Something else might have used the ADC in a different way,
// so we completely re-initialize it.

nrf_saadc_value_t value = -1;
nrf_saadc_value_t value = 0;

const nrf_saadc_channel_config_t config = {
.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
Expand Down Expand Up @@ -120,6 +120,17 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {

nrf_saadc_disable(NRF_SAADC);

// Adding the "asm volatile" memory fence here or anywhere after the declaration of `value`
// fixes an issue with gcc13 which causes `value` to always be zero.
// Compiling with gcc10 or gcc12 is fine.
// It can also be fixed by declaring `value` to be static.
// I think I'd like to declare `value` as volatile, but that causes type errors.
asm volatile ("" : : : "memory");

// Disconnect ADC from pin.
nrf_saadc_channel_input_set(NRF_SAADC, CHANNEL_NO, NRF_SAADC_INPUT_DISABLED, NRF_SAADC_INPUT_DISABLED);

// value is signed and might be (slightly) < 0, even on single-ended conversions, so force to 0.
if (value < 0) {
value = 0;
}
Expand Down
81 changes: 81 additions & 0 deletions ports/raspberrypi/boards/waveshare_rp2040_geek/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "supervisor/board.h"


#include "mpconfigboard.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-bindings/board/__init__.h"

#define DELAY 0x80

fourwire_fourwire_obj_t board_display_obj;

// display init sequence according to https://github.com/adafruit/Adafruit_CircuitPython_ST7789
uint8_t display_init_sequence[] = {
0x01, 0 | DELAY, 0x96, // _SWRESET and Delay 150ms
0x11, 0 | DELAY, 0xFF, // _SLPOUT and Delay 500ms
0x3A, 0x81, 0x55, 0x0A, // _COLMOD and Delay 10ms
0x36, 0x01, 0x08, // _MADCTL
0x21, 0 | DELAY, 0x0A, // _INVON Hack and Delay 10ms
0x13, 0 | DELAY, 0x0A, // _NORON and Delay 10ms
0x36, 0x01, 0xC0, // _MADCTL
0x29, 0 | DELAY, 0xFF, // _DISPON and Delay 500ms
};

static void display_init(void) {

busio_spi_obj_t *spi = common_hal_board_create_spi(0);
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;

bus->base.type = &fourwire_fourwire_type;

common_hal_fourwire_fourwire_construct(
bus,
spi,
&pin_GPIO8, // TFT_DC
&pin_GPIO9, // TFT_CS
&pin_GPIO12, // TFT_RST
50000000, // Baudrate
0, // Polarity
0 // Phase

);

busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
display->base.type = &busdisplay_busdisplay_type;

common_hal_busdisplay_busdisplay_construct(
display,
bus,
240, // Width
135, // Height
53, // column start
40, // row start
270, // rotation
16, // Color depth
false, // Grayscale
false, // Pixels in a byte share a row
1, // bytes per cell
false, // reverse_pixels_in_byte
true, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
display_init_sequence,
sizeof(display_init_sequence),
&pin_GPIO25, // backlight pin
NO_BRIGHTNESS_COMMAND,
1.0f, // brightness
false, // single_byte_bounds
false, // data_as_commands
true, // auto_refresh
60, // native_frames_per_second
true, // backlight_on_high
false, // SH1107_addressing
1000 // backlight pwm frequency
);
}

void board_init(void) {
display_init();
}
39 changes: 39 additions & 0 deletions ports/raspberrypi/boards/waveshare_rp2040_geek/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

// Micropython setup
#define MICROPY_HW_BOARD_NAME "Waveshare RP2040-GEEK"
#define MICROPY_HW_MCU_NAME "rp2040"

#define CIRCUITPY_BOARD_I2C (1)
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO29, .sda = &pin_GPIO28}}

#define CIRCUITPY_BOARD_SPI (2)
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO10, .mosi = &pin_GPIO11}, \
{.clock = &pin_GPIO18, .mosi = &pin_GPIO19, .miso = &pin_GPIO20}}

#define CIRCUITPY_BOARD_UART (1)
#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO4, .rx = &pin_GPIO5}}
11 changes: 11 additions & 0 deletions ports/raspberrypi/boards/waveshare_rp2040_geek/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
USB_VID = 0x2E8A
USB_PID = 0x1056
USB_PRODUCT = "RP2040-GEEK"
USB_MANUFACTURER = "Waveshare Electronics"

CHIP_VARIANT = RP2040
CHIP_FAMILY = rp2

EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ"

CIRCUITPY__EVE = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Put board-specific pico-sdk definitions here. This file must exist.
72 changes: 72 additions & 0 deletions ports/raspberrypi/boards/waveshare_rp2040_geek/pins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "shared-bindings/board/__init__.h"
#include "shared-module/displayio/__init__.h"

CIRCUITPY_BOARD_BUS_SINGLETON(sd_spi, spi, 1)
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS

// 2-3 DEBUG
{ MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) },
// 4-5 UART
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) },
// 8-12 LCD
{ MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) },
// 16-17 I2C
{ MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) },
// 18-23 SD Card
{ MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_IO22), MP_ROM_PTR(&pin_GPIO22) },
{ MP_ROM_QSTR(MP_QSTR_IO23), MP_ROM_PTR(&pin_GPIO23) },
// 25 LCD Backlight
{ MP_ROM_QSTR(MP_QSTR_IO25), MP_ROM_PTR(&pin_GPIO25) },
// 28-29 I2C
{ MP_ROM_QSTR(MP_QSTR_IO28), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_IO29), MP_ROM_PTR(&pin_GPIO29) },

// UART
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },

// I2C
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO29) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },

// SPI SD Card
{ MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO18)},
{ MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO19)},
{ MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO20)},
{ MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO23)},
{ MP_ROM_QSTR(MP_QSTR_SD_SPI), MP_ROM_PTR(&board_sd_spi_obj) },

// SDIO SD Card
{ MP_ROM_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_GPIO18)},
{ MP_ROM_QSTR(MP_QSTR_SDIO_COMMAND), MP_ROM_PTR(&pin_GPIO19)},
{ MP_ROM_QSTR(MP_QSTR_SDIO_DATA0), MP_ROM_PTR(&pin_GPIO20)},
{ MP_ROM_QSTR(MP_QSTR_SDIO_DATA1), MP_ROM_PTR(&pin_GPIO21)},
{ MP_ROM_QSTR(MP_QSTR_SDIO_DATA2), MP_ROM_PTR(&pin_GPIO22)},
{ MP_ROM_QSTR(MP_QSTR_SDIO_DATA3), MP_ROM_PTR(&pin_GPIO23)},

// LCD
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_LCD_BACKLIGHT), MP_ROM_PTR(&pin_GPIO25) },
{ MP_ROM_QSTR(MP_QSTR_LCD_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) },

};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Loading

0 comments on commit 1d50915

Please sign in to comment.