Skip to content

STM32: Add displayio to F7/H7 #2842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ports/stm/boards/STM32H743_fs.ld
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 128K /* sector 0, 128K */
FLASH_FS (r) : ORIGIN = 0x08020000, LENGTH = 128K /* sector 1, 128K */
FLASH_FIRMWARE (rx) : ORIGIN = 0x08040000, LENGTH = 1792K /* sectors 6*128 + 8*128 */
FLASH_FS (r) : ORIGIN = 0x08020000, LENGTH = 384K /* sector 1-3, 128K */
FLASH_FIRMWARE (rx) : ORIGIN = 0x08080000, LENGTH = 1536K /* sectors 4*128 + 8*128 */
DTCM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x24000000, LENGTH = 512K /* AXI SRAM */
SRAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K /* AHB1 SRAM */
Expand Down
11 changes: 0 additions & 11 deletions ports/stm/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,24 @@ ifeq ($(MCU_SERIES),H7)
CIRCUITPY_ANALOGIO = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_PULSEIO = 0
CIRCUITPY_OS = 1
CIRCUITPY_NVM = 0
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0
# shared-module modules that still need prerequisites filled
CIRCUITPY_DISPLAYIO = 0 # Requires SPI, PulseIO, and common-hal module (stub ok)
CIRCUITPY_RANDOM = 0 # Requires OS
CIRCUITPY_STORAGE = 0 # Requires OS, filesystem
endif

ifeq ($(MCU_SERIES),F7)
# Not yet implemented common-hal modules:
CIRCUITPY_ANALOGIO = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_PULSEIO = 1
CIRCUITPY_OS = 1
CIRCUITPY_NVM = 0
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CSLAVE = 0
# shared-module modules that still need prerequisites filled
CIRCUITPY_DISPLAYIO = 0 # Requires SPI, PulseIO, and common-hal module (stub ok)
CIRCUITPY_RANDOM = 0 # Requires OS
CIRCUITPY_STORAGE = 0 # Requires OS, filesystem
endif
2 changes: 1 addition & 1 deletion ports/stm/supervisor/internal_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

#ifdef STM32H743xx
#define STM32_FLASH_SIZE 0x200000 //2MB
#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x20000 //128KiB
#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x60000 //384KiB
#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x08020000
#endif

Expand Down
28 changes: 26 additions & 2 deletions shared-module/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
// Always set the backlight type in case we're reusing memory.
self->backlight_inout.base.type = &mp_type_NoneType;
if (backlight_pin != NULL && common_hal_mcu_pin_is_free(backlight_pin)) {
// Avoid PWM types and functions when the module isn't enabled
#if (CIRCUITPY_PULSEIO)
pwmout_result_t result = common_hal_pulseio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 50000, false);
if (result != PWMOUT_OK) {
self->backlight_inout.base.type = &digitalio_digitalinout_type;
Expand All @@ -120,6 +122,12 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
self->backlight_pwm.base.type = &pulseio_pwmout_type;
common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm);
}
#else
// Otherwise default to digital
self->backlight_inout.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->backlight_inout, backlight_pin);
common_hal_never_reset_pin(backlight_pin);
#endif
}
if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType ||
brightness_command != NO_BRIGHTNESS_COMMAND)) {
Expand Down Expand Up @@ -164,9 +172,21 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self,
brightness = 1.0-brightness;
}
bool ok = false;
if (self->backlight_pwm.base.type == &pulseio_pwmout_type) {

// Avoid PWM types and functions when the module isn't enabled
#if (CIRCUITPY_PULSEIO)
bool ispwm = (self->backlight_pwm.base.type == &pulseio_pwmout_type) ? true : false;
#else
bool ispwm = false;
#endif

if (ispwm) {
#if (CIRCUITPY_PULSEIO)
common_hal_pulseio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t) (0xffff * brightness));
ok = true;
#else
ok = false;
#endif
} else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) {
common_hal_digitalio_digitalinout_set_value(&self->backlight_inout, brightness > 0.99);
ok = true;
Expand Down Expand Up @@ -392,12 +412,16 @@ void displayio_display_background(displayio_display_obj_t* self) {

void release_display(displayio_display_obj_t* self) {
release_display_core(&self->core);
#if (CIRCUITPY_PULSEIO)
if (self->backlight_pwm.base.type == &pulseio_pwmout_type) {
common_hal_pulseio_pwmout_reset_ok(&self->backlight_pwm);
common_hal_pulseio_pwmout_deinit(&self->backlight_pwm);
common_hal_pulseio_pwmout_deinit(&self->backlight_pwm);
} else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) {
common_hal_digitalio_digitalinout_deinit(&self->backlight_inout);
}
#else
common_hal_digitalio_digitalinout_deinit(&self->backlight_inout);
#endif
}

void reset_display(displayio_display_obj_t* self) {
Expand Down