Forked to avoid changing the publioc repo
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
inc/drivers/MicroBitI2C.h@1:8aa5cdb4ab67, 2016-04-07 (annotated)
- Committer:
- Jonathan Austin
- Date:
- Thu Apr 07 01:33:22 2016 +0100
- Revision:
- 1:8aa5cdb4ab67
- Child:
- 4:9fbeeb89de59
Synchronized with git rev 55cb9199
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jonathan Austin |
1:8aa5cdb4ab67 | 1 | /* |
Jonathan Austin |
1:8aa5cdb4ab67 | 2 | The MIT License (MIT) |
Jonathan Austin |
1:8aa5cdb4ab67 | 3 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
Jonathan Austin |
1:8aa5cdb4ab67 | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
Jonathan Austin |
1:8aa5cdb4ab67 | 6 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
Jonathan Austin |
1:8aa5cdb4ab67 | 8 | copy of this software and associated documentation files (the "Software"), |
Jonathan Austin |
1:8aa5cdb4ab67 | 9 | to deal in the Software without restriction, including without limitation |
Jonathan Austin |
1:8aa5cdb4ab67 | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Jonathan Austin |
1:8aa5cdb4ab67 | 11 | and/or sell copies of the Software, and to permit persons to whom the |
Jonathan Austin |
1:8aa5cdb4ab67 | 12 | Software is furnished to do so, subject to the following conditions: |
Jonathan Austin |
1:8aa5cdb4ab67 | 13 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 14 | The above copyright notice and this permission notice shall be included in |
Jonathan Austin |
1:8aa5cdb4ab67 | 15 | all copies or substantial portions of the Software. |
Jonathan Austin |
1:8aa5cdb4ab67 | 16 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Jonathan Austin |
1:8aa5cdb4ab67 | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Jonathan Austin |
1:8aa5cdb4ab67 | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
Jonathan Austin |
1:8aa5cdb4ab67 | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
Jonathan Austin |
1:8aa5cdb4ab67 | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
Jonathan Austin |
1:8aa5cdb4ab67 | 23 | DEALINGS IN THE SOFTWARE. |
Jonathan Austin |
1:8aa5cdb4ab67 | 24 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 25 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 26 | #ifndef MICROBIT_I2C_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 27 | #define MICROBIT_I2C_H |
Jonathan Austin |
1:8aa5cdb4ab67 | 28 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 29 | #include "mbed.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 30 | #include "MicroBitConfig.h" |
Jonathan Austin |
1:8aa5cdb4ab67 | 31 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 32 | #define MICROBIT_I2C_MAX_RETRIES 9 |
Jonathan Austin |
1:8aa5cdb4ab67 | 33 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 34 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 35 | * Class definition for MicroBitI2C. |
Jonathan Austin |
1:8aa5cdb4ab67 | 36 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 37 | * Presents a wrapped mbed call to capture failed I2C operations caused by a known silicon bug in the nrf51822. |
Jonathan Austin |
1:8aa5cdb4ab67 | 38 | * Attempts to automatically reset and restart the I2C hardware if this case is detected. |
Jonathan Austin |
1:8aa5cdb4ab67 | 39 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 40 | * For reference see PAN56 in: |
Jonathan Austin |
1:8aa5cdb4ab67 | 41 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 42 | * https://www.nordicsemi.com/eng/nordic/Products/nRF51822/PAN-nRF51822/24634 |
Jonathan Austin |
1:8aa5cdb4ab67 | 43 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 44 | * v2.0 through to v2.4 |
Jonathan Austin |
1:8aa5cdb4ab67 | 45 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 46 | class MicroBitI2C : public I2C |
Jonathan Austin |
1:8aa5cdb4ab67 | 47 | { |
Jonathan Austin |
1:8aa5cdb4ab67 | 48 | uint8_t retries; |
Jonathan Austin |
1:8aa5cdb4ab67 | 49 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 50 | public: |
Jonathan Austin |
1:8aa5cdb4ab67 | 51 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 52 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 53 | * Constructor. |
Jonathan Austin |
1:8aa5cdb4ab67 | 54 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 55 | * Create an instance of MicroBitI2C for I2C communication. |
Jonathan Austin |
1:8aa5cdb4ab67 | 56 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 57 | * @param sda the Pin to be used for SDA |
Jonathan Austin |
1:8aa5cdb4ab67 | 58 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 59 | * @param scl the Pin to be used for SCL |
Jonathan Austin |
1:8aa5cdb4ab67 | 60 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 61 | * @code |
Jonathan Austin |
1:8aa5cdb4ab67 | 62 | * MicroBitI2C i2c(I2C_SDA0, I2C_SCL0); |
Jonathan Austin |
1:8aa5cdb4ab67 | 63 | * @endcode |
Jonathan Austin |
1:8aa5cdb4ab67 | 64 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 65 | * @note This class presents a wrapped mbed call to capture failed I2C operations caused by a known silicon bug in the nrf51822. |
Jonathan Austin |
1:8aa5cdb4ab67 | 66 | * Attempts to automatically reset and restart the I2C hardware if this case is detected. |
Jonathan Austin |
1:8aa5cdb4ab67 | 67 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 68 | * For reference see PAN56 in: |
Jonathan Austin |
1:8aa5cdb4ab67 | 69 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 70 | * https://www.nordicsemi.com/eng/nordic/Products/nRF51822/PAN-nRF51822/24634 |
Jonathan Austin |
1:8aa5cdb4ab67 | 71 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 72 | * v2.0 through to v2.4 |
Jonathan Austin |
1:8aa5cdb4ab67 | 73 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 74 | MicroBitI2C(PinName sda, PinName scl); |
Jonathan Austin |
1:8aa5cdb4ab67 | 75 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 76 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 77 | * Performs a complete read transaction. The bottom bit of the address is forced to 1 to indicate a read. |
Jonathan Austin |
1:8aa5cdb4ab67 | 78 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 79 | * @param address 8-bit I2C slave address [ addr | 1 ] |
Jonathan Austin |
1:8aa5cdb4ab67 | 80 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 81 | * @param data A pointer to a byte buffer used for storing retrieved data. |
Jonathan Austin |
1:8aa5cdb4ab67 | 82 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 83 | * @param length Number of bytes to read. |
Jonathan Austin |
1:8aa5cdb4ab67 | 84 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 85 | * @param repeated if true, stop is not sent at the end. Defaults to false. |
Jonathan Austin |
1:8aa5cdb4ab67 | 86 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 87 | * @return MICROBIT_OK on success, MICROBIT_I2C_ERROR if an unresolved read failure is detected. |
Jonathan Austin |
1:8aa5cdb4ab67 | 88 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 89 | int read(int address, char *data, int length, bool repeated = false); |
Jonathan Austin |
1:8aa5cdb4ab67 | 90 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 91 | /** |
Jonathan Austin |
1:8aa5cdb4ab67 | 92 | * Performs a complete write transaction. The bottom bit of the address is forced to 0 to indicate a write. |
Jonathan Austin |
1:8aa5cdb4ab67 | 93 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 94 | * @param address 8-bit I2C slave address [ addr | 0 ] |
Jonathan Austin |
1:8aa5cdb4ab67 | 95 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 96 | * @param data A pointer to a byte buffer containing the data to write. |
Jonathan Austin |
1:8aa5cdb4ab67 | 97 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 98 | * @param length Number of bytes to write |
Jonathan Austin |
1:8aa5cdb4ab67 | 99 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 100 | * @param repeated if true, stop is not sent at the end. Defaults to false. |
Jonathan Austin |
1:8aa5cdb4ab67 | 101 | * |
Jonathan Austin |
1:8aa5cdb4ab67 | 102 | * @return MICROBIT_OK on success, MICROBIT_I2C_ERROR if an unresolved write failure is detected. |
Jonathan Austin |
1:8aa5cdb4ab67 | 103 | */ |
Jonathan Austin |
1:8aa5cdb4ab67 | 104 | int write(int address, const char *data, int length, bool repeated = false); |
Jonathan Austin |
1:8aa5cdb4ab67 | 105 | }; |
Jonathan Austin |
1:8aa5cdb4ab67 | 106 | |
Jonathan Austin |
1:8aa5cdb4ab67 | 107 | #endif |