Martin Vejnár avatar Martin Vejnár committed 58964f7

Added usb_control_code_t, control writes are now void.

Comments (0)

Files changed (2)

 	std::unique_ptr<impl> m_pimpl;
 };
 
+struct usb_control_code_t
+{
+	uint8_t bmRequestType;
+	uint8_t bRequest;
+};
+
 class usb_device
 {
 public:
 	usb_device();
 	~usb_device();
 
+	void clear();
+	bool empty() const;
+
 	usb_device_descriptor descriptor() const;
 	usb_config_descriptor get_config_descriptor() const;
 
 	task<size_t> bulk_write(usb_endpoint_t ep, uint8_t const * buffer, size_t size);
 
 	task<size_t> control_read(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t * buffer, size_t size);
-	task<size_t> control_write(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t const * buffer, size_t size);
+	task<void> control_write(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t const * buffer, size_t size);
+
+	task<size_t> control_read(usb_control_code_t const & code, uint16_t wValue, uint16_t wIndex, uint8_t * buffer, size_t size);
+	task<void> control_write(usb_control_code_t const & code, uint16_t wValue, uint16_t wIndex, uint8_t const * buffer, size_t size);
 
 private:
 	usb_device(std::shared_ptr<usb_device_core> core);

libyb/usb/usb_device.cpp

 			size);
 	}
 
-	task<size_t> control_write(HANDLE hFile, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t const * buffer, size_t size)
+	task<void> control_write(HANDLE hFile, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t const * buffer, size_t size)
 	{
 		assert((bmRequestType & 0x80) == 0);
 		assert((bmRequestType & 0x60) < (3<<5));
 			buf.data(),
 			buf.size(),
 			0,
-			0);
+			0).ignore_result();
 	}
 
 	task<void> claim_interface(HANDLE hFile, uint8_t intfno)
 {
 }
 
+void usb_device::clear()
+{
+	m_core.reset();
+}
+
+bool usb_device::empty() const
+{
+	return m_core.get() == nullptr;
+}
+
 usb_device_descriptor usb_device::descriptor() const
 {
 	return m_core->desc;
 	}
 }
 
-task<size_t> usb_device::control_write(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t const * buffer, size_t size)
+task<void> usb_device::control_write(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint8_t const * buffer, size_t size)
 {
 	try
 	{
 		std::shared_ptr<usb_request_context> ctx(new usb_request_context());
-		return ctx->control_write(m_core->hFile.get(), bmRequestType, bRequest, wValue, wIndex, buffer, size).follow_with([ctx](size_t){});
+		return ctx->control_write(m_core->hFile.get(), bmRequestType, bRequest, wValue, wIndex, buffer, size).follow_with([ctx](){});
 	}
 	catch (...)
 	{
-		return async::raise<size_t>();
+		return async::raise<void>();
 	}
 }
+
+task<size_t> usb_device::control_read(usb_control_code_t const & code, uint16_t wValue, uint16_t wIndex, uint8_t * buffer, size_t size)
+{
+	return this->control_read(code.bmRequestType, code.bRequest, wValue, wIndex, buffer, size);
+}
+
+task<void> usb_device::control_write(usb_control_code_t const & code, uint16_t wValue, uint16_t wIndex, uint8_t const * buffer, size_t size)
+{
+	return this->control_write(code.bmRequestType, code.bRequest, wValue, wIndex, buffer, size);
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.