Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
i2c.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2012 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
28 #include "mcu_periph/i2c.h"
29 
30 #ifdef USE_I2C0
31 
32 struct i2c_periph i2c0;
33 
34 void i2c0_init(void) {
35  i2c_init(&i2c0);
36  i2c0_hw_init();
37 }
38 
39 #endif /* USE_I2C0 */
40 
41 
42 #ifdef USE_I2C1
43 
44 struct i2c_periph i2c1;
45 
46 void i2c1_init(void) {
47  i2c_init(&i2c1);
48  i2c1_hw_init();
49 }
50 
51 #endif /* USE_I2C1 */
52 
53 
54 #ifdef USE_I2C2
55 
56 struct i2c_periph i2c2;
57 
58 void i2c2_init(void) {
59  i2c_init(&i2c2);
60  i2c2_hw_init();
61 }
62 
63 #endif /* USE_I2C2 */
64 
65 
66 #ifdef USE_I2C3
67 
68 struct i2c_periph i2c3;
69 
70 void i2c3_init(void) {
71  i2c_init(&i2c3);
72  i2c3_hw_init();
73 }
74 
75 #endif /* USE_I2C2 */
76 
77 
78 void i2c_init(struct i2c_periph* p) {
79  p->trans_insert_idx = 0;
80  p->trans_extract_idx = 0;
81  p->status = I2CIdle;
82 }
83 
84 
85 bool_t i2c_transmit(struct i2c_periph* p, struct i2c_transaction* t,
86  uint8_t s_addr, uint8_t len)
87 {
88  t->type = I2CTransTx;
89  t->slave_addr = s_addr;
90  t->len_w = len;
91  t->len_r = 0;
92  return i2c_submit(p, t);
93 }
94 
95 bool_t i2c_receive(struct i2c_periph* p, struct i2c_transaction* t,
96  uint8_t s_addr, uint16_t len)
97 {
98  t->type = I2CTransRx;
99  t->slave_addr = s_addr;
100  t->len_w = 0;
101  t->len_r = len;
102  return i2c_submit(p, t);
103 }
104 
105 bool_t i2c_transceive(struct i2c_periph* p, struct i2c_transaction* t,
106  uint8_t s_addr, uint8_t len_w, uint16_t len_r)
107 {
108  t->type = I2CTransTxRx;
109  t->slave_addr = s_addr;
110  t->len_w = len_w;
111  t->len_r = len_r;
112  return i2c_submit(p, t);
113 }
unsigned short uint16_t
Definition: types.h:16
bool_t i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Definition: i2c_arch.c:333
uint8_t trans_extract_idx
Definition: i2c.h:94
void i2c_init(struct i2c_periph *p)
Definition: i2c.c:78
Definition: i2c.h:59
bool_t i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Definition: i2c.c:105
enum I2CStatus status
Definition: i2c.h:96
uint8_t slave_addr
Definition: i2c.h:79
bool_t i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Definition: i2c.c:85
uint8_t len_w
Definition: i2c.h:81
uint16_t len_r
Definition: i2c.h:80
unsigned char uint8_t
Definition: types.h:14
uint8_t trans_insert_idx
Definition: i2c.h:93
Definition: i2c.h:90
Definition: i2c.h:45
enum I2CTransactionType type
Definition: i2c.h:78
static float p[2][2]
Definition: i2c.h:46
bool_t i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Definition: i2c.c:95
Architecture independent I2C (Inter-Integrated Circuit Bus) API.