mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-29 22:00:54 +03:00
big merge
This commit is contained in:
65
components/squeezelite/external/dac_external.c
vendored
65
components/squeezelite/external/dac_external.c
vendored
@@ -20,8 +20,8 @@
|
||||
|
||||
static const char TAG[] = "DAC external";
|
||||
|
||||
static void speaker(bool active) { }
|
||||
static void headset(bool active) { }
|
||||
static void speaker(bool active);
|
||||
static void headset(bool active);
|
||||
static bool volume(unsigned left, unsigned right) { return false; }
|
||||
static void power(adac_power_e mode);
|
||||
static bool init(char *config, int i2c_port_num, i2s_config_t *i2s_config);
|
||||
@@ -95,6 +95,22 @@ static void power(adac_power_e mode) {
|
||||
else i2c_json_execute("poweron");
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* speaker
|
||||
*/
|
||||
static void speaker(bool active) {
|
||||
if (active) i2c_json_execute("speakeron");
|
||||
else i2c_json_execute("speakeroff");
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* headset
|
||||
*/
|
||||
static void headset(bool active) {
|
||||
if (active) i2c_json_execute("headseton");
|
||||
else i2c_json_execute("headsetoff");
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
@@ -104,25 +120,40 @@ bool i2c_json_execute(char *set) {
|
||||
|
||||
if (!json_set) return true;
|
||||
|
||||
cJSON_ArrayForEach(item, json_set)
|
||||
{
|
||||
cJSON_ArrayForEach(item, json_set) {
|
||||
cJSON *reg = cJSON_GetObjectItemCaseSensitive(item, "reg");
|
||||
cJSON *val = cJSON_GetObjectItemCaseSensitive(item, "val");
|
||||
cJSON *mode = cJSON_GetObjectItemCaseSensitive(item, "mode");
|
||||
|
||||
if (cJSON_IsArray(val)) {
|
||||
cJSON *value;
|
||||
uint8_t *data = malloc(cJSON_GetArraySize(val));
|
||||
int count = 0;
|
||||
|
||||
if (!data) continue;
|
||||
|
||||
cJSON_ArrayForEach(value, val) {
|
||||
data[count++] = value->valueint;
|
||||
}
|
||||
|
||||
adac_write(i2c_addr, reg->valueint, data, count);
|
||||
free(data);
|
||||
} else {
|
||||
cJSON *mode = cJSON_GetObjectItemCaseSensitive(item, "mode");
|
||||
|
||||
if (!reg || !val) continue;
|
||||
if (!reg || !val) continue;
|
||||
|
||||
if (!mode) {
|
||||
adac_write_byte(i2c_addr, reg->valueint, val->valueint);
|
||||
} else if (!strcasecmp(mode->valuestring, "or")) {
|
||||
uint8_t data = adac_read_byte(i2c_addr,reg->valueint);
|
||||
data |= (uint8_t) val->valueint;
|
||||
adac_write_byte(i2c_addr, reg->valueint, data);
|
||||
} else if (!strcasecmp(mode->valuestring, "and")) {
|
||||
uint8_t data = adac_read_byte(i2c_addr, reg->valueint);
|
||||
data &= (uint8_t) val->valueint;
|
||||
adac_write_byte(i2c_addr, reg->valueint, data);
|
||||
}
|
||||
if (!mode) {
|
||||
adac_write_byte(i2c_addr, reg->valueint, val->valueint);
|
||||
} else if (!strcasecmp(mode->valuestring, "or")) {
|
||||
uint8_t data = adac_read_byte(i2c_addr,reg->valueint);
|
||||
data |= (uint8_t) val->valueint;
|
||||
adac_write_byte(i2c_addr, reg->valueint, data);
|
||||
} else if (!strcasecmp(mode->valuestring, "and")) {
|
||||
uint8_t data = adac_read_byte(i2c_addr, reg->valueint);
|
||||
data &= (uint8_t) val->valueint;
|
||||
adac_write_byte(i2c_addr, reg->valueint, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user