is shows something

This commit is contained in:
PoliEcho 2025-09-14 22:00:13 +02:00
parent a02a20a957
commit f75fde6400
5 changed files with 111 additions and 19 deletions

View File

@ -1,3 +1,6 @@
#include <cstdint>
#include "gfxfont.h"
const uint8_t VGA1_16x32Bitmaps[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

View File

@ -66,9 +66,6 @@ extern "C" {
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GC9A01_H__ */
@ -106,3 +103,6 @@ void gc9a01_vline(gc9a01_GC9A01_obj_t *self, uint16_t x, uint16_t y, uint16_t w,
void gc9a01_text(gc9a01_GC9A01_obj_t *self, GFXfont *font, char *str, uint16_t x0, uint16_t y0, uint16_t fg_color, uint16_t bg_color);
uint8_t gc9a01_get_color(uint8_t bpp);
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -1,5 +1,98 @@
#include "spi.h"
#include "display.h"
#include "GC9A01/VGA1_16x32.h"
#include "gc9a01.h"
#include "hardware/gpio.h"
#include "hardware/spi.h"
#include "hardware/structs/io_bank0.h"
#include "pico/time.h"
#include "spi.h"
#include <cmath>
#include <cstdint>
#include <stdio.h>
// GC9A01
int32_t t_fine;
uint16_t dig_T1;
int16_t dig_T2, dig_T3;
// LCD config
gc9a01_GC9A01_obj_t create_lcd() {
spi_init(SPI_PORT, SPI_CLOCK_HZ); // Use your defined SPI port and clock speed
// Initialize GPIO pins for SPI communication using your definitions
gpio_set_function(PIN_SCK, GPIO_FUNC_SPI); // SCK = 18
gpio_set_function(PIN_MOSI, GPIO_FUNC_SPI); // MOSI = 19
// Note: MISO not needed for display, but if you had one it would be on a
// separate pin
// Configure Chip Select
gpio_init(PIN_CS); // CS = 17
gpio_set_dir(PIN_CS, GPIO_OUT);
gpio_put(PIN_CS, 1); // Set CS High
// Configure Reset pin
gpio_init(PIN_RST); // Reset = 20
gpio_set_dir(PIN_RST, GPIO_OUT);
gpio_put(PIN_RST, 0);
// Configure DC pin
gpio_init(PIN_DC); // DC = 16
gpio_set_dir(PIN_DC, GPIO_OUT);
gpio_put(PIN_DC, 0);
// Note: You don't have a backlight pin defined in spi.h
// If you have a backlight control, define PIN_BL in spi.h
// For now, commenting out backlight control:
/*
gpio_init(PIN_BL);
gpio_set_dir(PIN_BL, GPIO_OUT);
gpio_put(PIN_BL, 0);
*/
gc9a01_GC9A01_obj_t lcd;
lcd.spi_obj = SPI_PORT;
lcd.reset = PIN_RST;
lcd.dc = PIN_DC;
lcd.cs = PIN_CS;
lcd.backlight =
-1; // Set to -1 if no backlight control, or define PIN_BL in spi.h
lcd.xstart = 0;
lcd.ystart = 0;
lcd.display_width = 240;
lcd.display_height = 240;
lcd.rotation = 0;
lcd.buffer_size = 2048;
lcd.i2c_buffer = static_cast<uint16_t *>(malloc(2048));
return lcd;
}
void display_start() {
int8_t rslt;
char buf[10];
gc9a01_GC9A01_obj_t lcd = create_lcd();
uint16_t color = BLACK;
gc9a01_init(&lcd);
sleep_ms(100);
gc9a01_fill(&lcd, 0);
GFXfont font = VGA1_16x32;
while (true) {
color = (color == BLACK) ? MAGENTA : BLACK;
for (int i = 720; i > 0; i--) {
int x = 120 + (int)(119.0 * sin((180.0 + i / 2.0) * M_TWOPI / 360.0));
int y = 120 + (int)(119.0 * cos((180.0 + i / 2.0) * M_TWOPI / 360.0));
gc9a01_draw_pixel(&lcd, x, y, color);
}
volatile uint16_t c1 = RED;
volatile uint16_t c2 = GREEN;
gc9a01_text(&lcd, &font, "hello world", 120, 120, c1, c2);
sleep_ms(1000);
}
free(lcd.i2c_buffer);
}

View File

@ -17,6 +17,7 @@
#include "net_utils.h"
#include "timezones.h"
#include "spi.h"
#include "display.h"
#define NTP_DELTA 2208988800UL
@ -94,16 +95,7 @@ int main() {
// sign of life
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
// SPI initialisation.
spi_init(SPI_PORT, SPI_CLOCK_HZ);
gpio_set_function(PIN_MISO, GPIO_FUNC_SPI);
gpio_set_function(PIN_CS, GPIO_FUNC_SIO);
gpio_set_function(PIN_SCK, GPIO_FUNC_SPI);
gpio_set_function(PIN_MOSI, GPIO_FUNC_SPI);
// Chip select is active-low, so we'll initialise it to a driven-high state
gpio_set_dir(PIN_CS, GPIO_OUT);
gpio_put(PIN_CS, 1);
display_start();
// Timer example code - This example fires off the callback after 2000ms
// add_alarm_in_ms(2000, alarm_callback, NULL, false);

12
spi.h
View File

@ -6,12 +6,16 @@
// Pins can be changed, see the GPIO function select table in the datasheet for
// information on GPIO assignments
#define SPI_PORT spi0
#define PIN_MISO 16
#define PIN_CS 17
#define PIN_SCK 18
#define PIN_MOSI 19
#define PIN_DC 16
#define PIN_RST 20
#define PIN_DC 16
#define PIN_RST 20
#define SPI_CLOCK_HZ 12000000
#endif //SMART_ALARM_SPI_H
// #define SPI_CLOCK_HZ 1000
#define MEMORY_WRITE 0x2C
#define SLEEP_ON 0x10
#define SLEEP_OFF 0x11
#endif // SMART_ALARM_SPI_H