mirror of
https://github.com/meshtastic/firmware.git
synced 2026-11-06 14:24:20 -05:00
* initial commit * enable power save * implement mesh LED * add ADS1115+AW35615 for wio tracker L2 * add ES8311, GT911, AW35615, LP5814 to I2C scanner * update commit references * move variant.cpp to extras * update hw_model * update lovyanGFX * point to device-ui commit * trunk fmt * fix IO expander (have to take from SensorLib for now as long as AudioThread has the limitation to only support SensorLib and the previous IO expander clashes with duplicate names in arduino-audio-driver) * workaround duplicate defined symbol * remove SensorLib; add lightweight Pca9555 class and use unified USE_PCA95X5; add wake button detection * keep TP_INT disabled(OUTPUT) as we use wake button for wakeup * PA off by default, enabled when playing sound; add some delay because typical class-D amps (NS4150 family) spec 20–50ms for the output stage to reach full swing after power-on * refactored AW35615 into new external library * local revert of PR10571 as this PR completely breaks the alert sound * fix detection of ADS1115 * update device-ui commit reference * add synchronisation to IO expander and call toggleDisplay() on wake button press * add battery curve, fix io expander sync * add SPILock, simplify macro usage * update device-ui * fix wakeup from sleep * revert because of #11604 * use new AUDIO_AMP_SETTLE_MS * remove test logs * enable BaseUI * use touch screen * refactor wakekey thread * fix wake button toggle screen on/off * fix battery percentage and plugIn state * Update src/graphics/TFTDisplay.cpp Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * consider to return I2C errors to make coderabbi happy * fix warnings * use Throttle for millis comparison * fix endTransmission in write * make the rabbit happy * spli targets -tft / non-tft * fix compile * revert forced use of Throttle * remove MeshLED * add HW_MODEL --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
122 lines
3.2 KiB
C++
122 lines
3.2 KiB
C++
#pragma once
|
|
#include "PowerFSM.h"
|
|
#include "SPILock.h"
|
|
#include "concurrency/OSThread.h"
|
|
#include "configuration.h"
|
|
#include "main.h"
|
|
#include "sleep.h"
|
|
#include <memory>
|
|
|
|
#ifdef HAS_I2S
|
|
#include <AudioFileSourcePROGMEM.h>
|
|
#include <AudioGeneratorRTTTL.h>
|
|
#include <AudioOutputI2S.h>
|
|
#include <ESP8266SAM.h>
|
|
|
|
// A board with an I2S amplifier opts in by defining AUDIO_AMP_ENABLE(on) in its variant.h to power the
|
|
// amp on/off around playback (e.g. an enable pin on an I/O expander). The includes below expose the
|
|
// expander instances (io / mcpIoExpander) those macros typically reference.
|
|
#ifdef USE_PCA95X5
|
|
#include PCA95X5_INC
|
|
extern PCA95X5_CLS io;
|
|
#endif
|
|
|
|
#ifdef USE_MCP23017
|
|
#include "platform/esp32/ExtensionIOMCP23017.h"
|
|
#endif
|
|
|
|
#define AUDIO_THREAD_INTERVAL_MS 100
|
|
|
|
class AudioThread : public concurrency::OSThread
|
|
{
|
|
public:
|
|
AudioThread() : OSThread("Audio") { initOutput(); }
|
|
|
|
void beginRttl(const void *data, uint32_t len)
|
|
{
|
|
ampEnable(true);
|
|
setCPUFast(true);
|
|
rtttlFile = std::unique_ptr<AudioFileSourcePROGMEM>(new AudioFileSourcePROGMEM(data, len));
|
|
i2sRtttl = std::unique_ptr<AudioGeneratorRTTTL>(new AudioGeneratorRTTTL());
|
|
i2sRtttl->begin(rtttlFile.get(), audioOut.get());
|
|
}
|
|
|
|
// Also handles actually playing the RTTTL, needs to be called in loop
|
|
bool isPlaying()
|
|
{
|
|
if (i2sRtttl != nullptr) {
|
|
return i2sRtttl->isRunning() && i2sRtttl->loop();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void stop()
|
|
{
|
|
if (i2sRtttl != nullptr) {
|
|
i2sRtttl->stop();
|
|
i2sRtttl = nullptr;
|
|
}
|
|
|
|
rtttlFile = nullptr;
|
|
|
|
setCPUFast(false);
|
|
ampEnable(false);
|
|
}
|
|
|
|
void readAloud(const char *text)
|
|
{
|
|
if (i2sRtttl != nullptr) {
|
|
i2sRtttl->stop();
|
|
i2sRtttl = nullptr;
|
|
}
|
|
|
|
ampEnable(true);
|
|
auto sam = std::unique_ptr<ESP8266SAM>(new ESP8266SAM);
|
|
sam->Say(audioOut.get(), text);
|
|
setCPUFast(false);
|
|
audioOut->stop();
|
|
ampEnable(false);
|
|
}
|
|
|
|
protected:
|
|
int32_t runOnce() override
|
|
{
|
|
canSleep = true; // Assume we should not keep the board awake
|
|
|
|
// if (i2sRtttl != nullptr && i2sRtttl->isRunning()) {
|
|
// i2sRtttl->loop();
|
|
// }
|
|
return AUDIO_THREAD_INTERVAL_MS;
|
|
}
|
|
|
|
private:
|
|
// Amps like the NS4150 need time to leave shutdown, longer when the enable is an I/O expander write.
|
|
// Without a variant's AUDIO_AMP_SETTLE_MS the short system tones are over before any audio gets out.
|
|
static void ampEnable(bool on)
|
|
{
|
|
#ifdef AUDIO_AMP_ENABLE
|
|
AUDIO_AMP_ENABLE(on);
|
|
#ifdef AUDIO_AMP_SETTLE_MS
|
|
if (on)
|
|
delay(AUDIO_AMP_SETTLE_MS);
|
|
#endif
|
|
#else
|
|
(void)on;
|
|
#endif
|
|
}
|
|
|
|
void initOutput()
|
|
{
|
|
audioOut = std::unique_ptr<AudioOutputI2S>(new AudioOutputI2S(1, AudioOutputI2S::EXTERNAL_I2S));
|
|
audioOut->SetPinout(DAC_I2S_BCK, DAC_I2S_WS, DAC_I2S_DOUT, DAC_I2S_MCLK);
|
|
audioOut->SetGain(0.2);
|
|
};
|
|
|
|
std::unique_ptr<AudioGeneratorRTTTL> i2sRtttl = nullptr;
|
|
std::unique_ptr<AudioOutputI2S> audioOut = nullptr;
|
|
|
|
std::unique_ptr<AudioFileSourcePROGMEM> rtttlFile = nullptr;
|
|
};
|
|
|
|
#endif
|