Skip to content

Commit 56eb382

Browse files
committed
Add RP2040 oscilloscope device support
Signed-off-by: Daniel <danielgorbea@gmail.com>
1 parent bb36066 commit 56eb382

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; OpenHantek calibration file
2+
; individual calibration values for RP2040 without esternal circuit
3+
; copy into ~/.config/OpenHantek
4+
; will be read by .../src/hantekdso/modelRP2040.cpp
5+
6+
; multiply channel to get the correct gain
7+
[gain]
8+
9+
ch0\10mV=0.33
10+
ch0\20mV=0.33
11+
ch0\50mV=0.33
12+
ch0\100mV=0.33
13+
ch0\200mV=0.33
14+
ch0\500mV=0.33
15+
ch0\1000mV=0.33
16+
ch0\2000mV=0.33
17+
ch0\5000mV=0.33
18+
19+
ch1\10mV=0.33
20+
ch1\20mV=0.33
21+
ch1\50mV=0.33
22+
ch1\100mV=0.33
23+
ch1\200mV=0.33
24+
ch1\500mV=0.33
25+
ch1\1000mV=0.33
26+
ch1\2000mV=0.33
27+
ch1\5000mV=0.33
28+
29+
; add offset values
30+
[offset]
31+
32+
ch0\10mV=-127
33+
ch0\20mV=-127
34+
ch0\50mV=-127
35+
ch0\100mV=-127
36+
ch0\200mV=-127
37+
ch0\500mV=-127
38+
ch0\1000mV=-127
39+
ch0\2000mV=-127
40+
ch0\5000mV=-127
41+
42+
ch1\10mV=-127
43+
ch1\20mV=-127
44+
ch1\50mV=-127
45+
ch1\100mV=-127
46+
ch1\200mV=-127
47+
ch1\500mV=-127
48+
ch1\1000mV=-127
49+
ch1\2000mV=-127
50+
ch1\5000mV=-127
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
#include "modelRP2040.h"
4+
#include "hantekdsocontrol.h"
5+
#include "hantekprotocol/controlStructs.h"
6+
#include "usb/scopedevice.h"
7+
#include <QDebug>
8+
#include <QDir>
9+
#include <QSettings>
10+
11+
12+
#define VERBOSE 0
13+
14+
using namespace Hantek;
15+
16+
static ModelRP2040 modelInstance_rp2040;
17+
18+
static void initSpecifications( Dso::ControlSpecification &specification ) {
19+
// we drop 2K + 480 sample values due to unreliable start of stream
20+
// 20000 samples at 100kS/s = 200 ms gives enough to fill
21+
// the screen two times (for pre/post trigger) at 10ms/div = 100ms/screen
22+
// SAMPLESIZE defined in hantekdsocontrol.h
23+
// adapt accordingly in HantekDsoControl::convertRawDataToSamples()
24+
25+
// HW gain, voltage steps in V/div (ranges 20,50,100,200,500,1000,2000,5000 mV)
26+
specification.gain = { { 10, 20e-3 }, { 10, 50e-3 }, { 10, 100e-3 }, { 5, 200e-3 },
27+
{ 2, 500e-3 }, { 1, 1.00 }, { 1, 2.00 }, { 1, 5.00 } };
28+
29+
// Define the scaling between ADC sample values and real input voltage
30+
// Everything is scaled on the full screen height (8 divs)
31+
// The voltage/div setting: 20m 50m 100m 200m 500m 1V 2V 5V
32+
// Equivalent input voltage: 0.16V 0.4V 0.8V 1.6V 4V 8V 16V 40V
33+
// Theoretical gain setting: x10 x10 x10 x5 x2 x1 x1 x1
34+
// mV / digit: 4 4 4 8 20 40 40 40
35+
// specification.voltageScale[ 0 ] = { 255, 255, 255, 127.5, 51, 25.5, 25.5, 25.5 };
36+
// specification.voltageScale[ 1 ] = { 255, 255, 255, 127.5, 51, 25.5, 25.5, 25.5 };
37+
specification.voltageScale[ 0 ] = { 250, 250, 250, 125, 50, 25, 25, 25 };
38+
specification.voltageScale[ 1 ] = { 250, 250, 250, 125, 50, 25, 25, 25 };
39+
// Gain and offset can be corrected by individual config values from EEPROM or file
40+
// Lower effective sample rates < 10 kS/s use oversampling to increase the SNR
41+
42+
specification.samplerate.single.base = 100e3;
43+
specification.samplerate.single.max = 1e6;
44+
specification.samplerate.single.recordLengths = { UINT_MAX };
45+
specification.samplerate.multi.base = 100e3;
46+
specification.samplerate.multi.max = 1e6;
47+
specification.samplerate.multi.recordLengths = { UINT_MAX };
48+
49+
specification.fixedSampleRates = {
50+
// samplerate, sampleId, downsampling
51+
{ 1e3, 101, 10 },
52+
{ 2e3, 102, 10 },
53+
{ 5e3, 105, 10 },
54+
{ 10e3, 101, 1 },
55+
{ 20e3, 102, 1 },
56+
{ 50e3, 105, 1 },
57+
{ 100e3, 110, 1 },
58+
{ 200e3, 120, 1 },
59+
{ 500e3, 150, 1 },
60+
{ 1e6, 1, 1 }
61+
};
62+
63+
specification.couplings = { Dso::Coupling::DC, Dso::Coupling::AC };
64+
specification.triggerModes = {
65+
Dso::TriggerMode::AUTO,
66+
Dso::TriggerMode::NORMAL,
67+
Dso::TriggerMode::SINGLE,
68+
Dso::TriggerMode::ROLL,
69+
};
70+
71+
specification.fixedUSBinLength = 0;
72+
73+
specification.calfreqSteps = { 30, 40, 50, 60, 80, 100, 120, 160, 200, 250, 300, 400, 440,
74+
500, 600, 660, 800, 1000, 1200, 1600, 2000, 2500, 3300, 4000, 5000, 6000,
75+
8000, 10e3, 12e3, 16e3, 20e3, 25e3, 30e3, 40e3, 50e3, 60e3, 80e3, 100e3 };
76+
specification.hasCalibrationEEPROM = false;
77+
}
78+
79+
static void applyRequirements_( HantekDsoControl *dsoControl ) {
80+
dsoControl->addCommand( new ControlSetGain_CH1() ); // 0xE0
81+
dsoControl->addCommand( new ControlSetGain_CH2() ); // 0xE1
82+
dsoControl->addCommand( new ControlSetSamplerate() ); // 0xE2
83+
dsoControl->addCommand( new ControlStartSampling() ); // 0xE3
84+
dsoControl->addCommand( new ControlSetNumChannels() ); // 0xE4
85+
dsoControl->addCommand( new ControlSetCoupling() ); // 0xE5 (no effect w/o AC/DC HW mod)
86+
dsoControl->addCommand( new ControlSetCalFreq() ); // 0xE6
87+
}
88+
89+
/// VID/PID active VID/PID no FW Scope name
90+
// |------------| |------------| |------|
91+
ModelRP2040::ModelRP2040()
92+
: DSOModel( ID, 0x04b5, 0x2040, 0x04b5, 0x2040, 0, "", "RP2040", Dso::ControlSpecification( 2 ) ) {
93+
initSpecifications( specification );
94+
}
95+
96+
void ModelRP2040::applyRequirements( HantekDsoControl *dsoControl ) const { applyRequirements_( dsoControl ); }
97+
98+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
#pragma once
4+
5+
#include "dsomodel.h"
6+
7+
class HantekDsoControl;
8+
using namespace Hantek;
9+
10+
11+
struct ModelRP2040 : public DSOModel {
12+
static const int ID = 0x2040;
13+
ModelRP2040();
14+
void applyRequirements( HantekDsoControl *dsoControl ) const override;
15+
};
16+

openhantek/src/usb/scopedevice.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ bool ScopeDevice::connectDevice( QString &errorMessage ) {
7777
handle = nullptr;
7878
errorMessage =
7979
QCoreApplication::translate( "ScopeDevice", "Couldn't open device: %1" ).arg( libUsbErrorString( errorCode ) );
80+
qDebug() << " Couldn't open device: " << libUsbErrorString( errorCode );
8081
return false;
8182
}
8283
serialNumber = readUSBdescriptor( handle, descriptor.iSerialNumber );

utils/devd_rules_freebsd/openhantek.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,15 @@ notify 100 {
7878
match "product" "0x0120";
7979
action "chgrp openhantek /dev/$ugen; chmod g+rw /dev/$ugen; chgrp -h openhantek /dev/$ugen; chmod -h g+rw /dev/$ugen";
8080
};
81+
82+
83+
# RP2040 with FW
84+
85+
notify 100 {
86+
match "system" "USB";
87+
match "subsystem" "DEVICE";
88+
match "type" "ATTACH";
89+
match "vendor" "0x04B5";
90+
match "product" "0x2040";
91+
action "chgrp openhantek /dev/$ugen; chmod g+rw /dev/$ugen; chgrp -h openhantek /dev/$ugen; chmod -h g+rw /dev/$ugen";
92+
};

utils/udev_rules/60-openhantek.rules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ ATTRS{idVendor}=="04b5", ATTRS{idProduct}=="6021", TAG+="uaccess", TAG+="udev-ac
3131
ATTRS{idVendor}=="d4a2", ATTRS{idProduct}=="5660", TAG+="uaccess", TAG+="udev-acl", MODE="660", GROUP="plugdev"
3232
ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="608e", TAG+="uaccess", TAG+="udev-acl", MODE="660", GROUP="plugdev"
3333

34+
# RP2040 with FW
35+
ATTRS{idVendor}=="04b5", ATTRS{idProduct}=="2040", TAG+="uaccess", TAG+="udev-acl", MODE="660", GROUP="plugdev"
36+
3437
LABEL="openhantek_rules_end"

0 commit comments

Comments
 (0)