1111#include <zephyr/drivers/pinctrl.h>
1212#include <errno.h>
1313#include <reg/adc.h>
14+ #include <zephyr/logging/log.h>
1415
1516#define ADC_CONTEXT_USES_KERNEL_TIMER
1617#include "adc_context.h"
1718
19+ LOG_MODULE_REGISTER (adc_ene_kb1200 , CONFIG_ADC_LOG_LEVEL );
20+
1821struct adc_kb1200_config {
1922 /* ADC Register base address */
2023 struct adc_regs * adc ;
@@ -70,17 +73,17 @@ static int adc_kb1200_start_read(const struct device *dev, const struct adc_sequ
7073 int error = 0 ;
7174
7275 if (!sequence -> channels || (sequence -> channels & ~BIT_MASK (ADC_MAX_CHAN ))) {
73- printk ("Invalid ADC channels.\n " );
76+ LOG_ERR ("Invalid ADC channels." );
7477 return - EINVAL ;
7578 }
7679 /* Fixed 10 bit resolution of ene ADC */
7780 if (sequence -> resolution != ADC_RESOLUTION ) {
78- printk ("Unfixed 10 bit ADC resolution.\n " );
81+ LOG_ERR ("Unfixed 10 bit ADC resolution." );
7982 return - ENOTSUP ;
8083 }
8184 /* Check sequence->buffer_size is enough */
8285 if (!adc_kb1200_validate_buffer_size (sequence )) {
83- printk ("ADC buffer size too small.\n " );
86+ LOG_ERR ("ADC buffer size too small." );
8487 return - ENOMEM ;
8588 }
8689
@@ -107,7 +110,7 @@ static int adc_kb1200_start_read(const struct device *dev, const struct adc_sequ
107110 k_busy_wait (ADC_WAIT_TIME );
108111 count ++ ;
109112 if (count >= ADC_WAIT_CNT ) {
110- printk ("ADC busy timeout...\n " );
113+ LOG_ERR ("ADC busy timeout..." );
111114 error = - EBUSY ;
112115 break ;
113116 }
@@ -136,30 +139,30 @@ static int adc_kb1200_channel_setup(const struct device *dev,
136139 const struct adc_channel_cfg * channel_cfg )
137140{
138141 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 );
140143 return - EINVAL ;
141144 }
142145
143146 if (channel_cfg -> acquisition_time != ADC_ACQ_TIME_DEFAULT ) {
144- printk ("Unsupported channel acquisition time.\n " );
147+ LOG_ERR ("Unsupported channel acquisition time." );
145148 return - ENOTSUP ;
146149 }
147150
148151 if (channel_cfg -> differential ) {
149- printk ("Differential channels are not supported.\n " );
152+ LOG_ERR ("Differential channels are not supported." );
150153 return - ENOTSUP ;
151154 }
152155
153156 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 );
155158 return - ENOTSUP ;
156159 }
157160
158161 if (channel_cfg -> reference != ADC_REF_INTERNAL ) {
159- printk ("Unsupported channel reference.\n " );
162+ LOG_ERR ("Unsupported channel reference." );
160163 return - ENOTSUP ;
161164 }
162- printk ("ADC channel %d configured.\n " , channel_cfg -> channel_id );
165+ LOG_DBG ("ADC channel %d configured." , channel_cfg -> channel_id );
163166 return 0 ;
164167}
165168
@@ -199,7 +202,7 @@ static void adc_context_start_sampling(struct adc_context *ctx)
199202
200203 data -> repeat_buffer = data -> buffer ;
201204 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 );
203206 config -> adc -> ADCCFG |= ADC_FUNCTION_ENABLE ;
204207}
205208
@@ -231,7 +234,7 @@ static int adc_kb1200_init(const struct device *dev)
231234 /* Configure pin-mux for ADC device */
232235 ret = pinctrl_apply_state (config -> pcfg , PINCTRL_STATE_DEFAULT );
233236 if (ret < 0 ) {
234- printk ("ADC pinctrl setup failed (%d).\n " , ret );
237+ LOG_ERR ("ADC pinctrl setup failed (%d)." , ret );
235238 return ret ;
236239 }
237240
@@ -249,7 +252,7 @@ static int adc_kb1200_init(const struct device *dev)
249252 .adc = (struct adc_regs *)DT_INST_REG_ADDR(inst), \
250253 .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
251254 }; \
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, \
253256 &adc_kb1200_config_##inst, PRE_KERNEL_1, \
254257 CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &adc_kb1200_api);
255258
0 commit comments