-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #842 from Daft-Freak/pico-gpio-input
Generic GPIO input driver
- Loading branch information
Showing
15 changed files
with
255 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
set(BLIT_BOARD_NAME "Display Pack") | ||
|
||
blit_driver(display st7789) | ||
blit_driver(input gpio_abxy) | ||
blit_driver(input gpio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
set(BLIT_BOARD_NAME "Display Pack 2.0") | ||
|
||
blit_driver(display st7789) | ||
blit_driver(input gpio_abxy) | ||
blit_driver(input gpio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
#define BUTTON_A_PIN 12 | ||
#define BUTTON_B_PIN 13 | ||
#define BUTTON_X_PIN 14 | ||
#define BUTTON_Y_PIN 15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ set(BLIT_BOARD_DEFINITIONS | |
) | ||
|
||
blit_driver(display st7789) | ||
blit_driver(input tufty) | ||
blit_driver(input gpio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// generic GPIO buttons | ||
#include "input.hpp" | ||
#include "hardware/gpio.h" | ||
|
||
#include "pico/binary_info.h" | ||
|
||
#include "config.h" | ||
|
||
#include "engine/api_private.hpp" | ||
#include "engine/input.hpp" | ||
|
||
// order matches blit::Button | ||
static constexpr int button_io[] { | ||
BUTTON_LEFT_PIN, | ||
BUTTON_RIGHT_PIN, | ||
BUTTON_UP_PIN, | ||
BUTTON_DOWN_PIN, | ||
|
||
BUTTON_A_PIN, | ||
BUTTON_B_PIN, | ||
BUTTON_X_PIN, | ||
BUTTON_Y_PIN, | ||
|
||
BUTTON_HOME_PIN, | ||
BUTTON_MENU_PIN, | ||
BUTTON_JOYSTICK_PIN, | ||
}; | ||
|
||
static constexpr bool button_active[] { | ||
BUTTON_LEFT_ACTIVE_HIGH, | ||
BUTTON_RIGHT_ACTIVE_HIGH, | ||
BUTTON_UP_ACTIVE_HIGH, | ||
BUTTON_DOWN_ACTIVE_HIGH, | ||
|
||
BUTTON_A_ACTIVE_HIGH, | ||
BUTTON_B_ACTIVE_HIGH, | ||
BUTTON_X_ACTIVE_HIGH, | ||
BUTTON_Y_ACTIVE_HIGH, | ||
|
||
BUTTON_HOME_ACTIVE_HIGH, | ||
BUTTON_MENU_ACTIVE_HIGH, | ||
BUTTON_JOYSTICK_ACTIVE_HIGH, | ||
}; | ||
|
||
static void init_button(int pin, bool active_high) { | ||
gpio_set_function(pin, GPIO_FUNC_SIO); | ||
gpio_set_dir(pin, GPIO_IN); | ||
|
||
if(active_high) | ||
gpio_pull_down(pin); | ||
else | ||
gpio_pull_up(pin); | ||
} | ||
|
||
void init_input() { | ||
for(size_t i = 0; i < std::size(button_io); i++) | ||
init_button(button_io[i], button_active[i]); | ||
|
||
// declare pins | ||
#define BUTTON_BI_DECL(pin, btn) bi_decl(bi_1pin_with_name(pin, #btn" Button")); | ||
BUTTON_LEFT_BI_DECL | ||
BUTTON_RIGHT_BI_DECL | ||
BUTTON_UP_BI_DECL | ||
BUTTON_DOWN_BI_DECL | ||
BUTTON_A_BI_DECL | ||
BUTTON_B_BI_DECL | ||
BUTTON_X_BI_DECL | ||
BUTTON_Y_BI_DECL | ||
BUTTON_HOME_BI_DECL | ||
BUTTON_MENU_BI_DECL | ||
BUTTON_JOYSTICK_BI_DECL | ||
#undef BUTTON_BI_DECL | ||
} | ||
|
||
void update_input() { | ||
auto io = gpio_get_all(); | ||
|
||
uint32_t new_buttons = 0; | ||
|
||
for(size_t i = 0; i < std::size(button_io); i++) { | ||
// pin not defined, skip | ||
if(button_io[i] == -1) | ||
continue; | ||
|
||
bool pin_state = !!(io & (1 << button_io[i])); | ||
|
||
if(pin_state == button_active[i]) | ||
new_buttons |= 1 << i; | ||
} | ||
|
||
blit::api.buttons = new_buttons; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.