2011-01-28 10:44:05 -05:00
|
|
|
/* Name: main.c
|
|
|
|
* Project: hid-mouse, a very simple HID example
|
|
|
|
* Author: Christian Starkjohann
|
|
|
|
* Creation Date: 2008-04-07
|
|
|
|
* Tabsize: 4
|
|
|
|
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
|
|
|
|
* License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
|
|
|
|
* This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
|
|
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/wdt.h>
|
|
|
|
#include <avr/interrupt.h> /* for sei() */
|
|
|
|
#include <avr/pgmspace.h> /* required by usbdrv.h */
|
2011-02-02 23:26:44 -05:00
|
|
|
#include <util/delay.h> /* for _delay_ms() */
|
2011-01-28 10:44:05 -05:00
|
|
|
#include "usbdrv.h"
|
|
|
|
#include "usart_print.h" /* This is also an example for using debug macros */
|
|
|
|
#include "usb_keycodes.h"
|
|
|
|
#include "matrix_skel.h"
|
|
|
|
#include "keymap_skel.h"
|
2011-02-02 23:26:44 -05:00
|
|
|
#include "mousekey.h"
|
2011-01-28 10:44:05 -05:00
|
|
|
#include "layer.h"
|
|
|
|
#include "print.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "sendchar.h"
|
2011-02-02 23:26:44 -05:00
|
|
|
#include "host.h"
|
|
|
|
#include "host_vusb.h"
|
2011-01-28 10:44:05 -05:00
|
|
|
#include "timer.h"
|
2011-02-10 01:51:30 -05:00
|
|
|
#include "led.h"
|
|
|
|
#include "keyboard.h"
|
2011-01-28 10:44:05 -05:00
|
|
|
|
2011-02-07 00:59:07 -05:00
|
|
|
#define DEBUGP_INIT() do { DDRC = 0xFF; } while (0)
|
|
|
|
#define DEBUGP(x) do { PORTC = x; } while (0)
|
2011-01-28 10:44:05 -05:00
|
|
|
|
2011-02-10 01:51:30 -05:00
|
|
|
//static uint8_t last_led = 0;
|
2011-01-28 10:44:05 -05:00
|
|
|
int main(void)
|
|
|
|
{
|
2011-02-07 00:59:07 -05:00
|
|
|
DEBUGP_INIT();
|
2011-01-28 10:44:05 -05:00
|
|
|
wdt_enable(WDTO_1S);
|
|
|
|
/* Even if you don't use the watchdog, turn it off here. On newer devices,
|
|
|
|
* the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
|
|
|
|
*/
|
2011-02-02 23:26:44 -05:00
|
|
|
|
2011-01-28 10:44:05 -05:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
odDebugInit();
|
|
|
|
usbInit();
|
2011-02-02 23:26:44 -05:00
|
|
|
|
|
|
|
print_enable = true;
|
|
|
|
//debug_enable = true;
|
2011-02-10 01:51:30 -05:00
|
|
|
keyboard_init();
|
2011-02-02 23:26:44 -05:00
|
|
|
|
|
|
|
/* enforce re-enumeration, do this while interrupts are disabled! */
|
|
|
|
usbDeviceDisconnect();
|
|
|
|
uint8_t i = 0;
|
2011-01-28 10:44:05 -05:00
|
|
|
while(--i){ /* fake USB disconnect for > 250 ms */
|
|
|
|
wdt_reset();
|
|
|
|
_delay_ms(1);
|
|
|
|
}
|
|
|
|
usbDeviceConnect();
|
|
|
|
sei();
|
|
|
|
|
2011-02-10 01:51:30 -05:00
|
|
|
//uint8_t fn_bits = 0;
|
2011-01-28 10:44:05 -05:00
|
|
|
while (1) { /* main event loop */
|
2011-02-07 00:59:07 -05:00
|
|
|
DEBUGP(0x01);
|
2011-01-28 10:44:05 -05:00
|
|
|
wdt_reset();
|
|
|
|
usbPoll();
|
2011-02-02 23:26:44 -05:00
|
|
|
host_vusb_keyboard_send();
|
2011-01-28 10:44:05 -05:00
|
|
|
|
2011-02-07 00:59:07 -05:00
|
|
|
DEBUGP(0x02);
|
2011-02-10 01:51:30 -05:00
|
|
|
keyboard_proc();
|
|
|
|
DEBUGP(0x03);
|
|
|
|
/*
|
2011-01-28 10:44:05 -05:00
|
|
|
matrix_scan();
|
2011-02-02 23:26:44 -05:00
|
|
|
fn_bits = 0;
|
2011-02-10 01:51:30 -05:00
|
|
|
host_swap_keyboard_report();
|
|
|
|
host_clear_keyboard_report();
|
2011-02-02 23:26:44 -05:00
|
|
|
mousekey_clear_report();
|
|
|
|
for (int row = 0; row < matrix_rows(); row++) {
|
|
|
|
for (int col = 0; col < matrix_cols(); col++) {
|
|
|
|
if (!matrix_is_on(row, col)) continue;
|
|
|
|
|
|
|
|
uint8_t code = layer_get_keycode(row, col);
|
|
|
|
if (code == KB_NO) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
else if (IS_MOD(code)) {
|
2011-02-10 01:51:30 -05:00
|
|
|
host_add_mod_bit(MOD_BIT(code));
|
2011-02-02 23:26:44 -05:00
|
|
|
}
|
|
|
|
else if (IS_KEY(code)) {
|
2011-02-10 01:51:30 -05:00
|
|
|
host_add_key(code);
|
2011-02-02 23:26:44 -05:00
|
|
|
}
|
|
|
|
else if (IS_FN(code)) {
|
|
|
|
fn_bits |= FN_BIT(code);
|
|
|
|
}
|
|
|
|
else if (IS_MOUSEKEY(code)) {
|
|
|
|
mousekey_decode(code);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
debug("ignore keycode: "); debug_hex(code); debug("\n");
|
2011-01-28 10:44:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-07 00:59:07 -05:00
|
|
|
DEBUGP(0x03);
|
2011-01-28 10:44:05 -05:00
|
|
|
layer_switching(fn_bits);
|
|
|
|
if (matrix_is_modified()) {
|
2011-02-10 01:51:30 -05:00
|
|
|
host_send_keyboard_report();
|
2011-01-28 10:44:05 -05:00
|
|
|
}
|
2011-02-02 23:26:44 -05:00
|
|
|
mousekey_send();
|
2011-02-07 00:59:07 -05:00
|
|
|
|
2011-02-10 01:51:30 -05:00
|
|
|
if (last_led != host_keyboard_led()) {
|
|
|
|
led_set(host_keyboard_led());
|
|
|
|
last_led = host_keyboard_led();
|
2011-02-07 00:59:07 -05:00
|
|
|
}
|
2011-02-10 01:51:30 -05:00
|
|
|
*/
|
2011-01-28 10:44:05 -05:00
|
|
|
}
|
|
|
|
}
|