Crates.io | sega-controller |
lib.rs | sega-controller |
version | 0.1.0 |
source | src |
created_at | 2022-11-04 06:42:37.60936 |
updated_at | 2022-11-04 06:42:37.60936 |
description | Embedded driver for reading Sega controller input |
homepage | |
repository | https://github.com/UnderLogic/sega-controller |
max_upload_size | |
id | 704868 |
size | 10,889 |
Embedded driver for reading input from Sega controllers in Rust.
This library utilizes embedded-hal
traits as a platform-agnostic driver.
mega-drive
- includes Sega Mega Drive controllersall
- includes all available featuresuse sega_controller::mega_drive::{MegaDriveButton, MegaDriveController};
use sega_controller::Error;
// Using some kind of hal like `arduino_hal`
// NOTE: You should have pull-up resistors on these pins (10k ohm)
let controller = MegaDriveController::from_pins(
pins.d8.into_output(), // select pin
pins.d2.into_floating_input(), // data pin 0
pins.d3.into_floating_input(), // data pin 1
pins.d4.into_floating_input(), // data pin 2
pins.d5.into_floating_input(), // data pin 3
pins.d6.into_floating_input(), // data pin 4
pins.d7.into_floating_input(), // data pin 5
);
// Only do this once every frame (16ms)
match controller.read_state() {
Ok(state) => {
if state.is_six_button {
// do something special for six-button controllers if you like
}
if state.is_pressed(MegaDriveButton::Start) {
// start button is currently held down
}
}
Err(Error:NotPresent) => {} // controller is not connected
_ => {}
}
The Sega Mega Drive uses a standard DB9 serial port connector for controllers.
CONSOLE PORT (MALE)
,---------------------------,
\ (1) (2) (3) (4) (5) /
\ (6) (7) (8) (9) /
`-----------------------'
CONTROLLER CABLE (FEMALE)
,---------------------------,
\ (5) (4) (3) (2) (1) /
\ (9) (8) (7) (6) /
`-----------------------'
NOTE: The controller cable uses a female connector, where the console has male connectors.
Pin | Description | Mode |
---|---|---|
1 | Data Bit 0 | Input |
2 | Data Bit 1 | Input |
3 | Data Bit 2 | Input |
4 | Data Bit 3 | Input |
5 | +5V VDC | -- |
6 | Data Bit 4 | Input |
7 | Select | Output |
8 | Ground | -- |
9 | Data Bit 5 | Input |
NOTE: The Mode
is from the perspective of the console or microcontroller reading the controller.
Thanks to PlutieDev documentation on how the Mega Drive controller works. Especially useful for polling six-button controllers.
mdbook
+ GitHub Actionsmdbook
+ GitHub Actions