Commit 33bf745e authored by schneider's avatar schneider
Browse files

refact(card10): factor out init and diag code

parent 4ec04584
......@@ -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",