Example for updating the MTi-1's firmware. Uses a platform independent, retargetable pure C implementation of the firmware updater protocol.

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mtssp_i2c_driver.cpp Source File

mtssp_i2c_driver.cpp

Go to the documentation of this file.
00001 /*!
00002  * \file
00003  * \copyright Copyright (C) Xsens Technologies B.V., 2015.
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00006  * use this file except in compliance with the License. You may obtain a copy
00007  * of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00014  * License for the specific language governing permissions and limitations
00015  * under the License.
00016  */
00017 #include "mtssp_i2c_driver.h "
00018 #include <string.h>
00019 #include <assert.h>
00020 #include "board.h "
00021 
00022 #define MTI_I2C_ADDRESS             (0x1D << 1)
00023 #define MTI_I2C_ADDRESS_SELECTOR    0
00024 
00025 
00026 /*! \class MtsspI2cDriver
00027     \brief Implementation of MtsspDriver for communicating over I2C.
00028     
00029     The low level I2C driver is provided by the mbed platform.
00030 */
00031 
00032 
00033 /*! \brief Constructor
00034 */
00035 MtsspI2cDriver::MtsspI2cDriver()
00036 {
00037     m_slaveAddress = new BusOut(MT_ADD0, MT_ADD1, MT_ADD2);
00038     m_slaveAddress->write(MTI_I2C_ADDRESS_SELECTOR);
00039     m_i2c = new I2C(MT_SDA, MT_SCL);
00040     m_i2c->frequency(400000);
00041 }
00042 
00043 
00044 /*! \brief Destructor
00045 */
00046 MtsspI2cDriver::~MtsspI2cDriver()
00047 {
00048     delete m_i2c;
00049 }
00050 
00051 
00052 /*! \brief Perform a blocking write transfer over I2C
00053     \param opcode Opcode to use
00054     \param data Pointer to data to be written
00055     \param dataLength Number of data bytes to write
00056 */
00057 void MtsspI2cDriver::write(uint8_t opcode, uint8_t const* data, int dataLength)
00058 {
00059     uint8_t transferBuffer[8];
00060     assert(dataLength < sizeof(transferBuffer));
00061     transferBuffer[0] = opcode;
00062     memcpy(&transferBuffer[1], data, dataLength);
00063     m_i2c->write(MTI_I2C_ADDRESS, (char*)transferBuffer, dataLength + 1);
00064 }
00065 
00066 
00067 /*! \brief Perform a blocking read transfer over I2C
00068     \param opcode Opcode to use
00069     \param data Pointer to result buffer
00070     \param dataLength Number of data bytes to read
00071 */
00072 void MtsspI2cDriver::read(uint8_t opcode, uint8_t* data, int dataLength)
00073 {
00074     m_i2c->write(MTI_I2C_ADDRESS, (char*)&opcode, sizeof(opcode), true);
00075     m_i2c->read(MTI_I2C_ADDRESS, (char*)data, dataLength);
00076 }
00077 
00078 
00079 /*! \brief Perform a blocking write transfer over I2C
00080     \param data Pointer to data to be written
00081     \param dataLength Number of data bytes to write
00082 */
00083 void MtsspI2cDriver::writeRaw(uint8_t const* data, int dataLength)
00084 {
00085     m_i2c->write(MTI_I2C_ADDRESS, (char*)data, dataLength);
00086 }