De decomposition

This commit is contained in:
Stanislav N Mikhailov
2025-01-03 11:56:13 +03:00
parent e03683f9da
commit 4c4a500f6d
15 changed files with 60 additions and 70 deletions
+33 -2
View File
@@ -1,5 +1,36 @@
#include "DrawBezier.h"
#include "SetPixel.h"
#include "BackBuffer.h"
#include <math.h>
uint16_t frame_buffer[WIDTH * HEIGHT]; // Буфер для экрана
// Установка пикселя в буфере (с проверкой границ)
unsigned short reverse(unsigned short x)
{
x = (x & 0xFF) << 8 | (x & 0xFF00) >> 8;
return x;
}
void set_pixel(uint16_t x, uint16_t y, uint16_t color) {
if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT) {
frame_buffer[y * WIDTH + x] = color;
}
}
void generate_sine_wave_points(uint16_t num_points, int amplitude, float frequency, int offset_x, int offset_y, float phase_shift) {
if (num_points == 0) {
return;
}
float step = (2.0f * M_PI * frequency) / (num_points - 1);
float x_step = (float)WIDTH / (num_points - 1);
for (size_t i = 0; i < num_points; i++) {
int x = offset_x + (int)(i * x_step);
int y = offset_y + (int)(amplitude * sinf(i * step + phase_shift)); // Добавлен сдвиг фазы
set_pixel(x, y, reverse(0b0000011111100000));
}
}
// Функция для вычисления базисного полинома Бернштейна
float bernstein(int i, int n, float t) {
// Вычисление биномиального коэффициента C(n, i)
+20
View File
@@ -0,0 +1,20 @@
#ifndef __BACKBUFFER_H__
#define __BACKBUFFER_H__
#include <stdint.h>
#include <stddef.h>
#define WIDTH 320
#define HEIGHT 240
#define COLOR_BLACK 0x0000
#define COLOR_WHITE 0xFFFF
extern uint16_t frame_buffer[WIDTH * HEIGHT];
float bernstein(int i, int n, float t);
void draw_bezier(const int *points_x, const int *points_y, size_t num_points, uint16_t color);
unsigned short reverse(unsigned short x);
void set_pixel(uint16_t x, uint16_t y, uint16_t color);
void generate_sine_wave_points(uint16_t num_points, int amplitude, float frequency, int offset_x, int offset_y, float phase_shift);
#endif // __BACKBUFFER_H__
+1 -1
View File
@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
add_executable(${PROJECT_NAME} main.c Thread.c DrawBezier.c font_data.c Reverse.c SineWave.c SetPixel.c)
add_executable(${PROJECT_NAME} main.c Thread.c font_data.c BackBuffer.c)
target_link_libraries(${PROJECT_NAME}
pico_stdlib
-8
View File
@@ -1,8 +0,0 @@
#include <stdint.h>
#include <stddef.h>
#include <math.h>
#include "Thread.h"
float bernstein(int i, int n, float t);
void draw_bezier(const int *points_x, const int *points_y, size_t num_points, uint16_t color);
-5
View File
@@ -1,5 +0,0 @@
unsigned short reverse(unsigned short x)
{
x = (x & 0xFF) << 8 | (x & 0xFF00) >> 8;
return x;
}
-4
View File
@@ -1,4 +0,0 @@
#ifndef REVERSE_H
#define REVERSE_H
unsigned short reverse(unsigned short x);
#endif
-8
View File
@@ -1,8 +0,0 @@
#include "SetPixel.h"
#include "Thread.h"
// Установка пикселя в буфере (с проверкой границ)
void set_pixel(uint16_t x, uint16_t y, uint16_t color) {
if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT) {
frame_buffer[y * WIDTH + x] = color;
}
}
-5
View File
@@ -1,5 +0,0 @@
#ifndef SET_PIXEL_H
#define SET_PIXEL_H
#include <stdint.h>
void set_pixel(uint16_t x, uint16_t y, uint16_t color);
#endif
-20
View File
@@ -1,20 +0,0 @@
#include "SineWave.h"
#include "font_data.h"
#include "Thread.h"
#include "Reverse.h"
#include "SetPixel.h"
#include <math.h>
void generate_sine_wave_points(size_t num_points, int amplitude, float frequency, int offset_x, int offset_y, float phase_shift) {
if (num_points == 0) {
return;
}
float step = (2.0f * M_PI * frequency) / (num_points - 1);
float x_step = (float)WIDTH / (num_points - 1);
for (size_t i = 0; i < num_points; i++) {
int x = offset_x + (int)(i * x_step);
int y = offset_y + (int)(amplitude * sinf(i * step + phase_shift)); // Добавлен сдвиг фазы
set_pixel(x, y, reverse(0b0000011111100000));
}
}
-4
View File
@@ -1,4 +0,0 @@
#ifdef SINE_WAVE_H
#define SINE_WAVE_H
void generate_sine_wave_points(size_t num_points, int amplitude, float frequency, int offset_x, int offset_y, float phase_shift);
#endif
+1 -1
View File
@@ -2,8 +2,8 @@
#include "pico/stdlib.h"
#include "hardware/spi.h"
#include "pico/multicore.h"
#include "BackBuffer.h"
uint16_t frame_buffer[WIDTH * HEIGHT]; // Буфер для экрана
//uint16_t frame_buffer1[WIDTH * HEIGHT]; // Буфер для экрана1
+1 -6
View File
@@ -11,13 +11,8 @@
#define PIN_RST 13
#define PIN_BL 12
#define WIDTH 320
#define HEIGHT 240
#define COLOR_BLACK 0x0000
#define COLOR_WHITE 0xFFFF
extern uint16_t frame_buffer[WIDTH * HEIGHT];
extern uint16_t frame_buffer1[WIDTH * HEIGHT];
void st7789_send_command(uint8_t cmd);
void st7789_send_data(uint8_t data);
+1 -2
View File
@@ -1,9 +1,8 @@
// Шрифт, сгенерированный из /home/smikhai/Repo/rp_pico_test/Font/font_grid_with_cyrillic.bmp
#include "font_data.h"
#include "Thread.h"
#include "SetPixel.h"
#include <stdbool.h>
#include "Reverse.h"
#include "BackBuffer.h"
const uint16_t image_linear_width = 704;
const uint8_t char_width = 22;
const uint8_t char_height = 22;
+2 -2
View File
@@ -2,9 +2,9 @@
#include "Thread.h"
#include "pico/multicore.h"
#include "pico/stdlib.h"
#include "DrawBezier.h"
#include "font_data.h"
#include "Reverse.h"
#include "BackBuffer.h"
int main() {
uint16_t red = 0;
uint16_t green = 0;
+1 -2
View File
@@ -1,5 +1,4 @@
#include <stdio.h>
void fillBufer (uint16_t* buffer,uint16_t color);
unsigned short reverse(unsigned short x);
void generate_sine_wave_points(size_t num_points, int amplitude, float frequency, int offset_x, int offset_y, float phase_shift);
//unsigned short reverse(unsigned short x);