Working.
This commit is contained in:
parent
dc34252dd4
commit
b0c3a802a5
162
main.c
162
main.c
@ -14,35 +14,6 @@
|
|||||||
/* ----------------------------- USB interface ----------------------------- */
|
/* ----------------------------- USB interface ----------------------------- */
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// PROGMEM const char usbHidReportDescriptor[52] = { /* USB report descriptor, size must match usbconfig.h */
|
|
||||||
// 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
|
||||||
// 0x09, 0x02, // USAGE (Mouse)
|
|
||||||
// 0xa1, 0x01, // COLLECTION (Application)
|
|
||||||
// 0x09, 0x01, // USAGE (Pointer)
|
|
||||||
// 0xA1, 0x00, // COLLECTION (Physical)
|
|
||||||
// 0x05, 0x09, // USAGE_PAGE (Button)
|
|
||||||
// 0x19, 0x01, // USAGE_MINIMUM
|
|
||||||
// 0x29, 0x03, // USAGE_MAXIMUM
|
|
||||||
// 0x15, 0x00, // LOGICAL_MINIMUM (0)
|
|
||||||
// 0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
|
||||||
// 0x95, 0x03, // REPORT_COUNT (3)
|
|
||||||
// 0x75, 0x01, // REPORT_SIZE (1)
|
|
||||||
// 0x81, 0x02, // INPUT (Data,Var,Abs)
|
|
||||||
// 0x95, 0x01, // REPORT_COUNT (1)
|
|
||||||
// 0x75, 0x05, // REPORT_SIZE (5)
|
|
||||||
// 0x81, 0x03, // INPUT (Const,Var,Abs)
|
|
||||||
// 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
|
||||||
// 0x09, 0x30, // USAGE (X)
|
|
||||||
// 0x09, 0x31, // USAGE (Y)
|
|
||||||
// 0x09, 0x38, // USAGE (Wheel)
|
|
||||||
// 0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
|
||||||
// 0x25, 0x7F, // LOGICAL_MAXIMUM (127)
|
|
||||||
// 0x75, 0x08, // REPORT_SIZE (8)
|
|
||||||
// 0x95, 0x03, // REPORT_COUNT (3)
|
|
||||||
// 0x81, 0x06, // INPUT (Data,Var,Rel)
|
|
||||||
// 0xC0, // END_COLLECTION
|
|
||||||
// 0xC0, // END COLLECTION
|
|
||||||
// };
|
|
||||||
PROGMEM const char usbHidReportDescriptor[] = { /* USB report descriptor, size must match usbconfig.h */
|
PROGMEM const char usbHidReportDescriptor[] = { /* USB report descriptor, size must match usbconfig.h */
|
||||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
0x09, 0x02, // USAGE (Mouse)
|
0x09, 0x02, // USAGE (Mouse)
|
||||||
@ -63,17 +34,46 @@ PROGMEM const char usbHidReportDescriptor[] = { /* USB report descriptor, size m
|
|||||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
0x09, 0x30, // USAGE (X)
|
0x09, 0x30, // USAGE (X)
|
||||||
0x09, 0x31, // USAGE (Y)
|
0x09, 0x31, // USAGE (Y)
|
||||||
|
0x09, 0x38, // USAGE (Wheel)
|
||||||
0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
||||||
0x25, 0x7F, // LOGICAL_MAXIMUM (127)
|
0x25, 0x7F, // LOGICAL_MAXIMUM (127)
|
||||||
0x75, 0x08, // REPORT_SIZE (8)
|
0x75, 0x08, // REPORT_SIZE (8)
|
||||||
0x95, 0x03, // REPORT_COUNT (2)
|
0x95, 0x03, // REPORT_COUNT (3)
|
||||||
0x81, 0x06, // INPUT (Data,Var,Rel)
|
0x81, 0x06, // INPUT (Data,Var,Rel)
|
||||||
0x09, 0x38, // USAGE (Wheel)
|
|
||||||
0x95, 0x01, // REPORT_COUNT (1)
|
|
||||||
0x81, 0x06, // INPUT (Data, Variable, Relative)
|
|
||||||
0xC0, // END_COLLECTION
|
0xC0, // END_COLLECTION
|
||||||
0xC0, // END COLLECTION
|
0xC0, // END COLLECTION
|
||||||
};
|
};
|
||||||
|
// PROGMEM const char usbHidReportDescriptor[] = { /* USB report descriptor, size must match usbconfig.h */
|
||||||
|
// 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
// 0x09, 0x02, // USAGE (Mouse)
|
||||||
|
// 0xa1, 0x01, // COLLECTION (Application)
|
||||||
|
// 0x09, 0x01, // USAGE (Pointer)
|
||||||
|
// 0xA1, 0x00, // COLLECTION (Physical)
|
||||||
|
// 0x05, 0x09, // USAGE_PAGE (Button)
|
||||||
|
// 0x19, 0x01, // USAGE_MINIMUM
|
||||||
|
// 0x29, 0x03, // USAGE_MAXIMUM
|
||||||
|
// 0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
// 0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||||
|
// 0x95, 0x03, // REPORT_COUNT (3)
|
||||||
|
// 0x75, 0x01, // REPORT_SIZE (1)
|
||||||
|
// 0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
// 0x95, 0x01, // REPORT_COUNT (1)
|
||||||
|
// 0x75, 0x05, // REPORT_SIZE (5)
|
||||||
|
// 0x81, 0x03, // INPUT (Const,Var,Abs)
|
||||||
|
// 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
// 0x09, 0x30, // USAGE (X)
|
||||||
|
// 0x09, 0x31, // USAGE (Y)
|
||||||
|
// 0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
||||||
|
// 0x25, 0x7F, // LOGICAL_MAXIMUM (127)
|
||||||
|
// 0x75, 0x08, // REPORT_SIZE (8)
|
||||||
|
// 0x95, 0x03, // REPORT_COUNT (2)
|
||||||
|
// 0x81, 0x06, // INPUT (Data,Var,Rel)
|
||||||
|
// 0x09, 0x38, // USAGE (Wheel)
|
||||||
|
// 0x95, 0x01, // REPORT_COUNT (1)
|
||||||
|
// 0x81, 0x06, // INPUT (Data, Variable, Relative)
|
||||||
|
// 0xC0, // END_COLLECTION
|
||||||
|
// 0xC0, // END COLLECTION
|
||||||
|
// };
|
||||||
/* This is the same report descriptor as seen in a Logitech mouse. The data
|
/* This is the same report descriptor as seen in a Logitech mouse. The data
|
||||||
* described by this descriptor consists of 4 bytes:
|
* described by this descriptor consists of 4 bytes:
|
||||||
* . . . . . B2 B1 B0 .... one byte with mouse button states
|
* . . . . . B2 B1 B0 .... one byte with mouse button states
|
||||||
@ -102,32 +102,25 @@ static void read_Wheel(void)
|
|||||||
|
|
||||||
timing = get_timing(AnalogIn);
|
timing = get_timing(AnalogIn);
|
||||||
|
|
||||||
// PINB |= _BV(PB1);
|
|
||||||
|
|
||||||
if (AnalogIn < LowerDead[Debounce] || AnalogIn > UpperDead[Debounce])
|
if (AnalogIn < LowerDead[Debounce] || AnalogIn > UpperDead[Debounce])
|
||||||
{
|
{
|
||||||
if (Debounce == 1 || ticktock >= timing)
|
if (Debounce == 1 || ticktock >= timing)
|
||||||
{
|
{
|
||||||
|
PINB |= _BV(PB1);
|
||||||
reportBuffer.dWheel = Direction;
|
reportBuffer.dWheel = Direction;
|
||||||
Debounce = 0;
|
Debounce = 0;
|
||||||
ticktock = 0;
|
ticktock = 0;
|
||||||
PINB |= _BV(PB1);
|
|
||||||
// PINB &= ~(1<<PB1);
|
|
||||||
// LEDs_ToggleLEDs(LEDS_LED2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Debounce == 0)
|
if (Debounce == 0)
|
||||||
{
|
{
|
||||||
// PINB |= (1<<PB1);
|
PINB &= ~(1<<PB1);
|
||||||
Debounce = 1;
|
Debounce = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *ReportSize = sizeof(USB_MouseReport_Data_t);
|
|
||||||
// return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearReport()
|
void clearReport()
|
||||||
@ -145,7 +138,7 @@ uint8_t get_timing(uint16_t value)
|
|||||||
{
|
{
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return timingtable_out[index];
|
return timingtable_out[index] * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
@ -156,34 +149,13 @@ ISR(ADC_vect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ISR(TIM0_COMPA_vect)
|
ISR(TIM0_COMPA_vect)
|
||||||
{
|
{
|
||||||
// usbPoll();
|
read_Wheel();
|
||||||
// PINB |= _BV(PB1);
|
if(usbInterruptIsReady())
|
||||||
|
|
||||||
if (ticktock > 10)
|
|
||||||
{
|
{
|
||||||
// PINB |= _BV(PB1);
|
usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
|
||||||
|
|
||||||
// usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
|
|
||||||
// PINB |= (1<<PB1);
|
|
||||||
// PINB |= _BV(PB1);
|
|
||||||
read_Wheel();
|
|
||||||
if(usbInterruptIsReady())
|
|
||||||
{
|
|
||||||
// PINB |= _BV(PB1);
|
|
||||||
usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
|
|
||||||
}
|
|
||||||
ticktock = 0;
|
|
||||||
}
|
}
|
||||||
else
|
ticktock++;
|
||||||
{
|
|
||||||
// PINB &= ~(1<<PB1);
|
|
||||||
ticktock++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ticktock++;
|
|
||||||
// LEDs_ToggleLEDs(LEDS_LED1);
|
|
||||||
// wdt_reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||||
@ -194,17 +166,16 @@ void SetupHardware(void)
|
|||||||
MCUSR &= ~(1 << WDRF);
|
MCUSR &= ~(1 << WDRF);
|
||||||
wdt_disable();
|
wdt_disable();
|
||||||
|
|
||||||
/* Hardware Initialization */
|
DDRB |= (1<<PB1);
|
||||||
|
|
||||||
// clearReport();
|
/* Hardware Initialization */
|
||||||
|
|
||||||
usbInit();
|
usbInit();
|
||||||
/* enforce re-enumeration, do this while interrupts are disabled! */
|
/* enforce re-enumeration, do this while interrupts are disabled! */
|
||||||
usbDeviceDisconnect();
|
usbDeviceDisconnect();
|
||||||
for (int i = 0; i<250; i++)
|
for (int i = 0; i<250; i++)
|
||||||
{ /* fake USB disconnect for > 250 ms */
|
{ /* fake USB disconnect for > 250 ms */
|
||||||
// wdt_reset();
|
_delay_ms(2);
|
||||||
_delay_ms(4);
|
|
||||||
}
|
}
|
||||||
usbDeviceConnect();
|
usbDeviceConnect();
|
||||||
|
|
||||||
@ -244,8 +215,6 @@ void SetupHardware(void)
|
|||||||
|
|
||||||
TIMSK |= (1<<OCIE0A);
|
TIMSK |= (1<<OCIE0A);
|
||||||
|
|
||||||
DDRB |= (1<<PB1);
|
|
||||||
|
|
||||||
sei();
|
sei();
|
||||||
// wdt_enable(WDTO_1S);
|
// wdt_enable(WDTO_1S);
|
||||||
}
|
}
|
||||||
@ -314,42 +283,31 @@ void hadUsbReset()
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
// uchar i;
|
|
||||||
|
|
||||||
SetupHardware();
|
SetupHardware();
|
||||||
|
|
||||||
/* If you don't use the watchdog, replace the call above with a wdt_disable().
|
clearReport();
|
||||||
* On newer devices, the status of the watchdog (on/off, period) is PRESERVED
|
|
||||||
* OVER RESET!
|
// int count = 0;
|
||||||
*/
|
|
||||||
/* RESET status: all port bits are inputs without pull-up.
|
|
||||||
* That's the way we need D+ and D-. Therefore we don't need any
|
|
||||||
* additional hardware initialization.
|
|
||||||
*/
|
|
||||||
// for (int a = 0; a<6; a++)
|
|
||||||
// {
|
|
||||||
// PINB |= _BV(PB1);
|
|
||||||
// _delay_ms(500);
|
|
||||||
// }
|
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{ /* main event loop */
|
{
|
||||||
// if (USBIN&USBMASK)
|
if (USBIN&USBMASK)
|
||||||
// {
|
{
|
||||||
// sleep_cpu(); // sleep, except at SE0, until SOF
|
sleep_cpu(); // sleep, except at SE0, until SOF
|
||||||
// }
|
}
|
||||||
// DBG1(0x02, 0, 0); /* debug output: main loop iterates */
|
|
||||||
//wdt_reset();
|
//wdt_reset();
|
||||||
usbPoll();
|
usbPoll();
|
||||||
// usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
|
|
||||||
// PINB |= _BV(PB1);
|
|
||||||
// if(usbInterruptIsReady())
|
// if(usbInterruptIsReady())
|
||||||
// {
|
// {
|
||||||
// // PINB |= _BV(PB1);
|
// // if (count > 10)
|
||||||
|
// // {
|
||||||
|
// // PINB |= _BV(PB1);
|
||||||
|
// // count = 0;
|
||||||
|
// // }
|
||||||
|
// // count++;
|
||||||
|
|
||||||
// // /* called after every poll of the interrupt endpoint */
|
|
||||||
// // read_Wheel();
|
|
||||||
// // // DBG1(0x03, 0, 0); /* debug output: interrupt report prepared */
|
|
||||||
// usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
|
// usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
|
||||||
// clearReport();
|
// clearReport();
|
||||||
// }
|
// }
|
||||||
|
@ -282,7 +282,7 @@ extern void hadUsbReset(void); // define the function for usbdrv.c
|
|||||||
* CDC class is 2, use subclass 2 and protocol 1 for ACM
|
* CDC class is 2, use subclass 2 and protocol 1 for ACM
|
||||||
*/
|
*/
|
||||||
/* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */
|
/* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */
|
||||||
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 56
|
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 52
|
||||||
/* Define this to the length of the HID report descriptor, if you implement
|
/* Define this to the length of the HID report descriptor, if you implement
|
||||||
* an HID device. Otherwise don't define it or define it to 0.
|
* an HID device. Otherwise don't define it or define it to 0.
|
||||||
* If you use this define, you must add a PROGMEM character array named
|
* If you use this define, you must add a PROGMEM character array named
|
||||||
|
Loading…
Reference in New Issue
Block a user