From ab3ce4c0e967c7a590a2db6306cce2cf72b82d5b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 9 Jul 2017 04:17:26 +0200 Subject: added v-usb lib (not working yet) --- .gitignore | 1 + contrib/Makefile | 9 ++++- include.mk | 32 +++++++++++++++- vusb-led/Makefile | 33 ++++++++++++++++ vusb-led/usbconfig.h | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ vusb-led/vusb-led.c | 70 ++++++++++++++++++++++++++++++++++ vusb.mk | 41 ++++++++++++++++++++ 7 files changed, 290 insertions(+), 2 deletions(-) create mode 100644 vusb-led/Makefile create mode 100644 vusb-led/usbconfig.h create mode 100644 vusb-led/vusb-led.c create mode 100644 vusb.mk diff --git a/.gitignore b/.gitignore index b65385f..af8d6f1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ contrib/lufa-LUFA-* contrib/FastLED-* contrib/PJON-* contrib/BMP180-* +contrib/vusb-* contrib/.teensy-loader.prepared contrib/teensy_loader_cli contrib/.micronucleus.prepared diff --git a/contrib/Makefile b/contrib/Makefile index ac5fa22..05fe264 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -25,8 +25,9 @@ LUFA_VERSION := 151115 FASTLED_VERSION := 3.1.0 PJON_VERSION := 3.0 +VUSB_VERSION := 20121206 -all: download-lufa download-fastled download-pjon update-teensy-loader update-micronucleus +all: download-lufa download-fastled download-pjon download-vusb update-teensy-loader update-micronucleus download-lufa: LUFA-${LUFA_VERSION}.zip @@ -48,6 +49,12 @@ PJON-${PJON_VERSION}.zip: wget "https://github.com/gioblu/PJON/archive/${PJON_VERSION}.zip" -O "$@" unzip $@ +download-vusb: vusb-${VUSB_VERSION}.zip + +vusb-${VUSB_VERSION}.zip: + wget "https://www.obdev.at/downloads/vusb/vusb-${VUSB_VERSION}.zip" -O "$@" + unzip $@ + .teensy-loader.prepared: git clone https://github.com/PaulStoffregen/teensy_loader_cli.git touch $@ diff --git a/include.mk b/include.mk index 11341e6..de36d5d 100644 --- a/include.mk +++ b/include.mk @@ -38,7 +38,7 @@ CXX_OBJ_LIB := $(CXX_LIBS:%=lib-%.o) CXX_SRC_LIB := $(CXX_LIBS:%=$(LIB_DIR)/%.cpp) CXX_DEP_LIB := $(CXX_LIBS:%=lib-%.d) -.PHONY: prepare clean clean-external distclean clean-lufa clean-fastled clean-pjon program erase flash reset run +.PHONY: prepare clean clean-external distclean clean-lufa clean-fastled clean-pjon clean-vusb program erase flash reset run ELFFILE := $(NAME).elf HEXFILE := $(NAME).hex @@ -72,6 +72,13 @@ CXXFLAGS += -DARDUINO=106 CXXFLAGS += $(PJON_OPTS) endif +ifdef VUSB_PATH +CFLAGS += -I$(VUSB_PATH)/usbdrv +CFLAGS += -I. +CFLAGS += -DUSES_VUSB +CFLAGS += $(VUSB_OPTS) +endif + prepare: $(EXTERNAL_LIBS:%=build-%) clean-external: $(EXTERNAL_LIBS:%=clean-%) @@ -146,6 +153,29 @@ clean-pjon: @echo "****************************************************" +build-vusb: libvusb.a + +libvusb.a: Makefile + @echo "" + @echo "****************************************************" + @echo "building external V-USB lib ($(VUSB_PATH))" + @echo "" + make -f $(SPREADAVR_PATH)/vusb.mk libvusb.a + make -f $(SPREADAVR_PATH)/vusb.mk clean + @echo "" + @echo "****************************************************" + +clean-vusb: + @echo "" + @echo "****************************************************" + @echo "cleaning external V-USB lib ($(VUSB_PATH))" + @echo "" + make -f $(SPREADAVR_PATH)/vusb.mk clean + rm -f libvusb.a + @echo "" + @echo "****************************************************" + + ## project-specific objects %.d: %.c Makefile @set -e; rm -f $@; \ diff --git a/vusb-led/Makefile b/vusb-led/Makefile new file mode 100644 index 0000000..7f8af33 --- /dev/null +++ b/vusb-led/Makefile @@ -0,0 +1,33 @@ +## +## spreadspace avr utils +## +## +## Copyright (C) 2013-2016 Christian Pointner +## +## This file is part of spreadspace avr utils. +## +## spreadspace avr utils 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 3 of the License, or +## any later version. +## +## spreadspace avr utils is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with spreadspace avr utils. If not, see . +## + +NAME := usb-led +BOARD_TYPE := digispark +OBJ := $(NAME).o +LIBS := util led +EXTERNAL_LIBS := vusb +SPREADAVR_PATH := .. + +VUSB_PATH := $(SPREADAVR_PATH)/contrib/vusb-20121206 +VUSB_OPTS = -DDEBUG_LEVEL=0 + +include $(SPREADAVR_PATH)/include.mk diff --git a/vusb-led/usbconfig.h b/vusb-led/usbconfig.h new file mode 100644 index 0000000..00f89d2 --- /dev/null +++ b/vusb-led/usbconfig.h @@ -0,0 +1,106 @@ +/* Name: usbconfig.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2005-04-01 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + */ + +#ifndef __usbconfig_h_included__ +#define __usbconfig_h_included__ + + +/* ---------------------------- Hardware Config ---------------------------- */ +#define USB_CFG_IOPORTNAME B +#define USB_CFG_DMINUS_BIT 3 +#define USB_CFG_DPLUS_BIT 4 + +#define USB_CFG_CLOCK_KHZ (F_CPU/1000) +#define USB_CFG_CHECK_CRC 0 + +/* ----------------------- Optional Hardware Config ------------------------ */ + +/* #define USB_CFG_PULLUP_IOPORTNAME B */ +/* #define USB_CFG_PULLUP_BIT 3 */ + +/* --------------------------- Functional Range ---------------------------- */ + +#define USB_CFG_HAVE_INTRIN_ENDPOINT 0 +#define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 +#define USB_CFG_EP3_NUMBER 3 +/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ +#define USB_CFG_IMPLEMENT_HALT 0 +#define USB_CFG_SUPPRESS_INTR_CODE 0 +#define USB_CFG_INTR_POLL_INTERVAL 10 +#define USB_CFG_IS_SELF_POWERED 0 +#define USB_CFG_MAX_BUS_POWER 100 +#define USB_CFG_IMPLEMENT_FN_WRITE 0 +#define USB_CFG_IMPLEMENT_FN_READ 0 +#define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 +#define USB_CFG_HAVE_FLOWCONTROL 0 +#define USB_CFG_DRIVER_FLASH_PAGE 0 +#define USB_CFG_LONG_TRANSFERS 0 +/* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ +/* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ +/* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ +#define USB_COUNT_SOF 0 +/* #ifdef __ASSEMBLER__ + * macro myAssemblerMacro + * in YL, TCNT0 + * sts timer0Snapshot, YL + * endm + * #endif + * #define USB_SOF_HOOK myAssemblerMacro + */ +#define USB_CFG_CHECK_DATA_TOGGLING 0 +#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 +#define USB_USE_FAST_CRC 0 + +/* -------------------------- Device Description --------------------------- */ + +#define USB_CFG_VENDOR_ID 0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */ +#define USB_CFG_DEVICE_ID 0xdc, 0x05 /* = 0x05dc = 1500 */ +#define USB_CFG_DEVICE_VERSION 0x00, 0x01 +#define USB_CFG_VENDOR_NAME 'o', 'b', 'd', 'e', 'v', '.', 'a', 't' +#define USB_CFG_VENDOR_NAME_LEN 8 +#define USB_CFG_DEVICE_NAME 'T', 'e', 'm', 'p', 'l', 'a', 't', 'e' +#define USB_CFG_DEVICE_NAME_LEN 8 +/*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ +/*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ +#define USB_CFG_DEVICE_CLASS 0xff /* set to 0 if deferred to interface */ +#define USB_CFG_DEVICE_SUBCLASS 0 +#define USB_CFG_INTERFACE_CLASS 0 /* define class here if not at device level */ +#define USB_CFG_INTERFACE_SUBCLASS 0 +#define USB_CFG_INTERFACE_PROTOCOL 0 +/* #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 42 */ +/* #define USB_PUBLIC static */ + +/* ------------------- Fine Control over USB Descriptors ------------------- */ + +#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 + + +#define usbMsgPtr_t unsigned short + +/* ----------------------- Optional MCU Description ------------------------ */ + +/* #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 */ +/* #define USB_INTR_VECTOR INT0_vect */ + +#endif /* __usbconfig_h_included__ */ diff --git a/vusb-led/vusb-led.c b/vusb-led/vusb-led.c new file mode 100644 index 0000000..6818c8a --- /dev/null +++ b/vusb-led/vusb-led.c @@ -0,0 +1,70 @@ +/* + * spreadspace avr utils + * + * + * Copyright (C) 2013-2016 Christian Pointner + * + * This file is part of spreadspace avr utils. + * + * spreadspace avr utils 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 3 of the License, or + * any later version. + * + * spreadspace avr utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with spreadspace avr utils. If not, see . + */ + + +#include +#include +#include +#include +#include + +#include "util.h" +#include "led.h" + +void handle_cmd(uint8_t cmd) +{ + switch(cmd) { + case '0': led_off(); break; + case '1': led_on(); break; + case 't': led_toggle(); break; + case 'o': led2_off(); break; + case 'i': led2_on(); break; + case 'T': led2_toggle(); break; + case 'r': reset2bootloader(); break; + default: printf("error\r\n"); return; + } + printf("ok\r\n"); +} + +int main(void) +{ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + cpu_init(); + led_init(); +// usbio_init(); + sei(); + + for(;;) { + /* int16_t BytesReceived = usbio_bytes_received(); */ + /* while(BytesReceived > 0) { */ + /* int ReceivedByte = fgetc(stdin); */ + /* if(ReceivedByte != EOF) { */ + /* handle_cmd(ReceivedByte); */ + /* } */ + /* BytesReceived--; */ + /* } */ + +// usbio_task(); + } +} diff --git a/vusb.mk b/vusb.mk new file mode 100644 index 0000000..086d21b --- /dev/null +++ b/vusb.mk @@ -0,0 +1,41 @@ +## +## spreadspace avr utils +## +## +## Copyright (C) 2013-2016 Christian Pointner +## +## This file is part of spreadspace avr utils. +## +## spreadspace avr utils 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 3 of the License, or +## any later version. +## +## spreadspace avr utils is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with spreadspace avr utils. If not, see . +## + +include $(SPREADAVR_PATH)/defines.mk + +CFLAGS += -I$(VUSB_PATH)/usbdrv +CFLAGS += -I. +CFLAGS += $(VUSB_OPTS) + +OBJ = $(VUSB_PATH)/usbdrv/usbdrv.o $(VUSB_PATH)/usbdrv/usbdrvasm.o $(VUSB_PATH)/usbdrv/oddebug.o + +libvusb.a: $(OBJ) + $(AR) $@ $(OBJ) + +%.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + +%.o: %.S + $(CC) -c $(CFLAGS) $< -o $@ + +clean: + rm -f $(OBJ) -- cgit v1.2.3