mirror of
https://github.com/ayabusa/Numworks-zeta-os.git
synced 2024-11-24 11:53:26 +00:00
clean up
This commit is contained in:
parent
3a161a1181
commit
60540437fb
@ -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
|
BIN
numworks_port/build/Laplace/gpio_helper.o
Normal file
BIN
numworks_port/build/Laplace/gpio_helper.o
Normal file
Binary file not shown.
BIN
numworks_port/build/Laplace/laplace.o
Normal file
BIN
numworks_port/build/Laplace/laplace.o
Normal file
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
BIN
numworks_port/build/main.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
84
numworks_port/src/Laplace/gpio_helper.c
Normal file
84
numworks_port/src/Laplace/gpio_helper.c
Normal 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;
|
||||
}
|
||||
}
|
22
numworks_port/src/Laplace/gpio_helper.h
Normal file
22
numworks_port/src/Laplace/gpio_helper.h
Normal 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
|
7
numworks_port/src/Laplace/laplace.c
Normal file
7
numworks_port/src/Laplace/laplace.c
Normal 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();
|
||||
}
|
15
numworks_port/src/Laplace/laplace.h
Normal file
15
numworks_port/src/Laplace/laplace.h
Normal 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
|
@ -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);
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "../device/stm32f730xx.h"
|
||||
#include "gpio_helper.h"
|
||||
|
||||
void led_init();
|
||||
void set_led_red(bool state);
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <assert.h>
|
||||
#include <cstdint>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define byte4 0xFF, 0xFF, 0xFF, 0xFF
|
||||
|
8
numworks_port/src/main.c
Normal file
8
numworks_port/src/main.c
Normal 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
15
numworks_port/src/main.h
Normal 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
|
@ -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();
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user