improvement
I will get ice cream tomorrow
This commit is contained in:
parent
2b7322f0ff
commit
195e81a5af
5 changed files with 83 additions and 45 deletions
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -35,5 +35,8 @@
|
|||
"raspberry-pi-pico.cmakeAutoConfigure": true,
|
||||
"raspberry-pi-pico.useCmakeTools": false,
|
||||
"raspberry-pi-pico.cmakePath": "${HOME}/.pico-sdk/cmake/v3.28.0-rc6/bin/cmake",
|
||||
"raspberry-pi-pico.ninjaPath": "${HOME}/.pico-sdk/ninja/v1.11.1/ninja"
|
||||
"raspberry-pi-pico.ninjaPath": "${HOME}/.pico-sdk/ninja/v1.11.1/ninja",
|
||||
"files.associations": {
|
||||
"gpio.h": "c"
|
||||
}
|
||||
}
|
||||
|
|
7
include/constants.h
Normal file
7
include/constants.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef CONSTANTSH
|
||||
#define CONSTANTSH
|
||||
|
||||
#define SCREEN_WIDTH 240
|
||||
#define SCREEN_HEIGHT 360
|
||||
|
||||
#endif
|
5
include/st7789_lcd.h
Normal file
5
include/st7789_lcd.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
void lcd_start_pixels();
|
||||
void lcd_end_pixels();
|
||||
void lcd_put_rgb(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
void lcd_initialize();
|
26
src/main.c
Normal file
26
src/main.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include "hardware/gpio.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "st7789_lcd.h"
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
|
||||
lcd_initialize();
|
||||
|
||||
lcd_start_pixels();
|
||||
for (int y = 0; y < SCREEN_HEIGHT; ++y) {
|
||||
for (int x = 0; x < SCREEN_WIDTH; ++x) {
|
||||
//uint16_t colour = 31; // red
|
||||
//st7789_lcd_put(pio, sm, colour >> 8);
|
||||
// st7789_lcd_put(pio, sm, colour & 0xff);
|
||||
lcd_put_rgb(0, 0, 255);
|
||||
}
|
||||
}
|
||||
lcd_end_pixels();
|
||||
|
||||
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
||||
}
|
|
@ -12,14 +12,9 @@
|
|||
#include "hardware/gpio.h"
|
||||
#include "hardware/interp.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "st7789_lcd.pio.h"
|
||||
|
||||
// Tested with the parts that have the height of 240 and 320
|
||||
#define SCREEN_WIDTH 240
|
||||
#define SCREEN_HEIGHT 320
|
||||
#define IMAGE_SIZE 256
|
||||
#define LOG_IMAGE_SIZE 8
|
||||
|
||||
#define PIN_DIN 0
|
||||
#define PIN_CLK 1
|
||||
#define PIN_CS 2
|
||||
|
@ -29,6 +24,9 @@
|
|||
|
||||
#define SERIAL_CLK_DIV 1.f
|
||||
|
||||
#define pio pio0
|
||||
#define sm 0
|
||||
|
||||
// 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[] = {
|
||||
|
@ -38,7 +36,6 @@ 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, 0x13, // Normal display on, then 10 ms delay
|
||||
1, 2, 0x29, // Main screen turn on, then wait 500 ms
|
||||
0 // Terminate list
|
||||
|
@ -50,7 +47,7 @@ static inline void lcd_set_dc_cs(bool dc, bool cs) {
|
|||
sleep_us(1);
|
||||
}
|
||||
|
||||
static inline void lcd_write_cmd(PIO pio, uint sm, const uint8_t *cmd, size_t count) {
|
||||
static inline void lcd_write_cmd(const uint8_t *cmd, size_t count) {
|
||||
st7789_lcd_wait_idle(pio, sm);
|
||||
lcd_set_dc_cs(0, 0);
|
||||
st7789_lcd_put(pio, sm, *cmd++);
|
||||
|
@ -64,56 +61,56 @@ static inline void lcd_write_cmd(PIO pio, uint sm, const uint8_t *cmd, size_t co
|
|||
lcd_set_dc_cs(1, 1);
|
||||
}
|
||||
|
||||
static inline void lcd_init(PIO pio, uint sm, const uint8_t *init_seq) {
|
||||
const uint8_t *cmd = init_seq;
|
||||
static inline void lcd_init() {
|
||||
const uint8_t *cmd = st7789_init_seq;
|
||||
while (*cmd) {
|
||||
lcd_write_cmd(pio, sm, cmd + 2, *cmd);
|
||||
lcd_write_cmd(cmd + 2, *cmd);
|
||||
sleep_ms(*(cmd + 1) * 5);
|
||||
cmd += *cmd + 2;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void st7789_start_pixels(PIO pio, uint sm) {
|
||||
static inline void initialize_pins() {
|
||||
gpio_init(PIN_CS);
|
||||
gpio_set_dir(PIN_CS, GPIO_OUT);
|
||||
gpio_put(PIN_CS, 1);
|
||||
|
||||
gpio_init(PIN_DC);
|
||||
gpio_set_dir(PIN_DC, GPIO_OUT);
|
||||
|
||||
gpio_init(PIN_RESET);
|
||||
gpio_set_dir(PIN_RESET, GPIO_OUT);
|
||||
gpio_put(PIN_RESET, 1);
|
||||
|
||||
gpio_init(PIN_BL);
|
||||
gpio_set_dir(PIN_BL, GPIO_OUT);
|
||||
gpio_put(PIN_BL, 1);
|
||||
}
|
||||
|
||||
void lcd_start_pixels() {
|
||||
uint8_t cmd = 0x2c; // RAMWR
|
||||
lcd_write_cmd(pio, sm, &cmd, 1);
|
||||
lcd_write_cmd(&cmd, 1);
|
||||
lcd_set_dc_cs(1, 0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
void lcd_end_pixels() {
|
||||
lcd_set_dc_cs(0, 1);
|
||||
}
|
||||
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
void lcd_put_rgb(uint8_t r, uint8_t g, uint8_t b) {
|
||||
uint16_t colour = ((b >> 3 & 0x1f) << 11) | ((g >> 2 & 0x3f) << 5) | (r >> 3 & 0x1f);
|
||||
|
||||
PIO pio = pio0;
|
||||
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);
|
||||
|
||||
gpio_init(PIN_CS);
|
||||
gpio_init(PIN_DC);
|
||||
gpio_init(PIN_RESET);
|
||||
gpio_init(PIN_BL);
|
||||
gpio_set_dir(PIN_CS, GPIO_OUT);
|
||||
gpio_set_dir(PIN_DC, GPIO_OUT);
|
||||
gpio_set_dir(PIN_RESET, GPIO_OUT);
|
||||
gpio_set_dir(PIN_BL, GPIO_OUT);
|
||||
|
||||
gpio_put(PIN_CS, 1);
|
||||
gpio_put(PIN_RESET, 1);
|
||||
lcd_init(pio, sm, st7789_init_seq);
|
||||
gpio_put(PIN_BL, 1);
|
||||
|
||||
|
||||
while (1) {
|
||||
st7789_start_pixels(pio, sm);
|
||||
for (int y = 0; y < SCREEN_HEIGHT; ++y) {
|
||||
for (int x = 0; x < SCREEN_WIDTH; ++x) {
|
||||
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);
|
||||
}
|
||||
|
||||
void lcd_initialize() {
|
||||
stdio_init_all();
|
||||
|
||||
initialize_pins();
|
||||
|
||||
uint offset = pio_add_program(pio, &st7789_lcd_program);
|
||||
st7789_lcd_program_init(pio, sm, offset, PIN_DIN, PIN_CLK, SERIAL_CLK_DIV);
|
||||
|
||||
lcd_init();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue