aboutsummaryrefslogtreecommitdiffstats
path: root/testex
diff options
context:
space:
mode:
authorRocco Marco Guglielmi <roccomarco.guglielmi@gmail.com>2018-03-10 13:54:21 +0000
committerRocco Marco Guglielmi <roccomarco.guglielmi@gmail.com>2018-03-10 13:54:21 +0000
commitd4c4f24cffc301e2f578c81b65a60ccaabe997d7 (patch)
tree5e8caf23076757bf233e4b2404b8831153d8b34b /testex
parentf2f3035c3c49daa3a62aa7606455da90d350190e (diff)
downloadChibiOS-d4c4f24cffc301e2f578c81b65a60ccaabe997d7.tar.gz
ChibiOS-d4c4f24cffc301e2f578c81b65a60ccaabe997d7.tar.bz2
ChibiOS-d4c4f24cffc301e2f578c81b65a60ccaabe997d7.zip
Updated LPS25H and added a thermometer interface to the driver
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11686 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'testex')
-rw-r--r--testex/STM32/STM32F4xx/I2C-LPS25H/Makefile32
-rw-r--r--testex/STM32/STM32F4xx/I2C-LPS25H/main.c118
2 files changed, 50 insertions, 100 deletions
diff --git a/testex/STM32/STM32F4xx/I2C-LPS25H/Makefile b/testex/STM32/STM32F4xx/I2C-LPS25H/Makefile
index 3719f5377..5e16f5197 100644
--- a/testex/STM32/STM32F4xx/I2C-LPS25H/Makefile
+++ b/testex/STM32/STM32F4xx/I2C-LPS25H/Makefile
@@ -87,6 +87,9 @@ PROJECT = ch
# Imported source files and paths
CHIBIOS = ../../../..
+
+# Licensing files.
+include $(CHIBIOS)/os/license/license.mk
# Startup files.
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
# HAL-OSAL files (optional).
@@ -97,31 +100,23 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
-# Other files (optional).
+# EX files (optional).
include $(CHIBIOS)/os/ex/ST/lps25h.mk
+# Other files (optional).
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
-include $(CHIBIOS)/os/various/shell/shell.mk
# Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F401xE.ld
# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
-CSRC = $(STARTUPSRC) \
- $(KERNSRC) \
- $(PORTSRC) \
- $(OSALSRC) \
- $(HALSRC) \
- $(PLATFORMSRC) \
- $(BOARDSRC) \
- $(LPS25HSRC) \
- $(STREAMSSRC) \
- $(SHELLSRC) \
+CSRC = $(ALLCSRC) \
+ $(TESTSRC) \
main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
-CPPSRC =
+CPPSRC = $(ALLCPPSRC)
# C sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
@@ -147,10 +142,11 @@ TCPPSRC =
ASMSRC =
ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
-INCDIR = $(CHIBIOS)/os/license \
- $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
- $(HALINC) $(PLATFORMINC) $(BOARDINC) $(LPS25HINC) \
- $(STREAMSINC) $(SHELLINC)
+# List ASM source files here
+ASMSRC = $(ALLASMSRC)
+ASMXSRC = $(ALLXASMSRC)
+
+INCDIR = $(ALLINC) $(TESTINC)
#
# Project, sources and paths
@@ -200,7 +196,7 @@ CPPWARN = -Wall -Wextra -Wundef
#
# List all user C define here, like -D_DEBUG=1
-UDEFS = -DCHPRINTF_USE_FLOAT=1 -DSHELL_CMD_TEST_ENABLED=0 \
+UDEFS = -DCHPRINTF_USE_FLOAT=1 \
-DLPS25H_USE_ADVANCED=0 -DLPS25H_SHARED_I2C=0
# Define ASM defines here
diff --git a/testex/STM32/STM32F4xx/I2C-LPS25H/main.c b/testex/STM32/STM32F4xx/I2C-LPS25H/main.c
index 8aafdc19a..640a82c91 100644
--- a/testex/STM32/STM32F4xx/I2C-LPS25H/main.c
+++ b/testex/STM32/STM32F4xx/I2C-LPS25H/main.c
@@ -17,12 +17,11 @@
#include "ch.h"
#include "hal.h"
-#include "string.h"
-#include "shell.h"
#include "chprintf.h"
-
#include "lps25h.h"
+#define cls(chp) chprintf(chp, "\033[2J\033[1;1H")
+
/*===========================================================================*/
/* LPS25H related. */
/*===========================================================================*/
@@ -30,8 +29,11 @@
/* LPS25H Driver: This object represent an LPS25H instance */
static LPS25HDriver LPS25HD1;
-static int32_t rawdata;
-static float cookeddata;
+static int32_t baroraw;
+static int32_t thermoraw;
+
+static float barocooked;
+static float thermocooked;
static const I2CConfig i2ccfg = {
OPMODE_I2C,
@@ -42,9 +44,11 @@ static const I2CConfig i2ccfg = {
static const LPS25HConfig lps25hcfg = {
&I2CD1,
&i2ccfg,
+ LPS25H_SAD_VCC,
+ NULL,
+ NULL,
NULL,
NULL,
- LPS25H_SAD_VCC,
LPS25H_ODR_7HZ,
#if LPS25H_USE_ADVANCED
LPS25H_BDU_CONTINUOUS,
@@ -54,59 +58,10 @@ static const LPS25HConfig lps25hcfg = {
};
/*===========================================================================*/
-/* Command line related. */
-/*===========================================================================*/
-
-/* Enable use of special ANSI escape sequences */
-#define CHPRINTF_USE_ANSI_CODE TRUE
-#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
-
-static void cmd_read(BaseSequentialStream *chp, int argc, char *argv[]) {
-
- if (argc != 1) {
- chprintf(chp, "Usage: read [raw|cooked]\r\n");
- return;
- }
-
- while (chnGetTimeout((BaseChannel *)chp, 150) == Q_TIMEOUT) {
- if (!strcmp (argv[0], "raw")) {
-#if CHPRINTF_USE_ANSI_CODE
- chprintf(chp, "\033[2J\033[1;1H");
-#endif
- barometerReadRaw(&LPS25HD1, &rawdata);
- chprintf(chp, "LPS25H Barometer raw data...\r\n");
- chprintf(chp, "RAW: %d\r\n", rawdata);
- }
- else if (!strcmp (argv[0], "cooked")) {
-#if CHPRINTF_USE_ANSI_CODE
- chprintf(chp, "\033[2J\033[1;1H");
-#endif
- barometerReadCooked(&LPS25HD1, &cookeddata);
- chprintf(chp, "LPS25H Barometer cooked data...\r\n");
- chprintf(chp, "COOCKED: %.4f hPa\r\n", cookeddata);
- }
- else {
- chprintf(chp, "Usage: read [raw|cooked]\r\n");
- return;
- }
- }
- chprintf(chp, "Stopped\r\n");
-}
-
-static const ShellCommand commands[] = {
- {"read", cmd_read},
- {NULL, NULL}
-};
-
-static const ShellConfig shell_cfg1 = {
- (BaseSequentialStream *)&SD2,
- commands
-};
-
-/*===========================================================================*/
-/* Main code. */
+/* Generic code. */
/*===========================================================================*/
+static BaseSequentialStream* chp = (BaseSequentialStream*)&SD2;
/*
* LED blinker thread, times are in milliseconds.
*/
@@ -116,9 +71,7 @@ static THD_FUNCTION(Thread1, arg) {
(void)arg;
chRegSetThreadName("blinker");
while (true) {
- palClearPad(GPIOA, GPIOA_LED_GREEN);
- chThdSleepMilliseconds(500);
- palSetPad(GPIOA, GPIOA_LED_GREEN);
+ palToggleLine(LINE_LED_GREEN);
chThdSleepMilliseconds(500);
}
}
@@ -138,43 +91,44 @@ int main(void) {
halInit();
chSysInit();
+ /* Configuring I2C SCK and I2C SDA related GPIOs .*/
palSetLineMode(LINE_ARD_D15, PAL_MODE_ALTERNATE(4) |
PAL_STM32_OSPEED_HIGHEST | PAL_STM32_OTYPE_OPENDRAIN);
palSetLineMode(LINE_ARD_D14, PAL_MODE_ALTERNATE(4) |
PAL_STM32_OSPEED_HIGHEST | PAL_STM32_OTYPE_OPENDRAIN);
- /*
- * Activates the serial driver 2 using the driver default configuration.
- */
+ /* Activates the serial driver 1 using the driver default configuration.*/
sdStart(&SD2, NULL);
- /*
- * Creates the blinker thread.
- */
+ /* Creates the blinker thread.*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
- /*
- * LPS25H Object Initialization
- */
+ /* LPS25H Object Initialization.*/
lps25hObjectInit(&LPS25HD1);
- /*
- * Activates the LPS25H driver.
- */
+ /* Activates the LPS25H driver.*/
lps25hStart(&LPS25HD1, &lps25hcfg);
- /*
- * Shell manager initialization.
- */
- shellInit();
+ /* Normal main() thread activity, printing MEMS data on the SD2. */
+ while (true) {
+ lps25hBarometerReadRaw(&LPS25HD1, &baroraw);
+ chprintf(chp, "LPS25HD1 Barometer raw data...\r\n");
+ chprintf(chp, "Pres: %d\r\n", baroraw);
+
+ lps25hThermometerReadRaw(&LPS25HD1, &thermoraw);
+ chprintf(chp, "LPS25HD1 Thermometer raw data...\r\n");
+ chprintf(chp, "Temp: %d\r\n", &thermoraw);
+
+ lps25hBarometerReadCooked(&LPS25HD1, &barocooked);
+ chprintf(chp, "LPS25HD1 Barometer cooked data...\r\n");
+ chprintf(chp, "Pres: %.2f\r\n", barocooked);
- while(TRUE) {
+ lps25hThermometerReadCooked(&LPS25HD1, &thermocooked);
+ chprintf(chp, "LPS25HD1 Thermometer cooked data...\r\n");
+ chprintf(chp, "Temp: %.2f\r\n", thermocooked);
- thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE,
- "shell", NORMALPRIO + 1,
- shellThread, (void *)&shell_cfg1);
- chThdWait(shelltp); /* Waiting termination. */
- chThdSleepMilliseconds(1000);
+ chThdSleepMilliseconds(100);
+ cls(chp);
}
lps25hStop(&LPS25HD1);
}