forked from jhoenicke/Hantek6022API
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
- Loading branch information
Showing
55 changed files
with
2,273 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ var | |
sdist | ||
develop-eggs | ||
.installed.cfg | ||
lib | ||
lib64 | ||
__pycache__ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[submodule "fx2lib_update"] | ||
path = PyHT6022/Firmware/fx2lib | ||
path = Firmware/fx2lib | ||
url = https://github.com/Ho-Ro/fx2lib | ||
[fx2lib] | ||
branch = master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fx2.lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright (C) 2009 Ubixum, Inc. | ||
# | ||
# This library 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 2.1 of the License, or (at your option) any later version. | ||
# | ||
# This library 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 library; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
AS8051?=sdas8051 | ||
CC=sdcc | ||
SDAR?=sdar | ||
SOURCES = serial.c i2c.c delay.c setupdat.c gpif.c eputils.c $(wildcard interrupts/*.c) | ||
FX2_OBJS = $(patsubst %.c,%.rel, $(SOURCES)) usbav.rel | ||
INCLUDES = -I../include | ||
SDCC = $(CC) -mmcs51 $(SDCCFLAGS) | ||
LIBS = fx2.lib | ||
|
||
all: $(LIBS) | ||
|
||
$(LIBS): $(FX2_OBJS) | ||
$(SDAR) -rc fx2.lib $? | ||
|
||
usbav.rel: usbav.a51 | ||
$(AS8051) -logs usbav.a51 | ||
|
||
%.rel: %.c | ||
$(SDCC) $(INCLUDES) -c $< -o $@ | ||
|
||
clean: | ||
rm -f *.{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,lib} | ||
rm -f interrupts/*.{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,dcb,lib} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* Copyright (C) 2009 Ubixum, Inc. | ||
* | ||
* This library 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 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library 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 library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
**/ | ||
|
||
#include <fx2regs.h> | ||
#include <fx2macros.h> | ||
#include <delay.h> | ||
|
||
void delay(WORD millis) { | ||
/** | ||
* It takes 12 crystal pulses to make 1 machine cycle (8051.com) | ||
* ez-usb trm 1.13 | ||
* 83.3 ns at 48mhz per instruction cycle | ||
* (assume 166.6ns at 24mhz) | ||
* (assume 333.3ns at 12mhz) | ||
* ez-usb trm 12.1 | ||
* Includes the cycles for each instruction | ||
**/ | ||
WORD loop_count; | ||
volatile WORD count; // NOTE perhaps use different solutions w/ out volatile | ||
|
||
|
||
// set count to the number of times we need to | ||
// go around a loop for 1 millisecond | ||
|
||
// then do that loop millis times. (1000 us=1ms) | ||
|
||
// 48mhz: 1000 us / (17 cycles * 83.3 ns / cycle / 1000 ns/us) = 706 | ||
// 24mhz: 353 | ||
// 12mhz: 177 | ||
// recalculate if the number of cycles changes | ||
// like if you change the loop below | ||
loop_count = CPUFREQ == CLK_12M ? 177 : | ||
CPUFREQ == CLK_24M ? 353 : 706; | ||
|
||
// sdcc generated assembly | ||
/* cycles code | ||
; delay.c:31: do { | ||
00101$: | ||
; delay.c:32: } while ( --count ); | ||
2 dec _delay_count_1_1 | ||
2 mov a,#0xff | ||
4 cjne a,_delay_count_1_1,00121$ | ||
2 dec (_delay_count_1_1 + 1) | ||
00121$: | ||
2 mov a,_delay_count_1_1 | ||
2 orl a,(_delay_count_1_1 + 1) | ||
3 jnz 00101$ | ||
Total 17 | ||
*/ | ||
|
||
do { | ||
count = loop_count; | ||
do { | ||
} while ( --count ); | ||
} while ( --millis ); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (C) 2009 Ubixum, Inc. | ||
* | ||
* This library 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 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library 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 library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
**/ | ||
|
||
|
||
|
||
|
||
#include <eputils.h> | ||
|
||
#include <fx2regs.h> | ||
|
||
#ifdef DEBUG_EPUTILS | ||
#include <stdio.h> | ||
#else | ||
#define printf(...) | ||
#endif | ||
|
||
void readep0( BYTE* dst, WORD len) { | ||
WORD read = 0; // n bytes read | ||
BYTE c,avail; | ||
while (read < len) { | ||
EP0BCH = 0; | ||
// NOTE need syncdelay? | ||
EP0BCL = 0; // re-arm ep so host can send more | ||
while (EP0CS & bmEPBUSY); | ||
avail = EP0BCL; // max size fits in one byte (64 bytes) | ||
for (c=0;c<avail;++c) | ||
dst[read+c] = EP0BUF[c]; | ||
read += avail; | ||
} | ||
} | ||
|
||
|
||
void writeep0( BYTE* src, WORD len) { | ||
WORD written = 0; | ||
BYTE c; | ||
while ( written < len ) { | ||
while ( EP0CS & bmEPBUSY ); // wait | ||
for (c=0;c<64 && written<len;++c ) { | ||
EP0BUF[c] = src[written++]; | ||
} | ||
EP0BCH = 0; | ||
EP0BCL= c; | ||
printf ( "Write %d bytes\n", c ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# common make targets for compiling fx2 firmware | ||
# | ||
# In your Makefile, define: | ||
# SOURCES: list of c files to compile | ||
# A51_SOURCES: list of any a51 files. | ||
# DEPS: list of any depedancies (like auto-generated header files) that need | ||
# generated prior to compiling. You must provide the target definition | ||
# for any DEPS you define. | ||
# BASENAME: name of your firmware file, i.e., myfirmware, but not myfirmware.c | ||
# | ||
# Leave these alone or redefine as necessary to customize firmware. | ||
# (Redefine after including this makefile) | ||
# VID vendor id | ||
# PID product id | ||
# LIBS optional additional libraries to link with the firmware. | ||
# SDCC build/link options | ||
# CODE_SIZE: Default --code-size 0x3c00 | ||
# XRAM_SIZE: Default --xram-size 0x0200 | ||
# XRAM_LOC: Default --xram-loc 0x3c00 | ||
# BUILDDIR: build directory (default build) | ||
# These two can be changed to be blank if no device descriptor is being used. | ||
# DSCR_AREA: Default -Wl"-b DSCR_AREA=0x3e00" | ||
# INT2JT: Default -Wl"-b INT2JT=0x3f00" | ||
# | ||
# Provided targets: | ||
# | ||
# default target: creates $(BASENAME).ihx | ||
# bix: creates $(BASENAME).bix | ||
# iic: creates $(BASENAME).iic | ||
# load: uses fx2load to load firmware.bix onto the development board | ||
# (You can customize VID/PID if you need to load the firmware onto a device that has different vendor and product id | ||
# The default is 0x04b4, 0x8613 | ||
# clean: delete all the temp files. | ||
# | ||
# | ||
# | ||
|
||
AS8051?=sdas8051 | ||
|
||
VID?=0x04b4 | ||
PID?=0x8613 | ||
|
||
INCLUDES?="" | ||
DSCR_AREA?=-Wl"-b DSCR_AREA=0x3e00" | ||
INT2JT?=-Wl"-b INT2JT=0x3f00" | ||
CC=sdcc | ||
CODE_SIZE?=--code-size 0x3c00 | ||
XRAM_SIZE?=--xram-size 0x0200 | ||
XRAM_LOC?=--xram-loc 0x3c00 | ||
BUILDDIR?=build | ||
|
||
FX2LIBDIR?=$(dir $(lastword $(MAKEFILE_LIST)))../ | ||
|
||
RELS=$(addprefix $(BUILDDIR)/, $(addsuffix .rel, $(notdir $(basename $(SOURCES) $(A51_SOURCES))))) | ||
# these are pretty good settings for most firmwares. | ||
# Have to be careful with memory locations for | ||
# firmwares that require more xram etc. | ||
SDCC = $(CC) -mmcs51 \ | ||
$(SDCCFLAGS) \ | ||
$(CODE_SIZE) \ | ||
$(XRAM_SIZE) \ | ||
$(XRAM_LOC) \ | ||
$(DSCR_AREA) \ | ||
$(INT2JT) | ||
|
||
|
||
.PHONY: all ihx iic bix load clean clean-all | ||
|
||
all: ihx | ||
ihx: $(BUILDDIR)/$(BASENAME).ihx | ||
bix: $(BUILDDIR)/$(BASENAME).bix | ||
iic: $(BUILDDIR)/$(BASENAME).iic | ||
|
||
$(FX2LIBDIR)/lib/fx2.lib: $(FX2LIBDIR)/lib/*.c $(FX2LIBDIR)/lib/*.a51 | ||
$(MAKE) -C $(FX2LIBDIR)/lib | ||
|
||
$(BUILDDIR): | ||
mkdir -p $(BUILDDIR) | ||
|
||
$(BUILDDIR)/$(BASENAME).ihx: $(BUILDDIR) $(SOURCES) $(A51_SOURCES) $(FX2LIBDIR)/lib/fx2.lib $(DEPS) | ||
# can't use default target %.rel because there is no way | ||
# to differentiate the dependency. (Is it %.rel: %.c or %.a51) | ||
for a in $(A51_SOURCES); do \ | ||
cp $$a $(BUILDDIR)/; \ | ||
cd $(BUILDDIR) && $(AS8051) -logs `basename $$a` && cd ..; done | ||
for s in $(SOURCES); do \ | ||
THISREL=$$(basename `echo "$$s" | sed -e 's/\.c$$/\.rel/'`); \ | ||
$(SDCC) -c -I $(FX2LIBDIR)/include -I $(INCLUDES) $$s -o $(BUILDDIR)/$$THISREL ; done | ||
$(SDCC) -o $@ $(RELS) fx2.lib -L $(FX2LIBDIR)/lib $(LIBS) | ||
|
||
|
||
$(BUILDDIR)/$(BASENAME).bix: $(BUILDDIR)/$(BASENAME).ihx | ||
objcopy -I ihex -O binary $< $@ | ||
$(BUILDDIR)/$(BASENAME).iic: $(BUILDDIR)/$(BASENAME).ihx | ||
$(FX2LIBDIR)/utils/ihx2iic.py -v $(VID) -p $(PID) $< $@ | ||
|
||
load: $(BUILDDIR)/$(BASENAME).bix | ||
fx2load -v $(VID) -p $(PID) $(BUILDDIR)/$(BASENAME).bix | ||
|
||
clean: | ||
rm -f $(foreach ext, a51 asm ihx lnk lk lst map mem rel rst rest sym adb cdb bix, $(BUILDDIR)/*.${ext}) | ||
|
||
clean-all: clean | ||
$(MAKE) -C $(FX2LIBDIR)/lib clean | ||
|
Oops, something went wrong.