Example: bachelor of science

USB Keyboard Using MSP430 Microcontrollers - …

1 SLAA514 December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 MicrocontrollersApplicationReportSLAA514 December2011 USBK eyboardUsingMSP430 MicrocontrollersDavidRacine,Luis applicationreportdescribesa low-costhighly-flexiblecompositeUSBkeybo ardimplementationbasedon MSP430F5 includedallowingfor an easyimplementationand documentexplainsbasicnecessaryconceptsbu t familiaritywiththe MSP430 USBD evelopersPackage( MSP430 USBDEVPACK) and USBHID specificationis additionalinformationdescribedin this applicationreportcan be of Figures1 Key a Key a Key "Ghost" Key HID of Tables1 VID/PIDU sedby the December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 MicrocontrollersTrademarksMSP430,CodeCom poserStudioare trademarksof EmbeddedWorkbenchis a trademarkof IAR applicationreportdescribesthe implementationof a USBkeyboardwith the followingcharacteristics: 101 keys,2 LEDs:standardHID keyboardand LEDusage 16x8matrix:allowsfor easycustomizationof differentkeyboardlayouts CompositeUSBdevice:In additionto the keyboardinterface,it includesan HID-datapipeback-channelwhichcan be usedto transmitany customdata HID bootprotocolsupport,allowingkeyboar

Application Report SLAA514– December 2011 USB Keyboard Using MSP430™ Microcontrollers David Racine, Luis Reynoso..... MSP430 Apps ABSTRACT This application report describes a low-costhighly-flexiblecomposite USB keyboard implementation based

Tags:

  Using, Microcontrollers, Keyboard, Msp430, Usb keyboard using msp430 microcontrollers

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of USB Keyboard Using MSP430 Microcontrollers - …

1 1 SLAA514 December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 MicrocontrollersApplicationReportSLAA514 December2011 USBK eyboardUsingMSP430 MicrocontrollersDavidRacine,Luis applicationreportdescribesa low-costhighly-flexiblecompositeUSBkeybo ardimplementationbasedon MSP430F5 includedallowingfor an easyimplementationand documentexplainsbasicnecessaryconceptsbu t familiaritywiththe MSP430 USBD evelopersPackage( MSP430 USBDEVPACK) and USBHID specificationis additionalinformationdescribedin this applicationreportcan be of Figures1 Key a Key a Key "Ghost" Key HID of Tables1 VID/PIDU sedby the December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 MicrocontrollersTrademarksMSP430,CodeCom poserStudioare trademarksof EmbeddedWorkbenchis a trademarkof IAR applicationreportdescribesthe implementationof a USBkeyboardwith the followingcharacteristics: 101 keys,2 LEDs:standardHID keyboardand LEDusage 16x8matrix:allowsfor easycustomizationof differentkeyboardlayouts CompositeUSBdevice.

2 In additionto the keyboardinterface,it includesan HID-datapipeback-channelwhichcan be usedto transmitany customdata HID bootprotocolsupport,allowingkeyboardto be usedto interfacewith a PC'sBIOS "Ghost"key handlingin software,to preventerrorsfrommultiplekey presses UsesMSP430F550x/5510low-costUSBfamilyThe TexasInstrumentsMSP430F550x/5510devicesa re ultra-lowpowermicrocontrollersfeaturinga powerful16-bitRISCCPU,16-bitregisters,an d constantgeneratorsthat contributeto addition,this MSP430familyincludesan integratedUSBand full-speedcommunication,four 16-bittimers,a high-performance10-bitanalog-to-digitalc onverter(ADC),twouniversalserialcommunic ationinterfaces(USCI),hardwaremultiplier ,DMA,real-timeclockmodulewithalarmcapabi lities,and 31 or 47 I/O MatrixThe USBkeyboardpresentedin this applicationreportimplementsa key matrixof rowsand columnssimilarto smallerkeypadslike the one shownin the applicationreportImplementingAn Ultralow-PowerKeypadInterfacewith MSP430 (SLAA139).

3 This implementationusesa 16 rowsx 8 columnsmatrix,whichallowsup to 128 keys,but it actuallyusesonly 101 keysin key matrixis shownin + ~`1 QARightAltLeftAltCSpace barF3F4 CapsLock3 EDXZF2F1 Esc2 WSVBGT54 RFMNHY67UJ>. |\F11F109 OLRightShiftLeftShift<,Keypad*F7F6F58 IKKeypad8F9 RightCtrlLeftCtrl?/ _-F120P{[:; EnterPrtScrEnd+=Backspace}]PageDown December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 MicrocontrollersFigure1. Key MatrixEachkey workslike a switch,and pulldownsare implementedon eachcolumn,keepingthe idle statelow(seeFigure2).Figure2. KeyboardSchematicThereare multiplewaysto scana key matrix,but this applicationreportusestwo methods,referredin thisapplicationreportas: column-interruptand Enter Keypad+ Enter Keypad+ December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 MicrocontrollersIn the column-interruptapproach,all rowsare activelydrivenat the sametime and columnsare configuredto interruptthe processorwhenany singlekey is methodis usefulin low-powermodes,becauseany key can wakeup the microcontroller;however,itis importantto remarkthat the key pressis only usedfor that purpose,becauseit doesnot providetheexactkey showsthe key matrixbehaviorwhenthe Enterkey is pressedin columnsare shownin red.

4 Noticethat the Col1pin woulddetecta changewhenthe Enterkey is pressed,but the effectwouldbe the samefor any otherpin pressedin the Detectionof a Key UsingColumn-InterruptMethodAfterthe systemis awakedue to a key pressusingthe column-interruptapproach,the pollingmethodcanbe usedto determinewhichkey(s)is(are)beingpressed( seeFigure4). In the pollingmethod,eachrow isscannedseparatelydrivingone row at a time in columnsare Detectionof a Key UsingPollingMethodOne of the caveatswhenusingthis methodis that particularpatternscan causeunwantedconnections,knownas "ghost" behavioris causedwhenthreeor morekeyssharingrowsand columnsarepressedat the sametime (seeFigure5). Enter Keypad+ Enter Keypad+ Enter, PtrScr andkeys are pressed 2. Driving Row14 detects Enterand Enter Keypad+ Driving Row15 detectsbutit incorrectly detects F8 December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 MicrocontrollersFigure5.

5 "Ghost" Key DetectionThe softwareincludedin this applicationreportdetectspotential"ghost" keysand doesnot reportthemtothe applicationreportusesthe MSP430applicationprogramminginterface(AP I)stackfoundin theMSP430 USBD evelopersPackage( MSP430 USBDEVPACK).The stackis configuredto workas a compositeHID-HIDinterfacewith the first interfacebeinga standardKeyboardand the secondinterfaceusedas a of the advantagesof usingthisimplementation,whichusingonly HID interfaces,is that no driversare relevantcodefor the keyboardimplementationusesthe standardkeyboardinterface,theDataPipeint erfacewas addedto provideuserswith moreflexibilityand to interfacecan be usedto sendor receiveany type of datato/fromthe host,so that the MSP430microcontrollernot only performsthe job of a digitalkeyboard,but it can also be usedto performotherjobs takingadvantageof the sameUSBinterfaceand the rest of the reportingto PC, controllingactuatorsusingtimerPWMs, shouldbe notedthat whilethe host OS interpretsand usesthe datafromthe standardkeyboardinterfacewithoutaddition alapplicationsor drivers.

6 In the caseof the Datapipeinterface,a host applicationis HID API whichenablescommunicationbetweena PC and aMSP430microcontrollerrunningthe HID API HID API is availablein executableformatandsourcecodein the MSP430 USBD evelopersPackage( MSP430 USBDEVPACK).The keyboardinterfacesupportsBootprotocol,wh ichallowsit to workwith HID-limitedhosts(suchassomeBIOS).VID and PID can be modifiedaccordingto the particularapplicationbut the defaultcodeusedfor thisexampleusesthe valuesshownin VID/PIDU sedby the DeviceVID0x2047 PID0x0401 USBGPIOsTimerPMMUCSDMAUSB APIUSB HIDticktimerMSP430 DriverlibDKS (Digital Keyscan) Keyboard ReportCommProtocolUSB December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 softwareincludedin this applicationreportwas built and testedusing: IAR EmbeddedWorkbench for CodeComposerStudio (CCS) showsthe softwarelayersfor the USBK eyboardSoftwareModulesSoftwareis designedin a modularway,re-usingexistingTI librariessuchas driverliband the USBAPIand addingnew modulesfromlow-leveldriversto.

7 USBK eyboardDescriptionMainapplicationinitial izingthe microcontroller,peripherals,and executinga loop checkingandservicingthe rest of the \ KeyboardInitialize:PMM,UCS (clocks),GPIOs,Timers,USB,Timer,USB Active?Disable DKSUSBS uspended?USB orKeyboardactivity?Wake MCUF orce RemoteWakeupDatareceived?Process RX datafrom HID0/HID1 First loop?Initialize DKS andKBD_ReportmodulesAttend DKSmoduleAttendKBD_ReportmodulePendingta sks?SleepUSB, Timer orKeyboard activity? December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 MicrocontrollersFigure7. December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 Microcontrollers KeyboardReportDescriptionHandlesthe HID Keyboardreport,addingand removingkeysfromthe reportdependingonpress/releaseeventsand sendsthe reportto the \ \Include\ KeyboardReportFormatTable2.

8 HID KeyboardReportFormatBit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 Byte0 RightGUIR ightAltRightShiftRightCtrlLeft GUILeft AltLeft ShiftLeft CtrlByte1 ReservedByte2 Key_array[0]Byte3 Key_array[1]Byte4 Key_array[2]Byte5 Key_array[3]Byte6 Key_array[4]Byte7 Key_array[5] CommunicationProtocolDescriptionHandlest he HID custominterface,whichis usedto transferdatato/froman currentimplementationshowsa templatethat can be usedfor moduleusesthe HID-Datapipeas definedin the USBAPI includedin MSP430 USBD evelopersPackage( MSP430 USBDEVPACK).FilesSrc\ \Include\ CustomInterfaceReportDescriptorTable3. CommunicationProtocolReportDescriptorFie ldSizeDescriptionIN ReportReportID1 byteThe reportID of the chosenreport(automaticallyassignedto 0x3 Fbythe HID-Datapipecalls)Size1 byteThe numberof validbytesin the datafieldData62 bytesDatapayloadOUTR eportReportID1 byteThe reportID of the chosenreport(mustbe assignedto 0x3 Fby thehost)Size1 byteThe numberof validbytesin the datafieldData62 bytesDatapayloadDataPayloadProtocolTable 4.

9 ImplementedProtocolFieldSizeDescriptionC MD1 byte1 = ToggleCAPSLED2 = ToggleNUMLEDData61 bytesUnusedDigital KeyScanMode?Key pressdetected?DKS is initialized in interrupt-column mode bydefault if no key is to PollingmodeScan key matrix Ghost key?Key event?Keydebounced?Remove key fromreportIncrementdebounce counterReturnInactive timerexpired?Change toInterrupt-ColumnmodeAdd key to December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 Microcontrollers DKS(DigitalKeyScan)DescriptionHandlesthe digitalkeyboardscanning,detectingkey press/releaseevents,and reportingthemto \ \Include\ December2011 SubmitDocumentationFeedbackCopyright 2011,TexasInstrumentsIncorporatedUSBK eyboardUsingMSP430 Microcontrollers USBAPI / USBHIDD escriptionThe MSP430 USBAPI stackis a softwaresolutionprovidedby TexasInstrumentsthat includessupportfor: CommunicationsDeviceClass(CDC) HumanInterfaceDeviceclass(HID) MassStorageClass(MSC) PersonalHealthCareDeviceClass(PHDC)This softwaresolution,includingdetaileddocume ntation,is availablein the MSP430 USBD evelopersPackage( MSP430 USBDEVPACK).

10 FilesSrc\USB_API\*.*Src\USB_config\*.*Sr c\USB_App\*.* TicktimerDescriptionHandlesa generalpurposeinterrupttimerthat is usedas a timebase,to wake-upthe processor,and totriggera new keyboardscan, ticktimeris a defaulttime baseof 2 \ \Include\ MSP430 DriverlibDescriptionThe TexasInstrumentsMSP430 PeripheralDriverLibrary(Driverlib)is a set of driversthat provideaneasymechanismto use the softwareusesDriverlibto initializethe detaileddocumentationare availablein MSP430 Ware( ).For simplicitypurposes,this projectincludesonly the pre-compiledlibrariesfor IAR and CCSusingasmallmemorymodeland \ driverlib\*.hSrc\ driverlib\ \ driverlib\ ScanCodeTablesFor modularitypurposesand to allowfor an easieroptimizationor upgrade,the USBkeyboardsoftwarereservessomeFlashsect orsfor constanttablesthat definesomeof the functionalityof the applicationanddefinethe ScanCodetable.


Related search queries