mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-27 12:50:49 +03:00
Merge branch 'master' of https://github.com/sle118/squeezelite-esp32.git
Conflicts: components/config/config.c components/display/driver_SSD1306.c
This commit is contained in:
@@ -41,7 +41,7 @@ static int n_buttons = 0;
|
||||
#define DEBOUNCE 50
|
||||
|
||||
static EXT_RAM_ATTR struct button_s {
|
||||
void *id;
|
||||
void *client;
|
||||
int gpio;
|
||||
int debounce;
|
||||
button_handler handler;
|
||||
@@ -123,18 +123,18 @@ static void buttons_task(void* arg) {
|
||||
if (event == BUTTON_RELEASED) {
|
||||
// early release of a long-press button, send press/release
|
||||
if (!button.shifting) {
|
||||
(*button.handler)(button.id, BUTTON_PRESSED, press, false);
|
||||
(*button.handler)(button.id, BUTTON_RELEASED, press, false);
|
||||
(*button.handler)(button.client, BUTTON_PRESSED, press, false);
|
||||
(*button.handler)(button.client, BUTTON_RELEASED, press, false);
|
||||
}
|
||||
// button is a copy, so need to go to real context
|
||||
button.self->shifting = false;
|
||||
} else if (!button.shifting) {
|
||||
// normal long press and not shifting so don't discard
|
||||
(*button.handler)(button.id, BUTTON_PRESSED, press, true);
|
||||
(*button.handler)(button.client, BUTTON_PRESSED, press, true);
|
||||
}
|
||||
} else {
|
||||
// normal press/release of a button or release of a long-press button
|
||||
if (!button.shifting) (*button.handler)(button.id, event, press, button.long_press);
|
||||
if (!button.shifting) (*button.handler)(button.client, event, press, button.long_press);
|
||||
// button is a copy, so need to go to real context
|
||||
button.self->shifting = false;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ void dummy_handler(void *id, button_event_e event, button_press_e press) {
|
||||
/****************************************************************************************
|
||||
* Create buttons
|
||||
*/
|
||||
void button_create(void *id, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio) {
|
||||
void button_create(void *client, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio) {
|
||||
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__ ((aligned (4)));
|
||||
static EXT_RAM_ATTR StackType_t xStack[BUTTON_STACK_SIZE] __attribute__ ((aligned (4)));
|
||||
|
||||
@@ -168,7 +168,7 @@ void button_create(void *id, int gpio, int type, bool pull, int debounce, button
|
||||
memset(buttons + n_buttons, 0, sizeof(struct button_s));
|
||||
|
||||
// set mandatory parameters
|
||||
buttons[n_buttons].id = id;
|
||||
buttons[n_buttons].client = client;
|
||||
buttons[n_buttons].gpio = gpio;
|
||||
buttons[n_buttons].debounce = debounce ? debounce: DEBOUNCE;
|
||||
buttons[n_buttons].handler = handler;
|
||||
@@ -213,4 +213,54 @@ void button_create(void *id, int gpio, int type, bool pull, int debounce, button
|
||||
gpio_intr_enable(gpio);
|
||||
|
||||
n_buttons++;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Get stored id
|
||||
*/
|
||||
void button_get_client(int gpio) {
|
||||
for (int i = 0; i < n_buttons; i++) {
|
||||
if (buttons[i].gpio == gpio) return buttons[i].client;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Update buttons
|
||||
*/
|
||||
void *button_remap(void *client, int gpio, button_handler handler, int long_press, int shifter_gpio) {
|
||||
int i;
|
||||
struct button_s *button = NULL;
|
||||
void *prev_client;
|
||||
|
||||
ESP_LOGI(TAG, "remapping GPIO %u, long press %u shifter %u", gpio, long_press, shifter_gpio);
|
||||
|
||||
// find button
|
||||
for (i = 0; i < n_buttons; i++) {
|
||||
if (buttons[i].gpio == gpio) {
|
||||
button = buttons + i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// huh
|
||||
if (!button) return NULL;
|
||||
|
||||
prev_client = button->client;
|
||||
button->client = client;
|
||||
button->handler = handler;
|
||||
button->long_press = long_press;
|
||||
button->shifter_gpio = shifter_gpio;
|
||||
|
||||
// find our shifter (if any)
|
||||
for (i = 0; shifter_gpio != -1 && i < n_buttons; i++) {
|
||||
if (buttons[i].gpio == shifter_gpio) {
|
||||
button->shifter = buttons + i;
|
||||
// a shifter must have a long-press handler
|
||||
if (!buttons[i].long_press) buttons[i].long_press = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return prev_client;
|
||||
}
|
||||
|
||||
@@ -33,4 +33,6 @@ set shifter_gpio to -1 for no shift
|
||||
NOTE: shifter buttons *must* be created before shiftee
|
||||
*/
|
||||
|
||||
void button_create(void *id, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio);
|
||||
void button_create(void *client, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio);
|
||||
void *button_remap(void *client, int gpio, button_handler handler, int long_press, int shifter_gpio);
|
||||
void button_get_client(int gpio);
|
||||
|
||||
34
components/services/globdefs.h
Normal file
34
components/services/globdefs.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Squeezelite for esp32
|
||||
*
|
||||
* (c) Philippe G. 2019, philippe_44@outlook.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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define I2C_SYSTEM_PORT 1
|
||||
extern int i2c_system_port;
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
#define JACK_GPIO 34
|
||||
#define SPKFAULT_GPIO 2 // this requires a pull-up, so can't be >34
|
||||
#define LED_GREEN_GPIO 12
|
||||
#define LED_RED_GPIO 13
|
||||
#else
|
||||
#define LED_GREEN_GPIO CONFIG_LED_GREEN_GPIO
|
||||
#define LED_RED_GPIO CONFIG_LED_RED_GPIO
|
||||
#endif
|
||||
@@ -18,11 +18,7 @@
|
||||
#include "driver/gpio.h"
|
||||
#include "buttons.h"
|
||||
#include "led.h"
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
#define JACK_GPIO 34
|
||||
#define SPKFAULT_GPIO 2 // this requires a pull-up, so can't be >34
|
||||
#endif
|
||||
#include "globdefs.h"
|
||||
|
||||
#define MONITOR_TIMER (10*1000)
|
||||
|
||||
|
||||
@@ -9,33 +9,69 @@
|
||||
#include <stdio.h>
|
||||
#include "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#include <driver/i2c.h>
|
||||
#include "config.h"
|
||||
#include "battery.h"
|
||||
#include "led.h"
|
||||
#include "monitor.h"
|
||||
#include "globdefs.h"
|
||||
|
||||
extern void battery_svc_init(void);
|
||||
extern void monitor_svc_init(void);
|
||||
extern void led_svc_init(void);
|
||||
|
||||
static const char TAG[] = "services";
|
||||
int i2c_system_port = I2C_SYSTEM_PORT;
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
#define LED_GREEN_GPIO 12
|
||||
#define LED_RED_GPIO 13
|
||||
#endif
|
||||
static const char *TAG = "services";
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void services_init(void) {
|
||||
int scl = -1, sda = -1, i2c_speed = 250000;
|
||||
char *nvs_item, *p;
|
||||
|
||||
gpio_install_isr_service(0);
|
||||
|
||||
nvs_item = config_alloc_get(NVS_TYPE_STR, "i2c_config");
|
||||
|
||||
if (nvs_item) {
|
||||
if ((p = strcasestr(nvs_item, "scl")) != NULL) scl = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "sda")) != NULL) sda = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "speed")) != NULL) i2c_speed = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "port")) != NULL) i2c_system_port = atoi(strchr(p, '=') + 1);
|
||||
free(nvs_item);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
if (i2c_system_port == 0) {
|
||||
i2c_system_port = 1;
|
||||
ESP_LOGE(TAG, "can't use i2c port 0 on SqueezeAMP");
|
||||
}
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG,"Configuring I2C sda:%d scl:%d port:%u speed:%u", sda, scl, i2c_system_port, i2c_speed);
|
||||
|
||||
if (sda != -1 && scl != -1) {
|
||||
i2c_config_t i2c = { 0 };
|
||||
|
||||
i2c.mode = I2C_MODE_MASTER;
|
||||
i2c.sda_io_num = sda;
|
||||
i2c.sda_pullup_en = GPIO_PULLUP_ENABLE;
|
||||
i2c.scl_io_num = scl;
|
||||
i2c.scl_pullup_en = GPIO_PULLUP_ENABLE;
|
||||
i2c.master.clk_speed = i2c_speed;
|
||||
|
||||
i2c_param_config(i2c_system_port, &i2c);
|
||||
i2c_driver_install(i2c_system_port, i2c.mode, 0, 0, 0 );
|
||||
} else {
|
||||
ESP_LOGE(TAG, "can't initialize I2C");
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG,"Configuring LEDs");
|
||||
led_svc_init();
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
led_config(LED_GREEN, LED_GREEN_GPIO, 0);
|
||||
led_config(LED_RED, LED_RED_GPIO, 0);
|
||||
#endif
|
||||
|
||||
battery_svc_init();
|
||||
monitor_svc_init();
|
||||
|
||||
Reference in New Issue
Block a user