diff --git a/src/WioCellular.hpp b/src/WioCellular.hpp index ef1dbc6..7551e37 100644 --- a/src/WioCellular.hpp +++ b/src/WioCellular.hpp @@ -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 + +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; +using WioCellularModuleInterface = wiocellular::module::bg770a::Bg770aInterface; using WioCellularModule = wiocellular::module::bg770a::Bg770a; using WioCellularBoard = wiocellular::board::WioBg770a; diff --git a/src/module/bg770a/Bg770aInterface.hpp b/src/module/bg770a/Bg770aInterface.hpp index 86d3b94..82bd5fd 100644 --- a/src/module/bg770a/Bg770aInterface.hpp +++ b/src/module/bg770a/Bg770aInterface.hpp @@ -27,23 +27,26 @@ namespace wiocellular * * Quectel BG770Aとやりとりするインターフェースのクラスです。 */ - template + template class Bg770aInterface { private: - suli3::arduino::DigitalInputPin VddExt_; - suli3::arduino::DigitalOutputPin Pwrkey_; -#ifdef BG770AINTERFACE_RESET_N - suli3::arduino::DigitalOutputPin ResetN_; -#endif // BG770AINTERFACE_RESET_N + suli3::arduino::DigitalInputPin VddExt_; + suli3::arduino::DigitalOutputPin Pwrkey_; +#if defined(BOARD_VERSION_ES2) +#elif defined(BOARD_VERSION_1_0) + suli3::arduino::DigitalOutputPin ResetN_; +#else +#error "Unknown board version" +#endif SemaphoreHandle_t MainUartReceived_; // FreeRTOS SemaphoreHandle_t MainUartReceived2_; // FreeRTOS UART RealMainUart_; suli3::arduino::Uart MainUart_; - suli3::arduino::DigitalOutputPin MainDtr_; - suli3::arduino::DigitalInputPin MainDcd_; - suli3::arduino::DigitalInputPin MainRi_; + suli3::arduino::DigitalOutputPin MainDtr_; + suli3::arduino::DigitalInputPin MainDcd_; + suli3::arduino::DigitalInputPin MainRi_; public: /** @@ -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 @@ -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()) @@ -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); } /** @@ -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 } /**