File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ setup KEYWORD2
33detect KEYWORD2
44reset KEYWORD2
55device_attach_wait KEYWORD2
6+ device_attach_get KEYWORD2
67device_type_get KEYWORD2
78switch_state_set KEYWORD2
89register_read KEYWORD2
Original file line number Diff line number Diff line change @@ -111,6 +111,39 @@ int pi3usb9281c::device_attach_wait(const uint32_t timeout_ms) {
111111 }
112112}
113113
114+ /* *
115+ * @brief Checks for device attachment (non-blocking)
116+ *
117+ * Reads the interrupt register once to check for device attachment.
118+ * If a device is attached, clears the interrupt flag.
119+ *
120+ * @return 1 if device attached, 0 if no device attached, -EIO on I2C error
121+ */
122+ int pi3usb9281c::device_attach_get (void ) {
123+
124+ /* Read interrupt flags */
125+ uint8_t reg_interrupt = 0 ;
126+ if (register_read (PI3USB9281C_REGISTER_INTERRUPT, ®_interrupt) < 0 ) {
127+ return -EIO;
128+ }
129+
130+ /* Check accessory attached interrupt flag */
131+ if (reg_interrupt & 0b1 ) {
132+
133+ /* Clear interrupt flag */
134+ reg_interrupt = 0b1 ;
135+ if (register_write (PI3USB9281C_REGISTER_INTERRUPT, reg_interrupt) < 0 ) {
136+ return -EIO;
137+ }
138+
139+ /* Return device attached */
140+ return 1 ;
141+ }
142+
143+ /* Return no device attached */
144+ return 0 ;
145+ }
146+
114147/* *
115148 * @brief Gets the type of attached USB device or charger
116149 *
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ class pi3usb9281c {
8585 // !@{
8686 // ! Device detection and monitoring
8787 int device_attach_wait (const uint32_t timeout_ms);
88+ int device_attach_get (void );
8889 int device_type_get (enum pi3usb9281c_device_type *const type);
8990 // !@}
9091
You can’t perform that action at this time.
0 commit comments