Contiki-NG
bme280-arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Zolertia
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  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*---------------------------------------------------------------------------*/
32 /**
33  * \addtogroup zoul-bme280-sensor
34  * \ingroup zoul
35  *
36  * @{
37  *
38  * \file
39  * Architecture-specific I2C for the external BME280 weather sensor
40  *
41  * \author
42  * Antonio Lignan <alinan@zolertia.com>
43  */
44 /*---------------------------------------------------------------------------*/
45 #include "contiki.h"
46 #include "dev/i2c.h"
47 /*---------------------------------------------------------------------------*/
48 void
49 bme280_arch_i2c_init(void)
50 {
51  i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN,
52  I2C_SCL_NORMAL_BUS_SPEED);
53 }
54 /*---------------------------------------------------------------------------*/
55 void
56 bme280_arch_i2c_write_mem(uint8_t addr, uint8_t reg, uint8_t value)
57 {
58  uint8_t buf[2];
59 
60  buf[0] = reg;
61  buf[1] = value;
62 
64  i2c_burst_send(addr, buf, 2);
65 }
66 /*---------------------------------------------------------------------------*/
67 void
68 bme280_arch_i2c_read_mem(uint8_t addr, uint8_t reg, uint8_t *buf, uint8_t bytes)
69 {
71  if(i2c_single_send(addr, reg) == I2C_MASTER_ERR_NONE) {
72  while(i2c_master_busy());
73  i2c_burst_receive(addr, buf, bytes);
74  }
75 }
76 /*---------------------------------------------------------------------------*/
77 /**
78  * @}
79  */
uint8_t i2c_master_busy(void)
Return the busy state of I2C module.
Definition: i2c.c:141
uint8_t i2c_burst_send(uint8_t slave_addr, uint8_t *data, uint8_t len)
Perform all operations to send multiple bytes to a slave.
Definition: i2c.c:188
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107
void i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl, uint32_t bus_speed)
Initialize the I2C peripheral and pins.
Definition: i2c.c:49
uint8_t i2c_burst_receive(uint8_t slave_addr, uint8_t *data, uint8_t len)
Perform all operations to receive multiple bytes from a slave.
Definition: i2c.c:218
uint8_t i2c_single_send(uint8_t slave_addr, uint8_t data)
Perform all operations to send a byte to a slave.
Definition: i2c.c:159
void i2c_master_enable(void)
Enable master I2C module.
Definition: i2c.c:91