Example of single tap and double tap detection for LSM6DSL in X-NUCLEO-IKS01A2
Dependencies: X_NUCLEO_IKS01A2 mbed
Fork of SingleDoubleTap_IKS01A2 by
Single and Double Tap Demo Application based on sensor expansion board X-NUCLEO-IKS01A2
Main function is to show how to detect the single and double tap events using the sensor expansion board and send a notification using UART to a connected PC or Desktop and display it on terminal applications like TeraTerm.
After connection has been established:
- the user can try to tap the board and then view the notification using an hyper terminal. When the single tap is detected,
the LED is switched on for a while.
- the user can press the user button to pass from the single tap detection to the double tap detection feature. The user can try to double tap the board and then view the notification using an hyper terminal. When the double tap is detected, the LED is switched on twice for a while.
- the user can press again the user button to disable the single and double tap detection feature.
- the user can press the user button to enable again the single tap detection feature and so on.
Revision 8:0e76b8668551, committed 2016-11-28
- Comitter:
- nikapov
- Date:
- Mon Nov 28 13:14:55 2016 +0000
- Parent:
- 7:4f512b172555
- Child:
- 9:3cca185e654c
- Commit message:
- Updated libs.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_IKS01A2/ST_INTERFACES.lib Mon Nov 28 13:14:55 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#a7810e7acf8d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_IKS01A2/X_NUCLEO_COMMON.lib Mon Nov 28 13:14:55 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#12be3dfc15fd
--- a/X_NUCLEO_IKS01A2/X_NUCLEO_COMMON/DbgMCU/DbgMCU.h Thu Nov 24 16:45:55 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/**
- ******************************************************************************
- * @file DbgMCU.h
- * @author AST / EST
- * @version V0.0.1
- * @date 30-March-2015
- * @brief Header file for enabling debugging in sleep modes for STM32 MCUs
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
- *
- * 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 of STMicroelectronics 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 HOLDER 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.
- *
- ******************************************************************************
- */
-
-/* Define to prevent from recursive inclusion --------------------------------*/
-#ifndef __DBG_MCU_H
-#define __DBG_MCU_H
-
-/* Includes ------------------------------------------------------------------*/
-
-/* Classes -------------------------------------------------------------------*/
-/** Helper class DbgMCU providing a default constructor which enables debugging
- * on STM32 MCUs while using sleep modes.
- */
-class DbgMCU
-{
- public:
- /** Create a DbgMCU dummy object */
- DbgMCU(void) {
- /* the following code is NOT portable */
- volatile uint32_t *dbgmcu_creg = (uint32_t*)0xE0042004;
- uint32_t tmp = *dbgmcu_creg;
-
- tmp &= ~(0xE7);
- tmp |= 0x27; // Set asynchronous communication via DBGMCU_CR (for ITM/printf)
- // tmp |= 0xE7; // Set 4-pin tracing via DBGMCU_CR (for ETM)
- *dbgmcu_creg = tmp;
- }
-};
-
-#endif /* __DBG_MCU_H */
--- a/X_NUCLEO_IKS01A2/X_NUCLEO_COMMON/DevI2C/DevI2C.h Thu Nov 24 16:45:55 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-/**
- ******************************************************************************
- * @file DevI2C.h
- * @author AST / EST
- * @version V0.0.1
- * @date 21-January-2015
- * @brief Header file for a special I2C class DevI2C which provides some
- * helper function for on-board communication
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
- *
- * 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 of STMicroelectronics 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 HOLDER 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.
- *
- ******************************************************************************
- */
-
-/* Define to prevent from recursive inclusion --------------------------------*/
-#ifndef __DEV_I2C_H
-#define __DEV_I2C_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "mbed.h"
-
-/* Classes -------------------------------------------------------------------*/
-/** Helper class DevI2C providing functions for multi-register I2C communication
- * common for a series of I2C devices
- */
-class DevI2C : public I2C
-{
- public:
- /** Create a DevI2C Master interface, connected to the specified pins
- *
- * @param sda I2C data line pin
- * @param scl I2C clock line pin
- */
- DevI2C(PinName sda, PinName scl) : I2C(sda, scl) {}
-
- /**
- * @brief Writes a buffer towards the I2C peripheral device.
- * @param pBuffer pointer to the byte-array data to send
- * @param DeviceAddr specifies the peripheral device slave address.
- * @param RegisterAddr specifies the internal address register
- * where to start writing to (must be correctly masked).
- * @param NumByteToWrite number of bytes to be written.
- * @retval 0 if ok,
- * @retval -1 if an I2C error has occured, or
- * @retval -2 on temporary buffer overflow (i.e. NumByteToWrite was too high)
- * @note On some devices if NumByteToWrite is greater
- * than one, the RegisterAddr must be masked correctly!
- */
- int i2c_write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr,
- uint16_t NumByteToWrite)
- {
- int ret;
- uint8_t tmp[TEMP_BUF_SIZE];
-
- if(NumByteToWrite >= TEMP_BUF_SIZE) return -2;
-
- /* First, send device address. Then, send data and STOP condition */
- tmp[0] = RegisterAddr;
- memcpy(tmp+1, pBuffer, NumByteToWrite);
-
- ret = write(DeviceAddr, (const char*)tmp, NumByteToWrite+1, false);
-
- if(ret) return -1;
- return 0;
- }
-
- /**
- * @brief Reads a buffer from the I2C peripheral device.
- * @param pBuffer pointer to the byte-array to read data in to
- * @param DaviceAddr specifies the peripheral device slave address.
- * @param RegisterAddr specifies the internal address register
- * where to start reading from (must be correctly masked).
- * @param NumByteToRead number of bytes to be read.
- * @retval 0 if ok,
- * @retval -1 if an I2C error has occured
- * @note On some devices if NumByteToWrite is greater
- * than one, the RegisterAddr must be masked correctly!
- */
- int i2c_read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr,
- uint16_t NumByteToRead)
- {
- int ret;
-
- /* Send device address, with no STOP condition */
- ret = write(DeviceAddr, (const char*)&RegisterAddr, 1, true);
- if(!ret) {
- /* Read data, with STOP condition */
- ret = read(DeviceAddr, (char*)pBuffer, NumByteToRead, false);
- }
-
- if(ret) return -1;
- return 0;
- }
-
- private:
- static const unsigned int TEMP_BUF_SIZE = 32;
-};
-
-#endif /* __DEV_I2C_H */
--- a/X_NUCLEO_IKS01A2/X_NUCLEO_COMMON/DevSPI/DevSPI.h Thu Nov 24 16:45:55 2016 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,302 +0,0 @@
-/**
- ******************************************************************************
- * @file DevSPI.h
- * @author AST / Software Platforms and Cloud / EST
- * @version V1.2.1
- * @date 19-February-2016
- * @brief Header file for a special SPI class DevSPI which provides some
- * helper functions for on-board communication.
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
- *
- * 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 of STMicroelectronics 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 HOLDER 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.
- *
- ******************************************************************************
- */
-
-/* Define to prevent from recursive inclusion --------------------------------*/
-#ifndef __DEV_SPI_H
-#define __DEV_SPI_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "mbed.h"
-
-/* Macros --------------------------------------------------------------------*/
-#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) /* GCC */ || \
- (defined(G_BYTE_ORDER) && (G_BYTE_ORDER == G_BIG_ENDIAN)) /* IAR */ || \
- (defined(__BIG_ENDIAN)) /* ARM */
-#define __DEV_SPI_BIG_ENDIAN
-#endif
-
-/* Classes -------------------------------------------------------------------*/
-/** Helper class DevSPI providing functions for synchronous SPI communication
- * common for a series of SPI devices.
- */
-class DevSPI : public SPI
-{
- public:
- /*
- * Create a DevSPI interface.
- * @param mosi pin name of the MOSI pin of the SPI device to be used for communication.
- * @param miso pin name of the MISO pin of the SPI device to be used for communication.
- * @param sclk pin name of the SCLK pin of the SPI device to be used for communication.
- */
- DevSPI(PinName mosi, PinName miso, PinName sclk) : SPI(mosi, miso, sclk)
- {
- /* Set default configuration. */
- setup(8, 3, 1E6);
- }
-
- /*
- * Setup the spi.
- * Typically:
- * + 8 bit data;
- * + high steady state clock;
- * + second edge capture;
- * + 1MHz clock rate.
- *
- * @param bits Number of bits per SPI frame (4 - 16)
- * @param mode Clock polarity and phase mode (0 - 3)
- * @param frequency_hz SCLK frequency in hz (default = 1MHz)
- *
- * @code
- * mode | POL PHA
- * -----+--------
- * 0 | 0 0
- * 1 | 0 1
- * 2 | 1 0
- * 3 | 1 1
- * @endcode
- */
- void setup(int bits, int mode = 0, int frequency_hz = 1E6)
- {
- /* Set given configuration. */
- format(bits, mode);
- frequency(frequency_hz);
- }
-
- /**
- * @brief Writes a buffer to the SPI peripheral device in 8-bit data mode
- * using synchronous SPI communication.
- * @param[in] pBuffer pointer to the buffer of data to send.
- * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
- * @param[in] NumBytesToWrite number of bytes to write.
- * @retval 0 if ok.
- * @retval -1 if data format error.
- * @note When using the SPI in Interrupt-mode, remember to disable interrupts
- * before calling this function and to enable them again after.
- */
- int spi_write(uint8_t* pBuffer, DigitalOut &ssel, uint16_t NumBytesToWrite)
- {
- /* Check data format */
- if(_bits != 8) return -1;
-
- /* Select the chip. */
- ssel = 0;
-
- /* Write data. */
- for (int i = 0; i < NumBytesToWrite; i++) {
- write(pBuffer[i]);
- }
-
- /* Unselect the chip. */
- ssel = 1;
-
- return 0;
- }
-
- /**
- * @brief Reads a buffer from the SPI peripheral device in 8-bit data mode
- * using synchronous SPI communication.
- * @param[out] pBuffer pointer to the buffer to read data into.
- * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
- * @param[in] NumBytesToRead number of bytes to read.
- * @retval 0 if ok.
- * @retval -1 if data format error.
- * @note When using the SPI in Interrupt-mode, remember to disable interrupts
- * before calling this function and to enable them again after.
- */
- int spi_read(uint8_t* pBuffer, DigitalOut &ssel, uint16_t NumBytesToRead)
- {
- /* Check data format */
- if(_bits != 8) return -1;
-
- /* Select the chip. */
- ssel = 0;
-
- /* Read data. */
- for (int i = 0; i < NumBytesToRead; i++) {
- pBuffer[i] = write(0);
- }
-
- /* Unselect the chip. */
- ssel = 1;
-
- return 0;
- }
-
- /**
- * @brief Reads and write a buffer from/to the SPI peripheral device at the same time
- * in 8-bit data mode using synchronous SPI communication.
- * @param[out] pBufferToRead pointer to the buffer to read data into.
- * @param[in] pBufferToWrite pointer to the buffer of data to send.
- * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
- * @param[in] NumBytes number of bytes to read and write.
- * @retval 0 if ok.
- * @retval -1 if data format error.
- * @note When using the SPI in Interrupt-mode, remember to disable interrupts
- * before calling this function and to enable them again after.
- */
- int spi_read_write(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, DigitalOut &ssel, uint16_t NumBytes)
- {
- /* Check data format */
- if(_bits != 8) return -1;
-
- /* Select the chip. */
- ssel = 0;
-
- /* Read and write data at the same time. */
- for (int i = 0; i < NumBytes; i++) {
- pBufferToRead[i] = write(pBufferToWrite[i]);
- }
-
- /* Unselect the chip. */
- ssel = 1;
-
- return 0;
- }
-
- /**
- * @brief Writes a buffer to the SPI peripheral device in 16-bit data mode
- * using synchronous SPI communication.
- * @param[in] pBuffer pointer to the buffer of data to send.
- * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
- * @param[in] NumValuesToWrite number of 16-bit values to write.
- * @retval 0 if ok.
- * @retval -1 if data format error.
- * @note When using the SPI in Interrupt-mode, remember to disable interrupts
- * before calling this function and to enable them again after.
- * @note In order to guarantee this method to work correctly you have to
- * pass buffers which are correctly aligned.
- */
- int spi_write(uint16_t* pBuffer, DigitalOut &ssel, uint16_t NumValuesToWrite)
- {
- /* Check data format */
- if(_bits != 16) return -1;
-
- /* Select the chip. */
- ssel = 0;
-
- /* Write data. */
- for (int i = 0; i < NumValuesToWrite; i++) {
- write(htons(pBuffer[i]));
- }
-
- /* Unselect the chip. */
- ssel = 1;
-
- return 0;
- }
-
- /**
- * @brief Reads a buffer from the SPI peripheral device in 16-bit data mode
- * using synchronous SPI communication.
- * @param[out] pBuffer pointer to the buffer to read data into.
- * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
- * @param[in] NumValuesToRead number of 16-bit values to read.
- * @retval 0 if ok.
- * @retval -1 if data format error.
- * @note When using the SPI in Interrupt-mode, remember to disable interrupts
- * before calling this function and to enable them again after.
- * @note In order to guarantee this method to work correctly you have to
- * pass buffers which are correctly aligned.
- */
- int spi_read(uint16_t* pBuffer, DigitalOut &ssel, uint16_t NumValuesToRead)
- {
- /* Check data format */
- if(_bits != 16) return -1;
-
- /* Select the chip. */
- ssel = 0;
-
- /* Read data. */
- for (int i = 0; i < NumValuesToRead; i++) {
- pBuffer[i] = ntohs((uint16_t)write(0));
- }
-
- /* Unselect the chip. */
- ssel = 1;
-
- return 0;
- }
-
- /**
- * @brief Reads and write a buffer from/to the SPI peripheral device at the same time
- * in 16-bit data mode using synchronous SPI communication.
- * @param[out] pBufferToRead pointer to the buffer to read data into.
- * @param[in] pBufferToWrite pointer to the buffer of data to send.
- * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
- * @param[in] NumValues number of 16-bit values to read and write.
- * @retval 0 if ok.
- * @retval -1 if data format error.
- * @note When using the SPI in Interrupt-mode, remember to disable interrupts
- * before calling this function and to enable them again after.
- * @note In order to guarantee this method to work correctly you have to
- * pass buffers which are correctly aligned.
- */
- int spi_read_write(uint16_t* pBufferToRead, uint16_t* pBufferToWrite, DigitalOut &ssel, uint16_t NumValues)
- {
- /* Check data format */
- if(_bits != 16) return -1;
-
- /* Select the chip. */
- ssel = 0;
-
- /* Read and write data at the same time. */
- for (int i = 0; i < NumValues; i++) {
- pBufferToRead[i] = ntohs((uint16_t)write(htons(pBufferToWrite[i])));
- }
-
- /* Unselect the chip. */
- ssel = 1;
-
- return 0;
- }
-
-protected:
- inline uint16_t htons(uint16_t x) {
-#ifndef __DEV_SPI_BIG_ENDIAN
- return (((x)<<8)|((x)>>8));
-#else // __DEV_SPI_BIG_ENDIAN
- return (x);
-#endif // __DEV_SPI_BIG_ENDIAN
- }
-
- inline uint16_t ntohs(uint16_t x) {
- return htons(x);
- }
-};
-
-#endif /* __DEV_SPI_H */
--- a/X_NUCLEO_IKS01A2/X_NUCLEO_INTERFACES.lib Thu Nov 24 16:45:55 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/teams/ST-Expansion-SW-Team/code/X_NUCLEO_INTERFACES/#4bdd6ff149fc
