add raw sound

This commit is contained in:
sharandac
2020-08-04 01:05:04 +02:00
parent 685bfc005f
commit d966ad0bde
13 changed files with 10446 additions and 77 deletions

View File

@@ -41,9 +41,12 @@ void pmu_setup( TTGOClass *ttgo ) {
// Turn off unused power
ttgo->power->setPowerOutPut( AXP202_EXTEN, AXP202_OFF );
ttgo->power->setPowerOutPut( AXP202_DCDC2, AXP202_OFF );
ttgo->power->setPowerOutPut( AXP202_LDO3, AXP202_OFF );
ttgo->power->setPowerOutPut( AXP202_LDO4, AXP202_OFF );
// Turn i2s DAC on
ttgo->power->setLDO3Mode( AXP202_LDO3_MODE_DCIN );
ttgo->power->setPowerOutPut(AXP202_LDO3, AXP202_ON );
pinMode( AXP202_INT, INPUT );
attachInterrupt( AXP202_INT, &pmu_irq, FALLING );
}
@@ -81,6 +84,7 @@ void pmu_standby( void ) {
ttgo->power->setDCDC3Voltage( 3000 );
log_i("enable 3.0V standby voltage");
}
ttgo->power->setPowerOutPut(AXP202_LDO3, AXP202_OFF );
}
void pmu_wakeup( void ) {
@@ -97,6 +101,8 @@ void pmu_wakeup( void ) {
ttgo->power->clearTimerStatus();
ttgo->power->offTimer();
ttgo->power->setPowerOutPut( AXP202_LDO3, AXP202_ON );
}
/*
*

View File

@@ -34,6 +34,7 @@
#include "motor.h"
#include "touch.h"
#include "display.h"
#include "sound.h"
#include "gui/mainbar/mainbar.h"
@@ -52,6 +53,7 @@ void powermgm_setup( TTGOClass *ttgo ) {
wifictl_setup();
timesync_setup( ttgo );
touch_setup( ttgo );
sound_setup();
}
/*

85
src/hardware/sound.cpp Normal file
View File

@@ -0,0 +1,85 @@
/****************************************************************************
* Aug 3 22:21:17 2020
* Copyright 2020 Dirk Brosswick
* Email: dirk.brosswick@googlemail.com
****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "driver/i2s.h"
#include "sound.h"
#include "gui/sound/snd_start.h"
#include "gui/sound/snd_signal.h"
TaskHandle_t _sound_Task;
void sound_Task( void * pvParameters );
void sound_setup( void ) {
esp_err_t err;
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
.sample_rate = 8000,
.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // high interrupt priority
.dma_buf_count = 8,
.dma_buf_len = 64 //Interrupt level 1
};
i2s_pin_config_t pin_config = {
.bck_io_num = TWATCH_DAC_IIS_BCK, //this is BCK pin
.ws_io_num = TWATCH_DAC_IIS_WS, // this is LRCK pin
.data_out_num = TWATCH_DAC_IIS_DOUT, // this is DATA output pin
.data_in_num = -1 //Not used
};
err = i2s_driver_install( I2S_PORT, &i2s_config, 0, NULL);
if (err != ESP_OK) {
log_e("Failed installing driver: %d\r\n", err );
while (true);
}
err = i2s_set_pin( I2S_PORT, &pin_config);
if (err != ESP_OK) {
log_e("Failed settings pin config: %d\r\n", err );
while (true);
}
xTaskCreate( sound_Task, /* Function to implement the task */
"sound Task", /* Name of the task */
2000, /* Stack size in words */
NULL, /* Task input parameter */
1, /* Priority of the task */
&_sound_Task ); /* Task handle. */
}
void sound_Task( void * pvParameters ) {
esp_err_t err;
size_t written = 0;
err = i2s_write( I2S_PORT, start_raw, sizeof(start_raw), &written, portMAX_DELAY );
if (err != ESP_OK) {
log_e("Failed write bytes: %d\r\n", err );
}
i2s_stop( I2S_PORT );
vTaskDelete( NULL );
}

31
src/hardware/sound.h Normal file
View File

@@ -0,0 +1,31 @@
/****************************************************************************
* Aug 3 22:21:17 2020
* Copyright 2020 Dirk Brosswick
* Email: dirk.brosswick@googlemail.com
****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _SOUND_H
#define _SOUND_H
#include <TTGO.h>
#define I2S_PORT I2S_NUM_0
void sound_setup( void );
#endif // _EXAMPLE_APP_H