NRF5x: I2C EasyDMA support for NRF5x, extended API

This commit adds support for NRF52 TWI Master mode and slightly extends
existing I2C API. This is a breaking change, while mode selection needs to be
done during enabling I2C. There is one additional breaking change done because:
1) Unicore MX API design was PITA for writes
2) It is incompatible with EasyDMA

I strongly apologize to all two users who might be affected by this change.
This commit is contained in:
Eduard Drusa
2022-03-31 11:17:59 +02:00
committed by Karl Palsson
parent 458766398f
commit 66bf499e1b
6 changed files with 218 additions and 36 deletions

View File

@@ -6,6 +6,8 @@
* LGPL License Terms @ref lgpl_license
* @author @htmlonly © @endhtmlonly 2016
* Maxim Sloyko <maxims@google.com>
* @author @htmlonly &copy; @endhtmlonly 2021 - 2022
* Eduard Drusa <ventyl86(at)netkosice(dot)sk>
*
*/
@@ -35,16 +37,17 @@
/** @brief Enable I2C peripheral
*
* @param[in] i2c uint32_t i2c peripheral base
* @param[in] i2c i2c peripheral base, see @ref i2c_block
* @param[in] mode i2c @ref i2c_mode
*/
void i2c_enable(uint32_t i2c)
void i2c_enable(uint32_t i2c, uint32_t mode)
{
I2C_ENABLE(i2c) = I2C_ENABLE_VALUE;
I2C_ENABLE(i2c) = mode;
}
/** @brief Disable I2C peripheral
*
* @param[in] i2c uint32_t i2c peripheral base
* @param[in] i2c i2c peripheral base, see @ref i2c_block
*/
void i2c_disable(uint32_t i2c)
{
@@ -53,36 +56,37 @@ void i2c_disable(uint32_t i2c)
/** @brief Start I2C transmission.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @param[in] data uint8_t the first byte to send.
* Starts STARTTX task, which generates start condition on I2C bus and
* transmits address previously configured by @ref i2c_set_address.
*
* @param[in] i2c i2c peripheral base, see @ref i2c_block.
*/
void i2c_start_tx(uint32_t i2c, uint8_t data)
void i2c_start_tx(uint32_t i2c)
{
PERIPH_TRIGGER_TASK(I2C_TASK_STARTTX(i2c));
I2C_TXD(i2c) = data;
I2C_TASK_STARTTX(i2c) = 1;
}
/** @brief Start I2C reception.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @param[in] i2c i2c peripheral base, see @ref i2c_block.
*/
void i2c_start_rx(uint32_t i2c)
{
PERIPH_TRIGGER_TASK(I2C_TASK_STARTRX(i2c));
I2C_TASK_STARTRX(i2c) = 1;
}
/** @brief Signal stop on I2C line.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @param[in] i2c i2c peripheral base, see @ref i2c_block.
*/
void i2c_send_stop(uint32_t i2c)
{
PERIPH_TRIGGER_TASK(I2C_TASK_STOP(i2c));
I2C_TASK_STOP(i2c) = 1;
}
/** @brief Select Fast (400kHz) mode.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @param[in] i2c i2c peripheral base, see @ref i2c_block.
*/
void i2c_set_fast_mode(uint32_t i2c)
{
@@ -91,7 +95,7 @@ void i2c_set_fast_mode(uint32_t i2c)
/** @brief Select Standard (100kHz) mode.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @param[in] i2c i2c peripheral base, see @ref i2c_block.
*/
void i2c_set_standard_mode(uint32_t i2c)
{
@@ -103,8 +107,8 @@ void i2c_set_standard_mode(uint32_t i2c)
* In addition to Standard (100kHz) and Fast (400kHz) modes
* this peripheral also supports 250kHz mode.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @param[in] freq uint32_t frequency constant. See defines for details
* @param[in] i2c i2c peripheral base, see @ref i2c_block
* @param[in] freq frequency constant. See @ref i2c_freq_const for details
* and note that this is not actually a frequency in Hz or kHz.
*/
void i2c_set_frequency(uint32_t i2c, uint32_t freq)
@@ -114,8 +118,11 @@ void i2c_set_frequency(uint32_t i2c, uint32_t freq)
/** @brief Write Data to TXD register to be sent.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @param[in] data uint8_t byte to send next.
* Writes one byte into transmission buffer. This API is only
* available if @ref I2C_MODE_LEGACY is activated.
*
* @param[in] i2c i2c peripheral base, see @ref i2c_block
* @param[in] data byte to send next.
*/
void i2c_send_data(uint32_t i2c, uint8_t data)
{
@@ -124,8 +131,11 @@ void i2c_send_data(uint32_t i2c, uint8_t data)
/** @brief Read Data from RXD register.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @returns uint8_t data from RXD register.
* Reads one byte from reception buffer. This API is only
* available if @ref I2C_MODE_LEGACY is activated.
*
* @param[in] i2c i2c peripheral base, see @ref i2c_block
* @returns data from RXD register.
*/
uint8_t i2c_get_data(uint32_t i2c)
{
@@ -133,15 +143,17 @@ uint8_t i2c_get_data(uint32_t i2c)
}
/** @brief Select GPIO pins to be used by this peripheral.
*
* Configures GPIO pins assigned to SCL and SDA signals. These pins are only occupied
* by I2C peripheral whenever it is enabled using @ref i2c_enable. It is possible to
* ignore any given signal and not map it to pin by using special value of
* @ref GPIO_UNCONNECTED instead of @ref gpio_pin_id values.
*
* This needs to be configured when no transaction is in progress.
*
* @param[in] i2c i2c peripheral base.
* @param[in] scl_pin SCL pin. Use GPIO defines in @ref gpio_pin_id or GPIO_UNCONNECTED
* if signal shall not be connected to any pin.
* @param[in] sda_pin SDA pin. Use GPIO defines in @ref gpio_pin_id or GPIO_UNCONNECTED
* if signal shall not be connected to any pin.
* @param[in] i2c i2c peripheral base, see @ref i2c_block
* @param[in] scl_pin GPIO pin used for SCL signal
* @param[in] sda_pin GPIO pin used for SDA signal
*/
void i2c_select_pins(uint32_t i2c, uint32_t scl_pin, uint32_t sda_pin)
{
@@ -160,8 +172,8 @@ void i2c_select_pins(uint32_t i2c, uint32_t scl_pin, uint32_t sda_pin)
/** @brief Set 7bit I2C address of the device you wish to communicate with.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @param[in] addr uint8_t device address (7bit).
* @param[in] i2c i2c peripheral base, see @ref i2c_block
* @param[in] addr device address (7bit).
*/
void i2c_set_address(uint32_t i2c, uint8_t addr)
{
@@ -173,12 +185,22 @@ void i2c_set_address(uint32_t i2c, uint8_t addr)
* This function is unusual, but required to implement
* i2c exchange with this peripheral.
*
* @param[in] i2c uint32_t i2c peripheral base.
* @param[in] i2c i2c peripheral base, see @ref i2c_block
*/
void i2c_resume(uint32_t i2c)
{
PERIPH_TRIGGER_TASK(I2C_TASK_RESUME(i2c));
}
/** Configure event -> task shortcuts
*
* Sets new shortcut configuration bitmask for I2C peripheral.
*
* @param[in] i2c i2c peripheral base, see @ref i2c_block
* @param[in] shorts @ref i2c_shorts activated
*/
void i2c_set_shorts(uint32_t i2c, uint32_t shorts)
{
I2C_SHORTS(i2c) = shorts;
}
/**@}*/