aboutsummaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--board/board.h22
-rw-r--r--board/simple_board.h28
2 files changed, 26 insertions, 24 deletions
diff --git a/board/board.h b/board/board.h
index 36d39fb..0c95b9c 100644
--- a/board/board.h
+++ b/board/board.h
@@ -1,16 +1,22 @@
#ifndef CLAK_BOARD_H_
#define CLAK_BOARD_H_
-struct board {
- void (*on_down)(void);
- void (*on_up)(void);
+struct board_state;
+
+typedef void (*board_init_fn_t)(struct board_state *board_state);
+typedef void (*key_event_fn_t)(struct board_state *board_state);
+
+typedef void (*sound_play_fn_t)(unsigned char *buffer, unsigned int buffer_len);
+
+struct board_state {
+ /* Populated by plugin */
+ key_event_fn_t on_down;
+ key_event_fn_t on_up;
char *name;
-};
-struct board_data {
- void (*sound_play)(unsigned char *buffer, unsigned int buffer_len);
+ /* Runtime from main */
+ board_init_fn_t board_init;
+ sound_play_fn_t sound_play;
};
-typedef struct board *(*fn_board_init)(struct board_data data);
-
#endif /* CLAK_BOARD_H_ */
diff --git a/board/simple_board.h b/board/simple_board.h
index f0997c7..1a264de 100644
--- a/board/simple_board.h
+++ b/board/simple_board.h
@@ -1,36 +1,32 @@
#include "board.h"
-static struct board_data board_data;
-
#define WAV_LEN(W) PREPROC_CONCAT(W,_len)
#define PREPROC_CONCAT(A, B) A ## B
-void board_on_down(void)
+void board_on_down(struct board_state *state)
{
+ (void) state;
#ifdef BOARD_DOWN_WAV
- board_data.sound_play(BOARD_DOWN_WAV, WAV_LEN(BOARD_DOWN_WAV));
+ state->sound_play(BOARD_DOWN_WAV, WAV_LEN(BOARD_DOWN_WAV));
#endif
}
-void board_on_up(void)
+void board_on_up(struct board_state *state)
{
+ (void) state;
#ifdef BOARD_UP_WAV
- board_data.sound_play(BOARD_UP_WAV, WAV_LEN(BOARD_UP_WAV));
+ state->sound_play(BOARD_UP_WAV, WAV_LEN(BOARD_UP_WAV));
#endif
}
-static struct board board = {
- .on_down = &board_on_down,
- .on_up = &board_on_up,
+void board_init(struct board_state *state)
+{
#ifdef BOARD_NAME
- .name = BOARD_NAME,
+ state->name = BOARD_NAME;
#else
- .name = "Generic Board",
+ state->name = "Generic Board";
#endif
-};
-struct board *board_init(struct board_data data)
-{
- board_data = data;
- return &board;
+ state->on_down = &board_on_down;
+ state->on_up = &board_on_up;
}