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
19
typedef
struct
20
{
21
uint32_t
clock
;
//< I2C speed in Hz
22
bool
pullup
;
//< activate internal pull-up on SDA and SCL
23
}
i2c_conf_t
;
24
29
typedef
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)
37
}
i2c_xfer_t
;
38
40
typedef
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
51
}
i2c_res_e
;
52
54
typedef
void (*
i2c_on_transfer_done_cb_f
)(
i2c_res_e
res,
i2c_xfer_t
* xfer_p);
55
62
i2c_res_e
I2C_init
(
i2c_conf_t
* conf_p);
63
68
i2c_res_e
I2C_close
(
void
);
69
81
i2c_res_e
I2C_transfer
(
i2c_xfer_t
* xfer_p,
i2c_on_transfer_done_cb_f
cb);
82
87
i2c_res_e
I2C_status
(
void
);
88
89
#endif
/* I2C_H_ */
i2c_xfer_t::write_ptr
uint8_t * write_ptr
Definition:
i2c.h:32
i2c_xfer_t::read_ptr
uint8_t * read_ptr
Definition:
i2c.h:34
i2c_xfer_t
Definition:
i2c.h:29
I2C_transfer
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...
I2C_RES_BUS_HANG
@ I2C_RES_BUS_HANG
Definition:
i2c.h:50
i2c_conf_t
Simple minimal I2C master driver It only manages one I2C instance at a time.
Definition:
i2c.h:19
I2C_RES_ANACK
@ I2C_RES_ANACK
Definition:
i2c.h:48
I2C_RES_DNACK
@ I2C_RES_DNACK
Definition:
i2c.h:49
i2c_xfer_t::address
uint8_t address
Definition:
i2c.h:31
I2C_close
i2c_res_e I2C_close(void)
Close an already initialized I2C module.
i2c_res_e
i2c_res_e
Definition:
i2c.h:40
I2C_RES_INVALID_CONFIG
@ I2C_RES_INVALID_CONFIG
Definition:
i2c.h:43
I2C_init
i2c_res_e I2C_init(i2c_conf_t *conf_p)
Initialize I2C module.
i2c_xfer_t::write_size
uint8_t write_size
Definition:
i2c.h:33
I2C_RES_BUSY
@ I2C_RES_BUSY
Definition:
i2c.h:47
I2C_status
i2c_res_e I2C_status(void)
Return the status of the I2C driver.
I2C_RES_INVALID_XFER
@ I2C_RES_INVALID_XFER
Definition:
i2c.h:44
i2c_conf_t::clock
uint32_t clock
Definition:
i2c.h:21
I2C_RES_NOT_INITIALIZED
@ I2C_RES_NOT_INITIALIZED
Definition:
i2c.h:45
i2c_xfer_t::read_size
uint8_t read_size
Definition:
i2c.h:35
i2c_on_transfer_done_cb_f
void(* i2c_on_transfer_done_cb_f)(i2c_res_e res, i2c_xfer_t *xfer_p)
Definition:
i2c.h:54
i2c_conf_t::pullup
bool pullup
Definition:
i2c.h:22
I2C_RES_OK
@ I2C_RES_OK
Definition:
i2c.h:42
I2C_RES_ALREADY_INITIALIZED
@ I2C_RES_ALREADY_INITIALIZED
Definition:
i2c.h:46
i2c_xfer_t::custom
uint32_t custom
Definition:
i2c.h:36