gonzui


Format: Advanced Search

tkernel_2/driver/tef_em1d/kbpd/src/devcmd.cbare sourcepermlink (0.04 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:  *      devcmd.c
   17:  *
   18:  *       KB/PD device manager
   19:  *       I/O driver command transmission
   20:  */
   21: 
   22: #include "kbpd.h"
   23: 
   24: /*
   25:  * send command to a specified eventflag
   26:  */
   27: LOCAL ER sendDeviceCommandTo( ID flgid, UW cmd )
   28: {
   29:         UINT   rdy;
   30:         ER     ercd;
   31: 
   32:         /* wait until transmission ready */
   33:         ercd = tk_wai_flg(flgid, DeviceCommandReady, TWF_ORW|TWF_CLR,
   34:                           &rdy, TMO_FEVR);
   35:         if ( ercd != E_OK ) {
   36:                 DEBUG_PRINT(("sendDeviceCommandTo, wait err = %d\n", ercd));
   37:                 return ercd;
   38:         }
   39: 
   40:         /* send */
   41:         ercd = tk_set_flg(flgid, cmd);
   42:         if ( ercd != E_OK ) {
   43:                 DEBUG_PRINT(("sendDeviceCommandTo, send err = %d\n", ercd));
   44:                 return ercd;
   45:         }
   46: 
   47:         return E_OK;
   48: }
   49: 
   50: /*
   51:  * send device command
   52:  */
   53: EXPORT ER kpSendDeviceCommand( UW cmd )
   54: {
   55:         ID     id;
   56:         ER     err = E_OK;
   57:         ER     er;
   58:         int    i;
   59: 
   60:         for ( i = 0; i < MaxCmd; ++i ) {
   61:                 id = kpMgrInfo.cmdFlg[i];
   62:                 if ( id == InvalidID ) continue;
   63: 
   64:                 /* send command */
   65:                 er = sendDeviceCommandTo(id, cmd);
   66:                 if ( er != E_OK ) err = er;
   67:         }
   68: 
   69:         return err;
   70: }
   71: 
   72: /*
   73:  * change keyboard input mode
   74:  */
   75: EXPORT ER kpChangeKbInputMode( InputMode mode )
   76: {
   77:         ER     err;
   78: 
   79:         err = kpSendDeviceCommand(InputModeCmd(mode));
   80:         if ( err != E_OK ) {
   81:                 DEBUG_PRINT(("kpChangeKbInputMode, err = %d\n", err));
   82:         }
   83:         return err;
   84: }
   85: 
   86: /*
   87:  * change PD scan frequency
   88:  */
   89: EXPORT ER kpChangePdScanRate( W rate )
   90: {
   91:         ER     err;
   92: 
   93:         err = kpSendDeviceCommand(ScanRateCmd(rate));
   94:         if ( err != E_OK ) {
   95:                 DEBUG_PRINT(("kpChangePdScanRate, err = %d\n", err));
   96:         }
   97:         return err;
   98: }
   99: 
  100: /*
  101:  * change sensitivity
  102:  */
  103: EXPORT ER kpChangePdSense( W sense )
  104: {
  105:         ER     err;
  106: 
  107:         err = kpSendDeviceCommand(SenseCmd(sense));
  108:         if ( err != E_OK ) {
  109:                 DEBUG_PRINT(("kpChangePdSense, err = %d\n", err));
  110:         }
  111:         return err;
  112: }
  113: 
  114: /*
  115:  * send a command to set the current status
  116:  * to a specific device (eventflag)
  117:  */
  118: EXPORT ER kpSendInitialDeviceCommand( ID flgid )
  119: {
  120:         UW     cmd;
  121:         ER     err;
  122:         union {
  123:                 PdAttr        attr;
  124:                 UW    uw;
  125:         } u;
  126: 
  127:         /* set keyboard input mode */
  128:         cmd = InputModeCmd(kpMgrInfo.kpState.stat.mode);
  129:         err = sendDeviceCommandTo(flgid, cmd);
  130:         if ( err != E_OK ) {
  131:                 DEBUG_PRINT(("kpSendInitialDeviceCommand, err = %d\n", err));
  132:                 return err;
  133:         }
  134: 
  135:         /* set PD scan frequency */
  136:         cmd = ScanRateCmd(kpMgrInfo.pd.pdMode.attr.rate);
  137:         err = sendDeviceCommandTo(flgid, cmd);
  138:         if ( err != E_OK ) {
  139:                 DEBUG_PRINT(("kpSendInitialDeviceCommand, err = %d\n", err));
  140:                 return err;
  141:         }
  142: 
  143:         /* set PD sensitivity */
  144:         u.attr = kpMgrInfo.pd.pdMode.attr;
  145:         cmd = SenseCmd(u.uw & (PD_ACMSK|PD_ABS|PD_SNMSK));
  146:         err = sendDeviceCommandTo(flgid, cmd);
  147:         if ( err != E_OK ) {
  148:                 DEBUG_PRINT(("kpSendInitialDeviceCommand, err = %d\n", err));
  149:                 return err;
  150:         }
  151: 
  152:         return E_OK;
  153: }
  154: 
  155: /*
  156:  * send a command to set the current status
  157:  * to all the devices (eventflags)
  158:  */
  159: EXPORT ER kpSetAllDeviceStatus( void )
  160: {
  161:         ID     id;
  162:         int    i;
  163:         ER     err, error = E_OK;
  164: 
  165:         for ( i = 0; i < MaxCmd; ++i ) {
  166:                 id = kpMgrInfo.cmdFlg[i];
  167:                 if ( id == InvalidID ) continue;
  168: 
  169:                 /* send command to set the current status */
  170:                 err = kpSendInitialDeviceCommand(id);
  171:                 if ( err < E_OK ) error = err;
  172:         }
  173: 
  174:         return error;
  175: }