Turbo Vision

和现在的GUI不同,在 Dos 的时代,使用 ASCII 字符同样能够绘制精美的窗口,这种被称作“CUI”。 Turbo Pascal 7.0 就是典型的代表,它基于Turbo Vision来实现的。

最近看到了一个开源的 Turbo Vision项目,让这套界面在 Windows下再次焕发青春。项目地址是

https://github.com/magiblot/tvision

下面介绍一下编译方法:

  1. 需要准备 VS2019 这种 MS 的编译器
  2. 运行 cmake . -B ./build && -A x64

3. 运行 cmake –build ./build –config Release

编译后生成的 exe 在 build 目录下

有兴趣的朋友可以试试。

=============================================================

2024年2月19日

还可以使用下面的命令来生成 nmake 语法的 makefile

cmake . -B ./build2 -G "NMake Makefiles" ..

之后,进入 build2 目录,运行 nmake 也可以生成 exe

CMAKE 打开具体动作显示的方法

有些项目是通过 CMAKE 来实现的,我们可以通过在根目录下CMakeLists.txt文件添加

set(CMAKE_VERBOSE_MAKEFILE ON) 的方法打开显示,这样就可以看到具体使用的编译命令。例如:

cmake_minimum_required (VERSION 3.5)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
    cmake_policy(SET CMP0077 NEW) # 'option()' honors normal variables.
endif()

set(CMAKE_VERBOSE_MAKEFILE ON)

set(MASTER_PROJECT FALSE)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
    set(MASTER_https://zhuanlan.zhihu.com/p/587290104PROJECT )
endif()

上述方法来自 https://zhuanlan.zhihu.com/p/587290104

Ch9350 控制键盘 LED

CH9350 提供了控制键盘LED(就是 Caps Lock、Scroll Lock、 Num Lock) 的方法。不过非常遗憾的是对应的 DataSheet 语言不详,查阅了网上资料【参考1】【参考2】之后我感觉CH9350 可能是不断升级,所以这部分不是很确定。

最终经过实验,我手上的可以通过对CH9350 发送如下11 Bytes 长度的命令来实现:

0x57, 0xAB, 0x12, 0x00,  0x00, 0x00, 0x00, 0x00,  0x00, 0xAC, 0x20

修改其中的 Byte[7] ,可以实现更改Led的目标。对应的,在 DataSheet有如下介绍:

编写一个测试程序,运行在 ESP32 C3 上:

#include <Arduino.h>

void setup() {
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, RX, TX);
}
char LEDbuffer[11] =
{ 0x57, 0xAB, 0x12, 0x00,
  0x00, 0x00, 0x00, 0x00,
  0x00, 0xAC, 0x20
};

byte Index = 0;

void loop() {
  // 预留调试使用
  while (Serial.available()) {
    char c = Serial.read();
    // 简单返回
    if (c == '1') {
      Serial.printf("RX:%d TX:%d\n", RX, TX);
      Serial.println("Test Message");
    }
    //重启
    if (c == '2') {
      ESP.restart();
    }
  }
  LEDbuffer[7]=Index;
  Serial1.write(LEDbuffer, sizeof(LEDbuffer));
  Index++;
  if (Index == 8) {
    Index = 0;
  }
  delay(1000);
}

工作的测试视频在下面的链接可以看到:

https://www.bilibili.com/video/BV1K94y1r731/?share_source=copy_web&vd_source=5ca375392c3dd819bfc37d4672cb6d54

有兴趣的朋友可以试试。

参考:

  1. https://www.wch.cn/bbs/thread-69476-1.html “CH9350 如何設置鍵盤的NumLock/CapsLock/ScrollLock” WCH 官方论坛
  2. https://www.cnblogs.com/gooutlook/p/16805870.html 单片机读取键鼠数据串口

ESP32 IDF SDMMC 测试

官方的 sd_card_example_main.c 代码,在末尾添加如下代码:

	int64_t StartTime=esp_timer_get_time()/1000;
	
	char buffer[64];
	int  filesize,total=0,PicIndex=0;
	FILE *fd = NULL;
	
	for (PicIndex=0;PicIndex<100;PicIndex++) {
		sprintf(buffer,MOUNT_POINT"/m/%04d.jpg",PicIndex);	
		fd = fopen(buffer, "r");
		fseek(fd, 0, SEEK_END);  
		filesize = ftell(fd);  
		rewind(fd);
		fread(Buffer, 1, filesize, fd);
		fclose(fd);
		total=total+filesize;
	}
	ESP_LOGI(TAG, "Read %dKB in %llums",
				total/1024,
				(esp_timer_get_time()/1000-StartTime));

        StartTime=esp_timer_get_time()/1000;
	for (size_t i=0;i<100;i++) {
		sdmmc_read_sectors(card, Buffer, i*128, 128);
	}
	ESP_LOGI(TAG, "Read %dKB in %llums",
				64*100,
				(esp_timer_get_time()/1000-StartTime));

一段是从 m 目录下读取从 0000.jpg 到 0100.jpg ;另外一段是读取从0扇区开始的 100个64KB 扇区。最终运行结果如下:

前者花了 1789ms 读取 1.5MB 的内容;后者711ms能够读取 6.4MB 左右的内容。从这里可以看出文件系统的开销比较大。

几个常见的 ACPI Debug 相关 Table

HEST: Hardware Error Source Table

用于报告系统平台能够产生的错误来源。比如,对于 X86 架构的 MCE和CMC,以及PCIe AER, OS 能够处理的 MSI 和 PCI INTs 错误。

The HEST table enables host firmware to declare all errors that platform component can generate and error signaling for those. The host firmware shall create Error source entries in HEST for each component (such as, processor, PCIe device, PCIe bridge, etc) and each type of error with corresponding error notification mechanism (singling) to OS. These error entries include x86 architectural errors, industry standard errors and generic hardware error source for platform errors. The x86 architectural errors, MCE and CMC, and standard errors PCIe AER, MSI and PCI INTx can be handled by OS natively. The generic hardware error source can be used for all firmware 1st errors and platform errors (such as memory, board logic) that do not have OS native signaling, so they have to use platform signaling SCI or NMI


ERST:Error Record Serialization table

通过这个 Table 给 OS 提供一个能够存放错误的接口,通过这个接口,OS可以将一些信息存放在不受断电影响的存储器上,比如: NVRAM。

The ERST table provides a generic interface for the OS to store and retrieve error records in the platform persistent storage, such as NVRAM (Non-volatile RAM). The error records stored through this interface shall persist across system resets till OS clears it. The OS will use this interface store error information during critical error handling for later extensive error analysis. Host firmware shall provide serialization instruction using ACPI specification defined actions to facilitate read, write and clear error records


EINJ:Error Injection Table
通过这个 Table OS 可以给错误处理函数增加限定条件(具体使用场景我没有碰到过,对此不理解,有知道的朋友可以在评论指教一下)。

One of the important functions required in implementing the error is the ability to inject error conditions by the OS to evaluate the correct functionality of the entire error handling in the platform hardware, host firmware and the OS. The EINJ table interface facilitates error injection from the OS. The host firmware shall provide at minimum one error injection method per error type supported in the platform. The host firmware will provide the generic error serialization instructions to trigger the error in the hardware


BERT:Boot Error Record Table

记录启动时的错误信息并报告给OS,对于我们平常使用的X86来说一般是放在内存中的。

The BERT table provides the interface to report errors that occurred system boot time. In
addition BERT also can be used to report fatal errors that resulted in surprise system reset or shutdown before OS had the chance to see the error. The host firmware shall build this table with error record entries for each error that occurred

上述介绍来自下面这个文档

Step to UEFI (279)介绍一个最小的UEFI Application 编译器

最近接触到了 TinyCC (https://bellard.org/tcc/), 这是一个小巧的、开源、编译速度快的C编译器。

https://github.com/andreiw/tinycc/tree/mob 这里,有一个基于 TinyCC 支持编译UEFI Application的项目。这里介绍如何使用这个编译器编译生成 UEFI Shell Application。

第一步,下载上述代码。

第二步,生成 TinyCC  UEFI 编译器。下载的 Package 中只有源代码,没有二进制的 EXE ,所以需要先进行编译。我这边使用 VS2019 进行编译,进入源代码 Win32 目录下:

特别注意需要对 build-tcc.bat进行修改,其中的-DONE_SOURCE=0需要使用引号:

%CC% -o tcc.exe ..\tcc.c libtcc.dll %D% “-DONE_SOURCE=0”

运行 build-tcc.bat -c cl -t 64_ 命令:

生成的x86_64-win32-tcc.exe 就是我们需要的编译器:

第三步,在 EDK2 中编译生成一个 EFI Application。

  1. 拷贝 x86_64-win32-tcc.exe 到edk2-stable202308根目录下
  2. 将如下代码命名为 Hello.c
#include <Uefi.h>

CHAR16 *gHello = L"Hello from a TinyCC compiled UEFI binary!\r\n";

EFI_STATUS EFIAPI
_start(EFI_HANDLE Handle,
       EFI_SYSTEM_TABLE *SystemTable)
{
  SystemTable->ConOut->OutputString(SystemTable->ConOut, gHello);
  return EFI_SUCCESS;
}

3.直接打开一个 cmd 窗口(不需要 Vs2019)

4.编译命令如下

x86_64-win32-tcc -I MdePkg/Include -I MdePkg/Include/X64  hello.c  -Wl,-subsystem=efiapp -nostdlib -o efitest.x64.efi -DMDE_CPU_EBC

5.编译后直接生成 efitest.x64.efi

第四步,在模拟器中测试生成的 EFI 文件,可以看到能够正常工作。

本文提到的完整代码可以在下面下载:

10月 nVidia 工作机会

GPU Server- Firmware 应用工程师(上海/北京/深圳)

NVIDIA GPU Application Engineering 是为 NVIDIA 全球客户提供技术支持的部门。我们的主要任务是向我们的客户提供 NVIDIA GPU 技术信息,培训我们的客户设计 NVIDIA GPU 相关产品,并协助我们的客户成功地将产品推向市场。我们正在寻找软件应用工程师加入我们的应用工程团队!您将负责 GPU 软件设计支持和使用工具进行问题分析解决。

[工作内容]这是您即将从事的工作:

• 为客户提供 NVIDIA GPU 软件设计技术支持。

• 为客户在 GPU 的软件功能实现和调试提供支持。

• 在技术层面与客户硬件和软件工程师进行交流,以提供设计协助和解决问题。

• 协助內部测试部門复现客戶的问题并进行相关测试和验证解决方案。

• 与客户和总部进行沟通与协同工作,为客户的问题提供解决方案

[职位要求]• 电机工程,电子工程,计算机科学相关领域, 学士学位或以上学历。

• x86 系统 BIOS 或 GPU VBIOS/驱动程序经验。

• 有 x86 计算机系统结构, C, C++的背景。

• 良好的英文听说读写能力。• 有 BIOS/firmware 开发的经验

JR1967728 GPU Enterprise Firmware Application Engineer – 深圳/北京/上海

同样的还有Server 系统硬件设计应用工程师、数据中心 Server 硬件应用工程师 等等职位,有兴趣的朋友可以直接扫描如下链接进行查看:

DFRobot ESP32C3 USB HID Shield

这次带来的作品是 DFRobot Beetle ESP32-C3的扩展版,通过这个扩展版能够让 Beetle ESP32-C3 取得 USB 键盘鼠标这种 HID 设备的输入数据。

这个扩展版的核心是 WCH 出品的CH9350芯片,CH9350是USB键盘鼠标转串口通讯控制芯片。就是说USB 键盘鼠标连接到这个芯片之后,数据会转化为串口输出。关于这个芯片的功能介绍如下:

  • 支持12Mbps全速USB传输和1.5Mbps低速USB传输,兼容USB V2.0。
  • 上位机端USB端口符合标准HID类协议,不需要额外安装驱动程序,支持内置HID类设备驱动的Windows、Linux、macOS等操作系统。
  • 同一芯片可配置为上位机模式和下位机模式,分别连接USB-Host主机和USB键盘、鼠标。
  • 支持USB键盘鼠标在BIOS界面使用,支持多媒体功能键,支持不同分辨率USB鼠标。
  • 支持各种品牌的USB键盘鼠标、USB无线键盘鼠标、USB转PS2线等。
  • 上位机端和下位机端支持热插拔。
  • 提供发送状态引脚,支持485通讯。
  • 串口支持115200/57600/38400串口通信波特率。
  • 内置晶振和上电复位电路,外围电路简单。
  • 支持5V、3.3V电源电压。
  • 提供LQFP-48无铅封装,兼容RoHS。

电路图设计如下:

从DataSheet可以知道,芯片支持 3.3V h和5V供电,为了方便电路设计这里我们直接使用5V供电。PCB 设计如下:

3D渲染结果如下:

黑色PCB 风格非常接近DFRobot

为了Beetle 配合板子只使用了一个 USB 母头,实际芯片同时支持2个USB接口,让客户可以同时使用键盘和鼠标。

下面带来一个USB键盘转蓝牙例子,展示这个板子的能力。

从原理上来说,首先使用 CH9350取得鼠标数据,之后通过 Beetle ESP32-C3 的蓝牙功能将这个数据发送出去。

#include <Arduino.h>
#include <BleKeyboard.h>

BleKeyboard bleKeyboard;

#define DEBUGMODE 1

void setup() {
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, RX, TX);

  bleKeyboard.begin();

}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();
    if (c == '1') {
      Serial.println("get1");
    }
    if (c == '3') {
      ESP.restart();
    }
  }

  //根据 CH9350 Spec 每次最多输出 72Bytes
  byte Data[72];
  unsigned int CounterLast = Serial1.available();
  unsigned int CounterCurrent = 0;


  // 如果当前串口有数据
  if (CounterLast != 0) {
    // 进行简单测试,如果当前还在传输数据那么持续接收
    while (CounterCurrent != CounterLast) {
      CounterLast = Serial1.available();
      delayMicroseconds(500);
      CounterCurrent = Serial1.available();
    }
  }

  if (CounterCurrent > 0) {
    // 一次性将数据收取下来
    Serial1.readBytes(Data, CounterCurrent);
    unsigned int i = 0;
    unsigned int Length;
    while (i < CounterCurrent) {
      // 识别帧头
      if ((Data[i] == 0x57) && (Data[i + 1] == 0xAB)) {
        // 有效键值帧
        if (Data[i + 2] == 0x88) {
          // 获得数据长度
          Length = Data[i + 3];
          if (DEBUGMODE) {
            //Serial.print("Ln:");Serial.print(Length);
            for (int j = 1; j < Length + 1; j++) {
              if (Data[i + 3  + j] < 16) {
                Serial.print("0");
              }
              Serial.print(Data[i + 3  + j], HEX);
              Serial.print(" ");
            }
            Serial.println(" ");
          }

          //如果是键盘
          if (Data[i + 4] == 0x10) {
            if (DEBUGMODE) {
              Serial.print("Key");
              for (int j = 1; j < Length + 1; j++) {
                Serial.print(Data[i + 3  + j], HEX);
                Serial.print(" ");
              }
              Serial.println(" ");
            }
            
            //判断为Dostyle键盘
            if (Data[i + 3  + 1] == 0x10) { 
              if (bleKeyboard.isConnected() == true) {
                bleKeyboard.sendReport((KeyReport*)(&Data[i + 3  + 2]));
              }
            }
          }
          i = i + 3 + Length;
        } else if (Data[i + 2] == 0x82) {
          i = i + 3; // 跳过
        }
      }
      i++;
    } // while (i < Counter)
  }

}

首先,调用了 ESP32 的 BLE 键盘库(第三方),创建一个蓝牙键盘;之后就是分析串口数据。CH9350 能够获得USB 键盘鼠标数据,但是获得这个数据每家会有差别。正确的做法是使用工具(USBlyzer)读取键盘鼠标数据,然后编写分析代码。或者是使用工具读取这个设备的 HID Report Descriptor。再进一步解释就是,例如:市面上有2中鼠标,他们发送出来的数据格式可能是:

A鼠标:

Byte0:  Button

Byte1: X

Byte2: Y

Byte3: Wheel

B鼠标:

Byte0:  Button

Byte1: X 低8位

Byte2: X 高8位

Byte3: X 低8位

Byte4: X 高8位

Byte5: Wheel

具体的格式数据是设备通过HID Report Descriptor报告给系统的,而对于我们来说只能通过人工识别然后在代码中分析的方式来实现解析。相比USB鼠标,键盘的情况要好得多,通常都是使用8 Bytes 来报告按键信息。我这次测试使用的是一款机械键盘,使用的同样是 8 Bytes的格式,因此代码中直接将对应的数据以KeyReport结构体直接发送出去。

if (bleKeyboard.isConnected() == true) {
                bleKeyboard.sendReport((KeyReport*)(&Data[i + 3  + 2]));
 }

本文提到的电路图和PCB:

本文提到的完整代码:

本文使用的库: