Skip to content
Snippets Groups Projects
Commit 33bf745e authored by schneider's avatar schneider
Browse files

refact(card10): factor out init and diag code

parent 4ec04584
No related branches found
No related tags found
No related merge requests found
......@@ -67,8 +67,6 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
# Source files for this test (add path to VPATH below)
SRCS = main.c
SRCS += oled96.c
SRCS += fonts.c
SRCS += pmic.c
SRCS += bosch.c
SRCS += bhy_support.c bhy_uc_driver.c bhy.c
......@@ -76,6 +74,7 @@ SRCS += MAX77650-Arduino-Library.c
SRCS += bme680.h
SRCS += bma400.c
# Where to find source files for this test
VPATH = .
......
......@@ -41,167 +41,31 @@
*/
/***** Includes *****/
#include "pmic.h"
#include "card10.h"
#include "tmr_utils.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "mxc_config.h"
#include "led.h"
#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 "bma400.h"
#include "bosch.h"
/***** Definitions *****/
#define I2C_DEVICE MXC_I2C0_BUS0
#define SPI SPI0
#define SPI_SPEED 1000000 // Bit Rate
/***** Globals *****/
static const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE};
//static const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE};
/***** Functions *****/
#if 0
void I2C0_IRQHandler(void)
{
I2C_Handler(I2C_DEVICE);
return;
}
#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];
}
// *****************************************************************************
int main(void)
{
int count = 0;
printf("Hello World!\n");
//Setup the I2CM
I2C_Shutdown(MXC_I2C0_BUS0);
I2C_Init(MXC_I2C0_BUS0, I2C_FAST_MODE, NULL);
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
uint8_t dummy[1] = {0};
// "7-bit addresses 0b0000xxx and 0b1111xxx are reserved"
for (int addr = 0x8; addr < 0x78; ++addr) {
// A 0 byte write does not seem to work so always send a single byte.
int res = I2C_MasterWrite(MXC_I2C0_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C0\n", addr);
}
res = I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C1\n", addr);
}
}
oledInit(0x3c, 0, 0);
oledFill(0x00);
oledWriteString(0, 0, "Hello", 0);
oledWriteString(0, 2, "my name is", 0);
oledWriteString(0, 4, "card10", 1);
if(bhy_driver_init(bhy1_fw)) {
printf("Failed to init bhy\n");
}
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");
}
struct bma400_dev bma;
bma.intf_ptr = NULL; /* To attach your interface device reference */
bma.delay_ms = card10_bosch_delay;
bma.dev_id = BMA400_I2C_ADDRESS_SDO_LOW;
bma.read = card10_bosch_i2c_read_ex;
bma.write = card10_bosch_i2c_write_ex;
bma.intf = BMA400_I2C_INTF;
rslt = bma400_init(&bma);
if (rslt == BMA400_OK) {
printf("BMA400 found with chip ID 0x%X\r\n", bma.chip_id);
}
// Enable 32 kHz output
RTC_SquareWave(MXC_RTC, SQUARE_WAVE_ENABLED, F_32KHZ, NOISE_IMMUNE_MODE, NULL);
// Enable SPI
sys_cfg_spi_t spi17y_master_cfg;
spi17y_master_cfg.map = MAP_A;
spi17y_master_cfg.ss0 = Enable;
spi17y_master_cfg.ss1 = Disable;
spi17y_master_cfg.ss2 = Disable;
if (SPI_Init(SPI, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
printf("Error configuring SPI\n");
while (1);
}
for(int i=0; i<0x20; i++) {
uint32_t val = ecg_read_reg(i);
printf("%02x: 0x%06x\n", i, val);
}
card10_init();
card10_diag();
while (1) {
#if 1
pmic_set_led(0, 31);
pmic_set_led(1, 0);
pmic_set_led(2, 0);
......@@ -220,9 +84,22 @@ int main(void)
pmic_set_led(0, 0);
pmic_set_led(1, 0);
pmic_set_led(2, 0);
//TMR_Delay(MXC_TMR0, MSEC(200), 0);
#endif
#if 0
//TMR_Delay(MXC_TMR0, MSEC(600), 0);
GPIO_OutSet(&motor_pin);
TMR_Delay(MXC_TMR0, MSEC(500), 0);
TMR_Delay(MXC_TMR0, MSEC(30), 0);
GPIO_OutClr(&motor_pin);
TMR_Delay(MXC_TMR0, MSEC(200), 0);
#endif
#if 0
LED_Off(0);
TMR_Delay(MXC_TMR0, MSEC(500), 0);
LED_On(0);
TMR_Delay(MXC_TMR0, MSEC(500), 0);
#endif
TMR_Delay(MXC_TMR0, MSEC(1000), 0);
printf("count = %d\n", count++);
}
......
......@@ -75,6 +75,7 @@ SRCS += bhy_support.c bhy_uc_driver.c bhy.c
SRCS += MAX77650-Arduino-Library.c
SRCS += bme680.h
SRCS += bma400.c
SRCS += card10.c
# Where to find source files for this test
VPATH = .
......
......@@ -41,9 +41,6 @@
*/
/***** Includes *****/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "mxc_config.h"
#include "led.h"
#include "board.h"
......@@ -53,14 +50,15 @@
#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 "bma400.h"
#include "bosch.h"
#include "card10.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
/***** Definitions *****/
/***** Globals *****/
......@@ -95,37 +93,8 @@ void print_rslt(int8_t rslt)
// *****************************************************************************
int main(void)
{
int count = 0;
printf("Hello World!\n");
//Setup the I2CM
I2C_Shutdown(MXC_I2C0_BUS0);
I2C_Init(MXC_I2C0_BUS0, I2C_FAST_MODE, NULL);
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);
uint8_t dummy[1] = {0};
// "7-bit addresses 0b0000xxx and 0b1111xxx are reserved"
for (int addr = 0x8; addr < 0x78; ++addr) {
// A 0 byte write does not seem to work so always send a single byte.
int res = I2C_MasterWrite(MXC_I2C0_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C0\n", addr);
}
res = I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C1\n", addr);
}
}
card10_init();
card10_diag();
oledInit(0x3c, 0, 0);
oledFill(0x00);
......
......@@ -74,6 +74,9 @@ SRCS += bosch.c
SRCS += bhy_support.c bhy_uc_driver.c bhy.c
SRCS += MAX77650-Arduino-Library.c
SRCS += bme680.h
SRCS += bma400.c
SRCS += card10.c
# Where to find source files for this test
VPATH = .
......@@ -93,6 +96,9 @@ VPATH += ../lib/maxim/MAX77650-Arduino-Library
IPATH += ../lib/bosch/BME680_driver
VPATH += ../lib/bosch/BME680_driver
IPATH += ../lib/bosch/BMA400-API
VPATH += ../lib/bosch/BMA400-API
# Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
......
......@@ -41,9 +41,6 @@
*/
/***** Includes *****/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "mxc_config.h"
#include "led.h"
#include "board.h"
......@@ -51,46 +48,21 @@
#include "i2c.h"
#include "gpio.h"
#include "oled96.h"
#include "pmic.h"
#include "bme680.h"
#include "bosch.h"
#include "card10.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
/***** Definitions *****/
// *****************************************************************************
int main(void)
{
printf("Hello World!\n");
//Setup the I2CM
I2C_Shutdown(MXC_I2C0_BUS0);
I2C_Init(MXC_I2C0_BUS0, I2C_FAST_MODE, NULL);
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
uint8_t dummy[1] = {0};
// "7-bit addresses 0b0000xxx and 0b1111xxx are reserved"
for (int addr = 0x8; addr < 0x78; ++addr) {
// A 0 byte write does not seem to work so always send a single byte.
int res = I2C_MasterWrite(MXC_I2C0_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C0\n", addr);
}
res = I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C1\n", addr);
}
}
card10_init();
card10_diag();
oledInit(0x3c, 0, 0);
oledFill(0x00);
......
......@@ -70,8 +70,12 @@ SRCS = main.c
SRCS += pmic.c
SRCS += ../lib/card10/oled96.c
SRCS += ../lib/card10/fonts.c
SRCS += bosch.c
SRCS += bhy_support.c bhy_uc_driver.c bhy.c
SRCS += MAX77650-Arduino-Library.c
SRCS += bme680.h
SRCS += bma400.c
SRCS += card10.c
# Where to find source files for this test
VPATH = .
......@@ -82,9 +86,19 @@ IPATH = .
IPATH += ../lib/card10
VPATH += ../lib/card10
IPATH += ../lib/bosch/BHy1_driver_and_MCU_solution/driver/inc
IPATH += ../lib/bosch/BHy1_driver_and_MCU_solution/examples/firmware/
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
IPATH += ../lib/bosch/BMA400-API
VPATH += ../lib/bosch/BMA400-API
# Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
......
......@@ -55,28 +55,15 @@
#include "MAX30003.h"
#include "oled96.h"
#include "pmic.h"
#include "card10.h"
#include <stdbool.h>
/***** Definitions *****/
#define I2C_DEVICE MXC_I2C0_BUS0
#define SPI SPI0
#define SPI_SPEED 10000000 // Bit Rate
/***** Globals *****/
/***** Functions *****/
#if 0
void I2C0_IRQHandler(void)
{
I2C_Handler(I2C_DEVICE);
return;
}
#endif
uint32_t ecg_read_reg(uint8_t reg)
static uint32_t ecg_read_reg(uint8_t reg)
{
spi_req_t req;
uint8_t tx_data[] = {(reg << 1) | 1, 0, 0, 0};
......@@ -92,12 +79,12 @@ uint32_t ecg_read_reg(uint8_t reg)
req.tx_num = 0;
req.rx_num = 0;
SPI_MasterTrans(SPI, &req);
SPI_MasterTrans(SPI0, &req);
return (rx_data[1] << 16) | (rx_data[2] << 8) | rx_data[3];
}
void ecg_write_reg(uint8_t reg, uint32_t data)
static void ecg_write_reg(uint8_t reg, uint32_t data)
{
printf("write %02x %06x\n", reg, data);
spi_req_t req;
......@@ -114,7 +101,7 @@ void ecg_write_reg(uint8_t reg, uint32_t data)
req.tx_num = 0;
req.rx_num = 0;
SPI_MasterTrans(SPI, &req);
SPI_MasterTrans(SPI0, &req);
}
void ecg_config(void)
......@@ -243,52 +230,9 @@ void ecgFIFO_callback(void *data) {
// *****************************************************************************
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);
I2C_Shutdown(MXC_I2C1_BUS0);
I2C_Init(MXC_I2C1_BUS0, I2C_FAST_MODE, NULL);
#if 0
NVIC_EnableIRQ(I2C0_IRQn); // Not sure if we actually need this when not doing async requests
#endif
uint8_t dummy[1] = {0};
// "7-bit addresses 0b0000xxx and 0b1111xxx are reserved"
for (int addr = 0x8; addr < 0x78; ++addr) {
// A 0 byte write does not seem to work so always send a single byte.
int res = I2C_MasterWrite(MXC_I2C0_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C0\n", addr);
}
res = I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C1\n", addr);
}
}
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, " card10", 1);
TMR_Delay(MXC_TMR0, MSEC(1500), 0);
// Enable 32 kHz output
RTC_SquareWave(MXC_RTC, SQUARE_WAVE_ENABLED, F_32KHZ, NOISE_IMMUNE_MODE, NULL);
card10_init();
card10_diag();
const gpio_cfg_t interrupt_pin = {PORT_1, PIN_12, GPIO_FUNC_IN, GPIO_PAD_PULL_UP};
GPIO_Config(&interrupt_pin);
......@@ -298,24 +242,6 @@ int main(void)
NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(PORT_1));
// Enable SPI
sys_cfg_spi_t spi17y_master_cfg;
spi17y_master_cfg.map = MAP_A;
spi17y_master_cfg.ss0 = Enable;
spi17y_master_cfg.ss1 = Disable;
spi17y_master_cfg.ss2 = Disable;
if (SPI_Init(SPI, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
printf("Error configuring SPI\n");
while (1);
}
for(int i=0; i<0x20; i++) {
uint32_t val = ecg_read_reg(i);
printf("%02x: 0x%06x\n", i, val);
}
ecg_config();
for(int i=0; i<0x20; i++) {
......
......@@ -73,6 +73,10 @@ SRCS += pmic.c
SRCS += bosch.c
SRCS += bhy_support.c bhy_uc_driver.c bhy.c
SRCS += MAX77650-Arduino-Library.c
SRCS += bme680.h
SRCS += bma400.c
SRCS += card10.c
# Where to find source files for this test
VPATH = .
......@@ -89,6 +93,12 @@ 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
IPATH += ../lib/bosch/BMA400-API
VPATH += ../lib/bosch/BMA400-API
# Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
......
......@@ -41,9 +41,6 @@
*/
/***** Includes *****/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "mxc_config.h"
#include "led.h"
#include "board.h"
......@@ -52,19 +49,17 @@
#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 <math.h>
/***** Definitions *****/
#include "card10.h"
#define I2C_DEVICE MXC_I2C0_BUS0
#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define SPI SPI0
#define SPI_SPEED 1000000 // Bit Rate
/***** Definitions *****/
/* should be greater or equal to 69 bytes, page size (50) + maximum packet size(18) + 1 */
#define FIFO_SIZE 300
......@@ -74,24 +69,14 @@
/***** Globals *****/
static const gpio_cfg_t motor_pin = {PORT_0, PIN_8, GPIO_FUNC_OUT, GPIO_PAD_NONE};
char out_buffer[OUT_BUFFER_SIZE] = " W: 0.999 X: 0.999 Y: 0.999 Z: 0.999 \r";
uint8_t fifo[FIFO_SIZE];
/***** Functions *****/
#if 0
void I2C0_IRQHandler(void)
{
I2C_Handler(I2C_DEVICE);
return;
}
#endif
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",
printf("x=%05d, y=%05d, z=%05d status=%d\n",
sensor_data->data_vector.x,
sensor_data->data_vector.y,
sensor_data->data_vector.z,
......@@ -99,6 +84,17 @@ static void sensors_callback_vector(bhy_data_generic_t * sensor_data, bhy_virtua
);
}
static void sensors_callback_vector_uncalib(bhy_data_generic_t * sensor_data, bhy_virtual_sensor_t sensor_id)
{
printf("x=%05d, y=%05d, z=%05d status=%d\n",
sensor_data->data_uncalib_vector.x,
sensor_data->data_uncalib_vector.y,
sensor_data->data_uncalib_vector.z,
sensor_data->data_uncalib_vector.status
);
}
/*!
* @brief This function is callback function for acquring sensor datas
*
......@@ -167,49 +163,6 @@ static void sensors_callback_rotation_vector(bhy_data_generic_t * sensor_data, b
// *****************************************************************************
int main(void)
{
printf("Hello World!\n");
//Setup the I2CM
I2C_Shutdown(MXC_I2C0_BUS0);
I2C_Init(MXC_I2C0_BUS0, I2C_FAST_MODE, NULL);
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
uint8_t dummy[1] = {0};
// "7-bit addresses 0b0000xxx and 0b1111xxx are reserved"
for (int addr = 0x8; addr < 0x78; ++addr) {
// A 0 byte write does not seem to work so always send a single byte.
int res = I2C_MasterWrite(MXC_I2C0_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C0\n", addr);
}
res = I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C1\n", addr);
}
}
#if 0
oledInit(0x3c, 0, 0);
oledFill(0x00);
oledWriteString(0, 0, "Hello", 0);
oledWriteString(0, 2, "my name is", 0);
oledWriteString(0, 4, "card10", 1);
#endif
/* BHY Variable*/
uint8_t *fifoptr = NULL;
uint8_t bytes_left_in_fifo = 0;
......@@ -222,15 +175,14 @@ int main(void)
const gpio_cfg_t interrupt_pin = {PORT_0, PIN_13, GPIO_FUNC_IN, GPIO_PAD_PULL_UP};
GPIO_Config(&interrupt_pin);
if(bhy_driver_init(bhy1_fw)) {
printf("Failed to init bhy\n");
}
card10_init();
/* wait for the bhy trigger the interrupt pin go down and up again */
while (GPIO_InGet(&interrupt_pin));
while (!GPIO_InGet(&interrupt_pin));
card10_diag();
/* the remapping matrix for BHI and Magmetometer should be configured here to make sure rotation vector is */
/* calculated in a correct coordinates system. */
int8_t bhy_mapping_matrix_config[3*3] = {0,-1,0,1,0,0,0,0,1};
......@@ -255,7 +207,9 @@ int main(void)
#endif
//if(bhy_install_sensor_callback(VS_TYPE_GEOMAGNETIC_FIELD, VS_WAKEUP, sensors_callback_vector))
if(bhy_install_sensor_callback(VS_TYPE_GRAVITY, VS_WAKEUP, sensors_callback_vector))
//if(bhy_install_sensor_callback(VS_TYPE_GRAVITY, VS_WAKEUP, sensors_callback_vector))
//if(bhy_install_sensor_callback(VS_TYPE_ACCELEROMETER, VS_WAKEUP, sensors_callback_vector))
if(bhy_install_sensor_callback(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, sensors_callback_vector_uncalib))
{
printf("Fail to install sensor callback\n");
}
......@@ -270,7 +224,9 @@ int main(void)
/* enables the virtual sensor */
//if(bhy_enable_virtual_sensor(VS_TYPE_GEOMAGNETIC_FIELD, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
if(bhy_enable_virtual_sensor(VS_TYPE_GRAVITY, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_GRAVITY, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
//if(bhy_enable_virtual_sensor(VS_TYPE_ACCELEROMETER, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
if(bhy_enable_virtual_sensor(VS_TYPE_MAGNETIC_FIELD_UNCALIBRATED, VS_WAKEUP, ROTATION_VECTOR_SAMPLE_RATE, 0, VS_FLUSH_NONE, 0, 0))
{
printf("Fail to enable sensor id=%d\n", VS_TYPE_GEOMAGNETIC_FIELD);
}
......
......@@ -67,8 +67,6 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
# Source files for this test (add path to VPATH below)
SRCS = main.c
SRCS += oled96.c
SRCS += fonts.c
SRCS += pmic.c
SRCS += bosch.c
SRCS += bhy_support.c bhy_uc_driver.c bhy.c
......@@ -82,6 +80,7 @@ SRCS += font24.c
SRCS += font24CN.c
SRCS += image.c
SRCS += image2.c
SRCS += card10.c
# Where to find source files for this test
......
......@@ -41,9 +41,6 @@
*/
/***** Includes *****/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "mxc_config.h"
#include "led.h"
#include "board.h"
......@@ -52,20 +49,18 @@
#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 "bma400.h"
#include "bosch.h"
#include "LCD/LCD_Driver.h"
#include "GUI_DEV/GUI_Paint.h"
#include "Fonts/fonts.h"
#include "image/image.h"
#include "tmr.h"
#include "card10.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
// Parameters for PWM output
#define PORT_PWM PORT_0 // port
#define PIN_PWM PIN_28 // pin
......@@ -144,35 +139,8 @@ int main(void)
{
int count = 0;
printf("Hello World!\n");
#if 1
//Setup the I2CM
I2C_Shutdown(MXC_I2C0_BUS0);
I2C_Init(MXC_I2C0_BUS0, I2C_FAST_MODE, NULL);
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);
#endif
// Enable SPI
sys_cfg_spi_t spi17y_master_cfg;
spi17y_master_cfg.map = MAP_A;
spi17y_master_cfg.ss0 = Enable;
spi17y_master_cfg.ss1 = Disable;
spi17y_master_cfg.ss2 = Disable;
if (SPI_Init(SPI, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
printf("Error configuring SPI\n");
while (1);
}
card10_init();
card10_diag();
//GPIO_Config(&DEV_RST_PIN);
GPIO_Config(&DEV_DC_PIN);
......
#include "pmic.h"
#include "bosch.h"
#include "bhy_uc_driver.h"
#include "Bosch_PCB_7183_di03_BMI160_BMM150-7183_di03.2.1.11696_170103.h"
#include "bme680.h"
#include "bma400.h"
#include "bhy.h"
#include "mxc_config.h"
#include "led.h"
#include "board.h"
#include "tmr_utils.h"
#include "i2c.h"
#include "rtc.h"
#include "spi.h"
#include "gpio.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define SPI SPI0
#define SPI_SPEED 1000000 // Bit Rate
void card10_init(void)
{
printf("card10 init...\n");
//Setup the I2CM
I2C_Shutdown(MXC_I2C0_BUS0);
I2C_Init(MXC_I2C0_BUS0, I2C_FAST_MODE, NULL);
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);
// Enable 32 kHz output
RTC_SquareWave(MXC_RTC, SQUARE_WAVE_ENABLED, F_32KHZ, NOISE_IMMUNE_MODE, NULL);
// Enable SPI
sys_cfg_spi_t spi17y_master_cfg;
spi17y_master_cfg.map = MAP_A;
spi17y_master_cfg.ss0 = Enable;
spi17y_master_cfg.ss1 = Disable;
spi17y_master_cfg.ss2 = Disable;
if (SPI_Init(SPI, 0, SPI_SPEED, spi17y_master_cfg) != 0) {
printf("Error configuring SPI\n");
while (1);
}
if(bhy_driver_init(bhy1_fw)) {
printf("Failed to init bhy\n");
}
}
static 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(SPI0, &req);
return (rx_data[1] << 16) | (rx_data[2] << 8) | rx_data[3];
}
void card10_diag(void)
{
uint8_t dummy[1] = {0};
// "7-bit addresses 0b0000xxx and 0b1111xxx are reserved"
for (int addr = 0x8; addr < 0x78; ++addr) {
// A 0 byte write does not seem to work so always send a single byte.
int res = I2C_MasterWrite(MXC_I2C0_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C0\n", addr);
}
res = I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, dummy, 1, 0);
if(res == 1) {
printf("Found (7 bit) address 0x%02x on I2C1\n", addr);
}
}
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");
}
struct bma400_dev bma;
bma.intf_ptr = NULL; /* To attach your interface device reference */
bma.delay_ms = card10_bosch_delay;
bma.dev_id = BMA400_I2C_ADDRESS_SDO_LOW;
bma.read = card10_bosch_i2c_read_ex;
bma.write = card10_bosch_i2c_write_ex;
bma.intf = BMA400_I2C_INTF;
rslt = bma400_init(&bma);
if (rslt == BMA400_OK) {
printf("BMA400 found with chip ID 0x%X\r\n", bma.chip_id);
}
for(int i=0; i<0x20; i++) {
uint32_t val = ecg_read_reg(i);
printf("ECG: %02x: 0x%06x\n", i, val);
}
}
#ifndef CARD10_H
#include <stdint.h>
void card10_init(void);
void card10_diag(void);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment