From 21fe876c0bc32e6579024b983ad0774357bf3a04 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 16 May 2024 17:41:41 +0200 Subject: [PATCH] more work life update yes I did get an icecream. it wasn't very good tho --- CMakeLists.txt | 1 + include/bt4502.h | 1 + include/constants.h | 2 ++ include/st7789_lcd.h | 1 + src/bt4502.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 9 +++++-- src/st7789_lcd.c | 4 ++++ 7 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 include/bt4502.h create mode 100644 src/bt4502.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f6c7a71..a98be18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ cmake_minimum_required(VERSION 3.13) include(pico_sdk_import.cmake) project(dp) +set(CMAKE_CXX_FLAGS "-O3 -Wall -Wextra") # initialize the Raspberry Pi Pico SDK pico_sdk_init() diff --git a/include/bt4502.h b/include/bt4502.h new file mode 100644 index 0000000..72e1d2a --- /dev/null +++ b/include/bt4502.h @@ -0,0 +1 @@ +int bt_initialize(); \ No newline at end of file diff --git a/include/constants.h b/include/constants.h index 825a657..72d65c4 100644 --- a/include/constants.h +++ b/include/constants.h @@ -4,4 +4,6 @@ #define SCREEN_WIDTH 240 #define SCREEN_HEIGHT 360 +#define BT_NAME "pico bt display" + #endif \ No newline at end of file diff --git a/include/st7789_lcd.h b/include/st7789_lcd.h index 3282e67..43e24e6 100644 --- a/include/st7789_lcd.h +++ b/include/st7789_lcd.h @@ -1,3 +1,4 @@ +void lcd_backlight(bool enabled); void lcd_start_pixels(); void lcd_end_pixels(); void lcd_put_rgb(uint8_t r, uint8_t g, uint8_t b); diff --git a/src/bt4502.c b/src/bt4502.c new file mode 100644 index 0000000..1556de1 --- /dev/null +++ b/src/bt4502.c @@ -0,0 +1,57 @@ +#include +#include "hardware/gpio.h" +#include "hardware/uart.h" + +#include "constants.h" + +#define PIN_TX 21 // rxd on module +#define PIN_RX 22 // txd on module +#define PIN_WAKE 18 +#define PIN_PDN 19 +#define PIN_INT 20 + +#define UART uart0 + +static void interrupt_callback() { + // TODO +} + +static inline void initialize_pins() { + gpio_init(PIN_WAKE); + gpio_set_dir(PIN_WAKE, GPIO_OUT); + gpio_put(PIN_WAKE, 1); + + gpio_init(PIN_PDN); + gpio_set_dir(PIN_PDN, GPIO_OUT); + gpio_put(PIN_PDN, 0); + + gpio_init(PIN_INT); + gpio_set_dir(PIN_INT, GPIO_IN); + gpio_set_irq_enabled_with_callback(PIN_INT, GPIO_IRQ_EDGE_FALL, true, &interrupt_callback); + + uart_init(UART, 115200); + gpio_set_function(PIN_TX, GPIO_FUNC_UART); + gpio_set_function(PIN_RX, GPIO_FUNC_UART); + +} + +int bt_initialize() { + initialize_pins(); + + char ren_cmd[11 + sizeof(BT_NAME)]; + strcpy(ren_cmd, "TTM:REN-"); + strcat(ren_cmd, BT_NAME); + strcat(ren_cmd, "\r\n\0"); + + uart_puts(UART, ren_cmd); + + char resp[11]; + uart_read_blocking(UART, resp, 11); + + if (strcmp(resp, "TTM:OK\r\n\0") != 0) { + uart_read_blocking(UART, NULL, 1); + return 1; + } + + return 0; +} \ No newline at end of file diff --git a/src/main.c b/src/main.c index b6ed63f..e0b7b94 100644 --- a/src/main.c +++ b/src/main.c @@ -1,15 +1,18 @@ #include "hardware/gpio.h" +#include "pico/stdlib.h" #include "constants.h" #include "st7789_lcd.h" - - +#include "bt4502.h" int main() { gpio_init(PICO_DEFAULT_LED_PIN); gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); lcd_initialize(); + if (bt_initialize() != 0) { + return 1; + } lcd_start_pixels(); for (int y = 0; y < SCREEN_HEIGHT; ++y) { @@ -23,4 +26,6 @@ int main() { lcd_end_pixels(); gpio_put(PICO_DEFAULT_LED_PIN, 1); + sleep_ms(1000); + lcd_backlight(0); } \ No newline at end of file diff --git a/src/st7789_lcd.c b/src/st7789_lcd.c index b1fcefb..0913d4b 100644 --- a/src/st7789_lcd.c +++ b/src/st7789_lcd.c @@ -87,6 +87,10 @@ static inline void initialize_pins() { gpio_put(PIN_BL, 1); } +void lcd_backlight(bool enabled) { + gpio_put(PIN_BL, enabled); +} + void lcd_start_pixels() { uint8_t cmd = 0x2c; // RAMWR lcd_write_cmd(&cmd, 1);