Skip to content

Commit a7f342d

Browse files
committed
Merge branch 'buffered-terminal' of https://github.com/rustbox/esp32c3-vgaterm into refactor/nom-it-up
2 parents fb9d02f + 0b63b60 commit a7f342d

File tree

10 files changed

+57
-65
lines changed

10 files changed

+57
-65
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ critical-section = "1.1.1"
4040
embedded-graphics = "0.7.1"
4141
embedded-hal = "0.2"
4242
esp-alloc = { version = "0.2.0", features = ["oom-handler"] }
43+
esp-backtrace = { version = "0.6.0", features = [
44+
"esp32c3",
45+
"panic-handler",
46+
"exception-handler",
47+
"print-jtag-serial",
48+
] }
4349
esp-println = { version = "0.4.0", default-features = false, features = [
4450
"esp32c3",
4551
"jtag_serial",
@@ -54,12 +60,6 @@ nb = "1.1"
5460
nom = { version = "7.1.3", default-features = false, features = ["alloc"] }
5561
riscv = "0.10.1"
5662
unroll = "0.1.5"
57-
esp-backtrace = { version = "0.6.0", features = [
58-
"esp32c3",
59-
"panic-handler",
60-
"exception-handler",
61-
"print-jtag-serial",
62-
] }
6363

6464
[dev-dependencies]
6565

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ At this point you are ready to build and upload
3030

3131
2. Flash to the CPU
3232

33-
`espflash flash /dev/ttyUSB0 target/riscv32imac-unknown-none-elf/debug/vgaterm --monitor --format direct-boot`
33+
`espflash flash target/riscv32imac-unknown-none-elf/debug/vgaterm --monitor --format direct-boot`
3434

3535
Where `/dev/ttyUSB0` should be whatever serial port the esp32 is connected to. It's highly recommended that your user
3636
is added to the `dialout` group which will allow you to interact with `/dev/ttyUSB0` without using sudo.

examples/escape_seq.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ fn main() -> ! {
8787
riscv::interrupt::enable();
8888
}
8989

90-
9190
let r = ansi::parse_esc_str("abcd\u{1B}[XYZ\u{1B}[");
9291
println!("{:?}", r);
9392

src/ansi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn cursor_to_line_col(input: &str) -> OpResult {
214214
(
215215
rest,
216216
Op::MoveCursorAbs {
217-
x: b.saturating_sub(1) - 1,
217+
x: b.saturating_sub(1),
218218
y: a.saturating_sub(1),
219219
},
220220
)

src/bin/vgaterm.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
extern crate alloc;
66

77
use alloc::{collections::VecDeque, string::String, vec::Vec};
8-
use esp32c3_hal::{clock::{ClockControl, CpuClock}, peripherals::UART0};
8+
use esp32c3_hal::clock::{ClockControl, CpuClock};
99
use esp32c3_hal::prelude::*;
1010
use esp32c3_hal::timer::TimerGroup;
1111
use esp32c3_hal::{gpio::IO, peripherals::Peripherals, Rtc};
12+
use esp_backtrace as _;
1213
use esp_println::println;
13-
use vgaterm::{Delay, usb_keyboard::US_ENGLISH, Work, interrupt::Priority};
1414
use vgaterm::perf::configure_counter_for_cpu_cycles;
1515
use vgaterm::{self, video};
16-
use esp_backtrace as _;
16+
use vgaterm::{interrupt::Priority, usb_keyboard::US_ENGLISH, Work};
1717

18-
use core::{arch::asm, fmt::Write};
18+
use core::fmt::Write;
1919

20-
core::arch::global_asm!(".global _heap_size; _heap_size = 0xC000");
20+
core::arch::global_asm!(".global _heap_size; _heap_size = 0xB000");
2121

2222
#[global_allocator]
2323
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty();
@@ -79,15 +79,17 @@ fn main() -> ! {
7979
vgaterm::uart::interrupt_enable0(Priority::Priority6);
8080
vgaterm::gpio::interrupt_enable(Priority::max());
8181

82-
8382
unsafe {
8483
riscv::interrupt::enable();
8584
}
8685

8786
vgaterm::timer::start_repeat_timer0_callback(1_000_000, || unsafe {
8887
if NUM_BYTES > 0 {
89-
println!("{} bytes", NUM_BYTES );
90-
println!("{} draw cycles per byte", vgaterm::CHARACTER_DRAW_CYCLES as f32 / NUM_BYTES as f32);
88+
println!("{} bytes", NUM_BYTES);
89+
println!(
90+
"{} draw cycles per byte",
91+
vgaterm::CHARACTER_DRAW_CYCLES as f32 / NUM_BYTES as f32
92+
);
9193
NUM_BYTES = 0;
9294
}
9395
vgaterm::CHARACTER_DRAW_CYCLES = 0;
@@ -176,7 +178,9 @@ fn main() -> ! {
176178
while let Ok(r) = serial0.read() {
177179
b.push(r);
178180
}
179-
unsafe { NUM_BYTES += b.len(); }
181+
unsafe {
182+
NUM_BYTES += b.len();
183+
}
180184
String::from_utf8(b).unwrap()
181185
};
182186

@@ -188,23 +192,23 @@ fn main() -> ! {
188192
match mode {
189193
ConnectMode::ConnectHost => {
190194
let _ = serial0.write_str(c);
191-
},
195+
}
192196
ConnectMode::LocalEcho => {
193197
terminal.type_str(c);
194-
},
195-
ConnectMode::None => { }
198+
}
199+
ConnectMode::None => {}
196200
};
197-
198-
},
199-
Work::WouldBlock => {},
201+
}
202+
Work::WouldBlock => {}
200203
Work::WouldBlockUntil(_) => {}
201204
}
202205

203206
// Draw the characters on the frame
204207
// Flush the Display to the BUFFER
205-
// display.flush();
206-
207-
if !keyvents.is_empty() || unsafe { (*UART0::PTR).status.read().rxfifo_cnt().bits() } > 0 {
208+
display.flush();
209+
210+
if !keyvents.is_empty() {
211+
println!("{:?}", keyvents);
208212
continue;
209213
}
210214

src/channel.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
use core::cell::RefCell;
22

3-
use alloc::{collections::VecDeque, sync::Arc, vec::Vec, string::{ToString, String}};
3+
use alloc::{
4+
collections::VecDeque,
5+
string::{String, ToString},
6+
sync::Arc,
7+
vec::Vec,
8+
};
49
use critical_section::Mutex;
510

611
pub struct Sender<T> {

src/display.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use embedded_graphics::{
88
mono_font::{MonoTextStyle, MonoTextStyleBuilder},
99
pixelcolor::raw::RawU8,
1010
prelude::*,
11+
primitives::Rectangle,
1112
text::Text,
12-
Pixel, primitives::Rectangle,
13+
Pixel,
1314
};
14-
use esp_println::print;
1515

1616
use crate::{
1717
color::{self, Rgb3},
@@ -38,7 +38,7 @@ impl Display {
3838

3939
/// Sets the pixel color the location in the video BUFFER
4040
/// to the given color
41-
///
41+
///
4242
/// SAFETY: This directly sets the pixel to video memory which
4343
/// is unsafe, but should be okay since we're the only ones
4444
/// setting memory in the buffer and SPI takes exclusive control
@@ -53,7 +53,6 @@ impl Display {
5353
*unsafe { &mut video::BUFFER[pos] } = px;
5454
}
5555
}
56-
5756
}
5857

5958
impl Default for Display {
@@ -85,20 +84,20 @@ impl DrawTarget for Display {
8584
&& coord.y < video::HEIGHT as i32
8685
{
8786
let i = coord.y as usize * video::WIDTH + coord.x as usize;
88-
// let raw = RawU8::from(color);
89-
self.set_pixel(i, color.to_byte());
87+
let raw = RawU8::from(color);
88+
self.push(i, raw.into_inner());
9089
}
9190
}
9291
});
93-
// unsafe { crate::CHARACTER_DRAW_CYCLES += count };
92+
unsafe { crate::CHARACTER_DRAW_CYCLES += count };
9493
Ok(())
9594
}
9695

9796
#[inline(always)]
9897
fn fill_contiguous<I>(&mut self, area: &Rectangle, colors: I) -> Result<(), Self::Error>
99-
where
100-
I: IntoIterator<Item = Self::Color>, {
101-
98+
where
99+
I: IntoIterator<Item = Self::Color>,
100+
{
102101
let mut count = 0;
103102
crate::measure(&mut count, || {
104103
let mut colors = colors.into_iter();
@@ -117,7 +116,6 @@ impl DrawTarget for Display {
117116
unsafe { crate::CHARACTER_DRAW_CYCLES += count };
118117
Ok(())
119118
}
120-
121119
}
122120

123121
#[derive(Debug, Clone, Copy)]
@@ -357,7 +355,7 @@ fn index(row: usize, col: usize) -> usize {
357355
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
358356
enum Drawn {
359357
Dirty,
360-
Clean
358+
Clean,
361359
}
362360

363361
pub struct TextDisplay {
@@ -454,7 +452,6 @@ impl TextDisplay {
454452
if self.buffer[i].1 == Drawn::Dirty {
455453
self.buffer[i].1 = Drawn::Clean;
456454
self.draw(row, col, target)
457-
458455
}
459456
}
460457
}

src/keyboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloc::vec::Vec;
22
use esp32c3_hal::{
33
clock::Clocks,
4-
gpio::{Gpio1, Unknown, Gpio0},
4+
gpio::{Gpio0, Gpio1, Unknown},
55
interrupt::Priority,
66
peripherals::UART1,
77
};

src/terminal.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,8 @@ impl Cursor {
105105
text.write_char(self.pos.row(), self.pos.col(), c);
106106
}
107107

108-
fn reset_highlight_timer(&mut self, text: &mut TextDisplay) {
109-
self.set_highlight(text);
110-
self.time_to_next_blink = SystemTimer::now().wrapping_add(self.blink_length);
111-
}
112-
113108
fn update(&mut self, text: &mut TextDisplay) {
114109
let now = SystemTimer::now();
115-
// println!("now {}, upcoming time {}", now, self.time_to_next_blink);
116110
if now >= self.time_to_next_blink {
117111
self.time_to_next_blink = now.wrapping_add(self.blink_length);
118112
self.swap_highlight(text);
@@ -262,23 +256,18 @@ impl TextField {
262256
}
263257
EraseLine(erase) => match erase {
264258
EraseMode::All => {
265-
self.cursor.reset_highlight_timer(&mut self.text);
266259
for c in 0..display::COLUMNS {
267260
self.text.write(self.cursor.pos.row(), c, ' ');
268261
}
269262
}
270263
EraseMode::FromCursor => {
271-
self.cursor.reset_highlight_timer(&mut self.text);
272264
for c in self.cursor.pos.col()..display::COLUMNS {
273265
self.text.write(self.cursor.pos.row(), c, ' ');
274-
self.cursor.update(&mut self.text);
275266
}
276267
}
277268
EraseMode::ToCursor => {
278-
self.cursor.reset_highlight_timer(&mut self.text);
279269
for c in 0..self.cursor.pos.col() {
280270
self.text.write(self.cursor.pos.row(), c, ' ');
281-
self.cursor.update(&mut self.text);
282271
}
283272
}
284273
},

src/uart.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,11 @@ pub fn configure1(
6060
}
6161

6262
pub fn make_uart0<'a>(uart: UART0) -> Uart<'a, UART0> {
63-
uart.flow_conf.write(|w| {
64-
w.sw_flow_con_en().set_bit()
65-
});
66-
uart.swfc_conf0.write(|w| {
67-
w.xoff_threshold().variant(64)
68-
.xoff_char().variant(0x13)
69-
});
70-
uart.swfc_conf1.write(|w| {
71-
w.xon_threshold().variant(64)
72-
.xon_char().variant(0x11)
73-
});
63+
uart.flow_conf.write(|w| w.sw_flow_con_en().set_bit());
64+
uart.swfc_conf0
65+
.write(|w| w.xoff_threshold().variant(64).xoff_char().variant(0x13));
66+
uart.swfc_conf1
67+
.write(|w| w.xon_threshold().variant(64).xon_char().variant(0x11));
7468
let serial0: Uart<UART0> = Uart::new(uart);
7569

7670
serial0
@@ -202,7 +196,11 @@ fn UART0() {
202196
}
203197
}
204198
// Reset the "fifo full" interrupt
205-
unsafe { (*UART0::PTR).int_clr.write(|w| w.rxfifo_full_int_clr().set_bit()) }
199+
unsafe {
200+
(*UART0::PTR)
201+
.int_clr
202+
.write(|w| w.rxfifo_full_int_clr().set_bit())
203+
}
206204
});
207205
}
208206

0 commit comments

Comments
 (0)