![]() |
CHGame 0.3.0
Libraries for the CHGame handheld
|
An SPI master: the Arduino SPI API on one of the chip's SPI peripherals (the global SPI on this board). More...
#include <SPI.h>
Public Member Functions | |
| SPIClass () | |
An SPI on the variant's default pins: MOSI, MISO and SCK (PA7, PA6 and PA5 on this board), with no hardware chip select. | |
| SPIClass (uint32_t mosi, uint32_t miso, uint32_t sclk, uint32_t ssel=PNUM_NOT_DEFINED) | |
| An SPI on the given pins, which must all belong to the same SPI peripheral (on the CH32X035 only SPI1's PA7, PA6, PA5 and PA4 do). | |
| virtual void | begin (uint8_t _pin=CS_PIN_CONTROLLED_BY_USER) |
Starts the SPI with the pin's settings (the defaults the first time: 3 MHz, MSB first, SPI_MODE0). | |
| void | end (void) |
| Stops the SPI: resets SPI1, switches its clock off and forgets every pin's settings. | |
| virtual void | beginTransaction (uint8_t pin, SPISettings settings) |
| Stores a device's settings for a CS pin and programs SPI1 with them. | |
| void | beginTransaction (SPISettings settings) |
| Programs SPI1 with a device's settings, for a device whose CS the sketch drives itself. | |
| void | endTransaction (uint8_t pin) |
| Forgets the pin's settings: transfers for it do nothing until the next begin() or beginTransaction() for it. | |
| void | endTransaction (void) |
| Forgets the settings of the sketch-driven CS: transfer() does nothing until the next begin() or beginTransaction(). | |
| void | usingInterrupt (uint8_t interruptNumber) |
| Does nothing (kept for compatibility): transfers are never guarded against interrupts. | |
| void | attachInterrupt (void) |
| Does nothing (kept for compatibility). | |
| void | detachInterrupt (void) |
| Does nothing (kept for compatibility). | |
| SPI_HandleTypeDef * | getHandle (void) |
| The WCH peripheral library's view of this SPI: its instance and init structure, for mixing in WCH's own SPI functions. | |
Pins (call before begin()) | |
On the CH32X035 SPI1 has one pin for each role, so these only matter for an SPIClass made with no pins at all. | |
| void | setMISO (uint32_t miso) |
| Sets the MISO pin. | |
| void | setMOSI (uint32_t mosi) |
| Sets the MOSI pin. | |
| void | setSCLK (uint32_t sclk) |
| Sets the clock pin. | |
| void | setSSEL (uint32_t ssel) |
| Sets a hardware chip select, driven by the peripheral itself. | |
| void | setMISO (PinName miso) |
| Sets the MISO pin. | |
| void | setMOSI (PinName mosi) |
| Sets the MOSI pin. | |
| void | setSCLK (PinName sclk) |
| Sets the clock pin. | |
| void | setSSEL (PinName ssel) |
| Sets a hardware chip select. | |
Transfers | |
Each one needs begin() or beginTransaction() for its pin first. With a CS pin other than the last transfer's, SPI1 is reset and programmed with that pin's settings first. The class drives the pin low for the transfer and, with | |
| virtual byte | transfer (uint8_t pin, uint8_t _data, SPITransferMode _mode=SPI_LAST) |
| Sends one byte and returns the byte received meanwhile. | |
| virtual uint16_t | transfer16 (uint8_t pin, uint16_t _data, SPITransferMode _mode=SPI_LAST) |
| Sends 16 bits as two bytes and returns the 16 bits received. | |
| virtual void | transfer (uint8_t pin, void *_buf, size_t _count, SPITransferMode _mode=SPI_LAST) |
| Sends a buffer, replacing its bytes with the bytes received. | |
| virtual void | transfer (byte _pin, void *_bufout, void *_bufin, size_t _count, SPITransferMode _mode=SPI_LAST) |
| Sends one buffer and receives into another. | |
| byte | transfer (uint8_t _data, SPITransferMode _mode=SPI_LAST) |
| Sends one byte and returns the byte received meanwhile (CS driven by the sketch). | |
| uint16_t | transfer16 (uint16_t _data, SPITransferMode _mode=SPI_LAST) |
| Sends 16 bits and returns the 16 bits received (CS driven by the sketch). | |
| void | transfer (void *_buf, size_t _count, SPITransferMode _mode=SPI_LAST) |
| Sends a buffer, replacing its bytes with the bytes received (CS driven by the sketch). | |
| void | transfer (void *_bufout, void *_bufin, size_t _count, SPITransferMode _mode=SPI_LAST) |
| Sends one buffer and receives into another (CS driven by the sketch). | |
Deprecated settings | |
Kept for compatibility: use SPISettings with beginTransaction() instead. Each changes one of the pin's settings and then resets and programs SPI1 with them; for a pin with no settings it does nothing. | |
| void | setBitOrder (uint8_t _pin, BitOrder) |
| Sets the bit order for a CS pin. | |
| void | setBitOrder (BitOrder _order) |
| Sets the bit order. | |
| void | setDataMode (uint8_t _pin, uint8_t) |
| Sets the mode for a CS pin. | |
| void | setDataMode (uint8_t _mode) |
| Sets the mode. | |
| void | setClockDivider (uint8_t _pin, uint8_t) |
| Sets the clock for a CS pin as a divider of 48 MHz. | |
| void | setClockDivider (uint8_t _div) |
| Sets the clock as a divider of 48 MHz. | |
Protected Attributes | |
| spi_t | _spi |
| the instance's pins, peripheral and WCH init structure | |
An SPI master: the Arduino SPI API on one of the chip's SPI peripherals (the global SPI on this board).
Every method takes an optional CS pin first. Without it (or with CS_PIN_CONTROLLED_BY_USER) the sketch drives its device's chip select itself; with it, the class drives that pin low for the transfer and high after it, and keeps settings for it apart from other pins'.
| SPIClass::SPIClass | ( | ) |
An SPI on the variant's default pins: MOSI, MISO and SCK (PA7, PA6 and PA5 on this board), with no hardware chip select.
| SPIClass::SPIClass | ( | uint32_t | mosi, |
| uint32_t | miso, | ||
| uint32_t | sclk, | ||
| uint32_t | ssel = PNUM_NOT_DEFINED |
||
| ) |
An SPI on the given pins, which must all belong to the same SPI peripheral (on the CH32X035 only SPI1's PA7, PA6, PA5 and PA4 do).
| mosi | the MOSI pin (PA7). |
| miso | the MISO pin (PA6). |
| sclk | the clock pin (PA5). |
| ssel | a hardware chip select the peripheral drives itself (PA4, the panel's CS on this board), or PNUM_NOT_DEFINED (the default) for none. With one, do not pass CS pins to the other methods. |
|
inline |
Sets the MISO pin.
| miso | the pin's Arduino number (PA6). |
|
inline |
Sets the MOSI pin.
| mosi | the pin's Arduino number (PA7). |
|
inline |
Sets the clock pin.
| sclk | the pin's Arduino number (PA5). |
|
inline |
Sets a hardware chip select, driven by the peripheral itself.
| ssel | the pin's Arduino number (PA4, the panel's CS on this board). |
|
inline |
Sets the MISO pin.
| miso | the pin's name (PA_6). |
|
inline |
Sets the MOSI pin.
| mosi | the pin's name (PA_7). |
|
inline |
Sets the clock pin.
| sclk | the pin's name (PA_5). |
|
inline |
Sets a hardware chip select.
| ssel | the pin's name (PA_4). |
|
virtual |
Starts the SPI with the pin's settings (the defaults the first time: 3 MHz, MSB first, SPI_MODE0).
Resets SPI1 and programs it afresh, and sets the SPI pins up.
| _pin | a CS pin for the class to drive (made an output and set high here), or CS_PIN_CONTROLLED_BY_USER (the default). Nothing happens if NB_SPI_SETTINGS other pins already have settings. |
| void SPIClass::end | ( | void | ) |
Stops the SPI: resets SPI1, switches its clock off and forgets every pin's settings.
|
virtual |
Stores a device's settings for a CS pin and programs SPI1 with them.
Resets SPI1 and programs it afresh. Unlike on AVR, nothing is locked and interrupts are left alone.
| pin | a CS pin for the class to drive (made an output and set high here), or CS_PIN_CONTROLLED_BY_USER. Nothing happens if NB_SPI_SETTINGS other pins already have settings. |
| settings | the device's clock, bit order and mode. |
|
inline |
Programs SPI1 with a device's settings, for a device whose CS the sketch drives itself.
| settings | the device's clock, bit order and mode. |
| void SPIClass::endTransaction | ( | uint8_t | pin | ) |
Forgets the pin's settings: transfers for it do nothing until the next begin() or beginTransaction() for it.
SPI1 is left as it is.
| pin | the CS pin given to beginTransaction(). |
|
inline |
Forgets the settings of the sketch-driven CS: transfer() does nothing until the next begin() or beginTransaction().
|
virtual |
Sends one byte and returns the byte received meanwhile.
| pin | the device's CS pin. |
| _data | the byte to send. |
| _mode | SPI_LAST (the default) releases CS afterwards, SPI_CONTINUE keeps it low for the next transfer. |
SPI_TRANSMITONLY.
|
virtual |
Sends 16 bits as two bytes and returns the 16 bits received.
With MSBFIRST the high byte goes first, with LSBFIRST the low byte, so the bits go out in the chosen order.
| pin | the device's CS pin. |
| _data | the 16 bits to send. |
| _mode | SPI_LAST (the default) or SPI_CONTINUE. |
SPI_TRANSMITONLY.
|
virtual |
Sends a buffer, replacing its bytes with the bytes received.
| pin | the device's CS pin. |
| _buf | the bytes to send, overwritten with those received (left as sent with SPI_TRANSMITONLY). |
| _count | how many bytes (up to 65,535); 0 does nothing. |
| _mode | SPI_LAST (the default) or SPI_CONTINUE. |
|
virtual |
Sends one buffer and receives into another.
| _pin | the device's CS pin. |
| _bufout | the bytes to send. |
| _bufin | receives the bytes received (untouched with SPI_TRANSMITONLY); may be _bufout. |
| _count | how many bytes (up to 65,535); 0 does nothing. |
| _mode | SPI_LAST (the default) or SPI_CONTINUE. |
|
inline |
Sends one byte and returns the byte received meanwhile (CS driven by the sketch).
| _data | the byte to send. |
| _mode | ignored without a CS pin. |
SPI_TRANSMITONLY.
|
inline |
Sends 16 bits and returns the 16 bits received (CS driven by the sketch).
| _data | the 16 bits to send, in the chosen bit order. |
| _mode | ignored without a CS pin. |
SPI_TRANSMITONLY.
|
inline |
Sends a buffer, replacing its bytes with the bytes received (CS driven by the sketch).
| _buf | the bytes to send, overwritten with those received. |
| _count | how many bytes (up to 65,535). |
| _mode | ignored without a CS pin. |
|
inline |
Sends one buffer and receives into another (CS driven by the sketch).
| _bufout | the bytes to send. |
| _bufin | receives the bytes received. |
| _count | how many bytes (up to 65,535). |
| _mode | ignored without a CS pin. |
| void SPIClass::setBitOrder | ( | uint8_t | _pin, |
| BitOrder | |||
| ) |
Sets the bit order for a CS pin.
| _pin | the CS pin. |
_order: MSBFIRST or LSBFIRST.
|
inline |
Sets the bit order.
| _order | MSBFIRST or LSBFIRST. |
| void SPIClass::setDataMode | ( | uint8_t | _pin, |
| uint8_t | |||
| ) |
Sets the mode for a CS pin.
| _pin | the CS pin. |
_mode: SPI_MODE0 ... SPI_MODE3; any other value is ignored.
|
inline |
Sets the mode.
| _mode | SPI_MODE0 ... SPI_MODE3. |
| void SPIClass::setClockDivider | ( | uint8_t | _pin, |
| uint8_t | |||
| ) |
Sets the clock for a CS pin as a divider of 48 MHz.
| _pin | the CS pin. |
_div: SPI_CLOCK_DIV2 ... SPI_CLOCK_DIV128 (any 1-255 works; the result is rounded down to 48 MHz / 2^n); 0 means the default clock (3 MHz).
|
inline |
Sets the clock as a divider of 48 MHz.
| _div | SPI_CLOCK_DIV2 ... SPI_CLOCK_DIV128; 0 means the default clock (3 MHz). |
| void SPIClass::usingInterrupt | ( | uint8_t | interruptNumber | ) |
Does nothing (kept for compatibility): transfers are never guarded against interrupts.
| interruptNumber | ignored. |
| void SPIClass::attachInterrupt | ( | void | ) |
Does nothing (kept for compatibility).
| void SPIClass::detachInterrupt | ( | void | ) |
Does nothing (kept for compatibility).
|
inline |
The WCH peripheral library's view of this SPI: its instance and init structure, for mixing in WCH's own SPI functions.
Use at your own risk.
|
protected |
the instance's pins, peripheral and WCH init structure