Skip to content

Commit e41a6d8

Browse files
committed
Drivers: ADC_gecko: More formatting issues.
This time I ran clang-format against the file. Let's see if that takes care of all the problems. Signed-off-by: Kim Mansfield <[email protected]>
1 parent b4d87d2 commit e41a6d8

File tree

2 files changed

+102
-138
lines changed

2 files changed

+102
-138
lines changed

drivers/adc/adc_gecko.c

Lines changed: 102 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
#include <em_cmu.h>
1919
#include <em_gpio.h>
2020

21-
2221
#include <zephyr/logging/log.h>
2322
LOG_MODULE_REGISTER(adc_gecko, CONFIG_ADC_LOG_LEVEL);
2423

2524
#define ADC_GECKO_MAX_RESOLUTION 12
26-
#define ADC_GECKO_CHANNEL_NUM 32
25+
#define ADC_GECKO_CHANNEL_NUM 32
2726

2827
struct adc_gecko_config {
2928
ADC_TypeDef *base;
@@ -50,17 +49,17 @@ static int get_resolution(uint8_t resolution)
5049
{
5150

5251
switch (resolution) {
53-
case 12:
54-
return adcRes12Bit;
55-
case 8:
56-
return adcRes8Bit;
57-
case 6:
58-
return adcRes6Bit;
59-
case 0:
60-
return adcResOVS;
61-
default:
62-
LOG_ERR("ADC resolution value %d is not valid", resolution);
63-
return -EINVAL;
52+
case 12:
53+
return adcRes12Bit;
54+
case 8:
55+
return adcRes8Bit;
56+
case 6:
57+
return adcRes6Bit;
58+
case 0:
59+
return adcResOVS;
60+
default:
61+
LOG_ERR("ADC resolution value %d is not valid", resolution);
62+
return -EINVAL;
6463
}
6564
}
6665

@@ -81,14 +80,15 @@ static inline uint16_t adc_get_result(const struct device *dev)
8180
return (uint16_t)ADC_DataSingleGet(config->base);
8281
}
8382

84-
static int adc_get_channel_num(uint8_t id) {
85-
switch(id) {
86-
case 1:
87-
return adcPosSelAPORT3XCH10;
88-
case 2:
89-
return adcPosSelAPORT4XCH23;
90-
default:
91-
break;
83+
static int adc_get_channel_num(uint8_t id)
84+
{
85+
switch (id) {
86+
case 1:
87+
return adcPosSelAPORT3XCH10;
88+
case 2:
89+
return adcPosSelAPORT4XCH23;
90+
default:
91+
break;
9292
}
9393
return -1;
9494
}
@@ -99,7 +99,7 @@ static void adc_select_input(const struct device *dev, uint16_t channel_input)
9999
struct adc_gecko_data *data = dev->data;
100100

101101
config->initSingle_bv.resolution = get_resolution(data->resolution);
102-
config->initSingle_bv.posSel = adc_get_channel_num(channel_input+1);
102+
config->initSingle_bv.posSel = adc_get_channel_num(channel_input + 1);
103103
}
104104

105105
/**
@@ -112,8 +112,8 @@ static void adc_gecko_irq_handler(const struct device *dev)
112112
uint16_t result;
113113
uint8_t ainsel;
114114

115-
uint32_t flags = ADC_IntGet(ADC0); // get all interrupt flags
116-
if(flags & ADC_IF_SINGLE) {
115+
uint32_t flags = ADC_IntGet(ADC0); /* get all interrupt flags */
116+
if (flags & ADC_IF_SINGLE) {
117117
ADC_IntClear(config->base, flags);
118118

119119
/* Fetch result */
@@ -132,32 +132,31 @@ static void adc_gecko_irq_handler(const struct device *dev)
132132

133133
/* Kick next channel conversion */
134134
ainsel = (uint8_t)(find_lsb_set(data->channels) - 1);
135-
adc_select_input(dev,ainsel);
135+
adc_select_input(dev, ainsel);
136136
adc_start_once(dev);
137137
}
138-
139138
}
140139

141140
static int get_reference_voltage(int reference)
142141
{
143142
int ref;
144143

145144
switch (reference) {
146-
case ADC_REF_INTERNAL:
147-
ref = adcRef2V5;
148-
break;
149-
case ADC_REF_VDD_1:
150-
ref = adcRefVDD;
151-
break;
152-
case ADC_REF_VDD_1_2:
153-
ref = adcRef2V5;
154-
break;
155-
case ADC_REF_VDD_1_4:
156-
ref = adcRef1V25;
157-
break;
158-
default:
159-
ref = -1;
160-
break;
145+
case ADC_REF_INTERNAL:
146+
ref = adcRef2V5;
147+
break;
148+
case ADC_REF_VDD_1:
149+
ref = adcRefVDD;
150+
break;
151+
case ADC_REF_VDD_1_2:
152+
ref = adcRef2V5;
153+
break;
154+
case ADC_REF_VDD_1_4:
155+
ref = adcRef1V25;
156+
break;
157+
default:
158+
ref = -1;
159+
break;
161160
}
162161
return ref;
163162
}
@@ -168,42 +167,42 @@ static int get_acquisition_time(uint16_t acq)
168167

169168
/* Check acquisition time */
170169
switch (acq) {
171-
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 1):
172-
sample_cycl = adcAcqTime1;
173-
break;
174-
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 2):
175-
sample_cycl = adcAcqTime2;
176-
break;
177-
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 4):
178-
sample_cycl = adcAcqTime4;
179-
break;
180-
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 8):
181-
sample_cycl = adcAcqTime8;
182-
break;
183-
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 16):
184-
sample_cycl = adcAcqTime16;
185-
break;
186-
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 32):
187-
sample_cycl = adcAcqTime32;
188-
break;
189-
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 64):
190-
sample_cycl = adcAcqTime64;
191-
break;
192-
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 128):
193-
sample_cycl = adcAcqTime128;
194-
break;
195-
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 256):
196-
sample_cycl = adcAcqTime256;
197-
break;
198-
default:
199-
sample_cycl = 0;
200-
break;
170+
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 1):
171+
sample_cycl = adcAcqTime1;
172+
break;
173+
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 2):
174+
sample_cycl = adcAcqTime2;
175+
break;
176+
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 4):
177+
sample_cycl = adcAcqTime4;
178+
break;
179+
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 8):
180+
sample_cycl = adcAcqTime8;
181+
break;
182+
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 16):
183+
sample_cycl = adcAcqTime16;
184+
break;
185+
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 32):
186+
sample_cycl = adcAcqTime32;
187+
break;
188+
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 64):
189+
sample_cycl = adcAcqTime64;
190+
break;
191+
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 128):
192+
sample_cycl = adcAcqTime128;
193+
break;
194+
case ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 256):
195+
sample_cycl = adcAcqTime256;
196+
break;
197+
default:
198+
sample_cycl = 0;
199+
break;
201200
}
202201
return sample_cycl;
203202
}
204203

205204
static int adc_gecko_check_buffer_size(const struct device *dev,
206-
const struct adc_sequence *sequence)
205+
const struct adc_sequence *sequence)
207206
{
208207
const struct adc_gecko_config *config = dev->config;
209208
uint8_t channels = 0;
@@ -228,33 +227,29 @@ static int adc_gecko_check_buffer_size(const struct device *dev,
228227
return 0;
229228
}
230229

231-
232230
static void adc_context_start_sampling(struct adc_context *ctx)
233231
{
234-
struct adc_gecko_data *data = CONTAINER_OF(ctx, struct adc_gecko_data,
235-
ctx);
232+
struct adc_gecko_data *data = CONTAINER_OF(ctx, struct adc_gecko_data, ctx);
236233

237234
data->channels = ctx->sequence.channels;
238235
data->repeat_buf = data->buf;
239236
data->resolution = ctx->sequence.resolution;
240237
/* Find next channel and start conversion */
241-
adc_select_input(data->dev,find_lsb_set(data->channels) - 1 );
238+
adc_select_input(data->dev, find_lsb_set(data->channels) - 1);
242239
adc_start_once(data->dev);
243240
}
244241

245-
static void adc_context_update_buffer_pointer(struct adc_context *ctx,
246-
bool repeat_sampling)
242+
static void adc_context_update_buffer_pointer(struct adc_context *ctx, bool repeat_sampling)
247243
{
248-
struct adc_gecko_data *data = CONTAINER_OF(ctx, struct adc_gecko_data,
249-
ctx);
244+
struct adc_gecko_data *data = CONTAINER_OF(ctx, struct adc_gecko_data, ctx);
250245

251246
if (repeat_sampling) {
252247
data->buf = data->repeat_buf;
253248
}
254249
}
255250

256251
static int adc_gecko_channel_setup(const struct device *dev,
257-
const struct adc_channel_cfg *channel_cfg)
252+
const struct adc_channel_cfg *channel_cfg)
258253
{
259254
struct adc_gecko_config *config = (struct adc_gecko_config *)dev->config;
260255
if (channel_cfg->channel_id >= config->num_channels) {
@@ -274,22 +269,19 @@ static int adc_gecko_channel_setup(const struct device *dev,
274269
return 0;
275270
}
276271

277-
static int adc_gecko_start_read(const struct device *dev,
278-
const struct adc_sequence *sequence)
272+
static int adc_gecko_start_read(const struct device *dev, const struct adc_sequence *sequence)
279273
{
280274
const struct adc_gecko_config *config = dev->config;
281275
struct adc_gecko_data *data = dev->data;
282276
int err;
283277

284-
if (sequence->resolution > ADC_GECKO_MAX_RESOLUTION ||
285-
sequence->resolution == 0) {
278+
if (sequence->resolution > ADC_GECKO_MAX_RESOLUTION || sequence->resolution == 0) {
286279
LOG_ERR("unsupported resolution %d", sequence->resolution);
287280
return -ENOTSUP;
288281
}
289282

290283
if (find_msb_set(sequence->channels) > config->num_channels) {
291-
LOG_ERR("unsupported channels in mask: 0x%08x",
292-
sequence->channels);
284+
LOG_ERR("unsupported channels in mask: 0x%08x", sequence->channels);
293285
return -ENOTSUP;
294286
}
295287

@@ -305,9 +297,8 @@ static int adc_gecko_start_read(const struct device *dev,
305297
return adc_context_wait_for_completion(&data->ctx);
306298
}
307299

308-
static int adc_gecko_read_async(const struct device *dev,
309-
const struct adc_sequence *sequence,
310-
struct k_poll_signal *async)
300+
static int adc_gecko_read_async(const struct device *dev, const struct adc_sequence *sequence,
301+
struct k_poll_signal *async)
311302
{
312303
struct adc_gecko_data *data = dev->data;
313304
int err;
@@ -319,15 +310,14 @@ static int adc_gecko_read_async(const struct device *dev,
319310
return err;
320311
}
321312

322-
static int adc_gecko_read(const struct device *dev,
323-
const struct adc_sequence *sequence)
313+
static int adc_gecko_read(const struct device *dev, const struct adc_sequence *sequence)
324314
{
325315
return adc_gecko_read_async(dev, sequence, NULL);
326316
}
327317

328318
#ifdef CONFIG_ADC_ASYNC
329319
static int adc_gecko_read_async(const struct device *dev, const struct adc_sequence *sequence,
330-
struct k_poll_signal *async)
320+
struct k_poll_signal *async)
331321
{
332322
return -ENOTSUP;
333323
}
@@ -361,32 +351,30 @@ static int adc_gecko_init(const struct device *dev)
361351
return 0;
362352
}
363353

364-
#define IRQ_CONFIGURE_FUNC(idx) \
365-
static void adc_gecko_configure_func_##idx(void) \
366-
{ \
367-
IRQ_CONNECT(ADC0_IRQn, 0, \
368-
adc_gecko_irq_handler, DEVICE_DT_INST_GET(idx), 0); \
369-
irq_enable(ADC0_IRQn); \
370-
}
354+
#define IRQ_CONFIGURE_FUNC(idx) \
355+
static void adc_gecko_configure_func_##idx(void) \
356+
{ \
357+
IRQ_CONNECT(ADC0_IRQn, 0, adc_gecko_irq_handler, DEVICE_DT_INST_GET(idx), 0); \
358+
irq_enable(ADC0_IRQn); \
359+
}
371360

372361
#define IRQ_CONFIGURE_DEFINE(idx) .irq_configure = adc_gecko_configure_func_##idx
373362

374363
#define GECKO_ADC_INIT(inst) \
375-
IRQ_CONFIGURE_FUNC(inst) \
376-
static const struct adc_driver_api adc_gecko_api = { \
377-
.channel_setup = adc_gecko_channel_setup, \
378-
.read = adc_gecko_read, \
379-
.ref_internal = DT_INST_PROP(inst, vref_mv), \
380-
IF_ENABLED(CONFIG_ADC_ASYNC, (.read_async = adc_gecko_read_async,)) \
381-
}; \
382-
\
364+
IRQ_CONFIGURE_FUNC(inst) \
365+
static const struct adc_driver_api adc_gecko_api = { \
366+
.channel_setup = adc_gecko_channel_setup, \
367+
.read = adc_gecko_read, \
368+
.ref_internal = DT_INST_PROP(inst, vref_mv), \
369+
IF_ENABLED(CONFIG_ADC_ASYNC, (.read_async = adc_gecko_read_async, ))}; \
370+
\
383371
static struct adc_gecko_config adc_gecko_config##inst = { \
384-
.num_channels = ADC_GECKO_CHANNEL_NUM, \
385-
IRQ_CONFIGURE_DEFINE(inst), \
386-
}; \
372+
.num_channels = ADC_GECKO_CHANNEL_NUM, \
373+
IRQ_CONFIGURE_DEFINE(inst), \
374+
}; \
387375
static struct adc_gecko_data adc_gecko_data##inst; \
388-
\
376+
\
389377
DEVICE_DT_INST_DEFINE(inst, &adc_gecko_init, NULL, &adc_gecko_data##inst, \
390-
&adc_gecko_config##inst, POST_KERNEL, \
391-
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &adc_gecko_api);
378+
&adc_gecko_config##inst, POST_KERNEL, \
379+
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &adc_gecko_api);
392380
DT_INST_FOREACH_STATUS_OKAY(GECKO_ADC_INIT)

include/zephyr/drivers/adc/adc_gecko.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,4 @@
1212

1313
#include "em_adc.h"
1414

15-
#if 0
16-
#define ADC_GECKO_MAX_RESOLUTION 12
17-
18-
struct adc_gecko_config {
19-
ADC_TypeDef *base;
20-
ADC_InitSingle_TypeDef initSingle_bv;
21-
const struct gpio_dt_spec en_gpio;
22-
23-
/** Number of supported channels */
24-
uint8_t num_channels;
25-
};
26-
27-
struct adc_gecko_data {
28-
struct device *dev;
29-
struct adc_context ctx;
30-
uint16_t *buf;
31-
/** Pointer to where will be data stored in case of repeated sampling */
32-
uint16_t *repeat_buf;
33-
/** Mask with channels that will be sampled */
34-
uint32_t channels;
35-
uint32_t mVolts;
36-
};
37-
#endif
38-
3915
#endif

0 commit comments

Comments
 (0)