11
11
#include <zephyr/drivers/pinctrl.h>
12
12
#include <errno.h>
13
13
#include <reg/adc.h>
14
+ #include <zephyr/logging/log.h>
14
15
15
16
#define ADC_CONTEXT_USES_KERNEL_TIMER
16
17
#include "adc_context.h"
17
18
19
+ LOG_MODULE_REGISTER (adc_ene_kb1200 , CONFIG_ADC_LOG_LEVEL );
20
+
18
21
struct adc_kb1200_config {
19
22
/* ADC Register base address */
20
23
struct adc_regs * adc ;
@@ -70,17 +73,17 @@ static int adc_kb1200_start_read(const struct device *dev, const struct adc_sequ
70
73
int error = 0 ;
71
74
72
75
if (!sequence -> channels || (sequence -> channels & ~BIT_MASK (ADC_MAX_CHAN ))) {
73
- printk ("Invalid ADC channels.\n " );
76
+ LOG_ERR ("Invalid ADC channels." );
74
77
return - EINVAL ;
75
78
}
76
79
/* Fixed 10 bit resolution of ene ADC */
77
80
if (sequence -> resolution != ADC_RESOLUTION ) {
78
- printk ("Unfixed 10 bit ADC resolution.\n " );
81
+ LOG_ERR ("Unfixed 10 bit ADC resolution." );
79
82
return - ENOTSUP ;
80
83
}
81
84
/* Check sequence->buffer_size is enough */
82
85
if (!adc_kb1200_validate_buffer_size (sequence )) {
83
- printk ("ADC buffer size too small.\n " );
86
+ LOG_ERR ("ADC buffer size too small." );
84
87
return - ENOMEM ;
85
88
}
86
89
@@ -107,7 +110,7 @@ static int adc_kb1200_start_read(const struct device *dev, const struct adc_sequ
107
110
k_busy_wait (ADC_WAIT_TIME );
108
111
count ++ ;
109
112
if (count >= ADC_WAIT_CNT ) {
110
- printk ("ADC busy timeout...\n " );
113
+ LOG_ERR ("ADC busy timeout..." );
111
114
error = - EBUSY ;
112
115
break ;
113
116
}
@@ -136,30 +139,30 @@ static int adc_kb1200_channel_setup(const struct device *dev,
136
139
const struct adc_channel_cfg * channel_cfg )
137
140
{
138
141
if (channel_cfg -> channel_id >= ADC_MAX_CHAN ) {
139
- printk ("Invalid channel %d.\n " , channel_cfg -> channel_id );
142
+ LOG_ERR ("Invalid channel %d." , channel_cfg -> channel_id );
140
143
return - EINVAL ;
141
144
}
142
145
143
146
if (channel_cfg -> acquisition_time != ADC_ACQ_TIME_DEFAULT ) {
144
- printk ("Unsupported channel acquisition time.\n " );
147
+ LOG_ERR ("Unsupported channel acquisition time." );
145
148
return - ENOTSUP ;
146
149
}
147
150
148
151
if (channel_cfg -> differential ) {
149
- printk ("Differential channels are not supported.\n " );
152
+ LOG_ERR ("Differential channels are not supported." );
150
153
return - ENOTSUP ;
151
154
}
152
155
153
156
if (channel_cfg -> gain != ADC_GAIN_1 ) {
154
- printk ("Unsupported channel gain %d.\n " , channel_cfg -> gain );
157
+ LOG_ERR ("Unsupported channel gain %d." , channel_cfg -> gain );
155
158
return - ENOTSUP ;
156
159
}
157
160
158
161
if (channel_cfg -> reference != ADC_REF_INTERNAL ) {
159
- printk ("Unsupported channel reference.\n " );
162
+ LOG_ERR ("Unsupported channel reference." );
160
163
return - ENOTSUP ;
161
164
}
162
- printk ("ADC channel %d configured.\n " , channel_cfg -> channel_id );
165
+ LOG_DBG ("ADC channel %d configured." , channel_cfg -> channel_id );
163
166
return 0 ;
164
167
}
165
168
@@ -199,7 +202,7 @@ static void adc_context_start_sampling(struct adc_context *ctx)
199
202
200
203
data -> repeat_buffer = data -> buffer ;
201
204
config -> adc -> ADCCFG = (config -> adc -> ADCCFG & ~ADC_CHANNEL_BIT_MASK ) |
202
- (ctx -> sequence .channels << ADC_CHANNEL_BIT_POS );
205
+ (ctx -> sequence .channels << ADC_CHANNEL_BIT_POS );
203
206
config -> adc -> ADCCFG |= ADC_FUNCTION_ENABLE ;
204
207
}
205
208
@@ -231,7 +234,7 @@ static int adc_kb1200_init(const struct device *dev)
231
234
/* Configure pin-mux for ADC device */
232
235
ret = pinctrl_apply_state (config -> pcfg , PINCTRL_STATE_DEFAULT );
233
236
if (ret < 0 ) {
234
- printk ("ADC pinctrl setup failed (%d).\n " , ret );
237
+ LOG_ERR ("ADC pinctrl setup failed (%d)." , ret );
235
238
return ret ;
236
239
}
237
240
@@ -249,7 +252,7 @@ static int adc_kb1200_init(const struct device *dev)
249
252
.adc = (struct adc_regs *)DT_INST_REG_ADDR(inst), \
250
253
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
251
254
}; \
252
- DEVICE_DT_INST_DEFINE(inst, & adc_kb1200_init, NULL, &adc_kb1200_data_##inst, \
255
+ DEVICE_DT_INST_DEFINE(inst, adc_kb1200_init, NULL, &adc_kb1200_data_##inst, \
253
256
&adc_kb1200_config_##inst, PRE_KERNEL_1, \
254
257
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &adc_kb1200_api);
255
258
0 commit comments