Пример #1
0
void pal_get_current_time(uint32_t *timer_count)
{
	uint32_t time_val;
	/* This will avoid the hard faults, due to aligned nature of access */
	time_val = sw_timer_get_time();
	MEMCPY_ENDIAN((uint8_t *)timer_count, (uint8_t *)&time_val,
			sizeof(time_val));
}
Пример #2
0
void pal_get_current_time(uint32_t *timer_count)
{
    *timer_count = sw_timer_get_time();
}
Пример #3
0
void pal_trx_read_timestamp(uint32_t *timestamp)
{
    *timestamp  = sw_timer_get_time();
}
Пример #4
0
/**
 * @brief Application task and state machine
 */
static void app_task(void)
{
    switch (node_status)
    {
        case IDLE:
            {
                button_id_t button;                
                static uint32_t current_time;
                static uint32_t previous_button_time;
                uint8_t num_records = 1;
                static button_id_t previous_button;
				keyboard_input_desc_t *joystick_desc;
				 zid_report_data_record_t zid_report_data_joystick[2];
				 uint8_t report_data_buffer_joystick[80];
				 uint8_t *msg_ptr = &report_data_buffer_joystick[0];
				if(button_mode == BUTTON_GAME_MODE)
				{
					  /* Create the input report for the ppt control */
					  zid_report_data_joystick[0].report_type = INPUT;
					  zid_report_data_joystick[0].report_desc_identifier = KEYBOARD;
					  zid_report_data_joystick[0].report_data = (void *)msg_ptr;
                      joystick_desc = (keyboard_input_desc_t *)msg_ptr;
                      joystick_desc->modifier_keys = 0x00;
					  joystick_desc->key_code[0] = 0x00;
					  joystick_desc->key_code[1] = 0x00;
					  joystick_desc->key_code[2] = 0x00;
					  joystick_desc->key_code[3] = 0x00;
					  joystick_desc->key_code[4] = 0x00;
					  joystick_desc->key_code[5] = 0x00;
					  uint16_t x_temp = x_val;
					  uint16_t y_temp = y_val;
					   
					   if (y_temp > (ADC_val + APPX_5_DEGREE_VALUE))
					   {
						   joystick_desc->key_code[2] = 1;//down y-axis negative
					   }
					   else if (y_temp < (ADC_val - APPX_5_DEGREE_VALUE))
					   {
						   joystick_desc->key_code[2] = 2;//up y-axis positive
					   }

					   else if (x_temp > (ADC_val + APPX_5_DEGREE_VALUE))
					   {
						   joystick_desc->key_code[2] = 3;//left x-axis negative
					   }
					   else if (x_temp < (ADC_val - APPX_5_DEGREE_VALUE))
					   {
						   joystick_desc->key_code[2] = 4;//right x-axis positive
					   }
					   else
					   {
						   //
					   }
					
				}
				/* Scan the button events */
                button = button_scan();
				/* Check if any valid vents occurred */
                if ((button != BUTTON_UNKNOWN) && (button == previous_button))
                {
                    /* Check time to previous transmission. */

                     current_time= sw_timer_get_time();
                    if ((current_time - previous_button_time) < zid_interframe_duration)
                    {
                        return;
                    }
                    else
                    {
					  /* Check if the key press mode is mouse mode */
                       if(BUTTON_MOUSE_MODE == button_mode)
                       {
                         if(!((key_mapping_mouse[b_state] <= BUTTON_UP_E) &&  
                            (BUTTON_RIGHT_E >= key_mapping_mouse[b_state])))
                         {
						   /* Inter-frame duration for mouse will be less than the actual key events */
                           if((current_time - previous_button_time) < INTER_FRAME_DURATION_MOUSE_US)
                           {
                            return;
                           }
                         }
                       }
                        /* Store current time */
                        previous_button_time = current_time;                        
                    }
                    
					/* Get the key index value for the actual event */
                    b_state = get_zid_keyrc_button(button);                    
                    
					/* Check any mode change event occurred */
                    switch(key_mapping_media[b_state])
                    {
                    case BUTTON_MOUSE_MODE:
					   /* Configure for the mouse mode */
                       button_mode = BUTTON_MOUSE_MODE;
                       LED_On(LED_2);
                       LED_Off(LED_3);
                       LED_Off(LED_4);
                       LED_Off(LED_5);
                       zid_interframe_duration = INTER_FRAME_DURATION_MOUSE_US;
                       return;
                      break;
                      
                    case BUTTON_PPT_MODE:
					/* Configure for the ppt mode */
                      button_mode = BUTTON_PPT_MODE;
                       LED_Off(LED_2);
                       LED_On(LED_3);
                       LED_Off(LED_4);
                       LED_Off(LED_5);
                       zid_interframe_duration = INTER_FRAME_DURATION_US;
                       return;
                      break;
                      
                    case BUTTON_GAME_MODE:
					 /* Configure for the game controller mode. */
                      button_mode = BUTTON_GAME_MODE;
                       LED_Off(LED_2);
                       LED_Off(LED_3);
                       LED_On(LED_4);
                       LED_Off(LED_5);
					   read_acc(&x_val,&y_val,&z_val,&ADC_val);
					   app_calculate_offset();
					   Correct_x_offset(&x_val,x_offset);
					   Correct_y_offset(&y_val,y_offset);
					   sw_timer_start(APP_TIMER_ACC_READ,ACCELEROMETER_SAMPLE_TIME,SW_TIMEOUT_RELATIVE,
					   (FUNC_PTR)acc_read_cb,NULL);
                       zid_interframe_duration = INTER_FRAME_DURATION_US;
                       return;
                      break;
                      
                    case BUTTON_MEDIA_MODE:
					/* Configure for the media player control mode */
                      button_mode = BUTTON_MEDIA_MODE;
                       LED_Off(LED_2);
                       LED_Off(LED_3);
                       LED_Off(LED_4);
                       LED_On(LED_5);
                       zid_interframe_duration = INTER_FRAME_DURATION_US;
                       return;
                      break;
                      
                    default:
                      LED_On(LED_1);
                      break;
                    } 
                    
                    if(button_mode == BUTTON_MEDIA_MODE)
                    {
					  /* get the valid key inputs for the media player control */
                      zid_report_data_record_t zid_report_data[2];
                      uint8_t report_data_buffer[80];
                      uint8_t *msg_ptr = &report_data_buffer[0];
                      
                      if(key_mapping_media[b_state] == BUTTON_INVALID)
                      {
                        return;
                      }
                      
					  /* Create the input report for the media player control */
                      zid_report_data[0].report_type = INPUT;
                      zid_report_data[0].report_desc_identifier = KEYBOARD;
                      zid_report_data[0].report_data = (void *)msg_ptr;

                      keyboard_input_desc_t *keyboard_input_desc;
                      keyboard_input_desc = (keyboard_input_desc_t *)msg_ptr;

                      keyboard_input_desc->modifier_keys = 0x00;
                      keyboard_input_desc->key_code[0] = 0x00;
                      keyboard_input_desc->key_code[1] = 0x00;
                      keyboard_input_desc->key_code[2] = 0x00;
                      keyboard_input_desc->key_code[3] = 0x00;
                      keyboard_input_desc->key_code[4] = (uint8_t)key_mapping_media[b_state];
                      keyboard_input_desc->key_code[5] = (uint8_t)(key_mapping_media[b_state] >> 8);
                      num_records = 1;
                      
                      if (zid_report_data_request(pairing_ref,num_records, zid_report_data, TX_OPTIONS
  #ifdef RF4CE_CALLBACK_PARAM
                                                ,(FUNC_PTR)zid_report_data_confirm
  #endif
                        ))

                      {
                          node_status = TRANSMITTING;
                      }
                    }
                    else if(button_mode == BUTTON_PPT_MODE)
                    {
					  /* get the valid key inputs for the ppt mode */
                      zid_report_data_record_t zid_report_data[2];
                      uint8_t report_data_buffer[80];
                      uint8_t *msg_ptr = &report_data_buffer[0];
                      
                      if(key_mapping_ppt[b_state] == BUTTON_INVALID)
                      {
                        return;
                      }
					  /* Create the input report for the ppt control */
                      zid_report_data[0].report_type = INPUT;
                      zid_report_data[0].report_desc_identifier = KEYBOARD;
                      zid_report_data[0].report_data = (void *)msg_ptr;

                      keyboard_input_desc_t *keyboard_input_desc;
                      keyboard_input_desc = (keyboard_input_desc_t *)msg_ptr;

                      keyboard_input_desc->modifier_keys = 0x00;
                      keyboard_input_desc->key_code[0] = key_mapping_ppt[b_state];
                      keyboard_input_desc->key_code[1] = 0x00;
                      keyboard_input_desc->key_code[2] = 0x00;
                      keyboard_input_desc->key_code[3] = 0x00;
                      keyboard_input_desc->key_code[4] = 0x00;
                      keyboard_input_desc->key_code[5] = 0x00;
                      num_records = 1;
                    if (zid_report_data_request(pairing_ref,num_records, zid_report_data, TX_OPTIONS
  #ifdef RF4CE_CALLBACK_PARAM
                                                ,(FUNC_PTR)zid_report_data_confirm
  #endif
                        ))

                      {
                          node_status = TRANSMITTING;
                          b_state = BUTTON_INVALID;
                      }
                    }
                    else if(button_mode == BUTTON_MOUSE_MODE)
                    {              
						/* get the valid key inputs for the mouse mode */
                        zid_report_data_record_t zid_report_data[2];
                        uint8_t report_data_buffer[80];
                        uint8_t *msg_ptr = &report_data_buffer[0];
                        mouse_desc_t *mouse_desc;
                        
                        if(key_mapping_mouse[b_state] == BUTTON_INVALID)
                        {
                          return;
                        }
						
                        /* Create the input report for the mouse control */
                        zid_report_data[0].report_type = INPUT;
                        zid_report_data[0].report_desc_identifier = MOUSE;
                        zid_report_data[0].report_data = (void *)msg_ptr;                        
                        mouse_desc = (mouse_desc_t *)msg_ptr;
                        
                        mouse_desc->button0 = 0x00;
                        mouse_desc->button1 = 0x00;
                        mouse_desc->button2 = 0x00;
                        mouse_desc->x_coordinate = 0x00;
                        mouse_desc->y_coordinate = 0x00;

                          switch(key_mapping_mouse[b_state])
                          {
                          case BUTTON_UP_E:
                             mouse_desc->y_coordinate = MOUSE_NEGATIVE_DISPLACEMENT;
                            break;
                          case BUTTON_LEFT_E:
                             mouse_desc->x_coordinate = MOUSE_NEGATIVE_DISPLACEMENT;
                            break;
                          case BUTTON_RIGHT_E:
                            mouse_desc->x_coordinate = MOUSE_POSITIVE_DISPLACEMENT;
                            break;
                          case BUTTON_DOWN_E:
                            mouse_desc->y_coordinate = MOUSE_POSITIVE_DISPLACEMENT;
                            break;
                          case BUTTON_LEFT_SINGLE_CLK:
                            mouse_desc->button0 = 0x01;
                            break;
                          case BUTTON_RIGHT_SINGLE_CLK:
                            mouse_desc->button1 = 0x01;
                            break;
                          case BUTTON_MIDDLE_CLK:
                            mouse_desc->button2 = 0x01;
                            break;                            
                          case BUTTON_SCROLL_UP:
                            mouse_desc->y_coordinate = 1;
                            mouse_desc->button2 = 0x80;
                            break;
                          case BUTTON_SCROLL_DOWN:
                            mouse_desc->x_coordinate = -1;
                            mouse_desc->button2 = 0x80;
                            break;
                          default:
                            break;
                          }                   
                       

                        msg_ptr += sizeof(mouse_desc_t);
                        num_records = 1;
                    if (zid_report_data_request(pairing_ref, num_records, zid_report_data, TX_OPTIONS
  #ifdef RF4CE_CALLBACK_PARAM
                                                ,(FUNC_PTR)zid_report_data_confirm
  #endif
                        ))

                      {
                          node_status = TRANSMITTING;
                          b_state = BUTTON_INVALID;
                      }              
                    }
                    else if(button_mode == BUTTON_GAME_MODE)
                    {
                                             
                       if(key_mapping_gamepad[b_state] == BUTTON_INVALID)
                       {
	                       return;
                       }
                    
					  switch(key_mapping_gamepad[b_state])
					   {
						   case BUTTON_1:
						   case BUTTON_2:
						   case BUTTON_3:
						   case BUTTON_4:
						   joystick_desc->key_code[0]=key_mapping_gamepad[b_state];
						   break;
						   case BUTTON_THROTTLE_UP:
						   joystick_desc->key_code[1]=0x01;
						   break;
						   case BUTTON_THROTTLE_DOWN:
						   joystick_desc->key_code[1]=0x02;
						   default:
						   break;
					   }
					   
                       num_records = 1;
                      
                    }
                }