Skyduino:~#
Articles
C/C++, programmation

AVR-Stick – News

Salut à tous !
Voici le code source de mon hello world avec une board AVR-Stick de sparkfun.
Requiére la librairie vusb (dossier usbdrv !)
En espérant que cela va donner des idées à certain 😉

Tester et compiler sous winavr :
> make
> make flash
Petit bug bizarre le Hello World c’est transformé en Hello Zorld (W->Z) pourtant les tables hid sont juste, allez savoir pourquoi …
Edit: Ce n’est pas un bug en fait … qwerty power ! Et oui j’avais oublié mais les tables hid sont pour les claviers qwerty c’est bête hein !



AVR-Stick -> http://www.sparkfun.com/products/9147
Petit conseil : Coller un morceau de limande souple en dessous du connecteur usb pour le rendre plus épais et mettre un peu de soudure sur les connexions pour les rendre plus solide ;).

main.c

#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>

#include "usbdrv.h"
#include "oddebug.h"
#include "hid.h"

/*
Pin assignment:
PB3 = analog input (ADC3)
PB4 = analog input (ADC2) - Can alternately be used as an LED output.
PB1 = LED output

PB0, PB2 = USB data lines
*/

#define WHITE_LED 3
#define YELLOW_LED 1


#define UTIL_BIN4(x)        (uchar)((0##x & 01000)/64 + (0##x & 0100)/16 + (0##x & 010)/4 + (0##x & 1))
#define UTIL_BIN8(hi, lo)   (uchar)(UTIL_BIN4(hi) * 16 + UTIL_BIN4(lo))

#define sbi(var, mask)   ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask)   ((var) &= (uint8_t)~(1 << mask))

#ifndef NULL
#define NULL    ((void *)0)
#endif

/* ------------------------------------------------------------------------- */

static uchar    reportBuffer[2];    /* buffer for HID reports */
static uchar    idleRate;           /* in 4 ms units */
static uchar index = 0;
static uchar    text2send[13] = {KEY_H, KEY_E, KEY_L, KEY_L, KEY_O, KEY_SPACE, KEY_W, KEY_O, KEY_R, KEY_L, KEY_D, KEY_ENTER, 0x00};

/* ------------------------------------------------------------------------- */

PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x06,                    // USAGE (Keyboard)
    0xa1, 0x01,                    // COLLECTION (Application)
    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)
    0x25, 0x65,                    // LOGICAL_MAXIMUM (101)
    0x19, 0x00,                    // USAGE_MINIMUM (Reserved (no event indicated))
    0x29, 0x65,                    // USAGE_MAXIMUM (Keyboard Application)
    0x81, 0x00,                    // INPUT (Data,Ary,Abs)
    0xc0                           // END_COLLECTION
};
/* We use a simplifed keyboard report descriptor which does not support the
 * boot protocol. We don't allow setting status LEDs and we only allow one
 * simultaneous key press (except modifiers). We can therefore use short
 * 2 byte input reports.
 * The report descriptor has been created with usb.org's "HID Descriptor Tool"
 * which can be downloaded from http://www.usb.org/developers/hidpage/.
 * Redundant entries (such as LOGICAL_MINIMUM and USAGE_PAGE) have been omitted
 * for the second INPUT item.
 */

/* ------------------------------------------------------------------------- */

static void sendKey()
{
    if(index == 12) index = 0;
    reportBuffer[0] = 0;    /* no modifiers */
    reportBuffer[1] = text2send[index];
	index ++;
}

/* ------------------------------------------------------------------------- */
/* ------------------------ interface to USB driver ------------------------ */
/* ------------------------------------------------------------------------- */

uchar	usbFunctionSetup(uchar data[8])
{
usbRequest_t    *rq = (void *)data;

    usbMsgPtr = reportBuffer;
    if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS){    /* class request type */
        if(rq->bRequest == USBRQ_HID_GET_REPORT){  /* wValue: ReportType (highbyte), ReportID (lowbyte) */
            /* we only have one report type, so don't look at wValue */
            sendKey();
            return sizeof(reportBuffer);
        }else if(rq->bRequest == USBRQ_HID_GET_IDLE){
            usbMsgPtr = &idleRate;
            return 1;
        }else if(rq->bRequest == USBRQ_HID_SET_IDLE){
            idleRate = rq->wValue.bytes[1];
        }
    }else{
        /* no vendor specific requests implemented */
    }
	return 0;
}

/* ------------------------------------------------------------------------- */
/* ------------------------ Oscillator Calibration ------------------------- */
/* ------------------------------------------------------------------------- */

/* Calibrate the RC oscillator to 8.25 MHz. The core clock of 16.5 MHz is
 * derived from the 66 MHz peripheral clock by dividing. Our timing reference
 * is the Start Of Frame signal (a single SE0 bit) available immediately after
 * a USB RESET. We first do a binary search for the OSCCAL value and then
 * optimize this value with a neighboorhod search.
 * This algorithm may also be used to calibrate the RC oscillator directly to
 * 12 MHz (no PLL involved, can therefore be used on almost ALL AVRs), but this
 * is wide outside the spec for the OSCCAL value and the required precision for
 * the 12 MHz clock! Use the RC oscillator calibrated to 12 MHz for
 * experimental purposes only!
 */
static void calibrateOscillator(void)
{
uchar       step = 128;
uchar       trialValue = 0, optimumValue;
int         x, optimumDev, targetValue = (unsigned)(1499 * (double)F_CPU / 10.5e6 + 0.5);

    /* do a binary search: */
    do{
        OSCCAL = trialValue + step;
        x = usbMeasureFrameLength();    /* proportional to current real frequency */
        if(x < targetValue)             /* frequency still too low */
            trialValue += step;
        step >>= 1;
    }while(step > 0);
    /* We have a precision of +/- 1 for optimum OSCCAL here */
    /* now do a neighborhood search for optimum value */
    optimumValue = trialValue;
    optimumDev = x; /* this is certainly far away from optimum */
    for(OSCCAL = trialValue - 1; OSCCAL <= trialValue + 1; OSCCAL++){
        x = usbMeasureFrameLength() - targetValue;
        if(x < 0)
            x = -x;
        if(x < optimumDev){
            optimumDev = x;
            optimumValue = OSCCAL;
        }
    }
    OSCCAL = optimumValue;
}
/*
Note: This calibration algorithm may try OSCCAL values of up to 192 even if
the optimum value is far below 192. It may therefore exceed the allowed clock
frequency of the CPU in low voltage designs!
You may replace this search algorithm with any other algorithm you like if
you have additional constraints such as a maximum CPU clock.
For version 5.x RC oscillators (those with a split range of 2x128 steps, e.g.
ATTiny25, ATTiny45, ATTiny85), it may be useful to search for the optimum in
both regions.
*/

void    usbEventResetReady(void)
{
    calibrateOscillator();
}

/* ------------------------------------------------------------------------- */
/* --------------------------------- main ---------------------------------- */
/* ------------------------------------------------------------------------- */

int main(void)
{
unsigned int i;
	
	//Production Test Routine - Turn on both LEDs and an LED on the SparkFun Pogo Test Bed.
	DDRB |= 1 << WHITE_LED | 1 << YELLOW_LED | 1<<4;   /* output for LED */
	sbi(PORTB, WHITE_LED);
    for(i=0;i<20;i++){  /* 300 ms disconnect */
        _delay_ms(15);
    }
	cbi(PORTB, WHITE_LED);
	
	sbi(PORTB, YELLOW_LED);
    for(i=0;i<20;i++){  /* 300 ms disconnect */
        _delay_ms(15);
    }
	cbi(PORTB, YELLOW_LED);
	
	sbi(PORTB, 4);
    for(i=0;i<20;i++){  /* 300 ms disconnect */
        _delay_ms(15);
    }	
	cbi(PORTB, 4);
	
	DDRB &= ~(1<<4);
	
	//Initialize the USB Connection with the host computer.
    usbDeviceDisconnect();
    for(i=0;i<20;i++){  /* 300 ms disconnect */
        _delay_ms(15);
    }
    usbDeviceConnect();
    
    wdt_enable(WDTO_1S);
    
    usbInit();		//Initialize USB comm.
    sei();
    for(;;){    /* main event loop */
        wdt_reset();
        usbPoll();	//Check to see if it's time to send a USB packet
        if(usbInterruptIsReady()){ /* we can send another key */
            sendKey();	//Get the next 'key press' to send to the host. 
            usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
        }
    }
    return 0;
}

usbconfig.h (config usb)

/* Name: usbconfig.h
 * Project: AVR USB driver
 * Author: Christian Starkjohann
 * Creation Date: 2007-06-23
 * Tabsize: 4
 * Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
 * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
 * This Revision: $Id: usbconfig.h 537 2008-02-28 21:13:01Z cs $
 */

#ifndef __usbconfig_h_included__
#define __usbconfig_h_included__

/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME      B
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT      0
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT       2
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */
//#define USB_CFG_CLOCK_KHZ       (F_CPU/1000)
#define USB_CFG_CLOCK_KHZ       (16500000/1000)
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
 * deviation from the nominal frequency. All other rates require a precision
 * of 2000 ppm and thus a crystal!
 * Default if not specified: 12 MHz
 */

/* ----------------------- Optional Hardware Config ------------------------ */

/* #define USB_CFG_PULLUP_IOPORTNAME   D */
/* If you connect the 1.5k pullup resistor from D- to a port pin instead of
 * V+, you can connect and disconnect the device from firmware by calling
 * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h).
 * This constant defines the port on which the pullup resistor is connected.
 */
/* #define USB_CFG_PULLUP_BIT          4 */
/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined
 * above) where the 1.5k pullup resistor is connected. See description
 * above for details.
 */

/* --------------------------- Functional Range ---------------------------- */

#define USB_CFG_HAVE_INTRIN_ENDPOINT    1
/* Define this to 1 if you want to compile a version with two endpoints: The
 * default control endpoint 0 and an interrupt-in endpoint 1.
 */
#define USB_CFG_HAVE_INTRIN_ENDPOINT3   0
/* Define this to 1 if you want to compile a version with three endpoints: The
 * default control endpoint 0, an interrupt-in endpoint 1 and an interrupt-in
 * endpoint 3. You must also enable endpoint 1 above.
 */
#define USB_CFG_IMPLEMENT_HALT          0
/* Define this to 1 if you also want to implement the ENDPOINT_HALT feature
 * for endpoint 1 (interrupt endpoint). Although you may not need this feature,
 * it is required by the standard. We have made it a config option because it
 * bloats the code considerably.
 */
#define USB_CFG_INTR_POLL_INTERVAL      10
/* If you compile a version with endpoint 1 (interrupt-in), this is the poll
 * interval. The value is in milliseconds and must not be less than 10 ms for
 * low speed devices.
 */
#define USB_CFG_IS_SELF_POWERED         0
/* Define this to 1 if the device has its own power supply. Set it to 0 if the
 * device is powered from the USB bus.
 */
#define USB_CFG_MAX_BUS_POWER           50
/* Set this variable to the maximum USB bus power consumption of your device.
 * The value is in milliamperes. [It will be divided by two since USB
 * communicates power requirements in units of 2 mA.]
 */
#define USB_CFG_IMPLEMENT_FN_WRITE      0
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
 * transfers. Set it to 0 if you don't need it and want to save a couple of
 * bytes.
 */
#define USB_CFG_IMPLEMENT_FN_READ       0
/* Set this to 1 if you need to send control replies which are generated
 * "on the fly" when usbFunctionRead() is called. If you only want to send
 * data from a static buffer, set it to 0 and return the data from
 * usbFunctionSetup(). This saves a couple of bytes.
 */
#define USB_CFG_IMPLEMENT_FN_WRITEOUT   0
/* Define this to 1 if you want to use interrupt-out (or bulk out) endpoint 1.
 * You must implement the function usbFunctionWriteOut() which receives all
 * interrupt/bulk data sent to endpoint 1.
 */
#define USB_CFG_HAVE_FLOWCONTROL        0
/* Define this to 1 if you want flowcontrol over USB data. See the definition
 * of the macros usbDisableAllRequests() and usbEnableAllRequests() in
 * usbdrv.h.
 */
#ifndef __ASSEMBLER__
extern void usbEventResetReady(void);
#endif
#define USB_RESET_HOOK(isReset)             if(!isReset){usbEventResetReady();}
/* This macro is a hook if you need to know when an USB RESET occurs. It has
 * one parameter which distinguishes between the start of RESET state and its
 * end.
 */
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   1
/* define this macro to 1 if you want the function usbMeasureFrameLength()
 * compiled in. This function can be used to calibrate the AVR's RC oscillator.
 */

/* -------------------------- Device Description --------------------------- */

#define  USB_CFG_VENDOR_ID       0x4f, 0x1b
/* USB vendor ID for the device, low byte first. If you have registered your
 * own Vendor ID, define it here. Otherwise you use obdev's free shared
 * VID/PID pair. Be sure to read USBID-License.txt for rules!
 * This template uses obdev's shared VID/PID pair for HIDs: 0x16c0/0x5df.
 * Use this VID/PID pair ONLY if you understand the implications!
 */
#define  USB_CFG_DEVICE_ID       0x02, 0x00
/* This is the ID of the product, low byte first. It is interpreted in the
 * scope of the vendor ID. If you have registered your own VID with usb.org
 * or if you have licensed a PID from somebody else, define it here. Otherwise
 * you use obdev's free shared VID/PID pair. Be sure to read the rules in
 * USBID-License.txt!
 * This template uses obdev's shared VID/PID pair for HIDs: 0x16c0/0x5df.
 * Use this VID/PID pair ONLY if you understand the implications!
 */
#define USB_CFG_DEVICE_VERSION  0x13, 0x37
/* Version number of the device: Minor number first, then major number.
 */
#define USB_CFG_VENDOR_NAME     'S', 'k', 'y', 'w', 'o', 'd', 'd'
#define USB_CFG_VENDOR_NAME_LEN 7
/* These two values define the vendor name returned by the USB device. The name
 * must be given as a list of characters under single quotes. The characters
 * are interpreted as Unicode (UTF-16) entities.
 * If you don't want a vendor name string, undefine these macros.
 * ALWAYS define a vendor name containing your Internet domain name if you use
 * obdev's free shared VID/PID pair. See the file USBID-License.txt for
 * details.
 */
#define USB_CFG_DEVICE_NAME     'S', 'k', 'y', ' ', 'K', 'e', 'y', 'b', 'o', 'a', 'r', 'd'
#define USB_CFG_DEVICE_NAME_LEN 12
/* Same as above for the device name. If you don't want a device name, undefine
 * the macros. See the file USBID-License.txt before you assign a name if you
 * use a shared VID/PID.
 */
/*#define USB_CFG_SERIAL_NUMBER   'N', 'o', 'n', 'e' */
/*#define USB_CFG_SERIAL_NUMBER_LEN   0 */
/* Same as above for the serial number. If you don't want a serial number,
 * undefine the macros.
 * It may be useful to provide the serial number through other means than at
 * compile time. See the section about descriptor properties below for how
 * to fine tune control over USB descriptors such as the string descriptor
 * for the serial number.
 */
#define USB_CFG_DEVICE_CLASS        0
#define USB_CFG_DEVICE_SUBCLASS     0
/* See USB specification if you want to conform to an existing device class.
 */
#define USB_CFG_INTERFACE_CLASS     3   /* HID */
#define USB_CFG_INTERFACE_SUBCLASS  0   /* no boot interface */
#define USB_CFG_INTERFACE_PROTOCOL  0   /* no protocol */
/* See USB specification if you want to conform to an existing device class or
 * protocol.
 */
#define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH    35  /* total length of report descriptor */
/* 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.
 * Since this template defines a HID device, it must also specify a HID
 * report descriptor length. You must add a PROGMEM character array named
 * "usbHidReportDescriptor" to your code which contains the report descriptor.
 * Don't forget to keep the array and this define in sync!
 */

/* #define USB_PUBLIC static */
/* Use the define above if you #include usbdrv.c instead of linking against it.
 * This technique saves a couple of bytes in flash memory.
 */

/* ------------------- Fine Control over USB Descriptors ------------------- */
/* If you don't want to use the driver's default USB descriptors, you can
 * provide our own. These can be provided as (1) fixed length static data in
 * flash memory, (2) fixed length static data in RAM or (3) dynamically at
 * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more
 * information about this function.
 * Descriptor handling is configured through the descriptor's properties. If
 * no properties are defined or if they are 0, the default descriptor is used.
 * Possible properties are:
 *   + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched
 *     at runtime via usbFunctionDescriptor().
 *   + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found
 *     in static memory is in RAM, not in flash memory.
 *   + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash),
 *     the driver must know the descriptor's length. The descriptor itself is
 *     found at the address of a well known identifier (see below).
 * List of static descriptor names (must be declared PROGMEM if in flash):
 *   char usbDescriptorDevice[];
 *   char usbDescriptorConfiguration[];
 *   char usbDescriptorHidReport[];
 *   char usbDescriptorString0[];
 *   int usbDescriptorStringVendor[];
 *   int usbDescriptorStringDevice[];
 *   int usbDescriptorStringSerialNumber[];
 * Other descriptors can't be provided statically, they must be provided
 * dynamically at runtime.
 *
 * Descriptor properties are or-ed or added together, e.g.:
 * #define USB_CFG_DESCR_PROPS_DEVICE   (USB_PROP_IS_RAM | USB_PROP_LENGTH(18))
 *
 * The following descriptors are defined:
 *   USB_CFG_DESCR_PROPS_DEVICE
 *   USB_CFG_DESCR_PROPS_CONFIGURATION
 *   USB_CFG_DESCR_PROPS_STRINGS
 *   USB_CFG_DESCR_PROPS_STRING_0
 *   USB_CFG_DESCR_PROPS_STRING_VENDOR
 *   USB_CFG_DESCR_PROPS_STRING_PRODUCT
 *   USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
 *   USB_CFG_DESCR_PROPS_HID
 *   USB_CFG_DESCR_PROPS_HID_REPORT
 *   USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver)
 *
 */

#define USB_CFG_DESCR_PROPS_DEVICE                  0
#define USB_CFG_DESCR_PROPS_CONFIGURATION           0
#define USB_CFG_DESCR_PROPS_STRINGS                 0
#define USB_CFG_DESCR_PROPS_STRING_0                0
#define USB_CFG_DESCR_PROPS_STRING_VENDOR           0
#define USB_CFG_DESCR_PROPS_STRING_PRODUCT          0
#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER    0
#define USB_CFG_DESCR_PROPS_HID                     0
#define USB_CFG_DESCR_PROPS_HID_REPORT              0
#define USB_CFG_DESCR_PROPS_UNKNOWN                 0

/* ----------------------- Optional MCU Description ------------------------ */

/* The following configurations have working defaults in usbdrv.h. You
 * usually don't need to set them explicitly. Only if you want to run
 * the driver on a device which is not yet supported or with a compiler
 * which is not fully supported (such as IAR C) or if you use a differnt
 * interrupt than INT0, you may have to define some of these.
 */
/* #define USB_INTR_CFG            MCUCR */
/* #define USB_INTR_CFG_SET        ((1 << ISC00) | (1 << ISC01)) */
/* #define USB_INTR_CFG_CLR        0 */
/* #define USB_INTR_ENABLE         GIMSK */
/* #define USB_INTR_ENABLE_BIT     INT0 */
/* #define USB_INTR_PENDING        GIFR */
/* #define USB_INTR_PENDING_BIT    INTF0 */

#endif /* __usbconfig_h_included__ */

hid.h (commande hid pour clavier usb)

/* Keyboard HID Table */
#define MOD_CONTROL_LEFT    (1<<0)
#define MOD_SHIFT_LEFT      (1<<1)
#define MOD_ALT_LEFT        (1<<2)
#define MOD_GUI_LEFT        (1<<3)
#define MOD_CONTROL_RIGHT   (1<<4)
#define MOD_SHIFT_RIGHT     (1<<5)
#define MOD_ALT_RIGHT       (1<<6)
#define MOD_GUI_RIGHT       (1<<7)

#define KEY_A    0x04    //Keyboard a and A
#define KEY_B    0x05    //Keyboard b and B
#define KEY_C    0x06    //Keyboard c and C
#define KEY_D    0x07    //Keyboard d and D
#define KEY_E    0x08    //Keyboard e and E
#define KEY_F    0x09    //Keyboard f and F
#define KEY_G    0x0A    //Keyboard g and G
#define KEY_H    0x0B    //Keyboard h and H
#define KEY_I    0x0C    //Keyboard i and I
#define KEY_J    0x0D    //Keyboard j and J
#define KEY_K    0x0E    //Keyboard k and K
#define KEY_L    0x0F    //Keyboard l and L
#define KEY_M    0x10    //Keyboard m and M
#define KEY_N    0x11    //Keyboard n and N
#define KEY_O    0x12    //Keyboard o and O
#define KEY_P    0x13    //Keyboard p and P
#define KEY_Q    0x14    //Keyboard q and Q
#define KEY_R    0x15    //Keyboard r and R
#define KEY_S    0x16    //Keyboard s and S
#define KEY_T    0x17    //Keyboard t and T
#define KEY_U    0x18    //Keyboard u and U
#define KEY_V    0x19    //Keyboard v and V
#define KEY_W    0x1A    //Keyboard w and W -> Return Z WTF !
#define KEY_X    0x1B    //Keyboard x and X
#define KEY_Y    0x1C    //Keyboard y and Y
#define KEY_Z    0x1D    //Keyboard z and Z
#define KEY_1    0x1E    //Keyboard 1 and !
#define KEY_2    0x1F    //Keyboard 2 and @
#define KEY_3    0x20    //Keyboard 3 and #
#define KEY_4    0x21    //Keyboard 4 and $
#define KEY_5    0x22    //Keyboard 5 and %
#define KEY_6    0x23    //Keyboard 6 and ^
#define KEY_7    0x24    //Keyboard 7 and &
#define KEY_8    0x25    //Keyboard 8 and *
#define KEY_9    0x26    //Keyboard 9 and (
#define KEY_0    0x27    //Keyboard 0 and )
#define KEY_ENTER    0x28    //Keyboard Return (ENTER)
#define KEY_ESCAPE    0x29    //Keyboard ESCAPE
#define KEY_DELETE    0x2A    //Keyboard DELETE (Backspace)
#define KEY_TAB    0x2B    //Keyboard Tab
#define KEY_SPACE    0x2C    //Keyboard Spacebar
#define KEY_MINUS    0x2D    //Keyboard - and (underscore)
#define KEY_PLUS    0x2E    //Keyboard = and +
#define KEY_OPENBRACE    0x2F    //Keyboard [ and {
#define KEY_CLOSEBRACE    0x30    //Keyboard ] and }
#define KEY_SLASH    0x31    //Keyboard \ and |
#define KEY_TILDE    0x32    //Keyboard Non-US # and ~
#define KEY_SEMICOLUMN    0x33    //Keyboard ; and :
#define KEY_QUOTE    0x34    //Keyboard ' and "
#define KEY_GRAVEACCENT    0x35    //Keyboard Grave Accent and Tilde
#define KEY_COLUMN    0x36    //Keyboard, and <
#define KEY_POINT    0x37    //Keyboard . and >
#define KEY_INTEROGATION    0x38    //Keyboard / and ?
#define KEY_CAPLOCK    0x39    //Keyboard Caps Lock
#define KEY_F1    0x3A    //Keyboard F1
#define KEY_F2    0x3B    //Keyboard F2
#define KEY_F3    0x3C    //Keyboard F3
#define KEY_F4    0x3D    //Keyboard F4
#define KEY_F5    0x3E    //Keyboard F5
#define KEY_F6    0x3F    //Keyboard F6
#define KEY_F7    0x40    //Keyboard F7
#define KEY_F8    0x41    //Keyboard F8
#define KEY_F9    0x42    //Keyboard F9
#define KEY_F10    0x43    //Keyboard F10
#define KEY_F11    0x44    //Keyboard F11
#define KEY_F12    0x45    //Keyboard F12
#define KEY_PRINTSCREEN    0x46    //Keyboard PrintScreen
#define KEY_SCROLLLOCK    0x47    //Keyboard Scroll Lock
#define KEY_PAUSE    0x48    //Keyboard Pause
#define KEY_INSERT    0x49    //Keyboard Insert
#define KEY_HOME    0x4A    //Keyboard Home
#define KEY_PAGEUP    0x4B    //Keyboard PageUp
#define KEY_FORWARD    0x4C    //Keyboard Delete Forward
#define KEY_END    0x4D    //Keyboard End
#define KEY_PAGEDOWN    0x4E    //Keyboard PageDown
#define KEY_RIGHTARROW    0x4F    //Keyboard RightArrow
#define KEY_LEFTARROW    0x50    //Keyboard LeftArrow
#define KEY_DOWNARROW    0x51    //Keyboard DownArrow
#define KEY_UPARROW    0x52    //Keyboard UpArrow
#define KEY_NUMLOCK    0x53    //Keypad Num Lock and Clear
#define KEY_KEYPAD_SLASH    0x54    //Keypad /
#define KEY_KEYPAD_STAR    0x55    //Keypad *
#define KEY_KEYPAD_MINUS    0x56    //Keypad -
#define KEY_KEYPAD_PLUS    0x57    //Keypad +
#define KEY_KEYPAD_ENTER    0x58    //Keypad ENTER
#define KEY_KEYPAD_1    0x59    //Keypad 1 and End
#define KEY_KEYPAD_2    0x5A    //Keypad 2 and Down Arrow
#define KEY_KEYPAD_3    0x5B    //Keypad 3 and PageDn
#define KEY_KEYPAD_4    0x5C    //Keypad 4 and Left Arrow
#define KEY_KEYPAD_5    0x5D    //Keypad 5
#define KEY_KEYPAD_6    0x5E    //Keypad 6 and Right Arrow
#define KEY_KEYPAD_7    0x5F    //Keypad 7 and Home
#define KEY_KEYPAD_8    0x60    //Keypad 8 and Up Arrow
#define KEY_KEYPAD_9    0x61    //Keypad 9 and PageUp
#define KEY_KEYPAD_0    0x62    //Keypad 0 and Insert
#define KEY_KEYPAD_POINT    0x63    //Keypad . and Delete
#define KEY_UNDER_SLASH    0x64    //Keyboard Non-US \ and |
#define KEY_APPLICATION    0x65    //Keyboard Application
#define KEY_POWER    0x66    //Keyboard Power
#define KEY_EQUAL    0x67    //Keypad =
#define KEY_F13    0x68    //Keyboard F13
#define KEY_F14    0x69    //Keyboard F14
#define KEY_F15    0x6A    //Keyboard F15
#define KEY_F16    0x6B    //Keyboard F16
#define KEY_F17    0x6C    //Keyboard F17
#define KEY_F18    0x6D    //Keyboard F18
#define KEY_F19    0x6E    //Keyboard F19
#define KEY_F20    0x6F    //Keyboard F20
#define KEY_F21    0x70    //Keyboard F21
#define KEY_F22    0x71    //Keyboard F22
#define KEY_F23    0x72    //Keyboard F23
#define KEY_F24    0x73    //Keyboard F24
#define KEY_EXECUTE    0x74    //Keyboard Execute
#define KEY_HELP    0x75    //Keyboard Help
#define KEY_MENU    0x76    //Keyboard Menu
#define KEY_SELECT    0x77    //Keyboard Select
#define KEY_STOP    0x78    //Keyboard Stop
#define KEY_AGAIN    0x79    //Keyboard Again
#define KEY_UNDO    0x7A    //Keyboard Undo
#define KEY_CUT    0x7B    //Keyboard Cut
#define KEY_COPY    0x7C    //Keyboard Copy
#define KEY_PASTE    0x7D    //Keyboard Paste
#define KEY_FIND    0x7E    //Keyboard Find
#define KEY_MUTE    0x7F    //Keyboard Mute
#define KEY_VOLUMEUP    0x80    //Keyboard Volume Up
#define KEY_VOLUMEDOWN    0x81    //Keyboard Volume Down

Le makefile (piqué dans l’exemple de sparkfun)

# Name: Makefile
# Project: EasyLogger
# Author: Christian Starkjohann
# Creation Date: 2007-06-23
# Tabsize: 4
# Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
# License: GPLv2.
# This Revision: $Id: Makefile 362 2007-06-25 14:38:21Z cs $

DEVICE=attiny85
AVRDUDE = avrdude -c usbtiny -B 1 -p $(DEVICE)
# The two lines above are for "avrdude" and the STK500 programmer connected
# to an USB to serial converter to a Mac running Mac OS X.
# Choose your favorite programmer and interface.

COMPILE = avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=$(DEVICE) -DF_CPU=16500000 -DDEBUG_LEVEL=0
# NEVER compile the final product with debugging! Any debug output will
# distort timing so that the specs can't be met.

OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o

# symbolic targets:
all:	main.hex

.c.o:
	$(COMPILE) -c $< -o $@

.S.o:
	$(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
	$(COMPILE) -S $< -o $@

flash:	all
	$(AVRDUDE) -U flash:w:main.hex


# Fuse high byte:
# 0xdd = 1 1 0 1   1 1 0 1
#        ^ ^ ^ ^   ^ \-+-/ 
#        | | | |   |   +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
#        | | | |   +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
#        | | | +-------------- WDTON (watchdog timer always on -> disable)
#        | | +---------------- SPIEN (enable serial programming -> enabled)
#        | +------------------ DWEN (debug wire enable)
#        +-------------------- RSTDISBL (disable external reset -> enabled)
#
# Fuse low byte:
# 0xe1 = 1 1 1 0   0 0 0 1
#        ^ ^ \+/   \--+--/
#        | |  |       +------- CKSEL 3..0 (clock selection -> HF PLL)
#        | |  +--------------- SUT 1..0 (BOD enabled, fast rising power)
#        | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
#        +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
fuse:
	$(AVRDUDE) -U hfuse:w:0xdd:m -U lfuse:w:0xe1:m

readcal:
	$(AVRDUDE) -U calibration:r:/dev/stdout:i | head -1


clean:
	rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s

# file targets:
main.bin:	$(OBJECTS)
	$(COMPILE) -o main.bin $(OBJECTS)

main.hex:	main.bin
	rm -f main.hex main.eep.hex
	avr-objcopy -j .text -j .data -O ihex main.bin main.hex
#./checksize main.bin 4096 256
# do the checksize script as our last action to allow successful compilation
# on Windows with WinAVR where the Unix commands will fail.

disasm:	main.bin
	avr-objdump -d main.bin

cpp:
	$(COMPILE) -E main.c

Discussion

Les commentaires sont fermés.

Skyduino devient Carnet du Maker

Le site Carnet du Maker remplace désormais le blog Skyduino pour tout ce qui touche à l'Arduino, l'informatique et au DIY.