Skip to content

Commit

Permalink
Started custom firmware (not yet ready)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoenicke committed May 2, 2015
1 parent 44817f4 commit 445b323
Show file tree
Hide file tree
Showing 11 changed files with 788 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "PyHT6022/HantekFirmware/fx2lib"]
path = PyHT6022/HantekFirmware/fx2lib
url = https://github.com/djmuhlestein/fx2lib
9 changes: 8 additions & 1 deletion PyHT6022/HantekFirmware/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

def fx2_ihex_to_control_packets(firmware_location):
packets = []
# disable 8051
packets.append(FirmwareControlPacket(1, 0x7f92, '\x01'))
packets.append(FirmwareControlPacket(1, 0xe600, '\x01'))
with open(firmware_location, 'r') as f:
for line in f.readlines():
line = line.strip()
Expand All @@ -28,9 +31,13 @@ def fx2_ihex_to_control_packets(firmware_location):
packets.append(FirmwareControlPacket(record_len, addr, array.array('B', record_data).tostring()))
elif record_type == 0x01:
assert file_checksum == 0xFF
return packets
break;
else:
raise ValueError('Unknown record type 0x{:2x} encountered!'.format(record_type))
# enable 8051
packets.append(FirmwareControlPacket(1, 0x7f92, '\x00'))
packets.append(FirmwareControlPacket(1, 0xe600, '\x00'))
return packets

base_path = os.path.dirname(os.path.realpath(__file__))
stock_firmware = fx2_ihex_to_control_packets(os.path.join(base_path, 'stock', 'stock_fw.ihex'))
Expand Down
33 changes: 33 additions & 0 deletions PyHT6022/HantekFirmware/custom/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (C) 2010 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



# change location of fx2libdir if needed
FX2LIBDIR=../fx2lib
SOURCES=fw.c device.c
A51_SOURCES=dscr.a51
BASENAME=firmware


DSCR_AREA=-Wl"-b DSCR_AREA=0x3d00"
INT2JT=-Wl"-b INT2JT=0x3f00"
CODE_SIZE=--code-size 0x3c00
XRAM_LOC=--xram-loc 0x3c00
XRAM_SIZE=--xram-size 0x0100

include $(FX2LIBDIR)/lib/fx2.mk

213 changes: 213 additions & 0 deletions PyHT6022/HantekFirmware/custom/device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
/**
* Copyright (C) 2009 Ubixum, Inc.
* Copyright (C) 2015 Jochen Hoenicke
*
* 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 <fx2macros.h>

#ifdef DEBUG_FIRMWARE
#include <stdio.h>
#else
#define printf(...)
#endif




BOOL set_voltage(BYTE channel, BYTE val)
{
const BYTE val2bits[] = { 1, 0x24*4, 0x24*2, 1, 1, 0x24*0,
1, 1, 1, 1, 0x24*6 };
BYTE bits = val < 11 ? val2bits[val] : -1;
if (bits != 1) {
int mask = channel ? 0xe0 : 0x1c;
IOC = (IOC & ~mask) | (bits & mask);
return TRUE;
}
return FALSE;
}

BOOL set_numchannels(BYTE numchannels)
{
if (numchannels >=1 && numchannels <= 2) {
BYTE fifocfg = 7 + numchannels;
EP2FIFOCFG = fifocfg;
EP6FIFOCFG = fifocfg;
return TRUE;
}
return FALSE;
}

struct samplerate_info {
BYTE rate;
BYTE wait0;
BYTE wait1;
BYTE jump;
BYTE jopcode;
BYTE ifcfg;
} samplerates[] = {
{ 48, 1, 1, 9, 3, 0xea },
{ 30, 1, 1, 9, 3, 0xaa },
{ 24, 1, 1, 9, 1, 0xca },
{ 16, 1, 1, 1, 1, 0xca },
{ 12, 1, 2, 1, 1, 0xca },
{ 8, 2, 3, 1, 1, 0xca },
{ 4, 5, 6, 1, 1, 0xca },
{ 2, 11, 12, 1, 1, 0xca },
{ 1, 23, 24, 1, 1, 0xca },
{ 50, 47, 48, 1, 1, 0xca },
{ 20, 119, 120, 1, 1, 0xca },
{ 10, 239, 240, 1, 1, 0xca }
};

BOOL set_samplerate(BYTE rate)
{
int i;
for (i = 0; i < sizeof(samplerates)/sizeof(samplerates[0]); i++) {
if (samplerates[i].rate == rate) {
BYTE* data;
IFCONFIG = samplerates[i].ifcfg;
GPIFABORT = 0xff;
GPIFREADYCFG = 0xc0;
GPIFCTLCFG = 0x00;
GPIFIDLECS = 0x00;
GPIFIDLECTL = 0x0f;
GPIFWFSELECT = 0x00;
GPIFREADYSTAT = 0x00;

data = &GPIF_WAVE_DATA + 0;
*data++ = samplerates[i].wait0;
*data++ = samplerates[i].wait1;
*data++ = samplerates[i].jump;
data += 5;
*data++ = 1;
*data++ = 2;
*data++ = samplerates[i].jopcode;
data += 5;
*data++ = 0xff;
*data++ = samplerates[i].jopcode == 3 ? 0xff : 0xfb;
*data++ = 0xff;
data += 5;
*data++ = 0x0;
*data++ = 0x0;
*data++ = 0x12;
return TRUE;
}
}
return FALSE;
}

BOOL handle_get_descriptor() {
return FALSE;
}

//************************** Configuration Handlers *****************************

// change to support as many interfaces as you need
volatile BYTE alt=0; // alt interface

// set *alt_ifc to the current alt interface for ifc
BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc) {
*alt_ifc=alt;
return TRUE;
}
// return TRUE if you set the interface requested
// NOTE this function should reconfigure and reset the endpoints
// according to the interface descriptors you provided.
BOOL handle_set_interface(BYTE ifc,BYTE alt_ifc) {
printf ( "Set Interface.\n" );
if (ifc == 0) {
alt = alt_ifc;
// select_interface(ifc);
}
return TRUE;
}

// handle getting and setting the configuration
// 1 is the default. If you support more than one config
// keep track of the config number and return the correct number
// config numbers are set int the dscr file.
volatile BYTE config=1;
BYTE handle_get_configuration() {
return config;
}

// NOTE changing config requires the device to reset all the endpoints
BOOL handle_set_configuration(BYTE cfg) {
printf ( "Set Configuration.\n" );
config=cfg;
return TRUE;
}


//******************* VENDOR COMMAND HANDLERS **************************

extern volatile __bit active;

BOOL handle_vendorcommand(BYTE cmd) {
active = 1;
switch (cmd) {
case 0xa0:
// handled by EZ-USB
return TRUE;

case 0xe0:
case 0xe1:
while (EP0CS & bmEPBUSY);
set_voltage(cmd - 0xe0, EP0BUF[0]);
EP0BCH=0;
EP0BCL=0;
return TRUE;
case 0xe2:
while (EP0CS & bmEPBUSY);
set_samplerate(EP0BUF[0]);
EP0BCH=0;
EP0BCL=0;
return TRUE;
case 0xe4:
while (EP0CS & bmEPBUSY);
set_numchannels(EP0BUF[0]);
EP0BCH=0;
EP0BCL=0;
return TRUE;
}
return FALSE; // not handled by handlers
}

//******************** INIT ***********************

void main_init() {

REVCTL=3;
SETIF48MHZ();

EP4CFG = 0;
EP8CFG = 0;

set_voltage(0, 1);
set_voltage(1, 1);
set_samplerate(1);
set_numchannels(1);

printf ( "Initialization Done.\n" );
}


void main_loop() {
}


Loading

0 comments on commit 445b323

Please sign in to comment.