Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sol-i2c.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Soletta (TM) Project
3  *
4  * Copyright (C) 2015 Intel Corporation. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <sys/types.h>
24 
25 #include <sol-macros.h>
26 #include <sol-buffer.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
63 struct sol_i2c;
64 typedef struct sol_i2c sol_i2c;
65 
66 
78 struct sol_i2c_pending;
80 
93 };
94 
106 enum sol_i2c_speed sol_i2c_speed_from_str(const char *speed)
107 #ifndef DOXYGEN_RUN
109 #endif
110  ;
111 
123 const char *sol_i2c_speed_to_str(enum sol_i2c_speed speed)
124 #ifndef DOXYGEN_RUN
125  SOL_ATTR_WARN_UNUSED_RESULT
126 #endif
127  ;
128 
141 struct sol_i2c *sol_i2c_open_raw(uint8_t bus, enum sol_i2c_speed speed)
142 #ifndef DOXYGEN_RUN
143  SOL_ATTR_WARN_UNUSED_RESULT
144 #endif
145  ;
146 
161 struct sol_i2c *sol_i2c_open(uint8_t bus, enum sol_i2c_speed speed)
162 #ifndef DOXYGEN_RUN
163  SOL_ATTR_WARN_UNUSED_RESULT
164 #endif
165  ;
166 
173 void sol_i2c_close(struct sol_i2c *i2c);
174 
190 int sol_i2c_set_slave_address(struct sol_i2c *i2c, uint8_t slave_address);
191 
200 uint8_t sol_i2c_get_slave_address(struct sol_i2c *i2c);
201 
221 struct sol_i2c_pending *sol_i2c_write_quick(struct sol_i2c *i2c, bool rw, void (*write_quick_cb)(void *cb_data, struct sol_i2c *i2c, ssize_t status), const void *cb_data);
222 
252 struct sol_i2c_pending *sol_i2c_read(struct sol_i2c *i2c, uint8_t *data, size_t count, void (*read_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t *data, ssize_t status), const void *cb_data);
253 
283 struct sol_i2c_pending *sol_i2c_write(struct sol_i2c *i2c, uint8_t *data, size_t count, void (*write_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t *data, ssize_t status), const void *cb_data);
284 
309 struct sol_i2c_pending *sol_i2c_read_register(struct sol_i2c *i2c, uint8_t reg, uint8_t *data, size_t count, void (*read_reg_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status), const void *cb_data);
310 
335 struct sol_i2c_pending *sol_i2c_write_register(struct sol_i2c *i2c, uint8_t reg, const uint8_t *data, size_t count, void (*write_reg_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status), const void *cb_data);
336 
375 struct sol_i2c_pending *sol_i2c_read_register_multiple(struct sol_i2c *i2c, uint8_t reg, uint8_t *values, size_t count, uint8_t times, void (*read_reg_multiple_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status), const void *cb_data);
376 
384 uint8_t sol_i2c_get_bus(const struct sol_i2c *i2c);
385 
392 void sol_i2c_pending_cancel(struct sol_i2c *i2c, struct sol_i2c_pending *pending);
393 
394 #ifdef SOL_PLATFORM_LINUX
395 
415 int sol_i2c_create_device(const char *address, const char *dev_name, unsigned int dev_number, struct sol_buffer *result_path);
416 #endif
417 
442 };
443 
449 struct sol_i2c_op {
451  uint8_t reg;
452  uint8_t value;
453 };
454 
461 
475 struct sol_i2c_op_set_pending *sol_i2c_dispatcher_add_op_set(struct sol_i2c *i2c, uint8_t addr, struct sol_vector *set, void (*cb)(void *cb_data, ssize_t status), void *cb_data, uint32_t delay);
476 
484 
489 #ifdef __cplusplus
490 }
491 #endif
struct sol_http_client_connection * pending
Definition: download.c:29
struct sol_i2c_pending * sol_i2c_read(struct sol_i2c *i2c, uint8_t *data, size_t count, void(*read_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t *data, ssize_t status), const void *cb_data)
Perform successive asynchronous I2C byte read operations, with no specified register.
struct sol_i2c_pending * sol_i2c_read_register_multiple(struct sol_i2c *i2c, uint8_t reg, uint8_t *values, size_t count, uint8_t times, void(*read_reg_multiple_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status), const void *cb_data)
Asynchronous read of an arbitrary number of bytes from a register in repeated bursts of a given lengt...
struct sol_i2c_pending sol_i2c_pending
I2C pending operation handle structure.
Definition: sol-i2c.h:79
flag for low speed
Definition: sol-i2c.h:88
struct sol_i2c_pending * sol_i2c_write(struct sol_i2c *i2c, uint8_t *data, size_t count, void(*write_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t *data, ssize_t status), const void *cb_data)
Perform successive asynchronous I2C byte write operations, with no specified register.
struct sol_i2c * sol_i2c_open(uint8_t bus, enum sol_i2c_speed speed)
Open an I2C bus.
void sol_i2c_close(struct sol_i2c *i2c)
Close an I2C bus.
void sol_i2c_dispatcher_remove_op_set(struct sol_i2c *i2c, struct sol_i2c_op_set_pending *pending)
Cancel the execution of the pending operation set.
uint8_t value
Operation data.
Definition: sol-i2c.h:452
Definition: sol-i2c.h:440
struct sol_i2c_pending * sol_i2c_write_register(struct sol_i2c *i2c, uint8_t reg, const uint8_t *data, size_t count, void(*write_reg_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status), const void *cb_data)
Perform an asynchronous I2C write operation on a given device register.
sol_i2c_speed
Enum for I2C bus speed.
Definition: sol-i2c.h:87
These are common Soletta macros.
uint8_t sol_i2c_get_slave_address(struct sol_i2c *i2c)
Get the (slave) device address set on an I2C bus (to deliver I2C commands to)
int sol_i2c_set_slave_address(struct sol_i2c *i2c, uint8_t slave_address)
Set a (slave) device address on a I2C bus to deliver commands to.
static struct sol_network_link_addr address
Definition: echo-client.c:44
These are routines that Soletta provides for its buffer implementation.
enum sol_i2c_op_type type
I2C Operation type.
Definition: sol-i2c.h:450
const char * sol_i2c_speed_to_str(enum sol_i2c_speed speed)
Converts sol_i2c_speed to a string name.
#define SOL_ATTR_WARN_UNUSED_RESULT
Causes a warning to be emitted if a caller of the function with this attribute does not use its retur...
Definition: sol-macros.h:187
struct sol_i2c * sol_i2c_open_raw(uint8_t bus, enum sol_i2c_speed speed)
Open an I2C bus.
Definition: sol-i2c.h:441
flag for normal speed
Definition: sol-i2c.h:89
struct sol_i2c_pending * sol_i2c_write_quick(struct sol_i2c *i2c, bool rw, void(*write_quick_cb)(void *cb_data, struct sol_i2c *i2c, ssize_t status), const void *cb_data)
Perform a I2C write quick operation.
sol_i2c_op_type
I²C operation dispatcher.
Definition: sol-i2c.h:439
Structure to describe an operation that should be executed by the I2C Dispatcher. ...
Definition: sol-i2c.h:449
enum sol_i2c_speed sol_i2c_speed_from_str(const char *speed)
Converts a string I2C speed to sol_i2c_speed.
uint8_t sol_i2c_get_bus(const struct sol_i2c *i2c)
Get the I2C bus ID.
void sol_i2c_pending_cancel(struct sol_i2c *i2c, struct sol_i2c_pending *pending)
Cancel a pending operation.
flag for fast speed
Definition: sol-i2c.h:90
struct sol_i2c_op_set_pending sol_i2c_op_set_pending
I2C Dispatcher pending operation set handle structure.
Definition: sol-i2c.h:460
struct sol_i2c_pending * sol_i2c_read_register(struct sol_i2c *i2c, uint8_t reg, uint8_t *data, size_t count, void(*read_reg_cb)(void *cb_data, struct sol_i2c *i2c, uint8_t reg, uint8_t *data, ssize_t status), const void *cb_data)
Perform an asynchronous I2C read operation on a given device register.
uint8_t reg
I2C register in the slave device.
Definition: sol-i2c.h:451
struct sol_i2c sol_i2c
I2C handle structure.
Definition: sol-i2c.h:64
flag for high speed
Definition: sol-i2c.h:92
Soletta vector is an array that grows dynamically.
Definition: sol-vector.h:58
A sol_buffer is a dynamic array, that can be resized if needed.
Definition: sol-buffer.h:130
struct sol_i2c_op_set_pending * sol_i2c_dispatcher_add_op_set(struct sol_i2c *i2c, uint8_t addr, struct sol_vector *set, void(*cb)(void *cb_data, ssize_t status), void *cb_data, uint32_t delay)
Add an operation set in the dispatcher's queue of a given I2C bus.
flag for fast plus speed
Definition: sol-i2c.h:91