Commit 4424b864 authored by schneider's avatar schneider
Browse files

refact(bosch): Consolidate bosch support functions

parent 0c9389e0
......@@ -67,11 +67,13 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
# Source files for this test (add path to VPATH below)
SRCS = main.c
SRCS += ../lib/card10/oled96.c
SRCS += ../lib/card10/fonts.c
SRCS += ../lib/card10/pmic.c
SRCS += oled96.c
SRCS += fonts.c
SRCS += pmic.c
SRCS += bosch.c
SRCS += bhy_support.c bhy_uc_driver.c bhy.c
SRCS += MAX77650-Arduino-Library.c
SRCS += bme680.h
# Where to find source files for this test
VPATH = .
......@@ -88,6 +90,9 @@ VPATH += ../lib/bosch/BHy1_driver_and_MCU_solution/driver/src
IPATH += ../lib/maxim/MAX77650-Arduino-Library
VPATH += ../lib/maxim/MAX77650-Arduino-Library
IPATH += ../lib/bosch/BME680_driver
VPATH += ../lib/bosch/BME680_driver
# Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
......
......@@ -57,6 +57,8 @@
#include "Bosch_PCB_7183_di03_BMI160_BMM150-7183_di03.2.1.11696_170103.h"
#include "bhy_uc_driver.h"
#include "pmic.h"
#include "bme680.h"
#include "bosch.h"
/***** Definitions *****/
......@@ -104,7 +106,6 @@ int main(void)
int count = 0;
printf("Hello World!\n");
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
//Setup the I2CM
I2C_Shutdown(MXC_I2C0_BUS0);
......@@ -113,6 +114,12 @@ int main(void)
I2C_Shutdown(MXC_I2C1_BUS0);
I2C_Init(MXC_I2C1_BUS0, I2C_FAST_MODE, NULL);
pmic_init();
pmic_set_led(0, 0);
pmic_set_led(1, 0);
pmic_set_led(2, 0);
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
#if 0
NVIC_EnableIRQ(I2C0_IRQn); // Not sure if we actually need this when not doing async requests
#endif
......@@ -143,6 +150,21 @@ int main(void)
}
struct bme680_dev gas_sensor;
gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
gas_sensor.intf = BME680_I2C_INTF;
gas_sensor.read = card10_bosch_i2c_read;
gas_sensor.write = card10_bosch_i2c_write;
gas_sensor.delay_ms = card10_bosch_delay;
gas_sensor.amb_temp = 25;
int8_t rslt = BME680_OK;
rslt = bme680_init(&gas_sensor);
if(rslt != BME680_OK) {
printf("Failed to init BME680\n");
}
// Enable 32 kHz output
RTC_SquareWave(MXC_RTC, SQUARE_WAVE_ENABLED, F_32KHZ, NOISE_IMMUNE_MODE, NULL);
......@@ -164,7 +186,6 @@ int main(void)
printf("%02x: 0x%06x\n", i, val);
}
pmic_init();
while (1) {
pmic_set_led(0, 31);
......
......@@ -67,9 +67,10 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
# Source files for this test (add path to VPATH below)
SRCS = main.c
SRCS += ../lib/card10/oled96.c
SRCS += ../lib/card10/fonts.c
SRCS += ../lib/card10/pmic.c
SRCS += oled96.c
SRCS += fonts.c
SRCS += pmic.c
SRCS += bosch.c
SRCS += bhy_support.c bhy_uc_driver.c bhy.c
SRCS += MAX77650-Arduino-Library.c
SRCS += bme680.h
......
......@@ -49,55 +49,17 @@
#include "board.h"
#include "tmr_utils.h"
#include "i2c.h"
#include "rtc.h"
#include "spi.h"
#include "gpio.h"
#include "oled96.h"
#include "bhy.h"
#include "Bosch_PCB_7183_di03_BMI160_BMM150-7183_di03.2.1.11696_170103.h"
#include "bhy_uc_driver.h"
#include "pmic.h"
#include "bme680.h"
#include "bosch.h"
/***** Definitions *****/
void user_delay_ms(uint32_t period)
{
TMR_Delay(MXC_TMR0, MSEC(period), 0);
}
void hexdump(uint8_t *data, uint8_t len);
int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
//printf("sensor_i2c_read 0x%02x %d\n", reg_addr, len);
if(I2C_MasterWrite(MXC_I2C1_BUS0, dev_id << 1, &reg_addr, 1, 1) == 1) {
//printf("setup read ok\n");
int l = I2C_MasterRead(MXC_I2C1_BUS0, dev_id << 1, reg_data, len, 0);
//printf("read:"); hexdump(reg_data, l);
return l == len ? 0 : -1;
}
return -1;
}
int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
//printf("sensor_i2c_write 0x%02x:", reg_addr); hexdump(reg_data, len);
uint8_t buf[len + 1];
buf[0] = reg_addr;
memcpy(buf + 1, reg_data, len);
int l = I2C_MasterWrite(MXC_I2C1_BUS0, dev_id << 1, buf, len + 1, 0);
//printf("wrote: %d\n", l);
return l == len + 1 ? 0 : -1;
}
// *****************************************************************************
int main(void)
{
int count = 0;
printf("Hello World!\n");
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
//Setup the I2CM
I2C_Shutdown(MXC_I2C0_BUS0);
I2C_Init(MXC_I2C0_BUS0, I2C_FAST_MODE, NULL);
......@@ -105,6 +67,12 @@ int main(void)
I2C_Shutdown(MXC_I2C1_BUS0);
I2C_Init(MXC_I2C1_BUS0, I2C_FAST_MODE, NULL);
pmic_init();
pmic_set_led(0, 0);
pmic_set_led(1, 0);
pmic_set_led(2, 0);
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
#if 0
NVIC_EnableIRQ(I2C0_IRQn); // Not sure if we actually need this when not doing async requests
#endif
......@@ -124,13 +92,6 @@ int main(void)
}
}
pmic_init();
pmic_set_led(0, 0);
pmic_set_led(1, 0);
pmic_set_led(2, 0);
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
oledInit(0x3c, 0, 0);
oledFill(0x00);
oledWriteString(0, 0, "Hello", 0);
......@@ -140,9 +101,9 @@ int main(void)
struct bme680_dev gas_sensor;
gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
gas_sensor.intf = BME680_I2C_INTF;
gas_sensor.read = user_i2c_read;
gas_sensor.write = user_i2c_write;
gas_sensor.delay_ms = user_delay_ms;
gas_sensor.read = card10_bosch_i2c_read;
gas_sensor.write = card10_bosch_i2c_write;
gas_sensor.delay_ms = card10_bosch_delay;
/* amb_temp can be set to 25 prior to configuring the gas sensor
* or by performing a few temperature readings without operating the gas sensor.
*/
......
......@@ -67,9 +67,10 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
# Source files for this test (add path to VPATH below)
SRCS = main.c
SRCS += ../lib/card10/oled96.c
SRCS += ../lib/card10/fonts.c
SRCS += ../lib/card10/pmic.c
SRCS += oled96.c
SRCS += fonts.c
SRCS += pmic.c
SRCS += bosch.c
SRCS += bhy_support.c bhy_uc_driver.c bhy.c
SRCS += MAX77650-Arduino-Library.c
# Where to find source files for this test
......
......@@ -89,27 +89,6 @@ void I2C0_IRQHandler(void)
}
#endif
uint32_t ecg_read_reg(uint8_t reg)
{
spi_req_t req;
uint8_t tx_data[] = {(reg << 1) | 1, 0, 0, 0};
uint8_t rx_data[] = {0, 0, 0, 0};
req.tx_data = tx_data;
req.rx_data = rx_data;
req.len = 4;
req.bits = 8;
req.width = SPI17Y_WIDTH_1;
req.ssel = 0;
req.deass = 1;
req.ssel_pol = SPI17Y_POL_LOW;
req.tx_num = 0;
req.rx_num = 0;
SPI_MasterTrans(SPI, &req);
return (rx_data[1] << 16) | (rx_data[2] << 8) | rx_data[3];
}
static void sensors_callback_vector(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
printf("x=%d, y=%d, z=%d status=%d\n",
......@@ -189,7 +168,6 @@ static void sensors_callback_rotation_vector(bhy_data_generic_t * sensor_data, b
int main(void)
{
printf("Hello World!\n");
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
//Setup the I2CM
I2C_Shutdown(MXC_I2C0_BUS0);
......@@ -198,6 +176,13 @@ int main(void)
I2C_Shutdown(MXC_I2C1_BUS0);
I2C_Init(MXC_I2C1_BUS0, I2C_FAST_MODE, NULL);
pmic_init();
pmic_set_led(0, 0);
pmic_set_led(1, 0);
pmic_set_led(2, 0);
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
#if 0
NVIC_EnableIRQ(I2C0_IRQn); // Not sure if we actually need this when not doing async requests
#endif
......@@ -217,13 +202,6 @@ int main(void)
}
}
pmic_init();
pmic_set_led(0, 0);
pmic_set_led(1, 0);
pmic_set_led(2, 0);
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
#if 0
oledInit(0x3c, 0, 0);
oledFill(0x00);
......
......@@ -55,9 +55,8 @@
/********************************************************************************/
#include "bhy_support.h"
#include "bhy_uc_driver_config.h"
#include "bosch.h"
#include "i2c.h"
#include "tmr_utils.h"
#include <stdio.h>
#include <string.h>
......@@ -67,30 +66,17 @@
static struct bhy_t bhy;
static char *version = BHY_MCU_REFERENCE_VERSION;
#define I2C_DEVICE MXC_I2C1_BUS0
/********************************************************************************/
/* EXTERN FUNCTION DECLARATIONS */
/********************************************************************************/
static int8_t sensor_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
{
uint8_t buf[size + 1];
//printf("sensor_i2c_write 0x%02x %d\n", reg, size);
buf[0] = reg;
memcpy(buf + 1, p_buf, size);
int l = I2C_MasterWrite(I2C_DEVICE, addr << 1, buf, size + 1, 0);
return l == size + 1 ? BHY_SUCCESS : BHY_ERROR;
return card10_bosch_i2c_write(addr, reg, p_buf, size) == 0 ? BHY_SUCCESS : BHY_ERROR;
}
static int8_t sensor_i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
{
//printf("sensor_i2c_read 0x%02x %d\n", reg, size);
if(I2C_MasterWrite(I2C_DEVICE, addr << 1, &reg, 1, 1) == 1) {
int l = I2C_MasterRead(I2C_DEVICE, addr << 1, p_buf, size, 0);
return l == size ? BHY_SUCCESS : BHY_ERROR;
}
return BHY_ERROR;
return card10_bosch_i2c_read(addr, reg, p_buf, size) == 0 ? BHY_SUCCESS : BHY_ERROR;
}
/********************************************************************************/
......@@ -135,7 +121,7 @@ int8_t bhy_initialize_support(void)
*/
void bhy_delay_msec(uint32_t msec)
{
TMR_Delay(MXC_TMR0, MSEC(msec), 0);
card10_bosch_delay(msec);
}
/*!
* @brief provides a print function to the bhy driver on DD2.0 platform
......
#include "i2c.h"
#include "tmr_utils.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define I2C_DEVICE MXC_I2C1_BUS0
/********************************************************************************/
/* EXTERN FUNCTION DECLARATIONS */
/********************************************************************************/
#if 0
static void hexdump(uint8_t *data, uint8_t len)
{
for(int i=0; i<len; i++) {
printf("%02x ", data[i]);
}
printf("\n");
}
#endif
int8_t card10_bosch_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
{
uint8_t buf[size + 1];
//printf("sensor_i2c_write 0x%02x:", reg); hexdump(p_buf, size);
buf[0] = reg;
memcpy(buf + 1, p_buf, size);
int l = I2C_MasterWrite(I2C_DEVICE, addr << 1, buf, size + 1, 0);
//printf("wrote: %d\n", l);
return l == size + 1 ? 0 : -1;
//return l == size + 1 ? BHY_SUCCESS : BHY_ERROR;
}
int8_t card10_bosch_i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
{
//printf("sensor_i2c_read 0x%02x %d\n", reg, size);
if(I2C_MasterWrite(I2C_DEVICE, addr << 1, &reg, 1, 1) == 1) {
//printf("setup read ok\n");
int l = I2C_MasterRead(I2C_DEVICE, addr << 1, p_buf, size, 0);
//printf("read:"); hexdump(p_buf, l);
return l == size ? 0 : -1;
//return l == size ? BHY_SUCCESS : BHY_ERROR;
}
return -1;
//return BHY_ERROR;
}
void card10_bosch_delay(uint32_t msec)
{
TMR_Delay(MXC_TMR0, MSEC(msec), 0);
}
#ifndef BOSCH_H
#define BOSCH_H
#include <stdint.h>
int8_t card10_bosch_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);
int8_t card10_bosch_i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size);
void card10_bosch_delay(uint32_t msec);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment