CUED IIA Project

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_GATT_Example by Bluetooth Low Energy

Committer:
AidasL
Date:
Wed May 31 22:13:36 2017 +0000
Revision:
23:708cc5ef2604
Initial commit;

Who changed what in which revision?

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