]> git.ayabusa.dev Git - numworks-zeta-os.git/commitdiff
clean up
authorayabusa <lebgpub@gmail.com>
Sun, 31 Mar 2024 19:05:08 +0000 (21:05 +0200)
committerayabusa <lebgpub@gmail.com>
Sun, 31 Mar 2024 19:05:08 +0000 (21:05 +0200)
21 files changed:
numworks_port/Makefile
numworks_port/build/Laplace/gpio_helper.o [new file with mode: 0644]
numworks_port/build/Laplace/laplace.o [new file with mode: 0644]
numworks_port/build/Laplace/led.o
numworks_port/build/info_headers.o
numworks_port/build/main.bin
numworks_port/build/main.elf
numworks_port/build/main.o [new file with mode: 0644]
numworks_port/build/start_handler.o
numworks_port/build/vector_table.o
numworks_port/src/Laplace/gpio_helper.c [new file with mode: 0644]
numworks_port/src/Laplace/gpio_helper.h [new file with mode: 0644]
numworks_port/src/Laplace/laplace.c [new file with mode: 0644]
numworks_port/src/Laplace/laplace.h [new file with mode: 0644]
numworks_port/src/Laplace/led.c [new file with mode: 0644]
numworks_port/src/Laplace/led.cpp [deleted file]
numworks_port/src/Laplace/led.h
numworks_port/src/info_headers.cpp
numworks_port/src/main.c [new file with mode: 0644]
numworks_port/src/main.h [new file with mode: 0644]
numworks_port/src/start_handler.cpp

index cce2ae8edd8c8619a3e903baaeff7dd0596bff74..1e1ca642964f6a5b27973febb6d4c195456a2aeb 100644 (file)
@@ -87,5 +87,6 @@ $(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf
 .PHONY: clean
 clean:
        rm -f $(BUILD_DIR)/*.o
+       rm -f $(BUILD_DIR)/Laplace/*.o
        rm -f $(BUILD_DIR)/$(TARGET).elf
        rm -f $(BUILD_DIR)/$(TARGET).bin
\ No newline at end of file
diff --git a/numworks_port/build/Laplace/gpio_helper.o b/numworks_port/build/Laplace/gpio_helper.o
new file mode 100644 (file)
index 0000000..5e119b8
Binary files /dev/null and b/numworks_port/build/Laplace/gpio_helper.o differ
diff --git a/numworks_port/build/Laplace/laplace.o b/numworks_port/build/Laplace/laplace.o
new file mode 100644 (file)
index 0000000..dd5dd23
Binary files /dev/null and b/numworks_port/build/Laplace/laplace.o differ
index 1951be54e8b1cb12468307f2bcb12862a00fab1c..6284c5539b2b0ef408aceed1f119977b0c054081 100644 (file)
Binary files a/numworks_port/build/Laplace/led.o and b/numworks_port/build/Laplace/led.o differ
index 310b3e17fd07233613846df246c3cfc887c32393..e6000dcc982528f3b05e0694153c2587a5f488f9 100644 (file)
Binary files a/numworks_port/build/info_headers.o and b/numworks_port/build/info_headers.o differ
index 423b97fb77d88d53565b6adfb3d1194379cf2ca6..ba87df02f0d362b509db57513a46a24dc23cb77b 100755 (executable)
Binary files a/numworks_port/build/main.bin and b/numworks_port/build/main.bin differ
index e0cbe7893250abeee2226f9a9cd66e6e602b198f..ab1e7ff099a5ddac234975b6ae1984b796d256f6 100755 (executable)
Binary files a/numworks_port/build/main.elf and b/numworks_port/build/main.elf differ
diff --git a/numworks_port/build/main.o b/numworks_port/build/main.o
new file mode 100644 (file)
index 0000000..9b45cec
Binary files /dev/null and b/numworks_port/build/main.o differ
index abcdf0d5d5ddbde3f283141cb06d8c919a765a75..5ffb6102af33a626cfe1c302131cc72bd754aaef 100644 (file)
Binary files a/numworks_port/build/start_handler.o and b/numworks_port/build/start_handler.o differ
index 95f70dbe1345892e2dc63bed5543e55fe136029c..256854684e3f8c5284f16917a29b3af3a82dbba0 100644 (file)
Binary files a/numworks_port/build/vector_table.o and b/numworks_port/build/vector_table.o differ
diff --git a/numworks_port/src/Laplace/gpio_helper.c b/numworks_port/src/Laplace/gpio_helper.c
new file mode 100644 (file)
index 0000000..7211792
--- /dev/null
@@ -0,0 +1,84 @@
+#include "gpio_helper.h"
+
+uint8_t GPIOA_state = 0;
+uint8_t GPIOB_state = 0;
+uint8_t GPIOC_state = 0;
+uint8_t GPIOD_state = 0;
+uint8_t GPIOE_state = 0;
+
+void set_output_pin(uint8_t gpio_x, uint8_t pin, bool state){
+    switch (gpio_x)
+    {
+    case GPIO_A:
+        if(state){
+            GPIOA_state |= (1 << pin);
+        }else{
+            GPIOA_state &= ~(1 << pin);
+        }  
+        GPIOA->ODR = GPIOA_state;
+        break;
+
+    case GPIO_B:
+        if(state){
+            GPIOB_state |= (1 << pin);
+        }else{
+            GPIOB_state &= ~(1 << pin);
+        }  
+        GPIOB->ODR = GPIOB_state;
+        break;
+
+    case GPIO_C:
+        if(state){
+            GPIOC_state |= (1 << pin);
+        }else{
+            GPIOC_state &= ~(1 << pin);
+        }  
+        GPIOC->ODR = GPIOC_state;
+        break;
+    
+    case GPIO_D:
+        if(state){
+            GPIOD_state |= (1 << pin);
+        }else{
+            GPIOD_state &= ~(1 << pin);
+        }  
+        GPIOD->ODR = GPIOD_state;
+        break;
+
+    case GPIO_E:
+        if(state){
+            GPIOE_state |= (1 << pin);
+        }else{
+            GPIOE_state &= ~(1 << pin);
+        }  
+        GPIOE->ODR = GPIOE_state;
+        break;
+    
+    default:
+        break;
+    }
+}
+
+void enable_gpio_x_rcc(uint8_t gpio_x){
+    switch (gpio_x)
+    {
+        case GPIO_A:
+            RCC->AHB1ENR   |= RCC_AHB1ENR_GPIOAEN ;
+            break;
+        case GPIO_B:
+            RCC->AHB1ENR   |= RCC_AHB1ENR_GPIOBEN ;
+            break;
+        case GPIO_C:
+            RCC->AHB1ENR   |= RCC_AHB1ENR_GPIOCEN ;
+            break;
+        case GPIO_D:
+            RCC->AHB1ENR   |= RCC_AHB1ENR_GPIODEN ;
+            break;
+        case GPIO_E:
+            RCC->AHB1ENR   |= RCC_AHB1ENR_GPIOEEN ;
+            break;
+        
+        default:
+            break;
+    }
+}
\ No newline at end of file
diff --git a/numworks_port/src/Laplace/gpio_helper.h b/numworks_port/src/Laplace/gpio_helper.h
new file mode 100644 (file)
index 0000000..4f73d94
--- /dev/null
@@ -0,0 +1,22 @@
+/** @file gpio_helper.h
+ * 
+ * @brief Control all the GPIO
+ *
+ */ 
+
+#ifndef GPIO_HELPER_H
+#define GPIO_HELPER_H
+
+#include "stdbool.h"
+#include "../device/stm32f730xx.h"
+
+#define GPIO_A 0
+#define GPIO_B 1
+#define GPIO_C 2
+#define GPIO_D 3
+#define GPIO_E 4
+
+void set_output_pin(uint8_t gpio_x, uint8_t pin, bool state);
+void enable_gpio_x_rcc(uint8_t gpio_x);
+
+#endif
\ No newline at end of file
diff --git a/numworks_port/src/Laplace/laplace.c b/numworks_port/src/Laplace/laplace.c
new file mode 100644 (file)
index 0000000..4edfdd9
--- /dev/null
@@ -0,0 +1,7 @@
+#include "laplace.h"
+
+void laplace_init(){
+    // Enable the GPIO peripheral in RCC.
+    enable_gpio_x_rcc(GPIO_B);
+    led_init();
+}
\ No newline at end of file
diff --git a/numworks_port/src/Laplace/laplace.h b/numworks_port/src/Laplace/laplace.h
new file mode 100644 (file)
index 0000000..d775efb
--- /dev/null
@@ -0,0 +1,15 @@
+/** @file laplace.h
+ * 
+ * @brief Global function of Laplace
+ *
+ */ 
+
+#ifndef LAPLACE_H
+#define LAPLACE_H
+
+#include "gpio_helper.h"
+#include "led.h"
+
+void laplace_init();
+
+#endif
\ No newline at end of file
diff --git a/numworks_port/src/Laplace/led.c b/numworks_port/src/Laplace/led.c
new file mode 100644 (file)
index 0000000..db8ac59
--- /dev/null
@@ -0,0 +1,41 @@
+#include "led.h"
+
+// GPIOB for all the leds
+uint8_t gpio_b = GPIO_B;
+
+void led_init(){
+    // It should be set to push-pull low-speed output.
+
+    // setup red led
+    GPIOB->MODER  &= ~(0x3 << (RED_LED_PIN*2));
+    GPIOB->MODER  |=  (0x1 << (RED_LED_PIN*2));
+    GPIOB->OTYPER &= ~(1 << RED_LED_PIN);
+
+    // setup green led
+    GPIOB->MODER  &= ~(0x3 << (GREEN_LED_PIN*2));
+    GPIOB->MODER  |=  (0x1 << (GREEN_LED_PIN*2));
+    GPIOB->OTYPER &= ~(1 << GREEN_LED_PIN);
+
+    // setup blue led
+    GPIOB->MODER  &= ~(0x3 << (BLUE_LED_PIN*2));
+    GPIOB->MODER  |=  (0x1 << (BLUE_LED_PIN*2));
+    GPIOB->OTYPER &= ~(1 << BLUE_LED_PIN);
+}
+
+void set_led_red(bool state){
+    set_output_pin(gpio_b, RED_LED_PIN, state);
+}
+
+void set_led_green(bool state){
+    set_output_pin(gpio_b, GREEN_LED_PIN, state);
+}
+
+void set_led_blue(bool state){
+    set_output_pin(gpio_b, BLUE_LED_PIN, state);
+}
+
+void set_led_all(bool state){
+    set_output_pin(gpio_b, RED_LED_PIN, state);
+    set_output_pin(gpio_b, GREEN_LED_PIN, state);
+    set_output_pin(gpio_b, BLUE_LED_PIN, state);
+}
\ No newline at end of file
diff --git a/numworks_port/src/Laplace/led.cpp b/numworks_port/src/Laplace/led.cpp
deleted file mode 100644 (file)
index 3d2f664..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#include "led.h"
-
-// Variable to store the current state of LEDs
-uint8_t led_state = 0;
-
-void led_init(){
-    // It should be set to push-pull low-speed output.
-
-    // setup red led
-    GPIOB->MODER  &= ~(0x3 << (RED_LED_PIN*2));
-    GPIOB->MODER  |=  (0x1 << (RED_LED_PIN*2));
-    GPIOB->OTYPER &= ~(1 << RED_LED_PIN);
-
-    // setup green led
-    GPIOB->MODER  &= ~(0x3 << (GREEN_LED_PIN*2));
-    GPIOB->MODER  |=  (0x1 << (GREEN_LED_PIN*2));
-    GPIOB->OTYPER &= ~(1 << GREEN_LED_PIN);
-
-    // setup blue led
-    GPIOB->MODER  &= ~(0x3 << (BLUE_LED_PIN*2));
-    GPIOB->MODER  |=  (0x1 << (BLUE_LED_PIN*2));
-    GPIOB->OTYPER &= ~(1 << BLUE_LED_PIN);
-}
-
-void set_led_red(bool state){
-    if(state){
-        led_state |= (1 << RED_LED_PIN);
-    }else{
-        led_state &= ~(1 << RED_LED_PIN);
-    }
-    GPIOB->ODR = led_state;
-}
-
-void set_led_green(bool state){
-    if(state){
-        led_state |= (1 << GREEN_LED_PIN);
-    }else{
-        led_state &= ~(1 << GREEN_LED_PIN);
-    }
-    GPIOB->ODR = led_state;
-}
-
-void set_led_blue(bool state){
-    if(state){
-        led_state |= (1 << BLUE_LED_PIN);
-    }else{
-        led_state &= ~(1 << BLUE_LED_PIN);
-    }
-    GPIOB->ODR = led_state;
-}
-
-void set_led_all(bool state){
-    if(state){
-        led_state = (1 << RED_LED_PIN) | (1 << GREEN_LED_PIN) | (1 << BLUE_LED_PIN);
-    }else{
-        led_state = 0;
-    }
-    GPIOB->ODR = led_state;
-}
\ No newline at end of file
index 60b22d2722d9454c6b7069717dccccbb78ce2363..2be3080c6798722159c1fab8e123e255c85739dd 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <stdbool.h>
 #include "../device/stm32f730xx.h"
+#include "gpio_helper.h"
 
 void led_init();
 void set_led_red(bool state);
index a5537ec31cdf04baf98ef3ecf3ddeb9194e60b5b..f57cdcdd65753b3c4fd658191921bcc769490c3f 100644 (file)
@@ -1,5 +1,5 @@
 #include <assert.h>
-#include <cstdint>
+#include <stdint.h>
 #include <stddef.h>
 
 #define byte4 0xFF, 0xFF, 0xFF, 0xFF
diff --git a/numworks_port/src/main.c b/numworks_port/src/main.c
new file mode 100644 (file)
index 0000000..47c2a0f
--- /dev/null
@@ -0,0 +1,8 @@
+#include "main.h"
+
+// this is our main function, I separated it from the c++ code because I don't like this language
+main_entry(){
+    // init all the peripherals
+    laplace_init();
+    set_led_all(true);
+}
\ No newline at end of file
diff --git a/numworks_port/src/main.h b/numworks_port/src/main.h
new file mode 100644 (file)
index 0000000..6d4e8bf
--- /dev/null
@@ -0,0 +1,15 @@
+/** @file led.h
+ * 
+ * @brief Control the led
+ *
+ */ 
+
+#ifndef MAIN_H
+#define MAIN_H
+
+#include "Laplace/laplace.h"
+#include "Laplace/led.h"
+
+void main_entry();
+
+#endif
\ No newline at end of file
index 8f5e097c2839e782e0cfbe7e50b1dadb276853a9..7fa100452f5431c9721ff630b3e373393e07b393 100644 (file)
@@ -2,7 +2,9 @@
 #include <stddef.h>
 #include <stdint.h>
 #include "device/stm32f730xx.h"
-#include "Laplace/led.h"
+extern "C" {
+  #include "main.h"
+}
 
 //#define LED_PIN    (4) // PB0
 
@@ -58,22 +60,6 @@ void __attribute__((noinline)) start() {
   size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram);
   memset_custom(&_bss_section_start_ram, 0, bssSectionLength);
 
-  // Enable the GPIO peripheral in RCC.
-  RCC->AHB1ENR   |= RCC_AHB1ENR_GPIOBEN ;
-  led_init();
-  set_led_green(true);
-  set_led_red(true);
-  /*
-  // B0 is connected to the LED.
-  // It should be set to push-pull low-speed output.
-  GPIOB->MODER  &= ~(0x3 << (LED_PIN*2));
-  GPIOB->MODER  |=  (0x1 << (LED_PIN*2));
-  GPIOB->OTYPER &= ~(1 << LED_PIN);
-
-  GPIOB->ODR = (1 << LED_PIN);
-  */
-  while (0)
-  {
-    // code
-  }
+  main_entry();
+  
 }
\ No newline at end of file