uart_setup: add example on current uart use.
[contrib/mraa.git] / include / smbus.h
1 /*
2  * Author: Robin Knight (robin.knight@roadnarrows.com)
3  *
4  * Copyright © 2009 RoadNarrows LLC.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that
9  * (1) The above copyright notice and the following two paragraphs
10  * appear in all copies of the source code and (2) redistributions
11  * including binaries reproduces these notices in the supporting
12  * documentation.   Substantial modifications to this software may be
13  * copyrighted by their authors and need not follow the licensing terms
14  * described here, provided that the new terms are clearly indicated in
15  * all files where they apply.
16  *
17  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
18  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
19  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
20  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
21  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
22  * THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
26  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
27  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
28  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
29  */
30
31 #pragma once
32
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <fcntl.h>
36 #include <inttypes.h>
37 #include <sys/types.h>
38 #include <sys/errno.h>
39 #include <sys/ioctl.h>
40
41 #include "linux/i2c-dev.h"
42
43 typedef union i2c_smbus_data_union
44 {
45     uint8_t byte; ///< data byte
46     unsigned short word; ///< data short word
47     uint8_t block[I2C_SMBUS_BLOCK_MAX + 2];
48     ///< block[0] is used for length and one more for PEC
49 } i2c_smbus_data_t;
50
51 typedef struct i2c_smbus_ioctl_data_struct
52 {
53     uint8_t read_write; ///< operation direction
54     uint8_t command; ///< ioctl command
55     int size; ///< data size
56     i2c_smbus_data_t *data; ///< data
57 } i2c_smbus_ioctl_data_t;
58
59 // ---------------------------------------------------------------------------
60 // Prototypes
61 // ---------------------------------------------------------------------------
62
63 extern int i2c_smbus_access(int fd, uint8_t read_write, uint8_t command,
64                       int size, i2c_smbus_data_t *data);
65
66 extern int i2c_smbus_write_quick(int fd, uint8_t value);
67
68 extern int i2c_smbus_read_byte(int fd);
69
70 extern int i2c_smbus_write_byte(int fd, uint8_t value);
71
72 extern int i2c_smbus_read_byte_data(int fd, uint8_t command);
73
74 extern int i2c_smbus_write_byte_data(int fd, uint8_t command, uint8_t value);
75
76 extern int i2c_smbus_read_word_data(int fd, uint8_t command);
77
78 extern int i2c_smbus_write_word_data(int fd, uint8_t command, unsigned short value);
79
80 extern int i2c_smbus_process_call(int fd, uint8_t command, unsigned short value);
81
82 extern int i2c_smbus_read_block_data(int fd, uint8_t command, uint8_t *values);
83
84 extern int i2c_smbus_write_block_data(int fd, uint8_t command, uint8_t length,
85                                         const uint8_t *values);
86 extern int i2c_smbus_read_i2c_block_data(int fd, uint8_t command,
87                                           uint8_t *values);
88
89 extern int i2c_smbus_write_i2c_block_data(int fd, uint8_t command, uint8_t length,
90                                     const uint8_t *values);
91
92 extern int i2c_smbus_block_process_call(int fd, uint8_t command, uint8_t length,
93                                           uint8_t *values);