From 61e71aad8571ec108e00df46983f5c3252c32e7c Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 29 Aug 2011 23:06:54 +0000 Subject: More I2C tool logic git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3924 42af7a65-404d-4744-a932-0658087f49c3 --- apps/system/i2c/i2ctool.h | 91 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 13 deletions(-) (limited to 'apps/system/i2c/i2ctool.h') diff --git a/apps/system/i2c/i2ctool.h b/apps/system/i2c/i2ctool.h index 36726c7dc..dde1b7a13 100644 --- a/apps/system/i2c/i2ctool.h +++ b/apps/system/i2c/i2ctool.h @@ -52,8 +52,30 @@ /**************************************************************************** * Definitions ****************************************************************************/ +/* Configuration ************************************************************/ +#ifndef CONFIG_I2CTOOL_MINBUS +# define CONFIG_I2CTOOL_MINBUS 0 +#endif + +#ifndef CONFIG_I2CTOOL_MAXBUS +# define CONFIG_I2CTOOL_MAXBUS 3 +#endif -/* This is the maximum number of arguments that will be accepted for a command */ +#ifndef CONFIG_I2CTOOL_MINADDR +# define CONFIG_I2CTOOL_MINADDR 0x03 +#endif + +#ifndef CONFIG_I2CTOOL_MAXADDR +# define CONFIG_I2CTOOL_MAXADDR 0x77 +#endif + +#ifndef CONFIG_I2CTOOL_MAXREGADDR +# define CONFIG_I2CTOOL_MAXREGADDR 0xff +#endif + +/* This is the maximum number of arguments that will be accepted for a + * command + */ #define MAX_ARGUMENTS 6 @@ -61,6 +83,24 @@ #define MAX_LINELEN 80 +/* Are we using the NuttX console for I/O? Or some other character device? */ + +#ifdef CONFIG_I2CTOOL_INDEV +# define INFD(p) ((p)->ss_infd) +# define INSTREAM(p) ((p)->ss_instream) +#else +# define INFD(p) 0 +# define INSTREAM(p) stdin +#endif + +#ifdef CONFIG_I2CTOOL_OUTDEV +# define OUTFD(p) ((p)->ss_outfd) +# define OUTSTREAM(p) ((p)->ss_outstream) +#else +# define OUTFD(p) 1 +# define OUTSTREAM(p) stdout +#endif + /* Output is via printf but can be changed using this macro */ #ifdef CONFIG_CPP_HAVE_VARARGS @@ -73,15 +113,32 @@ * Public Types ****************************************************************************/ -typedef int (*cmd_t)(FAR void *handle, int argc, char **argv); +struct i2ctool_s +{ + /* Sticky options */ + + uint8_t addr; /* [-a addr] is the I2C device address */ + uint8_t bus; /* [-b bus] is the I2C bus number */ + uint8_t regaddr; /* [-r regaddr] is the I2C device register address */ + uint8_t width; /* [-w width] is the data width (8 or 16) */ + bool start; /* [-s|n], send/don't send start between command and data */ + + /* Output streams */ + +#ifdef CONFIG_I2CTOOL_OUTDEV + int ss_outfd; /* Output file descriptor */ + FILE *ss_outstream; /* Output stream */ +#endif +}; + +typedef int (*cmd_t)(FAR struct i2ctool_s *i2ctool, int argc, char **argv); struct cmdmap_s { - const char *cmd; /* Name of the command */ - cmd_t handler; /* Function that handles the command */ - uint8_t minargs; /* Minimum number of arguments (including command) */ - uint8_t maxargs; /* Maximum number of arguments (including command) */ - const char *usage; /* Usage instructions for 'help' command */ + FAR const char *cmd; /* Name of the command */ + cmd_t handler; /* Function that handles the command */ + FAR const char *desc; /* Short description */ + FAR const char *usage; /* Usage instructions for 'help' command */ }; /**************************************************************************** @@ -105,14 +162,22 @@ extern const char g_fmtinternalerror[]; /* Message handler */ -ssize_t i2ctool_write(FAR void *handle, FAR const void *buffer, size_t nbytes); -int i2ctool_printf(FAR void *handle, const char *fmt, ...); +ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, size_t nbytes); +int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...); /* Command handlers */ -extern int cmd_detect(FAR void *handle, int argc, char **argv); -extern int cmd_dump(FAR void *handle, int argc, char **argv); -extern int cmd_get(FAR void *handle, int argc, char **argv); -extern int cmd_set(FAR void *handle, int argc, char **argv); +int cmd_bus(FAR struct i2ctool_s *i2ctool, int argc, char **argv); +int cmd_dev(FAR struct i2ctool_s *i2ctool, int argc, char **argv); +int cmd_dump(FAR struct i2ctool_s *i2ctool, int argc, char **argv); +int cmd_get(FAR struct i2ctool_s *i2ctool, int argc, char **argv); +int cmd_set(FAR struct i2ctool_s *i2ctool, int argc, char **argv); + +/* Common logic */ + +int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg); +int arg_string(FAR char **arg, FAR char **value); +int arg_decimal(FAR char **arg, FAR long *value); +int arg_hex(FAR char **arg, FAR long *value); #endif /* __APPS_SYSTEM_I2C_I2CTOOLS_H */ -- cgit v1.2.3