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:
Tue Jun 30 09:45:08 2015 +0100
Revision:
576:99a3d3d9c43f
Parent:
567:a97fd0eca828
Child:
601:248b0d2dd755
Synchronized with git revision 1c13bc80fedd0fdfaedfab5c33183dc2b6f9b1bb

Full URL: https://github.com/mbedmicro/mbed/commit/1c13bc80fedd0fdfaedfab5c33183dc2b6f9b1bb/

Wiznet - Update and bug fix.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 558:0880f51c4036 1 /* mbed Microcontroller Library
mbed_official 558:0880f51c4036 2 *******************************************************************************
mbed_official 558:0880f51c4036 3 * Copyright (c) 2015 WIZnet Co.,Ltd. All rights reserved.
mbed_official 558:0880f51c4036 4 * All rights reserved.
mbed_official 558:0880f51c4036 5 *
mbed_official 558:0880f51c4036 6 * Redistribution and use in source and binary forms, with or without
mbed_official 558:0880f51c4036 7 * modification, are permitted provided that the following conditions are met:
mbed_official 558:0880f51c4036 8 *
mbed_official 558:0880f51c4036 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 558:0880f51c4036 10 * this list of conditions and the following disclaimer.
mbed_official 558:0880f51c4036 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 558:0880f51c4036 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 558:0880f51c4036 13 * and/or other materials provided with the distribution.
mbed_official 558:0880f51c4036 14 * 3. Neither the name of ARM Limited nor the names of its contributors
mbed_official 558:0880f51c4036 15 * may be used to endorse or promote products derived from this software
mbed_official 558:0880f51c4036 16 * without specific prior written permission.
mbed_official 558:0880f51c4036 17 *
mbed_official 558:0880f51c4036 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 558:0880f51c4036 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 558:0880f51c4036 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 558:0880f51c4036 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 558:0880f51c4036 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 558:0880f51c4036 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 558:0880f51c4036 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 558:0880f51c4036 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 558:0880f51c4036 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 558:0880f51c4036 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 558:0880f51c4036 28 *******************************************************************************
mbed_official 558:0880f51c4036 29 */
mbed_official 558:0880f51c4036 30
mbed_official 558:0880f51c4036 31 #include "mbed_assert.h"
mbed_official 558:0880f51c4036 32 #include "i2c_api.h"
mbed_official 558:0880f51c4036 33
mbed_official 576:99a3d3d9c43f 34
mbed_official 558:0880f51c4036 35 #if DEVICE_I2C
mbed_official 558:0880f51c4036 36
mbed_official 558:0880f51c4036 37 #include "cmsis.h"
mbed_official 558:0880f51c4036 38 #include "pinmap.h"
mbed_official 558:0880f51c4036 39 #include "PeripheralPins.h"
mbed_official 558:0880f51c4036 40
mbed_official 576:99a3d3d9c43f 41 #include "wait_api.h"
mbed_official 576:99a3d3d9c43f 42 #include "us_ticker_api.h"
mbed_official 576:99a3d3d9c43f 43
mbed_official 558:0880f51c4036 44 /* Timeout values for flags and events waiting loops. These timeouts are
mbed_official 558:0880f51c4036 45 not based on accurate values, they just guarantee that the application will
mbed_official 558:0880f51c4036 46 not remain stuck if the I2C communication is corrupted. */
mbed_official 558:0880f51c4036 47 #define FLAG_TIMEOUT ((int)0x1000)
mbed_official 558:0880f51c4036 48 #define LONG_TIMEOUT ((int)0xFFFF)
mbed_official 558:0880f51c4036 49
mbed_official 558:0880f51c4036 50 I2C_TypeDef * I2cHandle;
mbed_official 558:0880f51c4036 51
mbed_official 558:0880f51c4036 52 int i2c0_inited = 0;
mbed_official 558:0880f51c4036 53 int i2c1_inited = 0;
mbed_official 558:0880f51c4036 54
mbed_official 558:0880f51c4036 55 void i2c_init(i2c_t *obj, PinName sda, PinName scl)
mbed_official 558:0880f51c4036 56 {
mbed_official 558:0880f51c4036 57 // Determine the I2C to use
mbed_official 558:0880f51c4036 58 I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
mbed_official 558:0880f51c4036 59 I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
mbed_official 558:0880f51c4036 60
mbed_official 558:0880f51c4036 61 obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
mbed_official 558:0880f51c4036 62 MBED_ASSERT(obj->i2c != (I2CName)NC);
mbed_official 558:0880f51c4036 63
mbed_official 558:0880f51c4036 64 // Enable I2C1 clock and pinout if not done
mbed_official 558:0880f51c4036 65 if ((obj->i2c == I2C_0) && !i2c0_inited) {
mbed_official 558:0880f51c4036 66 i2c0_inited = 1;
mbed_official 558:0880f51c4036 67 // Configure I2C pins
mbed_official 558:0880f51c4036 68 pinmap_pinout(sda, PinMap_I2C_SDA);
mbed_official 558:0880f51c4036 69 pinmap_pinout(scl, PinMap_I2C_SCL);
mbed_official 567:a97fd0eca828 70 pin_mode(sda, PullUp);
mbed_official 567:a97fd0eca828 71 pin_mode(scl, PullUp);
mbed_official 558:0880f51c4036 72 }
mbed_official 558:0880f51c4036 73
mbed_official 558:0880f51c4036 74 // Enable I2C2 clock and pinout if not done
mbed_official 558:0880f51c4036 75 if ((obj->i2c == I2C_1) && !i2c1_inited) {
mbed_official 558:0880f51c4036 76 i2c1_inited = 1;
mbed_official 558:0880f51c4036 77 // Configure I2C pins
mbed_official 558:0880f51c4036 78 pinmap_pinout(sda, PinMap_I2C_SDA);
mbed_official 558:0880f51c4036 79 pinmap_pinout(scl, PinMap_I2C_SCL);
mbed_official 567:a97fd0eca828 80 pin_mode(sda, PullUp);
mbed_official 567:a97fd0eca828 81 pin_mode(scl, PullUp);
mbed_official 558:0880f51c4036 82 }
mbed_official 558:0880f51c4036 83
mbed_official 558:0880f51c4036 84 // Reset to clear pending flags if any
mbed_official 558:0880f51c4036 85 i2c_reset(obj);
mbed_official 558:0880f51c4036 86
mbed_official 558:0880f51c4036 87 // I2C configuration
mbed_official 558:0880f51c4036 88 i2c_frequency(obj, 100000); // 100 kHz per default
mbed_official 558:0880f51c4036 89 obj->is_setAddress = 0;
mbed_official 558:0880f51c4036 90 }
mbed_official 558:0880f51c4036 91
mbed_official 558:0880f51c4036 92 void i2c_frequency(i2c_t *obj, int hz)
mbed_official 558:0880f51c4036 93 {
mbed_official 576:99a3d3d9c43f 94 //MBED_ASSERT((hz == 100000) || (hz == 400000) || (hz == 1000000));
mbed_official 576:99a3d3d9c43f 95 MBED_ASSERT((hz == 100000));
mbed_official 558:0880f51c4036 96 I2cHandle = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 97
mbed_official 558:0880f51c4036 98 // wait before init
mbed_official 558:0880f51c4036 99 I2C_ConfigStruct conf;
mbed_official 558:0880f51c4036 100
mbed_official 558:0880f51c4036 101 conf.mode = I2C_Master;
mbed_official 558:0880f51c4036 102 conf.master.timeout = LONG_TIMEOUT;
mbed_official 576:99a3d3d9c43f 103 conf.master.prescale = 0x61; // Standard mode with Rise Time = 400ns and Fall Time = 100ns
mbed_official 558:0880f51c4036 104
mbed_official 558:0880f51c4036 105 // Common settings: I2C clock = 48 MHz, Analog filter = ON, Digital filter coefficient = 0
mbed_official 576:99a3d3d9c43f 106 // switch (hz) {
mbed_official 576:99a3d3d9c43f 107 // case 100000:
mbed_official 576:99a3d3d9c43f 108 // conf.master.prescale = 0x61; // Standard mode with Rise Time = 400ns and Fall Time = 100ns
mbed_official 576:99a3d3d9c43f 109 // break;
mbed_official 576:99a3d3d9c43f 110 // case 400000:
mbed_official 576:99a3d3d9c43f 111 // break;
mbed_official 576:99a3d3d9c43f 112 // case 1000000:
mbed_official 576:99a3d3d9c43f 113 // break;
mbed_official 576:99a3d3d9c43f 114 // default:
mbed_official 576:99a3d3d9c43f 115 // break;
mbed_official 576:99a3d3d9c43f 116 // }
mbed_official 558:0880f51c4036 117
mbed_official 558:0880f51c4036 118 // I2C configuration
mbed_official 558:0880f51c4036 119 I2C_Init(I2cHandle, conf);
mbed_official 558:0880f51c4036 120 }
mbed_official 558:0880f51c4036 121
mbed_official 558:0880f51c4036 122 inline int i2c_start(i2c_t *obj)
mbed_official 558:0880f51c4036 123 {
mbed_official 558:0880f51c4036 124 obj->is_setAddress = 0;
mbed_official 558:0880f51c4036 125
mbed_official 558:0880f51c4036 126 return 0;
mbed_official 558:0880f51c4036 127 }
mbed_official 558:0880f51c4036 128
mbed_official 558:0880f51c4036 129 inline int i2c_stop(i2c_t *obj)
mbed_official 558:0880f51c4036 130 {
mbed_official 558:0880f51c4036 131 I2cHandle = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 132
mbed_official 558:0880f51c4036 133 // Generate the STOP condition
mbed_official 558:0880f51c4036 134 I2C_Stop(I2cHandle);
mbed_official 558:0880f51c4036 135 I2C_Reset(I2cHandle);
mbed_official 576:99a3d3d9c43f 136
mbed_official 558:0880f51c4036 137 obj->is_setAddress = 0;
mbed_official 576:99a3d3d9c43f 138
mbed_official 558:0880f51c4036 139 return 0;
mbed_official 558:0880f51c4036 140 }
mbed_official 558:0880f51c4036 141
mbed_official 558:0880f51c4036 142 int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
mbed_official 558:0880f51c4036 143 {
mbed_official 558:0880f51c4036 144 I2cHandle = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 145 int count;
mbed_official 558:0880f51c4036 146 int value;
mbed_official 576:99a3d3d9c43f 147
mbed_official 558:0880f51c4036 148 if(!obj->is_setAddress)
mbed_official 558:0880f51c4036 149 {
mbed_official 558:0880f51c4036 150 if( I2C_Start(I2cHandle, address, I2C_READ_SA7) == ERROR )
mbed_official 558:0880f51c4036 151 {
mbed_official 576:99a3d3d9c43f 152 return -1;
mbed_official 558:0880f51c4036 153 }
mbed_official 558:0880f51c4036 154 obj->is_setAddress = 1;
mbed_official 558:0880f51c4036 155 obj->ADDRESS = address;
mbed_official 558:0880f51c4036 156 }
mbed_official 558:0880f51c4036 157 else
mbed_official 558:0880f51c4036 158 {
mbed_official 558:0880f51c4036 159 I2C_Restart_Structure(I2cHandle, address, I2C_READ_SA7);
mbed_official 558:0880f51c4036 160 obj->ADDRESS = address;
mbed_official 558:0880f51c4036 161 }
mbed_official 558:0880f51c4036 162
mbed_official 558:0880f51c4036 163 // Read all bytes
mbed_official 558:0880f51c4036 164 for (count = 0; count < (length-1); count++) {
mbed_official 576:99a3d3d9c43f 165 if( (value = i2c_byte_read(obj, 0)) == -1) {
mbed_official 576:99a3d3d9c43f 166 return value;
mbed_official 576:99a3d3d9c43f 167 }
mbed_official 558:0880f51c4036 168 data[count] = (char)value;
mbed_official 558:0880f51c4036 169 }
mbed_official 558:0880f51c4036 170
mbed_official 558:0880f51c4036 171 if(stop){
mbed_official 576:99a3d3d9c43f 172 if( (value = i2c_byte_read(obj, 1)) == -1) {
mbed_official 576:99a3d3d9c43f 173 return value;
mbed_official 576:99a3d3d9c43f 174 }
mbed_official 558:0880f51c4036 175 data[count] = (char)value;
mbed_official 576:99a3d3d9c43f 176
mbed_official 576:99a3d3d9c43f 177 i2c_stop(obj);
mbed_official 576:99a3d3d9c43f 178 obj->is_setAddress =1;
mbed_official 576:99a3d3d9c43f 179 count++;
mbed_official 576:99a3d3d9c43f 180 }
mbed_official 558:0880f51c4036 181 else{
mbed_official 576:99a3d3d9c43f 182 if( (value = i2c_byte_read(obj, 0)) == -1) {
mbed_official 576:99a3d3d9c43f 183
mbed_official 576:99a3d3d9c43f 184 return value;
mbed_official 576:99a3d3d9c43f 185 }
mbed_official 558:0880f51c4036 186 data[count] = (char)value;
mbed_official 576:99a3d3d9c43f 187 count++;
mbed_official 558:0880f51c4036 188 }
mbed_official 576:99a3d3d9c43f 189
mbed_official 558:0880f51c4036 190 return count;
mbed_official 576:99a3d3d9c43f 191
mbed_official 558:0880f51c4036 192 }
mbed_official 558:0880f51c4036 193
mbed_official 558:0880f51c4036 194 int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
mbed_official 558:0880f51c4036 195 {
mbed_official 558:0880f51c4036 196 I2cHandle = (I2C_TypeDef *)(obj->i2c);
mbed_official 576:99a3d3d9c43f 197 int count =0;
mbed_official 576:99a3d3d9c43f 198
mbed_official 558:0880f51c4036 199 if(!obj->is_setAddress)
mbed_official 558:0880f51c4036 200 {
mbed_official 558:0880f51c4036 201 if( I2C_Start(I2cHandle, address, I2C_WRITE_SA7) == ERROR )
mbed_official 558:0880f51c4036 202 {
mbed_official 576:99a3d3d9c43f 203 return -1;
mbed_official 558:0880f51c4036 204 }
mbed_official 558:0880f51c4036 205 obj->is_setAddress = 1;
mbed_official 558:0880f51c4036 206 obj->ADDRESS = address;
mbed_official 576:99a3d3d9c43f 207 }
mbed_official 558:0880f51c4036 208 else
mbed_official 558:0880f51c4036 209 {
mbed_official 558:0880f51c4036 210 I2C_Restart_Structure(I2cHandle, address, I2C_WRITE_SA7);
mbed_official 558:0880f51c4036 211 obj->ADDRESS = address;
mbed_official 576:99a3d3d9c43f 212
mbed_official 558:0880f51c4036 213 }
mbed_official 558:0880f51c4036 214
mbed_official 558:0880f51c4036 215 for (count = 0; count < length; count++) {
mbed_official 558:0880f51c4036 216 i2c_byte_write(obj, data[count]);
mbed_official 576:99a3d3d9c43f 217 wait_us(1);
mbed_official 558:0880f51c4036 218 }
mbed_official 558:0880f51c4036 219
mbed_official 576:99a3d3d9c43f 220
mbed_official 576:99a3d3d9c43f 221 if(length == 0x00)
mbed_official 576:99a3d3d9c43f 222 {
mbed_official 576:99a3d3d9c43f 223 I2C_GPIO();
mbed_official 576:99a3d3d9c43f 224 i2c_byte_write(obj, 0xff);
mbed_official 576:99a3d3d9c43f 225 GPIO_I2C();
mbed_official 576:99a3d3d9c43f 226 }
mbed_official 558:0880f51c4036 227 // If not repeated start, send stop
mbed_official 558:0880f51c4036 228 if (stop) {
mbed_official 558:0880f51c4036 229 i2c_stop(obj);
mbed_official 576:99a3d3d9c43f 230 }
mbed_official 576:99a3d3d9c43f 231 else
mbed_official 576:99a3d3d9c43f 232 {
mbed_official 576:99a3d3d9c43f 233 i2c_reset(obj);
mbed_official 576:99a3d3d9c43f 234
mbed_official 558:0880f51c4036 235 }
mbed_official 576:99a3d3d9c43f 236 return count;
mbed_official 558:0880f51c4036 237 }
mbed_official 558:0880f51c4036 238
mbed_official 558:0880f51c4036 239 int i2c_byte_read(i2c_t *obj, int last)
mbed_official 558:0880f51c4036 240 {
mbed_official 558:0880f51c4036 241 I2cHandle = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 242
mbed_official 558:0880f51c4036 243 return I2C_ReceiveData(I2cHandle, last);
mbed_official 558:0880f51c4036 244 }
mbed_official 558:0880f51c4036 245
mbed_official 558:0880f51c4036 246 int i2c_byte_write(i2c_t *obj, int data)
mbed_official 558:0880f51c4036 247 {
mbed_official 558:0880f51c4036 248 I2cHandle = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 249 return I2C_SendDataAck(I2cHandle,(uint8_t)data);
mbed_official 558:0880f51c4036 250 }
mbed_official 558:0880f51c4036 251
mbed_official 558:0880f51c4036 252 void i2c_reset(i2c_t *obj)
mbed_official 558:0880f51c4036 253 {
mbed_official 558:0880f51c4036 254 I2cHandle = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 255
mbed_official 558:0880f51c4036 256 I2C_Reset(I2cHandle);
mbed_official 558:0880f51c4036 257 }
mbed_official 558:0880f51c4036 258
mbed_official 558:0880f51c4036 259 //#if DEVICE_I2CSLAVE
mbed_official 558:0880f51c4036 260 //
mbed_official 558:0880f51c4036 261 //void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
mbed_official 558:0880f51c4036 262 //{
mbed_official 558:0880f51c4036 263 // I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 264 // uint16_t tmpreg = 0;
mbed_official 558:0880f51c4036 265 //
mbed_official 558:0880f51c4036 266 // // disable
mbed_official 558:0880f51c4036 267 // i2c->OAR1 &= (uint32_t)(~I2C_OAR1_OA1EN);
mbed_official 558:0880f51c4036 268 // // Get the old register value
mbed_official 558:0880f51c4036 269 // tmpreg = i2c->OAR1;
mbed_official 558:0880f51c4036 270 // // Reset address bits
mbed_official 558:0880f51c4036 271 // tmpreg &= 0xFC00;
mbed_official 558:0880f51c4036 272 // // Set new address
mbed_official 558:0880f51c4036 273 // tmpreg |= (uint16_t)((uint16_t)address & (uint16_t)0x00FE); // 7-bits
mbed_official 558:0880f51c4036 274 // // Store the new register value
mbed_official 558:0880f51c4036 275 // i2c->OAR1 = tmpreg;
mbed_official 558:0880f51c4036 276 // // enable
mbed_official 558:0880f51c4036 277 // i2c->OAR1 |= I2C_OAR1_OA1EN;
mbed_official 558:0880f51c4036 278 //}
mbed_official 558:0880f51c4036 279 //
mbed_official 558:0880f51c4036 280 //void i2c_slave_mode(i2c_t *obj, int enable_slave)
mbed_official 558:0880f51c4036 281 //{
mbed_official 558:0880f51c4036 282 // I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 283 // uint16_t tmpreg;
mbed_official 558:0880f51c4036 284 //
mbed_official 558:0880f51c4036 285 // // Get the old register value
mbed_official 558:0880f51c4036 286 // tmpreg = i2c->OAR1;
mbed_official 558:0880f51c4036 287 //
mbed_official 558:0880f51c4036 288 // // Enable / disable slave
mbed_official 558:0880f51c4036 289 // if (enable_slave == 1) {
mbed_official 558:0880f51c4036 290 // tmpreg |= I2C_OAR1_OA1EN;
mbed_official 558:0880f51c4036 291 // } else {
mbed_official 558:0880f51c4036 292 // tmpreg &= (uint32_t)(~I2C_OAR1_OA1EN);
mbed_official 558:0880f51c4036 293 // }
mbed_official 558:0880f51c4036 294 //
mbed_official 558:0880f51c4036 295 // // Set new mode
mbed_official 558:0880f51c4036 296 // i2c->OAR1 = tmpreg;
mbed_official 558:0880f51c4036 297 //}
mbed_official 558:0880f51c4036 298 //
mbed_official 558:0880f51c4036 299 //// See I2CSlave.h
mbed_official 558:0880f51c4036 300 //#define NoData 0 // the slave has not been addressed
mbed_official 558:0880f51c4036 301 //#define ReadAddressed 1 // the master has requested a read from this slave (slave = transmitter)
mbed_official 558:0880f51c4036 302 //#define WriteGeneral 2 // the master is writing to all slave
mbed_official 558:0880f51c4036 303 //#define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
mbed_official 558:0880f51c4036 304 //
mbed_official 558:0880f51c4036 305 //int i2c_slave_receive(i2c_t *obj)
mbed_official 558:0880f51c4036 306 //{
mbed_official 558:0880f51c4036 307 // I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 308 // int retValue = NoData;
mbed_official 558:0880f51c4036 309 //
mbed_official 558:0880f51c4036 310 // if (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY) == 1) {
mbed_official 558:0880f51c4036 311 // if (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_ADDR) == 1) {
mbed_official 558:0880f51c4036 312 // if (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_DIR) == 1)
mbed_official 558:0880f51c4036 313 // retValue = ReadAddressed;
mbed_official 558:0880f51c4036 314 // else
mbed_official 558:0880f51c4036 315 // retValue = WriteAddressed;
mbed_official 558:0880f51c4036 316 //
mbed_official 558:0880f51c4036 317 // __HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_ADDR);
mbed_official 558:0880f51c4036 318 // }
mbed_official 558:0880f51c4036 319 // }
mbed_official 558:0880f51c4036 320 //
mbed_official 558:0880f51c4036 321 // return (retValue);
mbed_official 558:0880f51c4036 322 //}
mbed_official 558:0880f51c4036 323 //
mbed_official 558:0880f51c4036 324 //int i2c_slave_read(i2c_t *obj, char *data, int length)
mbed_official 558:0880f51c4036 325 //{
mbed_official 558:0880f51c4036 326 // char size = 0;
mbed_official 558:0880f51c4036 327 //
mbed_official 558:0880f51c4036 328 // while (size < length) data[size++] = (char)i2c_byte_read(obj, 0);
mbed_official 558:0880f51c4036 329 //
mbed_official 558:0880f51c4036 330 // return size;
mbed_official 558:0880f51c4036 331 //}
mbed_official 558:0880f51c4036 332 //
mbed_official 558:0880f51c4036 333 //int i2c_slave_write(i2c_t *obj, const char *data, int length)
mbed_official 558:0880f51c4036 334 //{
mbed_official 558:0880f51c4036 335 // char size = 0;
mbed_official 558:0880f51c4036 336 // I2cHandle.Instance = (I2C_TypeDef *)(obj->i2c);
mbed_official 558:0880f51c4036 337 //
mbed_official 558:0880f51c4036 338 // do {
mbed_official 558:0880f51c4036 339 // i2c_byte_write(obj, data[size]);
mbed_official 558:0880f51c4036 340 // size++;
mbed_official 558:0880f51c4036 341 // } while (size < length);
mbed_official 558:0880f51c4036 342 //
mbed_official 558:0880f51c4036 343 // return size;
mbed_official 558:0880f51c4036 344 //}
mbed_official 558:0880f51c4036 345 //
mbed_official 558:0880f51c4036 346 //
mbed_official 558:0880f51c4036 347 //#endif // DEVICE_I2CSLAVE
mbed_official 558:0880f51c4036 348
mbed_official 558:0880f51c4036 349 #endif // DEVICE_I2C