Private
Public Access
2
0

ftdi_ft4222.c: clean up, styling fix

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2015-08-25 15:51:02 +01:00
parent a49d8d6d12
commit fc55088c03

View File

@@ -54,30 +54,26 @@ mraa_ftdi_ft4222_init()
int retCode = 0; int retCode = 0;
ftStatus = FT_CreateDeviceInfoList(&numDevs); ftStatus = FT_CreateDeviceInfoList(&numDevs);
if (ftStatus != FT_OK) if (ftStatus != FT_OK) {
{
syslog(LOG_ERR, "FT_CreateDeviceInfoList failed: error code %d\n", ftStatus); syslog(LOG_ERR, "FT_CreateDeviceInfoList failed: error code %d\n", ftStatus);
mraaStatus = MRAA_ERROR_NO_RESOURCES; mraaStatus = MRAA_ERROR_NO_RESOURCES;
goto init_exit; goto init_exit;
} }
if (numDevs == 0) if (numDevs == 0) {
{
syslog(LOG_ERR, "No FT4222 devices connected.\n"); syslog(LOG_ERR, "No FT4222 devices connected.\n");
goto init_exit; goto init_exit;
} }
devInfo = calloc((size_t) numDevs, sizeof(FT_DEVICE_LIST_INFO_NODE)); devInfo = calloc((size_t) numDevs, sizeof(FT_DEVICE_LIST_INFO_NODE));
if (devInfo == NULL) if (devInfo == NULL) {
{
syslog(LOG_ERR, "FT4222 allocation failure.\n"); syslog(LOG_ERR, "FT4222 allocation failure.\n");
mraaStatus = MRAA_ERROR_NO_RESOURCES; mraaStatus = MRAA_ERROR_NO_RESOURCES;
goto init_exit; goto init_exit;
} }
ftStatus = FT_GetDeviceInfoList(devInfo, &numDevs); ftStatus = FT_GetDeviceInfoList(devInfo, &numDevs);
if (ftStatus != FT_OK) if (ftStatus != FT_OK) {
{
syslog(LOG_ERR, "FT_GetDeviceInfoList failed (error code %d)\n", (int) ftStatus); syslog(LOG_ERR, "FT_GetDeviceInfoList failed (error code %d)\n", (int) ftStatus);
mraaStatus = MRAA_ERROR_NO_RESOURCES; mraaStatus = MRAA_ERROR_NO_RESOURCES;
goto init_exit; goto init_exit;
@@ -87,7 +83,8 @@ mraa_ftdi_ft4222_init()
FT4222_Version ft4222Version; FT4222_Version ft4222Version;
FT4222_STATUS ft4222Status = FT4222_GetVersion(ftHandle, &ft4222Version); FT4222_STATUS ft4222Status = FT4222_GetVersion(ftHandle, &ft4222Version);
if (FT4222_OK == ft4222Status){ if (FT4222_OK == ft4222Status){
syslog(LOG_NOTICE, "FT4222_GetVersion %08X %08X\n", ft4222Version.chipVersion, ft4222Version.dllVersion); syslog(LOG_NOTICE, "FT4222_GetVersion %08X %08X\n", ft4222Version.chipVersion,
ft4222Version.dllVersion);
} else } else
syslog(LOG_ERR, "FT4222_GetVersion failed with code %d", ft4222Status); syslog(LOG_ERR, "FT4222_GetVersion failed with code %d", ft4222Status);
*/ */
@@ -106,8 +103,7 @@ mraa_ftdi_ft4222_init()
} }
ftStatus = FT_OpenEx((PVOID)(uintptr_t) locationId, FT_OPEN_BY_LOCATION, &ftHandle); ftStatus = FT_OpenEx((PVOID)(uintptr_t) locationId, FT_OPEN_BY_LOCATION, &ftHandle);
if (ftStatus != FT_OK) if (ftStatus != FT_OK) {
{
syslog(LOG_ERR, "FT_OpenEx failed (error %d)\n", (int) ftStatus); syslog(LOG_ERR, "FT_OpenEx failed (error %d)\n", (int) ftStatus);
mraaStatus = MRAA_ERROR_NO_RESOURCES; mraaStatus = MRAA_ERROR_NO_RESOURCES;
goto init_exit; goto init_exit;
@@ -115,8 +111,7 @@ mraa_ftdi_ft4222_init()
// Tell the FT4222 to be an I2C Master. // Tell the FT4222 to be an I2C Master.
FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, bus_speed); FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, bus_speed);
if (FT4222_OK != ft4222Status) if (FT4222_OK != ft4222Status) {
{
syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status); syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status);
mraaStatus = MRAA_ERROR_NO_RESOURCES; mraaStatus = MRAA_ERROR_NO_RESOURCES;
goto init_exit; goto init_exit;
@@ -124,8 +119,7 @@ mraa_ftdi_ft4222_init()
// Reset the I2CM registers to a known state. // Reset the I2CM registers to a known state.
ft4222Status = FT4222_I2CMaster_Reset(ftHandle); ft4222Status = FT4222_I2CMaster_Reset(ftHandle);
if (FT4222_OK != ft4222Status) if (FT4222_OK != ft4222Status) {
{
syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status); syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status);
mraaStatus = MRAA_ERROR_NO_RESOURCES; mraaStatus = MRAA_ERROR_NO_RESOURCES;
goto init_exit; goto init_exit;
@@ -133,7 +127,8 @@ mraa_ftdi_ft4222_init()
init_exit: init_exit:
if (devInfo != NULL); if (devInfo != NULL)
;
free(devInfo); free(devInfo);
if (mraaStatus == MRAA_SUCCESS) if (mraaStatus == MRAA_SUCCESS)
syslog(LOG_NOTICE, "mraa_ftdi_ft4222_init completed successfully\n"); syslog(LOG_NOTICE, "mraa_ftdi_ft4222_init completed successfully\n");
@@ -171,8 +166,7 @@ mraa_ftdi_ft4222_i2c_read_internal(FT_HANDLE handle, uint8_t addr, uint8_t* data
// syslog(LOG_NOTICE, "FT4222_I2CMaster_Read(%#02X, %#02X)", addr, length); // syslog(LOG_NOTICE, "FT4222_I2CMaster_Read(%#02X, %#02X)", addr, length);
FT4222_STATUS ft4222Status = FT4222_I2CMaster_Read(handle, addr, data, length, &bytesRead); FT4222_STATUS ft4222Status = FT4222_I2CMaster_Read(handle, addr, data, length, &bytesRead);
ft4222Status = FT4222_I2CMaster_GetStatus(ftHandle, &controllerStatus); ft4222Status = FT4222_I2CMaster_GetStatus(ftHandle, &controllerStatus);
if (FT4222_OK != ft4222Status || I2CM_ERROR(controllerStatus)) if (FT4222_OK != ft4222Status || I2CM_ERROR(controllerStatus)) {
{
syslog(LOG_ERR, "FT4222_I2CMaster_Read failed (error %d)\n", (int) ft4222Status); syslog(LOG_ERR, "FT4222_I2CMaster_Read failed (error %d)\n", (int) ft4222Status);
return 0; return 0;
} }
@@ -185,10 +179,10 @@ mraa_ftdi_ft4222_i2c_write_internal(FT_HANDLE handle, uint8_t addr, const uint8_
uint16 bytesWritten = 0; uint16 bytesWritten = 0;
uint8 controllerStatus; uint8 controllerStatus;
// syslog(LOG_NOTICE, "FT4222_I2CMaster_Write(%#02X, %#02X, %d)", addr, *data, bytesToWrite); // syslog(LOG_NOTICE, "FT4222_I2CMaster_Write(%#02X, %#02X, %d)", addr, *data, bytesToWrite);
FT4222_STATUS ft4222Status = FT4222_I2CMaster_Write(handle, addr, (uint8_t*)data, bytesToWrite, &bytesWritten); FT4222_STATUS ft4222Status =
FT4222_I2CMaster_Write(handle, addr, (uint8_t*) data, bytesToWrite, &bytesWritten);
ft4222Status = FT4222_I2CMaster_GetStatus(ftHandle, &controllerStatus); ft4222Status = FT4222_I2CMaster_GetStatus(ftHandle, &controllerStatus);
if (FT4222_OK != ft4222Status || I2CM_ERROR(controllerStatus)) if (FT4222_OK != ft4222Status || I2CM_ERROR(controllerStatus)) {
{
syslog(LOG_ERR, "FT4222_I2CMaster_Write failed (error %d)\n", (int) ft4222Status); syslog(LOG_ERR, "FT4222_I2CMaster_Write failed (error %d)\n", (int) ft4222Status);
return 0; return 0;
} }
@@ -208,24 +202,20 @@ mraa_ftdi_ft4222_detect_io_expander()
} }
/******************* I2C functions *******************/ /******************* I2C functions *******************/
static mraa_i2c_context static mraa_i2c_context
mraa_ftdi_ft4222_i2c_init_raw(unsigned int bus) mraa_ftdi_ft4222_i2c_init_raw(unsigned int bus)
{ {
// Tell the FT4222 to be an I2C Master. // Tell the FT4222 to be an I2C Master.
FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, bus_speed); FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, bus_speed);
if (FT4222_OK != ft4222Status) if (FT4222_OK != ft4222Status) {
{
syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status); syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status);
return NULL; return NULL;
} }
// Reset the I2CM registers to a known state. // Reset the I2CM registers to a known state.
ft4222Status = FT4222_I2CMaster_Reset(ftHandle); ft4222Status = FT4222_I2CMaster_Reset(ftHandle);
if (FT4222_OK != ft4222Status) if (FT4222_OK != ft4222Status) {
{
syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status); syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status);
return NULL; return NULL;
} }
@@ -238,7 +228,8 @@ mraa_ftdi_ft4222_i2c_init_raw(unsigned int bus)
dev->handle = ftHandle; dev->handle = ftHandle;
dev->fh = -1; // We don't use file descriptors dev->fh = -1; // We don't use file descriptors
dev->funcs = I2C_FUNC_I2C; // Advertise minimal i2c support as per https://www.kernel.org/doc/Documentation/i2c/functionality dev->funcs = I2C_FUNC_I2C; // Advertise minimal i2c support as per
// https://www.kernel.org/doc/Documentation/i2c/functionality
return dev; return dev;
} }
@@ -247,23 +238,22 @@ mraa_ftdi_ft4222_i2c_init_bus_replace(mraa_i2c_context dev)
{ {
// Tell the FT4222 to be an I2C Master. // Tell the FT4222 to be an I2C Master.
FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, 400); FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, 400);
if (FT4222_OK != ft4222Status) if (FT4222_OK != ft4222Status) {
{
syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status); syslog(LOG_ERR, "FT4222_I2CMaster_Init failed (error %d)!\n", ft4222Status);
return MRAA_ERROR_NO_RESOURCES; return MRAA_ERROR_NO_RESOURCES;
} }
// Reset the I2CM registers to a known state. // Reset the I2CM registers to a known state.
ft4222Status = FT4222_I2CMaster_Reset(ftHandle); ft4222Status = FT4222_I2CMaster_Reset(ftHandle);
if (FT4222_OK != ft4222Status) if (FT4222_OK != ft4222Status) {
{
syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status); syslog(LOG_ERR, "FT4222_I2CMaster_Reset failed (error %d)!\n", ft4222Status);
return MRAA_ERROR_NO_RESOURCES; return MRAA_ERROR_NO_RESOURCES;
} }
dev->handle = ftHandle; dev->handle = ftHandle;
dev->fh = -1; // We don't use file descriptors dev->fh = -1; // We don't use file descriptors
dev->funcs = I2C_FUNC_I2C; // Advertise minimal i2c support as per https://www.kernel.org/doc/Documentation/i2c/functionality dev->funcs = I2C_FUNC_I2C; // Advertise minimal i2c support as per
// https://www.kernel.org/doc/Documentation/i2c/functionality
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -430,7 +420,8 @@ mraa_ftdi_ft4222_gpio_dir_replace(mraa_gpio_context dev, mraa_gpio_dir_t dir)
return mraa_ftdi_ft4222_gpio_write_replace(dev, 1); return mraa_ftdi_ft4222_gpio_write_replace(dev, 1);
case MRAA_GPIO_OUT_LOW: case MRAA_GPIO_OUT_LOW:
return mraa_ftdi_ft4222_gpio_write_replace(dev, 0); return mraa_ftdi_ft4222_gpio_write_replace(dev, 0);
default:; default:
;
} }
return MRAA_SUCCESS; return MRAA_SUCCESS;
} }
@@ -445,7 +436,8 @@ mraa_ftdi_ft4222_sleep_ms(unsigned long mseconds)
// Iterate nanosleep in a loop until the total sleep time is the original // Iterate nanosleep in a loop until the total sleep time is the original
// value of the seconds parameter // value of the seconds parameter
while ( ( nanosleep( &sleepTime, &sleepTime ) != 0 ) && ( errno == EINTR ) ); while ((nanosleep(&sleepTime, &sleepTime) != 0) && (errno == EINTR))
;
} }
static void* static void*
@@ -552,4 +544,3 @@ mraa_ftdi_ft4222()
sub_plat->adv_func = func_table; sub_plat->adv_func = func_table;
return sub_plat; return sub_plat;
} }