TM_USB_HIDDEVICE_Status_t TM_USB_HIDDEVICE_GamepadSend(TM_USB_HIDDEVICE_Gamepad_Number_t gamepad_id, TM_USB_HIDDEVICE_Gamepad_t* Gamepad_Data) {
	uint8_t buff[7]; /* 7 bytes long report */
	
	/* Check status */
	if (TM_USB_HIDDEVICE_INT_Status != TM_USB_HIDDEVICE_Status_Connected) {
		return TM_USB_HIDDEVICE_Status_Disconnected;
	}
	
	/* Report ID */
	buff[0] = gamepad_id; /* gamepad id */
	
	/* Buttons pressed, byte 1 */
	buff[1] = 0;
	buff[1] |= Gamepad_Data->Button1 	<< 0;	/* Bit 0 */
	buff[1] |= Gamepad_Data->Button2 	<< 1;	/* Bit 1 */
	buff[1] |= Gamepad_Data->Button3 	<< 2;	/* Bit 2 */
	buff[1] |= Gamepad_Data->Button4 	<< 3;	/* Bit 3 */
	buff[1] |= Gamepad_Data->Button5 	<< 4;	/* Bit 4 */
	buff[1] |= Gamepad_Data->Button6 	<< 5;	/* Bit 5 */
	buff[1] |= Gamepad_Data->Button7 	<< 6;	/* Bit 6 */
	buff[1] |= Gamepad_Data->Button8 	<< 7;	/* Bit 7 */
	
	/* Buttons pressed, byte 2 */
	buff[2] = 0;
	buff[2] |= Gamepad_Data->Button9 	<< 0;	/* Bit 0 */
	buff[2] |= Gamepad_Data->Button10 	<< 1;	/* Bit 1 */
	buff[2] |= Gamepad_Data->Button11 	<< 2;	/* Bit 2 */
	buff[2] |= Gamepad_Data->Button12 	<< 3;	/* Bit 3 */
	buff[2] |= Gamepad_Data->Button13 	<< 4;	/* Bit 4 */
	buff[2] |= Gamepad_Data->Button14 	<< 5;	/* Bit 5 */
	buff[2] |= Gamepad_Data->Button15 	<< 6;	/* Bit 6 */
	buff[2] |= Gamepad_Data->Button16 	<< 7;	/* Bit 7 */
	
	/* Left joystick */
	buff[3] = Gamepad_Data->LeftXAxis;
	buff[4] = Gamepad_Data->LeftYAxis;
	
	/* Right joystick */
	buff[5] = Gamepad_Data->RightXAxis;
	buff[6] = Gamepad_Data->RightYAxis;
	
	/* Send to USB gamepad data */
	USBD_HID_SendReport(&USB_OTG_dev, buff, 7);
	
	/* Return connected */
	return TM_USB_HIDDEVICE_Status_Connected;
}
Beispiel #2
0
/*
  Prepare and send new USB data packet

  The format of HID_Buffer is defined by
  USB endpoint description can be found in 
  file usb_hid_joystick.c, variable HID_JOYSTICK_ReportDesc
*/
void usbJoystickUpdate(void)
{
  static uint8_t HID_Buffer[HID_IN_PACKET];
  
  //buttons
  HID_Buffer[0] = 0;
  HID_Buffer[1] = 0;
  HID_Buffer[2] = 0;
  for (int i = 0; i < 8; ++i) {
    if ( channelOutputs[i+8] > 0 ) {
      HID_Buffer[0] |= (1 << i);
    } 
    if ( channelOutputs[i+16] > 0 ) {
      HID_Buffer[1] |= (1 << i);
    } 
    if ( channelOutputs[i+24] > 0 ) {
      HID_Buffer[2] |= (1 << i);
    } 
  }

  //analog values
  //uint8_t * p = HID_Buffer + 1;
  for (int i = 0; i < 8; ++i) {
    int16_t value = channelOutputs[i] / 8;
    if ( value > 127 ) value = 127;
    else if ( value < -127 ) value = -127;
    HID_Buffer[i+3] = static_cast<int8_t>(value);  
  }

  USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET );
}
// release() takes the specified key out of the persistent key report and
// sends the report.  This tells the OS the key is no longer pressed and that
// it shouldn't be repeated any more.
int keyboardRelease(uint8_t k) 
{
        uint8_t i;
        if (k >= 136) {                        // it's a non-printing key (not a modifier)
                k = k - 136;
        } else if (k >= 128) {        // it's a modifier key
                _keyReport.modifiers &= ~(1<<(k-128));
                k = 0;
        } else {                                // it's a printing key
                k = _asciimap[k];
                if (!k) {
                        return 0;
                }
                if (k & 0x80) {                                                        // it's a capital letter or other character reached with shift
                        _keyReport.modifiers &= ~(0x02);        // the left shift modifier
                        k &= 0x7F;
                }
        }
        
        // Test the key report to see if k is present.  Clear it if it exists.
        // Check all positions in case the key is present more than once (which it shouldn't be)
        for (i=0; i<6; i++) {
                if (0 != k && _keyReport.keys[i] == k) {
                        _keyReport.keys[i] = 0x00;
                }
        }

        //sendReport(&_keyReport);
        USBD_HID_SendReport (mycorehandle, &(_keyReport.modifiers), 8);
        return 1;
}
Beispiel #4
0
/**
  * @brief  USB Mouse cursor moving
  * @param  None 
  * @retval None
  */
void USB_Demo(void)
{
  uint8_t HID_Buffer[4];
  
  BSP_LED_On(LED3);
  BSP_LED_On(LED6);
  BSP_LED_Off(LED10);
  BSP_LED_Off(LED7);
  
  while ((BSP_PB_GetState(BUTTON_USER) != GPIO_PIN_SET))
  {
    USB_GetPointerData_Demo(HID_Buffer);
    
    /* send data though IN endpoint*/
    if((HID_Buffer[1] != 0) || (HID_Buffer[2] != 0))
    {
      USBD_HID_SendReport(&USBD_Device, HID_Buffer, 4);
    }
  }

  /* Turn Off Leds */   
  BSP_LED_Off(LED3);
  BSP_LED_Off(LED5);
  BSP_LED_Off(LED7);
  BSP_LED_Off(LED9);
  BSP_LED_Off(LED10);
  BSP_LED_Off(LED8);
  BSP_LED_Off(LED6);
}
Beispiel #5
0
void usb_hid_send_report(uint8_t *buf) {
#ifdef USE_DEVICE_MODE
    #if 0
    USBD_HID_SendReport(&USB_OTG_Core, buf, 4);
    #endif
#endif
}
Beispiel #6
0
/**
* @brief  USB recognized as a standard mouse
*         cursor moving according to discovery moving
* @param  None 
* @retval None
*/
void USB_Demo(void)
{
  
  uint8_t *buf;
  
  STM_EVAL_LEDOn(LED3);
  STM_EVAL_LEDOff(LED6);
  
  while ((STM_EVAL_PBGetState(BUTTON_USER) != Bit_SET))
  {
    buf = USBD_HID_GetPos();
    
    if((buf[1] != 0) ||(buf[2] != 0))
    {
      USBD_HID_SendReport (&USB_Device_dev, 
                           buf,
                           4);
      /* Insert 50ms delay */ 
      Delay (5);   
    }
  }
  
  /* Wait for User button is released */ 
  while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_RESET)
  {} 
  
  /* Turn Off Leds */   
  STM_EVAL_LEDOff(LED3);
  STM_EVAL_LEDOff(LED4);
  STM_EVAL_LEDOff(LED5);
  STM_EVAL_LEDOff(LED6);
  
}
TM_USB_HIDDEVICE_Status_t TM_USB_HIDDEVICE_MouseSend(TM_USB_HIDDEVICE_Mouse_t* Mouse_Data) {
	uint8_t buff[5]; /* 5 bytes long report */
	
	/* Check status */
	if (TM_USB_HIDDEVICE_INT_Status != TM_USB_HIDDEVICE_Status_Connected) {
		return TM_USB_HIDDEVICE_Status_Disconnected;
	}
	
	/* Report ID */
	buff[0] = 0x02;	/* Mouse */
	
	/* Set buttons */
	buff[1] = 0;
	buff[1] |= Mouse_Data->LeftButton << 0;		/* Bit 0 */
	buff[1] |= Mouse_Data->RightButton << 1;	/* Bit 1 */
	buff[1] |= Mouse_Data->MiddleButton << 2;	/* Bit 2 */
	
	/* Set X and Y offset */
	buff[2] = Mouse_Data->XAxis;
	buff[3] = Mouse_Data->YAxis;
	
	/* Set wheel */
	buff[4] = Mouse_Data->Wheel;
	
	/* Send to USB */
	USBD_HID_SendReport(&USB_OTG_dev, buff, 5);
	
	/* Return connected */
	return TM_USB_HIDDEVICE_Status_Connected;
}
Beispiel #8
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  
  /* Configure the system clock to 72 MHz */
  SystemClock_Config();
  
  /* Initialize LED2 */
  BSP_LED_Init(LED2);
  
  /* Configure Key button for remote wakeup */
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI);

  /* Init Device Library */
  USBD_Init(&USBD_Device, &HID_Desc, 0);

  /* Register the HID class */
  USBD_RegisterClass(&USBD_Device, USBD_HID_CLASS);

  /* Start Device Process */
  USBD_Start(&USBD_Device);

  while (1)
  {
    /* Insert delay 100 ms */
    HAL_Delay(100);  
    BSP_LED_Toggle(LED2);
    HAL_Delay(100);  
    GetPointerData(HID_Buffer);
    USBD_HID_SendReport(&USBD_Device, HID_Buffer, 4);
  }
}
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F469xx HAL library initialization */
  HAL_Init();

  /* Configure the system clock to 180 MHz */
  SystemClock_Config();

  /* Initialize IO expander (MFX) */
  BSP_IO_Init();

  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /* Initialize IO expander */
  BSP_IO_Init();

  /* Initialize Joystick */
  if (BSP_JOY_Init(JOY_MODE_GPIO) == 0)
  {
    JoyButtonInitialized = 1;
  }

  /* Init CDC Application */
  USBD_Init(&USBD_Device_HS, &VCP_Desc, 1);

  /* Init HID Application */
  USBD_Init(&USBD_Device_FS, &HID_Desc, 0);

  /* Add Supported Classes */
  USBD_RegisterClass(&USBD_Device_HS, &USBD_CDC);
  USBD_RegisterClass(&USBD_Device_FS, &USBD_HID);

    /* Add CDC Interface Class */
  USBD_CDC_RegisterInterface(&USBD_Device_HS, &USBD_CDC_fops);

  /* Start Device Process */
  USBD_Start(&USBD_Device_FS);
  USBD_Start(&USBD_Device_HS);

  /* Run Application (Interrupt mode) */
  while (1)
  {
    Toggle_Leds();
    if(HID_SendReport == 1)
    {
      HID_SendReport = 0;
      GetPointerData(HID_Buffer);

      /* Send data though IN endpoint*/
      if((HID_Buffer[1] != 0) || (HID_Buffer[2] != 0))
      {
        USBD_HID_SendReport(&USBD_Device_FS, HID_Buffer, 4);
      }
    }
  }
}
Beispiel #10
0
void sendRcDataToHid(void)
{
    int8_t report[8];
    for (unsigned i = 0; i < USB_CDC_HID_NUM_AXES; i++) {
        const uint8_t channel = hidChannelMapping[i];
        report[i] = scaleRange(constrain(rcData[channel], PWM_RANGE_MIN, PWM_RANGE_MAX), PWM_RANGE_MIN, PWM_RANGE_MAX, USB_CDC_HID_RANGE_MIN, USB_CDC_HID_RANGE_MAX);
        if (i == 1) {
            // For some reason ROLL is inverted in Windows
            report[i] = -report[i];
        }
    }
#if defined(STM32F4)
    USBD_HID_SendReport(&USB_OTG_dev, (uint8_t*)report, sizeof(report));
#elif defined(STM32F7)
    USBD_HID_SendReport(&USBD_Device, (uint8_t*)report, sizeof(report));
#else
# error "MCU does not support USB HID."
#endif
}
Beispiel #11
0
/**
  * @brief  Period elapsed callback in non blocking mode
  * @param  htim : TIM handle
  * @retval None
  */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
    __HAL_TIM_SET_COUNTER(htim, 0);

    switch (KB_state) {
    case BTN_Down:
        if ((len_KB_str == 0) || (pKB_str == NULL)) {
            HAL_TIM_Base_Stop_IT(htim);
            return;
        }
        KB_state = BTN_Up;

        char2KBID(*pKB_str);
        SEGGER_RTT_printf(0, "USB send char %c \r\n" , *pKB_str);
        pKB_str++;
        len_KB_str--;
        USBD_HID_SendReport(&USBD_Device, KB_USBBuf, HID_KB_SIZE);

        __HAL_TIM_SET_COUNTER(&TimHandle, 0);
        __HAL_TIM_SET_AUTORELOAD(&TimHandle, 200-1); // 200ms
        HAL_TIM_Base_Start_IT(&TimHandle);
        break;

    case BTN_Up:
        memset(KB_USBBuf, 0, 9);
        KB_USBBuf[0] = 1;
        USBD_HID_SendReport(&USBD_Device, KB_USBBuf, HID_KB_SIZE);
        if (len_KB_str == 0) {
            pKB_str = NULL;
            HAL_TIM_Base_Stop_IT(htim);
        } else {
            KB_state = BTN_Down;
            __HAL_TIM_SET_COUNTER(&TimHandle, 0);
            __HAL_TIM_SET_AUTORELOAD(&TimHandle, 200-1); // 200ms
            HAL_TIM_Base_Start_IT(&TimHandle);
        }
        break;
    default:
        pKB_str = NULL;
        HAL_TIM_Base_Stop_IT(htim);
        break;
    }
}
void SendStrToUSB(uint8_t* str)
{
	int i=0;
	while (*str)
	{
		InBuffer[i]=*str;
		i++;
		str++;
	}
	USBD_HID_SendReport(&USB_OTG_dev, InBuffer, i);
}
/* Custom report */
TM_USB_HIDDEVICE_Status_t TM_USB_HIDDEVICE_SendCustom(uint8_t* buff, uint8_t count) {
	/* Check status */
	if (TM_USB_HIDDEVICE_INT_Status != TM_USB_HIDDEVICE_Status_Connected) {
		return TM_USB_HIDDEVICE_Status_Disconnected;
	}	
	
	/* Send to USB */
	USBD_HID_SendReport(&USB_OTG_dev, buff, count);
	
	/* Return connected */
	return TM_USB_HIDDEVICE_Status_Connected;
}
Beispiel #14
0
/**
  * @brief  Sends sensors information.
  * @param  status: TSL user status
  * @retval None
  */
static void Process_Sensors(tsl_user_status_t status)
{
  if (LINEAR_DETECT)
  {
    GetPointerData(HID_Buffer);
    /* Send data through IN endpoint */
    if((HID_Buffer[1] != 0) || (HID_Buffer[2] != 0))
    {
      USBD_HID_SendReport(&USBD_Device, HID_Buffer, 4);
    }
  }
}
void keyboardReleaseAll(void)
{
        _keyReport.keys[0] = 0;
        _keyReport.keys[1] = 0;        
        _keyReport.keys[2] = 0;
        _keyReport.keys[3] = 0;        
        _keyReport.keys[4] = 0;
        _keyReport.keys[5] = 0;        
        _keyReport.modifiers = 0;
        //sendReport(&_keyReport);
        USBD_HID_SendReport (mycorehandle, &(_keyReport.modifiers), 8);
}
Beispiel #16
0
/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
  
  uint8_t *buf;
  
  buf = USBD_HID_GetPos();
  if((buf[1] != 0) ||(buf[2] != 0))
  {
    USBD_HID_SendReport (&USB_OTG_dev, 
                         buf,
                         4);
  } 
}
void SysTick_Handler(void)
{
  static uint8_t * buf;

  buf = USBD_HID_GetPos();         // 获取按键值,存入HID_Buffer
	
  if((buf[1] != 0) ||(buf[2] != 0))
  {
    USBD_HID_SendReport (&USB_OTG_dev, buf, 64);
		printf("buf    addr: %d : %d %d %d %d \r\n",(uint32_t)buf, buf[0],buf[1],buf[2],buf[3]);
		
  } 
	
}
Beispiel #18
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 168 Mhz */
  SystemClock_Config();
  
  /* Configure the LEDs */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
    /*Initialize Joystick */
  BSP_JOY_Init(JOY_MODE_GPIO);
  
  /* Init MSC Application */
  USBD_Init(&USBD_Device_HS, &MSC_Desc, 1);
    
  /* Init HID Application */
  USBD_Init(&USBD_Device_FS, &HID_Desc, 0);
  
  /* Add Supported Classes */
  USBD_RegisterClass(&USBD_Device_HS, &USBD_MSC);
  USBD_RegisterClass(&USBD_Device_FS, &USBD_HID);
  
  /* Add Storage callbacks for MSC Class */
  USBD_MSC_RegisterStorage(&USBD_Device_HS, &USBD_DISK_fops);
  
  /* Start Device Process */
  USBD_Start(&USBD_Device_FS);
  USBD_Start(&USBD_Device_HS);
  
  /* Run Application (Interrupt mode)*/
  while (1)
  {
    GetPointerData(HID_Buffer);
      
    if((HID_Buffer[1] != 0) || (HID_Buffer[2] != 0))
    {
      USBD_HID_SendReport(&USBD_Device_FS, HID_Buffer, 4);
    } 
  }
}
/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
  static __IO uint32_t counter=0;
  HAL_IncTick();
  
  if (counter++ == 10)
  {  
    GetPointerData(HID_Buffer);
    if((HID_Buffer[1] != 0) || (HID_Buffer[2] != 0))
    {
      USBD_HID_SendReport(&USBD_Device_FS, HID_Buffer, 4);
    }
    counter =0;
  }
  Toggle_Leds();
}
Beispiel #20
0
/**
  * @brief  This function sends the input report repeatedly.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
  uint8_t *buf;
  
  /* Get Joystick position */
  buf = USBD_HID_GetPos();
  
  /* Update the cursor position */
  if((buf[1] != 0) ||(buf[2] != 0))
  {
    /* Send Report */
    USBD_HID_SendReport (&USB_Device_dev, 
                         buf,
                         4);
  }    
} 
TM_USB_HIDDEVICE_Status_t TM_USB_HIDDEVICE_KeyboardReleaseAll(void) {
	uint8_t buff[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* 9 bytes long report */
	
	/* Check status */
	if (TM_USB_HIDDEVICE_INT_Status != TM_USB_HIDDEVICE_Status_Connected) {
		return TM_USB_HIDDEVICE_Status_Disconnected;
	}	
	
	/* Report ID */
	buff[0] = 0x01; /* Keyboard */
	
	/* Send to USB */
	USBD_HID_SendReport(&USB_OTG_dev, buff, 9);
	
	/* Return connected */
	return TM_USB_HIDDEVICE_Status_Connected;
}
TM_USB_HIDDEVICE_Status_t TM_USB_HIDDEVICE_MouseReleaseAll(void) {
	uint8_t buff[5] = {0, 0, 0, 0, 0}; /* 4 bytes long report */
	
	/* Check status */
	if (TM_USB_HIDDEVICE_INT_Status != TM_USB_HIDDEVICE_Status_Connected) {
		return TM_USB_HIDDEVICE_Status_Disconnected;
	}
	
	/* Report ID */
	buff[0] = 0x02;	/* Mouse */
	
	/* Send to USB to release all buttons and axes */
	USBD_HID_SendReport(&USB_OTG_dev, buff, 5);
	
	/* Return connected */
	return TM_USB_HIDDEVICE_Status_Connected;
}
TM_USB_HIDDEVICE_Status_t TM_USB_HIDDEVICE_GamepadReleaseAll(TM_USB_HIDDEVICE_Gamepad_Number_t gamepad_id) {
	uint8_t buff[7] = {0, 0, 0, 0, 0, 0, 0}; /* 7 bytes long report */
	
	/* Check status */
	if (TM_USB_HIDDEVICE_INT_Status != TM_USB_HIDDEVICE_Status_Connected) {
		return TM_USB_HIDDEVICE_Status_Disconnected;
	}
	
	/* Report ID */
	buff[0] = gamepad_id;
	
	/* Send to USB gamepad release all buttons and joysticks */
	USBD_HID_SendReport(&USB_OTG_dev, buff, 7);
	
	/* Return connected */
	return TM_USB_HIDDEVICE_Status_Connected;	
}
static void USBHidTask(void *Parameters)
{
	uint8_t hid_buffer[4] = {0};
	portTickType LastWake;

	GPIO_SetBits(GPIOD, GPIO_Pin_14);

	LastWake = xTaskGetTickCount();

	while(1) {
		hid_buffer[0] += 1;
		hid_buffer[1] += 1;

		USBD_HID_SendReport(&USB_OTG_dev, hid_buffer, 4);
		GPIO_ToggleBits(GPIOD, GPIO_Pin_14);
		vTaskDelayUntil(&LastWake, 3000);
	}
}
Beispiel #25
0
/**
  * @brief  Manage the activity on sensors when touched/released (example)
  * @param  None
  * @retval None
  */
void ProcessSensors(void)
{
  uint32_t TSC_RawPosition_1= 0;
  Send_Buffer[0] = 0x07;
  
  if((MyLinRots[0].p_Data->RawPosition) - (TSC_RawPosition_1) > 4)
  {
    if ((PrevXferDone) && (USB_Device_dev.dev.device_status == USB_CONFIGURED))
    {
      Send_Buffer[1] = (uint8_t)(MyLinRots[0].p_Data->RawPosition);
      
      USBD_HID_SendReport (&USB_Device_dev, Send_Buffer, 2);
      
      TSC_RawPosition_1 = MyLinRots[0].p_Data->RawPosition;
      PrevXferDone = 0;
    }
  }
}
Beispiel #26
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint8_t HID_Buffer[4];
  
  /* STM32L0xx HAL library initialization:
       - Configure the Flash prefetch, Flash preread and Buffer caches
       - Systick timer is configured by default as source of time base, but user 
             can eventually implement his proper time base source (a general purpose 
             timer for example or other time source), keeping in mind that Time base 
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
             handled in milliseconds basis.
       - Low Level Initialization
     */
  HAL_Init();
  
  /* Configure the system clock to get correspondent USB clock source */
  SystemClock_Config();
  
  /* Configure LED2 */
  BSP_LED_Init(LED2);
 
  /* Configure Key button for remote wakeup */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
  
  /* Init Device Library */
  USBD_Init(&USBD_Device, &HID_Desc, 0);
  
  /* Register the HID class */
  USBD_RegisterClass(&USBD_Device, &USBD_HID);
  
  /* Start Device Process */
  USBD_Start(&USBD_Device);

  /* In an infinite loop, send periodically host mouse pointer position (emulated) */  
  while (1)
  {
    HAL_Delay(10);  
    BSP_LED_Toggle(LED2);
    
    GetPointerData(HID_Buffer);
    USBD_HID_SendReport(&USBD_Device, HID_Buffer, 4);
  }
}
/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
  static __IO uint32_t counter=0;
  HAL_IncTick();
  
  /* check Joystick state every polling interval (10ms) */
  if (counter++ == USBD_HID_GetPollingInterval(&USBD_Device))
  {  
    GetPointerData(HID_Buffer);
    
    /* send data though IN endpoint*/
    if((HID_Buffer[1] != 0) || (HID_Buffer[2] != 0))
    {
      USBD_HID_SendReport(&USBD_Device, HID_Buffer, 4);
    }
    counter =0;
  }
  Toggle_Leds();
}
Beispiel #28
0
void USB_KB_type(const char *str, uint8_t len) {
	if (pKB_str != NULL) {
		return;
	}
	if (len == 0) {
        return;
	}

	strcpy(KB_strBuf, str);
	KB_state = BTN_Up;
	pKB_str = KB_strBuf;

	char2KBID(*pKB_str++);
	len_KB_str = len - 1;
	USBD_HID_SendReport(&USBD_Device, KB_USBBuf, HID_KB_SIZE);

	__HAL_TIM_SET_COUNTER(&TimHandle, 0);
	__HAL_TIM_SET_AUTORELOAD(&TimHandle, 50-1); // 50ms
	HAL_TIM_Base_Start_IT(&TimHandle);
}
int keyboardPress(uint8_t k) 
{
        uint8_t i;
        if (k >= 136) {                        // it's a non-printing key (not a modifier)
                k = k - 136;
        } else if (k >= 128) {        // it's a modifier key
                _keyReport.modifiers |= (1<<(k-128));
                k = 0;
        } else {                                // it's a printing key
                k = _asciimap[k];
                if (!k) {
                        //setWriteError();
                        return 0;
                }
                if (k & 0x80) {                                                // it's a capital letter or other character reached with shift
                        _keyReport.modifiers |= 0x02;        // the left shift modifier
                        k &= 0x7F;
                }
        }
        
        // Add k to the key report only if it's not already present
        // and if there is an empty slot.
        if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && 
                _keyReport.keys[2] != k && _keyReport.keys[3] != k &&
                _keyReport.keys[4] != k && _keyReport.keys[5] != k) {
                
                for (i=0; i<6; i++) {
                        if (_keyReport.keys[i] == 0x00) {
                                _keyReport.keys[i] = k;
                                break;
                        }
                }
                if (i == 6) {
                        //setWriteError();
                        return 0;
                }        
        }
        //sendReport(&_keyReport);
        USBD_HID_SendReport (mycorehandle, &(_keyReport.modifiers), 8);
        return 1;
}
int main(void) {

	/* USER CODE BEGIN 1 */

	/* USER CODE END 1 */

	/* MCU Configuration----------------------------------------------------------*/

	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
	HAL_Init();

	/* Configure the system clock */
	SystemClock_Config();

	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_TIM1_Init();
	MX_USB_DEVICE_Init();

	/* USER CODE BEGIN 2 */
	HAL_TIM_IC_Start_IT(&htim1, TIM_CHANNEL_1);

	/* USER CODE END 2 */

	/* Infinite loop */
	/* USER CODE BEGIN WHILE */

	//DBGMCU->CR |= DBGMCU_CR_DBG_TIM1_STOP; //this is for timer debugging

	while (1) {
		/* USER CODE END WHILE */

		/* USER CODE BEGIN 3 */
		if (data_ready) {
			USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t*) rc_data, 10);
			data_ready = 0;
		}
	}
	/* USER CODE END 3 */

}