# 使用DMA加速的SPI驱动(MicroPython)
from machine import Pin, SPI
import framebuf
spi = SPI(1, baudrate=10_000_000, polarity=0, phase=0) # 10MHz SPI
dc = Pin(4, Pin.OUT)
cs = Pin(5, Pin.OUT)
# 初始化SSD1306(兼容模式)
def init_oled():
cs.value(0)
dc.value(0)
spi.write(bytearray([0xAE, 0xD5, 0x80, 0xA8, 0x3F])) # 精简初始化序列
dc.value(1)
cs.value(1)
# 使用framebuf双缓冲
buf = bytearray(1024)
fb = framebuf.FrameBuffer(buf, 128, 64, framebuf.MONO_VLSB)
fb.text("Modern OLED", 0, 0, 1)
spi.write(buf) # DMA自动加速