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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cc3100_spi.h Source File

cc3100_spi.h

00001 /*
00002  * spi.h - mbed
00003  *
00004  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
00005  *
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *    Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  *    Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  *    Neither the name of Texas Instruments Incorporated nor the names of
00020  *    its contributors may be used to endorse or promote products derived
00021  *    from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035 */
00036 
00037 
00038 #ifndef SPI_H_
00039 #define SPI_H_
00040 
00041 #include "mbed.h"
00042 
00043 /*!
00044     \brief   type definition for the spi channel file descriptor
00045 
00046     \note    On each porting or platform the type could be whatever is needed
00047             - integer, pointer to structure etc.
00048 */
00049 typedef unsigned int Fd_t;
00050 
00051 typedef void (*P_EVENT_HANDLER)(void* pValue);
00052 
00053 typedef enum events
00054 {
00055     NO_ACTION = -1,
00056     PUSH_BUTTON_1_PRESSED = 3,
00057     PUSH_BUTTON_2_PRESSED = 4,
00058     BROKER_DISCONNECTION = 2
00059 } osi_messages; 
00060 
00061 namespace mbed_cc3100 {
00062     
00063 class cc3100_driver;    
00064     
00065 class cc3100_spi
00066 {
00067 public:
00068 
00069     cc3100_spi(PinName button1_irq, PinName button2_irq, PinName cc3100_irq, PinName cc3100_nHIB, PinName cc3100_cs, SPI cc3100_spi, cc3100_driver &driver);
00070 
00071     ~cc3100_spi();
00072 
00073 
00074     /*!
00075         \brief          Enables the CC3100
00076 
00077         \param[in]      none
00078 
00079         \return         none
00080 
00081         \note
00082 
00083         \warning
00084     */
00085     void CC3100_enable();
00086 
00087     /*!
00088         \brief          Disables the CC3100
00089 
00090         \param[in]      none
00091 
00092         \return         none
00093 
00094         \note
00095 
00096         \warning
00097     */
00098     void CC3100_disable();
00099     
00100 /*!
00101         \brief          Disables the button push interrupt
00102 
00103         \param[in]      none
00104 
00105         \return         none
00106 
00107         \note
00108 
00109         \warning
00110     */    
00111     void button1_InterruptDisable();
00112     
00113 /*!
00114         \brief          Enables the button push interrupt
00115 
00116         \param[in]      none
00117 
00118         \return         none
00119 
00120         \note
00121 
00122         \warning
00123     */   
00124     void button1_InterruptEnable();
00125     
00126 /*!
00127         \brief          Disables the button push interrupt
00128 
00129         \param[in]      none
00130 
00131         \return         none
00132 
00133         \note
00134 
00135         \warning
00136     */    
00137     void button2_InterruptDisable();
00138     
00139 /*!
00140         \brief          Enables the button push interrupt
00141 
00142         \param[in]      none
00143 
00144         \return         none
00145 
00146         \note
00147 
00148         \warning
00149     */   
00150     void button2_InterruptEnable();    
00151 
00152     /*!
00153         \brief          Enables the interrupt from the CC3100
00154 
00155         \param[in]      none
00156 
00157         \return         none
00158 
00159         \note
00160 
00161         \warning
00162     */
00163     void cc3100_InterruptEnable();
00164 
00165     /*!
00166         \brief          Disables the interrupt from the CC3100
00167 
00168         \param[in]      none
00169 
00170         \return         none
00171 
00172         \note
00173 
00174         \warning
00175     */
00176     void cc3100_InterruptDisable();
00177 
00178     /*!
00179         \brief open spi communication port to be used for communicating with a
00180                SimpleLink device
00181 
00182         Given an interface name and option flags, this function opens the spi
00183         communication port and creates a file descriptor. This file descriptor can
00184         be used afterwards to read and write data from and to this specific spi
00185         channel.
00186         The SPI speed, clock polarity, clock phase, chip select and all other
00187         attributes are all set to hardcoded values in this function.
00188 
00189         \param[in]      ifName    -    points to the interface name/path. The
00190                         interface name is an optional attributes that the simple
00191                         link driver receives on opening the device. in systems that
00192                         the spi channel is not implemented as part of the os device
00193                         drivers, this parameter could be NULL.
00194         \param[in]      flags     -    option flags
00195 
00196         \return         upon successful completion, the function shall open the spi
00197                         channel and return a non-negative integer representing the
00198                         file descriptor. Otherwise, -1 shall be returned
00199 
00200         \sa             spi_Close , spi_Read , spi_Write
00201         \note
00202         \warning
00203     */
00204 
00205     Fd_t spi_Open(int8_t *ifName, uint32_t flags);
00206 
00207     /*!
00208         \brief closes an opened spi communication port
00209 
00210         \param[in]      fd    -     file descriptor of an opened SPI channel
00211 
00212         \return         upon successful completion, the function shall return 0.
00213                         Otherwise, -1 shall be returned
00214 
00215         \sa             spi_Open
00216         \note
00217         \warning
00218     */
00219     int spi_Close(Fd_t fd);
00220 
00221     /*!
00222         \brief attempts to read up to len bytes from SPI channel into a buffer
00223                starting at pBuff.
00224 
00225         \param[in]      fd     -    file descriptor of an opened SPI channel
00226 
00227         \param[in]      pBuff  -    points to first location to start writing the
00228                         data
00229 
00230         \param[in]      len    -    number of bytes to read from the SPI channel
00231 
00232         \return         upon successful completion, the function shall return 0.
00233                         Otherwise, -1 shall be returned
00234 
00235         \sa             spi_Open , spi_Write
00236         \note
00237         \warning
00238     */
00239     int spi_Read(Fd_t fd, uint8_t *pBuff, int len);
00240 
00241     /*!
00242         \brief attempts to write up to len bytes to the SPI channel
00243 
00244         \param[in]      fd        -    file descriptor of an opened SPI channel
00245 
00246         \param[in]      pBuff     -    points to first location to start getting the
00247                         data from
00248 
00249         \param[in]      len       -    number of bytes to write to the SPI channel
00250 
00251         \return         upon successful completion, the function shall return 0.
00252                         Otherwise, -1 shall be returned
00253 
00254         \sa             spi_Open , spi_Read
00255         \note           This function could be implemented as zero copy and return
00256                         only upon successful completion of writing the whole buffer,
00257                         but in cases that memory allocation is not too tight, the
00258                         function could copy the data to internal buffer, return
00259                         back and complete the write in parallel to other activities
00260                         as long as the other SPI activities would be blocked untill
00261                         the entire buffer write would be completed
00262         \warning
00263     */
00264     int spi_Write(Fd_t fd, uint8_t *pBuff, int len);
00265 
00266     /*!
00267         \brief          The IntSpiGPIOHandler interrupt handler
00268 
00269         \param[in]      none
00270 
00271         \return         none
00272 
00273         \note
00274 
00275         \warning
00276     */
00277     void IntSpiGPIOHandler(void);
00278 
00279     /*!
00280         \brief register an interrupt handler for the host IRQ
00281 
00282         \param[in]      InterruptHdl    -    pointer to interrupt handler function
00283 
00284         \param[in]      pValue          -    pointer to a memory strcuture that is
00285                         passed to the interrupt handler.
00286 
00287         \return         upon successful registration, the function shall return 0.
00288                         Otherwise, -1 shall be returned
00289 
00290         \sa
00291         \note           If there is already registered interrupt handler, the
00292                         function should overwrite the old handler with the new one
00293         \warning
00294     */
00295     int registerInterruptHandler(P_EVENT_HANDLER InterruptHdl , void* pValue);
00296 
00297     /*!
00298         \brief      Masks the Host IRQ
00299 
00300         \param[in]      none
00301 
00302         \return         none
00303 
00304         \warning
00305     */
00306     void MaskIntHdlr();
00307 
00308     /*!
00309         \brief     Unmasks the Host IRQ
00310 
00311         \param[in]      none
00312 
00313         \return         none
00314 
00315         \warning
00316     */
00317     void UnMaskIntHdlr();
00318     
00319     void buttonHandler_1(void);
00320 
00321     void buttonHandler_2(void);
00322    
00323 private:
00324     
00325 //    InterruptIn         _sw1_irq;
00326 //    InterruptIn         _sw2_irq;
00327     InterruptIn         _wlan_irq;
00328     DigitalOut          _wlan_nHIB;
00329     DigitalOut          _wlan_cs;
00330     SPI                 _wlan_spi;
00331     cc3100_driver       &_driver;
00332 
00333 
00334 };//class
00335 }//namespace mbed_cc3100
00336 #endif
00337 
00338 
00339