initial setup

This commit is contained in:
matthias wagner
2023-05-13 11:10:52 +02:00
commit 741f1e56a6
335 changed files with 37058 additions and 0 deletions

17
src/main.c Normal file
View File

@@ -0,0 +1,17 @@
#include "main.h"
#include "hardware/gpio.h"
#include "pico/stdlib.h"
#include "tft.h"
int main()
{
gpio_init(DLED_PIN);
gpio_set_dir(DLED_PIN, GPIO_OUT);
while (true) {
gpio_put(DLED_PIN, 0);
sleep_ms(250);
gpio_put(DLED_PIN, 1);
sleep_ms(1000);
}
return 0;
}

8
src/main.h Normal file
View File

@@ -0,0 +1,8 @@
#include "hardware/gpio.h"
#include "pico/stdlib.h"
#include "tft.h"
#define DLED_PIN 25
// void* malloc(size_t size);
// size_t strlen(const char* str);

145
src/tft.c Normal file
View File

@@ -0,0 +1,145 @@
#include "tft.h"
void cmd(uint8_t cmd)
{
CS_L;
RS_C;
spi_write_blocking(spi_default, &cmd, 1);
CS_H;
}
void data(uint8_t data)
{
CS_L;
RS_D;
spi_write_blocking(spi_default, &data, 1);
CS_H;
}
void reset()
{
sleep_ms(120);
gpio_put(RESET_PIN, 1);
sleep_ms(120);
gpio_put(RESET_PIN, 0);
sleep_ms(120);
gpio_put(RESET_PIN, 1);
sleep_ms(120);
}
void init_pins()
{
gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT);
gpio_put(LED_PIN, 1);
gpio_init(RESET_PIN);
gpio_set_dir(RESET_PIN, GPIO_OUT);
gpio_init(RS_PIN);
gpio_set_dir(RS_PIN, GPIO_OUT);
gpio_init(CS_PIN);
gpio_set_dir(CS_PIN, GPIO_OUT);
CS_H;
spi_init(spi_default, SPI_CLK);
gpio_set_function(RX_PIN, GPIO_FUNC_SPI);
gpio_set_function(SCK_PIN, GPIO_FUNC_SPI);
gpio_set_function(TX_PIN, GPIO_FUNC_SPI);
}
void init()
{
init_pins();
write_command(0x01); // Software reset
sleep_ms(120);
write_command(0x11); // Sleep exit
sleep_ms(120);
write_command(0xF0); // Command Set control
write_data(0xC3); // Enable extension command 2 partI
write_command(0xF0); // Command Set control
write_data(0x96); // Enable extension command 2 partII
write_command(0x36); // Memory Data Access Control MX, MY, RGB mode
write_data(0x48); // X-Mirror, Top-Left to right-Buttom, RGB
write_command(0x3A); // Interface Pixel Format
write_data(0x55); // Control interface color format set to 16
write_command(0xB4); // Column inversion
write_data(0x01); // 1-dot inversion
write_command(0xB6); // Display Function Control
write_data(0x80); // Bypass
write_data(0x02); // Source Output Scan from S1 to S960, Gate Output scan from G1 to G480, scan cycle=2
write_data(0x3B); // LCD Drive Line=8*(59+1)
write_command(0xE8); // Display Output Ctrl Adjust
write_data(0x40);
write_data(0x8A);
write_data(0x00);
write_data(0x00);
write_data(0x29); // Source eqaulizing period time= 22.5 us
write_data(0x19); // Timing for "Gate start"=25 (Tclk)
write_data(0xA5); // Timing for "Gate End"=37 (Tclk), Gate driver EQ function ON
write_data(0x33);
write_command(0xC1); // Power control2
write_data(0x06); // VAP(GVDD)=3.85+( vcom+vcom offset), VAN(GVCL)=-3.85+( vcom+vcom offset)
write_command(0xC2); // Power control 3
write_data(0xA7); // Source driving current level=low, Gamma driving current level=High
write_command(0xC5); // VCOM Control
write_data(0x18); // VCOM=0.9
sleep_ms(120);
// ST7796 Gamma Sequence
write_command(0xE0); // Gamma"+"
write_data(0xF0);
write_data(0x09);
write_data(0x0b);
write_data(0x06);
write_data(0x04);
write_data(0x15);
write_data(0x2F);
write_data(0x54);
write_data(0x42);
write_data(0x3C);
write_data(0x17);
write_data(0x14);
write_data(0x18);
write_data(0x1B);
write_command(0xE1); // Gamma"-"
write_data(0xE0);
write_data(0x09);
write_data(0x0B);
write_data(0x06);
write_data(0x04);
write_data(0x03);
write_data(0x2B);
write_data(0x43);
write_data(0x42);
write_data(0x3B);
write_data(0x16);
write_data(0x14);
write_data(0x17);
write_data(0x1B);
sleep_ms(120);
write_command(0xF0); // Command Set control
write_data(0x3C); // Disable extension command 2 partI
write_command(0xF0); // Command Set control
write_data(0x69); // Disable extension command 2 partII
CS_H;
sleep_ms(120);
CS_L;
write_command(0x29); // Display on
}
void set_pixel_red()
{
write_data(0b111111000100000000);
}

28
src/tft.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef TFT_H
#define TFT_H
#include "hardware/gpio.h"
#include "hardware/spi.h"
#include "pico/stdlib.h"
#define LED_PIN 20
#define RESET_PIN 22
#define RS_PIN 26
#define RX_PIN PICO_DEFAULT_SPI_RX_PIN
#define CS_PIN PICO_DEFAULT_SPI_CSN_PIN
#define SCK_PIN PICO_DEFAULT_SPI_SCK_PIN
#define TX_PIN PICO_DEFAULT_SPI_TX_PIN
#define SPI_CLK 66666666
#define CS_L gpio_put(CS_PIN, 0)
#define CS_H gpio_put(CS_PIN, 1)
#define RS_C gpio_put(RS_PIN, 0)
#define RS_D gpio_put(RS_PIN, 1)
void write_command(uint8_t cmd);
void write_data(uint8_t data);
void reset();
void init_pins();
void init();
void set_pixel_red();
#endif // TFT_H