Skip to content

Commit a06ff2d

Browse files
committed
Use silabs template style app.c
1 parent ac1e030 commit a06ff2d

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#include "em_cmu.h"
22
#include "em_gpio.h"
33

4-
#include "sl_main_init.h"
54
#include "sl_sleeptimer.h"
6-
#include "sl_udelay.h"
75

86
#include <joybus/joybus.h>
97
#include <joybus/backend/gecko.h>
@@ -29,6 +27,9 @@ static uint8_t joybus_response[JOYBUS_BLOCK_SIZE] = {0};
2927
enum { POLL_MODE_IDENTIFY, POLL_MODE_READ };
3028
static uint8_t poll_mode = POLL_MODE_IDENTIFY;
3129

30+
// Sleeptimer handle for polling
31+
static sl_sleeptimer_timer_handle_t poll_timer;
32+
3233
void joybus_identify_cb(struct joybus *bus, int result, void *user_data)
3334
{
3435
// Stay in identify mode on any Joybus error
@@ -85,11 +86,8 @@ static void poll_task(sl_sleeptimer_timer_handle_t *handle, void *data)
8586
}
8687
}
8788

88-
int main()
89+
void app_init(void)
8990
{
90-
// Initialize chip
91-
sl_main_init();
92-
9391
// Set up GPIO for status LED
9492
CMU_ClockEnable(cmuClock_GPIO, true);
9593
GPIO_PinModeSet(LED_PORT, LED_PIN, gpioModePushPull, 0);
@@ -99,14 +97,12 @@ int main()
9997
joybus_enable(bus);
10098

10199
// Poll for Joybus data at regular intervals
102-
sl_sleeptimer_timer_handle_t poll_timer;
103100
sl_sleeptimer_init();
104101
sl_sleeptimer_start_periodic_timer(&poll_timer, sl_sleeptimer_ms_to_tick(JOYBUS_POLL_INTERVAL_MS), poll_task, bus, 0,
105102
SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG);
103+
}
106104

107-
// No work to do in main loop
108-
while (true)
109-
;
110-
111-
return 0;
105+
void app_process_action(void)
106+
{
107+
// Nothing to do here, everything is handled in the timer callback
112108
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ description: GameCube Controller Host Example for Gecko SDK
33
quality: production
44

55
component:
6-
- id: sl_main
7-
- id: sl_main_custom_main
6+
- id: clock_manager
87
- id: device_init
8+
- id: sl_main
99
- id: emlib
1010
- id: sleeptimer
11-
- id: udelay
1211
- id: libjoybus
1312
from: libjoybus
1413

1514
source:
16-
- path: main.c
15+
- path: app.c
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "em_cmu.h"
22
#include "em_gpio.h"
33

4-
#include "sl_main_init.h"
54
#include "sl_udelay.h"
65

76
#include <joybus/joybus.h>
@@ -22,11 +21,8 @@ struct joybus *bus = JOYBUS(&gecko_bus);
2221
// GameCube controller target instance
2322
static struct joybus_gc_controller gc_controller;
2423

25-
int main()
24+
void app_init(void)
2625
{
27-
// Initialize chip
28-
sl_main_init();
29-
3026
// Initialize GPIO for button
3127
CMU_ClockEnable(cmuClock_GPIO, true);
3228
GPIO_PinModeSet(BTN_PORT, BTN_PIN, gpioModeInput, 1);
@@ -40,16 +36,17 @@ int main()
4036

4137
// Register the target on the bus
4238
joybus_target_register(bus, JOYBUS_TARGET(&gc_controller));
39+
}
4340

44-
while (1) {
45-
// Clear previous button state
46-
gc_controller.input.buttons &= ~JOYBUS_GCN_BUTTON_MASK;
41+
void app_process_action(void)
42+
{
43+
// Clear previous button state
44+
gc_controller.input.buttons &= ~JOYBUS_GCN_BUTTON_MASK;
4745

48-
// Simulate pressing the A button when the BUTTON_GPIO (active low) is pressed
49-
if (GPIO_PinInGet(BTN_PORT, BTN_PIN) == 0)
50-
gc_controller.input.buttons |= JOYBUS_GCN_BUTTON_A;
46+
// Simulate pressing the A button when the BUTTON_GPIO (active low) is pressed
47+
if (GPIO_PinInGet(BTN_PORT, BTN_PIN) == 0)
48+
gc_controller.input.buttons |= JOYBUS_GCN_BUTTON_A;
5149

52-
// Chill for a bit
53-
sl_udelay_wait(10000);
54-
}
50+
// Chill for a bit
51+
sl_udelay_wait(10000);
5552
}

examples/gecko/gcn-target/app.slcp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
project_name: gcn_target
2+
description: GameCube Controller Target Example for Gecko SDK
3+
quality: production
4+
5+
component:
6+
- id: clock_manager
7+
- id: device_init
8+
- id: sl_main
9+
- id: emlib
10+
- id: udelay
11+
- id: libjoybus
12+
from: libjoybus
13+
14+
source:
15+
- path: app.c
16+
17+
configuration:
18+
- name: SL_CLOCK_MANAGER_HFRCO_DPLL_EN
19+
value: 1
20+
- name: SL_CLOCK_MANAGER_DEFAULT_HF_CLOCK_SOURCE
21+
value: SL_CLOCK_MANAGER_DEFAULT_HF_CLOCK_SOURCE_HFRCODPLL
22+
- name: SL_CLOCK_MANAGER_EM01GRPACLK_SOURCE
23+
value: CMU_EM01GRPACLKCTRL_CLKSEL_HFXO

examples/gecko/gcn-target/gcn_target.slcp

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)