diff --git a/Inc/image.h b/Inc/image.h new file mode 100644 index 0000000..c759e61 --- /dev/null +++ b/Inc/image.h @@ -0,0 +1,3 @@ +#include "stm32f4xx_hal.h" + +extern uint8_t image[1024]; \ No newline at end of file diff --git a/Inc/ssd1306.h b/Inc/ssd1306.h index 90b2af5..e0d3717 100644 --- a/Inc/ssd1306.h +++ b/Inc/ssd1306.h @@ -1,6 +1,8 @@ #include +#include #include "stm32f4xx_hal.h" #include "fonts.h" +#include "image.h" #ifndef ssd1306 #define ssd1306 @@ -86,8 +88,10 @@ char ssd1306_WriteString(char* str, FontDef Font, SSD1306_COLOR color); void ssd1306_SetCursor(uint8_t x, uint8_t y); void ssd1306_WriteCommand(uint8_t command); -void ssd1306_Scroll(void); +//void ssd1306_ScrollUp(unsigned int pixels, unsigned int delay); +void ssd1306_ScrollUp(unsigned int pixels, unsigned int delay, UART_HandleTypeDef uart); void startscrollright(uint8_t start, uint8_t stop); void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1); +void ssd1306_LoadImage(void); #endif diff --git a/Makefile b/Makefile index bbe4bca..d3ddc67 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ BUILD_DIR = build ###################################### C_SOURCES = \ Src/main.c \ + Src/image.c \ Src/cube.c \ Src/starfield.c \ Src/ssd1306.c \ diff --git a/Src/image.c b/Src/image.c new file mode 100644 index 0000000..0fa06ad --- /dev/null +++ b/Src/image.c @@ -0,0 +1,108 @@ +#include "image.h" + +uint8_t image[1024] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0xe0, 0x20, 0x20, 0x00, + 0xe0, 0xe0, 0x40, 0x40, 0x40, 0xe0, 0xf8, 0xf8, 0xf8, 0xf8, + 0xf8, 0x78, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, + 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x78, 0xf8, 0xf8, 0xf8, + 0xf8, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0xf8, 0xf8, 0x38, + 0x38, 0x38, 0x78, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, + 0xf8, 0xf8, 0xf8, 0xf8, 0x38, 0x38, 0x38, 0xf8, 0xf8, 0xf8, + 0xf8, 0x00, 0x00, 0x00, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, + 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x78, 0x38, 0x38, 0x38, 0xf8, + 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, + 0x00, 0x00, 0x00, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, + 0xf8, 0xf8, 0xf8, 0xf8, 0x78, 0x38, 0x38, 0x38, 0xf8, 0xf8, + 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x03, + 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, + 0x00, 0x00, 0xfc, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, + 0xfe, 0xfc, 0xe0, 0xc0, 0xc0, 0xc1, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0xe1, 0xc3, 0x87, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0xff, + 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x3f, 0x0f, 0x03, 0x00, 0xc0, 0xe0, 0x80, 0x01, 0x07, 0x1f, + 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x0f, 0x03, 0x00, 0xc0, 0xe0, 0x80, 0x01, 0x07, 0x1f, 0x7f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x7f, 0x7f, 0x7f, 0x77, 0x73, 0x73, 0x73, 0x73, 0x73, 0x73, + 0x03, 0x03, 0x03, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe1, 0xc3, 0x87, 0x07, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x07, 0x01, 0x80, 0x80, + 0x98, 0x9e, 0x9f, 0x9f, 0x9f, 0x9c, 0x80, 0x80, 0x00, 0x03, + 0x1f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x1f, 0x07, 0x01, 0x80, 0x80, 0x88, + 0x9e, 0x9f, 0x9f, 0x9f, 0x9c, 0x80, 0x80, 0x00, 0x03, 0x0f, + 0x3f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xfc, + 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, + 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xfc, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xfc, + 0xfc, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xfc, 0xfc, 0xfc, 0xfc, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xfc, 0xfc, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0xff, 0xfd, 0xfc, 0xfc, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0xfc, 0xfc, 0xff, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, +}; + diff --git a/Src/main.c b/Src/main.c index 38532c3..0e7bdd1 100644 --- a/Src/main.c +++ b/Src/main.c @@ -94,6 +94,9 @@ int main(void) cube_Init(); //DHT22_Init(); HAL_UART_Receive_IT(&huart1, (uint8_t*) &UART1_Data, 1); + //drawLine(0,2, 150, 2); + //drawLine(0,4, 150, 4); + ssd1306_LoadImage(); /* USER CODE END 2 */ /* Infinite loop */ @@ -103,33 +106,23 @@ int main(void) /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - ssd1306_Fill(Black); - - /* + //ssd1306_Fill(Black); +/* int x, msg; - HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6); //Toggle the state of pin PC9 - //DHT22_Read(htim6); - - //startscrollright(0x00, 0x0F); - - for(int times = 0; times < 12; times++) { - ssd1306_Scroll(); - ssd1306_UpdateScreen(); - HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_7); //Toggle the state of pin PC9 - } + //ssd1306_ScrollUp(64, 0); + ssd1306_ScrollUp(1, 50, huart1); x = rand() % 60 + 1; msg = rand() % 2 + 1; ssd1306_SetCursor(x, 53); ssd1306_WriteString((msg == 1) ? "GORDOS" : "LOL", Font_7x10, White); + + //starfield_Update(); + //cube_Update(60); */ - - starfield_Update(); - cube_Update(60); - ssd1306_UpdateScreen(); - HAL_Delay(25); + //HAL_Delay(25); } /* USER CODE END 3 */ } diff --git a/Src/ssd1306.c b/Src/ssd1306.c index 246bb37..4ceaea6 100644 --- a/Src/ssd1306.c +++ b/Src/ssd1306.c @@ -57,21 +57,36 @@ void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1) } } +void ssd1306_LoadImage(void) { + static uint32_t end_addr = SSD1306_WIDTH * 8; + + for(uint32_t addr = 0; addr < end_addr; addr++) { + SSD1306_Buffer[addr] = image[addr]; + } +} + /** * [ssd1306_ScrollUp scrolls the whole LCD buffer up] * @param pixels [How many pixels to scroll up] * @param delay [Delay between refresh] */ -void ssd1306_ScrollUp(unsigned int pixels, unsigned int delay) +//void ssd1306_ScrollUp(unsigned int pixels, unsigned int delay, ) +void ssd1306_ScrollUp(unsigned int pixels, unsigned int delay, UART_HandleTypeDef uart) { static uint32_t end_addr = SSD1306_WIDTH * 8; char lost_bit = 0; + //char buffer[64]; for(uint8_t times = 0; times < pixels; times++) { for(uint32_t addr = 0; addr < end_addr; addr++) { + //char binary[33]; + //itoa(SSD1306_Buffer[addr], binary, 2); + //sprintf(buffer, "addr: %x : %s\n\r", addr, binary); + //HAL_UART_Transmit(&uart, (uint8_t*)buffer, strlen(buffer), 0xFFFF); + // In the first bank we dont need to keep the lost bit - if (addr > 0x79) { + if (addr > 0x7f) { lost_bit = SSD1306_Buffer[addr] & 0x01; } @@ -79,7 +94,7 @@ void ssd1306_ScrollUp(unsigned int pixels, unsigned int delay) SSD1306_Buffer[addr] >>= 1; // In the first bank we dont need to do this - if (addr > 0x79) { + if (addr > 0x7f) { // Move the saved bit from the LSB to the MSB lost_bit <<= 7; // Add the saved bit to the bank above it diff --git a/gnaa.png b/gnaa.png new file mode 100644 index 0000000..b8d822f Binary files /dev/null and b/gnaa.png differ diff --git a/image.bmp b/image.bmp new file mode 100644 index 0000000..eca37d6 Binary files /dev/null and b/image.bmp differ diff --git a/image.py b/image.py new file mode 100755 index 0000000..660c37b --- /dev/null +++ b/image.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 + +# 128x64 +# convert gnaa.png +dither -monochrome -colors 2 image.bmp + + +from PIL import Image + +invert = 0 + +def set_bit(value, bit): + return value | (1<