oled_common.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #include "stm32g4xx_hal.h"
  2. #include "oled_common.h"
  3. #include "i2c_bridge.h"
  4. #include "logo_grayscale.h"
  5. #include "fonts.h"
  6. #include "SSD1327.h"
  7. extern "C" {
  8. #include "OLED_SSD1327.h"
  9. #include "GFX_SSD1327.h"
  10. }
  11. I2C_HandleTypeDef *i2c_bridge;
  12. //
  13. void init_oled(void)
  14. {
  15. init_gpio_oled();
  16. i2c_bridge_init();
  17. i2c_bridge = i2c_get_bridge();
  18. SSD1327_I2cInit(i2c_bridge);
  19. SSD1327_Clear(BLACK);
  20. #if 0
  21. ssd1327.clearBuffer();
  22. ssd1327.drawString(16, 16, (char*)"Hello", 0xF, 32);
  23. ssd1327.drawString(16, 48, (char*)"World!", 0xF, 32);
  24. ssd1327.writeFullBuffer();
  25. #endif
  26. #if 0
  27. SSD1327_DrawPixel(20, 20, 15);
  28. SSD1327_DrawPixel(21, 20, 15);
  29. SSD1327_DrawPixel(22, 20, 15);
  30. SSD1327_DrawPixel(20, 21, 15);
  31. SSD1327_DrawPixel(21, 21, 15);
  32. SSD1327_DrawPixel(22, 21, 15);
  33. SSD1327_DrawPixel(20, 22, 15);
  34. SSD1327_DrawPixel(21, 22, 15);
  35. SSD1327_DrawPixel(22, 22, 15);
  36. SSD1327_DrawPixel(20, 23, 15);
  37. SSD1327_DrawPixel(21, 23, 15);
  38. SSD1327_DrawPixel(22, 23, 15);
  39. #endif
  40. //GFX_Image(15, 0, (uint8_t*)logo_grayscale, 96, 96);
  41. SSD1327_Display();
  42. //while (1) {}
  43. }
  44. //
  45. void test_oled(void)
  46. {
  47. #if 0
  48. for (int i = 0; i < 16; i++) {
  49. SSD1327_DrawPixel(10, 20 + i, i);
  50. }
  51. SSD1327_DrawPixel(20, 20, 15);
  52. SSD1327_DrawPixel(30, 20, 15);
  53. SSD1327_DrawPixel(40, 20, 5);
  54. #endif
  55. //void GFX_DrawLine(int x_start, int y_start, int x_end, int y_end, uint8_t color);
  56. // Верхняя
  57. GFX_DrawLine(0, 0, 127, 0, 15);
  58. // Левая
  59. GFX_DrawLine(0, 0, 0, 127, 15);
  60. // Правая
  61. GFX_DrawLine(127, 0, 127, 127, 15);
  62. // Нижняя
  63. GFX_DrawLine(0, 127, 127, 127, 15);
  64. GFX_SetFont(font_8x5);
  65. GFX_SetFontSize(1);
  66. GFX_DrawString(4, 10, (char*)"BbAa12345", 15, 0);
  67. GFX_SetFontSize(2);
  68. GFX_DrawString(4, 30, (char*)"BbAa12345", 15, 0);
  69. GFX_SetFontSize(3);
  70. GFX_DrawString(4, 60, (char*)"BbAa12345", 15, 0);
  71. //GFX_DrawChar(50, 50, 'F', 15, 0);
  72. //GFX_DrawString(10, 100, "Hello!!!", 15, 0);
  73. #if 0
  74. uint8_t GFX_GetFontHeight(void);
  75. uint8_t GFX_GetFontWidth(void);
  76. uint8_t GFX_GetFontSize(void);
  77. void GFX_DrawChar(int x, int y, char chr, uint8_t color, uint8_t background);
  78. void GFX_DrawString(int x, int y, char* str, uint8_t color, uint8_t background);
  79. #endif
  80. SSD1327_Display();
  81. }
  82. // oled_draw_rec(3, 5, 123, 22, 15);
  83. void oled_draw_rec(int x_start, int y_start, int x_end, int y_end, uint8_t color)
  84. {
  85. for (int i = 0; i < y_end; i++) {
  86. GFX_DrawLine(x_start, y_start + i, x_end, y_start + i, color);
  87. }
  88. GFX_DrawLine(x_start, y_end, x_end, y_end, color);
  89. }
  90. #define STR_H 20
  91. #define STR_Y_S 36
  92. #define STR_FRAME_START_Y 8
  93. #define STR_X_S 4
  94. #define STR_X_E 123
  95. //
  96. void oled_draw_string_frame(uint8_t str_num)
  97. {
  98. for (int i = 0; i < 2; i++) {
  99. // нижняя
  100. GFX_DrawLine(STR_X_S, str_num*STR_H + STR_Y_S + i, STR_X_E, str_num*STR_H + STR_Y_S + i, 15);
  101. // верхняя
  102. GFX_DrawLine(STR_X_S, str_num*STR_H + STR_Y_S - STR_H + i, STR_X_E, str_num*STR_H + STR_Y_S - STR_H + i, 15);
  103. }
  104. // Правая
  105. GFX_DrawLine(STR_X_E, str_num*STR_H + STR_Y_S, STR_X_E, str_num*STR_H + STR_Y_S - STR_H, 15);
  106. // Левая
  107. GFX_DrawLine(STR_X_S, str_num*STR_H + STR_Y_S, STR_X_S, str_num*STR_H + STR_Y_S - STR_H, 15);
  108. }
  109. //
  110. void init_gpio_oled(void)
  111. {
  112. GPIO_InitTypeDef GPIO_InitStruct = {0};
  113. __HAL_RCC_GPIOA_CLK_ENABLE();
  114. GPIO_InitStruct.Pin = GPIO_PIN_5;
  115. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  116. GPIO_InitStruct.Pull = GPIO_NOPULL;
  117. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  118. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
  119. }