Merge remote-tracking branch 'origin/master'

This commit is contained in:
Sebastien
2020-01-10 16:06:44 -05:00
62 changed files with 4600 additions and 118 deletions

View File

@@ -94,7 +94,7 @@ void down(void *id, button_event_e event, button_press_e press, bool longpress)
*/
esp_err_t actrls_init(int n, const actrls_config_t *config) {
for (int i = 0; i < n; i++) {
button_create((void*) (config + i), config[i].gpio, config[i].type, config[i].pull, control_handler, config[i].long_press, config[i].shifter_gpio);
button_create((void*) (config + i), config[i].gpio, config[i].type, config[i].pull, config[i].debounce, control_handler, config[i].long_press, config[i].shifter_gpio);
}
return ESP_OK;
}
@@ -175,7 +175,7 @@ esp_err_t actrls_parse_config_map(const cJSON * member, actrls_config_t *cur_con
if (err == ESP_OK) {
button_create((void*) cur_config, cur_config->gpio,
cur_config->type, cur_config->pull,
cur_config->type, cur_config->pull,cur_config->debounce,
control_handler, cur_config->long_press,
cur_config->shifter_gpio);
}

View File

@@ -38,6 +38,7 @@ typedef struct {
int gpio;
int type;
bool pull;
int debounce;
int long_press;
int shifter_gpio;
actrls_action_e normal[2], longpress[2], shifted[2], longshifted[2]; // [0] keypressed, [1] keyreleased
@@ -54,6 +55,7 @@ typedef struct {
static const actrls_config_map_t actrls_config_map[] =
{
{"gpio", offsetof(actrls_config_t,gpio), ACTRLS_MAP_INT},
{"debounce", offsetof(actrls_config_t,debounce), ACTRLS_MAP_INT},
{"type", offsetof(actrls_config_t,type),ACTRLS_MAP_TYPE},
{"pull", offsetof(actrls_config_t,pull),ACTRLS_MAP_BOOL},
{"long_press", offsetof(actrls_config_t,long_press),ACTRLS_MAP_INT},

View File

@@ -43,6 +43,7 @@ static int n_buttons = 0;
static EXT_RAM_ATTR struct button_s {
void *id;
int gpio, index;
int debounce;
button_handler handler;
struct button_s *shifter;
int long_press;
@@ -63,7 +64,7 @@ static void IRAM_ATTR gpio_isr_handler(void* arg)
struct button_s *button = (struct button_s*) arg;
BaseType_t woken = pdFALSE;
if (xTimerGetPeriod(button->timer) > DEBOUNCE / portTICK_RATE_MS) xTimerChangePeriodFromISR(button->timer, DEBOUNCE / portTICK_RATE_MS, &woken); // does that restart the timer?
if (xTimerGetPeriod(button->timer) > button->debounce / portTICK_RATE_MS) xTimerChangePeriodFromISR(button->timer, button->debounce / portTICK_RATE_MS, &woken); // does that restart the timer?
else xTimerResetFromISR(button->timer, &woken);
// ESP_EARLY_LOGI(TAG, "INT gpio %u level %u", button->gpio, button->level);
}
@@ -149,7 +150,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, button_handler handler, int long_press, int shifter_gpio) {
void button_create(void *id, 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)));
@@ -159,7 +160,6 @@ void button_create(void *id, int gpio, int type, bool pull, button_handler handl
if (!n_buttons) {
button_evt_queue = xQueueCreate(10, sizeof(struct button_s));
gpio_install_isr_service(0);
xTaskCreateStatic( (TaskFunction_t) buttons_task, "buttons_thread", BUTTON_STACK_SIZE, NULL, ESP_TASK_PRIO_MIN + 1, xStack, &xTaskBuffer);
}
@@ -169,11 +169,12 @@ void button_create(void *id, int gpio, int type, bool pull, button_handler handl
// set mandatory parameters
buttons[n_buttons].id = id;
buttons[n_buttons].gpio = gpio;
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].type = type;
buttons[n_buttons].timer = xTimerCreate("buttonTimer", 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);
// little trick to find ourselves from queued copy
buttons[n_buttons].index = n_buttons;

View File

@@ -27,9 +27,10 @@ typedef enum { BUTTON_NORMAL, BUTTON_SHIFTED } button_press_e;
typedef void (*button_handler)(void *id, button_event_e event, button_press_e mode, bool long_press);
/*
set debounce to 0 for default (50ms)
set long_press to 0 for no long-press
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, button_handler handler, int long_press, int shifter_gpio);
void button_create(void *id, int gpio, int type, bool pull, int debounce, button_handler handler, int long_press, int shifter_gpio);

View File

@@ -15,12 +15,17 @@
#include "esp_system.h"
#include "esp_log.h"
#include "monitor.h"
#include "driver/gpio.h"
#include "buttons.h"
#define JACK_GPIO 34
#define MONITOR_TIMER (10*1000)
static const char TAG[] = "monitor";
static TimerHandle_t monitor_timer;
void (*jack_handler_svc)(bool inserted);
bool jack_inserted_svc(void);
/****************************************************************************************
*
@@ -33,12 +38,39 @@ static void monitor_callback(TimerHandle_t xTimer) {
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
}
/****************************************************************************************
*
*/
static void jack_handler_default(void *id, button_event_e event, button_press_e mode, bool long_press) {
ESP_LOGD(TAG, "Jack %s", event == BUTTON_PRESSED ? "inserted" : "removed");
if (jack_handler_svc) (*jack_handler_svc)(event == BUTTON_PRESSED);
}
/****************************************************************************************
*
*/
bool jack_inserted_svc (void) {
#ifdef JACK_GPIO
return !gpio_get_level(JACK_GPIO);
#else
return false;
#endif
}
/****************************************************************************************
*
*/
void monitor_svc_init(void) {
ESP_LOGI(TAG, "Initializing monitoring");
#ifdef JACK_GPIO
gpio_pad_select_gpio(JACK_GPIO);
gpio_set_direction(JACK_GPIO, GPIO_MODE_INPUT);
// re-use button management for jack handler, it's a GPIO after all
button_create(NULL, JACK_GPIO, BUTTON_LOW, false, 250, jack_handler_default, 0, -1);
#endif
monitor_timer = xTimerCreate("monitor", MONITOR_TIMER / portTICK_RATE_MS, pdTRUE, NULL, monitor_callback);
xTimerStart(monitor_timer, portMAX_DELAY);
}

View File

@@ -20,3 +20,6 @@
#pragma once
extern void (*jack_handler_svc)(bool inserted);
extern bool jack_inserted_svc(void);

View File

@@ -7,6 +7,8 @@
*/
#include <stdio.h>
#include "esp_log.h"
#include "driver/gpio.h"
#include "battery.h"
#include "led.h"
#include "monitor.h"
@@ -17,11 +19,24 @@ extern void led_svc_init(void);
static const char TAG[] = "services";
#ifdef CONFIG_SQUEEZEAMP
#define LED_GREEN_GPIO 12
#define LED_RED_GPIO 13
#endif
/****************************************************************************************
*
*/
void services_init(void) {
gpio_install_isr_service(0);
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();
led_svc_init();
}