xiaotailang opened a new issue, #12159:
URL: https://github.com/apache/nuttx/issues/12159

   I am interested in adding device drivers for I2C-based devices, such as 
G-sensors (accelerometers), RTCs, and the BH1750 light sensor, within the NuttX 
operating system. I have noticed existing drivers for devices like ADXL345, 
DS3231, and DS1307 in the nuttx/drivers directory, but upon examining the 
implementation of application-layer functions bound to open, write, and read, I 
find that the i2cdrvr_read and i2cdrvr_write functions lack concrete 
implementations. I have also seen an implementation for accessing the DS1307 
via I2C in the context of STM32F4, where the process involves initializing the 
I2C bus and binding it to the nSH, although the corresponding i2cdrvr_read and 
i2cdrvr_write functions remain without specific implementation details. Thus, I 
am unsure how the DS1307 is being read from and written to within the nSH 
environment. The implementation supporting the DS1307 on STM32F4 is as follows:
   int stm32_ds1307_init(void)
   {
     struct i2c_master_s *i2c;
     static bool initialized = false;
     int ret;
   
     /* Have we already initialized? */
   
     if (!initialized)
       {
         /* No.. Get the I2C bus driver */
   
         rtcinfo("Initialize I2C%d\n", DS1307_I2C_BUS);
         i2c = stm32_i2cbus_initialize(DS1307_I2C_BUS);
         if (!i2c)
           {
             rtcerr("ERROR: Failed to initialize I2C%d\n", DS1307_I2C_BUS);
             return -ENODEV;
           }
   
         /* Now bind the I2C interface to the DS1307 RTC driver */
   
         rtcinfo("Bind the DS1307 RTC driver to I2C%d\n", DS1307_I2C_BUS);
         ret = dsxxxx_rtc_initialize(i2c);
         if (ret < 0)
           {
             rtcerr("ERROR: Failed to bind I2C%d to the DS1307 RTC driver\n",
                    DS1307_I2C_BUS);
             return -ENODEV;
           }
   
   #ifdef CONFIG_I2C_DRIVER
         /* Register the I2C to get the "nsh> i2c bus" command working */
   
         ret = i2c_register(i2c, DS1307_I2C_BUS);
         if (ret < 0)
           {
             rtcerr("ERROR: Failed to register I2C%d driver: %d\n", bus, ret);
             return -ENODEV;
           }
   #endif
   
         /* Synchronize the system time to the RTC time */
   
         clock_synchronize(NULL);
   
         /* Now we are initialized */
   
         initialized = true;
       }
   
     return OK;
   }


-- 
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