drv_i2c.h
Go to the documentation of this file.
1 /*
2  drv_i2c.h : I^2C support for STM32F103CB
3 
4  Adapted from https://github.com/multiwii/baseflight/blob/master/src/drv_i2c.h
5 
6  This file is part of BreezySTM32.
7 
8  BreezySTM32 is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  BreezySTM32 is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with BreezySTM32. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 typedef enum I2CDevice {
28 } I2CDevice;
29 
30 typedef enum {
33 } i2cJobType_t;
34 
35 enum {
41 };
42 
43 typedef struct i2cJob{
45  uint8_t addr;
46  uint8_t reg;
47  uint8_t* data;
48  uint8_t length;
49  struct i2cJob* next_job;
50  volatile uint8_t* status;
51  void (*CB)(uint8_t);
52 } i2cJob_t;
53 
54 #define I2C_BUFFER_SIZE 16
55 
56 void i2cInit(I2CDevice index);
57 uint16_t i2cGetErrorCounter(void);
58 
59 // Blocking I2C functions (returns value success or failure)
60 bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data);
61 bool i2cWrite(uint8_t addr_, uint8_t reg, uint8_t data);
62 bool i2cRead(uint8_t addr_, uint8_t reg, uint8_t len, uint8_t *buf);
63 
64 // ===================================================================
65 // Asynchronous I2C handler
66 // To use this, queue up a job, and create a callback you want called when the job is finished
67 // You can track progress of the job using the status pointer. Otherwise, functions the same
68 // as the blocking versions.
69 //
70 // This uses a circular buffer to stage jobs for the I2C peripheral. The buffer is, by default, 16 jobs
71 // long (I2C_BUFFER_SIZE), with a maximum size of 256. I hope you never queue up that many jobs, because
72 // that will take a long time to process However, if you were to reach the limit, it would then start
73 // ignoring new jobs until there was space on the buffer.
74 //
75 // For an example of how to use, check out mpu6050_request_read_temp - the non-blocking way to read
76 // the accelerometer
77 void i2c_queue_job(i2cJobType_t type, uint8_t addr_, uint8_t reg_, uint8_t *data, uint8_t length, volatile uint8_t *status_, void (*CB)(uint8_t));
uint8_t * data
Definition: drv_i2c.h:47
struct i2cJob i2cJob_t
Definition: drv_i2c.h:32
void i2cInit(I2CDevice index)
Definition: drv_i2c.c:420
bool i2cWrite(uint8_t addr_, uint8_t reg, uint8_t data)
Definition: drv_i2c.c:152
void(* CB)(uint8_t)
Definition: drv_i2c.h:51
volatile uint8_t * status
Definition: drv_i2c.h:50
Definition: drv_i2c.h:43
bool i2cRead(uint8_t addr_, uint8_t reg, uint8_t len, uint8_t *buf)
Definition: drv_i2c.c:157
uint8_t length
Definition: drv_i2c.h:48
i2cJobType_t type
Definition: drv_i2c.h:44
uint8_t addr
Definition: drv_i2c.h:45
Definition: drv_i2c.h:31
struct i2cJob * next_job
Definition: drv_i2c.h:49
void i2c_queue_job(i2cJobType_t type, uint8_t addr_, uint8_t reg_, uint8_t *data, uint8_t length, volatile uint8_t *status_, void(*CB)(uint8_t))
Definition: drv_i2c.c:579
bool i2cWriteBuffer(uint8_t addr_, uint8_t reg_, uint8_t len_, uint8_t *data)
Definition: drv_i2c.c:113
I2CDevice
Definition: drv_i2c.h:24
i2cJobType_t
Definition: drv_i2c.h:30
uint8_t reg
Definition: drv_i2c.h:46
uint16_t i2cGetErrorCounter(void)
Definition: drv_i2c.c:467


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:24