Add script to convert image
This commit is contained in:
parent
07594d02f0
commit
e1f05a916a
|
@ -0,0 +1,3 @@
|
|||
#include "stm32f4xx_hal.h"
|
||||
|
||||
extern uint8_t image[1024];
|
|
@ -1,6 +1,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#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
|
||||
|
|
1
Makefile
1
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 \
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
27
Src/main.c
27
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 */
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<<bit)
|
||||
|
||||
def clear_bit(value, bit):
|
||||
return value & ~(1<<bit)
|
||||
|
||||
im = Image.open("image.bmp")
|
||||
buffer = []
|
||||
|
||||
for bank in range(0, 8):
|
||||
for x in range(0, 128):
|
||||
bits = ""
|
||||
value = 0
|
||||
if (invert == 1):
|
||||
value = 255
|
||||
c = 7
|
||||
for y in range(bank * 7 + 7, bank * 7 - 1, -1):
|
||||
b = im.getpixel((x,y))
|
||||
|
||||
if (b == 1 or b == 255):
|
||||
value = set_bit(value, c)
|
||||
if (invert == 1):
|
||||
value = clear_bit(value, c)
|
||||
c = c - 1
|
||||
buffer.append(value)
|
||||
|
||||
|
||||
c = 0
|
||||
bytes_per_line = 10
|
||||
|
||||
print('#include "image.h"')
|
||||
print()
|
||||
print("uint8_t image[1024] = {")
|
||||
|
||||
for v in buffer:
|
||||
if c == 0:
|
||||
print(" ", end='')
|
||||
|
||||
print(format(v, '#04x') + ", ", end='')
|
||||
c = c + 1
|
||||
if (c == bytes_per_line):
|
||||
print()
|
||||
c = 0
|
||||
|
||||
if (c <= bytes_per_line):
|
||||
print()
|
||||
print("};")
|
||||
print()
|
Loading…
Reference in New Issue