oled_common.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. //GFX_Image(15, 0, (uint8_t*)logo_grayscale, 96, 96);
  20. SSD1327_Display();
  21. test_oled();
  22. }
  23. //
  24. void test_oled(void)
  25. {
  26. //SSD1327_DrawPixel(int16_t x, int16_t y, uint8_t Color);
  27. #if 0
  28. for (int i = 0; i < 16; i++)
  29. {
  30. SSD1327_DrawPixel(10, 20 + i, i);
  31. }
  32. SSD1327_DrawPixel(20, 20, 15);
  33. SSD1327_DrawPixel(30, 20, 15);
  34. SSD1327_DrawPixel(40, 20, 5);
  35. #endif
  36. //void GFX_DrawLine(int x_start, int y_start, int x_end, int y_end, uint8_t color);
  37. // Верхняя
  38. GFX_DrawLine(0, 0, 127, 0, 15);
  39. // Левая
  40. GFX_DrawLine(0, 0, 0, 127, 15);
  41. // Правая
  42. GFX_DrawLine(127, 0, 127, 127, 15);
  43. // Нижняя
  44. GFX_DrawLine(0, 127, 127, 127, 15);
  45. GFX_SetFont(font_8x5);
  46. GFX_SetFontSize(2);
  47. //GFX_DrawChar(50, 50, 'F', 15, 0);
  48. GFX_DrawString(10, 100, "Hello!!!", 15, 0);
  49. #if 0
  50. uint8_t GFX_GetFontHeight(void);
  51. uint8_t GFX_GetFontWidth(void);
  52. uint8_t GFX_GetFontSize(void);
  53. void GFX_DrawChar(int x, int y, char chr, uint8_t color, uint8_t background);
  54. void GFX_DrawString(int x, int y, char* str, uint8_t color, uint8_t background);
  55. #endif
  56. SSD1327_Display();
  57. }
  58. //
  59. void init_gpio_oled(void)
  60. {
  61. GPIO_InitTypeDef GPIO_InitStruct = {0};
  62. __HAL_RCC_GPIOA_CLK_ENABLE();
  63. GPIO_InitStruct.Pin = GPIO_PIN_5;
  64. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  65. GPIO_InitStruct.Pull = GPIO_NOPULL;
  66. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  67. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
  68. #if 0
  69. /*Configure GPIO pin Output Level */
  70. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_RESET);
  71. /*Configure GPIO pin : PC13 */
  72. GPIO_InitStruct.Pin = GPIO_PIN_13;
  73. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  74. GPIO_InitStruct.Pull = GPIO_NOPULL;
  75. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  76. /*Configure GPIO pin : PC6 */
  77. GPIO_InitStruct.Pin = GPIO_PIN_6;
  78. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  79. GPIO_InitStruct.Pull = GPIO_NOPULL;
  80. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  81. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  82. #endif
  83. }