SPI or I2C to UART Bridge
Dependents: SC16IS750_Test mbed_SC16IS750 Xadow_SC16IS750_Test Xadow_MPU9150AHRS
SC16IS750 Class Reference
Abstract class SC16IS750 for a bridge between either SPI or I2C and a Serial port. More...
#include <SC16IS750.h>
Inherited by SC16IS750_I2C, SC16IS750_SPI, SC16IS752_I2C, and SC16IS752_SPI.
Public Member Functions | |
int | readable () |
Determine if there is a character available to read. | |
int | readableCount () |
Determine how many characters are available to read. | |
int | writable () |
Determine if there is space available to write a character. | |
int | writableCount () |
Determine how much space available for writing characters. | |
int | getc () |
Read char from UART Bridge. | |
int | putc (int c) |
Write char to UART Bridge. | |
int | printf (const char *format,...) |
Write a formatted string to the UART Bridge. | |
void | writeString (const char *str) |
Write char string to UART Bridge. | |
void | writeBytes (const char *data, int len) |
Write byte array to UART Bridge. | |
void | baud (int baudrate=SC16IS750_DEFAULT_BAUDRATE) |
Set baudrate of the serial port. | |
void | format (int bits=8, Serial::Parity parity=Serial::None, int stop_bits=1) |
Set the transmission format used by the serial port. | |
void | attach (void(*fptr)(void), IrqType type=RxIrq) |
Attach a function to call whenever a serial interrupt is generated. | |
template<typename T > | |
void | attach (T *tptr, void(T::*mptr)(void), IrqType type=RxIrq) |
Attach a member function to call whenever a serial interrupt is generated. | |
void | send_break () |
Generate a break condition on the serial line. | |
void | set_break (bool enable=false) |
Set a break condition on the serial line. | |
void | set_flow_control (Flow type=Disabled, PinName flow1=NC, PinName flow2=NC) |
Set the flow control type on the serial port Added for compatibility with Serial Class. | |
void | set_flow_triggers (int resume=TCR_RESUME_DEFAULT, int halt=TCR_HALT_DEFAULT) |
Set the RX FIFO flow control levels This method sets hardware flow control levels. | |
void | set_modem_control () |
Set the Modem Control register This method sets prescaler, enables TCR and TLR. | |
bool | connected () |
Check that UART is connected and operational. | |
void | set_fifo_control () |
FIFO control, sets TX and RX IRQ trigger levels and enables FIFO and save in _config Note FCR[5:4] (=TX_IRQ_LVL) only accessible when EFR[4] is set (enhanced functions enable) Note TLR only accessible when EFR[4] is set (enhanced functions enable) and MCR[2] is set. | |
void | flush () |
Flush the UART FIFOs while maintaining current FIFO mode. | |
void | ioSetDirection (unsigned char bits) |
Set direction of I/O port pins. | |
void | ioSetState (unsigned char bits) |
Set bits of I/O port pins. | |
unsigned char | ioGetState () |
Get bits of I/O port pins. | |
void | swReset () |
Software Reset SC16IS750 device. | |
virtual void | hwReset ()=0 |
Hardware Reset SC16IS750 device. | |
virtual void | writeRegister (RegisterName register_address, char data)=0 |
Write value to internal register. | |
virtual char | readRegister (RegisterName register_address)=0 |
Read value from internal register. | |
virtual void | writeDataBlock (const char *data, int len)=0 |
Write multiple datavalues to Transmitregister. | |
void | _init () |
Initialise internal registers Should be in protection section. | |
Protected Member Functions | |
SC16IS750 () | |
Constructor is protected for this abstract Class. | |
virtual int | _getc () |
Needed to implement Stream. | |
virtual int | _putc (int c) |
Needed to implement Stream. | |
virtual int | peek () |
Needed to implement Stream. |
Detailed Description
Abstract class SC16IS750 for a bridge between either SPI or I2C and a Serial port.
Supports both SPI and I2C interfaces through derived classes
Definition at line 286 of file SC16IS750.h.
Constructor & Destructor Documentation
SC16IS750 | ( | ) | [protected] |
Constructor is protected for this abstract Class.
Abstract class SC16IS750 for converter between either SPI or I2C and a Serial port Constructor for this Abstract Class is protected Supports both SPI and I2C interfaces through derived classes.
Definition at line 37 of file SC16IS750.cpp.
Member Function Documentation
virtual int _getc | ( | ) | [protected, virtual] |
Needed to implement Stream.
Read char from UART Bridge. Acts in the same manner as 'Serial.read()'.
- Parameters:
-
none
- Returns:
- char read or -1 if no data available.
Definition at line 661 of file SC16IS750.h.
void _init | ( | ) |
Initialise internal registers Should be in protection section.
Public for testing purposes If initialisation fails this method does not return.
- Parameters:
-
none
- Returns:
- none
Definition at line 233 of file SC16IS750.cpp.
virtual int _putc | ( | int | c ) | [protected, virtual] |
Needed to implement Stream.
Write char to UART Bridge. Blocking when no free space in FIFO
- Parameters:
-
value char to be written
- Returns:
- value written
Definition at line 672 of file SC16IS750.h.
void attach | ( | void(*)(void) | fptr, |
IrqType | type = RxIrq |
||
) |
Attach a function to call whenever a serial interrupt is generated.
- Parameters:
-
fptr A pointer to a void function, or 0 to set as none type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
void attach | ( | T * | tptr, |
void(T::*)(void) | mptr, | ||
IrqType | type = RxIrq |
||
) |
Attach a member function to call whenever a serial interrupt is generated.
- Parameters:
-
tptr pointer to the object to call the member function on mptr pointer to the member function to be called type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
- Returns:
- none
Definition at line 490 of file SC16IS750.h.
void baud | ( | int | baudrate = SC16IS750_DEFAULT_BAUDRATE ) |
Set baudrate of the serial port.
- Parameters:
-
baud integer baudrate (4800, 9600 etc)
- Returns:
- none
Definition at line 49 of file SC16IS750.cpp.
bool connected | ( | ) |
Check that UART is connected and operational.
- Parameters:
-
none
- Returns:
- bool true when connected, false otherwise
Definition at line 369 of file SC16IS750.cpp.
void flush | ( | ) |
Flush the UART FIFOs while maintaining current FIFO mode.
- Parameters:
-
none
- Returns:
- none
Definition at line 333 of file SC16IS750.cpp.
void format | ( | int | bits = 8 , |
Serial::Parity | parity = Serial::None , |
||
int | stop_bits = 1 |
||
) |
Set the transmission format used by the serial port.
- Parameters:
-
bits The number of bits in a word (5-8; default = 8) parity The parity used (Serial::None, Serial::Odd, Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None) stop_bits The number of stop bits (1 or 2; default = 1)
- Returns:
- none
Definition at line 70 of file SC16IS750.cpp.
int getc | ( | ) |
Read char from UART Bridge.
Acts in the same manner as 'Serial.read()'.
- Parameters:
-
none
- Returns:
- char read or -1 if no data available.
Definition at line 439 of file SC16IS750.cpp.
virtual void hwReset | ( | ) | [pure virtual] |
Hardware Reset SC16IS750 device.
Pure virtual, must be declared in derived class. This method is only functional when the Reset pin has been declared and is also connected
- Parameters:
-
none
- Returns:
- none
Implemented in SC16IS750_SPI, SC16IS750_I2C, SC16IS752_SPI, and SC16IS752_I2C.
unsigned char ioGetState | ( | ) |
Get bits of I/O port pins.
This method is specific to the SPI-I2C UART and not found on the 16750 Note: The SC16IS752 does not have separate GPIOs for Channel_A and Channel_B.
- Parameters:
-
none
- Returns:
- bits Bitpattern for I/O (1= bit set, 0 = bit cleared)
Definition at line 612 of file SC16IS750.cpp.
void ioSetDirection | ( | unsigned char | bits ) |
Set direction of I/O port pins.
This method is specific to the SPI-I2C UART and not found on the 16750 Note: The SC16IS752 does not have separate GPIOs for Channel_A and Channel_B.
- Parameters:
-
bits Bitpattern for I/O (1=output, 0=input)
- Returns:
- none
Definition at line 592 of file SC16IS750.cpp.
void ioSetState | ( | unsigned char | bits ) |
Set bits of I/O port pins.
This method is specific to the SPI-I2C UART and not found on the 16750 Note: The SC16IS752 does not have separate GPIOs for Channel_A and Channel_B.
- Parameters:
-
bits Bitpattern for I/O (1= set output bit, 0 = clear output bit)
- Returns:
- none
Definition at line 602 of file SC16IS750.cpp.
virtual int peek | ( | ) | [protected, virtual] |
Needed to implement Stream.
Definition at line 679 of file SC16IS750.h.
int printf | ( | const char * | format, |
... | |||
) |
Write a formatted string to the UART Bridge.
Blocking when no free space in FIFO
- Parameters:
-
format A printf-style format string, followed by the variables to use in formatting the string.
int putc | ( | int | value ) |
Write char to UART Bridge.
Blocking when no free space in FIFO
- Parameters:
-
value char to be written
- Returns:
- value written
Definition at line 454 of file SC16IS750.cpp.
int readable | ( | ) |
Determine if there is a character available to read.
This is data that's already arrived and stored in the receive buffer (which holds 64 chars).
- Returns:
- 1 if there is a character available to read, 0 otherwise
Definition at line 385 of file SC16IS750.cpp.
int readableCount | ( | ) |
Determine how many characters are available to read.
This is data that's already arrived and stored in the receive buffer (which holds 64 chars).
- Returns:
- int Characters available to read
Definition at line 402 of file SC16IS750.cpp.
virtual char readRegister | ( | RegisterName | register_address ) | [pure virtual] |
Read value from internal register.
Pure virtual, must be declared in derived class.
- Parameters:
-
registerAddress The address of the Register (enum RegisterName)
- Returns:
- char The 8bit value read from the register
Implemented in SC16IS750_SPI, SC16IS750_I2C, SC16IS752_SPI, and SC16IS752_I2C.
void send_break | ( | ) |
Generate a break condition on the serial line.
- Parameters:
-
none
- Returns:
- none
- none
Definition at line 116 of file SC16IS750.cpp.
void set_break | ( | bool | enable = false ) |
Set a break condition on the serial line.
- Parameters:
-
enable break condition
- Returns:
- none
Definition at line 134 of file SC16IS750.cpp.
void set_fifo_control | ( | ) |
FIFO control, sets TX and RX IRQ trigger levels and enables FIFO and save in _config Note FCR[5:4] (=TX_IRQ_LVL) only accessible when EFR[4] is set (enhanced functions enable) Note TLR only accessible when EFR[4] is set (enhanced functions enable) and MCR[2] is set.
FIFO control, sets TX and RX trigger levels and enables FIFO and save in _config Note FCR[5:4] (=TX_IRQ_LVL) only accessible when EFR[4] is set (enhanced functions enable) Note TLR only accessible when EFR[4] is set (enhanced functions enable) and MCR[2] is set.
- Parameters:
-
none
- Returns:
- none
Definition at line 300 of file SC16IS750.cpp.
void set_flow_control | ( | Flow | type = Disabled , |
PinName | flow1 = NC , |
||
PinName | flow2 = NC |
||
) |
Set the flow control type on the serial port Added for compatibility with Serial Class.
SC16IS750 supports only Flow, Pins can not be selected. This method sets hardware flow control levels. SC16IS750 supports XON/XOFF, but this is not implemented.
- Parameters:
-
type the flow control type (Disabled, RTS, CTS, RTSCTS) flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS) flow2 the second flow control pin (CTS for RTSCTS)
- Returns:
- none
SC16IS750 supports only Flow, Pins can not be selected. This method sets hardware flow control. SC16IS750 supports XON/XOFF, but this is not implemented.
- Parameters:
-
type the flow control type (Disabled, RTS, CTS, RTSCTS) flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS) - NOT USED flow2 the second flow control pin (CTS for RTSCTS) - NOT USED
- Returns:
- none
Definition at line 156 of file SC16IS750.cpp.
void set_flow_triggers | ( | int | resume = TCR_RESUME_DEFAULT , |
int | halt = TCR_HALT_DEFAULT |
||
) |
Set the RX FIFO flow control levels This method sets hardware flow control levels.
SC16IS750 supports XON/XOFF, but this is not implemented. Should be called BEFORE Auto RTS is enabled.
- Parameters:
-
resume trigger level to resume transmission (0..15, meaning 0-60 with a granularity of 4) halt trigger level to resume transmission (0..15, meaning 0-60 with granularity of 4)
- Returns:
- none
Definition at line 193 of file SC16IS750.cpp.
void set_modem_control | ( | ) |
Set the Modem Control register This method sets prescaler, enables TCR and TLR.
- Parameters:
-
none
- Returns:
- none
Definition at line 214 of file SC16IS750.cpp.
void swReset | ( | ) |
Software Reset SC16IS750 device.
This method is specific to the SPI-I2C UART and not found on the 16750 Note: The SC16IS752 does not have separate Reset for Channel_A and Channel_B.
- Parameters:
-
none
- Returns:
- none
Definition at line 623 of file SC16IS750.cpp.
int writable | ( | ) |
Determine if there is space available to write a character.
- Returns:
- 1 if there is a space for a character to write, 0 otherwise
Definition at line 410 of file SC16IS750.cpp.
int writableCount | ( | ) |
Determine how much space available for writing characters.
This considers data that's already stored in the transmit buffer (which holds 64 chars).
- Returns:
- int character space available to write
Definition at line 427 of file SC16IS750.cpp.
void writeBytes | ( | const char * | data, |
int | len | ||
) |
Write byte array to UART Bridge.
Blocking when no free space in FIFO
- Parameters:
-
*data byte array to be written len number of bytes to write
- Returns:
- none
Definition at line 533 of file SC16IS750.cpp.
virtual void writeDataBlock | ( | const char * | data, |
int | len | ||
) | [pure virtual] |
Write multiple datavalues to Transmitregister.
More Efficient implementation than writing individual bytes Pure virtual, must be declared in derived class.
- Parameters:
-
char* databytes The pointer to the block of data len The number of bytes to write
- Returns:
- none
Implemented in SC16IS750_SPI, SC16IS750_I2C, SC16IS752_SPI, and SC16IS752_I2C.
virtual void writeRegister | ( | RegisterName | register_address, |
char | data | ||
) | [pure virtual] |
Write value to internal register.
Pure virtual, must be declared in derived class.
- Parameters:
-
registerAddress The address of the Register (enum RegisterName) data The 8bit value to write
- Returns:
- none
Implemented in SC16IS750_SPI, SC16IS750_I2C, SC16IS752_SPI, and SC16IS752_I2C.
void writeString | ( | const char * | str ) |
Write char string to UART Bridge.
Blocking when no free space in FIFO
- Parameters:
-
*str char string to be written
- Returns:
- none
Definition at line 471 of file SC16IS750.cpp.
Generated on Wed Jul 13 2022 00:35:37 by 1.7.2