c1351.h File Reference

C1350 and C1351 interface. More...

#include <inttypes.h>

Include dependency graph for c1351.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  _potmode { POTMOUSE_C1351 = 0, POTMOUSE_JOYSTICK }

Functions

void potmouse_init ()
 Init all C1351-related I/O and interrupts, but don't start yet.
void potmouse_start (uint8_t mode)
 Set mode and start working.
void potmouse_movt (int16_t dx, int16_t dy, uint8_t button)
 Report movement from PS2 mouse.
void potmouse_zero (uint16_t zero)
 Define zero-point in time (normally 320us).


Detailed Description

C1350 and C1351 interface.


Enumeration Type Documentation

enum _potmode

Mouse mode: 1351 (analog, proportional) or joystick

See potmouse_start()

Enumerator:
POTMOUSE_C1351 
POTMOUSE_JOYSTICK 
00014               {
00015     POTMOUSE_C1351 = 0,             //<! proportional mode
00016     POTMOUSE_JOYSTICK               //<! joystick mode
00017 };


Function Documentation

void potmouse_init (  ) 

Init all C1351-related I/O and interrupts, but don't start yet.

00033                      {
00034     // Joystick outputs, all to Z and no pullup
00035     JOYPORT &= ~(_BV(JOYFIRE) | _BV(JOYUP) | _BV(JOYDOWN) | _BV(JOYLEFT) | _BV(JOYRIGHT)); 
00036     JOYDDR  &= ~(_BV(JOYFIRE) | _BV(JOYUP) | _BV(JOYDOWN) | _BV(JOYLEFT) | _BV(JOYRIGHT));
00037     
00038     // SID sensing port
00039     SENSEDDR  &= ~_BV(POTSENSE); // SENSE is input
00040     SENSEPORT &= ~_BV(POTSENSE); // pullup off, hi-biased by OC1B
00041 
00042     // SID POTX/POTY port
00043     POTPORT &= ~(_BV(POTX) | _BV(POTY));
00044     POTDDR  &= ~(_BV(POTX) | _BV(POTY));
00045 
00046     // prepare INT1
00047     GICR &= ~_BV(INT1);                     // disable INT1
00048     MCUCR &= ~(_BV(ISC11)|_BV(ISC10));  
00049     MCUCR |= _BV(ISC11);                    // ISC11:ISC10 == 10, @negedge   
00050     
00051     mode = POTMOUSE_C1351;
00052 }

void potmouse_movt ( int16_t  dx,
int16_t  dy,
uint8_t  button 
)

Report movement from PS2 mouse.

00080                                                            {
00081     uint16_t a, b;
00082     
00083     switch (mode) {
00084         case POTMOUSE_C1351:
00085             potmouse_xcounter = (potmouse_xcounter + dx) & 077; // modulo 64
00086             potmouse_ycounter = (potmouse_ycounter + dy) & 077;
00087         
00088             (button & 001) ? (JOYDDR |= _BV(JOYFIRE)) : (JOYDDR &= ~_BV(JOYFIRE));
00089             (button & 002) ? (JOYDDR |= _BV(JOYUP))   : (JOYDDR &= ~_BV(JOYUP));
00090             (button & 004) ? (JOYDDR |= _BV(JOYDOWN)) : (JOYDDR &= ~_BV(JOYDOWN));
00091             
00092             // scale should be 2x here, but for this particular chip, 66 counts work better where
00093             // 64 counds should be. so 66/64=100/96 and times two
00094             a = ocr_zero + potmouse_ycounter*200/96;
00095             b = ocr_zero + potmouse_xcounter*200/96;
00096             
00097             ocr1a_load = a;
00098             ocr1b_load = b;
00099             break;
00100         case POTMOUSE_JOYSTICK:
00101             JOYDDR  &= ~(_BV(JOYFIRE) | _BV(JOYUP) | _BV(JOYDOWN) | _BV(JOYLEFT) | _BV(JOYRIGHT));
00102 
00103             (dx < 0) ? (JOYDDR |= _BV(JOYLEFT)) : (JOYDDR &= ~_BV(JOYLEFT));
00104             (dx > 0) ? (JOYDDR |= _BV(JOYRIGHT)): (JOYDDR &= ~_BV(JOYRIGHT));
00105             (dy < 0) ? (JOYDDR |= _BV(JOYDOWN)) : (JOYDDR &= ~_BV(JOYDOWN));
00106             (dy > 0) ? (JOYDDR |= _BV(JOYUP))   : (JOYDDR &= ~_BV(JOYUP));
00107             (button & 001) ? (JOYDDR |= _BV(JOYFIRE)) : (JOYDDR &= ~_BV(JOYFIRE));
00108             (button & 002) ? (POTDDR |= _BV(POTX)) : (POTDDR &= ~_BV(POTX));
00109   
00110             TCNT1 = 65535-256;
00111             TCCR1A = 0;
00112             TCCR1B = _BV(CS12)|_BV(CS10);
00113             TIFR |= _BV(TOV1);
00114             TIMSK |= _BV(TOIE1);
00115             break;
00116     }
00117 }

void potmouse_start ( uint8_t  mode  ) 

Set mode and start working.

Parameters:
mode see _potmode
00054                                {
00055     mode = m;
00056     switch (mode) {
00057         case POTMOUSE_C1351:
00058             // Initialize Timer1 and use OC1A/OC1B to output values
00059             // don't count yet    
00060             TCCR1B = 0; 
00061             
00062             // POTX/Y normally controlled by output compare unit
00063             // initially should be pulled up to provide high bias on SENSE pin
00064             POTDDR  |= _BV(POTX) | _BV(POTY);   // enable POTX/POTY as outputs
00065             POTPORT |= _BV(POTX) | _BV(POTY);   // output "1" on both
00066             
00067             GIFR |= _BV(INTF1);                     // clear INT1 flag
00068             GICR |= _BV(INT1);                      // enable INT1
00069             break;
00070         case POTMOUSE_JOYSTICK:
00071             // Joystick emulation
00072             // close directional pins for ~20ms while there is movement
00073             TCCR1B = 0;
00074             TCCR1A = 0;
00075             
00076             break;
00077     }
00078 }

void potmouse_zero ( uint16_t  zero  ) 

Define zero-point in time (normally 320us).

00119                                   {
00120     ocr_zero = zero;
00121 }


Generated on Fri Nov 13 04:21:20 2009 for [M]ouse by  doxygen 1.5.9