diff --git a/labsw/fw/Makefile b/labsw/fw/Makefile new file mode 100644 index 0000000..d2bba16 --- /dev/null +++ b/labsw/fw/Makefile @@ -0,0 +1,35 @@ +# +# labsw/Makefile - Makefile for the Lab Switch firmware +# +# Written 2011 by Werner Almesberger +# Copyright 2011 Werner Almesberger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + + +MAIN = labsw +OBJS = $(MAIN) usb descr # version ep0 + +F32XBASE = ../../../f32xbase + +include $(F32XBASE)/fw/common/Makefile.system +include $(F32XBASE)/fw/common/Makefile.common + +CFLAGS += -I../common -I../include +LDFLAGS += --code-size $(PAYLOAD_SIZE) --code-loc $(PAYLOAD_START) + +USB_ID = $(shell \ + ( echo '\#include "usb-id.h"'; echo USB_VENDOR:USB_PRODUCT; ) | \ + cpp | sed '/^ *$$/d;/^\#/d' ) + +.PHONY: dfu + +# hack: for now, we just reuse the boot loader from cntr +USB_ID = 20b7:cb72 + +dfu: + dfu-util -d $(USB_ID) -D $(MAIN).bin diff --git a/labsw/fw/config.h b/labsw/fw/config.h new file mode 100644 index 0000000..f9c4b8c --- /dev/null +++ b/labsw/fw/config.h @@ -0,0 +1 @@ +#include "usb-id.h" diff --git a/labsw/fw/descr.c b/labsw/fw/descr.c new file mode 100644 index 0000000..149a349 --- /dev/null +++ b/labsw/fw/descr.c @@ -0,0 +1,68 @@ +/* + * descr.c - USB descriptors + * + * Written 2008-2011 by Werner Almesberger + * Copyright 2008-2011 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include "usb.h" + +#include "config.h" + + +/* + * Device descriptor + */ + +const uint8_t device_descriptor[18] = { + 18, /* bLength */ + USB_DT_DEVICE, /* bDescriptorType */ + LE(0x200), /* bcdUSB */ + USB_CLASS_VENDOR_SPEC, /* bDeviceClass */ + 0x00, /* bDeviceSubClass */ + 0x00, /* bDeviceProtocol */ + EP0_SIZE, /* bMaxPacketSize */ + LE(USB_VENDOR), /* idVendor */ + LE(USB_PRODUCT), /* idProduct */ + LE(0x0001), /* bcdDevice */ + 0, /* iManufacturer */ + 0, /* iProduct */ + 0, /* iSerialNumber */ + 1 /* bNumConfigurations */ +}; + + +/* + * Our configuration + * + * We're always bus-powered. + */ + +const uint8_t config_descriptor[] = { + 9, /* bLength */ + USB_DT_CONFIG, /* bDescriptorType */ + LE(9+9), /* wTotalLength */ + 1, /* bNumInterfaces */ + 1, /* bConfigurationValue (> 0 !) */ + 0, /* iConfiguration */ + USB_ATTR_BUS_POWERED, /* bmAttributes */ + 15, /* bMaxPower */ + + /* Interface #0 */ + + 9, /* bLength */ + USB_DT_INTERFACE, /* bDescriptorType */ + 0, /* bInterfaceNumber */ + 0, /* bAlternateSetting */ + 0, /* bNumEndpoints */ + USB_CLASS_VENDOR_SPEC, /* bInterfaceClass */ + 0, /* bInterfaceSubClass */ + 0, /* bInterfaceProtocol */ + 0, /* iInterface */ +}; diff --git a/labsw/fw/labsw.c b/labsw/fw/labsw.c new file mode 100644 index 0000000..9948bd7 --- /dev/null +++ b/labsw/fw/labsw.c @@ -0,0 +1,35 @@ +/* + * labsw.c - Lab Switch initialization and main loop + * + * Written 2011 by Werner Almesberger + * Copyright 2011 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include + +#include "regs.h" +#include "usb.h" + + +static void init_io(void) +{ +} + + +void main(void) +{ + init_io(); + + usb_init(); +// ep0_init(); + + while (1) { + usb_poll(); + } +} diff --git a/labsw/fw/regs.h b/labsw/fw/regs.h new file mode 100644 index 0000000..b64092b --- /dev/null +++ b/labsw/fw/regs.h @@ -0,0 +1 @@ +#include "regs-f320.h" diff --git a/labsw/fw/usb-id.h b/labsw/fw/usb-id.h new file mode 100644 index 0000000..489b3d5 --- /dev/null +++ b/labsw/fw/usb-id.h @@ -0,0 +1,29 @@ +/* + * labsw/usb-id.h - USB vendor and product ID + * + * Written 2011 by Werner Almesberger + * Copyright 2011 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#ifndef USB_ID_H +#define USB_ID_H + +/* + * Platform-specific settings + * + * USB_VENDOR = Qi Hardware + * USB_PRODUCT = 7ab5 + * + * 7ab5 is "LABS" in "leet", http://en.wikipedia.org/wiki/Leet + */ + +#define USB_VENDOR 0x20b7 /* Qi Hardware */ +#define USB_PRODUCT 0x7ab5 /* Lab Switch */ + +#endif /* !USB_ID_H */