Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migra o template para CPP #46

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)

# Cube file name without .ioc extension
project(stm32_project_template C ASM)
project(stm32_project_template C CXX ASM)

# Set the board version to an empty string if your board doesn't have a version
set(BOARD_VERSION "")
Expand Down Expand Up @@ -125,12 +125,12 @@ set(TEST_INCLUDE_DIRECTORIES
## Input files
###############################################################################

file(GLOB_RECURSE C_SOURCES CONFIGURE_DEPENDS "src/*.c")
file(GLOB_RECURSE C_HEADERS CONFIGURE_DEPENDS "inc/*.h")
file(GLOB_RECURSE C_SOURCES CONFIGURE_DEPENDS "src/*.cpp")
file(GLOB_RECURSE C_HEADERS CONFIGURE_DEPENDS "inc/*.hpp")
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved

file(GLOB_RECURSE TESTS_SOURCES CONFIGURE_DEPENDS "tests/src/*.c")
file(GLOB_RECURSE TESTS_HEADERS CONFIGURE_DEPENDS "tests/inc/*.h")
file(GLOB_RECURSE TESTS_BIN CONFIGURE_DEPENDS "tests/bin/*.c")
file(GLOB_RECURSE TESTS_SOURCES CONFIGURE_DEPENDS "tests/src/*.cpp")
file(GLOB_RECURSE TESTS_HEADERS CONFIGURE_DEPENDS "tests/inc/*.hpp")
file(GLOB_RECURSE TESTS_BIN CONFIGURE_DEPENDS "tests/bin/*.cpp")
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved

file(GLOB_RECURSE CUBE_SOURCES CONFIGURE_DEPENDS "cube/Src/*.c")

Expand Down Expand Up @@ -184,12 +184,12 @@ targets_generate_helpme_target()
## Generate test executables
###############################################################################

# Since each test has its own main function, we don't need the main.c from the project
list(REMOVE_ITEM C_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c)
# Since each test has its own main function, we don't need the main.cpp from the project
list(REMOVE_ITEM C_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp)

foreach(TEST_FILE ${TESTS_BIN})

# If TEST_FILE contains /dir1/dir2/file.c, TEST_NAME will be 'file'
# If TEST_FILE contains /dir1/dir2/file.cpp, TEST_NAME will be 'file'
get_filename_component(TEST_NAME ${TEST_FILE} NAME_WLE)

add_executable(${TEST_NAME} EXCLUDE_FROM_ALL
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Para isso é necessário mudar o nome do projeto, o qual deve ter o mesmo do arq

```c
# Cube file name without .ioc extension
project(stm32_project_template C ASM)
project(stm32_project_template C CXX ASM)
```

> Os argumentos `C` e `ASM` estão relacionados ao tipo de linguagem que o projeto utiliza (C e Assembly).
Expand Down
4 changes: 2 additions & 2 deletions cube/stm32_project_template.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Mcu.PinsNb=14
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F303RETx
MxCube.Version=6.9.0
MxDb.Version=DB.6.0.90
MxCube.Version=6.9.1
MxDb.Version=DB.6.0.91
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:false\:true\:false\:false
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:false\:true\:false\:false
NVIC.ForceEnableDMAVector=true
Expand Down
39 changes: 0 additions & 39 deletions inc/mcu.h

This file was deleted.

48 changes: 48 additions & 0 deletions inc/mcu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @file mcu.hpp
*
* @brief MCU related
*/

#ifndef __MCU_H__
#define __MCU_H__
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved

#include <stdint.h>

/*****************************************
* Public Function Prototypes
*****************************************/

extern "C"
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O uncrustify deixa essa chave aqui mesmo? Estranho ahushuashuashu

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aisduhas de fato estranho, mas o make format nao mudou isso aí

/**
* @brief Initializes System Clock.
* @note Defined by cube.
*/
void SystemClock_Config(void);
}

namespace hal
{
class mcu

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isso aqui é só um comentário. Nn sei se vejo muito sentido nisso aqui ser uma classe nn. Se a ideia for encapsulamento, "mcu" poderia ser um namespace. Por outro lado, eu entendo que está seguindo um padrão e piriri pororó.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

po foi 100% pelo padrão

a ideia era manter como nas futuras libs, mcu ser uma classe no namespace hal

{
public:
/**
* @brief Initializes MCU and some peripherals.
*/
static void init(void);

/**
* @brief Put the MCU to sleep.
*
* @param ms Sleep time in milliseconds
*/
static void sleep(uint32_t ms);

/**
* @brief Toggles LED.
*/
static void led_toggle(void);
};
};
#endif // __MCU_H__
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 10 additions & 8 deletions src/main.c → src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/**
* @file main.c
* @file main.cpp
*
* @brief Main function
*/

#include "mcu.h"
#include "mcu.hpp"

/*****************************************
* Private Constant Definitions
*****************************************/

#define LED_TOGGLE_DELAY_MS 1500
static constexpr uint16_t led_toggle_delay_ms = 1500;

/*****************************************
* Main Function
*****************************************/

int main(void) {
mcu_init();
int main(void)
{
hal::mcu::init();

for (;;) {
led_toggle();
mcu_sleep(LED_TOGGLE_DELAY_MS);
for (;;)
{
hal::mcu::led_toggle();
hal::mcu::sleep(led_toggle_delay_ms);
}
}
13 changes: 8 additions & 5 deletions src/mcu.c → src/mcu.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* @file mcu.c
* @file mcu.cpp
*
* @brief MCU related
*/

#include <stdint.h>

#include "mcu.h"
#include "mcu.hpp"

#include "gpio.h"
#include "main.h"
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -15,18 +15,21 @@
* Public Function Body Definitions
*****************************************/

void mcu_init(void) {
void hal::mcu::init(void)
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved
{
HAL_Init();

SystemClock_Config();

MX_GPIO_Init();
}

void mcu_sleep(uint32_t ms) {
void hal::mcu::sleep(uint32_t ms)
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved
{
HAL_Delay(ms);
}

void led_toggle(void) {
void hal::mcu::led_toggle(void)
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
Eduardo-Barreto marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 6 additions & 4 deletions tests/bin/test_main.c → tests/bin/test_main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/**
* @file test_main.c
* @file test_main.cpp
*
* @brief Main function for tests.
*/

#include <stdio.h>
#include "tests_core.h"
#include "test_core.hpp"

int main(void) {
int main(void)
{
test_core_init();

for (;;) {
for (;;)
{
}
}
2 changes: 1 addition & 1 deletion tests/inc/test_core.h → tests/inc/test_core.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file test_core.h
* @file test_core.hpp
*
* @brief Core functions to the test
*
Expand Down
11 changes: 6 additions & 5 deletions tests/src/test_core.c → tests/src/test_core.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file test_core.c
* @file test_core.cpp
*
* @brief Core functions to the test
*
Expand All @@ -9,13 +9,14 @@
*
*/

#include "test_core.h"
#include "mcu.h"
#include "test_core.hpp"
#include "mcu.hpp"

/*****************************************
* Public Functions Bodies Definitions
*****************************************/

void test_core_init(void) {
mcu_init();
void test_core_init(void)
{
hal::mcu::init();
}