/** * \brief Resets the hardware module * * This will reset the module to hardware defaults. * * \param[in,out] module Pointer to software module structure */ void i2c_slave_reset( struct i2c_slave_module *const module) { /* Sanity check arguments */ Assert(module); Assert(module->hw); SercomI2cs *const i2c_hw = &(module->hw->I2CS); #if I2C_SLAVE_CALLBACK_MODE == true /* Reset module instance */ module->registered_callback = 0; module->enabled_callback = 0; module->buffer_length = 0; module->buffer_remaining = 0; module->buffer = NULL; #endif /* Disable module */ i2c_slave_disable(module); #if I2C_SLAVE_CALLBACK_MODE == true /* Clear all pending interrupts */ system_interrupt_enter_critical_section(); system_interrupt_clear_pending(_sercom_get_interrupt_vector(module->hw)); system_interrupt_leave_critical_section(); #endif /* Wait for sync */ _i2c_slave_wait_for_sync(module); /* Reset module */ i2c_hw->CTRLA.reg = SERCOM_I2CS_CTRLA_SWRST; }
/** * \brief Resets the hardware module * * Reset the module to hardware defaults. * * \param[in,out] module Pointer to software module structure */ void i2c_master_reset(struct i2c_master_module *const module) { /* Sanity check arguments */ Assert(module); Assert(module->hw); SercomI2cm *const i2c_module = &(module->hw->I2CM); /* Wait for sync */ _i2c_master_wait_for_sync(module); /* Disable module */ i2c_master_disable(module); #if I2C_MASTER_CALLBACK_MODE == true /* Clear all pending interrupts */ system_interrupt_enter_critical_section(); system_interrupt_clear_pending(_sercom_get_interrupt_vector(module->hw)); system_interrupt_leave_critical_section(); #endif /* Wait for sync */ _i2c_master_wait_for_sync(module); /* Reset module */ i2c_module->CTRLA.reg = SERCOM_I2CM_CTRLA_SWRST; }