Skip to content

Commit

Permalink
i2c和spi在未选定时编译不会报错
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterywolf committed May 1, 2022
1 parent 8d6683f commit be07586
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
14 changes: 13 additions & 1 deletion libraries/buildin/SPI/SPI.cpp
Expand Up @@ -21,7 +21,6 @@
*/

#include "SPI.h"
#include <rtdevice.h>

SPIClass SPI;

Expand Down Expand Up @@ -116,3 +115,16 @@ void SPIClass::end(void)
{
/* Nothing to do. RTduino has no right to shutdown RT-Thread SPI devcies */
}

/* legacy functions */
void SPIClass::setBitOrder(uint8_t bitOrder)
{
}

void SPIClass::setDataMode(uint8_t dataMode)
{
}

void SPIClass::setClockDivider(uint8_t clockDiv)
{
}
21 changes: 19 additions & 2 deletions libraries/buildin/SPI/SPI.h
Expand Up @@ -53,10 +53,19 @@
#define MSBFIRST 1
#endif

#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06

#define SPI_MODE0 0x00 ///< CPOL: 0 CPHA: 0
#define SPI_MODE1 0x04 ///< CPOL: 0 CPHA: 1
#define SPI_MODE2 0x08 ///< CPOL: 1 CPHA: 0
#define SPI_MODE3 0x0C ///< CPOL: 1 CPHA: 1

class SPISettings
{
public:
Expand All @@ -67,18 +76,26 @@ class SPISettings
uint8_t _dataMode;
};

#ifndef RTDUINO_DEFAULT_SPI_BUS_NAME
#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi0" /* dummy name */
#endif

class SPIClass
{
private:
struct rt_spi_device spi_device;
public:
struct rt_spi_device spi_device;

void begin(const char *spi_bus_name = RTDUINO_DEFAULT_SPI_BUS_NAME);
void beginTransaction(SPISettings settings);
uint8_t transfer(uint8_t data);
void transfer(void *buf, size_t count);
uint16_t transfer16(uint16_t data);
void endTransaction(void);
void end(void);
/* legacy functions */
void setBitOrder(uint8_t bitOrder);
void setDataMode(uint8_t dataMode);
void setClockDivider(uint8_t clockDiv);
};

extern SPIClass SPI;
Expand Down
4 changes: 4 additions & 0 deletions libraries/buildin/Wire/Wire.h
Expand Up @@ -43,6 +43,10 @@
#define RTDUINO_WIRE_BUFFER_LENGTH 32
#endif

#ifndef RTDUINO_DEFAULT_IIC_BUS_NAME
#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c0" /* dummy name */
#endif

class TwoWire : public Stream
{
private:
Expand Down

0 comments on commit be07586

Please sign in to comment.