2 * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3 * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
4 * Copyright (c) 2014 Intel Corporation.
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:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
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.
29 #include "intel_galileo_rev_d.h"
33 static maa_pininfo_t* pindata;
34 static maa_board_t* plat = NULL;
46 maa_result_t __attribute__((constructor))
50 /** Once more board definitions have been added,
51 * A method for detecting them will need to be devised.
54 return MAA_ERROR_PLATFORM_ALREADY_INITIALISED;
57 // Initialise python threads, this allows use to grab the GIL when we are
62 plat = maa_intel_galileo_rev_d();
67 maa_setup_mux_mapped(maa_pin_t meta)
70 for (mi = 0; mi < meta.mux_total; mi++) {
71 maa_gpio_context mux_i;
72 mux_i = maa_gpio_init_raw(meta.mux[mi].pin);
74 return MAA_ERROR_INVALID_HANDLE;
75 if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
76 return MAA_ERROR_INVALID_RESOURCE;
77 if (maa_gpio_write(mux_i, meta.mux[mi].value) != MAA_SUCCESS)
78 return MAA_ERROR_INVALID_RESOURCE;
84 maa_check_gpio(int pin)
89 if (pin < 0 || pin > plat->phy_pin_count)
92 if(plat->pins[pin].capabilites.gpio != 1)
95 if (plat->pins[pin].gpio.mux_total > 0)
96 if (maa_setup_mux_mapped(plat->pins[pin].gpio) != MAA_SUCCESS)
98 return plat->pins[pin].gpio.pinmap;
102 maa_check_aio(int aio)
107 if (aio < 0 || aio > plat->aio_count)
110 int pin = aio + plat->gpio_count;
112 if (plat->pins[pin].capabilites.aio != 1)
115 if (plat->pins[pin].aio.mux_total > 0)
116 if (maa_setup_mux_mapped(plat->pins[pin].aio) != MAA_SUCCESS)
118 return plat->pins[pin].aio.pinmap;
122 maa_check_i2c(int bus_s)
127 if (plat->i2c_bus_count >! 0) {
128 fprintf(stderr, "No i2c buses defined in platform");
133 int pos = plat->i2c_bus[bus].sda;
134 if (plat->pins[pos].i2c.mux_total > 0)
135 if (maa_setup_mux_mapped(plat->pins[pos].i2c) != MAA_SUCCESS)
138 pos = plat->i2c_bus[bus].scl;
139 if (plat->pins[pos].i2c.mux_total > 0)
140 if (maa_setup_mux_mapped(plat->pins[pos].i2c) != MAA_SUCCESS)
143 return plat->i2c_bus[bus].bus_id;
147 maa_check_pwm(int pin)
152 if (plat->pins[pin].capabilites.pwm != 1)
155 if (plat->pins[pin].capabilites.gpio == 1) {
156 maa_gpio_context mux_i;
157 mux_i = maa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
160 if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
162 // Current REV D quirk. //TODO GEN 2
163 if (maa_gpio_write(mux_i, 1) != MAA_SUCCESS)
165 if (maa_gpio_close(mux_i) != MAA_SUCCESS)
169 if (plat->pins[pin].pwm.mux_total > 0)
170 if (maa_setup_mux_mapped(plat->pins[pin].pwm) != MAA_SUCCESS)
174 ret = (maa_pin_t*) malloc(sizeof(maa_pin_t));
175 ret->pinmap = plat->pins[pin].pwm.pinmap;
176 ret->parent_id = plat->pins[pin].pwm.parent_id;
181 maa_result_print(maa_result_t result)
184 case MAA_SUCCESS: fprintf(stderr, "MAA: SUCCESS\n");
186 case MAA_ERROR_FEATURE_NOT_IMPLEMENTED:
187 fprintf(stderr, "MAA: Feature not implemented.\n");
189 case MAA_ERROR_FEATURE_NOT_SUPPORTED:
190 fprintf(stderr, "MAA: Feature not supported by Hardware.\n");
192 case MAA_ERROR_INVALID_VERBOSITY_LEVEL:
193 fprintf(stderr, "MAA: Invalid verbosity level.\n");
195 case MAA_ERROR_INVALID_PARAMETER:
196 fprintf(stderr, "MAA: Invalid parameter.\n");
198 case MAA_ERROR_INVALID_HANDLE:
199 fprintf(stderr, "MAA: Invalid Handle.\n");
201 case MAA_ERROR_NO_RESOURCES:
202 fprintf(stderr, "MAA: No resources.\n");
204 case MAA_ERROR_INVALID_RESOURCE:
205 fprintf(stderr, "MAA: Invalid resource.\n");
207 case MAA_ERROR_INVALID_QUEUE_TYPE:
208 fprintf(stderr, "MAA: Invalid Queue Type.\n");
210 case MAA_ERROR_NO_DATA_AVAILABLE:
211 fprintf(stderr, "MAA: No Data available.\n");
213 case MAA_ERROR_INVALID_PLATFORM:
214 fprintf(stderr, "MAA: Platform not recognised.\n");
216 case MAA_ERROR_PLATFORM_NOT_INITIALISED:
217 fprintf(stderr, "MAA: Platform not initialised.\n");
219 case MAA_ERROR_PLATFORM_ALREADY_INITIALISED:
220 fprintf(stderr, "MAA: Platform already initialised.\n");
222 case MAA_ERROR_UNSPECIFIED:
223 fprintf(stderr, "MAA: Unspecified Error.\n");
225 default: fprintf(stderr, "MAA: Unrecognised error.\n");
231 maa_pin_mode_test(int pin, maa_pinmodes_t mode)
238 if (pin > plat->phy_pin_count || pin < 0)
243 if (plat->pins[pin].capabilites.valid == 1)
247 if (plat->pins[pin].capabilites.gpio ==1)
251 if (plat->pins[pin].capabilites.pwm ==1)
254 case MAA_PIN_FAST_GPIO:
255 if (plat->pins[pin].capabilites.fast_gpio ==1)
259 if (plat->pins[pin].capabilites.spi ==1)
263 if (plat->pins[pin].capabilites.i2c ==1)
267 if (pin < plat->aio_count)
268 pin = pin + plat->gpio_count;
269 if (plat->pins[pin].capabilites.aio ==1)