77#endif
88
99/* *
10+ * @brief Initializes the PI3USB9281C device
1011 *
11- * @param[in] i2c_library
12- * @param[in] i2c_address
13- * @param[in] pin_enb
12+ * This function sets up the I2C communication with the device and configures the enable pin.
13+ * The device only supports I2C address 0x25.
14+ *
15+ * @param[in] i2c_library Reference to the TwoWire I2C library instance to use
16+ * @param[in] i2c_address I2C address of the device (must be 0x25)
17+ * @param[in] pin_enb GPIO pin number connected to the device's enable pin
18+ * @return 0 on success, -EINVAL if invalid I2C address
1419 */
1520int pi3usb9281c::setup (TwoWire& i2c_library, const uint8_t i2c_address, const int pin_enb) {
1621
@@ -32,7 +37,11 @@ int pi3usb9281c::setup(TwoWire& i2c_library, const uint8_t i2c_address, const in
3237}
3338
3439/* *
40+ * @brief Detects if a PI3USB9281C device is present
41+ *
42+ * Reads the device ID register and verifies it matches the expected value (0x18).
3543 *
44+ * @return true if device is detected, false otherwise
3645 */
3746bool pi3usb9281c::detect (void ) {
3847 uint8_t reg_id;
@@ -44,7 +53,11 @@ bool pi3usb9281c::detect(void) {
4453}
4554
4655/* *
56+ * @brief Performs a software reset of the device
57+ *
58+ * Writes to the reset register to trigger a device reset.
4759 *
60+ * @return 0 on success, -EIO on I2C communication error
4861 */
4962int pi3usb9281c::reset (void ) {
5063
@@ -59,8 +72,13 @@ int pi3usb9281c::reset(void) {
5972}
6073
6174/* *
62- * @param[in] timeout_ms
63- * @return
75+ * @brief Waits for a device attachment event
76+ *
77+ * Polls the interrupt register for the device attachment flag.
78+ * When detected, clears the interrupt flag.
79+ *
80+ * @param[in] timeout_ms Maximum time to wait in milliseconds
81+ * @return 0 on device attached, -ETIMEDOUT on timeout, -EIO on I2C error
6482 */
6583int pi3usb9281c::device_attach_wait (const uint32_t timeout_ms) {
6684
@@ -94,7 +112,13 @@ int pi3usb9281c::device_attach_wait(const uint32_t timeout_ms) {
94112}
95113
96114/* *
115+ * @brief Gets the type of attached USB device or charger
116+ *
117+ * Reads the device type and charger status registers to determine what kind of
118+ * device is attached. Can detect various USB ports (SDP, CDP, DCP) and charger types.
97119 *
120+ * @param[out] type Pointer to store the detected device type
121+ * @return 0 on success, -EIO on I2C communication error
98122 */
99123int pi3usb9281c::device_type_get (enum pi3usb9281c_device_type* const type) {
100124
@@ -133,7 +157,14 @@ int pi3usb9281c::device_type_get(enum pi3usb9281c_device_type* const type) {
133157}
134158
135159/* *
160+ * @brief Controls the state of the D+/D- switch
136161 *
162+ * Sets the switch to either automatic control, manually open, or manually closed.
163+ * In automatic mode, the device controls the switch based on detected device type.
164+ * Manual modes allow forcing the switch state regardless of device type.
165+ *
166+ * @param[in] state Desired switch state (auto, manual open, or manual closed)
167+ * @return 0 on success, -EINVAL for invalid state, -EIO on I2C error
137168 */
138169int pi3usb9281c::switch_state_set (const enum pi3usb9281c_switch_state state) {
139170
@@ -157,10 +188,13 @@ int pi3usb9281c::switch_state_set(const enum pi3usb9281c_switch_state state) {
157188}
158189
159190/* *
160- * Reads the contents of the given register.
161- * @param[in] reg_address The address of the register.
162- * @param[out] reg_content A pointer to a variable that will be updated with the contents of the register.
163- * @return 0 in case of success, or a negative error code otherwise.
191+ * @brief Reads a device register
192+ *
193+ * Performs an I2C read transaction to get the contents of the specified register.
194+ *
195+ * @param[in] reg_address Register address to read
196+ * @param[out] reg_content Pointer to store the register value
197+ * @return 0 on success, -EINVAL if not initialized, -EIO on I2C error
164198 */
165199int pi3usb9281c::register_read (const enum pi3usb9281c_register reg_address, uint8_t * const reg_content) {
166200 int res;
@@ -179,7 +213,7 @@ int pi3usb9281c::register_read(const enum pi3usb9281c_register reg_address, uint
179213 }
180214
181215 /* Read data */
182- m_i2c_library->requestFrom (m_i2c_address, (uint8_t )1 , (uint8_t ) true );
216+ m_i2c_library->requestFrom (m_i2c_address, (uint8_t )1 , (uint8_t )true );
183217 res = m_i2c_library->available ();
184218 if (res == 0 ) {
185219 return -EIO;
@@ -191,10 +225,13 @@ int pi3usb9281c::register_read(const enum pi3usb9281c_register reg_address, uint
191225}
192226
193227/* *
194- * Updates the content of the given register.
195- * @param[in] reg_address The address of the register.
196- * @param[in] reg_content The new content of the register.
197- * @return 0 in case of success, or a negative error code otherwise.
228+ * @brief Writes to a device register
229+ *
230+ * Performs an I2C write transaction to update the specified register.
231+ *
232+ * @param[in] reg_address Register address to write
233+ * @param[in] reg_content Value to write to the register
234+ * @return 0 on success, -EINVAL if not initialized, -EIO on I2C error
198235 */
199236int pi3usb9281c::register_write (const enum pi3usb9281c_register reg_address, const uint8_t reg_content) {
200237 int res;
0 commit comments