VL53L3 Shield specific functions.
Dependents: 53L3A2_Ranging X_NUCLEO_53L3CX
XNucleo53LX.cpp@0:ba15439f45dd, 2020-10-16 (annotated)
- Committer:
- charlesmn
- Date:
- Fri Oct 16 15:11:45 2020 +0000
- Revision:
- 0:ba15439f45dd
- Child:
- 1:8afec488fa83
Change VL53L1 to VL53L3. Change name
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:ba15439f45dd | 1 | #include "XNucleo53LX.h" |
charlesmn | 0:ba15439f45dd | 2 | |
charlesmn | 0:ba15439f45dd | 3 | XNucleo53LX *XNucleo53LX::_instance = NULL; |
charlesmn | 0:ba15439f45dd | 4 | |
charlesmn | 0:ba15439f45dd | 5 | |
charlesmn | 0:ba15439f45dd | 6 | XNucleo53LX *XNucleo53LX::instance(vl53L1X_DevI2C *ext_i2c) |
charlesmn | 0:ba15439f45dd | 7 | { |
charlesmn | 0:ba15439f45dd | 8 | if (_instance == NULL) { |
charlesmn | 0:ba15439f45dd | 9 | _instance = new XNucleo53LX(ext_i2c); |
charlesmn | 0:ba15439f45dd | 10 | } else { |
charlesmn | 0:ba15439f45dd | 11 | printf("Failed to create XNucleo53LX instance\n\r\r\n"); |
charlesmn | 0:ba15439f45dd | 12 | } |
charlesmn | 0:ba15439f45dd | 13 | return _instance; |
charlesmn | 0:ba15439f45dd | 14 | } |
charlesmn | 0:ba15439f45dd | 15 | |
charlesmn | 0:ba15439f45dd | 16 | XNucleo53LX *XNucleo53LX::instance(vl53L1X_DevI2C *ext_i2c, |
charlesmn | 0:ba15439f45dd | 17 | PinName gpio1_centre, |
charlesmn | 0:ba15439f45dd | 18 | PinName gpio1_left, PinName gpio1_right) |
charlesmn | 0:ba15439f45dd | 19 | { |
charlesmn | 0:ba15439f45dd | 20 | if (_instance == NULL) { |
charlesmn | 0:ba15439f45dd | 21 | // printf("instance %d z\n",ext_i2c); |
charlesmn | 0:ba15439f45dd | 22 | _instance = new XNucleo53LX(ext_i2c, gpio1_centre, gpio1_left, gpio1_right); |
charlesmn | 0:ba15439f45dd | 23 | } else { |
charlesmn | 0:ba15439f45dd | 24 | printf("Failed to create XNucleo53LX instance\n\r"); |
charlesmn | 0:ba15439f45dd | 25 | } |
charlesmn | 0:ba15439f45dd | 26 | return _instance; |
charlesmn | 0:ba15439f45dd | 27 | } |
charlesmn | 0:ba15439f45dd | 28 | |
charlesmn | 0:ba15439f45dd | 29 | |
charlesmn | 0:ba15439f45dd | 30 | int XNucleo53LX::init_board() |
charlesmn | 0:ba15439f45dd | 31 | { |
charlesmn | 0:ba15439f45dd | 32 | printf("init_board \n"); |
charlesmn | 0:ba15439f45dd | 33 | int status, n_dev = 0; |
charlesmn | 0:ba15439f45dd | 34 | |
charlesmn | 0:ba15439f45dd | 35 | sensor_centre->VL53LX_Off(); |
charlesmn | 0:ba15439f45dd | 36 | sensor_left->VL53LX_Off(); |
charlesmn | 0:ba15439f45dd | 37 | sensor_right->VL53LX_Off(); |
charlesmn | 0:ba15439f45dd | 38 | |
charlesmn | 0:ba15439f45dd | 39 | |
charlesmn | 0:ba15439f45dd | 40 | |
charlesmn | 0:ba15439f45dd | 41 | // On startup or on the shutdown pin going high the VL53l1 devices have a i2c address of 0x52. |
charlesmn | 0:ba15439f45dd | 42 | // To initialise then we have to bring up one device at a time This involves raising the shutdown pin for that device, |
charlesmn | 0:ba15439f45dd | 43 | // initialising then setting the i2c address to a unique value. Once that is done the shutdown pins don't need to be touched. |
charlesmn | 0:ba15439f45dd | 44 | |
charlesmn | 0:ba15439f45dd | 45 | // set the shutdown pins to be outputs ( they are inputs on power up) |
charlesmn | 0:ba15439f45dd | 46 | stmpe1600_exp1->set_gpio_dir(GPIO_15,OUTPUT); |
charlesmn | 0:ba15439f45dd | 47 | stmpe1600_exp0->set_gpio_dir(GPIO_14,OUTPUT); |
charlesmn | 0:ba15439f45dd | 48 | stmpe1600_exp0->set_gpio_dir(GPIO_15,OUTPUT); |
charlesmn | 0:ba15439f45dd | 49 | |
charlesmn | 0:ba15439f45dd | 50 | // set the shutdown pins to low, this will reset the VL53l1s |
charlesmn | 0:ba15439f45dd | 51 | stmpe1600_exp1->clear_gpio(GPIO_15); |
charlesmn | 0:ba15439f45dd | 52 | stmpe1600_exp0->clear_gpio(GPIO_14); |
charlesmn | 0:ba15439f45dd | 53 | stmpe1600_exp0->clear_gpio(GPIO_15); |
charlesmn | 0:ba15439f45dd | 54 | |
charlesmn | 0:ba15439f45dd | 55 | // select the first VL53l1. It will have i2c address of 0x52. Set the i2c address to |
charlesmn | 0:ba15439f45dd | 56 | //NEW_SENSOR_CENTRE_ADDRESS |
charlesmn | 0:ba15439f45dd | 57 | stmpe1600_exp1->set_gpio(GPIO_15); |
charlesmn | 0:ba15439f45dd | 58 | printf("InitSensor \n"); |
charlesmn | 0:ba15439f45dd | 59 | status = sensor_centre->InitSensor(NEW_SENSOR_CENTRE_ADDRESS); |
charlesmn | 0:ba15439f45dd | 60 | if (status) { |
charlesmn | 0:ba15439f45dd | 61 | delete sensor_centre; |
charlesmn | 0:ba15439f45dd | 62 | delete xshutdown_centre; |
charlesmn | 0:ba15439f45dd | 63 | sensor_centre = NULL; |
charlesmn | 0:ba15439f45dd | 64 | xshutdown_centre = NULL; |
charlesmn | 0:ba15439f45dd | 65 | printf("Sensor centre not present\n\r"); |
charlesmn | 0:ba15439f45dd | 66 | } else { |
charlesmn | 0:ba15439f45dd | 67 | printf("Sensor centre present\n\r"); |
charlesmn | 0:ba15439f45dd | 68 | n_dev++; |
charlesmn | 0:ba15439f45dd | 69 | } |
charlesmn | 0:ba15439f45dd | 70 | |
charlesmn | 0:ba15439f45dd | 71 | // select the second VL53l1. It will have i2c address of 0x52. Set the i2c address to |
charlesmn | 0:ba15439f45dd | 72 | //NEW_SENSOR_LEFT_ADDRESS |
charlesmn | 0:ba15439f45dd | 73 | |
charlesmn | 0:ba15439f45dd | 74 | stmpe1600_exp0->set_gpio(GPIO_14); |
charlesmn | 0:ba15439f45dd | 75 | |
charlesmn | 0:ba15439f45dd | 76 | status = sensor_left->InitSensor(NEW_SENSOR_LEFT_ADDRESS); |
charlesmn | 0:ba15439f45dd | 77 | if (status) { |
charlesmn | 0:ba15439f45dd | 78 | delete sensor_left; |
charlesmn | 0:ba15439f45dd | 79 | delete xshutdown_left; |
charlesmn | 0:ba15439f45dd | 80 | sensor_left = NULL; |
charlesmn | 0:ba15439f45dd | 81 | xshutdown_left = NULL; |
charlesmn | 0:ba15439f45dd | 82 | printf("Sensor left not present\n\r"); |
charlesmn | 0:ba15439f45dd | 83 | } else { |
charlesmn | 0:ba15439f45dd | 84 | printf("Sensor left present\n\r"); |
charlesmn | 0:ba15439f45dd | 85 | n_dev++; |
charlesmn | 0:ba15439f45dd | 86 | } |
charlesmn | 0:ba15439f45dd | 87 | |
charlesmn | 0:ba15439f45dd | 88 | // select the 3rd VL53l1. It will have i2c address of 0x52. Set the i2c address to |
charlesmn | 0:ba15439f45dd | 89 | //NEW_SENSOR_RIGHT_ADDRESS |
charlesmn | 0:ba15439f45dd | 90 | stmpe1600_exp0->set_gpio(GPIO_15); |
charlesmn | 0:ba15439f45dd | 91 | status = sensor_right->InitSensor(NEW_SENSOR_RIGHT_ADDRESS); |
charlesmn | 0:ba15439f45dd | 92 | if (status) { |
charlesmn | 0:ba15439f45dd | 93 | delete sensor_right; |
charlesmn | 0:ba15439f45dd | 94 | delete xshutdown_right; |
charlesmn | 0:ba15439f45dd | 95 | sensor_right = NULL; |
charlesmn | 0:ba15439f45dd | 96 | xshutdown_right = NULL; |
charlesmn | 0:ba15439f45dd | 97 | printf("Sensor right not present\n\r"); |
charlesmn | 0:ba15439f45dd | 98 | } else { |
charlesmn | 0:ba15439f45dd | 99 | printf("Sensor right present\n\r"); |
charlesmn | 0:ba15439f45dd | 100 | n_dev++; |
charlesmn | 0:ba15439f45dd | 101 | } |
charlesmn | 0:ba15439f45dd | 102 | |
charlesmn | 0:ba15439f45dd | 103 | return 0; |
charlesmn | 0:ba15439f45dd | 104 | if (n_dev == 0) { |
charlesmn | 0:ba15439f45dd | 105 | return 1; |
charlesmn | 0:ba15439f45dd | 106 | } else { |
charlesmn | 0:ba15439f45dd | 107 | return 0; |
charlesmn | 0:ba15439f45dd | 108 | } |
charlesmn | 0:ba15439f45dd | 109 | } |
charlesmn | 0:ba15439f45dd | 110 |