USB BARCODE READER

Fork of USBHOST by ST

Committer:
shivanandgowdakr
Date:
Mon Jul 02 12:10:45 2018 +0000
Revision:
7:ccd0ac9ae1c9
Parent:
1:ab240722d7ef
USB BARCODE READER ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1 /* mbed USBHost Library
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 2 * Copyright (c) 2006-2013 ARM Limited
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 3 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 4 * Licensed under the Apache License, Version 2.0 (the "License");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 5 * you may not use this file except in compliance with the License.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 6 * You may obtain a copy of the License at
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 7 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 8 * http://www.apache.org/licenses/LICENSE-2.0
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 9 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 10 * Unless required by applicable law or agreed to in writing, software
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 11 * distributed under the License is distributed on an "AS IS" BASIS,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 13 * See the License for the specific language governing permissions and
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 14 * limitations under the License.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 15 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 16
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 17 #ifndef USBHOSTKEYBOARD_H
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 18 #define USBHOSTKEYBOARD_H
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 19
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 20 #include "USBHostConf.h"
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 21
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 22 #if USBHOST_KEYBOARD
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 23
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 24 #include "USBHost.h"
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 25
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 26 /**
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 27 * A class to communicate a USB keyboard
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 28 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 29 class USBHostKeyboard : public IUSBEnumerator {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 30 public:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 31
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 32 /**
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 33 * Constructor
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 34 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 35 USBHostKeyboard();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 36
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 37 /**
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 38 * Try to connect a keyboard device
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 39 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 40 * @return true if connection was successful
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 41 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 42 bool connect();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 43
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 44 /**
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 45 * Check if a keyboard is connected
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 46 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 47 * @returns true if a keyboard is connected
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 48 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 49 bool connected();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 50
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 51 /**
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 52 * Attach a callback called when a keyboard event is received
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 53 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 54 * @param ptr function pointer
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 55 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 56 inline void attach(void (*ptr)(uint8_t key)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 57 if (ptr != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 58 onKey = ptr;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 59 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 60 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 61
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 62 /**
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 63 * Attach a callback called when a keyboard event is received
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 64 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 65 * @param ptr function pointer
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 66 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 67 inline void attach(void (*ptr)(uint8_t keyCode, uint8_t modifier)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 68 if (ptr != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 69 onKeyCode = ptr;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 70 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 71 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 72
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 73 protected:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 74 //From IUSBEnumerator
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 75 virtual void setVidPid(uint16_t vid, uint16_t pid);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 76 virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 77 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 78
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 79 private:
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 80 USBHost * host;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 81 USBDeviceConnected * dev;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 82 USBEndpoint * int_in;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 83 uint8_t report[9];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 84 int keyboard_intf;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 85 bool keyboard_device_found;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 86
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 87 bool dev_connected;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 88
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 89 void rxHandler();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 90
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 91 void (*onKey)(uint8_t key);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 92 void (*onKeyCode)(uint8_t key, uint8_t modifier);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 93
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 94 int report_id;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 95
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 96 void init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 97
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 98 };
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 99
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 100 #endif
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 101
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 102 #endif