|
| 1 | +# Rust Wiimote Extension-Controller (Nunchuck/classic controller) Driver |
| 2 | + |
| 3 | +This is a platform agnostic Rust driver for Wiimote Extension controllers (Nunchuk, Classic, Classic Pro, NES Classic, SNES Classic, and clones) using the [`embedded-hal`] traits. |
| 4 | + |
| 5 | +This driver allows you to read all axes and buttons for Wiimote Extension controllers |
| 6 | + |
| 7 | +## Physical protocol details |
| 8 | + |
| 9 | +Wiimote extension controllers are designed to talk to a Wiimote over an I2C interface at 3.3V. |
| 10 | +The official controllers are capable of operating in fast-mode (400Khz) though some clones require normal-mode (100Khz). |
| 11 | +The protocol is quite simple - it's not officially documented, but it has been reverse-engineered. |
| 12 | + |
| 13 | +- http://wiibrew.org/wiki/Wiimote/Extension_Controllers |
| 14 | +- http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck |
| 15 | +- http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Classic_Controller |
| 16 | + |
| 17 | +High Resolution mode is a recent addition and was only discovered once the NES Classic console was released. It is described here: |
| 18 | +- https://www.raphnet-tech.com/support/classic_controller_high_res/ |
| 19 | + |
| 20 | + |
| 21 | +Wii Motion Plus support is planned, both in standalone and combo mode |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +To use this driver, import this crate and an `embedded_hal` implementation, |
| 26 | +then instantiate the appropriate device. |
| 27 | + |
| 28 | +```rust |
| 29 | +use wii_ext::classic::Classic; |
| 30 | +use ::I2C; // insert an include for your HAL i2c peripheral name here |
| 31 | + |
| 32 | +fn main() { |
| 33 | + let i2c = I2C::new(); // insert your HAL i2c init here |
| 34 | + let mut delay = cortex_m::delay::Delay::new(); // some delay source as well |
| 35 | + // Create, initialise and calibrate the controller |
| 36 | + let mut controller = Classic::new(i2c, &mut delay).unwrap(); |
| 37 | + // Enable hi-resolution mode. This also updates calibration |
| 38 | + controller.enable_hires(&mut delay).unwrap(); |
| 39 | + loop { |
| 40 | + let input = controller.read_blocking(&mut delay).unwrap(); |
| 41 | + // You can read individual buttons... |
| 42 | + let a = input.button_a; |
| 43 | + let b = input.button_b; |
| 44 | + // or joystick axes |
| 45 | + let x = input.joysick_left_x; |
| 46 | + let y = input.joysick_left_y; |
| 47 | + // the data structs optionally implement defmt::debug |
| 48 | + info!("{:?}", read); |
| 49 | + // Calibration can be manually performed via |
| 50 | + controller.update_calibration(); |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +## Status |
| 56 | + |
| 57 | +- Nunchuk is functional, no calibration yet |
| 58 | +- Classic controllers supported in regular and HD mode |
| 59 | + |
| 60 | +## Support |
| 61 | + |
| 62 | +For questions, issues, feature requests like compatibility with other Wiimote extension controllers please file an |
| 63 | +[issue in the github project](https://github.com/9names/wii-ext-rs/issues). |
| 64 | + |
| 65 | +## License |
| 66 | + |
| 67 | +Nunchuk portions of this crate are largely derived from |
| 68 | +https://github.com/rust-embedded/rust-i2cdev/blob/master/examples/nunchuck.rs |
| 69 | +Copyright 2015, Paul Osborne <[email protected]> |
| 70 | + |
| 71 | +Licensed under either of |
| 72 | + |
| 73 | + * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or |
| 74 | + http://www.apache.org/licenses/LICENSE-2.0) |
| 75 | + * MIT license ([LICENSE-MIT](LICENSE-MIT) or |
| 76 | + http://opensource.org/licenses/MIT) |
| 77 | + |
| 78 | +at your option. |
| 79 | + |
| 80 | +### Contributing |
| 81 | + |
| 82 | +Unless you explicitly state otherwise, any contribution intentionally submitted |
| 83 | +for inclusion in the work by you, as defined in the Apache-2.0 license, shall |
| 84 | +be dual licensed as above, without any additional terms or conditions. |
| 85 | + |
| 86 | +[`embedded-hal`]: https://github.com/rust-embedded/embedded-hal |
0 commit comments