Commit b47fa3a6 authored by schneider's avatar schneider
Browse files

feat(ecg): Basic MAX30003 support

parent 461bfe32
......@@ -49,11 +49,15 @@
#include "tmr_utils.h"
#include "i2c.h"
#include "rtc.h"
#include "spi.h"
/***** Definitions *****/
#define I2C_DEVICE MXC_I2C0_BUS0
#define SPI SPI0
#define SPI_SPEED 1000000 // Bit Rate
/***** Globals *****/
/***** Functions *****/
......@@ -64,6 +68,46 @@ void I2C0_IRQHandler(void)
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];
}
void ecg_write_reg(uint8_t reg, uint32_t data)
{
spi_req_t req;
uint8_t tx_data[] = {(reg << 1) | 0, 0, 0, 0};
uint8_t rx_data[] = {0, data >> 16, (data >> 8 ) & 0xFF, data & 0xFF};
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);
}
// *****************************************************************************
int main(void)
{
......@@ -91,6 +135,23 @@ int main(void)
// 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);
}
while (1) {
LED_On(0);
......
......@@ -176,10 +176,12 @@ __weak void SystemInit(void)
// All GPIO on port 1 to 1.8 V first
MXC_GPIO1->vssel = 0;
MXC_GPIO0->vssel |= (1UL << 0) | (1UL << 1) | (1UL << 2) | (1UL << 3) | (1UL << 4) | (1UL << 5); // SDHC
MXC_GPIO1->vssel |= (1UL << 0) | (1UL << 1) | (1UL << 2) | (1UL << 3) | (1UL << 4) | (1UL << 5); // SDHC
MXC_GPIO1->vssel |= (1 << 6) | (1 << 7); // GPIO to TOP
MXC_GPIO1->vssel |= (1 << 14) | (1 << 15); // GPIO for RGB LEDs
MXC_GPIO1->vssel |= (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11); // TODO: TMP for devboard
MXC_GPIO1->ps |= 0xFFFFFFFF;
MXC_GPIO1->pad_cfg1 |= 0xFFFFFFFF;
MXC_GPIO1->pad_cfg2 &= ~(0xFFFFFFFF);
......
......@@ -71,7 +71,8 @@ const gpio_cfg_t gpio_cfg_i2c0 = { PORT_0, (PIN_6 | PIN_7), GPIO_FUNC_ALT1, GP
const gpio_cfg_t gpio_cfg_i2c1 = { PORT_0, (PIN_14 | PIN_15), GPIO_FUNC_ALT1, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_i2c2 = { PORT_1, (PIN_14 | PIN_15), GPIO_FUNC_ALT1, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_spi17y0a = { PORT_1, (PIN_9 | PIN_10 | PIN_11 | PIN_12 | PIN_13), GPIO_FUNC_ALT1, GPIO_PAD_NONE };
//const gpio_cfg_t gpio_cfg_spi17y0a = { PORT_1, (PIN_9 | PIN_10 | PIN_11 | PIN_12 | PIN_13), GPIO_FUNC_ALT1, GPIO_PAD_NONE }; // TODO: move out of SDK
const gpio_cfg_t gpio_cfg_spi17y0a = { PORT_1, (PIN_9 | PIN_10 | PIN_11), GPIO_FUNC_ALT1, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_spi17y0b = { PORT_0, (PIN_9 | PIN_10 | PIN_11 | PIN_12 | PIN_13), GPIO_FUNC_ALT2, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_spi17y0_ss0a = { PORT_1, (PIN_8), GPIO_FUNC_ALT1, GPIO_PAD_NONE };
const gpio_cfg_t gpio_cfg_spi17y0_ss0b = { PORT_0, (PIN_8), GPIO_FUNC_ALT2, GPIO_PAD_NONE };
......
Supports Markdown
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