An integrated code base for smart watch model using nrf51822. Used the efforts from Roger Clark, Goran Mahovlic, Nordic team SDKs and mbed repos on OLED. Programming: The watch prototype can be interfaced to Tiny Seeed BLE programmer (left of the Tiny Seeed BLE board). Connect SWDIO, SWD CLK, Vin and GND pins. For USB debugging also connect RX and TX pins. Used Roger's nice webpage to come up with the pin mapping and many other HW insights. http://www.rogerclark.net/arduino-on-the-id100hr-fitness-tracker/

Dependencies:   BLE_API SFE_MicroOLED_debugPrint mbed nRF51822

Fork of BLE_TemperatureAdvertising by xiao sun

Committer:
root@developer-sjc-indigo-compiler.local.mbed.org
Date:
Wed Dec 27 06:52:35 2017 +0000
Revision:
8:c98204f59c76
Parent:
5:8c21994db8d2
Added tag dec26 for changeset 1b0597b7ead3

Who changed what in which revision?

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