Ejemplo n.º 1
0
void usb_init() {
  // If they are present, configure Vbus & Wake-up pins
  unsigned int priority = 0;
  #ifdef AT91C_ID_PIOD_E
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOD_E;
    AT91C_BASE_PIOD->PIO_ISR;
    AT91C_BASE_PIOD->PIO_IDR = 0xFFFFFFFF;
    AT91C_BASE_PIOE->PIO_ISR;
    AT91C_BASE_PIOE->PIO_IDR = 0xFFFFFFFF;
    IRQ_ConfigureIT(AT91C_ID_PIOD_E, priority, PIO_IT_InterruptHandler);
    IRQ_EnableIT(AT91C_ID_PIOD_E);
  #endif

  // If there is on board power, switch it off
  #ifdef PIN_USB_POWER_ENB
  { const Pin pinUsbPwr = PIN_USB_POWER_ENB;
    PIO_Configure(&pinUsbPwr, 1);
  }
  #endif
  
  // BOT driver initialization
  CDCDSerialDriver_Initialize();

  // connect if needed
  VBUS_CONFIGURE();

  // Connect pull-up, wait for configuration
  USBD_Connect();
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
/// Initializes drivers and start the USB <-> Serial bridge.
//------------------------------------------------------------------------------
void samserial_init()
{
    //TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
//    printf("-- USB Device CDC Serial Project %s --\n\r", SOFTPACK_VERSION);
//    printf("-- %s\n\r", BOARD_NAME);
//    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);


    CDCDSerialDriver_Initialize();

    // connect if needed
    VBUS_CONFIGURE();
    // Connect pull-up, wait for configuration
    USBD_Connect();
    
    // Driver loop
        while (USBD_GetState() < USBD_STATE_CONFIGURED) {
            if (isSerialConnected)
                isSerialConnected = 0;
        }
        isSerialConnected = 1;
        // Start receiving data on the USB
        CDCDSerialDriver_Read(usbBuffer,DATABUFFERSIZE,(TransferCallback) UsbDataReceived,0);
       
}
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
/// Initializes the CCID driver and runs it.
/// \return Unused (ANSI-C compatibility)
//------------------------------------------------------------------------------
int main( void )
{
    // Initialize traces
    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    printf("-- USB Device CCID Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);

    // Configure IT on Smart Card
    ConfigureCardDetection();

    // Configure ISO7816 driver
    PIO_Configure(pinsISO7816, PIO_LISTSIZE(pinsISO7816));
    PIO_Configure(pinsPower, PIO_LISTSIZE(pinsPower));

    /* power up the card */
    PIO_Set(&pinsPower[0]);

    ISO7816_Init( pinIso7816RstMC );

    // USB audio driver initialization
    CCIDDriver_Initialize();

    // connect if needed
    VBUS_CONFIGURE();
    while (USBD_GetState() < USBD_STATE_CONFIGURED);

    CCID_Insertion();

    // Infinite loop
    while (1) {

        if( USBState == STATE_SUSPEND ) {
            TRACE_DEBUG("suspend  !\n\r");
            LowPowerMode();
            USBState = STATE_IDLE;
        }
        if( USBState == STATE_RESUME ) {
            // Return in normal MODE
            TRACE_DEBUG("resume !\n\r");
            NormalPowerMode();
            USBState = STATE_IDLE;
        }
        CCID_SmartCardRequest();
    }
    return 0;
}
Ejemplo n.º 4
0
/**
 * @brief Initializes USB 0
 *
 * This function initializes the USB0 Channel and the ring buffer parameters.
 *
 */
void sio_usb_0_init(void)
{
    usb_0_buffer.tx_buf_head = 0;
    usb_0_buffer.tx_buf_tail = 0;
    usb_0_buffer.tx_count = 0;

    usb_0_buffer.rx_buf_head = 0;
    usb_0_buffer.rx_buf_tail = 0;
    usb_0_buffer.rx_count = 0;

    usb_0_rx_disable_flag = 1; //disable rx for startup

    /* CDC serial driver initialization */
    CDCDSerialDriver_Initialize();

    /* connect if needed */
    VBUS_CONFIGURE();

    while (USBD_GetState() < USBD_STATE_CONFIGURED)
        ;

    CDCDSerialDriver_Read(usb_0_rx_temp_buf, sizeof(usb_0_rx_temp_buf),
            (TransferCallback) usb0_rx_complete_handler, 0);
}
Ejemplo n.º 5
0
int main(void)
{
    unsigned char bmButtons = 0;

    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    printf("-- USB Device HID Mouse Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    // SPP +
    int i;

    button_flag = 0;

    //Enable RESET
    m_pRSTC->RSTC_RCR = 0xA5000008;
    m_pRSTC->RSTC_RMR = 0xA5000001;
    Delay(1000);

    // Init USB device
    //AT91F_USB_Open();

    // Configure the RTT:
    *AT91C_RTTC_RTMR = BUTTON_SAMPLING;

    // Set in PIO mode and Configure in Input
    //AT91F_PIOA_CfgPMC();

    // InitMAM
    InitMMA();

    // InitADC
    ADCInit();

    // UART0 Init
    InitUSART0();

    // Stat led
    s_pPio->PIO_PER   = BIT31;
    // Configure PA31 as output
    s_pPio->PIO_OER   = BIT31;
    // Set PA31 to HIGH
    s_pPio->PIO_SODR  = BIT31;


    // Test flash
    if(TestFlash()) 
    {
      for(i=0; i<20; i++) 
      {
        s_pPio->PIO_CODR  = BIT31; Delay(150000);
        s_pPio->PIO_SODR  = BIT31; Delay(150000);
      }
    }

    // Button
    // Configure P20 as input
    s_pPio->PIO_ODR   = BIT20;
    // Enable
    s_pPio->PIO_PER   = BIT20;

    Delay(1000);

    // CALIBRATE WHEN BUTT IS PRESS
    // while((s_pPio->PIO_PDSR&BIT20)==BIT20);

    Delay(1000);
    // SPP -

    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);

    WAKEUP_CONFIGURE();

    // If there is on board power, switch it off
  #ifdef PIN_USB_POWER_ENB
  { const Pin pinUsbPwr = PIN_USB_POWER_ENB;
    PIO_Configure(&pinUsbPwr, 1);
  }
  #endif

    // Initialize key statuses and configure push buttons
#if defined(at91cap9dk)
    const Pin pinRow0 = PIN_KEYBOARD_ROW0;
    PIO_Configure(&pinRow0, 1);
#endif       
    PIO_Configure(pinsJoystick, PIO_LISTSIZE(pinsJoystick));

    // HID driver initialization
    HIDDMouseDriver_Initialize();

    // connect if needed
    VBUS_CONFIGURE();
    
    // Infinite loop
    while (1) 
    {
       // SPP +
       #define TIMEOUT  100
       static int Timeout = TIMEOUT;
        GetCoordinates();
        base_y = Coordinates[0]/NSAMPLE;
        base_x = Coordinates[1]/NSAMPLE;
        base_z = Coordinates[2]/NSAMPLE;
       // SPP -

        if( USBState == STATE_SUSPEND ) 
        {
            TRACE_DEBUG("suspend  !\n\r");
            USBState = STATE_IDLE;
            LowPowerMode();
        }
        if( USBState == STATE_RESUME ) 
        {
            // Return in normal MODE
            NormalPowerMode();
            USBState = STATE_IDLE;
            TRACE_DEBUG("resume !\n\r");
        }
        if (USBD_GetState() < USBD_STATE_CONFIGURED)
            continue;

        if (!Timeout)
        {
        
            unsigned char status;

            do 
            {
               status = HIDDMouseDriver_ChangePoints(bmButtons, base_x, base_y);
            }
            while (status != USBD_STATUS_SUCCESS);
            Timeout = TIMEOUT;
        }
        else
           Timeout--;
        
    }
}
Ejemplo n.º 6
0
//-----------------------------------------------------------------------------
/// Initializes drivers and start the USB composite device.
//-----------------------------------------------------------------------------
int main()
{
    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
    printf("-- USB Composite Device Project %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    // If they are present, configure Vbus & Wake-up pins
    PIO_InitializeInterrupts(0);

    // ----- HID Function Initialize
    // Initialize key statuses and configure push buttons
    PIO_Configure(pinsPushButtons, PIO_LISTSIZE(pinsPushButtons));
    memset(keyStatus, 1, NUM_KEYS);

    // Configure LEDs
    LED_Configure(LED_NUMLOCK);

    // ----- CDC Function Initialize
    // Configure USART
    PIO_Configure(pinsUsart, PIO_LISTSIZE(pinsUsart));
    AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_US0;
    AT91C_BASE_US0->US_IDR = 0xFFFFFFFF;
    USART_Configure(AT91C_BASE_US0,
                    USART_MODE_ASYNCHRONOUS,
                    115200,
                    MCK);
    USART_SetTransmitterEnabled(AT91C_BASE_US0, 1);
    USART_SetReceiverEnabled(AT91C_BASE_US0, 1);
    AIC_ConfigureIT(AT91C_ID_US0, 0, ISR_Usart0);
    AIC_EnableIT(AT91C_ID_US0);

    // Configure timer 0
    AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_TC0);
    AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
    AT91C_BASE_TC0->TC_IDR = 0xFFFFFFFF;
    AT91C_BASE_TC0->TC_CMR = AT91C_TC_CLKS_TIMER_DIV5_CLOCK
                             | AT91C_TC_CPCSTOP
                             | AT91C_TC_CPCDIS
                             | AT91C_TC_WAVESEL_UP_AUTO
                             | AT91C_TC_WAVE;
    AT91C_BASE_TC0->TC_RC = 0x00FF;
    AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS;
    AIC_ConfigureIT(AT91C_ID_TC0, 0, ISR_Timer0);
    AIC_EnableIT(AT91C_ID_TC0);

    // USB COMPOSITE driver initialization
    COMPOSITEDDriver_Initialize();

    WAKEUP_CONFIGURE();

    // connect if needed
    VBUS_CONFIGURE();

    // Driver loop
    while (1) {

        // Device is not configured
        if (USBD_GetState() < USBD_STATE_CONFIGURED) {

            // Connect pull-up, wait for configuration
            USBD_Connect();
            while (USBD_GetState() < USBD_STATE_CONFIGURED);

            // Start receiving data on the USART
            usartCurrentBuffer = 0;
            USART_ReadBuffer(AT91C_BASE_US0, usartBuffers[0], DATABUFFERSIZE);
            USART_ReadBuffer(AT91C_BASE_US0, usartBuffers[1], DATABUFFERSIZE);
            AT91C_BASE_US0->US_IER = AT91C_US_ENDRX
                                     | AT91C_US_FRAME
                                     | AT91C_US_OVER;
            AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;

            // Start receiving data on the USB
            CDCDSerialDriver_Read(0, usbSerialBuffer0,
                                  DATABUFFERSIZE,
                                  (TransferCallback) UsbDataReceived0,
                                  0);
        }
        else {

            HIDDKeyboardProcessKeys();
        }
        if( USBState == STATE_SUSPEND ) {
            TRACE_DEBUG("suspend  !\n\r");
            LowPowerMode();
            USBState = STATE_IDLE;
        }
        if( USBState == STATE_RESUME ) {
            // Return in normal MODE
            TRACE_DEBUG("resume !\n\r");
            NormalPowerMode();
            USBState = STATE_IDLE;
        }
    }
}