Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions drivers/i2s/i2s_nrfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@
struct k_msgq tx_queue;
struct stream_cfg rx;
struct k_msgq rx_queue;
const nrfx_i2s_t *p_i2s;
nrfx_i2s_t i2s;
const uint32_t *last_tx_buffer;
enum i2s_state state;
enum i2s_dir active_dir;
bool stop; /* stop after the current (TX or RX) block */
bool discard_rx; /* discard further RX blocks */
volatile bool next_tx_buffer_needed;
bool tx_configured : 1;
bool rx_configured : 1;
bool request_clock : 1;
bool tx_configured: 1;
bool rx_configured: 1;
bool request_clock: 1;
};

struct i2s_nrfx_drv_cfg {
nrfx_i2s_data_handler_t data_handler;
nrfx_i2s_t i2s;
nrfx_i2s_config_t nrfx_def_cfg;
const struct pinctrl_dev_config *pcfg;
enum clock_source {
Expand Down Expand Up @@ -81,7 +80,7 @@
.allow_bypass = IS_ENABLED(CONFIG_I2S_NRFX_ALLOW_MCK_BYPASS),
};

if (nrfx_i2s_prescalers_calc(&clk_params, &config->prescalers) != NRFX_SUCCESS) {
if (nrfx_i2s_prescalers_calc(&clk_params, &config->prescalers)) {
LOG_ERR("Failed to find suitable I2S clock configuration.");
}
}
Expand Down Expand Up @@ -134,7 +133,7 @@
if (drv_data->active_dir != I2S_DIR_TX) { /* -> RX active */
if (!get_next_rx_buffer(drv_data, next)) {
drv_data->state = I2S_STATE_ERROR;
nrfx_i2s_stop(drv_data->p_i2s);
nrfx_i2s_stop(&drv_data->i2s);
return false;
}
/* Set buffer size if there is no TX buffer (which effectively
Expand All @@ -149,7 +148,7 @@
drv_data->last_tx_buffer = next->p_tx_buffer;

LOG_DBG("Next buffers: %p/%p", next->p_tx_buffer, next->p_rx_buffer);
nrfx_i2s_next_buffers_set(drv_data->p_i2s, next);
nrfx_i2s_next_buffers_set(&drv_data->i2s, next);
return true;
}

Expand Down Expand Up @@ -181,7 +180,7 @@
}
drv_data->last_tx_buffer = NULL;
}
nrfx_i2s_uninit(drv_data->p_i2s);
nrfx_i2s_uninit(&drv_data->i2s);
if (drv_data->request_clock) {
(void)onoff_release(drv_data->clk_mgr);
}
Expand All @@ -198,7 +197,7 @@
LOG_ERR("Next buffers not supplied on time");
drv_data->state = I2S_STATE_ERROR;
}
nrfx_i2s_stop(drv_data->p_i2s);
nrfx_i2s_stop(&drv_data->i2s);
return;
}

Expand Down Expand Up @@ -248,7 +247,7 @@
}

if (stop_transfer) {
nrfx_i2s_stop(drv_data->p_i2s);
nrfx_i2s_stop(&drv_data->i2s);
} else if (status & NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED) {
nrfx_i2s_buffers_t next = { 0 };

Expand Down Expand Up @@ -419,9 +418,9 @@
* the MCK output is used), find a suitable clock configuration for it.
*/
if (nrfx_cfg.mode == NRF_I2S_MODE_MASTER ||
(nrf_i2s_mck_pin_get(drv_cfg->i2s.p_reg) & I2S_PSEL_MCK_CONNECT_Msk)
(nrf_i2s_mck_pin_get(drv_data->i2s.p_reg) & I2S_PSEL_MCK_CONNECT_Msk)
== I2S_PSEL_MCK_CONNECT_Connected << I2S_PSEL_MCK_CONNECT_Pos) {
find_suitable_clock(drv_cfg, &nrfx_cfg, i2s_cfg);

Check notice on line 423 in drivers/i2s/i2s_nrfx.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/i2s/i2s_nrfx.c:423 - (nrf_i2s_mck_pin_get(drv_data->i2s.p_reg) & I2S_PSEL_MCK_CONNECT_Msk) - == I2S_PSEL_MCK_CONNECT_Connected << I2S_PSEL_MCK_CONNECT_Pos) { + (nrf_i2s_mck_pin_get(drv_data->i2s.p_reg) & I2S_PSEL_MCK_CONNECT_Msk) == + I2S_PSEL_MCK_CONNECT_Connected << I2S_PSEL_MCK_CONNECT_Pos) {
/* Unless the PCLK32M source is used with the HFINT oscillator
* (which is always available without any additional actions),
* it is required to request the proper clock to be running
Expand Down Expand Up @@ -578,7 +577,7 @@
/* Failed to allocate next RX buffer */
ret = -ENOMEM;
} else {
nrfx_err_t err;
int err;

/* It is necessary to set buffer size here only for I2S_DIR_RX,
* because only then the get_next_tx_buffer() call in the if
Expand All @@ -591,16 +590,16 @@

drv_data->last_tx_buffer = initial_buffers.p_tx_buffer;

err = nrfx_i2s_start(drv_data->p_i2s, &initial_buffers, 0);
if (err == NRFX_SUCCESS) {
err = nrfx_i2s_start(&drv_data->i2s, &initial_buffers, 0);
if (err == 0) {
return 0;
}

LOG_ERR("Failed to start I2S transfer: 0x%08x", err);
LOG_ERR("Failed to start I2S transfer: %d", err);
ret = -EIO;
}

nrfx_i2s_uninit(drv_data->p_i2s);
nrfx_i2s_uninit(&drv_data->i2s);
if (drv_data->request_clock) {
(void)onoff_release(drv_data->clk_mgr);
}
Expand Down Expand Up @@ -629,7 +628,7 @@
* the actual transfer in such case.
*/
if (drv_data->state == I2S_STATE_READY) {
nrfx_i2s_uninit(drv_data->p_i2s);
nrfx_i2s_uninit(&drv_data->i2s);
(void)onoff_release(drv_data->clk_mgr);
} else {
(void)start_transfer(drv_data);
Expand All @@ -640,22 +639,22 @@
{
struct i2s_nrfx_drv_data *drv_data = dev->data;
const struct i2s_nrfx_drv_cfg *drv_cfg = dev->config;
nrfx_err_t err;
int err;
int ret;
const nrfx_i2s_config_t *nrfx_cfg = (drv_data->active_dir == I2S_DIR_TX)
? &drv_data->tx.nrfx_cfg
: &drv_data->rx.nrfx_cfg;

err = nrfx_i2s_init(drv_data->p_i2s, nrfx_cfg, drv_cfg->data_handler);
if (err != NRFX_SUCCESS) {
LOG_ERR("Failed to initialize I2S: 0x%08x", err);
err = nrfx_i2s_init(&drv_data->i2s, nrfx_cfg, drv_cfg->data_handler);
if (err != 0) {
LOG_ERR("Failed to initialize I2S: %d", err);
return -EIO;
}

drv_data->state = I2S_STATE_RUNNING;

#if NRF_I2S_HAS_CLKCONFIG
nrf_i2s_clk_configure(drv_cfg->i2s.p_reg,
nrf_i2s_clk_configure(&drv_data->i2s,
drv_cfg->clk_src == ACLK ? NRF_I2S_CLKSRC_ACLK
: NRF_I2S_CLKSRC_PCLK32M,
nrfx_cfg->prescalers.enable_bypass);
Expand All @@ -669,7 +668,7 @@
clock_started_callback);
ret = onoff_request(drv_data->clk_mgr, &drv_data->clk_cli);
if (ret < 0) {
nrfx_i2s_uninit(drv_data->p_i2s);
nrfx_i2s_uninit(&drv_data->i2s);
drv_data->state = I2S_STATE_READY;

LOG_ERR("Failed to request clock: %d", ret);
Expand Down Expand Up @@ -776,7 +775,7 @@
case I2S_TRIGGER_DROP:
if (drv_data->state != I2S_STATE_READY) {
drv_data->discard_rx = true;
nrfx_i2s_stop(drv_data->p_i2s);
nrfx_i2s_stop(&drv_data->i2s);
}
purge_queue(dev, dir);
drv_data->state = I2S_STATE_READY;
Expand Down Expand Up @@ -835,7 +834,6 @@
PINCTRL_DT_DEFINE(I2S(idx)); \
static const struct i2s_nrfx_drv_cfg i2s_nrfx_cfg##idx = { \
.data_handler = data_handler##idx, \
.i2s = NRFX_I2S_INSTANCE(idx), \
.nrfx_def_cfg = NRFX_I2S_DEFAULT_CONFIG( \
NRF_I2S_PIN_NOT_CONNECTED, \
NRF_I2S_PIN_NOT_CONNECTED, \
Expand All @@ -849,8 +847,9 @@
}; \
static struct i2s_nrfx_drv_data i2s_nrfx_data##idx = { \
.state = I2S_STATE_READY, \
.p_i2s = &i2s_nrfx_cfg##idx.i2s \
.i2s = NRFX_I2S_INSTANCE(NRF_I2S##idx), \
}; \
NRFX_INSTANCE_IRQ_HANDLER_DEFINE(i2s, idx, &i2s_nrfx_data##idx.i2s); \
static int i2s_nrfx_init##idx(const struct device *dev) \
{ \
IRQ_CONNECT(DT_IRQN(I2S(idx)), DT_IRQ(I2S(idx), priority), \
Expand Down Expand Up @@ -881,7 +880,7 @@
DEVICE_DT_DEFINE(I2S(idx), i2s_nrfx_init##idx, NULL, \
&i2s_nrfx_data##idx, &i2s_nrfx_cfg##idx, \
POST_KERNEL, CONFIG_I2S_INIT_PRIORITY, \
&i2s_nrf_drv_api);

Check notice on line 883 in drivers/i2s/i2s_nrfx.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/i2s/i2s_nrfx.c:883 -#define I2S_NRFX_DEVICE(idx) \ - static struct i2s_buf tx_msgs##idx[CONFIG_I2S_NRFX_TX_BLOCK_COUNT]; \ - static struct i2s_buf rx_msgs##idx[CONFIG_I2S_NRFX_RX_BLOCK_COUNT]; \ - static void data_handler##idx(nrfx_i2s_buffers_t const *p_released, \ - uint32_t status) \ - { \ - data_handler(DEVICE_DT_GET(I2S(idx)), p_released, status); \ - } \ - PINCTRL_DT_DEFINE(I2S(idx)); \ - static const struct i2s_nrfx_drv_cfg i2s_nrfx_cfg##idx = { \ - .data_handler = data_handler##idx, \ - .nrfx_def_cfg = NRFX_I2S_DEFAULT_CONFIG( \ - NRF_I2S_PIN_NOT_CONNECTED, \ - NRF_I2S_PIN_NOT_CONNECTED, \ - NRF_I2S_PIN_NOT_CONNECTED, \ - NRF_I2S_PIN_NOT_CONNECTED, \ - NRF_I2S_PIN_NOT_CONNECTED), \ - .nrfx_def_cfg.skip_gpio_cfg = true, \ - .nrfx_def_cfg.skip_psel_cfg = true, \ - .pcfg = PINCTRL_DT_DEV_CONFIG_GET(I2S(idx)), \ - .clk_src = I2S_CLK_SRC(idx), \ - }; \ - static struct i2s_nrfx_drv_data i2s_nrfx_data##idx = { \ - .state = I2S_STATE_READY, \ - .i2s = NRFX_I2S_INSTANCE(NRF_I2S##idx), \ - }; \ - NRFX_INSTANCE_IRQ_HANDLER_DEFINE(i2s, idx, &i2s_nrfx_data##idx.i2s); \ - static int i2s_nrfx_init##idx(const struct device *dev) \ - { \ - IRQ_CONNECT(DT_IRQN(I2S(idx)), DT_IRQ(I2S(idx), priority), \ - nrfx_isr, nrfx_i2s_##idx##_irq_handler, 0); \ - const struct i2s_nrfx_drv_cfg *drv_cfg = dev->config; \ - int err = pinctrl_apply_state(drv_cfg->pcfg, \ - PINCTRL_STATE_DEFAULT); \ - if (err < 0) { \ - return err; \ - } \ - k_msgq_init(&i2s_nrfx_data##idx.tx_queue, \ - (char *)tx_msgs##idx, sizeof(struct i2s_buf), \ - ARRAY_SIZE(tx_msgs##idx)); \ - k_msgq_init(&i2s_nrfx_data##idx.rx_queue, \ - (char *)rx_msgs##idx, sizeof(struct i2s_buf), \ - ARRAY_SIZE(rx_msgs##idx)); \ - init_clock_manager(dev); \ - return 0; \ - } \ - BUILD_ASSERT(I2S_CLK_SRC(idx) != ACLK || \ - (NRF_I2S_HAS_CLKCONFIG && NRF_CLOCK_HAS_HFCLKAUDIO), \ - "Clock source ACLK is not available."); \ - BUILD_ASSERT(I2S_CLK_SRC(idx) != ACLK || \ - DT_NODE_HAS_PROP(DT_NODELABEL(clock), \ - hfclkaudio_frequency), \ - "Clock source ACLK requires the hfclkaudio-frequency " \ - "property to be defined in the nordic,nrf-clock node."); \ - DEVICE_DT_DEFINE(I2S(idx), i2s_nrfx_init##idx, NULL, \ - &i2s_nrfx_data##idx, &i2s_nrfx_cfg##idx, \ - POST_KERNEL, CONFIG_I2S_INIT_PRIORITY, \ +#define I2S_NRFX_DEVICE(idx) \ + static struct i2s_buf tx_msgs##idx[CONFIG_I2S_NRFX_TX_BLOCK_COUNT]; \ + static struct i2s_buf rx_msgs##idx[CONFIG_I2S_NRFX_RX_BLOCK_COUNT]; \ + static void data_handler##idx(nrfx_i2s_buffers_t const *p_released, uint32_t status) \ + { \ + data_handler(DEVICE_DT_GET(I2S(idx)), p_released, status); \ + } \ + PINCTRL_DT_DEFINE(I2S(idx)); \ + static const struct i2s_nrfx_drv_cfg i2s_nrfx_cfg##idx = { \ + .data_handler = data_handler##idx, \ + .nrfx_def_cfg = NRFX_I2S_DEFAULT_CONFIG( \ + NRF_I2S_PIN_NOT_CONNECTED, NRF_I2S_PIN_NOT_CONNECTED, \ + NRF_I2S_PIN_NOT_CONNECTED, NRF_I2S_PIN_NOT_CONNECTED, \ + NRF_I2S_PIN_NOT_CONNECTED), \ + .nrfx_def_cfg.skip_gpio_cfg = true,

#ifdef CONFIG_HAS_HW_NRF_I2S0
I2S_NRFX_DEVICE(0);
Expand Down
22 changes: 22 additions & 0 deletions modules/hal_nordic/nrfx/nrfx_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,25 @@
default: return "unknown";
}
}

char const *nrfx_new_error_string_get(int code)
{
#define NRFX_NEW_ERROR_STRING_CASE(code) case code: return #code

Check warning on line 51 in modules/hal_nordic/nrfx/nrfx_glue.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

MACRO_WITH_FLOW_CONTROL

modules/hal_nordic/nrfx/nrfx_glue.c:51 Macros with flow control statements should be avoided
switch (-code)

Check failure on line 52 in modules/hal_nordic/nrfx/nrfx_glue.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

OPEN_BRACE

modules/hal_nordic/nrfx/nrfx_glue.c:52 that open brace { should be on the previous line
{
NRFX_NEW_ERROR_STRING_CASE(0);

Check notice on line 54 in modules/hal_nordic/nrfx/nrfx_glue.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrfx/nrfx_glue.c:54 - #define NRFX_NEW_ERROR_STRING_CASE(code) case code: return #code - switch (-code) - { +#define NRFX_NEW_ERROR_STRING_CASE(code) \ + case code: \ + return #code + switch (-code) {
NRFX_NEW_ERROR_STRING_CASE(ECANCELED);
NRFX_NEW_ERROR_STRING_CASE(ENOMEM);
NRFX_NEW_ERROR_STRING_CASE(ENOTSUP);
NRFX_NEW_ERROR_STRING_CASE(EINVAL);
NRFX_NEW_ERROR_STRING_CASE(EINPROGRESS);
NRFX_NEW_ERROR_STRING_CASE(E2BIG);
NRFX_NEW_ERROR_STRING_CASE(ETIMEDOUT);
NRFX_NEW_ERROR_STRING_CASE(EPERM);
NRFX_NEW_ERROR_STRING_CASE(EFAULT);
NRFX_NEW_ERROR_STRING_CASE(EACCES);
NRFX_NEW_ERROR_STRING_CASE(EBUSY);
NRFX_NEW_ERROR_STRING_CASE(EALREADY);
default: return "unknown";
}

Check notice on line 68 in modules/hal_nordic/nrfx/nrfx_glue.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrfx/nrfx_glue.c:68 - default: return "unknown"; + default: + return "unknown";
}
10 changes: 10 additions & 0 deletions modules/hal_nordic/nrfx/nrfx_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@
#define NRFX_LOG_ERROR_STRING_GET(error_code) nrfx_error_string_get(error_code)
extern char const *nrfx_error_string_get(nrfx_err_t code);

/**
* @brief Macro for getting the textual representation of a given errno error code.
*
* @param[in] error_code Errno error code.
*
* @return String containing the textual representation of the errno error code.
*/
#define NRFX_NEW_LOG_ERROR_STRING_GET(error_code) nrfx_new_error_string_get(error_code)
extern char const *nrfx_new_error_string_get(int code);

Check notice on line 139 in modules/hal_nordic/nrfx/nrfx_log.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

modules/hal_nordic/nrfx/nrfx_log.h:139 -#define NRFX_NEW_LOG_ERROR_STRING_GET(error_code) nrfx_new_error_string_get(error_code) +#define NRFX_NEW_LOG_ERROR_STRING_GET(error_code) nrfx_new_error_string_get(error_code)

/** @} */

#ifdef __cplusplus
Expand Down
Loading