Skip to content

Commit 0910577

Browse files
committed
Split out RF-BM-BG22C3 board config, define a Mini Receiver board
1 parent e52e4fa commit 0910577

6 files changed

Lines changed: 82 additions & 80 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
strategy:
2121
matrix:
22-
board: ["efr32xg22e", "rf-bm-bg22c3"]
22+
board: ["efr32xg22e", "wavephoenix-mini-receiver"]
2323

2424
steps:
2525
# Checkout repository and submodules

firmware/app/src/main.c

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct {
7575

7676
// Joybus state
7777
static struct joybus_gecko joybus_gecko;
78-
static struct joybus_gc_controller joybus_gc_controller;
78+
static struct joybus_gc_controller wavebird_controller;
7979
static struct joybus *joybus = JOYBUS(&joybus_gecko);
8080

8181
// Buttons, switches, and LEDs
@@ -99,25 +99,6 @@ void SysTick_Handler(void)
9999
millis++;
100100
}
101101

102-
// Initialize (or reinitialize) as a controller on the SI bus
103-
static void initialize_controller(uint8_t controller_type)
104-
{
105-
switch (controller_type) {
106-
case WP_CONT_TYPE_GC_WIRED:
107-
joybus_gc_controller_init(&joybus_gc_controller, JOYBUS_GAMECUBE_CONTROLLER);
108-
break;
109-
case WP_CONT_TYPE_GC_WIRED_NOMOTOR:
110-
joybus_gc_controller_init(&joybus_gc_controller, JOYBUS_GAMECUBE_CONTROLLER | JOYBUS_ID_GCN_NO_MOTOR);
111-
break;
112-
default:
113-
printf("Unknown controller type '%d', defaulting to WaveBird", controller_type);
114-
/* fall through */
115-
case WP_CONT_TYPE_GC_WAVEBIRD:
116-
joybus_gc_controller_init(&joybus_gc_controller, JOYBUS_WAVEBIRD_RECEIVER);
117-
break;
118-
}
119-
}
120-
121102
#if HAS_PAIR_BTN
122103
// Begin or end pairing when the pair button is pressed
123104
static void handle_pair_button_press()
@@ -164,13 +145,13 @@ static void handle_wavebird_packet(const uint8_t *packet)
164145
// Check the controller id is as expected
165146
if (settings.cont_type == WP_CONT_TYPE_GC_WAVEBIRD) {
166147
// Implement wireless ID pinning exactly as OEM WaveBird receivers do
167-
if (joybus_gc_controller_wireless_id_fixed(&joybus_gc_controller)) {
148+
if (joybus_gc_controller_wireless_id_fixed(&wavebird_controller)) {
168149
// Drop packets from other controllers if the ID has been fixed
169-
if (joybus_gc_controller_get_wireless_id(&joybus_gc_controller) != wireless_id)
150+
if (joybus_gc_controller_get_wireless_id(&wavebird_controller) != wireless_id)
170151
return;
171152
} else {
172153
// Set the controller ID if it is not fixed
173-
joybus_gc_controller_set_wireless_id(&joybus_gc_controller, wireless_id);
154+
joybus_gc_controller_set_wireless_id(&wavebird_controller, wireless_id);
174155
}
175156
} else {
176157
// Emulate wireless ID pinning for wired controllers
@@ -196,15 +177,15 @@ static void handle_wavebird_packet(const uint8_t *packet)
196177
//
197178

198179
// Copy the buttons from the WaveBird message
199-
joybus_gc_controller.input.buttons &= ~JOYBUS_GCN_BUTTON_MASK;
200-
joybus_gc_controller.input.buttons |=
180+
wavebird_controller.input.buttons &= ~JOYBUS_GCN_BUTTON_MASK;
181+
wavebird_controller.input.buttons |=
201182
((message[3] & 0x80) >> 7) | ((message[2] & 0x0F) << 1) | ((message[3] & 0x7F) << 8);
202183

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

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

218199
// Update the origin state in the Joybus device
219-
joybus_gc_controller_set_origin(&joybus_gc_controller, &new_origin);
200+
joybus_gc_controller_set_origin(&wavebird_controller, &new_origin);
220201
}
221202
}
222203

@@ -260,9 +241,6 @@ static void handle_pairing_finished(uint8_t status, uint8_t channel)
260241
// Set the LED solid for 1 second to indicate pairing success
261242
if (status_led)
262243
led_effect_blink(status_led, 1000, 1);
263-
264-
// Reset the controller
265-
initialize_controller(settings.cont_type);
266244
} else if (status == WB_RADIO_PAIRING_TIMEOUT) {
267245
printf("Pairing timed out\n");
268246

@@ -378,12 +356,25 @@ int main(void)
378356
wavebird_radio_set_channel(settings.chan);
379357
}
380358

359+
// Initialize the WaveBird controller target
360+
switch (settings.cont_type) {
361+
case WP_CONT_TYPE_GC_WIRED:
362+
joybus_gc_controller_init(&wavebird_controller, JOYBUS_GAMECUBE_CONTROLLER);
363+
break;
364+
case WP_CONT_TYPE_GC_WIRED_NOMOTOR:
365+
joybus_gc_controller_init(&wavebird_controller, JOYBUS_GAMECUBE_CONTROLLER | JOYBUS_ID_GCN_NO_MOTOR);
366+
break;
367+
default:
368+
printf("Unknown controller type '%d', defaulting to WaveBird", settings.cont_type);
369+
/* fall through */
370+
case WP_CONT_TYPE_GC_WAVEBIRD:
371+
joybus_gc_controller_init(&wavebird_controller, JOYBUS_WAVEBIRD_RECEIVER);
372+
break;
373+
}
374+
381375
// Initialize Joybus
382376
joybus_gecko_init(&joybus_gecko, JOYBUS_PORT, JOYBUS_PIN, JOYBUS_TIMER, JOYBUS_USART);
383-
joybus_target_register(joybus, JOYBUS_TARGET(&joybus_gc_controller));
384-
385-
// Register to handle controller SI commands
386-
initialize_controller(settings.cont_type);
377+
joybus_target_register(joybus, JOYBUS_TARGET(&wavebird_controller));
387378

388379
// Enable Joybus
389380
joybus_enable(joybus);
@@ -405,7 +396,7 @@ int main(void)
405396
led_effect_update(status_led, millis);
406397

407398
// Invalidate stale inputs
408-
if (joybus_gc_controller.input_valid && (int32_t)(millis - input_valid_until) >= 0)
409-
joybus_gc_controller_input_valid(&joybus_gc_controller, false);
399+
if (wavebird_controller.input_valid && (int32_t)(millis - input_valid_until) >= 0)
400+
joybus_gc_controller_input_valid(&wavebird_controller, false);
410401
}
411402
}

firmware/boards/efr32xg22e.slcc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
id: efr32xg22e
2-
label: efr32xg22e
3-
package: "ext-comp"
2+
package: ext-comp
43
description: WavePhoenix board support for EFR32xG22E
54
category: External
65
quality: production

firmware/boards/rf-bm-bg22c3.slcc

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,16 @@
11
id: rf-bm-bg22c3
2-
label: rf-bm-bg22c3
3-
package: "ext-comp"
4-
description: WavePhoenix board support for RF-BM-BG22C3
2+
package: ext-comp
3+
description: Board support for RF-BM-BG22C3 based boards
54
category: External
65
quality: production
76

87
requires:
98
- name: efr32bg22c224f512gm32
109

11-
define:
12-
# Joybus configuration
13-
- name: JOYBUS_PORT
14-
value: gpioPortA
15-
- name: JOYBUS_PIN
16-
value: 2
17-
- name: JOYBUS_TIMER
18-
value: TIMER1
19-
- name: JOYBUS_USART
20-
value: USART0
21-
22-
# Pair button configuration
23-
- name: HAS_PAIR_BTN
24-
value: 1
25-
- name: PAIR_BTN_PORT
26-
value: gpioPortB
27-
- name: PAIR_BTN_PIN
28-
value: 0
29-
- name: HAS_STATUS_LED
30-
value: 1
10+
provides:
11+
- name: rf-bm-bg22c3
3112

32-
# Status LED configuration
33-
- name: STATUS_LED_PORT
34-
value: gpioPortC
35-
- name: STATUS_LED_PIN
36-
value: 1
37-
- name: STATUS_LED_INVERT
38-
value: 0
13+
define:
14+
# Crystal oscillator tuning
3915
- name: SL_CLOCK_MANAGER_HFXO_CTUNE
4016
value: 72
41-
42-
# Bootloader button configuration
43-
- name: SL_BTL_BUTTON_PORT
44-
value: gpioPortB
45-
- name: SL_BTL_BUTTON_PIN
46-
value: 0
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
id: wavephoenix-mini-receiver
2+
package: ext-comp
3+
description: Board support for the WavePhoenix Mini Receiver
4+
category: External
5+
quality: production
6+
7+
requires:
8+
- name: rf-bm-bg22c3
9+
10+
define:
11+
# Joybus configuration
12+
- name: JOYBUS_PORT
13+
value: gpioPortA
14+
- name: JOYBUS_PIN
15+
value: 2
16+
- name: JOYBUS_TIMER
17+
value: TIMER1
18+
- name: JOYBUS_USART
19+
value: USART0
20+
21+
# Pair button configuration
22+
- name: HAS_PAIR_BTN
23+
value: 1
24+
- name: PAIR_BTN_PORT
25+
value: gpioPortB
26+
- name: PAIR_BTN_PIN
27+
value: 0
28+
29+
# Status LED configuration
30+
- name: HAS_STATUS_LED
31+
value: 1
32+
- name: STATUS_LED_PORT
33+
value: gpioPortC
34+
- name: STATUS_LED_PIN
35+
value: 1
36+
- name: STATUS_LED_INVERT
37+
value: 0
38+
39+
# Bootloader button configuration
40+
- name: SL_BTL_BUTTON_PORT
41+
value: gpioPortB
42+
- name: SL_BTL_BUTTON_PIN
43+
value: 0

firmware/bootloader/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ If you are using a generic SWD debug probe, you can use OpenOCD to flash the boo
4747
3. If this is your first time flashing this chip, you'll need to do a full device erase to unlock the debug interface:
4848

4949
```bash
50-
openocd -f interface/cmsis-dap.cfg \
51-
-c "transport select swd" \
52-
-f target/efm32s2.cfg \
53-
-c "init; halt; efm32 mass_erase 0; exit"
50+
openocd -f "interface/cmsis-dap.cfg" \
51+
-f "target/efm32s2.cfg" \
52+
-c "init; efm32s2_dci_device_erase; shutdown"
5453
```
5554

5655
4. Disconnect then reconnect the debug probe.

0 commit comments

Comments
 (0)