it WORKS!!! les go it is wednesday my dudes
This commit is contained in:
parent
a729ede7e7
commit
2b7322f0ff
3 changed files with 8 additions and 43 deletions
|
@ -25,8 +25,8 @@ pico_sdk_init()
|
|||
|
||||
file(GLOB SOURCES "src/*.c")
|
||||
add_executable(dp ${SOURCES})
|
||||
pico_generate_pio_header(dp "${PROJECT_SOURCE_DIR}/src/st7789_lcd.pio")
|
||||
target_include_directories(dp PRIVATE "${PROJECT_SOURCE_DIR}/include")
|
||||
pico_generate_pio_header(pio_st7789_lcd ${CMAKE_CURRENT_LIST_DIR}/st7789_lcd.pio)
|
||||
|
||||
# Add pico_stdlib library which aggregates commonly used features
|
||||
target_link_libraries(dp pico_stdlib hardware_pio hardware_interp)
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
void init_display();
|
|
@ -13,7 +13,6 @@
|
|||
#include "hardware/interp.h"
|
||||
|
||||
#include "st7789_lcd.pio.h"
|
||||
#include "raspberry_256x256_rgb565.h"
|
||||
|
||||
// Tested with the parts that have the height of 240 and 320
|
||||
#define SCREEN_WIDTH 240
|
||||
|
@ -30,10 +29,6 @@
|
|||
|
||||
#define SERIAL_CLK_DIV 1.f
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
// Format: cmd length (including cmd byte), post delay in units of 5 ms, then cmd payload
|
||||
// Note the delays have been shortened a little
|
||||
static const uint8_t st7789_init_seq[] = {
|
||||
|
@ -43,7 +38,7 @@ static const uint8_t st7789_init_seq[] = {
|
|||
2, 0, 0x36, 0x00, // Set MADCTL: row then column, refresh is bottom to top ????
|
||||
5, 0, 0x2a, 0x00, 0x00, SCREEN_WIDTH >> 8, SCREEN_WIDTH & 0xff, // CASET: column addresses
|
||||
5, 0, 0x2b, 0x00, 0x00, SCREEN_HEIGHT >> 8, SCREEN_HEIGHT & 0xff, // RASET: row addresses
|
||||
1, 2, 0x21, // Inversion on, then 10 ms delay (supposedly a hack?)
|
||||
// 1, 2, 0x21, // Inversion on, then 10 ms delay (supposedly a hack?)
|
||||
1, 2, 0x13, // Normal display on, then 10 ms delay
|
||||
1, 2, 0x29, // Main screen turn on, then wait 500 ms
|
||||
0 // Terminate list
|
||||
|
@ -87,8 +82,11 @@ static inline void st7789_start_pixels(PIO pio, uint sm) {
|
|||
int main() {
|
||||
stdio_init_all();
|
||||
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
|
||||
PIO pio = pio0;
|
||||
uint sm = 0;
|
||||
uint sm = 0; // state machine
|
||||
uint offset = pio_add_program(pio, &st7789_lcd_program);
|
||||
st7789_lcd_program_init(pio, sm, offset, PIN_DIN, PIN_CLK, SERIAL_CLK_DIV);
|
||||
|
||||
|
@ -106,48 +104,16 @@ int main() {
|
|||
lcd_init(pio, sm, st7789_init_seq);
|
||||
gpio_put(PIN_BL, 1);
|
||||
|
||||
// Other SDKs: static image on screen, lame, boring
|
||||
// Raspberry Pi Pico SDK: spinning image on screen, bold, exciting
|
||||
|
||||
// Lane 0 will be u coords (bits 8:1 of addr offset), lane 1 will be v
|
||||
// coords (bits 16:9 of addr offset), and we'll represent coords with
|
||||
// 16.16 fixed point. ACCUM0,1 will contain current coord, BASE0/1 will
|
||||
// contain increment vector, and BASE2 will contain image base pointer
|
||||
#define UNIT_LSB 16
|
||||
interp_config lane0_cfg = interp_default_config();
|
||||
interp_config_set_shift(&lane0_cfg, UNIT_LSB - 1); // -1 because 2 bytes per pixel
|
||||
interp_config_set_mask(&lane0_cfg, 1, 1 + (LOG_IMAGE_SIZE - 1));
|
||||
interp_config_set_add_raw(&lane0_cfg, true); // Add full accumulator to base with each POP
|
||||
interp_config lane1_cfg = interp_default_config();
|
||||
interp_config_set_shift(&lane1_cfg, UNIT_LSB - (1 + LOG_IMAGE_SIZE));
|
||||
interp_config_set_mask(&lane1_cfg, 1 + LOG_IMAGE_SIZE, 1 + (2 * LOG_IMAGE_SIZE - 1));
|
||||
interp_config_set_add_raw(&lane1_cfg, true);
|
||||
|
||||
interp_set_config(interp0, 0, &lane0_cfg);
|
||||
interp_set_config(interp0, 1, &lane1_cfg);
|
||||
interp0->base[2] = (uint32_t) raspberry_256x256;
|
||||
|
||||
float theta = 0.f;
|
||||
float theta_max = 2.f * (float) M_PI;
|
||||
while (1) {
|
||||
theta += 0.02f;
|
||||
if (theta > theta_max)
|
||||
theta -= theta_max;
|
||||
int32_t rotate[4] = {
|
||||
(int32_t) (cosf(theta) * (1 << UNIT_LSB)), (int32_t) (-sinf(theta) * (1 << UNIT_LSB)),
|
||||
(int32_t) (sinf(theta) * (1 << UNIT_LSB)), (int32_t) (cosf(theta) * (1 << UNIT_LSB))
|
||||
};
|
||||
interp0->base[0] = rotate[0];
|
||||
interp0->base[1] = rotate[2];
|
||||
st7789_start_pixels(pio, sm);
|
||||
for (int y = 0; y < SCREEN_HEIGHT; ++y) {
|
||||
interp0->accum[0] = rotate[1] * y;
|
||||
interp0->accum[1] = rotate[3] * y;
|
||||
for (int x = 0; x < SCREEN_WIDTH; ++x) {
|
||||
uint16_t colour = *(uint16_t *) (interp0->pop[2]);
|
||||
uint16_t colour = 31; // red
|
||||
st7789_lcd_put(pio, sm, colour >> 8);
|
||||
st7789_lcd_put(pio, sm, colour & 0xff);
|
||||
}
|
||||
}
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue