CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
SPI.h File Reference

Arduino's SPI library (SPIClass, SPISettings), ported to WCH's chips: SPI master on the CH32X035's SPI1. More...

#include "Arduino.h"
#include <stdio.h>
#include "utility/spi_com.h"

Go to the source code of this file.

Classes

class  SPISettings
 A device's SPI settings: its maximum clock, bit order and mode, for SPIClass::beginTransaction(). More...
 
class  SPIClass
 An SPI master: the Arduino SPI API on one of the chip's SPI peripherals (the global SPI on this board). More...
 

Macros

#define SPI_HAS_TRANSACTION   1
 Defined to 1: this SPI has beginTransaction(), endTransaction(), usingInterrupt() and SPISettings(clock, bitOrder, dataMode).
 
#define CS_PIN_CONTROLLED_BY_USER   NUM_DIGITAL_PINS
 The "CS pin" that means the sketch drives its chip select itself, outside the SPI class (the default for every method).
 
#define NO_CONFIG   ((int16_t)(-1))
 Indicates there is no configuration selected (internal).
 
#define SPI_TRANSFER_TIMEOUT   1000
 How long one transfer call may take before it gives up, in ms (default 1000).
 
#define NB_SPI_SETTINGS   4
 The number of CS pins whose settings an SPIClass remembers, 1 to 254 (default 4).
 
Clock dividers for setClockDivider() (deprecated)

Compatibility with sketches designed for AVR at 16 MHz cannot be ensured, as the SPI clock depends on the system clock: here the divider applies to 48 MHz, and the result is then rounded down to 48 MHz / 2^n.

New code passes the clock in Hz to SPISettings with SPI.beginTransaction() instead.

#define SPI_CLOCK_DIV2   2
 48 MHz / 2 = 24 MHz
 
#define SPI_CLOCK_DIV4   4
 48 MHz / 4 = 12 MHz
 
#define SPI_CLOCK_DIV8   8
 48 MHz / 8 = 6 MHz
 
#define SPI_CLOCK_DIV16   16
 48 MHz / 16 = 3 MHz
 
#define SPI_CLOCK_DIV32   32
 48 MHz / 32 = 1.5 MHz
 
#define SPI_CLOCK_DIV64   64
 48 MHz / 64 = 750 kHz
 
#define SPI_CLOCK_DIV128   128
 48 MHz / 128 = 375 kHz
 
SPI modes, for SPISettings and setDataMode()
#define SPI_MODE0   0x00
 clock idles low, data sampled on the rising edge (CPOL 0, CPHA 0)
 
#define SPI_MODE1   0x01
 clock idles low, data sampled on the falling edge (CPOL 0, CPHA 1)
 
#define SPI_MODE2   0x02
 clock idles high, data sampled on the falling edge (CPOL 1, CPHA 0)
 
#define SPI_MODE3   0x03
 clock idles high, data sampled on the rising edge (CPOL 1, CPHA 1)
 
Receive or not, for SPISettings' noRecv
#define SPI_TRANSMITRECEIVE   0x0
 send and receive (the default)
 
#define SPI_TRANSMITONLY   0x1
 send only: what comes back is not read, and transfer() returns 0
 

Enumerations

enum  SPITransferMode {
  SPI_CONTINUE ,
  SPI_LAST
}
 What a transfer does with a CS pin the class drives, once it is done. More...
 

Variables

SPIClass SPI
 The SPI: SPI1 on PA5 (SCK), PA6 (MISO) and PA7 (MOSI), the bus the board's panel and SD card are on.
 

Detailed Description

Arduino's SPI library (SPIClass, SPISettings), ported to WCH's chips: SPI master on the CH32X035's SPI1.