| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #include "stm32g4xx_hal.h"
- #include "oled_common.h"
- #include "config.h"
- #include "i2c_bridge.h"
- #include "spi_bridge.h"
- #include "logo_grayscale.h"
- #include "fonts.h"
- #include "SSD1327.h"
- extern "C" {
- #include "OLED_SSD1327.h"
- #include "GFX_SSD1327.h"
- }
-
- #ifdef I2C_BRIDGE
- I2C_HandleTypeDef *i2c_bridge;
- #elif SPI_BRIDGE
- SPI_HandleTypeDef *spi_bridge;
- //DMA_HandleTypeDef hdma_spi_bridge;
- #endif
- //
- void init_oled(void)
- {
- init_gpio_oled();
-
- #ifdef I2C_BRIDGE
- i2c_bridge_init();
- i2c_bridge = i2c_get_bridge();
- SSD1327_I2cInit(i2c_bridge);
-
- #elif SPI_BRIDGE
- spi_bridge_init();
- #endif
-
- //return;
-
-
- SSD1327_Clear(BLACK);
-
- #if 0
- ssd1327.clearBuffer();
- ssd1327.drawString(16, 16, (char*)"Hello", 0xF, 32);
- ssd1327.drawString(16, 48, (char*)"World!", 0xF, 32);
- ssd1327.writeFullBuffer();
- #endif
-
- #if 0
- SSD1327_DrawPixel(20, 20, 15);
- SSD1327_DrawPixel(21, 20, 15);
- SSD1327_DrawPixel(22, 20, 15);
-
- SSD1327_DrawPixel(20, 21, 15);
- SSD1327_DrawPixel(21, 21, 15);
- SSD1327_DrawPixel(22, 21, 15);
-
- SSD1327_DrawPixel(20, 22, 15);
- SSD1327_DrawPixel(21, 22, 15);
- SSD1327_DrawPixel(22, 22, 15);
-
- SSD1327_DrawPixel(20, 23, 15);
- SSD1327_DrawPixel(21, 23, 15);
- SSD1327_DrawPixel(22, 23, 15);
- #endif
-
- //GFX_Image(15, 0, (uint8_t*)logo_grayscale, 96, 96);
-
- SSD1327_Display();
-
-
-
- //while (1) {}
- }
- //
- void test_oled(void)
- {
- #if 0
- for (int i = 0; i < 16; i++) {
- SSD1327_DrawPixel(10, 20 + i, i);
- }
-
- SSD1327_DrawPixel(20, 20, 15);
- SSD1327_DrawPixel(30, 20, 15);
- SSD1327_DrawPixel(40, 20, 5);
- #endif
- //void GFX_DrawLine(int x_start, int y_start, int x_end, int y_end, uint8_t color);
- // Верхняя
- GFX_DrawLine(0, 0, 127, 0, 15);
-
- // Левая
- GFX_DrawLine(0, 0, 0, 127, 15);
-
- // Правая
- GFX_DrawLine(127, 0, 127, 127, 15);
-
- // Нижняя
- GFX_DrawLine(0, 127, 127, 127, 15);
-
- GFX_SetFont(font_8x5);
-
- GFX_SetFontSize(1);
- GFX_DrawString(4, 10, (char*)"BbAa12345", 15, 0);
-
- GFX_SetFontSize(2);
- GFX_DrawString(4, 30, (char*)"BbAa12345", 15, 0);
-
- GFX_SetFontSize(3);
- GFX_DrawString(4, 60, (char*)"BbAa12345", 15, 0);
-
- //GFX_DrawChar(50, 50, 'F', 15, 0);
- //GFX_DrawString(10, 100, "Hello!!!", 15, 0);
-
-
- #if 0
- uint8_t GFX_GetFontHeight(void);
- uint8_t GFX_GetFontWidth(void);
- uint8_t GFX_GetFontSize(void);
- void GFX_DrawChar(int x, int y, char chr, uint8_t color, uint8_t background);
- void GFX_DrawString(int x, int y, char* str, uint8_t color, uint8_t background);
- #endif
- SSD1327_Display();
-
- }
- // oled_draw_rec(3, 5, 123, 22, 15);
- void oled_draw_rec(int x_start, int y_start, int x_end, int y_end, uint8_t color)
- {
- for (int i = 0; i < y_end; i++) {
- GFX_DrawLine(x_start, y_start + i, x_end, y_start + i, color);
- }
- GFX_DrawLine(x_start, y_end, x_end, y_end, color);
- }
- #define STR_H 20
- #define STR_Y_S 36
- #define STR_FRAME_START_Y 8
- #define STR_X_S 4
- #define STR_X_E 123
- //
- void oled_draw_string_frame(uint8_t str_num)
- {
- for (int i = 0; i < 2; i++) {
- // нижняя
- 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);
-
- // верхняя
- 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);
- }
-
- // Правая
- 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);
-
- // Левая
- 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);
- }
- //
- void init_gpio_oled(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
-
- __HAL_RCC_GPIOA_CLK_ENABLE();
-
- GPIO_InitStruct.Pin = GPIO_PIN_5;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
- }
|