Created
November 2, 2011 23:57
-
-
Save kevinmehall/1335347 to your computer and use it in GitHub Desktop.
PWM on Xmega
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "usb.h" | |
// PORT C | |
#define PWM1 (1<<0) | |
#define PWM2 (1<<1) | |
int main(void){ | |
sei(); | |
USB_ConfigureClock(); | |
USB_Init(); | |
PORTC.DIRSET = PWM1 | PWM2 | (1<<7); | |
PORTC.OUTSET = (1<<7); | |
PORTC.PIN1CTRL = PORT_INVEN_bm; | |
TCC0.CTRLA = TC_CLKSEL_DIV1_gc; | |
TCC0.CTRLB = TC0_CCAEN_bm | TC0_CCBEN_bm | TC_WGMODE_SINGLESLOPE_gc; | |
TCC0.PER = 1024; | |
TCC0.CCA = 512; | |
TCC0.CCB = 512; | |
TCC0.CNT = 0; | |
while (1){ | |
USB_Task(); | |
} | |
} | |
/** Event handler for the library USB Control Request reception event. */ | |
bool EVENT_USB_Device_ControlRequest(USB_Request_Header_t* req){ | |
if ((req->bmRequestType & CONTROL_REQTYPE_TYPE) == REQTYPE_VENDOR){ | |
if (req->bRequest == 0x02){ | |
TCC0.CCA = TCC0.CCB = req->wValue; | |
USB_ep0_send(0); | |
return true; | |
}else if (req->bRequest == 0x03){ | |
TCC0.PER = req->wValue; | |
USB_ep0_send(0); | |
return true; | |
}else if (req->bRequest == 0xBB){ | |
USB_ep0_send(0); | |
USB_ep0_wait_for_complete(); | |
_delay_us(10000); | |
USB_Detach(); | |
_delay_us(100000); | |
void (*enter_bootloader)(void) = (void *) 0x47fc /*0x8ff8/2*/; | |
enter_bootloader(); | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment