Esempio n. 1
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
  SetupHardware();
  uint16_t bytesAvailable, currentByte;

  CDC_Device_CreateStream(&tpad_CDC_Interface, &USBSerialStream);
  sei();

  for (;;)
  {

    //
    // Read pressures from 16 buttons
    //
    ButtonStates();

    //
    // Handle incoming bytes
    //
    bytesAvailable = CDC_Device_BytesReceived(&tpad_CDC_Interface);
    while (bytesAvailable--) {
      currentByte = CDC_Device_ReceiveByte(&tpad_CDC_Interface);
      // TODO: implement led updates from host
    }

    CDC_Device_USBTask(&tpad_CDC_Interface);
    USB_USBTask();
  }
}
Esempio n. 2
0
void main(void)  
{
    // Initialize Pull Up/Down ressistors
    //Port_0_Data_SHADE = 0x80;                     // Enable distance input pull-up P0.7
    //PRT0DR = Port_0_Data_SHADE;
    Port_2_Data_SHADE = 0x04;                     // Enable pull-down resistor on LED P2.2
    PRT2DR = Port_2_Data_SHADE;
    Port_3_Data_SHADE = 0x20;                     // Enable pull-up on button bit P3.5 
    PRT3DR = Port_3_Data_SHADE;
    Port_4_Data_SHADE = 0x44;						// Enable pull-down LED P4.2, P4.6
    PRT4DR = Port_4_Data_SHADE;

    Timer8_WritePeriod(50);				// 12MHz/15/16/50 = 1KHz => 1ms main timer interrupt
    Timer8_WriteCompareValue(0);
    Timer8_EnableInt();
    Timer8_Start();
	PRS8_WritePolynomial(0x78);			// load the PRS polynomial
	PRS8_WriteSeed(0xFF);				// load the PRS seed
	PRS8_Start();						// start the PRS8
	RED_Start();
	GREEN_Start();
	BLUE_Start();
    PWM8_WritePeriod(100);				// set period to eight clocks
    PWM8_WritePulseWidth(0); 			// set pulse width to generate a % duty cycle 
    PWM8_EnableInt(); 					// ensure interrupt is enabled  
    PWM8_Start();						// start PWM 
    //DAC_CR &= ~0x80;	                // turn off SplitMUX bit 7 (P0[7] on right, others on left)    
    PGA_Start(PGA_HIGHPOWER);           // Start PGA
    ADCINC_Start(ADCINC_HIGHPOWER);     // Start ADC
    ADCINC_GetSamples(1);               // initiate the first sample
	
    M8C_EnableGInt;						// Global interrupt enable
  
	ReadFlash();						// read on/off times and LED dutycyle from FLASH
    if(!(RamFlashBlock.Dummy == 0x55))
    {
        SetFlashDefaults();             // clear flash first time
    } 

	LedPowerTog = 1;						// flag change				
	LedPower = RamFlashBlock.PowerState;
    RedDutyMax = RamFlashBlock.RedDuty;
    BlueDutyMax = RamFlashBlock.BlueDuty;
    GreenDutyMax = RamFlashBlock.GreenDuty;
	the_state = RamFlashBlock.the_state;		
	ledChangeRate = RamFlashBlock.ledChangeRate;
	
    Events.press = 0;
    Events.hold = 0;
    Events.release = 0;  	
    MenuFsm(&Events, &the_state);       // initlaize the state machine 
	
    USB_Start(0, USB_3V_OPERATION);     // Start USB
    //while (!USB_bGetConfiguration());   // Wait to be enumerated
    USB_INT_REG |= USB_INT_SOF_MASK;
    USB_EnableOutEP(1);                 // Post a buffer to wait for a command
			    
    while(1)                            // cycle the puck here
    {       
        MeasureTemperature();               // sample input temperature sensor voltage
        ThermalProtection();                 // decrease LED power if temperature rises above limit
		ButtonStates();                    // button driver
        CommunicateUSB();                       // USB driver
		LedStates();						// LED Cadence state machine
		DelayedSaveFlash();					// Save power state and RGB dutycycle 10 seconds after last button event
	}
}