Contiki-NG
board-i2c.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 /*---------------------------------------------------------------------------*/
31 /**
32  * \addtogroup sensortag-cc26xx-peripherals
33  * @{
34  *
35  * \defgroup sensortag-cc26xx-i2c SensorTag 2.0 I2C functions
36  * @{
37  *
38  * \file
39  * Header file for the Sensortag I2C Driver
40  */
41 /*---------------------------------------------------------------------------*/
42 #ifndef BOARD_I2C_H_
43 #define BOARD_I2C_H_
44 /*---------------------------------------------------------------------------*/
45 #include <stdint.h>
46 #include <stdbool.h>
47 /*---------------------------------------------------------------------------*/
48 #define BOARD_I2C_INTERFACE_0 0
49 #define BOARD_I2C_INTERFACE_1 1
50 /*---------------------------------------------------------------------------*/
51 /**
52  * \brief Put the I2C controller in a known state
53  *
54  * In this state, pins SDA and SCL will be under i2c control and pins SDA HP
55  * and SCL HP will be configured as gpio inputs. This is equal to selecting
56  * BOARD_I2C_INTERFACE_0, but without selecting a slave device address
57  */
58 #define board_i2c_deselect() board_i2c_select(BOARD_I2C_INTERFACE_0, 0)
59 /*---------------------------------------------------------------------------*/
60 /**
61  * \brief Select an I2C slave
62  * \param interface The I2C interface to be used (BOARD_I2C_INTERFACE_0 or _1)
63  * \param slave_addr The slave's address
64  *
65  * The various sensors on the sensortag are connected either on interface 0 or
66  * 1. All sensors are connected to interface 0, with the exception of the MPU
67  * that is connected to 1.
68  */
69 void board_i2c_select(uint8_t interface, uint8_t slave_addr);
70 
71 /**
72  * \brief Burst read from an I2C device
73  * \param buf Pointer to a buffer where the read data will be stored
74  * \param len Number of bytes to read
75  * \return True on success
76  */
77 bool board_i2c_read(uint8_t *buf, uint8_t len);
78 
79 /**
80  * \brief Burst write to an I2C device
81  * \param buf Pointer to the buffer to be written
82  * \param len Number of bytes to write
83  * \return True on success
84  */
85 bool board_i2c_write(uint8_t *buf, uint8_t len);
86 
87 /**
88  * \brief Single write to an I2C device
89  * \param data The byte to write
90  * \return True on success
91  */
92 bool board_i2c_write_single(uint8_t data);
93 
94 /**
95  * \brief Write and read in one operation
96  * \param wdata Pointer to the buffer to be written
97  * \param wlen Number of bytes to write
98  * \param rdata Pointer to a buffer where the read data will be stored
99  * \param rlen Number of bytes to read
100  * \return True on success
101  */
102 bool board_i2c_write_read(uint8_t *wdata, uint8_t wlen, uint8_t *rdata,
103  uint8_t rlen);
104 
105 /**
106  * \brief Enables the I2C peripheral with defaults
107  *
108  * This function is called to wakeup and initialise the I2C.
109  *
110  * This function can be called explicitly, but it will also be called
111  * automatically by board_i2c_select() when required. One of those two
112  * functions MUST be called before any other I2C operation after a chip
113  * sleep / wakeup cycle or after a call to board_i2c_shutdown(). Failing to do
114  * so will lead to a bus fault.
115  */
116 void board_i2c_wakeup(void);
117 
118 /**
119  * \brief Stops the I2C peripheral and restores pins to s/w control
120  *
121  * This function is called automatically by the board's LPM logic, but it
122  * can also be called explicitly.
123  */
124 void board_i2c_shutdown(void);
125 /*---------------------------------------------------------------------------*/
126 #endif /* BOARD_I2C_H_ */
127 /*---------------------------------------------------------------------------*/
128 /**
129  * @}
130  * @}
131  */
void board_i2c_shutdown()
Stops the I2C peripheral and restores pins to s/w control.
Definition: board-i2c.c:114
bool board_i2c_read(uint8_t *data, uint8_t len)
Burst read from an I2C device.
Definition: board-i2c.c:207
bool board_i2c_write_read(uint8_t *wdata, uint8_t wlen, uint8_t *rdata, uint8_t rlen)
Write and read in one operation.
Definition: board-i2c.c:247
bool board_i2c_write_single(uint8_t data)
Single write to an I2C device.
Definition: board-i2c.c:188
bool board_i2c_write(uint8_t *data, uint8_t len)
Burst write to an I2C device.
Definition: board-i2c.c:145
void board_i2c_select(uint8_t new_interface, uint8_t address)
Select an I2C slave.
Definition: board-i2c.c:310
void board_i2c_wakeup()
Enables the I2C peripheral with defaults.
Definition: board-i2c.c:83