From: Uwe Hermann Date: Wed, 19 Apr 2017 22:47:03 +0000 (+0200) Subject: scopes: Factor out SET_COUPLING() and SET_CALIBRATION_PULSE(). X-Git-Tag: sigrok-firmware-fx2lafw-0.1.6~19 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=297fb13a138176c664bb80ef71f2d4f685793b29;p=sigrok-firmware-fx2lafw.git scopes: Factor out SET_COUPLING() and SET_CALIBRATION_PULSE(). --- diff --git a/hantek_6022be.c b/hantek_6022be.c index 93665b8d..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 @@ -137,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) { @@ -320,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) { @@ -367,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); @@ -388,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. */ diff --git a/hantek_6022bl.c b/hantek_6022bl.c index 66fc1de7..3da69116 100644 --- a/hantek_6022bl.c +++ b/hantek_6022bl.c @@ -26,6 +26,10 @@ #define SET_ANALOG_MODE() PA7 = 1 +#define SET_COUPLING(x) + +#define SET_CALIBRATION_PULSE(x) + /* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */ #define TOGGLE_CALIBRATION_PIN() PC2 = !PC2 @@ -138,6 +142,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) { @@ -321,6 +344,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) { @@ -368,7 +415,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); @@ -389,6 +436,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. */ diff --git a/sainsmart_dds120.c b/sainsmart_dds120.c index e4ba51c4..06e47905 100644 --- a/sainsmart_dds120.c +++ b/sainsmart_dds120.c @@ -26,6 +26,10 @@ #define SET_ANALOG_MODE() PA7 = 1 +#define SET_COUPLING(x) set_coupling(x) + +#define SET_CALIBRATION_PULSE(x) set_calibration_pulse(x) + /* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */ /* Note: There's no PE2 as IOE is not bit-addressable (see TRM 15.2). */ #define TOGGLE_CALIBRATION_PIN() IOE = IOE ^ 0x04 @@ -474,10 +478,10 @@ BOOL handle_vendorcommand(BYTE cmd) set_numchannels(EP0BUF[0]); return TRUE; case 0xe5: - set_coupling(EP0BUF[0]); + SET_COUPLING(EP0BUF[0]); return TRUE; case 0xe6: - set_calibration_pulse(EP0BUF[0]); + SET_CALIBRATION_PULSE(EP0BUF[0]); return TRUE; }