上传日期:2023-11-07 07:12:30
上 传 者sh-1993
说明:  SH1107 OLED(I2C)驱动程序,以及虚拟硬件测试台。
(SH1107 OLED (I2C) driver, plus virtual hardware testbench.)

doc/ (0, 2023-08-23)
doc/helloworld.jpg (1514210, 2023-08-23)
doc/vsh.png (404556, 2023-08-23)
flake.lock (10801, 2023-08-23)
flake.nix (3496, 2023-08-23)
pdm.lock (258, 2023-08-23)
pyproject.toml (761, 2023-08-23)
sh1107/ (0, 2023-08-23)
sh1107/ (0, 2023-08-23)
sh1107/ (989, 2023-08-23)
sh1107/ (355, 2023-08-23)
sh1107/ (3190, 2023-08-23)
sh1107/formal/ (0, 2023-08-23)
sh1107/formal/ (4894, 2023-08-23)
sh1107/formal/gtkw (1300, 2023-08-23)
sh1107/formal/sh1107.sby (550, 2023-08-23)
sh1107/ (2496, 2023-08-23)
sh1107/proto/ (0, 2023-08-23)
sh1107/proto/ (20061, 2023-08-23)
sh1107/proto/ (13941, 2023-08-23)
sh1107/rom/ (0, 2023-08-23)
sh1107/rom/IBM_VGA_8x8.bin (2048, 2023-08-23)
sh1107/rom/ (3669, 2023-08-23)
sh1107/rom/ (460, 2023-08-23)
sh1107/rtl/ (0, 2023-08-23)
sh1107/rtl/ (8016, 2023-08-23)
sh1107/rtl/common/ (0, 2023-08-23)
sh1107/rtl/common/ (225, 2023-08-23)
sh1107/rtl/common/ (2196, 2023-08-23)
sh1107/rtl/common/ (1664, 2023-08-23)
sh1107/rtl/common/ (932, 2023-08-23)
sh1107/rtl/common/ (407, 2023-08-23)
sh1107/rtl/common/ (1898, 2023-08-23)
sh1107/rtl/common/ (832, 2023-08-23)
... ...

# sh1107 [![Build status]]( This repository is a testbed for exploring [Amaranth] while learning digital design. It consists of a basic driver for SH1107-type OLEDs over IC such as the [Pimoroni 1.12" 128x128 monochrome OLED][Pimoroni OLED], a read/write IC controller, plus a simple SPI flash reader. The driver supports commands akin to old BASIC: `CLS`, `PRINT`, `LOCATE`. The classic IBM 8x8 font is used to this end. [Build status]: [Amaranth]: [Pimoroni OLED]: Execute the package to see what it can do: ```console $ py -m sh1107 -h usage: sh1107 [-h] {test,formal,build,rom,vsh} ... positional arguments: {test,formal,build,rom,vsh} test run the unit tests and sim tests formal formally verify the design build build the design, and optionally program it rom build the ROM image, and optionally program it vsh run the Virtual SH1107 options: -h, --help show this help message and exit ``` The current test deployment targets are: * iCEBreaker ([Crowd Supply][iCEBreaker on Crowd Supply], [1BitSquared][iCEBreaker on 1BitSquared]). * Connect PMOD1 A1 to SDA, A2 to SCL. * OrangeCrab ([1BitSquared][OrangeCrab on 1BitSquared]). * Connect the pins named SDA and SCL. * The code currently expects you have rev 0.2 with an 85F like I do. It's trivial to add support for rev 0.1 and/or the 25F. [iCEBreaker on Crowd Supply]: [iCEBreaker on 1BitSquared]: [OrangeCrab on 1BitSquared]: ## Requirements If no version is specified, the most recent release or the version in your package manager is probably fine, and if neither concept applies, just try the latest commit. For a detailed guide on installing specific versions of some of these tools, please see [Installing an HDL toolchain from source][notes-0001]. On Nix, [hdx] packages everything — `nix develop '.?submodules=1'`/`nix-shell` will use it. To run at all: * [Python 3] (3.8+ works; I work on 3.12 beta) * [Amaranth] ([`d218273`] or later) * [Board definitions for Amaranth][amaranth-boards] To run vsh: * [Zig] (~[`50339f5`] or later) * [SDL2] To build and deploy: * [nextpnr] configured with appropriate flows: * [Project IceStorm] for iCEBreaker * [Project Trellis] for OrangeCrab * [`dfu-util`] to upload the bitstream and ROM To run formal tests: * [Yosys] ([`d3ee4eb`] or later) * [SymbiYosys] * [Z3] (4.12+ is known to work; 4.8 is known not to) [notes-0001]: [hdx]: [Python 3]: [`d218273`]: [amaranth-boards]: [Yosys]: [`d3ee4eb`]: [SymbiYosys]: [Z3]: [nextpnr]: [Project IceStorm]: [Project Trellis]: [`dfu-util`]: [Zig]: [SDL2]: [`50339f5`]: ## TODOs - try QSPI. - OrangeCrab: try on-board DDR3 instead of EBR. ## vsh Maybe the most interesting thing right now is the Virtual SH1107 for testing the gateware. It emulates the internal state of the SH1107 device — what you see rendered is what you should see on the display. [screenshot of the Virtual SH1107 testbench](doc/vsh.png) [photo of the OLED device being run on an
iCEBreaker](doc/helloworld.jpg) Initially this was implemented in Python and ran cooperatively with Amaranth's own simulator, like the unit tests, but it was pretty slow. It's now written in [Zig], and interacts with the simulated hardware running on its own thread by compiling it to C++ through Yosys's [CXXRTL backend][CXXRTL]. [CXXRTL]: ```console $ py -m sh1107 vsh -h usage: sh1107 vsh [-h] [-i] [-f] [-c] [-s {100000,400000,2000000}] [-t TOP] [-v] [-O {none,rtl,zig,both}] options: -h, --help show this help message and exit -i, --whitebox-i2c simulate the full I2C protocol; by default it is replaced with a blackbox for speed -f, --whitebox-spifr simulate the full SPI protocol for the flash reader; by default it is replaced with a blackbox for speed -c, --compile compile only; don't run -s {100000,400000,2000000}, --speed {100000,400000,2000000} I2C bus speed to build at -t TOP, --top TOP which top-level module to simulate (default: oled.Top) -v, --vcd output a VCD file -O {none,rtl,zig,both}, --optimize {none,rtl,zig,both} build RTL or Zig with optimizations (default: both) ``` ### IC By default, the IC circuit is stubbed out with a [blackbox](vsh/ that acts close enough to the real controller for the rest of the design, and the Virtual SH1107 [spies](vsh/src/I2CBBConnector.zig) on the inputs to the blackbox directly. This is fast. At the most fine-grained level (`vsh -i`), it responds to the gateware by doing edge detection at IC level, [spying](vsh/src/I2CConnector.zig) on the IC lines. This method is faster than the pure Python version I started with, but still slow enough to take several seconds to clear the screen when not compiled with optimizations. ### SPI flash Sequences of SH1107 commands used by the driver are packed into a ROM image which is separately programmed onto the on-board flash. The driver reads the contents into RAM on startup over SPI. By default, the SPI flash reader component is stubbed out with a [blackbox](vsh/, which emulates the component's [interface](vsh/, returning data bytes directly to the OLED driver from the ROM embedded in the build. This blackbox can be replaced with a [whitebox](vsh/ (`vsh -f`), which emulates at one level lower, emulating the [SPI interface](vsh/ itself, returning data bitwise to the [flash reader](sh1107/spi/