Skip to content

Commit 9e6a501

Browse files
committed
feat(i3c): add end() to deinitialize the active bus
Signed-off-by: Aymane Bahssain <aymane.bahssain@st.com>
1 parent d7441e3 commit 9e6a501

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎libraries/I3C/src/I3C.cpp‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,60 @@ bool I3CBus::isTarget() const
331331
return _role == I3CRole::Target;
332332
}
333333

334+
void I3CBus::end()
335+
{
336+
if (_initialized) {
337+
disableIRQs();
338+
unregisterInstanceOwner();
339+
340+
(void)HAL_I3C_DeInit(&_hi3c);
341+
342+
deinitGPIO();
343+
deinitClocks();
344+
345+
_initialized = false;
346+
_role = I3CRole::None;
347+
348+
_ibiPending = false;
349+
_lastIbi = {};
350+
_targetEventPending = false;
351+
_lastTargetEventId = 0U;
352+
353+
std::memset(&_hi3c, 0, sizeof(_hi3c));
354+
_instance = nullptr;
355+
}
356+
}
357+
358+
void I3CBus::deinitClocks()
359+
{
360+
#if defined(I3C1)
361+
if (_instance == I3C1) {
362+
__HAL_RCC_I3C1_FORCE_RESET();
363+
__HAL_RCC_I3C1_RELEASE_RESET();
364+
__HAL_RCC_I3C1_CLK_DISABLE();
365+
}
366+
#endif
367+
368+
#if defined(I3C2)
369+
if (_instance == I3C2) {
370+
__HAL_RCC_I3C2_FORCE_RESET();
371+
__HAL_RCC_I3C2_RELEASE_RESET();
372+
__HAL_RCC_I3C2_CLK_DISABLE();
373+
}
374+
#endif
375+
}
376+
377+
void I3CBus::deinitGPIO()
378+
{
379+
if (_sdaPin != NC) {
380+
pin_function(_sdaPin, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
381+
}
382+
383+
if (_sclPin != NC) {
384+
pin_function(_sclPin, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
385+
}
386+
}
387+
334388
// ============================================================================
335389
// Default I3C controller transfers
336390
// ============================================================================

‎libraries/I3C/src/I3C.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ class I3CBus {
158158
bool isController() const;
159159
bool isTarget() const;
160160

161+
void end();
162+
161163
// ------------------------------------------------------------------------
162164
// Default I3C controller transfers
163165
// ------------------------------------------------------------------------
@@ -540,6 +542,9 @@ class I3CBus {
540542
void registerInstanceOwner();
541543
void unregisterInstanceOwner();
542544

545+
void deinitClocks();
546+
void deinitGPIO();
547+
543548
// ------------------------------------------------------------------------
544549
// Internal state
545550
// ------------------------------------------------------------------------

0 commit comments

Comments
 (0)