diff --git a/src/app/BoardConfig.cpp b/src/app/BoardConfig.cpp new file mode 100644 index 0000000..a05f289 --- /dev/null +++ b/src/app/BoardConfig.cpp @@ -0,0 +1,91 @@ +#include "BoardConfig.h" + +BoardConfig::BoardConfig(const uint16_t I2C_screenAddress, +const uint16_t screenWidth, +const uint16_t screenHeight, +const uint16_t I2C_IOExpanderAddress, +const uint16_t _I2C_RTCFlashAddress, +const Pin SPI_SDCard_cs, +const Pin I2C_sda, +const Pin I2C_scl, +const Pin SPI_mosi, +const Pin SPI_miso, +const Pin SPI_clk//, +//const SPISettings spiSpeed +): +_I2C_sda(I2C_sda == DEFAULT_PIN ? GPIO_4_SDA : I2C_sda), +_I2C_scl(I2C_scl == DEFAULT_PIN ? GPIO_5_SCL : I2C_scl), +_SPI_mosi(SPI_mosi == DEFAULT_PIN ? GPIO_13_MOSI : SPI_mosi), +_SPI_miso(SPI_miso == DEFAULT_PIN ? GPIO_12_MISO : SPI_miso), +_SPI_clk(SPI_clk == DEFAULT_PIN ? GPIO_14_CLK : SPI_clk), +_SPI_SDCard_cs(_SPI_SDCard_cs == DEFAULT_PIN ? GPIO_2 : SPI_SDCard_cs), +_I2C_screenAddress(I2C_screenAddress), +_I2C_IOExpanderAddress(I2C_IOExpanderAddress), +_I2C_RTCFlashAddress(_I2C_RTCFlashAddress), +//_SPISpeed(spiSpeed), +_screenWidth(screenWidth), +_screenHeight(screenHeight) +{ + +} + +Pin BoardConfig::getI2C_sda() const +{ + return _I2C_sda; +} + +Pin BoardConfig::getI2C_scl() const +{ + return _I2C_scl; +} + +Pin BoardConfig::getSPI_mosi() const +{ + return _SPI_mosi; +} + +Pin BoardConfig::getSPI_miso() const +{ + return _SPI_miso; +} + +Pin BoardConfig::getSPI_clk() const +{ + return _SPI_clk; +} + +Pin BoardConfig::getSPI_SDCard_cs() const +{ + return _SPI_SDCard_cs; +} + +uint16_t BoardConfig::getI2C_screenAddress() const +{ + return _I2C_screenAddress; +} + +uint16_t BoardConfig::getI2C_IOExpanderAddress() const +{ + return _I2C_IOExpanderAddress; +} + +uint16_t BoardConfig::getRTCFlashAddress() const +{ + return _I2C_RTCFlashAddress; +} + + +/*SPISettings BoardConfig::getSPISpeed() const +{ + return _SPISpeed; +}*/ + +uint16_t BoardConfig::getScreenWidth() const +{ + return _screenWidth; +} + +uint16_t BoardConfig::getScreenHeight() const +{ + return _screenHeight; +} diff --git a/src/app/BoardConfig.h b/src/app/BoardConfig.h new file mode 100644 index 0000000..38c4752 --- /dev/null +++ b/src/app/BoardConfig.h @@ -0,0 +1,68 @@ +/** + This file is used to define the hardware parameters of the whole board and thus replacing the following files : + ScreenConfig.h, SDcardConfig.h, PinMapping.h + It contains parameters Pins parameters, I2C addresses and more. +**/ +#ifndef BOARDCONFIG_H +#define BOARDCONFIG_H +#include "definition.h" +//#include + +class BoardConfig +{ + public: + BoardConfig(const uint16_t I2C_screenAddress = 0x3C, + const uint16_t screenWidth = 128, + const uint16_t screenHeight = 64, + const uint16_t I2C_IOExpanderAddress = 0x27, + const uint16_t _I2C_RTCFlashAddress = 0x0, + const Pin SPI_SDCard_cs = GPIO_2, + const Pin I2C_sda = GPIO_4_SDA, + const Pin I2C_scl = GPIO_5_SCL, + const Pin SPI_mosi = GPIO_13_MOSI, + const Pin SPI_miso = GPIO_12_MISO, + const Pin SPI_clk = GPIO_14_CLK//, + //const SPISettings spiSpeed = SPI_FULL_SPEED + ); + + Pin getI2C_sda() const; + Pin getI2C_scl() const; + + Pin getSPI_mosi() const; + Pin getSPI_miso() const; + Pin getSPI_clk() const; + Pin getSPI_SDCard_cs() const; + + uint16_t getI2C_screenAddress() const; + uint16_t getI2C_IOExpanderAddress() const; + uint16_t getRTCFlashAddress() const; + + //SPISettings getSPISpeed() const; + + uint16_t getScreenWidth() const; + uint16_t getScreenHeight() const; + protected: + + private: + //1) Pins + const Pin _I2C_sda; + const Pin _I2C_scl; + const Pin _SPI_mosi; + const Pin _SPI_miso; + const Pin _SPI_clk; + const Pin _SPI_SDCard_cs; + + //2) I2C Addresses + const uint16_t _I2C_screenAddress; + const uint16_t _I2C_IOExpanderAddress; + const uint16_t _I2C_RTCFlashAddress; + + //3) SPI Speed + //const SPISettings _SPISpeed; + + //4) Miscellaneous + const uint16_t _screenWidth; + const uint16_t _screenHeight; +}; + +#endif //BOARDCONFIG_H diff --git a/src/app/PinMapping.cpp b/src/app/PinMapping.cpp deleted file mode 100644 index f708e82..0000000 --- a/src/app/PinMapping.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "PinMapping.h" - -/** - * Helper class to define the pin mapping - */ - -//Default pin mapping -PinMapping::PinMapping() : -_I2C_sda(GPIO_4_SDA), -_I2C_scl(GPIO_5_SCL), -_SPI_mosi(GPIO_13_MOSI), -_SPI_miso(GPIO_12_MISO), -_SPI_clk(GPIO_14_CLK), -_SPI_sdCard_cs(GPIO_2) -{ -} - -//Custom pin mapping -PinMapping::PinMapping(const Pin I2C_sda, const Pin I2C_scl, const Pin SPI_mosi, const Pin SPI_miso, const Pin SPI_clk, const Pin SPI_sdCard_cs) : -_I2C_sda(I2C_sda == DEFAULT_PIN ? GPIO_4_SDA : I2C_sda), -_I2C_scl(I2C_scl == DEFAULT_PIN ? GPIO_5_SCL : I2C_scl), -_SPI_mosi(SPI_mosi == DEFAULT_PIN ? GPIO_13_MOSI : SPI_mosi), -_SPI_miso(SPI_miso == DEFAULT_PIN ? GPIO_12_MISO : SPI_miso), -_SPI_clk(SPI_clk == DEFAULT_PIN ? GPIO_14_CLK : SPI_clk), -_SPI_sdCard_cs(SPI_sdCard_cs == DEFAULT_PIN ? GPIO_2 : SPI_sdCard_cs) -{ -} - -//Accessors -Pin PinMapping::getI2C_sda() const -{ - return _I2C_sda; -} - -Pin PinMapping::getI2C_scl() const -{ - return _I2C_scl; -} - -Pin PinMapping::getSPI_mosi() const -{ - return _SPI_mosi; -} - -Pin PinMapping::getSPI_miso() const -{ - return _SPI_miso; -} - -Pin PinMapping::getSPI_clk() const -{ - return _SPI_clk; -} - -Pin PinMapping::getSPI_sdCard_cs() const -{ - return _SPI_sdCard_cs; -} - diff --git a/src/app/PinMapping.h b/src/app/PinMapping.h deleted file mode 100644 index 3375405..0000000 --- a/src/app/PinMapping.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef PINMAPPING_H -#define PINMAPPING_H -#include "definition.h" - -class PinMapping -{ - public: - PinMapping(); - PinMapping(const Pin I2C_sda, const Pin I2C_scl, const Pin SPI_mosi, const Pin SPI_miso, const Pin SPI_clk, const Pin SPI_sdCard_cs); - - Pin getI2C_sda() const; - Pin getI2C_scl() const; - - Pin getSPI_mosi() const; - Pin getSPI_miso() const; - Pin getSPI_clk() const; - Pin getSPI_sdCard_cs() const; - private: - const Pin _I2C_sda; - const Pin _I2C_scl; - const Pin _SPI_mosi; - const Pin _SPI_miso; - const Pin _SPI_clk; - const Pin _SPI_sdCard_cs; -}; - -#endif //PINMAPPING_H diff --git a/src/app/SAB.cpp b/src/app/SAB.cpp index 50e0d99..9639be6 100644 --- a/src/app/SAB.cpp +++ b/src/app/SAB.cpp @@ -1,16 +1,13 @@ #include "SAB.h" -SAB::SAB() : _screenConfig(128, 64, 0x3C), -_sdCardConfig(SPI_FULL_SPEED), -_display(_screenConfig.getWidth(), -_screenConfig.getHeight(), &Wire), +SAB::SAB() : _display(_boardConfig.getScreenWidth(), _boardConfig.getScreenHeight(), &Wire), _screenManager(_display), _rtc(), _rtcManager(_rtc), _sdCardManager(), _connectivityManager(NULL), //_webServerManager(80, &_sdCardManager), _webServer(80, &_sdCardManager), _ftpServer(21, &_sdCardManager, "ESP8266", "12345678"), -_pcf(0x27, Wire), +_pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire), _ioManager(_pcf), _taskSchedulerManager(_rtcManager), _error(0) @@ -22,18 +19,16 @@ _error(0) delay(200); //We initialize the pins for the I2C communication - Wire.begin(_pinConfig.getI2C_sda(), _pinConfig.getI2C_scl()); + Wire.begin(_boardConfig.getI2C_sda(), _boardConfig.getI2C_scl()); if(!_rtc.begin()) _error |= RTC_BEGIN_ERR; - if(!_display.begin(SSD1306_SWITCHCAPVCC, _screenConfig.getAddress())){ _error |= DISP_BEGIN_ERR; } - if(!_sdCardManager.begin(_pinConfig.getSPI_sdCard_cs(), _sdCardConfig.getSPISpeed())){ _error |= SDCARD_INIT_ERR; Serial.print("Failed to init SDCard : SPI_SPEED : "); Serial.print(_sdCardConfig.getSPISpeed()); Serial.print(" CS PIN : "); Serial.println(_pinConfig.getSPI_sdCard_cs());} + if(!_display.begin(SSD1306_SWITCHCAPVCC, _boardConfig.getI2C_screenAddress())){ _error |= DISP_BEGIN_ERR; } + if(!_sdCardManager.begin(_boardConfig.getSPI_SDCard_cs(), 8000000)){ _error |= SDCARD_INIT_ERR; Serial.print("Failed to init SDCard : SPI_SPEED : "); Serial.print(8000000); Serial.print(" CS PIN : "); Serial.println(_boardConfig.getSPI_SDCard_cs());} _connectivityManager = new ConnectivityManager(_sdCardManager); if(!_pcf.begin()){_error |= IO_INIT_ERR;} } -SAB::SAB(const PinMapping pinConfig, const ScreenConfig screenConfig, const SDCardConfig sdCardConfig, const unsigned int webServerPort) : _pinConfig(pinConfig), -_screenConfig(screenConfig), -_sdCardConfig(sdCardConfig), -_display(_screenConfig.getWidth(), _screenConfig.getHeight(), &Wire), +SAB::SAB(const BoardConfig boardConfig, const unsigned int webServerPort, const unsigned int ftpServerPort) : _boardConfig(boardConfig), +_display(_boardConfig.getScreenWidth(), _boardConfig.getScreenHeight(), &Wire), _screenManager(_display), _rtc(), _rtcManager(_rtc), @@ -41,8 +36,8 @@ _sdCardManager(), _connectivityManager(NULL), //_webServerManager(webServerPort, &_sdCardManager), _webServer(webServerPort, &_sdCardManager), -_ftpServer(21, &_sdCardManager, "ESP8266", "12345678"), -_pcf(0x27, Wire), +_ftpServer(ftpServerPort, &_sdCardManager, "ESP8266", "12345678"), +_pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire), _ioManager(_pcf), _taskSchedulerManager(_rtcManager), _error(0) @@ -53,10 +48,10 @@ _error(0) Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY); delay(200); //We initialize the pins for the I2C communication - Wire.begin(_pinConfig.getI2C_sda(), _pinConfig.getI2C_scl()); + Wire.begin(_boardConfig.getI2C_sda(), _boardConfig.getI2C_scl()); if(!_rtc.begin()) _error |= RTC_BEGIN_ERR; - if(!_display.begin(SSD1306_SWITCHCAPVCC, _screenConfig.getAddress())) _error |= DISP_BEGIN_ERR; - if(!_sdCardManager.begin(_pinConfig.getSPI_sdCard_cs(), _sdCardConfig.getSPISpeed())){ _error |= SDCARD_INIT_ERR; Serial.print("Failed to init SDCard : SPI_SPEED : "); Serial.print(_sdCardConfig.getSPISpeed()); Serial.print(" CS PIN : "); Serial.println(_pinConfig.getSPI_sdCard_cs());} + if(!_display.begin(SSD1306_SWITCHCAPVCC, _boardConfig.getI2C_screenAddress())) _error |= DISP_BEGIN_ERR; + if(!_sdCardManager.begin(_boardConfig.getSPI_SDCard_cs(), 8000000)){ _error |= SDCARD_INIT_ERR; Serial.print("Failed to init SDCard : SPI_SPEED : "); Serial.print(8000000); Serial.print(" CS PIN : "); Serial.println(_boardConfig.getSPI_SDCard_cs());} _connectivityManager = new ConnectivityManager(_sdCardManager); if(!_pcf.begin()){_error |= IO_INIT_ERR;} } @@ -116,19 +111,9 @@ PowerManager& SAB::getPowerManager() return _powerManager; } -ScreenConfig SAB::getScreenConfig() const +BoardConfig SAB::getBoardConfig() const { - return _screenConfig; -} - -PinMapping SAB::getPinConfig() const -{ - return _pinConfig; -} - -SDCardConfig SAB::getSdCardConfig() const -{ - return _sdCardConfig; + return _boardConfig; } const char *SAB::getSoftVersion() const diff --git a/src/app/SAB.h b/src/app/SAB.h index 54ca819..cf60227 100644 --- a/src/app/SAB.h +++ b/src/app/SAB.h @@ -1,8 +1,7 @@ #ifndef SAB_H #define SAB_H -#include "PinMapping.h" -#include "ScreenConfig.h" -#include "SDCardConfig.h" + +#include "BoardConfig.h" #include "RtcManager.h" #include "ScreenManager.h" #include "SDCardManager.h" @@ -24,7 +23,7 @@ class SAB enum Error {RTC_BEGIN_ERR = 1, DISP_BEGIN_ERR = 2, SDCARD_INIT_ERR = 4, IO_INIT_ERR = 8}; SAB(); - SAB(const PinMapping pinConfig, const ScreenConfig screenConfig, const SDCardConfig sdCardConfig, const unsigned int webServerPort); + SAB(const BoardConfig boardConfig, const unsigned int webServerPort = 80, const unsigned int ftpServerPort = 21); ~SAB() { delete _connectivityManager; @@ -40,16 +39,12 @@ class SAB IOManager& getIoManager(); TaskSchedulerManager& getTaskSchedulerManager(); PowerManager& getPowerManager(); - ScreenConfig getScreenConfig() const; - PinMapping getPinConfig() const; - SDCardConfig getSdCardConfig() const; + BoardConfig getBoardConfig() const; const char *getSoftVersion() const; unsigned char getError() const; private: void initGPIO(); - const PinMapping _pinConfig; - const ScreenConfig _screenConfig; - const SDCardConfig _sdCardConfig; + const BoardConfig _boardConfig; Adafruit_SSD1306 _display; ScreenManager _screenManager; diff --git a/src/app/SDCardConfig.cpp b/src/app/SDCardConfig.cpp deleted file mode 100644 index f71ab98..0000000 --- a/src/app/SDCardConfig.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include "SDCardConfig.h" - -SDCardConfig::SDCardConfig(const uint32_t spiSpeed) : _spiSpeed(spiSpeed) -{ -} - -const uint32_t SDCardConfig::getSPISpeed() const -{ - return _spiSpeed; -} - diff --git a/src/app/SDCardConfig.h b/src/app/SDCardConfig.h deleted file mode 100644 index 33d4f87..0000000 --- a/src/app/SDCardConfig.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef SDCARDCONFIG_H -#define SDCARDCONFIG_H - -class SDCardConfig -{ - public: - SDCardConfig(const uint32_t spiSpeed); - const uint32_t getSPISpeed() const; - private: - const uint32_t _spiSpeed; -}; - -#endif //SDCARDCONFIG_H diff --git a/src/app/ScreenConfig.cpp b/src/app/ScreenConfig.cpp deleted file mode 100644 index 336d238..0000000 --- a/src/app/ScreenConfig.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "ScreenConfig.h" - -ScreenConfig::ScreenConfig(const unsigned char width, const unsigned char height, const unsigned char address) : -_width(width), -_height(height), -_address(address) -{ -} - -unsigned char ScreenConfig::getWidth() const -{ - return _width; -} - -unsigned char ScreenConfig::getHeight() const -{ - return _height; -} - -unsigned char ScreenConfig::getAddress() const -{ - return _address; -} - diff --git a/src/app/ScreenConfig.h b/src/app/ScreenConfig.h deleted file mode 100644 index 43ce15b..0000000 --- a/src/app/ScreenConfig.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef SCREENCONFIG_H -#define SCREENCONFIG_H - -class ScreenConfig -{ - public: - ScreenConfig(const unsigned char width, const unsigned char height, const unsigned char address); - unsigned char getWidth() const; - unsigned char getHeight() const; - unsigned char getAddress() const; - private: - const unsigned char _width; - const unsigned char _height; - const unsigned char _address; -}; - -#endif //SCREENCONFIG_H diff --git a/src/app/app.ino b/src/app/app.ino index b6db938..738bcba 100644 --- a/src/app/app.ino +++ b/src/app/app.ino @@ -1,5 +1,4 @@ #include "definition.h" -#include "PinMapping.h" #include "SAB.h" #include "views.h" #include "webApi.h" diff --git a/src/app/webApi.cpp b/src/app/webApi.cpp index 80c9d40..75ee103 100644 --- a/src/app/webApi.cpp +++ b/src/app/webApi.cpp @@ -121,7 +121,7 @@ boolean sdCardMountApi(WEBServer::HttpRequestData &HRD, WiFiClient *w float *sdCardSize = (float *) &pV->pView->sdCardSize; char buffer[200]; - if(p->getSdCardManager().begin(p->getPinConfig().getSPI_sdCard_cs(), p->getSdCardConfig().getSPISpeed())) + if(p->getSdCardManager().begin(p->getBoardConfig().getSPI_SDCard_cs(), 8000000)) { sprintf(buffer,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{ \"status\" : \"ok\", \"card\" : \"mounted\" }"); *sdCardSize = p->getSdCardManager().getSize(GBYTE);