Building GIMX on Mac

Talk about anything concerning the source code.
0x1
Posts: 5
Joined: Fri May 06, 2016 6:34 am

Re: Building GIMX on Mac

Post by 0x1 » Fri May 06, 2016 6:38 pm

awesome wrote:Hi what did you need to install in macports?
I used MacPorts to install libusb, and fox (which handles the gui in X11).

$ sudo port install libusb
$ sudo port install fox

MacPorts is not required, although for libs that are maybe only found on linux it makes things much easier.

User avatar
Matlo
Posts: 4463
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Building GIMX on Mac

Post by Matlo » Fri May 06, 2016 7:04 pm

Hi,

First of all, if you want to help, please base your work on the refactoring branch.

The bluetooth feature only works on GNU/Linux, and the code is OS-specific (-lbluetooth).
It's much easier to port the USB feature to Mac OS X. It requires a cheap DIY USB adapter.

The hidapi library is not used anymore since GIMX 5.0.
I replaced it with a custom communication layer that provides asynchronous hid communications.
It uses the libusb on Linux, which means it probably can be ported easily to Mac OS X.

A first step is to port the shared/gasync code.
  • common/linux -> common/posix (done)
  • hid/linux -> hid/libusb (done)
  • input/darwin has to be used instead of input/linux
  • poll/linux -> poll/posix (done)
  • prio/darwin has to be created
  • serial/linux -> serial/posix (done)
  • timer/darwin has to be created
The shared/gasync/test folder contains test programs for most of the gasync code.
GIMX creator Donate Shop

Lythinari
Posts: 3
Joined: Sun Mar 06, 2016 7:17 am

Re: Building GIMX on Mac

Post by Lythinari » Sat May 07, 2016 4:33 am

@0x1,
Have you successfully used HIDAPI or libusb on OSX without a kext WITH the DS4?
Ive done some more experimenting in Go, and Ive had to use a codeless kext to prevent the OS taking the device when it gets connected.
I think windows does something similar?

Im currently implementing asynchronous calls for libusb in go(uses C) and diverged off GIMX for a little while.

As for compiling GIMX in C, maybe use the USB only instead of bluetooth?
Is it possible to compile without the bluetooth libraries matlo?

However, it might be useful to check out this..
/System/Library/Frameworks/IOBluetooth.framework

Serial posix is pretty much the same as linux - using termios to set the baudrate at the required 500000.

User avatar
Matlo
Posts: 4463
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Building GIMX on Mac

Post by Matlo » Sat May 07, 2016 7:13 am

Alright I moved some of the sources to make things easier.

What's remains to be done for the shared/gasync is the following:
  • input/darwin and input/sdl have to be selected instead of input/linux
  • input/darwin needs some more code to grab the mouse cursor
  • prio/darwin has to be created
  • timer/darwin has to be created
It's possible to compile without the bluetooth stuff. That's already done for Windows.
GIMX creator Donate Shop

0x1
Posts: 5
Joined: Fri May 06, 2016 6:34 am

Re: Building GIMX on Mac

Post by 0x1 » Sat May 07, 2016 5:53 pm

Matlo wrote: The bluetooth feature only works on GNU/Linux, and the code is OS-specific (-lbluetooth).
It's much easier to port the USB feature to Mac OS X. It requires a cheap DIY USB adapter.
The adapter I currently have is the "BCM2045A"... I'm guessing that one might no longer be sufficient? I did mess around with it a bit, and I'm able to probe it, dump all the descriptors, etc. on OS X. I can't remember how it was flashed exactly back in the early versions GIMX, or even if this one retains it's values to be honest.
Matlo wrote: The hidapi library is not used anymore since GIMX 5.0.
I replaced it with a custom communication layer that provides asynchronous hid communications.
It uses the libusb on Linux, which means it probably can be ported easily to Mac OS X.
Is your Linux libusb library modified at all? I'm not at all familiar with other components you mentioned (prio, and timer). If you need anything regarding the mouse code, or even keyboard input I could probably help you with that, I've coded some things in C, Objective-C, and Swift that return all cords, events, etc. (usb and bluetooth).

Code: Select all

IOBluetoothDevice:
https://developer.apple.com/library/mac/documentation/IOBluetooth/Reference/IOBluetoothDevice_reference/

IOHIDFamily:
https://developer.apple.com/library/mac/samplecode/HID_LED_test_tool/Introduction/Intro.html
https://developer.apple.com/library/mac/documentation/IOKit/Reference/IOHIDTransaction_header_reference/
https://developer.apple.com/library/mac/documentation/Kernel/Reference/IOHIDDevice_reference/
https://developer.apple.com/library/mac/samplecode/HID_Dumper/Introduction/Intro.html
https://developer.apple.com/library/mac/samplecode/HID_Calibrator/Listings/HID_Calibrator_HID_Utilities_IOHIDManager_IOHIDDevice__c.html
https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/HID/new_api_10_5/tn2187.html
https://developer.apple.com/library/mac/samplecode/HID_Utilities/Introduction/Intro.html
http://opensource.apple.com//source/IOHIDFamily/IOHIDFamily-701.20.10/
( In case you're curious how Apple handles some of it you can always check out the source code )
Lythinari wrote:@0x1,
Have you successfully used HIDAPI or libusb on OSX without a kext WITH the DS4?
Ive done some more experimenting in Go, and Ive had to use a codeless kext to prevent the OS taking the device when it gets connected.
I've really had no issues at all using any of the hidapi examples that are included with the source code (didn't install any .kexts). I can also send you the compiled binaries I created if you think they'll be of any use.
Lythinari wrote: However, it might be useful to check out this..
/System/Library/Frameworks/IOBluetooth.framework
You are very correct — in-fact the code is strikingly similar to the Linux equivalents, and there are some good example xcode projects available too. It would be great to use some of the native libraries with GIMX, and I'd imagine it's quite possible. You may or may not already be aware of the USB Prober.app which can be extracted from the iousbfamily683.dmg .pkg (from Apple's Developer site), although it could be quite helpful since it dumps a ton of information. If you need a link to the one I extracted just let me know :)

User avatar
Matlo
Posts: 4463
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Building GIMX on Mac

Post by Matlo » Wed May 11, 2016 12:14 pm

I wrote a few details about gasync here: http://gimx.fr/wiki/index.php?title=Gasync
It should be useful for anyone wanting to port GIMX to other OSes.

I think the port to Darwin / MAC OS X should first focus on the DIY USB adapter features (and leave aside the bluetooth features).
GIMX creator Donate Shop

awesome
Posts: 4
Joined: Sun Feb 21, 2016 5:21 pm

Re: Building GIMX on Mac

Post by awesome » Thu May 12, 2016 8:17 pm

Anyone got anything playable yet?

User avatar
Matlo
Posts: 4463
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Building GIMX on Mac

Post by Matlo » Fri May 20, 2016 7:22 pm

Hi there,

I googled a bit to find a way to port gtimer to Darwin / MAC OS X.

It looks like a kqueue file descriptor can be used in a poll context.
The documentation from apple: https://developer.apple.com/library/mac ... 89-CH5-SW2
links to: http://people.freebsd.org/~jmg/kq.html
and finally to: http://www.freebsd.org/cgi/man.cgi?quer ... ormat=html
In this last page, search for EVFILT_TIMER.
There is an interesting topic on stackoverflow:
http://stackoverflow.com/questions/3091 ... ith-select
GIMX creator Donate Shop

0x1
Posts: 5
Joined: Fri May 06, 2016 6:34 am

Re: Building GIMX on Mac

Post by 0x1 » Fri May 20, 2016 11:12 pm

I created a gist, from the OS X poll() man page (also: EVFILT_TIMER man page desc from kevent()).

There's also some good info regarding kernel event and timer waits; I'm thinking the way they do it might be the OS X equiv of gtimer()? :
https://developer.apple.com/library/mac ... vices.html. The kevent() example you posted is definitely more specific than the generalized example I just linked, although the "Queues" section might be of interest.

Also I was able to build libusb natively for OS X without any issues (it even nicely creates an Xcode project file along with test programs/examples). If you're interested in any of the headers it generated just let me know.

User avatar
Matlo
Posts: 4463
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

Re: Building GIMX on Mac

Post by Matlo » Sat May 21, 2016 8:21 am

The link you provided is about kernel programming. It won't be useful as GIMX runs in user-space (i.e. not in the kernel).

There's another interesting page here: https://developer.apple.com/library/mac ... index.html
The mach_wait_until() function is not really helpful as it would require running an extra thread.
The interesting thing is the "How do I get put into the real time scheduling class?" part.
This can provide the gprio functionality.
GIMX creator Donate Shop

Post Reply