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

Refactored GPIO_Defs #412

Merged
merged 7 commits into from Nov 17, 2021
4 changes: 4 additions & 0 deletions ESPixelStick/src/FileMgr.cpp
Expand Up @@ -137,8 +137,12 @@ void c_FileMgr::SetSpiIoPins ()
SD.end ();
}


#ifdef ARDUINO_ARCH_ESP32
SPI.begin (clk_pin, miso_pin, mosi_pin, cs_pin);
#ifdef USE_MISO_PULLUP
pinMode (miso_pin, INPUT_PULLUP); // on some hardware MISO is missing required pull-up resistor, use internal pull-up.
#endif // def USE_MISO_PULLUP
if (!SD.begin (cs_pin))
#else
if (!SD.begin (SD_CARD_CS_PIN, SD_CARD_CLK_MHZ))
Expand Down
54 changes: 9 additions & 45 deletions ESPixelStick/src/GPIO_Defs.hpp
Expand Up @@ -74,51 +74,15 @@ typedef enum


// Platform specific GPIO definitions
#if defined(ARDUINO_ARCH_ESP8266)
//Output Manager
#define DEFAULT_UART_1_GPIO gpio_num_t::GPIO_NUM_2

// File Manager
#define SD_CARD_MISO_PIN gpio_num_t::GPIO_NUM_12
#define SD_CARD_MOSI_PIN gpio_num_t::GPIO_NUM_13
#define SD_CARD_CLK_PIN gpio_num_t::GPIO_NUM_14
#define SD_CARD_CS_PIN gpio_num_t::GPIO_NUM_15

#elif defined(ESP32_CAM)
//Output Manager
#define DEFAULT_UART_1_GPIO gpio_num_t::GPIO_NUM_0
#define DEFAULT_UART_2_GPIO gpio_num_t::GPIO_NUM_1
#define DEFAULT_RMT_0_GPIO gpio_num_t::GPIO_NUM_3
#define DEFAULT_RMT_1_GPIO gpio_num_t::GPIO_NUM_16
#define LED_GPIO gpio_num_t::GPIO_NUM_4

// File Manager
#define SD_CARD_MISO_PIN gpio_num_t::GPIO_NUM_2
#define SD_CARD_MOSI_PIN gpio_num_t::GPIO_NUM_15
#define SD_CARD_CLK_PIN gpio_num_t::GPIO_NUM_14
#define SD_CARD_CS_PIN gpio_num_t::GPIO_NUM_13

#if defined(ESP32_CAM)
# include "GPIO_Defs_ESP32_CAM.hpp"
#elif defined (ESP32_TTGO_T8)
# include "GPIO_Defs_ESP32_TTG_T8.hpp"
#elif defined(ARDUINO_ARCH_ESP8266)
# include "GPIO_Defs_ESP8266_Generic.hpp"
#elif defined(ARDUINO_ARCH_ESP32)
//Output Manager
#define DEFAULT_UART_1_GPIO gpio_num_t::GPIO_NUM_2
#define DEFAULT_UART_2_GPIO gpio_num_t::GPIO_NUM_13
#define DEFAULT_RMT_0_GPIO gpio_num_t::GPIO_NUM_12
#define DEFAULT_RMT_1_GPIO gpio_num_t::GPIO_NUM_14
#define DEFAULT_RMT_2_GPIO gpio_num_t::GPIO_NUM_32
#define DEFAULT_RMT_3_GPIO gpio_num_t::GPIO_NUM_33
// #define DEFAULT_RMT_4_GPIO gpio_num_t::GPIO_NUM_
// #define DEFAULT_RMT_5_GPIO gpio_num_t::GPIO_NUM_
// #define DEFAULT_RMT_6_GPIO gpio_num_t::GPIO_NUM_
// #define DEFAULT_RMT_7_GPIO gpio_num_t::GPIO_NUM_

// SPI Output
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25

// File Manager
#define SD_CARD_MISO_PIN gpio_num_t::GPIO_NUM_19
#define SD_CARD_MOSI_PIN gpio_num_t::GPIO_NUM_23
#define SD_CARD_CLK_PIN gpio_num_t::GPIO_NUM_18
#define SD_CARD_CS_PIN gpio_num_t::GPIO_NUM_4

# include "GPIO_Defs_ESP32_generic.hpp"
#else
# error "No valid platform definition"
#endif // ndef platform specific GPIO definitions
32 changes: 32 additions & 0 deletions ESPixelStick/src/GPIO_Defs_ESP32_CAM.hpp
@@ -0,0 +1,32 @@
#pragma once
/*
* GPIO_Defs_ESP32_CAM.hpp - Output Management class
*
* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
* Copyright (c) 2021 Shelby Merrick
* http://www.forkineye.com
*
* This program is provided free for you to use in any way that you wish,
* subject to the laws and regulations where you are using it. Due diligence
* is strongly suggested before using this code. Please give credit where due.
*
* The Author makes no warranty of any kind, express or implied, with regard
* to this program or the documentation contained in this document. The
* Author shall not be liable in any event for incidental or consequential
* damages in connection with, or arising out of, the furnishing, performance
* or use of these programs.
*
*/

//Output Manager
#define DEFAULT_UART_1_GPIO gpio_num_t::GPIO_NUM_0
#define DEFAULT_UART_2_GPIO gpio_num_t::GPIO_NUM_1
#define DEFAULT_RMT_0_GPIO gpio_num_t::GPIO_NUM_3
#define DEFAULT_RMT_1_GPIO gpio_num_t::GPIO_NUM_16
#define LED_GPIO gpio_num_t::GPIO_NUM_4

// File Manager
#define SD_CARD_MISO_PIN gpio_num_t::GPIO_NUM_2
#define SD_CARD_MOSI_PIN gpio_num_t::GPIO_NUM_15
#define SD_CARD_CLK_PIN gpio_num_t::GPIO_NUM_14
#define SD_CARD_CS_PIN gpio_num_t::GPIO_NUM_13
35 changes: 35 additions & 0 deletions ESPixelStick/src/GPIO_Defs_ESP32_TTGO_T8.hpp
@@ -0,0 +1,35 @@
#pragma once
/*
* GPIO_Defs_ESP32_TTGO_T8.hpp - Output Management class
*
* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
* Copyright (c) 2021 Shelby Merrick
* http://www.forkineye.com
*
* This program is provided free for you to use in any way that you wish,
* subject to the laws and regulations where you are using it. Due diligence
* is strongly suggested before using this code. Please give credit where due.
*
* The Author makes no warranty of any kind, express or implied, with regard
* to this program or the documentation contained in this document. The
* Author shall not be liable in any event for incidental or consequential
* damages in connection with, or arising out of, the furnishing, performance
* or use of these programs.
*
*/

//Output Manager
#define DEFAULT_UART_1_GPIO gpio_num_t::GPIO_NUM_0
#define DEFAULT_UART_2_GPIO gpio_num_t::GPIO_NUM_4
#define DEFAULT_RMT_0_GPIO gpio_num_t::GPIO_NUM_25
#define DEFAULT_RMT_1_GPIO gpio_num_t::GPIO_NUM_26
#define DEFAULT_RMT_2_GPIO gpio_num_t::GPIO_NUM_27
#define DEFAULT_RMT_3_GPIO gpio_num_t::GPIO_NUM_14
#define LED_SDA gpio_num_t::GPIO_NUM_21 // Green LED and SDA. Will light-up if PCA9865 is used.

// File Manager
#define SD_CARD_MISO_PIN gpio_num_t::GPIO_NUM_2
#define SD_CARD_MOSI_PIN gpio_num_t::GPIO_NUM_15
#define SD_CARD_CLK_PIN gpio_num_t::GPIO_NUM_14
#define SD_CARD_CS_PIN gpio_num_t::GPIO_NUM_13
#define USE_MISO_PULLUP
41 changes: 41 additions & 0 deletions ESPixelStick/src/GPIO_Defs_ESP32_generic.hpp
@@ -0,0 +1,41 @@
#pragma once
/*
* GPIO_Defs_ESP32_generic.hpp - Output Management class
*
* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
* Copyright (c) 2021 Shelby Merrick
* http://www.forkineye.com
*
* This program is provided free for you to use in any way that you wish,
* subject to the laws and regulations where you are using it. Due diligence
* is strongly suggested before using this code. Please give credit where due.
*
* The Author makes no warranty of any kind, express or implied, with regard
* to this program or the documentation contained in this document. The
* Author shall not be liable in any event for incidental or consequential
* damages in connection with, or arising out of, the furnishing, performance
* or use of these programs.
*
*/

//Output Manager
#define DEFAULT_UART_1_GPIO gpio_num_t::GPIO_NUM_2
#define DEFAULT_UART_2_GPIO gpio_num_t::GPIO_NUM_13
#define DEFAULT_RMT_0_GPIO gpio_num_t::GPIO_NUM_12
#define DEFAULT_RMT_1_GPIO gpio_num_t::GPIO_NUM_14
#define DEFAULT_RMT_2_GPIO gpio_num_t::GPIO_NUM_32
#define DEFAULT_RMT_3_GPIO gpio_num_t::GPIO_NUM_33
// #define DEFAULT_RMT_4_GPIO gpio_num_t::GPIO_NUM_
// #define DEFAULT_RMT_5_GPIO gpio_num_t::GPIO_NUM_
// #define DEFAULT_RMT_6_GPIO gpio_num_t::GPIO_NUM_
// #define DEFAULT_RMT_7_GPIO gpio_num_t::GPIO_NUM_

// SPI Output
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_15
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_25

// File Manager
#define SD_CARD_MISO_PIN gpio_num_t::GPIO_NUM_19
#define SD_CARD_MOSI_PIN gpio_num_t::GPIO_NUM_23
#define SD_CARD_CLK_PIN gpio_num_t::GPIO_NUM_18
#define SD_CARD_CS_PIN gpio_num_t::GPIO_NUM_4
28 changes: 28 additions & 0 deletions ESPixelStick/src/GPIO_Defs_ESP8266_Generic.hpp
@@ -0,0 +1,28 @@
#pragma once
/*
* GPIO_Defs_ESP8266_Generic.hpp - Output Management class
*
* Project: ESPixelStick - An ESP8266 / ESP32 and E1.31 based pixel driver
* Copyright (c) 2021 Shelby Merrick
* http://www.forkineye.com
*
* This program is provided free for you to use in any way that you wish,
* subject to the laws and regulations where you are using it. Due diligence
* is strongly suggested before using this code. Please give credit where due.
*
* The Author makes no warranty of any kind, express or implied, with regard
* to this program or the documentation contained in this document. The
* Author shall not be liable in any event for incidental or consequential
* damages in connection with, or arising out of, the furnishing, performance
* or use of these programs.
*
*/

//Output Manager
#define DEFAULT_UART_1_GPIO gpio_num_t::GPIO_NUM_2

// File Manager
#define SD_CARD_MISO_PIN gpio_num_t::GPIO_NUM_12
#define SD_CARD_MOSI_PIN gpio_num_t::GPIO_NUM_13
#define SD_CARD_CLK_PIN gpio_num_t::GPIO_NUM_14
#define SD_CARD_CS_PIN gpio_num_t::GPIO_NUM_15
11 changes: 9 additions & 2 deletions ESPixelStick/src/input/InputFPPRemotePlayFile.cpp
Expand Up @@ -60,8 +60,15 @@ c_InputFPPRemotePlayFile::~c_InputFPPRemotePlayFile ()
void c_InputFPPRemotePlayFile::Start (String & FileName, float SecondsElapsed, uint32_t PlayCount)
{
// DEBUG_START;

pCurrentFsmState->Start (FileName, SecondsElapsed, PlayCount);
if (FileMgr.SdCardIsInstalled ())
{
pCurrentFsmState->Start (FileName, SecondsElapsed, PlayCount);
}
else
{
DEBUG_V ("No SD Card installed. Ignore Start request");
fsm_PlayFile_state_Idle_imp.Init (this);
}

// DEBUG_END;
} // Start
Expand Down
2 changes: 2 additions & 0 deletions ESPixelStick/src/input/InputFPPRemotePlayFile.hpp
Expand Up @@ -49,12 +49,14 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem
friend class fsm_PlayFile_state_Starting;
friend class fsm_PlayFile_state_PlayingFile;
friend class fsm_PlayFile_state_Stopping;
friend class fsm_PlayFile_state_Error;
friend class fsm_PlayFile_state;

fsm_PlayFile_state_Idle fsm_PlayFile_state_Idle_imp;
fsm_PlayFile_state_Starting fsm_PlayFile_state_Starting_imp;
fsm_PlayFile_state_PlayingFile fsm_PlayFile_state_PlayingFile_imp;
fsm_PlayFile_state_Stopping fsm_PlayFile_state_Stopping_imp;
fsm_PlayFile_state_Error fsm_PlayFile_state_Error_imp;

fsm_PlayFile_state * pCurrentFsmState = &fsm_PlayFile_state_Idle_imp;

Expand Down
81 changes: 78 additions & 3 deletions ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp
Expand Up @@ -35,7 +35,8 @@ void fsm_PlayFile_state_Idle::Poll ()
//-----------------------------------------------------------------------------
IRAM_ATTR void fsm_PlayFile_state_Idle::TimerPoll ()
{
// nothing to do
p_Parent->FrameControl.ElapsedPlayTimeMS = 0;
p_Parent->FrameControl.TotalNumberOfFramesInSequence = 0;

} // fsm_PlayFile_state_Idle::TimerPoll

Expand Down Expand Up @@ -65,7 +66,7 @@ void fsm_PlayFile_state_Idle::Start (String& FileName, float ElapsedSeconds, uin
p_Parent->RemainingPlayCount = RemainingPlayCount;

// DEBUG_V (String (" FileName: ") + p_Parent->PlayItemName);
// DEBUG_V (String (" StartingFrameId: ") + p_Parent->FrameControl.StartingFrameId);
// DEBUG_V (String (" ElapsedPlayTimeMS: ") + p_Parent->FrameControl.ElapsedPlayTimeMS);
// DEBUG_V (String (" RemainingPlayCount: ") + p_Parent->RemainingPlayCount);

p_Parent->fsm_PlayFile_state_Starting_imp.Init (p_Parent);
Expand Down Expand Up @@ -314,9 +315,10 @@ void fsm_PlayFile_state_PlayingFile::Init (c_InputFPPRemotePlayFile* Parent)
--p_Parent->RemainingPlayCount;
// DEBUG_V (String ("RemainingPlayCount: ") + p_Parent->RemainingPlayCount);


if (!p_Parent->ParseFseqFile ())
{
p_Parent->fsm_PlayFile_state_Stopping_imp.Init (p_Parent);
p_Parent->fsm_PlayFile_state_Error_imp.Init (p_Parent);
break;
}

Expand Down Expand Up @@ -514,3 +516,76 @@ bool fsm_PlayFile_state_Stopping::Sync (String&, float)
return false;

} // fsm_PlayFile_state_Stopping::Sync


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void fsm_PlayFile_state_Error::Poll ()
{
// xDEBUG_START;

// xDEBUG_END;

} // fsm_PlayFile_state_Error::Poll

//-----------------------------------------------------------------------------
IRAM_ATTR void fsm_PlayFile_state_Error::TimerPoll ()
{
// xDEBUG_START;
// nothing to do
// xDEBUG_END;

} // fsm_PlayFile_state_Error::TimerPoll

//-----------------------------------------------------------------------------
void fsm_PlayFile_state_Error::Init (c_InputFPPRemotePlayFile* Parent)
{
// DEBUG_START;

p_Parent = Parent;
Parent->pCurrentFsmState = &(Parent->fsm_PlayFile_state_Error_imp);

// DEBUG_END;

} // fsm_PlayFile_state_Error::Init

//-----------------------------------------------------------------------------
void fsm_PlayFile_state_Error::Start (String& FileName, float ElapsedSeconds, uint32_t PlayCount)
{
// DEBUG_START;

if (FileName != p_Parent->GetFileName ())
{
p_Parent->fsm_PlayFile_state_Idle_imp.Start (FileName, ElapsedSeconds, PlayCount);
}

// DEBUG_END

} // fsm_PlayFile_state_Error::Start

//-----------------------------------------------------------------------------
void fsm_PlayFile_state_Error::Stop (void)
{
// DEBUG_START;

p_Parent->fsm_PlayFile_state_Idle_imp.Init (p_Parent);

// DEBUG_END;

} // fsm_PlayFile_state_Error::Stop

//-----------------------------------------------------------------------------
bool fsm_PlayFile_state_Error::Sync (String& FileName, float ElapsedSeconds)
{
// DEBUG_START;

if (FileName != p_Parent->GetFileName ())
{
p_Parent->fsm_PlayFile_state_Idle_imp.Start (FileName, ElapsedSeconds, 1);
}

// DEBUG_END;
return false;

} // fsm_PlayFile_state_Error::Sync
16 changes: 16 additions & 0 deletions ESPixelStick/src/input/InputFPPRemotePlayFileFsm.hpp
Expand Up @@ -115,3 +115,19 @@ class fsm_PlayFile_state_Stopping : public fsm_PlayFile_state
uint32_t PlayCount = 0;

}; // fsm_PlayFile_state_Stopping

/*****************************************************************************/
class fsm_PlayFile_state_Error : public fsm_PlayFile_state
{
public:
virtual void Poll ();
virtual void Init (c_InputFPPRemotePlayFile* Parent);
virtual void GetStateName (String& sName) { sName = F ("Error"); }
virtual void Start (String& FileName, float SecondsElapsed, uint32_t RemainingPlayCount);
virtual void Stop (void);
virtual bool Sync (String& FileName, float SecondsElapsed);
virtual IRAM_ATTR void TimerPoll ();

private:

}; // fsm_PlayFile_state_Error
9 changes: 9 additions & 0 deletions platformio.ini
Expand Up @@ -121,6 +121,15 @@ monitor_dtr = 0
build_flags =
-DESP32_CAM

; ESP32 TTGO-T8 V1.x
[env:esp32_ttgo_t8]
extends = esp32git ; use until 2.0.0 core makes it into PlatformIO
board = wemos_d1_mini32 ; use until platformio adds TTGO-T8
monitor_rts = 0
monitor_dtr = 0
build_flags =
-DESP32_TTGO_T8

; Generic Wemos D1 Mini 32
[env:d1_mini32]
extends = esp32git ; use until 2.0.0 core makes it into PlatformIO
Expand Down