Skip to content

Commit

Permalink
Adjust formate
Browse files Browse the repository at this point in the history
  • Loading branch information
jixing.zou committed Sep 2, 2016
1 parent f300e45 commit 0f32f8a
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 506 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static void spi_release(spi_t *obj, int slave)
obj->spis->ENABLE = (SPIS_ENABLE_ENABLE_Disabled << SPIS_ENABLE_ENABLE_Pos);
} else {
obj->spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
}
}
}

static void spi_start(spi_t *obj, int slave)
Expand All @@ -48,79 +48,68 @@ static void spi_start(spi_t *obj, int slave)

static void spi_BitOrder(spi_t *obj, BitOrder bit)
{
//spi_release(obj, 0);
if(bit == MSBFIRST)
obj->spi->CONFIG |= (SPI_CONFIG_ORDER_MsbFirst << SPI_CONFIG_ORDER_Pos);
else
obj->spi->CONFIG |= (SPI_CONFIG_ORDER_LsbFirst << SPI_CONFIG_ORDER_Pos);
//spi_start(obj, 0);
//spi_release(obj, 0);
if(bit == MSBFIRST)
obj->spi->CONFIG |= (SPI_CONFIG_ORDER_MsbFirst << SPI_CONFIG_ORDER_Pos);
else
obj->spi->CONFIG |= (SPI_CONFIG_ORDER_LsbFirst << SPI_CONFIG_ORDER_Pos);
//spi_start(obj, 0);
}

SPIClass::SPIClass()
{
//do nothing
//do nothing
}

void SPIClass::begin(uint32_t scl, uint32_t mosi, uint32_t miso)
{
PinName nrf_scl, nrf_mosi, nrf_miso;
nrf_scl = Pin_nRF51822_to_Arduino(scl);
nrf_mosi = Pin_nRF51822_to_Arduino(mosi);
nrf_miso = Pin_nRF51822_to_Arduino(miso);

spi_init(&spi, nrf_mosi, nrf_miso, nrf_scl, (PinName)NC);
/* 8-bits, MODE0, master(0)/slave(1) */
spi_format(&spi, 8, SPI_MODE0, 0);
/* Default speed : 1MHz */
spi_frequency(&spi, SPI_1M);
PinName nrf_scl, nrf_mosi, nrf_miso;

nrf_scl = Pin_nRF51822_to_Arduino(scl);
nrf_mosi = Pin_nRF51822_to_Arduino(mosi);
nrf_miso = Pin_nRF51822_to_Arduino(miso);

spi_init(&spi, nrf_mosi, nrf_miso, nrf_scl, (PinName)NC);
/* 8-bits, MODE0, master(0)/slave(1) */
spi_format(&spi, 8, SPI_MODE0, 0);
/* Default speed : 1MHz */
spi_frequency(&spi, SPI_1M);
}

void SPIClass::begin()
{
begin(SCK, MOSI, MISO);
begin(SCK, MOSI, MISO);
}

uint8_t SPIClass::transfer(uint8_t data)
{
return ((uint8_t)spi_master_write(&spi, data));
return ((uint8_t)spi_master_write(&spi, data));
}

void SPIClass::endTransfer(void)
{
spi_release(&spi, 0);
spi_release(&spi, 0);
}

void SPIClass::setSPIMode(uint8_t mode)
{
if(mode > 3)
return;
/* 8-bits, MODE0, master(0)/slave(1) */
spi_format(&spi, 8, mode, 0);
if(mode > 3)
return;
/* 8-bits, MODE0, master(0)/slave(1) */
spi_format(&spi, 8, mode, 0);
}

void SPIClass::setFrequency(uint32_t speed )
{
/* Default speed : 1MHz */
spi_frequency(&spi, speed);
{
/* Default speed : 1MHz */
spi_frequency(&spi, speed);
}

void SPIClass::setBitORDER( BitOrder bit)
{
spi_BitOrder(&spi, bit);
spi_BitOrder(&spi, bit);
}


SPIClass SPI_Master;











SPIClass SPI_Master;

Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,41 @@

#include "Arduino.h"

#define SPI_125K 125000
#define SPI_250K 250000
#define SPI_500K 500000
#define SPI_1M 1000000
#define SPI_2M 2000000
#define SPI_4M 4000000
#define SPI_8M 8000000
#define SPI_125K 125000
#define SPI_250K 250000
#define SPI_500K 500000
#define SPI_1M 1000000
#define SPI_2M 2000000
#define SPI_4M 4000000
#define SPI_8M 8000000

#define SPI_MODE0 0
#define SPI_MODE1 1
#define SPI_MODE2 2
#define SPI_MODE3 3
#define SPI_MODE0 0
#define SPI_MODE1 1
#define SPI_MODE2 2
#define SPI_MODE3 3


class SPIClass
{
public:
SPIClass();

void begin();
void begin(uint32_t scl, uint32_t mosi, uint32_t miso);
uint8_t transfer(uint8_t data);
void endTransfer(void);

/*This also set bitOrder to MSBFIRST, so don't use setBitORDER befor this */
void setSPIMode(uint8_t mode);
void setFrequency(uint32_t speed );
/*Set bitOrder, this must be after setSPIMode */
void setBitORDER( BitOrder bit);

protected:

spi_t spi;
};
public:
SPIClass();

extern SPIClass SPI_Master;
void begin();
void begin(uint32_t scl, uint32_t mosi, uint32_t miso);
uint8_t transfer(uint8_t data);
void endTransfer(void);

#endif
/*This also set bitOrder to MSBFIRST, so don't use setBitORDER befor this */
void setSPIMode(uint8_t mode);
void setFrequency(uint32_t speed );
/*Set bitOrder, this must be after setSPIMode */
void setBitORDER( BitOrder bit);

protected:

spi_t spi;
};

extern SPIClass SPI_Master;

#endif
Loading

0 comments on commit 0f32f8a

Please sign in to comment.