oled_common.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "stm32g4xx_hal.h"
  2. #include "oled_common.h"
  3. #include "i2c_bridge.h"
  4. #include "logo_grayscale.h"
  5. extern "C" {
  6. #include "OLED_SSD1327.h"
  7. #include "GFX_SSD1327.h"
  8. }
  9. I2C_HandleTypeDef *i2c_bridge;
  10. //
  11. void init_oled(void)
  12. {
  13. init_gpio_oled();
  14. i2c_bridge_init();
  15. i2c_bridge = i2c_get_bridge();
  16. SSD1327_I2cInit(i2c_bridge);
  17. SSD1327_Clear(BLACK);
  18. //GFX_Image(15, 0, (uint8_t*)logo_grayscale, 96, 96);
  19. SSD1327_Display();
  20. test_oled();
  21. }
  22. //
  23. void test_oled(void)
  24. {
  25. //SSD1327_DrawPixel(int16_t x, int16_t y, uint8_t Color);
  26. for (int i = 0; i < 16; i++)
  27. {
  28. SSD1327_DrawPixel(10, 20 + i, i);
  29. }
  30. SSD1327_DrawPixel(20, 20, 15);
  31. SSD1327_DrawPixel(30, 20, 15);
  32. SSD1327_DrawPixel(40, 20, 5);
  33. SSD1327_Display();
  34. }
  35. //
  36. void init_gpio_oled(void)
  37. {
  38. GPIO_InitTypeDef GPIO_InitStruct = {0};
  39. __HAL_RCC_GPIOA_CLK_ENABLE();
  40. GPIO_InitStruct.Pin = GPIO_PIN_5;
  41. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  42. GPIO_InitStruct.Pull = GPIO_NOPULL;
  43. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  44. HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
  45. #if 0
  46. /*Configure GPIO pin Output Level */
  47. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_RESET);
  48. /*Configure GPIO pin : PC13 */
  49. GPIO_InitStruct.Pin = GPIO_PIN_13;
  50. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  51. GPIO_InitStruct.Pull = GPIO_NOPULL;
  52. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  53. /*Configure GPIO pin : PC6 */
  54. GPIO_InitStruct.Pin = GPIO_PIN_6;
  55. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  56. GPIO_InitStruct.Pull = GPIO_NOPULL;
  57. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  58. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  59. #endif
  60. }