mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon Nov 10 07:45:06 2014 +0000
Revision:
395:bfce16e86ea4
Parent:
314:b682143dd337
Child:
598:2d5fc5624619
Synchronized with git revision 8adfd82aa1bf8859ec08537ee7bcd4aaaec1769b

Full URL: https://github.com/mbedmicro/mbed/commit/8adfd82aa1bf8859ec08537ee7bcd4aaaec1769b/

Targets: LPC176X - Add repeater pinmode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 85:e1a8e879a6a9 1 /* mbed Microcontroller Library
mbed_official 104:a6a92e2e5a92 2 * Copyright (c) 2013 Nordic Semiconductor
mbed_official 85:e1a8e879a6a9 3 *
mbed_official 85:e1a8e879a6a9 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 85:e1a8e879a6a9 5 * you may not use this file except in compliance with the License.
mbed_official 85:e1a8e879a6a9 6 * You may obtain a copy of the License at
mbed_official 85:e1a8e879a6a9 7 *
mbed_official 85:e1a8e879a6a9 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 85:e1a8e879a6a9 9 *
mbed_official 85:e1a8e879a6a9 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 85:e1a8e879a6a9 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 85:e1a8e879a6a9 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 85:e1a8e879a6a9 13 * See the License for the specific language governing permissions and
mbed_official 85:e1a8e879a6a9 14 * limitations under the License.
mbed_official 85:e1a8e879a6a9 15 */
mbed_official 227:7bd0639b8911 16 #include "mbed_assert.h"
mbed_official 85:e1a8e879a6a9 17 #include "i2c_api.h"
mbed_official 85:e1a8e879a6a9 18 #include "cmsis.h"
mbed_official 85:e1a8e879a6a9 19 #include "pinmap.h"
mbed_official 395:bfce16e86ea4 20 #include "mbed_error.h"
mbed_official 85:e1a8e879a6a9 21
mbed_official 395:bfce16e86ea4 22 // nRF51822's I2C_0 and SPI_0 (I2C_1, SPI_1 and SPIS1) share the same address.
mbed_official 395:bfce16e86ea4 23 // They can't be used at the same time. So we use two global variable to track the usage.
mbed_official 395:bfce16e86ea4 24 // See nRF51822 address information at nRF51822_PS v2.0.pdf - Table 15 Peripheral instance reference
mbed_official 395:bfce16e86ea4 25 volatile i2c_spi_peripheral_t i2c0_spi0_peripheral = {0, 0, 0, 0};
mbed_official 395:bfce16e86ea4 26 volatile i2c_spi_peripheral_t i2c1_spi1_peripheral = {0, 0, 0, 0};
mbed_official 85:e1a8e879a6a9 27
mbed_official 300:55638feb26a4 28 void i2c_interface_enable(i2c_t *obj)
mbed_official 300:55638feb26a4 29 {
mbed_official 85:e1a8e879a6a9 30 obj->i2c->ENABLE = (TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos);
mbed_official 85:e1a8e879a6a9 31 }
mbed_official 85:e1a8e879a6a9 32
mbed_official 300:55638feb26a4 33 void twi_master_init(i2c_t *obj, PinName sda, PinName scl, int frequency)
mbed_official 300:55638feb26a4 34 {
mbed_official 300:55638feb26a4 35 NRF_GPIO->PIN_CNF[scl] = ((GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) |
mbed_official 300:55638feb26a4 36 (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
mbed_official 300:55638feb26a4 37 (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
mbed_official 300:55638feb26a4 38 (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) |
mbed_official 300:55638feb26a4 39 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos));
mbed_official 85:e1a8e879a6a9 40
mbed_official 300:55638feb26a4 41 NRF_GPIO->PIN_CNF[sda] = ((GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) |
mbed_official 300:55638feb26a4 42 (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
mbed_official 300:55638feb26a4 43 (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) |
mbed_official 300:55638feb26a4 44 (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) |
mbed_official 300:55638feb26a4 45 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos));
mbed_official 85:e1a8e879a6a9 46
mbed_official 300:55638feb26a4 47 obj->i2c->PSELSCL = scl;
mbed_official 300:55638feb26a4 48 obj->i2c->PSELSDA = sda;
mbed_official 85:e1a8e879a6a9 49 // set default frequency at 100k
mbed_official 85:e1a8e879a6a9 50 i2c_frequency(obj, frequency);
mbed_official 85:e1a8e879a6a9 51 i2c_interface_enable(obj);
mbed_official 85:e1a8e879a6a9 52 }
mbed_official 300:55638feb26a4 53
mbed_official 300:55638feb26a4 54 void i2c_init(i2c_t *obj, PinName sda, PinName scl)
mbed_official 300:55638feb26a4 55 {
mbed_official 395:bfce16e86ea4 56 NRF_TWI_Type *i2c;
mbed_official 395:bfce16e86ea4 57
mbed_official 395:bfce16e86ea4 58 if (i2c0_spi0_peripheral.usage == I2C_SPI_PERIPHERAL_FOR_I2C &&
mbed_official 395:bfce16e86ea4 59 i2c0_spi0_peripheral.sda_mosi == (uint8_t)sda &&
mbed_official 395:bfce16e86ea4 60 i2c0_spi0_peripheral.scl_miso == (uint8_t)scl) {
mbed_official 395:bfce16e86ea4 61 // The I2C with the same pins is already initialized
mbed_official 395:bfce16e86ea4 62 i2c = (NRF_TWI_Type *)I2C_0;
mbed_official 395:bfce16e86ea4 63 obj->peripheral = 0x1;
mbed_official 395:bfce16e86ea4 64 } else if (i2c1_spi1_peripheral.usage == I2C_SPI_PERIPHERAL_FOR_I2C &&
mbed_official 395:bfce16e86ea4 65 i2c1_spi1_peripheral.sda_mosi == (uint8_t)sda &&
mbed_official 395:bfce16e86ea4 66 i2c1_spi1_peripheral.scl_miso == (uint8_t)scl) {
mbed_official 395:bfce16e86ea4 67 // The I2C with the same pins is already initialized
mbed_official 395:bfce16e86ea4 68 i2c = (NRF_TWI_Type *)I2C_1;
mbed_official 395:bfce16e86ea4 69 obj->peripheral = 0x2;
mbed_official 395:bfce16e86ea4 70 } else if (i2c0_spi0_peripheral.usage == 0) {
mbed_official 395:bfce16e86ea4 71 i2c0_spi0_peripheral.usage = I2C_SPI_PERIPHERAL_FOR_I2C;
mbed_official 395:bfce16e86ea4 72 i2c0_spi0_peripheral.sda_mosi = (uint8_t)sda;
mbed_official 395:bfce16e86ea4 73 i2c0_spi0_peripheral.scl_miso = (uint8_t)scl;
mbed_official 395:bfce16e86ea4 74
mbed_official 395:bfce16e86ea4 75 i2c = (NRF_TWI_Type *)I2C_0;
mbed_official 395:bfce16e86ea4 76 obj->peripheral = 0x1;
mbed_official 395:bfce16e86ea4 77 } else if (i2c1_spi1_peripheral.usage == 0) {
mbed_official 395:bfce16e86ea4 78 i2c1_spi1_peripheral.usage = I2C_SPI_PERIPHERAL_FOR_I2C;
mbed_official 395:bfce16e86ea4 79 i2c1_spi1_peripheral.sda_mosi = (uint8_t)sda;
mbed_official 395:bfce16e86ea4 80 i2c1_spi1_peripheral.scl_miso = (uint8_t)scl;
mbed_official 395:bfce16e86ea4 81
mbed_official 395:bfce16e86ea4 82 i2c = (NRF_TWI_Type *)I2C_1;
mbed_official 395:bfce16e86ea4 83 obj->peripheral = 0x2;
mbed_official 395:bfce16e86ea4 84 } else {
mbed_official 395:bfce16e86ea4 85 // No available peripheral
mbed_official 395:bfce16e86ea4 86 error("No available I2C");
mbed_official 395:bfce16e86ea4 87 }
mbed_official 300:55638feb26a4 88
mbed_official 395:bfce16e86ea4 89 obj->i2c = i2c;
mbed_official 300:55638feb26a4 90 obj->scl = scl;
mbed_official 300:55638feb26a4 91 obj->sda = sda;
mbed_official 85:e1a8e879a6a9 92 obj->i2c->EVENTS_ERROR = 0;
mbed_official 227:7bd0639b8911 93 obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
mbed_official 227:7bd0639b8911 94 obj->i2c->POWER = 0;
mbed_official 300:55638feb26a4 95
mbed_official 300:55638feb26a4 96 for (int i = 0; i<100; i++) {
mbed_official 85:e1a8e879a6a9 97 }
mbed_official 300:55638feb26a4 98
mbed_official 300:55638feb26a4 99 obj->i2c->POWER = 1;
mbed_official 300:55638feb26a4 100 twi_master_init(obj, sda, scl, 100000);
mbed_official 85:e1a8e879a6a9 101 }
mbed_official 300:55638feb26a4 102
mbed_official 300:55638feb26a4 103 void i2c_reset(i2c_t *obj)
mbed_official 300:55638feb26a4 104 {
mbed_official 85:e1a8e879a6a9 105 obj->i2c->EVENTS_ERROR = 0;
mbed_official 227:7bd0639b8911 106 obj->i2c->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
mbed_official 227:7bd0639b8911 107 obj->i2c->POWER = 0;
mbed_official 300:55638feb26a4 108 for (int i = 0; i<100; i++) {
mbed_official 85:e1a8e879a6a9 109 }
mbed_official 300:55638feb26a4 110
mbed_official 300:55638feb26a4 111 obj->i2c->POWER = 1;
mbed_official 300:55638feb26a4 112 twi_master_init(obj, obj->sda, obj->scl, obj->freq);
mbed_official 85:e1a8e879a6a9 113 }
mbed_official 85:e1a8e879a6a9 114
mbed_official 300:55638feb26a4 115 int i2c_start(i2c_t *obj)
mbed_official 300:55638feb26a4 116 {
mbed_official 85:e1a8e879a6a9 117 int status = 0;
mbed_official 85:e1a8e879a6a9 118 i2c_reset(obj);
mbed_official 314:b682143dd337 119 obj->address_set = 0;
mbed_official 85:e1a8e879a6a9 120 return status;
mbed_official 85:e1a8e879a6a9 121 }
mbed_official 85:e1a8e879a6a9 122
mbed_official 300:55638feb26a4 123 int i2c_stop(i2c_t *obj)
mbed_official 300:55638feb26a4 124 {
mbed_official 85:e1a8e879a6a9 125 int timeOut = 100000;
mbed_official 85:e1a8e879a6a9 126 obj->i2c->EVENTS_STOPPED = 0;
mbed_official 85:e1a8e879a6a9 127 // write the stop bit
mbed_official 85:e1a8e879a6a9 128 obj->i2c->TASKS_STOP = 1;
mbed_official 300:55638feb26a4 129 while (!obj->i2c->EVENTS_STOPPED) {
mbed_official 85:e1a8e879a6a9 130 timeOut--;
mbed_official 300:55638feb26a4 131 if (timeOut<0) {
mbed_official 85:e1a8e879a6a9 132 return 1;
mbed_official 300:55638feb26a4 133 }
mbed_official 227:7bd0639b8911 134 }
mbed_official 314:b682143dd337 135 obj->address_set = 0;
mbed_official 85:e1a8e879a6a9 136 i2c_reset(obj);
mbed_official 85:e1a8e879a6a9 137 return 0;
mbed_official 85:e1a8e879a6a9 138 }
mbed_official 85:e1a8e879a6a9 139
mbed_official 300:55638feb26a4 140 int i2c_do_write(i2c_t *obj, int value)
mbed_official 300:55638feb26a4 141 {
mbed_official 85:e1a8e879a6a9 142 int timeOut = 100000;
mbed_official 85:e1a8e879a6a9 143 obj->i2c->TXD = value;
mbed_official 300:55638feb26a4 144 while (!obj->i2c->EVENTS_TXDSENT) {
mbed_official 85:e1a8e879a6a9 145 timeOut--;
mbed_official 300:55638feb26a4 146 if (timeOut<0) {
mbed_official 85:e1a8e879a6a9 147 return 1;
mbed_official 300:55638feb26a4 148 }
mbed_official 85:e1a8e879a6a9 149 }
mbed_official 227:7bd0639b8911 150 obj->i2c->EVENTS_TXDSENT = 0;
mbed_official 85:e1a8e879a6a9 151 return 0;
mbed_official 85:e1a8e879a6a9 152 }
mbed_official 85:e1a8e879a6a9 153
mbed_official 300:55638feb26a4 154 int i2c_do_read(i2c_t *obj, char *data, int last)
mbed_official 300:55638feb26a4 155 {
mbed_official 85:e1a8e879a6a9 156 int timeOut = 100000;
mbed_official 177:d57c40a064c8 157
mbed_official 300:55638feb26a4 158 if (last) {
mbed_official 314:b682143dd337 159 // To trigger stop task when a byte is received,
mbed_official 314:b682143dd337 160 // must be set before resume task.
mbed_official 314:b682143dd337 161 obj->i2c->SHORTS = 2;
mbed_official 177:d57c40a064c8 162 }
mbed_official 314:b682143dd337 163
mbed_official 314:b682143dd337 164 obj->i2c->TASKS_RESUME = 1;
mbed_official 314:b682143dd337 165
mbed_official 300:55638feb26a4 166 while (!obj->i2c->EVENTS_RXDREADY) {
mbed_official 85:e1a8e879a6a9 167 timeOut--;
mbed_official 300:55638feb26a4 168 if (timeOut<0) {
mbed_official 85:e1a8e879a6a9 169 return 1;
mbed_official 300:55638feb26a4 170 }
mbed_official 85:e1a8e879a6a9 171 }
mbed_official 300:55638feb26a4 172 obj->i2c->EVENTS_RXDREADY = 0;
mbed_official 85:e1a8e879a6a9 173 *data = obj->i2c->RXD;
mbed_official 300:55638feb26a4 174
mbed_official 85:e1a8e879a6a9 175 return 0;
mbed_official 85:e1a8e879a6a9 176 }
mbed_official 85:e1a8e879a6a9 177
mbed_official 300:55638feb26a4 178 void i2c_frequency(i2c_t *obj, int hz)
mbed_official 300:55638feb26a4 179 {
mbed_official 300:55638feb26a4 180 if (hz<250000) {
mbed_official 85:e1a8e879a6a9 181 obj->freq = 100000;
mbed_official 85:e1a8e879a6a9 182 obj->i2c->FREQUENCY = (TWI_FREQUENCY_FREQUENCY_K100 << TWI_FREQUENCY_FREQUENCY_Pos);
mbed_official 300:55638feb26a4 183 } else if (hz<400000) {
mbed_official 85:e1a8e879a6a9 184 obj->freq = 250000;
mbed_official 85:e1a8e879a6a9 185 obj->i2c->FREQUENCY = (TWI_FREQUENCY_FREQUENCY_K250 << TWI_FREQUENCY_FREQUENCY_Pos);
mbed_official 300:55638feb26a4 186 } else {
mbed_official 85:e1a8e879a6a9 187 obj->freq = 400000;
mbed_official 85:e1a8e879a6a9 188 obj->i2c->FREQUENCY = (TWI_FREQUENCY_FREQUENCY_K400 << TWI_FREQUENCY_FREQUENCY_Pos);
mbed_official 85:e1a8e879a6a9 189 }
mbed_official 85:e1a8e879a6a9 190 }
mbed_official 85:e1a8e879a6a9 191
mbed_official 300:55638feb26a4 192 int checkError(i2c_t *obj)
mbed_official 300:55638feb26a4 193 {
mbed_official 300:55638feb26a4 194 if (obj->i2c->EVENTS_ERROR == 1) {
mbed_official 300:55638feb26a4 195 if (obj->i2c->ERRORSRC & TWI_ERRORSRC_ANACK_Msk) {
mbed_official 300:55638feb26a4 196 obj->i2c->EVENTS_ERROR = 0;
mbed_official 300:55638feb26a4 197 obj->i2c->TASKS_STOP = 1;
mbed_official 85:e1a8e879a6a9 198 return I2C_ERROR_BUS_BUSY;
mbed_official 85:e1a8e879a6a9 199 }
mbed_official 300:55638feb26a4 200
mbed_official 300:55638feb26a4 201 obj->i2c->EVENTS_ERROR = 0;
mbed_official 300:55638feb26a4 202 obj->i2c->TASKS_STOP = 1;
mbed_official 227:7bd0639b8911 203 return I2C_ERROR_NO_SLAVE;
mbed_official 227:7bd0639b8911 204 }
mbed_official 85:e1a8e879a6a9 205 return 0;
mbed_official 85:e1a8e879a6a9 206 }
mbed_official 85:e1a8e879a6a9 207
mbed_official 300:55638feb26a4 208 int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
mbed_official 300:55638feb26a4 209 {
mbed_official 300:55638feb26a4 210 int status, count, errorResult;
mbed_official 300:55638feb26a4 211 obj->i2c->ADDRESS = (address >> 1);
mbed_official 314:b682143dd337 212 obj->i2c->SHORTS = 1; // to trigger suspend task when a byte is received
mbed_official 85:e1a8e879a6a9 213 obj->i2c->EVENTS_RXDREADY = 0;
mbed_official 85:e1a8e879a6a9 214 obj->i2c->TASKS_STARTRX = 1;
mbed_official 300:55638feb26a4 215
mbed_official 85:e1a8e879a6a9 216 // Read in all except last byte
mbed_official 85:e1a8e879a6a9 217 for (count = 0; count < (length - 1); count++) {
mbed_official 300:55638feb26a4 218 status = i2c_do_read(obj, &data[count], 0);
mbed_official 227:7bd0639b8911 219 if (status) {
mbed_official 85:e1a8e879a6a9 220 errorResult = checkError(obj);
mbed_official 85:e1a8e879a6a9 221 i2c_reset(obj);
mbed_official 300:55638feb26a4 222 if (errorResult<0) {
mbed_official 85:e1a8e879a6a9 223 return errorResult;
mbed_official 85:e1a8e879a6a9 224 }
mbed_official 85:e1a8e879a6a9 225 return count;
mbed_official 85:e1a8e879a6a9 226 }
mbed_official 85:e1a8e879a6a9 227 }
mbed_official 85:e1a8e879a6a9 228
mbed_official 85:e1a8e879a6a9 229 // read in last byte
mbed_official 300:55638feb26a4 230 status = i2c_do_read(obj, &data[length - 1], 1);
mbed_official 85:e1a8e879a6a9 231 if (status) {
mbed_official 85:e1a8e879a6a9 232 i2c_reset(obj);
mbed_official 85:e1a8e879a6a9 233 return length - 1;
mbed_official 85:e1a8e879a6a9 234 }
mbed_official 85:e1a8e879a6a9 235 // If not repeated start, send stop.
mbed_official 85:e1a8e879a6a9 236 if (stop) {
mbed_official 300:55638feb26a4 237 while (!obj->i2c->EVENTS_STOPPED) {
mbed_official 85:e1a8e879a6a9 238 }
mbed_official 85:e1a8e879a6a9 239 obj->i2c->EVENTS_STOPPED = 0;
mbed_official 227:7bd0639b8911 240 }
mbed_official 85:e1a8e879a6a9 241 return length;
mbed_official 85:e1a8e879a6a9 242 }
mbed_official 85:e1a8e879a6a9 243
mbed_official 300:55638feb26a4 244 int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
mbed_official 300:55638feb26a4 245 {
mbed_official 85:e1a8e879a6a9 246 int status, errorResult;
mbed_official 300:55638feb26a4 247 obj->i2c->ADDRESS = (address >> 1);
mbed_official 85:e1a8e879a6a9 248 obj->i2c->SHORTS = 0;
mbed_official 227:7bd0639b8911 249 obj->i2c->TASKS_STARTTX = 1;
mbed_official 300:55638feb26a4 250
mbed_official 300:55638feb26a4 251 for (int i = 0; i<length; i++) {
mbed_official 85:e1a8e879a6a9 252 status = i2c_do_write(obj, data[i]);
mbed_official 300:55638feb26a4 253 if (status) {
mbed_official 85:e1a8e879a6a9 254 i2c_reset(obj);
mbed_official 85:e1a8e879a6a9 255 errorResult = checkError(obj);
mbed_official 300:55638feb26a4 256 if (errorResult<0) {
mbed_official 85:e1a8e879a6a9 257 return errorResult;
mbed_official 85:e1a8e879a6a9 258 }
mbed_official 85:e1a8e879a6a9 259 return i;
mbed_official 85:e1a8e879a6a9 260 }
mbed_official 85:e1a8e879a6a9 261 }
mbed_official 300:55638feb26a4 262
mbed_official 85:e1a8e879a6a9 263 // If not repeated start, send stop.
mbed_official 85:e1a8e879a6a9 264 if (stop) {
mbed_official 300:55638feb26a4 265 if (i2c_stop(obj)) {
mbed_official 85:e1a8e879a6a9 266 return I2C_ERROR_NO_SLAVE;
mbed_official 85:e1a8e879a6a9 267 }
mbed_official 85:e1a8e879a6a9 268 }
mbed_official 85:e1a8e879a6a9 269 return length;
mbed_official 85:e1a8e879a6a9 270 }
mbed_official 85:e1a8e879a6a9 271
mbed_official 300:55638feb26a4 272 int i2c_byte_read(i2c_t *obj, int last)
mbed_official 300:55638feb26a4 273 {
mbed_official 85:e1a8e879a6a9 274 char data;
mbed_official 85:e1a8e879a6a9 275 int status;
mbed_official 300:55638feb26a4 276
mbed_official 300:55638feb26a4 277 status = i2c_do_read(obj, &data, last);
mbed_official 85:e1a8e879a6a9 278 if (status) {
mbed_official 85:e1a8e879a6a9 279 i2c_reset(obj);
mbed_official 85:e1a8e879a6a9 280 }
mbed_official 85:e1a8e879a6a9 281 return data;
mbed_official 85:e1a8e879a6a9 282 }
mbed_official 85:e1a8e879a6a9 283
mbed_official 300:55638feb26a4 284 int i2c_byte_write(i2c_t *obj, int data)
mbed_official 300:55638feb26a4 285 {
mbed_official 85:e1a8e879a6a9 286 int status = 0;
mbed_official 314:b682143dd337 287 if (!obj->address_set) {
mbed_official 314:b682143dd337 288 obj->address_set = 1;
mbed_official 300:55638feb26a4 289 obj->i2c->ADDRESS = (data >> 1);
mbed_official 300:55638feb26a4 290
mbed_official 300:55638feb26a4 291 if (data & 1) {
mbed_official 85:e1a8e879a6a9 292 obj->i2c->EVENTS_RXDREADY = 0;
mbed_official 314:b682143dd337 293 obj->i2c->SHORTS = 1;
mbed_official 85:e1a8e879a6a9 294 obj->i2c->TASKS_STARTRX = 1;
mbed_official 300:55638feb26a4 295 } else {
mbed_official 314:b682143dd337 296 obj->i2c->SHORTS = 0;
mbed_official 300:55638feb26a4 297 obj->i2c->TASKS_STARTTX = 1;
mbed_official 85:e1a8e879a6a9 298 }
mbed_official 300:55638feb26a4 299 } else {
mbed_official 85:e1a8e879a6a9 300 status = i2c_do_write(obj, data);
mbed_official 300:55638feb26a4 301 if (status) {
mbed_official 85:e1a8e879a6a9 302 i2c_reset(obj);
mbed_official 85:e1a8e879a6a9 303 }
mbed_official 85:e1a8e879a6a9 304 }
mbed_official 300:55638feb26a4 305 return (1 - status);
mbed_official 85:e1a8e879a6a9 306 }