USB HID and composite

The official STMicroelectronics Arduino core
danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: USB HID and composite

Post by danieleff » Tue Dec 13, 2016 4:52 pm

Freakeyyy wrote:
danieleff wrote: Or copy the joystick library, and modify it. Its copy-paste duplicate.
Do you mean copy the Mouse library and modify it ?
I meant copy https://github.com/MHeironimus/ArduinoJoystickLibrary . Which I just did.
For example this works now, looks like a gamecontroller on my win10:

Code: Select all

#include "USBDevice.h"
#include "Joystick.h"

#define BUTTON_PIN 32

Joystick_ Joystick;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT);
  
  USBDevice.beginSerialHID(&Joystick);
  
  Joystick.begin();
}

int previous_buttons = 0;
int y;

void loop() {
 
  if (previous_buttons != digitalRead(BUTTON_PIN)) {
    previous_buttons = digitalRead(BUTTON_PIN) ? 1 : 0;
    
    Joystick.setButton(0, digitalRead(BUTTON_PIN));
    Joystick.setYAxis(y);
    y += 10;
    
    digitalWrite(LED_BUILTIN, previous_buttons);
  }
 
}
If I can somehow make the original library work, this copy needs to be removed.

Now I'll try to remove the need to call `USBDevice.beginSerialHID(...);`. To be coordinated with viewtopic.php?f=48&t=1581

Elektrik
Posts: 4
Joined: Mon Dec 12, 2016 1:11 am

Re: USB HID and composite

Post by Elektrik » Tue Dec 13, 2016 11:14 pm

Good day, tested Joystick on windows 10 x64, seems to work well, buttons are read fine, now continue to test if pot value is passed as axis correctly. One issue I found - if I upload sketch when stm32 is already connected - it works fine. Once I reset/unplug-plug, it does not load as HID device. The actual sketch is flashed, just some issues during enumeration, will try to add delays before USBDevice.beginHID.
Image

Update:
Did not manage to check axis, since cannot read adc value (INPUT_ANALOG is not declared to turn on adc pin), tried to set bits manually, but it's too different in comparison with maple core definitions on original arduino_stm32 repo.

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: USB HID and composite

Post by danieleff » Wed Dec 14, 2016 5:55 am

Elektrik wrote: Did not manage to check axis, since cannot read adc value (INPUT_ANALOG is not declared to turn on adc pin), tried to set bits manually, but it's too different in comparison with maple core definitions on original arduino_stm32 repo.
INPUT_ANALOG is just a maple implementation thingy, and is not needed in the original arduino code or in this core. See the official example, no need for pinMode().

However there is an issue with the pin numbers that can be used as analog pins: https://github.com/stm32duino/Arduino_C ... /issues/28 (Basically do not use pins < 16)
Are you using bluepill or maple mini?

Elektrik
Posts: 4
Joined: Mon Dec 12, 2016 1:11 am

Re: USB HID and composite

Post by Elektrik » Wed Dec 14, 2016 4:55 pm

Oh, thank you for reply, that's might be an issue, since I tried it on A0 pin, will try now to use different pins.
danieleff wrote: Are you using bluepill or maple mini?
I do use generic stm32 board
Image

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: USB HID and composite

Post by danieleff » Wed Dec 14, 2016 5:06 pm

That is the bluepill, PB0 should work for now. And nothing else... for now. @RogerClark I would like to send PRs for these, just do not know which branch.

Elektrik
Posts: 4
Joined: Mon Dec 12, 2016 1:11 am

Re: USB HID and composite

Post by Elektrik » Wed Dec 14, 2016 6:12 pm

Tried on PB0, this cause board sometimes returning "Unkwnown USB descriptor", or sometimes it runs until analogRead() and then crashes.

Code: Select all

#include "USBDevice.h"
#include "Joystick.h"

#define BUTTON_PIN 32
#define LED_BUILTIN PC13

Joystick_ Joystick(0x01,  0x04,   10,  0,  true,  false,  false,  false,  false,  false,  false,  false,  false,  false,  false);

int val = 0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT);

  USBDevice.beginSerialHID(&Joystick);

  Joystick.begin();
}

int previous_buttons = 0;

void loop() {
  if (previous_buttons != digitalRead(BUTTON_PIN)) {
    previous_buttons = digitalRead(BUTTON_PIN) ? 1 : 0;
    Joystick.setButton(1, previous_buttons);
    digitalWrite(LED_BUILTIN, !previous_buttons);

    val = analogRead(PB0);
    Serial.println(val);

    Joystick.setXAxis(val);
  }

}

User avatar
RogerClark
Posts: 6681
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: USB HID and composite

Post by RogerClark » Wed Dec 14, 2016 7:33 pm

Daniel

I think Frederic @ STM is happy to have the new code in the master branch.
I think one of Frederic's PRs effectively moves the changes in the WIP branch into master, but I have not had time to test the PR, so those changes have not been made to the master yet.

Sorry. I have been very busy with commerical work, as I have pre-christmas deadlines and also deadlines due to Chinese New Year, ( my contacts in China start their holiday on 12th Jan, for about 3 weeks).
So I have not had time to test and pull the PRs from Frederic.

As I do not derive any income from STM etc, my work has to come first.

X71
Posts: 28
Joined: Wed Oct 26, 2016 11:53 pm

Re: USB HID and composite

Post by X71 » Fri Dec 30, 2016 2:55 am

This is what I've been trying to do on my F103VET6 board for a while now, but I'm confused on the actual architecture.

I've managed to get my board to boot as a USB Serial Device (thanks to Roger's FAQ), but I don't fully understand how to "turn" it in to a USB HID.

Is the code presented in this thread supposed to be the "bootloader" of the board, or do you just upload the code as a "sketch" and when plugged into the PC it's operates as a USB HID?

Can some provide a step by step guide on how I could get this running on my board?

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: USB HID and composite

Post by danieleff » Fri Dec 30, 2016 3:19 pm

X71 wrote:This is what I've been trying to do on my F103VET6 board for a while now, but I'm confused on the actual architecture.

I've managed to get my board to boot as a USB Serial Device (thanks to Roger's FAQ), but I don't fully understand how to "turn" it in to a USB HID.

Is the code presented in this thread supposed to be the "bootloader" of the board, or do you just upload the code as a "sketch" and when plugged into the PC it's operates as a USB HID?

Can some provide a step by step guide on how I could get this running on my board?
If you run on F103VET6, thats probably the libmaple core.
This one is for the official core (that does not have support for F103VET6 currently), install as here: viewtopic.php?f=16&t=1553 , except use my branch: https://github.com/danieleff/Arduino_Co ... _Composite

X71
Posts: 28
Joined: Wed Oct 26, 2016 11:53 pm

Re: USB HID and composite

Post by X71 » Sat Dec 31, 2016 12:46 am

danieleff wrote:
X71 wrote:This is what I've been trying to do on my F103VET6 board for a while now, but I'm confused on the actual architecture.

I've managed to get my board to boot as a USB Serial Device (thanks to Roger's FAQ), but I don't fully understand how to "turn" it in to a USB HID.

Is the code presented in this thread supposed to be the "bootloader" of the board, or do you just upload the code as a "sketch" and when plugged into the PC it's operates as a USB HID?

Can some provide a step by step guide on how I could get this running on my board?
If you run on F103VET6, thats probably the libmaple core.
This one is for the official core (that does not have support for F103VET6 currently), install as here: viewtopic.php?f=16&t=1553 , except use my branch: https://github.com/danieleff/Arduino_Co ... _Composite
It works !!!

You don't know how long I've been trying to get this to work ... thanks for your help @danieleff and especially @RogerClark for helping out a newbie :)
2016-12-31.png
2016-12-31.png (12.93 KiB) Viewed 575 times

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest