Author Topic: USB converter for Apple M0100 mouse  (Read 3559 times)

0 Members and 1 Guest are viewing this topic.

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteċ, Sweden
  • Alps & ISO <3
USB converter for Apple M0100 mouse
« on: Mon, 10 August 2015, 08:06:30 »
When trying to find an already made USB converter for the M0100 mouse, I did not find one. However, I stumbled upon this bus mouse converter by GuilleAcoustic:

https://hackaday.io/project/5875-busmouse-to-usb-hid-conversion
https://geekhack.org/index.php?topic=68612.0

With help from him and from some nice old documentation on the M0100, I figured out how this could possibly work. And, luckily, it did :)

The only changes made to the code is setting an internal pull-up for the switch pin (my first version used an external resistor), and commenting out the state check for right and middle buttons.

Wiring to the DB9 goes:

Code: [Select]
DB9     Pro Micro
    1       GND
    2       VCC
    3       GND
    4       D0      (pin 3)
    5       D1      (pin 2)
    6       -       (not connected)
    7       B3      (pin 14)
    8       D3      (pin TXO)
    9       D2      (pin RXI)

The code with my changes here:

Code: [Select]
/* ================================================================================
   Author  : GuilleAcoustic
   Date    : 2015-05-22
   Revision: V1.0
   Purpose : Opto-mechanical trackball firmware
   --------------------------------------------------------------------------------
   Wiring informations: Sparkfun Pro micro (Atmega32u4)
   --------------------------------------------------------------------------------
     - Red    : Gnd                          |   Pin: Gnd
     - Orange : Vcc (+5V)                    |   Pin: Vcc
     - Yellow : X axis encoder / channel A   |   Pin: PD3 - (INT0)
     - Green  : X axis encoder / channel B   |   Pin: PD2 - (INT1)
     - Blue   : Y axis encoder / channel A   |   Pin: PD0 - (INT2)
     - Violet : Y axis encoder / channel B   |   Pin: PD1 - (INT3)
     - Grey   : Switch 1                     |   Pin: PB3
     - White  : Switch 2                     |   Pin: PB2
     - Black  : Switch 3                     |   Pin: PB1
   
   --------------------------------------------------------------------------------
   Modified for use with Apple M0100 mouse
   By Johan Berglund, 2015-08-10

   Changes in code:
   - Internal pullup set for pin 14 (B3)
   - State check for right and middle buttons commented out

   Connection to DB9:
   
   DB9     Pro Micro
    1       GND
    2       VCC
    3       GND
    4       D0      (pin 3)
    5       D1      (pin 2)
    6       -       (not connected)
    7       B3      (pin 14)
    8       D3      (pin TXO)
    9       D2      (pin RXI)
   
   ================================================================================ */

// =================================================================================
// Type definition
// =================================================================================
typedef struct
{
  int8_t  coordinate = 0;
  uint8_t index      = 0;
} ENCODER_;

// =================================================================================
// Constant definition
// =================================================================================
const int8_t lookupTable[] = {0, 1, -1, 0, -1, 0, 0, 1, 1, 0, 0, -1, 0, -1,  1,  0};

// =================================================================================
// Volatile variables
// =================================================================================
volatile ENCODER_ xAxis;
volatile ENCODER_ yAxis;

// =================================================================================
// Setup function
// =================================================================================
void setup()
{

  // Set pull-up for mouse switch on M0100
  pinMode(14, INPUT_PULLUP);
 
  // Attach interruption to encoders channels
  attachInterrupt(0, ISR_HANDLER_X, CHANGE);
  attachInterrupt(1, ISR_HANDLER_X, CHANGE);
  attachInterrupt(2, ISR_HANDLER_Y, CHANGE);
  attachInterrupt(3, ISR_HANDLER_Y, CHANGE);
 
  // Start the mouse function
  Mouse.begin();
}

// =================================================================================
// Main program loop
// =================================================================================
void loop()
{
  // Update mouse coordinates
  if (xAxis.coordinate != 0 || yAxis.coordinate != 0)
  {
    Mouse.move(xAxis.coordinate, yAxis.coordinate);
    xAxis.coordinate = 0;
    yAxis.coordinate = 0;
  }

  // Update buttons state
  !(PINB & 0b1000) ? Mouse.press(MOUSE_LEFT)   : Mouse.release(MOUSE_LEFT);
  // !(PINB & 0b0100) ? Mouse.press(MOUSE_RIGHT)  : Mouse.release(MOUSE_RIGHT);
  // !(PINB & 0b0010) ? Mouse.press(MOUSE_MIDDLE) : Mouse.release(MOUSE_MIDDLE);


  // Wait a little before next update
  delay(10);
}

// =================================================================================
// Interrupt handlers
// =================================================================================
void ISR_HANDLER_X()
{
  // Build the LUT index from previous and new data
  xAxis.index       = (xAxis.index << 2) | ((PIND & 0b0011) >> 0);
  xAxis.coordinate += lookupTable[xAxis.index & 0b1111];
}

void ISR_HANDLER_Y()
{
  // Build the LUT index from previous and new data
  yAxis.index       = (yAxis.index << 2) | ((PIND & 0b1100) >> 2);
  yAxis.coordinate += lookupTable[yAxis.index & 0b1111];
}

Many thanks to GuilleAcoustic for this!

Offline CPTBadAss

  • Woke up like this
  • Posts: 14330
  • Location: CT, USA
  • Rich Homie Huang.
Re: USB converter for Apple M0100 mouse
« Reply #1 on: Mon, 10 August 2015, 08:09:04 »
You should shoot a video on your Instagram with the mouse and keyboard in action :D. Looks damn good!
Please check out TactileZine.com!

Offline sth

  • 2 girls 1 cuprubber
  • Posts: 3402
  • ftdoc.nl
    • forthedeclineofcivilisation
Re: USB converter for Apple M0100 mouse
« Reply #2 on: Mon, 10 August 2015, 08:09:20 »
Is this just on a teensy??? I might have to make one of these :D
11:48 -!- SmallFry [~SmallFry@unaffiliated/smallfry] has quit [Ping timeout: 245 seconds] ... rest in peace

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteċ, Sweden
  • Alps & ISO <3
Re: USB converter for Apple M0100 mouse
« Reply #3 on: Mon, 10 August 2015, 08:58:39 »
You should shoot a video on your Instagram with the mouse and keyboard in action :D. Looks damn good!

Haha, maybe.. and show off my lack of wpm and the lack of resolution and accuracy of that ancient mouse.. :P

Is this just on a teensy??? I might have to make one of these :D

It's a Pro Micro, but you can use a Teensy instead if you like.

Offline Hzza

  • Posts: 377
  • Location: Windsor, UK
Re: USB converter for Apple M0100 mouse
« Reply #4 on: Mon, 10 August 2015, 09:35:08 »
This is pretty cool, I'd love to see a shot of your new working set up :D.

I'm pretty sure someone added mouse support to the hasu ADBs converter a few months back, with the intention being that you could daisy chain it off of a keyboard running hasu's converter. I never got around to testing it though...I've got a mouse and all the parts for a new converter kicking around, maybe I'll have a go tonight. I'm struggling to adjust to a mouse with only 3 buttons down from one with 5 so god knows what I'd do with a 1 button mouse :D.

edit - Oh wait, that's a serial mouse! My bad, I saw Apple and assumed ADB :D.
« Last Edit: Mon, 10 August 2015, 09:39:53 by Hzza »

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteċ, Sweden
  • Alps & ISO <3
Re: USB converter for Apple M0100 mouse
« Reply #5 on: Mon, 10 August 2015, 11:18:14 »
Yeh, not even serial actually. The mouse connects the quadrature signals from the encoders directly. (See links in OP for info on this if curious.)

Offline GuilleAcoustic

  • Posts: 77
  • Location: France
Re: USB converter for Apple M0100 mouse
« Reply #6 on: Tue, 11 August 2015, 15:09:44 »
Please shoot a video with heavy click action, I'm gonna play it in loop.

I will add the internal pull-up support to my code. This was my first ever arduino code and I never thought it would be of any use to someone. Glad it found a nice home.

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteċ, Sweden
  • Alps & ISO <3
Re: USB converter for Apple M0100 mouse
« Reply #7 on: Thu, 13 August 2015, 04:58:35 »
Please shoot a video with heavy click action, I'm gonna play it in loop.

I will add the internal pull-up support to my code. This was my first ever arduino code and I never thought it would be of any use to someone. Glad it found a nice home.

Ok, I'm not a video savvy guy, but here you go!

https://youtu.be/hk-n0wEGkWY

Offline hasu

  • Posts: 2802
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: USB converter for Apple M0100 mouse
« Reply #8 on: Thu, 13 August 2015, 05:20:10 »
Great job really two of you guys!

I like to try this someday when I can get my hand on the mouse.
TMK products:HHKB Alt  ⌨ConvertersAlps64FC660C AltFC980C Alt

Offline GuilleAcoustic

  • Posts: 77
  • Location: France
Re: USB converter for Apple M0100 mouse
« Reply #9 on: Thu, 13 August 2015, 09:38:39 »
Ok, I'm not a video savvy guy, but here you go!

Woot ! That is so nice. It is alive ! ALIVE !

Great job really two of you guys!

I like to try this someday when I can get my hand on the mouse.

Thanks a lot, never imagined that my humble code would interest you ... I'm all blushy now  :-[
« Last Edit: Thu, 13 August 2015, 09:40:21 by GuilleAcoustic »

Offline sexzual

  • Posts: 37
  • Location: WI USA
Re: USB converter for Apple M0100 mouse
« Reply #10 on: Thu, 06 December 2018, 17:24:32 »
Sorry to revive a super old thread, but i have a ch products dt225 i'd love to convert to usb and have programmable functionality.  Do you think this would work for the ch?
« Last Edit: Thu, 06 December 2018, 23:26:31 by sexzual »