Skip to content

Commit 689c3b7

Browse files
committed
Add si_deinit function
1 parent e8d23e9 commit 689c3b7

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

firmware/libsi/include/si/si.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,9 @@ void si_read_bytes(uint8_t *buffer, uint8_t max_length, si_byte_cb_t byte_callba
145145
*
146146
* This function will block until the SI bus is idle.
147147
*/
148-
void si_await_bus_idle(void);
148+
void si_await_bus_idle(void);
149+
150+
/**
151+
* Deinitialize the SI bus.
152+
*/
153+
void si_deinit(void);

firmware/libsi/src/platform/efr32/si_efr32_emlib.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
static uint8_t si_data_port;
8383
static uint8_t si_data_pin;
8484
static bool si_mode;
85+
static bool si_initialized = false;
8586

8687
// RX state
8788
static uint16_t rx_edge_timings[2][RX_BUFFER_SIZE];
@@ -146,6 +147,8 @@ void si_init(uint8_t port, uint8_t pin, uint8_t mode, uint32_t rx_freq, uint32_t
146147
si_data_port = port;
147148
si_data_pin = pin;
148149
si_mode = mode;
150+
151+
si_initialized = true;
149152
}
150153

151154
void si_write_bytes(const uint8_t *bytes, uint8_t length, si_complete_cb_t callback)
@@ -373,4 +376,30 @@ void SI_TX_USART_IRQHandler()
373376
// Call the transfer callback with the number of bytes written
374377
if (si_xfer.complete_callback)
375378
si_xfer.complete_callback(si_xfer.max_length);
376-
}
379+
}
380+
381+
// Deinitialize SI peripherals
382+
void si_deinit(void)
383+
{
384+
if (!si_initialized)
385+
return;
386+
387+
// Disable timers
388+
TIMER_Enable(SI_RX_TIMER, false);
389+
390+
// Disable USART
391+
USART_Enable(SI_TX_USART, usartDisable);
392+
393+
// Free DMA channels
394+
DMADRV_FreeChannel(rx_dma_channel);
395+
DMADRV_FreeChannel(tx_dma_channel);
396+
397+
// Remove peripheral routes
398+
GPIO->TIMERROUTE[SI_RX_TIMER_IDX].ROUTEEN = 0;
399+
GPIO->USARTROUTE[SI_TX_USART_IDX].ROUTEEN = 0;
400+
401+
// Reset GPIO pin to input (safe state)
402+
GPIO_PinModeSet(si_data_port, si_data_pin, gpioModeInput, 0);
403+
404+
si_initialized = false;
405+
}

0 commit comments

Comments
 (0)