Fixed DMA and INT bugs
- Fixed indexed task notifications for INT and DMAf for both sensors - Fixed the INT debugger startup freeze (added != NULL check in callbacks) - Fixed DMA notifications not being read properly/too early - Changed IMU INT configure/enable function as one - Added proper DMA checking in IMU calibration
This commit is contained in:
1 parent
5daac77a37
commit
1409bad40b
67 files changed
+52921
-51367
No files matched your search
+118
-98
@@ -10,65 +10,60 @@
|
||||
//extern osThreadId_t defaultTaskHandle;
|
||||
//TaskHandle_t xStartDefaultTask = NULL;
|
||||
//extern osThreadId_t defaultTaskHandle
|
||||
osThreadId_t xIMU_Task = NULL;
|
||||
osThreadId_t xMagn_Task = NULL;
|
||||
volatile osThreadId_t xIMU_Task = NULL;
|
||||
volatile osThreadId_t xMagn_Task = NULL;
|
||||
//osThreadId_t xData_Task = NULL;
|
||||
|
||||
|
||||
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) {
|
||||
if (hspi->Instance == SPI1) {
|
||||
if (hspi->Instance == SPI1 && xIMU_Task != NULL) {
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_SET);
|
||||
|
||||
// notify the task that the data is ready
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
vTaskNotifyGiveFromISR(xIMU_Task, &xHigherPriorityTaskWoken);
|
||||
vTaskNotifyGiveIndexedFromISR(xIMU_Task, ICM_NOTIFY_DMA, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *I2C_address) {
|
||||
// printf("HAL_I2C_MemRxCpltCallback");
|
||||
if (I2C_address->Instance == I2C1) {
|
||||
if (I2C_address->Instance == I2C1 && xMagn_Task != NULL) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
vTaskNotifyGiveFromISR(xMagn_Task, &xHigherPriorityTaskWoken);
|
||||
// vTaskNotifyGiveFromISR(xMagn_Task, &xHigherPriorityTaskWoken);
|
||||
vTaskNotifyGiveIndexedFromISR(xMagn_Task, BMM_NOTIFY_DMA, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *I2C_address) {
|
||||
// printf("HAL_I2C_MemTxCpltCallback");
|
||||
if (I2C_address->Instance == I2C1) {
|
||||
if (I2C_address->Instance == I2C1 && xMagn_Task != NULL) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
vTaskNotifyGiveFromISR(xMagn_Task, &xHigherPriorityTaskWoken);
|
||||
// vTaskNotifyGiveFromISR(xMagn_Task, &xHigherPriorityTaskWoken);
|
||||
vTaskNotifyGiveIndexedFromISR(xMagn_Task, BMM_NOTIFY_DMA, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c) {
|
||||
if (hi2c->Instance == I2C1) {
|
||||
if (hi2c->Instance == I2C1 && xMagn_Task != NULL) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
printf("ErrorCallback: %ld\n", HAL_I2C_GetError(hi2c));
|
||||
vTaskNotifyGiveFromISR(xMagn_Task, &xHigherPriorityTaskWoken);
|
||||
// vTaskNotifyGiveFromISR(xMagn_Task, &xHigherPriorityTaskWoken);
|
||||
vTaskNotifyGiveIndexedFromISR(xMagn_Task, BMM_NOTIFY_DMA, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
|
||||
// was macht das?
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
if (GPIO_Pin == GPIO_IMU_INT_Pin) {
|
||||
vTaskNotifyGiveFromISR(xIMU_Task, &xHigherPriorityTaskWoken);
|
||||
if (GPIO_Pin == GPIO_IMU_INT_Pin && xIMU_Task != NULL) {
|
||||
// vTaskNotifyGiveFromISR(xIMU_Task, &xHigherPriorityTaskWoken);
|
||||
vTaskNotifyGiveIndexedFromISR(xIMU_Task, ICM_NOTIFY_INT_DRDY, &xHigherPriorityTaskWoken);
|
||||
// printf("Triggered ICM45686 EXTI\n");
|
||||
}
|
||||
|
||||
if (GPIO_Pin == GPIO_MAGN_INT_Pin) {
|
||||
vTaskNotifyGiveFromISR(xMagn_Task, &xHigherPriorityTaskWoken);
|
||||
// printf("Triggered BMM350 EXTI\n");
|
||||
if (GPIO_Pin == GPIO_MAGN_INT_Pin && xMagn_Task != NULL) {
|
||||
// vTaskNotifyGiveFromISR(xMagn_Task, &xHigherPriorityTaskWoken);
|
||||
vTaskNotifyGiveIndexedFromISR(xMagn_Task, BMM_NOTIFY_INT_DRDY, &xHigherPriorityTaskWoken);
|
||||
}
|
||||
// was macht das?
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
|
||||
}
|
||||
|
||||
// ICM 45686
|
||||
@@ -93,33 +88,10 @@ HAL_StatusTypeDef write_icm (ICM45686_HandleTypeDef *imu, uint8_t tx[], uint16_t
|
||||
}
|
||||
|
||||
void init_icm(ICM45686_HandleTypeDef *imu) {
|
||||
// TODO: Add settings as enum to choose from
|
||||
// FIFO
|
||||
// Interrupt
|
||||
/* Interrupt functionality is configured via the Interrupt Configuration register. Items that are configurable include the
|
||||
interrupt pins configuration, the interrupt latching and clearing method, and triggers for the interrupt. Items that
|
||||
can trigger an interrupt are (1) Clock generator locked to new reference oscillator (used when switching clock
|
||||
sources); (2) new data is available to be read (from the FIFO and Data registers); (3) accelerometer event
|
||||
interrupts; (4) FIFO watermark; (5) FIFO overflow. The interrupt status can be read from the Interrupt Status
|
||||
register.
|
||||
- Configure interrupt pin on icm
|
||||
- configure interrupt pin on bmm
|
||||
- -> push/pull or open drain, latch, polarity
|
||||
- everything stays as is only that a interrupt callback gets added, that when called wakes up the
|
||||
corresponding task for the sensor
|
||||
*/
|
||||
// APEX???
|
||||
// EDMP???
|
||||
|
||||
uint8_t tx[2], rx[2];
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
printf("Initializing ICM45686\n");
|
||||
// WHO AM
|
||||
// // WHO AM
|
||||
tx[0] = ICM45686_WHO_AM_I | 0x80;
|
||||
// HAL_GPIO_WritePin(imu->GPIO_Port, imu->GPIO_Pin, GPIO_PIN_RESET);
|
||||
// status = HAL_SPI_TransmitReceive(imu->hspi, tx, rx, sizeof(tx), 50);
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_SET);
|
||||
status = read_icm(imu, tx, rx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Error in reading WHO AM I:%d\n", status);
|
||||
@@ -127,12 +99,9 @@ void init_icm(ICM45686_HandleTypeDef *imu) {
|
||||
printf("WHO AM I (0xE9): 0x%02X \n", rx[1]);
|
||||
}
|
||||
|
||||
// acc
|
||||
// acc config
|
||||
tx[0] = ICM45686_ACCEL_CONFIG0;
|
||||
tx[1] = imu->acc_fs | imu->odr;
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_RESET);
|
||||
// status = HAL_SPI_Transmit(imu->hspi, tx, sizeof(tx), 50);
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_SET);
|
||||
status = write_icm(imu, tx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Error in setting ACCEL_CONFIG0:%d\n", status);
|
||||
@@ -142,9 +111,6 @@ void init_icm(ICM45686_HandleTypeDef *imu) {
|
||||
|
||||
tx[0] = ICM45686_ACCEL_CONFIG0 | 0x80;
|
||||
tx[1] = 0x00;
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_RESET);
|
||||
// status = HAL_SPI_TransmitReceive(imu->hspi, tx, rx, sizeof(tx), 50);
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_SET);
|
||||
status = read_icm(imu, tx, rx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Error reading ACCEL_CONFIG0:%d\n", status);
|
||||
@@ -152,12 +118,9 @@ void init_icm(ICM45686_HandleTypeDef *imu) {
|
||||
printf("ACCEL_CONFIG0 read: 0x%02X \n", rx[1]);
|
||||
}
|
||||
|
||||
// gyro
|
||||
// gyro config
|
||||
tx[0] = ICM45686_GYRO_CONFIG0;
|
||||
tx[1] = imu->gyro_fs | imu->odr;
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_RESET);
|
||||
// status = HAL_SPI_Transmit(imu->hspi, tx, sizeof(tx), 50);
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_SET);
|
||||
status = write_icm(imu, tx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Error in setting GYRO_CONFIG0:%d\n", status);
|
||||
@@ -167,9 +130,6 @@ void init_icm(ICM45686_HandleTypeDef *imu) {
|
||||
|
||||
tx[0] = ICM45686_GYRO_CONFIG0 | 0x80;
|
||||
tx[1] = 0x00;
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_RESET);
|
||||
// status = HAL_SPI_TransmitReceive(imu->hspi, tx, rx, sizeof(tx), 50);
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_SET);
|
||||
status = read_icm(imu, tx, rx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Error reading GYRO_CONFIG0:%d\n", status);
|
||||
@@ -180,9 +140,6 @@ void init_icm(ICM45686_HandleTypeDef *imu) {
|
||||
// power settings
|
||||
tx[0] = ICM45686_PWR_MGMT0;
|
||||
tx[1] = 0x0F; //0x10 | 0x03;
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_RESET);
|
||||
// status = HAL_SPI_Transmit(imu->hspi, tx, sizeof(tx), 50);
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_SET);
|
||||
status = write_icm(imu, tx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Error in setting PWR_MGMT0:%d\n", status);
|
||||
@@ -192,17 +149,12 @@ void init_icm(ICM45686_HandleTypeDef *imu) {
|
||||
|
||||
tx[0] = ICM45686_PWR_MGMT0 | 0x80;
|
||||
tx[1] = 0x00;
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_RESET);
|
||||
// status = HAL_SPI_TransmitReceive(imu->hspi, tx, rx, sizeof(tx), 50);
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_SPI1_IMU_CS_Pin, GPIO_PIN_SET);
|
||||
status = read_icm(imu, tx, rx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Error reading PWR_MGMT0:%d\n", status);
|
||||
} else {
|
||||
printf("PWR_MGMT0 read: 0x%02X \n", rx[1]);
|
||||
}
|
||||
|
||||
osDelay(250);
|
||||
}
|
||||
|
||||
void calibrate_icm(ICM45686_HandleTypeDef *imu, int samples) {
|
||||
@@ -213,10 +165,17 @@ void calibrate_icm(ICM45686_HandleTypeDef *imu, int samples) {
|
||||
tx[0] = 0x00 | 0x80;
|
||||
|
||||
for (int i = 1; i <= samples; i++) {
|
||||
status = read_icm_dma(imu, tx, raw_data, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Calibration read ICM failed: %d\n", status);
|
||||
}
|
||||
// status = read_icm_dma(imu, tx, raw_data, sizeof(tx));
|
||||
// osDelay(1);
|
||||
// if (status != HAL_OK) {
|
||||
// printf("Calibration read ICM failed: %d\n", status);
|
||||
// }
|
||||
ulTaskNotifyTakeIndexed(ICM_NOTIFY_INT_DRDY, pdTRUE, portMAX_DELAY);
|
||||
status = read_icm_dma(imu, tx, raw_data, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Calibration read ICM failed: %d\n", status);
|
||||
}
|
||||
if (ulTaskNotifyTakeIndexed(ICM_NOTIFY_DMA, pdTRUE, pdMS_TO_TICKS(10)) > 0) {
|
||||
sensor_data[0] += (int16_t)(raw_data[1] << 8 | raw_data[2]); // a_x
|
||||
sensor_data[1] += (int16_t)(raw_data[3] << 8 | raw_data[4]); // a_y
|
||||
sensor_data[2] += (int16_t)(raw_data[5] << 8 | raw_data[6]); // a_z
|
||||
@@ -224,6 +183,7 @@ void calibrate_icm(ICM45686_HandleTypeDef *imu, int samples) {
|
||||
sensor_data[4] += (int16_t)(raw_data[9] << 8 | raw_data[10]); // g_y
|
||||
sensor_data[5] += (int16_t)(raw_data[11] << 8 | raw_data[12]); // g_z
|
||||
sensor_data[6] += (int16_t)(raw_data[13] << 8 | raw_data[14]); // t
|
||||
}
|
||||
}
|
||||
|
||||
imu->imu_bias[0] = (float)sensor_data[0] / (float)samples;
|
||||
@@ -239,20 +199,38 @@ void calibrate_icm(ICM45686_HandleTypeDef *imu, int samples) {
|
||||
|
||||
imu->calibated = true;
|
||||
|
||||
printf("Calibration finished of ICM45686\n");
|
||||
printf("a_x: %.2f a_y: %.2f a_z: %.2f g_x: %.2f g_y: %.2f g_z: %.2f t: %.2f\n",
|
||||
printf("ICM calibration bias: a_x: %.2f a_y: %.2f a_z: %.2f g_x: %.2f g_y: %.2f g_z: %.2f t: %.2f\n",
|
||||
imu->imu_bias[0], imu->imu_bias[1], imu->imu_bias[2],
|
||||
imu->imu_bias[3], imu->imu_bias[4], imu->imu_bias[5],
|
||||
imu->imu_bias[6]);
|
||||
|
||||
}
|
||||
|
||||
void enable_interrupt_icm(ICM45686_HandleTypeDef *imu) {
|
||||
uint8_t tx[2], rx[2] = {0x00, 0x00};
|
||||
tx[0] = ICM45686_INT1_CONFIG0;
|
||||
tx[1] = 0x04;
|
||||
printf("Enabling IMU INT pin\n");
|
||||
//void enable_interrupt_icm(ICM45686_HandleTypeDef *imu) {
|
||||
// uint8_t tx[2], rx[2] = {0x00, 0x00};
|
||||
//
|
||||
// tx[0] = ICM45686_INT1_CONFIG0;
|
||||
// tx[1] = 0x04;
|
||||
// HAL_StatusTypeDef status = write_icm(imu, tx, sizeof(tx));
|
||||
// if (status != HAL_OK) {
|
||||
// printf("Enabling of IMU INT failed: %d\n", status);
|
||||
// }
|
||||
//
|
||||
// tx[0] = ICM45686_INT1_CONFIG0 | 0x80;
|
||||
// tx[1] = 0x00;
|
||||
// status = read_icm(imu, tx, rx, sizeof(tx));
|
||||
// if (status != HAL_OK) {
|
||||
// printf("Reading IMU INT1_CONFIG0 failed: %d\n", status);
|
||||
// } else {
|
||||
// printf("INT1_CONFIG0 read: 0x%02X\n", rx[1]);
|
||||
// }
|
||||
//}
|
||||
|
||||
void configure_and_enable_int_icm (ICM45686_HandleTypeDef *imu) {
|
||||
uint8_t tx[2], rx[2] = {0x00, 0x00};
|
||||
|
||||
// turn off int
|
||||
tx[0] = ICM45686_INT1_CONFIG0;
|
||||
tx[1] = 0x00;
|
||||
HAL_StatusTypeDef status = write_icm(imu, tx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Enabling of IMU INT failed: %d\n", status);
|
||||
@@ -262,19 +240,15 @@ void enable_interrupt_icm(ICM45686_HandleTypeDef *imu) {
|
||||
tx[1] = 0x00;
|
||||
status = read_icm(imu, tx, rx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Reading IMU INT configuration0 failed: %d\n", status);
|
||||
printf("Reading IMU INT1_CONFIG0 failed: %d\n", status);
|
||||
} else {
|
||||
printf("INT1_CONFIG0 read: 0x%02X\n", rx[1]);
|
||||
}
|
||||
}
|
||||
|
||||
void configure_interrupt_icm (ICM45686_HandleTypeDef *imu) {
|
||||
uint8_t tx[2], rx[2] = {0x00, 0x00};
|
||||
|
||||
// configure int1 to push-pull, pulse, active high
|
||||
tx[0] = ICM45686_INT1_CONFIG2;
|
||||
tx[1] = 0x01;
|
||||
printf("Configuring IMU INT\n");
|
||||
HAL_StatusTypeDef status = write_icm(imu, tx, sizeof(tx));
|
||||
status = write_icm(imu, tx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Configuration of IMU INT failed: %d\n", status);
|
||||
}
|
||||
@@ -283,10 +257,27 @@ void configure_interrupt_icm (ICM45686_HandleTypeDef *imu) {
|
||||
tx[1] = 0x00;
|
||||
status = read_icm(imu, tx, rx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Reading IMU INT configuration2 failed: %d\n", status);
|
||||
printf("Reading IMU INT1_CONFIG2 failed: %d\n", status);
|
||||
} else {
|
||||
printf("INT1_CONFIG2 read: 0x%02X\n", rx[1]);
|
||||
}
|
||||
|
||||
// enable int
|
||||
tx[0] = ICM45686_INT1_CONFIG0;
|
||||
tx[1] = 0x04;
|
||||
status = write_icm(imu, tx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Enabling of IMU INT failed: %d\n", status);
|
||||
}
|
||||
|
||||
tx[0] = ICM45686_INT1_CONFIG0 | 0x80;
|
||||
tx[1] = 0x00;
|
||||
status = read_icm(imu, tx, rx, sizeof(tx));
|
||||
if (status != HAL_OK) {
|
||||
printf("Reading IMU INT1_CONFIG0 failed: %d\n", status);
|
||||
} else {
|
||||
printf("INT1_CONFIG0 read: 0x%02X\n", rx[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// BMM350
|
||||
@@ -309,7 +300,9 @@ BMM350_INTF_RET_TYPE bmm350_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32
|
||||
// Device address is left-shifted by 1 for STM32 HAL
|
||||
// if (HAL_I2C_Mem_Read(&hi2c1, device_addr << 1, reg_addr, I2C_MEMADD_SIZE_8BIT, reg_data, length, HAL_I2C_TIMEOUT ) == HAL_OK) {
|
||||
if (HAL_I2C_Mem_Read_DMA(&hi2c1, device_addr << 1, reg_addr, I2C_MEMADD_SIZE_8BIT, reg_data, length) == HAL_OK) {
|
||||
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||
// if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||
if (ulTaskNotifyTakeIndexed(BMM_NOTIFY_DMA, pdTRUE, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||
// if (ulTaskNotifyTakeIndexed(pdTRUE, BMM_NOTIFY_DMA, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||
return BMM350_INTF_RET_SUCCESS; // 0
|
||||
}
|
||||
}
|
||||
@@ -317,6 +310,20 @@ BMM350_INTF_RET_TYPE bmm350_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32
|
||||
|
||||
}
|
||||
|
||||
//BMM350_INTF_RET_TYPE bmm350_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr) {
|
||||
// // Extract I2C device address from intf_ptr
|
||||
// uint8_t device_addr = *(uint8_t*)intf_ptr;
|
||||
//
|
||||
// // STM32 HAL: Write register address, then read data
|
||||
// // Device address is left-shifted by 1 for STM32 HAL
|
||||
// if (HAL_I2C_Mem_Read(&hi2c1, device_addr << 1, reg_addr, I2C_MEMADD_SIZE_8BIT, reg_data, length, HAL_I2C_TIMEOUT ) == HAL_OK)
|
||||
// {
|
||||
// return BMM350_INTF_RET_SUCCESS; // 0
|
||||
// }
|
||||
//
|
||||
// return -1; // Communication failure
|
||||
//}
|
||||
|
||||
BMM350_INTF_RET_TYPE bmm350_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr){
|
||||
uint8_t device_addr = *(uint8_t*)intf_ptr;
|
||||
// uint8_t rslt = HAL_I2C_Mem_Write_DMA(&hi2c1, device_addr << 1, reg_addr, I2C_MEMADD_SIZE_8BIT, (uint8_t*)reg_data, length);
|
||||
@@ -325,13 +332,26 @@ BMM350_INTF_RET_TYPE bmm350_i2c_write(uint8_t reg_addr, const uint8_t *reg_data,
|
||||
if (HAL_I2C_Mem_Write_DMA(&hi2c1, device_addr << 1, reg_addr, I2C_MEMADD_SIZE_8BIT, (uint8_t*)reg_data, length) == HAL_OK) {
|
||||
// if (HAL_I2C_Mem_Write(&hi2c1, device_addr << 1, reg_addr, I2C_MEMADD_SIZE_8BIT, (uint8_t*)reg_data, length, HAL_I2C_TIMEOUT ) == HAL_OK) {
|
||||
// if (rslt == HAL_OK) {
|
||||
if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||
// if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||
if (ulTaskNotifyTakeIndexed(BMM_NOTIFY_DMA, pdTRUE, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||
// if (ulTaskNotifyTakeIndexed(pdTRUE, BMM_NOTIFY_DMA, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||
return BMM350_INTF_RET_SUCCESS; // 0
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//BMM350_INTF_RET_TYPE bmm350_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr){
|
||||
// uint8_t device_addr = *(uint8_t*)intf_ptr;
|
||||
//
|
||||
// // STM32 HAL: Write register address + data
|
||||
// if (HAL_I2C_Mem_Write(&hi2c1, device_addr << 1, reg_addr, I2C_MEMADD_SIZE_8BIT, (uint8_t*)reg_data, length, HAL_I2C_TIMEOUT ) == HAL_OK) {
|
||||
// return BMM350_INTF_RET_SUCCESS;
|
||||
// }
|
||||
//
|
||||
// return -1;
|
||||
//}
|
||||
|
||||
void bmm350_delay(uint32_t period_us, void *intf_ptr){
|
||||
(void)intf_ptr; // Unused
|
||||
|
||||
@@ -355,7 +375,7 @@ int8_t init_bmm(struct bmm350_dev *dev) {
|
||||
dev->delay_us = bmm350_delay;
|
||||
dev->intf_ptr = &dev_addr;
|
||||
|
||||
printf("Starting up and configuring BMM350\n");
|
||||
// printf("Starting up and configuring BMM350\n");
|
||||
|
||||
// Initialize BMM350 driver
|
||||
rslt = bmm350_init(dev);
|
||||
@@ -370,8 +390,8 @@ int8_t init_bmm(struct bmm350_dev *dev) {
|
||||
// Set powermode, odr and avg
|
||||
rslt = bmm350_set_powermode(BMM350_NORMAL_MODE, dev);
|
||||
printf("Powermode (%d): %d\n", BMM350_NORMAL_MODE, rslt);
|
||||
rslt = bmm350_set_odr_performance(BMM350_DATA_RATE_200HZ, BMM350_AVERAGING_2, dev);
|
||||
printf("ODR(%d) and AVG(%d): %d\n", BMM350_DATA_RATE_200HZ, BMM350_AVERAGING_2, rslt);
|
||||
rslt = bmm350_set_odr_performance(BMM350_DATA_RATE_400HZ, BMM350_NO_AVERAGING, dev);
|
||||
printf("ODR(%d) and AVG(%d): %d\n", BMM350_DATA_RATE_400HZ, BMM350_NO_AVERAGING, rslt);
|
||||
|
||||
// // configure interrupt
|
||||
// rslt = bmm350_enable_interrupt(BMM350_ENABLE_INTERRUPT, dev);
|
||||
@@ -385,9 +405,9 @@ int8_t init_bmm(struct bmm350_dev *dev) {
|
||||
int8_t bmm_configure_interrupt (struct bmm350_dev *dev) {
|
||||
int8_t rslt;
|
||||
rslt = bmm350_enable_interrupt(BMM350_ENABLE_INTERRUPT, dev);
|
||||
printf("Interrupt enable: %d\n", rslt);
|
||||
printf("Interrupt enable: %d \n", rslt);
|
||||
rslt = bmm350_configure_interrupt(BMM350_PULSED, BMM350_ACTIVE_HIGH, BMM350_INTR_PUSH_PULL, BMM350_MAP_TO_PIN, dev);
|
||||
printf("Configure interrupt: %d\n", rslt);
|
||||
printf("Configure interrupt: %d \n", rslt);
|
||||
|
||||
return BMM350_OK;
|
||||
}
|
||||
Reference in new issue
Block a user