From 9c05cc9bd5198cac4d3847bfecd47b0ea3c95376 Mon Sep 17 00:00:00 2001 From: ds797 <73960745+ds797@users.noreply.github.com> Date: Wed, 22 May 2024 17:48:43 -0700 Subject: [PATCH 1/2] Update crossbeam Updated crossbeam to 0.3.11 and fixed breaking changes. --- .../edition-2/posts/12-async-await/index.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/blog/content/edition-2/posts/12-async-await/index.md b/blog/content/edition-2/posts/12-async-await/index.md index 69793acfd..30bccf308 100644 --- a/blog/content/edition-2/posts/12-async-await/index.md +++ b/blog/content/edition-2/posts/12-async-await/index.md @@ -1055,7 +1055,7 @@ To use the type, we need to add a dependency on the `crossbeam-queue` crate: # in Cargo.toml [dependencies.crossbeam-queue] -version = "0.2.1" +version = "0.3.11" default-features = false features = ["alloc"] ``` @@ -1233,8 +1233,8 @@ impl Stream for ScancodeStream { fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { let queue = SCANCODE_QUEUE.try_get().expect("not initialized"); match queue.pop() { - Ok(scancode) => Poll::Ready(Some(scancode)), - Err(crossbeam_queue::PopError) => Poll::Pending, + Some(scancode) => Poll::Ready(Some(scancode)), + None => Poll::Pending, } } } @@ -1284,17 +1284,17 @@ impl Stream for ScancodeStream { .expect("scancode queue not initialized"); // fast path - if let Ok(scancode) = queue.pop() { + if let Some(scancode) = queue.pop() { return Poll::Ready(Some(scancode)); } WAKER.register(&cx.waker()); match queue.pop() { - Ok(scancode) => { + Some(scancode) => { WAKER.take(); Poll::Ready(Some(scancode)) } - Err(crossbeam_queue::PopError) => Poll::Pending, + None => Poll::Pending, } } } @@ -1546,7 +1546,7 @@ impl Executor { waker_cache, } = self; - while let Ok(task_id) = task_queue.pop() { + while let Some(task_id) = task_queue.pop() { let task = match tasks.get_mut(&task_id) { Some(task) => task, None => continue, // task no longer exists From 1e108fba64a72e8a7ea895436cfdd4ed935c8bf7 Mon Sep 17 00:00:00 2001 From: ds797 <73960745+ds797@users.noreply.github.com> Date: Thu, 23 May 2024 01:12:15 +0000 Subject: [PATCH 2/2] Update pc_keyboard Updated pc_keyboard to 0.7.0 and fixed breaking changes. --- .../posts/07-hardware-interrupts/index.fa.md | 18 +++++++++--------- .../posts/07-hardware-interrupts/index.ja.md | 18 +++++++++--------- .../posts/07-hardware-interrupts/index.ko.md | 18 +++++++++--------- .../posts/07-hardware-interrupts/index.md | 18 +++++++++--------- .../07-hardware-interrupts/index.zh-CN.md | 18 +++++++++--------- .../edition-2/posts/12-async-await/index.ja.md | 4 ++-- .../edition-2/posts/12-async-await/index.md | 4 ++-- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/blog/content/edition-2/posts/07-hardware-interrupts/index.fa.md b/blog/content/edition-2/posts/07-hardware-interrupts/index.fa.md index 5a5319dc0..c1e54e469 100644 --- a/blog/content/edition-2/posts/07-hardware-interrupts/index.fa.md +++ b/blog/content/edition-2/posts/07-hardware-interrupts/index.fa.md @@ -654,13 +654,13 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( ترجمه کلیدهای دیگر نیز به همین روش کار می کند. خوشبختانه کرت ای با نام [`pc-keyboard`] برای ترجمه اسکن‌کد مجموعه های اسکن‌کد 1 و 2 وجود دارد ، بنابراین لازم نیست که خودمان این را پیاده سازی کنیم. برای استفاده از کرت ، آن را به `Cargo.toml` اضافه کرده و در`lib.rs` خود وارد می کنیم: -[`pc-keyboard`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/ +[`pc-keyboard`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/ ```toml # in Cargo.toml [dependencies] -pc-keyboard = "0.5.0" +pc-keyboard = "0.7.0" ``` اکنون میتوانیم از این کرت برای باز نویسی `keyboard_interrupt_handler` استفاده کنیم: @@ -677,8 +677,8 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( lazy_static! { static ref KEYBOARD: Mutex> = - Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1, - HandleControl::Ignore) + Mutex::new(Keyboard::new(ScancodeSet1::new(), + layouts::Us104Key, HandleControl::Ignore) ); } @@ -704,17 +704,17 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( ما از ماکرو `lazy_static` برای ایجاد یک شی ثابت [`Keyboard`] محافظت شده توسط Mutex استفاده می کنیم. `Keyboard` را با طرح صفحه کلید ایالات متحده و مجموعه اسکن کد 1 مقداردهی می کنیم. پارامتر [`HandleControl`] اجازه می دهد تا `ctrl+[a-z]` را به کاراکتر های `U+0001` تا `U+001A` نگاشت کنیم. ما نمی خواهیم چنین کاری انجام دهیم ، بنابراین از گزینه `Ignore` برای برخورد با `ctrl` مانند کلیدهای عادی استفاده می کنیم. -[`HandleControl`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/enum.HandleControl.html +[`HandleControl`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/enum.HandleControl.html در هر وقفه ، Mutex را قفل می کنیم ، اسکن کد را از کنترل کننده صفحه کلید می خوانیم و آن را به متد [`add_byte`] منتقل می کنیم ، که اسکن کد را به یک `> = - Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1, - HandleControl::Ignore) + Mutex::new(Keyboard::new(ScancodeSet1::new(), + layouts::Us104Key, HandleControl::Ignore) ); } @@ -705,17 +705,17 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( ミューテックスで保護された静的な [`Keyboard`] オブジェクトを作るために `lazy_static` マクロを使います。`Keyboard` は、レイアウトを US キーボードに、スキャンコードセットは1として初期化を行います。[`HandleControl`] パラメタは、`ctrl+[a-z]` を Unicode 文字の `U+0001` から `U+001A` にマッピングさせることができます。この機能は使いたくないので、`Ignore` オプションを使い `ctrl` キーを通常のキーと同様に扱います。 -[`HandleControl`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/enum.HandleControl.html +[`HandleControl`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/enum.HandleControl.html 各割り込みでは、ミューテックスをロックし、キーボードコントローラからスキャンコードを読み取り、それを読み取ったスキャンコードを `Option` に変換する [`add_byte`] メソッドに渡します。[`KeyEvent`] は、そのイベントを起こしたキーと、それが押されたのか離されたのかの情報を含んでいます。 -[`Keyboard`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html -[`add_byte`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html#method.add_byte -[`KeyEvent`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.KeyEvent.html +[`Keyboard`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html +[`add_byte`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html#method.add_byte +[`KeyEvent`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.KeyEvent.html このキーイベントを解釈するために、変換可能であればキーイベントを文字に変換する [`process_keyevent`] メソッドにキーイベントを渡します。例えば `A` キーの押下イベントを、シフトキーが押されていたかによって小文字の `a` か大文字の `A` に変換します。 -[`process_keyevent`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html#method.process_keyevent +[`process_keyevent`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html#method.process_keyevent 修正した割り込みハンドラで、テキストが入力できるようになります: diff --git a/blog/content/edition-2/posts/07-hardware-interrupts/index.ko.md b/blog/content/edition-2/posts/07-hardware-interrupts/index.ko.md index 7bef3b596..5af856e43 100644 --- a/blog/content/edition-2/posts/07-hardware-interrupts/index.ko.md +++ b/blog/content/edition-2/posts/07-hardware-interrupts/index.ko.md @@ -655,13 +655,13 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( 나머지 키를 인식하는 것도 위와 마찬가지 방법으로 진행하면 됩니다. 다행히도, [`pc-keyboard`] 크레이트가 1번/2번 스캔코드 셋을 해석하는 기능을 제공합니다. `Cargo.toml`에 이 크레이트를 추가하고 `lib.rs`에서 불러와 사용합니다. -[`pc-keyboard`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/ +[`pc-keyboard`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/ ```toml # in Cargo.toml [dependencies] -pc-keyboard = "0.5.0" +pc-keyboard = "0.7.0" ``` `pc-keyboard` 크레이트를 사용해 `keyboard_interrupt_handler` 함수를 새로 작성합니다. @@ -678,8 +678,8 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( lazy_static! { static ref KEYBOARD: Mutex> = - Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1, - HandleControl::Ignore) + Mutex::new(Keyboard::new(ScancodeSet1::new(), + layouts::Us104Key, HandleControl::Ignore) ); } @@ -705,17 +705,17 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( `lazy_static` 매크로를 사용해 Mutex로 감싼 [`Keyboard`] 타입의 static 오브젝트를 얻습니다. `Keyboard`가 미국 키보드 레이아웃과 1번 스캔코드 셋을 사용하도록 초기화합니다. [`HandleControl`] 매개변수를 사용하면 `ctrl+[a-z]` 키 입력을 유니코드 `U+0001`에서 `U+001A`까지 값에 대응시킬 수 있습니다. 우리는 그렇게 하지 않기 위해 해당 매개변수에 `Ignore` 옵션을 주고 `ctrl` 키를 일반 키로서 취급합니다. -[`HandleControl`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/enum.HandleControl.html +[`HandleControl`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/enum.HandleControl.html 인터럽트마다 우리는 Mutex를 잠그고 키보드 컨트롤러로부터 스캔 코드를 읽어온 후, 그 스캔 코드를 [`add_byte`] 함수에 전달합니다. 이 함수는 스캔 코드를 `Option`으로 변환합니다. [`KeyEvent`] 타입은 입력된 키의 정보와 키의 누름/뗌 정보를 저장합니다. -[`Keyboard`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html -[`add_byte`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html#method.add_byte -[`KeyEvent`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.KeyEvent.html +[`Keyboard`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html +[`add_byte`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html#method.add_byte +[`KeyEvent`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.KeyEvent.html [`process_keyevent`] 함수가 인자로 받은 `KeyEvent`를 변환하여 입력된 키의 문자를 반환합니다 (변환 불가한 경우 `None` 반환). 예를 들어, `A`키 입력 시 shift키 입력 여부에 따라 소문자 `a` 또는 대문자 `A`를 얻습니다. -[`process_keyevent`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html#method.process_keyevent +[`process_keyevent`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html#method.process_keyevent 수정한 인터럽트 처리 함수를 통해 텍스트를 입력한 대로 화면에 출력할 수 있습니다. diff --git a/blog/content/edition-2/posts/07-hardware-interrupts/index.md b/blog/content/edition-2/posts/07-hardware-interrupts/index.md index 7548a13ea..9826fc37c 100644 --- a/blog/content/edition-2/posts/07-hardware-interrupts/index.md +++ b/blog/content/edition-2/posts/07-hardware-interrupts/index.md @@ -649,13 +649,13 @@ Now we can write numbers: Translating the other keys works in the same way. Fortunately, there is a crate named [`pc-keyboard`] for translating scancodes of scancode sets 1 and 2, so we don't have to implement this ourselves. To use the crate, we add it to our `Cargo.toml` and import it in our `lib.rs`: -[`pc-keyboard`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/ +[`pc-keyboard`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/ ```toml # in Cargo.toml [dependencies] -pc-keyboard = "0.5.0" +pc-keyboard = "0.7.0" ``` Now we can use this crate to rewrite our `keyboard_interrupt_handler`: @@ -672,8 +672,8 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( lazy_static! { static ref KEYBOARD: Mutex> = - Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1, - HandleControl::Ignore) + Mutex::new(Keyboard::new(ScancodeSet1::new(), + layouts::Us104Key, HandleControl::Ignore) ); } @@ -699,17 +699,17 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( We use the `lazy_static` macro to create a static [`Keyboard`] object protected by a Mutex. We initialize the `Keyboard` with a US keyboard layout and the scancode set 1. The [`HandleControl`] parameter allows to map `ctrl+[a-z]` to the Unicode characters `U+0001` through `U+001A`. We don't want to do that, so we use the `Ignore` option to handle the `ctrl` like normal keys. -[`HandleControl`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/enum.HandleControl.html +[`HandleControl`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/enum.HandleControl.html On each interrupt, we lock the Mutex, read the scancode from the keyboard controller, and pass it to the [`add_byte`] method, which translates the scancode into an `Option`. The [`KeyEvent`] contains the key which caused the event and whether it was a press or release event. -[`Keyboard`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html -[`add_byte`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html#method.add_byte -[`KeyEvent`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.KeyEvent.html +[`Keyboard`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html +[`add_byte`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html#method.add_byte +[`KeyEvent`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.KeyEvent.html To interpret this key event, we pass it to the [`process_keyevent`] method, which translates the key event to a character, if possible. For example, it translates a press event of the `A` key to either a lowercase `a` character or an uppercase `A` character, depending on whether the shift key was pressed. -[`process_keyevent`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html#method.process_keyevent +[`process_keyevent`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html#method.process_keyevent With this modified interrupt handler, we can now write text: diff --git a/blog/content/edition-2/posts/07-hardware-interrupts/index.zh-CN.md b/blog/content/edition-2/posts/07-hardware-interrupts/index.zh-CN.md index d18b49ab9..539945ec3 100644 --- a/blog/content/edition-2/posts/07-hardware-interrupts/index.zh-CN.md +++ b/blog/content/edition-2/posts/07-hardware-interrupts/index.zh-CN.md @@ -655,13 +655,13 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( 其他扫描码也可以通过同样的手段进行译码,不过真的很麻烦,好在 [`pc-keyboard`] crate 已经帮助我们实现了Set-1和Set-2的译码工作,所以无需自己去实现。所以我们只需要将下述内容添加到 `Cargo.toml`,并在 `lib.rs` 里进行引用: -[`pc-keyboard`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/ +[`pc-keyboard`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/ ```toml # in Cargo.toml [dependencies] -pc-keyboard = "0.5.0" +pc-keyboard = "0.7.0" ``` 现在我们可以使用新的crate对 `keyboard_interrupt_handler` 进行改写: @@ -678,8 +678,8 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( lazy_static! { static ref KEYBOARD: Mutex> = - Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1, - HandleControl::Ignore) + Mutex::new(Keyboard::new(ScancodeSet1::new(), + layouts::Us104Key, HandleControl::Ignore) ); } @@ -705,17 +705,17 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( 首先我们使用 `lazy_static` 宏创建一个受到Mutex同步锁保护的 [`Keyboard`] 对象,初始化参数为美式键盘布局以及Set-1。至于 [`HandleControl`],它可以设定为将 `ctrl+[a-z]` 映射为Unicode字符 `U+0001` 至 `U+001A`,但我们不想这样,所以使用了 `Ignore` 选项让 `ctrl` 仅仅表现为一个正常键位。 -[`HandleControl`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/enum.HandleControl.html +[`HandleControl`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/enum.HandleControl.html 对于每一个中断,我们都会为 KEYBOARD 加锁,从键盘控制器获取扫描码并将其传入 [`add_byte`] 函数,并将其转化为 `Option` 结构。[`KeyEvent`] 包括了触发本次中断的按键信息,以及子动作是按下还是释放。 -[`Keyboard`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html -[`add_byte`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html#method.add_byte -[`KeyEvent`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.KeyEvent.html +[`Keyboard`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html +[`add_byte`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html#method.add_byte +[`KeyEvent`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.KeyEvent.html 要处理KeyEvent,我们还需要将其传入 [`process_keyevent`] 函数,将其转换为人类可读的字符,若果有必要,也会对字符进行一些处理。典型例子就是,要判断 `A` 键按下后输入的是小写 `a` 还是大写 `A`,这要取决于shift键是否同时被按下。 -[`process_keyevent`]: https://docs.rs/pc-keyboard/0.5.0/pc_keyboard/struct.Keyboard.html#method.process_keyevent +[`process_keyevent`]: https://docs.rs/pc-keyboard/0.7.0/pc_keyboard/struct.Keyboard.html#method.process_keyevent 进行这些修改之后,我们就可以正常输入英文了: diff --git a/blog/content/edition-2/posts/12-async-await/index.ja.md b/blog/content/edition-2/posts/12-async-await/index.ja.md index 94cf89108..b8f7dc97a 100644 --- a/blog/content/edition-2/posts/12-async-await/index.ja.md +++ b/blog/content/edition-2/posts/12-async-await/index.ja.md @@ -1363,8 +1363,8 @@ use crate::print; pub async fn print_keypresses() { let mut scancodes = ScancodeStream::new(); - let mut keyboard = Keyboard::new(layouts::Us104Key, ScancodeSet1, - HandleControl::Ignore); + let mut keyboard = Keyboard::new(ScancodeSet1::new(), + layouts::Us104Key, HandleControl::Ignore); while let Some(scancode) = scancodes.next().await { if let Ok(Some(key_event)) = keyboard.add_byte(scancode) { diff --git a/blog/content/edition-2/posts/12-async-await/index.md b/blog/content/edition-2/posts/12-async-await/index.md index 30bccf308..a808a0671 100644 --- a/blog/content/edition-2/posts/12-async-await/index.md +++ b/blog/content/edition-2/posts/12-async-await/index.md @@ -1350,8 +1350,8 @@ use crate::print; pub async fn print_keypresses() { let mut scancodes = ScancodeStream::new(); - let mut keyboard = Keyboard::new(layouts::Us104Key, ScancodeSet1, - HandleControl::Ignore); + let mut keyboard = Keyboard::new(ScancodeSet1::new(), + layouts::Us104Key, HandleControl::Ignore); while let Some(scancode) = scancodes.next().await { if let Ok(Some(key_event)) = keyboard.add_byte(scancode) {