Restructure of expansion board lib, moving files & folders.

Dependencies:   VL53L3CX

Dependents:   J_53L3_shield_single_polling_Mb515

Committer:
johnAlexander
Date:
Fri Oct 30 15:31:30 2020 +0000
Revision:
3:4ed68a07058d
Restructure

Who changed what in which revision?

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