SDMP_IOT / Mbed OS AdiSense1000_SmartBabySeat

Fork of Babyseat_NewFirmware_copy_sean by Ross O'Halloran

Committer:
kevin1990
Date:
Fri Aug 25 11:17:37 2017 +0000
Revision:
2:625a45555a85
Sensor Channel 0 Type K example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kevin1990 2:625a45555a85 1 /*!
kevin1990 2:625a45555a85 2 ******************************************************************************
kevin1990 2:625a45555a85 3 * @file: register_interface.cpp
kevin1990 2:625a45555a85 4 * @brief: ADISense1000 interface to register map in adisense firmware
kevin1990 2:625a45555a85 5 *-----------------------------------------------------------------------------
kevin1990 2:625a45555a85 6 *
kevin1990 2:625a45555a85 7 Copyright (c) 2017 Emutex Ltd. / Analog Devices, Inc.
kevin1990 2:625a45555a85 8
kevin1990 2:625a45555a85 9 All rights reserved.
kevin1990 2:625a45555a85 10
kevin1990 2:625a45555a85 11 Redistribution and use in source and binary forms, with or without modification,
kevin1990 2:625a45555a85 12 are permitted provided that the following conditions are met:
kevin1990 2:625a45555a85 13 - Redistributions of source code must retain the above copyright notice,
kevin1990 2:625a45555a85 14 this list of conditions and the following disclaimer.
kevin1990 2:625a45555a85 15 - Redistributions in binary form must reproduce the above copyright notice,
kevin1990 2:625a45555a85 16 this list of conditions and the following disclaimer in the documentation
kevin1990 2:625a45555a85 17 and/or other materials provided with the distribution.
kevin1990 2:625a45555a85 18 - Modified versions of the software must be conspicuously marked as such.
kevin1990 2:625a45555a85 19 - This software is licensed solely and exclusively for use with processors
kevin1990 2:625a45555a85 20 manufactured by or for Analog Devices, Inc.
kevin1990 2:625a45555a85 21 - This software may not be combined or merged with other code in any manner
kevin1990 2:625a45555a85 22 that would cause the software to become subject to terms and conditions
kevin1990 2:625a45555a85 23 which differ from those listed here.
kevin1990 2:625a45555a85 24 - Neither the name of Analog Devices, Inc. nor the names of its
kevin1990 2:625a45555a85 25 contributors may be used to endorse or promote products derived
kevin1990 2:625a45555a85 26 from this software without specific prior written permission.
kevin1990 2:625a45555a85 27 - The use of this software may or may not infringe the patent rights of one
kevin1990 2:625a45555a85 28 or more patent holders. This license does not release you from the
kevin1990 2:625a45555a85 29 requirement that you obtain separate licenses from these patent holders
kevin1990 2:625a45555a85 30 to use this software.
kevin1990 2:625a45555a85 31
kevin1990 2:625a45555a85 32 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND ANY
kevin1990 2:625a45555a85 33 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
kevin1990 2:625a45555a85 34 TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
kevin1990 2:625a45555a85 35 NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
kevin1990 2:625a45555a85 36 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
kevin1990 2:625a45555a85 37 (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
kevin1990 2:625a45555a85 38 PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
kevin1990 2:625a45555a85 39 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
kevin1990 2:625a45555a85 40 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
kevin1990 2:625a45555a85 41 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
kevin1990 2:625a45555a85 42 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
kevin1990 2:625a45555a85 43 *
kevin1990 2:625a45555a85 44 *****************************************************************************/
kevin1990 2:625a45555a85 45 /******************************************************************************/
kevin1990 2:625a45555a85 46 /* Include Files */
kevin1990 2:625a45555a85 47 /******************************************************************************/
kevin1990 2:625a45555a85 48 #include "inc/register_interface.h"
kevin1990 2:625a45555a85 49 #include "inc/spi_nucleo.h"
kevin1990 2:625a45555a85 50
kevin1990 2:625a45555a85 51 #define BUFFER_SIZE 256
kevin1990 2:625a45555a85 52 #define CS_HOLD 1
kevin1990 2:625a45555a85 53
kevin1990 2:625a45555a85 54 #define SET_WRITE_COMMAND(offset) \
kevin1990 2:625a45555a85 55 do { \
kevin1990 2:625a45555a85 56 uint16_t command = 0x8000 | (offset & 0x7FFF); \
kevin1990 2:625a45555a85 57 txBuff[0] = command >> 8; \
kevin1990 2:625a45555a85 58 txBuff[1] = command & 0xFF; \
kevin1990 2:625a45555a85 59 } while(0)
kevin1990 2:625a45555a85 60
kevin1990 2:625a45555a85 61 #define SET_READ_COMMAND(offset) \
kevin1990 2:625a45555a85 62 do { \
kevin1990 2:625a45555a85 63 uint16_t command = (offset & 0x7FFF); \
kevin1990 2:625a45555a85 64 txBuff[0] = command >> 8; \
kevin1990 2:625a45555a85 65 txBuff[1] = command & 0xFF; \
kevin1990 2:625a45555a85 66 } while(0)
kevin1990 2:625a45555a85 67
kevin1990 2:625a45555a85 68 static uint8_t txBuff[BUFFER_SIZE];
kevin1990 2:625a45555a85 69
kevin1990 2:625a45555a85 70 /*!
kevin1990 2:625a45555a85 71 * @brief Write configuration to adisense1000 register
kevin1990 2:625a45555a85 72 *
kevin1990 2:625a45555a85 73 * @param[in] addr id of register to write too
kevin1990 2:625a45555a85 74 * @param[in] size size of register in bytes
kevin1990 2:625a45555a85 75 * @param[in] pData data to be written
kevin1990 2:625a45555a85 76 *
kevin1990 2:625a45555a85 77 * @return Status
kevin1990 2:625a45555a85 78 * - #ADI_SENSE_SUCCESS Call completed successfully.
kevin1990 2:625a45555a85 79 * - todo
kevin1990 2:625a45555a85 80 *
kevin1990 2:625a45555a85 81 */
kevin1990 2:625a45555a85 82 ADI_SENSE_RESULT
kevin1990 2:625a45555a85 83 ADISense1000_RegWrite(uint16_t addr, uint16_t size, uint8_t *pData)
kevin1990 2:625a45555a85 84 {
kevin1990 2:625a45555a85 85 memset(txBuff, 0, sizeof(txBuff));
kevin1990 2:625a45555a85 86
kevin1990 2:625a45555a85 87 SET_WRITE_COMMAND(addr);
kevin1990 2:625a45555a85 88
kevin1990 2:625a45555a85 89 for (int i = 2; i < (size + REG_CMD_SIZE); i++)
kevin1990 2:625a45555a85 90 {
kevin1990 2:625a45555a85 91 txBuff[i] = pData[i - REG_CMD_SIZE];
kevin1990 2:625a45555a85 92 }
kevin1990 2:625a45555a85 93
kevin1990 2:625a45555a85 94 if (ADISense1000_HostSpiTransfer(txBuff, (size + REG_CMD_SIZE),
kevin1990 2:625a45555a85 95 !CS_HOLD) != ADI_SENSE_SUCCESS)
kevin1990 2:625a45555a85 96 return ADI_SENSE_FAILURE;
kevin1990 2:625a45555a85 97
kevin1990 2:625a45555a85 98 return ADI_SENSE_SUCCESS;
kevin1990 2:625a45555a85 99 }
kevin1990 2:625a45555a85 100
kevin1990 2:625a45555a85 101 /*!
kevin1990 2:625a45555a85 102 * @brief Read value of adisense1000 register
kevin1990 2:625a45555a85 103 *
kevin1990 2:625a45555a85 104 * @param[in] addr id of register to read from
kevin1990 2:625a45555a85 105 * @param[in] size size of register in bytes
kevin1990 2:625a45555a85 106 * @param[out] pData value from register
kevin1990 2:625a45555a85 107 *
kevin1990 2:625a45555a85 108 * @return Status
kevin1990 2:625a45555a85 109 * - #ADI_SENSE_SUCCESS Call completed successfully.
kevin1990 2:625a45555a85 110 * - todo
kevin1990 2:625a45555a85 111 *
kevin1990 2:625a45555a85 112 */
kevin1990 2:625a45555a85 113 ADI_SENSE_RESULT
kevin1990 2:625a45555a85 114 ADISense1000_RegRead(uint16_t addr, uint16_t size, uint8_t *data)
kevin1990 2:625a45555a85 115 {
kevin1990 2:625a45555a85 116 memset(txBuff, 0, sizeof(txBuff));
kevin1990 2:625a45555a85 117
kevin1990 2:625a45555a85 118 SET_READ_COMMAND(addr);
kevin1990 2:625a45555a85 119
kevin1990 2:625a45555a85 120 if (ADISense1000_HostSpiTransfer(txBuff, size, !CS_HOLD) != ADI_SENSE_SUCCESS)
kevin1990 2:625a45555a85 121 return ADI_SENSE_FAILURE;
kevin1990 2:625a45555a85 122
kevin1990 2:625a45555a85 123 memcpy(data, txBuff, size);
kevin1990 2:625a45555a85 124
kevin1990 2:625a45555a85 125 return ADI_SENSE_SUCCESS;
kevin1990 2:625a45555a85 126 }
kevin1990 2:625a45555a85 127