From a01331d59ac2698c5469e442bc832ca15d032ee3 Mon Sep 17 00:00:00 2001 From: Mikah Chapman Date: Sun, 26 Jun 2022 00:22:02 -0600 Subject: [PATCH] get build working with screen via pico-arduino-compat --- .gitignore | 2 + .vscode/settings.json | 5 ++ CMakeLists.txt | 7 ++- build/elf2uf2/tmp/ELF2UF2Build-cfgcmd.txt | 1 - traegerController.cpp | 58 ++++++++++++++++++++--- 5 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 build/elf2uf2/tmp/ELF2UF2Build-cfgcmd.txt diff --git a/.gitignore b/.gitignore index d73691d..e93529e 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,5 @@ Temporary Items # Built Visual Studio Code Extensions *.vsix +# Build directory +build*/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5cf31cc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cmake.environment": { + "PICO_SDK_PATH":"/Users/mchapman/source/pico/pico-sdk" + }, +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0998a5e..99ee01e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,9 @@ include(pico_sdk_import.cmake) project(traegerController C CXX ASM) +add_subdirectory(/Users/mchapman/source/pico-arduino-compat/libs/adafruit-gfx-library pac-adafruit-gfx-library) +add_subdirectory(/Users/mchapman/source/pico-arduino-compat/libs/adafruit-sh110x pac-adafruit-sh110x) + # Initialise the Raspberry Pi Pico SDK pico_sdk_init() @@ -38,7 +41,9 @@ target_link_libraries(traegerController hardware_spi hardware_i2c hardware_timer - ) + pac-adafruit-sh110x + pac-adafruit-gfx-library +) pico_add_extra_outputs(traegerController) diff --git a/build/elf2uf2/tmp/ELF2UF2Build-cfgcmd.txt b/build/elf2uf2/tmp/ELF2UF2Build-cfgcmd.txt deleted file mode 100644 index 8d216ba..0000000 --- a/build/elf2uf2/tmp/ELF2UF2Build-cfgcmd.txt +++ /dev/null @@ -1 +0,0 @@ -cmd='/opt/homebrew/Cellar/cmake/3.23.2/bin/cmake;-GUnix Makefiles;' diff --git a/traegerController.cpp b/traegerController.cpp index 4c2304d..7bdb763 100644 --- a/traegerController.cpp +++ b/traegerController.cpp @@ -1,5 +1,8 @@ #include +#include "Adafruit_GFX.h" +#include "Adafruit_SH110x.h" #include "pico/stdlib.h" +#include "pico/multicore.h" #include "hardware/spi.h" #include "hardware/i2c.h" #include "hardware/timer.h" @@ -14,18 +17,25 @@ #define PIN_MOSI 19 // I2C defines -// This example will use I2C0 on GPIO8 (SDA) and GPIO9 (SCL) running at 400KHz. +// This example will use I2C1 on GPIO2 (SDA) and GPIO3 (SCL) running at 400KHz. // Pins can be changed, see the GPIO function select table in the datasheet for information on GPIO assignments -#define I2C_PORT i2c0 -#define I2C_SDA 8 -#define I2C_SCL 9 +#define I2C_PORT i2c1 +#define I2C_SDA 2 +#define I2C_SCL 3 + +#define BUTTON_A 9 +#define BUTTON_B 8 +#define BUTTON_C 7 int64_t alarm_callback(alarm_id_t id, void *user_data) { // Put your timeout handler code in here return 0; } - +void core1_entry() +{ + +} int main() { @@ -41,7 +51,6 @@ int main() // 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); - // I2C Initialisation. Using it at 400Khz. i2c_init(I2C_PORT, 400*1000); @@ -50,6 +59,43 @@ int main() gpio_set_function(I2C_SCL, GPIO_FUNC_I2C); gpio_pull_up(I2C_SDA); gpio_pull_up(I2C_SCL); + gpio_set_dir(BUTTON_A, GPIO_IN); + gpio_set_dir(BUTTON_B, GPIO_IN); + gpio_set_dir(BUTTON_C, GPIO_IN); + gpio_pull_up(BUTTON_A); + gpio_pull_up(BUTTON_B); + gpio_pull_up(BUTTON_C); + + Wire1.setSCL(I2C_SCL); + Wire1.setSDA(I2C_SDA); + Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire1); + + display.begin(0x3c, true); + display.display(); + + sleep_ms(1000); + display.setRotation(1); + display.clearDisplay(); + display.display(); + + sleep_ms(500); + display.setTextSize(1); + display.setTextColor(SH110X_WHITE); + display.setCursor(0,0); + display.print("Hello from core 0!"); + display.display(); + + //multicore_launch_core1(core1_entry); + + sleep_ms(1000); + while(true) + { + if (gpio_get(BUTTON_A) == false) display.print("A\n"); + if (gpio_get(BUTTON_B) == false) display.print("B\n"); + if (gpio_get(BUTTON_C) == false) display.print("C\n"); + display.display(); + sleep_ms(250); + } // Timer example code - This example fires off the callback after 2000ms add_alarm_in_ms(2000, alarm_callback, NULL, false);