M5Unit-RS485 0.2.0 git rev:0956c20
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 */
21#ifndef M5_UNIT_RS485_UNIT_SIT3088_HPP
22#define M5_UNIT_RS485_UNIT_SIT3088_HPP
23
24#include "rs485_component.hpp"
25
26namespace m5 {
27namespace unit {
28
34 M5_UNIT_COMPONENT_HPP_BUILDER(UnitSIT3088, 0x00 /*UART*/);
35
36public:
45 int8_t dir_pin{-1};
46 };
47
53 virtual ~UnitSIT3088() = default;
54
59 virtual bool begin() override;
60
63
67 inline config_t config() const
68 {
69 // Only dir_pin lives here; the inherited fields are kept by the base alone, so that a write
70 // through an RS485Component & reference cannot leave two copies disagreeing. Assigning the
71 // base slice rather than each field keeps this correct when the base gains one.
72 config_t cfg{};
74 cfg.dir_pin = _dir_pin;
75 return cfg;
76 }
82 inline void config(const config_t &cfg)
83 {
84 _dir_pin = cfg.dir_pin;
86 }
88
89protected:
96 virtual void configure_dir_pin(const int8_t pin);
103 virtual void set_transmit(const bool tx_enable);
104 // Install a direction-pin-controlled ISerial decorator around the raw HardwareSerial.
105 virtual std::unique_ptr<ISerial> make_serial(AdapterUART *ad) override;
106
107 inline int8_t configured_dir_pin() const
108 {
109 return _configured_dir_pin;
110 }
111
112private:
113 // ISerial decorators that drive the DIR pin around each write, one per framework, defined in
114 // the translation unit. Nesting them here is what gives them access to set_transmit(), and it
115 // keeps their names out of the enclosing namespace. Declared unconditionally: a nested class
116 // that is never defined on this framework is harmless.
117 struct DirControlledSerial; // Arduino
118 struct DirControlledIDFSerial; // ESP-IDF native
119
120 int8_t _dir_pin{-1}; // the only field this class owns; see config()
121 int8_t _configured_dir_pin{-1}; // captured during begin(); immune to post-begin config changes
122};
123
124} // namespace unit
125} // namespace m5
126#endif
Non-instantiable base class for RS-485 transceiver units.
Definition rs485_component.hpp:37
config_t config() const
Gets the configuration.
Definition rs485_component.hpp:108
RS-485 unit using the SIT3088 transceiver (manual direction control via a DIR pin)
Definition unit_SIT3088.hpp:33
virtual bool begin() override
Configure the DIR pin, then begin using the registered UART adapter.
Definition unit_SIT3088.cpp:118
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:172
void config(const config_t &cfg)
Sets the configuration.
Definition unit_SIT3088.hpp:82
config_t config() const
Gets the configuration.
Definition unit_SIT3088.hpp:67
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:145
UnitSIT3088()
Constructor. dir_pin remains unset; set via config() before begin().
Definition unit_SIT3088.cpp:114
virtual void set_transmit(const bool tx_enable)
Switch the transceiver into transmit (true) or receive (false) mode.
Definition unit_SIT3088.cpp:160
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:98
Settings for begin (extends RS485Component::config_t with the SIT3088 DIR pin)
Definition unit_SIT3088.hpp:44
int8_t dir_pin
DIR (DE/RE tied) GPIO number; -1 = unset (begin() fails)
Definition unit_SIT3088.hpp:45