⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kpd_process_internal_msg.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
      subscriber_infos[subscriber_id]->mode = new_mode;
      subscriber_infos[subscriber_id]->notified_keys.nb_notified_keys = notified_keys->nb_notified_keys;
      subscriber_infos[subscriber_id]->notified_keys.long_press_time = 0;
      subscriber_infos[subscriber_id]->notified_keys.repeat_time = 0;
      for (i = 0; i < notified_keys->nb_notified_keys; i++)
      {
         /* Retrieve physical key Id from virtual key_id */
         kpd_retrieve_virtual_key_position(  notified_keys->notified_keys[i],
                                             new_mode,
                                             &position);

         subscriber_infos[subscriber_id]->notified_keys.notif_level[position] = KPD_RELEASE_NOTIF;
 
         /* Update link (ID <-> key) for new mode */
         physical_key_mask[position].subscriber_mask |= (1<<subscriber_id);
      }

      /* If the subscriber is the keypad owner, this privilege is unset */
      if (kpd_is_owner_keypad(subscriber_id) == TRUE)
         kpd_set_keypad_mode(MN_MODE);

      /* Send success message to suscriber */
      kpd_send_status_message(KPD_CHANGE_MODE_OP, KPD_PROCESS_OK, subscriber_infos[subscriber_id]->return_path);
   }

   return RV_OK;
}

/**
 * function: kpd_own_keypad_i
 */
T_RV_RET kpd_own_keypad_i(T_SUBSCRIBER_ID subscriber_id,
                          BOOL is_keypad_owner,
                          T_KPD_VIRTUAL_KEY_TABLE* keys_owner)
{
   INT8 position;
   UINT8 i;

   if (is_keypad_owner == FALSE)
   {
      /* Check if subscriber Id own the keypad */
      if (kpd_is_owner_keypad(subscriber_id))
      {
         kpd_set_keypad_mode(MN_MODE);

         /* Send success message to suscriber */
         kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_PROCESS_OK, subscriber_infos[subscriber_id]->return_path);

      }
      else
         kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_ERR_ID_OWNER_KEYPAD, subscriber_infos[subscriber_id]->return_path);
   }
   else
   {
      /* Check if keypad driver is already in single-notified mode */
      if (kpd_get_keypad_mode() == SN_MODE)
      {
         /* Send error message to suscriber */
         kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_ERR_SN_MODE, subscriber_infos[subscriber_id]->return_path);
      }
      else
      {
         /* Check if all the keys defined in keys_owner are notified to the subsciber */
         for (i = 0; i < keys_owner->nb_notified_keys; i++)
         {
            /* Retrieve physical key Id from virtual key_id */
            kpd_retrieve_virtual_key_position(  keys_owner->notified_keys[i],
                                                subscriber_infos[subscriber_id]->mode,
                                                &position);

            if ( subscriber_infos[subscriber_id]->notified_keys.notif_level == KPD_NO_NOTIF )
            {
               /* Send error message to suscriber */
               kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_ERR_KEYS_TABLE, subscriber_infos[subscriber_id]->return_path);
               return RV_INTERNAL_ERR;
            }
         }

         /* Set keypad driver in single-notified mode */
         kpd_set_keypad_mode(SN_MODE);

         /* Set owner keypad Id */
         kpd_set_owner_keypad_id(subscriber_id);

         /* Set list of keys used by the keypad owner. Thsi list is is a sub-list
            of the keys defined at subscription. For these keys, the keypad owner will
            be the only notified. */
         kpd_set_keys_in_sn_mode(keys_owner, subscriber_infos[subscriber_id]->mode);

         /* Send success message to suscriber */
         kpd_send_status_message(KPD_OWN_KEYPAD_OP, KPD_PROCESS_OK, subscriber_infos[subscriber_id]->return_path);
      }
   }

   return RV_OK;
}

/**
 * function: kpd_set_key_config_i
 */
T_RV_RET kpd_set_key_config_i(T_SUBSCRIBER_ID subscriber_id,
                              T_KPD_VIRTUAL_KEY_TABLE* reference_keys,
                              T_KPD_VIRTUAL_KEY_TABLE* new_keys)
{
#ifdef KPD_MODE_CONFIG
   UINT8 i;

   /* Check if some subscriber use the configurable mode */
   for (i = 0; i < KPD_MAX_SUBSCRIBER; i++)
   {
      if ( (subscriber_infos[i] != 0) && (subscriber_infos[i]->mode == KPD_MODE_CONFIG) )
      {
         /* Send error message to suscriber */
         kpd_send_status_message(KPD_SET_CONFIG_MODE_OP,
                                 KPD_ERR_CONFIG_MODE_USED,
                                 subscriber_infos[subscriber_id]->return_path);
         return RV_OK;
      }
   }

   /* Set keys in configurable mode */
   kpd_define_new_config(reference_keys, new_keys);

   /* Send success message to suscriber */
   kpd_send_status_message(KPD_SET_CONFIG_MODE_OP,
                           KPD_PROCESS_OK,
                           subscriber_infos[subscriber_id]->return_path);

#endif

   return RV_OK;
}


/**
 * function: kpd_process_key_pressed_i
 */
void kpd_process_key_pressed_i(T_KPD_PHYSICAL_KEY_ID physical_key_pressed_id)
{
   UINT8 i;
   UINT32 loop_counter = 0;
   UINT16 counter[KPD_MAX_SUBSCRIBER] = {0};
   T_KPD_PHYSICAL_KEY_ID key_id = physical_key_pressed_id;

   KPD_SEND_TRACE_PARAM("KPD: kpd_process_key_pressed_i ", key_id, RV_TRACE_LEVEL_DEBUG_LOW);

   /* Notify subscribers of the key pressed */
   for (i = 0; i < KPD_MAX_SUBSCRIBER; i++) /* To do : Loop on the real number of subscribers */
   { /* To do : Test on the physical_key_mask (to ensure subscriber is subscribed for this key) */
      if ( (subscriber_infos[i]!=0) && (subscriber_infos[i]->notified_keys.notif_level[key_id] & KPD_FIRST_PRESS_NOTIF) )
      {
         kpd_send_key_event_message(key_id, KPD_KEY_PRESSED,
                                    KPD_FIRST_PRESS, subscriber_infos[i]->mode,
                                    subscriber_infos[i]->return_path);
      }
   }

   /* If key pressed is the PWR key, the message "Released key" is immediately sent */
   if (key_id != KPD_SHORT_PRESS_PWR_KEY)
   {
      /* Loop infinitely until key is released */
      do
      {
         rvf_delay(RVF_MS_TO_TICKS(WAIT_TIME_LOOP));
         physical_key_pressed_id = kpd_scan_keypad();
         loop_counter++;

         /* Send message for repeat key */
         for (i = 0; i < KPD_MAX_SUBSCRIBER; i++)
         {
            if ( (subscriber_infos[i]!=0) && (subscriber_infos[i]->notified_keys.notif_level[key_id] & (KPD_LONG_PRESS_NOTIF|KPD_INFINITE_REPEAT_NOTIF)) )
            {
               if ((counter[i] == 0) && (WAIT_TIME_LOOP*loop_counter >= subscriber_infos[i]->notified_keys.long_press_time) )
               {
                  kpd_send_key_event_message(key_id, KPD_KEY_PRESSED,
                                             KPD_LONG_PRESS, subscriber_infos[i]->mode,
                                             subscriber_infos[i]->return_path);
                  counter[i] ++;
               }
               else if (subscriber_infos[i]->notified_keys.notif_level[key_id] & KPD_INFINITE_REPEAT_NOTIF)
               {
                  if (WAIT_TIME_LOOP*loop_counter >= (UINT32)((counter[i]*subscriber_infos[i]->notified_keys.repeat_time + subscriber_infos[i]->notified_keys.long_press_time)) )
                  {
                     kpd_send_key_event_message(key_id, KPD_KEY_PRESSED,
                                                KPD_REPEAT_PRESS, subscriber_infos[i]->mode,
                                                subscriber_infos[i]->return_path);
                     counter[i] ++;
                  }
               }
            }
         }

      } while (physical_key_pressed_id != KPD_PKEY_NULL);
   }

   /* Notify subscribers of the key released */
   for (i = 0; i < KPD_MAX_SUBSCRIBER; i++)
   {
      if ( (subscriber_infos[i]!=0) && (subscriber_infos[i]->notified_keys.notif_level[key_id] & KPD_RELEASE_NOTIF) )
      {
         kpd_send_key_event_message(key_id, KPD_KEY_RELEASED,
                                    KPD_INSIGNIFICANT_VALUE, subscriber_infos[i]->mode,
                                    subscriber_infos[i]->return_path);
      }
   }

   /* On board,this function unmask keypad interrupt
      On Riviera tool, this function is empty        */
   if (key_id != KPD_SHORT_PRESS_PWR_KEY)
   {
#if (CHIPSET == 12)
      kpd_software_reset();
      kpd_init_ctrl_reg(1, HARDWARE_DECODING, KPD_CLK_DIV32,
                        KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED,
                        KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED);
#endif

      kpd_acknowledge_key_pressed();
   }
}


/**
 * function: kpd_process_key_pressed_sn_mode_i
 */
void kpd_process_key_pressed_sn_mode_i(T_KPD_PHYSICAL_KEY_ID physical_key_pressed_id)
{
   T_SUBSCRIBER_ID owner_keypad_id = kpd_get_owner_keypad_id();
   T_KPD_PHYSICAL_KEY_ID key_id = physical_key_pressed_id;
   UINT32 loop_counter = 0;
   UINT16 counter = 0;

   if ( subscriber_infos[owner_keypad_id]->notified_keys.notif_level[key_id] & KPD_FIRST_PRESS_NOTIF )
   {
      /* Notify subscribers of the key pressed */
       kpd_send_key_event_message(key_id, KPD_KEY_PRESSED,
                                  KPD_FIRST_PRESS, subscriber_infos[owner_keypad_id]->mode,
                                  subscriber_infos[owner_keypad_id]->return_path);
   }

   /* If key pressed is the PWR key, the message "Released key" is immediately sent */
   if (key_id != KPD_SHORT_PRESS_PWR_KEY)
   {
      /* Loop infinitely until key is released */
      do
      {
         rvf_delay(RVF_MS_TO_TICKS(WAIT_TIME_LOOP));
         physical_key_pressed_id = kpd_scan_keypad();
         loop_counter++;

         /* Send message for repeat key */
         if (subscriber_infos[owner_keypad_id]->notified_keys.notif_level[key_id] & (KPD_LONG_PRESS_NOTIF|KPD_INFINITE_REPEAT_NOTIF))
         {
            if ((counter == 0) && (WAIT_TIME_LOOP*loop_counter >= subscriber_infos[owner_keypad_id]->notified_keys.long_press_time) )
            {
               kpd_send_key_event_message(key_id, KPD_KEY_PRESSED,
                                          KPD_LONG_PRESS, subscriber_infos[owner_keypad_id]->mode,
                                          subscriber_infos[owner_keypad_id]->return_path);
               counter ++;
            }
            else if (subscriber_infos[owner_keypad_id]->notified_keys.notif_level[key_id] & KPD_INFINITE_REPEAT_NOTIF)
            {
               if (WAIT_TIME_LOOP*loop_counter >= (UINT32)((counter*subscriber_infos[owner_keypad_id]->notified_keys.repeat_time + subscriber_infos[owner_keypad_id]->notified_keys.long_press_time)) )
               {
                  kpd_send_key_event_message(key_id, KPD_KEY_PRESSED,
                                             KPD_REPEAT_PRESS, subscriber_infos[owner_keypad_id]->mode,
                                             subscriber_infos[owner_keypad_id]->return_path);
                  counter ++;
               }
            }
         }

      } while (physical_key_pressed_id != KPD_PKEY_NULL);
   }

   if ( subscriber_infos[owner_keypad_id]->notified_keys.notif_level[key_id] & KPD_RELEASE_NOTIF )
   {
      /* Notify subscribers of the key released */
      kpd_send_key_event_message(key_id, KPD_KEY_RELEASED,
                                 KPD_INSIGNIFICANT_VALUE, subscriber_infos[owner_keypad_id]->mode,
                                 subscriber_infos[owner_keypad_id]->return_path);
   }

   /* On board,this function unmask keypad interrupt
      On Riviera tool, this function authorize to send new messages to keypad task */
   if (key_id != KPD_SHORT_PRESS_PWR_KEY)
   {
#if (CHIPSET == 12)
      kpd_software_reset();
      kpd_init_ctrl_reg(1, HARDWARE_DECODING, KPD_CLK_DIV32,
                        KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED,
                        KPD_DETECTION_DISABLED, KPD_DETECTION_DISABLED);
#endif
      kpd_acknowledge_key_pressed();
   }
}

/**
 * function: kpd_wait_for_key_release
 */
void kpd_wait_for_key_release(void)
{
   T_KPD_PHYSICAL_KEY_ID key_id;;

   do
   {
      rvf_delay(RVF_MS_TO_TICKS(WAIT_TIME_LOOP));
      key_id = kpd_scan_keypad();

   } while (key_id != KPD_PKEY_NULL);

   kpd_acknowledge_key_pressed();
}

/*@}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -