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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

strategy:
matrix:
board: ["efr32xg22e", "rf-bm-bg22c3"]
board: ["efr32xg22e", "wavephoenix-mini-receiver"]

steps:
# Checkout repository and submodules
Expand Down
65 changes: 28 additions & 37 deletions firmware/app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct {

// Joybus state
static struct joybus_gecko joybus_gecko;
static struct joybus_gc_controller joybus_gc_controller;
static struct joybus_gc_controller wavebird_controller;
static struct joybus *joybus = JOYBUS(&joybus_gecko);

// Buttons, switches, and LEDs
Expand All @@ -99,25 +99,6 @@ void SysTick_Handler(void)
millis++;
}

// Initialize (or reinitialize) as a controller on the SI bus
static void initialize_controller(uint8_t controller_type)
{
switch (controller_type) {
case WP_CONT_TYPE_GC_WIRED:
joybus_gc_controller_init(&joybus_gc_controller, JOYBUS_GAMECUBE_CONTROLLER);
break;
case WP_CONT_TYPE_GC_WIRED_NOMOTOR:
joybus_gc_controller_init(&joybus_gc_controller, JOYBUS_GAMECUBE_CONTROLLER | JOYBUS_ID_GCN_NO_MOTOR);
break;
default:
printf("Unknown controller type '%d', defaulting to WaveBird", controller_type);
/* fall through */
case WP_CONT_TYPE_GC_WAVEBIRD:
joybus_gc_controller_init(&joybus_gc_controller, JOYBUS_WAVEBIRD_RECEIVER);
break;
}
}

#if HAS_PAIR_BTN
// Begin or end pairing when the pair button is pressed
static void handle_pair_button_press()
Expand Down Expand Up @@ -164,13 +145,13 @@ static void handle_wavebird_packet(const uint8_t *packet)
// Check the controller id is as expected
if (settings.cont_type == WP_CONT_TYPE_GC_WAVEBIRD) {
// Implement wireless ID pinning exactly as OEM WaveBird receivers do
if (joybus_gc_controller_wireless_id_fixed(&joybus_gc_controller)) {
if (joybus_gc_controller_wireless_id_fixed(&wavebird_controller)) {
// Drop packets from other controllers if the ID has been fixed
if (joybus_gc_controller_get_wireless_id(&joybus_gc_controller) != wireless_id)
if (joybus_gc_controller_get_wireless_id(&wavebird_controller) != wireless_id)
return;
} else {
// Set the controller ID if it is not fixed
joybus_gc_controller_set_wireless_id(&joybus_gc_controller, wireless_id);
joybus_gc_controller_set_wireless_id(&wavebird_controller, wireless_id);
}
} else {
// Emulate wireless ID pinning for wired controllers
Expand All @@ -196,15 +177,15 @@ static void handle_wavebird_packet(const uint8_t *packet)
//

// Copy the buttons from the WaveBird message
joybus_gc_controller.input.buttons &= ~JOYBUS_GCN_BUTTON_MASK;
joybus_gc_controller.input.buttons |=
wavebird_controller.input.buttons &= ~JOYBUS_GCN_BUTTON_MASK;
wavebird_controller.input.buttons |=
((message[3] & 0x80) >> 7) | ((message[2] & 0x0F) << 1) | ((message[3] & 0x7F) << 8);

// Copy the stick, substick, and trigger values
memcpy(&joybus_gc_controller.input.stick_x, &message[4], 6);
memcpy(&wavebird_controller.input.stick_x, &message[4], 6);

// Set the input state as valid, and (re)set the validity timer
joybus_gc_controller_input_valid(&joybus_gc_controller, true);
joybus_gc_controller_input_valid(&wavebird_controller, true);
input_valid_until = millis + INPUT_VALID_MS;
} else {
//
Expand All @@ -216,7 +197,7 @@ static void handle_wavebird_packet(const uint8_t *packet)
wavebird_origin_copy((uint8_t *)&new_origin.stick_x, message);

// Update the origin state in the Joybus device
joybus_gc_controller_set_origin(&joybus_gc_controller, &new_origin);
joybus_gc_controller_set_origin(&wavebird_controller, &new_origin);
}
}

Expand Down Expand Up @@ -260,9 +241,6 @@ static void handle_pairing_finished(uint8_t status, uint8_t channel)
// Set the LED solid for 1 second to indicate pairing success
if (status_led)
led_effect_blink(status_led, 1000, 1);

// Reset the controller
initialize_controller(settings.cont_type);
} else if (status == WB_RADIO_PAIRING_TIMEOUT) {
printf("Pairing timed out\n");

Expand Down Expand Up @@ -378,12 +356,25 @@ int main(void)
wavebird_radio_set_channel(settings.chan);
}

// Initialize the WaveBird controller target
switch (settings.cont_type) {
case WP_CONT_TYPE_GC_WIRED:
joybus_gc_controller_init(&wavebird_controller, JOYBUS_GAMECUBE_CONTROLLER);
break;
case WP_CONT_TYPE_GC_WIRED_NOMOTOR:
joybus_gc_controller_init(&wavebird_controller, JOYBUS_GAMECUBE_CONTROLLER | JOYBUS_ID_GCN_NO_MOTOR);
break;
default:
printf("Unknown controller type '%d', defaulting to WaveBird", settings.cont_type);
/* fall through */
case WP_CONT_TYPE_GC_WAVEBIRD:
joybus_gc_controller_init(&wavebird_controller, JOYBUS_WAVEBIRD_RECEIVER);
break;
}

// Initialize Joybus
joybus_gecko_init(&joybus_gecko, JOYBUS_PORT, JOYBUS_PIN, JOYBUS_TIMER, JOYBUS_USART);
joybus_target_register(joybus, JOYBUS_TARGET(&joybus_gc_controller));

// Register to handle controller SI commands
initialize_controller(settings.cont_type);
joybus_target_register(joybus, JOYBUS_TARGET(&wavebird_controller));

// Enable Joybus
joybus_enable(joybus);
Expand All @@ -405,7 +396,7 @@ int main(void)
led_effect_update(status_led, millis);

// Invalidate stale inputs
if (joybus_gc_controller.input_valid && (int32_t)(millis - input_valid_until) >= 0)
joybus_gc_controller_input_valid(&joybus_gc_controller, false);
if (wavebird_controller.input_valid && (int32_t)(millis - input_valid_until) >= 0)
joybus_gc_controller_input_valid(&wavebird_controller, false);
}
}
3 changes: 1 addition & 2 deletions firmware/boards/efr32xg22e.slcc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
id: efr32xg22e
label: efr32xg22e
package: "ext-comp"
package: ext-comp
description: WavePhoenix board support for EFR32xG22E
category: External
quality: production
Expand Down
42 changes: 6 additions & 36 deletions firmware/boards/rf-bm-bg22c3.slcc
Original file line number Diff line number Diff line change
@@ -1,46 +1,16 @@
id: rf-bm-bg22c3
label: rf-bm-bg22c3
package: "ext-comp"
description: WavePhoenix board support for RF-BM-BG22C3
package: ext-comp
description: Board support for RF-BM-BG22C3 based boards
category: External
quality: production

requires:
- name: efr32bg22c224f512gm32

define:
# Joybus configuration
- name: JOYBUS_PORT
value: gpioPortA
- name: JOYBUS_PIN
value: 2
- name: JOYBUS_TIMER
value: TIMER1
- name: JOYBUS_USART
value: USART0

# Pair button configuration
- name: HAS_PAIR_BTN
value: 1
- name: PAIR_BTN_PORT
value: gpioPortB
- name: PAIR_BTN_PIN
value: 0
- name: HAS_STATUS_LED
value: 1
provides:
- name: rf-bm-bg22c3

# Status LED configuration
- name: STATUS_LED_PORT
value: gpioPortC
- name: STATUS_LED_PIN
value: 1
- name: STATUS_LED_INVERT
value: 0
define:
# Crystal oscillator tuning
- name: SL_CLOCK_MANAGER_HFXO_CTUNE
value: 72

# Bootloader button configuration
- name: SL_BTL_BUTTON_PORT
value: gpioPortB
- name: SL_BTL_BUTTON_PIN
value: 0
43 changes: 43 additions & 0 deletions firmware/boards/wavephoenix-mini-receiver.slcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
id: wavephoenix-mini-receiver
package: ext-comp
description: Board support for the WavePhoenix Mini Receiver
category: External
quality: production

requires:
- name: rf-bm-bg22c3

define:
# Joybus configuration
- name: JOYBUS_PORT
value: gpioPortA
- name: JOYBUS_PIN
value: 2
- name: JOYBUS_TIMER
value: TIMER1
- name: JOYBUS_USART
value: USART0

# Pair button configuration
- name: HAS_PAIR_BTN
value: 1
- name: PAIR_BTN_PORT
value: gpioPortB
- name: PAIR_BTN_PIN
value: 0

# Status LED configuration
- name: HAS_STATUS_LED
value: 1
- name: STATUS_LED_PORT
value: gpioPortC
- name: STATUS_LED_PIN
value: 1
- name: STATUS_LED_INVERT
value: 0

# Bootloader button configuration
- name: SL_BTL_BUTTON_PORT
value: gpioPortB
- name: SL_BTL_BUTTON_PIN
value: 0
7 changes: 3 additions & 4 deletions firmware/bootloader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ If you are using a generic SWD debug probe, you can use OpenOCD to flash the boo
3. If this is your first time flashing this chip, you'll need to do a full device erase to unlock the debug interface:

```bash
openocd -f interface/cmsis-dap.cfg \
-c "transport select swd" \
-f target/efm32s2.cfg \
-c "init; halt; efm32 mass_erase 0; exit"
openocd -f "interface/cmsis-dap.cfg" \
-f "target/efm32s2.cfg" \
-c "init; efm32s2_dci_device_erase; shutdown"
```

4. Disconnect then reconnect the debug probe.
Expand Down