Add partial ST7789 support

This commit is contained in:
shylie 2025-06-14 17:35:33 -04:00
parent 63bef7ecbc
commit 7d64ebf3e3
3 changed files with 58 additions and 22 deletions

View File

@ -1,14 +1,15 @@
#include <cmath>
#include <cstdlib>
#include <hardware/structs/io_bank0.h>
#include <pico/stdio_usb.h>
#include <pico/stdlib.h>
#include <pico/time.h>
#include <picoled/SSD1306.h>
#include <hardware/pwm.h>
#include <hardware/i2c.h>
#include <picoled/ST7789.h>
#include <picoled/gfx/2D.h>
#include <pico/stdlib.h>
#include <hardware/pwm.h>
using namespace picoled;
@ -43,6 +44,8 @@ constexpr uint8_t OLED_ADDRESS = 0x3C;
int main()
{
//set_sys_clock_khz(133000, false);
stdio_usb_init();
srand(time_us_64());
@ -52,42 +55,60 @@ int main()
gpio_pull_up(0);
gpio_pull_up(1);
ssd1306 oled(i2c0, OLED_ADDRESS);
spi_init(spi0, 32000000);
gpio_set_function(2, GPIO_FUNC_SPI);
gpio_set_function(3, GPIO_FUNC_SPI);
gpio_set_function(4, GPIO_FUNC_SPI);
gpio_set_function(5, GPIO_FUNC_SIO);
gpio_set_dir(5, GPIO_OUT);
gpio_put(5, false);
gpio_set_function(6, GPIO_FUNC_SIO);
gpio_set_dir(6, GPIO_OUT);
gpio_put(6, false);
st7789 oled(135, 240, spi0, 5, 6);
gfx::gfx2d gfx(oled);
float angle;
float angle = 0;
int64_t time = time_us_32();
buffer<pixel> tex(16, 16);
for (int x = 0; x < 16; x++)
buffer<pixel> tex(64, 64);
for (int x = 0; x < 64; x++)
{
for (int y = 0; y < 16; y++)
for (int y = 0; y < 64; y++)
{
tex.write(x, y, x * y);
const uint8_t r = 4 * x;
const uint8_t g = 4 * y;
const uint8_t b = 254 - 2 * x - 2 * y;
tex.write(x, y, { r, g, b });
}
}
while (true)
{
oled.clear();
int64_t current = time_us_32();
const float dt = std::abs(current - time) / 1000000.0f;
time = current;
angle -= get_encoder_delta(i2c0, RIGHT_ENCODER_ADDRESS) / 12.0f * 3.1415926f;
stdio_printf("%05f\n", dt);
const int32_t delta = get_encoder_delta(i2c0, RIGHT_ENCODER_ADDRESS);
angle -= delta / 12.0f * 3.1415926f;
const float angle2 = angle + (2 * 3.1415926f) / 3;
const float angle3 = angle + 2 * (2 * 3.1415926f) / 3;
const gfx::vec2 ap = { 30.0f + 20 * cosf(angle), 30.0f + 20 * sinf(angle) };
const gfx::vec2 bp = { 30.0f + 20 * cosf(angle2), 30.0f + 20 * sinf(angle2) };
const gfx::vec2 cp = { 30.0f + 20 * cosf(angle3), 30.0f + 20 * sinf(angle3) };
const gfx::vec2 ap = { 60.0f + 40 * cosf(angle), 60.0f + 40 * sinf(angle) };
const gfx::vec2 bp = { 60.0f + 40 * cosf(angle2), 60.0f + 40 * sinf(angle2) };
const gfx::vec2 cp = { 60.0f + 40 * cosf(angle3), 60.0f + 40 * sinf(angle3) };
const gfx::vec2 at = { 0.0f, 0.0f };
const gfx::vec2 bt = { 0.0f, 0.0f };
const gfx::vec2 ct = { 1.0f, 1.0f };
const gfx::vec2 bt = { 1.0f, 0.0f };
const gfx::vec2 ct = { 0.0f, 1.0f };
oled.clear();
gfx.draw_triangle({
{ ap, at },
{ bp, bt },

@ -1 +1 @@
Subproject commit dfeccd50b9d2e3583675b80cd4225cb98215356c
Subproject commit 846f909cfe99ec1a9cd66299d380e35e44cfd89f

View File

@ -5,8 +5,10 @@
#include <pico/stdlib.h>
#include <pico/time.h>
#include <hardware/pwm.h>
#include <hardware/i2c.h>
#include <hardware/spi.h>
#include <picoled/SSD1306.h>
#include <picoled/ST7789.h>
namespace
{
@ -70,7 +72,7 @@ constexpr uint8_t OLED_ADDRESS = 0x3C;
constexpr float PADDLE_SPEED = 20;
constexpr float INITIAL_BALL_SPEED = 32;
constexpr uint8_t BUZZER_PIN = 2;
constexpr uint8_t BUZZER_PIN = 7;
int64_t unbeep(alarm_id_t, void*)
{
@ -98,7 +100,20 @@ int main()
gpio_pull_up(0);
gpio_pull_up(1);
picoled::ssd1306 oled(i2c0, OLED_ADDRESS);
spi_init(spi0, 32000000);
gpio_set_function(2, GPIO_FUNC_SPI);
gpio_set_function(3, GPIO_FUNC_SPI);
gpio_set_function(4, GPIO_FUNC_SPI);
gpio_set_function(5, GPIO_FUNC_SIO);
gpio_set_dir(5, GPIO_OUT);
gpio_put(5, false);
gpio_set_function(6, GPIO_FUNC_SIO);
gpio_set_dir(6, GPIO_OUT);
gpio_put(6, false);
picoled::st7789 oled(135, 240, spi0, 5, 6);
oled.update();
rect player = { 8.0f, oled.get_height() / 2.0f - 8.0f, 4.0f, 16.0f };