Petras Saduikis
/
WiiNunchuckReader
A program allowing the output of one or two Wii Nunchucks to be read via I2C and decoded for use.
WiiNunchuckDefs.h@0:d51f5e2478c1, 2009-12-13 (annotated)
- Committer:
- snatch59
- Date:
- Sun Dec 13 12:19:31 2009 +0000
- Revision:
- 0:d51f5e2478c1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
snatch59 | 0:d51f5e2478c1 | 1 | /* |
snatch59 | 0:d51f5e2478c1 | 2 | * WiiNunchuckReader. A program allowing the output of one or two |
snatch59 | 0:d51f5e2478c1 | 3 | * Wii Nunchucks to be read via I2C and decoded for use, using the mbed |
snatch59 | 0:d51f5e2478c1 | 4 | * microcontroller and its associated libraries. |
snatch59 | 0:d51f5e2478c1 | 5 | * |
snatch59 | 0:d51f5e2478c1 | 6 | * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk> |
snatch59 | 0:d51f5e2478c1 | 7 | * |
snatch59 | 0:d51f5e2478c1 | 8 | * This file is part of WiiNunchuckReader. |
snatch59 | 0:d51f5e2478c1 | 9 | * |
snatch59 | 0:d51f5e2478c1 | 10 | * WiiNunchuckReader is free software: you can redistribute it and/or modify |
snatch59 | 0:d51f5e2478c1 | 11 | * it under the terms of the GNU General Public License as published by |
snatch59 | 0:d51f5e2478c1 | 12 | * the Free Software Foundation, either version 3 of the License, or |
snatch59 | 0:d51f5e2478c1 | 13 | * (at your option) any later version. |
snatch59 | 0:d51f5e2478c1 | 14 | * |
snatch59 | 0:d51f5e2478c1 | 15 | * WiiNunchuckReader is distributed in the hope that it will be useful, |
snatch59 | 0:d51f5e2478c1 | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
snatch59 | 0:d51f5e2478c1 | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
snatch59 | 0:d51f5e2478c1 | 18 | * GNU General Public License for more details. |
snatch59 | 0:d51f5e2478c1 | 19 | * |
snatch59 | 0:d51f5e2478c1 | 20 | * You should have received a copy of the GNU General Public License |
snatch59 | 0:d51f5e2478c1 | 21 | * along with WiiNunchuckReader. If not, see <http://www.gnu.org/licenses/>. |
snatch59 | 0:d51f5e2478c1 | 22 | */ |
snatch59 | 0:d51f5e2478c1 | 23 | |
snatch59 | 0:d51f5e2478c1 | 24 | #ifndef SNATCH59_WIINUNCHUCKDEFS_H |
snatch59 | 0:d51f5e2478c1 | 25 | #define SNATCH59_WIINUNCHUCKDEFS_H |
snatch59 | 0:d51f5e2478c1 | 26 | |
snatch59 | 0:d51f5e2478c1 | 27 | // I2C |
snatch59 | 0:d51f5e2478c1 | 28 | #define NUNCHUCK_ADDR 0xA4 // I2C library doesn't right shift the address, so provided shifted |
snatch59 | 0:d51f5e2478c1 | 29 | #define NUNCHUCK_REGADDR 0x40 // relevant register address |
snatch59 | 0:d51f5e2478c1 | 30 | #define NUNCHUCK_READLEN 0x06 // always read this many bytes back |
snatch59 | 0:d51f5e2478c1 | 31 | |
snatch59 | 0:d51f5e2478c1 | 32 | // received byte position |
snatch59 | 0:d51f5e2478c1 | 33 | #define JOY_X 0 |
snatch59 | 0:d51f5e2478c1 | 34 | #define JOY_Y 1 |
snatch59 | 0:d51f5e2478c1 | 35 | #define ACCEL_X 2 |
snatch59 | 0:d51f5e2478c1 | 36 | #define ACCEL_Y 3 |
snatch59 | 0:d51f5e2478c1 | 37 | #define ACCEL_Z 4 |
snatch59 | 0:d51f5e2478c1 | 38 | #define ADDITIONAL 5 |
snatch59 | 0:d51f5e2478c1 | 39 | |
snatch59 | 0:d51f5e2478c1 | 40 | // bitmasks for addition info byte |
snatch59 | 0:d51f5e2478c1 | 41 | #define MASK_CZ 0x03 |
snatch59 | 0:d51f5e2478c1 | 42 | #define MASK_ACCLX1 0x04 |
snatch59 | 0:d51f5e2478c1 | 43 | #define MASK_ACCLX2 0x08 |
snatch59 | 0:d51f5e2478c1 | 44 | #define MASK_ACCLY1 0x10 |
snatch59 | 0:d51f5e2478c1 | 45 | #define MASK_ACCLY2 0x20 |
snatch59 | 0:d51f5e2478c1 | 46 | #define MASK_ACCLZ1 0x40 |
snatch59 | 0:d51f5e2478c1 | 47 | #define MASK_ACCLZ2 0x80 |
snatch59 | 0:d51f5e2478c1 | 48 | |
snatch59 | 0:d51f5e2478c1 | 49 | // timing |
snatch59 | 0:d51f5e2478c1 | 50 | #define I2C_READ_DELAY 0.01 |
snatch59 | 0:d51f5e2478c1 | 51 | |
snatch59 | 0:d51f5e2478c1 | 52 | // I2C status |
snatch59 | 0:d51f5e2478c1 | 53 | #define I2C_OK 0 // zero on success (ACK), non-zero on fail (NACK) for read or write |
snatch59 | 0:d51f5e2478c1 | 54 | |
snatch59 | 0:d51f5e2478c1 | 55 | #endif |