Skip to content

Commit ec4d98f

Browse files
committed
Fix auto tx->rx transition
1 parent 5355bfd commit ec4d98f

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

firmware/libsi/src/device/commands.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,18 @@ void si_command_process()
127127

128128
void si_command_processing_enable()
129129
{
130+
if (auto_tx_rx_transition)
131+
return;
132+
130133
auto_tx_rx_transition = true;
131134
si_command_process();
132135
}
133136

134137
void si_command_processing_disable()
135138
{
139+
if (!auto_tx_rx_transition)
140+
return;
141+
136142
auto_tx_rx_transition = false;
137143
bus_state = BUS_STATE_UNKNOWN;
138144
}

firmware/receiver/src/main.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ struct {
7878

7979
// SI state
8080
static struct si_device_gc_controller si_device = {0};
81-
static bool enable_si_command_handling = true;
8281

8382
// Buttons, switches, and LEDs
8483
static struct led *status_led = NULL;
@@ -107,7 +106,7 @@ static void initialize_controller(uint8_t controller_type)
107106
if (controller_type == WP_CONT_TYPE_GC_WAVEBIRD) {
108107
// Present as an OEM WaveBird receiver
109108
si_device_gc_init(&si_device, SI_TYPE_GC | SI_GC_WIRELESS | SI_GC_NOMOTOR);
110-
enable_si_command_handling = true;
109+
si_command_processing_enable();
111110
} else if (controller_type == WP_CONT_TYPE_GC_WIRED_NOMOTOR) {
112111
// Present as a wired GameCube controller without rumble
113112
si_device_gc_init(&si_device, SI_TYPE_GC | SI_GC_STANDARD | SI_GC_NOMOTOR);
@@ -208,7 +207,7 @@ static void handle_wavebird_packet(const uint8_t *packet)
208207
memcpy(&si_device.input.stick_x, &message[4], 6);
209208

210209
// We have a good input state, enable SI command handling if it was disabled
211-
enable_si_command_handling = true;
210+
si_command_processing_enable();
212211

213212
// Set the input state as valid
214213
input_valid_until = millis + INPUT_VALID_MS;
@@ -246,7 +245,7 @@ static void handle_pairing_started(void)
246245
pairing_active = true;
247246

248247
// Disable SI command handling during pairing
249-
enable_si_command_handling = false;
248+
si_command_processing_disable();
250249

251250
// Set the LED effect to indicate pairing mode
252251
if (status_led)
@@ -281,7 +280,7 @@ static void handle_pairing_finished(uint8_t status, uint8_t channel)
281280
led_effect_blink(status_led, 500, 3);
282281

283282
// Immediately reenable SI command handling
284-
enable_si_command_handling = true;
283+
si_command_processing_enable();
285284
} else {
286285
DEBUG_PRINT("Pairing cancelled\n");
287286

@@ -290,7 +289,7 @@ static void handle_pairing_finished(uint8_t status, uint8_t channel)
290289
led_off(status_led);
291290

292291
// Immediately reenable SI command handling
293-
enable_si_command_handling = true;
292+
si_command_processing_enable();
294293
}
295294
}
296295

@@ -421,15 +420,8 @@ int main(void)
421420
: "Wired (no motor)");
422421
DEBUG_PRINT("\n");
423422

424-
// Wait for the SI bus to be idle before starting the main loop
425-
si_await_bus_idle();
426-
427423
// Main loop
428424
while (1) {
429-
// Check if we need to initiate the next SI transfer
430-
if (enable_si_command_handling)
431-
si_command_process();
432-
433425
// Check for new wavebird packets
434426
wavebird_radio_process();
435427

0 commit comments

Comments
 (0)