cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4

Sophie_Wang
New Contributor II

Hi I am reading keyboard.c of CY5672 Demo code, and feel a little confuse. could anyone explain the code below?

   

since,

   

index = i+j*8*ROWS;

   

NO_COLUMN_PORTS=1,

   

ROWS=3,

   

why in Keyboard_Add_Queue(index);,static KeyElement keyQueue[KEY_QUEUE_LEN]; keyQueue is defined with length of 18? what is the purpose of the definition of index?

   

static void Keyboard_Detect_Keys(void)
{
    uint8 i, j, index, col, p_col;
    /*By checking row by column key status detect which key is pressed or released*/
    for(i=0;i<ROWS;i++)
    {
        /*Check for any Ghost key detected*/
        if(!Keyboard_Detect_Ghost(i))
        {
            for(j=0;j<NO_COLUMN_PORTS;j++)
            {
                index = i+j*8*ROWS;

   

#if (NO_COLUMN_PORTS > 1)
                col = (curColumnStatus ^ prevColumnStatus);
                p_col = (col & prevColumnStatus);
                col = (col & curColumnStatus);
#else
                col = (curColumnStatus ^ prevColumnStatus);
                p_col = (col & prevColumnStatus);
                col = (col & curColumnStatus);                
#endif /* (NO_COLUMN_PORTS > 1) */
                while((col != 0) || (p_col != 0))
                {
                    /*If column value is 1 then update Keyboard queue with index*/
                    if(col & BIT_0_MASK)
                    {
                        Keyboard_Add_Queue(index);
                    }
                    /*If previous column value is 1 then update un-pressed status for status change 
                    in column*/
                    if(p_col & BIT_0_MASK)
                    {
                        Keyboard_Update_Release_Key_State(index);
                    }
                    index+=ROWS;
                    col = col>>BIT_1_POSITION;
                    p_col = p_col>>BIT_1_POSITION;
                }
#if (NO_COLUMN_PORTS > 1)
                prevColumnStatus = curColumnStatus;
#else 
                prevColumnStatus = curColumnStatus;
#endif /* (NO_COLUMN_PORTS > 1) */
            }
        }
    }
}

0 Likes
1 Solution
ShengY_96
Employee

what is the purpose of the definition of index?

   

A:index represent the key:SW1-SW10, like index-0 represent SW1.  

   

   API:  Keyboard_Add_Queue(index); shall use the the index to update Key's status(if key.index have already in queue) or add key to Queue(if key.index is not in the queue.). 

View solution in original post

0 Likes
1 Reply
ShengY_96
Employee

what is the purpose of the definition of index?

   

A:index represent the key:SW1-SW10, like index-0 represent SW1.  

   

   API:  Keyboard_Add_Queue(index); shall use the the index to update Key's status(if key.index have already in queue) or add key to Queue(if key.index is not in the queue.). 

View solution in original post

0 Likes