.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
--- /dev/null
+#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
--- /dev/null
+/** @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
--- /dev/null
+#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
--- /dev/null
+/** @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
--- /dev/null
+#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
+++ /dev/null
-#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
#include <stdbool.h>
#include "../device/stm32f730xx.h"
+#include "gpio_helper.h"
void led_init();
void set_led_red(bool state);
#include <assert.h>
-#include <cstdint>
+#include <stdint.h>
#include <stddef.h>
#define byte4 0xFF, 0xFF, 0xFF, 0xFF
--- /dev/null
+#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
--- /dev/null
+/** @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
#include <stddef.h>
#include <stdint.h>
#include "device/stm32f730xx.h"
-#include "Laplace/led.h"
+extern "C" {
+ #include "main.h"
+}
//#define LED_PIN (4) // PB0
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