微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 8.Ricoboard开发板上SPI模拟与OLED显示

8.Ricoboard开发板上SPI模拟与OLED显示

时间:10-02 整理:3721RD 点击:
在Ricoboard开发板上使能SPI0和SPI4的方法相信大家已经了解,我这里不在重复,因为使用正常的spi器件无法驱动手里的OLED模块,所以才想到使用GPIO模拟SPI的方法,理论不多说直接说实现步骤。
1.添加kernel编译支持。


2.选择合适的GPIO,这里直接使用SPI4的GPIO,如下图:


3.DTSI里面添加GPIO模拟SPI的设置


4.添加SPIDev测试驱动
因为在config里面设置CONFIG_SPI_SPIDEV=y,无法编译出spidev设备节点,所以直接在Makefile里面修改obj-$(CONFIG_SPI_SPIDEV)                += spidev.o为obj-y                += spidev.o。
5.添加应用程序测试SPIDEV设备节点


第一次和最后一次模拟处理的SPI的DO和D1是连接状态,中间一次是断开状态。测试结果如上图,pin连接如下图:


上面的步骤就可以保证我们模拟处理的SPI是可以正常通讯的,下面说说如何实现OELD的显示步骤。因为目前本职工作较忙,所以只是简单说一下实现步骤,相信有经验的人参考一下就可以实现这个功能。
OELD是一种非常高大尚的显示技术,据说苹果下一代产品就要使用OLED做显示屏,不过目前的OLED价格有点贵。
从技术上来讲实现难度并不大,只是可以参考的例子很少,在没有硬件支持的情况下自己将OLED点亮确实花费了一番功夫。
1.DTSI中OLED驱动加载


2.OLED接线方法


3.结果显示


4.驱动代码实现

  1. #include
  2. #include
  3. #include
  4. #include
  5. #include
  6. #include
  7. #include
  8. #include
  9. #include
  10. #include

  11. #define SSD1306_CMD    0
  12. #define SSD1306_DAT    1

  13. #define SSD1306_WIDTH    128
  14. #define SSD1306_HEIGHT   64

  15. static uint8_t s_chDispalyBuffer[128][8];

  16. const uint8_t c_chFont1608[95][16] = {      
  17. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
  18. {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xCC,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00},/*"!",1*/
  19. {0x00,0x00,0x08,0x00,0x30,0x00,0x60,0x00,0x08,0x00,0x30,0x00,0x60,0x00,0x00,0x00},/*""",2*/
  20. {0x02,0x20,0x03,0xFC,0x1E,0x20,0x02,0x20,0x03,0xFC,0x1E,0x20,0x02,0x20,0x00,0x00},/*"#",3*/
  21. {0x00,0x00,0x0E,0x18,0x11,0x04,0x3F,0xFF,0x10,0x84,0x0C,0x78,0x00,0x00,0x00,0x00},/*"$",4*/
  22. {0x0F,0x00,0x10,0x84,0x0F,0x38,0x00,0xC0,0x07,0x78,0x18,0x84,0x00,0x78,0x00,0x00},/*"%",5*/
  23. {0x00,0x78,0x0F,0x84,0x10,0xC4,0x11,0x24,0x0E,0x98,0x00,0xE4,0x00,0x84,0x00,0x08},/*"&",6*/
  24. {0x08,0x00,0x68,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
  25. {0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x18,0x18,0x20,0x04,0x40,0x02,0x00,0x00},/*"(",8*/
  26. {0x00,0x00,0x40,0x02,0x20,0x04,0x18,0x18,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00},/*")",9*/
  27. {0x02,0x40,0x02,0x40,0x01,0x80,0x0F,0xF0,0x01,0x80,0x02,0x40,0x02,0x40,0x00,0x00},/*"*",10*/
  28. {0x00,0x80,0x00,0x80,0x00,0x80,0x0F,0xF8,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x00},/*"+",11*/
  29. {0x00,0x01,0x00,0x0D,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*",",12*/
  30. {0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80},/*"-",13*/
  31. {0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*".",14*/
  32. {0x00,0x00,0x00,0x06,0x00,0x18,0x00,0x60,0x01,0x80,0x06,0x00,0x18,0x00,0x20,0x00},/*"/",15*/
  33. {0x00,0x00,0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"0",16*/
  34. {0x00,0x00,0x08,0x04,0x08,0x04,0x1F,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00},/*"1",17*/
  35. {0x00,0x00,0x0E,0x0C,0x10,0x14,0x10,0x24,0x10,0x44,0x11,0x84,0x0E,0x0C,0x00,0x00},/*"2",18*/
  36. {0x00,0x00,0x0C,0x18,0x10,0x04,0x11,0x04,0x11,0x04,0x12,0x88,0x0C,0x70,0x00,0x00},/*"3",19*/
  37. {0x00,0x00,0x00,0xE0,0x03,0x20,0x04,0x24,0x08,0x24,0x1F,0xFC,0x00,0x24,0x00,0x00},/*"4",20*/
  38. {0x00,0x00,0x1F,0x98,0x10,0x84,0x11,0x04,0x11,0x04,0x10,0x88,0x10,0x70,0x00,0x00},/*"5",21*/
  39. {0x00,0x00,0x07,0xF0,0x08,0x88,0x11,0x04,0x11,0x04,0x18,0x88,0x00,0x70,0x00,0x00},/*"6",22*/
  40. {0x00,0x00,0x1C,0x00,0x10,0x00,0x10,0xFC,0x13,0x00,0x1C,0x00,0x10,0x00,0x00,0x00},/*"7",23*/
  41. {0x00,0x00,0x0E,0x38,0x11,0x44,0x10,0x84,0x10,0x84,0x11,0x44,0x0E,0x38,0x00,0x00},/*"8",24*/
  42. {0x00,0x00,0x07,0x00,0x08,0x8C,0x10,0x44,0x10,0x44,0x08,0x88,0x07,0xF0,0x00,0x00},/*"9",25*/
  43. {0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x03,0x0C,0x00,0x00,0x00,0x00,0x00,0x00},/*":",26*/
  44. {0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*";",27*/
  45. {0x00,0x00,0x00,0x80,0x01,0x40,0x02,0x20,0x04,0x10,0x08,0x08,0x10,0x04,0x00,0x00},/*" ",30*/
  46. {0x00,0x00,0x0E,0x00,0x12,0x00,0x10,0x0C,0x10,0x6C,0x10,0x80,0x0F,0x00,0x00,0x00},/*"?",31*/
  47. {0x03,0xE0,0x0C,0x18,0x13,0xE4,0x14,0x24,0x17,0xC4,0x08,0x28,0x07,0xD0,0x00,0x00},/*"@",32*/
  48. {0x00,0x04,0x00,0x3C,0x03,0xC4,0x1C,0x40,0x07,0x40,0x00,0xE4,0x00,0x1C,0x00,0x04},/*"A",33*/
  49. {0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x11,0x04,0x0E,0x88,0x00,0x70,0x00,0x00},/*"B",34*/
  50. {0x03,0xE0,0x0C,0x18,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0x08,0x1C,0x10,0x00,0x00},/*"C",35*/
  51. {0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"D",36*/
  52. {0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x04,0x17,0xC4,0x10,0x04,0x08,0x18,0x00,0x00},/*"E",37*/
  53. {0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x17,0xC0,0x10,0x00,0x08,0x00,0x00,0x00},/*"F",38*/
  54. {0x03,0xE0,0x0C,0x18,0x10,0x04,0x10,0x04,0x10,0x44,0x1C,0x78,0x00,0x40,0x00,0x00},/*"G",39*/
  55. {0x10,0x04,0x1F,0xFC,0x10,0x84,0x00,0x80,0x00,0x80,0x10,0x84,0x1F,0xFC,0x10,0x04},/*"H",40*/
  56. {0x00,0x00,0x10,0x04,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x04,0x00,0x00,0x00,0x00},/*"I",41*/
  57. {0x00,0x03,0x00,0x01,0x10,0x01,0x10,0x01,0x1F,0xFE,0x10,0x00,0x10,0x00,0x00,0x00},/*"J",42*/
  58. {0x10,0x04,0x1F,0xFC,0x11,0x04,0x03,0x80,0x14,0x64,0x18,0x1C,0x10,0x04,0x00,0x00},/*"K",43*/
  59. {0x10,0x04,0x1F,0xFC,0x10,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x0C,0x00,0x00},/*"L",44*/
  60. {0x10,0x04,0x1F,0xFC,0x1F,0x00,0x00,0xFC,0x1F,0x00,0x1F,0xFC,0x10,0x04,0x00,0x00},/*"M",45*/
  61. {0x10,0x04,0x1F,0xFC,0x0C,0x04,0x03,0x00,0x00,0xE0,0x10,0x18,0x1F,0xFC,0x10,0x00},/*"N",46*/
  62. {0x07,0xF0,0x08,0x08,0x10,0x04,0x10,0x04,0x10,0x04,0x08,0x08,0x07,0xF0,0x00,0x00},/*"O",47*/
  63. {0x10,0x04,0x1F,0xFC,0x10,0x84,0x10,0x80,0x10,0x80,0x10,0x80,0x0F,0x00,0x00,0x00},/*"P",48*/
  64. {0x07,0xF0,0x08,0x18,0x10,0x24,0x10,0x24,0x10,0x1C,0x08,0x0A,0x07,0xF2,0x00,0x00},/*"Q",49*/
  65. {0x10,0x04,0x1F,0xFC,0x11,0x04,0x11,0x00,0x11,0xC0,0x11,0x30,0x0E,0x0C,0x00,0x04},/*"R",50*/
  66. {0x00,0x00,0x0E,0x1C,0x11,0x04,0x10,0x84,0x10,0x84,0x10,0x44,0x1C,0x38,0x00,0x00},/*"S",51*/
  67. {0x18,0x00,0x10,0x00,0x10,0x04,0x1F,0xFC,0x10,0x04,0x10,0x00,0x18,0x00,0x00,0x00},/*"T",52*/
  68. {0x10,0x00,0x1F,0xF8,0x10,0x04,0x00,0x04,0x00,0x04,0x10,0x04,0x1F,0xF8,0x10,0x00},/*"U",53*/
  69. {0x10,0x00,0x1E,0x00,0x11,0xE0,0x00,0x1C,0x00,0x70,0x13,0x80,0x1C,0x00,0x10,0x00},/*"V",54*/
  70. {0x1F,0xC0,0x10,0x3C,0x00,0xE0,0x1F,0x00,0x00,0xE0,0x10,0x3C,0x1F,0xC0,0x00,0x00},/*"W",55*/
  71. {0x10,0x04,0x18,0x0C,0x16,0x34,0x01,0xC0,0x01,0xC0,0x16,0x34,0x18,0x0C,0x10,0x04},/*"X",56*/
  72. {0x10,0x00,0x1C,0x00,0x13,0x04,0x00,0xFC,0x13,0x04,0x1C,0x00,0x10,0x00,0x00,0x00},/*"Y",57*/
  73. {0x08,0x04,0x10,0x1C,0x10,0x64,0x10,0x84,0x13,0x04,0x1C,0x04,0x10,0x18,0x00,0x00},/*"Z",58*/
  74. {0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x40,0x02,0x40,0x02,0x40,0x02,0x00,0x00},/*"[",59*/
  75. {0x00,0x00,0x30,0x00,0x0C,0x00,0x03,0x80,0x00,0x60,0x00,0x1C,0x00,0x03,0x00,0x00},/*"\",60*/
  76. {0x00,0x00,0x40,0x02,0x40,0x02,0x40,0x02,0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00},/*"]",61*/
  77. {0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00},/*"^",62*/
  78. {0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01},/*"_",63*/
  79. {0x00,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/
  80. {0x00,0x00,0x00,0x98,0x01,0x24,0x01,0x44,0x01,0x44,0x01,0x44,0x00,0xFC,0x00,0x04},/*"a",65*/
  81. {0x10,0x00,0x1F,0xFC,0x00,0x88,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x70,0x00,0x00},/*"b",66*/
  82. {0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x00},/*"c",67*/
  83. {0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x11,0x08,0x1F,0xFC,0x00,0x04},/*"d",68*/
  84. {0x00,0x00,0x00,0xF8,0x01,0x44,0x01,0x44,0x01,0x44,0x01,0x44,0x00,0xC8,0x00,0x00},/*"e",69*/
  85. {0x00,0x00,0x01,0x04,0x01,0x04,0x0F,0xFC,0x11,0x04,0x11,0x04,0x11,0x00,0x18,0x00},/*"f",70*/
  86. {0x00,0x00,0x00,0xD6,0x01,0x29,0x01,0x29,0x01,0x29,0x01,0xC9,0x01,0x06,0x00,0x00},/*"g",71*/
  87. {0x10,0x04,0x1F,0xFC,0x00,0x84,0x01,0x00,0x01,0x00,0x01,0x04,0x00,0xFC,0x00,0x04},/*"h",72*/
  88. {0x00,0x00,0x01,0x04,0x19,0x04,0x19,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00},/*"i",73*/
  89. {0x00,0x00,0x00,0x03,0x00,0x01,0x01,0x01,0x19,0x01,0x19,0xFE,0x00,0x00,0x00,0x00},/*"j",74*/
  90. {0x10,0x04,0x1F,0xFC,0x00,0x24,0x00,0x40,0x01,0xB4,0x01,0x0C,0x01,0x04,0x00,0x00},/*"k",75*/
  91. {0x00,0x00,0x10,0x04,0x10,0x04,0x1F,0xFC,0x00,0x04,0x00,0x04,0x00,0x00,0x00,0x00},/*"l",76*/
  92. {0x01,0x04,0x01,0xFC,0x01,0x04,0x01,0x00,0x01,0xFC,0x01,0x04,0x01,0x00,0x00,0xFC},/*"m",77*/
  93. {0x01,0x04,0x01,0xFC,0x00,0x84,0x01,0x00,0x01,0x00,0x01,0x04,0x00,0xFC,0x00,0x04},/*"n",78*/
  94. {0x00,0x00,0x00,0xF8,0x01,0x04,0x01,0x04,0x01,0x04,0x01,0x04,0x00,0xF8,0x00,0x00},/*"o",79*/
  95. {0x01,0x01,0x01,0xFF,0x00,0x85,0x01,0x04,0x01,0x04,0x00,0x88,0x00,0x70,0x00,0x00},/*"p",80*/
  96. {0x00,0x00,0x00,0x70,0x00,0x88,0x01,0x04,0x01,0x04,0x01,0x05,0x01,0xFF,0x00,0x01},/*"q",81*/
  97. {0x01,0x04,0x01,0x04,0x01,0xFC,0x00,0x84,0x01,0x04,0x01,0x00,0x01,0x80,0x00,0x00},/*"r",82*/
  98. {0x00,0x00,0x00,0xCC,0x01,0x24,0x01,0x24,0x01,0x24,0x01,0x24,0x01,0x98,0x00,0x00},/*"s",83*/
  99. {0x00,0x00,0x01,0x00,0x01,0x00,0x07,0xF8,0x01,0x04,0x01,0x04,0x00,0x00,0x00,0x00},/*"t",84*/
  100. {0x01,0x00,0x01,0xF8,0x00,0x04,0x00,0x04,0x00,0x04,0x01,0x08,0x01,0xFC,0x00,0x04},/*"u",85*/
  101. {0x01,0x00,0x01,0x80,0x01,0x70,0x00,0x0C,0x00,0x10,0x01,0x60,0x01,0x80,0x01,0x00},/*"v",86*/
  102. {0x01,0xF0,0x01,0x0C,0x00,0x30,0x01,0xC0,0x00,0x30,0x01,0x0C,0x01,0xF0,0x01,0x00},/*"w",87*/
  103. {0x00,0x00,0x01,0x04,0x01,0x8C,0x00,0x74,0x01,0x70,0x01,0x8C,0x01,0x04,0x00,0x00},/*"x",88*/
  104. {0x01,0x01,0x01,0x81,0x01,0x71,0x00,0x0E,0x00,0x18,0x01,0x60,0x01,0x80,0x01,0x00},/*"y",89*/
  105. {0x00,0x00,0x01,0x84,0x01,0x0C,0x01,0x34,0x01,0x44,0x01,0x84,0x01,0x0C,0x00,0x00},/*"z",90*/
  106. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x3E,0xFC,0x40,0x02,0x40,0x02},/*"{",91*/
  107. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00},/*"|",92*/
  108. {0x00,0x00,0x40,0x02,0x40,0x02,0x3E,0xFC,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"}",93*/
  109. {0x00,0x00,0x60,0x00,0x80,0x00,0x80,0x00,0x40,0x00,0x40,0x00,0x20,0x00,0x20,0x00},/*"~",94*/
  110. };

  111. struct spi_device *spi_ssd1306_dev;

  112. static void ssd1306_write_byte(uint8_t chData, uint8_t chCmd)
  113. {
  114.     struct spi_transfer t;
  115.     struct spi_message m;

  116.     uint16_t data = chData;
  117.    
  118.     memset(&t,0,sizeof(struct spi_transfer));
  119.      
  120.     if (chCmd) {
  121.         data |= (1 127 || chYpos > 63) {
  122.         return;
  123.     }
  124.     chPos = 7 - chYpos / 8; //
  125.     chBx = chYpos % 8;
  126.     chTemp = 1 (SSD1306_WIDTH - chSize / 2)) {
  127.             chXpos = 0;
  128.             chYpos += chSize;
  129.             if (chYpos > (SSD1306_HEIGHT - chSize)) {
  130.                 chYpos = chXpos = 0;
  131.                 ssd1306_clear_screen(0x00);
  132.             }
  133.         }
  134.         
  135.         ssd1306_display_char(chXpos, chYpos, *pchString, chSize, chMode);
  136.         chXpos += chSize / 2;
  137.         pchString ++;
  138.     }
  139. }

  140. void ssd1306_init(void)
  141. {
  142. #if 1
  143.     ssd1306_write_byte(0xAE, SSD1306_CMD);//--turn off oled panel
  144.     ssd1306_write_byte(0x00, SSD1306_CMD);//---set low column address
  145.     ssd1306_write_byte(0x10, SSD1306_CMD);//---set high column address
  146.     ssd1306_write_byte(0x40, SSD1306_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  147.     ssd1306_write_byte(0x81, SSD1306_CMD);//--set contrast control register
  148.     ssd1306_write_byte(0xCF, SSD1306_CMD);// Set SEG Output Current Brightness
  149.     ssd1306_write_byte(0xA1, SSD1306_CMD);//--Set SEG/Column Mapping     
  150.     ssd1306_write_byte(0xC0, SSD1306_CMD);//Set COM/Row Scan Direction   
  151.     ssd1306_write_byte(0xA6, SSD1306_CMD);//--set normal display
  152.     ssd1306_write_byte(0xA8, SSD1306_CMD);//--set multiplex ratio(1 to 64)
  153.     ssd1306_write_byte(0x3f, SSD1306_CMD);//--1/64 duty
  154.     ssd1306_write_byte(0xD3, SSD1306_CMD);//-set display offset    Shift Mapping RAM Counter (0x00~0x3F)
  155.     ssd1306_write_byte(0x00, SSD1306_CMD);//-not offset
  156.     ssd1306_write_byte(0xd5, SSD1306_CMD);//--set display clock divide ratio/oscillator frequency
  157.     ssd1306_write_byte(0x80, SSD1306_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
  158.     ssd1306_write_byte(0xD9, SSD1306_CMD);//--set pre-charge period
  159.     ssd1306_write_byte(0xF1, SSD1306_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  160.     ssd1306_write_byte(0xDA, SSD1306_CMD);//--set com pins hardware configuration
  161.     ssd1306_write_byte(0x12, SSD1306_CMD);
  162.     ssd1306_write_byte(0xDB, SSD1306_CMD);//--set vcomh
  163.     ssd1306_write_byte(0x40, SSD1306_CMD);//Set VCOM Deselect Level
  164.     ssd1306_write_byte(0x20, SSD1306_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
  165.     ssd1306_write_byte(0x02, SSD1306_CMD);//
  166.     ssd1306_write_byte(0x8D, SSD1306_CMD);//--set Charge Pump enable/disable
  167.     ssd1306_write_byte(0x14, SSD1306_CMD);//--set(0x10) disable
  168.     ssd1306_write_byte(0xA4, SSD1306_CMD);// Disable Entire Display On (0xa4/0xa5)
  169.     ssd1306_write_byte(0xA6, SSD1306_CMD);// Disable Inverse Display On (0xa6/a7)
  170.     ssd1306_write_byte(0xAF, SSD1306_CMD);//--turn on oled panel
  171. #else
  172.            ssd1306_write_byte(0xAE, SSD1306_CMD);//--turn off oled panel
  173.     ssd1306_write_byte(0x00, SSD1306_CMD);//---set low column address
  174.     ssd1306_write_byte(0x10, SSD1306_CMD);//---set high column address
  175.     ssd1306_write_byte(0x40, SSD1306_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  176.     ssd1306_write_byte(0xB0, SSD1306_CMD);//    ssd1306_write_byte(0xC0, SSD1306_CMD);//Set COM/Row Scan Direction   

  177.     ssd1306_write_byte(0x81, SSD1306_CMD);//--set contrast control register
  178.     ssd1306_write_byte(0xCF, SSD1306_CMD);// Set SEG Output Current Brightness
  179.     ssd1306_write_byte(0xA1, SSD1306_CMD);//--Set SEG/Column Mapping     
  180.     ssd1306_write_byte(0xA6, SSD1306_CMD);//--set normal display
  181.     ssd1306_write_byte(0xA8, SSD1306_CMD);//--set multiplex ratio(1 to 64)
  182.     ssd1306_write_byte(0x3f, SSD1306_CMD);//--1/64 duty
  183.     ssd1306_write_byte(0xC8, SSD1306_CMD);//-set display offset    Shift Mapping RAM Counter (0x00~0x3F)
  184.     ssd1306_write_byte(0xD3, SSD1306_CMD);//-set display offset    Shift Mapping RAM Counter (0x00~0x3F)
  185.     ssd1306_write_byte(0xC0, SSD1306_CMD);//-not offset
  186.     ssd1306_write_byte(0xd5, SSD1306_CMD);//--set display clock divide ratio/oscillator frequency
  187.     ssd1306_write_byte(0x80, SSD1306_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
  188.     ssd1306_write_byte(0xD9, SSD1306_CMD);//--set pre-charge period
  189.     ssd1306_write_byte(0xF1, SSD1306_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  190.     ssd1306_write_byte(0xDA, SSD1306_CMD);//--set com pins hardware configuration
  191.     ssd1306_write_byte(0x12, SSD1306_CMD);
  192.     ssd1306_write_byte(0xDB, SSD1306_CMD);//--set vcomh
  193.     ssd1306_write_byte(0x40, SSD1306_CMD);//Set VCOM Deselect Level

  194.     ssd1306_write_byte(0x8D, SSD1306_CMD);//--set Charge Pump enable/disable
  195.     ssd1306_write_byte(0x10, SSD1306_CMD);//--set(0x10) disable

  196.     ssd1306_write_byte(0xAF, SSD1306_CMD);//--turn on oled panel

  197. #endif
  198.     ssd1306_display_on();
  199.     ssd1306_clear_screen(0xff);
  200.    
  201. }


  202. static int spi_ssd1306_probe(struct spi_device *spi)
  203. {
  204.         printk("=11=spi_ssd1306_probe\n");
  205.         spi_ssd1306_dev = spi;
  206.         spi_ssd1306_dev->bits_per_word = 9;
  207.        
  208.         ssd1306_init();
  209.         printk("=2=spi_ssd1306_probe\n");
  210.         ssd1306_clear_screen(0x00);
  211.         printk("=3=spi_ssd1306_probe\n");
  212.         ssd1306_display_off();
  213.         printk("=4=spi_ssd1306_probe\n");
  214.        
  215.         ssd1306_display_string(18, 0, "hello, Linux!", 16, 1);
  216.         ssd1306_display_string(0, 16, "this is a spi driver demo!", 16, 1);
  217.         ssd1306_refresh_gram();
  218.         ssd1306_display_on();
  219.         printk("=5=spi_ssd1306_probe\n");
  220.        
  221.         return 0;
  222. }


  223. static int spi_ssd1306_remove(struct spi_device *spi)
  224. {
  225.     printk("ssd1306_remove\n");
  226.    
  227.     ssd1306_clear_screen(0x00);
  228.     ssd1306_display_off();
  229.     return 0;
  230. }

  231. static const struct of_device_id ssd1306_dt_ids[] = {
  232.         { .compatible = "oled,ssd1306" },
  233.         {},
  234. };
  235. MODULE_DEVICE_TABLE(of, ssd1306_dt_ids);
  236. static struct spi_driver spi_ssd1306_driver = {
  237.     .driver = {
  238.         .name    = "spi_ssd1306",
  239.         .bus    = &spi_bus_type,
  240.         .owner    = THIS_MODULE,
  241.                                 .of_match_table = of_match_ptr(ssd1306_dt_ids),
  242.     },
  243.     .probe    = spi_ssd1306_probe,
  244.     .remove    = spi_ssd1306_remove,
  245. };


  246. static int __init spi_ssd1306_init(void)
  247. {
  248.         printk("=0000=spi_ssd1306_init\n");
  249.     return spi_register_driver(&spi_ssd1306_driver);
  250. }


  251. static void __exit spi_ssd1306_exit(void)
  252. {
  253.     spi_unregister_driver(&spi_ssd1306_driver);
  254. }


  255. module_init(spi_ssd1306_init);
  256. module_exit(spi_ssd1306_exit);

  257. MODULE_LICENSE("GPL");

复制代码


5.改进方案
a.此次点亮的OLED模块是3-wire模式,4-wire和IIC模式后面有时间在尝试实现。
b.此次OELD显示的字符串是直接写在驱动中,后面有时间会尝试通过fileoption的方式在应用层实现输入显示内容。
c.因为时间关系,并没有详细按照OLED的文档进行解析,驱动中初始化,ON,OFF等等功能是如何实现的,后面有时间会补上。
6.特别感谢
这里特别感谢hackfun同学,非常感谢他无私,非常耐心的帮我理顺实现思路。
知识点总结:
1.DTSI中如何设置GPIO模拟SPI
2.T*I中如何在驱动中设置某个GPIO为“输出”,状态为“高”。
3.这种SPI协议驱动的器件,知道如何正确的使用示波器非常重要,非常重要,非常重要。
4.OLED驱动初始化,数据传输实现。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top