[Armadeus-commitlog] armadeus branch, master, updated. armadeus-5.3-305-g16f3bee
Brought to you by:
sszy
|
From: Julien B a. A. <ar...@us...> - 2014-06-25 08:54:23
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via 16f3bee792ed6af559b21b1855b12112c3e02b36 (commit)
from 7b32b10cf1143a8e8ff8570432369823f521fcc2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 16f3bee792ed6af559b21b1855b12112c3e02b36
Author: Julien Boibessot <jul...@ar...>
Date: Wed Jun 25 10:52:04 2014 +0200
[ASDEVICES] Lindent all C modules sources... again...
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/as_93lcxx.c | 378 +++++++++----------
target/packages/as_devices/c/as_93lcxx.h | 45 +--
target/packages/as_devices/c/as_adc.h | 8 +-
target/packages/as_devices/c/as_adc_iio.c | 161 ++++----
target/packages/as_devices/c/as_adc_iio.h | 7 +-
target/packages/as_devices/c/as_as1531.c | 111 +++---
target/packages/as_devices/c/as_as1531.h | 9 +-
target/packages/as_devices/c/as_backlight.c | 211 ++++++-----
target/packages/as_devices/c/as_backlight.h | 22 +-
target/packages/as_devices/c/as_dac.c | 2 +-
target/packages/as_devices/c/as_dac.h | 2 +-
target/packages/as_devices/c/as_gpio.c | 484 ++++++++++++------------
target/packages/as_devices/c/as_gpio.h | 27 +-
target/packages/as_devices/c/as_gpio_2_6_29.c | 348 +++++++++---------
target/packages/as_devices/c/as_helpers.c | 2 +-
target/packages/as_devices/c/as_i2c.c | 447 +++++++++++-----------
target/packages/as_devices/c/as_i2c.h | 31 +-
target/packages/as_devices/c/as_i2c_eeprom.c | 442 ++++++++++++----------
target/packages/as_devices/c/as_i2c_eeprom.h | 53 ++--
target/packages/as_devices/c/as_led.c | 201 +++++-----
target/packages/as_devices/c/as_led.h | 21 +-
target/packages/as_devices/c/as_max1027.c | 340 +++++++++--------
target/packages/as_devices/c/as_max1027.h | 22 +-
target/packages/as_devices/c/as_max5821.c | 279 +++++++-------
target/packages/as_devices/c/as_max5821.h | 29 +-
target/packages/as_devices/c/as_power_supply.c | 198 +++++-----
target/packages/as_devices/c/as_power_supply.h | 33 +-
target/packages/as_devices/c/as_pwm.c | 313 ++++++++--------
target/packages/as_devices/c/as_pwm.h | 20 +-
target/packages/as_devices/c/as_spi.c | 206 +++++-----
target/packages/as_devices/c/as_spi.h | 13 +-
31 files changed, 2249 insertions(+), 2216 deletions(-)
diff --git a/target/packages/as_devices/c/as_93lcxx.c b/target/packages/as_devices/c/as_93lcxx.c
index a1d17b9..69188fb 100644
--- a/target/packages/as_devices/c/as_93lcxx.c
+++ b/target/packages/as_devices/c/as_93lcxx.c
@@ -29,7 +29,7 @@
/* define start bits + opcode */
#define READ (6)
#define EWEN (4)
-#define EWEN_ADDR (3)
+#define EWEN_ADDR (3)
#define ERASE (7)
#define ERAL (4)
#define ERAL_ADDR (2)
@@ -48,9 +48,9 @@
//#define DEBUG
#ifdef DEBUG
-# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
-# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
+#define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__ */
#endif
/** @brief Private functions to ease making spi instructions
@@ -58,262 +58,246 @@
*/
static uint8_t address_len(uint8_t aType, uint8_t aWord_size)
{
- switch (aType)
- {
- case 46:
- if (aWord_size == 16)
- return 6;
- else
- return 7;
- case 56:
- case 66:
- if (aWord_size == 16)
- return 8;
- else
- return 9;
- default:
- return 0;
- }
+ switch (aType) {
+ case 46:
+ if (aWord_size == 16)
+ return 6;
+ else
+ return 7;
+ case 56:
+ case 66:
+ if (aWord_size == 16)
+ return 8;
+ else
+ return 9;
+ default:
+ return 0;
+ }
}
/*------------------------------------------------------------------------------*/
-struct as_93lcxx_device * as_93lcxx_open(unsigned char *aSpidev_filename,
- uint8_t aType,
- uint32_t aSpeed,
- uint8_t aWord_size)
+struct as_93lcxx_device *as_93lcxx_open(unsigned char *aSpidev_filename,
+ uint8_t aType,
+ uint32_t aSpeed, uint8_t aWord_size)
{
- int fd=-1;
- struct as_93lcxx_device *dev;
-
- /* open spidev bus */
- fd = as_spi_open(aSpidev_filename);
- if (fd < 0) {
- ERROR("Can't open spi device");
- return NULL;
- }
-
- /* verify datas */
- if (!( (aType == 46) || (aType == 56) || (aType == 66)))
- return NULL;
- if ((aWord_size < 1) || (aWord_size > 16))
- return NULL;
-
- dev = (struct as_93lcxx_device *)malloc(sizeof(struct as_93lcxx_device));
- if (dev == NULL) {
- ERROR("Can't allocate memory for eeprom structure device\n");
- return NULL;
- }
-
- /* fill in spidev structure */
- dev->spidev_filename = aSpidev_filename;
- dev->type = aType;
- dev->speed = aSpeed;
- dev->word_size = aWord_size;
- dev->fd = fd;
-
- return dev;
+ int fd;
+ struct as_93lcxx_device *dev;
+
+ /* open spidev bus */
+ fd = as_spi_open(aSpidev_filename);
+ if (fd < 0) {
+ ERROR("Can't open spi device");
+ return NULL;
+ }
+
+ /* verify datas */
+ if (!((aType == 46) || (aType == 56) || (aType == 66)))
+ return NULL;
+ if ((aWord_size < 1) || (aWord_size > 16))
+ return NULL;
+
+ dev =
+ (struct as_93lcxx_device *)malloc(sizeof(struct as_93lcxx_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate memory for eeprom structure device\n");
+ return NULL;
+ }
+
+ /* fill in spidev structure */
+ dev->spidev_filename = aSpidev_filename;
+ dev->type = aType;
+ dev->speed = aSpeed;
+ dev->word_size = aWord_size;
+ dev->fd = fd;
+
+ return dev;
}
/*------------------------------------------------------------------------------*/
-int32_t as_93lcxx_read(struct as_93lcxx_device *aDev, uint16_t aAddress)
+int32_t as_93lcxx_read(struct as_93lcxx_device * aDev, uint16_t aAddress)
{
- uint32_t data_out,msg=0;
- int add_length;
-
- add_length = address_len(aDev->type, aDev->word_size);
-
- /* forge message */
- msg = ((READ << (add_length+ (aDev->word_size)))
- | (aAddress << (aDev->word_size)));
-
- data_out = as_spi_msg(aDev->fd, msg,
- 3 + add_length + aDev->word_size,
- aDev->speed);
- if (data_out < 0) {
- ERROR("Error on forging spi message\n");
- return -1;
- }
-
- if (aDev->word_size == 8)
- return data_out & 0xff;
- else
- return data_out & 0xffff;
+ uint32_t data_out, msg = 0;
+ int add_length;
+
+ add_length = address_len(aDev->type, aDev->word_size);
+
+ /* forge message */
+ msg = ((READ << (add_length + (aDev->word_size)))
+ | (aAddress << (aDev->word_size)));
+
+ data_out = as_spi_msg(aDev->fd, msg,
+ 3 + add_length + aDev->word_size, aDev->speed);
+ if (data_out < 0) {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
+
+ if (aDev->word_size == 8)
+ return data_out & 0xff;
+ else
+ return data_out & 0xffff;
}
/*------------------------------------------------------------------------------*/
-int32_t as_93lcxx_ewen(struct as_93lcxx_device *aDev)
+int32_t as_93lcxx_ewen(struct as_93lcxx_device * aDev)
{
- uint32_t msg=0;
- int add_length;
- int ret;
+ uint32_t msg = 0;
+ int add_length;
+ int ret;
- add_length = address_len(aDev->type, aDev->word_size);
+ add_length = address_len(aDev->type, aDev->word_size);
- /* forge message */
- msg = ((EWEN << add_length) |(EWEN_ADDR << (add_length-2)));
+ /* forge message */
+ msg = ((EWEN << add_length) | (EWEN_ADDR << (add_length - 2)));
- ret = as_spi_msg(aDev->fd, msg,
- 3 + add_length,
- aDev->speed);
- if (ret < 0) {
- ERROR("Error on forging spi message\n");
- return -1;
- }
+ ret = as_spi_msg(aDev->fd, msg, 3 + add_length, aDev->speed);
+ if (ret < 0) {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
- return 0;
+ return 0;
}
/*------------------------------------------------------------------------------*/
-int32_t as_93lcxx_erase(struct as_93lcxx_device *aDev, uint16_t aAddress)
+int32_t as_93lcxx_erase(struct as_93lcxx_device * aDev, uint16_t aAddress)
{
- uint32_t msg=0;
- int add_length;
- int ret;
+ uint32_t msg = 0;
+ int add_length;
+ int ret;
- add_length = address_len(aDev->type, aDev->word_size);
+ add_length = address_len(aDev->type, aDev->word_size);
- /* forge message */
- msg = ((ERASE << (add_length + aDev->word_size))
- | (aAddress << (aDev->word_size)));
+ /* forge message */
+ msg = ((ERASE << (add_length + aDev->word_size))
+ | (aAddress << (aDev->word_size)));
- ret = as_spi_msg(aDev->fd, msg,
- 3 + add_length + aDev->word_size,
- aDev->speed);
- if (ret < 0) {
- ERROR("Error on forging spi message\n");
- return -1;
- }
+ ret = as_spi_msg(aDev->fd, msg,
+ 3 + add_length + aDev->word_size, aDev->speed);
+ if (ret < 0) {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
- usleep(TWC);
+ usleep(TWC);
- return 0;
+ return 0;
}
/*------------------------------------------------------------------------------*/
-int32_t as_93lcxx_erase_all(struct as_93lcxx_device *aDev)
+int32_t as_93lcxx_erase_all(struct as_93lcxx_device * aDev)
{
- uint32_t msg=0;
- int add_length;
- int ret;
+ uint32_t msg = 0;
+ int add_length;
+ int ret;
- add_length = address_len(aDev->type, aDev->word_size);
+ add_length = address_len(aDev->type, aDev->word_size);
- /* forge message */
- msg = ((ERAL << add_length)
- |(ERAL_ADDR << (add_length-2))
- );
+ /* forge message */
+ msg = ((ERAL << add_length)
+ | (ERAL_ADDR << (add_length - 2))
+ );
- ret = as_spi_msg(aDev->fd, msg,
- 3 + add_length,
- aDev->speed);
- if (ret < 0) {
- ERROR("Error on forging spi message\n");
- return -1;
- }
+ ret = as_spi_msg(aDev->fd, msg, 3 + add_length, aDev->speed);
+ if (ret < 0) {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
- /* wait for end of erase all */
- usleep(TEC);
+ /* wait for end of erase all */
+ usleep(TEC);
- return 0;
+ return 0;
}
/*------------------------------------------------------------------------------*/
-int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
- uint16_t aAddress,
- uint16_t aValue)
+int32_t as_93lcxx_write(struct as_93lcxx_device * aDev,
+ uint16_t aAddress, uint16_t aValue)
{
- uint32_t msg=0;
- int add_length;
- int ret;
-
- add_length = address_len(aDev->type, aDev->word_size);
-
- /* forge message */
- msg = ((WRITE << (add_length+ (aDev->word_size)))
- | (aAddress << (aDev->word_size))
- | aValue
- );
-
- ret = as_spi_msg(aDev->fd, msg,
- 3 + add_length + aDev->word_size,
- aDev->speed);
- if (ret < 0) {
- ERROR("Error on forging spi message\n");
- return -1;
- }
-
- /* Wait for end of writing */
- usleep(TWC);
-
- return 0;
+ uint32_t msg = 0;
+ int add_length;
+ int ret;
+
+ add_length = address_len(aDev->type, aDev->word_size);
+
+ /* forge message */
+ msg = ((WRITE << (add_length + (aDev->word_size)))
+ | (aAddress << (aDev->word_size))
+ | aValue);
+
+ ret = as_spi_msg(aDev->fd, msg,
+ 3 + add_length + aDev->word_size, aDev->speed);
+ if (ret < 0) {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
+
+ /* Wait for end of writing */
+ usleep(TWC);
+
+ return 0;
}
/*------------------------------------------------------------------------------*/
-int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
- uint16_t aValue)
+int32_t as_93lcxx_write_all(struct as_93lcxx_device * aDev, uint16_t aValue)
{
- uint32_t msg=0;
- int add_length;
- int ret;
-
- add_length = address_len(aDev->type, aDev->word_size);
-
- /* forge message */
- msg = ((WRAL << (add_length+ (aDev->word_size)))
- |(WRAL_ADDR << ((aDev->word_size) + (add_length-2)))
- |aValue
- );
-
- ret = as_spi_msg(aDev->fd, msg,
- 3 + add_length + aDev->word_size,
- aDev->speed);
- if (ret < 0) {
- ERROR("Error on forging spi message\n");
- return -1;
- }
-
- /* Wait for end of write all */
- usleep(TWL);
-
- return 0;
+ uint32_t msg = 0;
+ int add_length;
+ int ret;
+
+ add_length = address_len(aDev->type, aDev->word_size);
+
+ /* forge message */
+ msg = ((WRAL << (add_length + (aDev->word_size)))
+ | (WRAL_ADDR << ((aDev->word_size) + (add_length - 2)))
+ | aValue);
+
+ ret = as_spi_msg(aDev->fd, msg,
+ 3 + add_length + aDev->word_size, aDev->speed);
+ if (ret < 0) {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
+
+ /* Wait for end of write all */
+ usleep(TWL);
+
+ return 0;
}
/*------------------------------------------------------------------------------*/
-int32_t as_93lcxx_ewds(struct as_93lcxx_device *aDev)
+int32_t as_93lcxx_ewds(struct as_93lcxx_device * aDev)
{
- uint32_t msg=0;
- int add_length;
- int ret;
+ uint32_t msg = 0;
+ int add_length;
+ int ret;
- add_length = address_len(aDev->type, aDev->word_size);
+ add_length = address_len(aDev->type, aDev->word_size);
- /* forge message */
- msg = ((EWDS << add_length) |(EWDS_ADDR << (add_length-2)));
+ /* forge message */
+ msg = ((EWDS << add_length) | (EWDS_ADDR << (add_length - 2)));
- ret = as_spi_msg(aDev->fd, msg,
- 3 + add_length,
- aDev->speed);
- if (ret < 0) {
- ERROR("Error on forging spi message\n");
- return -1;
- }
+ ret = as_spi_msg(aDev->fd, msg, 3 + add_length, aDev->speed);
+ if (ret < 0) {
+ ERROR("Error on forging spi message\n");
+ return -1;
+ }
- return 0;
+ return 0;
}
/*------------------------------------------------------------------------------*/
void as_93lcxx_close(struct as_93lcxx_device *aDev)
{
- as_spi_close(aDev->fd);
- free(aDev);
+ as_spi_close(aDev->fd);
+ free(aDev);
}
-
diff --git a/target/packages/as_devices/c/as_93lcxx.h b/target/packages/as_devices/c/as_93lcxx.h
index 84b87e0..caae3bc 100644
--- a/target/packages/as_devices/c/as_93lcxx.h
+++ b/target/packages/as_devices/c/as_93lcxx.h
@@ -18,11 +18,9 @@
*
*/
-
#ifndef AS_93LCXX_H_
#define AS_93LCXX_H_
-
/** @file
* @brief Provide standard commands to drive 93LCxx eeprom (from microchip)
*
@@ -42,12 +40,12 @@ extern "C" {
*
* @ingroup c_files
*/
-struct as_93lcxx_device {
- unsigned char *spidev_filename; /**< filename of the spidev /dev file */
- uint8_t type; /**< type of the eeprom : 46, 56 or 66 (see DS) */
- uint32_t speed; /**< SCLK speed, in Hz */
- uint8_t word_size; /**< word size for transaction, 8 or 16 */
- int fd; /**< File handler for spidev bus */
+struct as_93lcxx_device {
+ unsigned char *spidev_filename; /**< filename of the spidev /dev file */
+ uint8_t type; /**< type of the eeprom : 46, 56 or 66 (see DS) */
+ uint32_t speed; /**< SCLK speed, in Hz */
+ uint8_t word_size; /**< word size for transaction, 8 or 16 */
+ int fd; /**< File handler for spidev bus */
};
/** @brief open the device
@@ -59,10 +57,10 @@ struct as_93lcxx_device {
*
* @return as_93lcxx_device struct pointer on success, NULL on error
*/
-struct as_93lcxx_device * as_93lcxx_open(unsigned char *aSpidev_filename,
- uint8_t aType,
- uint32_t aSpeed,
- uint8_t aWord_size);
+struct as_93lcxx_device *as_93lcxx_open(unsigned char *aSpidev_filename,
+ uint8_t aType,
+ uint32_t aSpeed,
+ uint8_t aWord_size);
/** @brief close the device
*
@@ -78,8 +76,8 @@ void as_93lcxx_close(struct as_93lcxx_device *aDev);
*
* @return positive register value on success, negative value on error.
*/
-int32_t as_93lcxx_read(struct as_93lcxx_device *aDev,
- uint16_t aAddress);
+int32_t as_93lcxx_read(struct as_93lcxx_device *aDev,
+ uint16_t aAddress);
/** @brief enable write on eeprom
*
@@ -96,8 +94,8 @@ int32_t as_93lcxx_ewen(struct as_93lcxx_device *aDev);
*
* @return positive register value on success, negative value on error.
*/
-int32_t as_93lcxx_erase(struct as_93lcxx_device *aDev,
- uint16_t aAddress);
+int32_t as_93lcxx_erase(struct as_93lcxx_device *aDev,
+ uint16_t aAddress);
/** @brief Force all bits in eeprom to 1
*
@@ -115,9 +113,8 @@ int32_t as_93lcxx_erase_all(struct as_93lcxx_device *aDev);
*
* @return positive register value on success, negative value on error.
*/
-int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
- uint16_t aAddress,
- uint16_t aValue);
+int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
+ uint16_t aAddress, uint16_t aValue);
/** @brief write the entire memory array with value given
*
@@ -126,8 +123,8 @@ int32_t as_93lcxx_write(struct as_93lcxx_device *aDev,
*
* @return positive register value on success, negative value on error.
*/
-int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
- uint16_t aValue);
+int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
+ uint16_t aValue);
/** @brief disable write on eeprom
*
@@ -137,9 +134,7 @@ int32_t as_93lcxx_write_all(struct as_93lcxx_device *aDev,
*/
int32_t as_93lcxx_ewds(struct as_93lcxx_device *aDev);
-
#ifdef __cplusplus
}
-#endif /* __cplusplus */
-
-#endif /* AS_93LCXX_H_ */
+#endif /* __cplusplus */
+#endif /* AS_93LCXX_H_ */
diff --git a/target/packages/as_devices/c/as_adc.h b/target/packages/as_devices/c/as_adc.h
index 4cab58a..e87f875 100644
--- a/target/packages/as_devices/c/as_adc.h
+++ b/target/packages/as_devices/c/as_adc.h
@@ -44,8 +44,8 @@ extern const char AS_IIO_NAME[];
*/
struct as_adc_device {
const char *device_type; /*!< device type: "as1531" or "max1027" */
- int device_num; /*!< device id on bus */
- int vref; /*!< reference voltage in millivolts */
+ int device_num; /*!< device id on bus */
+ int vref; /*!< reference voltage in millivolts */
void *chip_param; /*!< private data for chip handler */
};
@@ -80,5 +80,5 @@ int32_t as_adc_close(struct as_adc_device *adc);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
-#endif /* __AS_ADC_H__ */
+#endif /* __cplusplus */
+#endif /* __AS_ADC_H__ */
diff --git a/target/packages/as_devices/c/as_adc_iio.c b/target/packages/as_devices/c/as_adc_iio.c
index 78966b3..b6d87e8 100644
--- a/target/packages/as_devices/c/as_adc_iio.c
+++ b/target/packages/as_devices/c/as_adc_iio.c
@@ -40,103 +40,106 @@
#define IIO_DEVICE_MAX_CHANNELS 32
struct as_adc_iio_device {
- int channelDesc[IIO_DEVICE_MAX_CHANNELS];
+ int channelDesc[IIO_DEVICE_MAX_CHANNELS];
};
static int open_channels(struct as_adc_iio_device *aDev, int aDeviceNum)
{
- char buffer[128];
- int i;
- int count;
-
- count = 0;
- for (i=0; i<IIO_DEVICE_MAX_CHANNELS; i++) {
- snprintf(buffer, sizeof(buffer),
- "/sys/bus/iio/devices/iio:device%d/in_voltage%d_raw",
- aDeviceNum, i);
- aDev->channelDesc[i] = open(buffer, O_RDONLY);
- if (aDev->channelDesc[i] >= 0) {
- count++;
- }
- }
- return count;
+ char buffer[128];
+ int i;
+ int count;
+
+ count = 0;
+ for (i = 0; i < IIO_DEVICE_MAX_CHANNELS; i++) {
+ snprintf(buffer, sizeof(buffer),
+ "/sys/bus/iio/devices/iio:device%d/in_voltage%d_raw",
+ aDeviceNum, i);
+ aDev->channelDesc[i] = open(buffer, O_RDONLY);
+ if (aDev->channelDesc[i] >= 0) {
+ count++;
+ }
+ }
+ return count;
}
static void close_channels(struct as_adc_iio_device *aDev)
{
- int i;
+ int i;
- for (i=0; i<IIO_DEVICE_MAX_CHANNELS; i++) {
- if (aDev->channelDesc[i] >= 0) {
- close(aDev->channelDesc[i]);
- }
- }
+ for (i = 0; i < IIO_DEVICE_MAX_CHANNELS; i++) {
+ if (aDev->channelDesc[i] >= 0) {
+ close(aDev->channelDesc[i]);
+ }
+ }
}
struct as_adc_device *as_adc_open_iio(int aDeviceNum, int aVRef)
{
- struct as_adc_device *adc_dev;
- struct as_adc_iio_device *dev;
-
- dev = (struct as_adc_iio_device *)malloc(sizeof(struct as_adc_iio_device));
- if (dev == NULL) {
- ERROR("Error during memory allocation\n");
- return NULL;
- }
-
- if (open_channels(dev, aDeviceNum) == 0) {
- ERROR("No in voltage channel found\n");
- goto err;
- }
-
- adc_dev = (struct as_adc_device *)malloc(sizeof(struct as_adc_device));
- if (dev == NULL) {
- close_channels(dev);
- ERROR("Error during memory allocation\n");
- goto err;
- }
-
- adc_dev->chip_param = (void*)dev;
- adc_dev->device_type = AS_IIO_NAME;
- adc_dev->device_num = aDeviceNum;
- adc_dev->vref = aVRef; /* NOT USED */
-
- return adc_dev;
+ struct as_adc_device *adc_dev;
+ struct as_adc_iio_device *dev;
+
+ dev = (struct as_adc_iio_device *)
+ malloc(sizeof(struct as_adc_iio_device));
+ if (dev == NULL) {
+ ERROR("Error during memory allocation\n");
+ return NULL;
+ }
+
+ if (open_channels(dev, aDeviceNum) == 0) {
+ ERROR("No in voltage channel found\n");
+ goto err;
+ }
+
+ adc_dev = (struct as_adc_device *)malloc(sizeof(struct as_adc_device));
+ if (dev == NULL) {
+ close_channels(dev);
+ ERROR("Error during memory allocation\n");
+ goto err;
+ }
+
+ adc_dev->chip_param = (void *)dev;
+ adc_dev->device_type = AS_IIO_NAME;
+ adc_dev->device_num = aDeviceNum;
+ adc_dev->vref = aVRef; /* NOT USED */
+
+ return adc_dev;
err:
- free(dev);
- return NULL;
+ free(dev);
+ return NULL;
}
-int32_t as_adc_get_value_in_millivolts_iio(struct as_adc_device *aDev, int aChannel) {
- struct as_adc_iio_device *dev;
- int32_t value;
- int32_t ret;
-
- dev = (struct as_adc_iio_device *)aDev->chip_param;
-
- if ((aChannel >= IIO_DEVICE_MAX_CHANNELS) || (aChannel < 0)) {
- ERROR("Wrong num channel\n");
- return -1;
- }
-
- if (dev->channelDesc[aChannel] != -1) {
- ret = as_read_int(dev->channelDesc[aChannel], &value);
- if (ret < 0) {
- ERROR("Can't read input file\n");
- return -1;
- }
- }
-
- return value;
+int32_t as_adc_get_value_in_millivolts_iio(struct as_adc_device * aDev,
+ int aChannel)
+{
+ struct as_adc_iio_device *dev;
+ int32_t value;
+ int32_t ret;
+
+ dev = (struct as_adc_iio_device *)aDev->chip_param;
+
+ if ((aChannel >= IIO_DEVICE_MAX_CHANNELS) || (aChannel < 0)) {
+ ERROR("Wrong num channel\n");
+ return -1;
+ }
+
+ if (dev->channelDesc[aChannel] != -1) {
+ ret = as_read_int(dev->channelDesc[aChannel], &value);
+ if (ret < 0) {
+ ERROR("Can't read input file\n");
+ return -1;
+ }
+ }
+
+ return value;
}
-int32_t as_adc_close_iio(struct as_adc_device *aDev) {
- struct as_adc_iio_device *dev =
- (struct as_adc_iio_device *)aDev->chip_param;
+int32_t as_adc_close_iio(struct as_adc_device * aDev)
+{
+ struct as_adc_iio_device *dev =
+ (struct as_adc_iio_device *)aDev->chip_param;
- close_channels(dev);
- free(dev);
- return 0;
+ close_channels(dev);
+ free(dev);
+ return 0;
}
-
diff --git a/target/packages/as_devices/c/as_adc_iio.h b/target/packages/as_devices/c/as_adc_iio.h
index 2ac2fa8..42f516e 100644
--- a/target/packages/as_devices/c/as_adc_iio.h
+++ b/target/packages/as_devices/c/as_adc_iio.h
@@ -46,7 +46,7 @@ struct as_adc_device *as_adc_open_iio(int dev_num, int vref);
* @param channel channel to sample
*/
int32_t as_adc_get_value_in_millivolts_iio(struct as_adc_device *adc,
- int channel);
+ int channel);
/** @brief Close ADC access
*
@@ -56,6 +56,5 @@ int32_t as_adc_close_iio(struct as_adc_device *adc);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
-
-#endif /* __AS_ADC_IIO_H__ */
+#endif /* __cplusplus */
+#endif /* __AS_ADC_IIO_H__ */
diff --git a/target/packages/as_devices/c/as_as1531.c b/target/packages/as_devices/c/as_as1531.c
index 8a83bf4..a673562 100644
--- a/target/packages/as_devices/c/as_as1531.c
+++ b/target/packages/as_devices/c/as_as1531.c
@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
-#include <unistd.h> /* for close() */
+#include <unistd.h> /* for close() */
#define AS_AS1531_MAX_VALUE 2500
#define BUFF_SIZE (300)
@@ -14,73 +14,76 @@
struct as_adc_device *as_adc_open_as1531(int aDeviceNum, int aVRef)
{
- struct as_adc_device *dev;
- int ret;
- int fname;
- char buf[BUFF_SIZE];
+ struct as_adc_device *dev;
+ int ret;
+ int fname;
+ char buf[BUFF_SIZE];
- snprintf(buf, BUFF_SIZE, "/sys/class/hwmon/hwmon%d/device/name", aDeviceNum);
- fname = open(buf, O_RDONLY);
- if (fname < 0) {
- ERROR("Can't open file %s, is as1531 modprobed ?\n", buf);
- return NULL;
- }
+ snprintf(buf, BUFF_SIZE, "/sys/class/hwmon/hwmon%d/device/name",
+ aDeviceNum);
+ fname = open(buf, O_RDONLY);
+ if (fname < 0) {
+ ERROR("Can't open file %s, is as1531 modprobed ?\n", buf);
+ return NULL;
+ }
- ret = read(fname, buf, BUFF_SIZE);
- if (ret <= 0) {
- ERROR("Can't read name\n");
- return NULL;
- }
+ ret = read(fname, buf, BUFF_SIZE);
+ if (ret <= 0) {
+ ERROR("Can't read name\n");
+ return NULL;
+ }
- ret = strncmp(AS_AS1531_NAME, buf, strlen(AS_AS1531_NAME));
- if (ret != 0) {
- ERROR("Wrong driver name %s\n",buf);
- return NULL;
- }
+ ret = strncmp(AS_AS1531_NAME, buf, strlen(AS_AS1531_NAME));
+ if (ret != 0) {
+ ERROR("Wrong driver name %s\n", buf);
+ return NULL;
+ }
- close(fname);
+ close(fname);
- dev = malloc(sizeof(struct as_adc_device));
- if (dev == NULL) {
- ERROR("Can't allocate memory for as_adc structure\n");
- return NULL;
- }
+ dev = malloc(sizeof(struct as_adc_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate memory for as_adc structure\n");
+ return NULL;
+ }
- dev->device_type = AS_AS1531_NAME;
- dev->device_num = aDeviceNum;
- dev->vref = aVRef;
- return dev;
+ dev->device_type = AS_AS1531_NAME;
+ dev->device_num = aDeviceNum;
+ dev->vref = aVRef;
+ return dev;
}
-int32_t as_adc_get_value_in_millivolts_as1531(struct as_adc_device *aDev, int aChannel)
+int32_t as_adc_get_value_in_millivolts_as1531(struct as_adc_device * aDev,
+ int aChannel)
{
- int ret;
- int finput;
- int value;
- char buf[BUFF_SIZE];
+ int ret;
+ int finput;
+ int value;
+ char buf[BUFF_SIZE];
- snprintf(buf, BUFF_SIZE,
- "/sys/class/hwmon/hwmon%d/device/in%d_input",
- aDev->device_num, aChannel);
- finput = open(buf, O_RDONLY);
- if (finput < 0) {
- ERROR("Can't open file %s.\n", buf);
- return -1;
- }
+ snprintf(buf, BUFF_SIZE,
+ "/sys/class/hwmon/hwmon%d/device/in%d_input",
+ aDev->device_num, aChannel);
+ finput = open(buf, O_RDONLY);
+ if (finput < 0) {
+ ERROR("Can't open file %s.\n", buf);
+ return -1;
+ }
- ret = as_read_int(finput, &value);
- if (ret < 0) {
- ERROR("Can't read value on channel %d\n", aChannel);
- return -1;
- }
- close(finput);
+ ret = as_read_int(finput, &value);
+ if (ret < 0) {
+ ERROR("Can't read value on channel %d\n", aChannel);
+ return -1;
+ }
+ close(finput);
- if (AS_AS1531_MAX_VALUE == aDev->vref) return value;
+ if (AS_AS1531_MAX_VALUE == aDev->vref)
+ return value;
- return (value*aDev->vref)/AS_AS1531_MAX_VALUE;
+ return (value * aDev->vref) / AS_AS1531_MAX_VALUE;
}
-int32_t as_adc_close_as1531(struct as_adc_device *aDev)
+int32_t as_adc_close_as1531(struct as_adc_device * aDev)
{
- return 0;
+ return 0;
}
diff --git a/target/packages/as_devices/c/as_as1531.h b/target/packages/as_devices/c/as_as1531.h
index e818b41..743f8dc 100644
--- a/target/packages/as_devices/c/as_as1531.h
+++ b/target/packages/as_devices/c/as_as1531.h
@@ -30,17 +30,18 @@
#ifdef __cplusplus
extern "C" {
-#endif /* __cplusplus */
+#endif /* __cplusplus */
#include "as_adc.h"
struct as_adc_device *as_adc_open_as1531(int aDeviceNum, int aVRef);
-int32_t as_adc_get_value_in_millivolts_as1531(struct as_adc_device *aDev, int aChannel);
+int32_t as_adc_get_value_in_millivolts_as1531(struct as_adc_device
+ *aDev, int aChannel);
int32_t as_adc_close_as1531(struct as_adc_device *aDev);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
-#endif /* __ASAS1531_H__ */
+#endif /* __cplusplus */
+#endif /* __ASAS1531_H__ */
diff --git a/target/packages/as_devices/c/as_backlight.c b/target/packages/as_devices/c/as_backlight.c
index 3eaf036..5216002 100644
--- a/target/packages/as_devices/c/as_backlight.c
+++ b/target/packages/as_devices/c/as_backlight.c
@@ -22,15 +22,14 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
-#include <fcntl.h> /* for open() */
-#include <unistd.h> /* for write() */
+#include <fcntl.h> /* for open() */
+#include <unistd.h> /* for write() */
#include <limits.h>
#define DEBUG
#include "as_helpers.h"
#include "as_backlight.h"
-
#define BACKLIGHT_SYS_PATH "/sys/class/backlight"
#define BACKLIGHT_DEFAULT "imx-bl"
#define ACTUAL_BRIGHTNESS_PATH "actual_brightness"
@@ -41,133 +40,137 @@
struct as_backlight_device *as_backlight_open2(char *aBacklightName)
{
- char buffer[PATH_MAX];
- struct as_backlight_device *dev;
- char *fake_root;
-
- fake_root = as_helpers_get_root();
-
- if (aBacklightName == NULL) {
- aBacklightName = BACKLIGHT_DEFAULT;
- }
-
- dev = (struct as_backlight_device *)malloc(sizeof(struct as_backlight_device));
- if (dev == NULL) {
- ERROR("Can't allocate memory for backlight device structure\n");
- return NULL;
- }
-
- /* open backlight management files */
- snprintf(buffer, sizeof(buffer), "%s%s/%s/%s", fake_root, BACKLIGHT_SYS_PATH,
- aBacklightName, ACTUAL_BRIGHTNESS_PATH);
- if ((dev->fileActualBrightness = open(buffer, O_RDONLY)) < 0) {
- ERROR("Can't open %s file\n", buffer);
- return NULL;
- }
- snprintf(buffer, sizeof(buffer), "%s%s/%s/%s", fake_root, BACKLIGHT_SYS_PATH,
- aBacklightName, MAX_BRIGHTNESS_PATH);
- if ((dev->fileMaxBrightness = open(buffer, O_RDONLY)) < 0) {
- ERROR("Can't open %s file\n", buffer);
- return NULL;
- }
- snprintf(buffer, sizeof(buffer), "%s%s/%s/%s", fake_root, BACKLIGHT_SYS_PATH,
- aBacklightName, BRIGHTNESS_PATH);
- if((dev->fileBrightness = open(buffer, O_RDWR)) < 0) {
- ERROR("Can't open %s file\n", buffer);
- return NULL;
- }
-
- return dev;
+ char buffer[PATH_MAX];
+ struct as_backlight_device *dev;
+ char *fake_root;
+
+ fake_root = as_helpers_get_root();
+
+ if (aBacklightName == NULL) {
+ aBacklightName = BACKLIGHT_DEFAULT;
+ }
+
+ dev =
+ (struct as_backlight_device *)
+ malloc(sizeof(struct as_backlight_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate memory for backlight device structure\n");
+ return NULL;
+ }
+
+ /* open backlight management files */
+ snprintf(buffer, sizeof(buffer), "%s%s/%s/%s", fake_root,
+ BACKLIGHT_SYS_PATH, aBacklightName, ACTUAL_BRIGHTNESS_PATH);
+ if ((dev->fileActualBrightness = open(buffer, O_RDONLY)) < 0) {
+ ERROR("Can't open %s file\n", buffer);
+ return NULL;
+ }
+ snprintf(buffer, sizeof(buffer), "%s%s/%s/%s", fake_root,
+ BACKLIGHT_SYS_PATH, aBacklightName, MAX_BRIGHTNESS_PATH);
+ if ((dev->fileMaxBrightness = open(buffer, O_RDONLY)) < 0) {
+ ERROR("Can't open %s file\n", buffer);
+ return NULL;
+ }
+ snprintf(buffer, sizeof(buffer), "%s%s/%s/%s", fake_root,
+ BACKLIGHT_SYS_PATH, aBacklightName, BRIGHTNESS_PATH);
+ if ((dev->fileBrightness = open(buffer, O_RDWR)) < 0) {
+ ERROR("Can't open %s file\n", buffer);
+ return NULL;
+ }
+
+ return dev;
}
struct as_backlight_device *as_backlight_open()
{
- return as_backlight_open2(NULL);
+ return as_backlight_open2(NULL);
}
/*------------------------------------------------------------------------------*/
-int32_t as_backlight_get_actual_brightness(struct as_backlight_device *aDev)
+int32_t as_backlight_get_actual_brightness(struct as_backlight_device * aDev)
{
- char buffer[32];
- int ret;
-
- if (aDev == NULL) {
- ERROR("Device is NULL\n");
- return -1;
- }
-
- ret = as_read_buffer(aDev->fileActualBrightness, buffer, sizeof(buffer));
- if (ret < 0) {
- ERROR("Can't read actual brightness");
- return ret;
- }
-
- return atoi(buffer);
+ char buffer[32];
+ int ret;
+
+ if (aDev == NULL) {
+ ERROR("Device is NULL\n");
+ return -1;
+ }
+
+ ret =
+ as_read_buffer(aDev->fileActualBrightness, buffer, sizeof(buffer));
+ if (ret < 0) {
+ ERROR("Can't read actual brightness");
+ return ret;
+ }
+
+ return atoi(buffer);
}
/*------------------------------------------------------------------------------*/
-int32_t as_backlight_get_max_brightness(struct as_backlight_device *aDev)
+int32_t as_backlight_get_max_brightness(struct as_backlight_device * aDev)
{
- char buffer[32];
- int ret;
+ char buffer[32];
+ int ret;
- if (aDev == NULL) {
- ERROR("Device is NULL\n");
- return -1;
- }
+ if (aDev == NULL) {
+ ERROR("Device is NULL\n");
+ return -1;
+ }
- ret = as_read_buffer(aDev->fileMaxBrightness, buffer, sizeof(buffer));
- if (ret < 0) {
- ERROR("Can't read max brightness");
- return ret;
- }
+ ret = as_read_buffer(aDev->fileMaxBrightness, buffer, sizeof(buffer));
+ if (ret < 0) {
+ ERROR("Can't read max brightness");
+ return ret;
+ }
- return atoi(buffer);
+ return atoi(buffer);
}
/*------------------------------------------------------------------------------*/
-int32_t as_backlight_set_brightness(struct as_backlight_device *aDev, int aBrightness)
+int32_t as_backlight_set_brightness(struct as_backlight_device * aDev,
+ int aBrightness)
{
- if (aDev == NULL) {
- ERROR("Device is NULL\n");
- return -1;
- }
+ if (aDev == NULL) {
+ ERROR("Device is NULL\n");
+ return -1;
+ }
- return as_write_buffer(aDev->fileBrightness, aBrightness);
+ return as_write_buffer(aDev->fileBrightness, aBrightness);
}
/*------------------------------------------------------------------------------*/
-int32_t as_backlight_close(struct as_backlight_device *aDev)
+int32_t as_backlight_close(struct as_backlight_device * aDev)
{
- int ret = 0;
-
- if (aDev == NULL) {
- ERROR("Device is NULL\n");
- return -1;
- }
-
- /* Close backlight management files */
- ret = close(aDev->fileActualBrightness);
- if (ret < 0) {
- ERROR("Can't close /actual_brightness");
- return ret;
- }
- ret = close(aDev->fileMaxBrightness);
- if (ret < 0) {
- ERROR("Can't close /max_brightness");
- return ret;
- }
- ret = close(aDev->fileBrightness);
- if (ret < 0) {
- ERROR("Can't close /brightness");
- return ret;
- }
-
- free(aDev);
-
- return ret;
+ int ret = 0;
+
+ if (aDev == NULL) {
+ ERROR("Device is NULL\n");
+ return -1;
+ }
+
+ /* Close backlight management files */
+ ret = close(aDev->fileActualBrightness);
+ if (ret < 0) {
+ ERROR("Can't close /actual_brightness");
+ return ret;
+ }
+ ret = close(aDev->fileMaxBrightness);
+ if (ret < 0) {
+ ERROR("Can't close /max_brightness");
+ return ret;
+ }
+ ret = close(aDev->fileBrightness);
+ if (ret < 0) {
+ ERROR("Can't close /brightness");
+ return ret;
+ }
+
+ free(aDev);
+
+ return ret;
}
diff --git a/target/packages/as_devices/c/as_backlight.h b/target/packages/as_devices/c/as_backlight.h
index bf4c3dc..89fa693 100644
--- a/target/packages/as_devices/c/as_backlight.h
+++ b/target/packages/as_devices/c/as_backlight.h
@@ -30,7 +30,7 @@
#ifdef __cplusplus
extern "C" {
-#endif // __cplusplus
+#endif /* __cplusplus */
#include <stdint.h>
@@ -39,9 +39,9 @@ extern "C" {
* @ingroup c_files
*/
struct as_backlight_device {
- int fileActualBrightness; /*!< file descriptor to get current brightness */
- int fileMaxBrightness; /*!< file descriptor to get maximum brightness */
- int fileBrightness; /*!< file descriptor to set brightness */
+ int fileActualBrightness; /*!< file descriptor to get current brightness */
+ int fileMaxBrightness; /*!< file descriptor to get maximum brightness */
+ int fileBrightness; /*!< file descriptor to set brightness */
};
/** @brief Open Backlight device
@@ -64,7 +64,8 @@ struct as_backlight_device *as_backlight_open();
*
* @return actual brightness value, negative value on error
*/
-int32_t as_backlight_get_actual_brightness(struct as_backlight_device *aDev);
+int32_t as_backlight_get_actual_brightness(struct as_backlight_device
+ *aDev);
/** @brief Get maximum brightness
*
@@ -72,7 +73,8 @@ int32_t as_backlight_get_actual_brightness(struct as_backlight_device *aDev);
*
* @return maximum allowed brightness, negative value on error
*/
-int32_t as_backlight_get_max_brightness(struct as_backlight_device *aDev);
+int32_t as_backlight_get_max_brightness(struct as_backlight_device
+ *aDev);
/** @brief Set brightness
*
@@ -81,7 +83,8 @@ int32_t as_backlight_get_max_brightness(struct as_backlight_device *aDev);
*
* @return negative value on error
*/
-int32_t as_backlight_set_brightness(struct as_backlight_device *aDev, int aBrightness);
+int32_t as_backlight_set_brightness(struct as_backlight_device *aDev,
+ int aBrightness);
/** @brief Close backlight device
*
@@ -93,6 +96,5 @@ int32_t as_backlight_close(struct as_backlight_device *aDev);
#ifdef __cplusplus
}
-#endif // __cplusplus
-
-#endif /* __ASBACKLIGHT_H__ */
+#endif /* __cplusplus */
+#endif /* __ASBACKLIGHT_H__ */
diff --git a/target/packages/as_devices/c/as_dac.c b/target/packages/as_devices/c/as_dac.c
index a9a71c2..e24f798 100644
--- a/target/packages/as_devices/c/as_dac.c
+++ b/target/packages/as_devices/c/as_dac.c
@@ -21,7 +21,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
-#include <unistd.h> /* close() */
+#include <unistd.h> /* close() */
#include <string.h>
#include "as_dac.h"
diff --git a/target/packages/as_devices/c/as_dac.h b/target/packages/as_devices/c/as_dac.h
index 4dad9a4..e99c1bf 100644
--- a/target/packages/as_devices/c/as_dac.h
+++ b/target/packages/as_devices/c/as_dac.h
@@ -45,7 +45,7 @@ struct as_dac_device {
int bus_number; /*!< bus number */
int chip_address; /*!< chip address on bus */
int vref; /*!< reference voltage */
- const char *device_type; /*!< device type: "max5821" or "mcp4912" */
+ const char *device_type;/*!< device type: "max5821" or "mcp4912" */
void *chip_param; /*!< private data for chip handler */
};
diff --git a/target/packages/as_devices/c/as_gpio.c b/target/packages/as_devices/c/as_gpio.c
index adea8a0..11eddcd 100644
--- a/target/packages/as_devices/c/as_gpio.c
+++ b/target/packages/as_devices/c/as_gpio.c
@@ -22,7 +22,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
-#include <unistd.h> /* for close() */
+#include <unistd.h> /* for close() */
#include <sys/select.h>
#include <poll.h>
#include <errno.h>
@@ -41,295 +41,299 @@
struct as_gpio_device *as_gpio_open(int aGpioNum)
{
- struct as_gpio_device *dev;
- int pin_file;
- int export_file;
- int retval;
- char buf[BUFF_SIZE];
-
- export_file = open("/sys/class/gpio/export", O_WRONLY);
- if (export_file < 0) {
- ERROR("Can't open /sys/class/gpio/export\nBe sure that gpiolib is under your kernel\n");
- return NULL;
- }
-
- retval = as_write_buffer(export_file, aGpioNum);
- if (retval < 0) {
- ERROR("/sys/class/gpio/export can't be written\n");
- close(export_file);
- return NULL;
- }
- close(export_file);
-
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/value", aGpioNum);
- pin_file = open(buf, O_RDWR);
- if (pin_file < 0) {
- ERROR("Can't export gpio number %d\n", aGpioNum);
- return NULL;
- }
- close(pin_file);
-
- dev = malloc(sizeof(struct as_gpio_device));
- if (dev == NULL) {
- ERROR("Can't allocate as_gpio_device structure\n");
- return NULL;
- }
-
- dev->port_num = aGpioNum;
-
- return dev;
+ struct as_gpio_device *dev;
+ int pin_file;
+ int export_file;
+ int retval;
+ char buf[BUFF_SIZE];
+
+ export_file = open("/sys/class/gpio/export", O_WRONLY);
+ if (export_file < 0) {
+ ERROR
+ ("Can't open /sys/class/gpio/export\nBe sure that gpiolib is under your kernel\n");
+ return NULL;
+ }
+
+ retval = as_write_buffer(export_file, aGpioNum);
+ if (retval < 0) {
+ ERROR("/sys/class/gpio/export can't be written\n");
+ close(export_file);
+ return NULL;
+ }
+ close(export_file);
+
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/value", aGpioNum);
+ pin_file = open(buf, O_RDWR);
+ if (pin_file < 0) {
+ ERROR("Can't export gpio number %d\n", aGpioNum);
+ return NULL;
+ }
+ close(pin_file);
+
+ dev = malloc(sizeof(struct as_gpio_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate as_gpio_device structure\n");
+ return NULL;
+ }
+
+ dev->port_num = aGpioNum;
+
+ return dev;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_pin_direction(struct as_gpio_device *aDev, char *direction)
+int32_t as_gpio_set_pin_direction(struct as_gpio_device * aDev, char *direction)
{
- char buf[BUFF_SIZE];
- int gpio_fd;
- int ret = 0;
-
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return -EINVAL;
- }
-
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/direction", aDev->port_num);
- gpio_fd = open(buf, O_WRONLY);
- if (gpio_fd < 0) {
- ERROR("Can't open gpio%d direction\n", aDev->port_num);
- return -EINVAL;
- }
-
- ret = as_write_buffer_string(gpio_fd, direction);
- if (ret < 0)
- ERROR("Error writing direction\n");
-
- close(gpio_fd);
-
- return ret;
+ char buf[BUFF_SIZE];
+ int gpio_fd;
+ int ret = 0;
+
+ if (aDev == NULL) {
+ ERROR("device is NULL\n");
+ return -EINVAL;
+ }
+
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/direction",
+ aDev->port_num);
+ gpio_fd = open(buf, O_WRONLY);
+ if (gpio_fd < 0) {
+ ERROR("Can't open gpio%d direction\n", aDev->port_num);
+ return -EINVAL;
+ }
+
+ ret = as_write_buffer_string(gpio_fd, direction);
+ if (ret < 0)
+ ERROR("Error writing direction\n");
+
+ close(gpio_fd);
+
+ return ret;
}
/*------------------------------------------------------------------------------*/
-const char* as_gpio_get_pin_direction(struct as_gpio_device *aDev)
+const char *as_gpio_get_pin_direction(struct as_gpio_device *aDev)
{
- char buf[BUFF_SIZE];
- static char direction[4];
- FILE *gpio_file;
- int ret = 0;
- static const char none[] = "??";
-
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return NULL;
- }
-
- snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction",
- aDev->port_num);
- gpio_file = fopen(buf, "r");
- if (!gpio_file) {
- ERROR("Can't open gpio%d direction\n", aDev->port_num);
- return none;
- }
- ret = fscanf(gpio_file, "%s", direction);
- fclose(gpio_file);
- if (ret < 0) {
- ERROR("Can't get gpio%d direction\n", aDev->port_num);
- return none;
- }
-
- return direction;
+ char buf[BUFF_SIZE];
+ static char direction[4];
+ FILE *gpio_file;
+ int ret = 0;
+ static const char none[] = "??";
+
+ if (aDev == NULL) {
+ ERROR("device is NULL\n");
+ return NULL;
+ }
+
+ snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction",
+ aDev->port_num);
+ gpio_file = fopen(buf, "r");
+ if (!gpio_file) {
+ ERROR("Can't open gpio%d direction\n", aDev->port_num);
+ return none;
+ }
+ ret = fscanf(gpio_file, "%s", direction);
+ fclose(gpio_file);
+ if (ret < 0) {
+ ERROR("Can't get gpio%d direction\n", aDev->port_num);
+ return none;
+ }
+
+ return direction;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev, int aValue)
+int32_t as_gpio_set_pin_value(struct as_gpio_device * aDev, int aValue)
{
- char buf[BUFF_SIZE];
- int pin_file;
- int retval;
-
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return -1;
- }
-
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/value", aDev->port_num);
- pin_file = open(buf, O_WRONLY);
- if (pin_file < 0) {
- ERROR("Can't open gpio%d direction\n", aDev->port_num);
- return -1;
- }
-
- retval = as_write_buffer(pin_file, aValue);
- if (retval < 0) {
- ERROR("Can't write value\n");
- close(pin_file);
- return -1;
- }
- close(pin_file);
-
- return aValue;
+ char buf[BUFF_SIZE];
+ int pin_file;
+ int retval;
+
+ if (aDev == NULL) {
+ ERROR("device is NULL\n");
+ return -1;
+ }
+
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/value",
+ aDev->port_num);
+ pin_file = open(buf, O_WRONLY);
+ if (pin_file < 0) {
+ ERROR("Can't open gpio%d direction\n", aDev->port_num);
+ return -1;
+ }
+
+ retval = as_write_buffer(pin_file, aValue);
+ if (retval < 0) {
+ ERROR("Can't write value\n");
+ close(pin_file);
+ return -1;
+ }
+ close(pin_file);
+
+ return aValue;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_pin_value(struct as_gpio_device *aDev)
+int32_t as_gpio_get_pin_value(struct as_gpio_device * aDev)
{
- char buf[BUFF_SIZE];
- int pin_file;
- int retval;
- int value;
-
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return -1;
- }
-
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/value", aDev->port_num);
- pin_file = open(buf, O_RDONLY);
- if (pin_file < 0) {
- ERROR("Can't open gpio%d value\n", aDev->port_num);
- return -1;
- }
-
- retval = as_read_int(pin_file, &value);
- if (retval < 0) {
- ERROR("Can't read value\n");
- close(pin_file);
- return -1;
- }
- close(pin_file);
-
- return value;
+ char buf[BUFF_SIZE];
+ int pin_file;
+ int retval;
+ int value;
+
+ if (aDev == NULL) {
+ ERROR("device is NULL\n");
+ return -1;
+ }
+
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/value",
+ aDev->port_num);
+ pin_file = open(buf, O_RDONLY);
+ if (pin_file < 0) {
+ ERROR("Can't open gpio%d value\n", aDev->port_num);
+ return -1;
+ }
+
+ retval = as_read_int(pin_file, &value);
+ if (retval < 0) {
+ ERROR("Can't read value\n");
+ close(pin_file);
+ return -1;
+ }
+ close(pin_file);
+
+ return value;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_wait_event(struct as_gpio_device *aDev, int delay_ms)
+int32_t as_gpio_wait_event(struct as_gpio_device * aDev, int delay_ms)
{
- char gpio_sys_name[BUFF_SIZE];
- int gpio_fd;
- struct pollfd poll_set[1];
- int ret;
- char tmp[16];
-
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return -EINVAL;
- }
-
- snprintf(gpio_sys_name, BUFF_SIZE, "/sys/class/gpio/gpio%d/value",
- aDev->port_num);
- gpio_fd = open(gpio_sys_name, O_RDONLY);
- if (gpio_fd < 0) {
- ERROR("Can't open gpio%d value\n", aDev->port_num);
- return -EINVAL;
- }
-
- /* flush pending event */
- read(gpio_fd, tmp, sizeof(tmp));
-
- poll_set[0].fd = gpio_fd;
- poll_set[0].events = POLLPRI;
- poll_set[0].revents = 0;
- ret = poll(poll_set, 1, delay_ms);
- if (ret > 0) {
- ret = read(gpio_fd, tmp, sizeof(tmp));
- close(gpio_fd);
- return ret;
- } else if (ret < 0) {
- ERROR("poll()");
- close(gpio_fd);
- return ret;
- }
-
- /* if ret=0 it's a timeout */
- close(gpio_fd);
- return -ETIMEDOUT;
+ char gpio_sys_name[BUFF_SIZE];
+ int gpio_fd;
+ struct pollfd poll_set[1];
+ int ret;
+ char tmp[16];
+
+ if (aDev == NULL) {
+ ERROR("device is NULL\n");
+ return -EINVAL;
+ }
+
+ snprintf(gpio_sys_name, BUFF_SIZE, "/sys/class/gpio/gpio%d/value",
+ aDev->port_num);
+ gpio_fd = open(gpio_sys_name, O_RDONLY);
+ if (gpio_fd < 0) {
+ ERROR("Can't open gpio%d value\n", aDev->port_num);
+ return -EINVAL;
+ }
+
+ /* flush pending event */
+ read(gpio_fd, tmp, sizeof(tmp));
+
+ poll_set[0].fd = gpio_fd;
+ poll_set[0].events = POLLPRI;
+ poll_set[0].revents = 0;
+ ret = poll(poll_set, 1, delay_ms);
+ if (ret > 0) {
+ ret = read(gpio_fd, tmp, sizeof(tmp));
+ close(gpio_fd);
+ return ret;
+ } else if (ret < 0) {
+ ERROR("poll()");
+ close(gpio_fd);
+ return ret;
+ }
+
+ /* if ret=0 it's a timeout */
+ close(gpio_fd);
+ return -ETIMEDOUT;
}
/*------------------------------------------------------------------------------*/
-const char* as_gpio_get_irq_mode(struct as_gpio_device *aDev)
+const char *as_gpio_get_irq_mode(struct as_gpio_device *aDev)
{
- char buf[BUFF_SIZE];
- static char mode[8];
- FILE *gpio_file;
- int ret = 0;
- static const char unknown[] = "??";
-
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return unknown;
- }
-
- snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/edge", aDev->port_num);
- gpio_file = fopen(buf, "r");
- if (!gpio_file) {
- ERROR("Can't open gpio%d edge\n", aDev->port_num);
- return unknown;
- }
- ret = fscanf(gpio_file, "%s", mode);
- fclose(gpio_file);
- if (ret < 0) {
- ERROR("Can't get gpio%d edge\n", aDev->port_num);
- return unknown;
- }
-
- return mode;
+ char buf[BUFF_SIZE];
+ static char mode[8];
+ FILE *gpio_file;
+ int ret = 0;
+ static const char unknown[] = "??";
+
+ if (aDev == NULL) {
+ ERROR("device is NULL\n");
+ return unknown;
+ }
+
+ snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/edge",
+ aDev->port_num);
+ gpio_file = fopen(buf, "r");
+ if (!gpio_file) {
+ ERROR("Can't open gpio%d edge\n", aDev->port_num);
+ return unknown;
+ }
+ ret = fscanf(gpio_file, "%s", mode);
+ fclose(gpio_file);
+ if (ret < 0) {
+ ERROR("Can't get gpio%d edge\n", aDev->port_num);
+ return unknown;
+ }
+
+ return mode;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_irq_mode(struct as_gpio_device *aDev, char *mode)
+int32_t as_gpio_set_irq_mode(struct as_gpio_device * aDev, char *mode)
{
- char buf[BUFF_SIZE];
- int gpio_fd;
- int ret = 0;
+ char buf[BUFF_SIZE];
+ int gpio_fd;
+ int ret = 0;
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return -EINVAL;
- }
+ if (aDev == NULL) {
+ ERROR("device is NULL\n");
+ return -EINVAL;
+ }
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/edge", aDev->port_num);
- gpio_fd = open(buf, O_WRONLY);
- if (gpio_fd < 0) {
- ERROR("Can't open gpio%d edge\n", aDev->port_num);
- return -EINVAL;
- }
+ snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%d/edge", aDev->port_num);
+ gpio_fd = open(buf, O_WRONLY);
+ if (gpio_fd < 0) {
+ ERROR("Can't open gpio%d edge\n", aDev->port_num);
+ return -EINVAL;
+ }
- ret = as_write_buffer_string(gpio_fd, mode);
- if (ret < 0)
- ERROR("Error writing mode\n");
+ ret = as_write_buffer_string(gpio_fd, mode);
+ if (ret < 0)
+ ERROR("Error writing mode\n");
- close(gpio_fd);
+ close(gpio_fd);
- return ret;
+ return ret;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_pin_num(struct as_gpio_device *aDev)
+int32_t as_gpio_get_pin_num(struct as_gpio_device * aDev)
{
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return -1;
- }
+ if (aDev == NULL) {
+ ERROR("device is NULL\n");
+ return -1;
+ }
- return aDev->port_num;
+ return aDev->port_num;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_close(struct as_gpio_device *aDev)
+int32_t as_gpio_close(struct as_gpio_device * aDev)
{
- if(aDev == NULL){
- ERROR("device is NULL\n");
- return -1;
- }
+ if (aDev == NULL) {
+ ERROR("device is NULL\n");
+ return -1;
+ }
- return 0;
+ return 0;
}
-
diff --git a/target/packages/as_devices/c/as_gpio.h b/target/packages/as_devices/c/as_gpio.h
index a6a5d4f..594fb2b 100644
--- a/target/packages/as_devices/c/as_gpio.h
+++ b/target/packages/as_devices/c/as_gpio.h
@@ -32,7 +32,7 @@
#ifdef __cplusplus
extern "C" {
-#endif /* __cplusplus */
+#endif /* __cplusplus */
#define GPIO_IRQ_MODE_NOINT "none"
#define GPIO_IRQ_MODE_RISING "rising"
@@ -47,10 +47,10 @@ extern "C" {
* @ingroup c_files
*/
struct as_gpio_device {
- int port_num;
- int pin_number;
- int fpin; /* pin file for 2.6.29 interface*/
- int irq_mode;
+ int port_num;
+ int pin_number;
+ int fpin; /* pin file for 2.6.29 interface */
+ int irq_mode;
};
/** @brief Initialize port access
@@ -69,7 +69,7 @@ struct as_gpio_device *as_gpio_open(int aGpioNum);
* @return error if negative value
*/
int32_t as_gpio_set_pin_direction(struct as_gpio_device *gpio_dev,
- char *direction);
+ char *direction);
/** @brief Get pin direction
*
@@ -77,7 +77,7 @@ int32_t as_gpio_set_pin_direction(struct as_gpio_device *gpio_dev,
*
* @return error if negative value
*/
-const char* as_gpio_get_pin_direction(struct as_gpio_device *gpio_dev);
+const char *as_gpio_get_pin_direction(struct as_gpio_device *gpio_dev);
/** @brief Set pin value
*
@@ -86,8 +86,7 @@ const char* as_gpio_get_pin_direction(struct as_gpio_device *gpio_dev);
*
* @return error if negative
*/
-int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev,
- int aValue);
+int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev, int aValue);
/** @brief Get pin value
*
@@ -115,7 +114,8 @@ int32_t as_gpio_wait_event(struct as_gpio_device *aDev, int aDelay_ms);
*
* @return error if negative
*/
-int32_t as_gpio_set_irq_mode(struct as_gpio_device *gpio_dev, char *mode);
+int32_t as_gpio_set_irq_mode(struct as_gpio_device *gpio_dev,
+ char *mode);
/** @brief Get pin irq mode value
*
@@ -123,7 +123,7 @@ int32_t as_gpio_set_irq_mode(struct as_gpio_device *gpio_dev, char *mode);
*
* @return pin triggering mode: (rising/falling/both/none)
*/
-const char* as_gpio_get_irq_mode(struct as_gpio_device *gpio_dev);
+const char *as_gpio_get_irq_mode(struct as_gpio_device *gpio_dev);
/** @brief Get pin number value
*
@@ -143,6 +143,5 @@ int32_t as_gpio_close(struct as_gpio_device *aDev);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
-
-#endif /* __ASGPIO_H__ */
+#endif /* __cplusplus */
+#endif /* __ASGPIO_H__ */
diff --git a/target/packages/as_devices/c/as_gpio_2_6_29.c b/target/packages/as_devices/c/as_gpio_2_6_29.c
index 3c1702a..56bf379 100644
--- a/target/packages/as_devices/c/as_gpio_2_6_29.c
+++ b/target/packages/as_devices/c/as_gpio_2_6_29.c
@@ -22,7 +22,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
-#include <unistd.h> /* for close() */
+#include <unistd.h> /* for close() */
#include <sys/select.h>
#include <sys/ioctl.h>
@@ -50,7 +50,6 @@
#define GPIORDIRQMODE _IOR(PP_IOCTL, 0xF8, int)
#define GPIOWRIRQMODE _IOW(PP_IOCTL, 0xF9, int)
-
#define GPIO_BASE_PIN ("/dev/gpio/P")
#define BUFF_SIZE (300)
@@ -59,234 +58,233 @@
struct as_gpio_device *as_gpio_open(int aGpioNum)
{
- char aPortChar;
- int aPinNum;
-
- struct as_gpio_device *dev;
- char gpio_file_path[50];
- int ret = 0;
- int file;
- int value;
-
- aPortChar = (aGpioNum/32) + 'A';
- aPinNum = aGpioNum - (aPortChar-'A');
-
- /* make gpio port string path */
- ret = snprintf(gpio_file_path,50, "%s%c%d",
- GPIO_BASE_PIN, aPortChar, aPinNum);
- if (ret < 0) {
- ERROR("Can't forge gpio pin port path\n");
- goto path_error;
- }
-
- /* opening gpio port */
- file = open(gpio_file_path, O_RDWR);
- if (file < 0) {
- ERROR("Can't open file pin port\n");
- goto open_file_error;
- }
-
- dev = (struct as_gpio_device *)malloc(sizeof(struct as_gpio_device));
- if (dev == NULL) {
- ERROR("Can't allocate memory for gpio device structure\n");
- goto malloc_error;
- }
-
- dev->port_letter = aPortChar;
- dev->fpin = file;
- dev->pin_number = aPinNum;
-
- value = 1;
- ret = ioctl(dev->fpin, GPIOWRMODE, &value); /* set pin on gpio mode */
- if (ret < 0) {
- ERROR("can't set pin in gpio mode.\n");
- goto mode_error;
- }
-
- return dev;
+ char aPortChar;
+ int aPinNum;
+
+ struct as_gpio_device *dev;
+ char gpio_file_path[50];
+ int ret = 0;
+ int file;
+ int value;
+
+ aPortChar = (aGpioNum / 32) + 'A';
+ aPinNum = aGpioNum - (aPortChar - 'A');
+
+ /* make gpio port string path */
+ ret = snprintf(gpio_file_path, 50, "%s%c%d",
+ GPIO_BASE_PIN, aPortChar, aPinNum);
+ if (ret < 0) {
+ ERROR("Can't forge gpio pin port path\n");
+ goto path_error;
+ }
+
+ /* opening gpio port */
+ file = open(gpio_file_path, O_RDWR);
+ if (file < 0) {
+ ERROR("Can't open file pin port\n");
+ goto open_file_error;
+ }
+
+ dev = (struct as_gpio_device *)malloc(sizeof(struct as_gpio_device));
+ if (dev == NULL) {
+ ERROR("Can't allocate memory for gpio device structure\n");
+ goto malloc_error;
+ }
+
+ dev->port_letter = aPortChar;
+ dev->fpin = file;
+ dev->pin_number = aPinNum;
+
+ value = 1;
+ ret = ioctl(dev->fpin, GPIOWRMODE, &value); /* set pin on gpio mode */
+ if (ret < 0) {
+ ERROR("can't set pin in gpio mode.\n");
+ goto mode_error;
+ }
+
+ return dev;
mode_error:
- free(dev);
+ free(dev);
malloc_error:
- close(file);
+ close(file);
open_file_error:
path_error:
- return NULL;
+ return NULL;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_pin_direction(struct as_gpio_device *aDev, int aDirection)
+int32_t as_gpio_set_pin_direction(struct as_gpio_device * aDev, int aDirection)
{
- int ret = 0;
- int portval;
+ int ret = 0;
+ int portval;
- portval = (aDirection != 0) ? 1 : 0;
+ portval = (aDirection != 0) ? 1 : 0;
- ret = ioctl(aDev->fpin, GPIOWRDIRECTION, &portval);
- if (ret < 0) {
- ERROR("Can't set gpio direction\n");
- return ret;
- }
- return 0;
+ ret = ioctl(aDev->fpin, GPIOWRDIRECTION, &portval);
+ if (ret < 0) {
+ ERROR("Can't set gpio direction\n");
+ return ret;
+ }
+ return 0;
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_get_pin_direction(struct as_gpio_device *aDev)
+int32_t as_gpio_get_pin_direction(struct as_gpio_device * aDev)
{
- int ret = 0;
- int portval;
-
- ret = ioctl(aDev->fpin, GPIORDDIRECTION, &portval);
- if (ret < 0) {
- ERROR("Can't get gpio direction\n");
- return ret;
- }
- return ((portval !=0) ? 1 : 0);
+ int ret = 0;
+ int portval;
+
+ ret = ioctl(aDev->fpin, GPIORDDIRECTION, &portval);
+ if (ret < 0) {
+ ERROR("Can't get gpio direction\n");
+ return ret;
+ }
+ return ((portval != 0) ? 1 : 0);
}
/*------------------------------------------------------------------------------*/
-int32_t as_gpio_set_pin_value(struct as_gpio_device *aDev, int aValue)
+int32_t as_gpio_set_pin_value(struct a...
[truncated message content] |