ST Expansion SW Team / VL53L3CX_mbed

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   VL53L3CX_NoShield_1Sensor_poll_Mb06x VL53L3_NoShield_1Sensor_polling_Mb63 X_NUCLEO_53L3A2 53L3A2_Ranging

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers spi_interface.cpp Source File

spi_interface.cpp

00001 #include "ToF_I2C.h"
00002 #include "pinmap.h"
00003 #include "spi_interface.h"
00004 
00005 
00006 static   InterruptIn *_gpio1Int;
00007       
00008 
00009 /* This file is an interface between the c files and the mbed cpp files. */
00010 /* .c files cannot directly access mbed. */
00011 
00012  int v53l1x_i2c_write_if(uint8_t* pBuffer, uint8_t DeviceAddr, uint16_t RegisterAddr,
00013                   uint16_t NumByteToWrite) 
00014 {
00015     
00016       static ToF_DevI2C *dev_I2C = new ToF_DevI2C(D14, D15);
00017       
00018       dev_I2C->frequency(400000);
00019       
00020  //   printf("----ToF_i2c_write  %d %d %d %d\n", DeviceAddr, RegisterAddr,NumByteToWrite ,pBuffer[0]); 
00021       int status = dev_I2C->ToF_i2c_write(pBuffer, DeviceAddr, RegisterAddr, NumByteToWrite);     
00022 //             printf("----ToF_i2c_write %d %d %d %d %d\n",status, DeviceAddr, RegisterAddr,NumByteToWrite ,pBuffer[0]);        
00023  
00024        
00025       return status;       
00026 }
00027 
00028  int v53l1x_i2c_write_direct(uint8_t* pBuffer, uint8_t DeviceAddr,
00029                   uint16_t NumByteToWrite) 
00030 {
00031     
00032     static ToF_DevI2C *dev_I2C = new ToF_DevI2C(D14, D15);
00033       
00034     dev_I2C->frequency(400000);
00035       
00036      // printf("v53l1x_i2c_write_if %d\n",NumByteToWrite);
00037     int status = dev_I2C->ToF_i2c_write_direct(pBuffer, DeviceAddr, NumByteToWrite);     
00038 //             printf("----ToF_i2c_write_direct %d %d %d %d %d\n",status, DeviceAddr,NumByteToWrite ,pBuffer[0]);        
00039 
00040      return status;       
00041 }
00042 
00043 
00044 
00045 
00046  int v53l1x_i2c_read_if(uint8_t* pBuffer, uint8_t DeviceAddr, uint16_t RegisterAddr,
00047                   uint16_t NumByteToRead) 
00048 {
00049             
00050     
00051       static ToF_DevI2C *dev_I2C = new ToF_DevI2C(D14, D15);
00052       if (dev_I2C == NULL)
00053       {
00054                       printf("v53l1x_i2c_read_if  no pointer%d\n",NumByteToRead);
00055       }
00056       dev_I2C->frequency(400000);
00057     //        printf("v53l1x_i2c_read_if %d\n",NumByteToRead);
00058       int status = dev_I2C->ToF_i2c_read(pBuffer, DeviceAddr, RegisterAddr, NumByteToRead);   
00059  //           printf("v53l1x_i2c_read_if %d %d %d %d %d\n",status, DeviceAddr, RegisterAddr,NumByteToRead ,pBuffer[0]);    
00060   //    delete dev_I2C;    
00061                        
00062       return status;       
00063 }
00064 
00065 
00066 int GetTickCount(
00067     uint32_t *ptick_count_ms)
00068 {
00069 
00070     /* Returns current tick count in [ms] */
00071 
00072     int status  = 0;
00073 
00074     //*ptick_count_ms = timeGetTime();
00075     *ptick_count_ms = us_ticker_read() / 1000;
00076 
00077     return status;
00078 }
00079 
00080 
00081 // routines to create interrupts to handle ranging detection
00082 void create_interrupt_measure_detection_irq(PinName pin)
00083 {
00084      _gpio1Int = new InterruptIn(pin);
00085 
00086 }
00087 
00088 void delete_interrupt_measure_detection_irq()
00089 {
00090     if ( _gpio1Int != NULL)
00091     {
00092         _gpio1Int->disable_irq();
00093         delete _gpio1Int;
00094     }
00095 
00096 }
00097 
00098 void enable_interrupt_measure_detection_irq()
00099 {
00100      if ( _gpio1Int != NULL)
00101          _gpio1Int->enable_irq();
00102 
00103 }
00104 
00105 void disable_interrupt_measure_detection_irq()
00106 {
00107      if ( _gpio1Int != NULL)
00108          _gpio1Int->disable_irq();
00109 }
00110 
00111 void attach_interrupt_measure_detection_irq(void (*fptr)(void))
00112 {
00113      if ( _gpio1Int != NULL)
00114          _gpio1Int->rise(fptr);
00115 }
00116 
00117 
00118 void set_gpio_pin(PinName pin, int state)
00119 {
00120         DigitalOut sensorshut(pin);
00121         sensorshut = state;
00122 }