Skip to content

Commit

Permalink
scope: trig level and sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
vk2seb committed Dec 6, 2023
1 parent cb3c52f commit 68fbb5d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
42 changes: 38 additions & 4 deletions firmware/litex-fw/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
if opts.modify {
Text::with_alignment(
"-",
Point::new(vx+62, (vy+10*n) as i32),
Point::new(vx+62, (vy+7*n) as i32),
font,
Alignment::Left,
).draw(d)?;
Expand All @@ -166,13 +166,13 @@ where
}
Text::with_alignment(
opt.name(),
Point::new(vx+5, (vy+10*n) as i32),
Point::new(vx+5, (vy+7*n) as i32),
font,
Alignment::Left,
).draw(d)?;
Text::with_alignment(
&opt.value(),
Point::new(vx+60, (vy+10*n) as i32),
Point::new(vx+60, (vy+7*n) as i32),
font,
Alignment::Right,
).draw(d)?;
Expand Down Expand Up @@ -228,11 +228,45 @@ where
ufmt::uwrite!(&mut s, "SCOPE").ok();
draw_title_box(d, &s, Point::new(0, 0), Size::new(126, 64))?;

let yn = 3;

let stroke_grid = PrimitiveStyleBuilder::new()
.stroke_color(Gray4::new(1))
.stroke_width(1)
.build();

Line::new(Point::new(1, 32+yn),
Point::new(124, 32+yn))
.into_styled(stroke_grid)
.draw(d)?;

Line::new(Point::new(64, 10),
Point::new(64, 62))
.into_styled(stroke_grid)
.draw(d)?;

let trig_mv_px = opts.scope.trig_lvl.value >> 8;
let trig_sns_px = opts.scope.trig_sns.value >> 8;

Line::new(Point::new(1, 32+yn-trig_mv_px),
Point::new(124, 32+yn-trig_mv_px))
.into_styled(stroke_grid)
.draw(d)?;

Line::new(Point::new(1, 32+yn-trig_sns_px-trig_mv_px),
Point::new(4, 32+yn-trig_sns_px-trig_mv_px))
.into_styled(stroke_grid)
.draw(d)?;
Line::new(Point::new(1, 32+yn+trig_sns_px-trig_mv_px),
Point::new(4, 32+yn+trig_sns_px-trig_mv_px))
.into_styled(stroke_grid)
.draw(d)?;

let mut points: [Point; 124] = [Point::new(0, 0); 124];
for (n, point) in points.iter_mut().enumerate() {
if n < scope_samples.len() {
point.x = 1 + n as i32;
point.y = 33 + (scope_samples[n] >> 10) as i32;
point.y = 32+yn - (scope_samples[n] >> 10) as i32;
}
}
Polyline::new(&points)
Expand Down
14 changes: 12 additions & 2 deletions firmware/litex-fw/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct OScope {
trig_lo: bool,
subsample: usize,
n_subsample: usize,
trig_lvl_mv: i16,
trig_sns_mv: i16,
}

impl OScope {
Expand All @@ -66,6 +68,8 @@ impl OScope {
trig_lo: false,
subsample: 4,
n_subsample: 0,
trig_lvl_mv: 0,
trig_sns_mv: 1000,
}
}

Expand All @@ -80,8 +84,11 @@ impl OScope {
buf_in[N_CHANNELS*i+3],
];

self.trig_lo = self.trig_lo || x_in[0] < -4000;
let trigger = x_in[0] > 4000 && self.trig_lo;
let trig_lo_raw = 4*(self.trig_lvl_mv - self.trig_sns_mv);
let trig_hi_raw = 4*(self.trig_lvl_mv + self.trig_sns_mv);

self.trig_lo = self.trig_lo || x_in[0] < trig_lo_raw;
let trigger = x_in[0] > trig_hi_raw && self.trig_lo;

if (self.n_samples > 0 && self.n_samples != SCOPE_SAMPLES) ||
(self.n_samples == 0 && trigger) {
Expand Down Expand Up @@ -388,6 +395,8 @@ fn main() -> ! {
let scope = &mut oscope.borrow_ref_mut(cs);
if scope.full() {
scope.reset();
scope.trig_lvl_mv = opts.borrow_ref(cs).scope.trig_lvl.value as i16;
scope.trig_sns_mv = opts.borrow_ref(cs).scope.trig_sns.value as i16;
}
scope.samples
});
Expand All @@ -399,6 +408,7 @@ fn main() -> ! {
state.trace.len_us())
});


let touch = pmod0.touch();

draw::draw_main(&mut disp, opts, voices, &scope_samples, &touch,
Expand Down
18 changes: 17 additions & 1 deletion firmware/litex-fw/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub struct ScopeOptions {
pub selected: Option<usize>,
pub delay_len: NumOption<u32>,
pub enum_test: EnumOption<EnumTest>,
pub trig_lvl: NumOption<i32>,
pub trig_sns: NumOption<i32>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -102,7 +104,7 @@ impl_option_view!(AdsrOptions,
attack_ms, decay_ms, release_ms, resonance);

impl_option_view!(ScopeOptions,
delay_len, enum_test);
delay_len, enum_test, trig_lvl, trig_sns);

impl_option_view!(TouchOptions,
threshold);
Expand Down Expand Up @@ -166,6 +168,20 @@ impl Options {
min: 128,
max: 511,
},
trig_lvl: NumOption{
name: "trig lvl".into(),
value: 0,
step: 100,
min: -10000,
max: 10000,
},
trig_sns: NumOption{
name: "trig sns".into(),
value: 1000,
step: 100,
min: 100,
max: 5000,
},
enum_test: EnumOption{
name: "enumt".into(),
value: EnumTest::ValueA,
Expand Down

0 comments on commit 68fbb5d

Please sign in to comment.