Usb Device Interface, protocol, and programming homework #4 Audio Control device

Dependencies:   C12832_lcd USBDevice mbed

Revision:
1:948ffad3284f
Parent:
0:69eb9d19fb91
Child:
2:dec5e78d579b
diff -r 69eb9d19fb91 -r 948ffad3284f main.cpp
--- a/main.cpp	Tue Jul 30 22:35:10 2013 +0000
+++ b/main.cpp	Wed Jul 31 22:20:00 2013 +0000
@@ -3,40 +3,57 @@
 #include "USBAudioControl.h"
 #include "MyDisplayClass.h"
 
-#define PAUSEKEY 16
+//Define Key words for the special disconnect/connect functionality
+#define PAUSEKEY 0x10
 #define NUMSECONDSTOHOLD 5
 
+//Joystick array for the audio control functions
 BusIn btnArray(p15,p12,p13,p16,p14);
+//Display LED to provide feedback during the hold button sequence
 DigitalOut toggle(LED1);
 
+//Group all the display items in a class. This class creates a LCD object, and bargraph object
 MyDisplayClass display;
+
+//Set up the USB HID device
 USBAudioControl hid(0x1234,0x0006,0x0001);
+//temporary structure to hold data before filling the input report
 HID_REPORT tempReport;
 
-unsigned int features=0;
+
+//Variable to hold USB state
+// Bit 0: suspended=0,normal=1
+// Bit 1: 1=USB configured, 0 USB not configured
 unsigned int USBstate=0;
 
+//Callback funciton: When an Output Report is received, set the current volume level.
 void SetLevel(HID_REPORT *report){
     display.setLevel(report->data[0]);   
 }
 
+//Callback Function: When a feature report is sent, change the feature bits, and the scale
 void SetFeatures(HID_REPORT *report){
-    features=(report->data[1]&0x30)>>4;
+    display.volumeDisplayEnable=((report->data[1]&0x10)>>4)==0x1;
+    display.graphicModeEnable=((report->data[1]&0x20)>>5)==0x1;   
     display.setMaxLevel((report->data[1]&0x0f)<<2);
 }
 
+//Function to write the USB configured bit, this is polled.
 void WriteConnectedBit(unsigned int connected){
     USBstate = (connected << 1) | (USBstate & 0x1);
 }
 
+//Callback function: When the Suspend bit is changed, update USBstate
 void WriteSuspendBit(unsigned int suspend){
     USBstate = (suspend) | (USBstate & 0x2);
 }
- 
+
+//Fill a temp report with the button array state 
 void PollInputs(HID_REPORT *tempReport) {
    tempReport->data[0]=btnArray;
 }
 
+//Provide a check for a special button combination to connect and disconnect.
 void CheckForHeldPauseKey(HID_REPORT * tempreport, USBAudioControl * hid, DigitalOut * toggle){
  static int holdCount=0;
      
@@ -57,21 +74,33 @@
      }
 }
 
+
+//Main Function
 int main() {
    
+   //Assign callback functions for USB events
     hid.callbackSetOutputReport=&SetLevel;
     hid.callbackSetFeatureReport=&SetFeatures;
     hid.callbackSuspendChange=&WriteSuspendBit;
+    //The temp report needs to know how many bytes it has. 
+    // TODO: The Hid_report structure in USBHID_TYPES should be changed to a class.
     tempReport.length=1;
     
+    //Main Loop
     while(1) {
+     //Poll Inputs
      PollInputs(&tempReport);
+     //Poll USB Configured
      WriteConnectedBit(hid.getConnectState());
+     //Hidden Configureation option
      CheckForHeldPauseKey(&tempReport,&hid,&toggle);
+     //Set up the input data for a send
      hid.FillInputReport(&tempReport);
-     display.update(USBstate,features); 
+     //Update the display
+     display.update(USBstate); 
      wait(0.1);
     }
 }
 
 
+