drivers: spi: nrfx: Clean up code
- clean up registration of the drivers with the logging subsystem - use consistent naming of local variables accessing configuration and runtime data of driver instances, for easier code maintenance Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
parent
fa22634880
commit
2a87e04ce6
3 changed files with 40 additions and 46 deletions
|
@ -8,10 +8,8 @@
|
|||
#include <pm/device.h>
|
||||
#include <nrfx_spi.h>
|
||||
|
||||
#define LOG_DOMAIN "spi_nrfx_spi"
|
||||
#define LOG_LEVEL CONFIG_SPI_LOG_LEVEL
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(spi_nrfx_spi);
|
||||
LOG_MODULE_REGISTER(spi_nrfx_spi, CONFIG_SPI_LOG_LEVEL);
|
||||
|
||||
#include "spi_context.h"
|
||||
|
||||
|
@ -149,7 +147,7 @@ static int configure(const struct device *dev,
|
|||
|
||||
static void transfer_next_chunk(const struct device *dev)
|
||||
{
|
||||
const struct spi_nrfx_config *config = dev->config;
|
||||
const struct spi_nrfx_config *dev_config = dev->config;
|
||||
struct spi_nrfx_data *dev_data = dev->data;
|
||||
struct spi_context *ctx = &dev_data->ctx;
|
||||
int error = 0;
|
||||
|
@ -166,7 +164,7 @@ static void transfer_next_chunk(const struct device *dev)
|
|||
xfer.tx_length = spi_context_tx_buf_on(ctx) ? chunk_len : 0;
|
||||
xfer.p_rx_buffer = ctx->rx_buf;
|
||||
xfer.rx_length = spi_context_rx_buf_on(ctx) ? chunk_len : 0;
|
||||
result = nrfx_spi_xfer(&config->spi, &xfer, 0);
|
||||
result = nrfx_spi_xfer(&dev_config->spi, &xfer, 0);
|
||||
if (result == NRFX_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
@ -274,8 +272,8 @@ static int spi_nrfx_pm_action(const struct device *dev,
|
|||
enum pm_device_action action)
|
||||
{
|
||||
int ret = 0;
|
||||
struct spi_nrfx_data *data = dev->data;
|
||||
const struct spi_nrfx_config *config = dev->config;
|
||||
struct spi_nrfx_data *dev_data = dev->data;
|
||||
const struct spi_nrfx_config *dev_config = dev->config;
|
||||
|
||||
switch (action) {
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
|
@ -285,9 +283,9 @@ static int spi_nrfx_pm_action(const struct device *dev,
|
|||
break;
|
||||
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
if (data->initialized) {
|
||||
nrfx_spi_uninit(&config->spi);
|
||||
data->initialized = false;
|
||||
if (dev_data->initialized) {
|
||||
nrfx_spi_uninit(&dev_config->spi);
|
||||
dev_data->initialized = false;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -326,15 +324,15 @@ static int spi_nrfx_pm_action(const struct device *dev,
|
|||
": cannot enable both pull-up and pull-down on MISO line"); \
|
||||
static int spi_##idx##_init(const struct device *dev) \
|
||||
{ \
|
||||
struct spi_nrfx_data *data = dev->data; \
|
||||
int err; \
|
||||
struct spi_nrfx_data *dev_data = dev->data; \
|
||||
int err; \
|
||||
IRQ_CONNECT(DT_IRQN(SPI(idx)), DT_IRQ(SPI(idx), priority), \
|
||||
nrfx_isr, nrfx_spi_##idx##_irq_handler, 0); \
|
||||
err = spi_context_cs_configure_all(&data->ctx); \
|
||||
if (err < 0) { \
|
||||
return err; \
|
||||
} \
|
||||
spi_context_unlock_unconditionally(&data->ctx); \
|
||||
err = spi_context_cs_configure_all(&dev_data->ctx); \
|
||||
if (err < 0) { \
|
||||
return err; \
|
||||
} \
|
||||
spi_context_unlock_unconditionally(&dev_data->ctx); \
|
||||
return 0; \
|
||||
} \
|
||||
static struct spi_nrfx_data spi_##idx##_data = { \
|
||||
|
|
|
@ -14,10 +14,8 @@
|
|||
#include <hal/nrf_clock.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LOG_DOMAIN "spi_nrfx_spim"
|
||||
#define LOG_LEVEL CONFIG_SPI_LOG_LEVEL
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(spi_nrfx_spim);
|
||||
LOG_MODULE_REGISTER(spi_nrfx_spim, CONFIG_SPI_LOG_LEVEL);
|
||||
|
||||
#include "spi_context.h"
|
||||
|
||||
|
@ -247,26 +245,26 @@ static void anomaly_58_workaround_clear(struct spi_nrfx_data *dev_data)
|
|||
|
||||
static int anomaly_58_workaround_init(const struct device *dev)
|
||||
{
|
||||
struct spi_nrfx_data *data = dev->data;
|
||||
const struct spi_nrfx_config *config = dev->config;
|
||||
struct spi_nrfx_data *dev_data = dev->data;
|
||||
const struct spi_nrfx_config *dev_config = dev->config;
|
||||
nrfx_err_t err_code;
|
||||
|
||||
data->anomaly_58_workaround_active = false;
|
||||
dev_data->anomaly_58_workaround_active = false;
|
||||
|
||||
if (config->anomaly_58_workaround) {
|
||||
err_code = nrfx_ppi_channel_alloc(&data->ppi_ch);
|
||||
if (dev_config->anomaly_58_workaround) {
|
||||
err_code = nrfx_ppi_channel_alloc(&dev_data->ppi_ch);
|
||||
if (err_code != NRFX_SUCCESS) {
|
||||
LOG_ERR("Failed to allocate PPI channel");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
err_code = nrfx_gpiote_channel_alloc(&data->gpiote_ch);
|
||||
err_code = nrfx_gpiote_channel_alloc(&dev_data->gpiote_ch);
|
||||
if (err_code != NRFX_SUCCESS) {
|
||||
LOG_ERR("Failed to allocate GPIOTE channel");
|
||||
return -ENODEV;
|
||||
}
|
||||
LOG_DBG("PAN 58 workaround enabled for %s: ppi %u, gpiote %u",
|
||||
dev->name, data->ppi_ch, data->gpiote_ch);
|
||||
dev->name, dev_data->ppi_ch, dev_data->gpiote_ch);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -432,8 +430,8 @@ static int spim_nrfx_pm_action(const struct device *dev,
|
|||
enum pm_device_action action)
|
||||
{
|
||||
int ret = 0;
|
||||
struct spi_nrfx_data *data = dev->data;
|
||||
const struct spi_nrfx_config *config = dev->config;
|
||||
struct spi_nrfx_data *dev_data = dev->data;
|
||||
const struct spi_nrfx_config *dev_config = dev->config;
|
||||
|
||||
switch (action) {
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
|
@ -443,9 +441,9 @@ static int spim_nrfx_pm_action(const struct device *dev,
|
|||
break;
|
||||
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
if (data->initialized) {
|
||||
nrfx_spim_uninit(&config->spim);
|
||||
data->initialized = false;
|
||||
if (dev_data->initialized) {
|
||||
nrfx_spim_uninit(&dev_config->spim);
|
||||
dev_data->initialized = false;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -492,16 +490,16 @@ static int spim_nrfx_pm_action(const struct device *dev,
|
|||
": cannot enable both pull-up and pull-down on MISO line"); \
|
||||
static int spi_##idx##_init(const struct device *dev) \
|
||||
{ \
|
||||
struct spi_nrfx_data *data = dev->data; \
|
||||
int err; \
|
||||
struct spi_nrfx_data *dev_data = dev->data; \
|
||||
int err; \
|
||||
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SPIM##idx), \
|
||||
DT_IRQ(SPIM(idx), priority), \
|
||||
nrfx_isr, nrfx_spim_##idx##_irq_handler, 0); \
|
||||
err = spi_context_cs_configure_all(&data->ctx); \
|
||||
if (err < 0) { \
|
||||
return err; \
|
||||
} \
|
||||
spi_context_unlock_unconditionally(&data->ctx); \
|
||||
err = spi_context_cs_configure_all(&dev_data->ctx); \
|
||||
if (err < 0) { \
|
||||
return err; \
|
||||
} \
|
||||
spi_context_unlock_unconditionally(&dev_data->ctx); \
|
||||
COND_CODE_1(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, \
|
||||
(return anomaly_58_workaround_init(dev);), \
|
||||
(return 0;)) \
|
||||
|
|
|
@ -7,10 +7,8 @@
|
|||
#include <drivers/spi.h>
|
||||
#include <nrfx_spis.h>
|
||||
|
||||
#define LOG_DOMAIN "spi_nrfx_spis"
|
||||
#define LOG_LEVEL CONFIG_SPI_LOG_LEVEL
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(spi_nrfx_spis);
|
||||
LOG_MODULE_REGISTER(spi_nrfx_spis, CONFIG_SPI_LOG_LEVEL);
|
||||
|
||||
#include "spi_context.h"
|
||||
|
||||
|
@ -52,9 +50,9 @@ static inline nrf_spis_bit_order_t get_nrf_spis_bit_order(uint16_t operation)
|
|||
static int configure(const struct device *dev,
|
||||
const struct spi_config *spi_cfg)
|
||||
{
|
||||
const struct spi_nrfx_config *config = dev->config;
|
||||
struct spi_nrfx_data *data = dev->data;
|
||||
struct spi_context *ctx = &data->ctx;
|
||||
const struct spi_nrfx_config *dev_config = dev->config;
|
||||
struct spi_nrfx_data *dev_data = dev->data;
|
||||
struct spi_context *ctx = &dev_data->ctx;
|
||||
|
||||
if (spi_context_configured(ctx, spi_cfg)) {
|
||||
/* Already configured. No need to do it again. */
|
||||
|
@ -94,7 +92,7 @@ static int configure(const struct device *dev,
|
|||
|
||||
ctx->config = spi_cfg;
|
||||
|
||||
nrf_spis_configure(config->spis.p_reg,
|
||||
nrf_spis_configure(dev_config->spis.p_reg,
|
||||
get_nrf_spis_mode(spi_cfg->operation),
|
||||
get_nrf_spis_bit_order(spi_cfg->operation));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue