Browse Source

confirm SetReport LED.

tags/v1.9
tmk 12 years ago
parent
commit
a112f3614e
6 changed files with 91 additions and 61 deletions
  1. 1
    0
      common/command.c
  2. 4
    1
      common/host.c
  3. 1
    1
      keyboard/macway/keymap.c
  4. 7
    0
      protocol/lufa/descriptor.h
  5. 64
    58
      protocol/lufa/lufa.c
  6. 14
    1
      protocol/lufa/lufa.h

+ 1
- 0
common/command.c View File

} }
break; break;
case KB_S: case KB_S:
print("host_keyboard_leds:"); phex(host_keyboard_leds()); print("\n");
#ifdef HOST_PJRC #ifdef HOST_PJRC
print("UDCON: "); phex(UDCON); print("\n"); print("UDCON: "); phex(UDCON); print("\n");
print("UDIEN: "); phex(UDIEN); print("\n"); print("UDIEN: "); phex(UDIEN); print("\n");

+ 4
- 1
common/host.c View File



void host_system_send(uint16_t data) void host_system_send(uint16_t data)
{ {
static uint16_t last_data = 0;
if (data == last_data) return;
last_data = data;

if (!driver) return; if (!driver) return;
(*driver->send_system)(data); (*driver->send_system)(data);
} }


void host_consumer_send(uint16_t data) void host_consumer_send(uint16_t data)
{ {
// TODO: this is needed?
static uint16_t last_data = 0; static uint16_t last_data = 0;
if (data == last_data) return; if (data == last_data) return;
last_data = data; last_data = data;

+ 1
- 1
keyboard/macway/keymap.c View File

* `-----------------------------------------------------------' * `-----------------------------------------------------------'
*/ */
KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \ KEYMAP(PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, \
CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NO, \
CAPS,NO, NO, NO, NO, NO, NO, NO, PSCR,SLCK,BRK, UP, NO, NLCK,\
LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \ LCTL,VOLD,VOLU,MUTE,NO, NO, PAST,PSLS,HOME,PGUP,LEFT,RGHT,ENT, \
LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \ LSFT,NO, NO, NO, NO, NO, PPLS,PMNS,END, PGDN,DOWN,RSFT,FN1, \
NO, LGUI,LALT,SPC, RALT,NO, NO, NO, RCTL), NO, LGUI,LALT,SPC, RALT,NO, NO, NO, RCTL),

+ 7
- 0
protocol/lufa/descriptor.h View File

/*
* Copyright 2012 Jun Wako <[email protected]>
* This file is based on:
* LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse
* LUFA-120219/Demos/Device/Lowlevel/GenericHID
*/

/* /*
LUFA Library LUFA Library
Copyright (C) Dean Camera, 2012. Copyright (C) Dean Camera, 2012.

+ 64
- 58
protocol/lufa/lufa.c View File

#include "descriptor.h" #include "descriptor.h"
#include "lufa.h" #include "lufa.h"


static uint8_t idle_duration = 0;
static uint8_t protocol_report = 1;
static uint8_t keyboard_led_stats = 0; static uint8_t keyboard_led_stats = 0;


// TODO: impl Control Request GET_REPORT
static report_keyboard_t keyboard_report_sent; static report_keyboard_t keyboard_report_sent;
#ifdef MOUSE_ENABLE
static report_mouse_t mouse_report_sent;
#endif



/* Host driver */ /* Host driver */
static uint8_t keyboard_leds(void); static uint8_t keyboard_leds(void);
debug_keyboard = true; debug_keyboard = true;
debug_mouse = true; debug_mouse = true;


/* TODO: can't print here
_delay_ms(5000);
USB_USBTask();
print("abcdefg\n");
USB_USBTask();
*/
// TODO: can't print here
debug("LUFA init\n");


keyboard_init(); keyboard_init();
host_set_driver(&lufa_driver); host_set_driver(&lufa_driver);
ReportData = (uint8_t*)&keyboard_report_sent; ReportData = (uint8_t*)&keyboard_report_sent;
ReportSize = sizeof(keyboard_report_sent); ReportSize = sizeof(keyboard_report_sent);
break; break;
#ifdef MOUSE_ENABLE
case MOUSE_INTERFACE:
// TODO: test/check
ReportData = (uint8_t*)&mouse_report_sent;
ReportSize = sizeof(mouse_report_sent);
break;
#endif
#ifdef EXTRAKEY_ENABLE
case EXTRA_INTERFACE:
break;
#endif
case CONSOLE_INTERFACE:
break;
} }


/* Write the report data to the control endpoint */ /* Write the report data to the control endpoint */
case HID_REQ_SetReport: case HID_REQ_SetReport:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{ {
Endpoint_ClearSETUP();

/* Wait until the LED report has been sent by the host */
while (!(Endpoint_IsOUTReceived()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}


// Interface // Interface
switch (USB_ControlRequest.wIndex) { switch (USB_ControlRequest.wIndex) {
case KEYBOARD_INTERFACE: case KEYBOARD_INTERFACE:
// TODO: test/check
/* Read in the LED report from the host */
Endpoint_ClearSETUP();

while (!(Endpoint_IsOUTReceived())) {
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
keyboard_led_stats = Endpoint_Read_8(); keyboard_led_stats = Endpoint_Read_8();
break;
#ifdef MOUSE_ENABLE
case MOUSE_INTERFACE:
break;
#endif
#ifdef EXTRAKEY_ENABLE
case EXTRA_INTERFACE:
break;
#endif
case CONSOLE_INTERFACE:

Endpoint_ClearOUT();
Endpoint_ClearStatusStage();
break; break;
} }


Endpoint_ClearOUT();
}

break;

case HID_REQ_GetProtocol:
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
while (!(Endpoint_IsINReady()));
Endpoint_Write_8(protocol_report);
Endpoint_ClearIN();
Endpoint_ClearStatusStage();
}

break;
case HID_REQ_SetProtocol:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
Endpoint_ClearStatusStage();

protocol_report = ((USB_ControlRequest.wValue & 0xFF) != 0x00);
}

break;
case HID_REQ_SetIdle:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
Endpoint_ClearStatusStage();

idle_duration = ((USB_ControlRequest.wValue & 0xFF00) >> 8);
}

break;
case HID_REQ_GetIdle:
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
while (!(Endpoint_IsINReady()));
Endpoint_Write_8(idle_duration);
Endpoint_ClearIN();
Endpoint_ClearStatusStage(); Endpoint_ClearStatusStage();
} }


/* Finalize the stream transfer to send the last packet */ /* Finalize the stream transfer to send the last packet */
Endpoint_ClearIN(); Endpoint_ClearIN();
} }
mouse_report_sent = *report;
#endif #endif
} }


typedef struct {
uint8_t report_id;
uint16_t usage;
} __attribute__ ((packed)) report_extra_t;

static void send_system(uint16_t data) static void send_system(uint16_t data)
{ {
report_extra_t r = {
.report_id = REPORT_ID_SYSTEM,
.usage = data
};
Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); Endpoint_SelectEndpoint(EXTRA_IN_EPNUM);
if (Endpoint_IsReadWriteAllowed()) { if (Endpoint_IsReadWriteAllowed()) {
report_extra_t r = {
.report_id = REPORT_ID_SYSTEM,
.usage = data
};
Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }


static void send_consumer(uint16_t data) static void send_consumer(uint16_t data)
{ {
report_extra_t r = {
.report_id = REPORT_ID_CONSUMER,
.usage = data
};
Endpoint_SelectEndpoint(EXTRA_IN_EPNUM); Endpoint_SelectEndpoint(EXTRA_IN_EPNUM);
if (Endpoint_IsReadWriteAllowed()) { if (Endpoint_IsReadWriteAllowed()) {
report_extra_t r = {
.report_id = REPORT_ID_CONSUMER,
.usage = data
};
Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL); Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }

+ 14
- 1
protocol/lufa/lufa.h View File

/*
* Copyright 2012 Jun Wako <[email protected]>
* This file is based on:
* LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse
* LUFA-120219/Demos/Device/Lowlevel/GenericHID
*/

/* /*
LUFA Library LUFA Library
Copyright (C) Dean Camera, 2012. Copyright (C) Dean Camera, 2012.
#ifndef _LUFA_H_ #ifndef _LUFA_H_
#define _LUFA_H_ #define _LUFA_H_


/* Includes: */
#include <avr/io.h> #include <avr/io.h>
#include <avr/wdt.h> #include <avr/wdt.h>
#include <avr/power.h> #include <avr/power.h>
#include <LUFA/Version.h> #include <LUFA/Version.h>
#include <LUFA/Drivers/USB/USB.h> #include <LUFA/Drivers/USB/USB.h>



/* extra report structure */
typedef struct {
uint8_t report_id;
uint16_t usage;
} __attribute__ ((packed)) report_extra_t;

#endif #endif

Loading…
Cancel
Save