code de start qui marche a la fin du premier match, base pour la suite
Fork of CRAC-Strat_2017_homologation_petit_rob by
mbed/I2C.h@22:a466d08ac42b, 2017-05-25 (annotated)
- Committer:
- clementlignie
- Date:
- Thu May 25 14:40:49 2017 +0000
- Revision:
- 22:a466d08ac42b
- Parent:
- 0:ad97421fb1fb
code de strart qui marche, le 25-05, a 16h40, apres le premier match
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
antbig | 0:ad97421fb1fb | 1 | /* mbed Microcontroller Library - I2C |
antbig | 0:ad97421fb1fb | 2 | * Copyright (c) 2007-2011 ARM Limited. All rights reserved. |
antbig | 0:ad97421fb1fb | 3 | */ |
antbig | 0:ad97421fb1fb | 4 | |
antbig | 0:ad97421fb1fb | 5 | #ifndef MBED_I2C_H |
antbig | 0:ad97421fb1fb | 6 | #define MBED_I2C_H |
antbig | 0:ad97421fb1fb | 7 | |
antbig | 0:ad97421fb1fb | 8 | #include "device.h" |
antbig | 0:ad97421fb1fb | 9 | |
antbig | 0:ad97421fb1fb | 10 | #if DEVICE_I2C |
antbig | 0:ad97421fb1fb | 11 | |
antbig | 0:ad97421fb1fb | 12 | #include "platform.h" |
antbig | 0:ad97421fb1fb | 13 | #include "PinNames.h" |
antbig | 0:ad97421fb1fb | 14 | #include "PeripheralNames.h" |
antbig | 0:ad97421fb1fb | 15 | #include "Base.h" |
antbig | 0:ad97421fb1fb | 16 | |
antbig | 0:ad97421fb1fb | 17 | namespace mbed { |
antbig | 0:ad97421fb1fb | 18 | |
antbig | 0:ad97421fb1fb | 19 | /* Class: I2C |
antbig | 0:ad97421fb1fb | 20 | * An I2C Master, used for communicating with I2C slave devices |
antbig | 0:ad97421fb1fb | 21 | * |
antbig | 0:ad97421fb1fb | 22 | * Example: |
antbig | 0:ad97421fb1fb | 23 | * > // Read from I2C slave at address 0x62 |
antbig | 0:ad97421fb1fb | 24 | * > |
antbig | 0:ad97421fb1fb | 25 | * > #include "mbed.h" |
antbig | 0:ad97421fb1fb | 26 | * > |
antbig | 0:ad97421fb1fb | 27 | * > I2C i2c(p28, p27); |
antbig | 0:ad97421fb1fb | 28 | * > |
antbig | 0:ad97421fb1fb | 29 | * > int main() { |
antbig | 0:ad97421fb1fb | 30 | * > int address = 0x62; |
antbig | 0:ad97421fb1fb | 31 | * > char data[2]; |
antbig | 0:ad97421fb1fb | 32 | * > i2c.read(address, data, 2); |
antbig | 0:ad97421fb1fb | 33 | * > } |
antbig | 0:ad97421fb1fb | 34 | */ |
antbig | 0:ad97421fb1fb | 35 | class I2C : public Base { |
antbig | 0:ad97421fb1fb | 36 | |
antbig | 0:ad97421fb1fb | 37 | public: |
antbig | 0:ad97421fb1fb | 38 | |
antbig | 0:ad97421fb1fb | 39 | enum RxStatus { |
antbig | 0:ad97421fb1fb | 40 | NoData |
antbig | 0:ad97421fb1fb | 41 | , MasterGeneralCall |
antbig | 0:ad97421fb1fb | 42 | , MasterWrite |
antbig | 0:ad97421fb1fb | 43 | , MasterRead |
antbig | 0:ad97421fb1fb | 44 | }; |
antbig | 0:ad97421fb1fb | 45 | |
antbig | 0:ad97421fb1fb | 46 | enum Acknowledge { |
antbig | 0:ad97421fb1fb | 47 | NoACK = 0 |
antbig | 0:ad97421fb1fb | 48 | , ACK = 1 |
antbig | 0:ad97421fb1fb | 49 | }; |
antbig | 0:ad97421fb1fb | 50 | |
antbig | 0:ad97421fb1fb | 51 | /* Constructor: I2C |
antbig | 0:ad97421fb1fb | 52 | * Create an I2C Master interface, connected to the specified pins |
antbig | 0:ad97421fb1fb | 53 | * |
antbig | 0:ad97421fb1fb | 54 | * Variables: |
antbig | 0:ad97421fb1fb | 55 | * sda - I2C data line pin |
antbig | 0:ad97421fb1fb | 56 | * scl - I2C clock line pin |
antbig | 0:ad97421fb1fb | 57 | */ |
antbig | 0:ad97421fb1fb | 58 | I2C(PinName sda, PinName scl, const char *name = NULL); |
antbig | 0:ad97421fb1fb | 59 | |
antbig | 0:ad97421fb1fb | 60 | /* Function: frequency |
antbig | 0:ad97421fb1fb | 61 | * Set the frequency of the I2C interface |
antbig | 0:ad97421fb1fb | 62 | * |
antbig | 0:ad97421fb1fb | 63 | * Variables: |
antbig | 0:ad97421fb1fb | 64 | * hz - The bus frequency in hertz |
antbig | 0:ad97421fb1fb | 65 | */ |
antbig | 0:ad97421fb1fb | 66 | void frequency(int hz); |
antbig | 0:ad97421fb1fb | 67 | |
antbig | 0:ad97421fb1fb | 68 | /* Function: read |
antbig | 0:ad97421fb1fb | 69 | * Read from an I2C slave |
antbig | 0:ad97421fb1fb | 70 | * |
antbig | 0:ad97421fb1fb | 71 | * Performs a complete read transaction. The bottom bit of |
antbig | 0:ad97421fb1fb | 72 | * the address is forced to 1 to indicate a read. |
antbig | 0:ad97421fb1fb | 73 | * |
antbig | 0:ad97421fb1fb | 74 | * Variables: |
antbig | 0:ad97421fb1fb | 75 | * address - 8-bit I2C slave address [ addr | 1 ] |
antbig | 0:ad97421fb1fb | 76 | * data - Pointer to the byte-array to read data in to |
antbig | 0:ad97421fb1fb | 77 | * length - Number of bytes to read |
antbig | 0:ad97421fb1fb | 78 | * repeated - Repeated start, true - don't send stop at end |
antbig | 0:ad97421fb1fb | 79 | * returns - 0 on success (ack), or non-0 on failure (nack) |
antbig | 0:ad97421fb1fb | 80 | */ |
antbig | 0:ad97421fb1fb | 81 | int read(int address, char *data, int length, bool repeated = false); |
antbig | 0:ad97421fb1fb | 82 | |
antbig | 0:ad97421fb1fb | 83 | /* Function: read |
antbig | 0:ad97421fb1fb | 84 | * Read a single byte from the I2C bus |
antbig | 0:ad97421fb1fb | 85 | * |
antbig | 0:ad97421fb1fb | 86 | * Variables: |
antbig | 0:ad97421fb1fb | 87 | * ack - indicates if the byte is to be acknowledged (1 = acknowledge) |
antbig | 0:ad97421fb1fb | 88 | * returns - the byte read |
antbig | 0:ad97421fb1fb | 89 | */ |
antbig | 0:ad97421fb1fb | 90 | int read(int ack); |
antbig | 0:ad97421fb1fb | 91 | |
antbig | 0:ad97421fb1fb | 92 | /* Function: write |
antbig | 0:ad97421fb1fb | 93 | * Write to an I2C slave |
antbig | 0:ad97421fb1fb | 94 | * |
antbig | 0:ad97421fb1fb | 95 | * Performs a complete write transaction. The bottom bit of |
antbig | 0:ad97421fb1fb | 96 | * the address is forced to 0 to indicate a write. |
antbig | 0:ad97421fb1fb | 97 | * |
antbig | 0:ad97421fb1fb | 98 | * Variables: |
antbig | 0:ad97421fb1fb | 99 | * address - 8-bit I2C slave address [ addr | 0 ] |
antbig | 0:ad97421fb1fb | 100 | * data - Pointer to the byte-array data to send |
antbig | 0:ad97421fb1fb | 101 | * length - Number of bytes to send |
antbig | 0:ad97421fb1fb | 102 | * repeated - Repeated start, true - do not send stop at end |
antbig | 0:ad97421fb1fb | 103 | * returns - 0 on success (ack), or non-0 on failure (nack) |
antbig | 0:ad97421fb1fb | 104 | */ |
antbig | 0:ad97421fb1fb | 105 | int write(int address, const char *data, int length, bool repeated = false); |
antbig | 0:ad97421fb1fb | 106 | |
antbig | 0:ad97421fb1fb | 107 | /* Function: write |
antbig | 0:ad97421fb1fb | 108 | * Write single byte out on the I2C bus |
antbig | 0:ad97421fb1fb | 109 | * |
antbig | 0:ad97421fb1fb | 110 | * Variables: |
antbig | 0:ad97421fb1fb | 111 | * data - data to write out on bus |
antbig | 0:ad97421fb1fb | 112 | * returns - a '1' if an ACK was received, a '0' otherwise |
antbig | 0:ad97421fb1fb | 113 | */ |
antbig | 0:ad97421fb1fb | 114 | int write(int data); |
antbig | 0:ad97421fb1fb | 115 | |
antbig | 0:ad97421fb1fb | 116 | /* Function: start |
antbig | 0:ad97421fb1fb | 117 | * Creates a start condition on the I2C bus |
antbig | 0:ad97421fb1fb | 118 | */ |
antbig | 0:ad97421fb1fb | 119 | |
antbig | 0:ad97421fb1fb | 120 | void start(void); |
antbig | 0:ad97421fb1fb | 121 | |
antbig | 0:ad97421fb1fb | 122 | /* Function: stop |
antbig | 0:ad97421fb1fb | 123 | * Creates a stop condition on the I2C bus |
antbig | 0:ad97421fb1fb | 124 | */ |
antbig | 0:ad97421fb1fb | 125 | void stop(void); |
antbig | 0:ad97421fb1fb | 126 | |
antbig | 0:ad97421fb1fb | 127 | protected: |
antbig | 0:ad97421fb1fb | 128 | |
antbig | 0:ad97421fb1fb | 129 | void aquire(); |
antbig | 0:ad97421fb1fb | 130 | |
antbig | 0:ad97421fb1fb | 131 | I2CName _i2c; |
antbig | 0:ad97421fb1fb | 132 | static I2C *_owner; |
antbig | 0:ad97421fb1fb | 133 | int _hz; |
antbig | 0:ad97421fb1fb | 134 | |
antbig | 0:ad97421fb1fb | 135 | }; |
antbig | 0:ad97421fb1fb | 136 | |
antbig | 0:ad97421fb1fb | 137 | } // namespace mbed |
antbig | 0:ad97421fb1fb | 138 | |
antbig | 0:ad97421fb1fb | 139 | #endif |
antbig | 0:ad97421fb1fb | 140 | |
antbig | 0:ad97421fb1fb | 141 | #endif |
antbig | 0:ad97421fb1fb | 142 |