uint16_t prebufferk[4];
uint8_t bufferk[8];
typedef union {
uint16_t prebufferk[4];
uint8_t bufferk[8];
} combok;
uint8_t index_k;
const uint8_t index_k_ref=3;
extern USBD_HandleTypeDef hUsbDeviceHS;
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();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
index_k=0;
MX_GPIO_Init();
MX_USB_DEVICE_Init();
MX_SPI2_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
bufferk[0]=1;//reportID
bufferk[1]=0;//modifier
bufferk[2]=0;//OEM
bufferk[3]=0;//keycode data
bufferk[4]=0;//keycode data
bufferk[5]=0;//keycode data
bufferk[6]=0;//keycode data
bufferk[7]=0;//keycode data
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
if(LL_SPI_IsActiveFlag_RXNE(SPI2))
{
if(LL_GPIO_IsInputPinSet(f7i1_GPIO_Port, f7i1_Pin) && index_k !=index_k_ref) // If pin is high and index threshhold not reached
{
prebufferk[index_k]=SPI2->DR;
index_k ++;
}
else
{
}
}
if(index_k==index_k_ref){
USBD_HID_SendReport(&hUsbDeviceHS, bufferk, 8);
}
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
uint8_t *report,
uint16_t len)
{
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassData;
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (hhid->state == HID_IDLE)
{
hhid->state = HID_BUSY;
USBD_LL_Transmit(pdev,
HID_EPIN_ADDR,
report,
len);
index_k=0; // This part does not compile.
}
}
return USBD_OK;
}
So the goal is to transfer a SPI buffer into some ram and once the accompanying buffer is full, write to USB endpoint.
One problem I face face is that index_k in the HID_Sendreport function is not recognized, cant remember if I should put index_k extern and inside usbd_hid.c ?