M5Unit-RS485 0.1.0 git rev:8a0af48
Loading...
Searching...
No Matches
m5::unit::UnitSIT3088 Class Reference

RS-485 unit using the SIT3088 transceiver (manual direction control via a DIR pin) More...

#include <unit_SIT3088.hpp>

Inheritance diagram for m5::unit::UnitSIT3088:
m5::unit::RS485Component m5::unit::Tab5BuiltinRS485

Classes

struct  config_t
 Settings for begin (extends RS485Component::config_t with the SIT3088 DIR pin) More...
 

Public Member Functions

 UnitSIT3088 ()
 Constructor. dir_pin remains unset; set via config() before begin().
 
virtual ~UnitSIT3088 ()=default
 Destructor.
 
virtual bool begin () override
 Configure the DIR pin, then begin using the registered UART adapter.
 
Settings for begin
config_t config ()
 Gets the configuration.
 
void config (const config_t &cfg)
 Sets the configuration.
 
- Public Member Functions inherited from m5::unit::RS485Component
virtual ~RS485Component ()=default
 Destructor.
 
config_t config ()
 Gets the configuration.
 
void config (const config_t &cfg)
 Sets the configuration.
 
 operator bool () const
 Returns true if the unit is registered.
 
int available ()
 Returns the number of available bytes to read.
 
int availableForWrite ()
 Returns the number of bytes that can be written without blocking.
 
int peek ()
 Peeks the next incoming byte without removing it.
 
int read ()
 Reads one byte.
 
size_t read (uint8_t *buffer, const size_t size)
 Reads up to size bytes into buffer.
 
size_t read (char *buffer, const size_t size)
 Reads up to size bytes into buffer.
 
size_t readBytes (uint8_t *buffer, const size_t length)
 Reads bytes with timeout defined by underlying Serial.
 
size_t readBytes (char *buffer, const size_t length)
 Reads bytes with timeout defined by underlying Serial.
 
void flush ()
 Flushes the serial port.
 
void flush (const bool txOnly)
 Flushes the serial port.
 
size_t write (const uint8_t d, const bool flush=true)
 Writes one byte.
 
size_t write (const uint8_t *buffer, const size_t size, const bool flush=true)
 Writes bytes from buffer.
 
size_t write (const char *buffer, const size_t size, const bool flush=true)
 Writes bytes from buffer.
 
size_t write (const char *s, const bool flush=true)
 Writes a null-terminated string.
 
template<typename T , bool LittleEndian = true>
bool readValue (T &value)
 Read a trivially copyable value.
 
template<typename T , bool LittleEndian = true>
bool writeValue (const T value)
 Write a trivially copyable value.
 

Protected Member Functions

virtual void configure_dir_pin (const int8_t pin)
 One-time setup of the DIR pin as an output (called by begin()).
 
virtual void set_transmit (const bool tx_enable)
 Switch the transceiver into transmit (true) or receive (false) mode.
 
virtual std::unique_ptr< ISerial > make_serial (AdapterUART *ad) override
 Factory hook: build the concrete ISerial to be used by begin().
 
int8_t configured_dir_pin () const
 
- Protected Member Functions inherited from m5::unit::RS485Component
 RS485Component (const uint8_t addr)
 Base constructor (concrete subclasses pass their DEFAULT_ADDRESS)
 
ISerial * iserial ()
 

Additional Inherited Members

- Static Protected Member Functions inherited from m5::unit::RS485Component
template<typename T >
static T byteswap_if_needed (T v)
 
template<typename T >
static T byteswap_if_needed_impl (T v, byteswap_int_tag)
 
template<typename T >
static T byteswap_if_needed_impl (T v, byteswap_float_tag)
 
template<typename T >
static T byteswap_if_needed_impl (T v, byteswap_none_tag)
 
- Protected Attributes inherited from m5::unit::RS485Component
std::unique_ptr< ISerial > _serial {}
 
config_t _cfg {}
 

Detailed Description

RS-485 unit using the SIT3088 transceiver (manual direction control via a DIR pin)

Member Function Documentation

◆ begin()

bool m5::unit::UnitSIT3088::begin ( )
overridevirtual

Configure the DIR pin, then begin using the registered UART adapter.

Returns
True if successful; false if dir_pin is unset or the adapter is invalid.

Reimplemented from m5::unit::RS485Component.

◆ config() [1/2]

config_t m5::unit::UnitSIT3088::config ( )
inline

Gets the configuration.

Returns
Current configuration

◆ config() [2/2]

void m5::unit::UnitSIT3088::config ( const config_t & cfg)
inline

Sets the configuration.

Parameters
cfgConfiguration settings
Note
Call before Units.begin(). Post-begin mutations have no effect.

◆ configure_dir_pin()

void m5::unit::UnitSIT3088::configure_dir_pin ( const int8_t pin)
protectedvirtual

One-time setup of the DIR pin as an output (called by begin()).

Parameters
pinGPIO number to configure.
Note
Override to customize pin setup (e.g. use hardware RS-485 RTS mode via uart_set_mode).

◆ make_serial()

std::unique_ptr< UnitSIT3088::ISerial > m5::unit::UnitSIT3088::make_serial ( AdapterUART * ad)
overrideprotectedvirtual

Factory hook: build the concrete ISerial to be used by begin().

Parameters
adAdapterUART obtained via asAdapter<AdapterUART>() (never null at call site)
Returns
Owning pointer to the ISerial implementation, or a null-behavior implementation on frameworks not yet supported.
Note
Default implementation wraps the Arduino HardwareSerial exposed by the adapter. Chip-specific subclasses (e.g. UnitSIT3088) override to install a decorator that adds direction-pin control, etc.

Reimplemented from m5::unit::RS485Component.

◆ set_transmit()

void m5::unit::UnitSIT3088::set_transmit ( const bool tx_enable)
protectedvirtual

Switch the transceiver into transmit (true) or receive (false) mode.

Parameters
tx_enabletrue = drive DIR high (TX), false = drive DIR low (RX).
Note
Called on every write from the ISerial decorator. Must be fast (a single GPIO write) so as not to eat into the RS-485 turn-around budget.