2 * Author: Henry Bruce <henry.bruce@intel.com>
3 * Copyright (c) 2015 Intel Corporation.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include "linux/i2c-dev.h"
32 #include "libft4222.h"
33 #include "usb/ftdi_ft4222.h"
35 #define PLATFORM_NAME "FTDI FT4222"
36 #define I2CM_ERROR(status) (((status) &0x02) != 0)
37 #define PCA9672_ADDR 0x20
40 static FT_HANDLE ftHandleGPIO = (FT_HANDLE) NULL; //GPIO Handle
41 static FT_HANDLE ftHandle = (FT_HANDLE) NULL; //I2C/SPI Handle
42 static GPIO_Dir pinDirection[] = {GPIO_OUTPUT, GPIO_OUTPUT, GPIO_OUTPUT, GPIO_OUTPUT};
43 static int bus_speed = 400;
44 static int numI2cGpioExpanderPins;
47 mraa_ftdi_ft4222_init()
49 mraa_result_t mraaStatus = MRAA_SUCCESS;
50 FT_DEVICE_LIST_INFO_NODE* devInfo = NULL;
56 ftStatus = FT_CreateDeviceInfoList(&numDevs);
57 if (ftStatus != FT_OK) {
58 syslog(LOG_ERR, "FT_CreateDeviceInfoList failed: error code %d\n", ftStatus);
59 mraaStatus = MRAA_ERROR_NO_RESOURCES;
64 syslog(LOG_ERR, "No FT4222 devices connected.\n");
68 devInfo = calloc((size_t) numDevs, sizeof(FT_DEVICE_LIST_INFO_NODE));
69 if (devInfo == NULL) {
70 syslog(LOG_ERR, "FT4222 allocation failure.\n");
71 mraaStatus = MRAA_ERROR_NO_RESOURCES;
75 ftStatus = FT_GetDeviceInfoList(devInfo, &numDevs);
76 if (ftStatus != FT_OK) {
77 syslog(LOG_ERR, "FT_GetDeviceInfoList failed (error code %d)\n", (int) ftStatus);
78 mraaStatus = MRAA_ERROR_NO_RESOURCES;
83 FT4222_Version ft4222Version;
84 FT4222_STATUS ft4222Status = FT4222_GetVersion(ftHandle, &ft4222Version);
85 if (FT4222_OK == ft4222Status){
86 syslog(LOG_NOTICE, "FT4222_GetVersion %08X %08X\n", ft4222Version.chipVersion,
87 ft4222Version.dllVersion);
89 syslog(LOG_ERR, "FT4222_GetVersion failed with code %d", ft4222Status);
92 syslog(LOG_NOTICE, "FT_GetDeviceInfoList returned %d devices\n", numDevs);
95 syslog(LOG_ERR, "CNFMODE not supported. Valid modes are 0 or 3.\n");
96 mraaStatus = MRAA_ERROR_NO_RESOURCES;
100 // CNFMODE 0, GPIO interface available.
102 ftStatus = FT_OpenEx((PVOID)(uintptr_t) devInfo[1].LocId, FT_OPEN_BY_LOCATION, &ftHandleGPIO);
103 if (ftStatus != FT_OK) {
104 syslog(LOG_ERR, "FT_OpenEx GPIO handle failed (error %d)\n", (int) ftStatus);
105 mraaStatus = MRAA_ERROR_NO_RESOURCES;
109 // Disable Suspend and Wake on GPIO2 & GPIO3
110 FT4222_SetSuspendOut(ftHandleGPIO, 0);
111 FT4222_SetWakeUpInterrupt(ftHandleGPIO, 0);
113 ftStatus = FT4222_GPIO_Init(ftHandleGPIO, pinDirection);
114 if (ftStatus != FT_OK) {
115 syslog(LOG_ERR, "FT4222_GPIO_Init failed (error %d)\n", (int) ftStatus);
116 mraaStatus = MRAA_ERROR_NO_RESOURCES;
121 // I2C or SPI interface.
122 ftStatus = FT_OpenEx((PVOID)(uintptr_t) devInfo[0].LocId, FT_OPEN_BY_LOCATION, &ftHandle);
123 if (ftStatus != FT_OK) {
124 syslog(LOG_ERR, "FT_OpenEx I2C handle failed (error %d)\n", (int) ftStatus);
125 mraaStatus = MRAA_ERROR_NO_RESOURCES;
129 // Tell the FT4222 to be an I2C Master by default on init.
130 FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, bus_speed);
131 if (FT4222_OK != ft4222Status) {
132 syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status);
133 mraaStatus = MRAA_ERROR_NO_RESOURCES;
137 // Reset the I2CM registers to a known state.
138 ft4222Status = FT4222_I2CMaster_Reset(ftHandle);
139 if (FT4222_OK != ft4222Status) {
140 syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status);
141 mraaStatus = MRAA_ERROR_NO_RESOURCES;
149 if (mraaStatus == MRAA_SUCCESS)
150 syslog(LOG_NOTICE, "mraa_ftdi_ft4222_init completed successfully\n");
156 mraa_ftdi_ft4222_get_version(unsigned int* versionChip, unsigned int* versionLib)
158 if (ftHandle != NULL) {
159 FT4222_Version ft4222Version;
160 FT4222_STATUS ft4222Status = FT4222_GetVersion(ftHandle, &ft4222Version);
161 if (FT4222_OK == ft4222Status) {
162 *versionChip = (unsigned int) ft4222Version.chipVersion;
163 *versionLib = (unsigned int) ft4222Version.dllVersion;
164 syslog(LOG_NOTICE, "FT4222_GetVersion %08X %08X\n", *versionChip, *versionLib);
167 syslog(LOG_ERR, "libmraa: FT4222_GetVersion failed (error %d)\n", (int) ft4222Status);
168 return MRAA_ERROR_NO_RESOURCES;
171 syslog(LOG_ERR, "libmraa: bad FT4222 handle\n");
172 return MRAA_ERROR_INVALID_HANDLE;
178 mraa_ftdi_ft4222_i2c_read_internal(FT_HANDLE handle, uint8_t addr, uint8_t* data, int length)
180 uint16 bytesRead = 0;
181 uint8 controllerStatus;
182 // syslog(LOG_NOTICE, "FT4222_I2CMaster_Read(%#02X, %#02X)", addr, length);
183 FT4222_STATUS ft4222Status = FT4222_I2CMaster_Read(handle, addr, data, length, &bytesRead);
184 ft4222Status = FT4222_I2CMaster_GetStatus(ftHandle, &controllerStatus);
185 if (FT4222_OK != ft4222Status || I2CM_ERROR(controllerStatus)) {
186 syslog(LOG_ERR, "FT4222_I2CMaster_Read failed (error %d)\n", (int) ft4222Status);
193 mraa_ftdi_ft4222_i2c_write_internal(FT_HANDLE handle, uint8_t addr, const uint8_t* data, int bytesToWrite)
195 uint16 bytesWritten = 0;
196 uint8 controllerStatus;
197 // syslog(LOG_NOTICE, "FT4222_I2CMaster_Write(%#02X, %#02X, %d)", addr, *data, bytesToWrite);
198 FT4222_STATUS ft4222Status =
199 FT4222_I2CMaster_Write(handle, addr, (uint8_t*) data, bytesToWrite, &bytesWritten);
200 ft4222Status = FT4222_I2CMaster_GetStatus(ftHandle, &controllerStatus);
201 if (FT4222_OK != ft4222Status || I2CM_ERROR(controllerStatus)) {
202 syslog(LOG_ERR, "FT4222_I2CMaster_Write failed (error %d)\n", (int) ft4222Status);
206 if (bytesWritten != bytesToWrite)
207 syslog(LOG_ERR, "FT4222_I2CMaster_Write wrote %u of %u bytes.\n", bytesWritten, bytesToWrite);
212 // Function detects known I2C expanders and returns the number of GPIO pins on expander
214 mraa_ftdi_ft4222_detect_io_expander()
217 if(mraa_ftdi_ft4222_i2c_read_internal(ftHandle, PCA9672_ADDR, &data, 1) == 1) {
224 /******************* I2C functions *******************/
225 // Function not currently mapped or used since we have virtual pin definitions
226 static mraa_i2c_context
227 mraa_ftdi_ft4222_i2c_init_raw_replace(unsigned int bus)
229 // Tell the FT4222 to be an I2C Master.
230 FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, bus_speed);
231 if (FT4222_OK != ft4222Status) {
232 syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status);
236 // Reset the I2CM registers to a known state.
237 ft4222Status = FT4222_I2CMaster_Reset(ftHandle);
238 if (FT4222_OK != ft4222Status) {
239 syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status);
243 mraa_i2c_context dev = (mraa_i2c_context) malloc(sizeof(struct _i2c));
245 syslog(LOG_CRIT, "i2c: Failed to allocate memory for context");
249 dev->handle = ftHandle;
250 dev->fh = -1; // We don't use file descriptors
251 dev->funcs = I2C_FUNC_I2C; // Advertise minimal i2c support as per
252 // https://www.kernel.org/doc/Documentation/i2c/functionality
257 mraa_ftdi_ft4222_i2c_init_bus_replace(mraa_i2c_context dev)
259 // Tell the FT4222 to be an I2C Master.
260 FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, 400);
261 if (FT4222_OK != ft4222Status) {
262 syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status);
263 return MRAA_ERROR_NO_RESOURCES;
266 // Reset the I2CM registers to a known state.
267 ft4222Status = FT4222_I2CMaster_Reset(ftHandle);
268 if (FT4222_OK != ft4222Status) {
269 syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status);
270 return MRAA_ERROR_NO_RESOURCES;
273 syslog(LOG_NOTICE, "I2C interface enabled GPIO0 and GPIO1 will be unavailable.\n");
275 dev->handle = ftHandle;
276 dev->fh = -1; // We don't use file descriptors
277 dev->funcs = I2C_FUNC_I2C; // Advertise minimal i2c support as per
278 // https://www.kernel.org/doc/Documentation/i2c/functionality
284 mraa_ftdi_ft4222_i2c_frequency(mraa_i2c_context dev, mraa_i2c_mode_t mode)
287 case MRAA_I2C_STD: /**< up to 100Khz */
290 MRAA_I2C_FAST: /**< up to 400Khz */
293 MRAA_I2C_HIGH: /**< up to 3.4Mhz */
302 mraa_ftdi_ft4222_i2c_address(mraa_i2c_context dev, uint8_t addr)
304 dev->addr = (int) addr;
305 return FT4222_I2CMaster_Init(ftHandle, bus_speed) == FT4222_OK ? MRAA_SUCCESS : MRAA_ERROR_NO_RESOURCES;
310 mraa_ftdi_ft4222_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
312 return mraa_ftdi_ft4222_i2c_read_internal(dev->handle, dev->addr, data, length);
316 mraa_ftdi_ft4222_i2c_read_byte(mraa_i2c_context dev)
319 if (mraa_ftdi_ft4222_i2c_read_internal(dev->handle, dev->addr, &data, 1) == 1)
327 mraa_ftdi_ft4222_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
331 if (mraa_ftdi_ft4222_i2c_write_internal(dev->handle, dev->addr, &command, 1) != 1)
333 if (mraa_ftdi_ft4222_i2c_read_internal(dev->handle, dev->addr, buf, 2) != 2)
335 data = *(uint16_t*)buf;
340 mraa_ftdi_ft4222_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint8_t* data, int length)
342 if (mraa_ftdi_ft4222_i2c_write_internal(dev->handle, dev->addr, &command, 1) != 1)
344 return mraa_ftdi_ft4222_i2c_read_internal(dev->handle, dev->addr, data, length);
349 mraa_ftdi_ft4222_i2c_write(mraa_i2c_context dev, const uint8_t* data, int bytesToWrite)
351 uint16 bytesWritten = mraa_ftdi_ft4222_i2c_write_internal(dev->handle, dev->addr, data, bytesToWrite);
352 return bytesToWrite == bytesWritten ? MRAA_SUCCESS : MRAA_ERROR_INVALID_HANDLE;
357 mraa_ftdi_ft4222_i2c_write_byte(mraa_i2c_context dev, uint8_t data)
359 return mraa_ftdi_ft4222_i2c_write(dev, &data, 1);
364 mraa_ftdi_ft4222_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
366 const uint8_t reg_addr = command;
368 if (mraa_ftdi_ft4222_i2c_write(dev, ®_addr, 1) != MRAA_SUCCESS)
370 if (mraa_ftdi_ft4222_i2c_read(dev, &data, 1) != 1)
376 mraa_ftdi_ft4222_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command)
381 return mraa_ftdi_ft4222_i2c_write(dev, buf, 2);
385 mraa_ftdi_ft4222_i2c_write_word_data(mraa_i2c_context dev, const uint16_t data, const uint8_t command)
389 buf[1] = (uint8_t) data;
390 buf[2] = (uint8_t)(data >> 8);
391 return mraa_ftdi_ft4222_i2c_write(dev, buf, 3);
395 mraa_ftdi_ft4222_i2c_stop(mraa_i2c_context dev)
400 /******************* GPIO functions *******************/
403 mraa_ftdi_ft4222_gpio_init_internal_replace(int pin)
405 if ((pin - numI2cGpioExpanderPins) == 0 || (pin - numI2cGpioExpanderPins) == 1) {
406 syslog(LOG_NOTICE, "Closing I2C interface to enable GPIO%d\n", pin);
408 /* Replace with call to SPI init when SPI is fully implemented */
409 FT4222_STATUS ft4222Status = FT4222_SPIMaster_Init(ftHandle, SPI_IO_SINGLE, CLK_DIV_4, CLK_IDLE_HIGH, CLK_LEADING, 0x01);
410 if (FT4222_OK != ft4222Status){
411 syslog(LOG_ERR, "Failed to close I2C interface and start SPI (error %d)!\n", ft4222Status);
412 return MRAA_ERROR_NO_RESOURCES;
419 mraa_ftdi_ft4222_gpio_mode_replace(mraa_gpio_context dev, mraa_gpio_mode_t mode)
425 mraa_ftdi_ft4222_gpio_edge_mode_replace(mraa_gpio_context dev, mraa_gpio_edge_t mode)
431 mraa_ftdi_ft4222_gpio_read_replace(mraa_gpio_context dev)
433 uint8_t pin = dev->phy_pin;
434 uint8_t mask = 1 << pin;
437 if(pin >= numI2cGpioExpanderPins) {
439 FT4222_STATUS ft4222Status = FT4222_GPIO_Read(ftHandleGPIO, (pin - numI2cGpioExpanderPins), (BOOL*)&value);
440 if (FT4222_OK != ft4222Status) {
441 syslog(LOG_ERR, "FT4222_GPIO_Read failed (error %d)!\n", ft4222Status);
448 if (mraa_ftdi_ft4222_i2c_read_internal(ftHandle, PCA9672_ADDR, &value, 1) != 1)
450 return (value & mask) == mask;
456 mraa_ftdi_ft4222_gpio_write_replace(mraa_gpio_context dev, int write_value)
458 uint8_t pin = dev->phy_pin;
459 uint8_t mask = 1 << pin;
462 if(pin >= numI2cGpioExpanderPins) {
464 FT4222_STATUS ft4222Status = FT4222_GPIO_Write(ftHandleGPIO, (pin - numI2cGpioExpanderPins), write_value);
465 if (FT4222_OK != ft4222Status) {
466 syslog(LOG_ERR, "FT4222_GPIO_Write failed (error %d)!\n", ft4222Status);
467 return MRAA_ERROR_UNSPECIFIED;
472 if (mraa_ftdi_ft4222_i2c_read_internal(ftHandle, PCA9672_ADDR, &value, 1) != 1)
473 return MRAA_ERROR_UNSPECIFIED;
474 if (write_value == 1)
478 if (mraa_ftdi_ft4222_i2c_write_internal(ftHandle, PCA9672_ADDR, &value, 1) != 1)
479 return MRAA_ERROR_UNSPECIFIED;
486 mraa_ftdi_ft4222_gpio_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t dir)
490 if (dev->phy_pin >= numI2cGpioExpanderPins) {
491 pinDirection[dev->phy_pin - numI2cGpioExpanderPins] = GPIO_INPUT;
492 if (FT4222_GPIO_Init(ftHandleGPIO, pinDirection) != FT4222_OK)
493 return MRAA_ERROR_UNSPECIFIED;
497 if (dev->phy_pin >= numI2cGpioExpanderPins) {
498 pinDirection[dev->phy_pin - numI2cGpioExpanderPins] = GPIO_OUTPUT;
499 if (FT4222_GPIO_Init(ftHandleGPIO, pinDirection) != FT4222_OK)
500 return MRAA_ERROR_UNSPECIFIED;
503 case MRAA_GPIO_OUT_HIGH:
504 if (dev->phy_pin >= numI2cGpioExpanderPins) {
505 pinDirection[dev->phy_pin - numI2cGpioExpanderPins] = GPIO_OUTPUT;
506 if (FT4222_GPIO_Init(ftHandleGPIO, pinDirection) != FT4222_OK)
507 return MRAA_ERROR_UNSPECIFIED;
509 return mraa_ftdi_ft4222_gpio_write_replace(dev, 1);
510 case MRAA_GPIO_OUT_LOW:
511 if (dev->phy_pin >= numI2cGpioExpanderPins) {
512 pinDirection[dev->phy_pin - numI2cGpioExpanderPins] = GPIO_OUTPUT;
513 if (FT4222_GPIO_Init(ftHandleGPIO, pinDirection) != FT4222_OK)
514 return MRAA_ERROR_UNSPECIFIED;
516 return mraa_ftdi_ft4222_gpio_write_replace(dev, 0);
518 return MRAA_ERROR_INVALID_PARAMETER;
523 mraa_ftdi_ft4222_sleep_ms(unsigned long mseconds)
525 struct timespec sleepTime;
527 sleepTime.tv_sec = mseconds / 1000; // Number of seconds
528 sleepTime.tv_nsec = (mseconds % 1000) * 1000000; // Convert fractional seconds to nanoseconds
530 // Iterate nanosleep in a loop until the total sleep time is the original
531 // value of the seconds parameter
532 while ((nanosleep(&sleepTime, &sleepTime) != 0) && (errno == EINTR))
537 mraa_ftdi_ft4222_gpio_interrupt_handler_replace(mraa_gpio_context dev)
539 int prev_level = mraa_ftdi_ft4222_gpio_read_replace(dev);
541 int level = mraa_ftdi_ft4222_gpio_read_replace(dev);
542 // MRAA_GPIO_EDGE_BOTH
543 if (level != prev_level) {
544 dev->isr(dev->isr_args);
547 // printf("mraa_ftdi_ft4222_gpio_interrupt_handler_replace\n");
548 mraa_ftdi_ft4222_sleep_ms(100);
554 mraa_ftdi_ft4222_populate_i2c_func_table(mraa_adv_func_t* func_table)
556 func_table->i2c_init_bus_replace = &mraa_ftdi_ft4222_i2c_init_bus_replace;
557 func_table->i2c_set_frequency_replace = &mraa_ftdi_ft4222_i2c_frequency;
558 func_table->i2c_address_replace = &mraa_ftdi_ft4222_i2c_address;
559 func_table->i2c_read_replace = &mraa_ftdi_ft4222_i2c_read;
560 func_table->i2c_read_byte_replace = &mraa_ftdi_ft4222_i2c_read_byte;
561 func_table->i2c_read_byte_data_replace = &mraa_ftdi_ft4222_i2c_read_byte_data;
562 func_table->i2c_read_word_data_replace = &mraa_ftdi_ft4222_i2c_read_word_data;
563 func_table->i2c_read_bytes_data_replace = &mraa_ftdi_ft4222_i2c_read_bytes_data;
564 func_table->i2c_write_replace = &mraa_ftdi_ft4222_i2c_write;
565 func_table->i2c_write_byte_replace = &mraa_ftdi_ft4222_i2c_write_byte;
566 func_table->i2c_write_byte_data_replace = &mraa_ftdi_ft4222_i2c_write_byte_data;
567 func_table->i2c_write_word_data_replace = &mraa_ftdi_ft4222_i2c_write_word_data;
568 func_table->i2c_stop_replace = &mraa_ftdi_ft4222_i2c_stop;
572 mraa_ftdi_ft4222_populate_gpio_func_table(mraa_adv_func_t* func_table)
574 func_table->gpio_init_internal_replace = &mraa_ftdi_ft4222_gpio_init_internal_replace;
575 func_table->gpio_mode_replace = &mraa_ftdi_ft4222_gpio_mode_replace;
576 func_table->gpio_edge_mode_replace = &mraa_ftdi_ft4222_gpio_edge_mode_replace;
577 func_table->gpio_dir_replace = &mraa_ftdi_ft4222_gpio_dir_replace;
578 func_table->gpio_read_replace = &mraa_ftdi_ft4222_gpio_read_replace;
579 func_table->gpio_write_replace = &mraa_ftdi_ft4222_gpio_write_replace;
580 func_table->gpio_interrupt_handler_replace = &mraa_ftdi_ft4222_gpio_interrupt_handler_replace;
587 mraa_board_t* sub_plat = (mraa_board_t*) calloc(1, sizeof(mraa_board_t));
588 if (sub_plat == NULL)
590 numI2cGpioExpanderPins = mraa_ftdi_ft4222_detect_io_expander();
592 int numUsbPins = numI2cGpioExpanderPins + 4; // Add GPIO0/SDA, GPIO1/SCL, GPIO2, GPIO3
593 sub_plat->platform_name = PLATFORM_NAME;
594 sub_plat->phy_pin_count = numUsbPins;
595 sub_plat->gpio_count = numUsbPins;
596 mraa_pininfo_t* pins = (mraa_pininfo_t*) malloc(sizeof(mraa_pininfo_t) * numUsbPins);
600 sub_plat->pins = pins;
602 // Virtual gpio pins on i2c I/O expander.
603 mraa_pincapabilities_t pinCapsGpio = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 };
604 for (pinIndex = 0; pinIndex < numI2cGpioExpanderPins; ++pinIndex) {
606 sprintf(name, "Pin%d", pinIndex);
607 strncpy(sub_plat->pins[pinIndex].name, name, 8);
608 sub_plat->pins[pinIndex].capabilites = pinCapsGpio;
609 sub_plat->pins[pinIndex].gpio.mux_total = 0;
613 sub_plat->i2c_bus_count = 1;
614 sub_plat->def_i2c_bus = bus;
615 sub_plat->i2c_bus[bus].bus_id = bus;
617 // I2c pins (these are virtual, entries are required to configure i2c layer)
618 mraa_pincapabilities_t pinCapsI2c = (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 1, 0, 0 };
619 strncpy(sub_plat->pins[pinIndex].name, "SCL/GPIO0", 10);
620 sub_plat->pins[pinIndex].capabilites = pinCapsI2c;
621 sub_plat->pins[pinIndex].gpio.pinmap = pinIndex;
622 sub_plat->pins[pinIndex].gpio.mux_total = 0;
623 sub_plat->pins[pinIndex].i2c.mux_total = 0;
624 sub_plat->i2c_bus[bus].scl = pinIndex;
626 strncpy(sub_plat->pins[pinIndex].name, "SDA/GPIO1", 10);
627 sub_plat->pins[pinIndex].capabilites = pinCapsI2c;
628 sub_plat->pins[pinIndex].gpio.pinmap = pinIndex;
629 sub_plat->pins[pinIndex].gpio.mux_total = 0;
630 sub_plat->pins[pinIndex].i2c.mux_total = 0;
631 sub_plat->i2c_bus[bus].sda = pinIndex;
635 strncpy(sub_plat->pins[pinIndex].name, "GPIO2", 8);
636 sub_plat->pins[pinIndex].capabilites = pinCapsGpio;
637 sub_plat->pins[pinIndex].gpio.pinmap = pinIndex;
638 sub_plat->pins[pinIndex].gpio.mux_total = 0;
640 strncpy(sub_plat->pins[pinIndex].name, "GPIO3", 8);
641 sub_plat->pins[pinIndex].capabilites = pinCapsGpio;
642 sub_plat->pins[pinIndex].gpio.pinmap = pinIndex;
643 sub_plat->pins[pinIndex].gpio.mux_total = 0;
645 // Set override functions
646 mraa_adv_func_t* func_table = (mraa_adv_func_t*) calloc(1, sizeof(mraa_adv_func_t));
647 if (func_table == NULL) {
650 mraa_ftdi_ft4222_populate_i2c_func_table(func_table);
651 mraa_ftdi_ft4222_populate_gpio_func_table(func_table);
653 sub_plat->adv_func = func_table;