gonzui


Format: Advanced Search

tkernel_2/driver/tef_em1d/kbpd/src/kbpd.hbare sourcepermlink (0.05 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: 
   15: /*
   16:  *      kbpd.h
   17:  *
   18:  *       KB/PD device manager
   19:  *       common definitions
   20:  */
   21: 
   22: #include <tk/tkernel.h>
   23: #include <device/lowkbpd.h>
   24: #include <device/kbpd.h>
   25: #include <device/keycode.h>
   26: #include <device/devconf.h>
   27: #include <device/sdrvif.h>
   28: #include <sys/util.h>
   29: #include <tk/util.h>
   30: #include <sys/queue.h>
   31: #include <libstr.h>
   32: #include <sys/debug.h>
   33: 
   34: #define InvalidID       (0)           /* invalid ID */
   35: #define InvalidHNO      (0)          /* invalid handler number */
   36: #define InvalidDevID    (-1)               /* invalid device ID */
   37: #define InvalidKeytop   (-1)              /* invalid keytop number */
   38: #define InvalidKeycode  (0)              /* invalid key code */
   39: 
   40: #define DefaultPriority 30              /* default task priority */
   41: #define DefaultStkSize  3072             /* default stack size */
   42: 
   43: #define MAX_KID         0x7f           /* maximum number of keyboard ID */
   44: 
   45: /*
   46:  * maximum number of flags that can be registered for sending commands
   47:  */
   48: #define MaxCmd          4
   49: 
   50: /*
   51:  * key top information
   52:  */
   53: typedef union {
   54:         UW     w;
   55:         struct {
   56:                 UW    rsv:8;             /* reserved */
   57:                 UW    tenkey:1;  /* 1 in the case of ten key pad */
   58:                 UW    kid:7;             /* keyboard ID */
   59:                 UW    kcode:16;  /* key top code */
   60:         } u;
   61: } KeyTop;
   62: 
   63: /*
   64:  * types of direct key input
   65:  *      In principle, two or more keys can not be pushed simultaneously,
   66:  *      but for PD simulation, main CC (blue arrow) keys have to be pushed
   67:  *      with other keys simultaneously, hence they are treated as differently.
   68:  *        * CC key: Caret Control key (i.e. Character Cursor Control key)
   69:  */
   70: typedef enum {
   71:         NormalKey      =  0,        /* ordinary direct key input */
   72:         IK_CC_U                = -1, /* main CC UP */
   73:         IK_CC_D                = -2, /* main CC DOWN */
   74:         IK_CC_R                = -3, /* main CC RIGHT */
   75:         IK_CC_L                = -4  /* main CC LEFT */
   76: } InKeyKind;
   77: 
   78: /*
   79:  * type of shift key
   80:  */
   81: typedef enum {
   82:         NoShift                = 0x00,       /* other than shift key */
   83:         SK_SHIFT_L     = 0x01,     /* shift LEFT key */
   84:         SK_SHIFT_R     = 0x02,     /* shift RIGHT key */
   85:         SK_EXPANSION   = 0x04,   /* expansion key */
   86:         SK_COMMAND     = 0x08,     /* command key */
   87:         SK_ALL         = 0x0f /* all shift key */
   88: } ShiftKeyKind;
   89: 
   90: /*
   91:  * types of PD buttons
   92:  */
   93: typedef enum {
   94:         BK_MAIN                = 0x01,       /* main button */
   95:         BK_SUB         = 0x02,        /* subbutton */
   96:         BK_ALL         = BK_MAIN | BK_SUB
   97: } ButtonKind;
   98: 
   99: #define NumOfPdBut      (2)  /* number of PD buttons */
  100: 
  101: #define PdButKind(i)    ((ButtonKind)(BK_MAIN << (i)))
  102: 
  103: /*
  104:  * (note)
  105:  *       Some compilers treat enum as signed numbers,
  106:  *       if only the necessary bit width is used for a bit field, it may be sign extended inadvertedly,
  107:  * and you may get unexpected values. So some values are defined as UW.
  108:  */
  109: 
  110: /*
  111:  * KB/PD status
  112:  * The definitions in the specifications are modified to fit the internal processing needs.
  113:  */
  114: typedef union {
  115:         MetaBut                o;    /* Definitions in the specification */
  116: 
  117:         struct _MetaBut {
  118: #if BIGENDIAN
  119:                 UW            rsv1:8;           /* reserved (0) */
  120:                 UW            pdsim:2;  /* PD simulation */
  121:                 UW            nodsp:1;  /* Hide pointer */
  122:                 UW            rsv2:3;           /* reserved (0) */
  123:                 UW            kbsel:1;  /* keyboard selection */
  124:                 UW            han:1;            /* Hankaku mode */
  125: 
  126:         /*ShiftKeyKind*/ UW    tmpShift:4;        /* temporary shift */
  127:         /*ShiftKeyKind*/ UW    shiftLock:4;       /* simple lock */
  128:         /*ShiftKeyKind*/ UW    shift:4;   /* shift status */
  129: 
  130:         /*InputMode*/    UW    mode:2;            /* key input mode */
  131: 
  132:         /*ButtonKind*/   UW    button:2;  /* PD button status */
  133: #else
  134:         /*ButtonKind*/   UW    button:2;  /* PD button status */
  135: 
  136:         /*InputMode*/    UW    mode:2;            /* key input mode */
  137: 
  138:         /*ShiftKeyKind*/ UW    shift:4;   /* shift status */
  139:         /*ShiftKeyKind*/ UW    shiftLock:4;       /* simple lock */
  140:         /*ShiftKeyKind*/ UW    tmpShift:4;        /* temporary shift */
  141: 
  142:                 UW            han:1;            /* Hankaku mode */
  143:                 UW            kbsel:1;  /* keyboard selection */
  144:                 UW            rsv2:3;           /* reserved (0) */
  145:                 UW            nodsp:1;  /* Hide pointer */
  146:                 UW            pdsim:2;  /* PD simulation */
  147:                 UW            rsv1:8;           /* reserved (0) */
  148: #endif
  149:         } u;
  150: } KpMetaBut;
  151: 
  152: /*
  153:  * PD input data
  154:  * The definitions in the specifications are modified to fit the internal processing needs.
  155:  */
  156: typedef union {
  157:         PdInStat       o;    /* Definitions in the specification */
  158: 
  159:         struct _PdInStat {
  160:                 UW            read:1;           /* already read flag */
  161:                 InputCmd      cmd:7;               /* = INP_PD */
  162:                 UW            rsv1:4;           /* reserved (0) */
  163:                 DevError      err:4;               /* device error */
  164: 
  165:                 UW            nodsp:1;  /* hide pointer */
  166:                 UW            rsv2:1;           /* reserved (0) */
  167:                 UW            onebut:1; /* one button operation */
  168:                 UW            abs:1;            /* coordinate is absolute or relative. */
  169:                 UW            norel:1;  /* relative operation not supported */
  170:                 UW            tmout:1;  /* PD timeout is in effect */
  171:                 UW            butrev:1; /* enable button left-right swap */
  172:                 UW            xyrev:1;  /* enable XY coordinate reversal */
  173: 
  174: #if BIGENDIAN
  175:                 UW            rsv3:3;           /* reserved (0) */
  176:                 UW            qpress:1; /* quick-press modifier */
  177:                 UW            inv:1;            /* out of valid area (coordinates are invalid) */
  178:                 UW            vst:1;            /* enter the valid area from outside */
  179:         /*ButtonKind*/ UW      button:2;    /* PD button status */
  180: #else
  181:         /*ButtonKind*/ UW      button:2;    /* PD button status */
  182:                 UW            vst:1;            /* enter the valid area from outside */
  183:                 UW            inv:1;            /* out of valid area (coordinates are invalid) */
  184:                 UW            qpress:1; /* quick-press modifier */
  185:                 UW            rsv3:3;           /* reserved (0) */
  186: #endif
  187:         } u;
  188: } KpPdInStat;
  189: 
  190: /* ------------------------------------------------------------------------ */
  191: 
  192: #include "devevt.h"
  193: #include "innevt.h"
  194: #include "statmach.h"
  195: 
  196: /* ------------------------------------------------------------------------ */
  197: 
  198: /*
  199:  * keyboard definition data
  200:  */
  201: typedef struct {
  202:         W      size;                /* keyDef size (in bytes) */
  203:         KeyDef keyDef;         /* keyboard definition (variable length) */
  204: } KbDef;
  205: 
  206: /*
  207:  * keyboard attribute data
  208:  */
  209: typedef struct {
  210:         KbDef  *kbDef[2][MAX_KID+1];    /* keyboard definition (NULL = undefined) */
  211:         UW     keyID;                      /* default keyboard ID */
  212:         UW     defKeyID:2;         /* keyID setting
  213:                                           (0:unspecified 1:automatic 2:fixed) */
  214:         KeyMap keyMap;                 /* keymap */
  215:         KeyMode        keyMode;               /* key mode */
  216: } kbInfo;
  217: 
  218: #define GetKbDef(i, kid)                ( kpMgrInfo.kb.kbDef[i][kid] )
  219: #define SetKbDef(i, kid, kbdef)         ( kpMgrInfo.kb.kbDef[i][kid] = kbdef )
  220: 
  221: /*
  222:  * PD attribute data
  223:  */
  224: typedef struct {
  225:         PdMode pdMode;         /* PD mode */
  226:         PdRange        pdRange;       /* PD range */
  227:         W      pdSimSpeed;  /* PD simulation speed                */
  228:         BOOL   pdSimInh; /* halt PD simulation temporarily */
  229: } pdInfo;
  230: 
  231: /*
  232:  * PD location update period during PD simulation     unit in milliseconds
  233:  */
  234: #define simStartTime()          (50)            /* start time */
  235: #define simIntervalTime()       (50)          /* repeat time */
  236: 
  237: /*
  238:  * PD simulation status
  239:  */
  240: typedef struct {
  241:         /* direction / speed */
  242:         H      x;    /* left -1, stop 0, right +1 */
  243:         H      y;    /* up -1, stop 0, down +1 */
  244:         W      rep;  /* repeat count */
  245: } PdSimState;
  246: 
  247: /*
  248:  * manager information
  249:  */
  250: typedef struct {
  251:         FastLock       lock;         /* for exclusive control of manager information */
  252: 
  253:         /* interface between common part among devices */
  254:         ID     acceptPort;         /* port to accept device request */
  255:         ID     eventMbf;           /* message buffer for event notification */
  256:         SDI    Sdi;                       /* device driver I/F handler */
  257:         BOOL   suspended;                /* TRUE during suspended state */
  258: 
  259:         /* interface information for I/O driver */
  260:         ID     dataMbx;            /* mailbox for receiving data */
  261:         ID     cmdFlg[MaxCmd];             /* event flag for sending command */
  262: 
  263:         /* receiving task for data from I/O driver */
  264:         ID     dataReceiveTask;    /* data receiving task */
  265: 
  266:         /* attribute data */
  267:         KPStat kpState;                /* KB/PD status                          */
  268:         kbInfo kb;                     /* keyboard attribute data */
  269:         pdInfo pd;                     /* PD attribute data */
  270: 
  271:         /* state of the state machine */
  272:         StateMachine   statMach;
  273: 
  274:         /* other state information */
  275:         ShiftKeyKind   spress;           /* shift key press status */
  276: #if     0   /* we no longer support relative movement with absolute coordinate device. */
  277:         H              firstXpos;  /* absolute coordinate device */
  278:         H              firstYpos;  /* origin for relative mode */
  279: #endif
  280:         PdSimState     pdSimState; /* direction of PD simulation movement */
  281: } MgrInfo;
  282: IMPORT MgrInfo kpMgrInfo;
  283: 
  284: /* ------------------------------------------------------------------------ */
  285: 
  286: /*
  287:  * key code discovery
  288:  */
  289: #define isMetaKey(c)    ( ((c) & 0xffe0) == 0x1000 || (c) == KC_HAN )
  290: #define isShiftKey(c)   ( (c) >= KC_SHT_R && (c) <= KC_CMD )
  291: #define isLockKey(c)    ( isMetaKey(c) && !isShiftKey(c) )
  292: #define isMainCC(c)     ( (c) >= KC_CC_U && (c) <= KC_CC_L )
  293: #define isSubCC(c)      ( (c) >= KC_SC_U && (c) <= KC_SC_L )
  294: #define isCCKey(c)      ( (c) >= KC_CC_U && (c) <= KC_SC_L )
  295: 
  296: /*
  297:  * miscellaneous
  298:  */
  299: #define max(a,b)        (( (a) > (b) )? (a): (b))
  300: #define min(a,b)        (( (a) < (b) )? (a): (b))
  301: #define SWAP(type,x,y)  { type z = (x); (x) = (y); (y) = z; }
  302: 
  303: /* ----------------------------------------------------------------------- */
  304: 
  305: /*
  306:  *       meta key, PD button status
  307:  *       0: off 1: on
  308:  */
  309: #define ES_BUT          0x00000001      /* PD main button */
  310: #define ES_BUT2         0x00000002     /* PD subbutton */
  311: #define ES_ALPH         0x00000004     /* English lock key */
  312: #define ES_KANA         0x00000008     /* katakana lock key */
  313: #define ES_LSHFT        0x00000010     /* shift LEFT key */
  314: #define ES_RSHFT        0x00000020     /* shift RIGHT key */
  315: #define ES_EXT          0x00000040      /* expansion key */
  316: #define ES_CMD          0x00000080      /* command key */
  317: #define ES_LLSHFT       0x00000100    /* shift left simple lock */
  318: #define ES_LRSHFT       0x00000200    /* shift right simple lock */
  319: #define ES_LEXT         0x00000400     /* expansion simple lock */
  320: #define ES_LCMD         0x00000800     /* command simple lock */
  321: #define ES_TLSHFT       0x00001000    /* shift left temporary shift */
  322: #define ES_TRSHFT       0x00002000    /* shift right temporary shift */
  323: #define ES_TEXT         0x00004000     /* expansion temporary shift */
  324: #define ES_TCMD         0x00008000     /* command temporary shift */
  325: #define ES_HAN          0x00010000      /* hankaku key */
  326: #define ES_KBSEL        0x00020000     /* keyboard selection */
  327: 
  328: /*
  329:  *      meta key, PD button status masks
  330:  */
  331: #define ES_BASICBTN     0x00000003U /* PD basic button              */
  332: #define ES_META         0x001FFFFCU    /* metakey                 */
  333: #define ES_NODSP        0x00200000U    /* PD type                 */
  334: #define ES_PDSIM        0x00C00000U    /* PD state                        */
  335: #define ES_EXTBTN       0xFF000000U   /* PD extended button             */
  336: 
  337: /*
  338:  * input mode
  339:  *               Combination of English lock key and katakana lock key
  340:  *               selects input mode as follows.
  341:  */
  342: #define IM_HIRA         0x0000                 /* Japanese Hiragana */
  343: #define IM_ALPH         (ES_ALPH)              /* English (lower case) */
  344: #define IM_KATA         (ES_KANA)              /* Japanese katakana */
  345: #define IM_CAPS         (ES_ALPH | ES_KANA)    /* English (upper case) */
  346: #define IM_MASK         (ES_ALPH | ES_KANA)
  347: 
  348: #define KIN_KANA        0x0000                 /* Kana input mode */
  349: #define KIN_ROMAN       0x0001                        /* roman input mode */
  350: 
  351: /*
  352:  *      PD attribute
  353:  */
  354: #define PD_WHEEL        0x4000         /* Wheel (0: disabled)         */
  355: #define PD_QPRESS       0x2000                /* Quick press (0: disabled)  */
  356: #define PD_REV          0x1000          /* Flip horizontally            */
  357: #define PD_ACMSK        0x0e00         /* Acceleration (mask)         */
  358: #define PD_ABS          0x0100          /* Absolute coordinate type     */
  359: #define PD_REL          0x0000          /* Relative coordinate type     */
  360: #define PD_SCMSK        0x00f0         /* Scanning speed (mask)       */
  361: #define PD_SNMSK        0x000f         /* Sensitivity (mask)          */
  362: 
  363: /* ----------------------------------------------------------------------- */
  364: 
  365: #define IMPORT_DEFINE   1
  366: #if IMPORT_DEFINE
  367: /* accept.c */
  368: IMPORT INT kpReadFn( ID devid, INT datano, INT datacnt, void *buf, SDI sdi );
  369: IMPORT INT kpWriteFn( ID devid, INT datano, INT datacnt, void *buf, SDI sdi );
  370: IMPORT INT kpEventFn( INT evttyp, void *evtinf, SDI sdi );
  371: /* devcmd.c */
  372: IMPORT ER kpSendDeviceCommand( UW cmd );
  373: IMPORT ER kpChangeKbInputMode( InputMode mode );
  374: IMPORT ER kpChangePdScanRate( W rate );
  375: IMPORT ER kpChangePdSense( W sense );
  376: IMPORT ER kpSendInitialDeviceCommand( ID flgid );
  377: IMPORT ER kpSetAllDeviceStatus( void );
  378: /* etc.c */
  379: IMPORT ER kpNotifyEvent( void *evt, W size );
  380: IMPORT ER kpNotifyMetaEvent( void );
  381: IMPORT ER kpNotifyPdEvent( TDEvtTyp devEvt, UW nodsp );
  382: IMPORT UH kpToKeycode( KeyTop keytop, KpMetaBut *meta );
  383: IMPORT W kpGetKeyKind( KeyTop keytop );
  384: IMPORT BOOL kpChangeShiftLock( InnEvtType type, ShiftKeyKind skind );
  385: IMPORT W kpKeyTopCode( KeyTop keytop, UW kbsel );
  386: IMPORT void kpSetOrResetKeyMap( KeyTop keytop, UW kbsel, UW press );
  387: IMPORT void kpAllResetKeyMap( void );
  388: IMPORT void kpPdPreProcess( PdInput *msg );
  389: IMPORT BOOL kpMovePointer( W xpos, W ypos );
  390: IMPORT ER kpMovePointerAndNotify( H xpos, H ypos );
  391: IMPORT TDEvtTyp kpPdMoveEvent( InnerEvent *evt );
  392: IMPORT TDEvtTyp kpPdButEvent( InnerEvent *evt );
  393: /* key.c */
  394: IMPORT void kpExecKeyStateMachine( KeyState *ks, InnerEvent *evt, ReceiveData *msg );
  395: /* innevt.c */
  396: IMPORT void kpInnerEventProcess( InnerEvent *evt, TMO *tmout );
  397: /* main.C */
  398: IMPORT MgrInfo kpMgrInfo;
  399: IMPORT ER KbPdDrv ( INT ac, UB *av[] );
  400: IMPORT ER main( INT ac, UB *av[] );
  401: /* pdbut.c */
  402: IMPORT void kpExecPdButStateMachine( InnerEvent *evt, ReceiveData *msg, ButtonKind button );
  403: /* pdsim.c */
  404: IMPORT BOOL kpExecPdSimKeyDown( InnerEvent *evt, UH code, TMO *tmout );
  405: IMPORT BOOL kpExecPdSimKeyUp( InnerEvent *evt, UH code, TMO *tmout );
  406: IMPORT void kpExecPdSimRepeat( TMO *tmout );
  407: /* receive.c */
  408: IMPORT void kpDataReceiveTask( void );
  409: IMPORT ER kpStartDataReceiveTask( PRI pri );
  410: IMPORT void kpStopDataReceiveTask( void );
  411: /* statmach.c */
  412: IMPORT ER kpSendPseudoMsg( T_MSG *msg );
  413: IMPORT ER kpSetAlarm( AlarmState *alm, MSEC offsetTime );
  414: IMPORT BOOL kpChkAlarm( AlarmState *alm, TimeoutMsg *msg );
  415: IMPORT ER kpInitializeStateMachine( void );
  416: IMPORT void kpFinishStateMachine( void );
  417: IMPORT void kpReleaseKey( KeyState *ks );
  418: IMPORT BOOL kpExecStateMachine( InnerEvent *evt, ReceiveData *msg );
  419: IMPORT ER kpKeyAndButtonForceUp( void );
  420: #endif  //IMPORT_DEFINE