[Armadeus-commitlog] armadeus branch, master, updated. release-3.2-386-g0d09b77
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2010-06-01 16:24:59
|
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 0d09b77c52240b28b6a22a235430b609e89db8b6 (commit)
via 2cd0ecad691781639553cf29e703fb9a7f07ae1c (commit)
from 95f34287181f89e0db2890b5bb92a16422c7ca1a (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 0d09b77c52240b28b6a22a235430b609e89db8b6
Merge: 2cd0ecad691781639553cf29e703fb9a7f07ae1c 95f34287181f89e0db2890b5bb92a16422c7ca1a
Author: Fabien Marteau <fab...@ar...>
Date: Tue Jun 1 18:24:01 2010 +0200
Merge branch 'master' of git://armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit 2cd0ecad691781639553cf29e703fb9a7f07ae1c
Author: Fabien Marteau <fab...@ar...>
Date: Tue Jun 1 18:23:52 2010 +0200
[as_devices] adding Digital to Analog Chip as_max5821, not fully tested
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/c/Makefile | 1 +
target/packages/as_devices/c/as_i2c.h | 10 +--
target/packages/as_devices/c/as_max5821.c | 159 +++++++++++++++++++++++++++++
target/packages/as_devices/c/as_max5821.h | 100 ++++++++++++++++++
target/packages/as_devices/main.c | 2 +
target/packages/as_devices/test_c.h | 107 +++++++++++++++++++
6 files changed, 372 insertions(+), 7 deletions(-)
create mode 100644 target/packages/as_devices/c/as_max5821.c
create mode 100644 target/packages/as_devices/c/as_max5821.h
diff --git a/target/packages/as_devices/c/Makefile b/target/packages/as_devices/c/Makefile
index bf59fa8..e8c5e9d 100644
--- a/target/packages/as_devices/c/Makefile
+++ b/target/packages/as_devices/c/Makefile
@@ -26,6 +26,7 @@ OBJ+= as_gpio.o
OBJ+= as_93lcxx.o
OBJ+= as_spi.o
OBJ+= as_max1027.o
+OBJ+= as_max5821.o
LIBRARY=as_devices
LIB_VERS=1
diff --git a/target/packages/as_devices/c/as_i2c.h b/target/packages/as_devices/c/as_i2c.h
index e6ea0cb..8f967b4 100644
--- a/target/packages/as_devices/c/as_i2c.h
+++ b/target/packages/as_devices/c/as_i2c.h
@@ -3,12 +3,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -46,7 +46,7 @@ extern "C" {
/** @brief Open an I2C bus.
*
- * \e i2c_id is the ID of the I2C bus to open, it should strictly lower than
+ * \e i2c_id is the ID of the I2C bus to open, it should be strictly lower than
* \e AS_I2C_DEV_COUNT.
*
* @return the file descriptor of the opened device, -1 on error.
@@ -67,7 +67,6 @@ int as_i2c_close(int fd);
*/
int as_i2c_set_slave(int fd, uint8_t addr);
-
/** @brief Read several bytes.
*
* @return 0 on success, -1 on error.
@@ -80,7 +79,6 @@ int as_i2c_read(int fd, uint8_t addr, uint8_t *data, size_t n);
*/
int as_i2c_write(int fd, uint8_t addr, const uint8_t *data, size_t n);
-
/** @brief Read at a given register address.
*
* Send the \e reg byte, then read bytes.
@@ -97,7 +95,6 @@ int as_i2c_read_reg(int fd, uint8_t addr, uint8_t reg, uint8_t *data, size_t n);
*/
int as_i2c_write_reg(int fd, uint8_t addr, uint8_t reg, const uint8_t *data, size_t n);
-
/** @brief Read a given register byte.
*
* Send the \e reg byte, then read and return a single byte.
@@ -119,7 +116,6 @@ int as_i2c_read_reg_byte(int fd, uint8_t addr, uint8_t reg);
*/
int as_i2c_write_reg_byte(int fd, uint8_t addr, uint8_t reg, uint8_t val);
-
#ifdef __cplusplus
}
#endif // __cplusplus
diff --git a/target/packages/as_devices/c/as_max5821.c b/target/packages/as_devices/c/as_max5821.c
new file mode 100644
index 0000000..ce11c06
--- /dev/null
+++ b/target/packages/as_devices/c/as_max5821.c
@@ -0,0 +1,159 @@
+/*
+ * This software is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *
+ * Copyright (C) 2010 Fabien Marteau <fab...@ar...>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "as_max5821.h"
+#include "as_i2c.h"
+
+
+/* command bytes */
+#define MAX5821_UPDATE_ALL_DAC_COMMAND (0xE0)
+#define MAX5821_EXTENDED_COMMAND_MODE (0xF0)
+
+#define MAX5821_POWER_CTRL_SELECTED (0x1)
+#define MAX5821_POWER_CTRL_UNSELECTED (0x0)
+
+#define MAX5821M_MAX_DATA_VALUE (1023)
+
+//#define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
+#define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
+
+/*-----------------------------------------------------------------------------*/
+
+struct as_max5821_device *as_max5821_open(int aI2cBus, int aI2cAddress)
+{
+ struct as_max5821_device *dev;
+
+ dev = (struct as_max5821_device *)malloc(sizeof(struct as_max5821_device));
+ if (dev == NULL)
+ {
+ ERROR("can't allocate memory for device structure\n");
+ return NULL;
+ }
+
+ dev->i2c_bus = as_i2c_open(aI2cBus);
+ if (dev->i2c_bus < 0)
+ {
+ ERROR("Can't open i2c bus number %d\n",aI2cBus);
+ free(dev);
+ return NULL;
+ }
+
+ dev->i2c_address = aI2cAddress;
+
+ return dev;
+}
+
+/*-----------------------------------------------------------------------------*/
+
+int32_t as_max5821_power(struct as_max5821_device *aDev,
+ char aChannel,
+ AS_max5821_power_mode aMode)
+{
+ int ret;
+ unsigned char buff[2];
+
+ switch(aChannel)
+ {
+ case 'a':
+ case 'A': buff[1] = (1<<2) | aMode;
+ break;
+ case 'b':
+ case 'B': buff[1] = (1<<3) | aMode;
+ break;
+ default: ERROR("Wrong channel name %c\n", aChannel);
+ return -1;
+ }
+
+ buff[0] = MAX5821_EXTENDED_COMMAND_MODE;
+
+ ret = as_i2c_write(aDev->i2c_bus, aDev->i2c_address, buff, 2);
+ if (ret < 0) {
+ ERROR("can't write on i2c bus %d, address %d, value %x %x\n",
+ aDev->i2c_bus,aDev->i2c_address,buff[0], buff[1]);
+ return -1;
+ }
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------------------*/
+
+int32_t as_max5821_set_one_value(struct as_max5821_device *aDev,
+ char aChannel,
+ int aValue)
+{
+ int ret;
+ unsigned char buff[2];
+
+ switch(aChannel)
+ {
+ case 'a':
+ case 'A': buff[0] = (aValue >> 8) & 0x0F;
+ break;
+ case 'b':
+ case 'B': buff[0] = 0x10 | ((aValue >> 8) & 0x0F);
+ break;
+ default: ERROR("Wrong channel name %c\n", aChannel);
+ return -1;
+ }
+
+ buff[1] =(unsigned char)(aValue & 0x00FF);
+
+ ret = as_i2c_write(aDev->i2c_bus, aDev->i2c_address, buff, 2);
+ if (ret < 0) {
+ ERROR("can't write on i2c bus\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------------------*/
+
+int32_t as_max5821_set_both_value(struct as_max5821_device *aDev,
+ int aValue)
+{
+ int ret;
+ unsigned char buff[2];
+
+ buff[0] = 0xC0 | ((unsigned char)((aValue >> 8)) & 0x0F);
+ buff[1] = (unsigned char)(aValue & 0x00FF);
+
+ ret = as_i2c_write(aDev->i2c_bus, aDev->i2c_address, buff, 2);
+ if (ret < 0) {
+ ERROR("can't write on i2c bus\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*-----------------------------------------------------------------------------*/
+
+int32_t as_max5821_close(struct as_max5821_device *aDev)
+{
+ as_i2c_close(aDev->i2c_bus);
+ free(aDev);
+ return 0;
+}
+
diff --git a/target/packages/as_devices/c/as_max5821.h b/target/packages/as_devices/c/as_max5821.h
new file mode 100644
index 0000000..580d1bc
--- /dev/null
+++ b/target/packages/as_devices/c/as_max5821.h
@@ -0,0 +1,100 @@
+/*
+ * This software is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *
+ * Copyright (C) 2010 Fabien Marteau <fab...@ar...>
+ *
+ */
+
+#ifndef AS_MAX5821_H_
+#define AS_MAX5821_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "as_i2c.h"
+
+/**
+ * Store max5821 parameters
+ */
+struct as_max5821_device {
+ int i2c_bus;
+ int i2c_address;
+};
+
+typedef enum {
+ MAX5821_POWER_UP = 0,
+ MAX5821_POWER_DOWN_MODE0,
+ MAX5821_POWER_DOWN_MODE1,
+ MAX5821_POWER_DOWN_MODE2
+} AS_max5821_power_mode;
+
+/** @brief Open max5821
+ *
+ * @param aI2cBus i2c bus number
+ * @param aI2cAddress i2c chip address
+ *
+ * @return as_max5821_device structure on success, NULL on error
+ */
+struct as_max5821_device *as_max5821_open(int aI2cBus, int aI2cAddress);
+
+/** @brief Power a channel
+ *
+ * @param aDev pointer to device structure
+ * @param aChannel caracter to channel
+ * @param aPowerCmd power command
+ *
+ * @return negative value on header.
+ */
+int32_t as_max5821_power(struct as_max5821_device *aDev,
+ char aChannel,
+ AS_max5821_power_mode aMode);
+
+/** @brief set output value
+ *
+ * @param aDev pointer to device structure
+ * @param aChannel caracter to channel
+ * @param aValue value between 0 and 1023
+ *
+ * @return negative value on error.
+ */
+int32_t as_max5821_set_one_value(struct as_max5821_device *aDev,
+ char aChannel,
+ int aValue);
+
+/** @brief set both output value
+ *
+ * @param aDev pointer to device structure
+ * @param aValue value between 0 and 1023
+ *
+ * @return negative value on error
+ */
+int32_t as_max5821_set_both_value(struct as_max5821_device *aDev,
+ int aValue);
+
+/** @brief Close max5821
+ *
+ * @param aDev structure device pointer
+ *
+ * @return negative value on error
+ */
+int32_t as_max5821_close(struct as_max5821_device *aDev);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* AS_MAX5821_H_ */
diff --git a/target/packages/as_devices/main.c b/target/packages/as_devices/main.c
index f261c14..b0e4fd5 100644
--- a/target/packages/as_devices/main.c
+++ b/target/packages/as_devices/main.c
@@ -43,6 +43,7 @@ int main(int argc, char ** argv)
printf(" 4) Testing 93LCxx eprom\n");
printf(" 5) Testing gpio\n");
printf(" 6) Testing max1027\n");
+ printf(" 7) Testing max5821\n");
printf("> ");
scanf("%s",buffer);
@@ -60,6 +61,7 @@ int main(int argc, char ** argv)
break;
case '6' : test_max1027();
break;
+ case '7' : test_max5821();
default : break;
}
diff --git a/target/packages/as_devices/test_c.h b/target/packages/as_devices/test_c.h
index d864b5f..049ad08 100644
--- a/target/packages/as_devices/test_c.h
+++ b/target/packages/as_devices/test_c.h
@@ -28,6 +28,7 @@
#include "as_i2c.h"
#include "as_gpio.h"
#include "as_max1027.h"
+#include "as_max5821.h"
#define PWM_NUM 0
@@ -766,4 +767,110 @@ void test_max1027()
}
}
+void test_max5821()
+{
+ char buffer[50];
+ int ret;
+ int value;
+ struct as_max5821_device *max5821_dev;
+ int channelA=0;
+ int channelB=0;
+
+
+ max5821_dev = as_max5821_open(0, 0x38);
+ if (max5821_dev == NULL)
+ {
+ printf("Error, can't open max5821.\n");
+ pressEnterToContinue();
+ return ;
+ }
+ pressEnterToContinue();
+
+ while(buffer[0] != 'q')
+ {
+ system("clear");
+ printf("**************************\n");
+ printf(" Testing max5821 *\n");
+ printf("**************************\n");
+ printf("Choose ('q' to quit):\n");
+ printf(" 1) select power mode for channel A\n");
+ printf(" 2) select power mode for channel B\n");
+ printf(" 3) select channel A value %d\n", channelA);
+ printf(" 4) select channel B value %d\n", channelB);
+ printf(" 5) select both channel values\n");
+
+ printf("> ");
+ scanf("%s",buffer);
+
+ switch(buffer[0])
+ {
+ case '1' : printf("Choose your mode:\n");
+ printf(" 0) MAX5821_POWER_UP \n");
+ printf(" 1) MAX5821_POWER_DOWN_MODE0\n");
+ printf(" 2) MAX5821_POWER_DOWN_MODE1\n");
+ printf(" 3) MAX5821_POWER_DOWN_MODE2\n");
+ printf("> ");
+ scanf("%d", &value);
+ ret = as_max5821_power(max5821_dev, 'a', value);
+ if (ret < 0)
+ {
+ printf("Error, can't select power mode\n");
+ }
+ pressEnterToContinue();
+ break;
+ case '2' : printf("Choose your mode:\n");
+ printf(" 0) MAX5821_POWER_UP \n");
+ printf(" 1) MAX5821_POWER_DOWN_MODE0\n");
+ printf(" 2) MAX5821_POWER_DOWN_MODE1\n");
+ printf(" 3) MAX5821_POWER_DOWN_MODE2\n");
+ printf("> ");
+ scanf("%d", &value);
+ ret = as_max5821_power(max5821_dev, 'b', value);
+ if (ret < 0)
+ {
+ printf("Error, can't select power mode\n");
+ }
+ pressEnterToContinue();
+ break;
+ case '3' : printf("Give value between 0-1023\n");
+ printf("> ");
+ scanf("%d", &value);
+ ret = as_max5821_set_one_value(max5821_dev, 'a', value);
+ if (ret < 0)
+ {
+ printf("Error, can't select value\n");
+ }
+ pressEnterToContinue();
+ break;
+ case '4' : printf("Give value between 0-1023\n");
+ printf("> ");
+ scanf("%d", &value);
+ ret = as_max5821_set_one_value(max5821_dev, 'b', value);
+ if (ret < 0)
+ {
+ printf("Error, can't select value\n");
+ }
+ pressEnterToContinue();
+ break;
+ case '5' : printf("Give value between 0-1023\n");
+ printf("> ");
+ scanf("%d", &value);
+ ret = as_max5821_set_both_value(max5821_dev, value);
+ if (ret < 0)
+ {
+ printf("Error, can't select value\n");
+ }
+ pressEnterToContinue();
+ break;
+ default : break;
+ }
+ }
+
+ ret = as_max5821_close(max5821_dev);
+ if (ret < 0) {
+ printf("Error on closing max5821_dev\n");
+ pressEnterToContinue();
+ }
+}
+
hooks/post-receive
--
armadeus
|