Browse Source

more stuff

Thomas Buck 8 months ago
parent
commit
c28f1b2658
8 changed files with 101 additions and 3 deletions
  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 View File

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

+ 3
- 0
include/led.h View File

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

+ 4
- 1
include/sequence.h View File

19
 #ifndef __SEQUENCE_H__
19
 #ifndef __SEQUENCE_H__
20
 #define __SEQUENCE_H__
20
 #define __SEQUENCE_H__
21
 
21
 
22
+#include <stdint.h>
23
+#include "buttons.h"
24
+
22
 void sequence_init(void);
25
 void sequence_init(void);
23
 void sequence_set_bpm(uint32_t new_bpm);
26
 void sequence_set_bpm(uint32_t new_bpm);
24
 void sequence_set_beats(uint32_t new_beats);
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
 void sequence_run(void);
29
 void sequence_run(void);
27
 
30
 
28
 #endif // __SEQUENCE_H__
31
 #endif // __SEQUENCE_H__

+ 25
- 0
include/ui.h View File

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 View File

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

+ 3
- 0
src/main.c View File

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

+ 9
- 1
src/sequence.c View File

44
     beats = (new_beats <= MAX_BEATS) ? new_beats : MAX_BEATS;
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
     if (beat < MAX_BEATS) {
48
     if (beat < MAX_BEATS) {
49
         sequence[beat] = value;
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
 void sequence_run(void) {
61
 void sequence_run(void) {
54
     uint32_t now = to_ms_since_boot(get_absolute_time());
62
     uint32_t now = to_ms_since_boot(get_absolute_time());
55
 
63
 

+ 54
- 0
src/ui.c View File

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…
Cancel
Save