Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BufferedSpi Class Reference
A spi port (SPI) for communication with wifi device. More...
#include <BufferedSpi.h>
Public Member Functions | |
BufferedSpi (PinName mosi, PinName miso, PinName sclk, PinName nss, PinName datareadypin, uint32_t buf_size=2500, uint32_t tx_multiple=1, const char *name=NULL) | |
Create a BufferedSpi Port, connected to the specified transmit and receive pins. | |
virtual | ~BufferedSpi (void) |
Destroy a BufferedSpi Port. | |
virtual void | frequency (int hz) |
call to SPI frequency Function | |
virtual void | flush_txbuf (void) |
clear the transmit buffer | |
virtual void | format (int bits, int mode) |
call to SPI format function | |
virtual int | readable (void) |
Check on how many bytes are in the rx buffer. | |
virtual int | writeable (void) |
Check to see if the tx buffer has room. | |
virtual int | getc (void) |
Get a single byte from the BufferedSpi Port. | |
virtual int | putc (int c) |
Write a single byte to the BufferedSpi Port. | |
virtual int | puts (const char *s) |
Write a string to the BufferedSpi Port. | |
virtual int | printf (const char *format,...) |
Write a formatted string to the BufferedSpi Port. | |
virtual ssize_t | buffwrite (const void *s, std::size_t length) |
Write data to the Buffered Spi Port. | |
virtual ssize_t | buffsend (size_t length) |
Send datas to the Spi port that are already present in the internal _txbuffer. | |
virtual ssize_t | read () |
Read data from the Spi Port to the _rxbuf. | |
void | setTimeout (int timeout) |
Allows timeout to be changed between commands. | |
virtual void | sigio (Callback< void()> func) |
Register a callback once any data is ready for sockets. | |
virtual void | attach (Callback< void()> func, IrqType type=RxIrq) |
Attach a function to call whenever a serial interrupt is generated. | |
template<typename T > | |
void | attach (T *obj, void(T::*method)(), IrqType type=RxIrq) |
Attach a member function to call whenever a serial interrupt is generated. | |
template<typename T > | |
void | attach (T *obj, void(*method)(T *), IrqType type=RxIrq) |
Attach a member function to call whenever a serial interrupt is generated. |
Detailed Description
A spi port (SPI) for communication with wifi device.
Can be used for Full Duplex communication, or Simplex by specifying one pin as NC (Not Connected)
Example:
#include "mbed.h" #include "BufferedSerial.h" BufferedSerial pc(USBTX, USBRX); int main() { while(1) { Timer s; s.start(); pc.printf("Hello World - buffered\n"); int buffered_time = s.read_us(); wait(0.1f); // give time for the buffer to empty s.reset(); printf("Hello World - blocking\n"); int polled_time = s.read_us(); s.stop(); wait(0.1f); // give time for the buffer to empty pc.printf("printf buffered took %d us\n", buffered_time); pc.printf("printf blocking took %d us\n", polled_time); wait(0.5f); } }
Software buffers and interrupt driven tx and rx for Serial
Definition at line 71 of file BufferedSpi.h.
Constructor & Destructor Documentation
BufferedSpi | ( | PinName | mosi, |
PinName | miso, | ||
PinName | sclk, | ||
PinName | nss, | ||
PinName | datareadypin, | ||
uint32_t | buf_size = 2500 , |
||
uint32_t | tx_multiple = 1 , |
||
const char * | name = NULL |
||
) |
Create a BufferedSpi Port, connected to the specified transmit and receive pins.
- Parameters:
-
SPI mosi pin SPI miso pin SPI sclk pin SPI nss pin Dataready pin buf_size printf() buffer size tx_multiple amount of max printf() present in the internal ring buffer at one time name optional name
Definition at line 77 of file BufferedSpi.cpp.
~BufferedSpi | ( | void | ) | [virtual] |
Destroy a BufferedSpi Port.
Definition at line 95 of file BufferedSpi.cpp.
Member Function Documentation
void attach | ( | Callback< void()> | func, |
IrqType | type = RxIrq |
||
) | [virtual] |
Attach a function to call whenever a serial interrupt is generated.
- Parameters:
-
func A pointer to a void function, or 0 to set as none type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
Definition at line 318 of file BufferedSpi.cpp.
void attach | ( | T * | obj, |
void(T::*)() | method, | ||
IrqType | type = RxIrq |
||
) |
Attach a member function to call whenever a serial interrupt is generated.
- Parameters:
-
obj pointer to the object to call the member function on method pointer to the member function to call type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
Definition at line 218 of file BufferedSpi.h.
void attach | ( | T * | obj, |
void(*)(T *) | method, | ||
IrqType | type = RxIrq |
||
) |
Attach a member function to call whenever a serial interrupt is generated.
- Parameters:
-
obj pointer to the object to call the member function on method pointer to the member function to call type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
Definition at line 229 of file BufferedSpi.h.
ssize_t buffsend | ( | size_t | length ) | [virtual] |
Send datas to the Spi port that are already present in the internal _txbuffer.
- Parameters:
-
length
- Returns:
- the number of bytes written on the SPI port
Definition at line 222 of file BufferedSpi.cpp.
virtual ssize_t buffwrite | ( | const void * | s, |
std::size_t | length | ||
) | [virtual] |
Write data to the Buffered Spi Port.
- Parameters:
-
s A pointer to data to send length The amount of data being pointed to
- Returns:
- The number of bytes written to the Spi Port Buffer
void flush_txbuf | ( | void | ) | [virtual] |
clear the transmit buffer
Definition at line 151 of file BufferedSpi.cpp.
void format | ( | int | bits, |
int | mode | ||
) | [virtual] |
call to SPI format function
Definition at line 106 of file BufferedSpi.cpp.
void frequency | ( | int | hz ) | [virtual] |
call to SPI frequency Function
Definition at line 101 of file BufferedSpi.cpp.
int getc | ( | void | ) | [virtual] |
Get a single byte from the BufferedSpi Port.
Should check readable() before calling this.
- Returns:
- A byte that came in on the SPI Port
Definition at line 135 of file BufferedSpi.cpp.
int printf | ( | const char * | format, |
... | |||
) | [virtual] |
Write a formatted string to the BufferedSpi Port.
- Parameters:
-
format The string + format specifiers to write to the Spi Port
- Returns:
- The number of bytes written to the Spi Port Buffer
Definition at line 177 of file BufferedSpi.cpp.
int putc | ( | int | c ) | [virtual] |
Write a single byte to the BufferedSpi Port.
- Parameters:
-
c The byte to write to the SPI Port
- Returns:
- The byte that was written to the SPI Port Buffer
Definition at line 144 of file BufferedSpi.cpp.
int puts | ( | const char * | s ) | [virtual] |
Write a string to the BufferedSpi Port.
Must be NULL terminated
- Parameters:
-
s The string to write to the Spi Port
- Returns:
- The number of bytes written to the Spi Port Buffer
Definition at line 156 of file BufferedSpi.cpp.
ssize_t read | ( | ) | [virtual] |
Read data from the Spi Port to the _rxbuf.
- Parameters:
-
max,: optional. = max sieze of the input read
- Returns:
- The number of bytes read from the SPI port and written to the _rxbuf
Definition at line 245 of file BufferedSpi.cpp.
int readable | ( | void | ) | [virtual] |
Check on how many bytes are in the rx buffer.
- Returns:
- 1 if something exists, 0 otherwise
Definition at line 125 of file BufferedSpi.cpp.
void setTimeout | ( | int | timeout ) |
Allows timeout to be changed between commands.
- Parameters:
-
timeout timeout of the connection in ms
Definition at line 195 of file BufferedSpi.h.
void sigio | ( | Callback< void()> | func ) | [virtual] |
Register a callback once any data is ready for sockets.
- Parameters:
-
func Function to call on state change
Definition at line 323 of file BufferedSpi.cpp.
int writeable | ( | void | ) | [virtual] |
Check to see if the tx buffer has room.
- Returns:
- 1 always has room and can overwrite previous content if too small / slow
Definition at line 130 of file BufferedSpi.cpp.
Generated on Mon Aug 29 2022 19:53:43 by
