Thomas Buck před 8 měsíci
rodič
revize
c28f1b2658
8 změnil soubory, kde provedl 101 přidání a 3 odebrání
  1. 2
    0
      include/encoder.h
  2. 3
    0
      include/led.h
  3. 4
    1
      include/sequence.h
  4. 25
    0
      include/ui.h
  5. 1
    1
      src/lcd.c
  6. 3
    0
      src/main.c
  7. 9
    1
      src/sequence.c
  8. 54
    0
      src/ui.c

+ 2
- 0
include/encoder.h Zobrazit soubor

@@ -7,6 +7,8 @@
7 7
 #ifndef __ENCODER_H__
8 8
 #define __ENCODER_H__
9 9
 
10
+#include <stdint.h>
11
+
10 12
 void encoder_init(void);
11 13
 int32_t encoder_pos(void);
12 14
 void encoder_run(void);

+ 3
- 0
include/led.h Zobrazit soubor

@@ -19,6 +19,9 @@
19 19
 #ifndef __LED_H__
20 20
 #define __LED_H__
21 21
 
22
+#include <stdint.h>
23
+#include <stdbool.h>
24
+
22 25
 void led_init(void);
23 26
 void led_set(uint32_t i, bool v);
24 27
 

+ 4
- 1
include/sequence.h Zobrazit soubor

@@ -19,10 +19,13 @@
19 19
 #ifndef __SEQUENCE_H__
20 20
 #define __SEQUENCE_H__
21 21
 
22
+#include <stdint.h>
23
+#include "buttons.h"
24
+
22 25
 void sequence_init(void);
23 26
 void sequence_set_bpm(uint32_t new_bpm);
24 27
 void sequence_set_beats(uint32_t new_beats);
25
-void sequence_set(uint32_t beat, bool value);
28
+void sequence_handle_button(enum buttons btn, bool rec);
26 29
 void sequence_run(void);
27 30
 
28 31
 #endif // __SEQUENCE_H__

+ 25
- 0
include/ui.h Zobrazit soubor

@@ -0,0 +1,25 @@
1
+/*
2
+ * ui.h
3
+ *
4
+ * Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * See <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#ifndef __UI_H__
20
+#define __UI_H__
21
+
22
+void ui_init(void);
23
+void ui_run(void);
24
+
25
+#endif // __UI_H__

+ 1
- 1
src/lcd.c Zobrazit soubor

@@ -28,7 +28,7 @@
28 28
 static ssd1306_t disp;
29 29
 
30 30
 void lcd_init(void) {
31
-    i2c_init(i2c1, 400000);
31
+    i2c_init(i2c1, 1000 * 1000);
32 32
     gpio_set_function(0, GPIO_FUNC_I2C);
33 33
     gpio_set_function(1, GPIO_FUNC_I2C);
34 34
     gpio_pull_up(0);

+ 3
- 0
src/main.c Zobrazit soubor

@@ -24,6 +24,7 @@
24 24
 #include "encoder.h"
25 25
 #include "lcd.h"
26 26
 #include "sequence.h"
27
+#include "ui.h"
27 28
 #include "main.h"
28 29
 
29 30
 #define WATCHDOG_PERIOD_MS 100
@@ -34,6 +35,7 @@ int main(void) {
34 35
     buttons_init();
35 36
     lcd_init();
36 37
     sequence_init();
38
+    ui_init();
37 39
     printf("init done\n");
38 40
 
39 41
     while (1) {
@@ -41,6 +43,7 @@ int main(void) {
41 43
         buttons_run();
42 44
         encoder_run();
43 45
         sequence_run();
46
+        ui_run();
44 47
     }
45 48
 
46 49
     return 0;

+ 9
- 1
src/sequence.c Zobrazit soubor

@@ -44,12 +44,20 @@ void sequence_set_beats(uint32_t new_beats) {
44 44
     beats = (new_beats <= MAX_BEATS) ? new_beats : MAX_BEATS;
45 45
 }
46 46
 
47
-void sequence_set(uint32_t beat, bool value) {
47
+static void sequence_set(uint32_t beat, bool value) {
48 48
     if (beat < MAX_BEATS) {
49 49
         sequence[beat] = value;
50 50
     }
51 51
 }
52 52
 
53
+void sequence_handle_button(enum buttons btn, bool rec) {
54
+    // TODO trigger gpio impulse
55
+
56
+    if (rec) {
57
+
58
+    }
59
+}
60
+
53 61
 void sequence_run(void) {
54 62
     uint32_t now = to_ms_since_boot(get_absolute_time());
55 63
 

+ 54
- 0
src/ui.c Zobrazit soubor

@@ -0,0 +1,54 @@
1
+/*
2
+ * ui.c
3
+ *
4
+ * Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * See <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+#include "pico/stdlib.h"
20
+
21
+#include "buttons.h"
22
+#include "ui.h"
23
+
24
+static bool rec_held_down = false;
25
+
26
+static void ui_buttons(enum buttons btn, bool val) {
27
+    switch (btn) {
28
+        case BTN_A:
29
+        case BTN_B:
30
+        case BTN_C:
31
+            if (val) {
32
+                sequence_handle_button(btn, rec_held_down);
33
+            }
34
+            break;
35
+
36
+        case BTN_REC:
37
+            rec_held_down = val;
38
+            break;
39
+
40
+        case BTN_CLICK:
41
+            break;
42
+
43
+        default:
44
+            break;
45
+    }
46
+}
47
+
48
+void ui_init(void) {
49
+    buttons_callback(ui_buttons);
50
+}
51
+
52
+void ui_run(void) {
53
+
54
+}

Loading…
Zrušit
Uložit