Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDPutData.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /*
        !            23:        File:           HIDPutData.c
        !            24: 
        !            25:        Contains:       xxx put contents here xxx
        !            26: 
        !            27:        Version:        xxx put version here xxx
        !            28: 
        !            29:        Copyright:      � 1999 by Apple Computer, Inc., all rights reserved.
        !            30: 
        !            31:        File Ownership:
        !            32: 
        !            33:                DRI:                            xxx put dri here xxx
        !            34: 
        !            35:                Other Contact:          xxx put other contact here xxx
        !            36: 
        !            37:                Technology:                     xxx put technology here xxx
        !            38: 
        !            39:        Writers:
        !            40: 
        !            41:                (BWS)   Brent Schorsch
        !            42: 
        !            43:        Change History (most recent first):
        !            44: 
        !            45:          <USB1>          3/5/99        BWS             first checked in
        !            46: */
        !            47: 
        !            48: #include "HIDLib.h"
        !            49: 
        !            50: //#include <stdio.h>
        !            51: 
        !            52: /*
        !            53:  *------------------------------------------------------------------------------
        !            54:  *
        !            55:  * HIDPutData - Put a single data item to a report
        !            56:  *
        !            57:  *      Input:
        !            58:  *                       psReport                              - The report
        !            59:  *                       iReportLength                 - The length of the report
        !            60:  *                       iStart                                - Start Bit in report
        !            61:  *                       iSize                                 - Number of Bits
        !            62:  *                       iValue                                - The data
        !            63:  *      Output:
        !            64:  *      Returns:
        !            65:  *                       kHidP_Success                 - Success
        !            66:  *                       kHidP_NullPointer             - Argument, Pointer was Null
        !            67:  *
        !            68:  *------------------------------------------------------------------------------
        !            69: */
        !            70: OSStatus
        !            71: HIDPutData                                (void *                                      report,
        !            72:                                                        ByteCount                               reportLength,
        !            73:                                                        UInt32                                  start,
        !            74:                                                        UInt32                                  size,
        !            75:                                                        SInt32                                  value)
        !            76: {
        !            77:        Byte * psReport = report;
        !            78:        SInt32 data, iShiftedData;
        !            79:        UInt32 iStartByte, startBit;
        !            80:        UInt32 iLastByte, iLastBit;
        !            81:        UInt32 iStartMask, iLastMask;
        !            82:        UInt32 iDataMask;
        !            83: /*
        !            84:  *       Report
        !            85:  *       Bit 28 27 26 25 24 | 23 22 21 20 19 18 17 16 | 15 14 13 12 11 10 09 ...
        !            86:  *       Last Byte (3) |        |                Byte 2                   |     |      Start Byte (1)
        !            87:  *       Data x  x      x      d  d |  d  d  d  d      d  d  d  d |  d  d      y  y  y  y      y
        !            88:  *       Last Bit (1) /         |                                                 |      \ Start Bit (6)
        !            89:  *       ...  1  1      1      0  0 |     Intermediate            |  0  0      1  1  1  1      1 ...
        !            90:  *       Last Mask                      |               Byte(s)                   |            StartMask
        !            91: */
        !            92:        iLastByte = (start + size - 1)/8;
        !            93: /*
        !            94:  *     Check the parameters
        !            95: */
        !            96:        if ((start < 0) || (size <= 0) || (iLastByte >= reportLength))
        !            97:                return kHIDBadParameterErr;
        !            98:        iLastBit = (start + size - 1)&7;
        !            99:        iLastMask = ~((1<<(iLastBit+1)) - 1);
        !           100:        iStartByte = start/8;
        !           101:        startBit = start&7;
        !           102:        iStartMask = (1<<startBit) - 1;
        !           103: /*
        !           104:  *     If the data is contained in one byte then
        !           105:  *       handle it differently
        !           106:  *       Mask off just the area where the new data goes
        !           107:  *       Shift the data over to its new location
        !           108:  *       Mask the data for its new location
        !           109:  *       Or in the data
        !           110: */
        !           111:        if (iStartByte == iLastByte)
        !           112:        {
        !           113:                data = psReport[iStartByte];
        !           114:                iDataMask = iStartMask | iLastMask;
        !           115:                data &= iDataMask;
        !           116:                iShiftedData = value << startBit;
        !           117:                iShiftedData &= ~iDataMask;
        !           118:                data |= iShiftedData;
        !           119:        }
        !           120: /*
        !           121:  *     If the data is in more than one byte then
        !           122:  *     Do the start byte first
        !           123:  *     Mask off the bits where the new data goes
        !           124:  *     Shift the new data over to the start of field
        !           125:  *     Or the two together and store back out
        !           126: */
        !           127:        else
        !           128:        {
        !           129:                data = psReport[iStartByte];
        !           130:                data &= iStartMask;
        !           131:                iShiftedData = value << startBit;
        !           132:                data |= iShiftedData;
        !           133:                psReport[iStartByte] = (Byte) data;
        !           134:                value >>= 8;
        !           135: /*
        !           136:  *             Store out an intermediate bytes
        !           137: */
        !           138:                while (++iStartByte < iLastByte)
        !           139:                {
        !           140:                        psReport[iStartByte] = (Byte) value;
        !           141:                        value >>= 8;
        !           142:                }
        !           143: /*
        !           144:  *             Mask off the bits where the new data goes
        !           145:  *             Mask off the bits in the new data where the old goes
        !           146:  *             Or the two together and store back out
        !           147: */
        !           148:                data = psReport[iLastByte];
        !           149:                data &= iLastMask;
        !           150:                value &= ~iLastMask;
        !           151:                data |= value;
        !           152:        }
        !           153: /*
        !           154:  *     Store out the last or only Byte
        !           155: */
        !           156:        psReport[iStartByte] = (Byte) data;
        !           157:        return kHIDSuccess;
        !           158: }
        !           159: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.