-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadcuser.c
164 lines (143 loc) · 4.77 KB
/
adcuser.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*----------------------------------------------------------------------------
* U S B - K e r n e l
*----------------------------------------------------------------------------
* Name: ADCUSER.C
* Purpose: Audio Device Class Custom User Module
* Version: V1.10
*----------------------------------------------------------------------------
* This software is supplied "AS IS" without any warranties, express,
* implied or statutory, including but not limited to the implied
* warranties of fitness for purpose, satisfactory quality and
* noninfringement. Keil extends you a royalty-free right to reproduce
* and distribute executable files created using this software for use
* on NXP Semiconductors LPC family microcontroller devices only. Nothing
* else gives you the right to use this software.
*
* Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
*---------------------------------------------------------------------------*/
#include "type.h"
#include "usb.h"
#include "audio.h"
#include "usbcfg.h"
#include "usbcore.h"
#include "adcuser.h"
#include "usbaudio.h"
uint16_t VolCur = 0x0100; /* Volume Current Value */
const uint16_t VolMin = 0x0000; /* Volume Minimum Value */
const uint16_t VolMax = 0x0100; /* Volume Maximum Value */
const uint16_t VolRes = 0x0004; /* Volume Resolution */
/*
* Audio Device Class Interface Get Request Callback
* Called automatically on ADC Interface Get Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
uint32_t ADC_IF_GetRequest (void) {
/*
Interface = SetupPacket.wIndex.WB.L;
EntityID = SetupPacket.wIndex.WB.H;
Request = SetupPacket.bRequest;
Value = SetupPacket.wValue.W;
...
*/
if (SetupPacket.wIndex.W == 0x0200) {
/* Feature Unit: Interface = 0, ID = 2 */
if (SetupPacket.wValue.WB.L == 0) {
/* Master Channel */
switch (SetupPacket.wValue.WB.H) {
case AUDIO_MUTE_CONTROL:
switch (SetupPacket.bRequest) {
case AUDIO_REQUEST_GET_CUR:
EP0Buf[0] = Mute;
return (TRUE);
}
break;
case AUDIO_VOLUME_CONTROL:
switch (SetupPacket.bRequest) {
case AUDIO_REQUEST_GET_CUR:
*((__packed uint16_t *)EP0Buf) = VolCur;
return (TRUE);
case AUDIO_REQUEST_GET_MIN:
*((__packed uint16_t *)EP0Buf) = VolMin;
return (TRUE);
case AUDIO_REQUEST_GET_MAX:
*((__packed uint16_t *)EP0Buf) = VolMax;
return (TRUE);
case AUDIO_REQUEST_GET_RES:
*((__packed uint16_t *)EP0Buf) = VolRes;
return (TRUE);
}
break;
}
}
}
return (FALSE); /* Not Supported */
}
/*
* Audio Device Class Interface Set Request Callback
* Called automatically on ADC Interface Set Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
uint32_t ADC_IF_SetRequest (void) {
/*
Interface = SetupPacket.wIndex.WB.L;
EntityID = SetupPacket.wIndex.WB.H;
Request = SetupPacket.bRequest;
Value = SetupPacket.wValue.W;
...
*/
if (SetupPacket.wIndex.W == 0x0200) {
/* Feature Unit: Interface = 0, ID = 2 */
if (SetupPacket.wValue.WB.L == 0) {
/* Master Channel */
switch (SetupPacket.wValue.WB.H) {
case AUDIO_MUTE_CONTROL:
switch (SetupPacket.bRequest) {
case AUDIO_REQUEST_SET_CUR:
Mute = EP0Buf[0];
return (TRUE);
}
break;
case AUDIO_VOLUME_CONTROL:
switch (SetupPacket.bRequest) {
case AUDIO_REQUEST_SET_CUR:
VolCur = *((__packed uint16_t *)EP0Buf);
return (TRUE);
}
break;
}
}
}
return (FALSE); /* Not Supported */
}
/*
* Audio Device Class EndPoint Get Request Callback
* Called automatically on ADC EndPoint Get Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
uint32_t ADC_EP_GetRequest (void) {
/*
EndPoint = SetupPacket.wIndex.WB.L;
Request = SetupPacket.bRequest;
Value = SetupPacket.wValue.W;
...
*/
return (FALSE); /* Not Supported */
}
/*
* Audio Device Class EndPoint Set Request Callback
* Called automatically on ADC EndPoint Set Request
* Parameters: None (global SetupPacket and EP0Buf)
* Return Value: TRUE - Success, FALSE - Error
*/
uint32_t ADC_EP_SetRequest (void) {
/*
EndPoint = SetupPacket.wIndex.WB.L;
Request = SetupPacket.bRequest;
Value = SetupPacket.wValue.W;
...
*/
return (FALSE); /* Not Supported */
}