Files
traegerController/traegerController.cpp

118 lines
3.1 KiB
C++

#include <stdio.h>
#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"
#include "traegerLogo.h"
// SPI Defines
// We are going to use SPI 0, and allocate it to the following GPIO pins
// 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
// I2C defines
// 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 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;
}
[[noreturn]] void core1_entry()
{
// I2C Initialisation. Using it at 400Khz.
i2c_init(I2C_PORT, 400*1000);
gpio_set_function(I2C_SDA, GPIO_FUNC_I2C);
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.drawBitmap(0, 0, logo, 128, 64, SH110X_WHITE);
display.display();
sleep_ms(1000);
display.clearDisplay();
display.display();
sleep_ms(500);
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(0,0);
display.print("Hello! core 1\n");
display.display();
sleep_ms(1000);
display.setTextSize(2);
while(true)
{
display.clearDisplay();
display.setCursor(0,0);
display.print(!gpio_get(BUTTON_A) ? "A\n" : "\n");
display.print(!gpio_get(BUTTON_B) ? "B\n" : "\n");
display.print(!gpio_get(BUTTON_C) ? "C\n" : "\n");
display.display();
sleep_ms(100);
}
}
int main()
{
stdio_init_all();
// SPI initialisation. This example will use SPI at 1MHz.
spi_init(SPI_PORT, 1000*1000);
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);
multicore_launch_core1(core1_entry);
// Timer example code - This example fires off the callback after 2000ms
add_alarm_in_ms(2000, alarm_callback, NULL, false);
puts("Hello, world!");
while(true) {
tight_loop_contents();
}
}