diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 367b2c7..905350c 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -32,9 +32,9 @@ "_CONFIG_DFLT_INPUT_POLARITY_TRS_2_TIP=INPUT_POLARITY_ACTIVE_LOW", "_CONFIG_DFLT_INPUT_TYPE_TRS_2_RING=INPUT_TYPE_NONE", "_CONFIG_DFLT_INPUT_POLARITY_TRS_2_RING=INPUT_POLARITY_ACTIVE_LOW", - "_CONFIG_DFLT_KEYER_MODE=KEYER_MODE_IAMBIC", - "_CONFIG_DFLT_KEYER_OUTPUT_ACTIVE_LOW=true", - "_CONFIG_DFLT_KEYER_INVERT_PADDLES=false" + "_CONFIG_DFLT_KEYER_PADDLE_MODE=KEYER_PADDLE_MODE_IAMBIC", + "_CONFIG_DFLT_KEYER_PADDLE_INVERT=false", + "_CONFIG_DFLT_KEYER_OUTPUT_ACTIVE_LOW=true" ], "compilerPath": "/usr/bin/avr-gcc", "compilerArgs": [ diff --git a/configuration.cmake b/configuration.cmake index 99c3915..e94355f 100644 --- a/configuration.cmake +++ b/configuration.cmake @@ -60,12 +60,12 @@ set(CONFIG_DFLT_INPUT_TYPE_TRS_2_RING INPUT_TYPE_NONE CACHE STRING "Input type for the ring of TRS 0. (input_type_t)") set(CONFIG_DFLT_INPUT_POLARITY_TRS_2_RING INPUT_POLARITY_ACTIVE_LOW CACHE STRING "Input polarity for the ring of TRS 0. (input_polarity_t)") -set(CONFIG_DFLT_KEYER_MODE KEYER_MODE_IAMBIC - CACHE STRING "Keyer mode. (keyer_mode_t)") +set(CONFIG_DFLT_KEYER_PADDLE_MODE KEYER_PADDLE_MODE_IAMBIC + CACHE STRING "Keyer paddle mode. (keyer_paddle_mode_t)") +set(CONFIG_DFLT_KEYER_PADDLE_INVERT false + CACHE STRING "Set to true to invert the paddles. (true / false)") set(CONFIG_DFLT_KEYER_OUTPUT_ACTIVE_LOW true CACHE STRING "Set to true for active low keyer output. (true / false)") -set(CONFIG_DFLT_KEYER_INVERT_PADDLES false - CACHE STRING "Set to true to invert the paddles. (true / false)") # Set compile definitions add_compile_definitions( @@ -88,7 +88,7 @@ add_compile_definitions( _CONFIG_DFLT_INPUT_POLARITY_TRS_2_TIP=${CONFIG_DFLT_INPUT_POLARITY_TRS_2_TIP} _CONFIG_DFLT_INPUT_TYPE_TRS_2_RING=${CONFIG_DFLT_INPUT_TYPE_TRS_2_RING} _CONFIG_DFLT_INPUT_POLARITY_TRS_2_RING=${CONFIG_DFLT_INPUT_POLARITY_TRS_2_RING} - _CONFIG_DFLT_KEYER_MODE=${CONFIG_DFLT_KEYER_MODE} + _CONFIG_DFLT_KEYER_PADDLE_MODE=${CONFIG_DFLT_KEYER_PADDLE_MODE} + _CONFIG_DFLT_KEYER_PADDLE_INVERT=${CONFIG_DFLT_KEYER_PADDLE_INVERT} _CONFIG_DFLT_KEYER_OUTPUT_ACTIVE_LOW=${CONFIG_DFLT_KEYER_OUTPUT_ACTIVE_LOW} - _CONFIG_DFLT_KEYER_INVERT_PADDLES=${CONFIG_DFLT_KEYER_INVERT_PADDLES} ) diff --git a/src/main/application/config.c b/src/main/application/config.c index fa97fbe..6e4a585 100644 --- a/src/main/application/config.c +++ b/src/main/application/config.c @@ -73,9 +73,9 @@ void config_default( config_t * config ) config->input_polarity[ INPUT_PIN_TRS_2_RING ] = _CONFIG_DFLT_INPUT_POLARITY_TRS_2_RING; // Keyer configuration - config->keyer_mode = _CONFIG_DFLT_KEYER_MODE; + config->keyer_paddle_mode = _CONFIG_DFLT_KEYER_PADDLE_MODE; + config->keyer_paddle_invert = _CONFIG_DFLT_KEYER_PADDLE_INVERT; config->keyer_output_active_low = _CONFIG_DFLT_KEYER_OUTPUT_ACTIVE_LOW; - config->keyer_invert_paddles = _CONFIG_DFLT_KEYER_INVERT_PADDLES; // Ensure we generated a valid configuration assert_always( validate_config( config ) ); diff --git a/src/main/application/config.h b/src/main/application/config.h index 63996f1..2b8d658 100644 --- a/src/main/application/config.h +++ b/src/main/application/config.h @@ -46,15 +46,15 @@ typedef struct /** The configured input polarity for each input pin. */ input_polarity_t input_polarity[ INPUT_PIN_COUNT ]; - /** The keyer mode. */ - keyer_mode_t keyer_mode; + /** The keyer's paddle mode. */ + keyer_paddle_mode_t keyer_paddle_mode; + + /** If set to `true`, the keyer will emit dashes from the left paddle and dots from the right paddle. */ + bool keyer_paddle_invert; /** If set to `true`, the keyer's output is active low. */ bool keyer_output_active_low; - /** If set to `true`, the keyer will emit dashes from the left paddle and dots from the right paddle. */ - bool keyer_invert_paddles; - } config_t; /* ----------------------------------------------------- MACROS ----------------------------------------------------- */ diff --git a/src/main/application/debug_port.c b/src/main/application/debug_port.c index d013b58..23aedd6 100644 --- a/src/main/application/debug_port.c +++ b/src/main/application/debug_port.c @@ -534,13 +534,13 @@ static void exec_command_input( char const * const command ) static void exec_command_keyer( char const * const command ) { - static char const * s_mode_tbl[] = + static char const * s_paddle_mode_tbl[] = { - stringize( KEYER_MODE_IAMBIC ), - stringize( KEYER_MODE_ULTIMATIC ), - stringize( KEYER_MODE_ULTIMATIC_ALTERNATE ), + stringize( KEYER_PADDLE_MODE_IAMBIC ), + stringize( KEYER_PADDLE_MODE_ULTIMATIC ), + stringize( KEYER_PADDLE_MODE_ULTIMATIC_ALTERNATE ), }; - _Static_assert( array_count( s_mode_tbl ) == KEYER_MODE_COUNT, "Invalid string table!" ); + _Static_assert( array_count( s_paddle_mode_tbl ) == KEYER_PADDLE_MODE_COUNT, "Invalid string table!" ); // Drop "keyer" prefix char const * c = command + 5; @@ -549,16 +549,6 @@ static void exec_command_keyer( char const * const command ) { // No subcommand - interpret as a status request. no action required } - else if( string_equals( c, " invert_paddles " ENABLE_STR ) ) - { - // Set invert paddles to true - keyer_set_invert_paddles( true ); - } - else if( string_equals( c, " invert_paddles " DISABLE_STR ) ) - { - // Set invert paddles to false - keyer_set_invert_paddles( false ); - } else if( string_equals( c, " output_active_low " ENABLE_STR ) ) { // Set output to active low @@ -569,20 +559,30 @@ static void exec_command_keyer( char const * const command ) // Set output to active high keyer_set_output_active_low( false ); } - else if( string_equals( c, " " stringize( KEYER_MODE_IAMBIC ) ) ) + else if( string_equals( c, " " stringize( KEYER_PADDLE_MODE_IAMBIC ) ) ) { // Set to iambic mode - keyer_set_mode( KEYER_MODE_IAMBIC ); + keyer_set_paddle_mode( KEYER_PADDLE_MODE_IAMBIC ); } - else if( string_equals( c, " " stringize( KEYER_MODE_ULTIMATIC ) ) ) + else if( string_equals( c, " " stringize( KEYER_PADDLE_MODE_ULTIMATIC ) ) ) { // Set to ultimatic mode - keyer_set_mode( KEYER_MODE_ULTIMATIC ); + keyer_set_paddle_mode( KEYER_PADDLE_MODE_ULTIMATIC ); } - else if( string_equals( c, " " stringize( KEYER_MODE_ULTIMATIC_ALTERNATE ) ) ) + else if( string_equals( c, " " stringize( KEYER_PADDLE_MODE_ULTIMATIC_ALTERNATE ) ) ) { // Set to ultimatic alternate mode - keyer_set_mode( KEYER_MODE_ULTIMATIC_ALTERNATE ); + keyer_set_paddle_mode( KEYER_PADDLE_MODE_ULTIMATIC_ALTERNATE ); + } + else if( string_equals( c, " paddle_invert " ENABLE_STR ) ) + { + // Set invert paddles to true + keyer_set_paddle_invert( true ); + } + else if( string_equals( c, " paddle_invert " DISABLE_STR ) ) + { + // Set invert paddles to false + keyer_set_paddle_invert( false ); } else { @@ -592,10 +592,10 @@ static void exec_command_keyer( char const * const command ) } // Print status info - debug_port_printf( "Keyer: %s (active low %s, invert paddles %s)" NEWLINE_STR, - s_mode_tbl[ keyer_get_mode() ], - keyer_get_output_active_low() ? ENABLED_STR : DISABLED_STR, - keyer_get_invert_paddles() ? ENABLED_STR : DISABLED_STR ); + debug_port_printf( "Keyer: %s (%s - %s)" NEWLINE_STR, + keyer_get_on() ? ON_STR : OFF_STR, + s_paddle_mode_tbl[ keyer_get_paddle_mode() ], + keyer_get_paddle_invert() ? "inverted" : "normal" ); } /* exec_command_keyer() */ diff --git a/src/main/application/keyer.c b/src/main/application/keyer.c index 906ecb6..f7b6d76 100644 --- a/src/main/application/keyer.c +++ b/src/main/application/keyer.c @@ -175,25 +175,32 @@ static void update_ticks( void ); /* --------------------------------------------------- PROCEDURES --------------------------------------------------- */ -bool keyer_get_invert_paddles( void ) +bool keyer_get_on( void ) { - return( config()->keyer_invert_paddles ); + return( get_keyed() ); -} /* keyer_get_invert_paddles() */ +} /* keyer_get_on() */ -keyer_mode_t keyer_get_mode( void ) +bool keyer_get_output_active_low( void ) { - return( config()->keyer_mode ); + return( config()->keyer_output_active_low ); -} /* keyer_get_mode() */ +} /* keyer_get_output_active_low() */ -bool keyer_get_output_active_low( void ) +bool keyer_get_paddle_invert( void ) { - return( config()->keyer_output_active_low ); + return( config()->keyer_paddle_invert ); -} /* keyer_get_output_active_low() */ +} /* keyer_get_paddle_invert() */ + + +keyer_paddle_mode_t keyer_get_paddle_mode( void ) +{ + return( config()->keyer_paddle_mode ); + +} /* keyer_get_paddle_mode() */ void keyer_init( void ) @@ -228,34 +235,34 @@ void keyer_panic( void ) } /* keyer_panic() */ -void keyer_set_invert_paddles( bool invert ) +void keyer_set_output_active_low( bool active_low ) { config_t config; config_get( & config ); - config.keyer_invert_paddles = invert; + config.keyer_output_active_low = active_low; config_set( & config ); -} /* keyer_set_invert_paddles() */ +} /* keyer_set_output_active_low() */ -void keyer_set_mode( keyer_mode_t mode ) +void keyer_set_paddle_invert( bool invert ) { config_t config; config_get( & config ); - config.keyer_mode = mode; + config.keyer_paddle_invert = invert; config_set( & config ); -} /* keyer_set_mode() */ +} /* keyer_set_paddle_invert() */ -void keyer_set_output_active_low( bool active_lo ) +void keyer_set_paddle_mode( keyer_paddle_mode_t mode ) { config_t config; config_get( & config ); - config.keyer_output_active_low = active_lo; + config.keyer_paddle_mode = mode; config_set( & config ); -} /* keyer_set_output_active_low() */ +} /* keyer_set_paddle_mode() */ void keyer_tick( tick_t tick ) @@ -411,7 +418,7 @@ static state_t get_next_state( void ) static input_type_field_t inputs = 0; input_type_field_t prev_inputs = inputs; inputs = input_types_get_on(); - bool invert_paddles = keyer_get_invert_paddles(); + bool paddle_invert = keyer_get_paddle_invert(); // Determine next state if( is_bit_set( inputs, INPUT_TYPE_STRAIGHT_KEY ) ) @@ -422,29 +429,29 @@ static state_t get_next_state( void ) else if( is_bit_set( inputs, INPUT_TYPE_PADDLE_LEFT ) && is_bit_set( inputs, INPUT_TYPE_PADDLE_RIGHT ) ) { - switch( keyer_get_mode() ) + switch( keyer_get_paddle_mode() ) { - case KEYER_MODE_IAMBIC: + case KEYER_PADDLE_MODE_IAMBIC: // Always do interleaved in iambic mode return( STATE_INTERLEAVED ); - case KEYER_MODE_ULTIMATIC: + case KEYER_PADDLE_MODE_ULTIMATIC: // The first activated paddle wins return( s_state ); - case KEYER_MODE_ULTIMATIC_ALTERNATE: + case KEYER_PADDLE_MODE_ULTIMATIC_ALTERNATE: // The most recently activated paddle wins if( is_bit_set( inputs, INPUT_TYPE_PADDLE_LEFT ) && is_bit_clear( prev_inputs, INPUT_TYPE_PADDLE_LEFT ) ) { // Left paddle was more recently activated - return( invert_paddles ? STATE_DASHES : STATE_DOTS ); + return( paddle_invert ? STATE_DASHES : STATE_DOTS ); } else if( is_bit_set( inputs, INPUT_TYPE_PADDLE_RIGHT ) && is_bit_clear( prev_inputs, INPUT_TYPE_PADDLE_RIGHT ) ) { // Right paddle was more recently activated - return( invert_paddles ? STATE_DOTS : STATE_DASHES ); + return( paddle_invert ? STATE_DOTS : STATE_DASHES ); } else { @@ -457,14 +464,14 @@ static state_t get_next_state( void ) fail(); } } - else if( ( ! invert_paddles && is_bit_set( inputs, INPUT_TYPE_PADDLE_LEFT ) ) || - ( invert_paddles && is_bit_set( inputs, INPUT_TYPE_PADDLE_RIGHT ) ) ) + else if( ( ! paddle_invert && is_bit_set( inputs, INPUT_TYPE_PADDLE_LEFT ) ) || + ( paddle_invert && is_bit_set( inputs, INPUT_TYPE_PADDLE_RIGHT ) ) ) { // The left paddle traditionally emits dots return( STATE_DOTS ); } - else if( ( ! invert_paddles && is_bit_set( inputs, INPUT_TYPE_PADDLE_RIGHT ) ) || - ( invert_paddles && is_bit_set( inputs, INPUT_TYPE_PADDLE_LEFT ) ) ) + else if( ( ! paddle_invert && is_bit_set( inputs, INPUT_TYPE_PADDLE_RIGHT ) ) || + ( paddle_invert && is_bit_set( inputs, INPUT_TYPE_PADDLE_LEFT ) ) ) { // The right paddle traditionally emits dashes return( STATE_DASHES ); diff --git a/src/main/application/keyer.h b/src/main/application/keyer.h index d326ad7..ee020ff 100644 --- a/src/main/application/keyer.h +++ b/src/main/application/keyer.h @@ -18,50 +18,44 @@ /* ----------------------------------------------------- TYPES ------------------------------------------------------ */ /** - * @typedef keyer_mode_t - * @brief Enumeration of the supported keyer modes. + * @typedef keyer_paddle_mode_t + * @brief Enumeration of the paddle modes that the keyer supports. */ -typedef uint8_t keyer_mode_t; +typedef uint8_t keyer_paddle_mode_t; enum { /** - * In the `KEYER_MODE_IAMBIC` mode, pressing both paddles simultaneously will emit a stream of dashes and dots, - * starting with whichever one was pressed first. + * In the `KEYER_PADDLE_MODE_IAMBIC` mode, pressing both paddles simultaneously will emit a stream of dashes and + * dots, starting with whichever one was pressed first. */ - KEYER_MODE_IAMBIC, + KEYER_PADDLE_MODE_IAMBIC, /** - * In the `KEYER_MODE_ULTIMATIC` mode, pressing both paddles simultaneously will emit a stream of either dots or - * dashes, depending on which paddle was pressed *most recently*. For example, if the left paddle is held down, and - * the right paddle is then held down (while the left is still held down), the keyer will emit dashes. + * In the `KEYER_PADDLE_MODE_ULTIMATIC` mode, pressing both paddles simultaneously will emit a stream of either dots + * or dashes, depending on which paddle was pressed *first*. For example, if the left paddle is held down, and the + * right paddle is then held down (while the left is still held down), the keyer will emit dots. */ - KEYER_MODE_ULTIMATIC, + KEYER_PADDLE_MODE_ULTIMATIC, /** - * In the `KEYER_MODE_ULTIMATIC_ALTERNATE` mode, pressing both paddles simultaneously will emit a stream of either - * dots or dashes, depending on which paddle was pressed *first*. For example, if the left paddle is held down, and - * the right paddle is then held down (while the left is still held down), the keyer will emit dots. + * In the `KEYER_PADDLE_MODE_ULTIMATIC_ALTERNATE` mode, pressing both paddles simultaneously will emit a stream of + * either dots or dashes, depending on which paddle was pressed *most recently*. For example, if the left paddle is + * held down, and the right paddle is then held down (while the left is still held down), the keyer will emit + * dashes. */ - KEYER_MODE_ULTIMATIC_ALTERNATE, + KEYER_PADDLE_MODE_ULTIMATIC_ALTERNATE, - /** Number of valid keyer modes. */ - KEYER_MODE_COUNT, + /** Number of valid keyer paddle modes. */ + KEYER_PADDLE_MODE_COUNT, }; /* ---------------------------------------------- PROCEDURE PROTOTYPES ---------------------------------------------- */ /** - * @fn keyer_get_invert_paddles( void ) - * @brief Returns `true` if the keyer is configured to invert the paddles. In this case, the right paddle will emit - * dots and the left paddle will emit dashes. - */ -bool keyer_get_invert_paddles( void ); - -/** - * @fn keyer_get_mode( void ) - * @brief Returns the currently active keyer mode. + * @fn keyer_get_on( void ) + * @brief Returns `true` if the keyer is currently commanding the radio to transmit. */ -keyer_mode_t keyer_get_mode( void ); +bool keyer_get_on( void ); /** * @fn keyer_get_output_active_low( void ) @@ -69,6 +63,19 @@ keyer_mode_t keyer_get_mode( void ); */ bool keyer_get_output_active_low( void ); +/** + * @fn keyer_get_paddle_invert( void ) + * @brief Returns `true` if the keyer is configured to invert the paddles. In this case, the right paddle will emit + * dots and the left paddle will emit dashes. + */ +bool keyer_get_paddle_invert( void ); + +/** + * @fn keyer_get_paddle_mode( void ) + * @brief Returns the keyer's currently active mode. + */ +keyer_paddle_mode_t keyer_get_paddle_mode( void ); + /** * @fn keyer_init( void ) * @brief Initializes the keyer module. @@ -82,25 +89,26 @@ void keyer_init( void ); void keyer_panic( void ); /** - * @fn keyer_set_invert_paddles( bool ) - * @brief Enables or disables the "invert paddles" setting. + * @fn keyer_set_output_active_low( bool ) + * @brief Sets whether the keyer's output is active low or not. * @note This modifies the application configuration. */ -void keyer_set_invert_paddles( bool invert ); +void keyer_set_output_active_low( bool active_low ); /** - * @fn keyer_set_mode( keyer_mode_t ) - * @brief Sets the currently active keyer mode. + * @fn keyer_set_paddle_invert( bool ) + * @brief Enables or disables the "invert paddles" setting. If set to `true`, the right paddle will emit dots and the + * left paddle will emit dashes. * @note This modifies the application configuration. */ -void keyer_set_mode( keyer_mode_t mode ); +void keyer_set_paddle_invert( bool invert ); /** - * @fn keyer_set_output_active_low( bool ) - * @brief Sets whether the keyer's output is active low or not. + * @fn keyer_set_paddle_mode( keyer_paddle_mode_t ) + * @brief Sets the keyer's currently active paddle mode. * @note This modifies the application configuration. */ -void keyer_set_output_active_low( bool active_lo ); +void keyer_set_paddle_mode( keyer_paddle_mode_t mode ); /** * @fn keyer_tick( tick_t )