mbed library sources. Supersedes mbed-src.

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

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
187:0387e8f68319
mbed library release version 165

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