pwm period is now 200us instead of the default 20ms veml6040 config is now AF_BIT | TRIG_BIT

Dependencies:   mbed MMA8451Q USBDevice WakeUp vt100

Fork of afero_node_suntory_2017_06_15 by Orefatoi

spi/mbedSPI.cpp

Committer:
wataloh
Date:
2017-01-19
Revision:
1:b2a9a6f2c30e
Parent:
0:20bce0dcc921
Child:
21:d03c7bbb9f37

File content as of revision 1:b2a9a6f2c30e:

#include "mbedSPI.h"
#include "BitOrder.h"

using namespace MaruSolSensorManager;

mbedSPI::mbedSPI() :
    spi((PinName)PINS::ASR_1::SPI::MOSI,
        (PinName)PINS::ASR_1::SPI::MISO,
        (PinName)PINS::ASR_1::SPI::SCK),
    cs((PinName)PINS::ASR_1::SPI::CS,
        PINS::ASR_1::SPI::SIG::CS::DEASSERT)
{
    spi.format(
        PINS::ASR_1::SPI::NUM_BITS_PER_FRAME, //SPI_NUM_BITS_PER_FRAME,
        PINS::ASR_1::SPI::MODE_0);
    spi.frequency(PINS::ASR_1::SPI::FREQUENCY);
#if defined (TARGET_KL25Z)
    #ifndef SPI0_C1
        #define SPI0_C1 (*(uint8_t *)0x40076000)
    #endif
    SPI0_C1 |= 0x01 ; /* LSB First */
#elif defined (TARGET_TEENSY3_1)
    #define SPI0_CTAR0  ((uint32_t *)0x04002C00C)
    #define LSBFE_MASK 0x01000000
    *SPI0_CTAR0 |= LSBFE_MASK ;
#endif
}

void mbedSPI::begin()
{
}

void mbedSPI::beginSPI() /* settings are in this class */
{
    cs = PINS::ASR_1::SPI::SIG::CS::ASSERT;
    wait_us(1);
}

void mbedSPI::endSPI()
{
    cs = PINS::ASR_1::SPI::SIG::CS::DEASSERT;
}

void mbedSPI::transfer(char *bytes,int len)
{
  int i = 0;
  
  for(;i<len;++i)
  {
#if defined (TARGET_KL25Z) || (TARGET_TEENSY3_1)
    bytes[i] = spi.write(bytes[i]) ;
#else
    char c = spi.write(BitOrder::flip(bytes[i]));
    bytes[i] = BitOrder::flip(c);
#endif
  }
}