Skip to content

Commit

Permalink
drivers: nrf5: temp: Cleanup temp_nrf5.c source
Browse files Browse the repository at this point in the history
1. Remove nrf_common.h include
2. Remove unnecessary NRF_*Type defines, using
   CMSIS NRF_TEMP define directly instead.
3. Align driver code by including DEVICE_DECLARE,
   and moving DEVICE_AND_API_INIT() to the bottom.

Signed-off-by: Gaute Gamnes <[email protected]>
  • Loading branch information
gamnes authored and carlescufi committed Mar 12, 2019
1 parent f4f9898 commit 6af7856
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions drivers/sensor/nrf5/temp_nrf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
LOG_MODULE_REGISTER(TEMPNRF5);

#include "nrf.h"
#include "nrf_common.h"


/* The nRF5 temperature device returns measurements in 0.25C
Expand All @@ -30,7 +29,6 @@ struct temp_nrf5_data {

static int temp_nrf5_sample_fetch(struct device *dev, enum sensor_channel chan)
{
volatile NRF_TEMP_Type *temp = NRF_TEMP;
struct temp_nrf5_data *data = dev->driver_data;
int r;

Expand All @@ -47,15 +45,15 @@ static int temp_nrf5_sample_fetch(struct device *dev, enum sensor_channel chan)
r = clock_control_on(data->clk_m16_dev, (void *)1);
__ASSERT_NO_MSG(!r);

temp->TASKS_START = 1;
NRF_TEMP->TASKS_START = 1;
k_sem_take(&data->device_sync_sem, K_FOREVER);

r = clock_control_off(data->clk_m16_dev, (void *)1);
__ASSERT_NO_MSG(!r || r == -EBUSY);

data->sample = temp->TEMP;
data->sample = NRF_TEMP->TEMP;

temp->TASKS_STOP = 1;
NRF_TEMP->TASKS_STOP = 1;

return 0;
}
Expand All @@ -82,11 +80,10 @@ static int temp_nrf5_channel_get(struct device *dev,

static void temp_nrf5_isr(void *arg)
{
volatile NRF_TEMP_Type *temp = NRF_TEMP;
struct device *dev = (struct device *)arg;
struct temp_nrf5_data *data = dev->driver_data;

temp->EVENTS_DATARDY = 0;
NRF_TEMP->EVENTS_DATARDY = 0;
k_sem_give(&data->device_sync_sem);
}

Expand All @@ -95,18 +92,10 @@ static const struct sensor_driver_api temp_nrf5_driver_api = {
.channel_get = temp_nrf5_channel_get,
};

static int temp_nrf5_init(struct device *dev);

static struct temp_nrf5_data temp_nrf5_driver;

DEVICE_AND_API_INIT(temp_nrf5, CONFIG_TEMP_NRF5_NAME, temp_nrf5_init,
&temp_nrf5_driver, NULL,
POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &temp_nrf5_driver_api);
DEVICE_DECLARE(temp_nrf5);

static int temp_nrf5_init(struct device *dev)
{
volatile NRF_TEMP_Type *temp = NRF_TEMP;
struct temp_nrf5_data *data = dev->driver_data;

LOG_DBG("");
Expand All @@ -124,7 +113,18 @@ static int temp_nrf5_init(struct device *dev)
0);
irq_enable(DT_NORDIC_NRF_TEMP_0_IRQ_0);

temp->INTENSET = TEMP_INTENSET_DATARDY_Set;
NRF_TEMP->INTENSET = TEMP_INTENSET_DATARDY_Set;

return 0;
}

static struct temp_nrf5_data temp_nrf5_driver;

DEVICE_AND_API_INIT(temp_nrf5,
CONFIG_TEMP_NRF5_NAME,
temp_nrf5_init,
&temp_nrf5_driver,
NULL,
POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY,
&temp_nrf5_driver_api);

0 comments on commit 6af7856

Please sign in to comment.