I'm new with USB.
I want to implement a pointing device on a PIC microcontroller. USB will be used for communications between the pointing device and the host.
I would like to do the following:
Send deltas to the host's HID class driver, so the device can function as a simple mouse immediately after plug-in.
Send other data to the host using the CDC class for it to be post-processed by an application running on user space.
My main questions are:
What is the best way to implement this? Should I define 2 distinct interfaces?
What descriptors should I define?
I'm thinking of the following:
Device descriptor
Config descriptor
Interface 0 descriptor
Functional descriptors
EP descriptor
Interface 1 descriptor (CDC)
EP descriptors
Interface 2 descriptor (HID)
EP descriptors
How should I define the "functional descriptors" that go after Interface 0 descriptor? Should I define interfaces 1 and 2 as slaves of interface 0?
I believe you must implement two distinct interface for two interface types.
You need to go through the CDC and HID specifications to understand the interface descriptors and (Endpoint descriptors).
I did not understand "slave interface" word. Did you mean alternate interface?
You do not need any alternate interfaces.
Example for multiple interfaces please refer to the image.
Thanks
Related
Let's say I have a DUT (e.g. l2 cache) with AXI bus in master port and I have created a class AXI_transfer extended from sequence_item, 100 sequences of interesting test scenarios and a uvm driver. Now, the bus protocol of DUT has changed from AXI to AHB. Testbench components that need to be modified are the sequence_item, and the driver (because they are protocol dependent). Now, I don't like to redevelop sequences for AHB because they are transaction level scenarios. Instead, I'd like to reuse all my sequences tied to AXI_transfer items. What would be the best methodology?
My idea is that I define a base_transfer extended from sequence_item and extend AXI_transfer and AHB_transfer from this base_transfer. Also, I modify all my sequences to be parameterized with this base_transfer type. Now, in my uvm test, I can do
base_transfer::type_id::set_type_override( AXI_transfer::get_type());
if I need to use AXI_transfer or
base_transfer::type_id::set_type_override( AHB_transfer::get_type());
if I need to use AHB_transfer. For driver, I need to develop two drivers -- one for AXI and the other for AHB.
Do you think this would work? If not what other methods are recommended?
In general, I believe you seek a LAYERED approach. Your upper layer simply sends and receives abstract traffic. It's up to the lower layer to handle details of the protocol.
This is exactly the approach used by the uvm_register_adapter. See something like this: http://cluelogic.com/2012/10/uvm-tutorial-for-candy-lovers-register-abstraction
In practice, what is causing you to have a hundred different sequences for an interface? The things that are causing you to create additional sequences are quite likely the kind of things that will cause difficulty translating between protocols. Your AXI/ACE will certainly use memory barriers, but how are you going to create them on an AHB interface, for instance?
Vulkan has instance and device extensions, but I cannot find any information anywhere about what the difference between them is. What does it mean exactly if something is a device extension or an instance extension? Why is VK_KHR_external_memory a device extension and VK_KHR_external_memory_capabilities an instance extension? Why is it not just a single, unified extension system?
The difference between instance extensions and device extensions is the difference between instances and devices.
The Vulkan instance is the piece of code that is used to set up devices. It deals with things like enumerating VkPhysicalDevices and querying their properties, as well as the call to create VkDevices itself.
The Vulkan device is for dealing with Vulkan rendering systems.
Device extensions pertain to the behavior of a particular VkDevice object which was created with that extension activated. As such, that extension cannot describe the behavior of stuff that happens before the device is created.
External memory, for example, has obvious implications for the rendering system. So it is a device extension. However, particular VkPhysicalDevice objects have different properties that can be queried with regard to their external memory functionality. You need to be able to query these properties before you create the device, because if the device doesn't provide the properties you need, there's no point in making the device at all. Or at least, of making the device with that extension active.
But device extensions govern the behavior of a device. If you don't have a device yet because you haven't created one, because you're trying to decide whether to create one at all... what do you do?
Well, that behavior has to be an instance extension. It extends the part of Vulkan that deals with the set up for devices, not that governs the behavior of the device itself.
I know that Adapter is a structural pattern and Mediator is a behavioral one. But as far I understood, what both of them are doing, is connecting two (or more) other classes which are potentially incompatible (not so maintainable) for direct communication.
Can some one give a close comparison between these two and point out the exact difference?
These are the links for Adapter and Mediator explanations in TutorialsPoint.
And these are sourcemaking explanations. Adapter, Mediator.
They don't have much in common, IMO.
A mediator is used to avoid coupling several components together. Instead of each component "talking" with each other directly (and thus having to know each other and to know how to communicate all with each other), each component talks to a single object: the mediator. The name is chosen on purpose: when you're fighting with your neighbor and can't communicate with him, you go see a mediator and instead of talking to each other, you both talk with the mediator, who tries fixing the issue.
An adapter is used to "transform" an object with an interface into an object with an other interface. Just like, for example, an electrical adapter which transforms a european power outlet into an american one, so that you can use your American shaver in Europe.
Simple example: you need to store a Runnable into a list of Callables. Runnable has a method run(). Callable has a method call(). You thus create an Adapter:
public class RunnableAdapter implements Callable {
private Runnable runnable;
public RunnableAdapter(Runnable runnable) {
this.runnable = runnable;
}
public void call() {
runnable.run();
}
}
JB Nizet already wrote a good answer. I just want to explain the differences in simpler words:
Mediator should be used when you don't know how to communicate with other objects or you aren't allowed to
Adapter should be used when you know exactly how to communicate with objects, but these objects might not support some communication methods or differ
Adapter Pattern is useful when we already have two code base one consumer code and other producer code but the format in which Consumer wish the product to be in is different from what Producer code is producing. Here as Producing code is already there in place and we do not wish to modify the existing code [ code closed for modification, open for extension ]. Adapter class can transform the product produced by Producer into format as expected by Consumer code. Format may be the APIs whose return type is different as per what Producer code and expectation of the consumer code. Adapter class uses the API of the producer code and transforms them as per the expectation of the consumer.
Now Mediator pattern is useful when we are in process of designing the architecture or while refactoring. It helps in easy and loosely coupled interaction of objects. Define an object [Mediator] that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
Can some one give a close comparison between these two and point out the exact difference?
The intent and checklist in sourcemaking links, which have been quoted in your question provides good insight.
Adapter convert the interface of a class into another interface clients expect
Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
isn't there something that implicitly means that mediator is an adapter that supports for than 2 classes. Due to this reason, Mediator can't act as an Adapter.
Mediator does not transform incompatible interface to compatible interface, what client expects unlike Adapter.
Mediator interacts with Collegues of same interface.
Mediator abstracts/centralizes arbitrary communication between Colleague objects
Related posts with code examples:
Mediator Vs Observer Object-Oriented Design Patterns
Difference between Bridge pattern and Adapter pattern
I am currently learning OOP on my own with books and websites. I am at the point I need to practice. I started a small project that I know how to do in a procedural way. But it leaves me with questions when I try to do it in a OOP manner.
My project concept is like this. I want to organize/archive/manage interconnection on our system at work. I use 2 classes. Device and Interface.
A Device have some Interfaces.
Device class have the following methodes:
void addInterface( String name)
void removeInterface( Interface i)
Interface getInterface( Interface i) # I should have wrote : Interface getInterface( String interfaceName )
void printAllInterface()
Interface class have the following methodes :
void connectInterface( Interface interfaceToConnectTo )
void disconnectInterface( Interface interfaceToDisconnectFrom )
void printAllConnection()
Basically, I create two device, add some interfaces to each and finally make some connection between interfaces.
A device know all its interfaces. An interface know all other interface it is connected to.
But given an interface how do I know to what device it belong?
If Interface is aware of Device, they become tightly coupled. For what I learn so far it is not really good OO. An other way would be to browse all device to know if they have the Interface I am looking for. It seems really inefficient. I am sure I missed something obvious. Can anybody sees it?
Thanks
update :
This can be seen as shapes and connections in a MS Visio file. the interface is really just a connector on a shape. The device is the shape.
If you have the requirement that you must be able to determine the Device for a given Interface, that means that Device and Interface are already tightly coupled even if you haven't coded it. If you decouple the two classes then you can no longer assume that all Interfaces belong to a Device.
If it is the case that all Interface objects must belong to a Device, then I don't see any problem having setDevice/getDevice methods on Interface. Yes it creates a circular dependancy, but it looks like that is the best way to model your specific domain. Searching through every Device just to see if it contains a specific Interface is a much worse design decision in my opinion.
However, if it is desirable for an Interface to exist without belonging to a Device, or maybe belonging to a totally different class, then you'll need to rethink the architecture at a higher level. Something along the lines of: How can I restructure these classes so I don't need to get a Device from an Interface? The answer really depends on your specific domain, which we don't know very much about just from the information in your question.
A small comment on your existing interfaces. IMHO the print method on the interfaces should be moved to a different interface so that the Device interface has a single responsibility of just maintaining the Interfaces it controls. Also, what does the method "Interface getInterface(Interface pInterface)" receive as Input argument and return?
As for the answer, there are a few questions that the answer above raises. If I understand correctly, the device class creates an interface when addInterface() is invoked; If the use case is such that given an interface a device is to be returned, a getDevice() on Interface is okay (I wouldn't add a setDevice() method; Device can be passed into the Interface's constructor) if an Interface always belongs to a device.
Edit : The setDevice() method would however be preferrable if you want to give the user of your api an impression that your use case so demands that the device associated with an interface can change at runtime.
I want to find a tool that can see all the interface, including the methods, properties, events, exposed by a COM(or ActiveX) component. Is such tool available?
It's not actually possible to build such a tool for ANY COM object, you might have some luck with specific objects. If a type library is available then you could use OLEView or you can programatically open and traverse the type library itself. Bear in mind that the contents of the type library is just what the developer wanted to include in it; there's nothing to stop objects implementing more interfaces than their type libraries say they do.
For objects without type libraries it's impossible to produce a general purpose tool:
Given the way that QueryInterface works you would have to ask the object under investigation if it supports every interface possible. Where would such a tool obtain a list of all possible interfaces that the object in question could support? Whilst it's true that some interfaces are registered in the registry due to proxy requirements not all interfaces are and it's by no means a requirement that they should be.
Once you know that an object supports a given interface how do you work out what methods that interface supports? If the interface derives from IDispatch then this is possible as that's the purpose of IDispatch, but for interfaces derived from IUnknown there is no way to programatically discover things about the interface.
You also have the added problem that some objects may have additional interfaces implemented for them by the proxy layer, for example, if an interface has been proxied then you will also be able to QueryInterface from it to IProxyManager though the object itself does not implement this interface (it's part of the proxy).
If the component has a typelib (in resources or shipped separately) you can use OLE View that comes with Visual Studio. You should use "View Typelib", not "Bind to File" there.