mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Thu Sep 06 13:40:20 2018 +0100
Revision:
187:0387e8f68319
Parent:
149:156823d33999
Child:
189:f392fc9709a3
mbed-dev library. Release version 163

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /* mbed Microcontroller Library
<> 149:156823d33999 2 * Copyright (c) 2006-2013 ARM Limited
<> 149:156823d33999 3 *
<> 149:156823d33999 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 149:156823d33999 5 * you may not use this file except in compliance with the License.
<> 149:156823d33999 6 * You may obtain a copy of the License at
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 149:156823d33999 9 *
<> 149:156823d33999 10 * Unless required by applicable law or agreed to in writing, software
<> 149:156823d33999 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 149:156823d33999 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 149:156823d33999 13 * See the License for the specific language governing permissions and
<> 149:156823d33999 14 * limitations under the License.
<> 149:156823d33999 15 */
<> 149:156823d33999 16 #include "drivers/I2CSlave.h"
<> 149:156823d33999 17
<> 149:156823d33999 18 #if DEVICE_I2CSLAVE
<> 149:156823d33999 19
<> 149:156823d33999 20 namespace mbed {
<> 149:156823d33999 21
AnnaBridge 187:0387e8f68319 22 I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c()
AnnaBridge 187:0387e8f68319 23 {
<> 149:156823d33999 24 i2c_init(&_i2c, sda, scl);
<> 149:156823d33999 25 i2c_frequency(&_i2c, 100000);
<> 149:156823d33999 26 i2c_slave_mode(&_i2c, 1);
<> 149:156823d33999 27 }
<> 149:156823d33999 28
AnnaBridge 187:0387e8f68319 29 void I2CSlave::frequency(int hz)
AnnaBridge 187:0387e8f68319 30 {
<> 149:156823d33999 31 i2c_frequency(&_i2c, hz);
<> 149:156823d33999 32 }
<> 149:156823d33999 33
AnnaBridge 187:0387e8f68319 34 void I2CSlave::address(int address)
AnnaBridge 187:0387e8f68319 35 {
<> 149:156823d33999 36 int addr = (address & 0xFF) | 1;
<> 149:156823d33999 37 i2c_slave_address(&_i2c, 0, addr, 0);
<> 149:156823d33999 38 }
<> 149:156823d33999 39
AnnaBridge 187:0387e8f68319 40 int I2CSlave::receive(void)
AnnaBridge 187:0387e8f68319 41 {
<> 149:156823d33999 42 return i2c_slave_receive(&_i2c);
<> 149:156823d33999 43 }
<> 149:156823d33999 44
AnnaBridge 187:0387e8f68319 45 int I2CSlave::read(char *data, int length)
AnnaBridge 187:0387e8f68319 46 {
<> 149:156823d33999 47 return i2c_slave_read(&_i2c, data, length) != length;
<> 149:156823d33999 48 }
<> 149:156823d33999 49
AnnaBridge 187:0387e8f68319 50 int I2CSlave::read(void)
AnnaBridge 187:0387e8f68319 51 {
<> 149:156823d33999 52 return i2c_byte_read(&_i2c, 0);
<> 149:156823d33999 53 }
<> 149:156823d33999 54
AnnaBridge 187:0387e8f68319 55 int I2CSlave::write(const char *data, int length)
AnnaBridge 187:0387e8f68319 56 {
<> 149:156823d33999 57 return i2c_slave_write(&_i2c, data, length) != length;
<> 149:156823d33999 58 }
<> 149:156823d33999 59
AnnaBridge 187:0387e8f68319 60 int I2CSlave::write(int data)
AnnaBridge 187:0387e8f68319 61 {
<> 149:156823d33999 62 return i2c_byte_write(&_i2c, data);
<> 149:156823d33999 63 }
<> 149:156823d33999 64
AnnaBridge 187:0387e8f68319 65 void I2CSlave::stop(void)
AnnaBridge 187:0387e8f68319 66 {
<> 149:156823d33999 67 i2c_stop(&_i2c);
<> 149:156823d33999 68 }
<> 149:156823d33999 69
<> 149:156823d33999 70 }
<> 149:156823d33999 71
<> 149:156823d33999 72 #endif