Skip to content

Commit

Permalink
Merge pull request #525 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Fixed missing ESP32 start uart isr caused by adding the timer support for ESP8266
  • Loading branch information
forkineye committed May 6, 2022
2 parents 0a048de + c0c906f commit 8ef5710
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 67 deletions.
4 changes: 4 additions & 0 deletions ESPixelStick/src/FileMgr.cpp
Expand Up @@ -278,6 +278,7 @@ bool c_FileMgr::LoadConfigFile (const String& FileName, DeserializationHandler H
logcon (String(CN_stars) + CfgFileMessagePrefix + F ("Could not read file.") + CN_stars);
break;
}
logcon(RawFileData);
*/
fs::File file = LittleFS.open (FileName.c_str (), "r");
if (!file)
Expand Down Expand Up @@ -309,6 +310,9 @@ bool c_FileMgr::LoadConfigFile (const String& FileName, DeserializationHandler H
break;
}

// extern void PrettyPrint(DynamicJsonDocument & jsonStuff, String Name);
// PrettyPrint(jsonDoc, CfgFileMessagePrefix);

// DEBUG_V ("");
jsonDoc.garbageCollect ();

Expand Down
17 changes: 2 additions & 15 deletions ESPixelStick/src/output/OutputCommon.cpp
Expand Up @@ -42,10 +42,6 @@ c_OutputCommon::c_OutputCommon (c_OutputMgr::e_OutputChannelIds _OutputChannelId
// logcon (String ("UartId: '") + UartId + "'");
// logcon (String ("OutputChannelId: '") + OutputChannelId + "'");
// logcon (String ("OutputType: '") + OutputType + "'");
if (gpio_num_t (-1) != DataPin)
{
pinMode (DataPin, INPUT_PULLUP);
}

} // c_OutputCommon

Expand All @@ -54,15 +50,7 @@ c_OutputCommon::c_OutputCommon (c_OutputMgr::e_OutputChannelIds _OutputChannelId
c_OutputCommon::~c_OutputCommon ()
{
// DEBUG_START;
if(HasBeenInitialized)
{
if (gpio_num_t(-1) == DataPin)
{
return;
}
// DEBUG_V("Set Pin Mode");
pinMode(DataPin, INPUT_PULLUP);
}

// DEBUG_END;
} // ~c_OutputCommon

Expand All @@ -71,9 +59,8 @@ void c_OutputCommon::GetStatus (JsonObject & jsonStatus)
{
// DEBUG_START;

#define MicroSecondsInAsecond 1000000
jsonStatus[CN_id] = OutputChannelId;
jsonStatus["framerefreshrate"] = (0 == FrameRefreshTimeInMicroSec) ? 0 : int (MicroSecondsInAsecond / FrameRefreshTimeInMicroSec);
jsonStatus["framerefreshrate"] = (0 == FrameRefreshTimeInMicroSec) ? 0 : int(MicroSecondsInASecond / FrameRefreshTimeInMicroSec);
jsonStatus["FrameCount"] = FrameCount;

// DEBUG_END;
Expand Down
5 changes: 5 additions & 0 deletions ESPixelStick/src/output/OutputCommon.hpp
Expand Up @@ -58,6 +58,11 @@ class c_OutputCommon
virtual void ReadChannelData (size_t StartChannelId, size_t ChannelCount, byte *pTargetData);

protected:
#define MilliSecondsInASecond 1000
#define MicroSecondsInAmilliSecond 1000
#define MicroSecondsInASecond (MicroSecondsInAmilliSecond * MilliSecondsInASecond)
#define NanoSecondsInAMicroSecond 1000
#define NanoSecondsInASecond (MicroSecondsInASecond * NanoSecondsInAMicroSecond)

gpio_num_t DataPin = gpio_num_t (-1);
uart_port_t UartId = uart_port_t (-1);
Expand Down
39 changes: 29 additions & 10 deletions ESPixelStick/src/output/OutputMgr.cpp
Expand Up @@ -284,7 +284,7 @@ void c_OutputMgr::CreateJsonConfig (JsonObject& jsonConfig)
// DEBUG_V ("For Each Output Channel");
for (auto & CurrentChannel : OutputChannelDrivers)
{
// DEBUG_V (String("Create Section in Config file for the output channel: '") + CurrentChannel->GetOutputChannelId() + "'");
// DEBUG_V(String("Create Section in Config file for the output channel: '") + CurrentChannel.pOutputChannelDriver->GetOutputChannelId() + "'");
// create a record for this channel
JsonObject ChannelConfigData;
String sChannelId = String(CurrentChannel.pOutputChannelDriver->GetOutputChannelId());
Expand Down Expand Up @@ -380,8 +380,8 @@ void c_OutputMgr::CreateNewConfig ()
// DEBUG_V ("for each interface");
for (DriverInfo_t & CurrentOutputChannelDriver : OutputChannelDrivers)
{
// DEBUG_V(String("DriverId: ") + String(CurrentOutput.DriverId));
// DEBUG_V (String ("instantiate output type: ") + String (outputTypeId));
// DEBUG_V(String("DriverId: ") + String(CurrentOutputChannelDriver.DriverId));
// DEBUG_V (String ("instantiate output type: ") + String (CurrentOutputType.name));
InstantiateNewOutputChannel(CurrentOutputChannelDriver, CurrentOutputType.id, false);
// DEBUG_V ("");
} // end for each interface
Expand Down Expand Up @@ -485,7 +485,7 @@ void c_OutputMgr::InstantiateNewOutputChannel(DriverInfo_t & CurrentOutputChanne
// is there an existing driver?
if (nullptr != CurrentOutputChannelDriver.pOutputChannelDriver)
{
// DEBUG_V (String ("OutputChannelDrivers[uint(CurrentOutputChannel.DriverId)]->GetOutputType () '") + String (OutputChannelDrivers[uint(CurrentOutputChannel.DriverId)]->GetOutputType()) + String ("'"));
// DEBUG_V(String("OutputChannelDrivers[uint(CurrentOutputChannel.DriverId)]->GetOutputType () '") + String(OutputChannelDrivers[uint(CurrentOutputChannelDriver.DriverId)].pOutputChannelDriver->GetOutputType()) + String("'"));
// DEBUG_V (String ("NewOutputChannelType '") + int(NewOutputChannelType) + "'");

// DEBUG_V ("does the driver need to change?");
Expand Down Expand Up @@ -903,7 +903,7 @@ void c_OutputMgr::InstantiateNewOutputChannel(DriverInfo_t & CurrentOutputChanne
// DEBUG_V ("");
if (OM_IS_UART)
{
// DEBUG_V(CN_stars + String(F(" Starting UCS8903 UART for channel '")) + CurrentOutputChannel.DriverId + "'. " + CN_stars);
// DEBUG_V(CN_stars + String(F(" Starting UCS8903 UART for channel '")) + CurrentOutputChannelDriver.DriverId + "'. " + CN_stars);
CurrentOutputChannelDriver.pOutputChannelDriver = new c_OutputUCS8903Uart(CurrentOutputChannelDriver.DriverId, dataPin, UartId, OutputType_UCS8903);
// DEBUG_V ("");
break;
Expand Down Expand Up @@ -970,11 +970,17 @@ void c_OutputMgr::LoadConfig ()
// try to load and process the config file
if (!FileMgr.LoadConfigFile(ConfigFileName, [this](DynamicJsonDocument &JsonConfigDoc)
{
// extern void PrettyPrint(JsonConfigDoc & jsonStuff, String Name);
// PrettyPrint(JsonConfigDoc, "OM Load Config");

// DEBUG_V ("");
JsonObject JsonConfig = JsonConfigDoc.as<JsonObject> ();
// DEBUG_V ("");
this->ProcessJsonConfig (JsonConfig);
// DEBUG_V (""); }))

// extern void PrettyPrint(JsonObject & jsonStuff, String Name);
// PrettyPrint(JsonConfig, "OM Load Config");
// DEBUG_V ("Start");
this->ProcessJsonConfig(JsonConfig);
// DEBUG_V ("End");
}))
{
if (!IsBooting)
Expand Down Expand Up @@ -1009,6 +1015,9 @@ bool c_OutputMgr::ProcessJsonConfig (JsonObject& jsonConfig)

// DEBUG_V ("");

// extern void PrettyPrint(JsonObject & jsonStuff, String Name);
// PrettyPrint(jsonConfig, "ProcessJsonConfig");

do // once
{
if (false == jsonConfig.containsKey (CN_output_config))
Expand Down Expand Up @@ -1055,6 +1064,8 @@ bool c_OutputMgr::ProcessJsonConfig (JsonObject& jsonConfig)
JsonObject OutputChannelConfig = OutputChannelArray[String(CurrentOutputChannelDriver.DriverId).c_str()];
// DEBUG_V ("");

// PrettyPrint(OutputChannelConfig, "ProcessJson Channel Config");

// set a default value for channel type
uint32_t ChannelType = uint32_t (OutputType_End);
setFromJSON (ChannelType, OutputChannelConfig, CN_type);
Expand All @@ -1079,15 +1090,23 @@ bool c_OutputMgr::ProcessJsonConfig (JsonObject& jsonConfig)
continue;
}

// PrettyPrint(OutputChannelConfig, "ProcessJson Channel Config");

JsonObject OutputChannelDriverConfig = OutputChannelConfig[String (ChannelType)];
// DEBUG_V ("");
// DEBUG_V("");
// PrettyPrint(OutputChannelDriverConfig, "ProcessJson Channel Driver Config");
// DEBUG_V("");

// make sure the proper output type is running
InstantiateNewOutputChannel(CurrentOutputChannelDriver, e_OutputType(ChannelType));
// DEBUG_V ("");

// DEBUG_V();
// PrettyPrint(OutputChannelDriverConfig, "ProcessJson Channel Driver Config");
// DEBUG_V();

// send the config to the driver. At this level we have no idea what is in it
CurrentOutputChannelDriver.pOutputChannelDriver->SetConfig(OutputChannelDriverConfig);
// DEBUG_V();

} // end for each channel

Expand Down
36 changes: 12 additions & 24 deletions ESPixelStick/src/output/OutputServoPCA9685.cpp
Expand Up @@ -22,9 +22,6 @@ GNU General Public License for more details.

#include "OutputServoPCA9685.hpp"

#define SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH 650
#define SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH 2350

//----------------------------------------------------------------------------
c_OutputServoPCA9685::c_OutputServoPCA9685 (c_OutputMgr::e_OutputChannelIds OutputChannelId,
gpio_num_t outputGpio,
Expand All @@ -33,6 +30,18 @@ c_OutputServoPCA9685::c_OutputServoPCA9685 (c_OutputMgr::e_OutputChannelIds Outp
c_OutputCommon(OutputChannelId, outputGpio, uart, outputType)
{
// DEBUG_START;

for (ServoPCA9685Channel_t & currentServoPCA9685Channel : OutputList)
{
currentServoPCA9685Channel.Enabled = false;
currentServoPCA9685Channel.MinLevel = SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH;
currentServoPCA9685Channel.MaxLevel = SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH;
currentServoPCA9685Channel.PreviousValue = 0;
currentServoPCA9685Channel.IsReversed = false;
currentServoPCA9685Channel.Is16Bit = false;
currentServoPCA9685Channel.IsScaled = true;
}

// DEBUG_END;
} // c_OutputServoPCA9685

Expand All @@ -57,16 +66,6 @@ void c_OutputServoPCA9685::Begin ()

if(!HasBeenInitialized)
{
for (ServoPCA9685Channel_t & currentServoPCA9685Channel : OutputList)
{
currentServoPCA9685Channel.Enabled = false;
currentServoPCA9685Channel.MinLevel = SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH;
currentServoPCA9685Channel.MaxLevel = SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH;
currentServoPCA9685Channel.PreviousValue = 0;
currentServoPCA9685Channel.IsReversed = false;
currentServoPCA9685Channel.Is16Bit = false;
currentServoPCA9685Channel.IsScaled = true;
}
// DEBUG_V("Allocate PWM");
pwm = new Adafruit_PWMServoDriver();

Expand All @@ -84,15 +83,6 @@ void c_OutputServoPCA9685::Begin ()
} // Begin

//----------------------------------------------------------------------------
/*
* Validate that the current values meet our needs
*
* needs
* data set in the class elements
* returns
* true - no issues found
* false - had an issue and had to fix things
*/
bool c_OutputServoPCA9685::validate ()
{
// DEBUG_START;
Expand Down Expand Up @@ -188,8 +178,6 @@ bool c_OutputServoPCA9685::SetConfig (ArduinoJson::JsonObject & jsonConfig)
// DEBUG_V (String (" Enabled: ") + String (CurrentOutputChannel->Enabled));
// DEBUG_V (String (" MinLevel: ") + String (CurrentOutputChannel->MinLevel));
// DEBUG_V (String (" MaxLevel: ") + String (CurrentOutputChannel->MaxLevel));

++ChannelId;
}

} while (false);
Expand Down
28 changes: 15 additions & 13 deletions ESPixelStick/src/output/OutputServoPCA9685.hpp
Expand Up @@ -25,24 +25,27 @@ GNU General Public License for more details.

class c_OutputServoPCA9685 : public c_OutputCommon
{
public:
typedef struct ServoPCA9685Channel_s
private:
#define SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH 650
#define SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH 2350

public: typedef struct ServoPCA9685Channel_s
{
bool Enabled;
uint16_t MinLevel;
uint16_t MaxLevel;
uint16_t PreviousValue;
bool IsReversed;
bool Is16Bit;
bool IsScaled;
bool Enabled = false;
uint16_t MinLevel = SERVO_PCA9685_OUTPUT_MIN_PULSE_WIDTH;
uint16_t MaxLevel = SERVO_PCA9685_OUTPUT_MAX_PULSE_WIDTH;
uint16_t PreviousValue = 0;
bool IsReversed = false;
bool Is16Bit = false;
bool IsScaled = true;

} ServoPCA9685Channel_t;

// These functions are inherited from c_OutputCommon
c_OutputServoPCA9685 (c_OutputMgr::e_OutputChannelIds OutputChannelId,
gpio_num_t outputGpio,
uart_port_t uart,
c_OutputMgr::e_OutputType outputType);
gpio_num_t outputGpio,
uart_port_t uart,
c_OutputMgr::e_OutputType outputType);
virtual ~c_OutputServoPCA9685 ();

// functions to be provided by the derived class
Expand All @@ -54,7 +57,6 @@ class c_OutputServoPCA9685 : public c_OutputCommon
void GetStatus (ArduinoJson::JsonObject & jsonStatus) { c_OutputCommon::GetStatus (jsonStatus); }
size_t GetNumChannelsNeeded () { return Num_Channels; }


private:
# define OM_SERVO_PCA9685_CHANNEL_LIMIT 16
# define OM_SERVO_PCA9685_UPDATE_INTERVAL_NAME CN_updateinterval
Expand Down
13 changes: 10 additions & 3 deletions ESPixelStick/src/output/OutputUart.cpp
Expand Up @@ -120,6 +120,7 @@ static void IRAM_ATTR timer_intr_handler()
if (nullptr != currentChannel)
{
// U0F = '.';
// (*((volatile uint32_t *)(UART_FIFO_AHB_REG(0)))) = (uint32_t)('.');
currentChannel->ISR_Timer_Handler();
}
}
Expand Down Expand Up @@ -163,8 +164,10 @@ c_OutputUart::~c_OutputUart ()
*/
static void IRAM_ATTR uart_intr_handler (void* param)
{
// (*((volatile uint32_t *)(UART_FIFO_AHB_REG(0)))) = (uint32_t)('.');
if (param)
{
// (*((volatile uint32_t *)(UART_FIFO_AHB_REG(0)))) = (uint32_t)('|');
reinterpret_cast<c_OutputUart *>(param)->ISR_UART_Handler();
}

Expand Down Expand Up @@ -464,13 +467,14 @@ void c_OutputUart::InitializeUart()
// DEBUG_V (String ("UART_CLKDIV_REG (OutputUartConfig.UartId): 0x") + String (*((uint32_t*)UART_CLKDIV_REG (OutputUartConfig.UartId)), HEX));

// Set TX FIFO trigger.
// DEBUG_V(String("FiFoTriggerLevel: ") + String(OutputUartConfig.FiFoTriggerLevel));
WRITE_PERI_REG(UART_CONF1(OutputUartConfig.UartId), OutputUartConfig.FiFoTriggerLevel << UART_TXFIFO_EMPTY_THRHD_S);

CLEAR_PERI_REG_MASK(UART_CONF0(OutputUartConfig.UartId), UART_INV_MASK);
if (OutputUartConfig.InvertOutputPolarity)
{
// DEBUG_V("Invert the output");
CLEAR_PERI_REG_MASK(UART_CONF0(OutputUartConfig.UartId), UART_INV_MASK);
SET_PERI_REG_MASK (UART_CONF0(OutputUartConfig.UartId), (BIT(22)));
SET_PERI_REG_MASK(UART_CONF0(OutputUartConfig.UartId), (BIT(22)));
}

// #define SupportSetUartBaudrateWorkAround
Expand Down Expand Up @@ -986,7 +990,10 @@ void c_OutputUart::StartNewFrame()
ISR_Handler_SendIntensityData();
EnableUartInterrupts();
}
#endif // defined(ARDUINO_ARCH_ESP8266)
#else
ISR_Handler_SendIntensityData();
EnableUartInterrupts();
#endif // defined(ARDUINO_ARCH_ESP32)

// DEBUG_END;

Expand Down
2 changes: 2 additions & 0 deletions html/index.html
Expand Up @@ -469,6 +469,8 @@
<output id="usedBytes"></output>
<label class="control-label col-sm-2" for="remainingBytes">SD Remaining (MB):</label>
<output id="remainingBytes"></output>
<label class="control-label col-sm-2" for="FileNameLen">File Name max len:</label>
<output id="FileNameLen" value="64"></output>
</form>
<br />
<div>
Expand Down
2 changes: 1 addition & 1 deletion html/script.js
Expand Up @@ -620,7 +620,7 @@ function ProcessModeConfigurationDataRelay(RelayConfig)
let EnabledPattern = '<td><input type="checkbox" id="Enabled_' + (CurrentRowId) + '"></td>';
let InvertedPattern = '<td><input type="checkbox" id="Inverted_' + (CurrentRowId) + '"></td>';
let PwmPattern = '<td><input type="checkbox" id="Pwm_' + (CurrentRowId) + '"></td>';
let gpioPattern = '<td><input type="number" id="gpioId_' + (CurrentRowId) + '"step="1" min="0" max="24" value="30" class="form-control is-valid"></td>';
let gpioPattern = '<td><input type="number" id="gpioId_' + (CurrentRowId) + '"step="1" min="0" max="34" value="34" class="form-control is-valid"></td>';
let threshholdPattern = '<td><input type="number" id="threshhold_' + (CurrentRowId) + '"step="1" min="0" max="255" value="300" class="form-control is-valid"></td>';
let PwmFreqPattern = '';
if (true === HasPwmFrequency) {
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Expand Up @@ -85,7 +85,7 @@ extra_scripts = ${env.extra_scripts}
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
[esp32git]
extends = esp32
build_flags = ${esp32.build_flags}
build_flags = ${esp32.build_flags} -mtext-section-literals
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-idf-master
platform_packages =
; framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#master
Expand Down

0 comments on commit 8ef5710

Please sign in to comment.