../hidA8.c:276:4: warning: passing argument 1 of 'usbSendHidReport' from incompatible pointer type
../hidA8.c:194:6: note: expected 'unsigned char *' but argument is of type 'struct keyboard_report_t *'
// please see http://frank.circleofcurrent.com/index.php?page=hid_tutorial_1
// the "usb_hid_rpt_desc.hid" file needs to be viewed with the HID Descriptor Tool from USB.org
// required headers
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <string.h>
// V-USB
#include "usbdrv.h"
PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { //101
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x85, 0x01, // REPORT_ID (1)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0, // END_COLLECTION
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x85, 0x02, // REPORT_ID (2)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
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 (Cnst,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
};
typedef struct
{
uint8_t report_id;
uint8_t modifier;
uint8_t reserved;
uint8_t keycodes[6];
} keyboard_report_t;
typedef struct
{
uint8_t report_id;
uint8_t buttons;
int8_t x;
int8_t y;
int8_t wheel;
} mouse_report_t;
static uint8_t idle_rate = 500 / 4; // see HID1_11.pdf sect 7.2.4
static uint8_t protocol_version = 0; // see HID1_11.pdf sect 7.2.6
static keyboard_report_t keyboard_report;
static mouse_report_t mouse_report;
static keyboard_report_t keyboard_report_old;
static mouse_report_t mouse_report_old;
usbMsgLen_t usbFunctionSetup(uint8_t data[8])
{
// see HID1_11.pdf sect 7.2 and http://vusb.wikidot.com/driver-api
usbRequest_t *rq = (void *)data;
if ((rq->bmRequestType & USBRQ_TYPE_MASK) != USBRQ_TYPE_CLASS)
return 0; // ignore request if it's not a class specific request
// see HID1_11.pdf sect 7.2
switch (rq->bRequest)
{
case USBRQ_HID_GET_IDLE:
usbMsgPtr = &idle_rate; // send data starting from this byte
return 1; // send 1 byte
case USBRQ_HID_SET_IDLE:
idle_rate = rq->wValue.bytes[1]; // read in idle rate
return 0; // send nothing
case USBRQ_HID_GET_PROTOCOL:
usbMsgPtr = &protocol_version; // send data starting from this byte
return 1; // send 1 byte
case USBRQ_HID_SET_PROTOCOL:
protocol_version = rq->wValue.bytes[1];
return 0; // send nothing
case USBRQ_HID_GET_REPORT:
// check for report ID then send back report
if (rq->wValue.bytes[0] == 1)
{
usbMsgPtr = &keyboard_report;
return sizeof(keyboard_report);
}
else if (rq->wValue.bytes[0] == 2)
{
usbMsgPtr = &mouse_report;
return sizeof(mouse_report);
}
else
{
return 0; // no such report, send nothing
}
case USBRQ_HID_SET_REPORT: // no "output" or "feature" implemented, so ignore
return 0; // send nothing
default: // do not understand data, ignore
return 0; // send nothing
}
}
// this function is used to guarantee that the data is sent to the computer once
void usbSendHidReport(uchar * data, uchar len)
{
while(1)
{
usbPoll();
if (usbInterruptIsReady())
{
usbSetInterrupt(data, len);
break;
}
}
}
int main()
{
TCCR0 = 0b00000011;
TIMSK = 0b00000001;
wdt_enable(WDTO_2S);
TCCR1B = _BV(CS12) | _BV(CS11); // timer is initialized, used to keep track of idle period
usbInit(); // start v-usb
usbDeviceDisconnect(); // enforce USB re-enumeration, do this while interrupts are disabled!
_delay_ms(250);
usbDeviceConnect();
sei(); // enable interrupts
uint8_t to_send = 1; // boolean, true for first time
while (1)
{
wdt_reset();
usbPoll();
// set the report IDs manually
keyboard_report.report_id = 1;
mouse_report.report_id = 2;
/*
* this area is where you should set the movement
* and button values of the reports using the input
* method of your choice
*
*/
// determine whether or not the report should be sent
if ((TCNT1 > ((4 * (F_CPU / 1024000)) * idle_rate) || TCNT1 > 0x7FFF) && idle_rate != 0)
{// using idle rate
to_send = 1;
}
else
{// or if data has changed
if (memcmp(&keyboard_report, &keyboard_report_old, sizeof(keyboard_report_t)) != 0)
{
to_send = 1;
}
else if (memcmp(&mouse_report, &mouse_report_old, sizeof(mouse_report_t)) != 0)
{
to_send = 1;
}
}
usbPoll();
if (to_send != 0)
{
// send the data if needed
usbSendHidReport(&keyboard_report, sizeof(keyboard_report_t));
usbSendHidReport(&mouse_report, sizeof(mouse_report_t));
TCNT1 = 0; // reset timer
}
usbPoll();
memcpy(&mouse_report_old, &mouse_report, sizeof(mouse_report_t));
memcpy(&keyboard_report_old, &keyboard_report, sizeof(keyboard_report_t));
to_send = 0; // reset flag
}
return 0;
}
то есть не целиком конечно, там еще есть файлы которые она использует.
по идее должно работать, и компилится же. ругается непонятно на что и непонятно ошибка это или хуйня невлияющая