void DRV8834_Go(unsigned char steps)
{
	u8 i = 0;
	for(i=0;i<steps;i++)
	{
		GPIO_ResetBit(6,6);
		delayus(500);
		GPIO_SetBit(6,6);				//制造上升沿
		delayus(500);					//STEP频率不大于250KHz
	}
}
Esempio n. 2
0
static void wifi_callback(uint8_t value)
{
  NABTO_LOG_INFO(("WIFI callback: value = 0x%x", value));
    
  switch(value)
  {
    case CONN_STATUS_LINKED:
      linkIsUp = true;
      GPIO_ClrBit(LED_LINK_PORT, LED_LINK_PIN);
      break;
    case CONN_STATUS_DIS:
      linkIsUp = false;
      GPIO_SetBit(LED_LINK_PORT, LED_LINK_PIN);
      break;
  }
}
Esempio n. 3
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main (void)
{
	SYS_SetClockDivider_0(CLK_CLKDIV0_USB_MASK, USB_CLK_DIVIDER(1));

	/* PB[5] indicates the output voltage of level-shifter */
	GPIOB->PMD = (GPIOB->PMD & ~0xC00) | 0x400;
	//DrvGPIO_ClrBit(E_GPB, 5);			// 3V
	GPIO_SetBit(GPIOB, 5);				// 5V

	printf("+-----------------------------------------------+\n");
	printf("|          NANO100 USB CCID Sample Code         |\n");
	printf("+-----------------------------------------------+\n");					  

	printf("NANO100 USB CCID Start!\n");

	/* Select SC Clock Source From 12MHz */
	CLK->CLKSEL2 = (CLK->CLKSEL2 & ~CLK_CLKSEL2_SC_MASK) | CLK_CLKSEL2_SC_HXT;

	/* Set SC Clock divider which divide by 3 to 4Mhz be used */
	CLK->CLKDIV0 = (CLK->CLKDIV0 & ~CLK_CLKDIV0_SC0_MASK) | (2 << 28);
	CLK->CLKDIV1 = (CLK->CLKDIV1 & ~CLK_CLKDIV1_SC1_MASK) | 2;

	MFP_SC0_TO_PORTA();
	//MFP_SC1_TO_PORTC();
	//MFP_SC1_TO_PORTD();  // NuTiny
	
	/* SmartCard 0 Initialization */	
	SMARTCARD_Init(SC0, 1);
	SMARTCARD_PowerActiveLevel(SC0, 0);	// Power pin is active LOW
	SMARTCARD_Open(SC0);

	/* SmartCard 1 Initialization */
	//SMARTCARD_Init(SC1, 1);
	//SMARTCARD_PowerActiveLevel(SC1, 1);	// Power pin is active LOW
	//SMARTCARD_IgnoreCardAbsent(SC1);		// card 1 is always present
	//SMARTCARD_Open(SC1);

	/* Execute CCID process */
	CCID_MainProcess();
}
Esempio n. 4
0
bool platform_initialize(void* tcb)
{
  OS_ERR osErr;
  
  mainTcb = tcb;
  
  SYS_Init();
  
  GPIO_SetBit(LED_LINK_PORT, LED_LINK_PIN);
  GPIO_Open(LED_LINK_PORT, GPIO_PMD_PMD8_OUTPUT, GPIO_PMD_PMD8_MASK);
  
#if NABTO_ENABLE_LOGGING
  uart_initialize(115200);
#endif
  
  // Initialize OS tick system
  OS_CPU_SysTickInit(SYS_GetHCLKFreq() / OS_CFG_TICK_RATE_HZ);
  
  OSSemCreate(&loggingSemaphore, NULL, 1, &osErr);
  if(osErr != OS_ERR_NONE)
  {
    NABTO_LOG_FATAL(("Unable to create logging semaphore"));
  }
  
  NABTO_LOG_INFO(("Initializing..."));
    
  if (RAK_DriverInit() != RAK_OK)
  {
    NABTO_LOG_FATAL(("Platform initialize failed!"));
  }

  {
    char mac[6];
    if (RAK_GetMacAddr(mac) != RAK_OK)
    {
      NABTO_LOG_FATAL(("RAK_GetMacAddr() failed!"));
    }
    NABTO_LOG_INFO(("MAC: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]));
  }
  
  {
    RAK_CONNECT param;
    param.mode = NET_MODE_STA;
    param.sec_mode = PSK_MODE_SEC;
    param.ssid = wifiSsid;
    param.psk = wifiKey;
    param.conn_handle = wifi_callback;
    if (RAK_ConnectAP(&param) != RAK_OK)
    {
      NABTO_LOG_FATAL(("Wifi connect error!"));
    }
  }

  while(linkIsUp == false); // wait for callback to set connection status

  {
    RAK_IPCONFIG dhcp;
    
    if (RAK_IPConfigDHCP(&dhcp) != RAK_OK)
    {
      NABTO_LOG_FATAL(("DHCP error!"));
    }
    
    localAddress = dhcp.addr;
    localMask = dhcp.mask;
    gateway = dhcp.gw;
    dnsServer = dhcp.dnsrv1;
    NABTO_LOG_TRACE(("DHCP: Address=" PRI_IP " mask=" PRI_IP " gateway=" PRI_IP " DNS=" PRI_IP, PRI_IP_FORMAT(localAddress), PRI_IP_FORMAT(localMask), PRI_IP_FORMAT(gateway), PRI_IP_FORMAT(dnsServer)));
  }
  
  memset(sockets, 0, sizeof(sockets));
  
  sendBuffer = RAK_SendMalloc(SEND_BUFFER_SIZE);
  
  return true;
}
Esempio n. 5
0
//#if K20D_EXT_SRAM
void EXT_SRAM_Configuration(void)
{
	PORT_ClkEn ( PORTA );
	PORT_ClkEn ( PORTB );
	PORT_ClkEn ( PORTC );
	PORT_ClkEn ( PORTD );

	/* Configure the pins needed to FlexBus Function (Alt 5) */
	/* this example uses low drive strength settings	   */

	//address/data
	PORT_BitFn ( PORTB, PIN_9, FN_5);				// fb_ad[20]
	PORT_BitFn ( PORTB,PIN_10, FN_5);				// fb_ad[19]
	PORT_BitFn ( PORTB,PIN_11, FN_5);				// fb_ad[18]
	PORT_BitFn ( PORTB,PIN_16, FN_5);				// fb_ad[17]
	PORT_BitFn ( PORTB,PIN_17, FN_5);				// fb_ad[16]
	PORT_BitFn ( PORTB,PIN_18, FN_5);				// fb_ad[15]
	PORT_BitFn ( PORTC, PIN_0, FN_5);				// fb_ad[14]
	PORT_BitFn ( PORTC, PIN_1, FN_5);				// fb_ad[13]
	PORT_BitFn ( PORTC, PIN_2, FN_5);				// fb_ad[12]
	PORT_BitFn ( PORTC, PIN_4, FN_5);				// fb_ad[11]	
	PORT_BitFn ( PORTC, PIN_5, FN_5);				// fb_ad[10]
	PORT_BitFn ( PORTC, PIN_6, FN_5);				// fb_ad[9] 
	PORT_BitFn ( PORTC, PIN_7, FN_5);				// fb_ad[8]// fb_ad[8]
	PORT_BitFn ( PORTC, PIN_8, FN_5);				// fb_ad[7] 
	PORT_BitFn ( PORTC, PIN_9, FN_5);				// fb_ad[6]// fb_ad[6]
	PORT_BitFn ( PORTC,PIN_10, FN_5);				// fb_ad[5]
	PORT_BitFn ( PORTD, PIN_2, FN_5);				// fb_ad[4]
	PORT_BitFn ( PORTD, PIN_3, FN_5);				// fb_ad[3]
	PORT_BitFn ( PORTD, PIN_4, FN_5);				// fb_ad[2]
	PORT_BitFn ( PORTD, PIN_5, FN_5);				// fb_ad[1]
	PORT_BitFn ( PORTD, PIN_6, FN_5);				// fb_ad[0]
	//control signals
//	PORT_BitFn ( PORTC,PIN_16, FN_5);				// fb_be[15:8]
	PORT_BitFn ( PORTC,PIN_17, FN_5);				// fb_be[ 7:0]
	
	PORT_BitFn ( PORTB,PIN_19, FN_5);				// fb_oe_b
	PORT_BitFn ( PORTC,PIN_11, FN_5);				// fb_rw_b
	PORT_BitFn ( PORTD, PIN_0, FN_5);				// fb_ale
//	PORT_BitFn ( PORTC, PIN_3, FN_5);				// fb_clk_out
	
//	PORT_BitFn ( PORTD, PIN_1, FN_5);				// fb_cs0_b
	PORT_BitFn ( PORTC,PIN_18, FN_5);				// fb_cs2_b
#if 1

	//control signals
	//    PORT_BitFn ( PORTC,PIN_16, FN_5 );			    // fb_be[15:8]


#if RS_MODE == 0
	PORT_BitFn ( PORTD, PIN_0, FN_5 );			    // fb_ale
#endif

	//    PORT_BitFn ( PORTC, PIN_3, FN_5 );			    // fb_clk_out     
	//    PORT_BitFn ( PORTD, PIN_1, FN_5 );			    // fb_cs0_b
	//    PORT_BitFn ( PORTC,PIN_18, FN_5 );			    // fb_cs2_b

	PORT_BitFn(PORTD, PIN_1, FN_1 );			    // color lcd cs signal(soft)
	GPIO_BitDir(PTD, IO_1, OUT );			    // dir output
	GPIO_SetBit(PTD, IO_1);
	PORT_BitFn(PORTC, PIN_16, FN_1 );			    // color lcd rs signal(soft)

#if RS_MODE == 1
	GPIO_BitDir(PTC, IO_16, OUT );				    // dir output
#else
	GPIO_BitDir(PTC, IO_16, IN );
#endif
    #endif
	FLEXBUS_ClkEn();
	FLEXBUS_Init(0);

}
Esempio n. 6
0
int main(void)
{
    int32_t i32Err;

    sysDisableCache();
    sysFlushCache(I_D_CACHE);
    sysEnableCache(CACHE_WRITE_BACK);
    sysInitializeUART();

    sysprintf("+-------------------------------------------------+\n");
    sysprintf("|                 GPIO Sample Code                |\n");
    sysprintf("+-------------------------------------------------+\n\n");

    /* Configure Port C to input mode and pull-up */
    GPIO_Open(GPIOC, DIR_INPUT, PULL_UP);
   
    /* Set Port C output data to 0xFFF */
    GPIO_Set(GPIOC, 0xFFF);

    /* Set Port C output data to 0x000 */
    GPIO_Clr(GPIOC, 0xFFF);

    /* Configure Port C to default value */
    GPIO_Close(GPIOC);

    i32Err = 0;
    sysprintf("GPIO PD.3(output mode) connect to PD.4(input mode) ......");

    /* Configure PD3 to output mode */
    GPIO_OpenBit(GPIOD, BIT3, DIR_OUTPUT, NO_PULL_UP);

    /* Configure PD4 to output mode */
    GPIO_OpenBit(GPIOD, BIT4, DIR_INPUT, NO_PULL_UP);

    /* Use Pin Data Input/Output Control to pull specified I/O or get I/O pin status */
    /* Pull PD.3 to High and check PD.4 status */
    GPIO_SetBit(GPIOD, BIT3);

    if(GPIO_ReadBit(GPIOD,BIT4)==0)  
      i32Err = 1;

    /* Pull PD.3 to Low and check PD.4 status */
    GPIO_ClrBit(GPIOD, BIT3);

    if(GPIO_ReadBit(GPIOD,BIT4)==1)  
      i32Err = 1;

    if(i32Err)
    {
        sysprintf("  [FAIL].\n");
    }
    else
    {
        sysprintf("  [OK].\n");
    }

    /* Configure PD3 to default value */
    GPIO_CloseBit(GPIOD, BIT3);

    /* Configure PD4 to default value */
    GPIO_CloseBit(GPIOD, BIT3);

    /* Set MFP_GPF11 to EINT0 */
    outpw(REG_SYS_GPF_MFPH,(inpw(REG_SYS_GPF_MFPH) & ~(0xF<<12)) | (0xF<<12));

    /* Configure PF11 to input mode and pull-up */
    GPIO_OpenBit(GPIOF, BIT11, DIR_INPUT, PULL_UP);

    /* Confingure PF11 to rising-edge trigger */
    GPIO_EnableTriggerType(GPIOF, BIT11,RISING);

    /* Enable external 0 interrupt */
    GPIO_EnableEINT(NIRQ0, (GPIO_CALLBACK)EINT0Callback, 0);

    /* waiting for external 0 interrupt */
    sysprintf("waiting for PF11 rsing-edge trigger...");
    while(!eint_complete);

    /* Disable PF11 trigger type */
    GPIO_DisableTriggerType(GPIOF, BIT11);

    /* Enable external 0 interrupt */
    GPIO_DisableEINT(NIRQ0);

    sysprintf("  [OK].\n");

    /* Configure PF11 to default value */
    GPIO_CloseBit(GPIOF, BIT11);


    /* Configure PE3 to output mode */
    GPIO_OpenBit(GPIOE, BIT3, DIR_INPUT, NO_PULL_UP);

    /* Confingure PE3 to falling-edge trigger */
    GPIO_EnableTriggerType(GPIOE, BIT3,FALLING);

    /* Enable GPIOE interrupt */
    GPIO_EnableInt(GPIOE, (GPIO_CALLBACK)GPIOECallback, 0);

    /* waiting for external 0 interrupt */
    sysprintf("waiting for PE3 falling-edge trigger...");
    while(!gpio_complete);

    /* Disable PE3 to trigger type */
    GPIO_DisableTriggerType(GPIOE, BIT3);

    /* Disable GPIOE interrupt */
    GPIO_DisableInt(GPIOE);

    /* Configure PE0 to default value */
    GPIO_CloseBit(GPIOE, BIT3);

    sysprintf("  [OK].\n");

    while(1);
}