Wirepas SDK
i2c.h
Go to the documentation of this file.
1/* Copyright 2018 Wirepas Ltd. All Rights Reserved.
2 *
3 * See file LICENSE.txt for full license details.
4 *
5 */
6
11#ifndef I2C_H_
12#define I2C_H_
13
14#include <stdbool.h>
15#include <stdint.h>
16
17
19typedef struct
20{
21 uint32_t clock; //< I2C speed in Hz
22 bool pullup; //< activate internal pull-up on SDA and SCL
24
29typedef struct
30{
31 uint8_t address; //< Address of I2C slave
32 uint8_t * write_ptr; //< Pointer to bytes to write (Must be NULL for pure read)
33 uint8_t write_size; //< Number of bytes to write (Must be 0 for pure read)
34 uint8_t * read_ptr; //< Pointer to store bytes to read (Must be NULL for pure write)
35 uint8_t read_size; //< Number of bytes to read (Must be 0 for pure write)
36 uint32_t custom; //< Custom param (can be used to implement state machine)
38
40typedef enum
41{
42 I2C_RES_OK, //< Last operation was successful
43 I2C_RES_INVALID_CONFIG, //< Invalid initial parameters
44 I2C_RES_INVALID_XFER, //< Invalid transfer parameters
45 I2C_RES_NOT_INITIALIZED, //< Driver is not initialized
46 I2C_RES_ALREADY_INITIALIZED, //< Driver already initialized
47 I2C_RES_BUSY, //< Asynchronous transfer is ongoing
48 I2C_RES_ANACK, //< Slave responded with Address Nack
49 I2C_RES_DNACK, //< Slave responded with Data Nack
50 I2C_RES_BUS_HANG //< Slave did not respond during synchronous transfer
52
54typedef void (*i2c_on_transfer_done_cb_f)(i2c_res_e res, i2c_xfer_t * xfer_p);
55
63
69
82
88
89#endif /* I2C_H_ */
i2c_res_e I2C_status(void)
Return the status of the I2C driver.
i2c_res_e I2C_close(void)
Close an already initialized I2C module.
i2c_res_e
Definition i2c.h:41
@ I2C_RES_BUS_HANG
Definition i2c.h:50
@ I2C_RES_INVALID_CONFIG
Definition i2c.h:43
@ I2C_RES_INVALID_XFER
Definition i2c.h:44
@ I2C_RES_OK
Definition i2c.h:42
@ I2C_RES_ANACK
Definition i2c.h:48
@ I2C_RES_DNACK
Definition i2c.h:49
@ I2C_RES_ALREADY_INITIALIZED
Definition i2c.h:46
@ I2C_RES_NOT_INITIALIZED
Definition i2c.h:45
@ I2C_RES_BUSY
Definition i2c.h:47
uint32_t custom
Definition i2c.h:36
uint8_t * read_ptr
Definition i2c.h:34
i2c_res_e I2C_transfer(i2c_xfer_t *xfer_p, i2c_on_transfer_done_cb_f cb)
Initiate an I2C transfer In case there is a write followed by a read, the read is initiated by a REPE...
uint8_t write_size
Definition i2c.h:33
bool pullup
Definition i2c.h:22
void(* i2c_on_transfer_done_cb_f)(i2c_res_e res, i2c_xfer_t *xfer_p)
Definition i2c.h:54
uint8_t read_size
Definition i2c.h:35
uint8_t * write_ptr
Definition i2c.h:32
uint32_t clock
Definition i2c.h:21
i2c_res_e I2C_init(i2c_conf_t *conf_p)
Initialize I2C module.
uint8_t address
Definition i2c.h:31
Simple minimal I2C master driver It only manages one I2C instance at a time.
Definition i2c.h:20