Beispiel #1
0
    /*******************************************************************************
    * Function Name: USBFS_1_PutString
    ********************************************************************************
    *
    * Summary:
    *  Sends a null terminated string to the PC.
    *
    * Parameters:
    *  string: pointer to the string to be sent to the PC
    *
    * Return:
    *  None.
    *
    * Global variables:
    *   USBFS_1_cdc_data_in_ep: CDC IN endpoint number used for sending
    *     data.
    *
    * Reentrant:
    *  No.
    *
    * Theory:
    *  This function will block if there is not enough memory to place the whole
    *  string, it will block until the entire string has been written to the
    *  transmit buffer.
    *
    *******************************************************************************/
    void USBFS_1_PutString(char8* string) 
    {
        uint16 str_length;
        uint16 send_length;

        /* Get length of the null terminated string */
        str_length = strlen(string);
        do
        {
            /* Limits length to maximim packet size for the EP */
            send_length = (str_length > USBFS_1_EP[USBFS_1_cdc_data_in_ep].bufferSize) ?
                          USBFS_1_EP[USBFS_1_cdc_data_in_ep].bufferSize : str_length;
             /* Enable IN transfer */
            USBFS_1_LoadInEP(USBFS_1_cdc_data_in_ep, (uint8 *)string, send_length);
            str_length -= send_length;

            /* If more data are present to send */
            if(str_length > 0)
            {
                string += send_length;
                /* Wait for the Host to read it. */
                while(USBFS_1_EP[USBFS_1_cdc_data_in_ep].apiEpState ==
                                          USBFS_1_IN_BUFFER_FULL);
            }
        }while(str_length > 0);
    }
Beispiel #2
0
    /*******************************************************************************
    * Function Name: USBFS_1_PutChar
    ********************************************************************************
    *
    * Summary:
    *  Writes a single character to the PC.
    *
    * Parameters:
    *  txDataByte: Character to be sent to the PC.
    *
    * Return:
    *  None.
    *
    * Global variables:
    *   USBFS_1_cdc_data_in_ep: CDC IN endpoint number used for sending
    *     data.
    *
    * Reentrant:
    *  No.
    *
    *******************************************************************************/
    void USBFS_1_PutChar(char8 txDataByte) 
    {
        uint8 dataByte;
        dataByte = (uint8)txDataByte;

        USBFS_1_LoadInEP(USBFS_1_cdc_data_in_ep, &dataByte, 1u);
    }
Beispiel #3
0
    /*******************************************************************************
    * Function Name: USBFS_1_PutString
    ********************************************************************************
    *
    * Summary:
    *  Sends a null terminated string to the PC.
    *
    * Parameters:
    *  string: pointer to the string to be sent to the PC
    *
    * Return:
    *  None.
    *
    * Global variables:
    *   USBFS_1_cdc_data_in_ep: CDC IN endpoint number used for sending
    *     data.
    *
    * Reentrant:
    *  No.
    *
    * Theory:
    *  This function will block if there is not enough memory to place the whole
    *  string, it will block until the entire string has been written to the
    *  transmit buffer.
    *
    *******************************************************************************/
    void USBFS_1_PutString(const char8 string[]) 
    {
        uint16 str_length;
        uint16 send_length;
        uint16 buf_index = 0u;

        /* Get length of the null terminated string */
        str_length = USBFS_1_StrLen(string);
        do
        {
            /* Limits length to maximum packet size for the EP */
            send_length = (str_length > USBFS_1_EP[USBFS_1_cdc_data_in_ep].bufferSize) ?
                          USBFS_1_EP[USBFS_1_cdc_data_in_ep].bufferSize : str_length;
             /* Enable IN transfer */
            USBFS_1_LoadInEP(USBFS_1_cdc_data_in_ep, (const uint8 *)&string[buf_index], send_length);
            str_length -= send_length;

            /* If more data are present to send */
            if(str_length > 0u)
            {
                buf_index += send_length;
                /* Wait for the Host to read it. */
                while(USBFS_1_EP[USBFS_1_cdc_data_in_ep].apiEpState ==
                                          USBFS_1_IN_BUFFER_FULL)
                {
                    ;
                }
            }
        }while(str_length > 0u);
    }
Beispiel #4
0
void SendOutData(uint8 buffer[])
{
   if(USBFS_1_GetEPState(IN_EP) != USBFS_1_IN_BUFFER_EMPTY);
   {
      while(USBFS_1_GetEPState(IN_EP) != USBFS_1_IN_BUFFER_EMPTY);
      /* Load the IN buffer (this requires host request)*/
      USBFS_1_LoadInEP(IN_EP, &buffer[0u], BUF_SIZE);
   }
}
Beispiel #5
0
 /*******************************************************************************
 * Function Name: USBFS_1_PutData
 ********************************************************************************
 *
 * Summary:
 *  Sends a specified number of bytes from the location specified by a
 *  pointer to the PC.
 *
 * Parameters:
 *  pData: pointer to the buffer containing data to be sent.
 *  length: Specifies the number of bytes to send from the pData
 *  buffer. Maximum length will be limited by the maximum packet
 *  size for the endpoint.
 *
 * Return:
 *  None.
 *
 * Global variables:
 *   USBFS_1_cdc_data_in_ep: CDC IN endpoint number used for sending
 *     data.
 *
 * Reentrant:
 *  No.
 *
 *******************************************************************************/
 void USBFS_1_PutData(uint8* pData, uint16 length) 
 {
     /* Limits length to maximim packet size for the EP */
     if(length > USBFS_1_EP[USBFS_1_cdc_data_in_ep].bufferSize)
     {
         length = USBFS_1_EP[USBFS_1_cdc_data_in_ep].bufferSize;
     }
     USBFS_1_LoadInEP(USBFS_1_cdc_data_in_ep, pData, length);
 }
Beispiel #6
0
 /*******************************************************************************
 * Function Name: USBFS_1_PutData
 ********************************************************************************
 *
 * Summary:
 *  Sends a specified number of bytes from the location specified by a
 *  pointer to the PC.
 *
 * Parameters:
 *  pData: pointer to the buffer containing data to be sent.
 *  length: Specifies the number of bytes to send from the pData
 *  buffer. Maximum length will be limited by the maximum packet
 *  size for the endpoint.
 *
 * Return:
 *  None.
 *
 * Global variables:
 *   USBFS_1_cdc_data_in_ep: CDC IN endpoint number used for sending
 *     data.
 *
 * Reentrant:
 *  No.
 *
 *******************************************************************************/
 void USBFS_1_PutData(const uint8* pData, uint16 length) 
 {
     /* Limits length to maximum packet size for the EP */
     if(length > USBFS_1_EP[USBFS_1_cdc_data_in_ep].bufferSize)
     {
         /* Caution: Data will be lost if length is greater than Max Packet Length */
         length = USBFS_1_EP[USBFS_1_cdc_data_in_ep].bufferSize;
          /* Halt CPU in debug mode */
         CYASSERT(0u != 0u);
     }
     USBFS_1_LoadInEP(USBFS_1_cdc_data_in_ep, pData, length);
 }
Beispiel #7
0
void main()
{
    uint8 counter = 0u;
    
    /* Enable Global Interrupts */
    CyGlobalIntEnable;
    
    /* Set user defined Serial Number string descriptor */
    //USBFS_1_SerialNumString(&bSNstring[0u]);
    
    /* Start USBFS device 0 with 3V operation */
    USBFS_1_Start(0u, USBFS_1_5V_OPERATION); 

    /* Wait for Device to enumerate */
    while(!USBFS_1_GetConfiguration());

    /* Enumeration is done, load endpoint 1. Do not toggle the first time. */
    USBFS_1_LoadInEP(MOUSE_ENDPOINT, mouseData, MOUSE_DATA_LEN);
    
    while(1)
    {
        /* Wait for ACK before loading data */
        while(!USBFS_1_GetEPAckState(MOUSE_ENDPOINT));
        
        /* ACK has occurred, load the endpoint and toggle the data bit */
        USBFS_1_LoadInEP(1u, mouseData, MOUSE_DATA_LEN);
        
        /* When our counts hits 128 */
        if(counter == 128u)
        {
            /* Start moving the mouse to the right */
            mouseData[1u] = 40u;
            //mouseData[2u] |= 0x01;
            //mouseData[2u] &= ~0x01;
            
            mouseData[2u] |= 0x01;
            mouseData[2u] |= 0x02;
            mouseData[2u] |= 0x04;
            //mouseData[2u] |= 0x03;
            //mouseData[2u] &= ~0x03;
            //mouseData[2u] |= 0x04;
            //mouseData[2u] &= ~0x04;
            //mouseData[2u] |= 0x05;
            //mouseData[2u] &= ~0x05;
        }
        else if(counter == 255u)
        {
            /* Start moving the mouse to the left */
            //mouseData[1u] = (uint8)-(int8)CURSOR_STEP;
            //mouseData[2u] &= ~0x01;
            //mouseData[2u] &= ~0x02;
            mouseData[2u] &= ~0x04;
            mouseData[1u] = 0u;
        }
        //CyDelay(200);
        /*mouseData[2u] &= ~0x02;
        CyDelay(200);
        mouseData[2u] &= ~0x03;
        CyDelay(200);
        mouseData[2u] &= ~0x04;
        CyDelay(200);
        mouseData[2u] &= ~0x05;
        CyDelay(200);*/
        //}

        counter++;
    }
}
Beispiel #8
0
    /*******************************************************************************
    * Function Name: USBFS_1_PutCRLF
    ********************************************************************************
    *
    * Summary:
    *  Sends a carriage return (0x0D) and line feed (0x0A) to the PC
    *
    * Parameters:
    *  None.
    *
    * Return:
    *  None.
    *
    * Global variables:
    *   USBFS_1_cdc_data_in_ep: CDC IN endpoint number used for sending
    *     data.
    *
    * Reentrant:
    *  No.
    *
    *******************************************************************************/
    void USBFS_1_PutCRLF(void) 
    {
        const uint8 CYCODE txData[] = {0x0Du, 0x0Au};

        USBFS_1_LoadInEP(USBFS_1_cdc_data_in_ep, (uint8 *)txData, 2u);
    }
Beispiel #9
0
 /*******************************************************************************
 * Function Name: USBFS_1_PutChar
 ********************************************************************************
 *
 * Summary:
 *  Writes a single character to the PC.
 *
 * Parameters:
 *  txDataByte: Character to be sent to the PC.
 *
 * Return:
 *  None.
 *
 * Global variables:
 *   USBFS_1_cdc_data_in_ep: CDC IN endpoint number used for sending
 *     data.
 *
 * Reentrant:
 *  No.
 *
 *******************************************************************************/
 void USBFS_1_PutChar(char8 txDataByte) 
 {
     USBFS_1_LoadInEP(USBFS_1_cdc_data_in_ep, (uint8 *)&txDataByte, 1u);
 }