ghnotgood opened a new pull request, #22015:
URL: https://github.com/apache/nuttx/pull/22015

   ## Summary
   
   This PR contains basic implementation for Kinetis' analog-to-digital 
converter (ADC).
   
   ## Impact
   
   After this PR is merged, developers may use `kinetis_adc_initialize` to 
bring up ADC device with specified channels being used, e.g.:
   ```
   #if defined(CONFIG_KINETIS_ADC0)                                             
  
     uint8_t const adc_ch_list[] = {21, 22};                                    
  
     struct adc_dev_s *adc0_dev = kinetis_adc_initialize(0, adc_ch_list, 2);    
     
     if (NULL == adc0_dev)                                                      
  
       {                                                                        
  
         syslog(LOG_ERR, "ERROR: ADC 0 initialization failed");                 
  
       }                                                                        
  
     else                                                                       
  
       {                                                                        
  
         ret = adc_register("/dev/adc0", adc0_dev);                             
  
         if (OK != ret)                                                         
  
           {                                                                    
  
             syslog(LOG_ERR, "ERROR: ADC 0 register failed");                   
  
           }                                                                    
  
       }                                                                        
  
   #endif
   ```
   
   which creates `/dev/adc0` device.
   
   ## Testing
   
   Core of testing code is:
   ```
     int fd = open("/dev/adc0", O_RDONLY);                                      
  
                                                                                
  
     while (true)                                                               
  
       {                                                                        
  
         struct adc_msg_s samples[2];                                           
  
                                                                                
  
         ioctl(fd, ANIOC_TRIGGER, 0);                                           
  
                                                                                
  
         int rcount = read(fd, samples, 2 * sizeof *samples);                   
  
                                                                                
  
         double ch21 = 0;                                                       
  
         double ch22 = 0;                                                       
  
         for (int i = 0; i < rcount / sizeof *samples; i++)                     
  
           {                                                                    
  
             switch (samples[i].am_channel)                                     
  
               {                                                                
  
                 case 21:                                                       
  
                     ch21 = samples[i].am_data / 256.0;                         
  
                     break;                                                     
  
                 case 22:                                  
                     ch22 = samples[i].am_data / 256.0;                         
  
                     break;                                                     
  
                 default:                                                       
  
                     break;                                                     
  
               }                                                                
  
           }                                                                    
  
                                                                                
  
         printf("ch 21: %.2f, ch 22: %.2f\n", ch21, ch22);                      
  
         usleep(1000);                                                          
  
       }
   ```
   
   The result of testing on our hardware where channels 21 and 22 of ADC0 are 
used as ADC inputs is:
   ```
   ch 21: 0.09, ch 22: 0.37
   ch 21: 0.09, ch 22: 0.37
   ch 21: 0.09, ch 22: 0.37
   ch 21: 0.09, ch 22: 0.37
   ch 21: 0.07, ch 22: 0.37
   ch 21: 0.06, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.01, ch 22: 0.37
   ch 21: 0.01, ch 22: 0.37
   ch 21: 0.01, ch 22: 0.37
   ch 21: 0.01, ch 22: 0.37
   ch 21: 0.01, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.00, ch 22: 0.37
   ch 21: 0.01, ch 22: 0.37
   ch 21: 0.01, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.02, ch 22: 0.37
   ch 21: 0.03, ch 22: 0.37
   ch 21: 0.06, ch 22: 0.37
   ch 21: 0.09, ch 22: 0.37
   ch 21: 0.09, ch 22: 0.37
   ch 21: 0.09, ch 22: 0.37
   ch 21: 0.09, ch 22: 0.37
   ```
   
   (ch1 is connected to light sensor and I put my hand over the sensor for a 
while). The build log follows.
   ```
   $ make
   Create version.h
   Cloning rtttl-c repo...
   Cloning into 'rtttl-c'...
   remote: Enumerating objects: 12, done.
   remote: Counting objects: 100% (12/12), done.
   remote: Compressing objects: 100% (12/12), done.
   remote: Total 12 (delta 0), reused 11 (delta 0), pack-reused 0 (from 0)
   Receiving objects: 100% (12/12), 10.89 KiB | 655.00 KiB/s, done.
   warning: refs/tags/v0.1.0 31216e092cb93d9c8ecf5959459f882cde6273df is not a 
commit!
   Note: switching to 'a093e617a16fc6a40b9d69a544cac182b21514c2'.
   
   You are in 'detached HEAD' state. You can look around, make experimental
   changes and commit them, and you can discard any commits you make in this
   state without impacting any branches by switching back to a branch.
   
   If you want to create a new branch to retain commits you create, you may
   do so (now or later) by using -c with the switch command. Example:
   
     git switch -c <new-branch-name>
   
   Or undo this operation with:
   
     git switch -
   
   Turn off this advice by setting config variable advice.detachedHead to false
   
   Checking rtttl-c hashes...
   LN: platform/board to /foo/foo/our-board-with-nuttx/nuttx-apps/platform/dummy
   Register: dd
   Register: nsh
   Register: sh
   Register: ping
   Register: test_adc
   Register: test_beep
   Register: test_buttons
   Register: test_1wire
   Register: test_eeprom
   Register: test_gpio
   Register: test_keypad
   Register: test_lcd
   Register: test_leds
   Register: test_rs485
   Register: test_usb
   Register: startup
   CC:  iob/iob_update_pktlen.c iob/iob_update_pktlen.c: In function 
'iob_update_pktlen':
   iob/iob_update_pktlen.c:130:26: warning: 'penultimate' may be used 
uninitialized [-Wmaybe-uninitialized]
     130 |           next->io_flink = iob_tryalloc(throttled);
         |           ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
   iob/iob_update_pktlen.c:52:21: note: 'penultimate' was declared here
      52 |   FAR struct iob_s *penultimate;
         |                     ^~~~~~~~~~~
   CC:  chip/kinetis_serial.c chip/kinetis_serial.c: In function 'up_rxint':
   chip/kinetis_serial.c:1836:4: warning: #warning "Revisit:  How are errors 
enabled?" [-Wcpp]
    1836 | #  warning "Revisit:  How are errors enabled?"
         |    ^~~~~~~
   CC:  chip/kinetis_sdhc.c In file included from chip/kinetis_sdhc.c:34:
   chip/kinetis_sdhc.c: In function 'kinetis_blocksetup':
   chip/kinetis_sdhc.c:1906:10: warning: format '%ld' expects argument of type 
'long int', but argument 3 has type 'unsigned int' [-Wformat=]
    1906 |   mcinfo("blocksize=%ld, total transfer=%ld (%ld blocks)\n", 
blocksize,
         |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
~~~~~~~~~
         |                                                              |
         |                                                              
unsigned int
   chip/kinetis_sdhc.c:1906:23: note: format string is defined here
    1906 |   mcinfo("blocksize=%ld, total transfer=%ld (%ld blocks)\n", 
blocksize,
         |                     ~~^
         |                       |
         |                       long int
         |                     %d
   chip/kinetis_sdhc.c:1906:10: warning: format '%ld' expects argument of type 
'long int', but argument 4 has type 'unsigned int' [-Wformat=]
    1906 |   mcinfo("blocksize=%ld, total transfer=%ld (%ld blocks)\n", 
blocksize,
         |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1907 |          blocksize * nblocks, nblocks);
         |          ~~~~~~~~~~~~~~~~~~~
         |                    |
         |                    unsigned int
   chip/kinetis_sdhc.c:1906:43: note: format string is defined here
    1906 |   mcinfo("blocksize=%ld, total transfer=%ld (%ld blocks)\n", 
blocksize,
         |                                         ~~^
         |                                           |
         |                                           long int
         |                                         %d
   chip/kinetis_sdhc.c:1906:10: warning: format '%ld' expects argument of type 
'long int', but argument 5 has type 'unsigned int' [-Wformat=]
    1906 |   mcinfo("blocksize=%ld, total transfer=%ld (%ld blocks)\n", 
blocksize,
         |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1907 |          blocksize * nblocks, nblocks);
         |                               ~~~~~~~
         |                               |
         |                               unsigned int
   chip/kinetis_sdhc.c:1906:48: note: format string is defined here
    1906 |   mcinfo("blocksize=%ld, total transfer=%ld (%ld blocks)\n", 
blocksize,
         |                                              ~~^
         |                                                |
         |                                                long int
         |                                              %d
   chip/kinetis_sdhc.c: In function 'kinetis_recvshortcrc':
   chip/kinetis_sdhc.c:2235:13: warning: format '%x' expects argument of type 
'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} 
[-Wformat=]
    2235 |       mcerr("ERROR: Wrong response CMD=%08x\n", cmd);
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~
         |                                                 |
         |                                                 uint32_t {aka long 
unsigned int}
   chip/kinetis_sdhc.c:2235:43: note: format string is defined here
    2235 |       mcerr("ERROR: Wrong response CMD=%08x\n", cmd);
         |                                        ~~~^
         |                                           |
         |                                           unsigned int
         |                                        %08lx
   CC:  chip/kinetis_usbdev.c chip/kinetis_usbdev.c: In function 'khci_wrstart':
   chip/kinetis_usbdev.c:1333:26: warning: 'xfrd' may be used uninitialized 
[-Wmaybe-uninitialized]
    1333 |   buf = privreq->req.buf + xfrd;
         |         ~~~~~~~~~~~~~~~~~^~~~~~
   chip/kinetis_usbdev.c:1156:7: note: 'xfrd' was declared here
    1156 |   int xfrd;
         |       ^~~~
   chip/kinetis_usbdev.c:1323:14: warning: 'bytesleft' may be used 
uninitialized [-Wmaybe-uninitialized]
    1323 |           if (bytesleft ==  privep->ep.maxpacket &&
         |              ^
   chip/kinetis_usbdev.c:1155:7: note: 'bytesleft' was declared here
    1155 |   int bytesleft;
         |       ^~~~~~~~~
   CC:  main.c main.c: In function 'startup_main':
   main.c:183:17: warning: unused variable 'pfds' [-Wunused-variable]
     183 |   struct pollfd pfds[2] =
         |                 ^~~~
   main.c:134:7: warning: unused variable 'nfds' [-Wunused-variable]
     134 |   int nfds = 1;
         |       ^~~~
   CC:  userleds.c In file included from 
/foo/foo/our-board-with-nuttx/nuttx/include/debug.h:32,
                    from userleds.c:31:
   userleds.c: In function 'board_userled_all':
   userleds.c:105:11: warning: format '%X' expects argument of type 'unsigned 
int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Wformat=]
     105 |   ledinfo("setting all leds with 0x%08X", ledset);
         |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~
         |                                           |
         |                                           uint32_t {aka long 
unsigned int}
   userleds.c:105:39: note: format string is defined here
     105 |   ledinfo("setting all leds with 0x%08X", ledset);
         |                                    ~~~^
         |                                       |
         |                                       unsigned int
         |                                    %08lX
   CPP:  
/foo/foo/our-board-with-nuttx/nuttx/../our-board-bsp/scripts/our-board.ld-> 
/foo/foo/our-board-LD: nuttx
   Memory region         Used Size  Region Size  %age Used
          vectflash:         444 B         1 KB     43.36%
         cfmprotect:          16 B         16 B    100.00%
          progflash:      294684 B      1022 KB     28.16%
           datasram:       32108 B       128 KB     24.50%
   CP: nuttx.hex
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to