M5Unit-RS485 0.1.0 git rev:8a0af48
Loading...
Searching...
No Matches
unit_SIT3088.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
18#ifndef M5_UNIT_RS485_UNIT_SIT3088_HPP
19#define M5_UNIT_RS485_UNIT_SIT3088_HPP
20
21#include "rs485_component.hpp"
22
23namespace m5 {
24namespace unit {
25
31 M5_UNIT_COMPONENT_HPP_BUILDER(UnitSIT3088, 0x00 /*UART*/);
32
33public:
42 int8_t dir_pin{-1};
43 };
44
50 virtual ~UnitSIT3088() = default;
51
56 virtual bool begin() override;
57
60
65 {
66 return _sit_cfg;
67 }
73 inline void config(const config_t &cfg)
74 {
75 _sit_cfg = cfg;
76 // Sync inherited fields (flushRX) to the parent's storage so RS485Component::begin() sees them.
78 }
80
81protected:
88 virtual void configure_dir_pin(const int8_t pin);
95 virtual void set_transmit(const bool tx_enable);
96 // Install a direction-pin-controlled ISerial decorator around the raw HardwareSerial.
97 virtual std::unique_ptr<ISerial> make_serial(AdapterUART *ad) override;
98
99 inline int8_t configured_dir_pin() const
100 {
101 return _configured_dir_pin;
102 }
103
104private:
105 config_t _sit_cfg{};
106 int8_t _configured_dir_pin{-1}; // captured during begin(); immune to post-begin config changes
107
108#if defined(ARDUINO)
109 friend struct DirControlledSerial; // internal decorator needs set_transmit() access
110#endif
111};
112
113} // namespace unit
114} // namespace m5
115#endif
Non-instantiable base class for RS-485 transceiver units.
Definition rs485_component.hpp:37
config_t config()
Gets the configuration.
Definition rs485_component.hpp:79
RS-485 unit using the SIT3088 transceiver (manual direction control via a DIR pin)
Definition unit_SIT3088.hpp:30
config_t config()
Gets the configuration.
Definition unit_SIT3088.hpp:64
virtual bool begin() override
Configure the DIR pin, then begin using the registered UART adapter.
Definition unit_SIT3088.cpp:111
virtual std::unique_ptr< ISerial > make_serial(AdapterUART *ad) override
Factory hook: build the concrete ISerial to be used by begin().
Definition unit_SIT3088.cpp:154
void config(const config_t &cfg)
Sets the configuration.
Definition unit_SIT3088.hpp:73
virtual void configure_dir_pin(const int8_t pin)
One-time setup of the DIR pin as an output (called by begin()).
Definition unit_SIT3088.cpp:130
UnitSIT3088()
Constructor. dir_pin remains unset; set via config() before begin().
Definition unit_SIT3088.cpp:107
virtual void set_transmit(const bool tx_enable)
Switch the transceiver into transmit (true) or receive (false) mode.
Definition unit_SIT3088.cpp:145
virtual ~UnitSIT3088()=default
Destructor.
Top level namespace of M5Stack.
Unit-related namespace.
Common base for RS-485 transceiver units in M5UnitUnified.
Settings for begin.
Definition rs485_component.hpp:69
Settings for begin (extends RS485Component::config_t with the SIT3088 DIR pin)
Definition unit_SIT3088.hpp:41
int8_t dir_pin
DIR (DE/RE tied) GPIO number; -1 = unset (begin() fails)
Definition unit_SIT3088.hpp:42