Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: libfx2-migration: video example #52

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "third_party/fx2lib-linux-headers"]
path = third_party/fx2lib-linux-headers
url = https://github.com/mithro/fx2lib-linux-headers
[submodule "third_party/libfx2"]
path = third_party/libfx2
url = https://github.com/whitequark/libfx2.git
28 changes: 5 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,26 @@ addons:

install:
- export BOARD="$B" && echo "BOARD='$BOARD'"
- export TARGETS="$T" && echo "TARGETS='$TARGETS'"
- export DIR="$D" && echo "DIR='$DIR'"
- make conda
- export PATH=$PWD/conda/bin:$PATH
- which sdcc
- sdcc --version
- ./.travis/setup.sh

script:
- make $TARGETS
- make -C $DIR BOARD=$BOARD

jobs:
fail_fast: true
include:
#-----------------------------------------
# Video targets
# video
#-----------------------------------------
- stage: Build
env: B=opsis T="firmware-fx2"
env: B=opsis D="examples/video"
- stage: Build
env: B=atlys T="firmware-fx2"

#-----------------------------------------
# Audio targets
#-----------------------------------------
- stage: Build
env: B=opsis T="firmware-audio-fx2"
- stage: Build
env: B=atlys T="firmware-audio-fx2"
- stage: Build
env: B=fx2miniboard T="firmware-audio-fx2"

#-----------------------------------------
# Unconfigured targets
#-----------------------------------------
- stage: Build
env: B=opsis T="firmware-unconfigured"
- stage: Build
env: B=atlys T="firmware-unconfigured"
env: B=atlys D="examples/video"

#-----------------------------------------
# Build and deploy docs
Expand Down
141 changes: 35 additions & 106 deletions common/common.mk
Original file line number Diff line number Diff line change
@@ -1,114 +1,43 @@
#
# 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
CFLAGS += -DVID=0x$(VID) -DPID=0x$(PID) -DDID=0x$(DID)

$(TARGET).hex: $(CC_OBJS) $(AS_OBJS)
$(Q_LINK)$(CC) $(CFLAGS) -o $@ $+ $(LIBS)
LIBFX2DIR ?= ../third_party/libfx2
# variable required by libfx2 build system
LIBFX2 = $(LIBFX2DIR)/firmware/library
include $(LIBFX2)/fx2rules.mk

%.rel: %.a51
$(Q_AS)$(AS) -logs $?
# force proper dependecy to automatically build libfx2
$(LIBFX2)/lib/$(MODEL)/fx2.lib: $(LIBFX2)/.stamp
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