Skip to content

Commit

Permalink
Change define to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
matsujirushi committed Sep 6, 2024
1 parent 227147a commit d9f9c75
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
35 changes: 20 additions & 15 deletions src/WioCellular.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,35 @@

#ifdef ARDUINO_WIO_BG770A

#define BG770AINTERFACE_VDD_EXT (PIN_VDD_EXT)
#define BG770AINTERFACE_PWRKEY (PIN_PWRKEY)
#ifdef PIN_RESET_N
#define BG770AINTERFACE_RESET_N (PIN_RESET_N)
#endif // PIN_RESET_N

#define BG770AINTERFACE_MAIN_TXD (PIN_MAIN_TXD)
#define BG770AINTERFACE_MAIN_RXD (PIN_MAIN_RXD)
#define BG770AINTERFACE_MAIN_CTS (PIN_MAIN_CTS)
#define BG770AINTERFACE_MAIN_RTS (PIN_MAIN_RTS)
#define BG770AINTERFACE_MAIN_DTR (PIN_MAIN_DTR)
#define BG770AINTERFACE_MAIN_DCD (PIN_MAIN_DCD)
#define BG770AINTERFACE_MAIN_RI (PIN_MAIN_RI)

// TODO I want to remove the define, but I don't know what code to use. (X_X)
#define BG770AINTERFACE_MAIN_UARTE (MAIN_UARTE)
#define BG770AINTERFACE_MAIN_UARTE_IRQn (MAIN_UARTE_IRQn)
#define BG770AINTERFACE_MAIN_UARTE_IRQHANDLER (MAIN_UARTE_IRQHANDLER)

#include <Arduino.h>

struct Bg770aInterfaceConstant
{
static constexpr int VDD_EXT_PIN = PIN_VDD_EXT;
static constexpr int PWRKEY_PIN = PIN_PWRKEY;
#ifdef PIN_RESET_N
static constexpr int RESET_N_PIN = PIN_RESET_N;
#endif // PIN_RESET_N

static constexpr int MAIN_TXD_PIN = PIN_MAIN_TXD;
static constexpr int MAIN_RXD_PIN = PIN_MAIN_RXD;
static constexpr int MAIN_CTS_PIN = PIN_MAIN_CTS;
static constexpr int MAIN_RTS_PIN = PIN_MAIN_RTS;
static constexpr int MAIN_DTR_PIN = PIN_MAIN_DTR;
static constexpr int MAIN_DCD_PIN = PIN_MAIN_DCD;
static constexpr int MAIN_RI_PIN = PIN_MAIN_RI;
};

#include "module/bg770a/Bg770aInterface.hpp"
#include "module/bg770a/Bg770a.hpp"
#include "board/WioBg770a.hpp"

using WioCellularModuleInterface = wiocellular::module::bg770a::Bg770aInterface<Uart>;
using WioCellularModuleInterface = wiocellular::module::bg770a::Bg770aInterface<Bg770aInterfaceConstant, Uart>;
using WioCellularModule = wiocellular::module::bg770a::Bg770a<WioCellularModuleInterface>;
using WioCellularBoard = wiocellular::board::WioBg770a<WioCellularModule, WioCellularModuleInterface>;

Expand Down
36 changes: 20 additions & 16 deletions src/module/bg770a/Bg770aInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,26 @@ namespace wiocellular
*
* Quectel BG770Aとやりとりするインターフェースのクラスです。
*/
template <typename UART>
template <typename CONSTANT, typename UART>
class Bg770aInterface
{
private:
suli3::arduino::DigitalInputPin<BG770AINTERFACE_VDD_EXT> VddExt_;
suli3::arduino::DigitalOutputPin<BG770AINTERFACE_PWRKEY> Pwrkey_;
#ifdef BG770AINTERFACE_RESET_N
suli3::arduino::DigitalOutputPin<BG770AINTERFACE_RESET_N> ResetN_;
#endif // BG770AINTERFACE_RESET_N
suli3::arduino::DigitalInputPin<CONSTANT::VDD_EXT_PIN> VddExt_;
suli3::arduino::DigitalOutputPin<CONSTANT::PWRKEY_PIN> Pwrkey_;
#if defined(BOARD_VERSION_ES2)
#elif defined(BOARD_VERSION_1_0)
suli3::arduino::DigitalOutputPin<CONSTANT::RESET_N_PIN> ResetN_;
#else
#error "Unknown board version"
#endif

SemaphoreHandle_t MainUartReceived_; // FreeRTOS
SemaphoreHandle_t MainUartReceived2_; // FreeRTOS
UART RealMainUart_;
suli3::arduino::Uart<decltype(RealMainUart_)> MainUart_;
suli3::arduino::DigitalOutputPin<BG770AINTERFACE_MAIN_DTR> MainDtr_;
suli3::arduino::DigitalInputPin<BG770AINTERFACE_MAIN_DCD> MainDcd_;
suli3::arduino::DigitalInputPin<BG770AINTERFACE_MAIN_RI> MainRi_;
suli3::arduino::DigitalOutputPin<CONSTANT::MAIN_DTR_PIN> MainDtr_;
suli3::arduino::DigitalInputPin<CONSTANT::MAIN_DCD_PIN> MainDcd_;
suli3::arduino::DigitalInputPin<CONSTANT::MAIN_RI_PIN> MainRi_;

public:
/**
Expand All @@ -55,7 +58,7 @@ namespace wiocellular
Bg770aInterface(void)
: MainUartReceived_{nullptr},
MainUartReceived2_{nullptr},
RealMainUart_{BG770AINTERFACE_MAIN_UARTE, BG770AINTERFACE_MAIN_UARTE_IRQn, BG770AINTERFACE_MAIN_TXD, BG770AINTERFACE_MAIN_RXD, BG770AINTERFACE_MAIN_CTS, BG770AINTERFACE_MAIN_RTS},
RealMainUart_{BG770AINTERFACE_MAIN_UARTE, BG770AINTERFACE_MAIN_UARTE_IRQn, CONSTANT::MAIN_TXD_PIN, CONSTANT::MAIN_RXD_PIN, CONSTANT::MAIN_CTS_PIN, CONSTANT::MAIN_RTS_PIN},
MainUart_{RealMainUart_}
{
MainUartReceived_ = xSemaphoreCreateBinary(); // FreeRTOS
Expand Down Expand Up @@ -136,12 +139,10 @@ namespace wiocellular
Pwrkey_.begin(OUTPUT, 0);
#elif defined(BOARD_VERSION_1_0)
Pwrkey_.begin(OUTPUT_S0D1, 1);
ResetN_.begin(OUTPUT_S0D1, 1);
#else
#error "Unknown board version"
#endif
#ifdef BG770AINTERFACE_RESET_N
ResetN_.begin(OUTPUT_S0D1, 1);
#endif // BG770AINTERFACE_RESET_N
MainDtr_.begin(OUTPUT, 0);

if (isActive())
Expand All @@ -163,7 +164,7 @@ namespace wiocellular
}
}

attachInterrupt(BG770AINTERFACE_VDD_EXT, BG770AINTERFACE_VDD_EXT_IRQHANDLER, CHANGE);
attachInterrupt(CONSTANT::VDD_EXT_PIN, BG770AINTERFACE_VDD_EXT_IRQHANDLER, CHANGE);
}

/**
Expand Down Expand Up @@ -216,11 +217,14 @@ namespace wiocellular
*/
void reset(void)
{
#ifdef BG770AINTERFACE_RESET_N
#if defined(BOARD_VERSION_ES2)
#elif defined(BOARD_VERSION_1_0)
ResetN_.write(0);
delay(100 + 2);
ResetN_.write(1);
#endif // BG770AINTERFACE_RESET_N
#else
#error "Unknown board version"
#endif
}

/**
Expand Down

0 comments on commit d9f9c75

Please sign in to comment.