1 Reply Latest reply on Jul 27, 2017 2:40 AM by yans

    some questions about CY5672 Demo code

    user_385933205

      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[i][j] ^ prevColumnStatus[i][j]);
                      p_col = (col & prevColumnStatus[i][j]);
                      col = (col & curColumnStatus[i][j]);
      #else
                      col = (curColumnStatus[i] ^ prevColumnStatus[i]);
                      p_col = (col & prevColumnStatus[i]);
                      col = (col & curColumnStatus[i]);                
      #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[i][j] = curColumnStatus[i][j];
      #else 
                      prevColumnStatus[i] = curColumnStatus[i];
      #endif /* (NO_COLUMN_PORTS > 1) */
                  }
              }
          }
      }

        • 1. Re: some questions about CY5672 Demo code
          yans

          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.).