这次试一试使用这么小的板子驱动一下0.96寸OLED。看一下效果。
一、准备
硬件:
0.96寸 OLED 屏幕;
杜邦线;
软件:
下载官方OLED参考代码
OLED_1in5_Code.7z_免费高速下载|百度网盘-分享无限制 (baidu.com)
SPI/I2C 驱动 OLED (C) | LUCKFOX WIKI参考资料
二、确定连接引脚
如下表
由于开发板的引脚是通过引脚编号来确定具体引脚。那么对于开发板上GPIOn_Xn的标号与引脚编号对应关系如下:
pin = bank * 32 + (group * 8 + n); bank是因为芯片分成了几个bank区,例如GPIO1_C6:
GPIO1对应bank1;C对应group,为第2组,6为第2组里面第7个引脚;
即:GPIO1_C6 对应pin = 1 * 32 + 2 * 8 + 6 = 54
0.96inch OLED Module |
Luckfox Pico 引脚 |
功能 |
VCC |
3V3 |
电源输入 |
GND |
GND |
电源地 |
D1 |
GPIO1-C2 -----SPI0_MOSI(50) |
主机输出/从机输入 |
D0 |
GPIO1-C1------SPI0_CLK(48) |
SPI时钟信号 |
CS |
GPIO1_C7(55) |
片选 |
DC |
GPIO1_C6(54) |
数据/命令选择 |
RST |
GPIO1_C4(52) |
复位 |
三、修改SDK
进入/sysdrv/source/kernel/arch/arm/boot/dts/目录
如图操作
1、在添加rv1103g-luckfox-pico.dts中添加GPIO引脚配置,并在pinctrl中添加引脚
2、确认SPI0是否启用并添加SPI 0的 pinctrl
配置好的DTS如下:
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
* Copyright (c) 2022 Rockchip Electronics Co., Ltd.
*/
/dts-v1/;
#include "rv1103.dtsi"
#include "rv1106-evb.dtsi"
#include "rv1103-luckfox-pico-ipc.dtsi"
/ {
model = "Luckfox Pico";
compatible = "rockchip,rv1103g-38x38-ipc-v10", "rockchip,rv1103";
gpio1pc6:gpio1pc6 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio1_pc6>;
regulator-name = "gpio1_pc6";
regulator-always-on;
};
gpio1pc4:gpio1pc4 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio1_pc4>;
regulator-name = "gpio1_pc4";
regulator-always-on;
};
gpio1pc7:gpio1pc7 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio1_pc7>;
regulator-name = "gpio1_pc7";
regulator-always-on;
};
gpio4pa2:gpio4pa2 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio4_pa2>;
regulator-name = "gpio4_pa2";
regulator-always-on;
};
gpio4pa3:gpio4pa3 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio4_pa3>;
regulator-name = "gpio4_pa3";
regulator-always-on;
};
gpio4pa4:gpio4pa4 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio4_pa4>;
regulator-name = "gpio4_pa4";
regulator-always-on;
};
gpio4pa6:gpio4pa6 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio4_pa6>;
regulator-name = "gpio4_pa6";
regulator-always-on;
};
gpio4pb0:gpio4pb0 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio4_pb0>;
regulator-name = "gpio4_pb0";
regulator-always-on;
};
gpio4pb1:gpio4pb1 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gpio4_pb1>;
regulator-name = "gpio4_pb1";
regulator-always-on;
};
};
/**********GPIO**********/
&pinctrl {
gpio1-pc6 {
gpio1_pc6:gpio1-pc6 {
rockchip,pins = <1 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
gpio1-pc4 {
gpio1_pc4:gpio1-pc4 {
rockchip,pins = <1 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
gpio1-pc7 {
gpio1_pc7:gpio1-pc7 {
rockchip,pins = <1 RK_PC7 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
gpio4-pa2 {
gpio4_pa2:gpio4-pa2 {
rockchip,pins = <4 RK_PA2 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
gpio4-pa3 {
gpio4_pa3:gpio4-pa3 {
rockchip,pins = <4 RK_PA3 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
gpio4-pa4 {
gpio4_pa4:gpio4-pa4 {
rockchip,pins = <4 RK_PA4 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
gpio4-pa6 {
gpio4_pa6:gpio4-pa6 {
rockchip,pins = <4 RK_PA6 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
gpio4-pb0 {
gpio4_pb0:gpio4-pb0 {
rockchip,pins = <4 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
gpio4-pb1 {
gpio4_pb1:gpio4-pb1 {
rockchip,pins = <4 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>;
};
};
};
&pinctrl {
spi0 {
/omit-if-no-ref/
spi0m0_pins: spi0m0-pins {
rockchip,pins =
/* spi0_clk_m0 */
<1 RK_PC1 4 &pcfg_pull_none>,
/* spie_miso_m0 */
/* <1 RK_PC3 6 &pcfg_pull_none>,*/
/* spi_mosi_m0 */
<1 RK_PC2 6 &pcfg_pull_none>;
};
};
};
/**********ETH**********/
&gmac {
status = "disabled";
};
/**********USB**********/
// &usbdrd {
// status = "disabled";
// };
// &usbdrd_dwc3 {
// status = "disabled";
// };
// &u2phy {
// status = "disabled";
// };
// &u2phy_otg {
// status = "disabled";
// };
/**********I2C**********/
// &i2c0 {
// status = "okay";
// pinctrl-0 = <&i2c0m2_xfer>;
// clock-frequency = <100000>;
// };
&i2c3 {
status = "okay";
pinctrl-0 = <&i2c3m1_xfer>;
clock-frequency = <100000>;
};
// /**********SPI**********/
&spi0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi0m0_pins>;
cs-gpios = <&gpio1 RK_PC0 1>;
// cs-gpios = <&gpio1 26 1>;
#address-cells = <1>;
#size-cells = <0>;
spidev@0 {
compatible = "rockchip,spidev";
spi-max-frequency = <1000000000>;
reg = <0>;
};
};
// /**********UART**********/
&uart3 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&uart3m1_xfer>;
};
//&uart4 {
// status = "okay";
// pinctrl-names = "default";
// pinctrl-0 = <&uart4m1_xfer>;
//};
// &uart5 {
// status = "okay";
// pinctrl-names = "default";
// pinctrl-0 = <&uart5m0_xfer>;
// };
/**********PWM**********/
&pwm0 {
status = "okay";
pinctrl-names = "active";
pinctrl-0 = <&pwm0m0_pins>;
// pinctrl-0 = <&pwm0m1_pins>;
};
&pwm1 {
status = "okay";
pinctrl-names = "active";
pinctrl-0 = <&pwm1m0_pins>;
// pinctrl-0 = <&pwm1m1_pins>;
};
// &pwm2 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm2m2_pins>;
// };
// &pwm3 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm3m2_pins>;
// };
// &pwm4 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm4m2_pins>;
// };
// &pwm5 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm5m2_pins>;
// };
// &pwm6 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm6m2_pins>;
// };
// &pwm7 {
// status = "okay";
// pinctrl-names = "active";
// pinctrl-0 = <&pwm7m2_pins>;
// };
// &pwm8 {
// status = "okay";
// pinctrl-names = "active";
// // pinctrl-0 = <&pwm8m1_pins>;
// pinctrl-0 = <&pwm8m0_pins>;
// };
// &pwm9 {
// status = "okay";
// pinctrl-names = "active";
// // pinctrl-0 = <&pwm9m1_pins>;
// pinctrl-0 = <&pwm9m0_pins>;
// };
&pwm10 {
status = "okay";
pinctrl-names = "active";
pinctrl-0 = <&pwm10m1_pins>;
// pinctrl-0 = <&pwm10m2_pins>;
// pinctrl-0 = <&pwm10m0_pins>;
};
&pwm11 {
status = "okay";
pinctrl-names = "active";
pinctrl-0 = <&pwm11m1_pins>;
// pinctrl-0 = <&pwm11m2_pins>;
// pinctrl-0 = <&pwm11m0_pins>;
};
3、编译内核
1)选择对应的板子编译
2) 开始编译
3)内核编译成功
4)替换boot.img
在目录查看boot镜像生成时间,并将其复制到之前烧录的镜像文件中,进行烧录即可。
四、修改官方的OLED程序;
1、修改DC和RST引脚
1)查看原理图引脚IO口编号
2)修改DEV_Config.h中的DC和RST引脚
2、在虚拟机里编译修改的C文件
1)传输C工程到虚拟机里
2)进入c目录,修改Makefile文件中的编译器路径
3)直接 make,如图
产生可执行文件,如图
五、执行
1、把整个工程文件传输到WINDOWS,然后再将工程文件夹传输到开发板,如图
2、执行应用程序
1)添加权限
chmod -R 777 Luckfox_Pico_OLED
2)执行
3、实际效果