mbed
Dependents: DHTSensor_Test K64F_eCompass_OneNET_JW
i2c_api.h@0:2cc6bb4d7fea, 2015-02-25 (annotated)
- Committer:
- mbotkinl
- Date:
- Wed Feb 25 20:22:22 2015 +0000
- Revision:
- 0:2cc6bb4d7fea
Working code to read Temperature and Humidity readings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbotkinl | 0:2cc6bb4d7fea | 1 | /* mbed Microcontroller Library |
mbotkinl | 0:2cc6bb4d7fea | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbotkinl | 0:2cc6bb4d7fea | 3 | * |
mbotkinl | 0:2cc6bb4d7fea | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbotkinl | 0:2cc6bb4d7fea | 5 | * you may not use this file except in compliance with the License. |
mbotkinl | 0:2cc6bb4d7fea | 6 | * You may obtain a copy of the License at |
mbotkinl | 0:2cc6bb4d7fea | 7 | * |
mbotkinl | 0:2cc6bb4d7fea | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbotkinl | 0:2cc6bb4d7fea | 9 | * |
mbotkinl | 0:2cc6bb4d7fea | 10 | * Unless required by applicable law or agreed to in writing, software |
mbotkinl | 0:2cc6bb4d7fea | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbotkinl | 0:2cc6bb4d7fea | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbotkinl | 0:2cc6bb4d7fea | 13 | * See the License for the specific language governing permissions and |
mbotkinl | 0:2cc6bb4d7fea | 14 | * limitations under the License. |
mbotkinl | 0:2cc6bb4d7fea | 15 | */ |
mbotkinl | 0:2cc6bb4d7fea | 16 | #ifndef MBED_I2C_API_H |
mbotkinl | 0:2cc6bb4d7fea | 17 | #define MBED_I2C_API_H |
mbotkinl | 0:2cc6bb4d7fea | 18 | |
mbotkinl | 0:2cc6bb4d7fea | 19 | #include "device.h" |
mbotkinl | 0:2cc6bb4d7fea | 20 | |
mbotkinl | 0:2cc6bb4d7fea | 21 | #if DEVICE_I2C |
mbotkinl | 0:2cc6bb4d7fea | 22 | |
mbotkinl | 0:2cc6bb4d7fea | 23 | #ifdef __cplusplus |
mbotkinl | 0:2cc6bb4d7fea | 24 | extern "C" { |
mbotkinl | 0:2cc6bb4d7fea | 25 | #endif |
mbotkinl | 0:2cc6bb4d7fea | 26 | |
mbotkinl | 0:2cc6bb4d7fea | 27 | typedef struct i2c_s i2c_t; |
mbotkinl | 0:2cc6bb4d7fea | 28 | |
mbotkinl | 0:2cc6bb4d7fea | 29 | enum { |
mbotkinl | 0:2cc6bb4d7fea | 30 | I2C_ERROR_NO_SLAVE = -1, |
mbotkinl | 0:2cc6bb4d7fea | 31 | I2C_ERROR_BUS_BUSY = -2 |
mbotkinl | 0:2cc6bb4d7fea | 32 | }; |
mbotkinl | 0:2cc6bb4d7fea | 33 | |
mbotkinl | 0:2cc6bb4d7fea | 34 | void i2c_init (i2c_t *obj, PinName sda, PinName scl); |
mbotkinl | 0:2cc6bb4d7fea | 35 | void i2c_frequency (i2c_t *obj, int hz); |
mbotkinl | 0:2cc6bb4d7fea | 36 | int i2c_start (i2c_t *obj); |
mbotkinl | 0:2cc6bb4d7fea | 37 | int i2c_stop (i2c_t *obj); |
mbotkinl | 0:2cc6bb4d7fea | 38 | int i2c_read (i2c_t *obj, int address, char *data, int length, int stop); |
mbotkinl | 0:2cc6bb4d7fea | 39 | int i2c_write (i2c_t *obj, int address, const char *data, int length, int stop); |
mbotkinl | 0:2cc6bb4d7fea | 40 | void i2c_reset (i2c_t *obj); |
mbotkinl | 0:2cc6bb4d7fea | 41 | int i2c_byte_read (i2c_t *obj, int last); |
mbotkinl | 0:2cc6bb4d7fea | 42 | int i2c_byte_write (i2c_t *obj, int data); |
mbotkinl | 0:2cc6bb4d7fea | 43 | |
mbotkinl | 0:2cc6bb4d7fea | 44 | #if DEVICE_I2CSLAVE |
mbotkinl | 0:2cc6bb4d7fea | 45 | void i2c_slave_mode (i2c_t *obj, int enable_slave); |
mbotkinl | 0:2cc6bb4d7fea | 46 | int i2c_slave_receive(i2c_t *obj); |
mbotkinl | 0:2cc6bb4d7fea | 47 | int i2c_slave_read (i2c_t *obj, char *data, int length); |
mbotkinl | 0:2cc6bb4d7fea | 48 | int i2c_slave_write (i2c_t *obj, const char *data, int length); |
mbotkinl | 0:2cc6bb4d7fea | 49 | void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask); |
mbotkinl | 0:2cc6bb4d7fea | 50 | #endif |
mbotkinl | 0:2cc6bb4d7fea | 51 | |
mbotkinl | 0:2cc6bb4d7fea | 52 | #ifdef __cplusplus |
mbotkinl | 0:2cc6bb4d7fea | 53 | } |
mbotkinl | 0:2cc6bb4d7fea | 54 | #endif |
mbotkinl | 0:2cc6bb4d7fea | 55 | |
mbotkinl | 0:2cc6bb4d7fea | 56 | #endif |
mbotkinl | 0:2cc6bb4d7fea | 57 | |
mbotkinl | 0:2cc6bb4d7fea | 58 | #endif |