Skip to content

Commit

Permalink
BW lcd lower speed for some type.
Browse files Browse the repository at this point in the history
BW lcd lower speed for some type.
AP correction if no ip given (dhcp)
PDM gpio correction.
  • Loading branch information
karawin committed May 18, 2019
1 parent 3ecc73e commit 648749a
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 46 deletions.
Binary file modified boards/build/new_psram.bin
Binary file not shown.
Binary file added boards/build/pcm_psram.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion boards/lolin32pro.csv
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ P_LCD_RST,data,u8,21
P_IR_SIGNAL,data,u8,255
P_I2S_LRCK,data,u8,25
P_I2S_BCLK,data,u8,26
P_I2S_DATA,data,u8,27
P_I2S_DATA,data,u8,22
P_BACKLIGHT,data,u8,255
P_LED_GPIO,data,u8,5
P_ADC_KBD,data,u8,255
Expand Down
8 changes: 4 additions & 4 deletions boards/new_psram.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ P_MISO,data,u8,19
P_MOSI,data,u8,23
P_CLK,data,u8,18
P_XCS,data,u8,255
P_RST,data,u8,12
P_RST,data,u8,255
P_XDCS,data,u8,33
P_DREQ,data,u8,34
P_ENC0_A,data,u8,15
Expand All @@ -23,9 +23,9 @@ P_BTN0_C,data,u8,255
P_BTN1_A,data,u8,255
P_BTN1_B,data,u8,255
P_BTN1_C,data,u8,255
P_I2C_SCL,data,u8,14
P_I2C_SDA,data,u8,13
P_I2C_RST,data,u8,2
P_I2C_SCL,data,u8,255
P_I2C_SDA,data,u8,255
P_I2C_RST,data,u8,255
P_LCD_CS,data,u8,255
P_LCD_A0,data,u8,255
P_LCD_RST,data,u8,255
Expand Down
68 changes: 68 additions & 0 deletions boards/pcm_psram.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
key,type,encoding,value
label_space,namespace,,
L_LABEL,data,string,new_psram.csv
L_COMMENT,data,string,This is the standard simple configuration for a wrover. For PCM test .
gpio_space,namespace,,
K_SPI,data,u8,2
P_MISO,data,u8,19
P_MOSI,data,u8,23
P_CLK,data,u8,18
P_XCS,data,u8,255
P_RST,data,u8,255
P_XDCS,data,u8,33
P_DREQ,data,u8,34
P_ENC0_A,data,u8,15
P_ENC0_B,data,u8,27
P_ENC0_BTN,data,u8,5
P_ENC1_A,data,u8,255
P_ENC1_B,data,u8,27
P_ENC1_BTN,data,u8,5
P_BTN0_A,data,u8,255
P_BTN0_B,data,u8,255
P_BTN0_C,data,u8,255
P_BTN1_A,data,u8,255
P_BTN1_B,data,u8,255
P_BTN1_C,data,u8,255
P_I2C_SCL,data,u8,255
P_I2C_SDA,data,u8,255
P_I2C_RST,data,u8,255
P_LCD_CS,data,u8,255
P_LCD_A0,data,u8,255
P_LCD_RST,data,u8,255
P_IR_SIGNAL,data,u8,255
P_I2S_LRCK,data,u8,12
P_I2S_BCLK,data,u8,13
P_I2S_DATA,data,u8,14
P_TOUCH_CS,data,u8,255
P_JOY_0,data,u8,255
P_JOY_1,data,u8,255
P_LED_GPIO,data,u8,2
P_ADC_KBD,data,u8,255
P_BACKLIGHT,data,u8,255

option_space,namespace,,
O_LCD_TYPE,data,u8,255
O_LCD_ROTA,data,u8,255
O_LCD_OUT,data,u32,255
O_DDMM_FLAG,data,u8,255

custom_ir_space,namespace,,
K_UP,data,string,
K_LEFT,data,string,
K_OK,data,string,
K_RIGHT,data,string,
K_DOWN,data,string,
K_0,data,string,
K_1,data,string,
K_2,data,string,
K_3,data,string,
K_4,data,string,
K_5,data,string,
K_6,data,string,
K_7,data,string,
K_8,data,string,
K_9,data,string,
K_STAR,data,string,
K_DIESE,data,string,
K_INFO,data,string,

5 changes: 3 additions & 2 deletions components/MerusAudio/MerusAudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ uint8_t ma_read_byte(uint8_t address)
/*
* Output audio data to I2S and setup MerusAudio digital power amplifier
*/
void init_ma120(uint8_t vol)
uint8_t init_ma120(uint8_t vol)
{
printf("Setup MA120x0\n");

Expand All @@ -175,7 +175,8 @@ void init_ma120(uint8_t vol)
printf("Audio in mode : 0x%02x\n",res);

ma_write_byte(45,0x34); // Clean any errors on device
ma_write_byte(45,0x30);
if (!ma_write_byte(45,0x30)) return 0xff;

printf("Init done\n");
return 0;
}
2 changes: 1 addition & 1 deletion components/MerusAudio/include/MerusAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ esp_err_t ma_write(uint8_t address, uint8_t *wbuf, uint8_t n);
uint8_t ma_read_byte(uint8_t address);
esp_err_t ma_read(uint8_t address, uint8_t *rbuf, uint8_t n);

void init_ma120(uint8_t vol);
uint8_t init_ma120(uint8_t vol);

#endif /* _MERUSAUDIO_H_ */

Expand Down
5 changes: 1 addition & 4 deletions components/audio_player/audio_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,17 @@ void audio_player_init(player_t *player)

void audio_player_destroy()
{
renderer_destroy();
if (get_audio_output_mode() != VS1053) renderer_destroy();
player_status = UNINITIALIZED;
}

void audio_player_start()
{
//if (get_audio_output_mode() != VS1053)
{
if (get_audio_output_mode() != VS1053) renderer_start();
player_instance->media_stream->eof = false;
player_instance->command = CMD_START;
player_instance->decoder_command = CMD_NONE;
player_status = RUNNING;
}
}

void audio_player_stop()
Expand Down
77 changes: 48 additions & 29 deletions components/audio_renderer/audio_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "freertos/FreeRTOS.h"
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "esp_log.h"
#include <freertos/task.h>
#include <driver/dac.h>
#include "driver/gpio.h"
#include "gpio.h"
#include "app_main.h"
Expand Down Expand Up @@ -52,6 +54,7 @@ static void init_i2s(renderer_config_t *config)
if ((config->output_mode == I2S)||(config->output_mode == I2S_MERUS))
{
/* don't use audio pll on buggy rev0 chips */
// don't do it for PDM
if(out_info.revision > 0) {
use_apll = 1;
ESP_LOGI(TAG, "chip revision %d, enabling APLL", out_info.revision);
Expand All @@ -74,10 +77,11 @@ static void init_i2s(renderer_config_t *config)
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // 2-channels
.communication_format = comm_fmt,
.dma_buf_count = bigSram()?16:16, // number of buffers, 128 max. 16
.dma_buf_len = bigSram()?256:128, // size of each buffer 128
// .dma_buf_len = bigSram()?256:128, // size of each buffer 128
.dma_buf_len = bigSram()?128:128, // size of each buffer 128
// .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // lowest level 1
.intr_alloc_flags = 0, // default
.use_apll = use_apll
.use_apll = use_apll
};

gpio_num_t lrck;
Expand All @@ -102,7 +106,7 @@ static void init_i2s(renderer_config_t *config)
return;
}
ESP_LOGI(TAG,"i2s intr:%d", i2s_config.intr_alloc_flags);
if((mode & I2S_MODE_DAC_BUILT_IN) || (mode & I2S_MODE_PDM))
if((mode & I2S_MODE_DAC_BUILT_IN))// || (mode & I2S_MODE_PDM))
{
i2s_set_pin(config->i2s_num, NULL);
i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN);
Expand All @@ -119,6 +123,7 @@ static void init_i2s(renderer_config_t *config)
void renderer_volume(uint32_t vol)
{
// log volume (magic)
if (vol == 1) return; // volume 0
// ESP_LOGI(TAG, "Renderer vol: %d %X",vol,vol );
if (vol >= 255)
{
Expand All @@ -143,7 +148,7 @@ void renderer_volume(uint32_t vol)
*/
void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)
{
// ESP_LOGI(TAG, "buf_desc: bit_depth %d format %d num_chan %d sample_rate %d", buf_desc->bit_depth, buf_desc->buffer_format, buf_desc->num_channels, buf_desc->sample_rate);
// ESP_LOGV(TAG, "buf_desc: bit_depth %d format %d num_chan %d sample_rate %d", buf_desc->bit_depth, buf_desc->buffer_format, buf_desc->num_channels, buf_desc->sample_rate);
// ESP_LOGV(TAG, "renderer_instance: bit_depth %d, output_mode %d", renderer_instance->bit_depth, renderer_instance->output_mode);
// ESP_LOGI(TAG, "render_samples len: %d",buf_len);
int res = 0;
Expand Down Expand Up @@ -197,15 +202,16 @@ void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)
}
}
//-------------------------
/*ESP_LOGV(TAG, "I2S CHECK: buf_desc->bit_depth %d, renderer_instance->bit_depth %d, buf_desc->buffer_format %d, PCM_INTERLEAVED %d, buf_desc->num_channels %d (2), renderer_instance->output_mode %d, DAC_BUILT_IN %d ",buf_desc->bit_depth,renderer_instance->bit_depth,buf_desc->buffer_format,PCM_INTERLEAVED,buf_desc->num_channels,renderer_instance->output_mode,DAC_BUILT_IN);
*/
//ESP_LOGD(TAG, "I2S CHECK: buf_desc->bit_depth %d, renderer_instance->bit_depth %d, buf_desc->buffer_format %d, PCM_INTERLEAVED %d, buf_desc->num_channels %d (2), renderer_instance->output_mode %d, DAC_BUILT_IN %d ",buf_desc->bit_depth,renderer_instance->bit_depth,buf_desc->buffer_format,PCM_INTERLEAVED,buf_desc->num_channels,renderer_instance->output_mode,DAC_BUILT_IN);

// formats match, we can write the whole block
if (buf_desc->bit_depth == renderer_instance->bit_depth
&& buf_desc->buffer_format == PCM_INTERLEAVED
&& buf_desc->num_channels == 2
&& renderer_instance->output_mode != DAC_BUILT_IN
&& renderer_instance->output_mode != PDM)
{
&& renderer_instance->output_mode != PDM
)
{

// do not wait longer than the duration of the buffer
// TickType_t max_wait = buf_desc->sample_rate / num_samples / 2;
Expand All @@ -214,8 +220,7 @@ void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)
size_t bytes_left = buf_len;
size_t bytes_written = 0;
while(bytes_left > 0 && renderer_status != STOPPED) {
// ESP_LOGE(TAG, "i2s_write nb: %d",bytes_left);
// bytes_written = i2s_write_bytes(renderer_instance->i2s_num, buf, bytes_left, 1);
ESP_LOGE(TAG, "i2s_write nb: %d",bytes_left);
res = i2s_write(renderer_instance->i2s_num, buf, bytes_left,& bytes_written, 0);
if (res != ESP_OK) {
ESP_LOGE(TAG, "i2s_write error %d",res);
Expand Down Expand Up @@ -246,17 +251,18 @@ void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)
stride = buf_bytes_per_sample;
}

if (buf_desc->num_channels == 1) {
if (buf_desc->num_channels == 1) // duplicate
{
ptr_r = ptr_l;
}

TickType_t max_wait = 20 / portTICK_PERIOD_MS; // portMAX_DELAY = bad idea
//mult = mult>>12; // for sample on 8 bits 0 to 16

// har-in-air correction
uint32_t outBufBytes = buf_len*(2/buf_desc->num_channels);
if (renderer_instance->bit_depth == I2S_BITS_PER_SAMPLE_32BIT) outBufBytes <<= 1;
outBuf8 = malloc(outBufBytes);

outBuf8 = malloc(outBufBytes);

// outBuf8 = malloc(buf_len*(2/buf_desc->num_channels));
//
Expand All @@ -266,14 +272,15 @@ void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)
renderer_stop();
return;
}
// outBuf16 =(uint16_t*)outBuf8;
outBuf32 =(uint32_t*)outBuf8;
outBuf64 = (uint64_t*)outBuf8;


for (int i = 0; i < num_samples; i++) {
if (renderer_status == STOPPED) break;

if(renderer_instance->output_mode == DAC_BUILT_IN)
if((renderer_instance->output_mode == DAC_BUILT_IN))//||(renderer_instance->output_mode == PDM))
{
// assume 16 bit src bit_depth
int16_t left = *(int16_t *) ptr_l;
Expand All @@ -289,16 +296,22 @@ void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)

outBuf32[i] = sample;
}

/* else if (renderer_instance->output_mode == PDM)
{
const char samp16[2] = {ptr_l[0], ptr_l[1]};
outBuf16[i] = *((uint16_t*)samp16);
} */
else {

switch (renderer_instance->bit_depth)
{
case I2S_BITS_PER_SAMPLE_16BIT:
; // workaround

/* low - high / low - high */
const char samp32[4] = {ptr_l[0], ptr_l[1], ptr_r[0], ptr_r[1]};
outBuf32[i] = *((uint32_t*)samp32);
outBuf32[i] = *((uint32_t*)samp32);
break;

case I2S_BITS_PER_SAMPLE_32BIT:
Expand All @@ -318,14 +331,21 @@ void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)
}
//
// har-in-air correction
size_t bytes_left = outBufBytes;
size_t bytes_left = outBufBytes ;
size_t bytes_written = 0;

if (renderer_instance->output_mode == PDM)
{
// bytes_left = outBufBytes/4 ;
}


while(bytes_left > 0 && renderer_status != STOPPED) {
res = i2s_write(renderer_instance->i2s_num, (const char*) outBuf8, bytes_left,& bytes_written, max_wait);
if (res != ESP_OK) {
ESP_LOGE(TAG, "i2s_write error %d",res);
}
if (bytes_written != bytes_left) ESP_LOGV(TAG, "written: %d, len: %d",bytes_written,bytes_left);
// if (bytes_written != bytes_left) ESP_LOGV(TAG, "written: %d, len: %d",bytes_written,bytes_left);

/* size_t bytes_left = buf_len*(2/buf_desc->num_channels);
size_t bytes_written = 0;
Expand All @@ -338,7 +358,7 @@ void render_samples(char *buf, uint32_t buf_len, pcm_format_t *buf_desc)
*/

bytes_left -= bytes_written;
buf += bytes_written;
buf += (bytes_written );
}
free (outBuf8);
}
Expand Down Expand Up @@ -367,10 +387,9 @@ void renderer_init(renderer_config_t *config)
init_i2s(config);

if(config->output_mode == I2S_MERUS) {
init_ma120(0x50); // setup ma120x0p and initial volume
if (init_ma120(0x50)) // setup ma120x0p and initial volume
config->output_mode = I2S; // error, back to I2S
}

//free (config);
}


Expand All @@ -379,20 +398,20 @@ void renderer_start()
if(renderer_status == RUNNING)
return;

renderer_status = RUNNING;
i2s_start(renderer_instance->i2s_num);

// buffer might contain noise
i2s_zero_dma_buffer(renderer_instance->i2s_num);
// i2s_zero_dma_buffer(renderer_instance->i2s_num);
ESP_LOGV(TAG, "Start" );
i2s_start(renderer_instance->i2s_num);
renderer_status = RUNNING;
}

void renderer_stop()
{
if(renderer_status == STOPPED)
return;
renderer_status = STOPPED;

i2s_stop(renderer_instance->i2s_num);
renderer_status = STOPPED;
ESP_LOGV(TAG, "Stop" );
i2s_stop(renderer_instance->i2s_num);
}

void renderer_destroy()
Expand Down
6 changes: 5 additions & 1 deletion components/u8g2/csrc/u8g2_esp32_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ uint8_t u8g2_esp32_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
dev_config.duty_cycle_pos = 0;
dev_config.cs_ena_posttrans = 0;
dev_config.cs_ena_pretrans = 0;
dev_config.clock_speed_hz = 10000000;
if (u8x8->display_info->sck_clock_hz <= 1000000UL)
dev_config.clock_speed_hz = 400000UL;
else if (u8x8->display_info->sck_clock_hz <= 2000000UL)
dev_config.clock_speed_hz = u8x8->display_info->sck_clock_hz;
else dev_config.clock_speed_hz = 10000000UL;
// dev_config.clock_speed_hz = u8x8->display_info->sck_clock_hz;
dev_config.spics_io_num = u8g2_esp32_hal.cs;
dev_config.flags = (u8x8->display_info->chip_enable_level ?SPI_DEVICE_POSITIVE_CS : 0)|SPI_DEVICE_NO_DUMMY; // ST7920.
Expand Down
Loading

0 comments on commit 648749a

Please sign in to comment.