pub struct ControllerState {
pub up: Input<'static>,
pub down: Input<'static>,
pub left: Input<'static>,
pub right: Input<'static>,
pub a: Input<'static>,
pub b: Input<'static>,
pub c: Input<'static>,
pub d: Input<'static>,
pub select: Input<'static>,
pub start: Input<'static>,
}Expand description
State of all physical input buttons on the Lilka game console.
Each field is an esp-hal [Input] pin configured with an internal pull-up
resistor. The logic is active-low:
is_low()→ button is pressed.is_high()→ button is released.
§Layout
[UP GPIO38]
[LEFT GPIO39] [DOWN GPIO41] [RIGHT GPIO40]
[A GPIO5] [B GPIO6] [C GPIO10] [D GPIO9]
[SELECT GPIO0] [START GPIO4]§Example — D-pad and buttons in a game loop
use lilkaoxide::prelude::*;
loop {
if lilka.controller.up.is_low() {
// move player up
}
if lilka.controller.a.is_low() {
// action A
}
if lilka.controller.start.is_low() {
// pause menu
}
}Fields§
§up: Input<'static>D-pad up — GPIO38, active-low.
down: Input<'static>D-pad down — GPIO41, active-low.
left: Input<'static>D-pad left — GPIO39, active-low.
right: Input<'static>D-pad right — GPIO40, active-low.
a: Input<'static>Action button A — GPIO5, active-low.
b: Input<'static>Action button B — GPIO6, active-low.
c: Input<'static>Action button C — GPIO10, active-low.
d: Input<'static>Action button D — GPIO9, active-low.
select: Input<'static>Select button — GPIO0, active-low.
start: Input<'static>Start button — GPIO4, active-low.
Implementations§
Source§impl ControllerState
impl ControllerState
Sourcepub fn init_controller(
gpio5: GPIO5<'static>,
gpio6: GPIO6<'static>,
gpio10: GPIO10<'static>,
gpio9: GPIO9<'static>,
gpio38: GPIO38<'static>,
gpio41: GPIO41<'static>,
gpio39: GPIO39<'static>,
gpio40: GPIO40<'static>,
gpio0: GPIO0<'static>,
gpio4: GPIO4<'static>,
) -> Self
pub fn init_controller( gpio5: GPIO5<'static>, gpio6: GPIO6<'static>, gpio10: GPIO10<'static>, gpio9: GPIO9<'static>, gpio38: GPIO38<'static>, gpio41: GPIO41<'static>, gpio39: GPIO39<'static>, gpio40: GPIO40<'static>, gpio0: GPIO0<'static>, gpio4: GPIO4<'static>, ) -> Self
Initialises all controller GPIO pins as pull-up inputs.
This function is called internally by crate::Lilka::init — you should
not need to call it directly. It moves the concrete GPIO peripheral tokens
into [Input] handles with Pull::Up so that pressing a button drives the
pin to ground (active-low).
§Pin assignment
| Button | GPIO | Field |
|---|---|---|
| A | 5 | ControllerState::a |
| B | 6 | ControllerState::b |
| C | 10 | ControllerState::c |
| D | 9 | ControllerState::d |
| Up | 38 | ControllerState::up |
| Down | 41 | ControllerState::down |
| Left | 39 | ControllerState::left |
| Right | 40 | ControllerState::right |
| Select | 0 | ControllerState::select |
| Start | 4 | ControllerState::start |