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.
30 #include "intel_galileo_rev_d.h"
34 static maa_pininfo_t* pindata;
35 static maa_board_t* plat = NULL;
44 // this sets a compiler attribute (supported by GCC & clang) to have maa_init()
45 // be called as a constructor make sure your libc supports this! uclibc needs
46 // to be compiled with UCLIBC_CTOR_DTOR
47 maa_result_t maa_init() __attribute__((constructor));
52 /** Once more board definitions have been added,
53 * A method for detecting them will need to be devised.
56 return MAA_ERROR_PLATFORM_ALREADY_INITIALISED;
59 // Initialise python threads, this allows use to grab the GIL when we are
64 plat = maa_intel_galileo_rev_d();
69 maa_setup_mux_mapped(maa_pin_t meta)
72 for (mi = 0; mi < meta.mux_total; mi++) {
73 maa_gpio_context* mux_i;
74 mux_i = maa_gpio_init_raw(meta.mux[mi].pin);
76 return MAA_ERROR_INVALID_HANDLE;
77 if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
78 return MAA_ERROR_INVALID_RESOURCE;
79 if (maa_gpio_write(mux_i, meta.mux[mi].value) != MAA_SUCCESS)
80 return MAA_ERROR_INVALID_RESOURCE;
86 maa_check_gpio(int pin)
91 if (pin < 0 || pin > plat->phy_pin_count)
94 if(plat->pins[pin].capabilites.gpio != 1)
97 if (plat->pins[pin].gpio.mux_total > 0)
98 if (maa_setup_mux_mapped(plat->pins[pin].gpio) != MAA_SUCCESS)
100 return plat->pins[pin].gpio.pinmap;
104 maa_check_aio(int aio)
109 if (aio < 0 || aio > plat->aio_count)
112 int pin = aio + plat->gpio_count;
114 if (plat->pins[pin].capabilites.aio != 1)
117 if (plat->pins[pin].aio.mux_total > 0)
118 if (maa_setup_mux_mapped(plat->pins[pin].aio) != MAA_SUCCESS)
120 return plat->pins[pin].aio.pinmap;
124 maa_check_i2c(int bus_s)
129 if (plat->i2c_bus_count >! 0) {
130 fprintf(stderr, "No i2c buses defined in platform");
135 int pos = plat->i2c_bus[bus].sda;
136 if (plat->pins[pos].i2c.mux_total > 0)
137 if (maa_setup_mux_mapped(plat->pins[pos].i2c) != MAA_SUCCESS)
140 pos = plat->i2c_bus[bus].scl;
141 if (plat->pins[pos].i2c.mux_total > 0)
142 if (maa_setup_mux_mapped(plat->pins[pos].i2c) != MAA_SUCCESS)
145 return plat->i2c_bus[bus].bus_id;
149 maa_check_pwm(int pin)
154 if (plat->pins[pin].capabilites.pwm != 1)
157 if (plat->pins[pin].capabilites.gpio == 1) {
158 maa_gpio_context* mux_i;
159 mux_i = maa_gpio_init_raw(plat->pins[pin].gpio.pinmap);
162 if (maa_gpio_dir(mux_i, MAA_GPIO_OUT) != MAA_SUCCESS)
164 // Current REV D quirk. //TODO GEN 2
165 if (maa_gpio_write(mux_i, 1) != MAA_SUCCESS)
167 if (maa_gpio_close(mux_i) != MAA_SUCCESS)
171 if (plat->pins[pin].pwm.mux_total > 0)
172 if (maa_setup_mux_mapped(plat->pins[pin].pwm) != MAA_SUCCESS)
176 ret = (maa_pin_t*) malloc(sizeof(maa_pin_t));
177 ret->pinmap = plat->pins[pin].pwm.pinmap;
178 ret->parent_id = plat->pins[pin].pwm.parent_id;
183 maa_result_print(maa_result_t result)
186 case MAA_SUCCESS: fprintf(stderr, "MAA: SUCCESS\n");
188 case MAA_ERROR_FEATURE_NOT_IMPLEMENTED:
189 fprintf(stderr, "MAA: Feature not implemented.\n");
191 case MAA_ERROR_FEATURE_NOT_SUPPORTED:
192 fprintf(stderr, "MAA: Feature not supported by Hardware.\n");
194 case MAA_ERROR_INVALID_VERBOSITY_LEVEL:
195 fprintf(stderr, "MAA: Invalid verbosity level.\n");
197 case MAA_ERROR_INVALID_PARAMETER:
198 fprintf(stderr, "MAA: Invalid parameter.\n");
200 case MAA_ERROR_INVALID_HANDLE:
201 fprintf(stderr, "MAA: Invalid Handle.\n");
203 case MAA_ERROR_NO_RESOURCES:
204 fprintf(stderr, "MAA: No resources.\n");
206 case MAA_ERROR_INVALID_RESOURCE:
207 fprintf(stderr, "MAA: Invalid resource.\n");
209 case MAA_ERROR_INVALID_QUEUE_TYPE:
210 fprintf(stderr, "MAA: Invalid Queue Type.\n");
212 case MAA_ERROR_NO_DATA_AVAILABLE:
213 fprintf(stderr, "MAA: No Data available.\n");
215 case MAA_ERROR_INVALID_PLATFORM:
216 fprintf(stderr, "MAA: Platform not recognised.\n");
218 case MAA_ERROR_PLATFORM_NOT_INITIALISED:
219 fprintf(stderr, "MAA: Platform not initialised.\n");
221 case MAA_ERROR_PLATFORM_ALREADY_INITIALISED:
222 fprintf(stderr, "MAA: Platform already initialised.\n");
224 case MAA_ERROR_UNSPECIFIED:
225 fprintf(stderr, "MAA: Unspecified Error.\n");
227 default: fprintf(stderr, "MAA: Unrecognised error.\n");
233 maa_pin_mode_test(int pin, maa_pinmodes_t mode)
240 if (pin > plat->phy_pin_count || pin < 0)
245 if (plat->pins[pin].capabilites.valid == 1)
249 if (plat->pins[pin].capabilites.gpio ==1)
253 if (plat->pins[pin].capabilites.pwm ==1)
256 case MAA_PIN_FAST_GPIO:
257 if (plat->pins[pin].capabilites.fast_gpio ==1)
261 if (plat->pins[pin].capabilites.spi ==1)
265 if (plat->pins[pin].capabilites.i2c ==1)
269 if (pin < plat->aio_count)
270 pin = pin + plat->gpio_count;
271 if (plat->pins[pin].capabilites.aio ==1)