diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 94eeaba..55b3b56 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -12,7 +12,7 @@ "name": "Linux", "intelliSenseMode": "linux-gcc-arm", "includePath": [ - "${myDefaultIncludePath}", + "${myDefaultIncludePath}" ], "compilerPath": "/usr/bin/arm-none-eabi-gcc", "cStandard": "c11", diff --git a/CMakeLists.txt b/CMakeLists.txt index db89978..a880802 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,9 @@ add_library(Mod_VL53L8 Platform/platform.c ) +target_include_directories(Mod_VL53L8 PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/VL53L8CX_ULD_API/inc/ +) target_link_libraries(Mod_VL53L8 pico_stdlib diff --git a/Platform/platform.c b/Platform/platform.c index 69e0e4d..e95b65c 100644 --- a/Platform/platform.c +++ b/Platform/platform.c @@ -16,15 +16,32 @@ #include "hardware/i2c.h" #include + +// Configuration of the I2C communication +#define I2C_DEVICE i2c1 +#define I2C1_SDA_PIN 14 +#define I2C1_SCL_PIN 15 + #define I2C_SUCCESS 0 #define I2C_FAILED 1 #define I2C_BUFFER_EXCEEDED 2 -#define I2C_DEVICE i2c1 + #define MAX_I2C_BUFFER 0x8100 +void platform_i2c_init(void){ + i2c_init(I2C_DEVICE, 400 * 1000); + + printf("Initialisation des broches\n"); + printf("%d et %d en I2C\n", I2C1_SDA_PIN, I2C1_SCL_PIN); + gpio_set_function(I2C1_SDA_PIN, GPIO_FUNC_I2C); + gpio_set_function(I2C1_SCL_PIN, GPIO_FUNC_I2C); + gpio_pull_up(I2C1_SDA_PIN); + gpio_pull_up(I2C1_SCL_PIN); +} + /// @brief Blocking function allowing to write a register on an I2C device /// @param address_7_bits /// @param index : register to write diff --git a/Platform/platform.h b/Platform/platform.h index ee06db7..ecce7fd 100644 --- a/Platform/platform.h +++ b/Platform/platform.h @@ -163,4 +163,6 @@ uint8_t WaitMs( VL53L8CX_Platform *p_platform, uint32_t TimeMs); +void platform_i2c_init(void); + #endif // _PLATFORM_H_ \ No newline at end of file diff --git a/Readme.md b/Readme.md index 298ec7f..0e4f2c1 100644 --- a/Readme.md +++ b/Readme.md @@ -1,7 +1,12 @@ -Submodule Communication pour le RP2040 +Submodule VL53L8CX pour le RP2040 ===================================== -Ceci est un submodule git pour intégrer facilement notre protocole de communication à un projet. +Ceci est un submodule git pour intégrer facilement un capteur VL53L8CX à un projet. + +Le code présent ici se base sur [Ultra lite driver (ULD) API for the VL53L8CX](https://www.st.com/en/embedded-software/stsw-img040.html) + +La documentation est disponible ici : https://www.st.com/content/st_com/en/technical-documents/UM3109.html + On crée ce Submodule en se servant de la documentation disponible ici : https://git-scm.com/book/en/v2/Git-Tools-Submodules Utilisation @@ -28,22 +33,44 @@ Dans le fichier CMakeLists.txt, ajouter le dossier du sub module: Intégration au code source -------------------------- +Dans le code du module, ouvrez le fichier Platform/platform.c, adaptez les macro de configuration de l'i2c + #define I2C_DEVICE i2c1 + #define I2C1_SDA_PIN 14 + #define I2C1_SCL_PIN 15 -Ajout du fichier d'include : +Dans votre code, ajout du fichier d'include : - #include "RP2040_Servomoteurs/Servomoteur.h" + #include "Mod_VL53L8CX/VL53L8_2024.h" Initialisation du module : struct VL53L8CX_Configuration Dev; VL53L8_init(&Dev); -Lecture des distances +Lecture des distances : struct VL53L8CX_ResultsData Results; VL53L8_lecture(&Dev, &Results); +Affichage des distances : + + for (int i=0; i< 8; i++){ + for (int j=0; j< 8; j++){ + printf("%3d ",Results.distance_mm[8*i+j]); + } + printf("\n"); + } + +Configuration applicative +------------------------- + +Un système de masque permet de considéré que le capteur ne voit "rien" s'il la distance est supérieur à une certaine valeur. +Cette valeur se configure dans la variable ``masque` présente dans `VL53L8_2024.c`. + + + + Cas où vous clonez un projet contenant des submodules ----------------------------------------------------- diff --git a/VL53L8CX_ULD_API/src/vl53l8cx_api.c b/VL53L8CX_ULD_API/src/vl53l8cx_api.c index 88347b6..eac82f7 100644 --- a/VL53L8CX_ULD_API/src/vl53l8cx_api.c +++ b/VL53L8CX_ULD_API/src/vl53l8cx_api.c @@ -12,6 +12,7 @@ #include #include +#include #include "vl53l8cx_api.h" #include "vl53l8cx_buffers.h" diff --git a/VL53L8_2024.c b/VL53L8_2024.c index 952f554..2c95944 100644 --- a/VL53L8_2024.c +++ b/VL53L8_2024.c @@ -8,9 +8,10 @@ int masque[64]={ 3000,3000,3000,3000,3000,3000,3000,3000, 3000,3000,3000,3000,3000,3000,3000,3000, 3000,3000,3000,3000,3000,3000,3000,3000, - 350,350,350,350,350,350,350,350, - 281,286,299,306,310,314,302,286, - 195,200,202,206,213,200,200,202 + 3000,3000,3000,3000,3000,3000,3000,3000, + 3000,3000,3000,3000,3000,3000,3000,3000, + 3000,3000,3000,3000,3000,3000,3000,3000, + }; float old_min_distance; @@ -18,6 +19,9 @@ float old_min_distance; void VL53L8_init(VL53L8CX_Configuration * Dev){ uint8_t status, isAlive, isReady, i; + // Initialise i2c + platform_i2c_init(); + /*********************************/ /* Customer platform */ @@ -106,7 +110,7 @@ void VL53L8_lecture(VL53L8CX_Configuration * Dev, VL53L8CX_ResultsData * Results error = vl53l8cx_get_ranging_data(Dev, Results); if(error){ printf("Error VL53L8\n"); - VL53L8_init(Dev); + //VL53L8_init(Dev); }