geekhack Community > Input Devices

USB converter for Apple M0100 mouse

(1/3) > >>

Yoe:
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: --- 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)
--- End code ---

The code with my changes here:


--- Code: ---/* ================================================================================
   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];
}
--- End code ---

Many thanks to GuilleAcoustic for this!

CPTBadAss:
You should shoot a video on your Instagram with the mouse and keyboard in action :D. Looks damn good!

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

Yoe:

--- Quote from: CPTBadAss 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!

--- End quote ---

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


--- Quote from: sth on Mon, 10 August 2015, 08:09:20 ---Is this just on a teensy??? I might have to make one of these :D

--- End quote ---

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

Hzza:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version