MAV'RIC
i2c_driver_int.h
1 /*******************************************************************************
2  * Copyright (c) 2009-2014, MAV'RIC Development Team
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 are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  ******************************************************************************/
31 
32 /*******************************************************************************
33  * \file i2c_driver_int.h
34  *
35  * \author MAV'RIC Team
36  * \author Felix Schill
37  *
38  * \brief This file is the driver for i2c with interruptions
39  *
40  ******************************************************************************/
41 
42 #ifndef I2C_DRIVER_INT_H_
43 #define I2C_DRIVER_INT_H_
44 
45 #ifdef __cplusplus
46  extern "C" {
47 #endif
48 
49 #include "twim.h"
50 #include <stdint.h>
51 #include "dma_channel_config.h"
52 #include "scheduler.h"
53 
54 #define I2C_DEVICES 2
55 #define I2C_SCHEDULE_SLOTS 10
56 
57 #define I2C_READ 0
58 #define I2C_WRITE 1
59 #define I2C_WRITE1_THEN_READ 2
60 
61 
64 enum AVAILABLE_I2CS
65 {
66  I2C0,
67  I2C1
68 };
69 
73 typedef struct
74 {
75  uint8_t slave_address;
76  uint32_t i2c_speed;
77  int8_t direction;
79  uint8_t *data;
80  uint16_t data_size;
81  uint16_t data_index;
83  task_handle_t *event_handler;
84 } i2c_packet_t;
85 
92 void i2c_driver_init(uint8_t i2c_device, twim_options_t twi_opt);
93 
101 int32_t i2c_append_transfer(i2c_packet_t *request);
102 
113 int32_t i2c_append_read_transfer(uint8_t slave_address, uint8_t *data, uint16_t size, task_handle_t *event_handler);
114 
125 int32_t i2c_append_write_transfer(uint8_t slave_address, uint8_t *data, uint16_t size, task_handle_t *event_handler);
126 
138 int32_t i2c_append_register_read_transfer(uint8_t slave_address, uint8_t register_address, uint8_t *data, uint16_t size, task_handle_t *event_handler);
139 
145 int32_t i2c_clear_queue(void);
146 
152 bool i2c_is_ready(void);
153 
159 int32_t i2c_get_queued_requests(void);
160 
161 #ifdef __cplusplus
162  }
163 #endif
164 
165 #endif /* I2C_DRIVER_H_ */
uint8_t slave_address
I2C address of slave.
Definition: i2c_driver_int.h:75
uint16_t data_size
size of the data buffer
Definition: i2c_driver_int.h:80
uint8_t * data
pointer to a data buffer of uint8_t
Definition: i2c_driver_int.h:79
structure to embed the i2c's data
Definition: i2c_driver_int.h:73
uint16_t data_index
index of the data buffer
Definition: i2c_driver_int.h:81
bool transfer_in_progress
define whether the transfer is in progress
Definition: i2c_driver_int.h:82
task_handle_t * event_handler
pointer to a task handler buffer
Definition: i2c_driver_int.h:83
uint32_t i2c_speed
speed of i2c bus clock in kHz/kbps. Normally 100-400
Definition: i2c_driver_int.h:76
int8_t write_then_read_preamble
preamble in "write follow by read" mode
Definition: i2c_driver_int.h:78
int8_t direction
direction of the bus
Definition: i2c_driver_int.h:77