From 7e84dee23aecc79dc27d44e2342e8fe721861d4e Mon Sep 17 00:00:00 2001 From: Ben Peng Date: Fri, 20 May 2016 17:11:51 -0700 Subject: [PATCH 1/6] no pull i2c ports/100k external pullup/ need work on prox data format --- common/message_ant.h | 2 +- drivers/prox_i2c.c | 10 ++++++---- drivers/twi_hw_master.c | 4 ++-- pillx_EVT1/platform.h | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/common/message_ant.h b/common/message_ant.h index 4de010a6..abc914f2 100644 --- a/common/message_ant.h +++ b/common/message_ant.h @@ -65,8 +65,8 @@ typedef enum { ANT_PILL_SHAKING, ANT_PILL_DATA_ENCRYPTED, ANT_PILL_PROX_ENCRYPTED, - ANT_SENSE_RESPONSE_HEARTBEAT, ANT_PILL_PROX_PLAINTEXT, + ANT_SENSE_RESPONSE_HEARTBEAT, }MSG_ANT_PillDataType_t; typedef struct{ diff --git a/drivers/prox_i2c.c b/drivers/prox_i2c.c index d9d862a5..9400b044 100644 --- a/drivers/prox_i2c.c +++ b/drivers/prox_i2c.c @@ -60,7 +60,7 @@ static uint32_t _byte_check(const uint8_t * compare, const uint8_t * actual, siz return 0; } static void _reset_config(void){ - uint8_t RST[3] = {0x0C, 0x84, 0x90}; + uint8_t RST[3] = {0x0C, 0x84, 0x00}; TWI_WRITE(FDC_ADDRESS, RST, sizeof(RST)); } static void _check_id(void){ @@ -90,9 +90,11 @@ MSG_Status init_prox(void){ //tie vaux to vbat #ifdef PLATFORM_HAS_PROX nrf_gpio_cfg_output(PROX_BOOST_ENABLE); - nrf_gpio_pin_clear(PROX_BOOST_ENABLE); - nrf_gpio_cfg_output(PROX_VDD_EN); - nrf_gpio_pin_set(PROX_VDD_EN); + //nrf_gpio_pin_clear(PROX_BOOST_ENABLE); + nrf_gpio_pin_write(PROX_BOOST_ENABLE, 0); + nrf_gpio_cfg_output(PROX_VDD_EN); + //nrf_gpio_pin_set(PROX_VDD_EN); + nrf_gpio_pin_write(PROX_VDD_EN, 1); _reset_config(); _check_id(); _conf_prox(); diff --git a/drivers/twi_hw_master.c b/drivers/twi_hw_master.c index 3a968f77..da72f607 100644 --- a/drivers/twi_hw_master.c +++ b/drivers/twi_hw_master.c @@ -274,14 +274,14 @@ bool twi_master_init(void) NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER] = \ (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \ | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \ - | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \ + | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) \ | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \ | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_DATA_PIN_NUMBER] = \ (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \ | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) \ - | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) \ + | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) \ | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \ | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); diff --git a/pillx_EVT1/platform.h b/pillx_EVT1/platform.h index fa495c76..58b37f86 100644 --- a/pillx_EVT1/platform.h +++ b/pillx_EVT1/platform.h @@ -6,14 +6,14 @@ #define ANT_ENABLE #endif -#define BLE_ENABLE +//#define BLE_ENABLE #define HW_REVISION 3 #define DEVICE_KEY_ADDRESS 0x20003FF0 //use hello's ant network key #define USE_HLO_ANT_NETWORK -#define PILL_ANT_TYPE HLO_ANT_DEVICE_TYPE_PILL1_5 +//#define PILL_ANT_TYPE HLO_ANT_DEVICE_TYPE_PILL1_5 #define configTOTAL_HEAP_SIZE 1024 From e5a853fe66c23a29cdb3e267ef6df60fd522b63c Mon Sep 17 00:00:00 2001 From: Ben Peng Date: Mon, 23 May 2016 12:59:26 -0700 Subject: [PATCH 2/6] 4X gain/CAP 1 offset calibrated/24bit output --- drivers/prox_i2c.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/prox_i2c.c b/drivers/prox_i2c.c index 9400b044..2c431879 100644 --- a/drivers/prox_i2c.c +++ b/drivers/prox_i2c.c @@ -34,8 +34,14 @@ static inline void TWI_READ(uint8_t addr, uint8_t reg, void * ptr, size_t ptr_si } -static const uint8_t CONF_MEAS1[3] = { 0x08, 0x1C, 0x00 }; -static const uint8_t CONF_MEAS4[3] = { 0x0B, 0x7C, 0x00 }; +static const uint8_t CONF_MEAS1[3] = { 0x08, 0x1C, 0x00 };// if differential measurement- 0x0C/single ended measurement- 0x1C/ and store results in MEAS1 +static const uint8_t CONF_MEAS4[3] = { 0x0B, 0x7C, 0x00 };// single ended measurement- 0x7C/ and store results in MEAS4 + +static const uint8_t CONF_GAIN_CAL1[3] = {0x11, 0xFF, 0xFF};// CIN1 4x gain as 0xFF +static const uint8_t CONF_GAIN_CAL4[3] = {0x14, 0xFF, 0xFF};// CIN4 4x gain as 0xFF + +static const uint8_t CONF_OFFSET_CAL1[3] = {0x0D, 0xF0, 0x00};// CIN1 offset calibration -16pF -> 16pF +//static const uint8_t CONF_OFFSET_CAL4[3] = {0x10, 0xC8, 0x00}; static const uint8_t CONF_READ1[3] = {0x0C, 0x04, 0x80};//config nonrepeat static const uint8_t CONF_READ4[3] = {0x0C, 0x04, 0x10};//config nonrepeat @@ -78,6 +84,12 @@ static void _conf_prox(void){ uint8_t r[2] = {0}; TWI_WRITE(FDC_ADDRESS, CONF_MEAS1, sizeof(CONF_MEAS1)); TWI_WRITE(FDC_ADDRESS, CONF_MEAS4, sizeof(CONF_MEAS4)); + // CONFIG OFFSET + TWI_WRITE(FDC_ADDRESS, CONF_OFFSET_CAL1, sizeof(CONF_OFFSET_CAL1)); //OFFSET CANCELLATION FOR CAP1 (BATT SIDE) + // TWI_WRITE(FDC_ADDRESS, CONF_OFFSET_CAL4, sizeof(CONF_OFFSET_CAL4)); + // CONFIG GAIN + TWI_WRITE(FDC_ADDRESS, CONF_GAIN_CAL1, sizeof(CONF_GAIN_CAL1)); // GAIN COMPENSATION FOR CAP1 (BATT SIDE) + TWI_WRITE(FDC_ADDRESS, CONF_GAIN_CAL4, sizeof(CONF_GAIN_CAL4)); //verify TWI_READ(FDC_ADDRESS, CONF_MEAS1[0], r,sizeof(r)); APP_OK( _byte_check(r, &CONF_MEAS1[1], sizeof(r)) ); @@ -90,10 +102,8 @@ MSG_Status init_prox(void){ //tie vaux to vbat #ifdef PLATFORM_HAS_PROX nrf_gpio_cfg_output(PROX_BOOST_ENABLE); - //nrf_gpio_pin_clear(PROX_BOOST_ENABLE); nrf_gpio_pin_write(PROX_BOOST_ENABLE, 0); nrf_gpio_cfg_output(PROX_VDD_EN); - //nrf_gpio_pin_set(PROX_VDD_EN); nrf_gpio_pin_write(PROX_VDD_EN, 1); _reset_config(); _check_id(); @@ -108,8 +118,8 @@ void read_prox(uint32_t * out_val1, uint32_t * out_val4){ uint16_t cap_meas1_lo = 0; uint16_t cap_meas4_hi = 0; uint16_t cap_meas4_lo = 0; - uint64_t cap_meas1_raw = 0; - uint64_t cap_meas4_raw = 0; + uint32_t cap_meas1_raw = 0; + uint32_t cap_meas4_raw = 0; TWI_WRITE(FDC_ADDRESS, CONF_READ1, sizeof(CONF_READ1)); TWI_WRITE(FDC_ADDRESS, CONF_READ4, sizeof(CONF_READ4)); //todo verify write @@ -122,7 +132,7 @@ void read_prox(uint32_t * out_val1, uint32_t * out_val4){ cap_meas1_raw = cap_meas1_raw >> 8; cap_meas4_raw = swap_endian16(cap_meas4_lo) | (swap_endian16(cap_meas4_hi) << 16); cap_meas4_raw = cap_meas4_raw >> 8; - *out_val1 = (uint32_t)((cap_meas1_raw << 10) / 524288); - *out_val4 = (uint32_t)((cap_meas4_raw << 10) / 524288); + *out_val1 = (uint32_t)((cap_meas1_raw ) / 1); + *out_val4 = (uint32_t)((cap_meas4_raw ) / 1); #endif } From a028aa405d7f1e6d280a3d5d20546c01aac1fe57 Mon Sep 17 00:00:00 2001 From: Ben Peng Date: Mon, 23 May 2016 14:25:49 -0700 Subject: [PATCH 3/6] remove ANT_SENSE_RESPONSE_HEARTBEAT --- common/message_ant.h | 1 - 1 file changed, 1 deletion(-) diff --git a/common/message_ant.h b/common/message_ant.h index abc914f2..aa3b818b 100644 --- a/common/message_ant.h +++ b/common/message_ant.h @@ -66,7 +66,6 @@ typedef enum { ANT_PILL_DATA_ENCRYPTED, ANT_PILL_PROX_ENCRYPTED, ANT_PILL_PROX_PLAINTEXT, - ANT_SENSE_RESPONSE_HEARTBEAT, }MSG_ANT_PillDataType_t; typedef struct{ From 81d9f6fa1a8ec784a9671caaaa41e19ad4d40a14 Mon Sep 17 00:00:00 2001 From: Ben Peng Date: Mon, 23 May 2016 14:27:31 -0700 Subject: [PATCH 4/6] remove ANT_SENSE_RESPONSE_HEARTBEAT --- drivers/prox_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/prox_i2c.c b/drivers/prox_i2c.c index 2c431879..7e2f19b1 100644 --- a/drivers/prox_i2c.c +++ b/drivers/prox_i2c.c @@ -132,7 +132,7 @@ void read_prox(uint32_t * out_val1, uint32_t * out_val4){ cap_meas1_raw = cap_meas1_raw >> 8; cap_meas4_raw = swap_endian16(cap_meas4_lo) | (swap_endian16(cap_meas4_hi) << 16); cap_meas4_raw = cap_meas4_raw >> 8; - *out_val1 = (uint32_t)((cap_meas1_raw ) / 1); - *out_val4 = (uint32_t)((cap_meas4_raw ) / 1); + *out_val1 = (uint32_t)((cap_meas1_raw )); + *out_val4 = (uint32_t)((cap_meas4_raw )); #endif } From f8b9f21a565118e7d07abdc8b2f3603090d66487 Mon Sep 17 00:00:00 2001 From: Ben Peng Date: Tue, 24 May 2016 12:21:49 -0700 Subject: [PATCH 5/6] enable BLE and PILL_ANT_TYPE_HLO_ANT_DEVICE_TYPE_PILL1_5 --- pillx_EVT1/platform.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pillx_EVT1/platform.h b/pillx_EVT1/platform.h index 58b37f86..fa495c76 100644 --- a/pillx_EVT1/platform.h +++ b/pillx_EVT1/platform.h @@ -6,14 +6,14 @@ #define ANT_ENABLE #endif -//#define BLE_ENABLE +#define BLE_ENABLE #define HW_REVISION 3 #define DEVICE_KEY_ADDRESS 0x20003FF0 //use hello's ant network key #define USE_HLO_ANT_NETWORK -//#define PILL_ANT_TYPE HLO_ANT_DEVICE_TYPE_PILL1_5 +#define PILL_ANT_TYPE HLO_ANT_DEVICE_TYPE_PILL1_5 #define configTOTAL_HEAP_SIZE 1024 From 5f6872c6ad39c1c3e2e62f9a41017e6476e1779d Mon Sep 17 00:00:00 2001 From: Ben Peng Date: Tue, 24 May 2016 12:26:38 -0700 Subject: [PATCH 6/6] change nrf_gpio back to clear and set for PROX_BOOST_ENABLE and PROX_VDD_EN respectively --- drivers/prox_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/prox_i2c.c b/drivers/prox_i2c.c index 7e2f19b1..2b0fc235 100644 --- a/drivers/prox_i2c.c +++ b/drivers/prox_i2c.c @@ -102,9 +102,9 @@ MSG_Status init_prox(void){ //tie vaux to vbat #ifdef PLATFORM_HAS_PROX nrf_gpio_cfg_output(PROX_BOOST_ENABLE); - nrf_gpio_pin_write(PROX_BOOST_ENABLE, 0); + nrf_gpio_pin_clear(PROX_BOOST_ENABLE); nrf_gpio_cfg_output(PROX_VDD_EN); - nrf_gpio_pin_write(PROX_VDD_EN, 1); + nrf_gpio_pin_set(PROX_VDD_EN); _reset_config(); _check_id(); _conf_prox();