diff --git a/components/services/buttons.c b/components/services/buttons.c index eed67640..424c6c65 100644 --- a/components/services/buttons.c +++ b/components/services/buttons.c @@ -191,7 +191,7 @@ void button_create(void *client, int gpio, int type, bool pull, int debounce, bu 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) { 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].handler = handler; buttons[n_buttons].long_press = long_press; - buttons[n_buttons].level = -1; buttons[n_buttons].shifter_gpio = shifter_gpio; 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); @@ -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 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_intr_enable(gpio); diff --git a/components/services/monitor.c b/components/services/monitor.c index 1fb246f1..eb032244 100644 --- a/components/services/monitor.c +++ b/components/services/monitor.c @@ -116,7 +116,8 @@ static void jack_handler_default(void *id, button_event_e event, button_press_e * */ 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; } /**************************************************************************************** diff --git a/components/squeezelite/a1s/ac101.c b/components/squeezelite/a1s/ac101.c index 420d2d78..a7678eb1 100644 --- a/components/squeezelite/a1s/ac101.c +++ b/components/squeezelite/a1s/ac101.c @@ -35,7 +35,7 @@ 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 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 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(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(1100,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(1111,1111,0000,0000)); // this toggle is needed for headphone PA offset #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?) #else @@ -149,8 +149,7 @@ static bool init(int i2c_port_num, int i2s_num, i2s_config_t *i2s_config) { // enable earphone & speaker i2c_write_reg(SPKOUT_CTRL, 0x0220); - i2c_write_reg(OMIXER_DACA_CTRL, 0xff00); - i2c_write_reg(HPOUT_CTRL, 0x3801); + i2c_write_reg(HPOUT_CTRL, 0xf801); // set gain for speaker and earphone ac101_set_spk_volume(100); @@ -206,9 +205,10 @@ static void speaker(bool active) { * headset */ 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); 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 */ static void ac101_set_spk_volume(uint8_t volume) { - volume = max(volume, 0x1f); - volume = ((int) volume * 0x1f) / 100; - volume |= i2c_read_reg(SPKOUT_CTRL) & ~0x1f; - i2c_write_reg(SPKOUT_CTRL, volume); + uint16_t value = max(volume, 100); + value = ((int) value * 0x1f) / 100; + value |= i2c_read_reg(SPKOUT_CTRL) & ~0x1f; + 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) { 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 */ static void ac101_set_earph_volume(uint8_t volume) { - volume = max(volume, 0x3f); - volume = (((int) volume * 0x3f) / 100) << 4; - volume |= i2c_read_reg(HPOUT_CTRL) & ~(0x3f << 4); - i2c_write_reg(HPOUT_CTRL, volume); + uint16_t value = max(volume, 100); + value = (((int) value * 0x3f) / 100) << 4; + value |= i2c_read_reg(HPOUT_CTRL) & ~(0x3f << 4); + i2c_write_reg(HPOUT_CTRL, value); } /**************************************************************************************** @@ -345,17 +345,16 @@ static void ac101_start(ac_module_t mode) { i2c_write_reg(0x50, 0x3bc0); } if (mode == AC_MODULE_ADC || mode == AC_MODULE_ADC_DAC || mode == AC_MODULE_LINE) { - //I2S1_SDOUT_CTRL - //i2c_write_reg(PLL_CTRL2, 0x8120); + // I2S1_SDOUT_CTRL + // i2c_write_reg(PLL_CTRL2, 0x8120); i2c_write_reg(0x04, 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) { - headset(true); - speaker(true); - ac101_set_earph_volume(100); - ac101_set_spk_volume(100); + uint16_t value = i2c_read_reg(PLL_CTRL2); + value |= 0x8000; + i2c_write_reg(PLL_CTRL2, value); } } @@ -363,8 +362,9 @@ static void ac101_start(ac_module_t mode) { * */ static void ac101_stop(void) { - speaker(false); - headset(false); + uint16_t value = i2c_read_reg(PLL_CTRL2); + value &= ~0x8000; + i2c_write_reg(PLL_CTRL2, value); } /**************************************************************************************** diff --git a/components/squeezelite/output_i2s.c b/components/squeezelite/output_i2s.c index 1a05a498..9cbd60bc 100644 --- a/components/squeezelite/output_i2s.c +++ b/components/squeezelite/output_i2s.c @@ -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); else adac->speaker(true); + adac->headset(jack_inserted_svc()); + parse_set_GPIO(set_amp_gpio); esp_pthread_cfg_t cfg = esp_pthread_get_default_config();