#include "bma253.h"

void i2c_chekc(uint8_t result){
    switch(result){
        case HAL_OK:
        printf("HAL_OK : %d \r\n",result);
        break;
        case HAL_ERROR:
        printf("HAL_ERROR : %d\r\n",result);
        break;
        case HAL_BUSY:
        printf("HAL_BUSY : %d\r\n",result);
        break;
        case HAL_TIMEOUT:
        printf("HAL_TIMEOUT : %d\r\n",result);
        break;
    }

}
int bma253_get_chip_id(void){
    uint8_t data,res[1]={0,};
    
    data = HAL_I2C_Mem_Read(&hi2c2, (REG_VALUE_CHIP_ID << 1), 0, 1, &res[0], I2C_MEMADD_SIZE_8BIT, 1000);
    i2c_chekc(data);
    HAL_Delay(1000);
    
    data = HAL_I2C_Mem_Read(&hi2c2, REG_VALUE_CHIP_ID , 0, 1, &res[0], I2C_MEMADD_SIZE_8BIT, 1000);
    i2c_chekc(data);
    HAL_Delay(1000);
    
    data = HAL_I2C_Mem_Read(&hi2c2, REG_ADDR_BGW_CHIPID, REG_VALUE_CHIP_ID, 1, &res[0], I2C_MEMADD_SIZE_8BIT, 1000);
    i2c_chekc(data);
    HAL_Delay(1000);
    
    data = HAL_I2C_Mem_Read(&hi2c2, REG_ADDR_BGW_CHIPID, REG_VALUE_CHIP_ID<<1, 1, &res[0], I2C_MEMADD_SIZE_8BIT, 1000);
    i2c_chekc(data);
    HAL_Delay(1000);


    data = HAL_I2C_Mem_Read_IT(&hi2c2, (REG_VALUE_CHIP_ID << 1), 0, 1, &res[0], I2C_MEMADD_SIZE_8BIT);
    i2c_chekc(data);
    HAL_Delay(1000);
    
    data = HAL_I2C_Mem_Read_IT(&hi2c2, REG_VALUE_CHIP_ID , 0, 1, &res[0], 1);
    i2c_chekc(data);
    HAL_Delay(1000);
    
    data = HAL_I2C_Mem_Read_IT(&hi2c2, REG_ADDR_BGW_CHIPID, REG_VALUE_CHIP_ID, 1, &res[0], I2C_MEMADD_SIZE_8BIT);
    i2c_chekc(data);
    HAL_Delay(1000);
    
    data = HAL_I2C_Mem_Read_IT(&hi2c2, REG_ADDR_BGW_CHIPID, REG_VALUE_CHIP_ID<<1, 1, &res[0], I2C_MEMADD_SIZE_8BIT);
    i2c_chekc(data);
    HAL_Delay(1000);
}
