http://codeandlife.com/2012/03/03/diy-usb-password-generator/
Will the IDE accept the old style of code, eg, void setup{} and void loop{} are replaced with while(1) and there is no setup{} so can it be configured to accept code like
/**
* Project: AVR ATtiny USB Tutorial at http://codeandlife.com/
* Author: Joonas Pihlajamaa, joonas.pihlajamaa@iki.fi
* Base on V-USB example code by Christian Starkjohann
* Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
* License: GNU GPL v3 (see License.txt)
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include "usbdrv.h"
// *********************************
// *** BASIC PROGRAM DEFINITIONS ***
// *********************************
#define PASS_LENGTH 10 // password length for generated password
#define SEND_ENTER 0 // define to 1 if you want to send ENTER after password
PROGMEM uchar measuring_message[] = "Starting generation...";
PROGMEM uchar finish_message[] = " New password saved.";
// The buffer needs to accommodate the messages above and the password
#define MSG_BUFFER_SIZE 32
EEMEM uchar stored_password[MSG_BUFFER_SIZE];
// ************************
// *** USB HID ROUTINES ***
// ************************
// From Frank Zhao's USB Business Card project
// http://www.frank-zhao.com/cache/usbbusinesscard_details.php
PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x05, 0x07, // USAGE_PAGE (Keyboard)(Key Codes)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)(224)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)(231)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x81, 0x02, // INPUT (Data,Var,Abs) ; Modifier byte
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs) ; Reserved byte
0x95, 0x05, // REPORT_COUNT (5)
0x75, 0x01, // REPORT_SIZE (1)
0x05, 0x08, // USAGE_PAGE (LEDs)
0x19, 0x01, // USAGE_MINIMUM (Num Lock)
0x29, 0x05, // USAGE_MAXIMUM (Kana)
0x91, 0x02, // OUTPUT (Data,Var,Abs) ; LED report
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x03, // REPORT_SIZE (3)
0x91, 0x03, // OUTPUT (Cnst,Var,Abs) ; LED report padding
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)(Key Codes)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))(0)
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)(101)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0 // END_COLLECTION
};
typedef struct {
uint8_t modifier;
uint8_t reserved;
uint8_t keycode[6];
} keyboard_report_t;
static keyboard_report_t keyboard_report; // sent to PC
volatile static uchar LED_state = 0xff; // received from PC
static uchar idleRate; // repeat rate for keyboards
#define STATE_SEND 1
#define STATE_DONE 0
static uchar messageState = STATE_DONE;
static uchar messageBuffer[MSG_BUFFER_SIZE] = "";
static uchar messagePtr = 0;
static uchar messageCharNext = 1;
#define MOD_SHIFT_LEFT (1<<1)
// The buildReport is called by main loop and it starts transmitting
// characters when messageState == STATE_SEND. The message is stored
// in messageBuffer and messagePtr tells the next character to send.
// Remember to reset messagePtr to 0 after populating the buffer!
uchar buildReport() {
uchar ch;
if(messageState == STATE_DONE || messagePtr >= sizeof(messageBuffer) || messageBuffer[messagePtr] == 0) {
keyboard_report.modifier = 0;
keyboard_report.keycode[0] = 0;
return STATE_DONE;
}
if(messageCharNext) { // send a keypress
ch = messageBuffer[messagePtr++];
// convert character to modifier + keycode
if(ch >= '0' && ch <= '9') {
keyboard_report.modifier = 0;
keyboard_report.keycode[0] = (ch == '0') ? 39 : 30+(ch-'1');
} else if(ch >= 'a' && ch <= 'z') {
keyboard_report.modifier = (LED_state & 2) ? MOD_SHIFT_LEFT : 0;
keyboard_report.keycode[0] = 4+(ch-'a');
} else if(ch >= 'A' && ch <= 'Z') {
keyboard_report.modifier = (LED_state & 2) ? 0 : MOD_SHIFT_LEFT;
keyboard_report.keycode[0] = 4+(ch-'A');
} else {
keyboard_report.modifier = 0;
keyboard_report.keycode[0] = 0;
switch(ch) {
case '.':
keyboard_report.keycode[0] = 0x37;
break;
case '_':
keyboard_report.modifier = MOD_SHIFT_LEFT;
case '-':
keyboard_report.keycode[0] = 0x2D;
break;
case ' ':
keyboard_report.keycode[0] = 0x2C;
break;
case '\t':
keyboard_report.keycode[0] = 0x2B;
break;
case '\n':
keyboard_report.keycode[0] = 0x28;
break;
}
}
} else { // key release before the next keypress!
keyboard_report.modifier = 0;
keyboard_report.keycode[0] = 0;
}
messageCharNext = !messageCharNext; // invert
return STATE_SEND;
}
//..... more next post
I'm able to use AVRdude and flash the .hex file generated by a donor, but i'm trying to work out how to get this code to work with Arduino?