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:
Wed May 07 09:00:07 2014 +0100
Revision:
178:a873352662d8
Parent:
149:1fb5f62b92bd
Child:
180:097147d37470
Synchronized with git revision 42a3edb815167b2aed138226781ff2ebcac662e4

Full URL: https://github.com/mbedmicro/mbed/commit/42a3edb815167b2aed138226781ff2ebcac662e4/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 146:f64d43ff0c18 1 /* mbed Microcontroller Library
mbed_official 146:f64d43ff0c18 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 146:f64d43ff0c18 3 *
mbed_official 146:f64d43ff0c18 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 146:f64d43ff0c18 5 * you may not use this file except in compliance with the License.
mbed_official 146:f64d43ff0c18 6 * You may obtain a copy of the License at
mbed_official 146:f64d43ff0c18 7 *
mbed_official 146:f64d43ff0c18 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 146:f64d43ff0c18 9 *
mbed_official 146:f64d43ff0c18 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 146:f64d43ff0c18 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 146:f64d43ff0c18 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 146:f64d43ff0c18 13 * See the License for the specific language governing permissions and
mbed_official 146:f64d43ff0c18 14 * limitations under the License.
mbed_official 146:f64d43ff0c18 15 */
mbed_official 146:f64d43ff0c18 16 #include "i2c_api.h"
mbed_official 146:f64d43ff0c18 17
mbed_official 146:f64d43ff0c18 18 #include "cmsis.h"
mbed_official 146:f64d43ff0c18 19 #include "pinmap.h"
mbed_official 146:f64d43ff0c18 20 #include "error.h"
mbed_official 146:f64d43ff0c18 21 #include "fsl_clock_manager.h"
mbed_official 146:f64d43ff0c18 22 #include "fsl_i2c_hal.h"
mbed_official 146:f64d43ff0c18 23
mbed_official 146:f64d43ff0c18 24 static const PinMap PinMap_I2C_SDA[] = {
mbed_official 146:f64d43ff0c18 25 {PTE25, I2C_0, 5},
mbed_official 146:f64d43ff0c18 26 {PTB1 , I2C_0, 2},
mbed_official 146:f64d43ff0c18 27 {PTB3 , I2C_0, 2},
mbed_official 146:f64d43ff0c18 28 {PTC11, I2C_1, 2},
mbed_official 146:f64d43ff0c18 29 {PTA13, I2C_2, 5},
mbed_official 146:f64d43ff0c18 30 {PTD3 , I2C_0, 7},
mbed_official 146:f64d43ff0c18 31 {PTE0 , I2C_1, 6},
mbed_official 146:f64d43ff0c18 32 {NC , NC , 0}
mbed_official 146:f64d43ff0c18 33 };
mbed_official 146:f64d43ff0c18 34
mbed_official 146:f64d43ff0c18 35 static const PinMap PinMap_I2C_SCL[] = {
mbed_official 146:f64d43ff0c18 36 {PTE24, I2C_0, 5},
mbed_official 146:f64d43ff0c18 37 {PTB0 , I2C_0, 2},
mbed_official 146:f64d43ff0c18 38 {PTB2 , I2C_0, 2},
mbed_official 146:f64d43ff0c18 39 {PTC10, I2C_1, 2},
mbed_official 146:f64d43ff0c18 40 {PTA12, I2C_2, 5},
mbed_official 146:f64d43ff0c18 41 {PTA14, I2C_2, 5},
mbed_official 146:f64d43ff0c18 42 {PTD2 , I2C_0, 7},
mbed_official 146:f64d43ff0c18 43 {PTE1 , I2C_1, 6},
mbed_official 146:f64d43ff0c18 44 {NC , NC , 0}
mbed_official 146:f64d43ff0c18 45 };
mbed_official 146:f64d43ff0c18 46
mbed_official 146:f64d43ff0c18 47 void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
mbed_official 146:f64d43ff0c18 48 uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA);
mbed_official 146:f64d43ff0c18 49 uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL);
mbed_official 146:f64d43ff0c18 50 obj->instance = pinmap_merge(i2c_sda, i2c_scl);
mbed_official 146:f64d43ff0c18 51 if ((int)obj->instance == NC) {
mbed_official 146:f64d43ff0c18 52 error("I2C pin mapping failed");
mbed_official 146:f64d43ff0c18 53 }
mbed_official 146:f64d43ff0c18 54
mbed_official 146:f64d43ff0c18 55 clock_manager_set_gate(kClockModuleI2C, obj->instance, true);
mbed_official 146:f64d43ff0c18 56 i2c_hal_enable(obj->instance);
mbed_official 146:f64d43ff0c18 57 i2c_frequency(obj, 100000);
mbed_official 146:f64d43ff0c18 58
mbed_official 146:f64d43ff0c18 59 pinmap_pinout(sda, PinMap_I2C_SDA);
mbed_official 146:f64d43ff0c18 60 pinmap_pinout(scl, PinMap_I2C_SCL);
mbed_official 146:f64d43ff0c18 61 }
mbed_official 146:f64d43ff0c18 62
mbed_official 146:f64d43ff0c18 63 int i2c_start(i2c_t *obj) {
mbed_official 146:f64d43ff0c18 64 i2c_hal_send_start(obj->instance);
mbed_official 146:f64d43ff0c18 65 return 0;
mbed_official 146:f64d43ff0c18 66 }
mbed_official 146:f64d43ff0c18 67
mbed_official 146:f64d43ff0c18 68 int i2c_stop(i2c_t *obj) {
mbed_official 146:f64d43ff0c18 69 volatile uint32_t n = 0;
mbed_official 146:f64d43ff0c18 70 i2c_hal_send_stop(obj->instance);
mbed_official 146:f64d43ff0c18 71
mbed_official 146:f64d43ff0c18 72 // It seems that there are timing problems
mbed_official 146:f64d43ff0c18 73 // when there is no waiting time after a STOP.
mbed_official 146:f64d43ff0c18 74 // This wait is also included on the samples
mbed_official 146:f64d43ff0c18 75 // code provided with the freedom board
mbed_official 146:f64d43ff0c18 76 for (n = 0; n < 100; n++) __NOP();
mbed_official 146:f64d43ff0c18 77 return 0;
mbed_official 146:f64d43ff0c18 78 }
mbed_official 146:f64d43ff0c18 79
mbed_official 146:f64d43ff0c18 80 static int timeout_status_poll(i2c_t *obj, uint32_t mask) {
mbed_official 146:f64d43ff0c18 81 uint32_t i, timeout = 1000;
mbed_official 146:f64d43ff0c18 82
mbed_official 146:f64d43ff0c18 83 for (i = 0; i < timeout; i++) {
mbed_official 146:f64d43ff0c18 84 if (HW_I2C_S_RD(obj->instance) & mask)
mbed_official 146:f64d43ff0c18 85 return 0;
mbed_official 146:f64d43ff0c18 86 }
mbed_official 146:f64d43ff0c18 87 return 1;
mbed_official 146:f64d43ff0c18 88 }
mbed_official 146:f64d43ff0c18 89
mbed_official 146:f64d43ff0c18 90 // this function waits the end of a tx transfer and return the status of the transaction:
mbed_official 146:f64d43ff0c18 91 // 0: OK ack received
mbed_official 146:f64d43ff0c18 92 // 1: OK ack not received
mbed_official 146:f64d43ff0c18 93 // 2: failure
mbed_official 146:f64d43ff0c18 94 static int i2c_wait_end_tx_transfer(i2c_t *obj) {
mbed_official 146:f64d43ff0c18 95 // wait for the interrupt flag
mbed_official 146:f64d43ff0c18 96 if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) {
mbed_official 146:f64d43ff0c18 97 return 2;
mbed_official 146:f64d43ff0c18 98 }
mbed_official 146:f64d43ff0c18 99
mbed_official 146:f64d43ff0c18 100 i2c_hal_clear_interrupt(obj->instance);
mbed_official 146:f64d43ff0c18 101
mbed_official 146:f64d43ff0c18 102 // wait transfer complete
mbed_official 146:f64d43ff0c18 103 if (timeout_status_poll(obj, I2C_S_TCF_MASK)) {
mbed_official 146:f64d43ff0c18 104 return 2;
mbed_official 146:f64d43ff0c18 105 }
mbed_official 146:f64d43ff0c18 106
mbed_official 146:f64d43ff0c18 107 // check if we received the ACK or not
mbed_official 146:f64d43ff0c18 108 return i2c_hal_get_receive_ack(obj->instance) ? 0 : 1;
mbed_official 146:f64d43ff0c18 109 }
mbed_official 146:f64d43ff0c18 110
mbed_official 146:f64d43ff0c18 111 // this function waits the end of a rx transfer and return the status of the transaction:
mbed_official 146:f64d43ff0c18 112 // 0: OK
mbed_official 146:f64d43ff0c18 113 // 1: failure
mbed_official 146:f64d43ff0c18 114 static int i2c_wait_end_rx_transfer(i2c_t *obj) {
mbed_official 146:f64d43ff0c18 115 // wait for the end of the rx transfer
mbed_official 146:f64d43ff0c18 116 if (timeout_status_poll(obj, I2C_S_IICIF_MASK)) {
mbed_official 146:f64d43ff0c18 117 return 1;
mbed_official 146:f64d43ff0c18 118 }
mbed_official 146:f64d43ff0c18 119
mbed_official 146:f64d43ff0c18 120 i2c_hal_clear_interrupt(obj->instance);
mbed_official 146:f64d43ff0c18 121
mbed_official 146:f64d43ff0c18 122 return 0;
mbed_official 146:f64d43ff0c18 123 }
mbed_official 146:f64d43ff0c18 124
mbed_official 146:f64d43ff0c18 125 static int i2c_do_write(i2c_t *obj, int value) {
mbed_official 146:f64d43ff0c18 126 i2c_hal_write(obj->instance, value);
mbed_official 146:f64d43ff0c18 127
mbed_official 146:f64d43ff0c18 128 // init and wait the end of the transfer
mbed_official 146:f64d43ff0c18 129 return i2c_wait_end_tx_transfer(obj);
mbed_official 146:f64d43ff0c18 130 }
mbed_official 146:f64d43ff0c18 131
mbed_official 146:f64d43ff0c18 132 static int i2c_do_read(i2c_t *obj, char * data, int last) {
mbed_official 146:f64d43ff0c18 133 if (last) {
mbed_official 146:f64d43ff0c18 134 i2c_hal_send_nak(obj->instance);
mbed_official 146:f64d43ff0c18 135 } else {
mbed_official 146:f64d43ff0c18 136 i2c_hal_send_ack(obj->instance);
mbed_official 146:f64d43ff0c18 137 }
mbed_official 146:f64d43ff0c18 138
mbed_official 146:f64d43ff0c18 139 *data = (i2c_hal_read(obj->instance) & 0xFF);
mbed_official 146:f64d43ff0c18 140
mbed_official 146:f64d43ff0c18 141 // start rx transfer and wait the end of the transfer
mbed_official 146:f64d43ff0c18 142 return i2c_wait_end_rx_transfer(obj);
mbed_official 146:f64d43ff0c18 143 }
mbed_official 146:f64d43ff0c18 144
mbed_official 146:f64d43ff0c18 145 void i2c_frequency(i2c_t *obj, int hz) {
mbed_official 146:f64d43ff0c18 146 uint32_t busClock;
mbed_official 146:f64d43ff0c18 147
mbed_official 146:f64d43ff0c18 148 clock_manager_error_code_t error = clock_manager_get_frequency(kBusClock, &busClock);
mbed_official 146:f64d43ff0c18 149 if (error == kClockManagerSuccess) {
mbed_official 146:f64d43ff0c18 150 i2c_hal_set_baud(obj->instance, busClock, hz / 1000, NULL);
mbed_official 146:f64d43ff0c18 151 }
mbed_official 146:f64d43ff0c18 152 }
mbed_official 146:f64d43ff0c18 153
mbed_official 146:f64d43ff0c18 154 int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
mbed_official 146:f64d43ff0c18 155 int count;
mbed_official 146:f64d43ff0c18 156 char dummy_read, *ptr;
mbed_official 146:f64d43ff0c18 157
mbed_official 146:f64d43ff0c18 158 if (i2c_start(obj)) {
mbed_official 146:f64d43ff0c18 159 i2c_stop(obj);
mbed_official 146:f64d43ff0c18 160 return I2C_ERROR_BUS_BUSY;
mbed_official 146:f64d43ff0c18 161 }
mbed_official 146:f64d43ff0c18 162
mbed_official 146:f64d43ff0c18 163 if (i2c_do_write(obj, (address | 0x01))) {
mbed_official 146:f64d43ff0c18 164 i2c_stop(obj);
mbed_official 146:f64d43ff0c18 165 return I2C_ERROR_NO_SLAVE;
mbed_official 146:f64d43ff0c18 166 }
mbed_official 146:f64d43ff0c18 167
mbed_official 146:f64d43ff0c18 168 // set rx mode
mbed_official 146:f64d43ff0c18 169 i2c_hal_set_direction(obj->instance, kI2CReceive);
mbed_official 146:f64d43ff0c18 170
mbed_official 146:f64d43ff0c18 171 // Read in bytes
mbed_official 146:f64d43ff0c18 172 for (count = 0; count < (length); count++) {
mbed_official 146:f64d43ff0c18 173 ptr = (count == 0) ? &dummy_read : &data[count - 1];
mbed_official 146:f64d43ff0c18 174 uint8_t stop_ = (count == (length - 1)) ? 1 : 0;
mbed_official 146:f64d43ff0c18 175 if (i2c_do_read(obj, ptr, stop_)) {
mbed_official 146:f64d43ff0c18 176 i2c_stop(obj);
mbed_official 146:f64d43ff0c18 177 return count;
mbed_official 146:f64d43ff0c18 178 }
mbed_official 146:f64d43ff0c18 179 }
mbed_official 146:f64d43ff0c18 180
mbed_official 146:f64d43ff0c18 181 // If not repeated start, send stop.
mbed_official 146:f64d43ff0c18 182 if (stop)
mbed_official 146:f64d43ff0c18 183 i2c_stop(obj);
mbed_official 146:f64d43ff0c18 184
mbed_official 146:f64d43ff0c18 185 // last read
mbed_official 146:f64d43ff0c18 186 data[count-1] = i2c_hal_read(obj->instance);
mbed_official 146:f64d43ff0c18 187
mbed_official 146:f64d43ff0c18 188 return length;
mbed_official 146:f64d43ff0c18 189 }
mbed_official 146:f64d43ff0c18 190
mbed_official 146:f64d43ff0c18 191 int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
mbed_official 146:f64d43ff0c18 192 int i;
mbed_official 146:f64d43ff0c18 193
mbed_official 146:f64d43ff0c18 194 if (i2c_start(obj)) {
mbed_official 146:f64d43ff0c18 195 i2c_stop(obj);
mbed_official 146:f64d43ff0c18 196 return I2C_ERROR_BUS_BUSY;
mbed_official 146:f64d43ff0c18 197 }
mbed_official 146:f64d43ff0c18 198
mbed_official 146:f64d43ff0c18 199 if (i2c_do_write(obj, (address & 0xFE))) {
mbed_official 146:f64d43ff0c18 200 i2c_stop(obj);
mbed_official 146:f64d43ff0c18 201 return I2C_ERROR_NO_SLAVE;
mbed_official 146:f64d43ff0c18 202 }
mbed_official 146:f64d43ff0c18 203
mbed_official 146:f64d43ff0c18 204 for (i = 0; i < length; i++) {
mbed_official 146:f64d43ff0c18 205 if(i2c_do_write(obj, data[i])) {
mbed_official 146:f64d43ff0c18 206 i2c_stop(obj);
mbed_official 146:f64d43ff0c18 207 return i;
mbed_official 146:f64d43ff0c18 208 }
mbed_official 146:f64d43ff0c18 209 }
mbed_official 146:f64d43ff0c18 210
mbed_official 146:f64d43ff0c18 211 if (stop)
mbed_official 146:f64d43ff0c18 212 i2c_stop(obj);
mbed_official 146:f64d43ff0c18 213
mbed_official 146:f64d43ff0c18 214 return length;
mbed_official 146:f64d43ff0c18 215 }
mbed_official 146:f64d43ff0c18 216
mbed_official 146:f64d43ff0c18 217 void i2c_reset(i2c_t *obj) {
mbed_official 146:f64d43ff0c18 218 i2c_stop(obj);
mbed_official 146:f64d43ff0c18 219 }
mbed_official 146:f64d43ff0c18 220
mbed_official 146:f64d43ff0c18 221 int i2c_byte_read(i2c_t *obj, int last) {
mbed_official 146:f64d43ff0c18 222 char data;
mbed_official 146:f64d43ff0c18 223
mbed_official 146:f64d43ff0c18 224 // set rx mode
mbed_official 146:f64d43ff0c18 225 i2c_hal_set_direction(obj->instance, kI2CReceive);
mbed_official 146:f64d43ff0c18 226
mbed_official 178:a873352662d8 227 // Setup read
mbed_official 146:f64d43ff0c18 228 i2c_do_read(obj, &data, last);
mbed_official 146:f64d43ff0c18 229
mbed_official 178:a873352662d8 230 // set tx mode
mbed_official 178:a873352662d8 231 i2c_hal_set_direction(obj->instance, kI2CTransmit);
mbed_official 178:a873352662d8 232 return i2c_hal_read(obj->instance);
mbed_official 146:f64d43ff0c18 233 }
mbed_official 146:f64d43ff0c18 234
mbed_official 146:f64d43ff0c18 235 int i2c_byte_write(i2c_t *obj, int data) {
mbed_official 146:f64d43ff0c18 236 // set tx mode
mbed_official 146:f64d43ff0c18 237 i2c_hal_set_direction(obj->instance, kI2CTransmit);
mbed_official 146:f64d43ff0c18 238
mbed_official 146:f64d43ff0c18 239 return !i2c_do_write(obj, (data & 0xFF));
mbed_official 146:f64d43ff0c18 240 }
mbed_official 146:f64d43ff0c18 241
mbed_official 146:f64d43ff0c18 242
mbed_official 146:f64d43ff0c18 243 #if DEVICE_I2CSLAVE
mbed_official 146:f64d43ff0c18 244 void i2c_slave_mode(i2c_t *obj, int enable_slave) {
mbed_official 146:f64d43ff0c18 245 if (enable_slave) {
mbed_official 146:f64d43ff0c18 246 // set slave mode
mbed_official 146:f64d43ff0c18 247 BW_I2C_C1_MST(obj->instance, 0);
mbed_official 146:f64d43ff0c18 248 i2c_hal_enable_interrupt(obj->instance);
mbed_official 146:f64d43ff0c18 249 } else {
mbed_official 146:f64d43ff0c18 250 // set master mode
mbed_official 146:f64d43ff0c18 251 BW_I2C_C1_MST(obj->instance, 1);
mbed_official 146:f64d43ff0c18 252 }
mbed_official 146:f64d43ff0c18 253 }
mbed_official 146:f64d43ff0c18 254
mbed_official 146:f64d43ff0c18 255 int i2c_slave_receive(i2c_t *obj) {
mbed_official 146:f64d43ff0c18 256 switch(HW_I2C_S_RD(obj->instance)) {
mbed_official 146:f64d43ff0c18 257 // read addressed
mbed_official 146:f64d43ff0c18 258 case 0xE6:
mbed_official 146:f64d43ff0c18 259 return 1;
mbed_official 146:f64d43ff0c18 260 // write addressed
mbed_official 146:f64d43ff0c18 261 case 0xE2:
mbed_official 146:f64d43ff0c18 262 return 3;
mbed_official 146:f64d43ff0c18 263 default:
mbed_official 146:f64d43ff0c18 264 return 0;
mbed_official 146:f64d43ff0c18 265 }
mbed_official 146:f64d43ff0c18 266 }
mbed_official 146:f64d43ff0c18 267
mbed_official 146:f64d43ff0c18 268 int i2c_slave_read(i2c_t *obj, char *data, int length) {
mbed_official 146:f64d43ff0c18 269 uint8_t dummy_read;
mbed_official 146:f64d43ff0c18 270 uint8_t *ptr;
mbed_official 146:f64d43ff0c18 271 int count;
mbed_official 146:f64d43ff0c18 272
mbed_official 146:f64d43ff0c18 273 // set rx mode
mbed_official 146:f64d43ff0c18 274 i2c_hal_set_direction(obj->instance, kI2CTransmit);
mbed_official 146:f64d43ff0c18 275
mbed_official 146:f64d43ff0c18 276 // first dummy read
mbed_official 146:f64d43ff0c18 277 dummy_read = i2c_hal_read(obj->instance);
mbed_official 146:f64d43ff0c18 278 if (i2c_wait_end_rx_transfer(obj))
mbed_official 146:f64d43ff0c18 279 return 0;
mbed_official 146:f64d43ff0c18 280
mbed_official 146:f64d43ff0c18 281 // read address
mbed_official 146:f64d43ff0c18 282 dummy_read = i2c_hal_read(obj->instance);
mbed_official 146:f64d43ff0c18 283 if (i2c_wait_end_rx_transfer(obj))
mbed_official 146:f64d43ff0c18 284 return 0;
mbed_official 146:f64d43ff0c18 285
mbed_official 146:f64d43ff0c18 286 // read (length - 1) bytes
mbed_official 146:f64d43ff0c18 287 for (count = 0; count < (length - 1); count++) {
mbed_official 146:f64d43ff0c18 288 data[count] = i2c_hal_read(obj->instance);
mbed_official 146:f64d43ff0c18 289 if (i2c_wait_end_rx_transfer(obj))
mbed_official 146:f64d43ff0c18 290 return count;
mbed_official 146:f64d43ff0c18 291 }
mbed_official 146:f64d43ff0c18 292
mbed_official 146:f64d43ff0c18 293 // read last byte
mbed_official 146:f64d43ff0c18 294 ptr = (length == 0) ? &dummy_read : (uint8_t *)&data[count];
mbed_official 146:f64d43ff0c18 295 *ptr = i2c_hal_read(obj->instance);
mbed_official 146:f64d43ff0c18 296
mbed_official 146:f64d43ff0c18 297 return (length) ? (count + 1) : 0;
mbed_official 146:f64d43ff0c18 298 }
mbed_official 146:f64d43ff0c18 299
mbed_official 146:f64d43ff0c18 300 int i2c_slave_write(i2c_t *obj, const char *data, int length) {
mbed_official 146:f64d43ff0c18 301 int i, count = 0;
mbed_official 146:f64d43ff0c18 302
mbed_official 146:f64d43ff0c18 303 // set tx mode
mbed_official 146:f64d43ff0c18 304 i2c_hal_set_direction(obj->instance, kI2CTransmit);
mbed_official 146:f64d43ff0c18 305
mbed_official 146:f64d43ff0c18 306 for (i = 0; i < length; i++) {
mbed_official 146:f64d43ff0c18 307 if (i2c_do_write(obj, data[count++]) == 2)
mbed_official 146:f64d43ff0c18 308 return i;
mbed_official 146:f64d43ff0c18 309 }
mbed_official 146:f64d43ff0c18 310
mbed_official 146:f64d43ff0c18 311 // set rx mode
mbed_official 146:f64d43ff0c18 312 i2c_hal_set_direction(obj->instance, kI2CReceive);
mbed_official 146:f64d43ff0c18 313
mbed_official 146:f64d43ff0c18 314 // dummy rx transfer needed
mbed_official 146:f64d43ff0c18 315 // otherwise the master cannot generate a stop bit
mbed_official 146:f64d43ff0c18 316 i2c_hal_read(obj->instance);
mbed_official 146:f64d43ff0c18 317 if (i2c_wait_end_rx_transfer(obj) == 2)
mbed_official 146:f64d43ff0c18 318 return count;
mbed_official 146:f64d43ff0c18 319
mbed_official 146:f64d43ff0c18 320 return count;
mbed_official 146:f64d43ff0c18 321 }
mbed_official 146:f64d43ff0c18 322
mbed_official 146:f64d43ff0c18 323 void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask) {
mbed_official 146:f64d43ff0c18 324 i2c_hal_set_upper_slave_address_7bit(obj->instance, address & 0xfe);
mbed_official 146:f64d43ff0c18 325 }
mbed_official 146:f64d43ff0c18 326 #endif
mbed_official 146:f64d43ff0c18 327