aboutsummaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--board/board.c8
-rw-r--r--board/board.h14
-rw-r--r--board/mxblue/board.c14
-rw-r--r--board/quack/board.c14
-rw-r--r--board/simple_board.h33
5 files changed, 48 insertions, 35 deletions
diff --git a/board/board.c b/board/board.c
deleted file mode 100644
index 0410aef..0000000
--- a/board/board.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#include "board.h"
-
-static fn_sound_play sound_play;
-
-void board_init(fn_sound_play sp)
-{
- sound_play = sp;
-} \ No newline at end of file
diff --git a/board/board.h b/board/board.h
index 18f6afa..c7dfc1f 100644
--- a/board/board.h
+++ b/board/board.h
@@ -1,12 +1,16 @@
#ifndef CLAK_BOARD_H_
#define CLAK_BOARD_H_
-#include <stdbool.h>
+struct board {
+ void (*on_down)(void);
+ void (*on_up)(void);
+ char *name;
+};
-#include "../clak.h"
+struct board_data {
+ void (*sound_play)(unsigned char *buffer);
+};
-typedef void (*fn_board_init)(fn_sound_play sp);
-typedef void (*fn_board_on_down)(void);
-typedef void (*fn_board_on_up)(void);
+typedef struct board *(*fn_board_init)(struct board_data data);
#endif /* CLAK_BOARD_H_ */ \ No newline at end of file
diff --git a/board/mxblue/board.c b/board/mxblue/board.c
index 14277db..fb0456d 100644
--- a/board/mxblue/board.c
+++ b/board/mxblue/board.c
@@ -1,12 +1,4 @@
#include "sound.h"
-
-#include "../board.c"
-
-void board_on_down(void)
-{
- sound_play(mxblue_board_down_wav);
-}
-
-void board_on_up(void)
-{
-} \ No newline at end of file
+#define BOARD_NAME "Cherry MX Blue"
+#define BOARD_DOWN_WAV mxblue_board_down_wav
+#include "../simple_board.h" \ No newline at end of file
diff --git a/board/quack/board.c b/board/quack/board.c
index 893e366..9a58e2f 100644
--- a/board/quack/board.c
+++ b/board/quack/board.c
@@ -1,12 +1,4 @@
#include "sound.h"
-
-#include "../board.c"
-
-void board_on_down(void)
-{
- sound_play(quack_board_down_wav);
-}
-
-void board_on_up(void)
-{
-} \ No newline at end of file
+#define BOARD_NAME "Quack Quack"
+#define BOARD_DOWN_WAV quack_board_down_wav
+#include "../simple_board.h" \ No newline at end of file
diff --git a/board/simple_board.h b/board/simple_board.h
new file mode 100644
index 0000000..9d9836b
--- /dev/null
+++ b/board/simple_board.h
@@ -0,0 +1,33 @@
+#include "board.h"
+
+static struct board_data board_data;
+
+void board_on_down(void)
+{
+#ifdef BOARD_DOWN_WAV
+ board_data.sound_play(BOARD_DOWN_WAV);
+#endif
+}
+
+void board_on_up(void)
+{
+#ifdef BOARD_UP_WAV
+ board_data.sound_play(BOARD_UP_WAV);
+#endif
+}
+
+static struct board board = {
+ .on_down = &board_on_down,
+ .on_up = &board_on_up,
+#ifdef BOARD_NAME
+ .name = BOARD_NAME,
+#else
+ .name = "Generic Board",
+#endif
+};
+
+struct board *board_init(struct board_data data)
+{
+ board_data = data;
+ return &board;
+} \ No newline at end of file