Example of single tap and double tap detection for LSM6DSL in X-NUCLEO-IKS01A2

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of SingleDoubleTap_IKS01A2 by ST Expansion SW Team

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.

Committer:
cparata
Date:
Fri Aug 12 13:42:02 2016 +0000
Revision:
0:e4f89df7a7a5
First release of Single/Double Tap for LSM6DSL in IKS01A2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cparata 0:e4f89df7a7a5 1 /**
cparata 0:e4f89df7a7a5 2 ******************************************************************************
cparata 0:e4f89df7a7a5 3 * @file DevSPI.h
cparata 0:e4f89df7a7a5 4 * @author AST / Software Platforms and Cloud / EST
cparata 0:e4f89df7a7a5 5 * @version V1.2.1
cparata 0:e4f89df7a7a5 6 * @date 19-February-2016
cparata 0:e4f89df7a7a5 7 * @brief Header file for a special SPI class DevSPI which provides some
cparata 0:e4f89df7a7a5 8 * helper functions for on-board communication.
cparata 0:e4f89df7a7a5 9 ******************************************************************************
cparata 0:e4f89df7a7a5 10 * @attention
cparata 0:e4f89df7a7a5 11 *
cparata 0:e4f89df7a7a5 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
cparata 0:e4f89df7a7a5 13 *
cparata 0:e4f89df7a7a5 14 * Redistribution and use in source and binary forms, with or without modification,
cparata 0:e4f89df7a7a5 15 * are permitted provided that the following conditions are met:
cparata 0:e4f89df7a7a5 16 * 1. Redistributions of source code must retain the above copyright notice,
cparata 0:e4f89df7a7a5 17 * this list of conditions and the following disclaimer.
cparata 0:e4f89df7a7a5 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
cparata 0:e4f89df7a7a5 19 * this list of conditions and the following disclaimer in the documentation
cparata 0:e4f89df7a7a5 20 * and/or other materials provided with the distribution.
cparata 0:e4f89df7a7a5 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
cparata 0:e4f89df7a7a5 22 * may be used to endorse or promote products derived from this software
cparata 0:e4f89df7a7a5 23 * without specific prior written permission.
cparata 0:e4f89df7a7a5 24 *
cparata 0:e4f89df7a7a5 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cparata 0:e4f89df7a7a5 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cparata 0:e4f89df7a7a5 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cparata 0:e4f89df7a7a5 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
cparata 0:e4f89df7a7a5 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
cparata 0:e4f89df7a7a5 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
cparata 0:e4f89df7a7a5 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
cparata 0:e4f89df7a7a5 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cparata 0:e4f89df7a7a5 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
cparata 0:e4f89df7a7a5 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cparata 0:e4f89df7a7a5 35 *
cparata 0:e4f89df7a7a5 36 ******************************************************************************
cparata 0:e4f89df7a7a5 37 */
cparata 0:e4f89df7a7a5 38
cparata 0:e4f89df7a7a5 39 /* Define to prevent from recursive inclusion --------------------------------*/
cparata 0:e4f89df7a7a5 40 #ifndef __DEV_SPI_H
cparata 0:e4f89df7a7a5 41 #define __DEV_SPI_H
cparata 0:e4f89df7a7a5 42
cparata 0:e4f89df7a7a5 43 /* Includes ------------------------------------------------------------------*/
cparata 0:e4f89df7a7a5 44 #include "mbed.h"
cparata 0:e4f89df7a7a5 45
cparata 0:e4f89df7a7a5 46 /* Macros --------------------------------------------------------------------*/
cparata 0:e4f89df7a7a5 47 #if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) /* GCC */ || \
cparata 0:e4f89df7a7a5 48 (defined(G_BYTE_ORDER) && (G_BYTE_ORDER == G_BIG_ENDIAN)) /* IAR */ || \
cparata 0:e4f89df7a7a5 49 (defined(__BIG_ENDIAN)) /* ARM */
cparata 0:e4f89df7a7a5 50 #define __DEV_SPI_BIG_ENDIAN
cparata 0:e4f89df7a7a5 51 #endif
cparata 0:e4f89df7a7a5 52
cparata 0:e4f89df7a7a5 53 /* Classes -------------------------------------------------------------------*/
cparata 0:e4f89df7a7a5 54 /** Helper class DevSPI providing functions for synchronous SPI communication
cparata 0:e4f89df7a7a5 55 * common for a series of SPI devices.
cparata 0:e4f89df7a7a5 56 */
cparata 0:e4f89df7a7a5 57 class DevSPI : public SPI
cparata 0:e4f89df7a7a5 58 {
cparata 0:e4f89df7a7a5 59 public:
cparata 0:e4f89df7a7a5 60 /*
cparata 0:e4f89df7a7a5 61 * Create a DevSPI interface.
cparata 0:e4f89df7a7a5 62 * @param mosi pin name of the MOSI pin of the SPI device to be used for communication.
cparata 0:e4f89df7a7a5 63 * @param miso pin name of the MISO pin of the SPI device to be used for communication.
cparata 0:e4f89df7a7a5 64 * @param sclk pin name of the SCLK pin of the SPI device to be used for communication.
cparata 0:e4f89df7a7a5 65 */
cparata 0:e4f89df7a7a5 66 DevSPI(PinName mosi, PinName miso, PinName sclk) : SPI(mosi, miso, sclk)
cparata 0:e4f89df7a7a5 67 {
cparata 0:e4f89df7a7a5 68 /* Set default configuration. */
cparata 0:e4f89df7a7a5 69 setup(8, 3, 1E6);
cparata 0:e4f89df7a7a5 70 }
cparata 0:e4f89df7a7a5 71
cparata 0:e4f89df7a7a5 72 /*
cparata 0:e4f89df7a7a5 73 * Setup the spi.
cparata 0:e4f89df7a7a5 74 * Typically:
cparata 0:e4f89df7a7a5 75 * + 8 bit data;
cparata 0:e4f89df7a7a5 76 * + high steady state clock;
cparata 0:e4f89df7a7a5 77 * + second edge capture;
cparata 0:e4f89df7a7a5 78 * + 1MHz clock rate.
cparata 0:e4f89df7a7a5 79 *
cparata 0:e4f89df7a7a5 80 * @param bits Number of bits per SPI frame (4 - 16)
cparata 0:e4f89df7a7a5 81 * @param mode Clock polarity and phase mode (0 - 3)
cparata 0:e4f89df7a7a5 82 * @param frequency_hz SCLK frequency in hz (default = 1MHz)
cparata 0:e4f89df7a7a5 83 *
cparata 0:e4f89df7a7a5 84 * @code
cparata 0:e4f89df7a7a5 85 * mode | POL PHA
cparata 0:e4f89df7a7a5 86 * -----+--------
cparata 0:e4f89df7a7a5 87 * 0 | 0 0
cparata 0:e4f89df7a7a5 88 * 1 | 0 1
cparata 0:e4f89df7a7a5 89 * 2 | 1 0
cparata 0:e4f89df7a7a5 90 * 3 | 1 1
cparata 0:e4f89df7a7a5 91 * @endcode
cparata 0:e4f89df7a7a5 92 */
cparata 0:e4f89df7a7a5 93 void setup(int bits, int mode = 0, int frequency_hz = 1E6)
cparata 0:e4f89df7a7a5 94 {
cparata 0:e4f89df7a7a5 95 /* Set given configuration. */
cparata 0:e4f89df7a7a5 96 format(bits, mode);
cparata 0:e4f89df7a7a5 97 frequency(frequency_hz);
cparata 0:e4f89df7a7a5 98 }
cparata 0:e4f89df7a7a5 99
cparata 0:e4f89df7a7a5 100 /**
cparata 0:e4f89df7a7a5 101 * @brief Writes a buffer to the SPI peripheral device in 8-bit data mode
cparata 0:e4f89df7a7a5 102 * using synchronous SPI communication.
cparata 0:e4f89df7a7a5 103 * @param[in] pBuffer pointer to the buffer of data to send.
cparata 0:e4f89df7a7a5 104 * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
cparata 0:e4f89df7a7a5 105 * @param[in] NumBytesToWrite number of bytes to write.
cparata 0:e4f89df7a7a5 106 * @retval 0 if ok.
cparata 0:e4f89df7a7a5 107 * @retval -1 if data format error.
cparata 0:e4f89df7a7a5 108 * @note When using the SPI in Interrupt-mode, remember to disable interrupts
cparata 0:e4f89df7a7a5 109 * before calling this function and to enable them again after.
cparata 0:e4f89df7a7a5 110 */
cparata 0:e4f89df7a7a5 111 int spi_write(uint8_t* pBuffer, DigitalOut &ssel, uint16_t NumBytesToWrite)
cparata 0:e4f89df7a7a5 112 {
cparata 0:e4f89df7a7a5 113 /* Check data format */
cparata 0:e4f89df7a7a5 114 if(_bits != 8) return -1;
cparata 0:e4f89df7a7a5 115
cparata 0:e4f89df7a7a5 116 /* Select the chip. */
cparata 0:e4f89df7a7a5 117 ssel = 0;
cparata 0:e4f89df7a7a5 118
cparata 0:e4f89df7a7a5 119 /* Write data. */
cparata 0:e4f89df7a7a5 120 for (int i = 0; i < NumBytesToWrite; i++) {
cparata 0:e4f89df7a7a5 121 write(pBuffer[i]);
cparata 0:e4f89df7a7a5 122 }
cparata 0:e4f89df7a7a5 123
cparata 0:e4f89df7a7a5 124 /* Unselect the chip. */
cparata 0:e4f89df7a7a5 125 ssel = 1;
cparata 0:e4f89df7a7a5 126
cparata 0:e4f89df7a7a5 127 return 0;
cparata 0:e4f89df7a7a5 128 }
cparata 0:e4f89df7a7a5 129
cparata 0:e4f89df7a7a5 130 /**
cparata 0:e4f89df7a7a5 131 * @brief Reads a buffer from the SPI peripheral device in 8-bit data mode
cparata 0:e4f89df7a7a5 132 * using synchronous SPI communication.
cparata 0:e4f89df7a7a5 133 * @param[out] pBuffer pointer to the buffer to read data into.
cparata 0:e4f89df7a7a5 134 * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
cparata 0:e4f89df7a7a5 135 * @param[in] NumBytesToRead number of bytes to read.
cparata 0:e4f89df7a7a5 136 * @retval 0 if ok.
cparata 0:e4f89df7a7a5 137 * @retval -1 if data format error.
cparata 0:e4f89df7a7a5 138 * @note When using the SPI in Interrupt-mode, remember to disable interrupts
cparata 0:e4f89df7a7a5 139 * before calling this function and to enable them again after.
cparata 0:e4f89df7a7a5 140 */
cparata 0:e4f89df7a7a5 141 int spi_read(uint8_t* pBuffer, DigitalOut &ssel, uint16_t NumBytesToRead)
cparata 0:e4f89df7a7a5 142 {
cparata 0:e4f89df7a7a5 143 /* Check data format */
cparata 0:e4f89df7a7a5 144 if(_bits != 8) return -1;
cparata 0:e4f89df7a7a5 145
cparata 0:e4f89df7a7a5 146 /* Select the chip. */
cparata 0:e4f89df7a7a5 147 ssel = 0;
cparata 0:e4f89df7a7a5 148
cparata 0:e4f89df7a7a5 149 /* Read data. */
cparata 0:e4f89df7a7a5 150 for (int i = 0; i < NumBytesToRead; i++) {
cparata 0:e4f89df7a7a5 151 pBuffer[i] = write(0);
cparata 0:e4f89df7a7a5 152 }
cparata 0:e4f89df7a7a5 153
cparata 0:e4f89df7a7a5 154 /* Unselect the chip. */
cparata 0:e4f89df7a7a5 155 ssel = 1;
cparata 0:e4f89df7a7a5 156
cparata 0:e4f89df7a7a5 157 return 0;
cparata 0:e4f89df7a7a5 158 }
cparata 0:e4f89df7a7a5 159
cparata 0:e4f89df7a7a5 160 /**
cparata 0:e4f89df7a7a5 161 * @brief Reads and write a buffer from/to the SPI peripheral device at the same time
cparata 0:e4f89df7a7a5 162 * in 8-bit data mode using synchronous SPI communication.
cparata 0:e4f89df7a7a5 163 * @param[out] pBufferToRead pointer to the buffer to read data into.
cparata 0:e4f89df7a7a5 164 * @param[in] pBufferToWrite pointer to the buffer of data to send.
cparata 0:e4f89df7a7a5 165 * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
cparata 0:e4f89df7a7a5 166 * @param[in] NumBytes number of bytes to read and write.
cparata 0:e4f89df7a7a5 167 * @retval 0 if ok.
cparata 0:e4f89df7a7a5 168 * @retval -1 if data format error.
cparata 0:e4f89df7a7a5 169 * @note When using the SPI in Interrupt-mode, remember to disable interrupts
cparata 0:e4f89df7a7a5 170 * before calling this function and to enable them again after.
cparata 0:e4f89df7a7a5 171 */
cparata 0:e4f89df7a7a5 172 int spi_read_write(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, DigitalOut &ssel, uint16_t NumBytes)
cparata 0:e4f89df7a7a5 173 {
cparata 0:e4f89df7a7a5 174 /* Check data format */
cparata 0:e4f89df7a7a5 175 if(_bits != 8) return -1;
cparata 0:e4f89df7a7a5 176
cparata 0:e4f89df7a7a5 177 /* Select the chip. */
cparata 0:e4f89df7a7a5 178 ssel = 0;
cparata 0:e4f89df7a7a5 179
cparata 0:e4f89df7a7a5 180 /* Read and write data at the same time. */
cparata 0:e4f89df7a7a5 181 for (int i = 0; i < NumBytes; i++) {
cparata 0:e4f89df7a7a5 182 pBufferToRead[i] = write(pBufferToWrite[i]);
cparata 0:e4f89df7a7a5 183 }
cparata 0:e4f89df7a7a5 184
cparata 0:e4f89df7a7a5 185 /* Unselect the chip. */
cparata 0:e4f89df7a7a5 186 ssel = 1;
cparata 0:e4f89df7a7a5 187
cparata 0:e4f89df7a7a5 188 return 0;
cparata 0:e4f89df7a7a5 189 }
cparata 0:e4f89df7a7a5 190
cparata 0:e4f89df7a7a5 191 /**
cparata 0:e4f89df7a7a5 192 * @brief Writes a buffer to the SPI peripheral device in 16-bit data mode
cparata 0:e4f89df7a7a5 193 * using synchronous SPI communication.
cparata 0:e4f89df7a7a5 194 * @param[in] pBuffer pointer to the buffer of data to send.
cparata 0:e4f89df7a7a5 195 * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
cparata 0:e4f89df7a7a5 196 * @param[in] NumValuesToWrite number of 16-bit values to write.
cparata 0:e4f89df7a7a5 197 * @retval 0 if ok.
cparata 0:e4f89df7a7a5 198 * @retval -1 if data format error.
cparata 0:e4f89df7a7a5 199 * @note When using the SPI in Interrupt-mode, remember to disable interrupts
cparata 0:e4f89df7a7a5 200 * before calling this function and to enable them again after.
cparata 0:e4f89df7a7a5 201 * @note In order to guarantee this method to work correctly you have to
cparata 0:e4f89df7a7a5 202 * pass buffers which are correctly aligned.
cparata 0:e4f89df7a7a5 203 */
cparata 0:e4f89df7a7a5 204 int spi_write(uint16_t* pBuffer, DigitalOut &ssel, uint16_t NumValuesToWrite)
cparata 0:e4f89df7a7a5 205 {
cparata 0:e4f89df7a7a5 206 /* Check data format */
cparata 0:e4f89df7a7a5 207 if(_bits != 16) return -1;
cparata 0:e4f89df7a7a5 208
cparata 0:e4f89df7a7a5 209 /* Select the chip. */
cparata 0:e4f89df7a7a5 210 ssel = 0;
cparata 0:e4f89df7a7a5 211
cparata 0:e4f89df7a7a5 212 /* Write data. */
cparata 0:e4f89df7a7a5 213 for (int i = 0; i < NumValuesToWrite; i++) {
cparata 0:e4f89df7a7a5 214 write(htons(pBuffer[i]));
cparata 0:e4f89df7a7a5 215 }
cparata 0:e4f89df7a7a5 216
cparata 0:e4f89df7a7a5 217 /* Unselect the chip. */
cparata 0:e4f89df7a7a5 218 ssel = 1;
cparata 0:e4f89df7a7a5 219
cparata 0:e4f89df7a7a5 220 return 0;
cparata 0:e4f89df7a7a5 221 }
cparata 0:e4f89df7a7a5 222
cparata 0:e4f89df7a7a5 223 /**
cparata 0:e4f89df7a7a5 224 * @brief Reads a buffer from the SPI peripheral device in 16-bit data mode
cparata 0:e4f89df7a7a5 225 * using synchronous SPI communication.
cparata 0:e4f89df7a7a5 226 * @param[out] pBuffer pointer to the buffer to read data into.
cparata 0:e4f89df7a7a5 227 * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
cparata 0:e4f89df7a7a5 228 * @param[in] NumValuesToRead number of 16-bit values to read.
cparata 0:e4f89df7a7a5 229 * @retval 0 if ok.
cparata 0:e4f89df7a7a5 230 * @retval -1 if data format error.
cparata 0:e4f89df7a7a5 231 * @note When using the SPI in Interrupt-mode, remember to disable interrupts
cparata 0:e4f89df7a7a5 232 * before calling this function and to enable them again after.
cparata 0:e4f89df7a7a5 233 * @note In order to guarantee this method to work correctly you have to
cparata 0:e4f89df7a7a5 234 * pass buffers which are correctly aligned.
cparata 0:e4f89df7a7a5 235 */
cparata 0:e4f89df7a7a5 236 int spi_read(uint16_t* pBuffer, DigitalOut &ssel, uint16_t NumValuesToRead)
cparata 0:e4f89df7a7a5 237 {
cparata 0:e4f89df7a7a5 238 /* Check data format */
cparata 0:e4f89df7a7a5 239 if(_bits != 16) return -1;
cparata 0:e4f89df7a7a5 240
cparata 0:e4f89df7a7a5 241 /* Select the chip. */
cparata 0:e4f89df7a7a5 242 ssel = 0;
cparata 0:e4f89df7a7a5 243
cparata 0:e4f89df7a7a5 244 /* Read data. */
cparata 0:e4f89df7a7a5 245 for (int i = 0; i < NumValuesToRead; i++) {
cparata 0:e4f89df7a7a5 246 pBuffer[i] = ntohs((uint16_t)write(0));
cparata 0:e4f89df7a7a5 247 }
cparata 0:e4f89df7a7a5 248
cparata 0:e4f89df7a7a5 249 /* Unselect the chip. */
cparata 0:e4f89df7a7a5 250 ssel = 1;
cparata 0:e4f89df7a7a5 251
cparata 0:e4f89df7a7a5 252 return 0;
cparata 0:e4f89df7a7a5 253 }
cparata 0:e4f89df7a7a5 254
cparata 0:e4f89df7a7a5 255 /**
cparata 0:e4f89df7a7a5 256 * @brief Reads and write a buffer from/to the SPI peripheral device at the same time
cparata 0:e4f89df7a7a5 257 * in 16-bit data mode using synchronous SPI communication.
cparata 0:e4f89df7a7a5 258 * @param[out] pBufferToRead pointer to the buffer to read data into.
cparata 0:e4f89df7a7a5 259 * @param[in] pBufferToWrite pointer to the buffer of data to send.
cparata 0:e4f89df7a7a5 260 * @param[in] ssel GPIO of the SSEL pin of the SPI device to be used for communication.
cparata 0:e4f89df7a7a5 261 * @param[in] NumValues number of 16-bit values to read and write.
cparata 0:e4f89df7a7a5 262 * @retval 0 if ok.
cparata 0:e4f89df7a7a5 263 * @retval -1 if data format error.
cparata 0:e4f89df7a7a5 264 * @note When using the SPI in Interrupt-mode, remember to disable interrupts
cparata 0:e4f89df7a7a5 265 * before calling this function and to enable them again after.
cparata 0:e4f89df7a7a5 266 * @note In order to guarantee this method to work correctly you have to
cparata 0:e4f89df7a7a5 267 * pass buffers which are correctly aligned.
cparata 0:e4f89df7a7a5 268 */
cparata 0:e4f89df7a7a5 269 int spi_read_write(uint16_t* pBufferToRead, uint16_t* pBufferToWrite, DigitalOut &ssel, uint16_t NumValues)
cparata 0:e4f89df7a7a5 270 {
cparata 0:e4f89df7a7a5 271 /* Check data format */
cparata 0:e4f89df7a7a5 272 if(_bits != 16) return -1;
cparata 0:e4f89df7a7a5 273
cparata 0:e4f89df7a7a5 274 /* Select the chip. */
cparata 0:e4f89df7a7a5 275 ssel = 0;
cparata 0:e4f89df7a7a5 276
cparata 0:e4f89df7a7a5 277 /* Read and write data at the same time. */
cparata 0:e4f89df7a7a5 278 for (int i = 0; i < NumValues; i++) {
cparata 0:e4f89df7a7a5 279 pBufferToRead[i] = ntohs((uint16_t)write(htons(pBufferToWrite[i])));
cparata 0:e4f89df7a7a5 280 }
cparata 0:e4f89df7a7a5 281
cparata 0:e4f89df7a7a5 282 /* Unselect the chip. */
cparata 0:e4f89df7a7a5 283 ssel = 1;
cparata 0:e4f89df7a7a5 284
cparata 0:e4f89df7a7a5 285 return 0;
cparata 0:e4f89df7a7a5 286 }
cparata 0:e4f89df7a7a5 287
cparata 0:e4f89df7a7a5 288 protected:
cparata 0:e4f89df7a7a5 289 inline uint16_t htons(uint16_t x) {
cparata 0:e4f89df7a7a5 290 #ifndef __DEV_SPI_BIG_ENDIAN
cparata 0:e4f89df7a7a5 291 return (((x)<<8)|((x)>>8));
cparata 0:e4f89df7a7a5 292 #else // __DEV_SPI_BIG_ENDIAN
cparata 0:e4f89df7a7a5 293 return (x);
cparata 0:e4f89df7a7a5 294 #endif // __DEV_SPI_BIG_ENDIAN
cparata 0:e4f89df7a7a5 295 }
cparata 0:e4f89df7a7a5 296
cparata 0:e4f89df7a7a5 297 inline uint16_t ntohs(uint16_t x) {
cparata 0:e4f89df7a7a5 298 return htons(x);
cparata 0:e4f89df7a7a5 299 }
cparata 0:e4f89df7a7a5 300 };
cparata 0:e4f89df7a7a5 301
cparata 0:e4f89df7a7a5 302 #endif /* __DEV_SPI_H */