This commit is contained in:
ayabusa 2024-03-31 21:05:08 +02:00
parent 3a161a1181
commit 60540437fb
20 changed files with 167 additions and 46 deletions

View File

@ -87,5 +87,6 @@ $(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(BUILD_DIR)/*.o rm -f $(BUILD_DIR)/*.o
rm -f $(BUILD_DIR)/Laplace/*.o
rm -f $(BUILD_DIR)/$(TARGET).elf rm -f $(BUILD_DIR)/$(TARGET).elf
rm -f $(BUILD_DIR)/$(TARGET).bin rm -f $(BUILD_DIR)/$(TARGET).bin

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
numworks_port/build/main.o Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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;
}
}

View File

@ -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

View File

@ -0,0 +1,7 @@
#include "laplace.h"
void laplace_init(){
// Enable the GPIO peripheral in RCC.
enable_gpio_x_rcc(GPIO_B);
led_init();
}

View File

@ -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

View File

@ -1,7 +1,7 @@
#include "led.h" #include "led.h"
// Variable to store the current state of LEDs // GPIOB for all the leds
uint8_t led_state = 0; uint8_t gpio_b = GPIO_B;
void led_init(){ void led_init(){
// It should be set to push-pull low-speed output. // It should be set to push-pull low-speed output.
@ -23,37 +23,19 @@ void led_init(){
} }
void set_led_red(bool state){ void set_led_red(bool state){
if(state){ set_output_pin(gpio_b, RED_LED_PIN, state);
led_state |= (1 << RED_LED_PIN);
}else{
led_state &= ~(1 << RED_LED_PIN);
}
GPIOB->ODR = led_state;
} }
void set_led_green(bool state){ void set_led_green(bool state){
if(state){ set_output_pin(gpio_b, GREEN_LED_PIN, state);
led_state |= (1 << GREEN_LED_PIN);
}else{
led_state &= ~(1 << GREEN_LED_PIN);
}
GPIOB->ODR = led_state;
} }
void set_led_blue(bool state){ void set_led_blue(bool state){
if(state){ set_output_pin(gpio_b, BLUE_LED_PIN, state);
led_state |= (1 << BLUE_LED_PIN);
}else{
led_state &= ~(1 << BLUE_LED_PIN);
}
GPIOB->ODR = led_state;
} }
void set_led_all(bool state){ void set_led_all(bool state){
if(state){ set_output_pin(gpio_b, RED_LED_PIN, state);
led_state = (1 << RED_LED_PIN) | (1 << GREEN_LED_PIN) | (1 << BLUE_LED_PIN); set_output_pin(gpio_b, GREEN_LED_PIN, state);
}else{ set_output_pin(gpio_b, BLUE_LED_PIN, state);
led_state = 0;
}
GPIOB->ODR = led_state;
} }

View File

@ -13,6 +13,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "../device/stm32f730xx.h" #include "../device/stm32f730xx.h"
#include "gpio_helper.h"
void led_init(); void led_init();
void set_led_red(bool state); void set_led_red(bool state);

View File

@ -1,5 +1,5 @@
#include <assert.h> #include <assert.h>
#include <cstdint> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#define byte4 0xFF, 0xFF, 0xFF, 0xFF #define byte4 0xFF, 0xFF, 0xFF, 0xFF

8
numworks_port/src/main.c Normal file
View File

@ -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);
}

15
numworks_port/src/main.h Normal file
View File

@ -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

View File

@ -2,7 +2,9 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "device/stm32f730xx.h" #include "device/stm32f730xx.h"
#include "Laplace/led.h" extern "C" {
#include "main.h"
}
//#define LED_PIN (4) // PB0 //#define LED_PIN (4) // PB0
@ -58,22 +60,6 @@ void __attribute__((noinline)) start() {
size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram); size_t bssSectionLength = (&_bss_section_end_ram - &_bss_section_start_ram);
memset_custom(&_bss_section_start_ram, 0, bssSectionLength); memset_custom(&_bss_section_start_ram, 0, bssSectionLength);
// Enable the GPIO peripheral in RCC. main_entry();
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
}
} }