pls
Dependencies: BLE_API mbed nRF51822
Fork of zach_thresholding by
wire.h@17:bd261621151f, 2017-05-04 (annotated)
- Committer:
- znew711
- Date:
- Thu May 04 00:55:34 2017 +0000
- Revision:
- 17:bd261621151f
- Parent:
- 15:d117591084ff
pls work;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nkosarek | 15:d117591084ff | 1 | /* |
nkosarek | 15:d117591084ff | 2 | |
nkosarek | 15:d117591084ff | 3 | Copyright (c) 2014 RedBearLab, All rights reserved. |
nkosarek | 15:d117591084ff | 4 | |
nkosarek | 15:d117591084ff | 5 | This library is free software; you can redistribute it and/or |
nkosarek | 15:d117591084ff | 6 | modify it under the terms of the GNU Lesser General Public |
nkosarek | 15:d117591084ff | 7 | License as published by the Free Software Foundation; either |
nkosarek | 15:d117591084ff | 8 | version 2.1 of the License, or (at your option) any later version. |
nkosarek | 15:d117591084ff | 9 | |
nkosarek | 15:d117591084ff | 10 | This library is distributed in the hope that it will be useful, |
nkosarek | 15:d117591084ff | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
nkosarek | 15:d117591084ff | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
nkosarek | 15:d117591084ff | 13 | See the GNU Lesser General Public License for more details. |
nkosarek | 15:d117591084ff | 14 | |
nkosarek | 15:d117591084ff | 15 | You should have received a copy of the GNU Lesser General Public |
nkosarek | 15:d117591084ff | 16 | License along with this library; if not, write to the Free Software |
nkosarek | 15:d117591084ff | 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
nkosarek | 15:d117591084ff | 18 | |
nkosarek | 15:d117591084ff | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
nkosarek | 15:d117591084ff | 20 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
nkosarek | 15:d117591084ff | 21 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
nkosarek | 15:d117591084ff | 22 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
nkosarek | 15:d117591084ff | 23 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
nkosarek | 15:d117591084ff | 24 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
nkosarek | 15:d117591084ff | 25 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
nkosarek | 15:d117591084ff | 26 | |
nkosarek | 15:d117591084ff | 27 | */ |
nkosarek | 15:d117591084ff | 28 | |
nkosarek | 15:d117591084ff | 29 | #ifndef _WIRE_H_ |
nkosarek | 15:d117591084ff | 30 | #define _WIRE_H_ |
nkosarek | 15:d117591084ff | 31 | |
nkosarek | 15:d117591084ff | 32 | #include "mbed.h" |
nkosarek | 15:d117591084ff | 33 | |
nkosarek | 15:d117591084ff | 34 | #define TWI_DELAY(x) wait_us(x); |
nkosarek | 15:d117591084ff | 35 | |
nkosarek | 15:d117591084ff | 36 | #define BUFF_MAX_LENGTH 128 |
nkosarek | 15:d117591084ff | 37 | |
nkosarek | 15:d117591084ff | 38 | #define MAX_TIMEOUT_LOOPS (20000UL) |
nkosarek | 15:d117591084ff | 39 | |
nkosarek | 15:d117591084ff | 40 | #define TWI_FREQUENCY_100K 0 |
nkosarek | 15:d117591084ff | 41 | #define TWI_FREQUENCY_250K 1 |
nkosarek | 15:d117591084ff | 42 | #define TWI_FREQUENCY_400K 2 |
nkosarek | 15:d117591084ff | 43 | |
nkosarek | 15:d117591084ff | 44 | #define TWI_SCL 28 |
nkosarek | 15:d117591084ff | 45 | #define TWI_SDA 29 |
nkosarek | 15:d117591084ff | 46 | |
nkosarek | 15:d117591084ff | 47 | |
nkosarek | 15:d117591084ff | 48 | class TwoWire |
nkosarek | 15:d117591084ff | 49 | { |
nkosarek | 15:d117591084ff | 50 | public : |
nkosarek | 15:d117591084ff | 51 | TwoWire(NRF_TWI_Type *twi_use); |
nkosarek | 15:d117591084ff | 52 | void begin(); |
nkosarek | 15:d117591084ff | 53 | void begin(uint32_t scl_pin, uint32_t sda_pin, uint8_t speed); |
nkosarek | 15:d117591084ff | 54 | void beginTransmission(uint8_t); |
nkosarek | 15:d117591084ff | 55 | void beginTransmission(int); |
nkosarek | 15:d117591084ff | 56 | uint8_t endTransmission(void); |
nkosarek | 15:d117591084ff | 57 | uint8_t endTransmission(uint8_t); |
nkosarek | 15:d117591084ff | 58 | uint8_t requestFrom(uint8_t, uint8_t); |
nkosarek | 15:d117591084ff | 59 | uint8_t requestFrom(uint8_t, uint8_t, uint8_t); |
nkosarek | 15:d117591084ff | 60 | uint8_t requestFrom(int, int); |
nkosarek | 15:d117591084ff | 61 | uint8_t requestFrom(int, int, int); |
nkosarek | 15:d117591084ff | 62 | int write(uint8_t); |
nkosarek | 15:d117591084ff | 63 | int write(const uint8_t *, size_t); |
nkosarek | 15:d117591084ff | 64 | int available(void); |
nkosarek | 15:d117591084ff | 65 | int read(void); |
nkosarek | 15:d117591084ff | 66 | |
nkosarek | 15:d117591084ff | 67 | private : |
nkosarek | 15:d117591084ff | 68 | uint8_t RX_Buffer[BUFF_MAX_LENGTH]; |
nkosarek | 15:d117591084ff | 69 | uint8_t RX_BufferIndex; |
nkosarek | 15:d117591084ff | 70 | uint8_t RX_BufferLength; |
nkosarek | 15:d117591084ff | 71 | |
nkosarek | 15:d117591084ff | 72 | uint8_t TX_Buffer[BUFF_MAX_LENGTH]; |
nkosarek | 15:d117591084ff | 73 | uint8_t TX_BufferIndex; |
nkosarek | 15:d117591084ff | 74 | uint8_t TX_BufferLength; |
nkosarek | 15:d117591084ff | 75 | |
nkosarek | 15:d117591084ff | 76 | NRF_TWI_Type *twi; |
nkosarek | 15:d117591084ff | 77 | |
nkosarek | 15:d117591084ff | 78 | uint8_t PPI_channel; |
nkosarek | 15:d117591084ff | 79 | uint8_t Transform_Addr; |
nkosarek | 15:d117591084ff | 80 | |
nkosarek | 15:d117591084ff | 81 | uint32_t SDA_Pin; |
nkosarek | 15:d117591084ff | 82 | uint32_t SCL_Pin; |
nkosarek | 15:d117591084ff | 83 | |
nkosarek | 15:d117591084ff | 84 | uint32_t twi_frequency; |
nkosarek | 15:d117591084ff | 85 | |
nkosarek | 15:d117591084ff | 86 | enum TwoWireStatus { |
nkosarek | 15:d117591084ff | 87 | UNINITIALIZED, |
nkosarek | 15:d117591084ff | 88 | MASTER_IDLE, |
nkosarek | 15:d117591084ff | 89 | MASTER_SEND, |
nkosarek | 15:d117591084ff | 90 | MASTER_RECV, |
nkosarek | 15:d117591084ff | 91 | SLAVE_IDLE, |
nkosarek | 15:d117591084ff | 92 | SLAVE_RECV, |
nkosarek | 15:d117591084ff | 93 | SLAVE_SEND |
nkosarek | 15:d117591084ff | 94 | }; |
nkosarek | 15:d117591084ff | 95 | TwoWireStatus twi_status; |
nkosarek | 15:d117591084ff | 96 | |
nkosarek | 15:d117591084ff | 97 | bool twi_master_clear_bus(void); |
nkosarek | 15:d117591084ff | 98 | bool twi_master_init(void); |
nkosarek | 15:d117591084ff | 99 | uint8_t twi_master_read(uint8_t *data, uint8_t data_length, uint8_t issue_stop_condition); |
nkosarek | 15:d117591084ff | 100 | uint8_t twi_master_write(uint8_t *data, uint8_t data_length, uint8_t issue_stop_condition); |
nkosarek | 15:d117591084ff | 101 | }; |
nkosarek | 15:d117591084ff | 102 | |
nkosarek | 15:d117591084ff | 103 | #endif |