i2c: use I2C_FUNCS to store funcs map
[contrib/mraa.git] / include / mraa_internal_types.h
1 /*
2  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3  * Author: Brendan Le Foll <brendan.le.foll@intel.com>
4  * Copyright (c) 2014 Intel Corporation.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 #pragma once
27
28 #include "common.h"
29 #include "mraa.h"
30
31 // general status failures for internal functions
32 #define MRAA_PLATFORM_NO_INIT -3
33 #define MRAA_IO_SETUP_FAILURE -2
34 #define MRAA_NO_SUCH_IO -1
35
36 /**
37  * A structure representing a gpio pin.
38  */
39 struct _gpio {
40     /*@{*/
41     int pin; /**< the pin number, as known to the os. */
42     int phy_pin; /**< pin passed to clean init. -1 none and raw*/
43     int value_fp; /**< the file pointer to the value of the gpio */
44     void (* isr)(void *); /**< the interupt service request */
45     void *isr_args; /**< args return when interupt service request triggered */
46     pthread_t thread_id; /**< the isr handler thread id */
47     int isr_value_fp; /**< the isr file pointer on the value */
48     mraa_boolean_t owner; /**< If this context originally exported the pin */
49     mraa_result_t (*mmap_write) (mraa_gpio_context dev, int value);
50     int (*mmap_read) (mraa_gpio_context dev);
51     /*@}*/
52 };
53
54 /**
55  * A structure representing a I2C bus
56  */
57 struct _i2c {
58     /*@{*/
59     int busnum; /**< the bus number of the /dev/i2c-* device */
60     int fh; /**< the file handle to the /dev/i2c-* device */
61     int addr; /**< the address of the i2c slave */
62     unsigned long funcs;
63     /*@}*/
64 };
65
66 /**
67  * A structure representing a PWM pin
68  */
69 struct _pwm {
70     /*@{*/
71     int pin; /**< the pin number, as known to the os. */
72     int chipid; /**< the chip id, which the pwm resides */
73     int duty_fp; /**< File pointer to duty file */
74     mraa_boolean_t owner; /**< Owner of pwm context*/
75     /*@}*/
76 };
77
78 /**
79  * A structure representing a Analog Input Channel
80  */
81 struct _aio {
82     unsigned int channel; /**< the channel as on board and ADC module */
83     int adc_in_fp; /**< File Pointer to raw sysfs */
84     int value_bit; /**< 10 bits by default. Can be increased if board */
85 };
86
87 /**
88  * A structure representing a UART device
89  */
90 struct _uart {
91     /*@{*/
92     int index; /**< the uart index, as known to the os. */
93     /*@}*/
94 };