oled_common.cpp 4.1 KB

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