oled_common.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. extern "C" {
  7. #include "OLED_SSD1327.h"
  8. #include "GFX_SSD1327.h"
  9. }
  10. I2C_HandleTypeDef *i2c_bridge;
  11. //
  12. void init_oled(void)
  13. {
  14. init_gpio_oled();
  15. i2c_bridge_init();
  16. i2c_bridge = i2c_get_bridge();
  17. SSD1327_I2cInit(i2c_bridge);
  18. SSD1327_Clear(BLACK);
  19. /*
  20. SSD1327_DrawPixel(20, 20, 15);
  21. SSD1327_DrawPixel(21, 20, 15);
  22. SSD1327_DrawPixel(22, 20, 15);
  23. SSD1327_DrawPixel(20, 21, 15);
  24. SSD1327_DrawPixel(20, 22, 15);
  25. SSD1327_DrawPixel(22, 21, 15);
  26. */
  27. //GFX_Image(15, 0, (uint8_t*)logo_grayscale, 96, 96);
  28. SSD1327_Display();
  29. //while (1) {}
  30. }
  31. //
  32. void test_oled(void)
  33. {
  34. #if 0
  35. for (int i = 0; i < 16; i++) {
  36. SSD1327_DrawPixel(10, 20 + i, i);
  37. }
  38. SSD1327_DrawPixel(20, 20, 15);
  39. SSD1327_DrawPixel(30, 20, 15);
  40. SSD1327_DrawPixel(40, 20, 5);
  41. #endif
  42. //void GFX_DrawLine(int x_start, int y_start, int x_end, int y_end, uint8_t color);
  43. // Верхняя
  44. GFX_DrawLine(0, 0, 127, 0, 15);
  45. // Левая
  46. GFX_DrawLine(0, 0, 0, 127, 15);
  47. // Правая
  48. GFX_DrawLine(127, 0, 127, 127, 15);
  49. // Нижняя
  50. GFX_DrawLine(0, 127, 127, 127, 15);
  51. GFX_SetFont(font_8x5);
  52. GFX_SetFontSize(1);
  53. GFX_DrawString(4, 10, (char*)"BbAa12345", 15, 0);
  54. GFX_SetFontSize(2);
  55. GFX_DrawString(4, 30, (char*)"BbAa12345", 15, 0);
  56. GFX_SetFontSize(3);
  57. GFX_DrawString(4, 60, (char*)"BbAa12345", 15, 0);
  58. //GFX_DrawChar(50, 50, 'F', 15, 0);
  59. //GFX_DrawString(10, 100, "Hello!!!", 15, 0);
  60. #if 0
  61. uint8_t GFX_GetFontHeight(void);
  62. uint8_t GFX_GetFontWidth(void);
  63. uint8_t GFX_GetFontSize(void);
  64. void GFX_DrawChar(int x, int y, char chr, uint8_t color, uint8_t background);
  65. void GFX_DrawString(int x, int y, char* str, uint8_t color, uint8_t background);
  66. #endif
  67. SSD1327_Display();
  68. }
  69. // oled_draw_rec(3, 5, 123, 22, 15);
  70. void oled_draw_rec(int x_start, int y_start, int x_end, int y_end, uint8_t color)
  71. {
  72. for (int i = 0; i < y_end; i++) {
  73. GFX_DrawLine(x_start, y_start + i, x_end, y_start + i, color);
  74. }
  75. //GFX_DrawLine(x_start, y_start, x_end, y_start, color);
  76. GFX_DrawLine(x_start, y_end, x_end, y_end, color);
  77. //GFX_DrawLine(x_start, y_start, x_start, y_end, color);
  78. //GFX_DrawLine(x_end, y_start, x_end, y_end, color);
  79. }
  80. //
  81. void init_gpio_oled(void)
  82. {
  83. GPIO_InitTypeDef GPIO_InitStruct = {0};
  84. __HAL_RCC_GPIOA_CLK_ENABLE();
  85. GPIO_InitStruct.Pin = GPIO_PIN_5;
  86. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  87. GPIO_InitStruct.Pull = GPIO_NOPULL;
  88. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  89. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
  90. }