Contiki-NG
i2c-arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
3  * Copyright (c) 2020, George Oikonomou - http://www.spd.gr
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
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 cc13xx-cc26xx-i2c
34  * @{
35  *
36  * \file
37  * Implementation of the I2C HAL driver for CC13xx/CC26xx.
38  *
39  * \author
40  * Edvard Pettersen <e.pettersen@ti.com>
41  * \author
42  * George Oikonomou <george@contiki-ng.org>
43  */
44 /*---------------------------------------------------------------------------*/
45 #include "contiki.h"
46 #include "i2c-arch.h"
47 
48 #include <stddef.h>
49 #include <stdbool.h>
50 #include <stdint.h>
51 /*---------------------------------------------------------------------------*/
52 bool
53 i2c_arch_write_read(I2C_Handle i2c_handle, uint_least8_t slave_addr,
54  void *wbuf, size_t wcount, void *rbuf,
55  size_t rcount)
56 {
57  I2C_Transaction i2cTransaction = {
58  .writeBuf = wbuf,
59  .writeCount = wcount,
60  .readBuf = rbuf,
61  .readCount = rcount,
62  .slaveAddress = slave_addr,
63  };
64 
65  if(!i2c_handle) {
66  return false;
67  }
68 
69  return I2C_transfer(i2c_handle, &i2cTransaction);
70 }
71 /*---------------------------------------------------------------------------*/
72 /* Releases the I2C Peripheral */
73 void
74 i2c_arch_release(I2C_Handle i2c_handle)
75 {
76  if(!i2c_handle) {
77  return;
78  }
79 
80  I2C_close(i2c_handle);
81 }
82 /*---------------------------------------------------------------------------*/
83 I2C_Handle
84 i2c_arch_acquire(uint_least8_t index)
85 {
86  I2C_Params i2c_params;
87 
88  I2C_Params_init(&i2c_params);
89 
90  i2c_params.transferMode = I2C_MODE_BLOCKING;
91  i2c_params.bitRate = I2C_400kHz;
92 
93  return I2C_open(index, &i2c_params);
94 }
95 /*---------------------------------------------------------------------------*/
96 /** @} */
Implementation of the I2C HAL driver for CC13xx/CC26xx.
bool i2c_arch_write_read(I2C_Handle i2c_handle, uint_least8_t slave_addr, void *wbuf, size_t wcount, void *rbuf, size_t rcount)
Setup and peform an I2C transaction.
Definition: i2c-arch.c:53
void i2c_arch_release(I2C_Handle i2c_handle)
Release the I2C Peripheral for other modules to use.
Definition: i2c-arch.c:74
I2C_Handle i2c_arch_acquire(uint_least8_t index)
Open and lock the I2C Peripheral for use.
Definition: i2c-arch.c:84