Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"IDF_PATH": "/opt/esp/idf",
"PATH": "/opt/esp/idf/tools:${env:PATH}"
}
}
}
3 changes: 1 addition & 2 deletions solaris-v1/components/pressure_sensor_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
idf_component_register(
SRCS "bmp390.c"
INCLUDE_DIRS "include"
REQUIRES general esp_driver_spi spp_port_wrapper spp_wrapper
PRIV_REQUIRES esp_driver_gpio
REQUIRES general spp_port_wrapper spp_wrapper
)
26 changes: 12 additions & 14 deletions solaris-v1/components/pressure_sensor_driver/bmp390.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "bmp390.h"
#include <string.h>
#include <math.h>
#include "core/returntypes.h"
#include "spi.h"
#include "task.h"
#include "osal/task.h"
#include "spp_log.h"

static const char* TAG = "BMP390";
Expand Down Expand Up @@ -61,8 +60,6 @@ void BmpInit(void* p_data)

SPP_HAL_GPIO_ConfigInterrupt(p_bmp->int_pin, p_bmp->int_intr_type, p_bmp->int_pull);
SPP_HAL_GPIO_RegisterISR(p_bmp->int_pin, (void*)&p_bmp->isr_ctx);

SPP_OSAL_TaskDelete(NULL);
}


Expand All @@ -81,8 +78,8 @@ retval_t bmp390_soft_reset(void *p_spi)
(spp_uint8_t)BMP390_SOFT_RESET_CMD
};

retval_t ret = SPP_HAL_SPI_Transmit(p_spi, buf, (spp_uint8_t)sizeof(buf));
SPP_OSAL_TaskDelay(pdMS_TO_TICKS(100));
retval_t ret = SPP_HAL_SPI_Transmit(p_spi, buf, sizeof(buf));
SPP_OSAL_TaskDelay(100);

return ret;
}
Expand All @@ -102,7 +99,7 @@ retval_t bmp390_enable_spi_mode(void *p_spi)
};

retval_t ret = SPP_HAL_SPI_Transmit(p_spi, buf, (spp_uint8_t)sizeof(buf));
SPP_OSAL_TaskDelay(pdMS_TO_TICKS(100));
SPP_OSAL_TaskDelay(100);

return ret;
}
Expand All @@ -115,11 +112,11 @@ retval_t bmp390_enable_spi_mode(void *p_spi)
*/
retval_t bmp390_config_check(void *p_spi)
{
spp_uint8_t buf[6] =
spp_uint8_t buf[9] =
{
(spp_uint8_t)(READ_OP | BMP390_IF_CONF_REG), EMPTY_MESSAGE,
(spp_uint8_t)(READ_OP | BMP390_SOFT_RESET_REG), EMPTY_MESSAGE,
(spp_uint8_t)(READ_OP | BMP390_CHIP_ID_REG), EMPTY_MESSAGE
(spp_uint8_t)(READ_OP | BMP390_IF_CONF_REG), EMPTY_MESSAGE, EMPTY_MESSAGE,
(spp_uint8_t)(READ_OP | BMP390_SOFT_RESET_REG), EMPTY_MESSAGE, EMPTY_MESSAGE,
(spp_uint8_t)(READ_OP | BMP390_CHIP_ID_REG), EMPTY_MESSAGE, EMPTY_MESSAGE
};

retval_t ret;
Expand All @@ -129,9 +126,10 @@ retval_t bmp390_config_check(void *p_spi)
return ret;
}

SPP_LOGI(TAG, "ID: 0x%02X", buf[5]);
SPP_LOGI(TAG, "ID: 0x%02X", buf[8]);

if (buf[5] != 0x60) {

if (buf[8] != 0x60) {
SPP_LOGE(TAG, "BMP390 not detected! Expected ID: 0x%02X, Read ID: 0x%02X", 0x60, buf[5]);
return SPP_ERROR;
}
Expand All @@ -153,7 +151,7 @@ retval_t bmp390_aux_config(void *p_spi)
if (ret != SPP_OK) return ret;

ret = bmp390_enable_spi_mode(p_spi);
if (ret != SPP_OK) return ret;
if (ret != SPP_OK) return ret;

ret = bmp390_config_check(p_spi);
if (ret != SPP_OK) return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "returntypes.h"
#include "general.h"
#include "osal/eventgroups.h"
#include "osal/task.h"
#include "hal/gpio/gpio.h"

///--------------------Read/Write Operators------------------------------
Expand Down
2 changes: 1 addition & 1 deletion solaris-v1/external/spp-ports
84 changes: 50 additions & 34 deletions solaris-v1/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,75 @@

#include <unistd.h>

static const char* TAG = "MAIN";

static bmp_data_t s_bmp;
static icm_data_t s_icm;

static void bmp_init_task(void *arg)
{
BmpInit(arg);
}
// static void bmp_init_task(void *arg)
// {
// BmpInit(arg);
// SPP_OSAL_TaskDelete(NULL);
// }

void app_main(void)
{
Core_Init();
retval_t ret;

// sleep(5);
SPP_LOGI(TAG, "Starting application...");
// SPP_OSAL_TaskDelay(5000);

// Step 1: Initialize SPI Bus
ret = SPP_HAL_SPI_BusInit();
if (ret != SPP_OK) while (1) {}
if (ret != SPP_OK){
SPP_LOGE(TAG, "Failed to initialize SPI bus");
}

// Step 2: Initialize ICM SPI Device
void *p_spi_icm = SPP_HAL_SPI_GetHandler();
ret = SPP_HAL_SPI_DeviceInit(p_spi_icm);
if (ret != SPP_OK) while (1) {}
if (ret != SPP_OK){
SPP_LOGE(TAG, "Failed to initialize ICM SPI device");
}

// Step 3: Initialize BMP SPI Device
void *p_spi_bmp = SPP_HAL_SPI_GetHandler();
ret = SPP_HAL_SPI_DeviceInit(p_spi_bmp);
if (ret != SPP_OK) while (1) {}
if (ret != SPP_OK){
SPP_LOGE(TAG, "Failed to initialize BMP SPI device");
}

// Step 4: Assign SPI Handler to BMP Structure
s_bmp.p_handler_spi = p_spi_bmp;

// Step 5: Configure BMP390 Auxiliary Settings
ret = bmp390_aux_config(p_spi_bmp);
if (ret != SPP_OK) while (1) {}
if (ret != SPP_OK) {
SPP_LOGE(TAG, "Failed to configure BMP390");
}

// Step 6: Prepare BMP390 Measurement
ret = bmp390_prepare_measure(p_spi_bmp);
if (ret != SPP_OK) while (1) {}
if (ret != SPP_OK) {
SPP_LOGE(TAG, "Failed to prepare BMP390 measurement");
}

// Step 7: Configure Control Register
{
spp_uint8_t buf[2] = { (spp_uint8_t)0x19u, (spp_uint8_t)(1u << 6) };
ret = SPP_HAL_SPI_Transmit(p_spi_bmp, buf, (spp_uint8_t)sizeof(buf));
if (ret != SPP_OK) while (1) {}
if (ret != SPP_OK) {
SPP_LOGE(TAG, "Failed to configure BMP390 control register");
}
}

// Step 8: Configure Interrupt Pin Settings
s_bmp.int_pin = (spp_uint32_t)INT_GPIO;
s_bmp.int_intr_type = (spp_uint32_t)GPIO_INTR_POSEDGE;
s_bmp.int_pull = 0;
// s_bmp.int_pin = (spp_uint32_t)INT_GPIO;
// s_bmp.int_intr_type = (spp_uint32_t)GPIO_INTR_POSEDGE;
// s_bmp.int_pull = 0;

// Step 9: Create BMP Initialization Task
xTaskCreate(bmp_init_task, "bmp_init", BMP_INIT_TASK_STACK_SIZE, &s_bmp, BMP_INIT_PRIO, NULL);
// xTaskCreate(bmp_init_task, "bmp_init", BMP_INIT_TASK_STACK_SIZE, &s_bmp, BMP_INIT_PRIO, NULL);


SPP_LOGI("APP", "Application starting...");
Expand All @@ -78,30 +94,30 @@ void app_main(void)
SPP_LOGD("TEST", "Debug ejemplo");
SPP_LOGV("TEST", "Verbose ejemplo");

Core_Init();
// Core_Init();

// Getting one SPP packet
spp_packet_t *p_packet_1 = SPP_DATABANK_getPacket();
p_packet_1->primary_header.version = 0xFA;
ret = SPP_DATABANK_returnPacket(p_packet_1);
// // Getting one SPP packet
// spp_packet_t *p_packet_1 = SPP_DATABANK_getPacket();
// p_packet_1->primary_header.version = 0xFA;
// ret = SPP_DATABANK_returnPacket(p_packet_1);

// Following the logic this will have to return the same address of packet as p_packet_1
spp_packet_t *p_packet_2 = SPP_DATABANK_getPacket();
// We can check the new data is being written
p_packet_2->primary_header.version = 0xFE;
ret = SPP_DATABANK_returnPacket(p_packet_2);
// // Following the logic this will have to return the same address of packet as p_packet_1
// spp_packet_t *p_packet_2 = SPP_DATABANK_getPacket();
// // We can check the new data is being written
// p_packet_2->primary_header.version = 0xFE;
// ret = SPP_DATABANK_returnPacket(p_packet_2);



vTaskDelay(pdMS_TO_TICKS(100));
// vTaskDelay(pdMS_TO_TICKS(100));

// Step 10: Read Altitude Measurement
float altitude = 0.0f;
ret = bmp390_get_altitude(p_spi_bmp, &s_bmp, &altitude);
if (ret != SPP_OK) {
while (1) {}
}
// // Step 10: Read Altitude Measurement
// float altitude = 0.0f;
// ret = bmp390_get_altitude(p_spi_bmp, &s_bmp, &altitude);
// if (ret != SPP_OK) {
// while (1) {}
// }

vTaskDelay(pdMS_TO_TICKS(50));
// vTaskDelay(pdMS_TO_TICKS(50));

}