]> git.ayabusa.dev Git - numworks-zeta-os.git/commitdiff
added timer support, and incomplete keyboard system
authorayabusa <lebgpub@gmail.com>
Mon, 1 Apr 2024 16:32:34 +0000 (18:32 +0200)
committerayabusa <lebgpub@gmail.com>
Mon, 1 Apr 2024 16:32:34 +0000 (18:32 +0200)
18 files changed:
.vscode/settings.json
numworks_port/build/Laplace/gpio_helper.o
numworks_port/build/Laplace/keyboard.o [new file with mode: 0644]
numworks_port/build/Laplace/laplace.o
numworks_port/build/Laplace/time.o [new file with mode: 0644]
numworks_port/build/main.bin
numworks_port/build/main.elf
numworks_port/build/main.o
numworks_port/src/Laplace/gpio_helper.c
numworks_port/src/Laplace/gpio_helper.h
numworks_port/src/Laplace/keyboard.c [new file with mode: 0644]
numworks_port/src/Laplace/keyboard.h [new file with mode: 0644]
numworks_port/src/Laplace/laplace.c
numworks_port/src/Laplace/laplace.h
numworks_port/src/Laplace/time.c [new file with mode: 0644]
numworks_port/src/Laplace/time.h [new file with mode: 0644]
numworks_port/src/main.c
numworks_port/src/main.h

index 13b0224ab83c555f3ae6d7dad58657e7209a6217..02bb9b31f428ba696cab40e6973e7c4155c33722 100644 (file)
@@ -19,6 +19,8 @@
         "tuple": "cpp",
         "main.h": "c",
         "led.h": "c",
-        "stm32f730xx.h": "c"
+        "stm32f730xx.h": "c",
+        "keyboard.h": "c",
+        "gpio_helper.h": "c"
     }
 }
\ No newline at end of file
index 5e119b80713dd96cfdcdbae532c878b319c2cb70..3a0b9593130df5230eac96cd64a07e52e0efe777 100644 (file)
Binary files a/numworks_port/build/Laplace/gpio_helper.o and b/numworks_port/build/Laplace/gpio_helper.o differ
diff --git a/numworks_port/build/Laplace/keyboard.o b/numworks_port/build/Laplace/keyboard.o
new file mode 100644 (file)
index 0000000..0e37f31
Binary files /dev/null and b/numworks_port/build/Laplace/keyboard.o differ
index dd5dd2383737841e7a8dcb34e9c9d709b89e3ce7..2cb6cb80ea24d2d9372472c3addf3fe62dce1fc4 100644 (file)
Binary files a/numworks_port/build/Laplace/laplace.o and b/numworks_port/build/Laplace/laplace.o differ
diff --git a/numworks_port/build/Laplace/time.o b/numworks_port/build/Laplace/time.o
new file mode 100644 (file)
index 0000000..46216b8
Binary files /dev/null and b/numworks_port/build/Laplace/time.o differ
index ba87df02f0d362b509db57513a46a24dc23cb77b..4e1ba36cf309dd293c984a5fcad0b834f54e4412 100755 (executable)
Binary files a/numworks_port/build/main.bin and b/numworks_port/build/main.bin differ
index ab1e7ff099a5ddac234975b6ae1984b796d256f6..a8a93d7db0dceede698ee0264ca3ebcbd2055148 100755 (executable)
Binary files a/numworks_port/build/main.elf and b/numworks_port/build/main.elf differ
index 9b45cec0981edc7353dec2e37b1ed21c131d7a21..41168c9f98f9c17033e0a1ae4990c98ccb986bb6 100644 (file)
Binary files a/numworks_port/build/main.o and b/numworks_port/build/main.o differ
index 72117921f2ec71a3fbc90b2b3ce1faca3b7b49e0..d5ba4c2bf16be747daf320d5b67fde54109a0c86 100644 (file)
@@ -59,6 +59,34 @@ void set_output_pin(uint8_t gpio_x, uint8_t pin, bool state){
     }
 }
 
+bool read_input_pin(uint8_t gpio_x, uint8_t pin){
+    // Invert the IDR register since '0' means 'pressed'.
+    uint8_t idr_val = 0;
+    switch (gpio_x)
+    {
+    case GPIO_A:
+        idr_val = ~GPIOA->IDR;
+        break;
+    case GPIO_B:
+        idr_val = ~GPIOB->IDR;
+        break;
+    case GPIO_C:
+        idr_val = ~GPIOC->IDR;
+        break;
+    case GPIO_D:
+        idr_val = ~GPIOD->IDR;
+        break;
+    case GPIO_E:
+        idr_val = ~GPIOE->IDR;
+        break;
+    
+    default:
+        break;
+    }
+
+    return idr_val & (1 << pin);
+}
+
 void enable_gpio_x_rcc(uint8_t gpio_x){
     switch (gpio_x)
     {
index 4f73d94b4d0cbc5184fd2bff14a6c8d7385206f5..a09f88fc8884a3f688ed994e8063901ade9a0a7f 100644 (file)
@@ -17,6 +17,7 @@
 #define GPIO_E 4
 
 void set_output_pin(uint8_t gpio_x, uint8_t pin, bool state);
+bool read_input_pin(uint8_t gpio_x, uint8_t pin);
 void enable_gpio_x_rcc(uint8_t gpio_x);
 
 #endif
\ No newline at end of file
diff --git a/numworks_port/src/Laplace/keyboard.c b/numworks_port/src/Laplace/keyboard.c
new file mode 100644 (file)
index 0000000..46f2e13
--- /dev/null
@@ -0,0 +1,74 @@
+/* The keyboard is a matrix that is laid out as follow:
+ * (K_B2 and K_B3 are respectively specific to N0100 and N0110
+ *
+ *      |  PC0 |  PC1 | PC2  | PC3  | PC4  | PC5  |
+ * -----+------+------+------+------+------+------+
+ *  PE0 | K_A1 | K_A2 | K_A3 | K_A4 | K_A5 | K_A6 |
+ * -----+------+------+------+------+------+------+
+ *  PE1 | K_B1 |(K_B2)|(K_B3)|      |      |      |
+ * -----+------+------+------+------+------+------+
+ *  PE2 | K_C1 | K_C2 | K_C3 | K_C4 | K_C5 | K_C6 |
+ * -----+------+------+------+------+------+------+
+ *  PE3 | K_D1 | K_D2 | K_D3 | K_D4 | K_D5 | K_D6 |
+ * -----+------+------+------+------+------+------+
+ *  PE4 | K_E1 | K_E2 | K_E3 | K_E4 | K_E5 | K_E6 |
+ * -----+------+------+------+------+------+------+
+ *  PE5 | K_F1 | K_F2 | K_F3 | K_F4 | K_F5 |      |
+ * -----+------+------+------+------+------+------+
+ *  PE6 | K_G1 | K_G2 | K_G3 | K_G4 | K_G5 |      |
+ * -----+------+------+------+------+------+------+
+ *  PE7 | K_H1 | K_H2 | K_H3 | K_H4 | K_H5 |      |
+ * -----+------+------+------+------+------+------+
+ *  PE8 | K_I1 | K_I2 | K_I3 | K_I4 | K_I5 |      |
+ * -----+------+------+------+------+------+------|
+ *
+ *  We decide to drive the rows (PE0-8) and read the columns (PC0-5).
+ *
+ *  To avoid short-circuits, the pins E0-E8 will not be standard outputs but
+ *  only open-drain. Open drain means the pin is either driven low or left
+ *  floating.
+ *  When a user presses multiple keys, a connection between two rows can happen.
+ *  If we don't use open drain outputs, this situation could trigger a short
+ *  circuit between an output driving high and another driving low.
+ *
+ *  If the outputs are open-drain, this means that the input must be pulled up.
+ *  So if the input reads "1", this means the key is in fact *not* pressed, and
+ *  if it reads "0" it means that there's a short to an open-drain output. Which
+ *  means the corresponding key is pressed.
+ */
+
+#include "keyboard.h"
+
+const uint8_t number_of_rows = 9;
+const uint8_t number_of_columns = 6;
+
+void keyboard_init(){
+    for (int i = 0; i < number_of_rows; i++){
+        // setup rows (output open drain)
+        GPIOA->MODER  &= ~(0x3 << (i*2));
+        GPIOA->MODER  |=  (0x1 << (i*2));
+        GPIOA->OTYPER |= (1 << i);
+    }
+    for (int i = 0; i < number_of_columns; i++){
+        // setup columns (input pullup)
+        GPIOC->MODER  &= ~(0x3 << (i*2));
+        GPIOC->PUPDR  &= ~(0x3 << (i*2));
+        GPIOC->PUPDR  |=  (0x1 << (i*2));
+    }
+}
+
+bool keyboard_scan(){
+    set_output_pin(GPIO_A, 6, true);
+    bool key_state = read_input_pin(GPIO_C, 3);
+    return key_state; 
+    // A LOT TODO
+}
+
+void activate_row(uint8_t row_nb){
+    // set all row to 0 and then reenable selected row
+    for(int i =0; i < number_of_rows; i++){
+        set_output_pin(GPIO_A, i, true);
+    }
+    set_output_pin(GPIO_A, row_nb, false);
+    us_wait(100);
+}
\ No newline at end of file
diff --git a/numworks_port/src/Laplace/keyboard.h b/numworks_port/src/Laplace/keyboard.h
new file mode 100644 (file)
index 0000000..32d7b97
--- /dev/null
@@ -0,0 +1,27 @@
+/** @file keyboard.h
+ * 
+ * @brief All action related to keyboard scan
+ *
+ */ 
+
+#ifndef KEYBOARD_H
+#define KEYBOARD_H
+
+enum PIN_ROW {
+       A = 1,
+       B = 0,
+       C = 2,
+    D = 3,
+       E = 4,
+       F = 5,
+    G = 6,
+       H = 7,
+       I = 8
+};
+
+#include "gpio_helper.h"
+
+void keyboard_init();
+bool keyboard_scan();
+
+#endif
\ No newline at end of file
index 4edfdd90acb157dc22bb1cecf4a1ab02f9e7136a..deb4ae356af921a2cacdbe653bc5c1d17a03f95c 100644 (file)
@@ -4,4 +4,9 @@ void laplace_init(){
     // Enable the GPIO peripheral in RCC.
     enable_gpio_x_rcc(GPIO_B);
     led_init();
+    //col (in)
+    enable_gpio_x_rcc(GPIO_C);
+    //row (out)
+    enable_gpio_x_rcc(GPIO_A);
+    keyboard_init();
 }
\ No newline at end of file
index d775efb230ffa13ed3bb7a5d8be11af8cfa6adff..626bf7e1b70bb33201dccaae9d4536e2884537cb 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "gpio_helper.h"
 #include "led.h"
+#include "keyboard.h"
 
 void laplace_init();
 
diff --git a/numworks_port/src/Laplace/time.c b/numworks_port/src/Laplace/time.c
new file mode 100644 (file)
index 0000000..c257d18
--- /dev/null
@@ -0,0 +1,13 @@
+#include "time.h"
+
+void us_wait(uint8_t micro_seconds) {
+  for (volatile uint32_t i=0; i<loops_per_microsecond*micro_seconds; i++) {
+    __asm volatile("nop");
+  }
+}
+
+void ms_wait(uint16_t milli_seconds) {
+  for (volatile uint32_t i=0; i<loops_per_millisecond*milli_seconds; i++) {
+    __asm volatile("nop");
+  }
+}
\ No newline at end of file
diff --git a/numworks_port/src/Laplace/time.h b/numworks_port/src/Laplace/time.h
new file mode 100644 (file)
index 0000000..ed59cc8
--- /dev/null
@@ -0,0 +1,18 @@
+/** @file time.h
+ * 
+ * @brief Handle timer operation
+ *
+ */ 
+
+#ifndef TIME_H
+#define TIME_H
+
+#define loops_per_microsecond 1
+#define loops_per_millisecond 960
+
+#include "stdint.h"
+
+void us_wait(uint8_t micro_seconds);
+void ms_wait(uint16_t milli_seconds);
+
+#endif
\ No newline at end of file
index 47c2a0fd13f3feac15d92d2518a2b4148a046198..81f49068375942aac74aeaa61c6c7cf66fb3c3aa 100644 (file)
@@ -1,8 +1,18 @@
 #include "main.h"
 
 // this is our main function, I separated it from the c++ code because I don't like this language
-main_entry(){
+void main_entry(){
     // init all the peripherals
     laplace_init();
-    set_led_all(true);
+    ms_wait(2000);
+    set_led_green(true);
+    while (1)
+    {
+        /*if(keyboard_scan()){
+            set_led_green(true);
+        }else{
+            set_led_green(false);
+        }*/
+    }
+    
 }
\ No newline at end of file
index 6d4e8bfc1d122f405d98b3aa87520c9acd531128..85c894f9ed3f1d12feec5fd9ca12bd91b11be37e 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "Laplace/laplace.h"
 #include "Laplace/led.h"
+#include "Laplace/keyboard.h"
+#include "Laplace/time.h"
 
 void main_entry();