Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.

Dependencies:   mbed

Committer:
dflet
Date:
Tue Sep 15 16:45:04 2015 +0000
Revision:
22:f9b5e0b80bf2
Parent:
21:38c6b11aa348
Removed some debug.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 15:5433f9d94cd7 1 //*****************************************************************************
dflet 15:5433f9d94cd7 2 // i2cconfig.c
dflet 15:5433f9d94cd7 3 //
dflet 15:5433f9d94cd7 4 // I2C features APIs
dflet 15:5433f9d94cd7 5 //
dflet 15:5433f9d94cd7 6 // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 15:5433f9d94cd7 7 //
dflet 15:5433f9d94cd7 8 //
dflet 15:5433f9d94cd7 9 // Redistribution and use in source and binary forms, with or without
dflet 15:5433f9d94cd7 10 // modification, are permitted provided that the following conditions
dflet 15:5433f9d94cd7 11 // are met:
dflet 15:5433f9d94cd7 12 //
dflet 15:5433f9d94cd7 13 // Redistributions of source code must retain the above copyright
dflet 15:5433f9d94cd7 14 // notice, this list of conditions and the following disclaimer.
dflet 15:5433f9d94cd7 15 //
dflet 15:5433f9d94cd7 16 // Redistributions in binary form must reproduce the above copyright
dflet 15:5433f9d94cd7 17 // notice, this list of conditions and the following disclaimer in the
dflet 15:5433f9d94cd7 18 // documentation and/or other materials provided with the
dflet 15:5433f9d94cd7 19 // distribution.
dflet 15:5433f9d94cd7 20 //
dflet 15:5433f9d94cd7 21 // Neither the name of Texas Instruments Incorporated nor the names of
dflet 15:5433f9d94cd7 22 // its contributors may be used to endorse or promote products derived
dflet 15:5433f9d94cd7 23 // from this software without specific prior written permission.
dflet 15:5433f9d94cd7 24 //
dflet 15:5433f9d94cd7 25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 15:5433f9d94cd7 26 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 15:5433f9d94cd7 27 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 15:5433f9d94cd7 28 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 15:5433f9d94cd7 29 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 15:5433f9d94cd7 30 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 15:5433f9d94cd7 31 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 15:5433f9d94cd7 32 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 15:5433f9d94cd7 33 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 15:5433f9d94cd7 34 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 15:5433f9d94cd7 35 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 15:5433f9d94cd7 36 //
dflet 15:5433f9d94cd7 37 //*****************************************************************************
dflet 15:5433f9d94cd7 38 //*****************************************************************************
dflet 15:5433f9d94cd7 39 //
dflet 15:5433f9d94cd7 40 //! \addtogroup i2cconfig
dflet 15:5433f9d94cd7 41 //! @{
dflet 15:5433f9d94cd7 42 //
dflet 15:5433f9d94cd7 43 //*****************************************************************************
dflet 15:5433f9d94cd7 44 #include <stdbool.h>
dflet 15:5433f9d94cd7 45 #include <stdint.h>
dflet 15:5433f9d94cd7 46 #include "mbed.h"
dflet 15:5433f9d94cd7 47
dflet 18:3f1b52616d00 48 #include "cli_uart.h"
dflet 18:3f1b52616d00 49 #include "osi.h"
dflet 18:3f1b52616d00 50
dflet 15:5433f9d94cd7 51 #include "i2cconfig.h"
dflet 15:5433f9d94cd7 52 #include "cli_uart.h"
dflet 15:5433f9d94cd7 53 #include "myBoardInit.h"
dflet 15:5433f9d94cd7 54
dflet 15:5433f9d94cd7 55
dflet 15:5433f9d94cd7 56
dflet 15:5433f9d94cd7 57 I2C i2c(PB_9, PB_8);
dflet 15:5433f9d94cd7 58
dflet 18:3f1b52616d00 59 OsiLockObj_t g_i2cLock;
dflet 18:3f1b52616d00 60
dflet 15:5433f9d94cd7 61
dflet 15:5433f9d94cd7 62 //*****************************************************************************
dflet 15:5433f9d94cd7 63 //
dflet 15:5433f9d94cd7 64 //! I2CInit
dflet 15:5433f9d94cd7 65 //!
dflet 15:5433f9d94cd7 66 //! \param Delay
dflet 15:5433f9d94cd7 67 //! \return None
dflet 15:5433f9d94cd7 68 //
dflet 15:5433f9d94cd7 69 //*****************************************************************************
dflet 15:5433f9d94cd7 70 uint32_t I2CInit()
dflet 15:5433f9d94cd7 71 {
dflet 15:5433f9d94cd7 72
dflet 15:5433f9d94cd7 73 i2c.frequency (100000);
dflet 15:5433f9d94cd7 74
dflet 15:5433f9d94cd7 75 return 0;
dflet 15:5433f9d94cd7 76 }
dflet 15:5433f9d94cd7 77 //****************************************************************************
dflet 15:5433f9d94cd7 78 //
dflet 15:5433f9d94cd7 79 //! Invokes the I2C driver APIs to read from the device. This assumes the
dflet 15:5433f9d94cd7 80 //! device local address to read from is set using the I2CWrite API.
dflet 15:5433f9d94cd7 81 //!
dflet 15:5433f9d94cd7 82 //! \param ucDevAddr is the device I2C slave address
dflet 15:5433f9d94cd7 83 //! \param ucBuffer is the pointer to the read data to be placed
dflet 15:5433f9d94cd7 84 //! \param ulSize is the length of data to be read
dflet 15:5433f9d94cd7 85 //! \param ucFlags Flag
dflet 15:5433f9d94cd7 86 //!
dflet 15:5433f9d94cd7 87 //! This function works in a polling mode,
dflet 15:5433f9d94cd7 88 //! 1. Writes the device register address to be written to.
dflet 15:5433f9d94cd7 89 //! 2. In a loop, reads all the bytes over I2C
dflet 15:5433f9d94cd7 90 //!
dflet 15:5433f9d94cd7 91 //! \return 0: Success, < 0: Failure.
dflet 15:5433f9d94cd7 92 //
dflet 15:5433f9d94cd7 93 //****************************************************************************
dflet 15:5433f9d94cd7 94 int32_t I2CBufferRead(int32_t ucDevAddr, uint8_t *ucBuffer,
dflet 15:5433f9d94cd7 95 int32_t ulSize, unsigned char ucFlags)
dflet 15:5433f9d94cd7 96 {
dflet 15:5433f9d94cd7 97 // Uart_Write((uint8_t*)"I2CBufferRead \n\r");
dflet 15:5433f9d94cd7 98 /*
dflet 15:5433f9d94cd7 99 i2c.start();
dflet 15:5433f9d94cd7 100
dflet 15:5433f9d94cd7 101 // Set I2C slave read address
dflet 15:5433f9d94cd7 102 i2c.write(ucDevAddr);
dflet 15:5433f9d94cd7 103 if(ulSize == 1){
dflet 15:5433f9d94cd7 104 ucBuffer[0] = i2c.read(0);
dflet 15:5433f9d94cd7 105 }else{
dflet 15:5433f9d94cd7 106 for(int i=0;i<ulSize;i++){
dflet 15:5433f9d94cd7 107 ucBuffer[i] = i2c.read(0);
dflet 15:5433f9d94cd7 108 }
dflet 15:5433f9d94cd7 109 }
dflet 15:5433f9d94cd7 110
dflet 15:5433f9d94cd7 111 i2c.stop();
dflet 15:5433f9d94cd7 112 */
dflet 15:5433f9d94cd7 113 int32_t err = 0;
dflet 15:5433f9d94cd7 114
dflet 18:3f1b52616d00 115 // RTOS_MUTEX_ACQUIRE(&g_i2cLock);
dflet 18:3f1b52616d00 116
dflet 15:5433f9d94cd7 117 err = i2c.read(ucDevAddr,(char*)ucBuffer,ulSize);
dflet 15:5433f9d94cd7 118 if(err == 1){
dflet 15:5433f9d94cd7 119 Uart_Write((uint8_t*)"Return error I2C read\n\r");
dflet 18:3f1b52616d00 120 // RTOS_MUTEX_RELEASE(&g_i2cLock);
dflet 15:5433f9d94cd7 121 return -1;
dflet 15:5433f9d94cd7 122 }
dflet 21:38c6b11aa348 123 wait_ms(1);
dflet 18:3f1b52616d00 124 // RTOS_MUTEX_RELEASE(&g_i2cLock);
dflet 15:5433f9d94cd7 125 return 0;
dflet 15:5433f9d94cd7 126 }
dflet 15:5433f9d94cd7 127 //****************************************************************************
dflet 15:5433f9d94cd7 128 //
dflet 15:5433f9d94cd7 129 //! Invokes the I2C driver APIs to write to the specified address
dflet 15:5433f9d94cd7 130 //!
dflet 15:5433f9d94cd7 131 //! \param ucDevAddr is the device I2C slave address
dflet 15:5433f9d94cd7 132 //! \param ucBuffer is the pointer to the data to be written
dflet 15:5433f9d94cd7 133 //! \param ulSize is the length of data to be written
dflet 15:5433f9d94cd7 134 //! \param ucFlags
dflet 15:5433f9d94cd7 135 //!
dflet 15:5433f9d94cd7 136 //! This function works in a polling mode,
dflet 15:5433f9d94cd7 137 //! 1. Writes the device register address to be written to.
dflet 15:5433f9d94cd7 138 //! 2. In a loop, writes all the bytes over I2C
dflet 15:5433f9d94cd7 139 //!
dflet 15:5433f9d94cd7 140 //! \return 0: Success, < 0: Failure.
dflet 15:5433f9d94cd7 141 //
dflet 15:5433f9d94cd7 142 //****************************************************************************
dflet 15:5433f9d94cd7 143
dflet 15:5433f9d94cd7 144 int32_t I2CBufferWrite(int32_t ucDevAddr, uint8_t *ucBuffer,
dflet 15:5433f9d94cd7 145 int32_t ulSize,unsigned char ucFlags)
dflet 15:5433f9d94cd7 146 {
dflet 15:5433f9d94cd7 147 // Uart_Write((uint8_t*)"I2CBufferWrite \n\r");
dflet 15:5433f9d94cd7 148 /*
dflet 15:5433f9d94cd7 149 i2c.start();
dflet 15:5433f9d94cd7 150
dflet 15:5433f9d94cd7 151 // Set I2C slave write address
dflet 15:5433f9d94cd7 152 i2c.write(ucDevAddr);
dflet 15:5433f9d94cd7 153
dflet 15:5433f9d94cd7 154 if(ulSize == 1){
dflet 15:5433f9d94cd7 155 i2c.write(ucBuffer[0]);
dflet 15:5433f9d94cd7 156 }else{
dflet 15:5433f9d94cd7 157 for(int i=0;i<ulSize;i++){
dflet 15:5433f9d94cd7 158 i2c.write(ucBuffer[i]);
dflet 15:5433f9d94cd7 159 }
dflet 15:5433f9d94cd7 160 }
dflet 15:5433f9d94cd7 161
dflet 15:5433f9d94cd7 162 i2c.stop();
dflet 15:5433f9d94cd7 163 */
dflet 15:5433f9d94cd7 164 int32_t err = 0;
dflet 18:3f1b52616d00 165
dflet 18:3f1b52616d00 166 // RTOS_MUTEX_ACQUIRE(&g_i2cLock);
dflet 15:5433f9d94cd7 167 err = i2c.write(ucDevAddr,(char*)ucBuffer,ulSize);
dflet 15:5433f9d94cd7 168 if(err == 1){
dflet 15:5433f9d94cd7 169 Uart_Write((uint8_t*)"Return error I2C write\n\r");
dflet 18:3f1b52616d00 170 // RTOS_MUTEX_RELEASE(&g_i2cLock);
dflet 15:5433f9d94cd7 171 return -1;
dflet 15:5433f9d94cd7 172 }
dflet 21:38c6b11aa348 173 wait_ms(1);
dflet 18:3f1b52616d00 174 // RTOS_MUTEX_RELEASE(&g_i2cLock);
dflet 15:5433f9d94cd7 175 return 0;
dflet 15:5433f9d94cd7 176 }
dflet 15:5433f9d94cd7 177
dflet 15:5433f9d94cd7 178 //*****************************************************************************
dflet 15:5433f9d94cd7 179 //
dflet 15:5433f9d94cd7 180 // Close the Doxygen group.
dflet 15:5433f9d94cd7 181 //! @}
dflet 15:5433f9d94cd7 182 //
dflet 15:5433f9d94cd7 183 //*****************************************************************************
dflet 15:5433f9d94cd7 184
dflet 15:5433f9d94cd7 185