takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers I2CSlave.cpp Source File

I2CSlave.cpp

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