test in progress
This commit is contained in:
52
Core/ST7735/UI/monoimg.c
Normal file
52
Core/ST7735/UI/monoimg.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include <stdint.h>
|
||||
#include "monoimg.h"
|
||||
|
||||
#define max(a,b) ((a) >= (b) ? (a) : (b))
|
||||
#define min(a,b) ((a) <= (b) ? (a) : (b))
|
||||
|
||||
uint8_t mimg_get_pixel_unsafe(const uint8_t *img, uint8_t x, uint8_t y) {
|
||||
// MVLSB format
|
||||
uint8_t width = img[0] + 1;
|
||||
uint16_t index = (y >> 3) * width + x + 2;
|
||||
uint8_t offset = y & 0x07;
|
||||
uint8_t value = (img[index] >> offset) & 0x01;
|
||||
return value; // return 1 or 0
|
||||
}
|
||||
|
||||
uint8_t mimg_get_pixel(const uint8_t *img, uint16_t x, uint16_t y) {
|
||||
// MVLSB format
|
||||
uint8_t width = img[0] + 1;
|
||||
uint8_t height = img[1] + 1;
|
||||
if (x >= width || y >= height) {
|
||||
return 0;
|
||||
}
|
||||
return mimg_get_pixel_unsafe(img, (uint8_t)x, (uint8_t)y);
|
||||
}
|
||||
|
||||
void mimg_draw(mimg_FunctionSetPixel set_pixel, uint16_t x, uint16_t y, uint16_t color, const uint8_t *img, mimg_Area area) {
|
||||
uint8_t width_s1 = img[0]; // width - 1
|
||||
uint8_t height_s1 = img[1]; // height - 1
|
||||
uint8_t ix = min(area.x, width_s1);
|
||||
uint8_t iy = min(area.y, height_s1);
|
||||
uint8_t iw = min(area.w, width_s1 - ix + 1);
|
||||
uint8_t ih = min(area.h, height_s1 - iy + 1);
|
||||
uint8_t off_x, off_y;
|
||||
for (off_y = 0; off_y < ih; off_y ++) {
|
||||
for (off_x = 0; off_x < iw; off_x ++) {
|
||||
if (mimg_get_pixel_unsafe(img, ix + off_x, iy + off_y)) {
|
||||
set_pixel(x + off_x, y + off_y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mimg_Area mimg_get_tile_area(const uint8_t *img, uint8_t cols, uint8_t rows, uint8_t index) {
|
||||
uint8_t width = img[0] + 1;
|
||||
uint8_t height = img[1] + 1;
|
||||
mimg_Area area;
|
||||
area.w = width / cols;
|
||||
area.h = height / rows;
|
||||
area.y = (index / cols) * area.h;
|
||||
area.x = (index % cols) * area.w;
|
||||
return area;
|
||||
}
|
19
Core/ST7735/UI/monoimg.h
Normal file
19
Core/ST7735/UI/monoimg.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
typedef void (*mimg_FunctionSetPixel)(uint16_t x, uint16_t y, uint16_t color);
|
||||
typedef struct mimg_Area
|
||||
{
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t w;
|
||||
uint8_t h;
|
||||
} mimg_Area;
|
||||
|
||||
|
||||
/** get a pixel from img, return 1 or 0 */
|
||||
uint8_t mimg_get_pixel(const uint8_t *img, uint16_t x, uint16_t y);
|
||||
/** draw a part of img {ix, iy, iw, ih} , at (x, y) with color */
|
||||
void mimg_draw(mimg_FunctionSetPixel set_pixel, uint16_t x, uint16_t y, uint16_t color, const uint8_t *img, mimg_Area area);
|
||||
/** calc tile area */
|
||||
mimg_Area mimg_get_tile_area(const uint8_t *img, uint8_t cols, uint8_t rows, uint8_t index);
|
26
Core/ST7735/UI/ui.c
Normal file
26
Core/ST7735/UI/ui.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <stdint.h>
|
||||
#include "Images/digi18x32.h"
|
||||
#include "monoimg.h"
|
||||
#include "st7735.h"
|
||||
|
||||
void ui_text_number18x32(uint32_t num, uint16_t x, uint16_t y, uint16_t color) {
|
||||
uint32_t tmp = num;
|
||||
uint32_t div = 1;
|
||||
uint8_t num_count = 0;
|
||||
while (tmp > 0) {
|
||||
tmp = tmp / 10;
|
||||
num_count ++;
|
||||
div = div * 10;
|
||||
}
|
||||
div = div / 10;
|
||||
while (div > 0) {
|
||||
tmp = (num / div) % 10;
|
||||
printf("div: %d x: %d tmp: %d\n", div, x, tmp);
|
||||
mimg_Area area = mimg_get_tile_area(IMG_DIGI_18_32, 10, 1, tmp);
|
||||
mimg_draw(ST7735_DrawPixel, x, y, color, IMG_DIGI_18_32, area);
|
||||
x = x + 18;
|
||||
div = div / 10;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: 绘制文字的方法
|
4
Core/ST7735/UI/ui.h
Normal file
4
Core/ST7735/UI/ui.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
void ui_text_number18x32(uint32_t num, uint16_t x, uint16_t y, uint16_t color);
|
Reference in New Issue
Block a user