Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
UsbHidPeripheral.h
1 /*
2  * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _UsbHidPeripheral_h_
32 #define _UsbHidPeripheral_h_
33 
34 #include "Peripheral.h"
35 #include "hidapi.h"
36 
39 
40 namespace blfwk
41 {
48 {
49 public:
52  {
53  kDefault_Vid = 0x15a2,
54  kDefault_Pid = 0x0073,
55  };
56 
57 public:
62 
68  UsbHidPeripheral(unsigned short vendor_id, unsigned short product_id, const char *serial_number);
69 
71  virtual ~UsbHidPeripheral();
72 
79  virtual status_t read(uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t timeoutMS);
80 
84  virtual status_t write(const uint8_t *buffer, uint32_t byteCount) { return kStatus_Success; }
90  status_t write(const uint8_t *buffer, uint32_t byteCount, uint32_t timeoutMS);
91 
93  unsigned short getVendorId() { return m_vendor_id; }
95  unsigned short getProductId() { return m_product_id; }
97  const wchar_t *getSerialNumber() { return m_serial_number.c_str(); }
98 private:
102  bool init();
103 
104  unsigned short m_vendor_id;
105  unsigned short m_product_id;
106  std::wstring m_serial_number;
107  hid_device *m_device;
108 };
109 
110 } // namespace blfwk
111 
113 
114 #endif // _UsbHidPeripheral_h_
115 
117 // EOF
Definition: BlfwkErrors.h:16
virtual status_t write(const uint8_t *buffer, uint32_t byteCount)
Write bytes. This is a do nothing function implemented here to satisfy abstract base class requiremen...
Definition: UsbHidPeripheral.h:84
virtual status_t read(uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t timeoutMS)
Read bytes.
Definition: UsbHidPeripheral.cpp:100
PID for KL25Z48M.
Definition: UsbHidPeripheral.h:54
Freescale VID.
Definition: UsbHidPeripheral.h:53
unsigned short getProductId()
Return USB Product ID.
Definition: UsbHidPeripheral.h:95
UsbHidPeripheral()
Default constructor.
Definition: UsbHidPeripheral.cpp:45
_usbhid_contants
Constants.
Definition: UsbHidPeripheral.h:51
unsigned short getVendorId()
Return USB Vendor ID.
Definition: UsbHidPeripheral.h:93
const wchar_t * getSerialNumber()
Return USB Serial Number.
Definition: UsbHidPeripheral.h:97
virtual ~UsbHidPeripheral()
Destructor.
Definition: UsbHidPeripheral.cpp:89
Represents a USB HID peripheral.
Definition: UsbHidPeripheral.h:47
Represents a peripheral.
Definition: Peripheral.h:48