#include "usblib/usbd.h"
//driverlib-Header
#include <sysctl.h>
#include <gpio.h>
namespace Device{
void init() {
#ifdef _FLASH
extern unsigned RamfuncsLoadStart;
extern unsigned RamfuncsLoadSize;
// Copy time critical code and flash setup code to RAM.
std::memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
// Call Flash Initialization to setup flash waitstates.
// This function must reside in RAM.
Flash_initModule(FLASH0CTRL_BASE, FLASH0ECC_BASE, 3);
#endif
SysCtl_setClock(
SYSCTL_OSCSRC_XTAL // 10-MHz-Quarz
| SYSCTL_IMULT(40) // × 40 = 400 MHz
| SYSCTL_SYSDIV(2) // ÷ 2 = 200 MHz
| SYSCTL_PLL_ENABLE);
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_USBA);
}
}
// Error handling function to be called when an ASSERT is violated
// Must have C linkage, called by usb.lib
extern "C" void __error__(const char*filename, uint32_t line, const char*reason) {
// An ASSERT condition was evaluated as false. You can use the filename and
// line parameters to determine what went wrong.
ESTOP0;
}
namespace usb{
void GPIOEnable() { // Set the USB DM and DP.
GPIO_setMasterCore(42, GPIO_CORE_CPU1);
GPIO_setAnalogMode(42, GPIO_ANALOG_ENABLED);
GPIO_setMasterCore(43, GPIO_CORE_CPU1);
GPIO_setAnalogMode(43, GPIO_ANALOG_ENABLED);
}
}
//usb:: { tMyDevice -> tDevice }
usb::tMyDevice gMyDevice;
void MoveHandler() {
char dx=0, dy=0;
static unsigned tickcount;
switch (++tickcount>>6&3) {
case 0: dx = 1; break;
case 1: dy = 1; break;
case 2: dx =-1; break;
default:dy =-1; break;
}
gMyDevice.StateChange(0, dx, dy);
}
int main() {
Device::init();
#if 1 // mit DriverLib
SysCtl_setAuxClock(SYSCTL_OSCSRC_XTAL // 10-MHz-Quarz
| SYSCTL_PLL_ENABLE
| SYSCTL_IMULT(12) // × 12 => 120 MHz
| SYSCTL_SYSDIV(2)); // ÷ 2 => 60 MHz für USB
#else // mit device_support
#include <F2837xD_device.h>
EALLOW;
ClkCfgRegs.CLKSRCCTL2.all=1; // Quelle = Externer 10-MHz-Oszillator
SysCtl_delay(38); // 200 CPU-Takte warten: 9 Takte + 38×5 Takte
ClkCfgRegs.AUXPLLMULT.all=12; // 10 MHz × 12 = 120 MHz
// ClkCfgRegs.AUXCLKDIVSEL.all|=1; // steht schon auf /2 nach RESET
while (!ClkCfgRegs.AUXPLLSTS.bit.LOCKS);
ClkCfgRegs.AUXPLLCTL1.bit.PLLCLKEN=1;
EDIS;
#endif
usb::GPIOEnable();
gMyDevice.Init();
uint32_t t=gMyDevice.sofcnt;
for(;;) {
gMyDevice.poll();
if (gMyDevice.sofcnt-t>=10) {
t+=10; // If it is time to move the mouse then do so.
MoveHandler();
}
}
}
Vorgefundene Kodierung: UTF-8 | 0
|