Skip to content

Commit cc05153

Browse files
authored
Merge pull request #10736 from tannewt/fix_tab5_usb
Allow swapping LSFS USB on ESP32-P4 to USB OTG
2 parents 108860a + db86a75 commit cc05153

File tree

24 files changed

+151
-47
lines changed

24 files changed

+151
-47
lines changed

ports/analog/boards/apard32690/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ USB_VID=0x0456
1919
USB_PID=0x003C
2020
USB_MANUFACTURER="Analog Devices, Inc."
2121
USB_PRODUCT="MAX32690 APARD"
22-
USB_HIGHSPEED=1
2322

2423
# NOTE: MAX32 devices do not support IN/OUT pairs on the same EP
2524
USB_NUM_ENDPOINT_PAIRS=12

ports/analog/boards/max32690evkit/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ USB_VID=0x0456
1919
USB_PID=0x003D
2020
USB_MANUFACTURER="Analog Devices, Inc."
2121
USB_PRODUCT="MAX32690 EvKit"
22-
USB_HIGHSPEED=1
2322

2423
# NOTE: MAX32 devices do not support IN/OUT pairs on the same EP
2524
USB_NUM_ENDPOINT_PAIRS=12

ports/analog/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// 24KiB stack
1313
#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000
1414

15+
#define CIRCUITPY_USB_DEVICE_HIGH_SPEED (1)
16+
1517
// Also includes mpconfigboard.h
1618
#include "py/circuitpy_mpconfig.h"
1719

ports/broadcom/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define MICROPY_FATFS_EXFAT (1)
2727
#define MICROPY_FATFS_MKFS_FAT32 (1)
2828

29+
#define CIRCUITPY_USB_DEVICE_HIGH_SPEED (1)
30+
2931
////////////////////////////////////////////////////////////////////////////////////////////////////
3032

3133
// This also includes mpconfigboard.h.

ports/broadcom/mpconfigport.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ CIRCUITPY_VIDEOCORE = 1
2222
INTERNAL_FLASH_FILESYSTEM = 1
2323

2424
USB_NUM_ENDPOINT_PAIRS = 8
25-
USB_HIGHSPEED = 1
2625

2726
CIRCUITPY_BUILD_EXTENSIONS ?= disk.img.zip,kernel8.img
2827

ports/cxd56/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define USB_MSC_EP_NUM_OUT (5)
2424
#define USB_MSC_EP_NUM_IN (4)
2525

26+
#define CIRCUITPY_USB_DEVICE_HIGH_SPEED (1)
27+
2628
#include "py/circuitpy_mpconfig.h"
2729

2830
#define MICROPY_BYTES_PER_GC_BLOCK (32)

ports/cxd56/mpconfigport.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
USB_HIGHSPEED = 1
2-
31
# Number of USB endpoint pairs.
42
USB_NUM_ENDPOINT_PAIRS = 6
53

ports/espressif/boards/m5stack_tab5/mpconfigboard.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@
2525
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO19)
2626

2727
// Use the second USB device (numbered 0 and 1)
28-
#define CIRCUITPY_USB_DEVICE_INSTANCE 1
28+
#define CIRCUITPY_USB_DEVICE_INSTANCE 0
29+
#define CIRCUITPY_ESP32P4_SWAP_LSFS (1)

ports/espressif/common-hal/microcontroller/Pin.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,28 @@ static const uint64_t pin_mask_reset_forbidden =
204204
#endif // ESP32H2
205205

206206
#if defined(CONFIG_IDF_TARGET_ESP32P4)
207-
// Never ever reset pins used to communicate with the SPI flash.
208-
GPIO_SEL_28 |
209-
GPIO_SEL_29 |
210-
GPIO_SEL_30 |
211-
GPIO_SEL_32 |
212-
GPIO_SEL_33 |
213-
GPIO_SEL_34 |
207+
// SPI flash is on dedicated pins.
208+
209+
// USB is on the FS OTG
210+
#if CIRCUITPY_USB_DEVICE_INSTANCE == 0
211+
#if CIRCUITPY_ESP32P4_SWAP_LSFS == 1
212+
// We leave 24 and 25 alone in addition to 26 and 27 when swapped. It doesn't work otherwise. (Not sure why.)
213+
GPIO_SEL_24 | // USB D-
214+
GPIO_SEL_25 | // USB D+
215+
#endif
216+
GPIO_SEL_26 | // USB D-
217+
GPIO_SEL_27 | // USB D+
218+
#endif
214219
#if CIRCUITPY_ESP_USB_SERIAL_JTAG || (defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG)
215220
// Never ever reset serial/JTAG communication pins.
221+
#if CIRCUITPY_ESP32P4_SWAP_LSFS == 1
222+
GPIO_SEL_26 | // USB D-
223+
GPIO_SEL_27 | // USB D+
224+
#else
216225
GPIO_SEL_24 | // USB D-
217226
GPIO_SEL_25 | // USB D+
218227
#endif
228+
#endif
219229
#if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) && CONFIG_ESP_CONSOLE_UART_DEFAULT && CONFIG_ESP_CONSOLE_UART_NUM == 0
220230
// Never reset debug UART/console pins.
221231
GPIO_SEL_37 |

ports/espressif/common-hal/mipidsi/Display.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,40 @@ void common_hal_mipidsi_display_refresh(mipidsi_display_obj_t *self) {
222222
// sends data from the framebuffer to the display
223223
}
224224

225+
mp_float_t common_hal_mipidsi_display_get_brightness(mipidsi_display_obj_t *self) {
226+
return self->current_brightness;
227+
}
228+
229+
bool common_hal_mipidsi_display_set_brightness(mipidsi_display_obj_t *self, mp_float_t brightness) {
230+
if (!self->backlight_on_high) {
231+
brightness = 1.0 - brightness;
232+
}
233+
bool ok = false;
234+
235+
// Avoid PWM types and functions when the module isn't enabled
236+
#if (CIRCUITPY_PWMIO)
237+
bool ispwm = (self->backlight_pwm.base.type == &pwmio_pwmout_type) ? true : false;
238+
#else
239+
bool ispwm = false;
240+
#endif
241+
242+
if (ispwm) {
243+
#if (CIRCUITPY_PWMIO)
244+
common_hal_pwmio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t)(0xffff * brightness));
245+
ok = true;
246+
#else
247+
ok = false;
248+
#endif
249+
} else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) {
250+
common_hal_digitalio_digitalinout_set_value(&self->backlight_inout, brightness > 0.99);
251+
ok = true;
252+
}
253+
if (ok) {
254+
self->current_brightness = brightness;
255+
}
256+
return ok;
257+
}
258+
225259
int common_hal_mipidsi_display_get_width(mipidsi_display_obj_t *self) {
226260
return self->width;
227261
}

0 commit comments

Comments
 (0)