Skip to content

Commit ab035ce

Browse files
committed
Support inverted status LED
1 parent 1222ba1 commit ab035ce

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ports/zephyr-cp/cptools/zephyr2cp.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
logger = logging.getLogger(__name__)
1010

11+
# GPIO flags defined here: include/zephyr/dt-bindings/gpio/gpio.h
12+
GPIO_ACTIVE_LOW = 1 << 0
13+
1114
MANUAL_COMPAT_TO_DRIVER = {
1215
"renesas_ra_nv_flash": "flash",
1316
}
@@ -212,6 +215,7 @@ def zephyr_dts_to_cp_board(builddir, zephyrbuilddir): # noqa: C901
212215
flashes = []
213216
rams = []
214217
status_led = None
218+
status_led_inverted = False
215219
path2chosen = {}
216220
chosen2path = {}
217221
usb_num_endpoint_pairs = 0
@@ -320,6 +324,7 @@ def zephyr_dts_to_cp_board(builddir, zephyrbuilddir): # noqa: C901
320324
props = led.props
321325
ioport = props["gpios"]._markers[1][2]
322326
num = int.from_bytes(props["gpios"].value[4:8], "big")
327+
flags = int.from_bytes(props["gpios"].value[8:12], "big")
323328
if "label" in props:
324329
if (ioport, num) not in board_names:
325330
board_names[(ioport, num)] = []
@@ -330,6 +335,7 @@ def zephyr_dts_to_cp_board(builddir, zephyrbuilddir): # noqa: C901
330335
if "led0" in node2alias[led]:
331336
board_names[(ioport, num)].append("LED")
332337
status_led = (ioport, num)
338+
status_led_inverted = flags & GPIO_ACTIVE_LOW
333339
board_names[(ioport, num)].extend(node2alias[led])
334340

335341
if "gpio-keys" in compatible:
@@ -389,8 +395,12 @@ def zephyr_dts_to_cp_board(builddir, zephyrbuilddir): # noqa: C901
389395
header = board_dir / "mpconfigboard.h"
390396
if status_led:
391397
status_led = f"#define MICROPY_HW_LED_STATUS (&pin_{status_led})\n"
398+
status_led_inverted = (
399+
f"#define MICROPY_HW_LED_STATUS_INVERTED ({'1' if status_led_inverted else '0'})\n"
400+
)
392401
else:
393402
status_led = ""
403+
status_led_inverted = ""
394404
ram_list = []
395405
ram_externs = []
396406
max_size = 0
@@ -412,6 +422,7 @@ def zephyr_dts_to_cp_board(builddir, zephyrbuilddir): # noqa: C901
412422
#define MICROPY_HW_MCU_NAME "{soc_name}"
413423
#define CIRCUITPY_RAM_DEVICE_COUNT {len(rams)}
414424
{status_led}
425+
{status_led_inverted}
415426
"""
416427
if not header.exists() or header.read_text() != new_header_content:
417428
header.write_text(new_header_content)

0 commit comments

Comments
 (0)