diff --git a/numworks_port/Makefile b/numworks_port/Makefile index cce2ae8..1e1ca64 100644 --- a/numworks_port/Makefile +++ b/numworks_port/Makefile @@ -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 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 index 0000000..dd5dd23 Binary files /dev/null and b/numworks_port/build/Laplace/laplace.o differ diff --git a/numworks_port/build/Laplace/led.o b/numworks_port/build/Laplace/led.o index 1951be5..6284c55 100644 Binary files a/numworks_port/build/Laplace/led.o and b/numworks_port/build/Laplace/led.o differ diff --git a/numworks_port/build/info_headers.o b/numworks_port/build/info_headers.o index 310b3e1..e6000dc 100644 Binary files a/numworks_port/build/info_headers.o and b/numworks_port/build/info_headers.o differ diff --git a/numworks_port/build/main.bin b/numworks_port/build/main.bin index 423b97f..ba87df0 100755 Binary files a/numworks_port/build/main.bin and b/numworks_port/build/main.bin differ diff --git a/numworks_port/build/main.elf b/numworks_port/build/main.elf index e0cbe78..ab1e7ff 100755 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 index 0000000..9b45cec Binary files /dev/null and b/numworks_port/build/main.o differ diff --git a/numworks_port/build/start_handler.o b/numworks_port/build/start_handler.o index abcdf0d..5ffb610 100644 Binary files a/numworks_port/build/start_handler.o and b/numworks_port/build/start_handler.o differ diff --git a/numworks_port/build/vector_table.o b/numworks_port/build/vector_table.o index 95f70db..2568546 100644 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 index 0000000..7211792 --- /dev/null +++ b/numworks_port/src/Laplace/gpio_helper.c @@ -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 index 0000000..4f73d94 --- /dev/null +++ b/numworks_port/src/Laplace/gpio_helper.h @@ -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 index 0000000..4edfdd9 --- /dev/null +++ b/numworks_port/src/Laplace/laplace.c @@ -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 index 0000000..d775efb --- /dev/null +++ b/numworks_port/src/Laplace/laplace.h @@ -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.cpp b/numworks_port/src/Laplace/led.c similarity index 51% rename from numworks_port/src/Laplace/led.cpp rename to numworks_port/src/Laplace/led.c index 3d2f664..db8ac59 100644 --- a/numworks_port/src/Laplace/led.cpp +++ b/numworks_port/src/Laplace/led.c @@ -1,7 +1,7 @@ #include "led.h" -// Variable to store the current state of LEDs -uint8_t led_state = 0; +// GPIOB for all the leds +uint8_t gpio_b = GPIO_B; void led_init(){ // It should be set to push-pull low-speed output. @@ -23,37 +23,19 @@ void led_init(){ } 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; + set_output_pin(gpio_b, RED_LED_PIN, 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; + set_output_pin(gpio_b, GREEN_LED_PIN, 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; + set_output_pin(gpio_b, BLUE_LED_PIN, 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; + 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.h b/numworks_port/src/Laplace/led.h index 60b22d2..2be3080 100644 --- a/numworks_port/src/Laplace/led.h +++ b/numworks_port/src/Laplace/led.h @@ -13,6 +13,7 @@ #include #include "../device/stm32f730xx.h" +#include "gpio_helper.h" void led_init(); void set_led_red(bool state); diff --git a/numworks_port/src/info_headers.cpp b/numworks_port/src/info_headers.cpp index a5537ec..f57cdcd 100644 --- a/numworks_port/src/info_headers.cpp +++ b/numworks_port/src/info_headers.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #define byte4 0xFF, 0xFF, 0xFF, 0xFF diff --git a/numworks_port/src/main.c b/numworks_port/src/main.c new file mode 100644 index 0000000..47c2a0f --- /dev/null +++ b/numworks_port/src/main.c @@ -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 index 0000000..6d4e8bf --- /dev/null +++ b/numworks_port/src/main.h @@ -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 diff --git a/numworks_port/src/start_handler.cpp b/numworks_port/src/start_handler.cpp index 8f5e097..7fa1004 100644 --- a/numworks_port/src/start_handler.cpp +++ b/numworks_port/src/start_handler.cpp @@ -2,7 +2,9 @@ #include #include #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