Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
12 changes: 6 additions & 6 deletions configuration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}
)
4 changes: 2 additions & 2 deletions src/main/application/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
10 changes: 5 additions & 5 deletions src/main/application/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------------------------- */
Expand Down
50 changes: 25 additions & 25 deletions src/main/application/debug_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
{
Expand All @@ -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() */

Expand Down
65 changes: 36 additions & 29 deletions src/main/application/keyer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 ) )
Expand All @@ -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
{
Expand All @@ -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 );
Expand Down
Loading