@@ -108,33 +108,33 @@ static int interrupt_handler(int irq,
108108 void * context ,
109109 void * arg );
110110
111- static void get_next_channel (void );
112- static void add_device (struct adc_dev_s * dev );
113- static void remove_device (struct adc_dev_s * dev );
111+ static void adc_get_next_channel (void );
112+ static void adc_add_device (struct adc_dev_s * dev );
113+ static void adc_remove_device (struct adc_dev_s * dev );
114114
115115/* ADC methods */
116116
117- static int my_bind (struct adc_dev_s * dev ,
118- const struct adc_callback_s * callback );
117+ static int adc_bind (struct adc_dev_s * dev ,
118+ const struct adc_callback_s * callback );
119119
120- static void my_reset (struct adc_dev_s * dev );
121- static int my_setup (struct adc_dev_s * dev );
122- static void my_shutdown (struct adc_dev_s * dev );
123- static void my_rxint (struct adc_dev_s * dev , bool enable );
124- static int my_ioctl (struct adc_dev_s * dev , int cmd , unsigned long arg );
120+ static void adc_reset (struct adc_dev_s * dev );
121+ static int adc_setup (struct adc_dev_s * dev );
122+ static void adc_shutdown (struct adc_dev_s * dev );
123+ static void adc_rxint (struct adc_dev_s * dev , bool enable );
124+ static int adc_ioctl (struct adc_dev_s * dev , int cmd , unsigned long arg );
125125
126126/****************************************************************************
127127 * Private Data
128128 ****************************************************************************/
129129
130130static const struct adc_ops_s g_adcops =
131131{
132- .ao_bind = my_bind , /* Called first during initialization. */
133- .ao_reset = my_reset , /* Called second during initialization. */
134- .ao_setup = my_setup , /* Called during first open. */
135- .ao_shutdown = my_shutdown , /* Called during last close. */
136- .ao_rxint = my_rxint , /* Called to enable/disable interrupts. */
137- .ao_ioctl = my_ioctl , /* Called for custom ioctls. */
132+ .ao_bind = adc_bind , /* Called first during initialization. */
133+ .ao_reset = adc_reset , /* Called second during initialization. */
134+ .ao_setup = adc_setup , /* Called during first open. */
135+ .ao_shutdown = adc_shutdown , /* Called during last close. */
136+ .ao_rxint = adc_rxint , /* Called to enable/disable interrupts. */
137+ .ao_ioctl = adc_ioctl , /* Called for custom ioctls. */
138138};
139139
140140static const int8_t g_gpio_map [ADC_CHANNEL_COUNT ] =
@@ -227,13 +227,13 @@ static int interrupt_handler(int irq, void *context, void *arg)
227227
228228 /* Start next channel read */
229229
230- get_next_channel ();
230+ adc_get_next_channel ();
231231
232232 return OK ;
233233}
234234
235235/****************************************************************************
236- * Name: get_next_channel
236+ * Name: adc_get_next_channel
237237 *
238238 * Description:
239239 * Update g_current_channel to point to next channel in use and start
@@ -243,7 +243,7 @@ static int interrupt_handler(int irq, void *context, void *arg)
243243 *
244244 ****************************************************************************/
245245
246- static void get_next_channel (void )
246+ static void adc_get_next_channel (void )
247247{
248248 struct adc_dev_s * a_device ;
249249 uint8_t next = g_current_channel + 1 ;
@@ -316,7 +316,7 @@ static void get_next_channel(void)
316316}
317317
318318/****************************************************************************
319- * Name: add_device
319+ * Name: adc_add_device
320320 *
321321 * Description:
322322 * This function is called to link the device int the device list.
@@ -326,7 +326,7 @@ static void get_next_channel(void)
326326 *
327327 ****************************************************************************/
328328
329- static void add_device (struct adc_dev_s * dev )
329+ static void adc_add_device (struct adc_dev_s * dev )
330330{
331331 uint32_t value ;
332332
@@ -368,14 +368,14 @@ static void add_device(struct adc_dev_s *dev)
368368
369369 /* Start conversions on first required channel. */
370370
371- get_next_channel ();
371+ adc_get_next_channel ();
372372
373373 ainfo ("new cur %d\n" , g_current_channel );
374374 }
375375}
376376
377377/****************************************************************************
378- * Name: remove_device
378+ * Name: adc_remove_device
379379 *
380380 * Description:
381381 * This function is called to unlink the device from the device list.
@@ -384,7 +384,7 @@ static void add_device(struct adc_dev_s *dev)
384384 *
385385 ****************************************************************************/
386386
387- void remove_device (struct adc_dev_s * dev )
387+ void adc_remove_device (struct adc_dev_s * dev )
388388{
389389 struct adc_dev_s * a_device ;
390390
@@ -426,7 +426,7 @@ void remove_device(struct adc_dev_s *dev)
426426}
427427
428428/****************************************************************************
429- * Name: my_bind
429+ * Name: adc_bind
430430 *
431431 * Description:
432432 * This function is called when a driver is registered. It give us a
@@ -435,20 +435,20 @@ void remove_device(struct adc_dev_s *dev)
435435 *
436436 ****************************************************************************/
437437
438- static int my_bind (struct adc_dev_s * dev ,
439- const struct adc_callback_s * callback )
438+ static int adc_bind (struct adc_dev_s * dev ,
439+ const struct adc_callback_s * callback )
440440{
441441 DEBUGASSERT (PRIV (dev ) != NULL );
442442
443- ainfo ("entered \n" );
443+ ainfo ("Binding: 0x%08lX \n" , dev );
444444
445445 PRIV (dev )-> callback = callback ;
446446
447447 return OK ;
448448}
449449
450450/****************************************************************************
451- * Name: my_reset
451+ * Name: adc_reset
452452 *
453453 * Description:
454454 * This is called by the upper-half as part of the driver registration
@@ -459,27 +459,35 @@ static int my_bind(struct adc_dev_s *dev,
459459 *
460460 ****************************************************************************/
461461
462- static void my_reset (struct adc_dev_s * dev )
462+ static void adc_reset (struct adc_dev_s * dev )
463463{
464464 int a_gpio ;
465465
466- ainfo ("entered \n" );
466+ ainfo ("Resetting: 0x%08lX \n" , dev );
467467
468468 for (int i = 0 ; i < ADC_CHANNEL_COUNT ; ++ i )
469469 {
470470 a_gpio = g_gpio_map [i ];
471471
472- if (a_gpio >= 0 )
472+ if (PRIV ( dev ) -> has_channel [ i ] )
473473 {
474- rp2040_gpio_setdir (a_gpio , false);
475- rp2040_gpio_set_function (a_gpio , RP2040_GPIO_FUNC_NULL );
476- rp2040_gpio_set_pulls (a_gpio , false, false);
474+ if (a_gpio >= 0 )
475+ {
476+ ainfo ("Attaching GPIO %d to ADC channel %d\n" , a_gpio , i + 1 );
477+ rp2040_gpio_setdir (a_gpio , false);
478+ rp2040_gpio_set_function (a_gpio , RP2040_GPIO_FUNC_NULL );
479+ rp2040_gpio_set_pulls (a_gpio , false, false);
480+ }
481+ else
482+ {
483+ ainfo ("ADC channel %d is internally connected\n" , i + 1 );
484+ }
477485 }
478486 }
479487}
480488
481489/****************************************************************************
482- * Name: my_setup
490+ * Name: adc_setup
483491 *
484492 * Description:
485493 * This is called when a particular ADC driver is first opened.
@@ -490,11 +498,11 @@ static void my_reset(struct adc_dev_s *dev)
490498 *
491499 ****************************************************************************/
492500
493- static int my_setup (struct adc_dev_s * dev )
501+ static int adc_setup (struct adc_dev_s * dev )
494502{
495503 int ret ;
496504
497- ainfo ("entered : 0x%08lX\n" , dev );
505+ ainfo ("Setup : 0x%08lX\n" , dev );
498506
499507 /* Note: We check g_active_count here so we can return an error
500508 * in the, probably impossible, case we have too many.
@@ -514,7 +522,7 @@ static int my_setup(struct adc_dev_s *dev)
514522}
515523
516524/****************************************************************************
517- * Name: my_shutdown
525+ * Name: adc_shutdown
518526 *
519527 * Description:
520528 * This is called to shutdown an ADC device. It unlinks the
@@ -525,17 +533,17 @@ static int my_setup(struct adc_dev_s *dev)
525533 *
526534 ****************************************************************************/
527535
528- static void my_shutdown (struct adc_dev_s * dev )
536+ static void adc_shutdown (struct adc_dev_s * dev )
529537{
530- ainfo ("entered : 0x%08lX\n" , dev );
538+ ainfo ("Shutdown : 0x%08lX\n" , dev );
531539
532540 /* Remove adc_dev_s structure from the list */
533541
534- remove_device (dev );
542+ adc_remove_device (dev );
535543}
536544
537545/****************************************************************************
538- * Name: my_rxint
546+ * Name: adc_rxint
539547 *
540548 * Description:
541549 * Call to enable or disable ADC RX interrupts
@@ -544,37 +552,37 @@ static void my_shutdown(struct adc_dev_s *dev)
544552 *
545553 ****************************************************************************/
546554
547- static void my_rxint (struct adc_dev_s * dev , bool enable )
555+ static void adc_rxint (struct adc_dev_s * dev , bool enable )
548556{
549557 if (enable )
550558 {
551- ainfo ("entered: enable : 0x%08lX\n" , dev );
559+ ainfo ("Enabling : 0x%08lX\n" , dev );
552560
553- add_device (dev );
561+ adc_add_device (dev );
554562 }
555563 else
556564 {
557- ainfo ("entered: disable : 0x%08lX\n" , dev );
565+ ainfo ("Disabling : 0x%08lX\n" , dev );
558566
559- remove_device (dev );
567+ adc_remove_device (dev );
560568 }
561569}
562570
563571/****************************************************************************
564- * Name: my_ioctl
572+ * Name: adc_ioctl
565573 *
566574 * Description:
567575 * All ioctl calls will be routed through this method
568576 *
569577 ****************************************************************************/
570578
571- static int my_ioctl (struct adc_dev_s * dev ,
572- int cmd ,
573- unsigned long arg )
579+ static int adc_ioctl (struct adc_dev_s * dev ,
580+ int cmd ,
581+ unsigned long arg )
574582{
575583 /* No ioctl commands supported */
576584
577- ainfo ("entered \n" );
585+ ainfo ("ioctl: 0x%08lX \n" , dev );
578586
579587 return - ENOTTY ;
580588}
@@ -586,7 +594,7 @@ static int my_ioctl(struct adc_dev_s *dev,
586594#ifdef CONFIG_ADC
587595
588596/****************************************************************************
589- * Name: my_setup
597+ * Name: rp2040_adc_initialize
590598 *
591599 * Description:
592600 * Initialize and register the ADC driver.
@@ -604,18 +612,18 @@ static int my_ioctl(struct adc_dev_s *dev,
604612 * success or NULL (with errno set) on failure
605613 ****************************************************************************/
606614
607- int rp2040_adc_setup (const char * path ,
608- bool read_adc0 ,
609- bool read_adc1 ,
610- bool read_adc2 ,
611- bool read_adc3 ,
612- bool read_temp )
615+ int rp2040_adc_initialize (const char * path ,
616+ bool read_adc0 ,
617+ bool read_adc1 ,
618+ bool read_adc2 ,
619+ bool read_adc3 ,
620+ bool read_temp )
613621{
614622 struct adc_dev_s * dev ;
615623 struct private_s * priv ;
616624 int ret ;
617625
618- ainfo ("entered \n" );
626+ ainfo ("Initializing: 0x%08lX \n" , dev );
619627
620628 if (!read_adc0 && !read_adc1 && !read_adc2 && !read_adc3 && !read_temp )
621629 {
0 commit comments