mirror of
https://github.com/stasenso/rp_pico_test.git
synced 2026-06-26 21:42:44 +03:00
RGBView
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
build/*
|
||||
.vscode/*
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.18.4)
|
||||
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
|
||||
|
||||
project(circle C CXX ASM)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
pico_sdk_init()
|
||||
|
||||
add_executable(${PROJECT_NAME} main.c Thread.c)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
pico_stdlib
|
||||
hardware_spi
|
||||
hardware_dma
|
||||
pico_multicore
|
||||
)
|
||||
|
||||
pico_add_extra_outputs(${PROJECT_NAME})
|
||||
@@ -0,0 +1,117 @@
|
||||
#include "Thread.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/spi.h"
|
||||
#include "pico/multicore.h"
|
||||
|
||||
uint16_t frame_buffer[WIDTH * HEIGHT]; // Буфер для экрана
|
||||
|
||||
//uint16_t frame_buffer1[WIDTH * HEIGHT]; // Буфер для экрана1
|
||||
|
||||
void coreEntry(){
|
||||
st7789_init(); // Initialize SPI and GPIO
|
||||
gpio_put(PIN_BL, 1); // Подсветка
|
||||
multicore_fifo_push_blocking(0); //Экран 0 свободен
|
||||
//multicore_fifo_push_blocking(1); //Экран 1 свободен
|
||||
|
||||
while (true)
|
||||
{
|
||||
uint32_t data = multicore_fifo_pop_blocking();
|
||||
if (data==0)
|
||||
{
|
||||
st7789_send_framebuffer(frame_buffer); //Рисую экран 0
|
||||
multicore_fifo_push_blocking(0); //Экран 0 свободен
|
||||
}
|
||||
/*else if (data==1)
|
||||
{
|
||||
st7789_send_framebuffer(frame_buffer1); // Рисую первый экран
|
||||
multicore_fifo_push_blocking(1); //Экран 1 свободен
|
||||
}*/
|
||||
else
|
||||
{
|
||||
multicore_reset_core1(); // Сброс и остановка ядра 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void st7789_init() {
|
||||
// Initialize SPI
|
||||
spi_init(SPI_PORT, 1000 * 100 * 625); // 62.5MHz
|
||||
gpio_set_function(PIN_MOSI, GPIO_FUNC_SPI);
|
||||
gpio_set_function(PIN_SCK, GPIO_FUNC_SPI);
|
||||
|
||||
// Initialize control pins
|
||||
gpio_init(PIN_CS);
|
||||
gpio_init(PIN_DC);
|
||||
gpio_init(PIN_RST);
|
||||
gpio_init(PIN_BL);
|
||||
gpio_set_dir(PIN_CS, GPIO_OUT);
|
||||
gpio_set_dir(PIN_DC, GPIO_OUT);
|
||||
gpio_set_dir(PIN_RST, GPIO_OUT);
|
||||
gpio_set_dir(PIN_BL, GPIO_OUT);
|
||||
|
||||
// Reset the display
|
||||
gpio_put(PIN_RST, 0);
|
||||
sleep_ms(50);
|
||||
gpio_put(PIN_RST, 1);
|
||||
sleep_ms(50);
|
||||
|
||||
// Initialize ST7789 commands
|
||||
st7789_send_command(0x01); // Software reset
|
||||
sleep_ms(150);
|
||||
st7789_send_command(0x11); // Exit sleep mode
|
||||
sleep_ms(150);
|
||||
|
||||
st7789_send_command(0x36); // Memory data access control
|
||||
st7789_send_data(0x20); // RGB
|
||||
//st7789_send_data(0b00101000); // BGR
|
||||
|
||||
st7789_send_command(0x3A); // Interface pixel format
|
||||
st7789_send_data(0b01010101); // 16-bit/pixel
|
||||
|
||||
st7789_send_command(0x21); //INVON (21h): Display Inversion On
|
||||
st7789_send_command(0x29); // Display ON
|
||||
}
|
||||
|
||||
void st7789_send_command(uint8_t cmd) {
|
||||
gpio_put(PIN_DC, 0);
|
||||
gpio_put(PIN_CS, 0);
|
||||
spi_write_blocking(SPI_PORT, &cmd, 1);
|
||||
gpio_put(PIN_CS, 1);
|
||||
}
|
||||
|
||||
void st7789_send_data(uint8_t data) {
|
||||
gpio_put(PIN_DC, 1);
|
||||
gpio_put(PIN_CS, 0);
|
||||
spi_write_blocking(SPI_PORT, &data, 1);
|
||||
gpio_put(PIN_CS, 1);
|
||||
}
|
||||
|
||||
void st7789_send_framebuffer(uint16_t *buffer) {
|
||||
// Установить область для записи на весь экран
|
||||
st7789_send_command(0x2A); // Column address set
|
||||
st7789_send_data(0x00);
|
||||
st7789_send_data(0x00); // X-start = 0
|
||||
st7789_send_data((WIDTH - 1) >> 8);
|
||||
st7789_send_data((WIDTH - 1) & 0xFF); // X-end = WIDTH-1
|
||||
|
||||
st7789_send_command(0x2B); // Row address set
|
||||
st7789_send_data(0x00);
|
||||
st7789_send_data(0x00); // Y-start = 0
|
||||
st7789_send_data((HEIGHT - 1) >> 8);
|
||||
st7789_send_data((HEIGHT - 1) & 0xFF); // Y-end = HEIGHT-1
|
||||
|
||||
// Команда записи данных в память дисплея
|
||||
st7789_send_command(0x2C); // Memory write
|
||||
|
||||
// Передача буфера на дисплей
|
||||
gpio_put(PIN_DC, 1); // Режим данных
|
||||
gpio_put(PIN_CS, 0); // Выбор устройства
|
||||
|
||||
// Отправка буфера по SPI
|
||||
spi_write_blocking(SPI_PORT, (uint8_t *)buffer, WIDTH * HEIGHT * 2);
|
||||
|
||||
gpio_put(PIN_CS, 1); // Завершить передачу
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#define SPI_PORT spi0
|
||||
#define PIN_MISO -1
|
||||
#define PIN_MOSI 19
|
||||
#define PIN_SCK 18
|
||||
#define PIN_CS 17
|
||||
#define PIN_DC 22
|
||||
#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);
|
||||
void st7789_send_framebuffer(uint16_t *buffer);
|
||||
void coreEntry();
|
||||
void st7789_init();
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "main.h"
|
||||
#include "Thread.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
int main() {
|
||||
uint16_t red = 0;
|
||||
uint16_t green = 0;
|
||||
uint16_t blue = 0;
|
||||
uint16_t summcolor=0;
|
||||
uint32_t data;
|
||||
stdio_init_all();
|
||||
multicore_launch_core1(coreEntry); //Запускаю в ядре 1 процесс вывода на экран
|
||||
|
||||
while (red<32)
|
||||
{
|
||||
//uint8_t red_value = (pixel & red_mask) >> 11;
|
||||
//uint8_t green_value = (pixel & green_mask) >> 5;
|
||||
//uint8_t blue_value = (pixel & blue_mask);
|
||||
data = multicore_fifo_pop_blocking();
|
||||
fillBufer(frame_buffer,reverse(summcolor & 0b0000011111111111 | red << 11));//;
|
||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
||||
/*data = multicore_fifo_pop_blocking();
|
||||
fillBufer(frame_buffer1,0x0000);
|
||||
multicore_fifo_push_blocking(1); //Экран 0 нарисован*/
|
||||
red+=1;
|
||||
sleep_ms(20);
|
||||
}
|
||||
|
||||
while (green<64)
|
||||
{
|
||||
data = multicore_fifo_pop_blocking();
|
||||
fillBufer(frame_buffer,reverse(summcolor & 0b1111100000011111 | green << 5)); //
|
||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
||||
green+=1;
|
||||
sleep_ms(20);
|
||||
}
|
||||
|
||||
while (blue<32)
|
||||
{
|
||||
data = multicore_fifo_pop_blocking();
|
||||
fillBufer(frame_buffer,reverse(summcolor & 0b1111111111100000 | blue)); //
|
||||
multicore_fifo_push_blocking(0); //Экран 0 нарисован
|
||||
blue+=1;
|
||||
sleep_ms(20);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
tight_loop_contents();
|
||||
}
|
||||
}
|
||||
|
||||
void fillBufer (uint16_t* buffer,uint16_t color){
|
||||
for (uint16_t y = 0; y < HEIGHT; y++)
|
||||
{
|
||||
for (uint16_t x = 0; x < WIDTH; x++)
|
||||
{
|
||||
buffer[y*WIDTH+x]=color;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unsigned short reverse(unsigned short x)
|
||||
{
|
||||
x = (x & 0xFF) << 8 | (x & 0xFF00) >> 8;
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#include <stdio.h>
|
||||
void fillBufer (uint16_t* buffer,uint16_t color);
|
||||
unsigned short reverse(unsigned short x);
|
||||
@@ -0,0 +1,44 @@
|
||||
<mxfile host="Electron" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.7.17 Chrome/128.0.6613.36 Electron/32.0.1 Safari/537.36" version="24.7.17">
|
||||
<diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">
|
||||
<mxGraphModel dx="2074" dy="1203" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="WIyWlLk6GJQsqaUBKTNV-0" />
|
||||
<mxCell id="WIyWlLk6GJQsqaUBKTNV-1" parent="WIyWlLk6GJQsqaUBKTNV-0" />
|
||||
<mxCell id="btgQu8iJuiN861W0JhuT-10" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="btgQu8iJuiN861W0JhuT-0" target="btgQu8iJuiN861W0JhuT-7">
|
||||
<mxGeometry relative="1" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="btgQu8iJuiN861W0JhuT-0" value="Вход" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
|
||||
<mxGeometry x="354" y="40" width="66" height="30" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="btgQu8iJuiN861W0JhuT-12" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="btgQu8iJuiN861W0JhuT-7" target="btgQu8iJuiN861W0JhuT-16">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="387" y="250" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="btgQu8iJuiN861W0JhuT-7" value="Инициализирую экран&nbsp;" style="shape=process;whiteSpace=wrap;html=1;backgroundOutline=1;rounded=0;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
|
||||
<mxGeometry x="327" y="120" width="120" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="btgQu8iJuiN861W0JhuT-14" value="<div><br></div><div><br></div>" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="btgQu8iJuiN861W0JhuT-16" target="btgQu8iJuiN861W0JhuT-13">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="387" y="330" as="sourcePoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="btgQu8iJuiN861W0JhuT-15" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;" edge="1" parent="WIyWlLk6GJQsqaUBKTNV-1" source="btgQu8iJuiN861W0JhuT-13">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="387" y="220" as="targetPoint" />
|
||||
<Array as="points">
|
||||
<mxPoint x="200" y="450" />
|
||||
<mxPoint x="200" y="220" />
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="btgQu8iJuiN861W0JhuT-13" value="Рисуем экран с полученным номером и освобождаем его передав через&nbsp;<div>multicore_fifo_push_blocking номер нарисованного экрана</div>" style="shape=process;whiteSpace=wrap;html=1;backgroundOutline=1;rounded=0;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
|
||||
<mxGeometry x="232" y="410" width="310" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="btgQu8iJuiN861W0JhuT-16" value="multicore_fifo_pop_blocking()" style="shape=process;whiteSpace=wrap;html=1;backgroundOutline=1;rounded=0;" vertex="1" parent="WIyWlLk6GJQsqaUBKTNV-1">
|
||||
<mxGeometry x="280.5" y="280" width="213" height="60" as="geometry" />
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
||||
Reference in New Issue
Block a user