-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdac-es9018.c
134 lines (106 loc) · 2.44 KB
/
dac-es9018.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <stdint.h>
#include <unistd.h>
#include <linux/input-event-codes.h>
#include "dac.h"
#include "mcp.h"
#include "mpd.h"
#include "gpio.h"
#include "utils.h"
#include "dac-es9018.h"
static void dac_on() {
gpio_set(GPIO_DAC_POWER, 1);
mcp->dac_power = 1;
xlog("DAC switched on");
msleep(500);
gpio_set(GPIO_EXT_POWER, 1);
mcp->ext_power = 1;
xlog("DAC switched EXT on");
}
static void dac_off() {
gpio_set(GPIO_EXT_POWER, 0);
mcp->ext_power = 0;
xlog("DAC switched EXT off");
msleep(500);
gpio_set(GPIO_DAC_POWER, 0);
mcp->dac_power = 0;
xlog("DAC switched off");
}
void dac_power() {
if (!mcp->dac_power) {
dac_on();
// wait for XMOS USB boot
msleep(5000);
mpdclient_handle(KEY_PLAY);
} else {
mpdclient_handle(KEY_STOP);
dac_off();
}
}
void dac_volume_up() {
if (!mcp->dac_power)
return;
gpio_configure(GPIO_VOL_UP, 1, 0, 1);
msleep(50);
gpio_set(GPIO_VOL_UP, 0);
msleep(50);
gpio_configure(GPIO_VOL_UP, 0, 0, 0);
xlog("DAC vol++");
}
void dac_volume_down() {
if (!mcp->dac_power)
return;
gpio_configure(GPIO_VOL_DOWN, 1, 0, 1);
msleep(50);
gpio_set(GPIO_VOL_DOWN, 0);
msleep(50);
gpio_configure(GPIO_VOL_DOWN, 0, 0, 0);
xlog("DAC vol--");
}
void dac_mute() {
}
void dac_unmute() {
}
void dac_source(int source) {
}
int dac_status_get(const void *p1, const void *p2) {
return 0;
}
void dac_status_set(const void *p1, const void *p2, int value) {
}
void dac_handle(int c) {
switch (c) {
case KEY_VOLUMEUP:
dac_volume_up();
break;
case KEY_VOLUMEDOWN:
dac_volume_down();
break;
case KEY_POWER:
dac_power();
break;
case KEY_REDO:
case KEY_TIME:
mcp->switch4 = gpio_toggle(GPIO_SWITCH4);
break;
default:
mpdclient_handle(c);
}
}
static int init() {
gpio_configure(GPIO_VOL_UP, 0, 0, 0);
gpio_configure(GPIO_VOL_DOWN, 0, 0, 0);
mcp->switch2 = gpio_configure(GPIO_SWITCH2, 1, 0, -1);
xlog("DAC SWITCH2 is %s", mcp->switch2 ? "ON" : "OFF");
mcp->switch3 = gpio_configure(GPIO_SWITCH3, 1, 0, -1);
xlog("DAC SWITCH3 is %s", mcp->switch3 ? "ON" : "OFF");
mcp->switch4 = gpio_configure(GPIO_SWITCH4, 1, 0, -1);
xlog("DAC SWITCH4 is %s", mcp->switch4 ? "ON" : "OFF");
mcp->dac_power = gpio_configure(GPIO_DAC_POWER, 1, 0, -1);
xlog("DAC power is %s", mcp->dac_power ? "ON" : "OFF");
mcp->ext_power = gpio_configure(GPIO_EXT_POWER, 1, 0, -1);
xlog("DAC EXT power is %s", mcp->ext_power ? "ON" : "OFF");
return 0;
}
static void stop() {
}
MCP_REGISTER(dac_es9018, 3, &init, &stop, NULL);