mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 11:36:59 +03:00
Merge branch 'master' of https://github.com/sle118/squeezelite-esp32.git
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "config.h"
|
||||
#include "services.h"
|
||||
#include "accessors.h"
|
||||
|
||||
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
@@ -236,7 +236,7 @@ static const i2c_db_t i2c_db[] = {
|
||||
};
|
||||
void i2c_load_configuration(){
|
||||
ESP_LOGD(TAG,"Loading configuration from nvs");
|
||||
const i2c_config_t * conf = services_get_i2c_config((int *)&i2c_port);
|
||||
const i2c_config_t * conf = config_i2c_get((int *)&i2c_port);
|
||||
i2c_gpio_scl = conf->scl_io_num;
|
||||
i2c_gpio_sda = conf->sda_io_num;
|
||||
i2c_frequency = conf->master.clk_speed;
|
||||
@@ -523,7 +523,7 @@ static int do_i2cconfig_cmd(int argc, char **argv)
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = i2c_frequency
|
||||
};
|
||||
services_store_i2c_config(&config, i2c_port);
|
||||
config_i2c_set(&config, i2c_port);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
@@ -254,7 +254,7 @@ void grfe_handler( u8_t *data, int len) {
|
||||
SSD1306_SetDisplayAddressMode( &Display, AddressMode );
|
||||
}
|
||||
|
||||
// try to minmize I2C traffic which is very slow
|
||||
// try to minimize I2C traffic which is very slow
|
||||
int rows = (Display.Height > 32) ? 4 : Display.Height / 8;
|
||||
for (int r = 0; r < rows; r++) {
|
||||
uint8_t first = 0, last;
|
||||
@@ -264,7 +264,7 @@ void grfe_handler( u8_t *data, int len) {
|
||||
for (int c = 0; c < Display.Width; c++) {
|
||||
if (*iptr != *optr) {
|
||||
if (first) last = c;
|
||||
else first = c;
|
||||
else first = c + 1;
|
||||
}
|
||||
*optr++ = BitReverseTable256[*iptr];
|
||||
iptr += rows;
|
||||
|
||||
58
components/services/accessors.c
Normal file
58
components/services/accessors.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#include <driver/i2c.h>
|
||||
#include "config.h"
|
||||
#include "accessors.h"
|
||||
#include "globdefs.h"
|
||||
|
||||
static const char *TAG = "services";
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
esp_err_t config_i2c_set(const i2c_config_t * config, int port){
|
||||
int buffer_size=255;
|
||||
char * config_buffer=calloc(buffer_size,1);
|
||||
if(config_buffer) {
|
||||
snprintf(config_buffer,buffer_size,"scl=%u sda=%u speed=%u port=%u",config->scl_io_num,config->sda_io_num,config->master.clk_speed,port);
|
||||
ESP_LOGI(TAG,"Updating i2c configuration to %s",config_buffer);
|
||||
config_set_value(NVS_TYPE_STR, "i2c_config", config_buffer);
|
||||
free(config_buffer);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
const i2c_config_t * config_i2c_get(int * i2c_port) {
|
||||
char *nvs_item, *p;
|
||||
static i2c_config_t i2c = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = -1,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_io_num = -1,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = 400000,
|
||||
};
|
||||
|
||||
nvs_item = config_alloc_get(NVS_TYPE_STR, "i2c_config");
|
||||
if (nvs_item) {
|
||||
if ((p = strcasestr(nvs_item, "scl")) != NULL) i2c.scl_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "sda")) != NULL) i2c.sda_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "speed")) != NULL) i2c.master.clk_speed = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "port")) != NULL) i2c_system_port = atoi(strchr(p, '=') + 1);
|
||||
free(nvs_item);
|
||||
}
|
||||
if(i2c_port) *i2c_port=i2c_system_port;
|
||||
return &i2c;
|
||||
}
|
||||
15
components/services/accessors.h
Normal file
15
components/services/accessors.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "driver/i2c.h"
|
||||
|
||||
esp_err_t config_i2c_set(const i2c_config_t * config, int port);
|
||||
const i2c_config_t * config_i2c_get(int * i2c_port);
|
||||
@@ -36,12 +36,12 @@ typedef struct {
|
||||
actrls_config_map_handler * handler;
|
||||
} actrls_config_map_t;
|
||||
|
||||
esp_err_t actrls_process_member(const cJSON * member, actrls_config_t *cur_config);
|
||||
esp_err_t actrls_process_button(const cJSON * button, actrls_config_t *cur_config);
|
||||
esp_err_t actrls_process_int (const cJSON * member, actrls_config_t *cur_config, uint32_t offset);
|
||||
esp_err_t actrls_process_type (const cJSON * member, actrls_config_t *cur_config, uint32_t offset);
|
||||
esp_err_t actrls_process_bool (const cJSON * member, actrls_config_t *cur_config, uint32_t offset);
|
||||
esp_err_t actrls_process_action (const cJSON * member, actrls_config_t *cur_config, uint32_t offset);
|
||||
static esp_err_t actrls_process_member(const cJSON * member, actrls_config_t *cur_config);
|
||||
static esp_err_t actrls_process_button(const cJSON * button, actrls_config_t *cur_config);
|
||||
static esp_err_t actrls_process_int (const cJSON * member, actrls_config_t *cur_config, uint32_t offset);
|
||||
static esp_err_t actrls_process_type (const cJSON * member, actrls_config_t *cur_config, uint32_t offset);
|
||||
static esp_err_t actrls_process_bool (const cJSON * member, actrls_config_t *cur_config, uint32_t offset);
|
||||
static esp_err_t actrls_process_action (const cJSON * member, actrls_config_t *cur_config, uint32_t offset);
|
||||
|
||||
static const actrls_config_map_t actrls_config_map[] =
|
||||
{
|
||||
@@ -133,7 +133,10 @@ esp_err_t actrls_init(int n, const actrls_config_t *config) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
actrls_action_e actrls_parse_action_json(const char * name){
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static actrls_action_e actrls_parse_action_json(const char * name){
|
||||
|
||||
for(int i=0;i<ACTRLS_MAX && actrls_action_s[i][0]!='\0' ;i++){
|
||||
if(!strcmp(actrls_action_s[i], name)){
|
||||
@@ -143,14 +146,21 @@ actrls_action_e actrls_parse_action_json(const char * name){
|
||||
return ACTRLS_NONE;
|
||||
}
|
||||
|
||||
esp_err_t actrls_process_int (const cJSON * member, actrls_config_t *cur_config,uint32_t offset){
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static esp_err_t actrls_process_int (const cJSON * member, actrls_config_t *cur_config,uint32_t offset){
|
||||
esp_err_t err = ESP_OK;
|
||||
ESP_LOGD(TAG,"Processing int member");
|
||||
int *value = (int*)((char*) cur_config + offset);
|
||||
*value = member->valueint;
|
||||
return err;
|
||||
}
|
||||
esp_err_t actrls_process_type (const cJSON * member, actrls_config_t *cur_config, uint32_t offset){
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static esp_err_t actrls_process_type (const cJSON * member, actrls_config_t *cur_config, uint32_t offset){
|
||||
esp_err_t err = ESP_OK;
|
||||
ESP_LOGD(TAG,"Processing type member");
|
||||
int *value = (int *)((char*) cur_config + offset);
|
||||
@@ -167,7 +177,10 @@ esp_err_t actrls_process_type (const cJSON * member, actrls_config_t *cur_config
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t actrls_process_bool (const cJSON * member, actrls_config_t *cur_config, uint32_t offset){
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static esp_err_t actrls_process_bool (const cJSON * member, actrls_config_t *cur_config, uint32_t offset){
|
||||
esp_err_t err = ESP_OK;
|
||||
if(!member) {
|
||||
ESP_LOGE(TAG,"Null json member pointer!");
|
||||
@@ -187,7 +200,11 @@ esp_err_t actrls_process_bool (const cJSON * member, actrls_config_t *cur_config
|
||||
|
||||
return err;
|
||||
}
|
||||
esp_err_t actrls_process_action (const cJSON * member, actrls_config_t *cur_config, uint32_t offset){
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static esp_err_t actrls_process_action (const cJSON * member, actrls_config_t *cur_config, uint32_t offset){
|
||||
esp_err_t err = ESP_OK;
|
||||
cJSON * button_action= cJSON_GetObjectItemCaseSensitive(member, "pressed");
|
||||
actrls_action_e*value = (actrls_action_e*)((char *)cur_config + offset);
|
||||
@@ -210,8 +227,10 @@ esp_err_t actrls_process_action (const cJSON * member, actrls_config_t *cur_conf
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t actrls_process_member(const cJSON * member, actrls_config_t *cur_config) {
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static esp_err_t actrls_process_member(const cJSON * member, actrls_config_t *cur_config) {
|
||||
esp_err_t err = ESP_OK;
|
||||
const actrls_config_map_t * h=actrls_config_map;
|
||||
|
||||
@@ -230,7 +249,10 @@ esp_err_t actrls_process_member(const cJSON * member, actrls_config_t *cur_confi
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t actrls_process_button(const cJSON * button, actrls_config_t *cur_config) {
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static esp_err_t actrls_process_button(const cJSON * button, actrls_config_t *cur_config) {
|
||||
esp_err_t err= ESP_OK;
|
||||
const cJSON *member;
|
||||
|
||||
@@ -244,7 +266,10 @@ esp_err_t actrls_process_button(const cJSON * button, actrls_config_t *cur_confi
|
||||
|
||||
}
|
||||
|
||||
actrls_config_t * actrls_init_alloc_structure(const cJSON *buttons){
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static actrls_config_t * actrls_init_alloc_structure(const cJSON *buttons){
|
||||
int member_count = 0;
|
||||
const cJSON *button;
|
||||
actrls_config_t * json_config=NULL;
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
#include <stdio.h>
|
||||
#include "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "services.h"
|
||||
#include <driver/i2c.h>
|
||||
#include "config.h"
|
||||
#include "battery.h"
|
||||
#include "led.h"
|
||||
#include "monitor.h"
|
||||
#include "globdefs.h"
|
||||
#include "accessors.h"
|
||||
|
||||
extern void battery_svc_init(void);
|
||||
extern void monitor_svc_init(void);
|
||||
@@ -24,48 +25,11 @@ int i2c_system_port = I2C_SYSTEM_PORT;
|
||||
|
||||
static const char *TAG = "services";
|
||||
|
||||
esp_err_t services_store_i2c_config(const i2c_config_t * config, int i2c_system_port){
|
||||
int buffer_size=255;
|
||||
char * config_buffer=malloc(buffer_size);
|
||||
memset(config_buffer,0x00,buffer_size);
|
||||
if(config_buffer) {
|
||||
snprintf(config_buffer,buffer_size,"scl=%u sda=%u speed=%u port=%u",config->scl_io_num,config->sda_io_num,config->master.clk_speed,i2c_system_port);
|
||||
ESP_LOGI(TAG,"Updating i2c configuration to %s",config_buffer);
|
||||
config_set_value(NVS_TYPE_STR, "i2c_config", config_buffer);
|
||||
free(config_buffer);
|
||||
}
|
||||
return ESP_OK;
|
||||
|
||||
}
|
||||
const i2c_config_t * services_get_i2c_config(int * i2c_port) {
|
||||
char *nvs_item, *p;
|
||||
static i2c_config_t i2c = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = -1,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_io_num = -1,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master.clk_speed = 400000
|
||||
};
|
||||
|
||||
nvs_item = config_alloc_get(NVS_TYPE_STR, "i2c_config");
|
||||
if (nvs_item) {
|
||||
if ((p = strcasestr(nvs_item, "scl")) != NULL) i2c.scl_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "sda")) != NULL) i2c.sda_io_num = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "speed")) != NULL) i2c.master.clk_speed = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(nvs_item, "port")) != NULL) i2c_system_port = atoi(strchr(p, '=') + 1);
|
||||
free(nvs_item);
|
||||
}
|
||||
if(i2c_port) *i2c_port=i2c_system_port;
|
||||
return &i2c;
|
||||
}
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void services_init(void) {
|
||||
|
||||
gpio_install_isr_service(0);
|
||||
const i2c_config_t * i2c_config = services_get_i2c_config(&i2c_system_port);
|
||||
|
||||
#ifdef CONFIG_SQUEEZEAMP
|
||||
if (i2c_system_port == 0) {
|
||||
@@ -74,14 +38,16 @@ void services_init(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG,"Configuring I2C sda:%d scl:%d port:%u speed:%u", i2c_config->sda_io_num,i2c_config->scl_io_num, i2c_system_port, i2c_config->master.clk_speed);
|
||||
const i2c_config_t * i2c_config = config_i2c_get(&i2c_system_port);
|
||||
|
||||
ESP_LOGI(TAG,"Configuring I2C sda:%d scl:%d port:%u speed:%u", i2c_config->sda_io_num, i2c_config->scl_io_num, i2c_system_port, i2c_config->master.clk_speed);
|
||||
|
||||
if (i2c_config->sda_io_num != -1 && i2c_config->scl_io_num != -1) {
|
||||
i2c_param_config(i2c_system_port, i2c_config);
|
||||
i2c_driver_install(i2c_system_port, i2c_config->mode, 0, 0, 0 );
|
||||
} else {
|
||||
ESP_LOGE(TAG, "can't initialize I2C");
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG,"Configuring LEDs");
|
||||
led_svc_init();
|
||||
@@ -90,4 +56,4 @@ void services_init(void) {
|
||||
|
||||
battery_svc_init();
|
||||
monitor_svc_init();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* audio control callbacks
|
||||
*
|
||||
* (c) Sebastien 2019
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef COMPONENTS_SERVICES_SERVICES_H_
|
||||
#define COMPONENTS_SERVICES_SERVICES_H_
|
||||
#include <driver/i2c.h>
|
||||
#include "esp_system.h"
|
||||
|
||||
const i2c_config_t * services_get_i2c_config(int * i2c_port);
|
||||
esp_err_t services_store_i2c_config(const i2c_config_t * config, int i2c_system_port);
|
||||
void services_init(void);
|
||||
void display_init(char *welcome);
|
||||
|
||||
|
||||
|
||||
#endif /* COMPONENTS_SERVICES_SERVICES_H_ */
|
||||
@@ -47,7 +47,6 @@
|
||||
#include <math.h>
|
||||
#include "config.h"
|
||||
#include "audio_controls.h"
|
||||
#include "services.h"
|
||||
|
||||
// todo: this should be moved to the build scripts definitions
|
||||
static const char * actrls_brd1 = "[{\"gpio\":4,\"type\":\"BUTTON_LOW\",\"pull\":true,\"long_press\":1000, \"debounce\":0,\"shifter_gpio\":-1,\"normal\":{\"pressed\":\"ACTRLS_VOLUP\",\"released\":\"ACTRLS_NONE\"},\"longpress\":{\"pressed\":\"ACTRLS_PREV\",\"released\":\"ACTRLS_NONE\"},\"shifted\":{\"pressed\":\"ACTRLS_NONE\",\"released\":\"ACTRLS_NONE\"},\"longshifted\":{\"pressed\":\"ACTRLS_NONE\",\"released\":\"ACTRLS_NONE\"}},{\"gpio\":5,\"type\":\"BUTTON_LOW\",\"pull\":true,\"long_press\":1000, \"debounce\":0,\"shifter_gpio\":4,\"normal\":{\"pressed\":\"ACTRLS_VOLDOWN\",\"released\":\"ACTRLS_NONE\"},\"longpress\":{\"pressed\":\"ACTRLS_NEXT\",\"released\":\"ACTRLS_NONE\"},\"shifted\":{\"pressed\":\"ACTRLS_TOGGLE\",\"released\":\"ACTRLS_NONE\"},\"longshifted\":{\"pressed\":\"BCTRLS_DOWN\",\"released\":\"ACTRLS_NONE\"}}]";
|
||||
@@ -71,6 +70,9 @@ static bool bWifiConnected=false;
|
||||
extern const uint8_t server_cert_pem_start[] asm("_binary_github_pem_start");
|
||||
extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end");
|
||||
|
||||
// as an exception _init function don't need include
|
||||
extern void services_init(void);
|
||||
extern void display_init(char *welcome);
|
||||
|
||||
/* brief this is an exemple of a callback that you can setup in your own app to get notified of wifi manager event */
|
||||
void cb_connection_got_ip(void *pvParameter){
|
||||
|
||||
Reference in New Issue
Block a user