NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
i2c.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef CUSTOM_I2C_I2C_H_
20 #define CUSTOM_I2C_I2C_H_
21 
22 #include <stdint.h>
23 
24 #endif // CUSTOM_I2C_I2C_H_
25 
26 namespace custom_i2c {
27 // bus=1 for interface I2C2 on BBB
28 // returns handle to be used in remainder functions
29 // addr is a 7-bit value (so, for example the BMP085 datasheet specifies
30 // 0xEE, so we need to right-shift by 1 and use 0x77 for this function)
31 int i2c_open(const char* bus, uint8_t addr);
32 
33 int i2c_set_retries(int handle, int retries);
34 int i2c_set_timeout(int handle, int timeout);
35 
36 // These functions return -1 on error, otherwise return the number of bytes
37 // read/written. To perform a 'repeated start' use the i2c_write_read function
38 // which can write some data and then immediately read data without a stop bit
39 // in between.
40 int i2c_write(int handle, uint8_t* buf, unsigned int length);
41 int i2c_read(int handle, uint8_t* buf, unsigned int length);
42 int i2c_write_read(int handle, uint8_t addr_w, uint8_t* buf_w,
43  unsigned int len_w, uint8_t addr_r, uint8_t* buf_r,
44  unsigned int len_r);
45 int i2c_write_ignore_nack(int handle, uint8_t addr_w, uint8_t* buf,
46  unsigned int length);
47 int i2c_read_no_ack(int handle, uint8_t addr_r, uint8_t* buf,
48  unsigned int length);
49 int i2c_write_byte(int handle, uint8_t val);
50 int i2c_read_byte(int handle, uint8_t* val);
51 
52 // These functions return -1 on error, otherwise return 0 on success
53 int i2c_close(int handle);
54 // Provides an inaccurate delay (may be useful for waiting for ADC etc).
55 // The maximum delay is 999msec
56 int delay_ms(unsigned int msec);
57 
58 } // namespace custom_i2c
custom_i2c
Definition: i2c.h:26
custom_i2c::i2c_write
int i2c_write(int handle, uint8_t *buf, unsigned int length)
Definition: i2c.cc:57
custom_i2c::i2c_read_no_ack
int i2c_read_no_ack(int handle, uint8_t addr_r, uint8_t *buf, unsigned int length)
Definition: i2c.cc:148
custom_i2c::i2c_read_byte
int i2c_read_byte(int handle, uint8_t *val)
Definition: i2c.cc:82
custom_i2c::i2c_set_timeout
int i2c_set_timeout(int handle, int timeout)
Definition: i2c.cc:38
custom_i2c::i2c_write_ignore_nack
int i2c_write_ignore_nack(int handle, uint8_t addr_w, uint8_t *buf, unsigned int length)
Definition: i2c.cc:128
custom_i2c::i2c_close
int i2c_close(int handle)
Definition: i2c.cc:91
custom_i2c::delay_ms
int delay_ms(unsigned int msec)
Definition: i2c.cc:168
custom_i2c::i2c_write_byte
int i2c_write_byte(int handle, uint8_t val)
Definition: i2c.cc:65
custom_i2c::i2c_read
int i2c_read(int handle, uint8_t *buf, unsigned int length)
Definition: i2c.cc:74
custom_i2c::i2c_open
int i2c_open(const char *bus, uint8_t addr)
Definition: i2c.cc:42
custom_i2c::i2c_set_retries
int i2c_set_retries(int handle, int retries)
Definition: i2c.cc:34
custom_i2c::i2c_write_read
int i2c_write_read(int handle, uint8_t addr_w, uint8_t *buf_w, unsigned int len_w, uint8_t addr_r, uint8_t *buf_r, unsigned int len_r)
Definition: i2c.cc:101