diff options
| -rw-r--r-- | firmware/include/game/blocks.h | 9 | ||||
| -rw-r--r-- | firmware/include/game/game_state.h | 38 | ||||
| -rw-r--r-- | firmware/include/inputs/button.h | 5 | ||||
| -rw-r--r-- | firmware/include/inputs/input.h | 17 | ||||
| -rw-r--r-- | firmware/include/ui/ui.h | 22 | ||||
| -rw-r--r-- | firmware/platformio.ini | 6 | ||||
| -rw-r--r-- | firmware/src/game/game_state.cpp | 9 | ||||
| -rw-r--r-- | firmware/src/inputs/button.cpp | 18 | ||||
| -rw-r--r-- | firmware/src/inputs/input.cpp | 69 | ||||
| -rw-r--r-- | firmware/src/main.cpp | 23 | ||||
| -rw-r--r-- | firmware/src/ui/ui.cpp | 21 |
11 files changed, 219 insertions, 18 deletions
diff --git a/firmware/include/game/blocks.h b/firmware/include/game/blocks.h new file mode 100644 index 0000000..7e9b75f --- /dev/null +++ b/firmware/include/game/blocks.h @@ -0,0 +1,9 @@ +#pragma once + +#include <stdint.h> + +namespace game { + +enum class Block : uint8_t { T, L, J, O, I, Z, S, NONE }; + +} diff --git a/firmware/include/game/game_state.h b/firmware/include/game/game_state.h new file mode 100644 index 0000000..0878545 --- /dev/null +++ b/firmware/include/game/game_state.h @@ -0,0 +1,38 @@ +#pragma once + +#include <array> +#include <stdint.h> + +#include "game/blocks.h" +#include "inputs/input.h" + +namespace game { + +constexpr uint8_t NUM_ROWS { 20 }; +constexpr uint8_t NUM_COLS { 10 }; + +class GameState { +public: + GameState(); + + void update(const inputs::Input& input); + + uint32_t get_score(); + uint8_t get_level(); + + Block get_next_block(); + + Block get_block(uint8_t row, uint8_t col); + +private: + void move_down(); + void move_right(); + void move_left(); + + void rotate_right(); + void rotate_left(); + + std::array<Block, NUM_ROWS * NUM_COLS> grid; +}; + +} diff --git a/firmware/include/inputs/button.h b/firmware/include/inputs/button.h index c3530ae..908ea22 100644 --- a/firmware/include/inputs/button.h +++ b/firmware/include/inputs/button.h @@ -1,6 +1,6 @@ #pragma once -#include <cstdint> +#include <stdint.h> namespace inputs { @@ -8,9 +8,12 @@ class Button { public: Button(uint8_t pin); + void init(); + bool is_pressed(); private: + uint8_t pin; }; } diff --git a/firmware/include/inputs/input.h b/firmware/include/inputs/input.h index 7899ce7..116bd9c 100644 --- a/firmware/include/inputs/input.h +++ b/firmware/include/inputs/input.h @@ -6,7 +6,14 @@ namespace inputs { class Input { public: - Input(/* pins */); + Input( + uint8_t down_pin, + uint8_t up_pin, + uint8_t right_pin, + uint8_t left_pin, + uint8_t a_pin, + uint8_t b_pin, + uint8_t pause_pin); void init(); @@ -16,8 +23,16 @@ public: bool left_pressed(); bool a_pressed(); bool b_pressed(); + bool pause_pressed(); private: + Button down; + Button up; + Button left; + Button right; + Button a; + Button b; + Button pause; }; } diff --git a/firmware/include/ui/ui.h b/firmware/include/ui/ui.h new file mode 100644 index 0000000..44b4555 --- /dev/null +++ b/firmware/include/ui/ui.h @@ -0,0 +1,22 @@ +#pragma once + +#include <Adafruit_ST7735.h> +#include <stdint.h> + +#include "game/game_state.h" + +namespace ui { + +class UI { +public: + UI(int8_t tft_cs, int8_t tft_rst, int8_t tft_dc); + + void init(); + + void render_screen(const game::GameState& state); + +private: + Adafruit_ST7735 tft; +}; + +} diff --git a/firmware/platformio.ini b/firmware/platformio.ini index e0e6696..229adb5 100644 --- a/firmware/platformio.ini +++ b/firmware/platformio.ini @@ -5,3 +5,9 @@ platform_packages = framework-arduinoespressif32-libs @ https://github.com/espressif/arduino-esp32/releases/download/3.0.2/esp32-arduino-libs-3.0.2.zip board = seeed_xiao_esp32c6 framework = arduino +lib_deps = + spi + wire + adafruit/Adafruit BusIO@^1.16.2 + adafruit/Adafruit GFX Library@^1.11.11 + adafruit/Adafruit ST7735 and ST7789 Library@^1.10.4 diff --git a/firmware/src/game/game_state.cpp b/firmware/src/game/game_state.cpp new file mode 100644 index 0000000..219c627 --- /dev/null +++ b/firmware/src/game/game_state.cpp @@ -0,0 +1,9 @@ +#include "game/game_state.h" + +namespace game { + +GameState::GameState() {} + +void GameState::update(const inputs::Input& input) {} + +} diff --git a/firmware/src/inputs/button.cpp b/firmware/src/inputs/button.cpp new file mode 100644 index 0000000..ed02e32 --- /dev/null +++ b/firmware/src/inputs/button.cpp @@ -0,0 +1,18 @@ +#include "inputs/button.h" + +namespace inputs { + +Button::Button(uint8_t pin) + : pin { pin } +{ +} + +void Button::init() {} + +bool Button::is_pressed() +{ + // TODO + return false; +} + +} diff --git a/firmware/src/inputs/input.cpp b/firmware/src/inputs/input.cpp new file mode 100644 index 0000000..6f4109b --- /dev/null +++ b/firmware/src/inputs/input.cpp @@ -0,0 +1,69 @@ +#include "inputs/input.h" + +namespace inputs { + +Input::Input( + uint8_t down_pin, + uint8_t up_pin, + uint8_t right_pin, + uint8_t left_pin, + uint8_t a_pin, + uint8_t b_pin, + uint8_t pause_pin) + : down { down_pin } + , up { up_pin } + , right { right_pin } + , left { left_pin } + , a { a_pin } + , b { b_pin } + , pause { pause_pin } +{ +} + +void Input::init() +{ + down.init(); + up.init(); + left.init(); + right.init(); + a.init(); + b.init(); + pause.init(); +} + +bool Input::down_pressed() +{ + return down.is_pressed(); +} + +bool Input::up_pressed() +{ + return up.is_pressed(); +} + +bool Input::left_pressed() +{ + return left.is_pressed(); +} + +bool Input::right_pressed() +{ + return right.is_pressed(); +} + +bool Input::a_pressed() +{ + return a.is_pressed(); +} + +bool Input::b_pressed() +{ + return b.is_pressed(); +} + +bool Input::pause_pressed() +{ + return pause.is_pressed(); +} + +} diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index c512327..cb41c45 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -1,31 +1,22 @@ #include <Arduino.h> +#include "game/game_state.h" #include "inputs/input.h" +#include "ui/ui.h" game::GameState state {}; -ui::UI ui { /* pins */ }; -inputs::Input input { /* pins */ }; +ui::UI screen { 0, 0, 0 }; // TODO: add correct pins +inputs::Input input { 0, 0, 0, 0, 0, 0, 0 }; // TODO: add correct pins void setup() { - state.init(); input.init(); - ui.init(); + screen.init(); } void loop() { delay(1); - - if (input.down_pressed()) { - // TODO - } - - // update game state - // render game state - - // every second - // automatically move down - // update game state - // render game state + state.update(input); + screen.render_screen(state); } diff --git a/firmware/src/ui/ui.cpp b/firmware/src/ui/ui.cpp new file mode 100644 index 0000000..af27b37 --- /dev/null +++ b/firmware/src/ui/ui.cpp @@ -0,0 +1,21 @@ +#include "ui/ui.h" +#include "game/game_state.h" + +namespace ui { + +UI::UI(int8_t tft_cs, int8_t tft_rst, int8_t tft_dc) + : tft { tft_cs, tft_rst, tft_dc } +{ +} + +void UI::init() +{ + tft.initR(INITR_BLACKTAB); +} + +void UI::render_screen(const game::GameState& state) +{ + // TODO +} + +} |