🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 点屏之SPI OLED 这里使用常见的ssd1306驱动芯片的oled屏。 ssd1306支持6800,8080,4线SPI,3线SPI,I2C接口。 驱动手册在此下载:https://pan.baidu.com/s/1pLZchuF 这里以4线SPI为例驱动。 ## 硬件连接 |OLED屏|LicheePi Zero| |-----|-----| |GND|GND| |VCC|3V3| |D0|SPI SCK| |D1|SPI MOSI| |RES|3V3| |DC|PB5| |CS|SPI CS| ## 设备树修改 这里速率使用1M即可,太高会无法响应。 ~~~ &spi0 { status = "okay"; ssd1306@0 { compatible = "solomon,ssd1306"; reg = <0>; spi-max-frequency = <1000000>; rotate = <0>; bgr; fps = <30>; buswidth = <8>; reset-gpios = <&pio 1 7 GPIO_ACTIVE_LOW>; dc-gpios = <&pio 1 5 GPIO_ACTIVE_LOW>; debug = <0>; }; }; ~~~ ## 编译下载 在menuconfig中选中staging driver 下的fbtft的ssd1306驱动,编译入内核。 ## 显示效果 图片显示: ![](https://box.kancloud.cn/f647f9ba914ef7ce0b17ab0c0c1262d5_4032x3016.jpg) 视频播放: http://v.youku.com/v_show/id_XMzM5NDU4MjI0NA==.html ## 驱动走读 ~~~ /* Set Display OFF */ write_reg(par, 0xAE); /* Set Display Clock Divide Ratio/ Oscillator Frequency */ write_reg(par, 0xD5); //默认使用内部rc振荡电路,频率在370KHz左右 write_reg(par, 0x80); //帧率 370k/D/54/64=107 fps /* Set Multiplex Ratio */ write_reg(par, 0xA8); if (par->info->var.yres == 64) write_reg(par, 0x3F); else if (par->info->var.yres == 48) write_reg(par, 0x2F); else write_reg(par, 0x1F); /* Set Display Offset */ write_reg(par, 0xD3); write_reg(par, 0x0); /* Set Display Start Line */ write_reg(par, 0x40 | 0x0); /* Charge Pump Setting */ write_reg(par, 0x8D); /* A[2] = 1b, Enable charge pump during display on */ write_reg(par, 0x14); /* Set Memory Addressing Mode */ write_reg(par, 0x20); /* Vertical addressing mode */ write_reg(par, 0x01); /* Set Segment Re-map */ /* column address 127 is mapped to SEG0 */ write_reg(par, 0xA0 | 0x1); /* Set COM Output Scan Direction */ /* remapped mode. Scan from COM[N-1] to COM0 */ write_reg(par, 0xC8); /* Set COM Pins Hardware Configuration */ write_reg(par, 0xDA); if (par->info->var.yres == 64) /* A[4]=1b, Alternative COM pin configuration */ write_reg(par, 0x12); else if (par->info->var.yres == 48) /* A[4]=1b, Alternative COM pin configuration */ write_reg(par, 0x12); else /* A[4]=0b, Sequential COM pin configuration */ write_reg(par, 0x02); /* Set Pre-charge Period */ write_reg(par, 0xD9); write_reg(par, 0xF1); /* Set VCOMH Deselect Level */ write_reg(par, 0xDB); /* according to the datasheet, this value is out of bounds */ write_reg(par, 0x40); /* Entire Display ON */ /* Resume to RAM content display. Output follows RAM content */ write_reg(par, 0xA4); /* Set Normal Display * 0 in RAM: OFF in display panel * 1 in RAM: ON in display panel */ write_reg(par, 0xA6); /* Set Display ON */ write_reg(par, 0xAF); ~~~