Skip to content

Commit

Permalink
feat: make hal::Port's contents depend on actual available ports (#350)
Browse files Browse the repository at this point in the history
* feat: make hal::Port's contents depend on actual available ports

* chore: make Nucleo64WBUi compile conditionally on whether there is a GPIOD
  • Loading branch information
daantimmer authored Jun 28, 2024
1 parent e86f662 commit da30d1d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
2 changes: 2 additions & 0 deletions examples/helloworld/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "hal/interfaces/Gpio.hpp"
#include "hal_st/instantiations/NucleoUi.hpp"
#include "hal_st/instantiations/StmEventInfrastructure.hpp"
#include "hal_st/stm32fxxx/DmaStm.hpp"
#include "hal_st/stm32fxxx/UartStmDma.hpp"
#include "infra/timer/Timer.hpp"
#include "services/tracer/GlobalTracer.hpp"
#include "services/tracer/StreamWriterOnSerialCommunication.hpp"
Expand Down
4 changes: 2 additions & 2 deletions hal_st/instantiations/NucleoUi.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#ifndef HAL_ST_NUCLEO_UI_HPP
#define HAL_ST_NUCLEO_UI_HPP

#include "hal_st/stm32fxxx/DmaStm.hpp"
#include "hal_st/stm32fxxx/GpioStm.hpp"
#include "hal_st/stm32fxxx/UartStmDma.hpp"

namespace main_
{
Expand Down Expand Up @@ -36,6 +34,7 @@ namespace main_
#endif
};

#if defined(GPIOD)
// UM2435: MB1355 reference board with STM32WB55RG
struct Nucleo64WBUi
{
Expand All @@ -46,6 +45,7 @@ namespace main_
hal::GpioPinStm ledGreen{ hal::Port::B, 0 };
hal::GpioPinStm ledBlue{ hal::Port::B, 5 };
};
#endif

// UM3103: MB1863 reference board with STM32WBA52CG
struct Nucleo64WBAUi
Expand Down
16 changes: 11 additions & 5 deletions hal_st/stm32fxxx/GpioStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ namespace hal
{
namespace
{
GPIO_TypeDef* const portToGPIOPort[] = {
const std::array portToGPIOPort = {
#if defined(GPIOA)
GPIOA,
#endif
#if defined(GPIOB)
GPIOB,
#endif
#if defined(GPIOC)
GPIOC,
#endif
#if defined(GPIOD)
GPIOD,
#endif
Expand All @@ -37,7 +43,7 @@ namespace hal
#endif
};

const uint16_t pinToGPIOPin[16] = {
const std::array pinToGPIOPin = {
GPIO_PIN_0,
GPIO_PIN_1,
GPIO_PIN_2,
Expand All @@ -56,13 +62,13 @@ namespace hal
GPIO_PIN_15,
};

const uint32_t weakPullToPuPd[3] = {
const std::array weakPullToPuPd = {
GPIO_NOPULL,
GPIO_PULLUP,
GPIO_PULLDOWN
};

const uint32_t speedToSpeed[] = {
const std::array speedToSpeed = {
GPIO_SPEED_FREQ_LOW,
GPIO_SPEED_FREQ_MEDIUM,
GPIO_SPEED_FREQ_HIGH,
Expand All @@ -71,7 +77,7 @@ namespace hal
#endif
};

const uint32_t driveToAFMode[2] = {
const std::array driveToAFMode = {
GPIO_MODE_AF_PP,
GPIO_MODE_AF_OD
};
Expand Down
24 changes: 23 additions & 1 deletion hal_st/stm32fxxx/GpioStm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,39 @@ namespace hal

enum class Port : uint8_t
{
#if defined(GPIOA)
A,
#endif
#if defined(GPIOB)
B,
#endif
#if defined(GPIOC)
C,
#endif
#if defined(GPIOD)
D,
#endif
#if defined(GPIOE)
E,
#endif
#if defined(GPIOF)
F,
#endif
#if defined(GPIOG)
G,
#endif
#if defined(GPIOH)
H,
#endif
#if defined(GPIOI)
I,
#endif
#if defined(GPIOJ)
J,
K
#endif
#if defined(GPIOK)
K,
#endif
};

enum class WeakPull : uint8_t
Expand Down

0 comments on commit da30d1d

Please sign in to comment.