Skip to content

Commit

Permalink
add common uvc sources
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrzejboczar committed Jan 7, 2020
1 parent bc012bb commit 4f2b6eb
Show file tree
Hide file tree
Showing 5 changed files with 777 additions and 107 deletions.
140 changes: 33 additions & 107 deletions common/common.mk
Original file line number Diff line number Diff line change
@@ -1,114 +1,40 @@
#
# Copyright (C) 2009-2012 Chris McClelland
# Copyright 2015 Joel Stanley <[email protected]>
# Copyright 2017 Kyle Robbertze <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# configuration
BOARD ?= opsis
MODEL ?= small
SYNCDELAYLEN ?= 4

# To build the firmware you will need:
# SDCC from http://sdcc.sourceforge.net
# Git from https://git-scm.com/
#
# To build a firmware suitable for loading into RAM:
# make
#
# To build a firmware suitable for loading from EEPROM:
# make FLAGS="-DEEPROM"
#
# To load a firmware:
# make load
# You will need HDMI2USB-mode-switch from
# https://github.com/timvideos/HDMI2USB-mode-switch
#
# Common rules
# use conda enviorment if it exists
MAKEFILE_PATH := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
export PATH := $(MAKEFILE_PATH)../conda/bin:$(PATH)

LIBS ?= $(FX2LIBDIR)/lib/fx2.lib
INCS += -I sdcc -I$(FX2LIBDIR)/include -I. -I$(COMMON_DIR)/boards

# Settings specific for the TimVideo hdmi2usb firmware
BOARD ?= opsis
FLAGS +=-DDEBUG -DBOARD_$(BOARD)

# Must only be hex numbers
FIRMWARE_VERSION := $(shell date +%Y%m%d)

CC_OBJS := $(CC_SRCS:%.c=%.rel)
AS_OBJS := $(AS_SRCS:%.a51=%.rel)

CC := sdcc
AS8051 := sdas8051
AS := $(AS8051)

CFLAGS += -DDATE=0x$(FIRMWARE_VERSION) -mmcs51 $(FLAGS)
CFLAGS += --std-c99 -DSDCC -Wa"-p" --xram-size 0x0200

# Use make V=1 for a verbose build.
ifndef V
Q_CC=@echo ' CC ' $@;
Q_AS=@echo ' AS ' $@;
Q_LINK=@echo ' LINK ' $@;
Q_RM=@echo ' CLEAN ';
Q_OBJCOPY=@echo ' OBJCOPY ' $@;
Q_GEN=@echo ' GEN ' $@;
CFLAGS =
CFLAGS += --std-sdcc99
CFLAGS += -Wa"-p"
CFLAGS += --xram-size 0x0200
CFLAGS += -DSYNCDELAYLEN=$(SYNCDELAYLEN)

# should to override previously set flags
FLAGS ?=
CFLAGS += $(FLAGS)

# set USB IDs depending on board
ifeq (${BOARD},atlys)
VID := 1D50
PID := 60B7
DID := 0002
else
ifeq (${BOARD},opsis)
VID := 2A19
PID := 5442
DID := 0002
else
$(error "Unknown board type '$(BOARD)'")
endif
endif

.PHONY: all clean distclean check check-descriptors check_int2jt load

all: $(TARGET).hex

check_int2jt: $(TARGET).hex
@export REQUESTED=$(shell grep "INT2JT=" $(TARGET).map | sed -e's/INT2JT=//'); \
export ACTUAL=$(shell grep "C:.*INT2JT" $(TARGET).map | sed -e's/C: *0*\([^ ]*\) _INT2JT.*/0x\1/' | tr A-Z a-z ); \
if [ "$$REQUESTED" != "$$ACTUAL" ]; then \
echo "INT2JT at $$ACTUAL but requested $$REQUESTED"; \
exit 1; \
fi

check: check_int2jt

clean:
$(Q_RM)$(RM) *.adb *.asm *.cdb *.iic *.lk *.lnk *.lst *.omf *.map \
*.mem *.rel *.rst *.sym descriptors_strings.* a.out date.h \
date.inc progOffsets.h version_data.h version_data.c ${TARGET}.hex
cd $(FX2LIBDIR) && make clean

distclean: clean
$(RM) -r $(FX2LIBDIR)

load: $(TARGET).hex
hdmi2usb-mode-switch --load-fx2-firmware $(TARGET).hex

$(CC_SRCS) $(AS_SRCS): $(FX2LIBDIR)/lib/fx2.lib

$(FX2LIBDIR)/lib/fx2.lib: $(FX2LIBDIR)/.git
cd $(dir $@) && make -j1

# We depend on a file inside the directory as git creates an
# empty dir for us.
#
# Note that although we have the variable FX2LIBDIR, the submodule
# magic will always check it out in fx2lib/
$(FX2LIBDIR)/.git: ../.gitmodules
git submodule sync --recursive -- $$(dirname $@)
git submodule update --recursive --init $$(dirname $@)
touch $@ -r ../.gitmodules

$(TARGET).hex: $(CC_OBJS) $(AS_OBJS)
$(Q_LINK)$(CC) $(CFLAGS) -o $@ $+ $(LIBS)
CFLAGS += -DVID=0x$(VID) -DPID=0x$(PID) -DDID=0x$(DID)

%.rel: %.a51
$(Q_AS)$(AS) -logs $?
LIBFX2DIR ?= ../third_party/libfx2
# variable required by libfx2 build system
LIBFX2 = $(LIBFX2DIR)/firmware/library
include $(LIBFX2)/fx2rules.mk
36 changes: 36 additions & 0 deletions common/usb_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef USB_DEFS_H
#define USB_DEFS_H

#include <fx2lib.h>
#include <fx2usb.h>

// Macro to easily define typedefs for descriptor structures
#define USB_DESC_CONST_CODE_TYPEDEF(desc) \
typedef __code const struct desc \
desc ## _c;

enum {
// Interface association descriptor, requires proper device descriptor
// see: USB Interface Association Descriptor Device Class Code and Use Model, 1.0
// https://www.usb.org/sites/default/files/iadclasscode_r10.pdf
USB_DEV_CLASS_MISCELLANEOUS = 0xef,
USB_DEV_SUBCLASS_COMMON = 0x02,
USB_DEV_PROTOCOL_INTERFACE_ASSOCIATION_DESCRIPTOR = 0x01,
USB_DESC_IF_ASSOC = 0x0b,
};

struct usb_desc_if_assoc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bFirstInterface;
uint8_t bInterfaceCount;
uint8_t bFunctionClass;
uint8_t bFunctionSubClass;
uint8_t bFunctionProtocol;
uint8_t iFunction;
};

USB_DESC_CONST_CODE_TYPEDEF(usb_desc_if_assoc)


#endif /* USB_DEFS_H */
Loading

0 comments on commit 4f2b6eb

Please sign in to comment.