Jelajahi Sumber

cores/no2usb: Include the USB fw code inside the 'core'

This allow all the usb stack stuff to be re-used between projects

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Sylvain Munaut 4 tahun lalu
induk
melakukan
17a79b32b5

+ 5 - 0
cores/usb/fw/fw.mk

@@ -0,0 +1,5 @@
+SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
+
+ifeq ($(NO2USB_FW_VERSION),0)
+include $(SELF_DIR)v0/fw.mk
+endif

projects/riscv_usb/fw/usb_gen_strings.py → cores/usb/fw/usb_gen_strings.py


+ 25 - 0
cores/usb/fw/v0/fw.mk

@@ -0,0 +1,25 @@
+CORE_no2usb_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/../..)
+
+INC_no2usb := -I$(CORE_no2usb_DIR)/fw/v0/include
+
+HEADERS_no2usb=$(addprefix $(CORE_no2usb_DIR)/fw/v0/include/, \
+	no2usb/usb.h \
+	no2usb/usb_dfu.h \
+	no2usb/usb_dfu_proto.h \
+	no2usb/usb_dfu_rt.h \
+	no2usb/usb_hw.h \
+	no2usb/usb_priv.h \
+	no2usb/usb_proto.h \
+)
+
+SOURCES_no2usb=$(addprefix $(CORE_no2usb_DIR)/fw/v0/src/, \
+	usb.c \
+	usb_ctrl_ep0.c \
+	usb_ctrl_std.c \
+	usb_dfu.c \
+	usb_dfu_rt.c \
+	usb_dfu_vendor.c \
+)
+
+usb_str_%.gen.h: usb_str_%.txt
+	$(CORE_no2usb_DIR)/fw/usb_gen_strings.py $< $@ $(BOARD)

projects/riscv_usb/fw/usb.h → cores/usb/fw/v0/include/no2usb/usb.h


projects/riscv_usb/fw/usb_dfu.h → cores/usb/fw/v0/include/no2usb/usb_dfu.h


projects/riscv_usb/fw/usb_dfu_proto.h → cores/usb/fw/v0/include/no2usb/usb_dfu_proto.h


projects/riscv_usb/fw/usb_dfu_rt.h → cores/usb/fw/v0/include/no2usb/usb_dfu_rt.h


projects/riscv_usb/fw/usb_hw.h → cores/usb/fw/v0/include/no2usb/usb_hw.h


projects/riscv_usb/fw/usb_priv.h → cores/usb/fw/v0/include/no2usb/usb_priv.h


projects/riscv_usb/fw/usb_proto.h → cores/usb/fw/v0/include/no2usb/usb_proto.h


+ 4 - 3
projects/riscv_usb/fw/usb.c

@@ -25,10 +25,11 @@
 #include <stdbool.h>
 #include <string.h>
 
+#include <no2usb/usb_hw.h>
+#include <no2usb/usb_priv.h>
+#include <no2usb/usb.h>
+
 #include "console.h"
-#include "usb_hw.h"
-#include "usb_priv.h"
-#include "usb.h"
 
 
 /* Main stack state */

+ 3 - 2
projects/riscv_usb/fw/usb_ctrl_ep0.c

@@ -25,9 +25,10 @@
 #include <stdbool.h>
 #include <string.h>
 
+#include <no2usb/usb_hw.h>
+#include <no2usb/usb_priv.h>
+
 #include "console.h"
-#include "usb_hw.h"
-#include "usb_priv.h"
 
 #define EP0_PKT_LEN	64
 

+ 3 - 2
projects/riscv_usb/fw/usb_ctrl_std.c

@@ -25,9 +25,10 @@
 #include <stdbool.h>
 #include <string.h>
 
+#include <no2usb/usb_hw.h>
+#include <no2usb/usb_priv.h>
+
 #include "console.h"
-#include "usb_hw.h"
-#include "usb_priv.h"
 
 
 	/* Control Request implementation */

+ 4 - 3
projects/riscv_usb/fw/usb_dfu.c

@@ -25,10 +25,11 @@
 #include <stdbool.h>
 #include <string.h>
 
+#include <no2usb/usb.h>
+#include <no2usb/usb_dfu.h>
+#include <no2usb/usb_dfu_proto.h>
+
 #include "spi.h"
-#include "usb.h"
-#include "usb_dfu.h"
-#include "usb_dfu_proto.h"
 
 
 #define DFU_VENDOR_PROTO

+ 3 - 3
projects/riscv_usb/fw/usb_dfu_rt.c

@@ -25,9 +25,9 @@
 #include <stdbool.h>
 #include <string.h>
 
-#include "usb.h"
-#include "usb_dfu_rt.h"
-#include "usb_dfu_proto.h"
+#include <no2usb/usb.h>
+#include <no2usb/usb_dfu_rt.h>
+#include <no2usb/usb_dfu_proto.h>
 
 
 #define DFU_POLL_MS		250

+ 2 - 1
projects/riscv_usb/fw/usb_dfu_vendor.c

@@ -25,7 +25,8 @@
 #include <stdbool.h>
 #include <string.h>
 
-#include "usb.h"
+#include <no2usb/usb.h>
+
 #include "spi.h"
 
 

+ 14 - 22
projects/riscv_usb/fw/Makefile

@@ -6,8 +6,11 @@ ICEPROG = iceprog
 DFU_UTIL = dfu-util
 
 BOARD_DEFINE=BOARD_$(shell echo $(BOARD) | tr a-z\- A-Z_)
-CFLAGS=-Wall -Os -march=rv32i -mabi=ilp32 -ffreestanding -flto -nostartfiles -fomit-frame-pointer -Wl,--gc-section --specs=nano.specs -D$(BOARD_DEFINE)
+CFLAGS=-Wall -Os -march=rv32i -mabi=ilp32 -ffreestanding -flto -nostartfiles -fomit-frame-pointer -Wl,--gc-section --specs=nano.specs -D$(BOARD_DEFINE) -I.
 
+NO2USB_FW_VERSION=0
+include ../../../cores/usb/fw/fw.mk
+CFLAGS += $(INC_no2usb)
 
 HEADERS_common=\
 	config.h \
@@ -15,10 +18,8 @@ HEADERS_common=\
 	led.h \
 	mini-printf.h \
 	spi.h \
-	usb_hw.h \
-	usb_priv.h \
-	usb_proto.h \
-	utils.h
+	utils.h \
+	$(HEADERS_no2usb)
 
 SOURCES_common=\
 	start.S \
@@ -26,31 +27,25 @@ SOURCES_common=\
 	led.c \
 	mini-printf.c  \
 	spi.c \
-	usb.c \
-	usb_ctrl_ep0.c \
-	usb_ctrl_std.c \
-	utils.c
+	utils.c \
+	$(SOURCES_no2usb)
 
 HEADERS_dfu=\
-	usb_dfu.h \
-	usb_dfu_proto.h \
 	usb_str_dfu.gen.h
 
 SOURCES_dfu=\
 	fw_dfu.c \
-	usb_dfu.c \
-	usb_dfu_vendor.c \
-	usb_desc_dfu.c
+	usb_desc_dfu.c \
+	$(NULL)
 
 HEADERS_app=\
-	usb_dfu_rt.h \
-	usb_dfu_proto.h \
-	usb_str_app.gen.h
+	usb_str_app.gen.h \
+	$(NULL)
 
 SOURCES_app=\
 	fw_app.c \
-	usb_dfu_rt.c \
-	usb_desc_app.c
+	usb_desc_app.c \
+	$(NULL)
 
 
 all: boot_dfu.hex boot_app.hex fw_dfu.bin fw_app.bin
@@ -75,9 +70,6 @@ fw_app.elf: lnk-app.lds $(HEADERS_app) $(SOURCES_app) $(HEADERS_common) $(SOURCE
 %.bin: %.elf
 	$(OBJCOPY) -O binary $< $@
 
-usb_str_%.gen.h: usb_str_%.txt
-	./usb_gen_strings.py $< $@ $(BOARD)
-
 
 prog_dfu: fw_dfu.bin
 	$(ICEPROG) -o 384k $<

+ 2 - 2
projects/riscv_usb/fw/fw_app.c

@@ -29,8 +29,8 @@
 #include "led.h"
 #include "mini-printf.h"
 #include "spi.h"
-#include "usb.h"
-#include "usb_dfu_rt.h"
+#include <no2usb/usb.h>
+#include <no2usb/usb_dfu_rt.h>
 #include "utils.h"
 
 

+ 2 - 2
projects/riscv_usb/fw/fw_dfu.c

@@ -29,8 +29,8 @@
 #include "led.h"
 #include "mini-printf.h"
 #include "spi.h"
-#include "usb.h"
-#include "usb_dfu.h"
+#include <no2usb/usb.h>
+#include <no2usb/usb_dfu.h>
 #include "utils.h"
 
 

+ 2 - 2
projects/riscv_usb/fw/usb_desc_app.c

@@ -21,8 +21,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "usb_proto.h"
-#include "usb.h"
+#include <no2usb/usb_proto.h>
+#include <no2usb/usb.h>
 
 #define NULL ((void*)0)
 #define num_elem(a) (sizeof(a) / sizeof(a[0]))

+ 2 - 2
projects/riscv_usb/fw/usb_desc_dfu.c

@@ -21,8 +21,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include "usb_proto.h"
-#include "usb.h"
+#include <no2usb/usb_proto.h>
+#include <no2usb/usb.h>
 
 #define NULL ((void*)0)
 #define num_elem(a) (sizeof(a) / sizeof(a[0]))