X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hantek_6022be.c;h=ad8f5ae862633bcc23378c5a765d45f8902a4569;hb=297fb13a138176c664bb80ef71f2d4f685793b29;hp=bfd4fd44447c1cf7c820883a95d83dded6a4aace;hpb=4d971e019068b5747fe439b177c57cd635f3b9dd;p=sigrok-firmware-fx2lafw.git diff --git a/hantek_6022be.c b/hantek_6022be.c index bfd4fd44..ad8f5ae8 100644 --- a/hantek_6022be.c +++ b/hantek_6022be.c @@ -26,6 +26,10 @@ #define SET_ANALOG_MODE() +#define SET_COUPLING(x) + +#define SET_CALIBRATION_PULSE(x) + /* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */ #define TOGGLE_CALIBRATION_PIN() PA7 = !PA7 @@ -33,6 +37,12 @@ #define LED_GREEN() PC0 = 1; PC1 = 0; #define LED_RED() PC0 = 0; PC1 = 1; +/* CTLx pin index (IFCLK, ADC clock input). */ +#define CTL_BIT 2 + +#define OUT0 ((1 << CTL_BIT) << 4) /* OEx = 1, CTLx = 0 */ +#define OE_CTL (((1 << CTL_BIT) << 4) | (1 << CTL_BIT)) /* OEx = CTLx = 1 */ + /* Change to support as many interfaces as you need. */ static BYTE altiface = 0; @@ -131,6 +141,25 @@ static BOOL set_voltage(BYTE channel, BYTE val) return TRUE; } +/** + * Each LSB in the nibble of the byte controls the coupling per channel. + * + * Setting PE3 disables AC coupling capacitor on CH0. + * Setting PE0 disables AC coupling capacitor on CH1. + */ +static void set_coupling(BYTE coupling_cfg) +{ + if (coupling_cfg & 0x01) + IOE |= 0x08; + else + IOE &= ~0x08; + + if (coupling_cfg & 0x10) + IOE |= 0x01; + else + IOE &= ~0x01; +} + static BOOL set_numchannels(BYTE numchannels) { if (numchannels == 1 || numchannels == 2) { @@ -224,16 +253,16 @@ static const struct samplerate_info { } samplerates[] = { { 48, 0x80, 0, 3, 0, 0x00, 0xea }, { 30, 0x80, 0, 3, 0, 0x00, 0xaa }, - { 24, 1, 0, 2, 1, 0x40, 0xca }, - { 16, 1, 1, 2, 0, 0x40, 0xca }, - { 12, 2, 1, 2, 0, 0x40, 0xca }, - { 8, 3, 2, 2, 0, 0x40, 0xca }, - { 4, 6, 5, 2, 0, 0x40, 0xca }, - { 2, 12, 11, 2, 0, 0x40, 0xca }, - { 1, 24, 23, 2, 0, 0x40, 0xca }, - { 50, 48, 47, 2, 0, 0x40, 0xca }, - { 20, 120, 119, 2, 0, 0x40, 0xca }, - { 10, 240, 239, 2, 0, 0x40, 0xca }, + { 24, 1, 0, 2, 1, OUT0, 0xca }, + { 16, 1, 1, 2, 0, OUT0, 0xca }, + { 12, 2, 1, 2, 0, OUT0, 0xca }, + { 8, 3, 2, 2, 0, OUT0, 0xca }, + { 4, 6, 5, 2, 0, OUT0, 0xca }, + { 2, 12, 11, 2, 0, OUT0, 0xca }, + { 1, 24, 23, 2, 0, OUT0, 0xca }, + { 50, 48, 47, 2, 0, OUT0, 0xca }, + { 20, 120, 119, 2, 0, OUT0, 0xca }, + { 10, 240, 239, 2, 0, OUT0, 0xca }, }; static BOOL set_samplerate(BYTE rate) @@ -290,8 +319,8 @@ static BOOL set_samplerate(BYTE rate) /* OUTPUT 0-7 */ EXTAUTODAT2 = samplerates[i].out0; - EXTAUTODAT2 = 0x44; /* OE2=1, CTL2=1 */ - EXTAUTODAT2 = 0x44; /* OE2=1, CTL2=1 */ + EXTAUTODAT2 = OE_CTL; + EXTAUTODAT2 = OE_CTL; EXTAUTODAT2 = 0; EXTAUTODAT2 = 0; EXTAUTODAT2 = 0; @@ -314,6 +343,30 @@ static BOOL set_samplerate(BYTE rate) return TRUE; } +static BOOL set_calibration_pulse(BYTE fs) +{ + switch (fs) { + case 0: // 100Hz + RCAP2L = -10000 & 0xff; + RCAP2H = (-10000 & 0xff00) >> 8; + return TRUE; + case 1: // 1kHz + RCAP2L = -1000 & 0xff; + RCAP2H = (-1000 & 0xff00) >> 8; + return TRUE; + case 10: // 1kHz + RCAP2L = (BYTE)(-100 & 0xff); + RCAP2H = 0xff; + return TRUE; + case 50: // 50kHz + RCAP2L = (BYTE)(-20 & 0xff); + RCAP2H = 0xff; + return TRUE; + default: + return FALSE; + } +} + /* Set *alt_ifc to the current alt interface for ifc. */ BOOL handle_get_interface(BYTE ifc, BYTE *alt_ifc) { @@ -361,7 +414,7 @@ BOOL handle_vendorcommand(BYTE cmd) ledcounter = 1000; /* Clear EP0BCH/L for each valid command. */ - if (cmd >= 0xe0 && cmd <= 0xe4) { + if (cmd >= 0xe0 && cmd <= 0xe6) { EP0BCH = 0; EP0BCL = 0; while (EP0CS & bmEPBUSY); @@ -382,6 +435,12 @@ BOOL handle_vendorcommand(BYTE cmd) case 0xe4: set_numchannels(EP0BUF[0]); return TRUE; + case 0xe5: + SET_COUPLING(EP0BUF[0]); + return TRUE; + case 0xe6: + SET_CALIBRATION_PULSE(EP0BUF[0]); + return TRUE; } return FALSE; /* Not handled by handlers. */ @@ -435,7 +494,7 @@ static void main(void) ET2 = 1; TR2 = 1; - RENUMERATE(); + RENUMERATE_UNCOND(); PORTECFG = 0; PORTCCFG = 0;