diff --git a/configs/dk-tm4c129x/src/Makefile b/configs/dk-tm4c129x/src/Makefile index 8f9643144ca..48420d6d1fe 100644 --- a/configs/dk-tm4c129x/src/Makefile +++ b/configs/dk-tm4c129x/src/Makefile @@ -57,7 +57,7 @@ CSRCS += tm4c_timer.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += tm4c_nsh.c +CSRCS += tm4c_appinit.c endif ifeq ($(CONFIG_I2C_LM75),y) diff --git a/configs/dk-tm4c129x/src/dk-tm4c129x.h b/configs/dk-tm4c129x/src/dk-tm4c129x.h index 37d79c5f55d..11567e8ec17 100644 --- a/configs/dk-tm4c129x/src/dk-tm4c129x.h +++ b/configs/dk-tm4c129x/src/dk-tm4c129x.h @@ -60,6 +60,13 @@ # undef CONFIG_TIVA_SSI0 #endif +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#define HAVE_I2CTOOL 1 +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* LED definitions ******************************************************************/ /* The TMC4C123G LaunchPad has a single RGB LED. There is only one visible LED which * will vary in color. But, from the standpoint of the firmware, this appears as diff --git a/configs/dk-tm4c129x/src/tm4c_nsh.c b/configs/dk-tm4c129x/src/tm4c_appinit.c similarity index 92% rename from configs/dk-tm4c129x/src/tm4c_nsh.c rename to configs/dk-tm4c129x/src/tm4c_appinit.c index b0567d7b357..bd6c1b4b6b9 100644 --- a/configs/dk-tm4c129x/src/tm4c_nsh.c +++ b/configs/dk-tm4c129x/src/tm4c_appinit.c @@ -1,5 +1,5 @@ /**************************************************************************** - * config/dk-tm4c129x/src/tm4c_nsh.c + * config/dk-tm4c129x/src/tm4c_appinit.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -43,10 +43,6 @@ #include "dk-tm4c129x.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/configs/dk-tm4c129x/src/tm4c_bringup.c b/configs/dk-tm4c129x/src/tm4c_bringup.c index af713c69116..16ebb76ed9e 100644 --- a/configs/dk-tm4c129x/src/tm4c_bringup.c +++ b/configs/dk-tm4c129x/src/tm4c_bringup.c @@ -1,7 +1,7 @@ /**************************************************************************** * config/dk-tm4c129x/src/tm4c_bringup.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -41,8 +41,10 @@ #include +#include #include +#include "tiva_i2c.h" #include "dk-tm4c129x.h" /**************************************************************************** @@ -63,6 +65,87 @@ # define TMP100_DEVNAME "/dev/temp" #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tm4c_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void tm4c_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = tiva_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + tiva_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: tm4c_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void tm4c_i2ctool(void) +{ +#ifdef CONFIG_TIVA_I2C0 + tm4c_i2c_register(0); +#endif +#ifdef CONFIG_TIVA_I2C1 + tm4c_i2c_register(1); +#endif +#ifdef CONFIG_TIVA_I2C2 + tm4c_i2c_register(2); +#endif +#ifdef CONFIG_TIVA_I2C3 + tm4c_i2c_register(3); +#endif +#ifdef CONFIG_TIVA_I2C4 + tm4c_i2c_register(4); +#endif +#ifdef CONFIG_TIVA_I2C5 + tm4c_i2c_register(5); +#endif +#ifdef CONFIG_TIVA_I2C6 + tm4c_i2c_register(6); +#endif +#ifdef CONFIG_TIVA_I2C7 + tm4c_i2c_register(7); +#endif +#ifdef CONFIG_TIVA_I2C8 + tm4c_i2c_register(8); +#endif +#ifdef CONFIG_TIVA_I2C9 + tm4c_i2c_register(9); +#endif +} +#else +# define tm4c_i2ctool() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -81,6 +164,10 @@ int tm4c_bringup(void) int ret; #endif + /* Register I2C drivers on behalf of the I2C tool */ + + tm4c_i2ctool(); + #ifdef HAVE_TMP100 /* Initialize and register the TMP-100 Temperature Sensor driver. */ diff --git a/configs/fire-stm32v2/src/Makefile b/configs/fire-stm32v2/src/Makefile index 8e9aaa3a767..339d2da069a 100644 --- a/configs/fire-stm32v2/src/Makefile +++ b/configs/fire-stm32v2/src/Makefile @@ -53,7 +53,7 @@ CSRCS += stm32_buttons.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += stm32_nsh.c +CSRCS += stm32_appinit.c endif ifeq ($(CONFIG_ENC28J60),y) diff --git a/configs/fire-stm32v2/src/fire-stm32v2.h b/configs/fire-stm32v2/src/fire-stm32v2.h index 5309f751355..c9868767a9f 100644 --- a/configs/fire-stm32v2/src/fire-stm32v2.h +++ b/configs/fire-stm32v2/src/fire-stm32v2.h @@ -66,6 +66,13 @@ # warning "The M3 Wildfire only supports CAN1" #endif +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#define HAVE_I2CTOOL 1 +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* M3 Wildfire GPIOs ****************************************************************/ /* Camera * diff --git a/configs/fire-stm32v2/src/stm32_nsh.c b/configs/fire-stm32v2/src/stm32_appinit.c similarity index 76% rename from configs/fire-stm32v2/src/stm32_nsh.c rename to configs/fire-stm32v2/src/stm32_appinit.c index 69218abeb82..8c45062a8f3 100644 --- a/configs/fire-stm32v2/src/stm32_nsh.c +++ b/configs/fire-stm32v2/src/stm32_appinit.c @@ -1,5 +1,5 @@ /**************************************************************************** - * config/fire-stm32v2/src/stm32_nsh.c + * config/fire-stm32v2/src/stm32_appinit.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -45,8 +45,10 @@ #include #include +#include #include "stm32.h" +#include "stm32_i2c.h" #include "fire-stm32v2.h" /**************************************************************************** @@ -124,6 +126,66 @@ # undef HAVE_USBDEV #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void stm32_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = stm32_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + stm32_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: stm32_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void stm32_i2ctool(void) +{ +#ifdef CONFIG_STM32_I2C1 + stm32_i2c_register(1); +#endif +#ifdef CONFIG_STM32_I2C2 + stm32_i2c_register(2); +#endif +#ifdef CONFIG_STM32_I2C3 + stm32_i2c_register(3); +#endif +} +#else +# define stm32_i2ctool() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -142,9 +204,13 @@ int board_app_initialize(void) int ret; #endif - /* Initialize and register the W25 FLASH file system. */ + /* Register I2C drivers on behalf of the I2C tool */ + + stm32_i2ctool(); #ifdef HAVE_W25 + /* Initialize and register the W25 FLASH file system. */ + ret = stm32_w25initialize(CONFIG_NSH_W25MINOR); if (ret < 0) { @@ -154,9 +220,9 @@ int board_app_initialize(void) } #endif +#ifdef HAVE_MMCSD /* Initialize the SDIO-based MMC/SD slot */ -#ifdef HAVE_MMCSD ret = stm32_sdinitialize(CONFIG_NSH_MMCSDMINOR); if (ret < 0) { @@ -165,5 +231,6 @@ int board_app_initialize(void) return ret; } #endif + return OK; } diff --git a/configs/fire-stm32v2/src/stm32_composite.c b/configs/fire-stm32v2/src/stm32_composite.c index 33d081fa6b6..4cc8d8e2292 100644 --- a/configs/fire-stm32v2/src/stm32_composite.c +++ b/configs/fire-stm32v2/src/stm32_composite.c @@ -70,7 +70,7 @@ int composite_archinitialize(void) { /* If system/composite is built as an NSH command, then SD slot should - * already have been initialized in board_app_initialize() (see stm32_nsh.c). + * already have been initialized in board_app_initialize() (see stm32_appinit.c). * In this case, there is nothing further to be done here. * * NOTE: CONFIG_NSH_BUILTIN_APPS is not a fool-proof indication that NSH diff --git a/configs/fire-stm32v2/src/stm32_usbmsc.c b/configs/fire-stm32v2/src/stm32_usbmsc.c index 1d34a600839..96157cdf7ef 100644 --- a/configs/fire-stm32v2/src/stm32_usbmsc.c +++ b/configs/fire-stm32v2/src/stm32_usbmsc.c @@ -71,7 +71,7 @@ int usbmsc_archinitialize(void) { /* If system/usbmsc is built as an NSH command, then SD slot should - * already have been initialized in board_app_initialize() (see stm32_nsh.c). + * already have been initialized in board_app_initialize() (see stm32_appinit.c). * In this case, there is nothing further to be done here. */ diff --git a/configs/lpc4337-ws/src/Makefile b/configs/lpc4337-ws/src/Makefile index 5d1e4e3e0aa..c2a57984a5d 100644 --- a/configs/lpc4337-ws/src/Makefile +++ b/configs/lpc4337-ws/src/Makefile @@ -39,7 +39,7 @@ ASRCS = CSRCS = lpc43_boot.c ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += lpc43_nsh.c +CSRCS += lpc43_appinit.c endif ifeq ($(CONFIG_LPC43_ADC0),y) diff --git a/configs/lpc4337-ws/src/lpc4337-ws.h b/configs/lpc4337-ws/src/lpc4337-ws.h index d65d78e4ead..7c31fe745be 100644 --- a/configs/lpc4337-ws/src/lpc4337-ws.h +++ b/configs/lpc4337-ws/src/lpc4337-ws.h @@ -46,6 +46,17 @@ #include "lpc43_pinconfig.h" #include "lpc43_gpio.h" +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#define HAVE_I2CTOOL 1 +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /**************************************************************************** * Public data ****************************************************************************/ diff --git a/configs/lpc4337-ws/src/lpc43_appinit.c b/configs/lpc4337-ws/src/lpc43_appinit.c new file mode 100644 index 00000000000..83b8cddc1e9 --- /dev/null +++ b/configs/lpc4337-ws/src/lpc43_appinit.c @@ -0,0 +1,127 @@ +/**************************************************************************** + * configs/lpc4337-ws/src/lpc43_appinit.c + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include +#include + +#include "lpc43_i2c.h" +#include "chip.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lpc43_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void lpc43_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = lpc43_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + lpc43_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: lpc43_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void lpc43_i2ctool(void) +{ +#ifdef CONFIG_LPC43_I2C0 + lpc43_i2c_register(0); +#endif +#ifdef CONFIG_STM32_I2C1 + lpc43_i2c_register(1); +#endif +} +#else +# define lpc43_i2ctool() +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform architecture specific initialization + * + ****************************************************************************/ + +int board_app_initialize(void) +{ + /* Register I2C drivers on behalf of the I2C tool */ + + lpc43_i2ctool(); + return OK; +} diff --git a/configs/lpc4337-ws/src/lpc43_nsh.c b/configs/lpc4337-ws/src/lpc43_nsh.c deleted file mode 100644 index 466bc3f1a4b..00000000000 --- a/configs/lpc4337-ws/src/lpc43_nsh.c +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * configs/lpc4337-ws/src/lpc43-nsh.c - * - * Copyright (C) 2016 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include - -#include "chip.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform architecture specific initialization - * - ****************************************************************************/ - -int board_app_initialize(void) -{ - return OK; -} diff --git a/configs/lpc4370-link2/src/Makefile b/configs/lpc4370-link2/src/Makefile index 3dbb22559fa..798b87e0644 100644 --- a/configs/lpc4370-link2/src/Makefile +++ b/configs/lpc4370-link2/src/Makefile @@ -39,7 +39,7 @@ ASRCS = CSRCS = lpc43_boot.c ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += lpc43_nsh.c +CSRCS += lpc43_appinit.c endif ifeq ($(CONFIG_ARCH_FPU),y) diff --git a/configs/lpc4370-link2/src/lpc4370-link2.h b/configs/lpc4370-link2/src/lpc4370-link2.h index 9fe33877511..887d5b94f49 100644 --- a/configs/lpc4370-link2/src/lpc4370-link2.h +++ b/configs/lpc4370-link2/src/lpc4370-link2.h @@ -50,6 +50,13 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#define HAVE_I2CTOOL 1 +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* LED definitions **********************************************************/ /* The LPC4370-LINK2 has one user-controllable LED labelled D6 controlled by * the signal LED_3V3: diff --git a/configs/lpc4370-link2/src/lpc43_appinit.c b/configs/lpc4370-link2/src/lpc43_appinit.c new file mode 100644 index 00000000000..74fce0eb1f4 --- /dev/null +++ b/configs/lpc4370-link2/src/lpc43_appinit.c @@ -0,0 +1,127 @@ +/**************************************************************************** + * config/lpc4370-link2/src/lpc43_appinit.c + * + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include +#include + +#include +#include + +#include "lpc43_i2c.h" +#include "chip.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lpc43_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void lpc43_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = lpc43_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + lpc43_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: lpc43_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void lpc43_i2ctool(void) +{ +#ifdef CONFIG_LPC43_I2C0 + lpc43_i2c_register(0); +#endif +#ifdef CONFIG_STM32_I2C1 + lpc43_i2c_register(1); +#endif +} +#else +# define lpc43_i2ctool() +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform architecture specific initialization + * + ****************************************************************************/ + +int board_app_initialize(void) +{ + /* Register I2C drivers on behalf of the I2C tool */ + + lpc43_i2ctool(); + return OK; +} diff --git a/configs/lpc4370-link2/src/lpc43_nsh.c b/configs/lpc4370-link2/src/lpc43_nsh.c deleted file mode 100644 index 51ca33a8d29..00000000000 --- a/configs/lpc4370-link2/src/lpc43_nsh.c +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * config/lpc4370-link2/src/lpc43_nsh.c - * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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 - -#include -#include -#include - -#include - -#include "chip.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: board_app_initialize - * - * Description: - * Perform architecture specific initialization - * - ****************************************************************************/ - -int board_app_initialize(void) -{ - return OK; -} diff --git a/configs/sama5d4-ek/src/Makefile b/configs/sama5d4-ek/src/Makefile index 015a33204f0..3b13ea848a4 100644 --- a/configs/sama5d4-ek/src/Makefile +++ b/configs/sama5d4-ek/src/Makefile @@ -113,7 +113,7 @@ CSRCS += sam_maxtouch.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += sam_nsh.c sam_bringup.c +CSRCS += sam_appinit.c sam_bringup.c else ifeq ($(CONFIG_BOARD_INITIALIZE),y) CSRCS += sam_bringup.c diff --git a/configs/sama5d4-ek/src/sam_nsh.c b/configs/sama5d4-ek/src/sam_appinit.c similarity index 98% rename from configs/sama5d4-ek/src/sam_nsh.c rename to configs/sama5d4-ek/src/sam_appinit.c index 228fe954aa4..9632e33353f 100644 --- a/configs/sama5d4-ek/src/sam_nsh.c +++ b/configs/sama5d4-ek/src/sam_appinit.c @@ -1,5 +1,5 @@ /**************************************************************************** - * config/sama5d4-ek/src/sam_nsh.c + * config/sama5d4-ek/src/sam_appinit.c * * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/configs/sama5d4-ek/src/sam_bringup.c b/configs/sama5d4-ek/src/sam_bringup.c index 547ee4b5b6e..2c0ca5cc8da 100644 --- a/configs/sama5d4-ek/src/sam_bringup.c +++ b/configs/sama5d4-ek/src/sam_bringup.c @@ -52,7 +52,9 @@ #include #include +#include +#include "sam_twi.h" #include "sama5d4-ek.h" #ifdef HAVE_ROMFS @@ -75,6 +77,69 @@ # define SYSLOG dbg #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = sam_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + sam_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: sam_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2ctool(void) +{ +#ifdef CONFIG_SAMA5_TWI0 + sam_i2c_register(0); +#endif +#ifdef CONFIG_SAMA5_TWI1 + sam_i2c_register(1); +#endif +#ifdef CONFIG_SAMA5_TWI2 + sam_i2c_register(2); +#endif +#ifdef CONFIG_SAMA5_TWI3 + sam_i2c_register(3); +#endif +} +#else +# define sam_i2ctool() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -96,6 +161,10 @@ int sam_bringup(void) int ret; #endif + /* Register I2C drivers on behalf of the I2C tool */ + + sam_i2ctool(); + #ifdef HAVE_NAND /* Initialize the NAND driver */ diff --git a/configs/sama5d4-ek/src/sama5d4-ek.h b/configs/sama5d4-ek/src/sama5d4-ek.h index e92cd5f9a3b..de3dac7cb9d 100644 --- a/configs/sama5d4-ek/src/sama5d4-ek.h +++ b/configs/sama5d4-ek/src/sama5d4-ek.h @@ -1,7 +1,7 @@ /************************************************************************************ * configs/sama5d4-ek/src/sama5d4-ek.h * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -71,6 +71,7 @@ #define HAVE_PMIC 1 #define HAVE_ELF 1 #define HAVE_ROMFS 1 +#define HAVE_I2CTOOL 1 /* HSMCI */ /* Can't support MMC/SD if the card interface(s) are not enable */ @@ -478,6 +479,12 @@ # undef HAVE_ROMFS #endif +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* procfs File System */ #ifdef CONFIG_FS_PROCFS diff --git a/configs/same70-xplained/src/Makefile b/configs/same70-xplained/src/Makefile index 18a3562ff27..ad1d3d4885e 100644 --- a/configs/same70-xplained/src/Makefile +++ b/configs/same70-xplained/src/Makefile @@ -43,7 +43,7 @@ CSRCS += sam_sdram.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += sam_nsh.c sam_bringup.c +CSRCS += sam_appinit.c sam_bringup.c else ifeq ($(CONFIG_BOARD_INITIALIZE),y) CSRCS += sam_bringup.c endif diff --git a/configs/same70-xplained/src/sam_nsh.c b/configs/same70-xplained/src/sam_appinit.c similarity index 98% rename from configs/same70-xplained/src/sam_nsh.c rename to configs/same70-xplained/src/sam_appinit.c index 5660574411b..2026dd4836e 100644 --- a/configs/same70-xplained/src/sam_nsh.c +++ b/configs/same70-xplained/src/sam_appinit.c @@ -1,5 +1,5 @@ /**************************************************************************** - * config/same70-xplained/src/sam_nsh.c + * config/same70-xplained/src/sam_appinit.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/configs/same70-xplained/src/sam_bringup.c b/configs/same70-xplained/src/sam_bringup.c index 9d1d1c99fe7..e5631b89308 100644 --- a/configs/same70-xplained/src/sam_bringup.c +++ b/configs/same70-xplained/src/sam_bringup.c @@ -1,7 +1,7 @@ /**************************************************************************** * config/same70-xplained/src/sam_bringup.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -54,7 +54,9 @@ #include #include #include +#include +#include "sam_twihs.h" #include "same70-xplained.h" #ifdef HAVE_PROGMEM_CHARDEV @@ -82,6 +84,66 @@ # define SYSLOG dbg #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = sam_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + sam_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: sam_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2ctool(void) +{ +#ifdef CONFIG_SAMV7_TWIHS0 + sam_i2c_register(0); +#endif +#ifdef CONFIG_SAMV7_TWIHS1 + sam_i2c_register(1); +#endif +#ifdef CONFIG_SAMV7_TWIHS2 + sam_i2c_register(2); +#endif +} +#else +# define sam_i2ctool() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -103,6 +165,10 @@ int sam_bringup(void) #endif int ret; + /* Register I2C drivers on behalf of the I2C tool */ + + sam_i2ctool(); + #ifdef HAVE_MACADDR /* Read the Ethernet MAC address from the AT24 FLASH and configure the * Ethernet driver with that address. diff --git a/configs/same70-xplained/src/same70-xplained.h b/configs/same70-xplained/src/same70-xplained.h index 1c823d0cfb1..f377d2ba2f3 100644 --- a/configs/same70-xplained/src/same70-xplained.h +++ b/configs/same70-xplained/src/same70-xplained.h @@ -62,6 +62,7 @@ #define HAVE_MACADDR 1 #define HAVE_MTDCONFIG 1 #define HAVE_PROGMEM_CHARDEV 1 +#define HAVE_I2CTOOL 1 /* HSMCI */ /* Can't support MMC/SD if the card interface is not enabled */ @@ -190,6 +191,12 @@ #define PROGMEM_MTD_MINOR 0 +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* procfs File System */ #ifdef CONFIG_FS_PROCFS diff --git a/configs/samv71-xult/src/Makefile b/configs/samv71-xult/src/Makefile index fdb9819edbd..2520789fcb2 100644 --- a/configs/samv71-xult/src/Makefile +++ b/configs/samv71-xult/src/Makefile @@ -43,7 +43,7 @@ CSRCS += sam_sdram.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += sam_nsh.c sam_bringup.c +CSRCS += sam_appinit.c sam_bringup.c else ifeq ($(CONFIG_BOARD_INITIALIZE),y) CSRCS += sam_bringup.c endif diff --git a/configs/samv71-xult/src/sam_nsh.c b/configs/samv71-xult/src/sam_appinit.c similarity index 98% rename from configs/samv71-xult/src/sam_nsh.c rename to configs/samv71-xult/src/sam_appinit.c index 40ac938d670..59b977ca5f7 100644 --- a/configs/samv71-xult/src/sam_nsh.c +++ b/configs/samv71-xult/src/sam_appinit.c @@ -1,5 +1,5 @@ /**************************************************************************** - * config/samv71-xult/src/sam_nsh.c + * config/samv71-xult/src/sam_appinit.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/configs/samv71-xult/src/sam_bringup.c b/configs/samv71-xult/src/sam_bringup.c index 83be9db8e19..7ce0e86593b 100644 --- a/configs/samv71-xult/src/sam_bringup.c +++ b/configs/samv71-xult/src/sam_bringup.c @@ -54,7 +54,9 @@ #include #include #include +#include +#include "sam_twihs.h" #include "samv71-xult.h" #if defined(HAVE_S25FL1) || defined(HAVE_PROGMEM_CHARDEV) @@ -101,6 +103,66 @@ # define SYSLOG dbg #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sam_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = sam_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + sam_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: sam_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void sam_i2ctool(void) +{ +#ifdef CONFIG_SAMV7_TWIHS0 + sam_i2c_register(0); +#endif +#ifdef CONFIG_SAMV7_TWIHS1 + sam_i2c_register(1); +#endif +#ifdef CONFIG_SAMV7_TWIHS2 + sam_i2c_register(2); +#endif +} +#else +# define sam_i2ctool() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -130,6 +192,10 @@ int sam_bringup(void) #endif int ret; + /* Register I2C drivers on behalf of the I2C tool */ + + sam_i2ctool(); + #if defined(HAVE_RTC_PCF85263) /* Get an instance of the TWIHS0 I2C interface */ diff --git a/configs/samv71-xult/src/samv71-xult.h b/configs/samv71-xult/src/samv71-xult.h index 4b74c625590..238fd0f7c79 100644 --- a/configs/samv71-xult/src/samv71-xult.h +++ b/configs/samv71-xult/src/samv71-xult.h @@ -70,6 +70,7 @@ #define HAVE_AUDIO_NULL 1 #define HAVE_RTC_DSXXXX 1 #define HAVE_RTC_PCF85263 1 +#define HAVE_I2CTOOL 1 /* HSMCI */ /* Can't support MMC/SD if the card interface is not enabled */ @@ -352,6 +353,12 @@ # define PCF85263_I2C_ADDRESS 0x51 #endif +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* SAMV71-XULT GPIO Pin Definitions *************************************************/ /* Ethernet MAC. diff --git a/configs/stm3210e-eval/src/Makefile b/configs/stm3210e-eval/src/Makefile index 84ecd432911..3e6d599ea6a 100644 --- a/configs/stm3210e-eval/src/Makefile +++ b/configs/stm3210e-eval/src/Makefile @@ -45,7 +45,7 @@ CSRCS += stm32_selectlcd.c stm32_deselectlcd.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += stm32_nsh.c +CSRCS += stm32_appinit.c endif ifeq ($(CONFIG_ADC),y) diff --git a/configs/stm3210e-eval/src/stm3210e-eval.h b/configs/stm3210e-eval/src/stm3210e-eval.h index b0711d0c6c4..aa129bf9ce7 100644 --- a/configs/stm3210e-eval/src/stm3210e-eval.h +++ b/configs/stm3210e-eval/src/stm3210e-eval.h @@ -65,6 +65,13 @@ # warning "The STM3210E-EVAL only supports CAN1" #endif +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#define HAVE_I2CTOOL 1 +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* STM3210E-EVAL GPIOs **************************************************************/ /* LEDs */ diff --git a/configs/stm3210e-eval/src/stm32_nsh.c b/configs/stm3210e-eval/src/stm32_appinit.c similarity index 79% rename from configs/stm3210e-eval/src/stm32_nsh.c rename to configs/stm3210e-eval/src/stm32_appinit.c index 466152ffb13..abc4e5881d0 100644 --- a/configs/stm3210e-eval/src/stm32_nsh.c +++ b/configs/stm3210e-eval/src/stm32_appinit.c @@ -1,7 +1,7 @@ /**************************************************************************** - * config/stm3210e_eval/src/stm32_nsh.c + * config/stm3210e_eval/src/stm32_appinit.c * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ #include #include +#include #ifdef CONFIG_STM32_SPI1 # include @@ -57,6 +58,7 @@ #endif #include "stm32.h" +#include "stm32_i2c.h" #include "stm3210e-eval.h" /**************************************************************************** @@ -106,6 +108,66 @@ # define CONFIG_NSH_MMCSDMINOR 0 #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void stm32_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = stm32_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + stm32_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: stm32_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void stm32_i2ctool(void) +{ +#ifdef CONFIG_STM32_I2C1 + stm32_i2c_register(1); +#endif +#ifdef CONFIG_STM32_I2C2 + stm32_i2c_register(2); +#endif +#ifdef CONFIG_STM32_I2C3 + stm32_i2c_register(3); +#endif +} +#else +# define stm32_i2ctool() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -131,6 +193,10 @@ int board_app_initialize(void) int ret; #endif + /* Register I2C drivers on behalf of the I2C tool */ + + stm32_i2ctool(); + /* Configure SPI-based devices */ #ifdef CONFIG_STM32_SPI1 diff --git a/configs/stm3210e-eval/src/stm32_composite.c b/configs/stm3210e-eval/src/stm32_composite.c index 03089f892e4..2753f9a0d6c 100644 --- a/configs/stm3210e-eval/src/stm32_composite.c +++ b/configs/stm3210e-eval/src/stm32_composite.c @@ -91,7 +91,7 @@ int composite_archinitialize(void) { /* If system/composite is built as an NSH command, then SD slot should * already have been initialized in board_app_initialize() (see - * stm32_nsh.c). In this case, there is nothing further to be done here. + * stm32_appinit.c). In this case, there is nothing further to be done here. * * NOTE: CONFIG_NSH_BUILTIN_APPS is not a fool-proof indication that NSH * was built. diff --git a/configs/stm3220g-eval/src/Makefile b/configs/stm3220g-eval/src/Makefile index 9485ac5a7d0..b68d6cbef32 100644 --- a/configs/stm3220g-eval/src/Makefile +++ b/configs/stm3220g-eval/src/Makefile @@ -69,7 +69,7 @@ CSRCS += stm32_can.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += stm32_nsh.c +CSRCS += stm32_appinit.c endif ifeq ($(CONFIG_WATCHDOG),y) diff --git a/configs/stm3220g-eval/src/stm3220g-eval.h b/configs/stm3220g-eval/src/stm3220g-eval.h index c259586e8a2..d00b0e8eaea 100644 --- a/configs/stm3220g-eval/src/stm3220g-eval.h +++ b/configs/stm3220g-eval/src/stm3220g-eval.h @@ -87,6 +87,13 @@ # warning "The STM3250G-EVAL will only support one of CAN2 and USB OTG HS" #endif +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#define HAVE_I2CTOOL 1 +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* STM3220G-EVAL GPIOs ******************************************************************************/ /* LEDs */ diff --git a/configs/stm3220g-eval/src/stm32_nsh.c b/configs/stm3220g-eval/src/stm32_appinit.c similarity index 78% rename from configs/stm3220g-eval/src/stm32_nsh.c rename to configs/stm3220g-eval/src/stm32_appinit.c index a7461bb4de1..54311e8fe82 100644 --- a/configs/stm3220g-eval/src/stm32_nsh.c +++ b/configs/stm3220g-eval/src/stm32_appinit.c @@ -1,7 +1,7 @@ /**************************************************************************** - * config/stm3220g_eval/src/stm32_nsh.c + * config/stm3220g_eval/src/stm32_appinit.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ #include #include +#include #ifdef CONFIG_STM32_SPI1 # include @@ -61,6 +62,7 @@ #endif #include "stm32.h" +#include "stm32_i2c.h" #include "stm3220g-eval.h" /**************************************************************************** @@ -119,6 +121,66 @@ # undef HAVE_USBHOST #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void stm32_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = stm32_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + stm32_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: stm32_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void stm32_i2ctool(void) +{ +#ifdef CONFIG_STM32_I2C1 + stm32_i2c_register(1); +#endif +#ifdef CONFIG_STM32_I2C2 + stm32_i2c_register(2); +#endif +#ifdef CONFIG_STM32_I2C3 + stm32_i2c_register(3); +#endif +} +#else +# define stm32_i2ctool() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -144,6 +206,10 @@ int board_app_initialize(void) int ret; #endif + /* Register I2C drivers on behalf of the I2C tool */ + + stm32_i2ctool(); + /* Configure SPI-based devices */ #ifdef CONFIG_STM32_SPI1 diff --git a/configs/stm3240g-eval/src/Makefile b/configs/stm3240g-eval/src/Makefile index bc656936bf3..7f220e50681 100644 --- a/configs/stm3240g-eval/src/Makefile +++ b/configs/stm3240g-eval/src/Makefile @@ -70,7 +70,7 @@ CSRCS += stm32_can.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += stm32_nsh.c +CSRCS += stm32_appinit.c endif ifeq ($(CONFIG_ARCH_FPU),y) diff --git a/configs/stm3240g-eval/src/stm3240g-eval.h b/configs/stm3240g-eval/src/stm3240g-eval.h index 29d7b37d1d2..696d29e6a5e 100644 --- a/configs/stm3240g-eval/src/stm3240g-eval.h +++ b/configs/stm3240g-eval/src/stm3240g-eval.h @@ -88,6 +88,13 @@ # warning "The STM3250G-EVAL will only support one of CAN2 and USB OTG HS" #endif +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#define HAVE_I2CTOOL 1 +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* STM3240G-EVAL GPIOs ******************************************************************************/ /* LEDs */ diff --git a/configs/stm3240g-eval/src/stm32_nsh.c b/configs/stm3240g-eval/src/stm32_appinit.c similarity index 78% rename from configs/stm3240g-eval/src/stm32_nsh.c rename to configs/stm3240g-eval/src/stm32_appinit.c index 31ee1ccbaec..649f6b80837 100644 --- a/configs/stm3240g-eval/src/stm32_nsh.c +++ b/configs/stm3240g-eval/src/stm32_appinit.c @@ -1,7 +1,7 @@ /**************************************************************************** - * config/stm3240g_eval/src/stm32_nsh.c + * config/stm3240g_eval/src/stm32_appinit.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,7 @@ #include #include +#include #ifdef CONFIG_STM32_SPI1 # include @@ -61,6 +62,7 @@ #endif #include "stm32.h" +#include "stm32_i2c.h" #include "stm3240g-eval.h" /**************************************************************************** @@ -125,6 +127,66 @@ # undef HAVE_USBHOST #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void stm32_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = stm32_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + stm32_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: stm32_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void stm32_i2ctool(void) +{ +#ifdef CONFIG_STM32_I2C1 + stm32_i2c_register(1); +#endif +#ifdef CONFIG_STM32_I2C2 + stm32_i2c_register(2); +#endif +#ifdef CONFIG_STM32_I2C3 + stm32_i2c_register(3); +#endif +} +#else +# define stm32_i2ctool() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -150,6 +212,10 @@ int board_app_initialize(void) int ret; #endif + /* Register I2C drivers on behalf of the I2C tool */ + + stm32_i2ctool(); + /* Configure SPI-based devices */ #ifdef CONFIG_STM32_SPI1 diff --git a/configs/tm4c1294-launchpad/src/Makefile b/configs/tm4c1294-launchpad/src/Makefile index aeb66d3ae52..73d28f01b77 100644 --- a/configs/tm4c1294-launchpad/src/Makefile +++ b/configs/tm4c1294-launchpad/src/Makefile @@ -57,7 +57,7 @@ CSRCS += tm4c_timer.c endif ifeq ($(CONFIG_NSH_ARCHINIT),y) -CSRCS += tm4c_nsh.c +CSRCS += tm4c_appinit.c endif include $(TOPDIR)/configs/Board.mk diff --git a/configs/tm4c1294-launchpad/src/tm4c1294-launchpad.h b/configs/tm4c1294-launchpad/src/tm4c1294-launchpad.h index e871249f658..ea3cf536e96 100644 --- a/configs/tm4c1294-launchpad/src/tm4c1294-launchpad.h +++ b/configs/tm4c1294-launchpad/src/tm4c1294-launchpad.h @@ -60,6 +60,13 @@ # undef CONFIG_TIVA_SSI0 #endif +/* Do we need to register I2C drivers on behalf of the I2C tool? */ + +#define HAVE_I2CTOOL 1 +#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) +# undef HAVE_I2CTOOL +#endif + /* LED definitions ******************************************************************/ /* The EK-TM4C1294XL has a four green LEDs. * diff --git a/configs/tm4c1294-launchpad/src/tm4c_nsh.c b/configs/tm4c1294-launchpad/src/tm4c_appinit.c similarity index 98% rename from configs/tm4c1294-launchpad/src/tm4c_nsh.c rename to configs/tm4c1294-launchpad/src/tm4c_appinit.c index a1fea63ca32..c360d7f00cb 100644 --- a/configs/tm4c1294-launchpad/src/tm4c_nsh.c +++ b/configs/tm4c1294-launchpad/src/tm4c_appinit.c @@ -1,5 +1,5 @@ /**************************************************************************** - * config/tm4c1294-launchpad/src/tm4c_nsh.c + * config/tm4c1294-launchpad/src/tm4c_appinit.c * * Copyright (C) 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt diff --git a/configs/tm4c1294-launchpad/src/tm4c_bringup.c b/configs/tm4c1294-launchpad/src/tm4c_bringup.c index 8fb5c53d9fb..da1778d0fda 100644 --- a/configs/tm4c1294-launchpad/src/tm4c_bringup.c +++ b/configs/tm4c1294-launchpad/src/tm4c_bringup.c @@ -41,8 +41,10 @@ #include +#include #include +#include "tiva_i2c.h" #include "tm4c1294-launchpad.h" /**************************************************************************** @@ -53,6 +55,87 @@ # define HAVE_TIMER #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: tm4c_i2c_register + * + * Description: + * Register one I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void tm4c_i2c_register(int bus) +{ + FAR struct i2c_master_s *i2c; + int ret; + + i2c = tiva_i2cbus_initialize(bus); + if (i2c == NULL) + { + dbg("ERROR: Failed to get I2C%d interface\n", bus); + } + else + { + ret = i2c_register(i2c, bus); + if (ret < 0) + { + dbg("ERROR: Failed to register I2C%d driver: %d\n", bus, ret); + tiva_i2cbus_uninitialize(i2c); + } + } +} +#endif + +/**************************************************************************** + * Name: tm4c_i2ctool + * + * Description: + * Register I2C drivers for the I2C tool. + * + ****************************************************************************/ + +#ifdef HAVE_I2CTOOL +static void tm4c_i2ctool(void) +{ +#ifdef CONFIG_TIVA_I2C0 + tm4c_i2c_register(0); +#endif +#ifdef CONFIG_TIVA_I2C1 + tm4c_i2c_register(1); +#endif +#ifdef CONFIG_TIVA_I2C2 + tm4c_i2c_register(2); +#endif +#ifdef CONFIG_TIVA_I2C3 + tm4c_i2c_register(3); +#endif +#ifdef CONFIG_TIVA_I2C4 + tm4c_i2c_register(4); +#endif +#ifdef CONFIG_TIVA_I2C5 + tm4c_i2c_register(5); +#endif +#ifdef CONFIG_TIVA_I2C6 + tm4c_i2c_register(6); +#endif +#ifdef CONFIG_TIVA_I2C7 + tm4c_i2c_register(7); +#endif +#ifdef CONFIG_TIVA_I2C8 + tm4c_i2c_register(8); +#endif +#ifdef CONFIG_TIVA_I2C9 + tm4c_i2c_register(9); +#endif +} +#else +# define tm4c_i2ctool() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -71,6 +154,10 @@ int tm4c_bringup(void) int ret; #endif + /* Register I2C drivers on behalf of the I2C tool */ + + tm4c_i2ctool(); + #ifdef HAVE_TIMER /* Initialize the timer driver */