Ejemplo n.º 1
0
//------------------------------------------------------------------------------
void myHidTransmitKey(int key_index)
{
  if (myUSB0_ep1_state == EPN_DISABLED)
    return;

  while (myUSB0_ep1_state != EPN_IDLE)
    ;

  myUSB0_ep1_state = EPN_BUSY;
  USB0_EPn_write_fifo(SI32_USB_0_EP1, &s_KeyTable[key_index], 1);
  SI32_USBEP_A_set_in_packet_ready(SI32_USB_0_EP1);

}
Ejemplo n.º 2
0
void ep_write(U8 ep_num)
{
    U8 i, ep_size, len;
    usb_pcb_t *pcb = usb_pcb_get();

    uint32_t ControlReg = SI32_USB_A_read_ep0control(SI32_USB_0);

    ep_size = ep_size_get( ep_num );
    len = pcb->fifo[ep_num].len;

    if( len > 0 )
    {
        if( ep_num == 0 )
        {
            // Make sure we're free to write
            while( SI32_USB_A_read_ep0control(SI32_USB_0) & SI32_USB_A_EP0CONTROL_IPRDYI_MASK );

            //if( ( ongoing_write & ( 1 < ep_num ) ) == 0)
                //SI32_USB_A_clear_out_packet_ready_ep0( SI32_USB_0 );

            for (i=0; i<len; i++)
            {
                if ( i == ep_size )
                {
                    // we've filled the max packet size so break and send the data
                    //ControlReg |= SI32_USB_A_EP0CONTROL_IPRDYI_MASK;
                    //SI32_USB_0->EP0CONTROL.U32 = ControlReg;
                    ongoing_write |= ( 1 < ep_num );
                    break;
                }

                SI32_USB_A_write_ep0_fifo_u8( SI32_USB_0, usb_buf_read( ep_num ) );
            }
            ongoing_write = 0;
            ControlReg |= SI32_USB_A_EP0CONTROL_IPRDYI_MASK;
            //ControlReg |= SI32_USB_A_EP0CONTROL_DEND_MASK;
            SI32_USB_0->EP0CONTROL.U32 = ControlReg;

        }
        else
        {
            if( ep_dir_get( ep_num )  == DIR_OUT )
                return;

            // JEFF TESTING: Return immediately if our endpoint is not ready. This should never be the case
            // unless the endpoint is hung. We are not sending that much data so something must be wrong.
            // Also add a timer to the fifo_empty function at the end to eliminate endless loop on USB error.
            if( !SI32_USBEP_A_is_in_fifo_empty( usb_ep[ ep_num - 1 ] ) )
                return;
            if( SI32_USBEP_A_read_epcontrol( usb_ep[ ep_num - 1 ] ) & SI32_USBEP_A_EPCONTROL_IPRDYI_MASK )
                return;

            // Make sure we're free to write
            //while( SI32_USBEP_A_read_epcontrol( usb_ep[ ep_num - 1 ] ) & SI32_USBEP_A_EPCONTROL_IPRDYI_MASK );

            for (i=0; i<len; i++)
            {
                // check if we've reached the max packet size for the endpoint
                if ( i == ep_size )
                {
                    // we've filled the max packet size so break and send the data
                    break;
                }

                SI32_USBEP_A_write_fifo_u8( usb_ep[ ep_num - 1 ], usb_buf_read( ep_num ) );
            }

            // clearing these two will send the data out
            SI32_USBEP_A_clear_in_data_underrun( usb_ep[ ep_num - 1 ] );
            SI32_USBEP_A_set_in_packet_ready( usb_ep[ ep_num - 1 ] );
        }
    }
}