From 72f0f5fc0913c2b145889ba1ff8d350577acd351 Mon Sep 17 00:00:00 2001 From: Chris Vig Date: Sun, 31 Aug 2025 12:10:19 -0500 Subject: [PATCH] Make device pinout configurable in build system. --- .vscode/c_cpp_properties.json | 12 ++++++++++- configuration.cmake | 38 +++++++++++++++++++++++++++++++++++ src/main/application/buzzer.c | 1 + src/main/application/io.c | 16 +++++++-------- src/main/application/led.c | 5 ++--- src/main/drivers/gpio.h | 4 ++++ 6 files changed, 64 insertions(+), 12 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 08cfe26..dab045d 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -39,7 +39,17 @@ "_CONFIG_DFLT_IO_TYPE_TRS_3_RING=IO_TYPE_NONE", "_CONFIG_DFLT_IO_POLARITY_TRS_3_RING=IO_POLARITY_ACTIVE_LOW", "_CONFIG_DFLT_KEYER_PADDLE_MODE=KEYER_PADDLE_MODE_IAMBIC", - "_CONFIG_DFLT_KEYER_PADDLE_INVERT=false" + "_CONFIG_DFLT_KEYER_PADDLE_INVERT=false", + "_PIN_LED_STATUS=GPIO_PIN_D7", + "_PIN_LED_KEY=GPIO_PIN_D6", + "_PIN_IO_PIN_TRS_0_TIP=GPIO_PIN_A0", + "_PIN_IO_PIN_TRS_0_RING=GPIO_PIN_A1", + "_PIN_IO_PIN_TRS_1_TIP=GPIO_PIN_A2", + "_PIN_IO_PIN_TRS_1_RING=GPIO_PIN_A3", + "_PIN_IO_PIN_TRS_2_TIP=GPIO_PIN_A4", + "_PIN_IO_PIN_TRS_2_RING=GPIO_PIN_A5", + "_PIN_IO_PIN_TRS_3_TIP=GPIO_PIN_A6", + "_PIN_IO_PIN_TRS_3_RING=GPIO_PIN_A7" ], "compilerPath": "/usr/bin/avr-gcc", "compilerArgs": [ diff --git a/configuration.cmake b/configuration.cmake index 86f0360..d5befa1 100644 --- a/configuration.cmake +++ b/configuration.cmake @@ -114,3 +114,41 @@ add_compile_definitions( _CONFIG_DFLT_KEYER_PADDLE_INVERT=${CONFIG_DFLT_KEYER_PADDLE_INVERT} _CONFIG_DFLT_KEYER_OUTPUT_ACTIVE_LOW=${CONFIG_DFLT_KEYER_OUTPUT_ACTIVE_LOW} ) + +# -- Pin Configuration -- + +# Define values +set(PIN_IO_PIN_TRS_0_TIP GPIO_PIN_A0 + CACHE STRING "GPIO pin for the tip connector of TRS 0. (gpio_pin_t)") +set(PIN_IO_PIN_TRS_0_RING GPIO_PIN_A1 + CACHE STRING "GPIO pin for the ring connector of TRS 0. (gpio_pin_t)") +set(PIN_IO_PIN_TRS_1_TIP GPIO_PIN_A2 + CACHE STRING "GPIO pin for the tip connector of TRS 1. (gpio_pin_t)") +set(PIN_IO_PIN_TRS_1_RING GPIO_PIN_A3 + CACHE STRING "GPIO pin for the ring connector of TRS 1. (gpio_pin_t)") +set(PIN_IO_PIN_TRS_2_TIP GPIO_PIN_A4 + CACHE STRING "GPIO pin for the tip connector of TRS 2. (gpio_pin_t)") +set(PIN_IO_PIN_TRS_2_RING GPIO_PIN_A5 + CACHE STRING "GPIO pin for the ring connector of TRS 2. (gpio_pin_t)") +set(PIN_IO_PIN_TRS_3_TIP GPIO_PIN_A6 + CACHE STRING "GPIO pin for the tip connector of TRS 3. (gpio_pin_t)") +set(PIN_IO_PIN_TRS_3_RING GPIO_PIN_A7 + CACHE STRING "GPIO pin for the ring connector of TRS 3. (gpio_pin_t)") +set(PIN_LED_STATUS GPIO_PIN_D7 + CACHE STRING "GPIO pin for the status LED. (gpio_pin_t)") +set(PIN_LED_KEY GPIO_PIN_D6 + CACHE STRING "GPIO pin for the key LED. (gpio_pin_t)") + +# Set compile definitions +add_compile_definitions( + _PIN_IO_PIN_TRS_0_TIP=${PIN_IO_PIN_TRS_0_TIP} + _PIN_IO_PIN_TRS_0_RING=${PIN_IO_PIN_TRS_0_RING} + _PIN_IO_PIN_TRS_1_TIP=${PIN_IO_PIN_TRS_1_TIP} + _PIN_IO_PIN_TRS_1_RING=${PIN_IO_PIN_TRS_1_RING} + _PIN_IO_PIN_TRS_2_TIP=${PIN_IO_PIN_TRS_2_TIP} + _PIN_IO_PIN_TRS_2_RING=${PIN_IO_PIN_TRS_2_RING} + _PIN_IO_PIN_TRS_3_TIP=${PIN_IO_PIN_TRS_3_TIP} + _PIN_IO_PIN_TRS_3_RING=${PIN_IO_PIN_TRS_3_RING} + _PIN_LED_STATUS=${PIN_LED_STATUS} + _PIN_LED_KEY=${PIN_LED_KEY} +) diff --git a/src/main/application/buzzer.c b/src/main/application/buzzer.c index 46ae275..a2e8858 100644 --- a/src/main/application/buzzer.c +++ b/src/main/application/buzzer.c @@ -25,6 +25,7 @@ /** * @def OCRA_GPIO_PIN * @brief The GPIO pin associated with the OCRA pin connected to the buzzer. + * @note This is hard-coded (not configurable), since the timer output is locked to a specific pin. */ #define OCRA_GPIO_PIN GPIO_PIN_D5 diff --git a/src/main/application/io.c b/src/main/application/io.c index 240c466..80797aa 100644 --- a/src/main/application/io.c +++ b/src/main/application/io.c @@ -26,14 +26,14 @@ static gpio_pin_t const s_pin_tbl[] = { - GPIO_PIN_A0, /* IO_PIN_TRS_0_TIP */ - GPIO_PIN_A1, /* IO_PIN_TRS_0_RING */ - GPIO_PIN_A2, /* IO_PIN_TRS_1_TIP */ - GPIO_PIN_A3, /* IO_PIN_TRS_1_RING */ - GPIO_PIN_A4, /* IO_PIN_TRS_2_TIP */ - GPIO_PIN_A5, /* IO_PIN_TRS_2_RING */ - GPIO_PIN_A6, /* IO_PIN_TRS_3_TIP */ - GPIO_PIN_A7, /* IO_PIN_TRS_3_RING */ + _PIN_IO_PIN_TRS_0_TIP, + _PIN_IO_PIN_TRS_0_RING, + _PIN_IO_PIN_TRS_1_TIP, + _PIN_IO_PIN_TRS_1_RING, + _PIN_IO_PIN_TRS_2_TIP, + _PIN_IO_PIN_TRS_2_RING, + _PIN_IO_PIN_TRS_3_TIP, + _PIN_IO_PIN_TRS_3_RING, }; _Static_assert( array_count( s_pin_tbl ) == IO_PIN_COUNT, "Invalid pin table!" ); diff --git a/src/main/application/led.c b/src/main/application/led.c index a6fc561..e75b3dd 100644 --- a/src/main/application/led.c +++ b/src/main/application/led.c @@ -23,9 +23,8 @@ static gpio_pin_t const s_gpio_tbl[] = { - // Must be in same order as led_t enum - GPIO_PIN_C0, /* LED_STATUS */ - GPIO_PIN_D6, /* LED_KEY */ + _PIN_LED_STATUS, + _PIN_LED_KEY, }; _Static_assert( array_count( s_gpio_tbl ) == LED_COUNT, "Invalid GPIO table!" ); diff --git a/src/main/drivers/gpio.h b/src/main/drivers/gpio.h index 92363ed..75367d0 100644 --- a/src/main/drivers/gpio.h +++ b/src/main/drivers/gpio.h @@ -33,6 +33,10 @@ enum /** * @typedef gpio_pin_t * @brief Enumeration of the supported GPIO pins. + * @note Note that the availability of a pin in this enumeration does not necessarily mean that it may be used for + * I/O. Many of the I/O pins are being used for their alternative functions, and attempting to use them as GPIO + * pins will result in undefined behavior. Refer to doc/hardware-guide.md for more details on the usage of each + * pin. */ typedef uint8_t gpio_pin_t; enum