Esempio n. 1
0
WEAK void mbed_die(void) {
    
#ifndef EMUNO
    CyHalt(1);
    PWM_Start();
    PWM_WriteCompare2(0);
    CyPins_SetPinDriveMode(SW_USER, CY_PINS_DM_RES_UP);
    Bootloadable_SET_RUN_TYPE(0); // do not force bootloader
    
    while(1)
    {
        PWM_WriteCompare1(16);
        CyDelay(250);
        PWM_WriteCompare1(64);
        
        if (CyPins_ReadPin(SW_USER) == 0)
        {
            CyDelay(200); // allow yser to release btn, to not go into bootloader
            CySoftwareReset();
        }
        
        CyDelay(400);
        
        if (CyPins_ReadPin(SW_USER) == 0)
        {
            CyDelay(200); // allow yser to release btn, to not go into bootloader
            CySoftwareReset();
        }
    }
#endif

}
Esempio n. 2
0
/*******************************************************************************
* Function Name: Bootloadable_1_Load
****************************************************************************//**
*
* \brief
*  Schedules the Bootloader/Launcher to be launched and then performs
*  a software reset to launch it
*
* \return
*  This method will never return. It will load a new application and reset
*  the device.
*
*******************************************************************************/
void Bootloadable_1_Load(void)
{
    /* Schedule Bootloader to start after reset */
    Bootloadable_1_SET_RUN_TYPE(Bootloadable_1_SCHEDULE_BTLDR);

    CySoftwareReset();
}
Esempio n. 3
0
void Select( unsigned char ch )
{
			switch (ch ) {
				case 'a':
					Icicle(6,9 , 6);
					break;
				case 'b':
					Sparkler( 100,1,8 ,0);
					break;
				
				case 'c':
					Sparkler(100,1,8 ,1);
					break;
				
				case 'd':
					StripLights_DisplayClear( StripLights_LTGREEN );
					break;
				case 'e':
					StripLights_DisplayClear( StripLights_WHITE );
					break;
				case 'f':
					StripLights_DisplayClear( StripLights_BLUE );
					break;
				case 'g':
					SingleLEDPingPong(1 ,6, getColor(rand()%StripLights_COLOR_WHEEL_SIZE));
					break;
				case 'h':
					Tween1();
					break;
				case 'i':
					ColorFader(1, getColor(rand()%StripLights_COLOR_WHEEL_SIZE));
					break;
				case 'j':
					CandyCane(5, StripLights_RED, StripLights_WHITE );
					break;
				case 'k':
					Snake(5);
					break;
				case 'l':
					ColorWheel(10);
					break;
				case 'm':
					CandyCane(5, getColor(rand()%StripLights_COLOR_WHEEL_SIZE), StripLights_WHITE );
					break;
					
				case 'n':
					CandyCaneSmooth(5, (led_color)getColor(rand()%StripLights_COLOR_WHEEL_SIZE), 
									(led_color)getColor(rand()%StripLights_COLOR_WHEEL_SIZE) );
					break;

				case '0':
					CySoftwareReset();
					break;
			}
}
Esempio n. 4
0
void Icicle (uint8 redraw, uint8 length, int fade_amount )           
 {
    int x,j,i;
	led_color temp;

	// for entire length of strip, plus engough to move it off the display)
	for(x = StripLights_MIN_X; x <= StripLights_MAX_X + ( length * 2 ); x++)
	{
		
		if(fade_amount ) {
			// Fade  strip	
			FadeStrip( StripLights_MIN_X, StripLights_MAX_X , fade_amount );
		} else { 
			StripLights_MemClear(0);
		}
		
		
		// draw in same place 8 times
		for ( j = 0 ; j < redraw ;j++ ){
			
			// length of icicle
			for(i=0; i < length; i++)
			{
				// caculate a randow twink based on current position in length
				temp.c.r =
				temp.c.g =
				temp.c.b = calculate_sparkle( i  );

				// draw a pixel at x+i
			    StripLights_Pixel(x+i, 0, temp.rgb );
				
				CyDelay( 1 );  
		 	}    
			    
		    // strip ready?
			while( StripLights_Ready() == 0);
			
			//push current data to led strip
		    StripLights_Trigger(1);
		    CyDelay( 3 );        
		}
		
		// check if firmware load requested
	    if( Boot_P0_7_Read ( ) == 0 )   CySoftwareReset();
	}
}
Esempio n. 5
0
int main()
{

	// striplights component init
    StripLights_Start();
	
	/* Start UART component and clear the TX,RX buffers */
	UART_Start();
	UART_SpiUartClearRxBuffer();

	// Switch on ESP8266's PD function
	CH_PD_SetDriveMode(CH_PD_DM_STRONG ) ;
	CH_PD_Write(1);

	// start UART for esp wifi 
	uWIFI_Start();
	uWIFI_SpiUartClearRxBuffer();
    
	CyGlobalIntEnable;  /* Un/comment this line to dis/enable global interrupts. */

	// LED output
	P1_6_SetDriveMode(P1_6_DM_STRONG ) ;
	
	// LED on.
	P1_6_Write(1);
	
	//cycle each of the primaries on all LED's, DisplayClear sets and pushes to LED's, MemoryClear just clears the buffer.
	StripLights_DisplayClear( StripLights_RED_MASK );	CyDelay( 500 ); 
	StripLights_DisplayClear( StripLights_GREEN_MASK );	CyDelay( 500 ); 
	StripLights_DisplayClear( StripLights_BLUE_MASK );	CyDelay( 500 ); 

	// Set to off
	StripLights_DisplayClear( 0 );

	// uncomment for echo back, useful to setup ESP8266 as well
	//echo_uart();
	
	run_server();
	
	
	//reboot on return
    CySoftwareReset();
    
    return 0;
}
/*******************************************************************************
* Function Name: Bootloader_HostLink
********************************************************************************
*
* Summary:
*  Causes the bootloader to attempt to read data being transmitted by the
*  host application.  If data is sent from the host, this establishes the
*  communication interface to process all requests.
*
* Parameters:
*  timeOut:
*   The amount of time to listen for data before giving up. Timeout is
*   measured in 10s of ms.  Use 0 for an infinite wait.
*
* Return:
*   None
*
*******************************************************************************/
static void Bootloader_HostLink(uint32 timeout) 
{
  uint16    CYDATA numberRead;
  cystatus  CYDATA readStat;
  uint16    bytesToRead;
  uint16    bytesToWrite;  
  uint32    counterVal;
  
  static const uint8 deviceID[7] = {'A','V','R','B', 'O', 'O', 'T'};
  static const uint8 swID[2] = {'1', '0'};
  static const uint8 hwID[2] = {'1', '0'};
  
  uint32 currentAddress = 0;

  uint8     packetBuffer[Bootloader_SIZEOF_COMMAND_BUFFER];

  /* Initialize communications channel. */
  CyBtldrCommStart();
  counterVal = 0;
  do
  {
    do
    {
      readStat = CyBtldrCommRead(packetBuffer,
                                 Bootloader_SIZEOF_COMMAND_BUFFER,
                                 &numberRead,
                                 10);
      counterVal = Reset_Timer_ReadCounter() * -1;
      #ifdef USE_UART
      char dbstring[24];
      sprintf(dbstring,"%ld\r", counterVal);
      UART_PutString(dbstring);
      CyDelay(50);
      #endif
      if (counterVal >= timeout)
      {    
        Bootloader_SET_RUN_TYPE(Bootloader_SCHEDULE_BTLDB);
        CySoftwareReset();
      }
    } while ( readStat != CYRET_SUCCESS );

    Reset_Timer_Stop();
    Reset_Timer_WriteCounter(0);
    Reset_Timer_Start();
    
    switch(packetBuffer[0])
    {
    /*************************************************************************
    *   Set read/write address
    *************************************************************************/
    case 'A':
      currentAddress = packetBuffer[1] << 9;
      currentAddress |= packetBuffer[2] << 1;
      packetBuffer[0] = '\r';
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      break;
      
    /*************************************************************************
    *   Set read/write address
    *************************************************************************/
    case 'H':
      currentAddress = packetBuffer[1] << 17;
      currentAddress |= packetBuffer[2] << 9;
      currentAddress |= packetBuffer[3] << 1;
      packetBuffer[0] = '\r';
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      break;
      
    /*************************************************************************
    *   Erase chip (unimplemented)
    *************************************************************************/
    case 'e':
      break;

    /*************************************************************************
    *   Enter/Leave bootloader mode - UNUSED
    *************************************************************************/
    case 'P':
    case 'L':
      packetBuffer[0] = '\r';
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      break;

    /*************************************************************************
    *   Exit bootloader
    *************************************************************************/
    case 'E':
      /* Normally, the CyBootloader checks the validity of the app here. We will
      *   assume that the app is valid b/c it was checked as it was being
      *   uploaded. */
      Bootloader_SET_RUN_TYPE(Bootloader_SCHEDULE_BTLDB);
      packetBuffer[0] = '\r';
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      while (USBUART_CDCIsReady() == 0)
      { /* wait for USB to finish sending response to the exit command */ }
      CySoftwareReset();
      /* Will never get here */
      break;
      
    /*************************************************************************
    *   Block read
    *************************************************************************/
    case 'g':
      bytesToRead = packetBuffer[1] << 8;
      bytesToRead |= packetBuffer[2];
      int16 idx;
      for(idx = 0u; idx < bytesToRead; idx++)
      {
        packetBuffer[idx] = Bootloader_GET_CODE_BYTE(currentAddress + idx);
      }
      CyBtldrCommWrite(packetBuffer, bytesToRead, NULL, 0);
      break;
      
    /*************************************************************************
    *   Block load
    *************************************************************************/  
    case 'B':
      bytesToWrite = packetBuffer[1]<<8 | packetBuffer[2];
      packetBuffer[0] = BlockLoad(packetBuffer[3], bytesToWrite, \
                                  packetBuffer + 4, currentAddress);
      if ((packetBuffer[0] == '\r') && packetBuffer[3] == 'F')
      {
        currentAddress += bytesToWrite;
      }
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      break;
    /*************************************************************************
    *   Report device ID
    *************************************************************************/
    case 'S':
      CyBtldrCommWrite((uint8*)deviceID, 8, NULL, 0);
      break;
    /*************************************************************************
    *   Report firmware revision
    *************************************************************************/
    case 'V':
      CyBtldrCommWrite((uint8*)swID, 2, NULL, 0);
      break;
    /*************************************************************************
    *   Report programmer type ('S' for "Serial")
    *************************************************************************/
    case 'p':
      packetBuffer[0] = 'S';
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      break;
    /*************************************************************************
    *   Report autoincrement address support ('Y' for "Yes")
    *************************************************************************/
    case 'a':
      packetBuffer[0] = 'Y';
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      break;
    /*************************************************************************
    *   Report block write support ('Y' for "Yes", then two bytes of block size
    *    written MSB first.
    *************************************************************************/
    case 'b':
      packetBuffer[0] = 'Y';
      packetBuffer[1] = 0x01;
      packetBuffer[2] = 0x00;
      CyBtldrCommWrite(packetBuffer, 3, NULL, 0);
      break;
    /*************************************************************************
    *   Report hardware device version
    *************************************************************************/
    case 'v':
      CyBtldrCommWrite((uint8*)hwID, 2, NULL, 0);
      break;
    /*************************************************************************
    *   Report (bogus) part ID, followed by list terminator 0x00.
    *************************************************************************/
    case 't':
      packetBuffer[0] = 0x44;
      packetBuffer[1] = 0;
      CyBtldrCommWrite(packetBuffer, 2, NULL, 0);
      break;
    /*************************************************************************
    *   Report device signature (this is that of the Atmega32u4)
    *************************************************************************/
    case 's':
      packetBuffer[0] = 0x87;
      packetBuffer[1] = 0x95;
      packetBuffer[2] = 0x1e;
      CyBtldrCommWrite(packetBuffer, 3, NULL, 0);
      break;
    /*************************************************************************
    *   Unimplemented fuse AVR fuse register read/write
    *************************************************************************/
    case 'N':  
    case 'Q':
    case 'F':
    case 'r':
      packetBuffer[0] = 0x00;
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      break;
    /*************************************************************************
    *   Unused but implemented in AVRDUDE, so some response needed.
    *************************************************************************/
    case 'T':
    case 'x':
    case 'y':
      packetBuffer[0] = '\r';
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      break;
    /*************************************************************************
    *   Unsupported command
    *************************************************************************/
    default:
      packetBuffer[0] = '?';
      CyBtldrCommWrite(packetBuffer, 1, NULL, 0);
      break;
    }
  } while (1);
}