oled_common.cpp 2.5 KB

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