diff options
Diffstat (limited to 'apps/system/i2c')
-rw-r--r-- | apps/system/i2c/Kconfig | 61 | ||||
-rw-r--r-- | apps/system/i2c/Makefile | 108 | ||||
-rw-r--r-- | apps/system/i2c/README.txt | 397 | ||||
-rw-r--r-- | apps/system/i2c/i2c_bus.c | 99 | ||||
-rw-r--r-- | apps/system/i2c/i2c_common.c | 216 | ||||
-rw-r--r-- | apps/system/i2c/i2c_dev.c | 235 | ||||
-rw-r--r-- | apps/system/i2c/i2c_get.c | 257 | ||||
-rw-r--r-- | apps/system/i2c/i2c_main.c | 446 | ||||
-rw-r--r-- | apps/system/i2c/i2c_set.c | 275 | ||||
-rw-r--r-- | apps/system/i2c/i2c_verf.c | 249 | ||||
-rw-r--r-- | apps/system/i2c/i2ctool.h | 210 |
11 files changed, 0 insertions, 2553 deletions
diff --git a/apps/system/i2c/Kconfig b/apps/system/i2c/Kconfig deleted file mode 100644 index 745378b37..000000000 --- a/apps/system/i2c/Kconfig +++ /dev/null @@ -1,61 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see misc/tools/kconfig-language.txt. -# - - -config SYSTEM_I2CTOOL - bool "I2C tool" - default n - depends on I2C - ---help--- - Enable support for the I2C tool. - -config I2CTOOL_BUILTIN - bool "NSH built-in command" - default y - depends on SYSTEM_I2CTOOL && NSH_BUILTIN_APPS - ---help--- - Build the tools as an NSH built-in command - -config I2CTOOL_MINBUS - int "Minimum bus number" - default 0 - depends on SYSTEM_I2CTOOL - ---help--- - Smallest bus index supported by the hardware (default 0). - -config I2CTOOL_MAXBUS - int "Maximum bus number" - depends on SYSTEM_I2CTOOL - default 3 - ---help--- - Largest bus index supported by the hardware (default 3) - -config I2CTOOL_MINADDR - hex "Minimum I2C address" - depends on SYSTEM_I2CTOOL - default 0x03 - ---help--- - Minium 7-bit device address (default: 0x03) - -config I2CTOOL_MAXADDR - hex "Maximum I2C address" - depends on SYSTEM_I2CTOOL - default 0x77 - ---help--- - Largest 7-bit device address (default: 0x77) - -config I2CTOOL_MAXREGADDR - hex "Maximum I2C register address" - default 0xff - depends on SYSTEM_I2CTOOL - ---help--- - Largest I2C register address (default: 0xff) - -config I2CTOOL_DEFFREQ - int "Default I2C frequency" - default 4000000 - depends on SYSTEM_I2CTOOL - ---help--- - Default I2C frequency (default: 4000000) diff --git a/apps/system/i2c/Makefile b/apps/system/i2c/Makefile deleted file mode 100644 index 7f0e6005b..000000000 --- a/apps/system/i2c/Makefile +++ /dev/null @@ -1,108 +0,0 @@ -############################################################################ -# apps/system/i2c/Makefile -# -# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt <gnutt@nuttx.org> -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - --include $(TOPDIR)/.config --include $(TOPDIR)/Make.defs -include $(APPDIR)/Make.defs - -# I2C tool - -ASRCS = -CSRCS = i2c_bus.c i2c_common.c i2c_dev.c i2c_get.c i2c_main.c i2c_set.c i2c_verf.c - -AOBJS = $(ASRCS:.S=$(OBJEXT)) -COBJS = $(CSRCS:.c=$(OBJEXT)) - -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) - -ifeq ($(CONFIG_WINDOWS_NATIVE),y) - BIN = ..\..\libapps$(LIBEXT) -else -ifeq ($(WINTOOL),y) - BIN = ..\\..\\libapps$(LIBEXT) -else - BIN = ../../libapps$(LIBEXT) -endif -endif - -ROOTDEPPATH = --dep-path . -VPATH = - -APPNAME = i2c -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 -MAXOPTIMIZATION = -Os - -# Build Targets - -all: .built -.PHONY: context .depend depend clean distclean - -$(AOBJS): %$(OBJEXT): %.S - $(call ASSEMBLE, $<, $@) - -$(COBJS): %$(OBJEXT): %.c - $(call COMPILE, $<, $@) - -.built: $(OBJS) - $(call ARCHIVE, $(BIN), $(OBJS)) - $(Q) touch .built - -ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) - -context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat -else -context: -endif - -.depend: Makefile $(SRCS) - $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep - $(Q) touch $@ - -depend: .depend - -clean: - $(call DELFILE, .built) - $(call CLEAN) - -distclean: clean - $(call DELFILE, Make.dep) - $(call DELFILE, .depend) - --include Make.dep - diff --git a/apps/system/i2c/README.txt b/apps/system/i2c/README.txt deleted file mode 100644 index 7b432533b..000000000 --- a/apps/system/i2c/README.txt +++ /dev/null @@ -1,397 +0,0 @@ -README File for the I2C Tool
-============================
-
-The I2C tool provides a way to debug I2C related problems. This README file
-will provide usage information for the I2C tools.
-
-CONTENTS
-========
-
- o System Requirements
- - I2C Driver
- - Configuration Options
- o Help
- o Common Line Form
- o Common Command Options
- - "Sticky" Options
- - Environment variables
- - Common Option Summary
- o Command summary
- - bus
- - dev
- - get
- - set
- - verf
- o I2C Build Configuration
- - NuttX Configuration Requirements
- - I2C Tool Configuration Options
-
-System Requirements
-===================
-
-I2C Driver
-----------
-In order to use the I2C driver, you system -- in particular, your I2C driver --
-must meet certain requirements:
-
-1. It support calling up_i2cinitialize() numerous times, resetting the I2C
- hardware on each (initial) time. up_i2cuninitialize() will be called after
- each call to up_i2cinitialize() to free any resources and disable the I2C.
-2. up_i2cinitialize must accept any interface number without crashing. It
- must simply return NULL if the device is not supported.
-3. The I2C driver must support the transfer method (CONFIG_I2C_TRANSFER=y).
-
-The I2C tool is designed to be implemented as a NuttShell (NSH) add-on. Read
-the apps/nshlib/README.txt file for information about add-ons.
-
-Configuration Options
----------------------
-CONFIG_I2CTOOL_BUILTIN - Build the tools as an NSH built-in command
-CONFIG_I2CTOOL_MINBUS - Smallest bus index supported by the hardware (default 0).
-CONFIG_I2CTOOL_MAXBUS - Largest bus index supported by the hardware (default 3)
-CONFIG_I2CTOOL_MINADDR - Minium device address (default: 0x03)
-CONFIG_I2CTOOL_MAXADDR - Largest device address (default: 0x77)
-CONFIG_I2CTOOL_MAXREGADDR - Largest register address (default: 0xff)
-CONFIG_I2CTOOL_DEFFREQ - Default frequency (default: 4000000)
-
-HELP
-====
-
-First of all, the I2C tools supports a pretty extensive help output. That
-help output can be view by entering either:
-
- nsh> i2c help
-
-or
-
- nsh> i2c ?
-
-Here is an example of the help output. I shows the general form of the
-command line, the various I2C commands supported with their unique command
-line options, and a more detailed summary of the command I2C command
-options.
-
- nsh> i2c help
- Usage: i2c <cmd> [arguments]
- Where <cmd> is one of:
-
- Show help : ?
- List buses : bus
- List devices : dev [OPTIONS] <first> <last>
- Read register : get [OPTIONS] [<repititions>]
- Show help : help
- Write register: set [OPTIONS] <value> [<repititions>]
- Verify access : verf [OPTIONS] <value> [<repititions>]
-
- Where common "sticky" OPTIONS include:
- [-a addr] is the I2C device address (hex). Default: 03 Current: 03
- [-b bus] is the I2C bus number (decimal). Default: 1 Current: 1
- [-r regaddr] is the I2C device register address (hex). Default: 00 Current: 00
- [-w width] is the data width (8 or 16 decimal). Default: 8 Current: 8
- [-s|n], send/don't send start between command and data. Default: -n Current: -n
- [-i|j], Auto increment|don't increment regaddr on repititions. Default: NO Current: NO
- [-f freq] I2C frequency. Default: 100000 Current: 100000
-
- NOTES:
- o An environment variable like $PATH may be used for any argument.
- o Arguments are "sticky". For example, once the I2C address is
- specified, that address will be re-used until it is changed.
-
- WARNING:
- o The I2C dev command may have bad side effects on your I2C devices.
- Use only at your own risk.
-
-COMMAND LINE FORM
-=================
-
-The I2C is started from NSH by invoking the 'i2c' command from the NSH
-command line. The general form of the 'i2c' command is:
-
- i2c <cmd> [arguments]
-
-Where <cmd> is a "sub-command" and identifies one I2C operations supported
-by the tool. [arguments] represents the list of arguments needed to perform
-the I2C operation. Those arguments vary from command to command as
-described below. However, there is also a core set of common OPTIONS
-supported by all commands. So perhaps a better representation of the
-general I2C command would be:
-
- i2c <cmd> [OPTIONS] [arguments]
-
-Where [OPTIONS] represents the common options and and arguments represent
-the operation-specific arguments.
-
-COMMON COMMAND OPTIONS
-======================
-
-"Sticky" Options
-----------------
-In order to interact with I2C devices, there are a number of I2C parameters
-that must be set correctly. One way to do this would be to provide to set
-the value of each separate command for each I2C parameter. The I2C tool
-takes a different approach, instead: The I2C configuration can be specified
-as a (potentially long) sequence of command line arguments.
-
-These arguments, however, are "sticky." They are sticky in the sense that
-once you set the I2C parameter, that value will remain until it is reset
-with a new value (or until you reset the board).
-
-Environment Variables
----------------------
-NOTE also that if environment variables are not disabled (by
-CONFIG_DISABLE_ENVIRON=y), then these options may also be environment
-variables. Environment variables must be preceded with the special
-character $. For example, PWD is the variable that holds the current
-working directory and so $PWD could be used as a command line argument. The
-use of environment variables on the I2C tools command is really only useful
-if you wish to write NSH scripts to execute a longer, more complex series of
-I2C commands.
-
-Common Option Summary
----------------------
-
-[-a addr] is the I2C device address (hex). Default: 03 Current: 03
-
- The [-a addr] sets the I2C device address. The valid range is 0x03
- through 0x77 (this valid range is controlled by the configuration settings
- CONFIG_I2CTOOL_MINADDR and CONFIG_I2CTOOL_MAXADDR). If you are working
- with the same device, the address needs to be set only once.
-
- All I2C address are 7-bit, hexadecimal values.
-
- NOTE 1: Notice in the "help" output above it shows both default value of
- the I2C address (03 hex) and the current address value (also 03 hex).
-
- NOTE 2: Sometimes I2C addresses are represented as 8-bit values (with
- bit zero indicating a read or write operation). The I2C tool uses a
- 7-bit representation of the address with bit 7 unused and no read/write
- indication in bit 0. Essentially, the 7-bit address is like the 8-bit
- address shifted right by 1.
-
- NOTE 3: Most I2C bus controllers will also support 10-bit addressing.
- That capability has not been integrated into the I2C tool as of this
- writing.
-
-[-b bus] is the I2C bus number (decimal). Default: 1 Current: 1
-
- Most devices support multiple I2C devices and also have unique bus
- numbering. This option identifies which bus you are working with now.
- The valid range of bus numbers is controlled by the configuration settings
- CONFIG_I2CTOOL_MINBUS and CONFIG_I2CTOOL_MAXBUS.
-
- The bus numbers are small, decimal numbers.
-
-[-r regaddr] is the I2C device register address (hex). Default: 00 Current: 00
-
- The I2C set and get commands will access registers on the I2C device. This
- option selects the device register address (sometimes called the sub-address).
- This is an 8-bit hexadecimal value. The maximum value is determined by
- the configuration setting CONFIG_I2CTOOL_MAXREGADDR.
-
-[-w width] is the data width (8 or 16 decimal). Default: 8 Current: 8
-
- Device register data may be 8-bit or 16-bit. This options selects one of
- those two data widths.
-
-[-s|n], send/don't send start between command and data. Default: -n Current: -n
-
- This determines whether or not there should be a new I2C START between
- sending of the register address and sending/receiving of the register data.
-
-[-i|j], Auto increment|don't increment regaddr on repititions. Default: NO Current: NO
-
- On commands that take a optional number of repetitions, the option can be
- used to temporarily increment the regaddr value by one on each repitition.
-
-[-f freq] I2C frequency. Default: 400000 Current: 400000
-
- The [-f freq] sets the frequency of the I2C device.
-
-COMMAND SUMMARY
-===============
-
-We have already seen the I2C help (or ?) commands above. This section will
-discuss the remaining commands.
-
-List buses: bus [OPTIONS]
---------------------------
-
-This command will simply list all of the configured I2C buses and indicate
-which are supported by the driver and which are not:
-
- BUS EXISTS?
- Bus 1: YES
- Bus 2: NO
-
-The valid range of bus numbers is controlled by the configuration settings
-CONFIG_I2CTOOL_MINBUS and CONFIG_I2CTOOL_MAXBUS.
-
-List devices: dev [OPTIONS] <first> <last>
-------------------------------------------
-
-The 'dev' command will attempt to identify all of the I2C devices on the
-selected bus. The <first> and <last> arguments are 7-bit, hexadecimal
-I2C addresses. This command will examine a range of addresses beginning
-with <first> and continuing through <last>. It will request the value
-of register zero from each device.
-
-If the device at an address responds, then this command will display the
-address of the device. If the device does not respond, this command will
-display "--". The resulting display is like:
-
-nsh> i2c dev 03 77
- 0 1 2 3 4 5 6 7 8 9 a b c d e f
-00: -- -- -- -- -- -- -- -- -- -- -- -- --
-10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-40: -- -- -- -- -- -- -- -- -- 49 -- -- -- -- -- --
-50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-70: -- -- -- -- -- -- -- --
-
-WARNINGS:
- o The I2C dev command may have bad side effects on certain I2C devices.
- For example, if could cause data loss in an EEPROM device.
- o The I2C dev command also depends upon the underlying behavior of the
- I2C driver. How does the driver respond to addressing failures?
-
-Read register: get [OPTIONS]
-----------------------------
-
- This command will read the value of the I2C register using the selected
- I2C parameters in the common options. No other arguments are required.
-
- This command with write the 8-bit address value then read an 8- or 16-bit
- data value from the device. Optionally, it may re-start the transfer
- before obtaining the data.
-
- An optional <repititions> argument can be supplied to repeat the
- read operation an arbitrary number of times (up to 2 billion). If
- auto-increment is select (-i), then the register address will be
- temporarily incremented on each repitions. The increment is temporary
- in the since that it will not alter the "sticky" value of the
- register address.
-
- On success, the output will look like the following (the data value
- read will be shown as a 4-character hexadecimal number if the 16-bit
- data width option is selected).
-
- READ Bus: 1 Addr: 49 Subaddr: 04 Value: 96
-
- All values (except the bus numbers) are hexadecimal.
-
-Write register: set [OPTIONS] <value>
--------------------------------------
-
- This command will write a value to an I2C register using the selected
- I2C parameters in the common options. The value to write must be provided
- as the final, hexadecimal value. This value may be an 8-bit value (in the
- range 00-ff) or a 16-bit value (in the range 0000-ffff), depending upon
- the selected data width.
-
- This command will write the 8-bit address value then write the 8- or 16-bit
- data value to the device. Optionally, it may re-start the transfer
- before writing the data.
-
- An optional <repititions> argument can be supplied to repeat the
- write operation an arbitrary number of times (up to 2 billion). If
- auto-increment is select (-i), then the register address will be
- temporarily incremented on each repitions. The increment is temporary
- in the since that it will not alter the "sticky" value of the
- register address.
-
- On success, the output will look like the following (the data value
- written will be shown as a 4-character hexadecimal number if the 16-bit
- data width option is selected).
-
- WROTE Bus: 1 Addr: 49 Subaddr: 04 Value: 96
-
- All values (except the bus numbers) are hexadecimal.
-
-Verify access : verf [OPTIONS] <value> [<repititions>]
-------------------------------------------------------
-
- This command combines writing and reading from an I2C device register.
- It will write a value to an will write a value to an I2C register using
- the selected I2C parameters in the common options just as described for
- tie 'set' command. Then this command will read the value back just
- as described with the 'get' command. Finally, this command will compare
- the value read and against the value written and emit an error message
- if they do not match.
-
- If no value is provided, then this command will use the register address
- itself as the data, providing for a address-in-address test.
-
- An optional <repititions> argument can be supplied to repeat the
- verify operation an arbitrary number of times (up to 2 billion). If
- auto-increment is select (-i), then the register address will be
- temporarily incremented on each repitions. The increment is temporary
- in the since that it will not alter the "sticky" value of the
- register address.
-
- On success, the output will look like the following (the data value
- written will be shown as a 4-character hexadecimal number if the 16-bit
- data width option is selected).
-
- VERIFY Bus: 1 Addr: 49 Subaddr: 04 Wrote: 96 Read: 92 FAILURE
-
- All values (except the bus numbers) are hexadecimal.
-
-I2C BUILD CONFIGURATION
-=======================
-
-NuttX Configuration Requirements
---------------------------------
-The I2C tools requires the following in your NuttX configuration:
-
-1. Device-specific I2C support must be enabled. The I2C tool will call the
- platform-specific function up_i2cinitialize() to get instances of the
- I2C interface and the platform-specific function up_i2cuninitialize()
- to discard instances of the I2C interface.
-
- NOTE 1: The I2C interface is defined in include/nuttx/i2c.h.
-
- NOTE 2: This I2C tool uses direct I2C device interfaces. As such, it
- relies on internal OS interfaces that are not normally available to a
- user-space program. As a result, the I2C tool cannot be used if a
- NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL).
-
-2. I2C driver configuration
-
- The CONFIG_I2C_TRANSFER option must also be set in your NuttX
- configuration. This configuration is the defconfig file in your
- configuration directory that is copied to the NuttX top-level
- directory as .config when NuttX is configured.
-
- CONFIG_I2C_TRANSFER=y
-
- NOTE: CONFIG_I2C_TRANSFER adds extra methods to the I2C interface.
- Not all I2C interfaces support these extra methods. If your platform's
- I2C driver does not support these extra methods, then you cannot use
- the I2C tool unless you extend the support in your platform I2C
- driver.
-
-3. Application configuration.
-
- The path to the I2C tool directory must also be set in your NuttX
- application configuration. This application configuration is the
- appconfig file in your configuration directory that is copied to the
- NuttX application directory as .config when NuttX is configured.
-
- CONFIGURE_APPS += system/i2c
-
-I2C Tool Configuration Options
-------------------------------
-
-The default behavior of the I2C tool can be modified by the setting the
-options in the NuttX configuration. This configuration is the defconfig
-file in your configuration directory that is copied to the NuttX top-level
-directory as .config when NuttX is configured.
-
- CONFIG_I2CTOOL_BUILTIN: Build the tools as an NSH built-in command
- CONFIG_I2CTOOL_MINBUS: Smallest bus index supported by the hardware (default 0).
- CONFIG_I2CTOOL_MAXBUS: Largest bus index supported by the hardware (default 3)
- CONFIG_I2CTOOL_MINADDR: Minium device address (default: 0x03)
- CONFIG_I2CTOOL_MAXADDR: Largest device address (default: 0x77)
- CONFIG_I2CTOOL_MAXREGADDR: Largest register address (default: 0xff)
- CONFIG_I2CTOOL_DEFFREQ: Default frequency (default: 4000000)
diff --git a/apps/system/i2c/i2c_bus.c b/apps/system/i2c/i2c_bus.c deleted file mode 100644 index a684166ff..000000000 --- a/apps/system/i2c/i2c_bus.c +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_bus.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_bus - ****************************************************************************/ - -int i2ccmd_bus(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - FAR struct i2c_dev_s *dev; - int i; - - i2ctool_printf(i2ctool, " BUS EXISTS?\n"); - for (i = CONFIG_I2CTOOL_MINBUS; i <= CONFIG_I2CTOOL_MAXBUS; i++) - { - dev = up_i2cinitialize(i); - if (dev) - { - i2ctool_printf(i2ctool, "Bus %d: YES\n", i); - (void)up_i2cuninitialize(dev); - } - else - { - i2ctool_printf(i2ctool, "Bus %d: NO\n", i); - } - } - - return OK; -} diff --git a/apps/system/i2c/i2c_common.c b/apps/system/i2c/i2c_common.c deleted file mode 100644 index 4af648c7d..000000000 --- a/apps/system/i2c/i2c_common.c +++ /dev/null @@ -1,216 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_common.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: common_args - ****************************************************************************/ - -int common_args(FAR struct i2ctool_s *i2ctool, FAR char **arg) -{ - FAR char *ptr = *arg; - long value; - int ret; - - if (ptr[0] != '-') - { - goto invalid_argument; - } - - switch (ptr[1]) - { - case 'a': - ret = arg_hex(arg, &value); - if (value < CONFIG_I2CTOOL_MINADDR || value > CONFIG_I2CTOOL_MAXADDR) - { - goto out_of_range; - } - - i2ctool->addr = (uint8_t) value; - return ret; - - case 'b': - ret = arg_decimal(arg, &value); - if (value < CONFIG_I2CTOOL_MINBUS || value > CONFIG_I2CTOOL_MAXBUS) - { - goto out_of_range; - } - - i2ctool->bus = (uint8_t) value; - return ret; - - case 'f': - ret = arg_decimal(arg, &value); - if (value == 0) - { - goto out_of_range; - } - - i2ctool->freq = value; - return ret; - - case 'i': - i2ctool->autoincr = true; - return 1; - - case 'j': - i2ctool->autoincr = false; - return 1; - - case 'n': - i2ctool->start = false; - return 1; - - case 'r': - ret = arg_hex(arg, &value); - if (value < 0 || value > CONFIG_I2CTOOL_MAXREGADDR) - { - goto out_of_range; - } - - i2ctool->regaddr = (uint8_t) value; - return ret; - - case 's': - i2ctool->start = true; - return 1; - - case 'w': - ret = arg_decimal(arg, &value); - if (value != 8 && value != 16) - { - goto out_of_range; - } - - i2ctool->width = (uint8_t) value; - return ret; - - default: - goto invalid_argument; - } - -invalid_argument: - i2ctool_printf(i2ctool, g_i2carginvalid, ptr); - return ERROR; - -out_of_range: - i2ctool_printf(i2ctool, g_i2cargrange, ptr); - return ERROR; -} - -/**************************************************************************** - * Name: arg_string - ****************************************************************************/ - -int arg_string(FAR char **arg, FAR char **value) -{ - FAR char *ptr = *arg; - - if (ptr[2] == '\0') - { - *value = arg[1]; - return 2; - } - else - { - *value = &ptr[2]; - return 1; - } -} - -/**************************************************************************** - * Name: arg_decimal - ****************************************************************************/ - -int arg_decimal(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 10); - return ret; -} - -/**************************************************************************** - * Name: arg_hex - ****************************************************************************/ - -int arg_hex(FAR char **arg, FAR long *value) -{ - FAR char *string; - int ret; - - ret = arg_string(arg, &string); - *value = strtol(string, NULL, 16); - return ret; -} diff --git a/apps/system/i2c/i2c_dev.c b/apps/system/i2c/i2c_dev.c deleted file mode 100644 index 3d0480a15..000000000 --- a/apps/system/i2c/i2c_dev.c +++ /dev/null @@ -1,235 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_dev.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_dev - ****************************************************************************/ - -int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - FAR struct i2c_dev_s *dev; - struct i2c_msg_s msg[2]; - FAR char *ptr; - union - { - uint16_t data16; - uint8_t data8; - } u; - - uint8_t regaddr; - long first; - long last; - int addr; - int nargs; - int argndx; - int ret; - int i; - int j; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* There should be exactly two more things on the command line: The first and - * last addresses to be probed. - */ - - if (argndx+1 < argc) - { - first = strtol(argv[argndx], NULL, 16); - last = strtol(argv[argndx+1], NULL, 16); - if (first < 0 || first > 0x7f || last < 0 || last > 0x7f || first > last) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx += 2; - } - else - { - i2ctool_printf(i2ctool, g_i2cargrequired, argv[0]); - return ERROR; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - - /* Probe each address */ - - i2ctool_printf(i2ctool, " 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); - for (i = 0; i < 128; i += 16) - { - i2ctool_printf(i2ctool, "%02x: ", i); - for (j = 0; j < 16; j++) - { - /* Skip addresses that are out of the selected range */ - - addr = i+j; - if (addr < first || addr > last) - { - i2ctool_printf(i2ctool, " "); - continue; - } - - /* Set the I2C address */ - - I2C_SETADDRESS(dev, addr, 7); - - /* Set up data structures */ - - regaddr = 0; - - msg[0].addr = addr; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; - - msg[1].addr = addr; - msg[1].flags = I2C_M_READ; - if (i2ctool->width == 8) - { - msg[1].buffer = &u.data8; - msg[1].length = 1; - } - else - { - msg[1].buffer = (uint8_t*)&u.data16; - msg[1].length = 2; - } - - if (i2ctool->start) - { - ret = I2C_TRANSFER(dev, &msg[0], 1); - if (ret == OK) - { - ret = I2C_TRANSFER(dev, &msg[1], 1); - } - } - else - { - ret = I2C_TRANSFER(dev, msg, 2); - } - - if (ret == OK) - { - i2ctool_printf(i2ctool, "%02x ", addr); - } - else - { - i2ctool_printf(i2ctool, "-- "); - } - } - i2ctool_printf(i2ctool, "\n"); - i2ctool_flush(i2ctool); - } - - (void)up_i2cuninitialize(dev); - return OK; -} diff --git a/apps/system/i2c/i2c_get.c b/apps/system/i2c/i2c_get.c deleted file mode 100644 index 08510af4b..000000000 --- a/apps/system/i2c/i2c_get.c +++ /dev/null @@ -1,257 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_get.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_get - ****************************************************************************/ - -int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) -{ - FAR struct i2c_dev_s *dev; - FAR char *ptr; - uint16_t result; - uint8_t regaddr; - long repititions; - int nargs; - int argndx; - int ret; - int i; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* There may be one more thing on the command line: The repitition - * count. - */ - - repititions = 1; - if (argndx < argc) - { - repititions = strtol(argv[argndx], NULL, 16); - if (repititions < 1) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - I2C_SETADDRESS(dev, i2ctool->addr, 7); - - /* Loop for the requested number of repititions */ - - regaddr = i2ctool->regaddr; - ret = OK; - - for (i = 0; i < repititions; i++) - { - /* Read from the I2C bus */ - - ret = i2ctool_get(i2ctool, dev, regaddr, &result); - - /* Display the result */ - - if (ret == OK) - { - i2ctool_printf(i2ctool, "READ Bus: %d Addr: %02x Subaddr: %02x Value: ", - i2ctool->bus, i2ctool->addr, i2ctool->regaddr); - if (i2ctool->width == 8) - { - i2ctool_printf(i2ctool, "%02x\n", result); - } - else - { - i2ctool_printf(i2ctool, "%04x\n", result); - } - } - else - { - i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); - break; - } - - /* Auto-increment the address if so configured */ - - if (i2ctool->autoincr) - { - regaddr++; - } - } - - (void)up_i2cuninitialize(dev); - return ret; -} - -/**************************************************************************** - * Name: i2ctool_get - ****************************************************************************/ - -int i2ctool_get(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t regaddr, uint16_t *result) -{ - struct i2c_msg_s msg[2]; - union - { - uint16_t data16; - uint8_t data8; - } u; - int ret; - - /* Set up data structures */ - - msg[0].addr = i2ctool->addr; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; - - msg[1].addr = i2ctool->addr; - msg[1].flags = I2C_M_READ; - if (i2ctool->width == 8) - { - msg[1].buffer = &u.data8; - msg[1].length = 1; - } - else - { - msg[1].buffer = (uint8_t*)&u.data16; - msg[1].length = 2; - } - - if (i2ctool->start) - { - ret = I2C_TRANSFER(dev, &msg[0], 1); - if (ret== OK) - { - ret = I2C_TRANSFER(dev, &msg[1], 1); - } - } - else - { - ret = I2C_TRANSFER(dev, msg, 2); - } - - /* Return the result of the read operation */ - - if (ret == OK) - { - if (i2ctool->width == 8) - { - *result = (uint16_t)u.data8; - } - else - { - *result = u.data16; - } - } - return ret; -} diff --git a/apps/system/i2c/i2c_main.c b/apps/system/i2c/i2c_main.c deleted file mode 100644 index 0cf6786cb..000000000 --- a/apps/system/i2c/i2c_main.c +++ /dev/null @@ -1,446 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_main.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <stdarg.h> -#include <assert.h> -#include <errno.h> -#include <debug.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv); -static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **argv); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -struct i2ctool_s g_i2ctool; - -static const struct cmdmap_s g_i2ccmds[] = -{ - { "?", i2ccmd_help, "Show help ", NULL }, - { "bus", i2ccmd_bus, "List busses ", NULL }, - { "dev", i2ccmd_dev, "List devices ", "[OPTIONS] <first> <last>" }, - { "get", i2ccmd_get, "Read register ", "[OPTIONS] [<repititions>]" }, - { "help", i2ccmd_help, "Show help ", NULL }, - { "set", i2ccmd_set, "Write register", "[OPTIONS] <value> [<repititions>]" }, - { "verf", i2ccmd_verf, "Verify access ", "[OPTIONS] [<value>] [<repititions>]" }, - { NULL, NULL, NULL, NULL } -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* Common, message formats */ - -const char g_i2cargrequired[] = "i2ctool: %s: missing required argument(s)\n"; -const char g_i2carginvalid[] = "i2ctool: %s: argument invalid\n"; -const char g_i2cargrange[] = "i2ctool: %s: value out of range\n"; -const char g_i2ccmdnotfound[] = "i2ctool: %s: command not found\n"; -const char g_i2ctoomanyargs[] = "i2ctool: %s: too many arguments\n"; -const char g_i2ccmdfailed[] = "i2ctool: %s: %s failed: %d\n"; -const char g_i2cxfrerror[] = "i2ctool: %s: Transfer failed: %d\n"; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_help - ****************************************************************************/ - -static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - const struct cmdmap_s *ptr; - - i2ctool_printf(i2ctool, "Usage: i2c <cmd> [arguments]\n"); - i2ctool_printf(i2ctool, "Where <cmd> is one of:\n\n"); - for (ptr = g_i2ccmds; ptr->cmd; ptr++) - { - if (ptr->usage) - { - i2ctool_printf(i2ctool, " %s: %s %s\n", ptr->desc, ptr->cmd, ptr->usage); - } - else - { - i2ctool_printf(i2ctool, " %s: %s\n", ptr->desc, ptr->cmd); - } - } - - i2ctool_printf(i2ctool, "\nWhere common \"sticky\" OPTIONS include:\n"); - i2ctool_printf(i2ctool, " [-a addr] is the I2C device address (hex). " - "Default: %02x Current: %02x\n", - CONFIG_I2CTOOL_MINADDR, i2ctool->addr); - i2ctool_printf(i2ctool, " [-b bus] is the I2C bus number (decimal). " - "Default: %d Current: %d\n", - CONFIG_I2CTOOL_MINBUS, i2ctool->bus); - i2ctool_printf(i2ctool, " [-r regaddr] is the I2C device register address (hex). " - "Default: 00 Current: %02x\n", - i2ctool->regaddr); - i2ctool_printf(i2ctool, " [-w width] is the data width (8 or 16 decimal). " - "Default: 8 Current: %d\n", - i2ctool->width); - i2ctool_printf(i2ctool, " [-s|n], send/don't send start between command and data. " - "Default: -n Current: %s\n", - i2ctool->start ? "-s" : "-n"); - i2ctool_printf(i2ctool, " [-i|j], Auto increment|don't increment regaddr on repititions. " - "Default: NO Current: %s\n", - i2ctool->autoincr ? "YES" : "NO"); - i2ctool_printf(i2ctool, " [-f freq] I2C frequency. " - "Default: %d Current: %d\n", - CONFIG_I2CTOOL_DEFFREQ, i2ctool->freq); - i2ctool_printf(i2ctool, "\nNOTES:\n"); -#ifndef CONFIG_DISABLE_ENVIRON - i2ctool_printf(i2ctool, "o An environment variable like $PATH may be used for any argument.\n"); -#endif - i2ctool_printf(i2ctool, "o Arguments are \"sticky\". For example, once the I2C address is\n"); - i2ctool_printf(i2ctool, " specified, that address will be re-used until it is changed.\n"); - i2ctool_printf(i2ctool, "\nWARNING:\n"); - i2ctool_printf(i2ctool, "o The I2C dev command may have bad side effects on your I2C devices.\n"); - i2ctool_printf(i2ctool, " Use only at your own risk.\n"); - return OK; -} - -/**************************************************************************** - * Name: i2ccmd_unrecognized - ****************************************************************************/ - -static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **argv) -{ - i2ctool_printf(i2ctool, g_i2ccmdnotfound, argv[0]); - return ERROR; -} - -/**************************************************************************** - * Name: i2c_execute - ****************************************************************************/ - -static int i2c_execute(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) -{ - const struct cmdmap_s *cmdmap; - const char *cmd; - cmd_t handler; - int ret; - - /* The form of argv is: - * - * argv[0]: The command name. This is argv[0] when the arguments - * are, finally, received by the command vtblr - * argv[1]: The beginning of argument (up to MAX_ARGUMENTS) - * argv[argc]: NULL terminating pointer - */ - - /* See if the command is one that we understand */ - - cmd = argv[0]; - handler = i2ccmd_unrecognized; - - for (cmdmap = g_i2ccmds; cmdmap->cmd; cmdmap++) - { - if (strcmp(cmdmap->cmd, cmd) == 0) - { - handler = cmdmap->handler; - break; - } - } - - ret = handler(i2ctool, argc, argv); - return ret; -} - -/**************************************************************************** - * Name: i2c_argument - ****************************************************************************/ - -FAR char *i2c_argument(FAR struct i2ctool_s *i2ctool, int argc, char *argv[], int *pindex) -{ - FAR char *arg; - int index = *pindex; - - /* If we are at the end of the arguments with nothing, then return NULL */ - - if (index >= argc) - { - return NULL; - } - - /* Get the return parameter */ - - arg = argv[index]; - *pindex = index + 1; - -#ifndef CONFIG_DISABLE_ENVIRON - /* Check for references to environment variables */ - - if (arg[0] == '$') - { - /* Return the value of the environment variable with this name */ - - FAR char *value = getenv(arg+1); - if (value) - { - return value; - } - else - { - return (FAR char*)""; - } - } -#endif - - /* Return the next argument. */ - - return arg; -} - -/**************************************************************************** - * Name: i2c_parse - ****************************************************************************/ - -int i2c_parse(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) -{ - FAR char *newargs[MAX_ARGUMENTS+2]; - FAR char *cmd; - int nargs; - int index; - - /* Parse out the command, skipping the first argument (the program name)*/ - - index = 1; - cmd = i2c_argument(i2ctool, argc, argv, &index); - - /* Check if any command was provided */ - - if (!cmd) - { - /* An empty line is not an error and an unprocessed command cannot - * generate an error, but neither should they change the last - * command status. - */ - - return i2ccmd_help(i2ctool, 0, NULL); - } - - /* Parse all of the arguments following the command name. */ - - newargs[0] = cmd; - for (nargs = 1; nargs <= MAX_ARGUMENTS; nargs++) - { - newargs[nargs] = i2c_argument(i2ctool, argc, argv, &index); - if (!newargs[nargs]) - { - break; - } - } - newargs[nargs] = NULL; - - /* Then execute the command */ - - return i2c_execute(i2ctool, nargs, newargs); -} - -/**************************************************************************** - * Name: i2c_setup - ****************************************************************************/ - -static inline int i2c_setup(FAR struct i2ctool_s *i2ctool) -{ - /* Initialize the output stream */ - -#ifdef CONFIG_I2CTOOL_OUTDEV - i2ctool->ss_outfd = open(CONFIG_I2CTOOL_OUTDEV, O_WRONLY); - if (i2ctool->ss_outfd < 0) - { - fprintf(stderr, g_i2ccmdfailed, "open", errno); - return ERROR; - } - - /* Create a standard C stream on the console device */ - - i2ctool->ss_outstream = fdopen(i2ctool->ss_outfd, "w"); - if (!i2ctool->ss_outstream) - { - fprintf(stderr, g_i2ccmdfailed, "fdopen", errno); - return ERROR; - } -#endif - - return OK; -} - -/**************************************************************************** - * Name: i2c_teardown - * - * Description: - * Close the output stream if it is not the standard output stream. - * - ****************************************************************************/ - -static void i2c_teardown(FAR struct i2ctool_s *i2ctool) -{ - fflush(OUTSTREAM(&g_i2ctool)); - -#ifdef CONFIG_I2CTOOL_OUTDEV - fclose(i2ctool->ss_outstream); -#endif -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2c_main - ****************************************************************************/ - -int i2c_main(int argc, char *argv[]) -{ - /* Verify settings */ - - if (g_i2ctool.bus < CONFIG_I2CTOOL_MINBUS || g_i2ctool.bus > CONFIG_I2CTOOL_MAXBUS) - { - g_i2ctool.bus = CONFIG_I2CTOOL_MINBUS; - } - - if (g_i2ctool.addr < CONFIG_I2CTOOL_MINADDR || g_i2ctool.addr > CONFIG_I2CTOOL_MAXADDR) - { - g_i2ctool.addr = CONFIG_I2CTOOL_MINADDR; - } - - if (g_i2ctool.regaddr < CONFIG_I2CTOOL_MAXREGADDR) - { - g_i2ctool.regaddr = 0; - } - - if (g_i2ctool.width != 8 && g_i2ctool.width != 16) - { - g_i2ctool.width = 8; - } - - if (g_i2ctool.freq == 0) - { - g_i2ctool.freq = CONFIG_I2CTOOL_DEFFREQ; - } - - /* Parse process the command line */ - - i2c_setup(&g_i2ctool); - (void)i2c_parse(&g_i2ctool, argc, argv); - - i2ctool_flush(&g_i2ctool); - i2c_teardown(&g_i2ctool); - return OK; -} - -/**************************************************************************** - * Name: i2ctool_printf - * - * Description: - * Print a string to the currently selected stream. - * - ****************************************************************************/ - -int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = vfprintf(OUTSTREAM(i2ctool), fmt, ap); - va_end(ap); - - return ret; -} - -/**************************************************************************** - * Name: i2ctool_write - * - * Description: - * write a buffer to the currently selected stream. - * - ****************************************************************************/ - -ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, size_t nbytes) -{ - ssize_t ret; - - /* Write the data to the output stream */ - - ret = fwrite(buffer, 1, nbytes, OUTSTREAM(i2ctool)); - if (ret < 0) - { - dbg("[%d] Failed to send buffer: %d\n", OUTFD(i2ctool), errno); - } - return ret; -} - -/**************************************************************************** - * Name: i2ctool_flush - * - * Description: - * Flush buffered I/O to the currently selected stream. - * - ****************************************************************************/ - -void i2ctool_flush(FAR struct i2ctool_s *i2ctool) -{ - fflush(OUTSTREAM(i2ctool)); -} diff --git a/apps/system/i2c/i2c_set.c b/apps/system/i2c/i2c_set.c deleted file mode 100644 index 5baf7f835..000000000 --- a/apps/system/i2c/i2c_set.c +++ /dev/null @@ -1,275 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_set.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_set - ****************************************************************************/ - -int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) -{ - FAR struct i2c_dev_s *dev; - FAR char *ptr; - uint8_t regaddr; - long value; - long repititions; - int nargs; - int argndx; - int ret; - int i; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* There must be at least one more thing on the command line: The value - * to be written. - */ - - if (argndx < argc) - { - value = strtol(argv[argndx], NULL, 16); - if (i2ctool->width == 8) - { - if (value < 0 || value > 255) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - } - else if (value < 0 || value > 65535) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - else - { - i2ctool_printf(i2ctool, g_i2cargrequired, argv[0]); - return ERROR; - } - - /* There may be one more thing on the command line: The repitition - * count. - */ - - repititions = 1; - if (argndx < argc) - { - repititions = strtol(argv[argndx], NULL, 16); - if (repititions < 1) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - I2C_SETADDRESS(dev, i2ctool->addr, 7); - - /* Loop for the requested number of repititions */ - - regaddr = i2ctool->regaddr; - ret = OK; - - for (i = 0; i < repititions; i++) - { - /* Write to the I2C bus */ - - ret = i2ctool_set(i2ctool, dev, regaddr, (uint16_t)value); - - /* Display the result */ - - if (ret == OK) - { - i2ctool_printf(i2ctool, "WROTE Bus: %d Addr: %02x Subaddr: %02x Value: ", - i2ctool->bus, i2ctool->addr, i2ctool->regaddr); - if (i2ctool->width == 8) - { - i2ctool_printf(i2ctool, "%02x\n", (int)value); - } - else - { - i2ctool_printf(i2ctool, "%04x\n", (int)value); - } - } - else - { - i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); - break; - } - - /* Auto-increment the address if so configured */ - - if (i2ctool->autoincr) - { - regaddr++; - } - } - - (void)up_i2cuninitialize(dev); - return ret; -} - -/**************************************************************************** - * Name: i2ctool_set - ****************************************************************************/ - -int i2ctool_set(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t regaddr, uint16_t value) -{ - struct i2c_msg_s msg[2]; - union - { - uint16_t data16; - uint8_t data8; - } u; - int ret; - - /* Set up data structures */ - - msg[0].addr = i2ctool->addr; - msg[0].flags = 0; - msg[0].buffer = ®addr; - msg[0].length = 1; - - msg[1].addr = i2ctool->addr; - msg[1].flags = 0; - if (i2ctool->width == 8) - { - u.data8 = (uint8_t)value; - msg[1].buffer = &u.data8; - msg[1].length = 1; - } - else - { - u.data16 = value; - msg[1].buffer = (uint8_t*)&u.data16; - msg[1].length = 2; - } - - if (i2ctool->start) - { - ret = I2C_TRANSFER(dev, &msg[0], 1); - if (ret == OK) - { - ret = I2C_TRANSFER(dev, &msg[1], 1); - } - } - else - { - ret = I2C_TRANSFER(dev, msg, 2); - } - - return ret; -} diff --git a/apps/system/i2c/i2c_verf.c b/apps/system/i2c/i2c_verf.c deleted file mode 100644 index 109e9c4ce..000000000 --- a/apps/system/i2c/i2c_verf.c +++ /dev/null @@ -1,249 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2c_verf.c - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> - -#include <stdlib.h> - -#include <nuttx/i2c.h> - -#include "i2ctool.h" - -/**************************************************************************** - * Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: i2ccmd_verf - ****************************************************************************/ - -int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) -{ - FAR struct i2c_dev_s *dev; - FAR char *ptr; - uint16_t rdvalue; - uint8_t regaddr; - bool addrinaddr; - long wrvalue; - long repititions; - int nargs; - int argndx; - int ret; - int i; - - /* Parse any command line arguments */ - - for (argndx = 1; argndx < argc; ) - { - /* Break out of the look when the last option has been parsed */ - - ptr = argv[argndx]; - if (*ptr != '-') - { - break; - } - - /* Otherwise, check for common options */ - - nargs = common_args(i2ctool, &argv[argndx]); - if (nargs < 0) - { - return ERROR; - } - argndx += nargs; - } - - /* The options may be followed by the optional wrvalue to be written. If omitted, then - * the register address will be used as the wrvalue, providing an address-in-address - * test. - */ - - addrinaddr = true; - wrvalue = 0; - - if (argndx < argc) - { - wrvalue = strtol(argv[argndx], NULL, 16); - if (i2ctool->width == 8) - { - if (wrvalue < 0 || wrvalue > 255) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - } - else if (wrvalue < 0 || wrvalue > 65535) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - addrinaddr = false; - argndx++; - } - - /* There may be one more thing on the command line: The repitition - * count. - */ - - repititions = 1; - if (argndx < argc) - { - repititions = strtol(argv[argndx], NULL, 16); - if (repititions < 1) - { - i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); - return ERROR; - } - - argndx++; - } - - if (argndx != argc) - { - i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); - return ERROR; - } - - /* Get a handle to the I2C bus */ - - dev = up_i2cinitialize(i2ctool->bus); - if (!dev) - { - i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); - return ERROR; - } - - /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ - - I2C_SETFREQUENCY(dev, i2ctool->freq); - I2C_SETADDRESS(dev, i2ctool->addr, 7); - - /* Loop for the requested number of repititions */ - - regaddr = i2ctool->regaddr; - ret = OK; - - for (i = 0; i < repititions; i++) - { - /* If we are performing an address-in-address test, then use the register - * address as the value to write. - */ - - if (addrinaddr) - { - wrvalue = regaddr; - } - - /* Write to the I2C bus */ - - ret = i2ctool_set(i2ctool, dev, regaddr, (uint16_t)wrvalue); - if (ret == OK) - { - /* Read the value back from the I2C bus */ - - ret = i2ctool_get(i2ctool, dev, regaddr, &rdvalue); - } - - /* Display the result */ - - if (ret == OK) - { - i2ctool_printf(i2ctool, "VERIFY Bus: %d Addr: %02x Subaddr: %02x Wrote: ", - i2ctool->bus, i2ctool->addr, i2ctool->regaddr); - - if (i2ctool->width == 8) - { - i2ctool_printf(i2ctool, "%02x Read: %02x", (int)wrvalue, (int)rdvalue); - } - else - { - i2ctool_printf(i2ctool, "%04x Read: %04x", (int)wrvalue, (int)rdvalue); - } - - if (wrvalue != rdvalue) - { - i2ctool_printf(i2ctool, " <<< FAILURE\n"); - } - else - { - i2ctool_printf(i2ctool, "\n"); - } - } - else - { - i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); - break; - } - - /* Auto-increment the address if so configured */ - - if (i2ctool->autoincr) - { - regaddr++; - } - } - - (void)up_i2cuninitialize(dev); - return ret; -} diff --git a/apps/system/i2c/i2ctool.h b/apps/system/i2c/i2ctool.h deleted file mode 100644 index 4ff26d03e..000000000 --- a/apps/system/i2c/i2ctool.h +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** - * apps/system/i2c/i2ctool.h - * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#ifndef __APPS_SYSTEM_I2C_I2CTOOLS_H -#define __APPS_SYSTEM_I2C_I2CTOOLS_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include <nuttx/config.h> -#include <nuttx/compiler.h> - -#include <sys/types.h> -#include <stdio.h> -#include <stdint.h> -#include <stdbool.h> -#include <errno.h> - -#include <nuttx/i2c.h> - -/**************************************************************************** - * Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ -/* CONFIG_I2CTOOL_BUILTIN - Build the tools as an NSH built-in command - * CONFIG_I2CTOOL_MINBUS - Smallest bus index supported by the hardware (default 0). - * CONFIG_I2CTOOL_MAXBUS - Largest bus index supported by the hardware (default 3) - * CONFIG_I2CTOOL_MINADDR - Minium device address (default: 0x03) - * CONFIG_I2CTOOL_MAXADDR - Largest device address (default: 0x77) - * CONFIG_I2CTOOL_MAXREGADDR - Largest register address (default: 0xff) - * CONFIG_I2CTOOL_DEFFREQ - Default frequency (default: 4000000) - */ - -#ifndef CONFIG_I2C_TRANSFER -# error "CONFIG_I2C_TRANSFER is required in the configuration" -#endif - -#ifndef CONFIG_I2CTOOL_MINBUS -# define CONFIG_I2CTOOL_MINBUS 0 -#endif - -#ifndef CONFIG_I2CTOOL_MAXBUS -# define CONFIG_I2CTOOL_MAXBUS 3 -#endif - -#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 - -#ifndef CONFIG_I2CTOOL_DEFFREQ -# define CONFIG_I2CTOOL_DEFFREQ 100000 -#endif - -/* This is the maximum number of arguments that will be accepted for a - * command. The only real limit is in the OS configuration that limits - * the number of parameters passed to a task. - */ - -#define MAX_ARGUMENTS (CONFIG_MAX_TASK_ARGS-1) - -/* Maximum size of one command line */ - -#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 -# define i2c_output(v, fmt...) printf(v, ##fmt) -#else -# define i2c_output printf -#endif - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -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 */ - bool autoincr; /* [-i|j], Auto increment|don't increment regaddr on repititions */ - uint32_t freq; /* [-f freq] I2C frequency */ - - /* 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, FAR char **argv); - -struct cmdmap_s -{ - 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 */ -}; - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern const char g_i2cargrequired[]; -extern const char g_i2carginvalid[]; -extern const char g_i2cargrange[]; -extern const char g_i2ccmdnotfound[]; -extern const char g_i2ctoomanyargs[]; -extern const char g_i2ccmdfailed[]; -extern const char g_i2cxfrerror[]; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/* Message handler */ - -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, ...); -void i2ctool_flush(FAR struct i2ctool_s *i2ctool); - -/* Command handlers */ - -int i2ccmd_bus(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); -int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); - -/* I2C access functions */ - -int i2ctool_get(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t addr, uint16_t *result); -int i2ctool_set(FAR struct i2ctool_s *i2ctool, FAR struct i2c_dev_s *dev, - uint8_t regaddr, uint16_t value); - -/* 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 */ |