@Wuerfel_21 said:
Yea that's what I think I'll do. Do you mean one word for X/Y each or one long each? I'm favoring the latter. But it'll dump it in it's own DAT area.
From memory its 16 bits each combined into a single long (so it can be updated atomically).
@Wuerfel_21 said:
Ok, I've merged in basic mouse support. Get from GitHub. I've wrenched basic mouse info printing into the hidpad test, but I can't get the cursor to appear in @rogloh 's funny video driver. Please tell me what I'm doing wrong.
Cool I'll have a look today. IIRC there are some specific control field bits in the region or display structure needed to be configured to display the mouse on the screen. I'll look it up.
@Wuerfel_21 said:
Ok, I've merged in basic mouse support. Get from GitHub. I've wrenched basic mouse info printing into the hidpad test...
√ An Apple Mouse (Model A1152) works with this driver.
√ And, a Logitech Precision (Model G-UG16) game pad...
√ Either works hooked to the top-most USB port on the P2 Serial Host expansion board. This is with the new-ish P2 Edge Breakout.
√ Both worked through a non-powered RCA USB-C-HUB (C to A adapted)
√ Both worked through a Raspberry Pi Keyboard's HUB
But:
I was NOT able to get good results with a powered USB-3 HUB...
Was not able to get any keyboard input from the RPi keyboard and 2 other USB keyboards (GearHead Model KB1700U, GMYL USB Mini keyboard). For a test, these keyboards all worked plugged into a MacBook...
I dug up my video driver documentation work in progress from my other machine and found this information related to the mouse which I've pasted here. I think it should currently apply to the driver code but will also double check it myself a bit later. You'll probably want to use a global mouse in this case and setup the region flags appropriately. If the co-ordinates are out of your screen range (e.g, outside X=0-639 or Y=0-479) no mouse is drawn which might be occurring. You need to setup a hub RAM pointer to some mouse sprite data as well, although random garbage data probably still draws something unless it's all zeroed perhaps. Also you may want to ensure you are in a graphics mode. I think it still does render a graphics mouse in text mode but not 100% sure.
@Wuerfel_21 I tried to use your latest usbnew code base from GitHub. Not sure if it's another one of those "you just need the latest spin2cpp repo" type of problems or if the code is in flux and is currently broken in GitHub but I can't get a response from the hidpad_to_vga.spin2 code. No mouse data is reporting on screen. I tried a couple of USB mice that have worked for me before with the P2 USB code and also attempted with and without a USB hub. In the hub case I don't see the LED flashing on P57 like I do with the emupad_to_vga.spin2 application which does at least appear to still work with my gamepads. Maybe the USB driver is getting frozen up or something in that case, although it flashes slowly without a USB hub if directly connected with a generic mouse. Maybe a 500mA current issue.
One mouse is a genuine Microsoft Wheel Mouse Optical, and the other is a generic USB cheapie. So it's a bit hard for me to test the mouse sprite and my video driver with this problem right now. If I can find some other mice I'll try them too and maybe patch in the latest spin2cpp somewhere to test that too...
Looking at the test code I see you are setting flags to enable the mouse and put the hotspot at 15,15 and to read the sprite data from hub address 0. But I don't see any code that updates the display structure's mouse co-ordinates (in its 8th long). You may want to set the hotspot XY params to 0 to make sure you see something displayed when 0,0 is the actual mouse co-ordinate.
This code snippet will show a dumb mouse sprite pattern on screen for you (it does work in text mode). You'd need to update the long at long[@display][7] from the USB driver to move it around:
VAR
long mouseData[48]
PUB main() | tmp
text.initVga(-1,vgaBase,vgaVsync,0,text.VGA)
text.setTextColours($F,$1)
text.clear()
usb.start()
usb.mouse_set_limits(640-1,480-1)
'usb.mouse_set_outptr(text.getDisplay() + 7*4)
byte[text.getRegion()][5] |= 128 ' enable mouse cursor (in awful way)
long[text.getRegion()][9] := @mouseData
long[text.getDisplay()][7] := $100010 ' show mouse at 16,16
repeat tmp from 0 to 15 ' setup a dumb mouse sprite pattern
mouseData[3*tmp]:=$55555555<<(tmp&1) ' mask
mouseData[3*tmp+1]:=-1 ' color nibbles (white by default)
mouseData[3*tmp+2]:=-1
text.printStr(@"USB HID test")
Version 6.1.2-beta-v6.1.0-42-g0854c031 Compiled on: May 6 2023
Run with Edge 32MB. Set USB pin to 0, VGA pin to 8, LEDs at 38,39.
LED blinks. The driver gives the debug (below). No reaction on key pressing or mouse move, neither on the VGA screen (all zeroes) nor on the serial debug (nothing). The serial debug window still reacts to connecting things
@Wuerfel_21 I tried to use your latest usbnew code base from GitHub. Not sure if it's another one of those "you just need the latest spin2cpp repo" type of problems or if the code is in flux and is currently broken in GitHub but I can't get a response from the hidpad_to_vga.spin2 code. No mouse data is reporting on screen. I tried a couple of USB mice that have worked for me before with the P2 USB code and also attempted with and without a USB hub. In the hub case I don't see the LED flashing on P57 like I do with the emupad_to_vga.spin2 application which does at least appear to still work with my gamepads. Maybe the USB driver is getting frozen up or something in that case, although it flashes slowly without a USB hub if directly connected with a generic mouse. Maybe a 500mA current issue.
You just need the latest spin2cpp repo And maybe not the latest... what was the version it was compiled with?
Compiled with several days older spin2cpp does not respond at all.
Compiled with the latest from here: https://github.com/totalspectrum/spin2cpp/actions/runs/4903698400 works as described above. The LED blinks, there is reaction on the debug screen when inserted a device, there is no reaction when a device (kbd, mouse) is used.
@pik33 said:
You just need the latest spin2cpp repo And maybe not the latest... what was the version it was compiled with?
Oh man, I hate the bleeding edge thing. Am gonna try to install the latest now.
EDIT: Just got the latest and greatest spin2cpp and it's working and I see the mouse co-ordinates changing on screen. Cool! Even the scroll wheel is working, although the mouse position update to the video driver's hub RAM location is not present (or configured correctly) in this code yet.
@pik33 said:
You just need the latest spin2cpp repo And maybe not the latest... what was the version it was compiled with?
Oh man, I hate the bleeding edge thing. Am gonna try to install the latest now.
EDIT: Just got the latest and greatest spin2cpp and it's working and I see the mouse co-ordinates changing on screen. Cool! Even the scroll wheel is working, although the mouse position update to the video driver's hub RAM location is not present (or configured correctly) in this code yet.
I tried another mouse. It works. Raspberry keyboard doesn't work. It worked in the previous version of the driver I tested. The working mouse works even if connected to the RPi keyboard. Sometimes connecting the device hangs the driver (LED doesn't blink). It can return to normal operation after reconnecting the device. The working mouse is the cheap thing, the not working mouse is Logitech M215.
Yeah my cheapie optical mouse is the one that is working for me right now and the real Microsoft's LED isn't lighting up very much - maybe too much current - say's 100mA on the back and it's quite old (probably less power efficient).
I still can't seem to get the configured mouse co-ordinate long address to update from the mouse even after writing the address to the driver (this line was commented out before). If I print the hex long at this address in the main loop it remains static even though the USB code appears to want to write to if it's a non zero address (am still digging...)
Fixed it! Now the mouse sprite follows the mouse coordinates in a silky smooth way. @Wuerfel_21 this USB code was using the wrong pointer (htmp2 instead of htmp3):
' if outptr set, write X/Y words
cmp htmp2,#0 wz
if_nz setword hr1,hr2,#1
if_nz wrlong hr1,htmp2
ret
It should be changed to this:
' if outptr set, write X/Y words
cmp htmp3,#0 wz
if_nz setword hr1,hr2,#1
if_nz wrlong hr1,htmp3
ret
You also need to uncomment that mouse_set_outptr call and add the lines I mentioned in my previous posts to configure some dummy mouse sprite etc (or create a real one).
Here's a simple 4bpp mouse pointer I made a while ago that can be used (might want to set the hotspot to the tip of the finger at y=0,x=4).
mouse4bpp long %0000_0000_0001_0000, $000f0000, $00000000
long %0000_0000_0011_1000, $00f0f000, $00000000
long %0000_0000_0111_1000, $0f00f000, $00000000
long %0000_0001_1111_1000, $ff00f000, $0000000f
long %0000_1111_1111_1000, $0f00f000, $0000fff0
long %0011_1111_1111_1011, $0f00f0ff, $00ff00f0
long %0111_1111_1111_1111, $0f00ff0f, $0f0f00f0
long %1111_1111_1111_1110, $0000f0f0, $f00f0000
long %1111_1111_1111_1110, $0000f0f0, $f0000000
long %1111_1111_1111_1100, $00000f00, $f0000000
long %1111_1111_1111_1100, $00000f00, $f0000000
long %0111_1111_1111_1000, $0000f000, $0f000000
long %0111_1111_1111_1000, $0000f000, $0f000000
long %0111_1111_1111_0000, $000f0000, $0f000000
long %0011_1111_1111_0000, $000f0000, $00f00000
long %0011_1111_1111_0000, $ffff0000, $00ffffff
@pik33 said:
I tried another mouse. It works. Raspberry keyboard doesn't work. It worked in the previous version of the driver I tested. The working mouse works even if connected to the RPi keyboard. Sometimes connecting the device hangs the driver (LED doesn't blink). It can return to normal operation after reconnecting the device. The working mouse is the cheap thing, the not working mouse is Logitech M215.
Same for me. My USB keyboard doesn't work anymore either (it did work in an older version). Hopefully by the end of it all we'll have a Keyboard,Mouse and 2 USB controllers working together from a 4 port hub. That would be ideal for me anyway.
You also need to uncomment that mouse_set_outptr call and add the lines I mentioned in my previous posts to configure some dummy mouse sprite etc (or create a real one).
I need to connect this to my HDMI driver instead... I have 16 sprites there and a mouse definition ready too.
You also need to uncomment that mouse_set_outptr call and add the lines I mentioned in my previous posts to configure some dummy mouse sprite etc (or create a real one).
I need to connect this to my HDMI driver instead... I have 16 sprites there and a mouse definition ready too.
If you can use the same XY co-ordinate format (top left is 0,0 bottom right is width-1, height-1) and read X and Y as two words from a single long (Y as the MSW, X as the LSW) it should be possible to use this USB driver as is to update a mouse sprite position in your driver. Otherwise some USB driver adjustments would be needed. The actual sprite format is independent, as the USB driver knows nothing about that.
A Logitech M215: fail (as far as I remember, this is the 12bit nightmare)
Coordinates: 0,0,0
LED lit.
Debug constantly pukes this:
Edit: Moderators, please make the post text size limit higher... any longer debug doesn't fit.
Edit 2: This logitech mouse hanged up something in the driver. After connecting the working mouse and keyboard, no response until reset.
I think it gets confused because there is both a mouse interface and also another generic HID interface (which it would want to pick up as a game controller). Not sure why that'd cause an infinite loop. My brain's kinda scrambled right now.
Actually, no, it fails to configure for some reason and that causes it to jump to .notify_client with a garbage value ($47) in htmp2, which gets put into hdev_type. Not sure why that causes an infinite loop, either.
Also, it seems that one of my wireless mice also has a keyboard interface, so it needs to be plugged into a higher-numbered port than the actual keyboard to work... (because the keyboard I/F is ignored if another one has already configured)
I connected this mouse to the hub. Better. Still no response (x,y,z=0), but the keyboard still works and the debug doesn't puke. Instead, it reported this:
@Wuerfel_21 Just tried your latest code, and I have 2 USB gamepads, a mouse and a keyboard all fitted to a 4 port USB hub and each reporting nicely running hidpad_to_vga.spin2. Nice work
Comments
From memory its 16 bits each combined into a single long (so it can be updated atomically).
Cool I'll have a look today. IIRC there are some specific control field bits in the region or display structure needed to be configured to display the mouse on the screen. I'll look it up.
√ An Apple Mouse (Model A1152) works with this driver.
√ And, a Logitech Precision (Model G-UG16) game pad...
√ Either works hooked to the top-most USB port on the P2 Serial Host expansion board. This is with the new-ish P2 Edge Breakout.
√ Both worked through a non-powered RCA USB-C-HUB (C to A adapted)
√ Both worked through a Raspberry Pi Keyboard's HUB
But:
I was NOT able to get good results with a powered USB-3 HUB...
Was not able to get any keyboard input from the RPi keyboard and 2 other USB keyboards (GearHead Model KB1700U, GMYL USB Mini keyboard). For a test, these keyboards all worked plugged into a MacBook...
dgately
I dug up my video driver documentation work in progress from my other machine and found this information related to the mouse which I've pasted here. I think it should currently apply to the driver code but will also double check it myself a bit later. You'll probably want to use a global mouse in this case and setup the region flags appropriately. If the co-ordinates are out of your screen range (e.g, outside X=0-639 or Y=0-479) no mouse is drawn which might be occurring. You need to setup a hub RAM pointer to some mouse sprite data as well, although random garbage data probably still draws something unless it's all zeroed perhaps. Also you may want to ensure you are in a graphics mode. I think it still does render a graphics mouse in text mode but not 100% sure.
@Wuerfel_21 I tried to use your latest usbnew code base from GitHub. Not sure if it's another one of those "you just need the latest spin2cpp repo" type of problems or if the code is in flux and is currently broken in GitHub but I can't get a response from the hidpad_to_vga.spin2 code. No mouse data is reporting on screen. I tried a couple of USB mice that have worked for me before with the P2 USB code and also attempted with and without a USB hub. In the hub case I don't see the LED flashing on P57 like I do with the emupad_to_vga.spin2 application which does at least appear to still work with my gamepads. Maybe the USB driver is getting frozen up or something in that case, although it flashes slowly without a USB hub if directly connected with a generic mouse. Maybe a 500mA current issue.
One mouse is a genuine Microsoft Wheel Mouse Optical, and the other is a generic USB cheapie. So it's a bit hard for me to test the mouse sprite and my video driver with this problem right now. If I can find some other mice I'll try them too and maybe patch in the latest spin2cpp somewhere to test that too...
Looking at the test code I see you are setting flags to enable the mouse and put the hotspot at 15,15 and to read the sprite data from hub address 0. But I don't see any code that updates the display structure's mouse co-ordinates (in its 8th long). You may want to set the hotspot XY params to 0 to make sure you see something displayed when 0,0 is the actual mouse co-ordinate.
This code snippet will show a dumb mouse sprite pattern on screen for you (it does work in text mode). You'd need to update the long at long[@display][7] from the USB driver to move it around:
Doesn't work as expected.
Compiled with the newest spin2cpp
Version 6.1.2-beta-v6.1.0-42-g0854c031 Compiled on: May 6 2023
Run with Edge 32MB. Set USB pin to 0, VGA pin to 8, LEDs at 38,39.
LED blinks. The driver gives the debug (below). No reaction on key pressing or mouse move, neither on the VGA screen (all zeroes) nor on the serial debug (nothing). The serial debug window still reacts to connecting things
You just need the latest spin2cpp repo And maybe not the latest... what was the version it was compiled with?
Compiled with several days older spin2cpp does not respond at all.
Compiled with the latest from here: https://github.com/totalspectrum/spin2cpp/actions/runs/4903698400 works as described above. The LED blinks, there is reaction on the debug screen when inserted a device, there is no reaction when a device (kbd, mouse) is used.
Oh man, I hate the bleeding edge thing. Am gonna try to install the latest now.
EDIT: Just got the latest and greatest spin2cpp and it's working and I see the mouse co-ordinates changing on screen. Cool! Even the scroll wheel is working, although the mouse position update to the video driver's hub RAM location is not present (or configured correctly) in this code yet.
I tried another mouse. It works. Raspberry keyboard doesn't work. It worked in the previous version of the driver I tested. The working mouse works even if connected to the RPi keyboard. Sometimes connecting the device hangs the driver (LED doesn't blink). It can return to normal operation after reconnecting the device. The working mouse is the cheap thing, the not working mouse is Logitech M215.
Yeah my cheapie optical mouse is the one that is working for me right now and the real Microsoft's LED isn't lighting up very much - maybe too much current - say's 100mA on the back and it's quite old (probably less power efficient).
I still can't seem to get the configured mouse co-ordinate long address to update from the mouse even after writing the address to the driver (this line was commented out before). If I print the hex long at this address in the main loop it remains static even though the USB code appears to want to write to if it's a non zero address (am still digging...)
Fixed it! Now the mouse sprite follows the mouse coordinates in a silky smooth way. @Wuerfel_21 this USB code was using the wrong pointer (htmp2 instead of htmp3):
It should be changed to this:
You also need to uncomment that mouse_set_outptr call and add the lines I mentioned in my previous posts to configure some dummy mouse sprite etc (or create a real one).
Here's a simple 4bpp mouse pointer I made a while ago that can be used (might want to set the hotspot to the tip of the finger at y=0,x=4).
Same for me. My USB keyboard doesn't work anymore either (it did work in an older version). Hopefully by the end of it all we'll have a Keyboard,Mouse and 2 USB controllers working together from a 4 port hub. That would be ideal for me anyway.
I need to connect this to my HDMI driver instead... I have 16 sprites there and a mouse definition ready too.
32bpp mouse: https://gitlab.com/pik33/P2-retromachine/-/blob/main/Propeller/Videodriver_develop/mouse32.def
8bpp mouse: https://gitlab.com/pik33/P2-retromachine/-/blob/main/Propeller/P2P16/mouse.def
0 is transparent.
If you can use the same XY co-ordinate format (top left is 0,0 bottom right is width-1, height-1) and read X and Y as two words from a single long (Y as the MSW, X as the LSW) it should be possible to use this USB driver as is to update a mouse sprite position in your driver. Otherwise some USB driver adjustments would be needed. The actual sprite format is independent, as the USB driver knows nothing about that.
Oh, y'all posted a lot tonight. I'll look into the keyboard issue.
EDIT: great, one of the mice that worked yesterday now doesn't for no appreciable reason.
Yes, I can. There are 16-bit variables for sprite x and y in my driver.
Ok, keyboard not working is flexsplorp, code is right but gets assembled to nonsense:
EDIT: NO IM STUPID
Ok, keyboards should now work again....
Keyboard now OK
A cheap mouse: OK
A Logitech M215: fail (as far as I remember, this is the 12bit nightmare)
Coordinates: 0,0,0
LED lit.
Debug constantly pukes this:
Edit: Moderators, please make the post text size limit higher... any longer debug doesn't fit.
Edit 2: This logitech mouse hanged up something in the driver. After connecting the working mouse and keyboard, no response until reset.
I think it gets confused because there is both a mouse interface and also another generic HID interface (which it would want to pick up as a game controller). Not sure why that'd cause an infinite loop. My brain's kinda scrambled right now.
Actually, no, it fails to configure for some reason and that causes it to jump to
.notify_client
with a garbage value ($47) inhtmp2
, which gets put intohdev_type
. Not sure why that causes an infinite loop, either.Also, it seems that one of my wireless mice also has a keyboard interface, so it needs to be plugged into a higher-numbered port than the actual keyboard to work... (because the keyboard I/F is ignored if another one has already configured)
I connected this mouse to the hub. Better. Still no response (x,y,z=0), but the keyboard still works and the debug doesn't puke. Instead, it reported this:
Hmm. Currently trying to work out parsing full mouse reports. I got a 12 bit one, with a bunch of awful nonsense in there, too:
@pik33 try this version where I hacked in some extra DEBUG lines (and also the descriptor reader)
@Wuerfel_21 Just tried your latest code, and I have 2 USB gamepads, a mouse and a keyboard all fitted to a 4 port USB hub and each reporting nicely running hidpad_to_vga.spin2. Nice work
No response for the Logitech. This is the RPi kbd with the mouse,
A normal mouse works OK
But that's the one I was interested in!
Though what you posted is also broken?
EDIT: wait no I'm being stupid again
This is the mouse alone (endless debug reports)
Try replugging the whole thing, it doesn't even try to configure right now