mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
I2CSlave.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include "drivers/I2CSlave.h" 00018 00019 #if DEVICE_I2CSLAVE 00020 00021 namespace mbed { 00022 00023 I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c() 00024 { 00025 i2c_init(&_i2c, sda, scl); 00026 i2c_frequency(&_i2c, 100000); 00027 i2c_slave_mode(&_i2c, 1); 00028 } 00029 00030 void I2CSlave::frequency(int hz) 00031 { 00032 i2c_frequency(&_i2c, hz); 00033 } 00034 00035 void I2CSlave::address(int address) 00036 { 00037 int addr = (address & 0xFF) | 1; 00038 i2c_slave_address(&_i2c, 0, addr, 0); 00039 } 00040 00041 int I2CSlave::receive(void) 00042 { 00043 return i2c_slave_receive(&_i2c); 00044 } 00045 00046 int I2CSlave::read(char *data, int length) 00047 { 00048 return i2c_slave_read(&_i2c, data, length) != length; 00049 } 00050 00051 int I2CSlave::read(void) 00052 { 00053 return i2c_byte_read(&_i2c, 0); 00054 } 00055 00056 int I2CSlave::write(const char *data, int length) 00057 { 00058 return i2c_slave_write(&_i2c, data, length) != length; 00059 } 00060 00061 int I2CSlave::write(int data) 00062 { 00063 return i2c_byte_write(&_i2c, data); 00064 } 00065 00066 void I2CSlave::stop(void) 00067 { 00068 i2c_stop(&_i2c); 00069 } 00070 00071 } 00072 00073 #endif
Generated on Tue Jul 12 2022 20:41:15 by 1.7.2