@@ -50,23 +50,23 @@ static int get_resolution(uint8_t resolution)
50
50
{
51
51
52
52
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 ;
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 ;
64
64
}
65
65
}
66
66
67
67
static inline void adc_start_once (const struct device * dev )
68
68
{
69
- struct adc_gecko_config * config = (struct adc_gecko_config * )dev -> config ;
69
+ struct adc_gecko_config * config = (struct adc_gecko_config * )dev -> config ;
70
70
ADC_TypeDef * adc_reg = (ADC_TypeDef * )config -> base ;
71
71
72
72
/* Start ADC conversion */
@@ -95,7 +95,7 @@ static int adc_get_channel_num(uint8_t id) {
95
95
96
96
static void adc_select_input (const struct device * dev , uint16_t channel_input )
97
97
{
98
- struct adc_gecko_config * config = (struct adc_gecko_config * )dev -> config ;
98
+ struct adc_gecko_config * config = (struct adc_gecko_config * )dev -> config ;
99
99
struct adc_gecko_data * data = dev -> data ;
100
100
101
101
config -> initSingle_bv .resolution = get_resolution (data -> resolution );
@@ -108,33 +108,33 @@ static void adc_select_input(const struct device *dev, uint16_t channel_input)
108
108
static void adc_gecko_irq_handler (const struct device * dev )
109
109
{
110
110
struct adc_gecko_data * data = dev -> data ;
111
- struct adc_gecko_config * config = (struct adc_gecko_config * )dev -> config ;
111
+ struct adc_gecko_config * config = (struct adc_gecko_config * )dev -> config ;
112
112
uint16_t result ;
113
113
uint8_t ainsel ;
114
114
115
- uint32_t flags = ADC_IntGet (ADC0 ); // get all interrupt flags
116
- if (flags & ADC_IF_SINGLE ) {
117
- ADC_IntClear (config -> base , flags );
115
+ uint32_t flags = ADC_IntGet (ADC0 ); // get all interrupt flags
116
+ if (flags & ADC_IF_SINGLE ) {
117
+ ADC_IntClear (config -> base , flags );
118
118
119
- /* Fetch result */
120
- result = adc_get_result (dev );
121
- ainsel = find_lsb_set (data -> channels ) - 1 ;
119
+ /* Fetch result */
120
+ result = adc_get_result (dev );
121
+ ainsel = find_lsb_set (data -> channels ) - 1 ;
122
122
123
- /* Copy to buffer and mark this channel as completed to channels bitmap. */
124
- * data -> buf ++ = result ;
125
- data -> channels &= ~(BIT (ainsel ));
123
+ /* Copy to buffer and mark this channel as completed to channels bitmap. */
124
+ * data -> buf ++ = result ;
125
+ data -> channels &= ~(BIT (ainsel ));
126
126
127
- /* Notify result if all data gathered. */
128
- if (data -> channels == 0 ) {
129
- adc_context_on_sampling_done (& data -> ctx , dev );
130
- return ;
131
- }
127
+ /* Notify result if all data gathered. */
128
+ if (data -> channels == 0 ) {
129
+ adc_context_on_sampling_done (& data -> ctx , dev );
130
+ return ;
131
+ }
132
132
133
- /* Kick next channel conversion */
134
- ainsel = (uint8_t )(find_lsb_set (data -> channels ) - 1 );
133
+ /* Kick next channel conversion */
134
+ ainsel = (uint8_t )(find_lsb_set (data -> channels ) - 1 );
135
135
adc_select_input (dev ,ainsel );
136
- adc_start_once (dev );
137
- }
136
+ adc_start_once (dev );
137
+ }
138
138
139
139
}
140
140
@@ -143,21 +143,21 @@ static int get_reference_voltage(int reference)
143
143
int ref ;
144
144
145
145
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 ;
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 ;
161
161
}
162
162
return ref ;
163
163
}
@@ -168,42 +168,42 @@ static int get_acquisition_time(uint16_t acq)
168
168
169
169
/* Check acquisition time */
170
170
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 ;
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 ;
201
201
}
202
202
return sample_cycl ;
203
203
}
204
204
205
205
static int adc_gecko_check_buffer_size (const struct device * dev ,
206
- const struct adc_sequence * sequence )
206
+ const struct adc_sequence * sequence )
207
207
{
208
208
const struct adc_gecko_config * config = dev -> config ;
209
209
uint8_t channels = 0 ;
@@ -232,7 +232,7 @@ static int adc_gecko_check_buffer_size(const struct device *dev,
232
232
static void adc_context_start_sampling (struct adc_context * ctx )
233
233
{
234
234
struct adc_gecko_data * data = CONTAINER_OF (ctx , struct adc_gecko_data ,
235
- ctx );
235
+ ctx );
236
236
237
237
data -> channels = ctx -> sequence .channels ;
238
238
data -> repeat_buf = data -> buf ;
@@ -243,18 +243,18 @@ static void adc_context_start_sampling(struct adc_context *ctx)
243
243
}
244
244
245
245
static void adc_context_update_buffer_pointer (struct adc_context * ctx ,
246
- bool repeat_sampling )
246
+ bool repeat_sampling )
247
247
{
248
248
struct adc_gecko_data * data = CONTAINER_OF (ctx , struct adc_gecko_data ,
249
- ctx );
249
+ ctx );
250
250
251
251
if (repeat_sampling ) {
252
252
data -> buf = data -> repeat_buf ;
253
253
}
254
254
}
255
255
256
256
static int adc_gecko_channel_setup (const struct device * dev ,
257
- const struct adc_channel_cfg * channel_cfg )
257
+ const struct adc_channel_cfg * channel_cfg )
258
258
{
259
259
struct adc_gecko_config * config = (struct adc_gecko_config * )dev -> config ;
260
260
if (channel_cfg -> channel_id >= config -> num_channels ) {
@@ -275,21 +275,21 @@ static int adc_gecko_channel_setup(const struct device *dev,
275
275
}
276
276
277
277
static int adc_gecko_start_read (const struct device * dev ,
278
- const struct adc_sequence * sequence )
278
+ const struct adc_sequence * sequence )
279
279
{
280
280
const struct adc_gecko_config * config = dev -> config ;
281
281
struct adc_gecko_data * data = dev -> data ;
282
282
int err ;
283
283
284
284
if (sequence -> resolution > ADC_GECKO_MAX_RESOLUTION ||
285
- sequence -> resolution == 0 ) {
285
+ sequence -> resolution == 0 ) {
286
286
LOG_ERR ("unsupported resolution %d" , sequence -> resolution );
287
287
return - ENOTSUP ;
288
288
}
289
289
290
290
if (find_msb_set (sequence -> channels ) > config -> num_channels ) {
291
291
LOG_ERR ("unsupported channels in mask: 0x%08x" ,
292
- sequence -> channels );
292
+ sequence -> channels );
293
293
return - ENOTSUP ;
294
294
}
295
295
@@ -306,8 +306,8 @@ static int adc_gecko_start_read(const struct device *dev,
306
306
}
307
307
308
308
static int adc_gecko_read_async (const struct device * dev ,
309
- const struct adc_sequence * sequence ,
310
- struct k_poll_signal * async )
309
+ const struct adc_sequence * sequence ,
310
+ struct k_poll_signal * async )
311
311
{
312
312
struct adc_gecko_data * data = dev -> data ;
313
313
int err ;
@@ -320,14 +320,14 @@ static int adc_gecko_read_async(const struct device *dev,
320
320
}
321
321
322
322
static int adc_gecko_read (const struct device * dev ,
323
- const struct adc_sequence * sequence )
323
+ const struct adc_sequence * sequence )
324
324
{
325
325
return adc_gecko_read_async (dev , sequence , NULL );
326
326
}
327
327
328
328
#ifdef CONFIG_ADC_ASYNC
329
329
static int adc_gecko_read_async (const struct device * dev , const struct adc_sequence * sequence ,
330
- struct k_poll_signal * async )
330
+ struct k_poll_signal * async )
331
331
{
332
332
return - ENOTSUP ;
333
333
}
@@ -363,11 +363,11 @@ static int adc_gecko_init(const struct device *dev)
363
363
364
364
#define IRQ_CONFIGURE_FUNC (idx ) \
365
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
- }
366
+ { \
367
+ IRQ_CONNECT(ADC0_IRQn, 0, \
368
+ adc_gecko_irq_handler, DEVICE_DT_INST_GET(idx), 0); \
369
+ irq_enable(ADC0_IRQn); \
370
+ }
371
371
372
372
#define IRQ_CONFIGURE_DEFINE (idx ) .irq_configure = adc_gecko_configure_func_##idx
373
373
@@ -379,14 +379,14 @@ static int adc_gecko_init(const struct device *dev)
379
379
.ref_internal = DT_INST_PROP(inst, vref_mv), \
380
380
IF_ENABLED(CONFIG_ADC_ASYNC, (.read_async = adc_gecko_read_async,)) \
381
381
}; \
382
- \
382
+ \
383
383
static struct adc_gecko_config adc_gecko_config##inst = { \
384
384
.num_channels = ADC_GECKO_CHANNEL_NUM, \
385
385
IRQ_CONFIGURE_DEFINE(inst), \
386
- }; \
386
+ }; \
387
387
static struct adc_gecko_data adc_gecko_data##inst; \
388
- \
388
+ \
389
389
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);
390
+ &adc_gecko_config##inst, POST_KERNEL, \
391
+ CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &adc_gecko_api);
392
392
DT_INST_FOREACH_STATUS_OKAY (GECKO_ADC_INIT )
0 commit comments