;------------------------------------------------------------- ; PS/2 ISR Tiny-2106, LPC-H2214 ; ; Version for MCUs without appropriate Timer/Counters (esp. counters) ; ; uses external interrupt (EINT) triggered by CLOCK to ; count and read incoming bits. ; EINT is assumed level sensitive, active low ; (LPC-H2214 has both level and edge sensitive EINT but ; edge sensitivity is not used here) ; -> PS2 CLOCK must be on Gpio0 and Pinsel0 (P0.0 to P0.15) ;------------------------------------------------------------- ; open the init-lcd-uart file (define p (open-output-file "init-lcd-ps2")) ; TINY-2106 ; P0.29 = PS2 IO pin, gpio ; P0.15 = PS2 CLK pin, EINT2 (write '(begin (define ps2_iogpi #x0e002800) ; IO & CLK gpio base (define ps2_iopin 29) ; IO = P0.29 (define ps2_ckpcf #x00) ; CLK pin on pnsl0 (define ps2_ckpin 15) ; CLK = P0.15 (define ps2_ckint 2) ; CLK = EINT 2 (define ps2_ckcfg #b10) ; #b10 => P0.15 to EINT2 (define ps2_isr 16) ; EINT2 isr index in Vic (define Vic_iclr #x30)) ; interrupt clear offset p) ; LPC-H2214 ; P0.10 = PS2 IO pin, gpio ; P0.9 = PS2 CLK pin, EINT3 ; (keyboard needs to be connected and powered or EINT will trip) ; (+5V power for keyboard comes from external, regulated, power supply, ; and external ground is connected to H2214 board ground on jtag plug) (write '(begin (define ps2_iogpi #x0e002800) ; IO & CLK gpio base (define ps2_iopin 10) ; IO = P0.10 (define ps2_ckpcf #x00) ; CLK pin on pnsl0 (define ps2_ckpin 9) ; CLK = P0.9 (define ps2_ckint 3) ; CLK = EINT 3 (define ps2_ckcfg #b11) ; #b11 => P0.9 to EINT3 (define ps2_isr 17) ; EINT3 isr index in Vic (define Vic_iclr #x30)) ; interrupt clear offset p) ; build the PS/2 ISR ; part 1 (due to limitations in read buffer size) (write '(define temp '#(0 0 #xeb 0 #x3FE5 #xE28F #x3000 #xE593 #x2083 #xE1A0 #xC003 #xE3A0 #xC21C #xE1A0 #xE20E #xE3A0 #xE90B #xE38E #x1000 #xE59E #xC00C #xE1C1 #xC000 #xE58E #xCFD9 #xE28F #xC000 #xE59C #x2001 #xE3A0 #x3312 #xE1A0 #x2000 #xE59C #x2003 #xE012 #xF010 #x24F #x1000 #xE58E #xEE33 #xE28F #x3000 #xE59E #xCA0F #xE203 #xA0A #xE35C #xE094 #x528F #xF00E #x51A0 #x0 #xE33C #x30FF #x3C3 #x3CFF #x3C3 #xCE32 #xE28F #xC000 #xE59C #x2FC7 #xE28F #x2000 #xE592 #xC000 #xE59C #x200C #xE002 #x0 #xE332 #xC623 #x1A0 #xC00F #x20C #x2001 #x3A0 #x2C12 #x1A0 #x3002 #x183 #x3A01 #xE283)) p) ; part 2 (due to limitations in read buffer size) (write '(define temp (vector-append temp '#(#xEFB6 #xE28F #x3000 #xE58E #x220E #xE3A0 #x281F #xE382 #x2CC1 #xE382 #xCFB9 #xE28F #xC000 #xE59C #xC040 #xE582 #x24FF #xE3A0 #x2642 #xE1A0 #xCFAE #xE28F #xC000 #xE59C #x200C #xE082 #xC000 #xE3A0 #xC000 #xE582 #xC01C #xE59D #xF00C #xE16F #x500F #xE8DD #xD018 #xE28D #x4000 #xE8BD #xF00E #xE1B0 #x3 #xE1E0 #x20FF #xE3A0 #x20A0 #xE002 #x34FF #xE203 #xF0 #xE332 #x3302 #x383 #xE0 #x1332 #xE078 #x24F #xF00E #x1A0 #xAA #xE332 #x3000 #x3A0 #xE088 #x24F #xF00E #x1A0 #x14 #xE332 #x402 #x3A0 #x301 #x13A0 #x12 #x1332 #x59 #x1332 #xE018 #x128F))) p) ; part 3 (due to limitations in read buffer size) (write '(define temp (vector-append temp '#(#xF00E #x11A0 #x302 #xE313 #x3000 #x11C3 #x3000 #x183 #x3302 #xE3C3 #xE0BC #xE24F #xF00E #xE1A0 #x302 #xE313 #x3302 #x1223 #xE0CC #x124F #xF00E #x11A0 #x2080 #xE3C2 #xF5E #xE28F #x2002 #xE7D0 #x406 #xE313 #x64 #x28F #xF000 #x1A0 #x301 #xE313 #xE0 #x3A0 #xA0 #x13A0 #x61 #xE352 #x2000 #x51C2 #x48 #x528F #xF000 #x51A0 #x27 #xE332 #x2022 #x3A0 #x38 #x28F #xF000 #x1A0 #x3D #xE332 #x202B #x3A0 #x28 #x28F #xF000 #x1A0 #x40 #xE352 #x202C #x4242 #x200F #x4202 #xF67 #x428F #x2002 #x47D0 #xC #x428F #xF000 #x41A0 #x60 #xE332))) p) ; part 4 (due to limitations in read buffer size) (write '(define temp (vector-append temp '#(#x207E #x3A0 #x2020 #x1382 #xF67 #xE28F #x0 #xE590 #x3 #xE332 #x20A4 #x28F #xF002 #x1A0 #x10AC #xE92D #x1000 #xE590 #x1C01 #xE281 #x1000 #xE580 #x1421 #xE1A0 #x1003 #xE281 #x2001 #xE7C0 #x3002 #xE1A0 #x30FF #xE203 #x5F5A #xE28F #x5000 #xE595 #xC004 #xE595 #xC014 #xE59C #xC004 #xE28C #xE000 #xE28F #xF00C #xE1A0 #x30FF #xE203 #x8 #xE333 #xC044 #x128F #xF00C #x11A0 #x3020 #xE3A0 #xC004 #xE595 #xC014 #xE59C #xC004 #xE28C #xE000 #xE28F #xF00C #xE1A0 #x3008 #xE3A0 #xC004 #xE595 #xC014 #xE59C #xC004 #xE28C #xE000 #xE28F #xF00C #xE1A0 #x1000 #xE590))) p) ; part 5 (due to limitations in read buffer size) (write '(define temp (vector-append temp '#(#x1C02 #xE241 #x53 #xE351 #x1053 #x43A0 #x1000 #xE580 #x10AC #xE8BD #x1000 #xE59C #xEC02 #xE24F #xF00E #xE1A0 #x2053 #xE3A0 #x2000 #xE580 #xE0D0 #xE28F #x3000 #xE58E #x220E #xE3A0 #x281F #xE382 #x2CC1 #xE382 #xC0DC #xE28F #xC000 #xE59C #xC040 #xE582 #x24FF #xE3A0 #x2642 #xE1A0 #xC0B0 #xE28F #xC000 #xE59C #x200C #xE082 #xC000 #xE3A0 #xC000 #xE582 #xE098 #xE28F #xE000 #xE59E #xF00E #xE1A0 #xFFFF #xFFFF #xFFFF #xFFFF #xFFFF #xFFFF #x9FF #xFF60 #xFFFF #xFFFF #x71FF #xFF31 #xFFFF #x737A #x7761 #xFF32 #x63FF #x6478 #x3465 #xFF33 #x20FF #x6676 #x7274 #xFF35))) p) ; part 6 (due to limitations in read buffer size) (write '(define temp (vector-append temp '#(#x6EFF #x6862 #x7967 #xFF36 #xFFFF #x6A6D #x3775 #xFF38 #x2CFF #x696B #x306F #xFF39 #x2EFF #x6C2F #x703B #xFF2D #xFFFF #xFF27 #x3D5B #xFFFF #xFFFF #x5D0D #x5CFF #xFFFF #xFFFF #xFFFF #xFFFF #xFF08 #x15FF #x11FF #xFF12 #xFFFF #x7FFF #xFF19 #x1810 #xFF1B #xFFFF #xFF14 #x13FF #xFFFF #x5F3C #x3F3E #x2129 #x2340 #x2524 #x265E #x282A #x3AFF #x0 #x0 #x7A4 #x0))) p) ; part 7 (due to limitations in read buffer size) (write '(begin (vector-set! _ISR ps2_isr (install (vector-append temp (vector (logand #xffff Vic_iclr) (logand #xffff (ash Vic_iclr -16)) (logand #xffff (ash _RBF 2)) (logand #xffff (ash _RBF -14)) (logand #xffff (ash lcop 2)) (logand #xffff (ash lcop -14)) (logand #xffff (ash ps2_iogpi 4)) (logand #xffff (ash ps2_iogpi -12)) (logand #xffff (ash 1 ps2_iopin)) (logand #xffff (ash 1 (- ps2_iopin 16))) (logand #xffff ps2_ckpin) (logand #xffff (ash ps2_ckpin -16)) (logand #xffff (ash 1 ps2_ckint)) 0)))) (set! temp #t)) p) ; define the bit-set and bit-clear utility functions ; (bit-set bit reg ofst) ; (bit-clear bit reg ofst) ; For arm7tdmi, arm9tdmi. (write '(begin (define bit-set (install '#(#x27 0 #x03eb 0 #x2144 #xE1A0 #x3145 #xE1A0 #xC146 #xE1A0 #x3203 #xE08C #xC001 #xE3A0 #xC21C #xE1A0 #x2000 #xE593 #x200C #xE182 #x2000 #xE583 #x400F #xE3A0 #xF001 #xE1A0))) (define bit-clear (install '#(#x27 0 #x03eb 0 #x2144 #xE1A0 #x3145 #xE1A0 #xC146 #xE1A0 #x3203 #xE08C #xC001 #xE3A0 #xC21C #xE1A0 #x2000 #xE593 #x200C #xE1C2 #x2000 #xE583 #x400F #xE3A0 #xF001 #xE1A0)))) p) ; define the word-copy utility function ; (word-copy dest-reg dest-ofst src-reg src-ofst) ; For arm7tdmi, arm9tdmi. (write '(define word-copy (install '#(#x27 0 #x04eb 0 #x3146 #xE1A0 #xC147 #xE1A0 #x3203 #xE08C #x2000 #xE593 #x3144 #xE1A0 #xC145 #xE1A0 #x3203 #xE08C #x2000 #xE583 #x400F #xE3A0 #xF001 #xE1A0))) p) ; configure PS2 CLK pin, interrupt ; VicIntEnClr <- disable EINT interrupts ; configure ps2 io and ck pins ; configure VIC, enable EINT (write '(let* ((pinsel #x0E002C00) (VIC #x0fffff00) (ckbt (ash (modulo ps2_ckpin 16) 1)) (bcfg (lambda (a1 a2 a3 a4) (apply (if (zero? (logand a1 a2)) bit-clear bit-set) (list a3 pinsel a4))))) (bit-set ps2_isr VIC #x14) (bcfg #b01 ps2_ckcfg ckbt ps2_ckpcf) (bcfg #b10 ps2_ckcfg (+ 1 ckbt) ps2_ckpcf) (word-copy VIC (logior #x100 (ash ps2_isr 2)) VIC #x110) (bit-set ps2_ckint #x0e01fc10 #x40) (bit-set ps2_isr VIC #x10)) p) ; set output port to LCD (write '(begin (define ocop (current-output-port)) (define (current-output-port) lcop)) p) ; close the file (close-output-port p)