ssd1306.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. #include "ssd1306.h"
  2. #include "esp_log.h"
  3. #include "driver/gpio.h"
  4. #include "driver/i2c.h"
  5. #include <driver/gpio.h>
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task.h"
  8. #include "freertos/queue.h"
  9. #include "freertos/task.h"
  10. #include "stdlib.h"
  11. #include "string.h"
  12. #include "config.h"
  13. #ifdef ENABLE_SSD1306
  14. const uint8_t font_width = 8;
  15. static uint8_t SSD1306_Buffer[SSD1306_WIDTH * SSD1306_HEIGHT / 8];
  16. typedef struct {
  17. uint16_t CurrentX;
  18. uint16_t CurrentY;
  19. uint8_t Inverted;
  20. uint8_t Initialized;
  21. } SSD1306_t;
  22. /* Private variable */
  23. static SSD1306_t SSD1306;
  24. const uint16_t Font_data_7x10 [] = {
  25. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // sp
  26. 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x1000, 0x0000, 0x0000, // !
  27. 0x2800, 0x2800, 0x2800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // "
  28. 0x2400, 0x2400, 0x7C00, 0x2400, 0x4800, 0x7C00, 0x4800, 0x4800, 0x0000, 0x0000, // #
  29. 0x0C00, 0x1200, 0x1200, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Deg C
  30. 0x2000, 0x5400, 0x5800, 0x3000, 0x2800, 0x5400, 0x1400, 0x0800, 0x0000, 0x0000, // %
  31. 0x1000, 0x2800, 0x2800, 0x1000, 0x3400, 0x4800, 0x4800, 0x3400, 0x0000, 0x0000, // &
  32. 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // '
  33. 0x0800, 0x1000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x1000, 0x0800, // (
  34. 0x2000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x1000, 0x2000, // )
  35. 0x1000, 0x3800, 0x1000, 0x2800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // *
  36. 0x0000, 0x0000, 0x1000, 0x1000, 0x7C00, 0x1000, 0x1000, 0x0000, 0x0000, 0x0000, // +
  37. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x1000, 0x1000, // ,
  38. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3800, 0x0000, 0x0000, 0x0000, 0x0000, // -
  39. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, // .
  40. 0x0800, 0x0800, 0x1000, 0x1000, 0x1000, 0x1000, 0x2000, 0x2000, 0x0000, 0x0000, // /
  41. 0x3800, 0x4400, 0x4400, 0x5400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // 0
  42. 0x1000, 0x3000, 0x5000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // 1
  43. 0x3800, 0x4400, 0x4400, 0x0400, 0x0800, 0x1000, 0x2000, 0x7C00, 0x0000, 0x0000, // 2
  44. 0x3800, 0x4400, 0x0400, 0x1800, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // 3
  45. 0x0800, 0x1800, 0x2800, 0x2800, 0x4800, 0x7C00, 0x0800, 0x0800, 0x0000, 0x0000, // 4
  46. 0x7C00, 0x4000, 0x4000, 0x7800, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // 5
  47. 0x3800, 0x4400, 0x4000, 0x7800, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // 6
  48. 0x7C00, 0x0400, 0x0800, 0x1000, 0x1000, 0x2000, 0x2000, 0x2000, 0x0000, 0x0000, // 7
  49. 0x3800, 0x4400, 0x4400, 0x3800, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // 8
  50. 0x3800, 0x4400, 0x4400, 0x4400, 0x3C00, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // 9
  51. 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, // :
  52. 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, 0x0000, 0x1000, 0x1000, 0x1000, // ;
  53. 0x0000, 0x0000, 0x0C00, 0x3000, 0x4000, 0x3000, 0x0C00, 0x0000, 0x0000, 0x0000, // <
  54. 0x0000, 0x0000, 0x0000, 0x7C00, 0x0000, 0x7C00, 0x0000, 0x0000, 0x0000, 0x0000, // =
  55. 0x0000, 0x0000, 0x6000, 0x1800, 0x0400, 0x1800, 0x6000, 0x0000, 0x0000, 0x0000, // >
  56. 0x3800, 0x4400, 0x0400, 0x0800, 0x1000, 0x1000, 0x0000, 0x1000, 0x0000, 0x0000, // ?
  57. 0x3800, 0x4400, 0x4C00, 0x5400, 0x5C00, 0x4000, 0x4000, 0x3800, 0x0000, 0x0000, // @
  58. 0x1000, 0x2800, 0x2800, 0x2800, 0x2800, 0x7C00, 0x4400, 0x4400, 0x0000, 0x0000, // A
  59. 0x7800, 0x4400, 0x4400, 0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x0000, 0x0000, // B
  60. 0x3800, 0x4400, 0x4000, 0x4000, 0x4000, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000, // C
  61. 0x7000, 0x4800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4800, 0x7000, 0x0000, 0x0000, // D
  62. 0x7C00, 0x4000, 0x4000, 0x7C00, 0x4000, 0x4000, 0x4000, 0x7C00, 0x0000, 0x0000, // E
  63. 0x7C00, 0x4000, 0x4000, 0x7800, 0x4000, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000, // F
  64. 0x3800, 0x4400, 0x4000, 0x4000, 0x5C00, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // G
  65. 0x4400, 0x4400, 0x4400, 0x7C00, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // H
  66. 0x3800, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x3800, 0x0000, 0x0000, // I
  67. 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // J
  68. 0x4400, 0x4800, 0x5000, 0x6000, 0x5000, 0x4800, 0x4800, 0x4400, 0x0000, 0x0000, // K
  69. 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x7C00, 0x0000, 0x0000, // L
  70. 0x4400, 0x6C00, 0x6C00, 0x5400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // M
  71. 0x4400, 0x6400, 0x6400, 0x5400, 0x5400, 0x4C00, 0x4C00, 0x4400, 0x0000, 0x0000, // N
  72. 0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // O
  73. 0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000, // P
  74. 0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x5400, 0x3800, 0x0400, 0x0000, // Q
  75. 0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x4800, 0x4800, 0x4400, 0x0000, 0x0000, // R
  76. 0x3800, 0x4400, 0x4000, 0x3000, 0x0800, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // S
  77. 0x7C00, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // T
  78. 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // U
  79. 0x4400, 0x4400, 0x4400, 0x2800, 0x2800, 0x2800, 0x1000, 0x1000, 0x0000, 0x0000, // V
  80. 0x4400, 0x4400, 0x5400, 0x5400, 0x5400, 0x6C00, 0x2800, 0x2800, 0x0000, 0x0000, // W
  81. 0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x2800, 0x2800, 0x4400, 0x0000, 0x0000, // X
  82. 0x4400, 0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // Y
  83. 0x7C00, 0x0400, 0x0800, 0x1000, 0x1000, 0x2000, 0x4000, 0x7C00, 0x0000, 0x0000, // Z
  84. 0x1800, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1800, // [
  85. 0x2000, 0x2000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0000, 0x0000, /* \ */
  86. 0x3000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x3000, // ]
  87. 0x1000, 0x2800, 0x2800, 0x4400, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ^
  88. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFE00, // _
  89. 0x2000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // `
  90. 0x0000, 0x0000, 0x3800, 0x4400, 0x3C00, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000, // a
  91. 0x4000, 0x4000, 0x5800, 0x6400, 0x4400, 0x4400, 0x6400, 0x5800, 0x0000, 0x0000, // b
  92. 0x0000, 0x0000, 0x3800, 0x4400, 0x4000, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000, // c
  93. 0x0400, 0x0400, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000, // d
  94. 0x0000, 0x0000, 0x3800, 0x4400, 0x7C00, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000, // e
  95. 0x0C00, 0x1000, 0x7C00, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // f
  96. 0x0000, 0x0000, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0400, 0x7800, // g
  97. 0x4000, 0x4000, 0x5800, 0x6400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // h
  98. 0x1000, 0x0000, 0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // i
  99. 0x1000, 0x0000, 0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0xE000, // j
  100. 0x4000, 0x4000, 0x4800, 0x5000, 0x6000, 0x5000, 0x4800, 0x4400, 0x0000, 0x0000, // k
  101. 0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // l
  102. 0x0000, 0x0000, 0x7800, 0x5400, 0x5400, 0x5400, 0x5400, 0x5400, 0x0000, 0x0000, // m
  103. 0x0000, 0x0000, 0x5800, 0x6400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // n
  104. 0x0000, 0x0000, 0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // o
  105. 0x0000, 0x0000, 0x5800, 0x6400, 0x4400, 0x4400, 0x6400, 0x5800, 0x4000, 0x4000, // p
  106. 0x0000, 0x0000, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0400, 0x0400, // q
  107. 0x0000, 0x0000, 0x5800, 0x6400, 0x4000, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000, // r
  108. 0x0000, 0x0000, 0x3800, 0x4400, 0x3000, 0x0800, 0x4400, 0x3800, 0x0000, 0x0000, // s
  109. 0x2000, 0x2000, 0x7800, 0x2000, 0x2000, 0x2000, 0x2000, 0x1800, 0x0000, 0x0000, // t
  110. 0x0000, 0x0000, 0x4400, 0x4400, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000, // u
  111. 0x0000, 0x0000, 0x4400, 0x4400, 0x2800, 0x2800, 0x2800, 0x1000, 0x0000, 0x0000, // v
  112. 0x0000, 0x0000, 0x5400, 0x5400, 0x5400, 0x6C00, 0x2800, 0x2800, 0x0000, 0x0000, // w
  113. 0x0000, 0x0000, 0x4400, 0x2800, 0x1000, 0x1000, 0x2800, 0x4400, 0x0000, 0x0000, // x
  114. 0x0000, 0x0000, 0x4400, 0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x1000, 0x6000, // y
  115. 0x0000, 0x0000, 0x7C00, 0x0800, 0x1000, 0x2000, 0x4000, 0x7C00, 0x0000, 0x0000, // z
  116. 0x1800, 0x1000, 0x1000, 0x1000, 0x2000, 0x2000, 0x1000, 0x1000, 0x1000, 0x1800, // {
  117. 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, // |
  118. 0x3000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x1000, 0x1000, 0x1000, 0x3000, // }
  119. 0x0000, 0x0000, 0x0000, 0x7400, 0x4C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ~
  120. };
  121. FontDef_t Font_7x10 = {
  122. 7,
  123. 10,
  124. Font_data_7x10
  125. };
  126. esp_err_t i2c_tx_cmd(const uint8_t *data, const uint8_t length) {
  127. i2c_cmd_handle_t handle = i2c_cmd_link_create();
  128. i2c_master_start(handle);
  129. i2c_master_write_byte(handle, (SSD1306_OLED_ADDR << 1) | WRITE_BIT, ACK_CHECK_EN);
  130. i2c_master_write_byte(handle, COMMAND_MODE, ACK_CHECK_EN);
  131. i2c_master_write(handle, data, length, ACK_CHECK_EN);
  132. i2c_master_stop(handle);
  133. esp_err_t retVal = i2c_master_cmd_begin(I2C_MASTER_NUM, handle, 1000 / portTICK_RATE_MS);
  134. i2c_cmd_link_delete(handle);
  135. return retVal;
  136. }
  137. esp_err_t i2c_tx_data(const uint8_t *data, const uint8_t length) {
  138. i2c_cmd_handle_t handle = i2c_cmd_link_create();
  139. i2c_master_start(handle);
  140. i2c_master_write_byte(handle, (SSD1306_OLED_ADDR << 1) | WRITE_BIT, ACK_CHECK_EN);
  141. i2c_master_write_byte(handle, DATA_MODE, ACK_CHECK_EN);
  142. i2c_master_write(handle, data, length, ACK_CHECK_EN);
  143. i2c_master_stop(handle);
  144. esp_err_t retVal = i2c_master_cmd_begin(I2C_MASTER_NUM, handle, 1000 / portTICK_RATE_MS);
  145. i2c_cmd_link_delete(handle);
  146. return retVal;
  147. }
  148. void SSD1306_DrawPixel(uint16_t x, uint16_t y, SSD1306_COLOR_t color) {
  149. if (
  150. x >= SSD1306_WIDTH ||
  151. y >= SSD1306_HEIGHT
  152. ) {
  153. return;
  154. }
  155. if (color == SSD1306_COLOR_WHITE) {
  156. SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] |= 1 << (y % 8);
  157. } else {
  158. SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] &= ~(1 << (y % 8));
  159. }
  160. }
  161. char SSD1306_Putc(char ch, const FontDef_t* Font, SSD1306_COLOR_t color) {
  162. uint32_t i, b, j;
  163. /* Check available space in LCD */
  164. if (
  165. SSD1306_WIDTH <= (SSD1306.CurrentX + Font->FontWidth) ||
  166. SSD1306_HEIGHT <= (SSD1306.CurrentY + Font->FontHeight)
  167. ) {
  168. /* Error */
  169. return 0;
  170. }
  171. /* Go through font */
  172. for (i = 0; i < Font->FontHeight; i++) {
  173. b = Font->data[(ch - 32) * Font->FontHeight + i];
  174. for (j = 0; j < Font->FontWidth; j++) {
  175. if ((b << j) & 0x8000) {
  176. SSD1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR_t) color);
  177. } else {
  178. SSD1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR_t)!color);
  179. }
  180. }
  181. }
  182. /* Increase pointer */
  183. SSD1306.CurrentX += Font->FontWidth;
  184. /* Return character written */
  185. return ch;
  186. }
  187. char SSD1306_Puts(char* str, FontDef_t* Font, SSD1306_COLOR_t color) {
  188. /* Write characters */
  189. while (*str) {
  190. /* Write character by character */
  191. if (SSD1306_Putc(*str, Font, color) != *str) {
  192. /* Return error */
  193. return *str;
  194. }
  195. /* Increase string pointer */
  196. str++;
  197. }
  198. /* Everything OK, zero should be returned */
  199. return *str;
  200. }
  201. void SSD1306_UpdateScreen(void) {
  202. uint8_t m;
  203. for (m = 0; m < 8; m++) {
  204. uint8_t configMsg[] = {
  205. PAGE_START_ADDR+m, // set page range:
  206. 0x00, // y / 8
  207. 0x10, // y / 8
  208. };
  209. i2c_tx_cmd(configMsg, sizeof configMsg);
  210. i2c_tx_data(&SSD1306_Buffer[SSD1306_WIDTH * m], SSD1306_WIDTH);
  211. }
  212. }
  213. esp_err_t oled_ssd1306_init() {
  214. i2c_cmd_handle_t cmd = i2c_cmd_link_create();
  215. i2c_master_start(cmd);
  216. i2c_master_write_byte(cmd, (SSD1306_OLED_ADDR << 1) | WRITE_BIT, ACK_CHECK_EN);
  217. // Initialization (page 64)
  218. // The next bytes are commands
  219. i2c_master_write_byte(cmd, COMMAND_MODE, ACK_CHECK_EN);
  220. // Mux Ratio
  221. i2c_master_write_byte(cmd, MULTIPLEX_RATIO, ACK_CHECK_EN);
  222. i2c_master_write_byte(cmd, 0x3F, ACK_CHECK_EN);
  223. // Set display offset
  224. i2c_master_write_byte(cmd, DISPLAY_OFFSET, ACK_CHECK_EN);
  225. i2c_master_write_byte(cmd, 0x00, ACK_CHECK_EN);
  226. // Set display line start
  227. i2c_master_write_byte(cmd, DISPLAY_LINE_START, ACK_CHECK_EN);
  228. i2c_master_write_byte(cmd, 0x00, ACK_CHECK_EN);
  229. // Set Segment re-map
  230. i2c_master_write_byte(cmd, SEGMENT_REMAP, ACK_CHECK_EN);
  231. // Set COM output scan dir
  232. i2c_master_write_byte(cmd, COM_OUTPUT_SCAN_DIR, ACK_CHECK_EN);
  233. i2c_master_write_byte(cmd, 0x00, ACK_CHECK_EN);
  234. // Set COM pins hardware config
  235. i2c_master_write_byte(cmd, COM_PINS_HARDWARE_CONFIG, ACK_CHECK_EN);
  236. i2c_master_write_byte(cmd, 0x12, ACK_CHECK_EN);
  237. // Set contrast Control
  238. i2c_master_write_byte(cmd, CONTRAST_CONTROL, ACK_CHECK_EN);
  239. i2c_master_write_byte(cmd, 0x7F, ACK_CHECK_EN);
  240. i2c_master_write_byte(cmd, DEACTIVATE_SCROLL, ACK_CHECK_EN);
  241. // Disable entire display ON
  242. i2c_master_write_byte(cmd, DISABLE_ENTIRE_DISPLAY, ACK_CHECK_EN);
  243. // Set normal display
  244. i2c_master_write_byte(cmd, NORMAL_DISPLAY, ACK_CHECK_EN);
  245. // Set OSC frequency
  246. i2c_master_write_byte(cmd, DISPLAY_CLK_RATIO, ACK_CHECK_EN);
  247. i2c_master_write_byte(cmd, 0x80, ACK_CHECK_EN);
  248. // Enable charge pump regulator
  249. i2c_master_write_byte(cmd, CHARGE_PUMP_SET, ACK_CHECK_EN);
  250. i2c_master_write_byte(cmd, 0x14, ACK_CHECK_EN);
  251. // Display on
  252. i2c_master_write_byte(cmd, DISPLAY_ON, ACK_CHECK_EN);
  253. // Stop bit
  254. i2c_master_stop(cmd);
  255. esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
  256. i2c_cmd_link_delete(cmd);
  257. SSD1306.CurrentX = 30;
  258. SSD1306.CurrentY = 10;
  259. SSD1306.Initialized = 1;
  260. SSD1306_Putc('A',&Font_7x10,SSD1306_COLOR_WHITE);
  261. SSD1306_DrawPixel(50,40, SSD1306_COLOR_WHITE);
  262. SSD1306_Putc('X',&Font_7x10,SSD1306_COLOR_WHITE);
  263. SSD1306_Puts(" THOMAS WAS\nHERE", &Font_7x10,SSD1306_COLOR_WHITE);
  264. SSD1306_UpdateScreen();
  265. return ret;
  266. }
  267. void i2c_master_init() {
  268. int i2c_master_port = I2C_MASTER_NUM;
  269. i2c_config_t conf;
  270. conf.mode = I2C_MODE_MASTER;
  271. conf.sda_io_num = I2C_SDA_PIN; // Data pin
  272. conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
  273. conf.scl_io_num = I2C_CLK_PIN; // Clock pin
  274. conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
  275. conf.master.clk_speed = 100000;
  276. i2c_param_config(i2c_master_port, &conf);
  277. i2c_driver_install(i2c_master_port,
  278. conf.mode,
  279. I2C_MASTER_RX_BUF_DISABLE,
  280. I2C_MASTER_TX_BUF_DISABLE,
  281. 0);
  282. }
  283. #endif