Skip to content

Commit 05391b1

Browse files
committed
Group add/assign by bus type and complete Doxygen comments
1 parent 87dca49 commit 05391b1

2 files changed

Lines changed: 215 additions & 48 deletions

File tree

src/M5UnitComponent.hpp

Lines changed: 172 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,18 @@ class Component {
8282

8383
///@name Component settings
8484
///@{
85-
/*! @brief Gets the common configurations in each unit */
85+
/*!
86+
@brief Gets the common configurations in each unit
87+
@return Current component configuration
88+
*/
8689
inline component_config_t component_config() const
8790
{
8891
return _component_cfg;
8992
}
90-
//! @brief Set the common configurations in each unit
93+
/*!
94+
@brief Set the common configurations in each unit
95+
@param cfg Configuration to apply
96+
*/
9197
inline void component_config(const component_config_t& cfg)
9298
{
9399
_component_cfg = cfg;
@@ -116,55 +122,85 @@ class Component {
116122

117123
///@name Properties
118124
///@{
119-
/*! @brief Gets the device name */
125+
/*!
126+
@brief Gets the device name
127+
@return Pointer to the null-terminated device name string
128+
*/
120129
inline const char* deviceName() const
121130
{
122131
return unit_device_name();
123132
}
124-
//! @brief Gets the identifier
133+
/*!
134+
@brief Gets the identifier
135+
@return Unique identifier of the unit
136+
*/
125137
inline types::uid_t identifier() const
126138
{
127139
return unit_identifier();
128140
}
129-
//! @brief Gets the attributes
141+
/*!
142+
@brief Gets the attributes
143+
@return Attribute flags of the unit
144+
*/
130145
inline types::attr_t attribute() const
131146
{
132147
return unit_attribute();
133148
}
134-
//! @brief Gets the category
149+
/*!
150+
@brief Gets the category
151+
@return Category of the unit
152+
*/
135153
inline types::category_t category() const
136154
{
137155
return unit_category();
138156
}
139-
//! @brief Gets the registered order (== 0 means not yet)
157+
/*!
158+
@brief Gets the registered order (== 0 means not yet)
159+
@return Registration order; 0 if not yet registered
160+
*/
140161
inline uint32_t order() const
141162
{
142163
return _order;
143164
}
144-
//! @brief Gets the channel if connected to another unit
165+
/*!
166+
@brief Gets the channel if connected to another unit
167+
@return Channel number; negative if not connected to a parent
168+
*/
145169
inline int16_t channel() const
146170
{
147171
return _channel;
148172
}
149-
//! @brief Is the unit registered with the manager?
173+
/*!
174+
@brief Is the unit registered with the manager?
175+
@return True if registered with a UnitUnified manager
176+
*/
150177
inline bool isRegistered() const
151178
{
152179
return _manager != nullptr;
153180
}
154-
//! @brief Address used to I2C access the device
181+
/*!
182+
@brief Address used to I2C access the device
183+
@return I2C address of the device
184+
*/
155185
inline uint8_t address() const
156186
{
157187
return _addr;
158188
}
159189
/*!
160190
@brief Gets the access adapter
191+
@return Pointer to the adapter; ownership is retained by the unit
161192
@warning Ownership is retained by the unit and should not be released
162193
*/
163194
inline Adapter* adapter() const
164195
{
165196
return _adapter.get();
166197
}
167-
//! @brief Gets the access adapter
198+
/*!
199+
@brief Gets the access adapter cast to the specified type
200+
@tparam T Adapter-derived pointer type to cast to
201+
@param t Expected adapter type
202+
@return Pointer to the adapter cast to T, or nullptr if type does not match
203+
*/
168204
template <class T>
169205
inline auto asAdapter(const Adapter::Type t) ->
170206
typename std::remove_cv<typename std::remove_pointer<T>::type>::type*
@@ -173,6 +209,12 @@ class Component {
173209
static_assert(std::is_base_of<Adapter, U>::value, "T must be derived from Adapter");
174210
return (_adapter->type() == t) ? static_cast<U*>(_adapter.get()) : nullptr;
175211
}
212+
/*!
213+
@brief Gets the access adapter cast to the specified type (const overload)
214+
@tparam T Adapter-derived pointer type to cast to
215+
@param t Expected adapter type
216+
@return Const pointer to the adapter cast to T, or nullptr if type does not match
217+
*/
176218
template <class T>
177219
inline auto asAdapter(const Adapter::Type t) const -> const
178220
typename std::remove_cv<typename std::remove_pointer<T>::type>::type*
@@ -185,20 +227,42 @@ class Component {
185227

186228
///@name Attributes
187229
///@{
230+
/*!
231+
@brief Can the unit access via I2C?
232+
@return True if the current adapter supports I2C access
233+
*/
188234
bool canAccessI2C() const;
235+
/*!
236+
@brief Can the unit access via GPIO?
237+
@return True if the current adapter supports GPIO access
238+
*/
189239
bool canAccessGPIO() const;
240+
/*!
241+
@brief Can the unit access via UART?
242+
@return True if the current adapter supports UART access
243+
*/
190244
bool canAccessUART() const;
245+
/*!
246+
@brief Can the unit access via SPI?
247+
@return True if the current adapter supports SPI access
248+
*/
191249
bool canAccessSPI() const;
192250
///@}
193251

194252
///@name Periodic measurement
195253
///@{
196-
/*! @brief In periodic measurement? */
254+
/*!
255+
@brief In periodic measurement?
256+
@return True if the unit is currently in periodic measurement mode
257+
*/
197258
inline bool inPeriodic() const
198259
{
199260
return in_periodic();
200261
}
201-
//! @brief Periodic measurement data updated?
262+
/*!
263+
@brief Periodic measurement data updated?
264+
@return True if measurement data was updated in the last update() call
265+
*/
202266
inline bool updated() const
203267
{
204268
return _updated;
@@ -221,54 +285,128 @@ class Component {
221285
}
222286
///@}
223287

224-
///@name Bus assignment
288+
///@name Assign(I2C)
225289
///@{
226-
/*! @brief Assign m5::hal::bus */
227-
virtual bool assign(m5::hal::bus::Bus* bus);
228-
/*! @brief Assign TwoWire */
290+
/*!
291+
@brief Assign TwoWire as the communication bus
292+
@param wire TwoWire to be used
293+
@return True if successful
294+
*/
229295
virtual bool assign(TwoWire& wire);
230-
/*! @brief Assign I2C_Class */
296+
/*!
297+
@brief Assign I2C_Class as the communication bus
298+
@param i2c I2C_Class to be used (e.g. M5.In_I2C)
299+
@return True if successful
300+
*/
231301
virtual bool assign(m5::I2C_Class& i2c);
232-
/*! @brief Assign GPIO */
302+
///@}
303+
304+
///@name Assign(GPIO)
305+
///@{
306+
/*!
307+
@brief Assign GPIO pins as the communication bus
308+
@param rx_pin Pin number to be used for RX
309+
@param tx_pin Pin number to be used for TX
310+
@return True if successful
311+
*/
233312
virtual bool assign(const int8_t rx_pin, const int8_t tx_pin);
234-
/*! @brief Assign UART */
313+
///@}
314+
315+
///@name Assign(UART)
316+
///@{
317+
/*!
318+
@brief Assign HardwareSerial as the communication bus
319+
@param serial HardwareSerial to be used
320+
@return True if successful
321+
*/
235322
virtual bool assign(HardwareSerial& serial);
236-
/*! @brief Assign SPI */
323+
///@}
324+
325+
///@name Assign(SPI)
326+
///@{
327+
/*!
328+
@brief Assign SPIClass as the communication bus
329+
@param spi SPIClass to be used
330+
@param settings SPI settings to be applied
331+
@return True if successful
332+
*/
237333
virtual bool assign(SPIClass& spi, const SPISettings& settings);
238334
///@}
239335

336+
///@name Assign(M5HAL)
337+
///@{
338+
/*!
339+
@brief Assign m5::hal::bus as the communication bus
340+
@param bus Bus to be used
341+
@return True if successful
342+
*/
343+
virtual bool assign(m5::hal::bus::Bus* bus);
344+
///@}
345+
240346
///@note For daisy-chaining units such as hubs
241347
///@name Parent-children relationship
242348
///@{
243-
/*! @brief Has parent unit? */
349+
/*!
350+
@brief Has parent unit?
351+
@return True if this unit is connected to a parent unit
352+
*/
244353
inline bool hasParent() const
245354
{
246355
return _parent != nullptr;
247356
}
248-
//! @brief Are there any other devices connected to the same parent unit besides yourself?
357+
/*!
358+
@brief Are there any other devices connected to the same parent unit besides yourself?
359+
@return True if sibling units exist on the same parent
360+
*/
249361
inline bool hasSiblings() const
250362
{
251363
return (_prev != nullptr) || (_next != nullptr);
252364
}
253-
//! @brief Are there other devices connected to me?
365+
/*!
366+
@brief Are there other devices connected to me?
367+
@return True if at least one child unit is connected
368+
*/
254369
inline bool hasChildren() const
255370
{
256371
return _child;
257372
}
258-
//! @brief Number of units connected to me
373+
/*!
374+
@brief Number of units connected to me
375+
@return Number of child units connected to this unit
376+
*/
259377
size_t childrenSize() const;
260-
//! @brief Is there an other unit connected to the specified channel?
378+
/*!
379+
@brief Is there another unit connected to the specified channel?
380+
@param ch Channel number to check
381+
@return True if a child unit is connected on the specified channel
382+
*/
261383
bool existsChild(const uint8_t ch) const;
262-
//! @brief Gets the parent unit
384+
/*!
385+
@brief Gets the parent unit
386+
@return Pointer to the parent unit, or nullptr if there is no parent
387+
*/
263388
inline Component* parent()
264389
{
265390
return _parent;
266391
}
267-
//! @brief Gets the device connected to the specified channel
392+
/*!
393+
@brief Gets the device connected to the specified channel
394+
@param channel Channel number to query
395+
@return Pointer to the child unit on that channel, or nullptr if none
396+
*/
268397
Component* child(const uint8_t channel) const;
269-
//! @brief Connect the unit to the specified channel
398+
/*!
399+
@brief Connect the unit to the specified channel
400+
@param c Child component to connect
401+
@param channel Channel number to connect on
402+
@return True if successful
403+
*/
270404
bool add(Component& c, const int16_t channel);
271-
//! @brief Select valid channel if exists
405+
/*!
406+
@brief Select valid channel if exists
407+
@param ch Channel number to select
408+
@return True if the channel was selected successfully
409+
*/
272410
bool selectChannel(const uint8_t ch = 8);
273411
///@}
274412

@@ -346,7 +484,10 @@ class Component {
346484
*/
347485
bool generalCall(const uint8_t* data, const size_t len);
348486

349-
//! @brief Output information for debug
487+
/*!
488+
@brief Output information for debug
489+
@return String containing debug information about this unit
490+
*/
350491
virtual std::string debugInfo() const;
351492

352493
////// TODO : Split interface (I2C, GPIO, UART, SPI)

0 commit comments

Comments
 (0)