libraries / Mitov / Mitov_SoftwareSPI.hon commit Added link to project report (97a3ba0)
   1////////////////////////////////////////////////////////////////////////////////
   2//                                                                            //
   3//     This software is supplied under the terms of a license agreement or    //
   4//     nondisclosure agreement with Mitov Software and may not be copied      //
   5//     or disclosed except in accordance with the terms of that agreement.    //
   6//         Copyright(c) 2002-2016 Mitov Software. All Rights Reserved.        //
   7//                                                                            //
   8////////////////////////////////////////////////////////////////////////////////
   9
  10#ifndef _MITOV_SOFTWARE_SPI_h
  11#define _MITOV_SOFTWARE_SPI_h
  12
  13#include <Mitov.h>
  14#include <Mitov_Basic_SPI.h>
  15
  16namespace Mitov
  17{
  18        template<int MOSI_PIN_NUMBER, int CLOCK_PIN_NUMBER> class VisuinoSoftwareSPI : public Mitov::BasicSPI
  19        {
  20                typedef Mitov::BasicSPI inherited;
  21
  22        public:
  23                virtual uint16_t transfer16(uint16_t data)
  24                {
  25                        shiftOut( MOSI_PIN_NUMBER, CLOCK_PIN_NUMBER, MSBFIRST, data >> 8 );
  26                        shiftOut( MOSI_PIN_NUMBER, CLOCK_PIN_NUMBER, MSBFIRST, data );
  27
  28                        return 0;
  29                }
  30
  31                virtual uint8_t transfer(uint8_t data)
  32                {
  33                        shiftOut( MOSI_PIN_NUMBER, CLOCK_PIN_NUMBER, MSBFIRST, data );
  34
  35                        return 0;
  36                }
  37
  38                virtual void transfer(void *buf, size_t count)
  39                {
  40                        for( int i = 0; i < count; ++i )
  41                                shiftOut( MOSI_PIN_NUMBER, CLOCK_PIN_NUMBER, MSBFIRST, ((byte *)buf)[ i ] );
  42                }
  43
  44                virtual void beginTransaction(SPISettings settings)
  45                {
  46                }
  47
  48                virtual void endTransaction()
  49                {
  50                }
  51
  52
  53        protected:
  54                virtual void SystemInit() 
  55                {
  56                        pinMode( MOSI_PIN_NUMBER, OUTPUT );
  57                        pinMode( CLOCK_PIN_NUMBER, OUTPUT );
  58
  59                        inherited::SystemInit();
  60                }
  61
  62        };
  63}
  64
  65#endif