Skip to content

Commit

Permalink
pico: add tufty2040 config
Browse files Browse the repository at this point in the history
This is what the rotation/8bit changes were for
  • Loading branch information
Daft-Freak committed Oct 2, 2023
1 parent 4b4b9d4 commit 8221dc2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
8 changes: 8 additions & 0 deletions 32blit-pico/board/tufty2040/config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(BLIT_BOARD_NAME "Tufty 2040")

set(BLIT_BOARD_DEFINITIONS
PICO_FLASH_SIZE_BYTES=8388608
)

blit_driver(display st7789)
blit_driver(input tufty)
17 changes: 17 additions & 0 deletions 32blit-pico/board/tufty2040/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#define DISPLAY_WIDTH 320



#define ST7789_8BIT
#define ST7789_ROTATE_180
#define LCD_CS_PIN 10
#define LCD_DC_PIN 11
#define LCD_SCK_PIN 12 // WR
#define LCD_RD_PIN 13
#define LCD_MOSI_PIN 14 // DB0
#define LCD_BACKLIGHT_PIN 2
// #define LCD_VSYNC_PIN 11 // shared

// there is a white LED
63 changes: 63 additions & 0 deletions 32blit-pico/input_tufty.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "input.hpp"

#include "hardware/gpio.h"

#include "pico/binary_info.h"

#include "engine/api_private.hpp"
#include "engine/input.hpp"

enum class ButtonIO {
UP = 22,
DOWN = 6,

A = 7,
B = 8,
C = 9,
USER = 23, // USER_SW
};

static void init_button(ButtonIO b) {
int gpio = static_cast<int>(b);
gpio_set_function(gpio, GPIO_FUNC_SIO);
gpio_set_dir(gpio, GPIO_IN);
gpio_pull_down(gpio);
}

inline bool get_button(ButtonIO b) {
auto gpio = static_cast<int>(b);

if(b == ButtonIO::USER) // USER_SW goes the other way
return !gpio_get(gpio);

return gpio_get(gpio);
}

void init_input() {
init_button(ButtonIO::UP);
init_button(ButtonIO::DOWN);
init_button(ButtonIO::A);
init_button(ButtonIO::B);
init_button(ButtonIO::C);
init_button(ButtonIO::USER);

#define BUTTON_DECL(btn) bi_decl(bi_1pin_with_name(static_cast<int>(ButtonIO::btn), #btn" Button"));
BUTTON_DECL(UP)
BUTTON_DECL(DOWN)
BUTTON_DECL(A)
BUTTON_DECL(B)
BUTTON_DECL(C)
BUTTON_DECL(USER)
#undef BUTTON_DECL
}

void update_input() {
using namespace blit;

api.buttons = (get_button(ButtonIO::UP) ? uint32_t(Button::DPAD_UP) : 0)
| (get_button(ButtonIO::DOWN) ? uint32_t(Button::DPAD_DOWN) : 0)
| (get_button(ButtonIO::A) ? uint32_t(Button::A) : 0)
| (get_button(ButtonIO::B) ? uint32_t(Button::B) : 0)
| (get_button(ButtonIO::C) ? uint32_t(Button::X) : 0)
| (get_button(ButtonIO::USER) ? uint32_t(Button::Y) : 0);
}

0 comments on commit 8221dc2

Please sign in to comment.