kopia lustrzana https://github.com/meshtastic/firmware
RTTTL ringtones on T-Deck / T-Watch S3 and potentially more I2S audio enabled devices (#2917)
* WIP * ESP8266 SAM fun * I2S audio / ext. notification module * Remove * Protos * Add use_i2s_as_buzzer from protos * Fixes * Stuff * Thing * Ext. Notification working(ish) * Remove SAM commented code * Trunk upgrade * Trunk * Fixes * Slow not fast... :-| * T-Deck and T-Watch don't use normal buttons * Stop ext. notification nagging with touchscreen as well * Add button gpio back for T-Deck, but guard against long-press during ext. notification * Ext. notification wrap up * Better place to guard against long-press false positives * Adjust default gain and guard against non-i2s devices referencing audio-thread * Simplify guard logic with a boolean * Supress uninitMemberVar * Protos merge got out of wack * Trunk resolution * Remove extra crap * Cleanup and thread-interval * Default to alert message buzzer and add nag timeout * Formattingpull/2998/head^2
rodzic
35938392f1
commit
d14d2c89c3
|
@ -0,0 +1,77 @@
|
|||
#pragma once
|
||||
#include "PowerFSM.h"
|
||||
#include "concurrency/OSThread.h"
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
#include "sleep.h"
|
||||
|
||||
#ifdef HAS_I2S
|
||||
#include <AudioFileSourcePROGMEM.h>
|
||||
#include <AudioGeneratorRTTTL.h>
|
||||
#include <AudioOutputI2S.h>
|
||||
#include <ESP8266SAM.h>
|
||||
|
||||
#define AUDIO_THREAD_INTERVAL_MS 100
|
||||
|
||||
class AudioThread : public concurrency::OSThread
|
||||
{
|
||||
public:
|
||||
AudioThread() : OSThread("AudioThread") { initOutput(); }
|
||||
|
||||
void beginRttl(const void *data, uint32_t len)
|
||||
{
|
||||
setCPUFast(true);
|
||||
rtttlFile = new AudioFileSourcePROGMEM(data, len);
|
||||
i2sRtttl = new AudioGeneratorRTTTL();
|
||||
i2sRtttl->begin(rtttlFile, audioOut);
|
||||
}
|
||||
|
||||
bool isPlaying()
|
||||
{
|
||||
if (i2sRtttl != nullptr) {
|
||||
return i2sRtttl->isRunning() && i2sRtttl->loop();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
if (i2sRtttl != nullptr) {
|
||||
i2sRtttl->stop();
|
||||
delete i2sRtttl;
|
||||
i2sRtttl = nullptr;
|
||||
}
|
||||
if (rtttlFile != nullptr) {
|
||||
delete rtttlFile;
|
||||
rtttlFile = nullptr;
|
||||
}
|
||||
|
||||
setCPUFast(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:
|
||||
void initOutput()
|
||||
{
|
||||
audioOut = new AudioOutputI2S(1, AudioOutputI2S::EXTERNAL_I2S);
|
||||
audioOut->SetPinout(DAC_I2S_BCK, DAC_I2S_WS, DAC_I2S_DOUT);
|
||||
audioOut->SetGain(0.2);
|
||||
};
|
||||
|
||||
AudioGeneratorRTTTL *i2sRtttl = nullptr;
|
||||
AudioOutputI2S *audioOut;
|
||||
|
||||
AudioFileSourcePROGMEM *rtttlFile;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -5,6 +5,7 @@
|
|||
#include "configuration.h"
|
||||
#include "graphics/Screen.h"
|
||||
#include "main.h"
|
||||
#include "modules/ExternalNotificationModule.h"
|
||||
#include "power.h"
|
||||
#include <OneButton.h>
|
||||
|
||||
|
@ -205,6 +206,12 @@ class ButtonThread : public concurrency::OSThread
|
|||
|
||||
static void userButtonPressedLongStart()
|
||||
{
|
||||
#ifdef T_DECK
|
||||
// False positive long-press triggered on T-Deck with i2s audio, so short circuit
|
||||
if (moduleConfig.external_notification.enabled && (externalNotificationModule->nagCycleCutoff != UINT32_MAX)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (millis() > 30 * 1000) {
|
||||
LOG_DEBUG("Long press start!\n");
|
||||
longPressTime = millis();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "InputBroker.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "configuration.h"
|
||||
#include "modules/ExternalNotificationModule.h"
|
||||
|
||||
TouchScreenImpl1 *touchScreenImpl1;
|
||||
|
||||
|
@ -63,7 +64,11 @@ void TouchScreenImpl1::onEvent(const TouchEvent &event)
|
|||
break;
|
||||
}
|
||||
case TOUCH_ACTION_TAP: {
|
||||
powerFSM.trigger(EVENT_INPUT);
|
||||
if (moduleConfig.external_notification.enabled && (externalNotificationModule->nagCycleCutoff != UINT32_MAX)) {
|
||||
externalNotificationModule->stopNow();
|
||||
} else {
|
||||
powerFSM.trigger(EVENT_INPUT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -84,6 +84,11 @@ NRF52Bluetooth *nrf52Bluetooth;
|
|||
#include "AmbientLightingThread.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAS_I2S
|
||||
#include "AudioThread.h"
|
||||
AudioThread *audioThread;
|
||||
#endif
|
||||
|
||||
using namespace concurrency;
|
||||
|
||||
// We always create a screen object, but we only init it if we find the hardware
|
||||
|
@ -122,6 +127,7 @@ ATECCX08A atecc;
|
|||
#ifdef T_WATCH_S3
|
||||
Adafruit_DRV2605 drv;
|
||||
#endif
|
||||
|
||||
bool isVibrating = false;
|
||||
|
||||
bool eink_found = true;
|
||||
|
@ -671,6 +677,11 @@ void setup()
|
|||
}
|
||||
nodeStatus->observe(&nodeDB.newStatus);
|
||||
|
||||
#ifdef HAS_I2S
|
||||
LOG_DEBUG("Starting audio thread\n");
|
||||
audioThread = new AudioThread();
|
||||
#endif
|
||||
|
||||
service.init();
|
||||
|
||||
// Now that the mesh service is created, create any modules
|
||||
|
@ -880,7 +891,6 @@ void setup()
|
|||
// This must be _after_ service.init because we need our preferences loaded from flash to have proper timeout values
|
||||
PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS
|
||||
powerFSMthread = new PowerFSMThread();
|
||||
|
||||
setCPUFast(false); // 80MHz is fine for our slow peripherals
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,12 @@ extern ATECCX08A atecc;
|
|||
#include <Adafruit_DRV2605.h>
|
||||
extern Adafruit_DRV2605 drv;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_I2S
|
||||
#include "AudioThread.h"
|
||||
extern AudioThread *audioThread;
|
||||
#endif
|
||||
|
||||
extern bool isVibrating;
|
||||
|
||||
extern int TCPPort; // set by Portduino
|
||||
|
|
|
@ -245,9 +245,12 @@ void NodeDB::installDefaultModuleConfig()
|
|||
moduleConfig.external_notification.output_ms = 1000;
|
||||
moduleConfig.external_notification.nag_timeout = 60;
|
||||
#endif
|
||||
#ifdef T_WATCH_S3
|
||||
// Don't worry about the other settings, we'll use the DRV2056 behavior for notifications
|
||||
#ifdef HAS_I2S
|
||||
// Don't worry about the other settings for T-Watch, we'll also use the DRV2056 behavior for notifications
|
||||
moduleConfig.external_notification.enabled = true;
|
||||
moduleConfig.external_notification.use_i2s_as_buzzer = true;
|
||||
moduleConfig.external_notification.alert_message_buzzer = true;
|
||||
moduleConfig.external_notification.nag_timeout = 60;
|
||||
#endif
|
||||
#ifdef NANO_G2_ULTRA
|
||||
moduleConfig.external_notification.enabled = true;
|
||||
|
|
|
@ -20,11 +20,10 @@
|
|||
#include "Router.h"
|
||||
#include "buzz/buzz.h"
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
#include "mesh/generated/meshtastic/rtttl.pb.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#ifdef HAS_NCP5623
|
||||
#include <graphics/RAKled.h>
|
||||
|
||||
|
@ -54,6 +53,8 @@ bool ascending = true;
|
|||
#endif
|
||||
#define EXT_NOTIFICATION_MODULE_OUTPUT_MS 1000
|
||||
|
||||
#define EXT_NOTIFICATION_DEFAULT_THREAD_MS 25
|
||||
|
||||
#define ASCII_BELL 0x07
|
||||
|
||||
meshtastic_RTTTLConfig rtttlConfig;
|
||||
|
@ -71,7 +72,12 @@ int32_t ExternalNotificationModule::runOnce()
|
|||
if (!moduleConfig.external_notification.enabled) {
|
||||
return INT32_MAX; // we don't need this thread here...
|
||||
} else {
|
||||
if ((nagCycleCutoff < millis()) && !rtttl::isPlaying()) {
|
||||
|
||||
bool isPlaying = rtttl::isPlaying();
|
||||
#ifdef HAS_I2S
|
||||
isPlaying = rtttl::isPlaying() || audioThread->isPlaying();
|
||||
#endif
|
||||
if ((nagCycleCutoff < millis()) && !isPlaying) {
|
||||
// let the song finish if we reach timeout
|
||||
nagCycleCutoff = UINT32_MAX;
|
||||
LOG_INFO("Turning off external notification: ");
|
||||
|
@ -132,6 +138,16 @@ int32_t ExternalNotificationModule::runOnce()
|
|||
#endif
|
||||
}
|
||||
|
||||
// Play RTTTL over i2s audio interface if enabled as buzzer
|
||||
#ifdef HAS_I2S
|
||||
if (moduleConfig.external_notification.use_i2s_as_buzzer) {
|
||||
if (audioThread->isPlaying()) {
|
||||
// Continue playing
|
||||
} else if (isNagging && (nagCycleCutoff >= millis())) {
|
||||
audioThread->beginRttl(rtttlConfig.ringtone, strlen_P(rtttlConfig.ringtone));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// now let the PWM buzzer play
|
||||
if (moduleConfig.external_notification.use_pwm) {
|
||||
if (rtttl::isPlaying()) {
|
||||
|
@ -142,7 +158,7 @@ int32_t ExternalNotificationModule::runOnce()
|
|||
}
|
||||
}
|
||||
|
||||
return 25;
|
||||
return EXT_NOTIFICATION_DEFAULT_THREAD_MS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,6 +191,7 @@ void ExternalNotificationModule::setExternalOn(uint8_t index)
|
|||
digitalWrite(output, (moduleConfig.external_notification.active ? true : false));
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef HAS_NCP5623
|
||||
if (rgb_found.type == ScanI2C::NCP5623) {
|
||||
rgb.setColor(red, green, blue);
|
||||
|
@ -226,6 +243,9 @@ bool ExternalNotificationModule::getExternal(uint8_t index)
|
|||
void ExternalNotificationModule::stopNow()
|
||||
{
|
||||
rtttl::stop();
|
||||
#ifdef HAS_I2S
|
||||
audioThread->stop();
|
||||
#endif
|
||||
nagCycleCutoff = 1; // small value
|
||||
isNagging = false;
|
||||
setIntervalFromNow(0);
|
||||
|
@ -246,6 +266,7 @@ ExternalNotificationModule::ExternalNotificationModule()
|
|||
// moduleConfig.external_notification.alert_message = true;
|
||||
// moduleConfig.external_notification.alert_message_buzzer = true;
|
||||
// moduleConfig.external_notification.alert_message_vibra = true;
|
||||
// moduleConfig.external_notification.use_i2s_as_buzzer = true;
|
||||
|
||||
// moduleConfig.external_notification.active = true;
|
||||
// moduleConfig.external_notification.alert_bell = 1;
|
||||
|
@ -255,6 +276,13 @@ ExternalNotificationModule::ExternalNotificationModule()
|
|||
// moduleConfig.external_notification.output_vibra = 28; // RAK4631 IO7
|
||||
// moduleConfig.external_notification.nag_timeout = 300;
|
||||
|
||||
// T-Watch / T-Deck i2s audio as buzzer:
|
||||
// moduleConfig.external_notification.enabled = true;
|
||||
// moduleConfig.external_notification.nag_timeout = 300;
|
||||
// moduleConfig.external_notification.output_ms = 1000;
|
||||
// moduleConfig.external_notification.use_i2s_as_buzzer = true;
|
||||
// moduleConfig.external_notification.alert_message_buzzer = true;
|
||||
|
||||
if (moduleConfig.external_notification.enabled) {
|
||||
if (!nodeDB.loadProto(rtttlConfigFile, meshtastic_RTTTLConfig_size, sizeof(meshtastic_RTTTLConfig),
|
||||
&meshtastic_RTTTLConfig_msg, &rtttlConfig)) {
|
||||
|
@ -309,14 +337,13 @@ ExternalNotificationModule::ExternalNotificationModule()
|
|||
ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshPacket &mp)
|
||||
{
|
||||
if (moduleConfig.external_notification.enabled) {
|
||||
#if T_WATCH_S3
|
||||
#ifdef T_WATCH_S3
|
||||
drv.setWaveform(0, 75);
|
||||
drv.setWaveform(1, 56);
|
||||
drv.setWaveform(2, 0);
|
||||
drv.go();
|
||||
#endif
|
||||
if (getFrom(&mp) != nodeDB.getNodeNum()) {
|
||||
|
||||
// Check if the message contains a bell character. Don't do this loop for every pin, just once.
|
||||
auto &p = mp.decoded;
|
||||
bool containsBell = false;
|
||||
|
@ -359,7 +386,11 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
|
|||
if (!moduleConfig.external_notification.use_pwm) {
|
||||
setExternalOn(2);
|
||||
} else {
|
||||
#ifdef HAS_I2S
|
||||
audioThread->beginRttl(rtttlConfig.ringtone, strlen_P(rtttlConfig.ringtone));
|
||||
#else
|
||||
rtttl::begin(config.device.buzzer_gpio, rtttlConfig.ringtone);
|
||||
#endif
|
||||
}
|
||||
if (moduleConfig.external_notification.nag_timeout) {
|
||||
nagCycleCutoff = millis() + moduleConfig.external_notification.nag_timeout * 1000;
|
||||
|
@ -394,10 +425,16 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP
|
|||
if (moduleConfig.external_notification.alert_message_buzzer) {
|
||||
LOG_INFO("externalNotificationModule - Notification Module (Buzzer)\n");
|
||||
isNagging = true;
|
||||
if (!moduleConfig.external_notification.use_pwm) {
|
||||
if (!moduleConfig.external_notification.use_pwm && !moduleConfig.external_notification.use_i2s_as_buzzer) {
|
||||
setExternalOn(2);
|
||||
} else {
|
||||
#ifdef HAS_I2S
|
||||
if (moduleConfig.external_notification.use_i2s_as_buzzer) {
|
||||
audioThread->beginRttl(rtttlConfig.ringtone, strlen_P(rtttlConfig.ringtone));
|
||||
}
|
||||
#else
|
||||
rtttl::begin(config.device.buzzer_gpio, rtttlConfig.ringtone);
|
||||
#endif
|
||||
}
|
||||
if (moduleConfig.external_notification.nag_timeout) {
|
||||
nagCycleCutoff = millis() + moduleConfig.external_notification.nag_timeout * 1000;
|
||||
|
|
|
@ -49,4 +49,5 @@ virtualCallInConstructor
|
|||
|
||||
passedByValue:*/RedirectablePrint.h
|
||||
|
||||
internalAstError:*/CrossPlatformCryptoEngine.cpp
|
||||
internalAstError:*/CrossPlatformCryptoEngine.cpp
|
||||
uninitMemberVar:*/AudioThread.h
|
|
@ -2,8 +2,8 @@
|
|||
[env:t-deck]
|
||||
extends = esp32s3_base
|
||||
board = t-deck
|
||||
upload_protocol = esp-builtin
|
||||
debug_tool = esp-builtin
|
||||
upload_protocol = esptool
|
||||
#upload_port = COM29
|
||||
|
||||
build_flags = ${esp32_base.build_flags}
|
||||
-DT_DECK
|
||||
|
@ -12,4 +12,6 @@ build_flags = ${esp32_base.build_flags}
|
|||
-Ivariants/t-deck
|
||||
|
||||
lib_deps = ${esp32s3_base.lib_deps}
|
||||
lovyan03/LovyanGFX@^1.1.9
|
||||
lovyan03/LovyanGFX@^1.1.9
|
||||
earlephilhower/ESP8266Audio@^1.9.7
|
||||
earlephilhower/ESP8266SAM@^1.0.1
|
|
@ -65,6 +65,12 @@
|
|||
#define ES7210_LRCK 21
|
||||
#define ES7210_MCLK 48
|
||||
|
||||
// dac / amp
|
||||
#define HAS_I2S
|
||||
#define DAC_I2S_BCK 7
|
||||
#define DAC_I2S_WS 5
|
||||
#define DAC_I2S_DOUT 6
|
||||
|
||||
// LoRa
|
||||
#define USE_SX1262
|
||||
#define USE_SX1268
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
extends = esp32s3_base
|
||||
board = t-watch-s3
|
||||
upload_protocol = esptool
|
||||
upload_speed = 115200
|
||||
upload_port = /dev/tty.usbmodem3485188D636C1
|
||||
|
||||
build_flags = ${esp32_base.build_flags}
|
||||
-DT_WATCH_S3
|
||||
|
@ -12,4 +14,6 @@ build_flags = ${esp32_base.build_flags}
|
|||
lib_deps = ${esp32s3_base.lib_deps}
|
||||
lovyan03/LovyanGFX@^1.1.9
|
||||
lewisxhe/PCF8563_Library@1.0.1
|
||||
adafruit/Adafruit DRV2605 Library@^1.2.2
|
||||
adafruit/Adafruit DRV2605 Library@^1.2.2
|
||||
earlephilhower/ESP8266Audio@^1.9.7
|
||||
earlephilhower/ESP8266SAM@^1.0.1
|
|
@ -30,6 +30,11 @@
|
|||
|
||||
#define TFT_BL ST7789_BACKLIGHT_EN
|
||||
|
||||
#define HAS_I2S
|
||||
#define DAC_I2S_BCK 48
|
||||
#define DAC_I2S_WS 15
|
||||
#define DAC_I2S_DOUT 46
|
||||
|
||||
#define HAS_AXP2101
|
||||
|
||||
#define HAS_RTC 1
|
||||
|
@ -37,8 +42,6 @@
|
|||
#define I2C_SDA 10 // For QMC6310 sensors and screens
|
||||
#define I2C_SCL 11 // For QMC6310 sensors and screens
|
||||
|
||||
#define BUTTON_PIN 0
|
||||
|
||||
#define BMA4XX_INT 14 // Interrupt for BMA_423 axis sensor
|
||||
|
||||
#define HAS_GPS 0
|
||||
|
|
Ładowanie…
Reference in New Issue