Skip to content
Snippets Groups Projects
Commit 55ca5bf8 authored by minute's avatar minute
Browse files

trackball: init usb first, reduce delays; untabify

parent 1b65e81c
No related branches found
No related tags found
No related merge requests found
...@@ -108,20 +108,20 @@ static uint8_t PrevMouseHIDReportBuffer[sizeof(USB_WheelMouseReport_Data_t)]; ...@@ -108,20 +108,20 @@ static uint8_t PrevMouseHIDReportBuffer[sizeof(USB_WheelMouseReport_Data_t)];
* within a device can be differentiated from one another. * within a device can be differentiated from one another.
*/ */
USB_ClassInfo_HID_Device_t Mouse_HID_Interface = USB_ClassInfo_HID_Device_t Mouse_HID_Interface =
{ {
.Config = .Config =
{ {
.InterfaceNumber = INTERFACE_ID_Mouse, .InterfaceNumber = INTERFACE_ID_Mouse,
.ReportINEndpoint = .ReportINEndpoint =
{ {
.Address = MOUSE_EPADDR, .Address = MOUSE_EPADDR,
.Size = MOUSE_EPSIZE, .Size = MOUSE_EPSIZE,
.Banks = 1, .Banks = 1,
}, },
.PrevReportINBuffer = PrevMouseHIDReportBuffer, .PrevReportINBuffer = PrevMouseHIDReportBuffer,
.PrevReportINBufferSize = sizeof(PrevMouseHIDReportBuffer), .PrevReportINBufferSize = sizeof(PrevMouseHIDReportBuffer),
}, },
}; };
void led_error(void) { void led_error(void) {
DDRC = 0b11110100; DDRC = 0b11110100;
...@@ -155,13 +155,13 @@ uint8_t twi_read_buf[10]; ...@@ -155,13 +155,13 @@ uint8_t twi_read_buf[10];
void SetupHardware(void) void SetupHardware(void)
{ {
/* Disable watchdog if enabled by bootloader/fuses */ /* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF); MCUSR &= ~(1 << WDRF);
wdt_disable(); wdt_disable();
// Disable clock division // Disable clock division
// this should yield 8Mhz with internal osc // this should yield 8Mhz with internal osc
clock_prescale_set(clock_div_1); clock_prescale_set(clock_div_1);
DDRD = 0b00000000; DDRD = 0b00000000;
//DDRB = 0b11000110; //DDRB = 0b11000110;
...@@ -177,13 +177,15 @@ void SetupHardware(void) ...@@ -177,13 +177,15 @@ void SetupHardware(void)
//MCUCR |=(1<<JTD); //MCUCR |=(1<<JTD);
//MCUCR |=(1<<JTD); //MCUCR |=(1<<JTD);
i2c_init();
USB_Init(); USB_Init();
Delay_MS(1000); i2c_init();
}
void init_sensor(void) {
Delay_MS(100);
led_error(); led_error();
Delay_MS(1000); Delay_MS(100);
if (!i2c_start(ADDR_SENSOR|I2C_WRITE)) { if (!i2c_start(ADDR_SENSOR|I2C_WRITE)) {
i2c_write(0x7f); i2c_write(0x7f);
...@@ -199,7 +201,6 @@ void SetupHardware(void) ...@@ -199,7 +201,6 @@ void SetupHardware(void)
led_ok(); led_ok();
} }
Delay_MS(100);
} }
/** Event handler for the library USB Connection event. */ /** Event handler for the library USB Connection event. */
...@@ -215,23 +216,23 @@ void EVENT_USB_Device_Disconnect(void) ...@@ -215,23 +216,23 @@ void EVENT_USB_Device_Disconnect(void)
/** Event handler for the library USB Configuration Changed event. */ /** Event handler for the library USB Configuration Changed event. */
void EVENT_USB_Device_ConfigurationChanged(void) void EVENT_USB_Device_ConfigurationChanged(void)
{ {
bool ConfigSuccess = true; bool ConfigSuccess = true;
ConfigSuccess &= HID_Device_ConfigureEndpoints(&Mouse_HID_Interface); ConfigSuccess &= HID_Device_ConfigureEndpoints(&Mouse_HID_Interface);
USB_Device_EnableSOFEvents(); USB_Device_EnableSOFEvents();
} }
/** Event handler for the library USB Control Request reception event. */ /** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void) void EVENT_USB_Device_ControlRequest(void)
{ {
HID_Device_ProcessControlRequest(&Mouse_HID_Interface); HID_Device_ProcessControlRequest(&Mouse_HID_Interface);
} }
/** Event handler for the USB device Start Of Frame event. */ /** Event handler for the USB device Start Of Frame event. */
void EVENT_USB_Device_StartOfFrame(void) void EVENT_USB_Device_StartOfFrame(void)
{ {
HID_Device_MillisecondElapsed(&Mouse_HID_Interface); HID_Device_MillisecondElapsed(&Mouse_HID_Interface);
} }
/** HID class driver callback function for the creation of HID reports to the host. /** HID class driver callback function for the creation of HID reports to the host.
...@@ -254,14 +255,13 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn ...@@ -254,14 +255,13 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
if (*ReportID==0) { if (*ReportID==0) {
*ReportID=2; *ReportID=2;
} }
if (*ReportID==2) { if (*ReportID==2) {
USB_WheelMouseFeatureReport_Data_t* FeatureReport = (USB_WheelMouseFeatureReport_Data_t*)ReportData; USB_WheelMouseFeatureReport_Data_t* FeatureReport = (USB_WheelMouseFeatureReport_Data_t*)ReportData;
FeatureReport->Multiplier = 2; FeatureReport->Multiplier = 2;
*ReportSize = sizeof(USB_WheelMouseFeatureReport_Data_t); *ReportSize = sizeof(USB_WheelMouseFeatureReport_Data_t);
return true; return true;
} else { } else {
led_set(0x2);
return false; return false;
} }
} }
...@@ -269,9 +269,8 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn ...@@ -269,9 +269,8 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
if (*ReportID==0) { if (*ReportID==0) {
*ReportID=1; *ReportID=1;
} }
if (*ReportID!=1) { if (*ReportID!=1) {
led_set(0x1);
return false; return false;
} }
...@@ -306,7 +305,7 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn ...@@ -306,7 +305,7 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
MouseReport->Pan = 0; MouseReport->Pan = 0;
MouseReport->Wheel = 0; MouseReport->Wheel = 0;
if (!(PIND&1) || !(PIND&(1<<2))) { if (!(PIND&1) || !(PIND&(1<<2))) {
// wheel // wheel
MouseReport->Pan = 2*nx; MouseReport->Pan = 2*nx;
...@@ -345,12 +344,18 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI ...@@ -345,12 +344,18 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI
int main(void) int main(void)
{ {
SetupHardware(); int sensor_initialized = 0;
GlobalInterruptEnable();
SetupHardware();
for (;;) GlobalInterruptEnable();
{
HID_Device_USBTask(&Mouse_HID_Interface); for (;;) {
USB_USBTask(); HID_Device_USBTask(&Mouse_HID_Interface);
} USB_USBTask();
if (!sensor_initialized) {
init_sensor();
sensor_initialized = 1;
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment