Skip to content

Commit

Permalink
Merge pull request #76 from adafruit/fix-print-c-program
Browse files Browse the repository at this point in the history
Avoid printing `True` in C program
  • Loading branch information
jepler authored Jan 23, 2025
2 parents 00cb534 + 6495261 commit f78d675
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion adafruit_pioasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def print_c_program(self, name: str, qualifier: str = "const") -> None:
sideset_pin_count = self.pio_kwargs.get("sideset_pin_count", 0)
print(f"{qualifier} int {name}_sideset_pin_count = {sideset_pin_count};")
print(
f"{qualifier} bool {name}_sideset_enable = {self.pio_kwargs['sideset_enable']};"
f"{qualifier} bool {name}_sideset_enable = {+self.pio_kwargs['sideset_enable']};"
)
print(f"{qualifier} uint16_t {name}[] = " + "{")
last_line = 0
Expand Down
17 changes: 17 additions & 0 deletions tests/test_print_c_program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2025 Jeff Epler, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import contextlib
import io

import adafruit_pioasm


def test_print_c_program():
output = io.StringIO()
with contextlib.redirect_stdout(output):
adafruit_pioasm.Program(".side_set 1 opt").print_c_program("mood")
c_program = output.getvalue()
assert "True" not in c_program
assert "sideset_enable = 1" in c_program

0 comments on commit f78d675

Please sign in to comment.