igor 163 Posted April 11, 2014 Share Posted April 11, 2014 Clarification - the example I gave above of creating a device similar to the MS Sidewinder Pro was not intended as using the micro as a host for that particular joystick. What I was trying to do was work out how one would use this library in order to create a USB device that would appear to the host computer as a joystick with similar properties. Writing an example of code that would use the API should help clarify how it is supposed to work, and help turn up difficulties. For instance, somebody seeing the API might assume that joystick1 can have an analog16, an analog8 and a digital stick (as I did), but somebody else might assume that it can only have one of type of joystick (i.e. joystick 1 can be either analog16 or analog8 or digital). Joysticks with hat sticks, or gamepads with multiple joysticks or joypads seem to be norm, so it makes sense to design the interface to handle typical controllers. So here is some pseudo-code of what a use of the API might look like for a launchpad that has analog and digital devices connected on various pins, and uses the API to package it up like a joystick. buttons[] = { button1, button2, button3, ... button8 } setup{ initializeHIDcomp(4, 6, 8); } loop{ joyxv = analogread(joyx) joyyv = analogread(joyy) joy1_AN16(joyxv, joyyv); throttle = analogread(throttlepin) turnl = digitalread(turnleftpin) turnr = digitalread(turnrightpin) turn = (turnl ? -127 : (turnr ? 127 : 0)) // Digital sensors converted to analog reading joy1_AN8(throttle, turn); hatleft, hatright, hatup, hatdown = digitalread(bhatleft, bhatright, bhatup, bhatdown) joy1_DIG((hatleft ? -1 : hatright ? 1 : 0), (hatup ? 1 : hatdown ? -1 : 0)); for (i = 0; i < sizeof (buttons); i++) { butstate = digitalread(buttons[i]) joy1_button_set(i, butstate); } } Hope that makes it clearer. Quote Link to post Share on other sites
Rhys 0 Posted April 11, 2014 Author Share Posted April 11, 2014 Ok, I see where you are going with that. The prototype functions I setup assume that you pick one of the three options for the joystick, either AN8, AN16, or Digital. They are meant to allow a simple single x/y axis, 8 button joystick for simple use scenarios. For what you are talking about, that is far more complex than I plan to deal with for simple prototype functions, and is why I will include the ability to build custom HID devices. I haven't decided yet exactly how I'm going to set that up. I will probably create an example program to show how to create a custom HID descriptor, how to initialize it as a custom device, and how to send reports. That allows for more complex devices like what you are describing to be built without having to learn the entire usblib stack like I did. Once I have the wrapper completed, I'll also convert my Mame control panel code over to Energia as an example of both how to create custom composite HID devices and at least one simple method of dealing with debouncing of digital inputs, as well as report structure for USB HID devices. I haven't even started on the code yet, and examples won't come till after the code is close to completion. There is a LOT of back end work I have to do to support those simple prototype functions for the library to work. Most of what would normally be in the device code has to be moved into the wrapper library, such as setting up the physical USB port, handling report submission and error trapping, and all of the device configuration. It's not especially complex, but will be a fair chunk of code. I will continue to post updates as things move along. Hoping to have the header file created (if not complete or final) and a github repository setup this weekend. Might even manage to get some code started. Thank you guys for all the comments and suggestions so far. Keep them coming! Quote Link to post Share on other sites
JStat60 0 Posted May 22, 2014 Share Posted May 22, 2014 Hi Folks, Hope you don't mind answering some possibly dumb questions from someone with very limited coding experience. I recently figured out that I could not communicate with my Stellaris / Tiva launchpads the "device" USB connection. It appears to me that this is the issue that you are working on. Is that correct? If you are able to accomplish what you are attempting, will it be possible to communicate with the launchpads without downloading and installing the ICDI drivers? I would like to use some launchpad based instruments to teach chemistry labs and I foresee installing the drivers on the student computers as a major obstacle. If this is not what you are working on and there is a simple answer to my problem, I would be grateful for that info. Thanks, Jack Quote Link to post Share on other sites
igor 163 Posted May 23, 2014 Share Posted May 23, 2014 While you would not need the ICDI drivers, you still might need drivers, depending on your operating system and what type of communication you are using. Specifically, Windows often needs to install drivers for a USB_CDC (serial port) device. However I believe Linux generally does not need a driver installed for USB_CDC. For HID devices (joystick, mouse, keyboard), both Windows and Linux have built-in drivers. I do not know about Macs, although since they have *nix underpinnings I would sort of expect them to act more like Linux in this regard. So, if your device acts like a serial port, then it might need a driver for Windows. If it looks like one of the other HID types, then probably not. Quote Link to post Share on other sites
JStat60 0 Posted May 23, 2014 Share Posted May 23, 2014 Thanks. Quote Link to post Share on other sites
igor 163 Posted December 14, 2014 Share Posted December 14, 2014 Saw some projects over in the Teensy world which might have some bits that could be borrowed. http://hackaday.com/2014/12/13/usb-on-the-teensy-3-from-the-ground-up/ http://kevincuzner.com/2014/12/12/teensy-3-1-bare-metal-writing-a-usb-driver/ Quote Link to post Share on other sites
Marc 10 Posted May 1, 2016 Share Posted May 1, 2016 Just curious, has there been any progress on this matter? Has anyone tried packaging a usb_dev_serial.c type application for energia? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.