Raspberry 500 / Amiga Pi ?


94 posts   Page 1 of 4   1, 2, 3, 4
by thradtke » Thu Jul 12, 2012 9:58 am
Ok, it's cheated somehow: The case contains a case - a ModMyPi sample case. I realized, however, I could have mounted the PCB just as the power brick PCB.

The case contains keyboard (connected as USB HID device through an Arduino reading out the Amiga keyboard MCU) and USB-hub.

The 16 MHz Arduino is on the edge here, it just works but there are not much cycles left to add more fancy stuff.

Connectivity is rather humble, just two powered USB slots and HDMI. Coming up is Ethernet and, if I can manage to make solder an adapter card, a SD slot.

Feel encouraged to take your (dead!) home computer and do something similar! :-)
Attachments
RPI500_b.jpg
Inside view
RPI500_b.jpg (46.14 KiB) Viewed 9488 times
RPI500_a.jpg
rear view
RPI500_a.jpg (59.88 KiB) Viewed 9488 times
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by carl_retrotext » Fri Jul 13, 2012 6:42 pm
Its looking good, most of the leads you can break out, like in the VC 314 project, there is no reason why your one wont look better. :)
User avatar
Posts: 76
Joined: Sun May 06, 2012 1:05 pm
Location: essex
by thradtke » Sat Jul 14, 2012 6:13 am
Thanks, Carl! I missed your VC project, so thanks for the pointer. My A500 doesn't nearly look as pretty as this one, and I have no idea how (or if) I should modify the housing. I'm impressed by projects like that or the wooden Acorn done by Ben Heckendorn.

The hardest part now is getting out the SD card socket. I've wired a new socket (snap in/out) and cut open an adapter card. Fingers crossed it works electrically at those frequencies when finished.
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by carl_retrotext » Sat Jul 14, 2012 8:14 am
If you have difficulty with your keyboard adapter, you can try the Keyrah one that I used- It is amiga compatible too.

I traded off the sim card access as I wanted to avoid cutting the case and it would also restrict where I could site my PI, so I just open it up to change SDs ( not that I have any intention) I use one of the four usb slots with a pen drive for extra data like roms or MP3 files.

However, could you use the expansion hatch under the Amiga for PI access?
User avatar
Posts: 76
Joined: Sun May 06, 2012 1:05 pm
Location: essex
by thradtke » Sat Jul 14, 2012 9:05 am
I did the keyboard adapter myself just for the sake of it ;-). It works and now includes key repeat. The nice thing about DIY is to have full control over e.g. key mapping, and of course, it's a lot of fun learning such things :-).

If it had turned out to be impossible with a 16MHz AVR, I'd have had still an option to kick out the A500 keyboard controller und use some serial registers on the keyboard matrix. That would have been easier from the software side of things also (i.e. is not time critical).

The hatch is right under the keyboard. The Pi is not accessible from there, unfortunately. I could have placed it there, and it would have been a nice idea indeed! :-)
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by bennard1989 » Thu Oct 11, 2012 10:58 am
Hi, how did you manage to readout the Amiga Keyboard MCU, does ist work similar to the C64 Keyboard?!? Is it also a Keyboard-Matrix and you can read it out with a Arduino ?!?

Best regards,

Bennard
Posts: 2
Joined: Thu Oct 11, 2012 10:50 am
by thradtke » Thu Oct 11, 2012 12:42 pm
Hi Bennard,

bennard1989 wrote:Hi, how did you manage to readout the Amiga Keyboard MCU, does ist work similar to the C64 Keyboard?!? Is it also a Keyboard-Matrix and you can read it out with a Arduino ?!?


The A500 keyboard, unlike that of a C64, does have a separate controller. You can read out Data and Clock easily as described in the Technical and Hardware Reference Manuals. Note that Data has to be read and written by the Arduino and it's a open collector signal. Rather than doing it yourself, I can mail you my sketches for either Leonardo (recommended) or Duemilanove (additional hardware needed). Or both, of course. Note also that my sketches are for a german layout. As this keyboard has a non-standard layout, you cannot count on Linux drivers.

The four LEDs have to be driven by a constant current source, as the Arduino can't deliver the current needed.

Let me know if you need Sketches or my wiring scheme for the LEDs.

Best regards,

Thomas
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by thradtke » Thu Oct 11, 2012 12:47 pm
BTW., the project is finished now :-). I further added a 1.8 inch HDD for the rootfs and an Ethernet port. Works great and feels like a real computer ;-P.
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by bennard1989 » Sun Oct 21, 2012 1:11 am
thradtke wrote:Hi Bennard,

bennard1989 wrote:Hi, how did you manage to readout the Amiga Keyboard MCU, does ist work similar to the C64 Keyboard?!? Is it also a Keyboard-Matrix and you can read it out with a Arduino ?!?


The A500 keyboard, unlike that of a C64, does have a separate controller. You can read out Data and Clock easily as described in the Technical and Hardware Reference Manuals. Note that Data has to be read and written by the Arduino and it's a open collector signal. Rather than doing it yourself, I can mail you my sketches for either Leonardo (recommended) or Duemilanove (additional hardware needed). Or both, of course. Note also that my sketches are for a german layout. As this keyboard has a non-standard layout, you cannot count on Linux drivers.

The four LEDs have to be driven by a constant current source, as the Arduino can't deliver the current needed.

Let me know if you need Sketches or my wiring scheme for the LEDs.

Best regards,

Thomas


Hi Thomas,

it would be great if you could send me over your Sketches, so i dont have to totally find it out for myself how it works. I got a german Amiga too, so the german keylayout shouldn't be the problem.
I have a Arduino Uno Board, so it should be possible to let it work as a Hud-Device...

With best regards,

Bennard
Posts: 2
Joined: Thu Oct 11, 2012 10:50 am
by thradtke » Sun Oct 21, 2012 7:44 am
You have mail.
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by thradtke » Thu Nov 01, 2012 6:39 am
Since there were some requests, I'll post the Leonardo sketch below.

Code: Select all
#define A500CLK 8
#define A500SP 9
#define A500RES 10
#define LED_A 11
#define LED_B 12

#define SYNCH_HI 1
#define SYNCH_LO 2
#define HANDSHAKE 4
#define READ 16
#define WAIT_LO 8
#define WAIT_RES 64

unsigned char state;
signed char bitn=-1;
long counter;
unsigned short key,lkey=1000;
byte mode, fn, caps=0, num=0, scroll=0;

// normal layout
unsigned char ktab1[]={
  // Tilde, 1-9, 0, sz, Accent, backslash, Num 0 (00 - 0F)
  0x35, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2D, 0x2E, 0x31, 0, 0x62,
  // Q bis +, -, Num 1, Num 2, Num3 (10 - 1F)
  0x14, 0x1A, 0x08, 0x15, 0x17, 0x1C, 0x18, 0x0C, 0x12, 0x13, 0x2F, 0x30, 0, 0x59, 0x5A, 0x5B,
  // A-#, -, Num 4, Num 5, Num 6 (20 - 2F)
  0x04, 0x16, 0x07, 0x09, 0x0A, 0x0B, 0x0D, 0x0E, 0x0F, 0x33, 0x34, 0x32, 0, 0x5C, 0x5D, 0x5E,
  // <>,Y- -, -, Num . , Num 7, Num 8, Num 9 (30 - 3F)
  0x64 , 0x1D, 0x1B, 0x06, 0x19, 0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0, 0x63, 0x5F, 0x60, 0x61,
  // Space, BS, Tab, Enter, Return, ESC, Del, -, -, -, Num -, -, up, down, right, left (40 - 4F)
  0x2C, 0x2A, 0x2B, 0x58, 0x28, 0x29, 0x4C, 0, 0, 0, 0x56, 0, 0x52, 0x51, 0x4F, 0x50,
  // F1-F10, -, -, Num /, Num *, Num +, - (50 - 5F)
  0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0, 0, 0x54, 0x55, 0x57, 0x3A
};

// num-lock layout
unsigned char ktab2[]={
  // Tilde, 1-9, 0, sz, Accent, backslash, Num 0 (00 - 0F)
  0x35, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2D, 0x2E, 0x31, 0, 0x27,
  // Q bis +, -, Num 1, Num 2, Num3 (10 - 1F)
  0x14, 0x1A, 0x08, 0x15, 0x17, 0x1C, 0x18, 0x0C, 0x12, 0x13, 0x2F, 0x30, 0, 0x1E, 0x1F, 0x20,
  // A-#, -, Num 4, Num 5, Num 6 (20 - 2F)
  0x04, 0x16, 0x07, 0x09, 0x0A, 0x0B, 0x0D, 0x0E, 0x0F, 0x33, 0x34, 0x32, 0, 0x21, 0x22, 0x23,
  // <>,Y- -, -, Num . , Num 7, Num 8, Num 9 (30 - 3F)
  0x64 , 0x1D, 0x1B, 0x06, 0x19, 0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0, 0x37, 0x24, 0x25, 0x26,
  // Space, BS, Tab, Enter, Return, ESC, Del, -, -, -, Num -, -, up, down, right, left (40 - 4F)
  0x2C, 0x2A, 0x2B, 0x58, 0x28, 0x29, 0x4C, 0, 0, 0, 0x56, 0, 0x52, 0x51, 0x4F, 0x50,
  // F1-F10, -, -, Num /, Num *, Num +, - (50 - 5F)
  0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0, 0, 0x54, 0x55, 0x57, 0x3A
};
unsigned char *ktab;

void setup() { 
  pinMode(A500CLK, INPUT);
  pinMode(A500SP, INPUT); 
  pinMode(A500RES, INPUT);
  pinMode(LED_A, OUTPUT);
  pinMode(LED_B, OUTPUT);
  digitalWrite(A500SP, LOW);
  state=SYNCH_HI;
  counter=0;
  ktab=ktab1;
  Keyboard.begin();
}

void loop() {
  // Reset
  if (digitalRead(A500RES)==LOW && state!=WAIT_RES) {
    digitalWrite(LED_B,LOW);
    interrupts();
    Keyboard.press2(0x4C,0x05);
    Keyboard.release2(0x4C,0x05);
   delay(10);
    fn=false;
    lkey=1000;
    state=WAIT_RES;
  }
  // Warten Reset Ende
  else if (state==WAIT_RES) {
    if (digitalRead(A500RES)==HIGH) state=SYNCH_HI;
  }
  // Synch-Puls
  else if (state==SYNCH_HI) {
    if (digitalRead(A500CLK)==LOW) state=SYNCH_LO;
  }
  else if (state==SYNCH_LO) {
    if (digitalRead(A500CLK)==HIGH) {
      digitalWrite(LED_B,HIGH);
      state=HANDSHAKE;
    }
  }
  else if (state==HANDSHAKE) {
    if (counter==0) {
      pinMode(A500SP, OUTPUT);
      digitalWrite(A500SP,LOW);
      counter=millis();
    }
    else if (millis()-counter>84) {
      counter=0;
      pinMode(A500SP, INPUT);
      digitalWrite(A500SP, HIGH);
      state=WAIT_LO;
      key=0;
      bitn=7;
    }
  }
  else if (state==READ) {
    if (digitalRead(A500CLK)==HIGH) {

      // add bit
     
      key+=(!digitalRead(A500SP))<<(bitn?bitn-1:7);

      // all bits read
      if (--bitn<0) {
        //digitalWrite(13, HIGH);
        interrupts();
        state=HANDSHAKE;
        //Keyboard.begin();
      
      Serial.begin();
      Serial.prinln(key);
      
        if (key==lkey) {
        }
        else {
          lkey=key;
         
          switch (key) {
          case 0x63:  // Control left
            mode|=0x01;
            break;
          case 0xE3:
            mode&=0xFE;
            break;
          case 0x67:  // Control right (Amiga right)
            mode|=0x10;
            break;
          case 0xE7:
            mode&=0xEF;
            break;
          case 0x64:  // Alt left
            mode|=0x04;
            break;
          case 0xE4:
            mode&=0xFB;
            break;
          case 0x65:  // Alt right
            mode|=0x40;
            break;
          case 0xE5:
            mode&=0xBF;
            break;
          case 0x60:  // Shift left
            mode|=0x02;
            break;
          case 0xE0:
            mode&=0xFD;
            break;
          case 0x61:  // Shift right
            mode|=0x20;
            break;
          case 0xE1:
            mode&=0xDF;
            break;
          case 0x66:  // left amiga / FN
            fn=true;
            break;
          case 0xE6:
            fn=false;
            break;
          default:
            // left Amiga
            if (fn) {
              // F11-F12
              if (key==0x50) {
                Keyboard.press2(0x44,0);
                Keyboard.release2(0x44,0);
              }
              else if (key==0x51) {
                Keyboard.press2(0x45,0);
                Keyboard.release2(0x45,0);
              }
              // NumLock
              else if (key==0x5A) {
                num^=1;
                if (num) {
                  digitalWrite(LED_A, HIGH);
                  ktab=ktab2;
                }
                else {
                  ktab=ktab1;
                  digitalWrite(LED_A, LOW);
                }
              }
              // At
              else if (key==0x02) {
                Keyboard.press2(0x14,0x40);
                Keyboard.release2(0x14,0x40);
              }
              // Grad
              else if (key==0x04) {
                Keyboard.press2(0x35,0x40);
                Keyboard.release2(0x35,0x40);
              }
            }
            // CapsLock
            else if (key==0x62) {
              caps=0x02;
            }
            else if (key==0xE2) {
              caps=0;
            }
 
           
            else if (key==0x00) {
              if (mode&0x02 || mode&0x20) {
                // Tilde
                Keyboard.press2(0x30,0x40);
                Keyboard.release2(0x30,0x40);
              }
              else {
                // Apostroph
                Keyboard.press2(0x32,0x20);
                Keyboard.release2(0x32,0x20);
              }
            }
           
           
            // Backslash and Seperator
            else if (key==0x0D) {
              if (mode&0x02 || mode&0x20) {
                Keyboard.press2(0x64,0x40);
                Keyboard.release2(0x64,0x40);
              }
              else {
                Keyboard.press2(0x2D,0x40);
                Keyboard.release2(0x2D,0x40);
              }
            }
            // Dach
            else if (key==0x2B && (mode&0x02 || mode&0x20)) {
              Keyboard.press2(0x35,0);
              Keyboard.release2(0x35,0);
            }
            // [ {
            else if (key==0x5A) {
              if (mode&0x02 || mode&0x20) {
                Keyboard.press2(0x24,0x40);
                Keyboard.release2(0x24,0x40);
              }
              else {
                Keyboard.press2(0x25,0x40);
                Keyboard.release2(0x25,0x40);
              }
            }
            // ] }
            else if (key==0x5B) {
              if (mode&0x02 || mode&0x20) {
                Keyboard.press2(0x27,0x40);
                Keyboard.release2(0x27,0x40);
              }
              else {
                Keyboard.press2(0x26,0x40);
                Keyboard.release2(0x26,0x40);
              }
            }
 
            // Tabelle
            else if (((byte)key&0x7F)<0x60) {
              if (((byte)key&0x80)==0x80) Keyboard.release2(ktab[(byte)key&0x7F],mode|caps);
              else Keyboard.press2(ktab[key],mode|caps);
            }
           
            // Fehler (keyboard)
            else if (key==0xF9) {
              mode=0;
           fn=false;
              Keyboard.releaseAll();
            }
            else if (key==0xFD) {
           fn=false;
              mode=0;
              Keyboard.releaseAll();
            }
            break;
          }
        }
        key=0;
      }
      else state=WAIT_LO;
    }
  }
  else if (state==WAIT_LO) {
    if (digitalRead(A500CLK)==LOW) {
      noInterrupts();
      //digitalWrite(13, LOW);
      state=READ;
    }
  }
}





Please refer to the code for how to connect the lines.

This is the LTSpice listing for both LED drivers:

Code: Select all
Version 4
SHEET 1 880 680
WIRE 112 64 -112 64
WIRE 112 160 112 64
WIRE -112 208 -112 64
WIRE -32 208 -112 208
WIRE 208 256 112 256
FLAG 336 256 0
FLAG -192 64 0
FLAG -32 288 0
SYMBOL res 64 192 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R1
SYMATTR Value 4K7
SYMBOL LED 208 272 R270
WINDOW 0 72 32 VTop 2
WINDOW 3 0 32 VBottom 2
SYMATTR InstName D1
SYMBOL LED 272 272 R270
WINDOW 0 72 32 VTop 2
WINDOW 3 0 32 VBottom 2
SYMATTR InstName D2
SYMBOL voltage -96 64 R90
WINDOW 0 -32 56 VBottom 2
WINDOW 3 32 56 VTop 2
WINDOW 123 0 0 Left 2
WINDOW 39 60 56 VTop 2
SYMATTR InstName V1
SYMATTR Value 5
SYMATTR SpiceLine Rser=1
SYMBOL npn 48 160 R0
SYMATTR InstName Q1
SYMATTR Value BC546B
SYMBOL res -16 192 M0
SYMATTR InstName R2
SYMATTR Value 10K
TEXT -232 304 Left 2 !.tran 0 1 .5


leftamiga has a special meaning:

    lamiga-numlock: numlock (orange LEDs)
    lamiga-F1: F11
    lamiga-F2: F12

There are additional symbols on the keyboard accessible also with lamiga.

Please ask questions here, not via PM.

Enjoy :)
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by Wizard » Fri Nov 02, 2012 2:00 am
Here's my rather "overkill" A500 keyboard solution :mrgreen:

Image

I was inspired by the work of thradtke (thanks!) but decided to write my own solution.
I had never played with arduinos keyboard class before and decided to write my own from scratch instead in order to learn.

I will build a dedicated hardware solution later since a DUE is a "bit" too much... hehe...

Now I only need to get directfb working with uae and my A500 revival is complete!
Raspberry Pi - finally a worthy replacement for A500!!!
User avatar
Posts: 120
Joined: Sun Aug 19, 2012 4:52 am
Location: Sweden
by thradtke » Sat Nov 03, 2012 6:48 pm
A more current version of the program w/o debug stuff:

Code: Select all
#define A500CLK 8
#define A500SP 9
#define A500RES 10
#define LED_A 11
#define LED_B 12

#define SYNCH_HI 1
#define SYNCH_LO 2
#define HANDSHAKE 4
#define READ 16
#define WAIT_LO 8
#define WAIT_RES 64

unsigned char state;
signed char bitn=-1;
long counter;
unsigned short key,lkey=1000;
byte mode, fn, caps=0, num=0, scroll=0;

// normal layout
unsigned char ktab1[]={
  // Tilde, 1-9, 0, sz, Accent, backslash, Num 0 (00 - 0F)
  0x35, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2D, 0x2E, 0x31, 0, 0x62,
  // Q bis +, -, Num 1, Num 2, Num3 (10 - 1F)
  0x14, 0x1A, 0x08, 0x15, 0x17, 0x1C, 0x18, 0x0C, 0x12, 0x13, 0x2F, 0x30, 0, 0x59, 0x5A, 0x5B,
  // A-#, -, Num 4, Num 5, Num 6 (20 - 2F)
  0x04, 0x16, 0x07, 0x09, 0x0A, 0x0B, 0x0D, 0x0E, 0x0F, 0x33, 0x34, 0x32, 0, 0x5C, 0x5D, 0x5E,
  // <>,Y- -, -, Num . , Num 7, Num 8, Num 9 (30 - 3F)
  0x64 , 0x1D, 0x1B, 0x06, 0x19, 0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0, 0x63, 0x5F, 0x60, 0x61,
  // Space, BS, Tab, Enter, Return, ESC, Del, -, -, -, Num -, -, up, down, right, left (40 - 4F)
  0x2C, 0x2A, 0x2B, 0x58, 0x28, 0x29, 0x4C, 0, 0, 0, 0x56, 0, 0x52, 0x51, 0x4F, 0x50,
  // F1-F10, -, -, Num /, Num *, Num +, - (50 - 5F)
  0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0, 0, 0x54, 0x55, 0x57, 0x3A
};

// num-lock layout
unsigned char ktab2[]={
  // Tilde, 1-9, 0, sz, Accent, backslash, Num 0 (00 - 0F)
  0x35, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2D, 0x2E, 0x31, 0, 0x27,
  // Q bis +, -, Num 1, Num 2, Num3 (10 - 1F)
  0x14, 0x1A, 0x08, 0x15, 0x17, 0x1C, 0x18, 0x0C, 0x12, 0x13, 0x2F, 0x30, 0, 0x1E, 0x1F, 0x20,
  // A-#, -, Num 4, Num 5, Num 6 (20 - 2F)
  0x04, 0x16, 0x07, 0x09, 0x0A, 0x0B, 0x0D, 0x0E, 0x0F, 0x33, 0x34, 0x32, 0, 0x21, 0x22, 0x23,
  // <>,Y- -, -, Num . , Num 7, Num 8, Num 9 (30 - 3F)
  0x64 , 0x1D, 0x1B, 0x06, 0x19, 0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0, 0x37, 0x24, 0x25, 0x26,
  // Space, BS, Tab, Enter, Return, ESC, Del, -, -, -, Num -, -, up, down, right, left (40 - 4F)
  0x2C, 0x2A, 0x2B, 0x58, 0x28, 0x29, 0x4C, 0, 0, 0, 0x56, 0, 0x52, 0x51, 0x4F, 0x50,
  // F1-F10, -, -, Num /, Num *, Num +, - (50 - 5F)
  0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0, 0, 0x54, 0x55, 0x57, 0x3A
};
unsigned char *ktab;

void setup() { 
  pinMode(A500CLK, INPUT);
  pinMode(A500SP, INPUT); 
  pinMode(A500RES, INPUT);
  pinMode(LED_A, OUTPUT);
  pinMode(LED_B, OUTPUT);
  digitalWrite(A500SP, LOW);
  state=SYNCH_HI;
  counter=0;
  ktab=ktab1;
  Keyboard.begin();
}

void loop() {
  // Reset
  if (digitalRead(A500RES)==LOW && state!=WAIT_RES) {
    digitalWrite(LED_B,LOW);
    interrupts();
    Keyboard.press2(0x4C,0x05);
    delay(20);
    Keyboard.release2(0x4C,0x05);
    delay(20);
    fn=false;
    lkey=1000;
    state=WAIT_RES;
  }
  // Warten Reset Ende
  else if (state==WAIT_RES) {
    if (digitalRead(A500RES)==HIGH) state=SYNCH_HI;
  }
  // Synch-Puls
  else if (state==SYNCH_HI) {
    if (digitalRead(A500CLK)==LOW) state=SYNCH_LO;
  }
  else if (state==SYNCH_LO) {
    if (digitalRead(A500CLK)==HIGH) {
      digitalWrite(LED_B,HIGH);
      state=HANDSHAKE;
    }
  }
  else if (state==HANDSHAKE) {
    if (counter==0) {
      pinMode(A500SP, OUTPUT);
      digitalWrite(A500SP,LOW);
      counter=millis();
    }
    else if (millis()-counter>84) {
      counter=0;
      pinMode(A500SP, INPUT);
      digitalWrite(A500SP, HIGH);
      state=WAIT_LO;
      key=0;
      bitn=7;
    }
  }
  else if (state==READ) {
    if (digitalRead(A500CLK)==HIGH) {

      // add bit
     
      key+=(!digitalRead(A500SP))<<(bitn?bitn-1:7);

      // all bits read
      if (--bitn<0) {
        //digitalWrite(13, HIGH);
        interrupts();
        state=HANDSHAKE;
        //Keyboard.begin();
       
        if (key==lkey) {
        }
        else {
          lkey=key;
         
          switch (key) {
          case 0x63:  // Control left
            mode|=0x01;
            break;
          case 0xE3:
            mode&=0xFE;
            break;
          case 0x67:  // Control right (Amiga right)
            mode|=0x10;
            break;
          case 0xE7:
            mode&=0xEF;
            break;
          case 0x64:  // Alt left
            mode|=0x04;
            //UsbKeyboard.sendKeyStroke(0xE2);
            break;
          case 0xE4:
            mode&=0xFB;
            break;
          case 0x65:  // Alt right
            mode|=0x40;
            //UsbKeyboard.sendKeyStroke(0xE6);
            break;
          case 0xE5:
            mode&=0xBF;
            break;
          case 0x60:  // Shift left
            mode|=0x02;
            //UsbKeyboard.sendKeyStroke(0xE1);
            break;
          case 0xE0:
            mode&=0xFD;
            break;
          case 0x61:  // Shift right
            mode|=0x20;
            //UsbKeyboard.sendKeyStroke(0xE5);
            break;
          case 0xE1:
            mode&=0xDF;
            break;
          case 0x66:  // left amiga / FN
            fn=true;
            break;
          case 0xE6:
            fn=false;
            break;
          default:
            // left Amiga
            if (fn) {
              // F11-F12
              if (key==0x50) {
                Keyboard.press2(0x44,0);
                Keyboard.release2(0x44,0);
              }
              else if (key==0x51) {
                Keyboard.press2(0x45,0);
                Keyboard.release2(0x45,0);
              }
              // NumLock
              else if (key==0x5A) {
                num^=1;
                if (num) {
                  digitalWrite(LED_A, HIGH);
                  ktab=ktab2;
                }
                else {
                  ktab=ktab1;
                  digitalWrite(LED_A, LOW);
                }
              }
              // At
              else if (key==0x02) {
                Keyboard.press2(0x14,0x40);
                Keyboard.release2(0x14,0x40);
              }
              // Grad
              else if (key==0x04) {
                Keyboard.press2(0x35,0x40);
                Keyboard.release2(0x35,0x40);
              }
            }
            // CapsLock
            else if (key==0x62) {
              caps=0x02;
            }
            else if (key==0xE2) {
              caps=0;
            }
 
           
            else if (key==0x00) {
              if (mode&0x02 || mode&0x20) {
                // Tilde
                Keyboard.press2(0x30,0x40);
                Keyboard.release2(0x30,0x40);
              }
              else {
                // Apostroph
                Keyboard.press2(0x32,0x20);
                Keyboard.release2(0x32,0x20);
              }
            }
           
           
            // Backslash and Seperator
            else if (key==0x0D) {
              if (mode&0x02 || mode&0x20) {
                Keyboard.press2(0x64,0x40);
                Keyboard.release2(0x64,0x40);
              }
              else {
                Keyboard.press2(0x2D,0x40);
                Keyboard.release2(0x2D,0x40);
              }
            }
            // Dach
            else if (key==0x2B && (mode&0x02 || mode&0x20)) {
              Keyboard.press2(0x35,0);
              Keyboard.release2(0x35,0);
            }
            // [ {
            else if (key==0x5A) {
              if (mode&0x02 || mode&0x20) {
                Keyboard.press2(0x24,0x40);
                Keyboard.release2(0x24,0x40);
              }
              else {
                Keyboard.press2(0x25,0x40);
                Keyboard.release2(0x25,0x40);
              }
            }
            // ] }
            else if (key==0x5B) {
              if (mode&0x02 || mode&0x20) {
                Keyboard.press2(0x27,0x40);
                Keyboard.release2(0x27,0x40);
              }
              else {
                Keyboard.press2(0x26,0x40);
                Keyboard.release2(0x26,0x40);
              }
            }
 
            // Tabelle
            else if (((byte)key&0x7F)<0x60) {
             
              if (((byte)key&0x80)==0x80) Keyboard.release2(ktab[(byte)key&0x7F],mode|caps);
              else Keyboard.press2(ktab[key],mode|caps);
            }
           
            // Fehler (keyboard)
            else if (key==0xF9) {
              mode=0;
              Keyboard.releaseAll();
            }
            else if (key==0xFD) {
              mode=0;
              Keyboard.releaseAll();
            }
            break;
          }
        }
        key=0;
      }
      else state=WAIT_LO;
    }
  }
  else if (state==WAIT_LO) {
    if (digitalRead(A500CLK)==LOW) {
      noInterrupts();
      //digitalWrite(13, LOW);
      state=READ;
    }
  }
}


...and the necessary new methods in arduino-1.0.1\hardware\arduino\cores\arduino/HID.cpp:

Code: Select all
size_t Keyboard_::press2(uint8_t k, uint8_t m)
{
   uint8_t i;
   if (m!=0) _keyReport.modifiers |= m;
   
   for (i=0; i<6; i++) {
      if (_keyReport.keys[i] == 0x00) {
         _keyReport.keys[i] = k;
         break;
      }
   }
   if (i == 6) {
      setWriteError();
      return 0;
   }   
   sendReport(&_keyReport);
   return 1;
}


Code: Select all
size_t Keyboard_::release2(uint8_t k, uint8_t m)
{
   uint8_t i;
   //if (m!=0) _keyReport.modifiers &= ~m;
   _keyReport.modifiers = 0;
   for (i=0; i<6; i++) {
      if (0 != k && _keyReport.keys[i] == k) {
         _keyReport.keys[i] = 0x00;
      }
   }
   sendReport(&_keyReport);
   return 1;
}


Sorry for the omission!
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by Wizard » Sun Nov 04, 2012 1:32 am
thradtke wrote:A more current version of the program w/o debug stuff:
...

Sorry for the omission!


Don't forget to update .../arduino-1.5/hardware/arduino/sam/cores/arduino/USB/USBAPI.h as well.

Code: Select all
class Keyboard_ : public Print
{
private:
   KeyReport _keyReport;
   void sendReport(KeyReport* keys);
public:
   Keyboard_(void);
   void begin(void);
   void end(void);
   virtual size_t write(uint8_t k);
   virtual size_t press(uint8_t k);
   virtual size_t press2(uint8_t k, uint8_t m);
   virtual size_t release(uint8_t k);
   virtual size_t release2(uint8_t k, uint8_t m);
   virtual void releaseAll(void);
};


You've done a good job here thradtke and I've borrowed some of your code into my solution.
If I could only get uae to run in directfb my job is done! ;)
Raspberry Pi - finally a worthy replacement for A500!!!
User avatar
Posts: 120
Joined: Sun Aug 19, 2012 4:52 am
Location: Sweden
by thradtke » Sun Nov 04, 2012 7:06 am
Yeah, thanks! :)
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by Altairst8te74 » Mon Nov 19, 2012 10:17 pm
This is brilliant!
I need some help so I apologise if im not up to speed on all this.

I want to use this on a mini-itx project, will it just work? I am clueless on all this but I want to give it a bash.

If I buy this: rduino-Compatible Mega 2560 R3 ATEMAGE16U2 will it work and where can I get all the required files/firmware to get this working with the amiga keyboard?

Also do you have any bigger pictures of the Amiga? Im liking the clean work :)

Thanx
Posts: 23
Joined: Mon Nov 19, 2012 10:08 pm
by Wizard » Mon Nov 19, 2012 11:04 pm
Altairst8te74 wrote:This is brilliant!
I need some help so I apologise if im not up to speed on all this.

I want to use this on a mini-itx project, will it just work? I am clueless on all this but I want to give it a bash.

If I buy this: rduino-Compatible Mega 2560 R3 ATEMAGE16U2 will it work and where can I get all the required files/firmware to get this working with the amiga keyboard?

Also do you have any bigger pictures of the Amiga? Im liking the clean work :)

Thanx


What you need is only to act as a USB device and the Mega is way overkill to be honest.
Arduino Pro Mini or Leonardo is more in line with what you need.
A simple ATTiny could do the work on a breakout board with FTDI loading but that requires some knowledge...

My A500pi has a Leonardo inside to handle the keyboard but that's due to me being lazy (and the fact that I've got a box full of various microcontrollers I don't use) and that work's like a charm!
Raspberry Pi - finally a worthy replacement for A500!!!
User avatar
Posts: 120
Joined: Sun Aug 19, 2012 4:52 am
Location: Sweden
by Altairst8te74 » Mon Nov 19, 2012 11:17 pm
Ok I have done some reading and im catching up quick!

I like the Arduino Pro Mini but I just noticed its 3.3v... So I will go for the Leonardo.
I have also just grabbed v1.02 of the arduino stuff and will have a good nose around.

All I need now is how to actually get the keyboard talking to the device, can I please have your schematics and stuff? Btw I will be using a UK Layout keyboard so I assume that means me remapping a bit?

Thanx! If it were not for you guys then none of this cool stuff would be possible :)
Posts: 23
Joined: Mon Nov 19, 2012 10:08 pm
by Wizard » Mon Nov 19, 2012 11:50 pm
Arduino Pro Mini is available as 5v as well.

https://www.sparkfun.com/products/11113
Raspberry Pi - finally a worthy replacement for A500!!!
User avatar
Posts: 120
Joined: Sun Aug 19, 2012 4:52 am
Location: Sweden
by thradtke » Tue Nov 20, 2012 6:33 am
Altairst8te74 wrote:All I need now is how to actually get the keyboard talking to the device, can I please have your schematics and stuff?

Everything that's not here is in the technical and hardware reference manuals for the A2000/A500. You can easily identify the pinout in the sourcecode:

Code: Select all
#define A500CLK 8
#define A500SP 9
#define A500RES 10
#define LED_A 11
#define LED_B 12


So, basically you need a piggyback ('Shield' in Arduino terms) that holds the header for the A500 keyboard connector and wire it up accordingly. If you're not using a Leonardo or its clones, additional work has to be done on the USB connector (did it, but wouldn't recommend it). For a luxery version you need a constant current source for each LED. They take up approx. 100mA each, so cannot be directly connected! The schematics is in one of my posts in this thread.

I have no further pictures and no other schematics. I think this is a task everyone can do on its own who really cares and involves himself in this matter. I as a noob could, and that means something! ;-).

BTW, someone in the Arduino forum does an extended version, even integrating successfully Joystick ports and do some optimization! I'm really looking forward to see his work.
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by Altairst8te74 » Tue Nov 20, 2012 8:17 am
I appreciate all the help :)

I will suss it, this will be fun. I have a keyrah but its very touchy and sometimes just dies for no reason? along with all the stupid messing around trying to show-horn it in and then having a1200 ribbons die on me, I have decided to ditch it for now. I have a plan to do a c64 mod anyway so it belongs in that.

I am very interested in that arduino with the joystick ports! That is one thing I am not happy about regarding the keyrah, because im not using it now im going to loose the joystick ports :(
Posts: 23
Joined: Mon Nov 19, 2012 10:08 pm
by thradtke » Tue Nov 20, 2012 9:07 am
Since you mentioned those keyboards: A1200 and C64 keyboards are a whole different story. They don't come with an integrated keyboard controller, means you have to care for the keyboard matrix by means of some serial registers yourself.
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by Altairst8te74 » Tue Nov 20, 2012 10:01 am
I bought the keyrah for that job! But I just dont like the a1200 solution they came up with. I suppose there was not much choice due to how the thing attaches to the a1200 motherboard, its a pita as these ribbon/membraines are fragile and I think mine is fubard already, tested it months ago and it was fine but now when I finally start building it up the top row of numbers are stone dead? Even if I fix this up I will always be paranoid that it will go awol again the moment I start moving things.

So I have to find one in my storage or the better option is an a500 keyboard and arduino. I have a500 keyboards ready to go all I need is the arduino itself and some time.

EDIT: On the a500 keyboard, I am not going to bother using the two leds on the controller board but would like the capslock key led to work. Is that possible? I will go with my initial plan of using the two leds as power and hdd activity (did a test back along and it works) but will have to cut tracks/isolate them maybe?
Posts: 23
Joined: Mon Nov 19, 2012 10:08 pm
by thradtke » Tue Nov 20, 2012 10:21 am
Altairst8te74 wrote:EDIT: On the a500 keyboard, I am not going to bother using the two leds on the controller board but would like the capslock key led to work. Is that possible?

Yes, it lights up automatically. This key is special: It doesn't report up or down on pressing, but lock and unlock caps. I take care of this in my program, so it just do what it should.

I used one of the LEDs as numlock indicator, a feature that is incredibly useful on this keyboard as there are no dedicated begin/end and page up/down keys. The numlock is used quite often to allow for convenient number entry and editing at the same time.
Full-time noob forever.
Posts: 430
Joined: Wed May 16, 2012 5:16 am
Location: Germany / EL
by Altairst8te74 » Tue Nov 20, 2012 11:28 am
Just attacked my wallet with this lot:

Arduino Leonardo ATMega32U4
Arduino Electronic breadboard 170 points lead kit 65 wires 4 x 40 headers
Arduino Prototyping Sheild R3

Just need some strip board pins or whatever they are called.
Posts: 23
Joined: Mon Nov 19, 2012 10:08 pm