globalize a few things

This commit is contained in:
philippe44
2020-01-14 16:11:15 -08:00
parent eb5c7c3cea
commit e96ba5fd5b
6 changed files with 102 additions and 33 deletions

View 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
#endif

View File

@@ -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)

View File

@@ -9,26 +9,63 @@
#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);
}
#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();