Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
drivers/I2CSlave.cpp@170:54ff26da7eb6, 2017-07-04 (annotated)
- Committer:
- thedo
- Date:
- Tue Jul 04 06:23:13 2017 +0000
- Revision:
- 170:54ff26da7eb6
- Parent:
- 167:1657b442184c
project opencv 3.1 on GR PEACH board, no use SD card.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thedo | 167:1657b442184c | 1 | /* mbed Microcontroller Library |
thedo | 167:1657b442184c | 2 | * Copyright (c) 2006-2013 ARM Limited |
thedo | 167:1657b442184c | 3 | * |
thedo | 167:1657b442184c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
thedo | 167:1657b442184c | 5 | * you may not use this file except in compliance with the License. |
thedo | 167:1657b442184c | 6 | * You may obtain a copy of the License at |
thedo | 167:1657b442184c | 7 | * |
thedo | 167:1657b442184c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
thedo | 167:1657b442184c | 9 | * |
thedo | 167:1657b442184c | 10 | * Unless required by applicable law or agreed to in writing, software |
thedo | 167:1657b442184c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
thedo | 167:1657b442184c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
thedo | 167:1657b442184c | 13 | * See the License for the specific language governing permissions and |
thedo | 167:1657b442184c | 14 | * limitations under the License. |
thedo | 167:1657b442184c | 15 | */ |
thedo | 167:1657b442184c | 16 | #include "drivers/I2CSlave.h" |
thedo | 167:1657b442184c | 17 | |
thedo | 167:1657b442184c | 18 | #if DEVICE_I2CSLAVE |
thedo | 167:1657b442184c | 19 | |
thedo | 167:1657b442184c | 20 | namespace mbed { |
thedo | 167:1657b442184c | 21 | |
thedo | 167:1657b442184c | 22 | I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c() { |
thedo | 167:1657b442184c | 23 | i2c_init(&_i2c, sda, scl); |
thedo | 167:1657b442184c | 24 | i2c_frequency(&_i2c, 100000); |
thedo | 167:1657b442184c | 25 | i2c_slave_mode(&_i2c, 1); |
thedo | 167:1657b442184c | 26 | } |
thedo | 167:1657b442184c | 27 | |
thedo | 167:1657b442184c | 28 | void I2CSlave::frequency(int hz) { |
thedo | 167:1657b442184c | 29 | i2c_frequency(&_i2c, hz); |
thedo | 167:1657b442184c | 30 | } |
thedo | 167:1657b442184c | 31 | |
thedo | 167:1657b442184c | 32 | void I2CSlave::address(int address) { |
thedo | 167:1657b442184c | 33 | int addr = (address & 0xFF) | 1; |
thedo | 167:1657b442184c | 34 | i2c_slave_address(&_i2c, 0, addr, 0); |
thedo | 167:1657b442184c | 35 | } |
thedo | 167:1657b442184c | 36 | |
thedo | 167:1657b442184c | 37 | int I2CSlave::receive(void) { |
thedo | 167:1657b442184c | 38 | return i2c_slave_receive(&_i2c); |
thedo | 167:1657b442184c | 39 | } |
thedo | 167:1657b442184c | 40 | |
thedo | 167:1657b442184c | 41 | int I2CSlave::read(char *data, int length) { |
thedo | 167:1657b442184c | 42 | return i2c_slave_read(&_i2c, data, length) != length; |
thedo | 167:1657b442184c | 43 | } |
thedo | 167:1657b442184c | 44 | |
thedo | 167:1657b442184c | 45 | int I2CSlave::read(void) { |
thedo | 167:1657b442184c | 46 | return i2c_byte_read(&_i2c, 0); |
thedo | 167:1657b442184c | 47 | } |
thedo | 167:1657b442184c | 48 | |
thedo | 167:1657b442184c | 49 | int I2CSlave::write(const char *data, int length) { |
thedo | 167:1657b442184c | 50 | return i2c_slave_write(&_i2c, data, length) != length; |
thedo | 167:1657b442184c | 51 | } |
thedo | 167:1657b442184c | 52 | |
thedo | 167:1657b442184c | 53 | int I2CSlave::write(int data) { |
thedo | 167:1657b442184c | 54 | return i2c_byte_write(&_i2c, data); |
thedo | 167:1657b442184c | 55 | } |
thedo | 167:1657b442184c | 56 | |
thedo | 167:1657b442184c | 57 | void I2CSlave::stop(void) { |
thedo | 167:1657b442184c | 58 | i2c_stop(&_i2c); |
thedo | 167:1657b442184c | 59 | } |
thedo | 167:1657b442184c | 60 | |
thedo | 167:1657b442184c | 61 | } |
thedo | 167:1657b442184c | 62 | |
thedo | 167:1657b442184c | 63 | #endif |
thedo | 167:1657b442184c | 64 |