URL
https://opencores.org/ocsvn/neorv32/neorv32/trunk
[/] [neorv32/] [trunk/] [sw/] [lib/] [source/] [neorv32_twi.c] - Diff between revs 64 and 68
Go to most recent revision |
Show entire file |
Details |
Blame |
View Log
Rev 64 |
Rev 68 |
Line 63... |
Line 63... |
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Enable and configure TWI controller. The TWI control register bits are listed in #NEORV32_TWI_CTRL_enum.
|
* Enable and configure TWI controller. The TWI control register bits are listed in #NEORV32_TWI_CTRL_enum.
|
*
|
*
|
* @param[in] prsc Clock prescaler select (0..7). See #NEORV32_CLOCK_PRSC_enum.
|
* @param[in] prsc Clock prescaler select (0..7). See #NEORV32_CLOCK_PRSC_enum.
|
* @param[in] ckst_en Enable clock-stretching by peripherals when 1.
|
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_twi_setup(uint8_t prsc, uint8_t ckst_en) {
|
void neorv32_twi_setup(uint8_t prsc) {
|
|
|
NEORV32_TWI.CTRL = 0; // reset
|
NEORV32_TWI.CTRL = 0; // reset
|
|
|
uint32_t ct_enable = 1;
|
uint32_t ct_enable = 1;
|
ct_enable = ct_enable << TWI_CTRL_EN;
|
ct_enable = ct_enable << TWI_CTRL_EN;
|
|
|
uint32_t ct_prsc = (uint32_t)(prsc & 0x07);
|
uint32_t ct_prsc = (uint32_t)(prsc & 0x07);
|
ct_prsc = ct_prsc << TWI_CTRL_PRSC0;
|
ct_prsc = ct_prsc << TWI_CTRL_PRSC0;
|
|
|
uint32_t ct_cksten = (uint32_t)(ckst_en & 0x01);
|
NEORV32_TWI.CTRL = ct_enable | ct_prsc;
|
ct_cksten = ct_cksten << TWI_CTRL_CKSTEN;
|
|
|
|
NEORV32_TWI.CTRL = ct_enable | ct_prsc | ct_cksten;
|
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Disable TWI controller.
|
* Disable TWI controller.
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.