mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 19:47:02 +03:00
Tweak A1S to make it work with devkit + correct one minor bug in buttons - release
This commit is contained in:
@@ -191,7 +191,7 @@ void button_create(void *client, int gpio, int type, bool pull, int debounce, bu
|
|||||||
|
|
||||||
if (n_buttons >= MAX_BUTTONS) return;
|
if (n_buttons >= MAX_BUTTONS) return;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Creating button using GPIO %u, type %u, pull-up/down %u, long press %u shifter %u", gpio, type, pull, long_press, shifter_gpio);
|
ESP_LOGI(TAG, "Creating button using GPIO %u, type %u, pull-up/down %u, long press %u shifter %d", gpio, type, pull, long_press, shifter_gpio);
|
||||||
|
|
||||||
if (!n_buttons) {
|
if (!n_buttons) {
|
||||||
button_evt_queue = xQueueCreate(BUTTON_QUEUE_LEN, sizeof(struct button_s));
|
button_evt_queue = xQueueCreate(BUTTON_QUEUE_LEN, sizeof(struct button_s));
|
||||||
@@ -209,7 +209,6 @@ void button_create(void *client, int gpio, int type, bool pull, int debounce, bu
|
|||||||
buttons[n_buttons].debounce = debounce ? debounce: DEBOUNCE;
|
buttons[n_buttons].debounce = debounce ? debounce: DEBOUNCE;
|
||||||
buttons[n_buttons].handler = handler;
|
buttons[n_buttons].handler = handler;
|
||||||
buttons[n_buttons].long_press = long_press;
|
buttons[n_buttons].long_press = long_press;
|
||||||
buttons[n_buttons].level = -1;
|
|
||||||
buttons[n_buttons].shifter_gpio = shifter_gpio;
|
buttons[n_buttons].shifter_gpio = shifter_gpio;
|
||||||
buttons[n_buttons].type = type;
|
buttons[n_buttons].type = type;
|
||||||
buttons[n_buttons].timer = xTimerCreate("buttonTimer", buttons[n_buttons].debounce / portTICK_RATE_MS, pdFALSE, (void *) &buttons[n_buttons], buttons_timer);
|
buttons[n_buttons].timer = xTimerCreate("buttonTimer", buttons[n_buttons].debounce / portTICK_RATE_MS, pdFALSE, (void *) &buttons[n_buttons], buttons_timer);
|
||||||
@@ -247,6 +246,9 @@ void button_create(void *client, int gpio, int type, bool pull, int debounce, bu
|
|||||||
|
|
||||||
// nasty ESP32 bug: fire-up constantly INT on GPIO 36/39 if ADC1, AMP, Hall used which WiFi does when PS is activated
|
// nasty ESP32 bug: fire-up constantly INT on GPIO 36/39 if ADC1, AMP, Hall used which WiFi does when PS is activated
|
||||||
if (gpio == 36 || gpio == 39) gpio36_39_used = true;
|
if (gpio == 36 || gpio == 39) gpio36_39_used = true;
|
||||||
|
|
||||||
|
// and initialize level ...
|
||||||
|
buttons[n_buttons].level = gpio_get_level(gpio);
|
||||||
|
|
||||||
gpio_isr_handler_add(gpio, gpio_isr_handler, (void*) &buttons[n_buttons]);
|
gpio_isr_handler_add(gpio, gpio_isr_handler, (void*) &buttons[n_buttons]);
|
||||||
gpio_intr_enable(gpio);
|
gpio_intr_enable(gpio);
|
||||||
|
|||||||
@@ -116,7 +116,8 @@ static void jack_handler_default(void *id, button_event_e event, button_press_e
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool jack_inserted_svc (void) {
|
bool jack_inserted_svc (void) {
|
||||||
return button_is_pressed(jack.gpio, NULL);
|
if (jack.gpio != -1) return button_is_pressed(jack.gpio, NULL);
|
||||||
|
else return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
const static char TAG[] = "AC101";
|
const static char TAG[] = "AC101";
|
||||||
|
|
||||||
#define SPKOUT_EN ((1 << 11) | (1 << 7))
|
#define SPKOUT_EN ((1 << 9) | (1 << 11) | (1 << 7) | (1 << 5))
|
||||||
#define EAROUT_EN ((1 << 11) | (1 << 12) | (1 << 13))
|
#define EAROUT_EN ((1 << 11) | (1 << 12) | (1 << 13))
|
||||||
#define BIN(a,b,c,d) 0b##a##b##c##d
|
#define BIN(a,b,c,d) 0b##a##b##c##d
|
||||||
|
|
||||||
@@ -132,8 +132,8 @@ static bool init(int i2c_port_num, int i2s_num, i2s_config_t *i2s_config) {
|
|||||||
//Path Configuration
|
//Path Configuration
|
||||||
i2c_write_reg(DAC_MXR_SRC, BIN(1000,1000,0000,0000)); // DAC from I2S
|
i2c_write_reg(DAC_MXR_SRC, BIN(1000,1000,0000,0000)); // DAC from I2S
|
||||||
i2c_write_reg(DAC_DIG_CTRL, BIN(1000,0000,0000,0000)); // enable DAC
|
i2c_write_reg(DAC_DIG_CTRL, BIN(1000,0000,0000,0000)); // enable DAC
|
||||||
i2c_write_reg(OMIXER_DACA_CTRL, BIN(1111,0000,0000,000)); // enable DAC/Analogue (see note on offset removal and PA)
|
i2c_write_reg(OMIXER_DACA_CTRL, BIN(1111,0000,0000,0000)); // enable DAC/Analogue (see note on offset removal and PA)
|
||||||
i2c_write_reg(OMIXER_DACA_CTRL, BIN(1100,0000,0000,000)); // enable DAC/Analogue (see note on offset removal and PA)
|
i2c_write_reg(OMIXER_DACA_CTRL, BIN(1111,1111,0000,0000)); // this toggle is needed for headphone PA offset
|
||||||
#if ENABLE_ADC
|
#if ENABLE_ADC
|
||||||
i2c_write_reg(OMIXER_SR, BIN(0000,0001,0000,0010)); // source=DAC(R/L) (are DACR and DACL really inverted in bitmap?)
|
i2c_write_reg(OMIXER_SR, BIN(0000,0001,0000,0010)); // source=DAC(R/L) (are DACR and DACL really inverted in bitmap?)
|
||||||
#else
|
#else
|
||||||
@@ -149,8 +149,7 @@ static bool init(int i2c_port_num, int i2s_num, i2s_config_t *i2s_config) {
|
|||||||
|
|
||||||
// enable earphone & speaker
|
// enable earphone & speaker
|
||||||
i2c_write_reg(SPKOUT_CTRL, 0x0220);
|
i2c_write_reg(SPKOUT_CTRL, 0x0220);
|
||||||
i2c_write_reg(OMIXER_DACA_CTRL, 0xff00);
|
i2c_write_reg(HPOUT_CTRL, 0xf801);
|
||||||
i2c_write_reg(HPOUT_CTRL, 0x3801);
|
|
||||||
|
|
||||||
// set gain for speaker and earphone
|
// set gain for speaker and earphone
|
||||||
ac101_set_spk_volume(100);
|
ac101_set_spk_volume(100);
|
||||||
@@ -206,9 +205,10 @@ static void speaker(bool active) {
|
|||||||
* headset
|
* headset
|
||||||
*/
|
*/
|
||||||
static void headset(bool active) {
|
static void headset(bool active) {
|
||||||
|
// there might be aneed to toggle OMIXER_DACA_CTRL 11:8, not sure
|
||||||
uint16_t value = i2c_read_reg(HPOUT_CTRL);
|
uint16_t value = i2c_read_reg(HPOUT_CTRL);
|
||||||
if (active) i2c_write_reg(HPOUT_CTRL, value | EAROUT_EN);
|
if (active) i2c_write_reg(HPOUT_CTRL, value | EAROUT_EN);
|
||||||
else i2c_write_reg(HPOUT_CTRL, value & ~EAROUT_EN);
|
else i2c_write_reg(HPOUT_CTRL, value & ~EAROUT_EN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
@@ -284,14 +284,14 @@ static int ac101_get_spk_volume(void) {
|
|||||||
* Set normalized (0..100) volume
|
* Set normalized (0..100) volume
|
||||||
*/
|
*/
|
||||||
static void ac101_set_spk_volume(uint8_t volume) {
|
static void ac101_set_spk_volume(uint8_t volume) {
|
||||||
volume = max(volume, 0x1f);
|
uint16_t value = max(volume, 100);
|
||||||
volume = ((int) volume * 0x1f) / 100;
|
value = ((int) value * 0x1f) / 100;
|
||||||
volume |= i2c_read_reg(SPKOUT_CTRL) & ~0x1f;
|
value |= i2c_read_reg(SPKOUT_CTRL) & ~0x1f;
|
||||||
i2c_write_reg(SPKOUT_CTRL, volume);
|
i2c_write_reg(SPKOUT_CTRL, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
* Get normalized (0..100) earphonz volume
|
* Get normalized (0..100) earphone volume
|
||||||
*/
|
*/
|
||||||
static int ac101_get_earph_volume(void) {
|
static int ac101_get_earph_volume(void) {
|
||||||
return (((i2c_read_reg(HPOUT_CTRL) >> 4) & 0x3f) * 100) / 0x3f;
|
return (((i2c_read_reg(HPOUT_CTRL) >> 4) & 0x3f) * 100) / 0x3f;
|
||||||
@@ -301,10 +301,10 @@ static int ac101_get_earph_volume(void) {
|
|||||||
* Set normalized (0..100) earphone volume
|
* Set normalized (0..100) earphone volume
|
||||||
*/
|
*/
|
||||||
static void ac101_set_earph_volume(uint8_t volume) {
|
static void ac101_set_earph_volume(uint8_t volume) {
|
||||||
volume = max(volume, 0x3f);
|
uint16_t value = max(volume, 100);
|
||||||
volume = (((int) volume * 0x3f) / 100) << 4;
|
value = (((int) value * 0x3f) / 100) << 4;
|
||||||
volume |= i2c_read_reg(HPOUT_CTRL) & ~(0x3f << 4);
|
value |= i2c_read_reg(HPOUT_CTRL) & ~(0x3f << 4);
|
||||||
i2c_write_reg(HPOUT_CTRL, volume);
|
i2c_write_reg(HPOUT_CTRL, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
@@ -345,17 +345,16 @@ static void ac101_start(ac_module_t mode) {
|
|||||||
i2c_write_reg(0x50, 0x3bc0);
|
i2c_write_reg(0x50, 0x3bc0);
|
||||||
}
|
}
|
||||||
if (mode == AC_MODULE_ADC || mode == AC_MODULE_ADC_DAC || mode == AC_MODULE_LINE) {
|
if (mode == AC_MODULE_ADC || mode == AC_MODULE_ADC_DAC || mode == AC_MODULE_LINE) {
|
||||||
//I2S1_SDOUT_CTRL
|
// I2S1_SDOUT_CTRL
|
||||||
//i2c_write_reg(PLL_CTRL2, 0x8120);
|
// i2c_write_reg(PLL_CTRL2, 0x8120);
|
||||||
i2c_write_reg(0x04, 0x800c);
|
i2c_write_reg(0x04, 0x800c);
|
||||||
i2c_write_reg(0x05, 0x800c);
|
i2c_write_reg(0x05, 0x800c);
|
||||||
//res |= i2c_write_reg(0x06, 0x3000);
|
// res |= i2c_write_reg(0x06, 0x3000);
|
||||||
}
|
}
|
||||||
if (mode == AC_MODULE_DAC || mode == AC_MODULE_ADC_DAC || mode == AC_MODULE_LINE) {
|
if (mode == AC_MODULE_DAC || mode == AC_MODULE_ADC_DAC || mode == AC_MODULE_LINE) {
|
||||||
headset(true);
|
uint16_t value = i2c_read_reg(PLL_CTRL2);
|
||||||
speaker(true);
|
value |= 0x8000;
|
||||||
ac101_set_earph_volume(100);
|
i2c_write_reg(PLL_CTRL2, value);
|
||||||
ac101_set_spk_volume(100);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,8 +362,9 @@ static void ac101_start(ac_module_t mode) {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void ac101_stop(void) {
|
static void ac101_stop(void) {
|
||||||
speaker(false);
|
uint16_t value = i2c_read_reg(PLL_CTRL2);
|
||||||
headset(false);
|
value &= ~0x8000;
|
||||||
|
i2c_write_reg(PLL_CTRL2, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
|
|||||||
@@ -274,6 +274,8 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
|
|||||||
if (jack_mutes_amp && jack_inserted_svc()) adac->speaker(false);
|
if (jack_mutes_amp && jack_inserted_svc()) adac->speaker(false);
|
||||||
else adac->speaker(true);
|
else adac->speaker(true);
|
||||||
|
|
||||||
|
adac->headset(jack_inserted_svc());
|
||||||
|
|
||||||
parse_set_GPIO(set_amp_gpio);
|
parse_set_GPIO(set_amp_gpio);
|
||||||
|
|
||||||
esp_pthread_cfg_t cfg = esp_pthread_get_default_config();
|
esp_pthread_cfg_t cfg = esp_pthread_get_default_config();
|
||||||
|
|||||||
Reference in New Issue
Block a user