/** 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(); /* Create a regular blocking character stream for the interface so that it can be used with the stdio.h functions */ CDC_Device_CreateBlockingStream(&VirtualSerial_CDC_Interface, &USBSerialStream); sei(); for (;;) { /* Read in next LED colour command from the host */ uint8_t ColourUpdate = fgetc(&USBSerialStream); /* Top 3 bits select the LED, bottom 5 control the brightness */ uint8_t Channel = (ColourUpdate & 0b11100000); uint8_t Duty = (ColourUpdate & 0b00011111); if (Channel & (1 << 5)) SoftPWM_Channel1_Duty = Duty; if (Channel & (1 << 6)) SoftPWM_Channel2_Duty = Duty; if (Channel & (1 << 7)) SoftPWM_Channel3_Duty = Duty; CDC_Device_USBTask(&VirtualSerial_CDC_Interface); USB_USBTask(); } }
/** Initializes all of the hardware. */ void initialize(void){ CPU_PRESCALE(0x00); //LED DDRE |= (1<<PE2); //RGB LED DDRB |= (1<<PB5) | (1<<PB6); DDRC |= (1<<PC6); /** LUFA USB related inits */ USB_Init(); CDC_Device_CreateBlockingStream (&VirtualSerial_CDC_Interface, &USBSerialStream); touch_init(); pwm16_rgb_init(); /** enable interrupts*/ sei(); }
/** Initializes all of the hardware. */ void initialize(void){ /* Disable watchdog if enabled by bootloader/fuses */ MCUSR &= ~(1 << WDRF); wdt_disable(); /* Disable clock division */ clock_prescale_set(clock_div_1); /* Init SPI */ spi_init(SPIMODE2); /* Init AD9833 */ ad9833_init(); /* LUFA USB related inits */ USB_Init(); CDC_Device_CreateBlockingStream (&VirtualSerial_CDC_Interface, &USBSerialStream); /* enable interrupts*/ sei(); }