Initial commit: MT firmware project
- BLE peripheral applications - dr_piezo and bladder_patch projects Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
158
project/ble_peripheral/ble_app_bladder_patch/LED_Parse.c
Normal file
158
project/ble_peripheral/ble_app_bladder_patch/LED_Parse.c
Normal file
@@ -0,0 +1,158 @@
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
#include "nrf_drv_spi.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "boards.h"
|
||||
#include "nrf_log.h"
|
||||
|
||||
#include "LED_Parse.h"
|
||||
#include "app_timer.h"
|
||||
#include "measurements.h"
|
||||
#include "main.h"
|
||||
//#include "fstorage.h"
|
||||
#include "mcp4725_i2c.h" //VGA
|
||||
#include "ir_i2c.h" //IR
|
||||
#include "debug_print.h"
|
||||
//#define LED_S1 0x50 //VGA LED1~5
|
||||
//#define LED_S2 0x50
|
||||
//#define LED_S3 0x51
|
||||
//#define LED_S4 0x52
|
||||
//#define LED_S5 0x53
|
||||
//#define LED_S6 0x51 //VGA
|
||||
//#define LED_S7 0x54
|
||||
//#define LED_S8 0x55
|
||||
//#define LED_S9 0x56
|
||||
//#define LED_S10 0x57 //LED 46~50
|
||||
|
||||
#define LED_S0 0x50
|
||||
#define LED_S1 0x51
|
||||
#define LED_S2 0x52
|
||||
#define LED_S3 0x53
|
||||
#define LED_S4 0x54
|
||||
#define LED_S5 0x55
|
||||
#define LED_S6 0x56
|
||||
#define LED_S7 0x57
|
||||
|
||||
|
||||
uint8_t LED_READ_ROM(uint8_t led_index)
|
||||
{
|
||||
// uint32_t err_code = NRF_SUCCESS;
|
||||
uint8_t addr=0xf0;
|
||||
uint8_t r_index;
|
||||
r_index = (led_index)%6;
|
||||
uint8_t r_data[10];
|
||||
uint8_t r_value=0;
|
||||
|
||||
|
||||
switch(led_index) {
|
||||
|
||||
|
||||
|
||||
case 0: case 1: case 2: case 3: case 4: case 5:
|
||||
r_value = ir_command_read(LED_S0, addr + r_index, r_data);
|
||||
break;
|
||||
|
||||
case 6: case 7: case 8: case 9: case 10: case 11:
|
||||
r_value = ir_command_read(LED_S1, addr + r_index, r_data);
|
||||
break;
|
||||
|
||||
case 12: case 13: case 14: case 15: case 16: case 17:
|
||||
r_value = ir_command_read(LED_S2, addr + r_index, r_data);
|
||||
break;
|
||||
|
||||
case 18: case 19: case 20: case 21: case 22: case 23:
|
||||
r_value = ir_command_read(LED_S3, addr + r_index, r_data);
|
||||
break;
|
||||
|
||||
case 24: case 25: case 26: case 27: case 28: case 29:
|
||||
r_value = ir_command_read(LED_S4, addr + r_index, r_data);
|
||||
break;
|
||||
|
||||
case 30: case 31: case 32: case 33: case 34: case 35:
|
||||
r_value = ir_command_read(LED_S5, addr + r_index, r_data);
|
||||
break;
|
||||
|
||||
case 36: case 37: case 38: case 39: case 40: case 41:
|
||||
r_value = ir_command_read(LED_S6, addr + r_index, r_data);
|
||||
break;
|
||||
|
||||
case 42: case 43: case 44: case 45: case 46: case 47:
|
||||
r_value = ir_command_read(LED_S7, addr + r_index, r_data);
|
||||
break;
|
||||
default:
|
||||
DBG_PRINTF("Invalid LED index\r\n");
|
||||
// err_code = NRF_ERROR_NOT_FOUND;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return r_value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ret_code_t LED_WRITE_ROM(uint8_t led_index, int16_t led_power)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
uint8_t addr=0xf0;
|
||||
uint8_t r_index;
|
||||
r_index = (led_index)%6;
|
||||
|
||||
|
||||
|
||||
switch(led_index) {
|
||||
|
||||
|
||||
|
||||
case 0: case 1: case 2: case 3: case 4: case 5:
|
||||
ir_command_write(LED_S0, addr + r_index, led_power);
|
||||
break;
|
||||
|
||||
case 6: case 7: case 8: case 9: case 10: case 11:
|
||||
ir_command_write(LED_S1, addr + r_index, led_power);
|
||||
break;
|
||||
|
||||
case 12: case 13: case 14: case 15: case 16: case 17:
|
||||
ir_command_write(LED_S2, addr + r_index, led_power);
|
||||
break;
|
||||
|
||||
case 18: case 19: case 20: case 21: case 22: case 23:
|
||||
ir_command_write(LED_S3, addr + r_index, led_power);
|
||||
break;
|
||||
|
||||
case 24: case 25: case 26: case 27: case 28: case 29:
|
||||
ir_command_write(LED_S4, addr + r_index, led_power);
|
||||
break;
|
||||
|
||||
case 30: case 31: case 32: case 33: case 34: case 35:
|
||||
ir_command_write(LED_S5, addr + r_index, led_power);
|
||||
break;
|
||||
|
||||
case 36: case 37: case 38: case 39: case 40: case 41:
|
||||
ir_command_write(LED_S6, addr + r_index, led_power);
|
||||
break;
|
||||
|
||||
case 42: case 43: case 44: case 45: case 46: case 47:
|
||||
ir_command_write(LED_S7, addr + r_index, led_power);
|
||||
break;
|
||||
default:
|
||||
DBG_PRINTF("Invalid LED index\r\n");
|
||||
err_code = NRF_ERROR_NOT_FOUND;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
DBG_PRINTF("write\r\n");
|
||||
return err_code;
|
||||
}
|
||||
|
||||
26
project/ble_peripheral/ble_app_bladder_patch/LED_Parse.h
Normal file
26
project/ble_peripheral/ble_app_bladder_patch/LED_Parse.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _LED_Parse_H_
|
||||
#define _LED_Parse_H_
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "app_timer.h"
|
||||
#include "measurements.h"
|
||||
#include "main.h"
|
||||
//#include "fstorage.h"
|
||||
#include "mcp4725_i2c.h" //VGA
|
||||
#include "ir_i2c.h" //IR
|
||||
|
||||
|
||||
uint8_t LED_READ_ROM(uint8_t led_index);
|
||||
|
||||
ret_code_t LED_WRITE_ROM(uint8_t led_index, int16_t led_power);
|
||||
|
||||
#endif /* PARSE */
|
||||
|
||||
299
project/ble_peripheral/ble_app_bladder_patch/ad5272_i2c.c
Normal file
299
project/ble_peripheral/ble_app_bladder_patch/ad5272_i2c.c
Normal file
@@ -0,0 +1,299 @@
|
||||
/*******************************************************************************
|
||||
* @file ad5272_i2c.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
/* board driver */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "nrfx_twi.h"
|
||||
|
||||
#include "nrf_delay.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "debug_print.h"
|
||||
|
||||
/* I2C number and slave address for AD5272 */
|
||||
#define AD5272_I2C_ADDR 0x2F /* Default I2C address if ADDR = GND */
|
||||
#define AD5272_MAX_SERIAL_WRITE 16
|
||||
|
||||
int16_t read_from_ad5272 = 0;
|
||||
uint16_t data_16_to_write = 0;
|
||||
|
||||
|
||||
/* TWI instance. */
|
||||
const nrfx_twi_t m_twi_ad5272 = NRFX_TWI_INSTANCE(AD5272_I2C_INSTANCE);
|
||||
|
||||
|
||||
void ad5272_i2c_uninit(void){
|
||||
nrfx_twi_disable(&m_twi_ad5272);
|
||||
nrfx_twi_uninit(&m_twi_ad5272);
|
||||
}
|
||||
|
||||
|
||||
void ad5272_i2c_init(void){
|
||||
ret_code_t err_code;
|
||||
|
||||
const nrfx_twi_config_t twi_ad5272_config = {
|
||||
.scl = AD5272_I2C_SCL_PIN,
|
||||
.sda = AD5272_I2C_SDA_PIN,
|
||||
.frequency = NRF_TWI_FREQ_400K,
|
||||
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
|
||||
};
|
||||
|
||||
err_code = nrfx_twi_init(&m_twi_ad5272, &twi_ad5272_config, NULL, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_twi_enable(&m_twi_ad5272);
|
||||
}
|
||||
|
||||
|
||||
ret_code_t ad5272_twi_tx( uint8_t device_id,
|
||||
uint8_t const * p_data,
|
||||
uint8_t length,
|
||||
bool no_stop)
|
||||
{
|
||||
ret_code_t ret;
|
||||
ret = nrfx_twi_tx(&m_twi_ad5272, device_id, p_data, length, no_stop);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t ad5272_twi_rx( uint8_t device_id,
|
||||
uint8_t * p_data,
|
||||
uint8_t length)
|
||||
{
|
||||
ret_code_t ret;
|
||||
ret = nrfx_twi_rx(&m_twi_ad5272, device_id, p_data, length);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int16_t ad5272_command_read(uint8_t command, uint8_t write_data)
|
||||
{
|
||||
uint8_t error_count = 0;
|
||||
uint8_t data_buff[1+AD5272_MAX_SERIAL_WRITE];
|
||||
uint16_t data_to_write = 0;
|
||||
int16_t read_data = 0;
|
||||
ret_code_t ret;
|
||||
|
||||
if (AD5272_50TP_WIPER_READ == command)
|
||||
{
|
||||
// shift the command over into bits 13:10
|
||||
data_to_write = command<<10;
|
||||
// also need to send 6-bit 50-TP location
|
||||
data_to_write |= write_data;
|
||||
}
|
||||
else if ( (AD5272_RDAC_READ == command) || (AD5272_50TP_LAST_USED == command) || (AD5272_CONTROL_READ == command) )
|
||||
{
|
||||
// command is in range and something possible to read
|
||||
// shift the command over into bits 13:10
|
||||
data_to_write = command<<10;
|
||||
}
|
||||
else
|
||||
{
|
||||
// It's either a bad command (out of range, > AD5272_SHUTDOWN), or its not a readable command
|
||||
// Bad command, we can't reasonably proceed
|
||||
error_count = 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* At this point, if error_count == 0 we have a valid read command
|
||||
*/
|
||||
if (0 == error_count)
|
||||
{
|
||||
memset(data_buff, 0, 1+AD5272_MAX_SERIAL_WRITE);
|
||||
data_buff[0] = (data_to_write >> 8); // ms byte to write
|
||||
data_buff[1] = data_to_write & 0x0FF; // ls byte to write
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ad5272_rx_1_buff[0]=0x%x, [1]=0x%x\r\n", data_buff[0], data_buff[1]);
|
||||
#endif
|
||||
ret = ad5272_twi_tx(AD5272_I2C_ADDR, data_buff, 2, true);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
ret = ad5272_twi_tx(AD5272_I2C_ADDR, data_buff, 2, true);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ad5272_ERR! i2c read-1\r\n");
|
||||
#endif
|
||||
//APP_ERROR_CHECK(ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
memset(data_buff, 0, 1+AD5272_MAX_SERIAL_WRITE);
|
||||
|
||||
ret = ad5272_twi_rx(AD5272_I2C_ADDR, data_buff, 2);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
ret = ad5272_twi_rx(AD5272_I2C_ADDR, data_buff, 2);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ad5272_ERR! i2c read-2\r\n");
|
||||
#endif
|
||||
//APP_ERROR_CHECK(ret);
|
||||
}
|
||||
}
|
||||
read_data = data_buff[0] << 8; // ms byte
|
||||
read_data |= data_buff[1]; // ls byte
|
||||
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ad5272_read_data = 0x%x\r\n",read_data);
|
||||
#endif
|
||||
}else{
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ad5272_read_data USELESS!!!\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
return read_data;
|
||||
}
|
||||
|
||||
|
||||
int8_t ad5272_command_write(uint8_t command, uint16_t write_data)
|
||||
{
|
||||
uint8_t error_count = 0;
|
||||
uint8_t data_buff[1+AD5272_MAX_SERIAL_WRITE];
|
||||
ret_code_t ret;
|
||||
|
||||
int8_t return_val = 0;
|
||||
uint16_t data_to_write = 0;
|
||||
|
||||
if (write_data > 0x3FF)
|
||||
{
|
||||
// data in bits 13:10 will clobber the command when we OR in write_datum16
|
||||
write_data &= 0x3FF; // clip off any bad high bits even though we are going to error out and not use them
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ad5272_ERR! Input Value wrong!\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if ( (AD5272_RDAC_WRITE == command) || (AD5272_CONTROL_WRITE == command) || (AD5272_SHUTDOWN == command) )
|
||||
{
|
||||
// these commands need to use data we send over
|
||||
// shift the command over into bits 13:10
|
||||
data_to_write = command<<10;
|
||||
// also need to send 10-bit or 8-bit wiper value, or 3 control bits, or shutdown bit
|
||||
data_to_write |= write_data;
|
||||
}
|
||||
else if ( (AD5272_50TP_WRITE == command) || (AD5272_RDAC_REFRESH == command) )
|
||||
{
|
||||
// shift the command over into bits 13:10
|
||||
data_to_write = command<<10;
|
||||
// no data needed
|
||||
}
|
||||
else
|
||||
{
|
||||
// It's either a bad command (out of range, > AD5272_SHUTDOWN), or its not a writeable command
|
||||
// Bad command, we can't reasonably proceed
|
||||
error_count = 100;
|
||||
}
|
||||
|
||||
// if no errors so far, command is valid and datum is too
|
||||
if (0 == error_count)
|
||||
{
|
||||
data_buff[0] = (data_to_write >> 8); // ms byte to write
|
||||
data_buff[1] = data_to_write & 0x0FF; // ls byte to write
|
||||
ret = ad5272_twi_tx(AD5272_I2C_ADDR, data_buff, 2, false);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
ret = ad5272_twi_tx(AD5272_I2C_ADDR, data_buff, 2, false);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ad5272_ERR! i2c write\r\n");
|
||||
#endif
|
||||
//APP_ERROR_CHECK(ret);
|
||||
return_val = NRF_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return return_val;
|
||||
}
|
||||
|
||||
|
||||
void ad5272_i2c_is_busy(void)
|
||||
{
|
||||
uint8_t buffer[3]; /* Addr + data */
|
||||
|
||||
buffer[0] = AD5272_COMMAND_NOP;
|
||||
buffer[1] = 0x00;
|
||||
|
||||
while(NRF_SUCCESS != ad5272_twi_tx(AD5272_I2C_ADDR, buffer, 1, false))
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ad5272_BUSY : is Busy\r\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
int8_t ad5272_write_and_read_rdac (uint16_t data_16_to_write)
|
||||
{
|
||||
ret_code_t ret;
|
||||
|
||||
ret = ad5272_command_write(AD5272_CONTROL_WRITE, AD5272_RDAC_WIPER_WRITE_ENABLE); /* Write Enable */
|
||||
ret |= ad5272_command_write(AD5272_RDAC_WRITE, data_16_to_write); /* Write Data */
|
||||
ret |= ad5272_command_write(AD5272_CONTROL_WRITE, 0x00); /* Write Disable & Use 50tp value */
|
||||
|
||||
read_from_ad5272 = ad5272_command_read(AD5272_RDAC_READ, 0x00);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int16_t ad5272_read_rdac (void)
|
||||
{
|
||||
read_from_ad5272 = ad5272_command_read(AD5272_RDAC_READ, 0x00);
|
||||
|
||||
return read_from_ad5272;
|
||||
}
|
||||
|
||||
|
||||
int8_t ad5272_write_rdac (uint16_t data_16_to_write)
|
||||
{
|
||||
ret_code_t ret;
|
||||
|
||||
ret = ad5272_command_write(AD5272_CONTROL_WRITE, AD5272_RDAC_WIPER_WRITE_ENABLE); /* Write Enable */
|
||||
ret |= ad5272_command_write(AD5272_RDAC_WRITE, data_16_to_write); /* Write Data */
|
||||
ret |= ad5272_command_write(AD5272_CONTROL_WRITE, 0x00); /* Write Disable & Use 50tp value */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void ad5272_RDAC_refresh(void)
|
||||
{
|
||||
ad5272_command_write(AD5272_RDAC_REFRESH, 0x00);
|
||||
|
||||
ad5272_i2c_is_busy();
|
||||
}
|
||||
|
||||
|
||||
void ad5272_shutdown_mode(void)
|
||||
{
|
||||
ad5272_command_write(AD5272_SHUTDOWN, 0x01);
|
||||
|
||||
ad5272_i2c_is_busy();
|
||||
}
|
||||
|
||||
|
||||
void ad5272_normal_mode(void)
|
||||
{
|
||||
ad5272_command_write(AD5272_SHUTDOWN, 0x00);
|
||||
|
||||
ad5272_i2c_is_busy();
|
||||
}
|
||||
|
||||
|
||||
102
project/ble_peripheral/ble_app_bladder_patch/ad5272_i2c.h
Normal file
102
project/ble_peripheral/ble_app_bladder_patch/ad5272_i2c.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/*******************************************************************************
|
||||
* @file ad5272_i2c.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _ADA5272_I2C_H_
|
||||
#define _ADA5272_I2C_H_
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
|
||||
|
||||
#define AD5272_I2C_INSTANCE 1 /**< I2C instance index. */
|
||||
#define AD5272_I2C_SDA_PIN NRF_GPIO_PIN_MAP(0,10)
|
||||
#define AD5272_I2C_SCL_PIN NRF_GPIO_PIN_MAP(0,9)
|
||||
|
||||
/**
|
||||
* COMMAND CONSTANTS
|
||||
* Commands are 16-bit writes: bits 15:14 are 0s
|
||||
* Bits 13:10 are the command value below
|
||||
* Bits 9:0 are data for the command, but not all bits are used with all commands
|
||||
*/
|
||||
|
||||
// The NOP command is included for completeness. It is a valid I2C operation.
|
||||
#define AD5272_COMMAND_NOP 0x00 // Do nothing. Why you would want to do this I don't know
|
||||
|
||||
// write the 10 or 8 data bits to the RDAC wiper register (it must be unlocked first)
|
||||
#define AD5272_RDAC_WRITE 0x01
|
||||
|
||||
#define AD5272_RDAC_READ 0x02 // read the RDAC wiper register
|
||||
|
||||
#define AD5272_50TP_WRITE 0x03 // store RDAC setting to 50-TP
|
||||
|
||||
// SW reset: refresh RDAC with last 50-TP stored value
|
||||
// If not 50-TP value, reset to 50% I think???
|
||||
// data bits are all dont cares
|
||||
#define AD5272_RDAC_REFRESH 0x04 // TODO refactor this to AD5272_SOFT_RESET
|
||||
|
||||
// read contents of 50-TP in next frame, at location in data bits 5:0,
|
||||
// see Table 16 page 22 Rev D datasheet
|
||||
// location 0x0 is reserved, 0x01 is first programmed wiper location, 0x32 is 50th programmed wiper location
|
||||
#define AD5272_50TP_WIPER_READ 0x05
|
||||
|
||||
/**
|
||||
* Read contents of last-programmed 50-TP location
|
||||
* This is the location used in SW Reset command 4 or on POR
|
||||
*/
|
||||
#define AD5272_50TP_LAST_USED 0x06
|
||||
|
||||
#define AD5272_CONTROL_WRITE 0x07 // data bits 2:0 are the control bits
|
||||
|
||||
#define AD5272_CONTROL_READ 0x08 // data bits all dont cares
|
||||
|
||||
#define AD5272_SHUTDOWN 0x09 // data bit 0 set = shutdown, cleared = normal mode
|
||||
|
||||
|
||||
/**
|
||||
* Control bits are three bits written with command 7
|
||||
*/
|
||||
// enable writing to the 50-TP memory by setting this control bit C0
|
||||
// default is cleared so 50-TP writing is disabled
|
||||
// only 50 total writes are possible!
|
||||
#define AD5272_50TP_WRITE_ENABLE 0x01
|
||||
|
||||
// enable writing to volatile RADC wiper by setting this control bit C1
|
||||
// otherwise it is frozen to the value in the 50-TP memory
|
||||
// default is cleared, can't write to the wiper
|
||||
#define AD5272_RDAC_WIPER_WRITE_ENABLE 0x02
|
||||
|
||||
// enable high precision calibration by clearing this control bit C2
|
||||
// set this bit to disable high accuracy mode (dunno why you would want to)
|
||||
// default is 0 = emabled
|
||||
#define AD5272_RDAC_CALIB_DISABLE 0x04
|
||||
|
||||
// 50TP memory has been successfully programmed if this bit is set
|
||||
#define AD5272_50TP_WRITE_SUCCESS 0x08
|
||||
|
||||
#define AD5272_NORMAL_MODE 0x01
|
||||
#define AD5272_SHUTDOWN_MODE 0x01
|
||||
|
||||
void ad5272_i2c_uninit(void);
|
||||
void ad5272_i2c_init(void);
|
||||
int16_t ad5272_command_read(uint8_t command, uint8_t write_data);
|
||||
int8_t ad5272_command_write(uint8_t command, uint16_t write_data);
|
||||
void ad5272_i2c_is_busy(void);
|
||||
int8_t ad5272_write_and_read_rdac (uint16_t data_16_to_write);
|
||||
int16_t ad5272_read_rdac (void);
|
||||
int8_t ad5272_write_rdac (uint16_t data_16_to_write);
|
||||
|
||||
void read_all_50tp (void);
|
||||
void ad5272_RDAC_refresh(void);
|
||||
void ad5272_shutdown_mode(void);
|
||||
void ad5272_normal_mode(void);
|
||||
|
||||
#endif /* !_ADA5272_I2C_H_ */
|
||||
|
||||
112
project/ble_peripheral/ble_app_bladder_patch/ada2200_spi.c
Normal file
112
project/ble_peripheral/ble_app_bladder_patch/ada2200_spi.c
Normal file
@@ -0,0 +1,112 @@
|
||||
/*******************************************************************************
|
||||
* @file ada2200_spi.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
#include "nrf_drv_spi.h"
|
||||
#include "nrf_delay.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "ada2200_spi.h"
|
||||
|
||||
|
||||
static const nrf_drv_spi_t spi_ada2200 = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */
|
||||
|
||||
//static uint8_t ada2200_startR[] ={ 0x00, 0x00, 0x81 }; /* {addr 16bit, data}, Reset for Defaults */
|
||||
|
||||
static uint8_t ada2200_start0[] ={ 0x00, 0x00, 0x18 }; /* {addr 16bit, data}, Set SDIO input only, Activate SDO */
|
||||
static uint8_t ada2200_start1[] ={ 0x00, 0x2B, 0x06 }; /* {addr 16bit, data}, Clock Configuration */
|
||||
static uint8_t ada2200_start2[] ={ 0x00, 0x2A, 0x18 }; /* {addr 16bit, data}, Enable Mixer, Select SDO output for Pin 13, OFF RCLK. */
|
||||
static uint8_t ada2200_start3[] ={ 0x00, 0x29, 0x23 }; /* 0x27 {addr 16bit, data}, Disable SYNCO output, Select SYNCO edge location (Sync timing adjustment) */
|
||||
static uint8_t ada2200_start4[] ={ 0x00, 0x2C, 0x01 }; /* {addr 16bit, data}, Enable RCLK output */
|
||||
|
||||
static uint8_t ada2200_stop0[] ={ 0x00, 0x00, 0x18 }; /* {addr 16bit, data}, Set SDIO input only, Activate SDO */
|
||||
static uint8_t ada2200_stop1[] ={ 0x00, 0x2B, 0x06 }; /* {addr 16bit, data}, Clock Configuration */
|
||||
static uint8_t ada2200_stop2[] ={ 0x00, 0x2A, 0x10 }; /* {addr 16bit, data}, Enable Mixer, Select SDO output for Pin 13, OFF RCLK. */
|
||||
static uint8_t ada2200_stop3[] ={ 0x00, 0x29, 0x01 }; /* 0x07 {addr 16bit, data}, Disable SYNCO output, Select SYNCO edge location (Sync timing adjustment) */
|
||||
static uint8_t ada2200_stop4[] ={ 0x00, 0x2C, 0x00 }; /* {addr 16bit, data}, Enable RCLK output */
|
||||
|
||||
static uint8_t m_tx_buf[3]; /**< TX buffer. */
|
||||
static uint8_t m_length = sizeof(m_tx_buf); /**< Transfer length. */
|
||||
|
||||
|
||||
void ada2200_spi_write(const void * data, size_t size)
|
||||
{
|
||||
memcpy(m_tx_buf, data, size);
|
||||
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi_ada2200, m_tx_buf, size, NULL, 0));
|
||||
}
|
||||
|
||||
|
||||
extern void ada2200_start(void)
|
||||
{
|
||||
//ada2200_spi_write(ada2200_startR, m_length);
|
||||
|
||||
ada2200_spi_write(ada2200_start0, m_length);
|
||||
nrf_delay_us(2);
|
||||
ada2200_spi_write(ada2200_start1, m_length);
|
||||
nrf_delay_us(2);
|
||||
ada2200_spi_write(ada2200_start2, m_length);
|
||||
nrf_delay_us(2);
|
||||
ada2200_spi_write(ada2200_start3, m_length);
|
||||
nrf_delay_us(2);
|
||||
ada2200_spi_write(ada2200_start4, m_length);
|
||||
nrf_delay_us(2);
|
||||
}
|
||||
|
||||
|
||||
extern void ada2200_stop(void)
|
||||
{
|
||||
ada2200_spi_write(ada2200_stop0, m_length);
|
||||
nrf_delay_us(2);
|
||||
ada2200_spi_write(ada2200_stop1, m_length);
|
||||
nrf_delay_us(2);
|
||||
ada2200_spi_write(ada2200_stop2, m_length);
|
||||
nrf_delay_us(2);
|
||||
ada2200_spi_write(ada2200_stop3, m_length);
|
||||
nrf_delay_us(2);
|
||||
ada2200_spi_write(ada2200_stop4, m_length);
|
||||
nrf_delay_us(2);
|
||||
}
|
||||
|
||||
|
||||
extern void ada2200_init(void)
|
||||
{
|
||||
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
|
||||
spi_config.ss_pin = SPI_CS_PIN;
|
||||
spi_config.miso_pin = SPI_MISO_PIN; /* Not USed */
|
||||
spi_config.mosi_pin = SPI_MOSI_PIN;
|
||||
spi_config.sck_pin = SPI_SCLK_PIN;
|
||||
spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
|
||||
spi_config.mode = NRF_DRV_SPI_MODE_0;
|
||||
spi_config.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST;
|
||||
|
||||
APP_ERROR_CHECK(nrf_drv_spi_init(&spi_ada2200, &spi_config, NULL, NULL));
|
||||
}
|
||||
|
||||
|
||||
extern void ada2200_uninit(void)
|
||||
{
|
||||
nrf_drv_spi_uninit(&spi_ada2200);
|
||||
|
||||
/* If SPIM2 is used: */
|
||||
*(volatile uint32_t *)0x40023FFC = 0;
|
||||
*(volatile uint32_t *)0x40023FFC;
|
||||
*(volatile uint32_t *)0x40023FFC = 1;
|
||||
|
||||
nrf_gpio_cfg_default(SPI_CS_PIN);
|
||||
nrf_gpio_cfg_default(SPI_MISO_PIN);
|
||||
nrf_gpio_cfg_default(SPI_MOSI_PIN);
|
||||
nrf_gpio_cfg_default(SPI_SCLK_PIN);
|
||||
}
|
||||
|
||||
|
||||
25
project/ble_peripheral/ble_app_bladder_patch/ada2200_spi.h
Normal file
25
project/ble_peripheral/ble_app_bladder_patch/ada2200_spi.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* @file ada2200_spi.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _ADA2200_SPI_H_
|
||||
#define _ADA2200_SPI_H_
|
||||
|
||||
#define SPI_INSTANCE 2 /**< SPI instance index. */
|
||||
|
||||
#define SPI_MOSI_PIN 16
|
||||
#define SPI_MISO_PIN 15 /* Not Used */
|
||||
#define SPI_SCLK_PIN 14
|
||||
#define SPI_CS_PIN 13
|
||||
|
||||
extern void ada2200_start(void);
|
||||
extern void ada2200_stop(void);
|
||||
extern void ada2200_init(void);
|
||||
extern void ada2200_uninit(void);
|
||||
|
||||
#endif //_ADA2200_SPI_H_
|
||||
|
||||
317
project/ble_peripheral/ble_app_bladder_patch/battery_saadc.c
Normal file
317
project/ble_peripheral/ble_app_bladder_patch/battery_saadc.c
Normal file
@@ -0,0 +1,317 @@
|
||||
/*******************************************************************************
|
||||
* @file battery_saadc.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "ble_nus.h"
|
||||
#include "nrf_log.h"
|
||||
#include "main.h"
|
||||
#include "app_timer.h"
|
||||
//#include "fstorage.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "main_timer.h"
|
||||
#include "meas_pd_48.h"
|
||||
#include <cmd_parse.h>
|
||||
#include "debug_print.h"
|
||||
#define BATTERY_REF_VOLTAGE_IN_MILLIVOLTS 600 /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
|
||||
#define BATTERY_PRE_SCALING_COMPENSATION 6 /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
|
||||
#define BATTERY_ADC_RES_10BITS 1023 /**< Maximum digital value for 10-bit ADC conversion. */
|
||||
//#define PRESSURE_RESULT_IN_MILLI_VOLTS(adc) ((adc * 3600) / 1023)
|
||||
|
||||
#define PRESSURE_OFFSET_DEFAULT 0 // ?? offset. ?? ? ??? ?? ??.
|
||||
#define MV_PER_ADC_STEP 805 // ? 0.805mV per 1 LSB (nRF 12bit + scaling)
|
||||
/**@brief Macro to convert the result of ADC conversion in millivolts.
|
||||
*
|
||||
* @param[in] ADC_VALUE ADC result.
|
||||
*
|
||||
* @retval Result converted to millivolts.
|
||||
*/
|
||||
#define BATTERY_RESULT_IN_MILLI_VOLTS(ADC_VALUE)\
|
||||
((((ADC_VALUE) * BATTERY_REF_VOLTAGE_IN_MILLIVOLTS) / BATTERY_ADC_RES_10BITS) * BATTERY_PRE_SCALING_COMPENSATION)
|
||||
|
||||
static nrf_saadc_value_t adc_bufs[2];
|
||||
static int16_t pressure_adc_buf[2]; //cj add 25/11/19
|
||||
static uint16_t convert_adc_to_mV(int16_t raw_adc); //cj add 25/11/19
|
||||
|
||||
APP_TIMER_DEF(m_battery_loop_timer_id);
|
||||
#define BATTERY_LOOP_INTERVAL 5000
|
||||
|
||||
bool low_battery_check = false;
|
||||
extern bool info4; //cmd_parse
|
||||
|
||||
// cj add edit 25/11/24
|
||||
extern volatile uint16_t info_p1;
|
||||
extern volatile uint16_t info_p2;
|
||||
|
||||
|
||||
extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
extern bool go_device_power_off;
|
||||
extern volatile bool processing;
|
||||
|
||||
extern which_cmd_t cmd_type_t;
|
||||
|
||||
extern uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] ;
|
||||
extern volatile uint16_t info_batt; //48_c
|
||||
extern bool go_temp; //
|
||||
extern bool go_batt; //cmd_parse
|
||||
|
||||
extern bool motion_raw_data_enabled ;
|
||||
extern bool ble_got_new_data;
|
||||
extern bool motion_data_once ;
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static uint16_t convert_adc_to_mV(int16_t raw_adc)
|
||||
{
|
||||
if (raw_adc < 0)
|
||||
raw_adc = 0;
|
||||
|
||||
int32_t mv = (int32_t)raw_adc * MV_PER_ADC_STEP; // ?: 805 uV
|
||||
mv /= 1000;
|
||||
|
||||
// ===== (3) 0~3500mV ??? ???? ?? ?? =====
|
||||
if (mv < 0)
|
||||
mv = 0;
|
||||
|
||||
if (mv > 3500)
|
||||
mv = 3500;
|
||||
|
||||
|
||||
return (uint16_t)mv;
|
||||
}
|
||||
void pressure_all_event_handler(nrf_drv_saadc_evt_t const * p_event)
|
||||
{
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
int16_t p1_adc = p_event->data.done.p_buffer[0]; // AIN7
|
||||
int16_t p2_adc = p_event->data.done.p_buffer[1]; // AIN4
|
||||
|
||||
|
||||
uint16_t p1_mV = convert_adc_to_mV(p1_adc);
|
||||
uint16_t p2_mV = convert_adc_to_mV(p2_adc);
|
||||
|
||||
// PD Full mode(info4=true)When info_p1/info_p2 to Update
|
||||
if(info4 == true)
|
||||
{
|
||||
info_p1 = p1_mV;
|
||||
info_p2 = p2_mV;
|
||||
}
|
||||
// Re-buffer
|
||||
APP_ERROR_CHECK(nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 2));
|
||||
|
||||
// uninit
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
nrf_drv_saadc_channel_uninit(1);
|
||||
|
||||
// UART send
|
||||
|
||||
if(cmd_type_t == CMD_UART)
|
||||
{
|
||||
DBG_PRINTF("P1:%d P2:%d\r\n", p1_mV, p2_mV);
|
||||
}
|
||||
else if(cmd_type_t == CMD_BLE && info4 == false)
|
||||
{
|
||||
DBG_PRINTF("P1:%d P2:%d\r\n", p1_mV, p2_mV);
|
||||
// uint16_t len = sprintf((char*)ble_bin_buffer,
|
||||
// "rpn:%04x,%04x", p1_mV, p2_mV);
|
||||
uint16_t result_data[2];
|
||||
result_data[0] = p1_mV;
|
||||
result_data[1] = p2_mV;
|
||||
format_data(ble_bin_buffer, "rpn:", result_data,2);
|
||||
binary_tx_handler(ble_bin_buffer,4);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void battery_event_handler( nrf_drv_saadc_evt_t const * p_event )
|
||||
{
|
||||
|
||||
static uint8_t low_battery_cnt = 0;
|
||||
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
nrf_saadc_value_t register_val = 0;
|
||||
uint16_t batt_lvl_in_milli_volt_0 = 0;
|
||||
uint16_t batt_lvl_in_milli_volt_1 = 0;
|
||||
uint32_t err_code = 0;
|
||||
|
||||
register_val = p_event->data.done.p_buffer[0];
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 1);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
|
||||
batt_lvl_in_milli_volt_0 = BATTERY_RESULT_IN_MILLI_VOLTS(register_val);
|
||||
batt_lvl_in_milli_volt_1 = (batt_lvl_in_milli_volt_0) *1.42;
|
||||
if(low_battery_check == true) {
|
||||
|
||||
low_battery_check = false;
|
||||
|
||||
if(batt_lvl_in_milli_volt_1 <= LOW_BATTERY_VOLTAGE) {
|
||||
if(low_battery_cnt >= 10) {
|
||||
low_battery_cnt = 0;
|
||||
/*go to power off and fds save */
|
||||
DBG_PRINTF("Save FDS parameters and then Power OFF\r\n");
|
||||
go_device_power_off = true;
|
||||
main_timer_start();
|
||||
}else{
|
||||
low_battery_cnt++;
|
||||
DBG_PRINTF("WARNING!!! low_battery cnt = %d, Batt = %d(mV)\r\n", low_battery_cnt, batt_lvl_in_milli_volt_1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (info4 == true){
|
||||
|
||||
info_batt = batt_lvl_in_milli_volt_1;
|
||||
DBG_PRINTF("INFOTn%d\r\n\r\n", batt_lvl_in_milli_volt_1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
DBG_PRINTF("Tn%d\r\n\r\n", batt_lvl_in_milli_volt_1);
|
||||
} else if(cmd_type_t == CMD_BLE) {
|
||||
|
||||
single_format_data(ble_bin_buffer, "rsn:", batt_lvl_in_milli_volt_1);
|
||||
|
||||
binary_tx_handler(ble_bin_buffer,3);
|
||||
//data_tx_handler(ble_tx_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (info4 == true){
|
||||
go_batt =false;
|
||||
go_temp = true;
|
||||
main_timer_start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for configuring ADC to do battery level conversion.
|
||||
*/
|
||||
static void battery_configure(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_saadc_init(NULL, battery_event_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_saadc_channel_config_t config =
|
||||
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
|
||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(&adc_bufs[0], 1);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(&adc_bufs[1], 1);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
void pressure_all_configure(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_saadc_init(NULL, pressure_all_event_handler);
|
||||
if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) {
|
||||
DBG_PRINTF("SAADC init err=%d\r\n", err_code);
|
||||
return;
|
||||
}
|
||||
|
||||
nrf_saadc_channel_config_t ch0_cfg =
|
||||
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN7);
|
||||
nrf_saadc_channel_config_t ch1_cfg =
|
||||
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4);
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(0, &ch0_cfg);
|
||||
if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) {
|
||||
DBG_PRINTF("SAADC ch0 init err=%d\r\n", err_code);
|
||||
return;
|
||||
}
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(1, &ch1_cfg);
|
||||
if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) {
|
||||
DBG_PRINTF("SAADC ch1 init err=%d\r\n", err_code);
|
||||
return;
|
||||
}
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(pressure_adc_buf, 2);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
DBG_PRINTF("SAADC buf conv err=%d\r\n", err_code);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void battery_level_meas(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
battery_configure();
|
||||
err_code = nrf_drv_saadc_sample();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
|
||||
}
|
||||
void pressure_all_level_meas(void) //add cj add 25/11/19
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
pressure_all_configure(); // 2
|
||||
|
||||
err_code = nrf_drv_saadc_sample();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
void battery_loop(void * p_context) /* For 1sec */
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
if(processing==true)
|
||||
{
|
||||
processing = false ; // add 20241218
|
||||
//low_battery_check = true;
|
||||
return;}
|
||||
else{
|
||||
low_battery_check = true;
|
||||
battery_level_meas();
|
||||
}
|
||||
}
|
||||
|
||||
void battery_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_battery_loop_timer_id, APP_TIMER_TICKS(BATTERY_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void battery_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_battery_loop_timer_id));
|
||||
}
|
||||
|
||||
void battery_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_battery_loop_timer_id, APP_TIMER_MODE_REPEATED, battery_loop));
|
||||
}
|
||||
|
||||
|
||||
22
project/ble_peripheral/ble_app_bladder_patch/battery_saadc.h
Normal file
22
project/ble_peripheral/ble_app_bladder_patch/battery_saadc.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*******************************************************************************
|
||||
* @file battery_saadc.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _BATTERY_SAADC_H_
|
||||
#define _BATTERY_SAADC_H_
|
||||
|
||||
#define LOW_BATTERY_VOLTAGE 3100 /* Low Battery 임계값 */
|
||||
|
||||
|
||||
void battery_level_meas(void);
|
||||
void pressure_all_level_meas(void);
|
||||
void battery_timer_start(void);
|
||||
void battery_timer_stop(void);
|
||||
void battery_timer_init(void);
|
||||
|
||||
#endif //_BATTERY_SAADC_H_
|
||||
|
||||
163
project/ble_peripheral/ble_app_bladder_patch/cat_i2c.c
Normal file
163
project/ble_peripheral/ble_app_bladder_patch/cat_i2c.c
Normal file
@@ -0,0 +1,163 @@
|
||||
/*******************************************************************************
|
||||
* @file cat_i2c.c
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "nrfx_twi.h"
|
||||
#include "nrf_drv_twi.h"
|
||||
|
||||
#include "nrf_delay.h"
|
||||
#include "cat_i2c.h"
|
||||
|
||||
|
||||
|
||||
#define CAT_I2C_ADDR 0x50
|
||||
#define MAX_SERIAL_WRITE 16
|
||||
|
||||
//int16_t read_from_DS3930 = 0;
|
||||
//uint16_t data_160_to_write = 0;
|
||||
//static volatile bool m_xfer_done = false;
|
||||
|
||||
/* TWI instance. */
|
||||
//const nrfx_twi_t m_twi_ir = NRFX_TWI_INSTANCE(IR_I2C_INSTANCE);
|
||||
const nrf_drv_twi_t m_twi_cat = NRF_DRV_TWI_INSTANCE (CAT_I2C_INSTANCE);
|
||||
//void twi_handler(nrfx_twi_evt_t const * p_event, void * p_context)
|
||||
//{
|
||||
// m_xfer_done = true;
|
||||
//}
|
||||
//void ir_irq_init(void){
|
||||
// ret_code_t err_code;
|
||||
|
||||
// /* Initialize int pin */
|
||||
// if (!nrfx_gpiote_is_init())
|
||||
// {
|
||||
// err_code = nrfx_gpiote_init();
|
||||
// APP_ERROR_CHECK(err_code);
|
||||
// }
|
||||
|
||||
// nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
|
||||
// in_config.pull = NRF_GPIO_PIN_PULLDOWN;
|
||||
|
||||
// err_code = nrfx_gpiote_in_init(ADA2200_SYNCO_PIN, &in_config, NULL);
|
||||
// APP_ERROR_CHECK(err_code);
|
||||
|
||||
// nrfx_gpiote_in_event_enable(ADA2200_SYNCO_PIN, true);
|
||||
//}
|
||||
|
||||
|
||||
//void ir_irq_uninit(void){
|
||||
|
||||
// nrfx_gpiote_in_event_disable(ADA2200_SYNCO_PIN);
|
||||
// nrfx_gpiote_in_uninit(ADA2200_SYNCO_PIN);
|
||||
//}
|
||||
void cat_i2c_uninit(void){
|
||||
nrf_drv_twi_disable(&m_twi_cat);
|
||||
nrf_drv_twi_uninit(&m_twi_cat);
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
void cat_i2c_init(void){
|
||||
ret_code_t err_code;
|
||||
|
||||
const nrf_drv_twi_config_t twi_cat_config = {
|
||||
.scl = CAT_I2C_SCL_PIN,
|
||||
.sda = CAT_I2C_SDA_PIN,
|
||||
.frequency = NRF_DRV_TWI_FREQ_100K,
|
||||
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
|
||||
.clear_bus_init = false
|
||||
};
|
||||
|
||||
err_code = nrf_drv_twi_init(&m_twi_cat, &twi_cat_config, NULL, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_drv_twi_enable(&m_twi_cat);
|
||||
// ir_irq_init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t cat_command_read(uint8_t device_id, uint8_t address, uint8_t *data)
|
||||
{
|
||||
uint8_t read_data = 0;
|
||||
char adata[8];
|
||||
ret_code_t err_code;
|
||||
//address = 1|(address<<1);
|
||||
address = (address & 0xFF);
|
||||
err_code = nrf_drv_twi_tx(&m_twi_cat, device_id, &address, 1, true);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
// Handle error
|
||||
// return;
|
||||
}
|
||||
|
||||
err_code = nrf_drv_twi_rx(&m_twi_cat, device_id, data, 8);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
// Handle error
|
||||
return 0;
|
||||
}
|
||||
read_data = data[0];
|
||||
memcpy(adata,data,8);
|
||||
printf("Data %s . \r\n", adata);
|
||||
return read_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cat_command_write(uint8_t device_id, uint8_t address, uint8_t *data)
|
||||
{
|
||||
//uint16_t data_to_write = 0;
|
||||
|
||||
uint8_t buffer[9]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
|
||||
address = (address & 0xFF);
|
||||
|
||||
//buffer[0] = 0x00;
|
||||
buffer[0] = (address);
|
||||
// buffer[1] =(data & 0xFF);
|
||||
// buffer[2] = data1+1;
|
||||
// buffer[3] = data1+2;
|
||||
// buffer[4] = data1+3;
|
||||
// buffer[5] = data1+4;
|
||||
// buffer[6] = data1+5;
|
||||
memcpy(&buffer[1], data, 8 );
|
||||
|
||||
|
||||
ret_code_t err_code;
|
||||
//err_code = nrf_drv_twi_tx(&m_twi_ir, device_id, 0x00, 1, false);
|
||||
|
||||
err_code = nrf_drv_twi_tx(&m_twi_cat, device_id, buffer, 9, false);
|
||||
|
||||
|
||||
printf("Data %x %x %x %x. \r\n", buffer[0], buffer[1], buffer[2], buffer[3]);
|
||||
printf("Data %s. \r\n", buffer);
|
||||
|
||||
//err_code = nrf_drv_twi_tx(&m_twi_ir, device_id, buffer, 6, false);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
|
||||
printf("TWI Error.\r\n");
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
50
project/ble_peripheral/ble_app_bladder_patch/cat_i2c.h
Normal file
50
project/ble_peripheral/ble_app_bladder_patch/cat_i2c.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*******************************************************************************
|
||||
* @file ir_i2c.h
|
||||
* @date 2024-07-17
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CAT_I2C_H_
|
||||
#define _CAT_I2C_H_
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
|
||||
|
||||
#define CAT_I2C_INSTANCE 0 /**< I2C instance index. */
|
||||
#define CAT_I2C_SDA_PIN NRF_GPIO_PIN_MAP(1,15)
|
||||
#define CAT_I2C_SCL_PIN NRF_GPIO_PIN_MAP(1,14)
|
||||
//#define IR_I2C_SDA_PIN NRF_GPIO_PIN_MAP(0,25)
|
||||
//#define IR_I2C_SCL_PIN NRF_GPIO_PIN_MAP(1,0)
|
||||
/**
|
||||
* COMMAND CONSTANTS
|
||||
* Commands are 16-bit writes: bits 15:14 are 0s
|
||||
* Bits 13:10 are the command value below
|
||||
* Bits 9:0 are data for the command, but not all bits are used with all commands
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cat_i2c_uninit(void);
|
||||
void cat_i2c_init(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t cat_command_read(uint8_t device_id, uint8_t address, uint8_t *data);
|
||||
void cat_command_write(uint8_t device_id, uint8_t address, uint8_t *data);
|
||||
|
||||
|
||||
|
||||
#endif /* !_ADA5272_I2C_H_ */
|
||||
|
||||
522
project/ble_peripheral/ble_app_bladder_patch/cat_interface.c
Normal file
522
project/ble_peripheral/ble_app_bladder_patch/cat_interface.c
Normal file
@@ -0,0 +1,522 @@
|
||||
/*******************************************************************************
|
||||
* @file cat_interface.c
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
/* board driver */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "nrfx_twi.h"
|
||||
#include "nrf_crypto.h"
|
||||
#include "nrf_crypto_aes.h"
|
||||
|
||||
#include "nrf_drv_twi.h"
|
||||
#include "system_interface.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "cat_interface.h"
|
||||
#include "debug_print.h"
|
||||
/* I2C number and slave address for INV device */
|
||||
#define ICM_I2C_ADDR 0x68
|
||||
#define INV_MAX_SERIAL_WRITE 16
|
||||
|
||||
|
||||
#define EEPROM_I2C_ADDRESS 0x50
|
||||
#define EEPROM_PAGE_SIZE 64
|
||||
#define EEPROM_INSTANCE 0
|
||||
|
||||
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
|
||||
static uint8_t aes_key[16] = {
|
||||
0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
|
||||
0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81
|
||||
};
|
||||
|
||||
static uint8_t aes_iv[16] = { 0 }; // Fixed IV for simplicity
|
||||
|
||||
|
||||
|
||||
|
||||
const nrfx_twi_t m_eeprom = NRFX_TWI_INSTANCE(EEPROM_INSTANCE);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ret_code_t encrypt_data(const uint8_t *input, size_t length, uint8_t *output, size_t *output_len) {
|
||||
nrf_crypto_aes_context_t aes_ctx;
|
||||
size_t padded_len = ((length + AES_BLOCK_SIZE - 1) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
|
||||
|
||||
uint8_t buffer[padded_len];
|
||||
memcpy(buffer, input, length);
|
||||
memset(&buffer[length], 0, padded_len - length); // Zero padding
|
||||
|
||||
ret_code_t err = nrf_crypto_aes_init(&aes_ctx, &g_nrf_crypto_aes_cbc_128_info, NRF_CRYPTO_ENCRYPT);
|
||||
VERIFY_SUCCESS(err);
|
||||
|
||||
err = nrf_crypto_aes_key_set(&aes_ctx, aes_key);
|
||||
VERIFY_SUCCESS(err);
|
||||
|
||||
err = nrf_crypto_aes_iv_set(&aes_ctx, aes_iv);
|
||||
VERIFY_SUCCESS(err);
|
||||
|
||||
*output_len = padded_len;
|
||||
err = nrf_crypto_aes_finalize(&aes_ctx, buffer, padded_len, output, output_len);
|
||||
return err;
|
||||
}
|
||||
|
||||
ret_code_t decrypt_data(const uint8_t *input, size_t length, uint8_t *output) {
|
||||
nrf_crypto_aes_context_t aes_ctx;
|
||||
uint8_t input_copy[length];
|
||||
memcpy(input_copy, input, length);
|
||||
|
||||
ret_code_t err = nrf_crypto_aes_init(&aes_ctx, &g_nrf_crypto_aes_cbc_128_info, NRF_CRYPTO_DECRYPT);
|
||||
VERIFY_SUCCESS(err);
|
||||
|
||||
err = nrf_crypto_aes_key_set(&aes_ctx, aes_key);
|
||||
VERIFY_SUCCESS(err);
|
||||
|
||||
err = nrf_crypto_aes_iv_set(&aes_ctx, aes_iv);
|
||||
VERIFY_SUCCESS(err);
|
||||
|
||||
size_t output_len = length;
|
||||
err = nrf_crypto_aes_finalize(&aes_ctx, input_copy, length, output, &output_len);
|
||||
return err;
|
||||
}
|
||||
|
||||
ret_code_t eeprom_write_encrypted(uint16_t mem_address, const uint8_t *plaintext, size_t length) {
|
||||
uint8_t encrypted_buf[256]; // Adjust if needed
|
||||
size_t encrypted_len = 0;
|
||||
|
||||
ret_code_t err = encrypt_data(plaintext, length, encrypted_buf, &encrypted_len);
|
||||
VERIFY_SUCCESS(err);
|
||||
|
||||
return eeprom_write_bytes(mem_address, encrypted_buf, encrypted_len);
|
||||
}
|
||||
|
||||
|
||||
ret_code_t eeprom_read_decrypted(uint16_t mem_address, uint8_t *plaintext, size_t original_length) {
|
||||
size_t encrypted_len = ((original_length + AES_BLOCK_SIZE - 1) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
|
||||
uint8_t encrypted_buf[256]; // Adjust as needed
|
||||
|
||||
ret_code_t err = eeprom_read_bytes(mem_address, encrypted_buf, encrypted_len);
|
||||
VERIFY_SUCCESS(err);
|
||||
|
||||
return decrypt_data(encrypted_buf, encrypted_len, plaintext);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void eeprom_uninitialize(void){
|
||||
nrfx_twi_disable(&m_eeprom);
|
||||
nrfx_twi_uninit(&m_eeprom);
|
||||
}
|
||||
|
||||
void eeprom_initialize(void){
|
||||
ret_code_t err_code;
|
||||
|
||||
const nrfx_twi_config_t eeprom_config = {
|
||||
.scl = ICM42670_I2C_SCL_PIN,
|
||||
.sda = ICM42670_I2C_SDA_PIN,
|
||||
.frequency = NRF_TWI_FREQ_400K,
|
||||
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
|
||||
};
|
||||
|
||||
err_code = nrfx_twi_init(&m_eeprom, &eeprom_config, NULL, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_twi_enable(&m_eeprom);
|
||||
}
|
||||
|
||||
ret_code_t eeprom_write_page(uint16_t mem_address, const uint8_t *data)
|
||||
{
|
||||
|
||||
uint8_t buffer[2 + EEPROM_PAGE_SIZE]; // 2 bytes for address + 64 bytes data
|
||||
ret_code_t ret;
|
||||
|
||||
buffer[0] = (uint8_t)(mem_address >> 8); // MSB
|
||||
buffer[1] = (uint8_t)(mem_address & 0xFF); // LSB
|
||||
memcpy(&buffer[2], data, EEPROM_PAGE_SIZE);
|
||||
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, buffer, 2 + EEPROM_PAGE_SIZE, false);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM write failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Wait for internal EEPROM write cycle (typically ~5ms)
|
||||
for (int i = 0; i < 100; i++) {
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, NULL, 0, false);
|
||||
if (ret == NRF_SUCCESS)
|
||||
break;
|
||||
nrf_delay_us(100); // Wait 100us before retry
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t eeprom_write_uint16_array(uint16_t start_address, const uint16_t *data, size_t count)
|
||||
{
|
||||
|
||||
if (count != 48) {
|
||||
DBG_PRINTF("Error: This function is only for writing exactly 48 uint16_t values.\n");
|
||||
return NRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
if (start_address < 128) {
|
||||
DBG_PRINTF("Error: This function is only for after 192....\n");
|
||||
return NRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
uint8_t buffer[EEPROM_PAGE_SIZE];
|
||||
ret_code_t ret;
|
||||
|
||||
// Write first 32 uint16_t values (64 bytes)
|
||||
for (size_t i = 0; i < 32; i++) {
|
||||
buffer[i * 2] = (uint8_t)(data[i] >> 8); // MSB
|
||||
buffer[i * 2 + 1] = (uint8_t)(data[i] & 0xFF); // LSB
|
||||
// buffer[i * 2 +1] = (uint8_t)(data[i] >> 8); // MSB
|
||||
// buffer[i * 2 ] = (uint8_t)(data[i] & 0xFF); // LSB
|
||||
}
|
||||
|
||||
ret = eeprom_write_page(start_address, buffer);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Write remaining 16 uint16_t values (32 bytes)
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
buffer[i * 2] = (uint8_t)(data[i + 32] >> 8);
|
||||
buffer[i * 2 + 1] = (uint8_t)(data[i + 32] & 0xFF);
|
||||
}
|
||||
|
||||
ret = eeprom_write_page(start_address + EEPROM_PAGE_SIZE, buffer); // next page
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ret_code_t eeprom_read_uint16_array(uint16_t start_address, uint16_t *data, size_t count)
|
||||
{
|
||||
|
||||
|
||||
if (count != 48) {
|
||||
DBG_PRINTF("Error: This function is only for reading exactly 48 uint16_t values.\n");
|
||||
return NRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
uint8_t buffer[EEPROM_PAGE_SIZE];
|
||||
ret_code_t ret;
|
||||
|
||||
// Read first 64 bytes (32 uint16_t)
|
||||
ret = eeprom_read_bytes(start_address, buffer, EEPROM_PAGE_SIZE);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 32; i++) {
|
||||
data[i] = ((uint16_t)buffer[i * 2] << 8) | buffer[i * 2 + 1];
|
||||
}
|
||||
|
||||
// Read next 32 bytes (16 uint16_t)
|
||||
ret = eeprom_read_bytes(start_address + EEPROM_PAGE_SIZE, buffer, 32);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
data[i + 32] = ((uint16_t)buffer[i * 2] << 8) | buffer[i * 2 + 1];
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
ret_code_t eeprom_read_page(uint16_t mem_address, uint8_t *data)
|
||||
{
|
||||
|
||||
uint8_t addr_buf[2];
|
||||
ret_code_t ret;
|
||||
|
||||
addr_buf[0] = (uint8_t)(mem_address >> 8);
|
||||
addr_buf[1] = (uint8_t)(mem_address & 0xFF);
|
||||
|
||||
// Send memory address first
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, addr_buf, 2, true);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM set read address failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Read the page
|
||||
ret = icm42670_twi_rx(EEPROM_I2C_ADDRESS, data, EEPROM_PAGE_SIZE);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM read failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
DBG_PRINTF("EEPROM read \n");
|
||||
for (int i = 0; i < EEPROM_PAGE_SIZE; i++) {
|
||||
|
||||
DBG_PRINTF("%02X\n", data[i]);
|
||||
}
|
||||
DBG_PRINTF("\r\n");
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ret_code_t eeprom_write_byte(uint16_t mem_address, uint8_t data)
|
||||
{
|
||||
|
||||
uint8_t buffer[3]; // 2 bytes for address + 1 byte data
|
||||
ret_code_t ret;
|
||||
|
||||
buffer[0] = (uint8_t)(mem_address >> 8); // MSB of address
|
||||
buffer[1] = (uint8_t)(mem_address & 0xFF); // LSB of address
|
||||
buffer[2] = data;
|
||||
DBG_PRINTF("EEPROM write byte %02X,%02X,%02X\n", buffer[0], buffer[1], buffer[2]);
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, buffer, 3, false);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM write byte failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Wait for internal EEPROM write cycle (typically ~5ms)
|
||||
for (int i = 0; i < 100; i++) {
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, NULL, 0, false);
|
||||
if (ret == NRF_SUCCESS)
|
||||
break;
|
||||
nrf_delay_us(100); // Wait 100us before retry
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
ret_code_t eeprom_read_byte(uint16_t mem_address, uint8_t *data)
|
||||
{
|
||||
|
||||
uint8_t addr_buf[2];
|
||||
ret_code_t ret;
|
||||
|
||||
addr_buf[0] = (uint8_t)(mem_address >> 8); // MSB of address
|
||||
addr_buf[1] = (uint8_t)(mem_address & 0xFF); // LSB of address
|
||||
|
||||
// Send memory address
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, addr_buf, 2, true);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM set address failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Read 1 byte
|
||||
ret = icm42670_twi_rx(EEPROM_I2C_ADDRESS, data, 1);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM read byte failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t eeprom_write_bytes(uint16_t mem_address, const uint8_t *data, size_t length)
|
||||
{
|
||||
|
||||
ret_code_t ret;
|
||||
size_t bytes_written = 0;
|
||||
|
||||
while (bytes_written < length) {
|
||||
size_t page_offset = mem_address % EEPROM_PAGE_SIZE;
|
||||
size_t bytes_to_write = EEPROM_PAGE_SIZE - page_offset;
|
||||
if (bytes_to_write > (length - bytes_written)) {
|
||||
bytes_to_write = length - bytes_written;
|
||||
}
|
||||
|
||||
uint8_t buffer[2 + EEPROM_PAGE_SIZE]; // 2-byte addr + up to 64 data bytes
|
||||
buffer[0] = (uint8_t)(mem_address >> 8);
|
||||
buffer[1] = (uint8_t)(mem_address & 0xFF);
|
||||
memcpy(&buffer[2], &data[bytes_written], bytes_to_write);
|
||||
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, buffer, bytes_to_write + 2, false);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM write error at addr 0x%04X\n", mem_address);
|
||||
return ret;
|
||||
}
|
||||
// Wait for internal EEPROM write cycle (typically ~5ms)
|
||||
for (int i = 0; i < 100; i++) {
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, NULL, 0, false);
|
||||
if (ret == NRF_SUCCESS)
|
||||
break;
|
||||
nrf_delay_us(100); // Wait 100us before retry
|
||||
}
|
||||
|
||||
mem_address += bytes_to_write;
|
||||
bytes_written += bytes_to_write;
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
ret_code_t eeprom_read_bytes(uint16_t mem_address, uint8_t *data, size_t length)
|
||||
{
|
||||
|
||||
ret_code_t ret;
|
||||
uint8_t addr_buf[2];
|
||||
|
||||
addr_buf[0] = (uint8_t)(mem_address >> 8);
|
||||
addr_buf[1] = (uint8_t)(mem_address & 0xFF);
|
||||
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, addr_buf, 2, true); // send addr, no stop
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM read set address failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = icm42670_twi_rx(EEPROM_I2C_ADDRESS, data, length);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM read failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
ret_code_t eeprom_write_word(uint16_t mem_address, uint16_t data)
|
||||
{
|
||||
|
||||
uint8_t buffer[4]; // 2 bytes for address + 2 bytes for data
|
||||
ret_code_t ret;
|
||||
|
||||
buffer[0] = (uint8_t)(mem_address >> 8); // MSB of address
|
||||
buffer[1] = (uint8_t)(mem_address & 0xFF); // LSB of address
|
||||
buffer[2] = (uint8_t)(data & 0xFF); // LSB of data
|
||||
buffer[3] = (uint8_t)(data >> 8); // MSB of data
|
||||
|
||||
DBG_PRINTF("EEPROM write word %02X,%02X,%02X,%02X\n", buffer[0], buffer[1], buffer[2], buffer[3]);
|
||||
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, buffer, 4, false);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM write word failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Wait for internal write cycle (~5ms typical)
|
||||
for (int i = 0; i < 100; i++) {
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, NULL, 0, false);
|
||||
if (ret == NRF_SUCCESS)
|
||||
break;
|
||||
nrf_delay_us(100); // 100us delay between polling
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t eeprom_read_word(uint16_t mem_address, uint16_t *data)
|
||||
{
|
||||
|
||||
uint8_t addr_buf[2];
|
||||
uint8_t read_buf[2];
|
||||
ret_code_t ret;
|
||||
|
||||
addr_buf[0] = (uint8_t)(mem_address >> 8);
|
||||
addr_buf[1] = (uint8_t)(mem_address & 0xFF);
|
||||
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, addr_buf, 2, true);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM set address for word read failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = icm42670_twi_rx(EEPROM_I2C_ADDRESS, read_buf, 2);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM read word failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*data = ((uint16_t)read_buf[1] << 8) | read_buf[0]; // Little-endian
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
ret_code_t eeprom_write_uint32(uint16_t mem_address, uint32_t data)
|
||||
{
|
||||
|
||||
uint8_t buffer[6]; // 2 bytes address + 4 bytes data
|
||||
ret_code_t ret;
|
||||
|
||||
buffer[0] = (uint8_t)(mem_address >> 8); // MSB of address
|
||||
buffer[1] = (uint8_t)(mem_address & 0xFF); // LSB of address
|
||||
buffer[2] = (uint8_t)(data >> 24);
|
||||
buffer[3] = (uint8_t)(data >> 16);
|
||||
buffer[4] = (uint8_t)(data >> 8);
|
||||
buffer[5] = (uint8_t)(data);
|
||||
|
||||
DBG_PRINTF("EEPROM write uint32: %02X %02X %02X %02X %02X %02X\n",
|
||||
buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
|
||||
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, buffer, 6, false);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM write uint32 failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Wait for internal EEPROM write cycle
|
||||
for (int i = 0; i < 100; i++) {
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, NULL, 0, false);
|
||||
if (ret == NRF_SUCCESS)
|
||||
break;
|
||||
nrf_delay_us(100);
|
||||
}
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ret_code_t eeprom_read_uint32(uint16_t mem_address, uint32_t *data)
|
||||
{
|
||||
uint8_t addr_buf[2];
|
||||
uint8_t data_buf[4];
|
||||
ret_code_t ret;
|
||||
|
||||
|
||||
addr_buf[0] = (uint8_t)(mem_address >> 8);
|
||||
addr_buf[1] = (uint8_t)(mem_address & 0xFF);
|
||||
|
||||
DBG_PRINTF("EEPROM address:%02X,%02X \n",addr_buf[0],addr_buf[1]);
|
||||
// Send memory address to read from
|
||||
ret = icm42670_twi_tx(EEPROM_I2C_ADDRESS, addr_buf, 2, true);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM read (addr phase) failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Read 4 bytes of data
|
||||
ret = icm42670_twi_rx(EEPROM_I2C_ADDRESS, data_buf, 4);
|
||||
if (ret != NRF_SUCCESS) {
|
||||
DBG_PRINTF("EEPROM read (data phase) failed (code: %d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*data = ((uint32_t)data_buf[0] << 24) |
|
||||
((uint32_t)data_buf[1] << 16) |
|
||||
((uint32_t)data_buf[2] << 8) |
|
||||
((uint32_t)data_buf[3]);
|
||||
|
||||
DBG_PRINTF("EEPROM read uint32: %02X %02X %02X %02X -> %08X\n",
|
||||
data_buf[0], data_buf[1], data_buf[2], data_buf[3], *data);
|
||||
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
66
project/ble_peripheral/ble_app_bladder_patch/cat_interface.h
Normal file
66
project/ble_peripheral/ble_app_bladder_patch/cat_interface.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* @file app_raw_main.h
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CAT_INTERFACE_H_
|
||||
#define _CAT_INTERFACE_H_
|
||||
#include "sdk_config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include "nordic_common.h"
|
||||
#include "nrf.h"
|
||||
#include "sdk_errors.h"
|
||||
#define EEPROM_I2C_ADDRESS 0x50
|
||||
#define EEPROM_PAGE_SIZE 64
|
||||
#define SERIAL_ADDRESS 0x0030
|
||||
|
||||
|
||||
ret_code_t encrypt_data(const uint8_t *input, size_t length, uint8_t *output, size_t *output_len);
|
||||
|
||||
ret_code_t decrypt_data(const uint8_t *input, size_t length, uint8_t *output);
|
||||
|
||||
ret_code_t eeprom_write_encrypted(uint16_t mem_address, const uint8_t *plaintext, size_t length);
|
||||
|
||||
|
||||
ret_code_t eeprom_read_decrypted(uint16_t mem_address, uint8_t *plaintext, size_t original_length);
|
||||
|
||||
|
||||
|
||||
ret_code_t eeprom_read_page(uint16_t mem_address, uint8_t *data);
|
||||
|
||||
ret_code_t eeprom_write_page(uint16_t mem_address, const uint8_t *data);
|
||||
|
||||
ret_code_t eeprom_write_byte(uint16_t mem_address, uint8_t data);
|
||||
|
||||
ret_code_t eeprom_read_byte(uint16_t mem_address, uint8_t *data);
|
||||
|
||||
ret_code_t eeprom_write_bytes(uint16_t mem_address, const uint8_t *data, size_t length);
|
||||
|
||||
ret_code_t eeprom_read_bytes(uint16_t mem_address, uint8_t *data, size_t length);
|
||||
|
||||
ret_code_t eeprom_write_uint16_array(uint16_t start_address, const uint16_t *data, size_t count);
|
||||
|
||||
ret_code_t eeprom_read_uint16_array(uint16_t start_address, uint16_t *data, size_t count);
|
||||
|
||||
ret_code_t eeprom_write_word(uint16_t mem_address, uint16_t data);
|
||||
|
||||
ret_code_t eeprom_read_word(uint16_t mem_address, uint16_t *data);
|
||||
|
||||
|
||||
void eeprom_uninitialize(void);
|
||||
|
||||
void eeprom_initialize(void);
|
||||
|
||||
|
||||
|
||||
ret_code_t eeprom_write_uint32(uint16_t mem_address, uint32_t data);
|
||||
|
||||
ret_code_t eeprom_read_uint32(uint16_t mem_address, uint32_t *data);
|
||||
|
||||
|
||||
#endif /* */
|
||||
|
||||
2206
project/ble_peripheral/ble_app_bladder_patch/cmd_parse.c
Normal file
2206
project/ble_peripheral/ble_app_bladder_patch/cmd_parse.c
Normal file
File diff suppressed because it is too large
Load Diff
90
project/ble_peripheral/ble_app_bladder_patch/cmd_parse.h
Normal file
90
project/ble_peripheral/ble_app_bladder_patch/cmd_parse.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/*******************************************************************************
|
||||
* @file cmd_parse.h
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
#ifndef _CMD_PARSE_H_
|
||||
#define _CMD_PARSE_H_
|
||||
#include "sdk_config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nordic_common.h"
|
||||
#include "nrf.h"
|
||||
#include "ble_hci.h"
|
||||
#include "ble_advdata.h"
|
||||
#include "ble_advertising.h"
|
||||
#include "ble_conn_params.h"
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_soc.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
#include "nrf_ble_gatt.h"
|
||||
#include "nrf_ble_qwr.h"
|
||||
#include "app_timer.h"
|
||||
#include "ble_nus.h"
|
||||
#include "app_uart.h"
|
||||
#include "app_util_platform.h"
|
||||
#include "bsp_btn_ble.h"
|
||||
#include "nrf_pwr_mgmt.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "math.h"
|
||||
#include "crc16.h" //add 25.04.23
|
||||
#include "nrf_ble_lesc.h"
|
||||
#include "cat_interface.h"
|
||||
#include "ir_i2c.h"
|
||||
#include "nrf_crypto.h"
|
||||
#include "nrf_pwr_mgmt.h"
|
||||
#include <ctype.h>
|
||||
|
||||
#include "system_interface.h"
|
||||
#include "main.h"
|
||||
#include "app_raw_main.h" //0117
|
||||
#include "main_timer.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "ada2200_spi.h"
|
||||
#include "power_control.h"
|
||||
#include "tmp235_q1.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "measurements.h"
|
||||
//#include "fstorage.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "mcp4725_adc.h"
|
||||
#include "meas_pd_voltage_simple.h"
|
||||
#include "meas_pd_voltage_half.h"
|
||||
#include "meas_pd_voltage_full.h"
|
||||
#include "full_agc.h"
|
||||
//#include "meas_pd_voltage_custom.h"
|
||||
#include "meas_pd_imm.h"
|
||||
|
||||
#include "meas_pd_48.h"
|
||||
typedef struct {
|
||||
char tag[5]; // Null-terminated 4-char command
|
||||
uint16_t value0; // Data value
|
||||
uint16_t value1; // Data value
|
||||
uint16_t value2; // Data value
|
||||
uint16_t value3; // Data value
|
||||
uint16_t value4; // Data value
|
||||
char value_ascii[13];
|
||||
uint8_t values[24]; // data vlue
|
||||
// uint16_t crc; // CRC value
|
||||
} ParsedCmd;
|
||||
uint32_t serial_to_passkey_hash(const char *input);
|
||||
void received_command_process(uint8_t const *data_array, which_cmd_t cmd_t,uint8_t length);
|
||||
bool length_error(const char *cmd , uint8_t target_length, uint8_t length);
|
||||
bool parse_cmd(const uint8_t *buffer, ParsedCmd *cmd_out,uint8_t length);
|
||||
bool activate_error(const char *cmd , bool device_status);
|
||||
void param_error(const char *cmd );
|
||||
void quest_error(const char *cmd );
|
||||
bool is_valid_serial_no(const char *serial);
|
||||
|
||||
|
||||
bool is_valid_passkey(const char *passkey);
|
||||
ret_code_t eeprom_init_values_read(void);
|
||||
|
||||
bool crc16_check(uint8_t const * p_data, uint32_t data_len, uint16_t expected_crc);
|
||||
bool crc16_check_packet(uint8_t const * packet, uint32_t packet_len);
|
||||
#endif /* */
|
||||
|
||||
14
project/ble_peripheral/ble_app_bladder_patch/debuf_print.h
Normal file
14
project/ble_peripheral/ble_app_bladder_patch/debuf_print.h
Normal file
@@ -0,0 +1,14 @@
|
||||
// file: debug_print.h
|
||||
#ifndef DEBUG_PRINT_H
|
||||
#define DEBUG_PRINT_H
|
||||
|
||||
#define ENABLE_PRINTF 1 // Set to 0 to disable globally
|
||||
|
||||
#if ENABLE_PRINTF
|
||||
#include <stdio.h>
|
||||
#define DBG_PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define DBG_PRINTF(...) // Do nothing
|
||||
#endif
|
||||
|
||||
#endif // DEBUG_PRINT_H
|
||||
14
project/ble_peripheral/ble_app_bladder_patch/debug_print.h
Normal file
14
project/ble_peripheral/ble_app_bladder_patch/debug_print.h
Normal file
@@ -0,0 +1,14 @@
|
||||
// file: debug_print.h
|
||||
#ifndef DEBUG_PRINT_H
|
||||
#define DEBUG_PRINT_H
|
||||
|
||||
#define ENABLE_PRINTF 1 // Set to 0 to disable globally
|
||||
|
||||
#if ENABLE_PRINTF
|
||||
#include <stdio.h>
|
||||
#define DBG_PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define DBG_PRINTF(...) // Do nothing
|
||||
#endif
|
||||
|
||||
#endif // DEBUG_PRINT_H
|
||||
370
project/ble_peripheral/ble_app_bladder_patch/fstorage.c
Normal file
370
project/ble_peripheral/ble_app_bladder_patch/fstorage.c
Normal file
@@ -0,0 +1,370 @@
|
||||
/*******************************************************************************
|
||||
TEST medi50 Dec 23
|
||||
******************************************************************************/
|
||||
|
||||
#include "sdk_config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
#include "nrf_fstorage.h"
|
||||
#include "nrf_soc.h"
|
||||
#include "nrf_strerror.h"
|
||||
#include "sdk_config.h"
|
||||
#include "nrf_fstorage_sd.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "ble_gap.h"
|
||||
#include "fds.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
|
||||
#include "fstorage.h"
|
||||
#include "nrf_pwr_mgmt.h"
|
||||
#include "measurements.h"
|
||||
#include "main.h"
|
||||
|
||||
|
||||
/* File ID and Key used for the configuration record. */
|
||||
|
||||
#define CONFIG_FILE (0x8010)
|
||||
#define CONFIG_REC_KEY (0x7010)
|
||||
|
||||
#define CONFIG_MAGIC_NUMBER_VALUE (0x20231226)
|
||||
config_data_t m_config;
|
||||
|
||||
extern bool go_device_power_off;
|
||||
extern bool go_sleep_mode_enter;
|
||||
extern bool go_NVIC_SystemReset;
|
||||
|
||||
/* Flag to check fds initialization. */
|
||||
static bool volatile m_fds_initialized;
|
||||
|
||||
bool fds_flag_write = false;
|
||||
/* A record containing dummy configuration data. */
|
||||
static fds_record_t const m_dummy_record =
|
||||
{
|
||||
.file_id = CONFIG_FILE,
|
||||
.key = CONFIG_REC_KEY,
|
||||
.data.p_data = (void const *)&m_config,
|
||||
/* The length of a record is always expressed in 4-byte units (words). */
|
||||
.data.length_words = (sizeof(m_config) + 3) / sizeof(uint32_t),
|
||||
};
|
||||
|
||||
|
||||
/* 공장 입력 항목 1 */
|
||||
|
||||
|
||||
/* 공장 입력 항목 2 */
|
||||
//char serial_number_dflt[12] = "2025AAMAY0FF";
|
||||
//uint16_t pd_delay_us = 0;
|
||||
//int8_t reset_status=0;
|
||||
|
||||
//uint32_t pd_adc_calibration_dflt_PD0[M_LED_NUM] =
|
||||
// {1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, /* PD01 */
|
||||
//};
|
||||
//uint32_t pd_adc_calibration_dflt_PD1[M_LED_NUM] =
|
||||
// {1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, /* PD1 */
|
||||
//};
|
||||
//uint32_t pd_adc_calibration_dflt_PD2[M_LED_NUM] =
|
||||
// {1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, /* MOD1 */
|
||||
//};
|
||||
|
||||
///* 공장 입력 항목 5 */
|
||||
//uint32_t dark_noise_for_pd_dflt[PD_NUM] = /*PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7, PD8, PD9, PD10, PD11, PD12, PD13, PD14, PD15, PD16, PD17, PD18, PD19, PD20, */
|
||||
// {1111, 1111};
|
||||
|
||||
|
||||
/* 공장 입력 항목 8 */
|
||||
//int8_t pd_adc_cnt_dflt = 8; /* 8, 16, 24, 32 */
|
||||
int8_t reset_status_dflt =99;
|
||||
/* 공장 입력 항목 9 */
|
||||
//uint16_t led_delay_us_dflt = 8000; /* 0 ~ 65535 */
|
||||
|
||||
/* 공장 입력 항목 10 */
|
||||
//uint16_t pd_delay_us_dflt = 8000; /* 0 ~ 65535 */
|
||||
|
||||
#if FEATURE_SECURE_CONNECTION
|
||||
/* Bonding information delete */
|
||||
//bool bond_data_delete_dflt = true;//
|
||||
|
||||
/* Static Passkey */
|
||||
uint8_t static_passkey_dflt[6] = "123456";
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
//uint16_t led_power_dp_dflt[48] = {
|
||||
// //NULL, 42, 29, 41, 31, 28, 28, 42, 28, 39, 29, 27, 27, 42, 29, 40, 30, 28, 28, 40, 27, 38, 28, 25, 22
|
||||
// 25,25,25,18,19,24,24,25,25,18,19,25,23,25,25,18,19,24,24,25,25,19,20,25,24,25,25,25,18,19,24,24,25,25,18,19,25,23,25,25,18,19,24,24,25,25,19,20
|
||||
//};
|
||||
|
||||
void fds_default_value_set(void)
|
||||
{
|
||||
|
||||
/* Serial Number */
|
||||
//memcpy(m_config.serial_number, serial_number_dflt, 12);
|
||||
|
||||
/* PD-ADC Calibration Value */
|
||||
// for(uint8_t j = 0; j < M_LED_NUM; j++){
|
||||
// m_config.pd_adc_calibration_PD0[j] = pd_adc_calibration_dflt_PD0[j];
|
||||
// }
|
||||
// for(uint8_t j = 0; j < M_LED_NUM; j++){
|
||||
// m_config.pd_adc_calibration_PD1[j] = pd_adc_calibration_dflt_PD1[j];
|
||||
// }
|
||||
// for(uint8_t j = 0; j < M_LED_NUM; j++){
|
||||
// m_config.pd_adc_calibration_PD2[j] = pd_adc_calibration_dflt_PD2[j];
|
||||
// }
|
||||
|
||||
|
||||
// /* Dark Noise of PD */
|
||||
// for(uint8_t i = 0; i < PD_NUM; i++){
|
||||
// m_config.dark_noise_for_pd[i] = dark_noise_for_pd_dflt[i];
|
||||
// }
|
||||
|
||||
/* PD-ADC Cycle for 8, 16, 24, 32 */
|
||||
// m_config.pd_adc_cnt = pd_adc_cnt_dflt;
|
||||
|
||||
/* LED ON Delay for usec */
|
||||
// m_config.led_delay_us = led_delay_us_dflt;
|
||||
|
||||
/* PD ON Delay for usec */
|
||||
// m_config.pd_delay_us = pd_delay_us_dflt;
|
||||
|
||||
|
||||
m_config.reset_status = reset_status_dflt;
|
||||
|
||||
#if FEATURE_SECURE_CONNECTION
|
||||
/* Bonding information delete */
|
||||
// m_config.bond_data_delete = bond_data_delete_dflt;
|
||||
|
||||
/* Static Passkey */
|
||||
memcpy(m_config.static_passkey, static_passkey_dflt, 6);
|
||||
|
||||
#endif
|
||||
//for(uint8_t i = 0; i < PD_NUM; i++){
|
||||
// for(uint8_t j = 0; j < LED_NUM; j++){
|
||||
// m_config.led_pd_dac_v[j] = 1000;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// for(uint8_t j = 0; j < LED_NUM; j++){
|
||||
// m_config.led_power_dp[j] = led_power_dp_dflt[j] ;
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
static void fds_evt_handler( fds_evt_t const *p_evt )
|
||||
{
|
||||
switch( p_evt->id )
|
||||
{
|
||||
case FDS_EVT_INIT:
|
||||
if( p_evt->result == NRF_SUCCESS )
|
||||
{
|
||||
m_fds_initialized = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FDS_EVT_WRITE:
|
||||
{
|
||||
fds_flag_write = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case FDS_EVT_UPDATE:
|
||||
{
|
||||
fds_flag_write = false;
|
||||
|
||||
if(go_device_power_off == true) {
|
||||
/* After flash writing completed, System Power Off */
|
||||
device_power_off();
|
||||
}
|
||||
if(go_sleep_mode_enter == true) {
|
||||
/* After flash writing completed, System go to Sleep Mode */
|
||||
sleep_mode_enter();
|
||||
}
|
||||
if(go_NVIC_SystemReset == true) {
|
||||
/* After flash writing completed, System Reset */
|
||||
printf("Off FDS_ENVET\r\n");
|
||||
NVIC_SystemReset(); //0112
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case FDS_EVT_DEL_RECORD:
|
||||
break;
|
||||
|
||||
case FDS_EVT_DEL_FILE:
|
||||
break;
|
||||
|
||||
case FDS_EVT_GC:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**@brief Wait for fds to initialize. */
|
||||
static void wait_for_fds_ready( void )
|
||||
{
|
||||
while( !m_fds_initialized )
|
||||
{
|
||||
nrf_pwr_mgmt_run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void config_load( void )
|
||||
{
|
||||
ret_code_t rc;
|
||||
fds_record_desc_t desc = { 0 };
|
||||
fds_find_token_t tok = { 0 };
|
||||
|
||||
cfg_load_start:
|
||||
memset((char *)&desc, 0, sizeof(desc));
|
||||
memset((char *)&tok, 0, sizeof(tok));
|
||||
rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);
|
||||
|
||||
if( rc == NRF_SUCCESS )
|
||||
{
|
||||
/* A config file is in flash. Let's update it. */
|
||||
fds_flash_record_t config = { 0 };
|
||||
|
||||
/* Open the record and read its contents. */
|
||||
rc = fds_record_open(&desc, &config);
|
||||
APP_ERROR_CHECK(rc);
|
||||
|
||||
/* Copy the configuration from flash into m_dummy_cfg. */
|
||||
memcpy(&m_config, config.p_data, sizeof(config_data_t));
|
||||
|
||||
/* Close the record when done reading. */
|
||||
rc = fds_record_close(&desc);
|
||||
APP_ERROR_CHECK(rc);
|
||||
|
||||
if( m_config.magic_number != (uint32_t)CONFIG_MAGIC_NUMBER_VALUE )
|
||||
{ // first init
|
||||
rc = fds_record_delete(&desc);
|
||||
APP_ERROR_CHECK(rc);
|
||||
m_config.magic_number = CONFIG_MAGIC_NUMBER_VALUE;
|
||||
|
||||
// default....
|
||||
fds_default_value_set();
|
||||
|
||||
/* Write the updated record to flash. */
|
||||
rc = fds_record_update(&desc, &m_dummy_record);
|
||||
if( (rc != NRF_SUCCESS) && (rc == FDS_ERR_NO_SPACE_IN_FLASH) )
|
||||
{
|
||||
rc = fds_gc();
|
||||
APP_ERROR_CHECK(rc);
|
||||
}
|
||||
else
|
||||
{
|
||||
APP_ERROR_CHECK(rc);
|
||||
}
|
||||
goto cfg_load_start;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* System config not found; write a new one. */
|
||||
m_config.magic_number = CONFIG_MAGIC_NUMBER_VALUE;
|
||||
|
||||
// default....
|
||||
fds_default_value_set();
|
||||
|
||||
rc = fds_record_write(&desc, &m_dummy_record);
|
||||
while( fds_flag_write )
|
||||
{
|
||||
nrf_pwr_mgmt_run();
|
||||
}
|
||||
if( (rc != NRF_SUCCESS) && (rc == FDS_ERR_NO_SPACE_IN_FLASH) )
|
||||
{
|
||||
rc = fds_gc();
|
||||
APP_ERROR_CHECK(rc);
|
||||
}
|
||||
else
|
||||
{
|
||||
APP_ERROR_CHECK(rc);
|
||||
}
|
||||
NRF_LOG_FLUSH();
|
||||
goto cfg_load_start;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void config_save( void )
|
||||
{
|
||||
ret_code_t rc;
|
||||
fds_record_desc_t desc = { 0 };
|
||||
fds_find_token_t tok = { 0 };
|
||||
|
||||
rc = fds_gc();
|
||||
APP_ERROR_CHECK(rc);
|
||||
|
||||
if( m_config.magic_number != (uint32_t)CONFIG_MAGIC_NUMBER_VALUE )
|
||||
{
|
||||
m_config.magic_number = CONFIG_MAGIC_NUMBER_VALUE;
|
||||
}
|
||||
|
||||
config_save_start:
|
||||
|
||||
fds_flag_write = true;
|
||||
|
||||
memset((char *)&desc, 0, sizeof(desc));
|
||||
memset((char *)&tok, 0, sizeof(tok));
|
||||
rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);
|
||||
|
||||
if( rc == NRF_SUCCESS )
|
||||
{
|
||||
/* Write the updated record to flash. */
|
||||
rc = fds_record_update(&desc, &m_dummy_record);
|
||||
if( (rc != NRF_SUCCESS) && (rc == FDS_ERR_NO_SPACE_IN_FLASH) )
|
||||
{
|
||||
rc = fds_gc();
|
||||
APP_ERROR_CHECK(rc);
|
||||
goto config_save_start;
|
||||
}
|
||||
else
|
||||
{
|
||||
APP_ERROR_CHECK(rc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = fds_record_write(&desc, &m_dummy_record);
|
||||
APP_ERROR_CHECK(rc);
|
||||
|
||||
goto config_save_start;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void fs_set_value(void)
|
||||
{
|
||||
config_load();
|
||||
}
|
||||
|
||||
void fs_storage_init(void)
|
||||
{
|
||||
ret_code_t rc;
|
||||
|
||||
/* Register first to receive an event when initialization is complete. */
|
||||
rc = fds_register(fds_evt_handler);
|
||||
APP_ERROR_CHECK(rc);
|
||||
rc = fds_init();
|
||||
APP_ERROR_CHECK(rc);
|
||||
/* Wait for fds to initialize. */
|
||||
wait_for_fds_ready();
|
||||
fds_stat_t stat = { 0 };
|
||||
rc = fds_stat(&stat);
|
||||
APP_ERROR_CHECK(rc);
|
||||
}
|
||||
|
||||
60
project/ble_peripheral/ble_app_bladder_patch/fstorage.h
Normal file
60
project/ble_peripheral/ble_app_bladder_patch/fstorage.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* @file fstorage.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef IHP_FSTORAGE_H_
|
||||
#define IHP_FSTORAGE_H_
|
||||
|
||||
#include "sdk_config.h"
|
||||
|
||||
#include "nordic_common.h"
|
||||
#include <stdint.h>
|
||||
#include "measurements.h"
|
||||
|
||||
#define LED_NUM 48 /* LED0 사용하지 않음, 대신 NULL값 입력 */
|
||||
#define PD_NUM 2 /* PD0 사용하지 않음, 대신 NULL값 입력 * 0,1 data 2 mod 3 off*/
|
||||
#define mW 13 /* LED mW 설정 파워 값 */
|
||||
#define M_LED_NUM 24 /*측정할 L*/
|
||||
#pragma pack(1)
|
||||
typedef struct
|
||||
{
|
||||
uint32_t magic_number;
|
||||
//char serial_number[13];
|
||||
|
||||
// uint32_t pd_adc_calibration_PD0[M_LED_NUM];
|
||||
// uint32_t pd_adc_calibration_PD1[M_LED_NUM];
|
||||
// uint32_t pd_adc_calibration_PD2[M_LED_NUM];
|
||||
|
||||
|
||||
// uint32_t dark_noise_for_pd[PD_NUM];
|
||||
// int8_t pd_adc_cnt;
|
||||
int8_t reset_status;
|
||||
// uint16_t led_delay_us;
|
||||
// uint16_t pd_delay_us;
|
||||
|
||||
#if FEATURE_SECURE_CONNECTION
|
||||
// bool bond_data_delete;
|
||||
uint8_t static_passkey[6];
|
||||
|
||||
#endif
|
||||
|
||||
// uint16_t led_pd_dac_v[LED_NUM];
|
||||
// uint16_t led_power_dp[LED_NUM];
|
||||
|
||||
} config_data_t; /* Flash에 저장하는 값 */
|
||||
|
||||
extern config_data_t m_config;
|
||||
|
||||
void fds_default_value_set(void);
|
||||
void config_load( void );
|
||||
void config_save( void );
|
||||
|
||||
void fs_set_value(void);
|
||||
void fs_storage_init(void);
|
||||
|
||||
#endif /* IHP_FSTORAGE_H_ */
|
||||
|
||||
1033
project/ble_peripheral/ble_app_bladder_patch/full_agc.c
Normal file
1033
project/ble_peripheral/ble_app_bladder_patch/full_agc.c
Normal file
File diff suppressed because it is too large
Load Diff
34
project/ble_peripheral/ble_app_bladder_patch/full_agc.h
Normal file
34
project/ble_peripheral/ble_app_bladder_patch/full_agc.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*******************************************************************************
|
||||
* @file full_agc.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _FULL_AGC_H__
|
||||
#define _FULL_AGC_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#define PD_NO 1
|
||||
//#define LED_NO 50
|
||||
|
||||
|
||||
void full_agc_start(void);
|
||||
void full_agc_end(void);
|
||||
void full_agc_adc_init(void);
|
||||
void full_agc_uninit(void);
|
||||
void full_agc_loop(void * p_context); /* For x ms */
|
||||
void full_agc_timer_start(void);
|
||||
void full_agc_timer_stop(void);
|
||||
void full_agc_timer_init(void);
|
||||
void full_agc_mesurement_start(void);
|
||||
|
||||
void full_agc_send_loop(void * p_context); /* For x ms */
|
||||
void full_agc_send_timer_start(void);
|
||||
void full_agc_send_timer_stop(void);
|
||||
void full_agc_send_timer_init(void);
|
||||
#endif /* _FULL_AGC_H__ */
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
set CURDIR=%cd%
|
||||
|
||||
|
||||
|
||||
copy ..\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.hex medithings_bladder_patch_0001.hex
|
||||
copy ..\..\..\dfu\secure_bootloader\pca10056_s140_ble\arm5_no_packs\_build\nrf52840_xxaa_s140.hex medithings_bladder_patch_bootloader.hex
|
||||
|
||||
nrfutil settings generate --family NRF52840 --application medithings_bladder_patch_0001.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 medithings_bladder_patch_bootloader_setting.hex
|
||||
|
||||
mergehex.exe --merge s140_nrf52_7.2.0_softdevice.hex medithings_bladder_patch_0001.hex --output medithings_bladder_patch_merged_1.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_bootloader.hex medithings_bladder_patch_bootloader_setting.hex --output medithings_bladder_patch_merged_2.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_merged_1.hex medithings_bladder_patch_merged_2.hex --output medithings_bladder_patch_dfu_merged_all.hex
|
||||
|
||||
nrfjprog --family NRF52 --recover
|
||||
nrfjprog --family NRF52 --eraseall
|
||||
nrfjprog --family NRF52 --program medithings_bladder_patch_dfu_merged_all.hex
|
||||
nrfjprog --family NRF52 --reset
|
||||
nrfjprog --family NRF52 --rbp ALL
|
||||
|
||||
|
||||
pause
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
set CURDIR=%cd%
|
||||
|
||||
|
||||
|
||||
copy ..\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.hex medithings_bladder_patch_0001.hex
|
||||
copy ..\..\..\dfu\secure_bootloader\pca10056_s140_ble\arm5_no_packs\_build\nrf52840_xxaa_s140.hex medithings_bladder_patch_bootloader.hex
|
||||
|
||||
nrfutil settings generate --family NRF52840 --application medithings_bladder_patch_0001.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 medithings_bladder_patch_bootloader_setting.hex
|
||||
|
||||
mergehex.exe --merge s140_nrf52_7.2.0_softdevice.hex medithings_bladder_patch_0001.hex --output medithings_bladder_patch_merged_1.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_bootloader.hex medithings_bladder_patch_bootloader_setting.hex --output medithings_bladder_patch_merged_2.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_merged_1.hex medithings_bladder_patch_merged_2.hex --output medithings_bladder_patch_dfu_merged_all.hex
|
||||
|
||||
nrfjprog --family NRF52 --recover
|
||||
nrfjprog --family NRF52 --eraseall
|
||||
nrfjprog --family NRF52 --program medithings_bladder_patch_dfu_merged_all.hex
|
||||
|
||||
|
||||
|
||||
pause
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
set CURDIR=%cd%
|
||||
|
||||
|
||||
|
||||
copy ..\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.hex medithings_bladder_patch_0001.hex
|
||||
copy ..\..\..\dfu\secure_bootloader\pca10056_s140_ble\arm5_no_packs\_build\nrf52840_xxaa_s140.hex medithings_bladder_patch_bootloader.hex
|
||||
|
||||
nrfutil settings generate --family NRF52840 --application medithings_bladder_patch_0001.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 medithings_bladder_patch_bootloader_setting.hex
|
||||
|
||||
mergehex.exe --merge s140_nrf52_7.2.0_softdevice.hex medithings_bladder_patch_0001.hex --output medithings_bladder_patch_merged_1.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_bootloader.hex medithings_bladder_patch_bootloader_setting.hex --output medithings_bladder_patch_merged_2.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_merged_1.hex medithings_bladder_patch_merged_2.hex --output medithings_bladder_patch_dfu_merged_all.hex
|
||||
|
||||
|
||||
nrfjprog --family NRF52 --eraseall
|
||||
nrfjprog --family NRF52 --program medithings_bladder_patch_dfu_merged_all.hex
|
||||
nrfjprog --family NRF52 --reset
|
||||
nrfjprog --family NRF52 --rbp ALL
|
||||
|
||||
|
||||
pause
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
set CURDIR=%cd%
|
||||
|
||||
|
||||
|
||||
copy ..\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.hex medithings_bladder_patch_0001.hex
|
||||
copy ..\..\..\dfu\secure_bootloader\pca10056_s140_ble\arm5_no_packs\_build\nrf52840_xxaa_s140.hex medithings_bladder_patch_bootloader.hex
|
||||
|
||||
nrfutil settings generate --family NRF52840 --application medithings_bladder_patch_0001.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 medithings_bladder_patch_bootloader_setting.hex
|
||||
|
||||
mergehex.exe --merge s140_nrf52_7.2.0_softdevice.hex medithings_bladder_patch_0001.hex --output medithings_bladder_patch_merged_1.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_bootloader.hex medithings_bladder_patch_bootloader_setting.hex --output medithings_bladder_patch_merged_2.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_merged_1.hex medithings_bladder_patch_merged_2.hex --output medithings_bladder_patch_dfu_merged_all.hex
|
||||
|
||||
|
||||
nrfjprog --memrd 0x10001208
|
||||
|
||||
|
||||
nrfjprog --family NRF52 --recover
|
||||
|
||||
nrfjprog --memrd 0x10001208
|
||||
|
||||
nrfjprog --family NRF52 --eraseall
|
||||
nrfjprog --family NRF52 --program medithings_bladder_patch_dfu_merged_all.hex --verify
|
||||
nrfjprog --family NRF52 --reset
|
||||
nrfjprog --family NRF52 --rbp ALL
|
||||
nrfjprog --memwr 0x10001208 --val 0x00
|
||||
nrfjprog --memrd 0x10001208
|
||||
|
||||
pause
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
set CURDIR=%cd%
|
||||
|
||||
|
||||
|
||||
copy ..\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.hex medithings_bladder_patch_0001.hex
|
||||
copy ..\..\..\dfu\secure_bootloader\pca10056_s140_ble\arm5_no_packs\_build\nrf52840_xxaa_s140.hex medithings_bladder_patch_bootloader.hex
|
||||
|
||||
nrfutil settings generate --family NRF52840 --application medithings_bladder_patch_0001.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 medithings_bladder_patch_bootloader_setting.hex
|
||||
|
||||
mergehex.exe --merge s140_nrf52_7.2.0_softdevice.hex medithings_bladder_patch_0001.hex --output medithings_bladder_patch_merged_1.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_bootloader.hex medithings_bladder_patch_bootloader_setting.hex --output medithings_bladder_patch_merged_2.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_merged_1.hex medithings_bladder_patch_merged_2.hex --output medithings_bladder_patch_dfu_merged_all.hex
|
||||
|
||||
nrfjprog --family NRF52 --recover
|
||||
nrfjprog --family NRF52 --eraseall
|
||||
nrfjprog --family NRF52 --program medithings_bladder_patch_dfu_merged_all.hex --verify
|
||||
nrfjprog --family NRF52 --reset
|
||||
nrfjprog --family NRF52 --rbp ALL
|
||||
|
||||
echo %date% %time%
|
||||
pause
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
set CURDIR=%cd%
|
||||
|
||||
|
||||
|
||||
copy ..\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.hex medithings_bladder_patch_0001.hex
|
||||
copy ..\..\..\dfu\secure_bootloader\pca10056_s140_ble\arm5_no_packs\_build\nrf52840_xxaa_s140.hex medithings_bladder_patch_bootloader.hex
|
||||
|
||||
nrfutil settings generate --family NRF52840 --application medithings_bladder_patch_0001.hex --application-version 1 --bootloader-version 1 --bl-settings-version 2 medithings_bladder_patch_bootloader_setting.hex
|
||||
|
||||
mergehex.exe --merge s140_nrf52_7.2.0_softdevice.hex medithings_bladder_patch_0001.hex --output medithings_bladder_patch_merged_1.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_bootloader.hex medithings_bladder_patch_bootloader_setting.hex --output medithings_bladder_patch_merged_2.hex
|
||||
mergehex.exe --merge medithings_bladder_patch_merged_1.hex medithings_bladder_patch_merged_2.hex --output medithings_bladder_patch_dfu_merged_all.hex
|
||||
|
||||
nrfjprog --family NRF52 --program medithings_bladder_patch_0001.hex
|
||||
nrfjprog --family NRF52 --reset
|
||||
|
||||
|
||||
|
||||
pause
|
||||
137
project/ble_peripheral/ble_app_bladder_patch/hex/cp.bat
Normal file
137
project/ble_peripheral/ble_app_bladder_patch/hex/cp.bat
Normal file
@@ -0,0 +1,137 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
echo ==========================================
|
||||
echo MEDiThings Bladder Patch Programming
|
||||
echo (mergehex + nrfutil 8.x)
|
||||
echo ==========================================
|
||||
|
||||
REM -----------------------------------------------------
|
||||
REM Create hex output folder
|
||||
REM -----------------------------------------------------
|
||||
if not exist hex mkdir hex
|
||||
|
||||
REM -----------------------------------------------------
|
||||
REM 1. Copy HEX files
|
||||
REM -----------------------------------------------------
|
||||
echo [1/7] Copying HEX files...
|
||||
copy "..\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.hex" hex\app.hex
|
||||
copy "..\..\..\dfu\secure_bootloader\pca10056_s140_ble\arm5_no_packs\_build\nrf52840_xxaa_s140.hex" hex\boot.hex
|
||||
|
||||
if %errorlevel% neq 0 (
|
||||
echo ERROR: failed copying files.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM -----------------------------------------------------
|
||||
REM 2. Generate Bootloader DFU Settings
|
||||
REM -----------------------------------------------------
|
||||
echo [2/7] Generating Bootloader DFU settings...
|
||||
nrfutil settings generate ^
|
||||
--family NRF52840 ^
|
||||
--application hex\app.hex ^
|
||||
--application-version 1 ^
|
||||
--bootloader-version 1 ^
|
||||
--bl-settings-version 2 ^
|
||||
hex\settings.hex
|
||||
|
||||
if %errorlevel% neq 0 (
|
||||
echo ERROR: nrfutil settings failed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM -----------------------------------------------------
|
||||
REM 3. Merge HEX (SoftDevice + Application)
|
||||
REM -----------------------------------------------------
|
||||
echo [3/7] Merging SoftDevice + Application...
|
||||
mergehex.exe --merge s140_nrf52_7.2.0_softdevice.hex hex\app.hex --output hex\part1.hex
|
||||
|
||||
if %errorlevel% neq 0 (
|
||||
echo ERROR: mergehex part1 failed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM -----------------------------------------------------
|
||||
REM 4. Merge HEX (Bootloader + Settings)
|
||||
REM -----------------------------------------------------
|
||||
echo [4/7] Merging Bootloader + Settings...
|
||||
mergehex.exe --merge hex\boot.hex hex\settings.hex --output hex\part2.hex
|
||||
|
||||
if %errorlevel% neq 0 (
|
||||
echo ERROR: mergehex part2 failed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM -----------------------------------------------------
|
||||
REM 5. Final HEX merge (Combine everything)
|
||||
REM -----------------------------------------------------
|
||||
echo [5/7] Creating final combined HEX...
|
||||
mergehex.exe --merge hex\part1.hex hex\part2.hex --output hex\firmware_all.hex
|
||||
|
||||
if %errorlevel% neq 0 (
|
||||
echo ERROR: mergehex final merge failed.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Final merged HEX: hex\firmware_all.hex
|
||||
|
||||
REM -----------------------------------------------------
|
||||
REM 6. Detect device SERIAL NUMBER
|
||||
REM -----------------------------------------------------
|
||||
echo [6/7] Detecting device serial number...
|
||||
|
||||
for /f %%A in ('
|
||||
powershell -Command "(nrfutil device list --json | Select-String '\"type\":\"info\"' | ConvertFrom-Json).data.devices[0].serialNumber"
|
||||
') do set SERIALNUMBER=%%A
|
||||
|
||||
if "%SERIALNUMBER%"=="" (
|
||||
echo ERROR: No serial number found.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Using Serial Number: %SERIALNUMBER%
|
||||
echo Flashing: recover → erase → program → reset
|
||||
|
||||
REM recover
|
||||
nrfutil device recover --serial-number %SERIALNUMBER%
|
||||
if %errorlevel% neq 0 goto flash_fail
|
||||
|
||||
REM erase
|
||||
nrfutil device erase --serial-number %SERIALNUMBER%
|
||||
if %errorlevel% neq 0 goto flash_fail
|
||||
|
||||
REM program
|
||||
nrfutil device program --firmware hex\firmware_all.hex --serial-number %SERIALNUMBER%
|
||||
if %errorlevel% neq 0 goto flash_fail
|
||||
|
||||
REM reset
|
||||
nrfutil device reset --serial-number %SERIALNUMBER%
|
||||
if %errorlevel% neq 0 goto flash_fail
|
||||
|
||||
goto flash_success
|
||||
|
||||
:flash_fail
|
||||
echo ERROR: Flashing failed.
|
||||
pause
|
||||
exit /b 1
|
||||
|
||||
:flash_success
|
||||
|
||||
REM -----------------------------------------------------
|
||||
REM 7. Set Readback Protection (RBP)
|
||||
REM -----------------------------------------------------
|
||||
echo [7/7] Setting Readback Protection (ALL)...
|
||||
nrfutil device protection-set ALL --serial-number %SERIALNUMBER%
|
||||
|
||||
echo ==========================================
|
||||
echo Programming Complete!
|
||||
echo %date% %time%
|
||||
echo ==========================================
|
||||
pause
|
||||
endlocal
|
||||
@@ -0,0 +1,3 @@
|
||||
nrfjprog --family NRF52 --recover
|
||||
nrfjprog --family NRF52 --eraseall
|
||||
pause
|
||||
@@ -0,0 +1,3 @@
|
||||
nrfjprog --family NRF52 --rbp ALL
|
||||
nrfjprog --family NRF52 --pinreset
|
||||
pause
|
||||
@@ -0,0 +1,2 @@
|
||||
nrfjprog --family NRF52 --recover
|
||||
pause
|
||||
@@ -0,0 +1,2 @@
|
||||
nrfjprog --family NRF52 --pinreset
|
||||
pause
|
||||
@@ -0,0 +1,8 @@
|
||||
chcp 437
|
||||
set CURDIR=%cd%
|
||||
|
||||
|
||||
copy ..\pca10056\s140\arm5_no_packs\_build\nrf52840_xxaa.hex medithings_bladder_patch_0001.hex
|
||||
|
||||
nrfutil pkg generate --application medithings_bladder_patch_0001.hex --application-version 1 --hw-version 52 --sd-req 0x0100 --sd-id 0x0100 --key-file private.key medithings_bladder_patch_dfu.zip
|
||||
pause
|
||||
413
project/ble_peripheral/ble_app_bladder_patch/hex/log.log
Normal file
413
project/ble_peripheral/ble_app_bladder_patch/hex/log.log
Normal file
@@ -0,0 +1,413 @@
|
||||
[2025-Dec-02 21:41:39] [debug] --------------------------------------------------------------------------------
|
||||
[2025-Dec-02 21:41:39] [debug] nrfjprog --recover -s 682580999 --log
|
||||
[2025-Dec-02 21:41:39] [debug] nrfjprog version 10.19.0 external
|
||||
[2025-Dec-02 21:41:39] [debug] --------------------------------------------------------------------------------
|
||||
[2025-Dec-02 21:41:39] [ info] Load library at d:\nrfutil\bin\nrfjprog.dll.
|
||||
[2025-Dec-02 21:41:39] [ info] Library loaded, loading member functions.
|
||||
[2025-Dec-02 21:41:39] [ info] Member functions succesfully loaded.
|
||||
[2025-Dec-02 21:41:39] [debug] [ Client] - open
|
||||
[2025-Dec-02 21:41:39] [debug] [ Client] - start
|
||||
[2025-Dec-02 21:41:39] [ info] [ Client] - stdout: Jlinkarm nRF Worker ready. Handling sequence 9216d55f-e6c3-46dc-87a3-92d9ff8623b1.
|
||||
|
||||
[2025-Dec-02 21:41:39] [trace] [ Client] - Command open executed for 36 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - Logger sink registered in Segger backend logger
|
||||
[2025-Dec-02 21:41:39] [debug] [ Client] - config
|
||||
[2025-Dec-02 21:41:39] [debug] [ JLink] - Logger sink registered in JLink logger
|
||||
[2025-Dec-02 21:41:39] [debug] [ nRFXX] - open
|
||||
[2025-Dec-02 21:41:39] [debug] [ nRFXX] - just_check_family
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - open_dll
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - No J-Link DLL path was provided. Attempting to auto detect.
|
||||
[2025-Dec-02 21:41:39] [ info] [SeggerBackend] - Load library at C:\Program Files\SEGGER\JLink_V818\JLinkARM.dll.
|
||||
[2025-Dec-02 21:41:39] [ info] [SeggerBackend] - Library loaded, loading member functions.
|
||||
[2025-Dec-02 21:41:39] [ info] [SeggerBackend] - Member functions succesfully loaded.
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - Set batch mode
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - dll_version
|
||||
[2025-Dec-02 21:41:39] [ info] [SeggerBackend] - Segger dll version 8.18. loaded.
|
||||
[2025-Dec-02 21:41:39] [trace] [ Worker] - Command open executed for 4 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:39] [trace] [ Client] - Command config executed for 15 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:39] [debug] [ Client] - enum_emu_snr
|
||||
[2025-Dec-02 21:41:39] [debug] [ nRFXX] - config
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - enum_emu_snr
|
||||
[2025-Dec-02 21:41:39] [trace] [ Worker] - Command config executed for 2 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:39] [trace] [ Client] - Command enum_emu_con_info executed for 15 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:39] [debug] [ Client] - connect_to_emu_with_snr
|
||||
[2025-Dec-02 21:41:39] [debug] [ nRFXX] - enum_emu_con_info
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - is_connected_to_emu
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - enum_emu_con_info
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - is_connected_to_emu
|
||||
[2025-Dec-02 21:41:39] [trace] [ Worker] - Command enum_emu_con_info executed for 3 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:39] [debug] [ nRFXX] - connect_to_emu_with_snr
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - is_connected_to_emu
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - connect_to_emu_with_snr
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - is_connected_to_emu
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - ---just_enum_emu_snr
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - ---just_get_num_emus
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - ---just_connect_to_emu_with_snr
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - ---just_connect_to_emu_without_snr
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - Segger logging enabled.
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jul 8 2025 10:14:41
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jul 8 2025 10:14:41
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - Hardware: V1.00
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - S/N: 682580999
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - OEM: SEGGER
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - Bootloader: 2014 Sep 11
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - USB speed mode: High speed (480 MBit/s)
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - TELNET listener socket opened on port 19021
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - WEBSRV WEBSRV_Init(): Starting webserver thread(s)
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - WEBSRV Webserver running on local port 19080
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - Looking for J-Link GUI Server exe at: C:\Program Files\SEGGER\JLink_V818\JLinkGUIServer.exe
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - Forking J-Link GUI Server: C:\Program Files\SEGGER\JLink_V818\JLinkGUIServer.exe
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - J-Link GUI Server info: "J-Link GUI server V8.18 "
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 37.124ms returns "O.K."
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_Lock()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_ExecCommand("SetRestartOnClose = 0", ...).
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.001ms returns 0x01
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_ExecCommand("DisableFlashDL", ...).
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.000ms returns 0x00
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_ExecCommand("ExcludeFlashCacheRange 0x0-0xFFFFFFFF", ...).
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.002ms returns 0x00
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_SetHookUnsecureDialog
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_SetHookUnsecureDialog(...)
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.010ms returns 0
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_TIF_Select(JLINKARM_TIF_SWD)
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.479ms returns 0x00
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_GetSpeedInfo()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - 10000000 Hz / n, n >= 10
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.007ms
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - Connected emulator supports SWD speeds up to 1000kHz
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - Requested speed 2000kHz is higher than the emulator max speed of 1000kHz
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_SetSpeed(2000)
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.046ms
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_GetSpeed()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.003ms returns 1000
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - SWD speed was reported as 1000kHz after requesting 2000kHz. Check the capabilities of the selected emulator.
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_GetSN()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.003ms returns 682580999
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.004ms
|
||||
[2025-Dec-02 21:41:39] [debug] [ nRFXX] - read_device_family
|
||||
[2025-Dec-02 21:41:39] [debug] [ nRFXX] - read_device_family
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - is_connected_to_emu
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_IsOpen()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.003ms returns 0x01
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_Lock()
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - read_debug_port_idr
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - read_debug_port_register
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - ---just_read_debug_port_register
|
||||
[2025-Dec-02 21:41:39] [debug] [SeggerBackend] - coresight_configure
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_GetHWStatus(...)
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - - 0.137ms returns 0
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:39] [trace] [ JLink] - JLINK_CORESIGHT_Configure()
|
||||
[2025-Dec-02 21:41:40] [trace] [ Client] - Command connect_to_emu_with_snr executed for 188 milliseconds with result -102
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 104.594ms returns 0
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - read_debug_port_idr
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - read_debug_port_register
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_read_debug_port_register
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_select_debug_port_register
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Select AP 255, DP Bank 0, AP Bank 255
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.793ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.780ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.970ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.732ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.740ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.736ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.698ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.741ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.721ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.726ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.707ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.703ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.716ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.728ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.727ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.760ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.765ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.722ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.723ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.734ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.711ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.715ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.714ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.710ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.716ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.750ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.718ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.849ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.744ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.761ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.040ms
|
||||
[2025-Dec-02 21:41:40] [trace] [ Worker] - Command connect_to_emu_with_snr executed for 187 milliseconds with result -102
|
||||
[2025-Dec-02 21:41:40] [debug] [ nRFXX] - close
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - is_connected_to_emu
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_IsOpen()
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.005ms returns 0x01
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_Lock()
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - close
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - disconnect_from_emu
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_disconnect_from_emu
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - is_connected_to_device
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_IsConnected()
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.003ms returns FALSE
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_is_debug_region_powered
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_read_debug_port_register
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_select_debug_port_register
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Select AP 255, DP Bank 0, AP Bank 255
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.733ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.759ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.720ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.772ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.740ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.725ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.734ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.746ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.738ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.735ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.746ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.723ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.717ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.753ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.737ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.741ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.818ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.725ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.717ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.704ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.727ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.711ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.686ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.719ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.721ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - ---just_abort_debug_action
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Attempting to clear any configuration errors in debug port before closing connection.
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.760ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.786ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.739ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.764ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x00, 0x0000001F)
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.793ms returns -1
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_HasError()
|
||||
[2025-Dec-02 21:41:40] [error] [SeggerBackend] - JLinkARM.dll reported "-1", "An unknown error.".
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - - 0.028ms
|
||||
[2025-Dec-02 21:41:40] [trace] [ JLink] - JLINK_Close()
|
||||
[2025-Dec-02 21:41:40] [debug] [SeggerBackend] - Segger Backend closed.
|
||||
[2025-Dec-02 21:41:40] [debug] [ nRFXX] - nRF family DLL closed
|
||||
[2025-Dec-02 21:41:40] [trace] [ Worker] - Command close executed for 60 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:40] [trace] [ Client] - Command close executed for 61 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:40] [debug] [ Client] - terminate
|
||||
[2025-Dec-02 21:41:40] [trace] [ Client] - Command terminate executed for 0 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:40] [trace] [ Worker] - Command terminate executed for 0 milliseconds with result 0
|
||||
[2025-Dec-02 21:41:40] [trace] [ Worker] - Executed 6 commands for 256 milliseconds
|
||||
[2025-Dec-02 21:41:40] [debug] [ Client] - Worker process exited with code: 0
|
||||
[2025-Dec-02 21:41:40] [debug] [ Client] - Worker process exited with code: 0
|
||||
[2025-Dec-02 21:41:40] [debug] [ Client] - Child process terminated with result 0
|
||||
[2025-Dec-02 21:41:40] [trace] [ Client] - Executed 6 commands for 315 milliseconds
|
||||
@@ -0,0 +1,5 @@
|
||||
-----BEGIN EC PRIVATE KEY-----
|
||||
MHcCAQEEIHf/LPF4rHM8BNLwocN5rRNXA7nxqMZytmagH4csLaBUoAoGCCqGSM49
|
||||
AwEHoUQDQgAE1ZAavjWbKjEoGnKJm65rdtwnIIG8F15sg2pw5QPLW2f6iAh24ig+
|
||||
A8fY5qAD1vbELamAp4bYO9daX3m1OSRL7A==
|
||||
-----END EC PRIVATE KEY-----
|
||||
@@ -0,0 +1,3 @@
|
||||
set path=d:\nrfutil\bin;%path%
|
||||
d:
|
||||
cd D:\mt_project\mt_firmware\project\ble_peripheral\ble_app_bladder_patch\hex
|
||||
94
project/ble_peripheral/ble_app_bladder_patch/i2c_manager.c
Normal file
94
project/ble_peripheral/ble_app_bladder_patch/i2c_manager.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/*******************************************************************************
|
||||
* @file i2c_manager.c
|
||||
* @brief Reliable HW↔SW I2C Switching Logic (with Mode Set Logging)
|
||||
******************************************************************************/
|
||||
|
||||
#include "i2c_manager.h"
|
||||
#include "debug_print.h"
|
||||
#include "nrf_delay.h"
|
||||
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "nrf_drv_twi.h"
|
||||
#include "cat_interface.h"
|
||||
bool HW_I2C_FRQ = true;
|
||||
bool SW_I2C_FRQ = false;
|
||||
|
||||
/* 외부 EEPROM TWI 인스턴스 */
|
||||
extern const nrf_drv_twi_t m_eeprom;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* HW (TWI) 초기화 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void hw_i2c_init_once(void)
|
||||
{
|
||||
// SW 모드일 경우 강제 해제 후 HW 전환
|
||||
if (SW_I2C_FRQ)
|
||||
{
|
||||
//DBG_PRINTF("[I2C]SW→HW\r\n");
|
||||
|
||||
// SW 리소스 해제 (필요 시 추가)
|
||||
SW_I2C_FRQ = false;
|
||||
nrf_delay_ms(2);
|
||||
}
|
||||
|
||||
// 이미 HW면 스킵
|
||||
if (HW_I2C_FRQ)
|
||||
{
|
||||
// DBG_PRINTF("[I2C] HW I2C set\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 실제 HW 초기화
|
||||
eeprom_initialize();
|
||||
nrf_delay_ms(2);
|
||||
|
||||
HW_I2C_FRQ = true;
|
||||
SW_I2C_FRQ = false;
|
||||
|
||||
// DBG_PRINTF("[I2C] HW I2C Mode set!\r\n");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* SW (Port Bang-Bang) 초기화 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void sw_i2c_init_once(void)
|
||||
{
|
||||
// HW 모드일 경우 강제 해제 후 SW 전환
|
||||
if (HW_I2C_FRQ)
|
||||
{
|
||||
//DBG_PRINTF("[I2C]HW→SW\r\n");
|
||||
|
||||
nrf_drv_twi_disable(&m_eeprom);
|
||||
nrf_drv_twi_uninit(&m_eeprom);
|
||||
nrf_delay_ms(2);
|
||||
|
||||
HW_I2C_FRQ = false;
|
||||
}
|
||||
|
||||
// 이미 SW 모드면 재실행 금지
|
||||
if (SW_I2C_FRQ)
|
||||
{
|
||||
// DBG_PRINTF("[I2C] SWI2C already initialized\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 실제 SW 초기화
|
||||
eeprom_uninitialize(); // TWI 라인 해제
|
||||
nrf_delay_ms(1);
|
||||
mcp4725_init(); // Port BangBang 방식 DAC init
|
||||
|
||||
SW_I2C_FRQ = true;
|
||||
HW_I2C_FRQ = false;
|
||||
|
||||
// DBG_PRINTF("[I2C] SW I2C Mode set!\r\n");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 전체 리셋 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void i2c_reset_state(void)
|
||||
{
|
||||
HW_I2C_FRQ = false;
|
||||
SW_I2C_FRQ = false;
|
||||
DBG_PRINTF("Flags reset\r\n");
|
||||
}
|
||||
18
project/ble_peripheral/ble_app_bladder_patch/i2c_manager.h
Normal file
18
project/ble_peripheral/ble_app_bladder_patch/i2c_manager.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* @file i2c_manager.h
|
||||
* @brief Common header for HW/SW I2C mutex control
|
||||
******************************************************************************/
|
||||
#ifndef __I2C_MANAGER_H__
|
||||
#define __I2C_MANAGER_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "app_error.h"
|
||||
|
||||
extern bool HW_I2C_FRQ;
|
||||
extern bool SW_I2C_FRQ;
|
||||
|
||||
void hw_i2c_init_once(void);
|
||||
void sw_i2c_init_once(void);
|
||||
void i2c_reset_state(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#include "DataConverter.h"
|
||||
|
||||
uint8_t * inv_dc_int32_to_little8(int32_t x, uint8_t * little8)
|
||||
{
|
||||
little8[3] = (uint8_t)((x >> 24) & 0xff);
|
||||
little8[2] = (uint8_t)((x >> 16) & 0xff);
|
||||
little8[1] = (uint8_t)((x >> 8) & 0xff);
|
||||
little8[0] = (uint8_t)(x & 0xff);
|
||||
|
||||
return little8;
|
||||
}
|
||||
|
||||
uint8_t * inv_dc_int16_to_little8(int16_t x, uint8_t * little8)
|
||||
{
|
||||
little8[0] = (uint8_t)(x & 0xff);
|
||||
little8[1] = (uint8_t)((x >> 8) & 0xff);
|
||||
|
||||
return little8;
|
||||
}
|
||||
|
||||
uint8_t * inv_dc_int32_to_big8(int32_t x, uint8_t * big8)
|
||||
{
|
||||
big8[0] = (uint8_t)((x >> 24) & 0xff);
|
||||
big8[1] = (uint8_t)((x >> 16) & 0xff);
|
||||
big8[2] = (uint8_t)((x >> 8) & 0xff);
|
||||
big8[3] = (uint8_t)(x & 0xff);
|
||||
|
||||
return big8;
|
||||
}
|
||||
|
||||
int32_t inv_dc_little8_to_int32(const uint8_t * little8)
|
||||
{
|
||||
int32_t x = 0;
|
||||
|
||||
x |= ((int32_t)little8[3] << 24);
|
||||
x |= ((int32_t)little8[2] << 16);
|
||||
x |= ((int32_t)little8[1] << 8);
|
||||
x |= ((int32_t)little8[0]);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int16_t inv_dc_big16_to_int16(uint8_t * data)
|
||||
{
|
||||
int16_t result;
|
||||
|
||||
result = (*data << 8);
|
||||
data++;
|
||||
result |= *data;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int16_t inv_dc_le_to_int16(const uint8_t * little8)
|
||||
{
|
||||
uint16_t x = 0;
|
||||
|
||||
x |= ((uint16_t)little8[0]);
|
||||
x |= ((uint16_t)little8[1] << 8);
|
||||
|
||||
return (int16_t)x;
|
||||
}
|
||||
|
||||
void inv_dc_sfix32_to_float(const int32_t * in, uint32_t len, uint8_t qx, float * out)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < len; ++i) {
|
||||
out[i] = (float)in[i] / (1 << qx);
|
||||
}
|
||||
}
|
||||
|
||||
void inv_dc_float_to_sfix32(const float * in, uint32_t len, uint8_t qx, int32_t * out)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for(i = 0; i < len; ++i) {
|
||||
out[i] = (int32_t)((in[i] * (1 << qx)) + ((in[i] >= 0) - 0.5f));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @defgroup DataConverter Data Converter
|
||||
* @brief Helper functions to convert integer
|
||||
* @ingroup EmbUtils
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _INV_DATA_CONVERTER_H_
|
||||
#define _INV_DATA_CONVERTER_H_
|
||||
|
||||
#include "InvExport.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/** @brief Converts a 32-bit long to a little endian byte stream
|
||||
*/
|
||||
uint8_t INV_EXPORT * inv_dc_int32_to_little8(int32_t x, uint8_t * little8);
|
||||
|
||||
/** @brief Converts a 16-bit integer to a little endian byte stream
|
||||
*/
|
||||
uint8_t INV_EXPORT * inv_dc_int16_to_little8(int16_t x, uint8_t * little8);
|
||||
|
||||
/** @brief Converts a 32-bit long to a big endian byte stream
|
||||
*/
|
||||
uint8_t INV_EXPORT * inv_dc_int32_to_big8(int32_t x, uint8_t *big8);
|
||||
|
||||
/** @brief Converts a little endian byte stream into a 32-bit integer
|
||||
*/
|
||||
int32_t INV_EXPORT inv_dc_little8_to_int32(const uint8_t * little8);
|
||||
|
||||
/** @brief Converts a little endian byte stream into a 16-bit integer
|
||||
*/
|
||||
int16_t INV_EXPORT inv_dc_le_to_int16(const uint8_t * little8);
|
||||
|
||||
/** @brief Converts big endian on 16 bits into an unsigned short
|
||||
*/
|
||||
int16_t INV_EXPORT inv_dc_big16_to_int16(uint8_t * data);
|
||||
|
||||
/** @brief Converts an array of 32-bit signed fixed-point integers to an array of floats
|
||||
* @param[in] in Pointer to the first element of the array of 32-bit signed fixed-point integers
|
||||
* @param[in] len Length of the array
|
||||
* @param[in] qx Number of bits used to represent the decimal part of the fixed-point integers
|
||||
* @param[out] out Pointer to the memory area where the output will be stored
|
||||
*/
|
||||
void INV_EXPORT inv_dc_sfix32_to_float(const int32_t * in, uint32_t len, uint8_t qx, float * out);
|
||||
|
||||
/** @brief Converts an array of floats to an array of 32-bit signed fixed-point integers
|
||||
* @param[in] in Pointer to the first element of the array of floats
|
||||
* @param[in] len Length of the array
|
||||
* @param[in] qx Number of bits used to represent the decimal part of the fixed-point integers
|
||||
* @param[out] out Pointer to the memory area where the output will be stored
|
||||
*/
|
||||
void INV_EXPORT inv_dc_float_to_sfix32(const float * in, uint32_t len, uint8_t qx, int32_t * out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INV_DATA_CONVERTER_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#include "ErrorHelper.h"
|
||||
|
||||
const char * inv_error_str(int error)
|
||||
{
|
||||
switch(error) {
|
||||
case INV_ERROR_SUCCESS: return "Success";
|
||||
case INV_ERROR: return "Unspecified error";
|
||||
case INV_ERROR_NIMPL: return "Not implemented";
|
||||
case INV_ERROR_TRANSPORT: return "Transport error";
|
||||
case INV_ERROR_TIMEOUT: return "Timeout, action did not complete in time";
|
||||
case INV_ERROR_SIZE: return "Wrong size error";
|
||||
case INV_ERROR_OS: return "Operating system failure";
|
||||
case INV_ERROR_IO: return "Input/Output error";
|
||||
case INV_ERROR_MEM: return "Bad allocation";
|
||||
case INV_ERROR_HW: return "Hardware error";
|
||||
case INV_ERROR_BAD_ARG: return "Invalid arguments";
|
||||
case INV_ERROR_UNEXPECTED: return "Unexpected error";
|
||||
case INV_ERROR_FILE: return "Invalid file format";
|
||||
case INV_ERROR_PATH: return "Invalid file path";
|
||||
case INV_ERROR_IMAGE_TYPE: return "Unknown image type";
|
||||
case INV_ERROR_WATCHDOG: return "Watchdog error";
|
||||
default: return "Unknown error";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @defgroup ErrorHelper Error Helper
|
||||
* @brief Helper functions related to error code
|
||||
* @ingroup EmbUtils
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _INV_ERROR_HELPER_H_
|
||||
#define _INV_ERROR_HELPER_H_
|
||||
|
||||
#include "InvExport.h"
|
||||
#include "InvError.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Returns string describing error number
|
||||
* @sa enum inv_error
|
||||
*/
|
||||
const char INV_EXPORT * inv_error_str(int error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INV_ERROR_HELPER_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 InvenSense Inc. Portions Copyright (c) 2014-2015 Movea. All rights reserved.
|
||||
|
||||
This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
to InvenSense and its licensors' intellectual property rights under U.S. and international copyright and
|
||||
other intellectual property rights laws.
|
||||
|
||||
InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
and any use, reproduction, disclosure or distribution of the Software without an express license
|
||||
agreement from InvenSense is strictly prohibited.
|
||||
*/
|
||||
|
||||
#include "InvBasicMath.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
unsigned int InvBasicMath_log2u(unsigned int val)
|
||||
{
|
||||
unsigned int ret = UINT_MAX;
|
||||
|
||||
while (val != 0) {
|
||||
val >>= 1;
|
||||
ret++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int InvBasicMath_isAnOrthonormalMatrix(const float matrix[9])
|
||||
{
|
||||
// Check if matrix is orthogonal
|
||||
// Matrix is orthogonal if transpose(Matrix) x Matrix = Identity
|
||||
|
||||
float transpose[9];
|
||||
float mult[9];
|
||||
int i, j;
|
||||
|
||||
// Compute Transpose(matrix)
|
||||
for (i = 0; i < 3; i++) {
|
||||
for(j = 0; j < 3; j++) {
|
||||
transpose[i*3+j] = matrix[i+j*3];
|
||||
}
|
||||
}
|
||||
|
||||
// Multiply transpose x matrix
|
||||
mult[0] = transpose[0]*matrix[0] + transpose[1]*matrix[3] + transpose[2]*matrix[6];
|
||||
mult[1] = transpose[0]*matrix[1] + transpose[1]*matrix[4] + transpose[2]*matrix[7];
|
||||
mult[2] = transpose[0]*matrix[2] + transpose[1]*matrix[5] + transpose[2]*matrix[8];
|
||||
|
||||
mult[3] = transpose[3]*matrix[0] + transpose[4]*matrix[3] + transpose[5]*matrix[6];
|
||||
mult[4] = transpose[3]*matrix[1] + transpose[4]*matrix[4] + transpose[5]*matrix[7];
|
||||
mult[5] = transpose[3]*matrix[2] + transpose[4]*matrix[5] + transpose[5]*matrix[8];
|
||||
|
||||
mult[6] = transpose[6]*matrix[0] + transpose[7]*matrix[3] + transpose[8]*matrix[6];
|
||||
mult[7] = transpose[6]*matrix[1] + transpose[7]*matrix[4] + transpose[8]*matrix[7];
|
||||
mult[8] = transpose[6]*matrix[2] + transpose[7]*matrix[5] + transpose[8]*matrix[8];
|
||||
|
||||
// Check that mult is identity
|
||||
for (i = 0; i < 3; i++) {
|
||||
for(j = 0; j < 3; j++) {
|
||||
if (i == j) {
|
||||
if (mult[i+j*3] != 1)
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (mult[i+j*3] != 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
float InvBasicMath_computeMatrixDeterminant(const float matrix[9])
|
||||
{
|
||||
return matrix[0] * (matrix[4]*matrix[8] - matrix[7]*matrix[5])
|
||||
-matrix[1] * (matrix[3]*matrix[8] - matrix[6]*matrix[5])
|
||||
+matrix[2] * (matrix[3]*matrix[7] - matrix[4]*matrix[6]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 InvenSense Inc. Portions Copyright (c) 2014-2015 Movea. All rights reserved.
|
||||
|
||||
This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
to InvenSense and its licensors' intellectual property rights under U.S. and international copyright and
|
||||
other intellectual property rights laws.
|
||||
|
||||
InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
and any use, reproduction, disclosure or distribution of the Software without an express license
|
||||
agreement from InvenSense is strictly prohibited.
|
||||
*/
|
||||
|
||||
/** @defgroup InvBasicMath InvBasicMath
|
||||
@brief This file contains basic (overloadable) math functions and macros
|
||||
@ingroup EmbUtils
|
||||
@{
|
||||
*/
|
||||
|
||||
#ifndef _INV_BASIC_MATH_H_
|
||||
#define _INV_BASIC_MATH_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Return absolute value of argument
|
||||
*/
|
||||
#ifndef INV_ABS
|
||||
# define INV_ABS(a) ((a) < 0 ? -(a) : (a))
|
||||
#endif
|
||||
|
||||
/** @brief Return minimum of two arguments
|
||||
*/
|
||||
#ifndef INV_MIN
|
||||
# define INV_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/** @brief Return maximum of two arguments
|
||||
*/
|
||||
#ifndef INV_MAX
|
||||
# define INV_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/** @brief Define value for pi
|
||||
*/
|
||||
#ifndef INV_PI
|
||||
# define INV_PI 3.14159265358979
|
||||
#endif
|
||||
#ifndef M_PI
|
||||
# define M_PI INV_PI
|
||||
#endif
|
||||
|
||||
/** @brief Return saturated integer
|
||||
*/
|
||||
#ifndef INV_SATURATE
|
||||
static inline long InvBasicMath_saturatel(long in, long min, long max)
|
||||
{
|
||||
if (in > max)
|
||||
return max;
|
||||
else if (in < min)
|
||||
return min;
|
||||
else
|
||||
return in;
|
||||
}
|
||||
# define INV_SATURATE(a, min, max) InvBasicMath_saturatel(a, min, max)
|
||||
#endif
|
||||
|
||||
/** @brief Compute log2 from integer
|
||||
*/
|
||||
#ifndef INV_LOG2
|
||||
unsigned int InvBasicMath_log2u(unsigned int val);
|
||||
# define INV_LOG2(a) InvBasicMath_log2u(a)
|
||||
#endif
|
||||
|
||||
/** @brief Check if matrix is orthonormal
|
||||
* @param [in] matrix 3x3 Matrix to be checked
|
||||
* @return 1 if it is an orthonormal matrix, 0 otherwise
|
||||
*/
|
||||
int InvBasicMath_isAnOrthonormalMatrix(const float matrix[9]);
|
||||
|
||||
/** @brief Compute the determinant of the matrix
|
||||
* @param [in] matrix 3x3 Matrix to be checked
|
||||
* @return the determinant value
|
||||
*/
|
||||
float InvBasicMath_computeMatrixDeterminant(const float matrix[9]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INV_BASIC_MATH_H_ */
|
||||
|
||||
/** @} */
|
||||
|
||||
@@ -0,0 +1,389 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 InvenSense Inc. Portions Copyright (c) 2014-2015 Movea. All rights reserved.
|
||||
|
||||
This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
to InvenSense and its licensors' intellectual property rights under U.S. and international copyright and
|
||||
other intellectual property rights laws.
|
||||
|
||||
InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
and any use, reproduction, disclosure or distribution of the Software without an express license
|
||||
agreement from InvenSense is strictly prohibited.
|
||||
*/
|
||||
|
||||
/** \defgroup RingBuffer RingBuffer
|
||||
\brief Macros to manage static circular buffer of any data type
|
||||
\ingroup EmbUtils
|
||||
\{
|
||||
*/
|
||||
|
||||
#ifndef _RING_BUFFER_H_
|
||||
#define _RING_BUFFER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/** \brief Macro to declare a ring buffer
|
||||
\param[in] type type of item contained in the ring buffer
|
||||
\param[in] size number of items that can contain the ring buffer
|
||||
To improve speed, size should be a power of 2
|
||||
*/
|
||||
#define RINGBUFFER_DECLARE(type, size) \
|
||||
struct { \
|
||||
uint16_t read, write; \
|
||||
type buffer[size]; \
|
||||
}
|
||||
|
||||
/** \brief Macro to declare a volatile ring buffer, i.e. modified within an interrupt context
|
||||
\param[in] type type of item contained in the ring buffer
|
||||
\param[in] size number of items that can contain the ring buffer
|
||||
To improve speed, size should be a power of 2
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_DECLARE(type, size) \
|
||||
struct { \
|
||||
volatile uint16_t read, write; \
|
||||
volatile type buffer[size]; \
|
||||
}
|
||||
|
||||
/** \brief Macro to declare a ring buffer
|
||||
\param[in] name name of the circular buffer
|
||||
\param[in] size number of items that can contain the ring buffer
|
||||
To improve speed, size should be a power of 2
|
||||
\param[in] type type of item contained in the ring buffer
|
||||
*/
|
||||
#define RINGBUFFER(name, size, type) RINGBUFFER_DECLARE(type, size) name
|
||||
|
||||
/** \brief Macro to declare a volatile ring buffer, i.e. modified within an interrupt context
|
||||
\param[in] name name of the circular buffer
|
||||
\param[in] size number of items that can contain the ring buffer
|
||||
To improve speed, size should be a power of 2
|
||||
\param[in] type type of item contained in the ring buffer
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE(name, size, type) RINGBUFFER_VOLATILE_DECLARE(type, size) name
|
||||
|
||||
/** \brief Macro to get maximum size of a ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return maximum number of items that can contain the ringbuffer
|
||||
*/
|
||||
#define RINGBUFFER_MAXSIZE(rb) (sizeof((rb)->buffer)/sizeof((rb)->buffer[0]))
|
||||
|
||||
/** \brief Macro to get maximum size of a volatile ring buffer, i.e. modified within an interrupt context
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return maximum number of items that can contain the ringbuffer
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_MAXSIZE(rb) RINGBUFFER_MAXSIZE(rb)
|
||||
|
||||
/** \brief Macro to get current size of a ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return current number of items hold in the ringbuffer
|
||||
*/
|
||||
#define RINGBUFFER_SIZE(rb) ((uint16_t)((rb)->write - (rb)->read))
|
||||
|
||||
static inline uint16_t get_ringbuffer_volatile_size(void * rb)
|
||||
{
|
||||
struct { uint16_t read, write; } rb_var;
|
||||
memcpy(&rb_var, rb, sizeof(rb_var));
|
||||
return (rb_var.write - rb_var.read);
|
||||
}
|
||||
|
||||
/** \brief Macro to get current size of a volatile ring buffer, i.e. modified within an interrupt context
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return current number of items hold in the ringbuffer
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_SIZE(rb) get_ringbuffer_volatile_size(rb)
|
||||
|
||||
/** \brief Macro to check if a ring buffer is full
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return 1 if there is no slot left in the ring buffer, 0 otherwise
|
||||
*/
|
||||
#define RINGBUFFER_FULL(rb) (RINGBUFFER_SIZE(rb) == RINGBUFFER_MAXSIZE(rb))
|
||||
|
||||
/** \brief Macro to check if a volatile ring buffer, i.e. modified within an interrupt context, is full
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return 1 if there is no slot left in the ring buffer, 0 otherwise
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_FULL(rb) (RINGBUFFER_VOLATILE_SIZE(rb) == RINGBUFFER_VOLATILE_MAXSIZE(rb))
|
||||
|
||||
/** \brief Macro to check if a ring buffer is empty
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return 1 if there is no item in the ring buffer, 0 otherwise
|
||||
*/
|
||||
#define RINGBUFFER_EMPTY(rb) (RINGBUFFER_SIZE(rb) == 0)
|
||||
|
||||
/** \brief Macro to check if a volatile ring buffer, i.e. modified within an interrupt context, is empty
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return 1 if there is no item in the ring buffer, 0 otherwise
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_EMPTY(rb) (RINGBUFFER_VOLATILE_SIZE(rb) == 0)
|
||||
|
||||
/** \brief Macro to get number of available slot in a ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return number of empty slot in the ring buffer
|
||||
*/
|
||||
#define RINGBUFFER_AVAILABLE(rb) (RINGBUFFER_MAXSIZE(rb) - RINGBUFFER_SIZE(rb))
|
||||
|
||||
/** \brief Macro to get number of available slot in a volatile ring buffer, i.e. modified within an interrupt context
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\return number of empty slot in the ring buffer
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_AVAILABLE(rb) (RINGBUFFER_VOLATILE_MAXSIZE(rb) - RINGBUFFER_VOLATILE_SIZE(rb))
|
||||
|
||||
/** \brief Macro to clear a ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
*/
|
||||
#define RINGBUFFER_CLEAR(rb) \
|
||||
do { \
|
||||
(rb)->read = 0, (rb)->write = 0; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to clear a volatile ring buffer, i.e. modified within an interrupt context
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_CLEAR(rb) RINGBUFFER_CLEAR(rb)
|
||||
|
||||
/** \brief Push item by reference
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] refData to available item slot
|
||||
\warning There is no error checking done.
|
||||
*/
|
||||
#define RINGBUFFER_PUSHREF(rb, refData) \
|
||||
do { \
|
||||
refData = &(rb)->buffer[(rb)->write % RINGBUFFER_MAXSIZE(rb)]; \
|
||||
++(rb)->write; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Push item by reference
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] refData to available item slot
|
||||
\warning There is no error checking done.
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_PUSHREF(rb, refData) \
|
||||
do { \
|
||||
uint16_t wr_ptr = (rb)->write; \
|
||||
refData = &(rb)->buffer[wr_ptr % RINGBUFFER_VOLATILE_MAXSIZE(rb)]; \
|
||||
++(rb)->write; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Return reference to next available slot
|
||||
No push is performed
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] refData to available item slot
|
||||
\warning There is no error checking done.
|
||||
*/
|
||||
#define RINGBUFFER_GETREFNEXT(rb, refData) \
|
||||
do { \
|
||||
refData = &(rb)->buffer[(rb)->write % RINGBUFFER_MAXSIZE(rb)]; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Return reference to next available slot
|
||||
No push is performed
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] refData to available item slot
|
||||
\warning There is no error checking done.
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_GETREFNEXT(rb, refData) \
|
||||
do { \
|
||||
uint16_t wr_ptr = (rb)->write; \
|
||||
refData = &(rb)->buffer[wr_ptr % RINGBUFFER_VOLATILE_MAXSIZE(rb)]; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Increment write counter
|
||||
Actually performed a push (assuming data were already copied)
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\warning There is no error checking done.
|
||||
*/
|
||||
#define RINGBUFFER_INCREMENT(rb, refData) \
|
||||
do { \
|
||||
++(rb)->write; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Increment write counter
|
||||
Actually performed a push (assuming data were already copied)
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\warning There is no error checking done.
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_INCREMENT(rb, refData) \
|
||||
do { \
|
||||
++(rb)->write; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Return reference to youngest item
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] refData reference to youngest item
|
||||
\warning There is no error checking done.
|
||||
*/
|
||||
#define RINGBUFFER_BACK(rb, refData) \
|
||||
do { \
|
||||
refData = &(rb)->buffer[((rb)->write-1) % RINGBUFFER_MAXSIZE(rb)]; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Return reference to youngest item
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] refData reference to youngest item
|
||||
\warning There is no error checking done.
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_BACK(rb, refData) \
|
||||
do { \
|
||||
uint16_t wr_ptr = (rb)->write; \
|
||||
refData = &(rb)->buffer[(wr_ptr-1) % RINGBUFFER_VOLATILE_MAXSIZE(rb)]; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to push an item to a ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[in] ptrData pointer to the item to push.
|
||||
\warning There is no error checking done.
|
||||
You must check for fullness before pushing data
|
||||
*/
|
||||
#define RINGBUFFER_PUSH(rb, ptrData) \
|
||||
do { \
|
||||
(rb)->buffer[(rb)->write % RINGBUFFER_MAXSIZE(rb)] = *ptrData; \
|
||||
++(rb)->write; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to push an item to a volatile ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[in] ptrData pointer to the item to push.
|
||||
\warning There is no error checking done.
|
||||
You must check for fullness before pushing data
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_PUSH(rb, ptrData) \
|
||||
do { \
|
||||
uint16_t wr_ptr = (rb)->write; \
|
||||
(rb)->buffer[wr_ptr % RINGBUFFER_VOLATILE_MAXSIZE(rb)] = *ptrData; \
|
||||
++(rb)->write; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to unpush an item to a ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[in] ptrData pointer to placeholder to hold unpushed item
|
||||
\warning There is no error checking done.
|
||||
You must check for emptiness before pushing data
|
||||
*/
|
||||
#define RINGBUFFER_UNPUSH(rb, ptrData) \
|
||||
do { \
|
||||
--(rb)->write; \
|
||||
*ptrData = (rb)->buffer[(rb)->write % RINGBUFFER_MAXSIZE(rb)]; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to unpush an item to a volatile ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[in] ptrData pointer to placeholder to hold unpushed item
|
||||
\warning There is no error checking done.
|
||||
You must check for emptiness before pushing data
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_UNPUSH(rb, ptrData) \
|
||||
do { \
|
||||
--(rb)->write; \
|
||||
uint16_t wr_ptr = (rb)->write; \
|
||||
*ptrData = (rb)->buffer[wr_ptr % RINGBUFFER_VOLATILE_MAXSIZE(rb)]; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Return reference to oldest item
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] refData reference to oldest item
|
||||
\warning There is no error checking done.
|
||||
*/
|
||||
#define RINGBUFFER_FRONT(rb, refData) \
|
||||
do { \
|
||||
refData = &(rb)->buffer[(rb)->read % RINGBUFFER_MAXSIZE(rb)]; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Return reference to oldest item
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] refData reference to oldest item
|
||||
\warning There is no error checking done.
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_FRONT(rb, refData) \
|
||||
do { \
|
||||
uint16_t rd_ptr = (rb)->read; \
|
||||
refData = &(rb)->buffer[rd_ptr % RINGBUFFER_VOLATILE_MAXSIZE(rb)]; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to pop an item from a ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] ptrData pointer to placeholder to hold popped item
|
||||
\warning There is no error checking done.
|
||||
You must check for emptiness before popping data
|
||||
*/
|
||||
#define RINGBUFFER_POP(rb, ptrData) \
|
||||
do { \
|
||||
*ptrData = (rb)->buffer[(rb)->read % RINGBUFFER_MAXSIZE(rb)]; \
|
||||
++(rb)->read; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to pop an item from a volatile ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] ptrData pointer to placeholder to hold popped item
|
||||
\warning There is no error checking done.
|
||||
You must check for emptiness before popping data
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_POP(rb, ptrData) \
|
||||
do { \
|
||||
uint16_t rd_ptr = (rb)->read; \
|
||||
*ptrData = (rb)->buffer[rd_ptr % RINGBUFFER_VOLATILE_MAXSIZE(rb)]; \
|
||||
++(rb)->read; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to pop an item from a ring buffer (data is not copied)
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\warning There is no error checking done.
|
||||
You must check for emptiness before popping data
|
||||
*/
|
||||
#define RINGBUFFER_POPNLOSE(rb) \
|
||||
do { \
|
||||
++(rb)->read; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to pop an item from a volatile ring buffer (data is not copied)
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\warning There is no error checking done.
|
||||
You must check for emptiness before popping data
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_POPNLOSE(rb) \
|
||||
do { \
|
||||
++(rb)->read; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to unpop an item to a ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] ptrData pointer to to the item to unpop.
|
||||
\warning There is no error checking done.
|
||||
You must check for fullness before unpopping data
|
||||
*/
|
||||
#define RINGBUFFER_UNPOP(rb, ptrData) \
|
||||
do { \
|
||||
--(rb)->read; \
|
||||
(rb)->buffer[(rb)->read % RINGBUFFER_MAXSIZE(rb)] = *ptrData; \
|
||||
} while(0)
|
||||
|
||||
/** \brief Macro to unpop an item to a volatile ring buffer
|
||||
\param[in] rb pointer to the ring buffer
|
||||
\param[out] ptrData pointer to to the item to unpop.
|
||||
\warning There is no error checking done.
|
||||
You must check for fullness before unpopping data
|
||||
\warning it is advised to put this in a critical section
|
||||
*/
|
||||
#define RINGBUFFER_VOLATILE_UNPOP(rb, ptrData) \
|
||||
do { \
|
||||
--(rb)->read; \
|
||||
uint16_t rd_ptr = (rb)->read; \
|
||||
(rb)->buffer[rd_ptr % RINGBUFFER_VOLATILE_MAXSIZE(rb)] = *ptrData; \
|
||||
} while(0)
|
||||
|
||||
#endif
|
||||
|
||||
/** \} */
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @brief Custom definition for boolean type to avoid compiler discrepancies
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _INV_BOOL_H_
|
||||
#define _INV_BOOL_H_
|
||||
|
||||
typedef int inv_bool_t;
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
#ifndef true
|
||||
#define true 1
|
||||
#endif
|
||||
|
||||
#ifndef false
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _INV_BOOL_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @defgroup InvError Error code
|
||||
* @brief Common error code
|
||||
*
|
||||
* @ingroup EmbUtils
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _INV_ERROR_H_
|
||||
#define _INV_ERROR_H_
|
||||
|
||||
/** @brief Common error code definition
|
||||
*/
|
||||
enum inv_error
|
||||
{
|
||||
INV_ERROR_SUCCESS = 0, /**< no error */
|
||||
INV_ERROR = -1, /**< unspecified error */
|
||||
INV_ERROR_NIMPL = -2, /**< function not implemented for given
|
||||
arguments */
|
||||
INV_ERROR_TRANSPORT = -3, /**< error occurred at transport level */
|
||||
INV_ERROR_TIMEOUT = -4, /**< action did not complete in the expected
|
||||
time window */
|
||||
INV_ERROR_SIZE = -5, /**< size/length of given arguments is not
|
||||
suitable to complete requested action */
|
||||
INV_ERROR_OS = -6, /**< error related to OS */
|
||||
INV_ERROR_IO = -7, /**< error related to IO operation */
|
||||
INV_ERROR_MEM = -9, /**< not enough memory to complete requested
|
||||
action */
|
||||
INV_ERROR_HW = -10, /**< error at HW level */
|
||||
INV_ERROR_BAD_ARG = -11, /**< provided arguments are not good to
|
||||
perform requested action */
|
||||
INV_ERROR_UNEXPECTED = -12, /**< something unexpected happened */
|
||||
INV_ERROR_FILE = -13, /**< cannot access file or unexpected format */
|
||||
INV_ERROR_PATH = -14, /**< invalid file path */
|
||||
INV_ERROR_IMAGE_TYPE = -15, /**< error when image type is not managed */
|
||||
INV_ERROR_WATCHDOG = -16, /**< error when device doesn't respond
|
||||
to ping */
|
||||
};
|
||||
|
||||
#endif /* _INV_ERROR_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#ifndef _INV_IDD_EXPORT_H_
|
||||
#define _INV_IDD_EXPORT_H_
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if !defined(INV_EXPORT) && defined(INV_DO_DLL_EXPORT)
|
||||
#define INV_EXPORT __declspec(dllexport)
|
||||
#elif !defined(INV_EXPORT) && defined(INV_DO_DLL_IMPORT)
|
||||
#define INV_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(INV_EXPORT)
|
||||
#define INV_EXPORT
|
||||
#endif
|
||||
|
||||
#endif /* _INV_IDD_EXPORT_H_ */
|
||||
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2017 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#include "inv_imu_defs.h"
|
||||
#include "inv_imu_extfunc.h"
|
||||
#include "inv_imu_driver.h"
|
||||
#include "inv_imu_apex.h"
|
||||
|
||||
int inv_imu_apex_enable_ff(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
status |= inv_imu_start_dmp(s);
|
||||
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &value);
|
||||
value &= ~APEX_CONFIG1_FF_ENABLE_MASK;
|
||||
value |= (uint8_t)APEX_CONFIG1_FF_ENABLE_EN;
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG1, 1, &value);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_disable_ff(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &value);
|
||||
value &= ~APEX_CONFIG1_FF_ENABLE_MASK;
|
||||
value |= (uint8_t)APEX_CONFIG1_FF_ENABLE_DIS;
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG1, 1, &value);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_enable_smd(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
status |= inv_imu_start_dmp(s);
|
||||
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &value);
|
||||
value &= ~APEX_CONFIG1_SMD_ENABLE_MASK;
|
||||
value |= (uint8_t)APEX_CONFIG1_SMD_ENABLE_EN;
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG1, 1, &value);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_disable_smd(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &value);
|
||||
value &= ~APEX_CONFIG1_SMD_ENABLE_MASK;
|
||||
value |= (uint8_t)APEX_CONFIG1_SMD_ENABLE_DIS;
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG1, 1, &value);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_init_parameters_struct(struct inv_imu_device *s, inv_imu_apex_parameters_t *apex_inputs)
|
||||
{
|
||||
int status = 0;
|
||||
(void)s;
|
||||
|
||||
/* Default parameters at POR */
|
||||
apex_inputs->pedo_amp_th = APEX_CONFIG3_PEDO_AMP_TH_62_MG;
|
||||
apex_inputs->pedo_step_cnt_th = 0x5;
|
||||
apex_inputs->pedo_step_det_th = 0x2;
|
||||
apex_inputs->pedo_sb_timer_th = APEX_CONFIG4_PEDO_SB_TIMER_TH_150_SAMPLES;
|
||||
apex_inputs->pedo_hi_enrgy_th = APEX_CONFIG4_PEDO_HI_ENRGY_TH_104_MG;
|
||||
apex_inputs->tilt_wait_time = APEX_CONFIG5_TILT_WAIT_TIME_4_S;
|
||||
apex_inputs->power_save_time = APEX_CONFIG2_DMP_POWER_SAVE_TIME_SEL_8_S;
|
||||
apex_inputs->power_save = APEX_CONFIG0_DMP_POWER_SAVE_EN;
|
||||
apex_inputs->sensitivity_mode = APEX_CONFIG9_SENSITIVITY_MODE_NORMAL;
|
||||
apex_inputs->low_energy_amp_th = APEX_CONFIG2_LOW_ENERGY_AMP_TH_SEL_80_MG;
|
||||
apex_inputs->smd_sensitivity = APEX_CONFIG9_SMD_SENSITIVITY_0;
|
||||
apex_inputs->ff_debounce_duration = APEX_CONFIG9_FF_DEBOUNCE_DURATION_2000_MS;
|
||||
apex_inputs->ff_max_duration_cm = APEX_CONFIG12_FF_MAX_DURATION_204_CM;
|
||||
apex_inputs->ff_min_duration_cm = APEX_CONFIG12_FF_MIN_DURATION_10_CM;
|
||||
apex_inputs->lowg_peak_th = APEX_CONFIG10_LOWG_PEAK_TH_563_MG;
|
||||
apex_inputs->lowg_peak_hyst = APEX_CONFIG5_LOWG_PEAK_TH_HYST_156_MG;
|
||||
apex_inputs->lowg_samples_th = APEX_CONFIG10_LOWG_TIME_TH_1_SAMPLE;
|
||||
apex_inputs->highg_peak_th = APEX_CONFIG11_HIGHG_PEAK_TH_2500_MG;
|
||||
apex_inputs->highg_peak_hyst = APEX_CONFIG5_HIGHG_PEAK_TH_HYST_156_MG;
|
||||
apex_inputs->highg_samples_th = APEX_CONFIG11_HIGHG_TIME_TH_1_SAMPLE;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_configure_parameters(struct inv_imu_device *s, const inv_imu_apex_parameters_t *apex_inputs)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t data;
|
||||
uint8_t apexConfig[7];
|
||||
APEX_CONFIG1_PED_ENABLE_t pedo_state;
|
||||
APEX_CONFIG1_TILT_ENABLE_t tilt_state;
|
||||
APEX_CONFIG1_FF_ENABLE_t ff_state;
|
||||
APEX_CONFIG1_SMD_ENABLE_t smd_state;
|
||||
|
||||
/* DMP cannot be configured if it is running, hence make sure all APEX algorithms are off */
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &data);
|
||||
pedo_state = (APEX_CONFIG1_PED_ENABLE_t)(data & APEX_CONFIG1_PED_ENABLE_MASK);
|
||||
tilt_state = (APEX_CONFIG1_TILT_ENABLE_t)(data & APEX_CONFIG1_TILT_ENABLE_MASK);
|
||||
ff_state = (APEX_CONFIG1_FF_ENABLE_t)(data & APEX_CONFIG1_FF_ENABLE_MASK);
|
||||
smd_state = (APEX_CONFIG1_SMD_ENABLE_t)(data & APEX_CONFIG1_SMD_ENABLE_MASK);
|
||||
if (pedo_state == APEX_CONFIG1_PED_ENABLE_EN)
|
||||
return INV_ERROR;
|
||||
if (tilt_state == APEX_CONFIG1_TILT_ENABLE_EN)
|
||||
return INV_ERROR;
|
||||
if (ff_state == APEX_CONFIG1_FF_ENABLE_EN)
|
||||
return INV_ERROR;
|
||||
if (smd_state == APEX_CONFIG1_SMD_ENABLE_EN)
|
||||
return INV_ERROR;
|
||||
|
||||
|
||||
status |= inv_imu_switch_on_mclk(s);
|
||||
|
||||
/* Power Save mode and low energy amplitude threshold (for Pedometer in Slow Walk mode) */
|
||||
/* APEX_CONFIG2_MREG1 */
|
||||
apexConfig[0] = (uint8_t)apex_inputs->power_save_time
|
||||
| (uint8_t)apex_inputs->low_energy_amp_th;
|
||||
|
||||
/* Pedometer parameters */
|
||||
/* APEX_CONFIG3_MREG1 */
|
||||
apexConfig[1] = (uint8_t)apex_inputs->pedo_amp_th
|
||||
| (apex_inputs->pedo_step_cnt_th & APEX_CONFIG3_PED_STEP_CNT_TH_SEL_MASK);
|
||||
|
||||
/* APEX_CONFIG4_MREG1 */
|
||||
apexConfig[2] = ((apex_inputs->pedo_step_det_th << APEX_CONFIG4_PED_STEP_DET_TH_SEL_POS)
|
||||
& APEX_CONFIG4_PED_STEP_DET_TH_SEL_MASK)
|
||||
| (uint8_t)apex_inputs->pedo_sb_timer_th
|
||||
| (uint8_t)apex_inputs->pedo_hi_enrgy_th;
|
||||
|
||||
/* Tilt, Lowg and highg parameters */
|
||||
/* APEX_CONFIG5_MREG1 */
|
||||
apexConfig[3] = (uint8_t)apex_inputs->tilt_wait_time
|
||||
| (uint8_t)apex_inputs->lowg_peak_hyst
|
||||
| (uint8_t)apex_inputs->highg_peak_hyst;
|
||||
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG2_MREG1, 4, &apexConfig[0]);
|
||||
|
||||
|
||||
/* APEX_CONFIG0 */
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG0, 1, &apexConfig[0]);
|
||||
apexConfig[0] &= ~APEX_CONFIG0_DMP_POWER_SAVE_EN_MASK;
|
||||
apexConfig[0] |= apex_inputs->power_save;
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG0, 1, &apexConfig[0]);
|
||||
|
||||
/* free fall parameter, SMD parameter and parameters for Pedometer in Slow Walk mode */
|
||||
/* APEX_CONFIG9_MREG1 */
|
||||
apexConfig[0] = (uint8_t)apex_inputs->ff_debounce_duration
|
||||
| (uint8_t)apex_inputs->smd_sensitivity
|
||||
| (uint8_t)apex_inputs->sensitivity_mode;
|
||||
|
||||
/* Lowg and highg parameters and free fall parameters */
|
||||
/* APEX_CONFIG10_MREG1 */
|
||||
apexConfig[1] = (uint8_t)apex_inputs->lowg_peak_th
|
||||
| (uint8_t)apex_inputs->lowg_samples_th;
|
||||
|
||||
/* APEX_CONFIG11_MREG1 */
|
||||
apexConfig[2] = (uint8_t)apex_inputs->highg_peak_th
|
||||
| (uint8_t)apex_inputs->highg_samples_th;
|
||||
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG9_MREG1, 3, &apexConfig[0]);
|
||||
|
||||
|
||||
/* APEX_CONFIG12_MREG1 */
|
||||
apexConfig[0] = (uint8_t)apex_inputs->ff_max_duration_cm
|
||||
| (uint8_t)apex_inputs->ff_min_duration_cm;
|
||||
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG12_MREG1, 1, &apexConfig[0]);
|
||||
|
||||
status |= inv_imu_switch_off_mclk(s);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_get_parameters(struct inv_imu_device *s, inv_imu_apex_parameters_t *apex_params)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t data[7];
|
||||
uint8_t value;
|
||||
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG0, 1, &value);
|
||||
apex_params->power_save = (APEX_CONFIG0_DMP_POWER_SAVE_t)(value & APEX_CONFIG0_DMP_POWER_SAVE_EN_MASK);
|
||||
|
||||
/* Access continuous config registers (CONFIG2-CONFIG11) */
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG2_MREG1, sizeof(data), &data[0]);
|
||||
|
||||
/* Get params from apex_config2 : dmp_power_save_time and low_energy_amp_th */
|
||||
apex_params->power_save_time = (APEX_CONFIG2_DMP_POWER_SAVE_TIME_t)
|
||||
(data[0] & APEX_CONFIG2_DMP_POWER_SAVE_TIME_SEL_MASK);
|
||||
apex_params->low_energy_amp_th = (APEX_CONFIG2_LOW_ENERGY_AMP_TH_t)
|
||||
(data[0] & APEX_CONFIG2_LOW_ENERGY_AMP_TH_SEL_MASK);
|
||||
|
||||
/* Get params from apex_config3 : pedo_amp_th and pedo_step_cnt_th */
|
||||
apex_params->pedo_amp_th = (APEX_CONFIG3_PEDO_AMP_TH_t)
|
||||
(data[1] & APEX_CONFIG3_PED_AMP_TH_SEL_MASK);
|
||||
apex_params->pedo_step_cnt_th = (data[1] & APEX_CONFIG3_PED_STEP_CNT_TH_SEL_MASK)
|
||||
>> APEX_CONFIG3_PED_STEP_CNT_TH_SEL_POS;
|
||||
|
||||
/* Get params from apex_config4 : pedo_step_det_th, pedo_sb_timer_th and pedo_hi_enrgy_th */
|
||||
apex_params->pedo_step_det_th = (data[2] & APEX_CONFIG4_PED_STEP_DET_TH_SEL_MASK)
|
||||
>> APEX_CONFIG4_PED_STEP_DET_TH_SEL_POS;
|
||||
apex_params->pedo_sb_timer_th = (APEX_CONFIG4_PEDO_SB_TIMER_TH_t)
|
||||
(data[2] & APEX_CONFIG4_PED_SB_TIMER_TH_SEL_MASK);
|
||||
apex_params->pedo_hi_enrgy_th = (APEX_CONFIG4_PEDO_HI_ENRGY_TH_t)
|
||||
(data[2] & APEX_CONFIG4_PED_HI_EN_TH_SEL_MASK);
|
||||
|
||||
/* Get params from apex_config5 : tilt_wait_time, lowg_peak_hyst and highg_peak_hyst */
|
||||
apex_params->tilt_wait_time = (APEX_CONFIG5_TILT_WAIT_TIME_t)
|
||||
(data[3] & APEX_CONFIG5_TILT_WAIT_TIME_SEL_MASK);
|
||||
apex_params->lowg_peak_hyst = (APEX_CONFIG5_LOWG_PEAK_TH_HYST_t)
|
||||
(data[3] & APEX_CONFIG5_LOWG_PEAK_TH_HYST_SEL_MASK);
|
||||
apex_params->highg_peak_hyst = (APEX_CONFIG5_HIGHG_PEAK_TH_HYST_t)
|
||||
(data[3] & APEX_CONFIG5_HIGHG_PEAK_TH_HYST_SEL_MASK);
|
||||
|
||||
/* Get params from apex_config9 : ff_debounce_duration, smd_sensitivity and sensitivity_mode */
|
||||
apex_params->ff_debounce_duration = (APEX_CONFIG9_FF_DEBOUNCE_DURATION_t)
|
||||
(data[4] & APEX_CONFIG9_FF_DEBOUNCE_DURATION_SEL_MASK);
|
||||
apex_params->smd_sensitivity = (APEX_CONFIG9_SMD_SENSITIVITY_t)
|
||||
(data[4] & APEX_CONFIG9_SMD_SENSITIVITY_SEL_MASK);
|
||||
apex_params->sensitivity_mode = (APEX_CONFIG9_SENSITIVITY_MODE_t)
|
||||
(data[4] & APEX_CONFIG9_SENSITIVITY_MODE_MASK);
|
||||
|
||||
/* Get params from apex_config10 : lowg_peak_th and lowg_samples_th */
|
||||
apex_params->lowg_peak_th = (APEX_CONFIG10_LOWG_PEAK_TH_t)
|
||||
(data[5] & APEX_CONFIG10_LOWG_PEAK_TH_SEL_MASK);
|
||||
apex_params->lowg_samples_th = (APEX_CONFIG10_LOWG_TIME_TH_SAMPLES_t)
|
||||
(data[5] & APEX_CONFIG10_LOWG_TIME_TH_SEL_MASK);
|
||||
|
||||
/* Get params from apex_config11 : highg_peak_th and highg_samples_th */
|
||||
apex_params->highg_peak_th = (APEX_CONFIG11_HIGHG_PEAK_TH_t)
|
||||
(data[6] & APEX_CONFIG11_HIGHG_PEAK_TH_SEL_MASK);
|
||||
apex_params->highg_samples_th = (APEX_CONFIG11_HIGHG_TIME_TH_SAMPLES_t)
|
||||
(data[6] & APEX_CONFIG11_HIGHG_TIME_TH_SEL_MASK);
|
||||
|
||||
/* Access apex reg 12 */
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG12_MREG1, 1, &data[0]);
|
||||
|
||||
/* Get params from apex_config12 : ff_max_duration_cm and ff_min_duration_cm */
|
||||
apex_params->ff_max_duration_cm = (APEX_CONFIG12_FF_MAX_DURATION_t)
|
||||
(data[0] & APEX_CONFIG12_FF_MAX_DURATION_SEL_MASK);
|
||||
apex_params->ff_min_duration_cm = (APEX_CONFIG12_FF_MIN_DURATION_t)
|
||||
(data[0] & APEX_CONFIG12_FF_MIN_DURATION_SEL_MASK);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_set_frequency(struct inv_imu_device *s, const APEX_CONFIG1_DMP_ODR_t frequency)
|
||||
{
|
||||
uint8_t value;
|
||||
int status = 0;
|
||||
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &value);
|
||||
|
||||
value &= ~APEX_CONFIG1_DMP_ODR_MASK;
|
||||
value |= frequency;
|
||||
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG1, 1, &value);
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_enable_pedometer(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
status |= inv_imu_start_dmp(s);
|
||||
|
||||
/* Enable Pedometer */
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &value);
|
||||
value &= ~APEX_CONFIG1_PED_ENABLE_MASK;
|
||||
value |= (uint8_t)APEX_CONFIG1_PED_ENABLE_EN;
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG1, 1, &value);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_disable_pedometer(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
/* Disable Pedometer */
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &value);
|
||||
value &= ~APEX_CONFIG1_PED_ENABLE_MASK;
|
||||
value |= (uint8_t)APEX_CONFIG1_PED_ENABLE_DIS;
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG1, 1, &value);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_enable_tilt(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
status |= inv_imu_start_dmp(s);
|
||||
|
||||
/* Enable Tilt */
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &value);
|
||||
value &= ~APEX_CONFIG1_TILT_ENABLE_MASK;
|
||||
value |= (uint8_t)APEX_CONFIG1_TILT_ENABLE_EN;
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG1, 1, &value);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_disable_tilt(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
/* Disable Tilt */
|
||||
status |= inv_imu_read_reg(s, APEX_CONFIG1, 1, &value);
|
||||
value &= ~APEX_CONFIG1_TILT_ENABLE_MASK;
|
||||
value |= (uint8_t)APEX_CONFIG1_TILT_ENABLE_DIS;
|
||||
status |= inv_imu_write_reg(s, APEX_CONFIG1, 1, &value);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_get_data_activity(struct inv_imu_device *s, inv_imu_apex_step_activity_t *apex_activity)
|
||||
{
|
||||
uint8_t data[4];
|
||||
int status = inv_imu_read_reg(s, APEX_DATA0, 4, data);
|
||||
|
||||
apex_activity->step_cnt = data[1] << 8 | data[0];
|
||||
apex_activity->step_cadence = data[2];
|
||||
apex_activity->activity_class = data[3] & APEX_DATA3_ACTIVITY_CLASS_MASK;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_apex_get_data_free_fall(struct inv_imu_device *s, uint16_t *freefall_duration)
|
||||
{
|
||||
uint8_t data[2];
|
||||
int status = inv_imu_read_reg(s, APEX_DATA4, 2, &data[0]);
|
||||
|
||||
*freefall_duration = (data[1] << 8) | data[0];
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2017 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @defgroup DriverApex IMU driver high level functions related to APEX and the DMP
|
||||
* @brief High-level function to setup an IMU device
|
||||
* @ingroup Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @file inv_imu_apex.h
|
||||
* High-level function to setup an IMU device
|
||||
*/
|
||||
|
||||
#ifndef _INV_IMU_APEX_H_
|
||||
#define _INV_IMU_APEX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "inv_imu_defs.h"
|
||||
|
||||
#include "InvError.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Forward declarations */
|
||||
struct inv_imu_device;
|
||||
|
||||
/** @brief IMU APEX inputs parameters definition
|
||||
*/
|
||||
typedef struct {
|
||||
APEX_CONFIG3_PEDO_AMP_TH_t pedo_amp_th;
|
||||
uint8_t pedo_step_cnt_th;
|
||||
uint8_t pedo_step_det_th;
|
||||
APEX_CONFIG4_PEDO_SB_TIMER_TH_t pedo_sb_timer_th;
|
||||
APEX_CONFIG4_PEDO_HI_ENRGY_TH_t pedo_hi_enrgy_th;
|
||||
APEX_CONFIG5_TILT_WAIT_TIME_t tilt_wait_time;
|
||||
APEX_CONFIG2_DMP_POWER_SAVE_TIME_t power_save_time;
|
||||
APEX_CONFIG0_DMP_POWER_SAVE_t power_save;
|
||||
APEX_CONFIG9_SENSITIVITY_MODE_t sensitivity_mode;
|
||||
APEX_CONFIG2_LOW_ENERGY_AMP_TH_t low_energy_amp_th;
|
||||
APEX_CONFIG9_SMD_SENSITIVITY_t smd_sensitivity;
|
||||
APEX_CONFIG9_FF_DEBOUNCE_DURATION_t ff_debounce_duration;
|
||||
APEX_CONFIG12_FF_MAX_DURATION_t ff_max_duration_cm;
|
||||
APEX_CONFIG12_FF_MIN_DURATION_t ff_min_duration_cm;
|
||||
APEX_CONFIG10_LOWG_PEAK_TH_t lowg_peak_th;
|
||||
APEX_CONFIG5_LOWG_PEAK_TH_HYST_t lowg_peak_hyst;
|
||||
APEX_CONFIG10_LOWG_TIME_TH_SAMPLES_t lowg_samples_th;
|
||||
APEX_CONFIG11_HIGHG_PEAK_TH_t highg_peak_th;
|
||||
APEX_CONFIG5_HIGHG_PEAK_TH_HYST_t highg_peak_hyst;
|
||||
APEX_CONFIG11_HIGHG_TIME_TH_SAMPLES_t highg_samples_th;
|
||||
} inv_imu_apex_parameters_t;
|
||||
|
||||
/** @brief APEX pedometer outputs
|
||||
*/
|
||||
typedef struct inv_imu_apex_step_activity {
|
||||
uint16_t step_cnt; /**< Number of steps taken */
|
||||
uint8_t step_cadence; /**< Walk/run cadence in number of samples.
|
||||
Format is u6.2. E.g, At 50Hz and 2Hz walk frequency, if the cadency is 25 samples.
|
||||
The register will output 100. */
|
||||
uint8_t activity_class; /**< Detected activity unknown (0), walk (1) or run (2) */
|
||||
} inv_imu_apex_step_activity_t;
|
||||
|
||||
/** @brief Enable Free Fall.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_enable_ff(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable Free Fall.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_disable_ff(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Enable Significant Motion Detection.
|
||||
* note : SMD requests to have the accelerometer enabled to work.
|
||||
* To have good performance, it's recommended to set accelerometer ODR (Output Data Rate) to 20ms
|
||||
* and the accelerometer in Low Power Mode.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_enable_smd(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable Significant Motion Detection.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_disable_smd(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Fill the APEX parameters structure with all the default parameters for APEX algorithms (pedometer, tilt)
|
||||
* @param[out] apex_inputs Default input parameters. See @sa inv_imu_apex_parameters_t
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_init_parameters_struct(struct inv_imu_device *s, inv_imu_apex_parameters_t *apex_inputs);
|
||||
|
||||
/** @brief Configures DMP parameters for APEX algorithms (pedometer, tilt, lowg, highg).
|
||||
* This programmable parameters will be decoded and propagate to the SRAM to be executed at DMP start.
|
||||
* @param[in] apex_inputs The requested input parameters. See @sa inv_imu_apex_parameters_t
|
||||
* @warning APEX inputs can't change on the fly, this API should be called before enabling any APEX features.
|
||||
* @warning APEX configuration can't be done too frequently, but only once every 10ms.
|
||||
* Otherwise it can create unknown behavior.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_configure_parameters(struct inv_imu_device *s, const inv_imu_apex_parameters_t *apex_inputs);
|
||||
|
||||
/** @brief Returns current DMP parameters for APEX algorithms (pedometer, tilt).
|
||||
* @param[out] apex_params The current parameter, fetched from registers. See @sa inv_imu_apex_parameters_t
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_get_parameters(struct inv_imu_device *s, inv_imu_apex_parameters_t *apex_params);
|
||||
|
||||
/** @brief Configure DMP Output Data Rate for APEX algorithms (pedometer, tilt)
|
||||
* @param[in] frequency The requested frequency.
|
||||
* @sa APEX_CONFIG1_DMP_ODR_t
|
||||
* @warning DMP_ODR can change on the fly, and the DMP code will accommodate necessary modifications
|
||||
* @warning The user needs to take care to set Accel frequency >= DMP frequency. This is a hard constraint
|
||||
since HW will not handle incorrect setting.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_set_frequency(struct inv_imu_device *s, const APEX_CONFIG1_DMP_ODR_t frequency);
|
||||
|
||||
/** @brief Enable APEX algorithm Pedometer.
|
||||
* note : Pedometer request to have the accelerometer enabled to works
|
||||
* with accelerometer frequency less than dmp frequency.
|
||||
* @return 0 on success, negative value on error.
|
||||
* @warning Pedometer must be turned OFF to reconfigure it
|
||||
*/
|
||||
int inv_imu_apex_enable_pedometer(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable APEX algorithm Pedometer.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_disable_pedometer(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Enable APEX algorithm Tilt.
|
||||
* note : Tilt request to have the accelerometer enabled to works
|
||||
* with accelerometer frequency less than dmp frequency.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_enable_tilt(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable APEX algorithm Tilt.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_apex_disable_tilt(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Retrieve APEX pedometer outputs and format them
|
||||
* @param[out] apex_activity Apex step and activity data value.
|
||||
* @return 0 in case of success, negative value on error. See enum inv_error
|
||||
*/
|
||||
int inv_imu_apex_get_data_activity(struct inv_imu_device *s, inv_imu_apex_step_activity_t *apex_activity);
|
||||
|
||||
/** @brief Retrieve APEX free fall outputs and format them
|
||||
* @param[out] Free fall duration in number of sample.
|
||||
* @return 0 in case of success, negative value on error. See enum inv_error
|
||||
*/
|
||||
int inv_imu_apex_get_data_free_fall(struct inv_imu_device *s, uint16_t *freefall_duration);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INV_IMU_APEX_H_ */
|
||||
|
||||
/** @} */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,520 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2017 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @defgroup Driver IMU driver high level functions
|
||||
* @brief High-level function to setup an IMU device
|
||||
* @ingroup DriverIcm
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @file inv_imu_driver.h
|
||||
* High-level function to setup an IMU device
|
||||
*/
|
||||
|
||||
#ifndef _INV_IMU_DRIVER_H_
|
||||
#define _INV_IMU_DRIVER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "inv_imu_defs.h"
|
||||
#include "inv_imu_transport.h"
|
||||
|
||||
#include "InvError.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/** @brief IMU max FSR values for accel and gyro
|
||||
* Dependent on chip
|
||||
*/
|
||||
#define ACCEL_CONFIG0_FS_SEL_MAX ACCEL_CONFIG0_FS_SEL_16g
|
||||
#define GYRO_CONFIG0_FS_SEL_MAX GYRO_CONFIG0_FS_SEL_2000dps
|
||||
|
||||
#define ACCEL_OFFUSER_MAX_MG 1000
|
||||
#define GYRO_OFFUSER_MAX_DPS 64
|
||||
|
||||
/** @brief IMU maximum buffer size mirrored from FIFO at polling time
|
||||
* @warning fifo_idx type variable must be large enough to parse the FIFO_MIRRORING_SIZE
|
||||
*/
|
||||
#define FIFO_MIRRORING_SIZE 16 * 258 // packet size * max_count = 4kB
|
||||
|
||||
/** @brief IMU Accelerometer start-up time before having correct data
|
||||
*/
|
||||
#define ACC_STARTUP_TIME_US 10000
|
||||
|
||||
/** @brief IMU Gyroscope start-up time before having correct data
|
||||
*/
|
||||
#define GYR_STARTUP_TIME_US 70000
|
||||
|
||||
/** @brief IMU Gyroscope power off to power on duration
|
||||
*/
|
||||
#define GYR_POWER_OFF_DUR_US 20000
|
||||
|
||||
/** @brief Sensor identifier for UI control function
|
||||
*/
|
||||
enum inv_imu_sensor {
|
||||
INV_SENSOR_ACCEL, /**< Accelerometer */
|
||||
INV_SENSOR_GYRO, /**< Gyroscope */
|
||||
INV_SENSOR_FSYNC_EVENT, /**< FSYNC */
|
||||
INV_SENSOR_TEMPERATURE, /**< Chip temperature */
|
||||
INV_SENSOR_DMP_PEDOMETER_EVENT, /**< Pedometer: step detected */
|
||||
INV_SENSOR_DMP_PEDOMETER_COUNT, /**< Pedometer: step counter */
|
||||
INV_SENSOR_DMP_TILT, /**< Tilt */
|
||||
INV_SENSOR_DMP_FF, /**< FreeFall */
|
||||
INV_SENSOR_DMP_LOWG, /**< Low G */
|
||||
INV_SENSOR_DMP_SMD, /**< Significant Motion Detection */
|
||||
INV_SENSOR_MAX
|
||||
};
|
||||
|
||||
/** @brief Configure Fifo usage
|
||||
*/
|
||||
typedef enum {
|
||||
INV_IMU_FIFO_DISABLED = 0, /**< Fifo is disabled and data source is sensors registers */
|
||||
INV_IMU_FIFO_ENABLED = 1, /**< Fifo is used as data source */
|
||||
}INV_IMU_FIFO_CONFIG_t;
|
||||
|
||||
/** @brief Sensor event structure definition
|
||||
*/
|
||||
typedef struct {
|
||||
int sensor_mask;
|
||||
uint16_t timestamp_fsync;
|
||||
int16_t accel[3];
|
||||
int16_t gyro[3];
|
||||
int16_t temperature;
|
||||
int8_t accel_high_res[3];
|
||||
int8_t gyro_high_res[3];
|
||||
} inv_imu_sensor_event_t;
|
||||
|
||||
/** @brief IMU driver states definition
|
||||
*/
|
||||
struct inv_imu_device {
|
||||
struct inv_imu_transport transport; /**< Transport layer
|
||||
Must be the first one of struct inv_imu_device */
|
||||
void (*sensor_event_cb)(inv_imu_sensor_event_t *event); /**< callback executed by:
|
||||
inv_imu_get_data_from_fifo (if FIFO is used)
|
||||
inv_imu_get_data_from_registers (if FIFO isn't used)
|
||||
May be NULL if above API are not used by application */
|
||||
uint8_t fifo_data[FIFO_MIRRORING_SIZE]; /**< FIFO mirroring memory area */
|
||||
uint8_t dmp_is_on; /**< DMP started status */
|
||||
uint8_t endianness_data; /**< Data endianness configuration */
|
||||
uint8_t fifo_highres_enabled; /**< Highres mode configuration */
|
||||
INV_IMU_FIFO_CONFIG_t fifo_is_used; /**< FIFO configuration */
|
||||
uint64_t gyro_start_time_us; /**< Gyro start time used to discard first samples */
|
||||
uint64_t accel_start_time_us; /**< Accel start time used to discard first samples */
|
||||
uint64_t gyro_power_off_tmst; /**< Gyro power off time */
|
||||
};
|
||||
|
||||
|
||||
/* Interrupt enum state for INT1, INT2, and IBI */
|
||||
typedef enum {
|
||||
INV_IMU_DISABLE = 0,
|
||||
INV_IMU_ENABLE
|
||||
} inv_imu_interrupt_value;
|
||||
|
||||
/** @brief Interrupt definition
|
||||
*/
|
||||
typedef struct {
|
||||
inv_imu_interrupt_value INV_UI_FSYNC;
|
||||
inv_imu_interrupt_value INV_UI_DRDY;
|
||||
inv_imu_interrupt_value INV_FIFO_THS;
|
||||
inv_imu_interrupt_value INV_FIFO_FULL;
|
||||
inv_imu_interrupt_value INV_SMD;
|
||||
inv_imu_interrupt_value INV_WOM_X;
|
||||
inv_imu_interrupt_value INV_WOM_Y;
|
||||
inv_imu_interrupt_value INV_WOM_Z;
|
||||
inv_imu_interrupt_value INV_FF;
|
||||
inv_imu_interrupt_value INV_LOWG;
|
||||
inv_imu_interrupt_value INV_STEP_DET;
|
||||
inv_imu_interrupt_value INV_STEP_CNT_OVFL;
|
||||
inv_imu_interrupt_value INV_TILT_DET;
|
||||
} inv_imu_interrupt_parameter_t;
|
||||
|
||||
|
||||
/** @brief Configure the serial interface used to access the device and execute hardware initialization.
|
||||
*
|
||||
* This functions first configures serial interface passed in parameter to make sure device
|
||||
* is accessible both in read and write. Thus no serial access should be done before
|
||||
* successfully executing the present function.
|
||||
*
|
||||
* Then if requested serial interface is a primary interface (aka UI interface or AP
|
||||
* interface), this function initializes the device using the following hardware settings:
|
||||
* - set timestamp resolution to 16us
|
||||
* - enable FIFO mechanism with the following configuration:
|
||||
* - FIFO record mode i.e FIFO count unit is packet
|
||||
* - FIFO snapshot mode i.e drop the data when the FIFO overflows
|
||||
* - Timestamp is logged in FIFO
|
||||
* - Little Endian fifo_count and fifo_data
|
||||
* - generate FIFO threshold interrupt when packet count reaches FIFO watermark
|
||||
* - set FIFO watermark to 1 packet
|
||||
* - enable temperature and timestamp data to go to FIFO
|
||||
*
|
||||
*
|
||||
* @param[in] s driver structure. Note that first field of this structure MUST be a struct
|
||||
* inv_imu_serif.
|
||||
*
|
||||
* @param[in] serif pointer on serial interface structure to be used to access inv_device.
|
||||
*
|
||||
* @param[in] sensor_event_cb callback executed by inv_imu_get_data_from_fifo function
|
||||
* each time it extracts some valid data from fifo. Or inv_imu_get_data_from_registers read data
|
||||
* from register. Thus this parameter is optional as long
|
||||
* as inv_imu_get_data_from_fifo/inv_imu_get_data_from_registers function is not used.
|
||||
*
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_init(struct inv_imu_device *s,
|
||||
struct inv_imu_serif *serif,
|
||||
void (*sensor_event_cb)(inv_imu_sensor_event_t *event));
|
||||
|
||||
/** @brief Perform a soft reset of the device
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_device_reset(struct inv_imu_device *s);
|
||||
|
||||
/** @brief return WHOAMI value
|
||||
* @param[out] who_am_i WHOAMI for device
|
||||
* @return 0 on success, negative value on error
|
||||
*/
|
||||
int inv_imu_get_who_am_i(struct inv_imu_device *s, uint8_t *who_am_i);
|
||||
|
||||
/** @brief Enable/put accel in low power mode
|
||||
* @return 0 on success, negative value on error.
|
||||
* @details
|
||||
* It enables accel and gyro data in the FIFO (so
|
||||
* the packet format is 16 bytes). If called first,
|
||||
* the configuration will be applied, otherwise it
|
||||
* will be ignored if the FIFO is not empty (but since
|
||||
* the new configuration is identical it is not a issue).
|
||||
* @warning inv_device::register_cache::pwr_mgmt0_reg is modified by this function
|
||||
*/
|
||||
int inv_imu_enable_accel_low_power_mode(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Enable/put accel in low noise mode
|
||||
* @return 0 on success, negative value on error.
|
||||
* @details
|
||||
* It enables accel and gyro data in the FIFO (so
|
||||
* the packet format is 16 bytes). If called first,
|
||||
* the configuration will be applied, otherwise it
|
||||
* will be ignored if the FIFO is not empty (but since
|
||||
* the new configuration is identical it is not a issue).
|
||||
* @warning inv_device::register_cache::pwr_mgmt0_reg is modified by this function
|
||||
*/
|
||||
int inv_imu_enable_accel_low_noise_mode(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable all 3 axes of accel
|
||||
* @return 0 on success, negative value on error.
|
||||
* @details
|
||||
* If both accel and gyro are turned off as a result of this
|
||||
* function, they will also be removed from the FIFO and a
|
||||
* FIFO reset will be performed (to guarantee no side effects
|
||||
* until the next enable sensor call)
|
||||
* @warning inv_device::register_cache::pwr_mgmt0_reg is modified by this function
|
||||
*/
|
||||
int inv_imu_disable_accel(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Enable/put gyro in low noise mode
|
||||
* @return 0 on success, negative value on error.
|
||||
* @details
|
||||
* It enables gyro and accel data in the FIFO (so
|
||||
* the packet format is 16 bytes). If called first,
|
||||
* the configuration will be applied, otherwise it
|
||||
* will be ignored if the FIFO is not empty (but since
|
||||
* the new configuration is identical it is not a issue).
|
||||
* @warning inv_device::register_cache::pwr_mgmt0_reg is modified by this function
|
||||
*/
|
||||
int inv_imu_enable_gyro_low_noise_mode(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable all 3 axes of gyro
|
||||
* @return 0 on success, negative value on error.
|
||||
* @details
|
||||
* If both accel and gyro are turned off as a result of this
|
||||
* function, they will also be removed from the FIFO and a
|
||||
* FIFO reset will be performed (to guarantee no side effects
|
||||
* until the next enable sensor call)
|
||||
* @warning inv_device::register_cache::pwr_mgmt0_reg is modified by this function
|
||||
*/
|
||||
int inv_imu_disable_gyro(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Enable fsync tagging functionality.
|
||||
* In details it:
|
||||
* - enables fsync
|
||||
* - enables timestamp to registers. Once fsync is enabled fsync counter is pushed to
|
||||
* fifo instead of timestamp. So timestamp is made available in registers. Note that
|
||||
* this increase power consumption.
|
||||
* - enables fsync related interrupt
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_enable_fsync(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable fsync tagging functionality.
|
||||
* In details it:
|
||||
* - disables fsync
|
||||
* - disables timestamp to registers. Once fsync is disabled timestamp is pushed to fifo
|
||||
* instead of fsync counter. So in order to decrease power consumption, timestamp is no
|
||||
* more available in registers.
|
||||
* - disables fsync related interrupt
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_disable_fsync(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Configure which interrupt source can trigger INT1.
|
||||
* @param[in] interrupt_to_configure structure with the corresponding state to manage INT1.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_set_config_int1(struct inv_imu_device *s,
|
||||
inv_imu_interrupt_parameter_t *interrupt_to_configure);
|
||||
|
||||
/** @brief Retrieve interrupts configuration.
|
||||
* @param[in] interrupt_to_configure structure with the corresponding state to manage INT1.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_get_config_int1(struct inv_imu_device *s,
|
||||
inv_imu_interrupt_parameter_t *interrupt_to_configure);
|
||||
|
||||
/** @brief Configure which interrupt source can trigger INT2.
|
||||
* @param[in] interrupt_to_configure structure with the corresponding state to INT2.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_set_config_int2(struct inv_imu_device *s,
|
||||
inv_imu_interrupt_parameter_t *interrupt_to_configure);
|
||||
|
||||
/** @brief Retrieve interrupts configuration.
|
||||
* @param[in] interrupt_to_configure structure with the corresponding state to manage INT2.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_get_config_int2(struct inv_imu_device *s,
|
||||
inv_imu_interrupt_parameter_t *interrupt_to_configure);
|
||||
|
||||
/** @brief Read all registers containing data (temperature, accelerometer and gyroscope). Then it calls
|
||||
* sensor_event_cb function passed in parameter of inv_imu_init function for each packet
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_get_data_from_registers(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Read all available packets from the FIFO. For each packet function builds a
|
||||
* sensor event containing packet data and validity information. Then it calls
|
||||
* sensor_event_cb funtion passed in parameter of inv_imu_init function for each
|
||||
* packet.
|
||||
* @return number of valid packets read on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_get_data_from_fifo(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Converts ACCEL_CONFIG0_ODR_t or GYRO_CONFIG0_ODR_t enums to period expressed in us
|
||||
* @param[in] odr_bitfield An ACCEL_CONFIG0_ODR_t or GYRO_CONFIG0_ODR_t enum
|
||||
* @return The corresponding period expressed in us
|
||||
*/
|
||||
uint32_t inv_imu_convert_odr_bitfield_to_us(uint32_t odr_bitfield);
|
||||
|
||||
/** @brief Configure accel Output Data Rate
|
||||
* @param[in] frequency The requested frequency.
|
||||
* @sa ACCEL_CONFIG0_ODR_t
|
||||
* @return 0 on success, negative value on error.
|
||||
* @warning inv_device::register_cache::accel_config0_reg is modified by this function
|
||||
*/
|
||||
int inv_imu_set_accel_frequency(struct inv_imu_device *s,
|
||||
const ACCEL_CONFIG0_ODR_t frequency);
|
||||
|
||||
/** @brief Configure gyro Output Data Rate
|
||||
* @param[in] frequency The requested frequency.
|
||||
* @sa GYRO_CONFIG0_ODR_t
|
||||
* @return 0 on success, negative value on error.
|
||||
* @warning inv_device::register_cache::gyro_config0_reg is modified by this function
|
||||
*/
|
||||
int inv_imu_set_gyro_frequency(struct inv_imu_device *s,
|
||||
const GYRO_CONFIG0_ODR_t frequency);
|
||||
|
||||
/** @brief Set accel full scale range
|
||||
* @param[in] accel_fsr_g requested full scale range.
|
||||
* @sa ACCEL_CONFIG0_FS_SEL_t.
|
||||
* @return 0 on success, negative value on error.
|
||||
* @warning inv_device::register_cache::accel_config0_reg is modified by this function
|
||||
*/
|
||||
int inv_imu_set_accel_fsr(struct inv_imu_device *s,
|
||||
ACCEL_CONFIG0_FS_SEL_t accel_fsr_g);
|
||||
|
||||
/** @brief Access accel full scale range
|
||||
* @param[out] accel_fsr_g current full scale range.
|
||||
* @sa ACCEL_CONFIG0_FS_SEL_t.
|
||||
* @return 0 on success, negative value on error.
|
||||
* @warning inv_device::register_cache::accel_config0_reg is relied upon by this function
|
||||
*/
|
||||
int inv_imu_get_accel_fsr(struct inv_imu_device *s,
|
||||
ACCEL_CONFIG0_FS_SEL_t *accel_fsr_g);
|
||||
|
||||
/** @brief Set gyro full scale range
|
||||
* @param[in] gyro_fsr_dps requested full scale range.
|
||||
* @sa GYRO_CONFIG0_FS_SEL_t.
|
||||
* @return 0 on success, negative value on error.
|
||||
* @warning inv_device::register_cache::gyro_config0_reg is modified by this function
|
||||
*/
|
||||
int inv_imu_set_gyro_fsr(struct inv_imu_device *s,
|
||||
GYRO_CONFIG0_FS_SEL_t gyro_fsr_dps);
|
||||
|
||||
/** @brief Access gyro full scale range
|
||||
* @param[out] gyro_fsr_dps current full scale range.
|
||||
* @sa GYRO_CONFIG0_FS_SEL_t.
|
||||
* @return 0 on success, negative value on error.
|
||||
* @warning inv_device::register_cache::gyro_config0_reg is relied upon by this function
|
||||
*/
|
||||
int inv_imu_get_gyro_fsr(struct inv_imu_device *s,
|
||||
GYRO_CONFIG0_FS_SEL_t *gyro_fsr_dps);
|
||||
|
||||
/** @brief Set accel Low-Power averaging value
|
||||
* @param[in] acc_avg requested averaging value
|
||||
* @sa ACCEL_CONFIG1_ACCEL_FILT_AVG_t
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_set_accel_lp_avg(struct inv_imu_device *s,
|
||||
ACCEL_CONFIG1_ACCEL_FILT_AVG_t acc_avg);
|
||||
|
||||
/** @brief Set accel Low-Noise bandwidth value
|
||||
* @param[in] acc_bw requested averaging value
|
||||
* @sa ACCEL_CONFIG1_ACCEL_FILT_BW_t
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_set_accel_ln_bw(struct inv_imu_device *s,
|
||||
ACCEL_CONFIG1_ACCEL_FILT_BW_t acc_bw);
|
||||
|
||||
/** @brief Set gyro Low-Noise bandwidth value
|
||||
* @param[in] gyr_bw requested averaging value
|
||||
* @sa GYRO_CONFIG1_GYRO_FILT_BW_t
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_set_gyro_ln_bw(struct inv_imu_device *s,
|
||||
GYRO_CONFIG1_GYRO_FILT_BW_t gyr_bw);
|
||||
|
||||
/** @brief Set timestamp resolution
|
||||
* @param[in] timestamp_resol requested timestamp resolution
|
||||
* @sa TMST_CONFIG1_RESOL_t
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_set_timestamp_resolution(struct inv_imu_device *s,
|
||||
const TMST_CONFIG1_RESOL_t timestamp_resol);
|
||||
|
||||
/** @brief reset IMU fifo
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_reset_fifo(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Enable 20 bits raw acc and raw gyr data in fifo.
|
||||
* @return 0 on success, negative return code otherwise
|
||||
*/
|
||||
int inv_imu_enable_high_resolution_fifo(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable 20 bits raw acc and raw gyr data in fifo.
|
||||
* @return 0 on success, negative return code otherwise
|
||||
*/
|
||||
int inv_imu_disable_high_resolution_fifo(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Configure Fifo
|
||||
* @param[in] fifo_config Fifo configuration method :
|
||||
* if FIFO is enabled, data are pushed to FIFO and FIFO THS interrupt is set
|
||||
* if FIFO is disabled, data are not pused to FIFO and DRDY interrupt is set
|
||||
* @sa INV_IMU_FIFO_CONFIG_t
|
||||
*/
|
||||
int inv_imu_configure_fifo(struct inv_imu_device *s,
|
||||
INV_IMU_FIFO_CONFIG_t fifo_config);
|
||||
|
||||
/** @brief Get FIFO timestamp resolution
|
||||
* @return the timestamp resolution in us as a q24 or 0 in case of error
|
||||
*/
|
||||
int32_t inv_imu_get_fifo_timestamp_resolution_us_q24(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Get register timestamp resolution
|
||||
* @return the timestamp resolution in us as a q24 or 0 in case of error
|
||||
*/
|
||||
uint32_t inv_imu_get_reg_timestamp_resolution_us_q24(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Enable Wake On Motion.
|
||||
* @param[in] wom_x_th threshold value for the Wake on Motion Interrupt for X-axis accelerometer.
|
||||
* @param[in] wom_y_th threshold value for the Wake on Motion Interrupt for Y-axis accelerometer.
|
||||
* @param[in] wom_z_th threshold value for the Wake on Motion Interrupt for Z-axis accelerometer.
|
||||
* @param[in] wom_int select which mode between AND/OR is used to generate interrupt.
|
||||
* @param[in] wom_dur select the number of overthreshold event to wait before generating interrupt.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_configure_wom(struct inv_imu_device *s,
|
||||
const uint8_t wom_x_th,
|
||||
const uint8_t wom_y_th,
|
||||
const uint8_t wom_z_th,
|
||||
WOM_CONFIG_WOM_INT_MODE_t wom_int,
|
||||
WOM_CONFIG_WOM_INT_DUR_t wom_dur);
|
||||
|
||||
/** @brief Enable Wake On Motion.
|
||||
* note : WoM requests to have the accelerometer enabled to work.
|
||||
* As a consequence Fifo water-mark interrupt is disabled to only trigger WoM interrupts.
|
||||
* To have good performance, it's recommended to set accelerometer ODR (Output Data Rate) to 20ms
|
||||
* and the accelerometer in Low Power Mode.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_enable_wom(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable Wake On Motion.
|
||||
* note : Fifo water-mark interrupt is re-enabled when WoM is disabled.
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_disable_wom(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Start DMP for APEX algorithms and selftest
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_start_dmp(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Reset DMP for APEX algorithms and selftest
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_reset_dmp(struct inv_imu_device *s,
|
||||
const APEX_CONFIG0_DMP_MEM_RESET_t sram_reset);
|
||||
|
||||
/** @breif Set the UI endianness and set the inv_device endianness field
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_set_endianness(struct inv_imu_device *s,
|
||||
INTF_CONFIG0_DATA_ENDIAN_t endianness);
|
||||
|
||||
/** @breif Read the UI endianness and set the inv_device endianness field
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_get_endianness(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Configure Fifo decimation
|
||||
* @param[in] requested decimation factor value from 2 to 256
|
||||
* @return 0 on success, negative value on error.
|
||||
*/
|
||||
int inv_imu_configure_fifo_data_rate(struct inv_imu_device *s,
|
||||
FDR_CONFIG_FDR_SEL_t dec_factor);
|
||||
|
||||
/** @brief Return driver version x.y.z-suffix as a char array
|
||||
* @retval driver version a char array "x.y.z-suffix"
|
||||
*/
|
||||
const char * inv_imu_get_version(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INV_IMU_DRIVER_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2017 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @defgroup DriverExt IMU driver extern functions
|
||||
* @brief Extern functions for IMU devices
|
||||
* @ingroup Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @file inv_imu_extfunc.h
|
||||
* Extern functions for IMU devices
|
||||
*/
|
||||
|
||||
#ifndef _INV_IMU_EXTFUNC_H_
|
||||
#define _INV_IMU_EXTFUNC_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/** @brief Hook for low-level high res system sleep() function to be implemented by upper layer
|
||||
* ~100us resolution is sufficient
|
||||
* @param[in] us number of us the calling thread should sleep
|
||||
*/
|
||||
extern void inv_imu_sleep_us(uint32_t us);
|
||||
|
||||
/** @brief Hook for low-level high res system get_time() function to be implemented by upper layer
|
||||
* Value shall be on 64bit with a 1 us resolution
|
||||
* @return The current time in us
|
||||
*/
|
||||
extern uint64_t inv_imu_get_time_us(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INV_IMU_EXTFUNC_H_ */
|
||||
|
||||
/** @} */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#include "inv_imu_selftest.h"
|
||||
#include "inv_imu_extfunc.h"
|
||||
#include "inv_imu_transport.h"
|
||||
|
||||
static int configure_selftest_parameters(struct inv_imu_device *s,
|
||||
const inv_imu_selftest_parameters_t st_params);
|
||||
|
||||
int inv_imu_run_selftest(struct inv_imu_device *s,
|
||||
const inv_imu_selftest_parameters_t st_params,
|
||||
inv_imu_selftest_output_t *st_output)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
uint8_t data[2] = {0};
|
||||
uint8_t st_done = 0;
|
||||
int polling_timeout_ms = 1000;
|
||||
|
||||
/* Disables Gyro/Accel sensors */
|
||||
status |= inv_imu_read_reg(s, PWR_MGMT0, 1, &value);
|
||||
value &= ~(PWR_MGMT0_ACCEL_MODE_MASK | PWR_MGMT0_GYRO_MODE_MASK);
|
||||
status |= inv_imu_write_reg(s, PWR_MGMT0, 1, &value);
|
||||
|
||||
/* Enable RC oscillator */
|
||||
status |= inv_imu_switch_on_mclk(s);
|
||||
|
||||
/* Clear DMP SRAM (1 ms wait included in `inv_imu_reset_dmp()`) */
|
||||
status |= inv_imu_reset_dmp(s, APEX_CONFIG0_DMP_MEM_RESET_APEX_ST_EN);
|
||||
/* Update `dmp_is_on` since APEX features will have to restart from scratch */
|
||||
s->dmp_is_on = 0;
|
||||
|
||||
/* Load self-test data */
|
||||
status |= inv_imu_load_selftest_data(s);
|
||||
|
||||
/* Set self-test parameters */
|
||||
status |= configure_selftest_parameters(s, st_params);
|
||||
|
||||
/*
|
||||
* Enable accel and/or gyro self-test.
|
||||
* If both accel and gyro self-test are enabled,
|
||||
* they should be set simultaneously in the same write access
|
||||
*/
|
||||
status |= inv_imu_read_reg(s, SELFTEST_MREG1, 1, &value);
|
||||
value &= ~SELFTEST_EN;
|
||||
value |= (uint8_t)st_params.st_control;
|
||||
status |= inv_imu_write_reg(s, SELFTEST_MREG1, 1, &value);
|
||||
|
||||
/* Poll int_status_st_done bit */
|
||||
do {
|
||||
inv_imu_sleep_us(1000);
|
||||
status |= inv_imu_read_reg(s, INT_STATUS, 1, &st_done);
|
||||
st_done &= INT_STATUS_ST_INT_MASK;
|
||||
|
||||
if (0 == --polling_timeout_ms)
|
||||
return (status | -1); /* Return error if timeout is reached */
|
||||
|
||||
} while ( !st_done /* Exit if ST_DONE */
|
||||
&& !status /* Or if error is detected */);
|
||||
|
||||
/* Read self-test results */
|
||||
status |= inv_imu_read_reg(s, ST_STATUS1_MREG1, 2, &data[0]);
|
||||
st_output->accel_status = (data[0] & ST_STATUS1_ACCEL_ST_PASS_MASK) >> ST_STATUS1_ACCEL_ST_PASS_POS;
|
||||
st_output->ax_status = (data[0] & ST_STATUS1_AX_ST_PASS_MASK) >> ST_STATUS1_AX_ST_PASS_POS;
|
||||
st_output->ay_status = (data[0] & ST_STATUS1_AY_ST_PASS_MASK) >> ST_STATUS1_AY_ST_PASS_POS;
|
||||
st_output->az_status = (data[0] & ST_STATUS1_AZ_ST_PASS_MASK) >> ST_STATUS1_AZ_ST_PASS_POS;
|
||||
st_output->gyro_status = (data[1] & ST_STATUS2_GYRO_ST_PASS_MASK) >> ST_STATUS2_GYRO_ST_PASS_POS;
|
||||
st_output->gyro_status |= ((data[1] & ST_STATUS2_ST_INCOMPLETE_MASK) >> ST_STATUS2_ST_INCOMPLETE_POS) << 1;
|
||||
st_output->gx_status = (data[1] & ST_STATUS2_GX_ST_PASS_MASK) >> ST_STATUS2_GX_ST_PASS_POS;
|
||||
st_output->gy_status = (data[1] & ST_STATUS2_GY_ST_PASS_MASK) >> ST_STATUS2_GY_ST_PASS_POS;
|
||||
st_output->gz_status = (data[1] & ST_STATUS2_GZ_ST_PASS_MASK) >> ST_STATUS2_GZ_ST_PASS_POS;
|
||||
|
||||
/* Disable self-test */
|
||||
status |= inv_imu_read_reg(s, SELFTEST_MREG1, 1, &value);
|
||||
value &= ~SELFTEST_EN;
|
||||
value |= (uint8_t)SELFTEST_DIS;
|
||||
status |= inv_imu_write_reg(s, SELFTEST_MREG1, 1, &value);
|
||||
|
||||
/* Reset FIFO because ST data may have been pushed to it */
|
||||
status |= inv_imu_reset_fifo(s);
|
||||
|
||||
/* Restore idle bit */
|
||||
status |= inv_imu_switch_off_mclk(s);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_init_selftest_parameters_struct(struct inv_imu_device *s,
|
||||
inv_imu_selftest_parameters_t *st_params)
|
||||
{
|
||||
(void)s;
|
||||
st_params->st_num_samples = ST_CONFIG_16_SAMPLES;
|
||||
st_params->st_control = (SELFTEST_ACCEL_GYRO_ST_EN_t)SELFTEST_EN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int inv_imu_load_selftest_data(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
/* Enable RC oscillator */
|
||||
status |= inv_imu_switch_on_mclk(s);
|
||||
|
||||
/* Set up OTP controller to reload factory-trimmed self-test response into SRAM */
|
||||
status |= inv_imu_read_reg(s, OTP_CONFIG_MREG1, 1, &value);
|
||||
value &= ~OTP_CONFIG_OTP_COPY_MODE_MASK;
|
||||
value |= (uint8_t)OTP_CONFIG_OTP_COPY_ST_DATA;
|
||||
status |= inv_imu_write_reg(s, OTP_CONFIG_MREG1, 1, &value);
|
||||
|
||||
/* Take the OTP macro out of power-down mode */
|
||||
status |= inv_imu_read_reg(s, OTP_CTRL7_MREG2, 1, &value);
|
||||
value &= ~OTP_CTRL7_OTP_PWR_DOWN_MASK;
|
||||
value |= (uint8_t)OTP_CTRL7_PWR_DOWN_DIS;
|
||||
status |= inv_imu_write_reg(s, OTP_CTRL7_MREG2, 1, &value);
|
||||
|
||||
/* Wait for voltage generator to power on */
|
||||
inv_imu_sleep_us(100);
|
||||
|
||||
/* Host should disable INT function first before kicking off OTP copy operation */
|
||||
|
||||
/* Trigger OTP to reload data (this time in self-test mode) */
|
||||
status |= inv_imu_read_reg(s, OTP_CTRL7_MREG2, 1, &value);
|
||||
value &= ~OTP_CTRL7_OTP_RELOAD_MASK;
|
||||
value |= (uint8_t)OTP_CTRL7_OTP_RELOAD_EN;
|
||||
status |= inv_imu_write_reg(s, OTP_CTRL7_MREG2, 1, &value);
|
||||
|
||||
/* Wait for OTP reload */
|
||||
inv_imu_sleep_us(20);
|
||||
|
||||
/* Disable RC oscillator */
|
||||
status |= inv_imu_switch_off_mclk(s);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int configure_selftest_parameters(struct inv_imu_device *s,
|
||||
const inv_imu_selftest_parameters_t st_params)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t value;
|
||||
|
||||
/* Self-test configuration cannot be updated if it already running */
|
||||
status |= inv_imu_read_reg(s, SELFTEST_MREG1, 1, &value);
|
||||
if ((value & SELFTEST_EN) != SELFTEST_DIS)
|
||||
return INV_ERROR_UNEXPECTED;
|
||||
|
||||
status |= inv_imu_read_reg(s, ST_CONFIG_MREG1, 1, &value);
|
||||
value &= ~((uint8_t)ST_CONFIG_ST_NUMBER_SAMPLE_MASK
|
||||
| (uint8_t)ST_CONFIG_ACCEL_ST_LIM_MASK
|
||||
| (uint8_t)ST_CONFIG_GYRO_ST_LIM_MASK);
|
||||
value |= (uint8_t)st_params.st_num_samples
|
||||
| (uint8_t)ST_CONFIG_ACCEL_ST_LIM_50
|
||||
| (uint8_t)ST_CONFIG_GYRO_ST_LIM_50;
|
||||
status |= inv_imu_write_reg(s, ST_CONFIG_MREG1, 1, &value);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @defgroup DriverST SelfTest IMU selftest
|
||||
* @brief Low-level function to run selftest on a IMU device
|
||||
* @ingroup Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @file inv_imu_selftest.h
|
||||
* Low-level function to run selftest on a IMU device
|
||||
*/
|
||||
|
||||
#ifndef _INV_IMU_SELFTEST_H_
|
||||
#define _INV_IMU_SELFTEST_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "InvExport.h"
|
||||
#include "inv_imu_defs.h"
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* forward declaration */
|
||||
struct inv_imu_device;
|
||||
|
||||
|
||||
/** @brief Self-test input parameters
|
||||
*/
|
||||
typedef struct {
|
||||
ST_CONFIG_NUM_SAMPLES_t st_num_samples; /**< Number of samples used to perform self-test */
|
||||
SELFTEST_ACCEL_GYRO_ST_EN_t st_control; /**< Define which sensor is under self-test */
|
||||
} inv_imu_selftest_parameters_t;
|
||||
|
||||
/** @brief Self-test routine outputs
|
||||
*/
|
||||
typedef struct {
|
||||
int8_t accel_status; /**< global accelerometer self-test passed */
|
||||
int8_t gyro_status; /**< global gyroscope self-test status: st_pass (bit0), st_incomplete (bit1) */
|
||||
int8_t ax_status; /**< AX self-test status */
|
||||
int8_t ay_status; /**< AY self-test status */
|
||||
int8_t az_status; /**< AZ self-test status */
|
||||
int8_t gx_status; /**< GX self-test status */
|
||||
int8_t gy_status; /**< GY self-test status */
|
||||
int8_t gz_status; /**< GZ self-test status */
|
||||
} inv_imu_selftest_output_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Perform hardware self-test for Accel and Gyro
|
||||
* @param[in] Self-test parameters (see inv_imu_selftest_parameters_t)
|
||||
* @param[out] Self-test results (see inv_imu_selftest_output_t)
|
||||
* @return 0 on completion, negative number if intermediate errors occurred
|
||||
*/
|
||||
int inv_imu_run_selftest(struct inv_imu_device *s,
|
||||
const inv_imu_selftest_parameters_t st_params,
|
||||
inv_imu_selftest_output_t *st_output);
|
||||
|
||||
/** @brief Fill the self-test configuration structure with default configuration
|
||||
* @param[in] selftest_params self-test parameters to be initialized
|
||||
* @return 0 on success, negative return code otherwise
|
||||
*/
|
||||
int inv_imu_init_selftest_parameters_struct(struct inv_imu_device *s,
|
||||
inv_imu_selftest_parameters_t *selftest_params);
|
||||
|
||||
/** @brief Load self-test data
|
||||
* @return 0 on success, negative return code otherwise
|
||||
*/
|
||||
int inv_imu_load_selftest_data(struct inv_imu_device *s);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INV_IMU_SELFTEST_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#include "inv_imu_extfunc.h"
|
||||
#include "inv_imu_transport.h"
|
||||
#include "inv_imu_regmap.h"
|
||||
|
||||
#include "InvError.h"
|
||||
|
||||
|
||||
/* Function definition */
|
||||
static uint8_t *get_register_cache_addr(struct inv_imu_device *s, uint32_t reg);
|
||||
static int write_sreg(struct inv_imu_device *s, uint8_t reg, uint32_t len, const uint8_t *buf);
|
||||
static int read_sreg(struct inv_imu_device *s, uint8_t reg, uint32_t len, uint8_t *buf);
|
||||
static int write_mclk_reg(struct inv_imu_device *s, uint16_t regaddr, uint8_t wr_cnt, const uint8_t *buf);
|
||||
static int read_mclk_reg(struct inv_imu_device *s, uint16_t regaddr, uint8_t rd_cnt, uint8_t *buf);
|
||||
|
||||
|
||||
int inv_imu_init_transport(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
struct inv_imu_transport *t = (struct inv_imu_transport *)s;
|
||||
|
||||
status |= read_sreg(s, (uint8_t)PWR_MGMT0, 1, &(t->register_cache.pwr_mgmt0_reg));
|
||||
status |= read_sreg(s, (uint8_t)GYRO_CONFIG0, 1, &(t->register_cache.gyro_config0_reg));
|
||||
status |= read_sreg(s, (uint8_t)ACCEL_CONFIG0, 1, &(t->register_cache.accel_config0_reg));
|
||||
|
||||
status |= read_mclk_reg(s, (TMST_CONFIG1_MREG1 & 0xFFFF), 1, &(t->register_cache.tmst_config1_reg));
|
||||
|
||||
t->need_mclk_cnt = 0;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_read_reg(struct inv_imu_device *s, uint32_t reg, uint32_t len, uint8_t *buf)
|
||||
{
|
||||
uint32_t i;
|
||||
int rc = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
uint8_t *cache_addr = get_register_cache_addr(s, reg + i);
|
||||
|
||||
if (cache_addr) {
|
||||
buf[i] = *cache_addr;
|
||||
} else {
|
||||
if (!(reg & 0x10000)) {
|
||||
rc |= read_mclk_reg(s, ((reg + i) & 0xFFFF), 1, &buf[i]);
|
||||
} else {
|
||||
rc |= read_sreg(s, (uint8_t)reg + i, len - i, &buf[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int inv_imu_write_reg(struct inv_imu_device *s, uint32_t reg, uint32_t len, const uint8_t *buf)
|
||||
{
|
||||
uint32_t i;
|
||||
int rc = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
uint8_t *cache_addr = get_register_cache_addr(s, reg + i);
|
||||
|
||||
if (cache_addr)
|
||||
*cache_addr = buf[i];
|
||||
|
||||
if (!(reg & 0x10000))
|
||||
rc |= write_mclk_reg(s, ((reg + i) & 0xFFFF), 1, &buf[i]);
|
||||
}
|
||||
|
||||
if (reg & 0x10000)
|
||||
rc |= write_sreg(s, (uint8_t)reg, len, buf);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int inv_imu_switch_on_mclk(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t data;
|
||||
struct inv_imu_transport *t = (struct inv_imu_transport *)s;
|
||||
|
||||
/* set IDLE bit only if it is not set yet */
|
||||
if (t->need_mclk_cnt == 0) {
|
||||
|
||||
status |= inv_imu_read_reg(s, PWR_MGMT0, 1, &data);
|
||||
data |= PWR_MGMT0_IDLE_MASK;
|
||||
status |= inv_imu_write_reg(s, PWR_MGMT0, 1, &data);
|
||||
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* Check if MCLK is ready */
|
||||
do {
|
||||
status = inv_imu_read_reg(s, MCLK_RDY, 1, &data);
|
||||
} while ((status != 0) || !(data & MCLK_RDY_MCLK_RDY_MASK));
|
||||
} else {
|
||||
|
||||
/* Make sure it is already on */
|
||||
status |= inv_imu_read_reg(s, PWR_MGMT0, 1, &data);
|
||||
if (0 == (data &= PWR_MGMT0_IDLE_MASK))
|
||||
status |= INV_ERROR;
|
||||
}
|
||||
|
||||
/* Increment the counter to keep track of number of MCLK requesters */
|
||||
t->need_mclk_cnt++;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int inv_imu_switch_off_mclk(struct inv_imu_device *s)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t data;
|
||||
struct inv_imu_transport *t = (struct inv_imu_transport *)s;
|
||||
|
||||
/* Reset the IDLE but only if there is one requester left */
|
||||
if (t->need_mclk_cnt == 1) {
|
||||
status |= inv_imu_read_reg(s, PWR_MGMT0, 1, &data);
|
||||
data &= ~PWR_MGMT0_IDLE_MASK;
|
||||
status |= inv_imu_write_reg(s, PWR_MGMT0, 1, &data);
|
||||
} else {
|
||||
/* Make sure it is still on */
|
||||
status |= inv_imu_read_reg(s, PWR_MGMT0, 1, &data);
|
||||
if (0 == (data &= PWR_MGMT0_IDLE_MASK))
|
||||
status |= INV_ERROR;
|
||||
}
|
||||
|
||||
/* Decrement the counter */
|
||||
t->need_mclk_cnt--;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/* Static function */
|
||||
|
||||
static uint8_t *get_register_cache_addr(struct inv_imu_device *s, uint32_t reg)
|
||||
{
|
||||
struct inv_imu_transport *t = (struct inv_imu_transport *)s;
|
||||
|
||||
switch(reg) {
|
||||
case PWR_MGMT0: return &(t->register_cache.pwr_mgmt0_reg);
|
||||
case GYRO_CONFIG0: return &(t->register_cache.gyro_config0_reg);
|
||||
case ACCEL_CONFIG0: return &(t->register_cache.accel_config0_reg);
|
||||
case TMST_CONFIG1_MREG1: return &(t->register_cache.tmst_config1_reg);
|
||||
default: return (uint8_t *)0; // Not found
|
||||
}
|
||||
}
|
||||
|
||||
static int read_sreg(struct inv_imu_device *s, uint8_t reg, uint32_t len, uint8_t *buf)
|
||||
{
|
||||
struct inv_imu_serif *serif = (struct inv_imu_serif *)s;
|
||||
|
||||
if (len > serif->max_read)
|
||||
return INV_ERROR_SIZE;
|
||||
|
||||
if (serif->read_reg(serif, reg, buf, len) != 0)
|
||||
return INV_ERROR_TRANSPORT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int write_sreg(struct inv_imu_device *s, uint8_t reg, uint32_t len, const uint8_t *buf)
|
||||
{
|
||||
struct inv_imu_serif *serif = (struct inv_imu_serif *)s;
|
||||
|
||||
if (len > serif->max_write)
|
||||
return INV_ERROR_SIZE;
|
||||
|
||||
if (serif->write_reg(serif, reg, buf, len) != 0)
|
||||
return INV_ERROR_TRANSPORT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_mclk_reg(struct inv_imu_device *s, uint16_t regaddr, uint8_t rd_cnt, uint8_t *buf)
|
||||
{
|
||||
uint8_t data;
|
||||
uint8_t blk_sel = (regaddr & 0xFF00) >> 8;
|
||||
int status = 0;
|
||||
|
||||
// Have IMU not in IDLE mode to access MCLK domain
|
||||
status |= inv_imu_switch_on_mclk(s);
|
||||
|
||||
// optimize by changing BLK_SEL only if not NULL
|
||||
if (blk_sel)
|
||||
status |= write_sreg(s, (uint8_t)BLK_SEL_R & 0xff, 1, &blk_sel);
|
||||
|
||||
data = (regaddr & 0x00FF);
|
||||
status |= write_sreg(s, (uint8_t)MADDR_R, 1, &data);
|
||||
inv_imu_sleep_us(10);
|
||||
status |= read_sreg(s, (uint8_t)M_R, rd_cnt, buf);
|
||||
inv_imu_sleep_us(10);
|
||||
|
||||
if (blk_sel) {
|
||||
data = 0;
|
||||
status |= write_sreg(s, (uint8_t)BLK_SEL_R, 1, &data);
|
||||
}
|
||||
|
||||
// switch OFF MCLK if needed
|
||||
status |= inv_imu_switch_off_mclk(s);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int write_mclk_reg(struct inv_imu_device *s, uint16_t regaddr, uint8_t wr_cnt, const uint8_t *buf)
|
||||
{
|
||||
uint8_t data;
|
||||
uint8_t blk_sel = (regaddr & 0xFF00) >> 8;
|
||||
int status = 0;
|
||||
|
||||
// Have IMU not in IDLE mode to access MCLK domain
|
||||
status |= inv_imu_switch_on_mclk(s);
|
||||
|
||||
// optimize by changing BLK_SEL only if not NULL
|
||||
if (blk_sel)
|
||||
status |= write_sreg(s, (uint8_t)BLK_SEL_W, 1, &blk_sel);
|
||||
|
||||
data = (regaddr & 0x00FF);
|
||||
status |= write_sreg(s, (uint8_t)MADDR_W, 1, &data);
|
||||
for (uint8_t i = 0; i < wr_cnt; i++) {
|
||||
status |= write_sreg(s, (uint8_t)M_W, 1, &buf[i]);
|
||||
inv_imu_sleep_us(10);
|
||||
}
|
||||
|
||||
if (blk_sel) {
|
||||
data = 0;
|
||||
status = write_sreg(s, (uint8_t)BLK_SEL_W, 1, &data);
|
||||
}
|
||||
|
||||
status |= inv_imu_switch_off_mclk(s);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2015-2015 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively "Software") is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
/** @defgroup Transport IMU transport
|
||||
* @brief Low-level IMU SCLK register access
|
||||
* @ingroup Driver
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @file inv_imu_transport.h
|
||||
* Low-level IMU SCLK register access
|
||||
*/
|
||||
|
||||
#ifndef _INV_IMU_TRANSPORT_H_
|
||||
#define _INV_IMU_TRANSPORT_H_
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* forward declaration */
|
||||
struct inv_imu_device;
|
||||
|
||||
|
||||
/** @brief enumeration of serial interfaces available on IMU */
|
||||
typedef enum
|
||||
{
|
||||
UI_I2C,
|
||||
UI_SPI4,
|
||||
UI_SPI3
|
||||
} SERIAL_IF_TYPE_t;
|
||||
|
||||
/** @brief basesensor serial interface
|
||||
*/
|
||||
struct inv_imu_serif {
|
||||
void *context;
|
||||
int (*read_reg)(struct inv_imu_serif *serif, uint8_t reg, uint8_t *buf, uint32_t len);
|
||||
int (*write_reg)(struct inv_imu_serif *serif, uint8_t reg, const uint8_t *buf, uint32_t len);
|
||||
int (*configure)(struct inv_imu_serif *serif);
|
||||
uint32_t max_read;
|
||||
uint32_t max_write;
|
||||
SERIAL_IF_TYPE_t serif_type;
|
||||
};
|
||||
|
||||
/** @brief transport interface
|
||||
*/
|
||||
struct inv_imu_transport {
|
||||
struct inv_imu_serif serif; /**< Warning : this field MUST be the first one of struct inv_imu_transport */
|
||||
|
||||
/** @brief Contains mirrored values of some IP registers */
|
||||
struct register_cache {
|
||||
uint8_t pwr_mgmt0_reg; /**< PWR_MGMT0, Bank: 0 */
|
||||
uint8_t gyro_config0_reg; /**< GYRO_CONFIG0, Bank: 0 */
|
||||
uint8_t accel_config0_reg; /**< ACCEL_CONFIG0, Bank: 0 */
|
||||
uint8_t tmst_config1_reg; /**< TMST_CONFIG1, Bank: MREG_TOP1 */
|
||||
} register_cache; /**< Store mostly used register values on SRAM */
|
||||
|
||||
uint8_t need_mclk_cnt; /**< internal counter to keep track of everyone that needs MCLK */
|
||||
|
||||
};
|
||||
|
||||
/** @brief Init cache variable.
|
||||
* @return 0 in case of success, -1 for any error
|
||||
*/
|
||||
int inv_imu_init_transport(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Reads data from a register on IMU.
|
||||
* @param[in] reg register address to be read
|
||||
* @param[in] len number of byte to be read
|
||||
* @param[out] buf output data from the register
|
||||
* @return 0 in case of success, -1 for any error
|
||||
*/
|
||||
int inv_imu_read_reg(struct inv_imu_device *s, uint32_t reg, uint32_t len, uint8_t *buf);
|
||||
|
||||
/** @brief Writes data to a register on IMU.
|
||||
* @param[in] reg register address to be written
|
||||
* @param[in] len number of byte to be written
|
||||
* @param[in] buf input data to write
|
||||
* @return 0 in case of success, -1 for any error
|
||||
*/
|
||||
int inv_imu_write_reg(struct inv_imu_device *s, uint32_t reg, uint32_t len, const uint8_t *buf);
|
||||
|
||||
/** @brief Enable MCLK so that MREG are clocked and system beyond SOI can be safely accessed
|
||||
* @return 0 in case of success, -1 for any error
|
||||
*/
|
||||
int inv_imu_switch_on_mclk(struct inv_imu_device *s);
|
||||
|
||||
/** @brief Disable MCLK so that MREG are not clocked anymore, hence reducing power consumption
|
||||
* @return 0 in case of success, -1 for any error
|
||||
*/
|
||||
int inv_imu_switch_off_mclk(struct inv_imu_device *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INV_IMU_TRANSPORT_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* ________________________________________________________________________________________________________
|
||||
* Copyright (c) 2019 InvenSense Inc. All rights reserved.
|
||||
*
|
||||
* This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
* to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
* and other intellectual property rights laws.
|
||||
*
|
||||
* InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
* and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
* from InvenSense is strictly prohibited.
|
||||
*
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, THE SOFTWARE IS
|
||||
* PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
||||
* EXCEPT AS OTHERWISE PROVIDED IN A LICENSE AGREEMENT BETWEEN THE PARTIES, IN NO EVENT SHALL
|
||||
* INVENSENSE BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
|
||||
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THE SOFTWARE.
|
||||
* ________________________________________________________________________________________________________
|
||||
*/
|
||||
|
||||
#ifndef _INV_IMU_VERSION_H_
|
||||
#define _INV_IMU_VERSION_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INV_IMU_VERSION_STRING "2.0.4"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _INV_IMU_VERSION_H_ */
|
||||
@@ -0,0 +1,153 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright © 2014-2015 InvenSense Inc. Portions Copyright © 2014-2015 Movea. All rights reserved.
|
||||
|
||||
This software, related documentation and any modifications thereto (collectively “Software”) is subject
|
||||
to InvenSense and its licensors' intellectual property rights under U.S. and international copyright
|
||||
and other intellectual property rights laws.
|
||||
|
||||
InvenSense and its licensors retain all intellectual property and proprietary rights in and to the Software
|
||||
and any use, reproduction, disclosure or distribution of the Software without an express license agreement
|
||||
from InvenSense is strictly prohibited.
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef INVN_COMMON_INVN_TYPES_H_
|
||||
#define INVN_COMMON_INVN_TYPES_H_
|
||||
|
||||
/**
|
||||
* @defgroup invn_types Types
|
||||
* @brief Motion Library - Type definitions.
|
||||
* \details Definition of codes and error codes used within the MPL and
|
||||
* returned to the user.
|
||||
* Every function tries to return a meaningful error code basing
|
||||
* on the occuring error condition. The error code is numeric.
|
||||
*
|
||||
* The available error codes and their associated values are:
|
||||
* - (0) INV_SUCCESS
|
||||
* - (32) INV_ERROR
|
||||
* - (22 / EINVAL) INV_ERROR_INVALID_PARAMETER
|
||||
* - (1 / EPERM) INV_ERROR_FEATURE_NOT_ENABLED
|
||||
* - (36) INV_ERROR_FEATURE_NOT_IMPLEMENTED
|
||||
* - (64) INV_ERROR_FIFO_READ_COUNT
|
||||
* \todo Clean up the details documentation in order to use only the \\def one.
|
||||
* \todo Add documentation to all the definitions
|
||||
* \ingroup Common
|
||||
* @file invn_types.h
|
||||
*/
|
||||
|
||||
//=======================================//
|
||||
//========= Integer Definition =========//
|
||||
//=======================================//
|
||||
#ifdef _MSC_VER
|
||||
# include "inttypes.h"
|
||||
#else
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
//=======================================//
|
||||
//======= Fixed Point Conversion =======//
|
||||
//=======================================//
|
||||
|
||||
//! \def INVN_FLT_TO_FXP
|
||||
//! Convert the \a value from float to QN value. \ingroup invn_macro
|
||||
#define INVN_FLT_TO_FXP(value, shift) ( (int32_t) ((float)(value)*(1ULL << (shift)) + ( (value>=0)-0.5f )) )
|
||||
//! \def INVN_DBL_TO_FXP
|
||||
//! Convert the \a value from double to QN value. \ingroup invn_macro
|
||||
#define INVN_DBL_TO_FXP(value, shift) ( (int32_t) ((double)(value)*(1ULL << (shift)) + ( (value>=0)-0.5 )) )
|
||||
//! \def INVN_FLT_TO_UFXP
|
||||
//! Convert the \a value from float to unsigned QN value. \ingroup invn_macro
|
||||
#define INVN_FLT_TO_UFXP(value, shift) ( (uint32_t) ((float)(value)*(1ULL << (shift)) + 0.5f) )
|
||||
//! \def INVN_DBL_TO_UFXP
|
||||
//! Convert the \a value from double to unsigned QN value. \ingroup invn_macro
|
||||
#define INVN_DBL_TO_UFXP(value, shift) ( (uint32_t) ((double)(value)*(1ULL << (shift)) + 0.5) )
|
||||
//! \def INVN_FXP_TO_FLT
|
||||
//! Convert the \a value from QN value to float. \ingroup invn_macro
|
||||
#define INVN_FXP_TO_FLT(value, shift) ( (float) (int32_t)(value) / (float)(1ULL << (shift)) )
|
||||
//! \def INVN_FXP_TO_DBL
|
||||
//! Convert the \a value from QN value to double. \ingroup invn_macro
|
||||
#define INVN_FXP_TO_DBL(value, shift) ( (double) (int32_t)(value) / (double)(1ULL << (shift)) )
|
||||
//! \def INVN_UFXP_TO_FLT
|
||||
//! Convert the \a value from unsigned QN value to float. \ingroup invn_macro
|
||||
#define INVN_UFXP_TO_FLT(value, shift) ( (float) (uint32_t)(value) / (float)(1ULL << (shift)) )
|
||||
//! \def INVN_UFXP_TO_DBL
|
||||
//! Convert the \a value from unsigned QN value to double. \ingroup invn_macro
|
||||
#define INVN_UFXP_TO_DBL(value, shift) ( (double) (uint32_t)(value) / (double)(1ULL << (shift)) )
|
||||
//! \def INVN_CONVERT_FLT_TO_FXP
|
||||
//! Macro to convert float values from an address into QN values, and copy them to another address. \ingroup invn_macro
|
||||
#define INVN_CONVERT_FLT_TO_FXP(fltptr, fixptr, length, shift) { int32_t i; for(i=0; i<(length); ++i) (fixptr)[i] = INVN_FLT_TO_FXP((fltptr)[i], shift); }
|
||||
//! \def INVN_CONVERT_FLT_TO_UFXP
|
||||
//! Macro to convert float values from an address into unsigned QN values, and copy them to another address. \ingroup invn_macro
|
||||
#define INVN_CONVERT_FLT_TO_UFXP(fltptr, fixptr, length, shift) { int32_t i; for(i=0; i<(length); ++i) (fixptr)[i] = INVN_FLT_TO_UFXP((fltptr)[i], shift); }
|
||||
//! \def INVN_CONVERT_DBL_TO_FXP
|
||||
//! Macro to convert double values from an address into QN values, and copy them to another address. \ingroup invn_macro
|
||||
#define INVN_CONVERT_DBL_TO_FXP(fltptr, fixptr, length, shift) { int32_t i; for(i=0; i<(length); ++i) (fixptr)[i] = INVN_DBL_TO_FXP((fltptr)[i], shift); }
|
||||
//! \def INVN_CONVERT_DBL_TO_UFXP
|
||||
//! Macro to convert double values from an address into unsigned QN values, and copy them to another address. \ingroup invn_macro
|
||||
#define INVN_CONVERT_DBL_TO_UFXP(fltptr, fixptr, length, shift) { int32_t i; for(i=0; i<(length); ++i) (fixptr)[i] = INVN_DBL_TO_UFXP((fltptr)[i], shift); }
|
||||
//! \def INVN_CONVERT_FXP_TO_FLT
|
||||
//! Macro to convert QN values from an address into float values, and copy them to another address. \ingroup invn_macro
|
||||
#define INVN_CONVERT_FXP_TO_FLT(fixptr, fltptr, length, shift) { int32_t i; for(i=0; i<(length); ++i) (fltptr)[i] = INVN_FXP_TO_FLT((fixptr)[i], shift); }
|
||||
//! \def INVN_CONVERT_UFXP_TO_FLT
|
||||
//! Macro to convert unsigned QN values from an address into float values, and copy them to another address. \ingroup invn_macro
|
||||
#define INVN_CONVERT_UFXP_TO_FLT(fixptr, fltptr, length, shift) { int32_t i; for(i=0; i<(length); ++i) (fltptr)[i] = INVN_UFXP_TO_FLT((fixptr)[i], shift); }
|
||||
//! \def INVN_CONVERT_FXP_TO_DBL
|
||||
//! Macro to convert QN values from an address into double values, and copy them to another address. \ingroup invn_macro
|
||||
#define INVN_CONVERT_FXP_TO_DBL(fixptr, fltptr, length, shift) { int32_t i; for(i=0; i<(length); ++i) (fltptr)[i] = INVN_FXP_TO_DBL((fixptr)[i], shift); }
|
||||
//! \def INVN_CONVERT_UFXP_TO_DBL
|
||||
//! \brief Macro to convert unsigned QN values from an address into double values, and copy them to another address. \ingroup invn_macro
|
||||
#define INVN_CONVERT_UFXP_TO_DBL(fixptr, fltptr, length, shift) { int32_t i; for(i=0; i<(length); ++i) (fltptr)[i] = INVN_UFXP_TO_DBL((fixptr)[i], shift); }
|
||||
|
||||
|
||||
//=====================================//
|
||||
//========= Error Definition =========//
|
||||
//=====================================//
|
||||
|
||||
#ifndef REMOVE_INV_ERROR_T
|
||||
typedef int32_t inv_error_t; /*!< Type used for error definitions. \ingroup invn_types */
|
||||
#endif
|
||||
|
||||
//typedef int32_t mpu_error_t;
|
||||
typedef int64_t mpu_time_t; /*!< Type used for mpu time. \ingroup invn_types */
|
||||
|
||||
// Typically I2C addresses are 8-bit, but some specifications allow for a 10-bit address
|
||||
// This definition allows the length to be optimally defined for the platform
|
||||
typedef uint8_t inv_i2c_addr_t; /*!< Type used for I2C addresses. \ingroup invn_types */
|
||||
|
||||
#ifdef __IAR_SYSTEMS_ICC__
|
||||
// These are defined in standard C errno.h
|
||||
#define EINVAL (22)
|
||||
#define EPERM (1)
|
||||
#define ENOMEM (12)
|
||||
#else
|
||||
#include "errno.h"
|
||||
#endif
|
||||
|
||||
#define INVN_SUCCESS (0) /*!< Constant definition for success. \ingroup invn_types */
|
||||
#define INVN_ERROR_BASE (0x20) /*!< Constant definition for basic error. Value is \b 32 \ingroup invn_types */
|
||||
#define INVN_ERROR (INVN_ERROR_BASE) /*!< Constant definition for error. Value is \b 32 \ingroup invn_types */
|
||||
#define INVN_ERROR_FEATURE_NOT_ENABLED (EPERM) /*!< Constant definition for feature not enabled error. \ingroup invn_types */
|
||||
#define INVN_ERROR_FEATURE_NOT_IMPLEMENTED (INVN_ERROR_BASE + 4) /*!< Constant definition for feature not implemented error. \ingroup invn_types */
|
||||
#define INVN_ERROR_INVALID_PARAMETER (EINVAL) /*!< Constant definition for invalid parameter error. \ingroup invn_types */
|
||||
#define INVN_ERROR_FILE_OPEN (INVN_ERROR_BASE + 14) /*!< Constant definition for opening file error. \ingroup invn_types */
|
||||
#define INVN_ERROR_FILE_READ (INVN_ERROR_BASE + 15) /*!< Constant definition for reading file error. \ingroup invn_types */
|
||||
#define INVN_ERROR_FILE_WRITE (INVN_ERROR_BASE + 16) /*!< Constant definition for writing file error. \ingroup invn_types */
|
||||
#define INVN_ERROR_INVALID_CONFIGURATION (INVN_ERROR_BASE + 17) /*!< Constant definition for invalid configuration error. \ingroup invn_types */
|
||||
/* Serial Communication */
|
||||
#define INVN_ERROR_SERIAL_OPEN_ERROR (INVN_ERROR_BASE + 21) /*!< Constant definition for serial open error. \ingroup invn_types */
|
||||
#define INVN_ERROR_SERIAL_READ (INVN_ERROR_BASE + 22) /*!< Constant definition for serial read error. \ingroup invn_types */
|
||||
#define INVN_ERROR_SERIAL_WRITE (INVN_ERROR_BASE + 23) /*!< Constant definition for serial write error. \ingroup invn_types */
|
||||
/* Fifo */
|
||||
#define INVN_ERROR_FIFO_OVERFLOW (INVN_ERROR_BASE + 30) /*!< Constant definition for fifo overflow error. \ingroup invn_types */
|
||||
#define INVN_ERROR_FIFO_FOOTER (INVN_ERROR_BASE + 31) /*!< Constant definition for fifo footer error. \ingroup invn_types */
|
||||
#define INVN_ERROR_FIFO_READ_COUNT (INVN_ERROR_BASE + 32) /*!< Constant definition for fifo read count error. \ingroup invn_types */
|
||||
#define INVN_ERROR_FIFO_READ_DATA (INVN_ERROR_BASE + 33) /*!< Constant definition for fifo read data error. \ingroup invn_types */
|
||||
/* OS interface errors */
|
||||
#define INVN_ERROR_OS_BAD_HANDLE (INVN_ERROR_BASE + 61) /*!< Constant definition for OS bad handle error. \ingroup invn_types */
|
||||
#define INVN_ERROR_OS_CREATE_FAILED (INVN_ERROR_BASE + 62) /*!< Constant definition for OS create failed error. \ingroup invn_types */
|
||||
#define INVN_ERROR_OS_LOCK_FAILED (INVN_ERROR_BASE + 63) /*!< Constant definition for OS lock failed error. \ingroup invn_types */
|
||||
/* Warning */
|
||||
#define INVN_WARNING_SEMAPHORE_TIMEOUT (INVN_ERROR_BASE + 86) /*!< Constant definition for semaphore timeout warning. \ingroup invn_types */
|
||||
|
||||
|
||||
#endif // INVN_COMMON_INVN_TYPES_H_
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
$License:
|
||||
Copyright (C) 2018 InvenSense Corporation, All Rights Reserved.
|
||||
$
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _INVN_ALGO_AGM_H_
|
||||
#define _INVN_ALGO_AGM_H_
|
||||
|
||||
#include "invn_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \defgroup AGM AGM
|
||||
* \brief Algorithm that provides device orientation. Algorithm inputs are raw Accelerometer, Gyroscope and Magnetometer data.
|
||||
* Algorithm outputs: calibrated sensor and 9-axis sensor fusion.
|
||||
* \warning supported sampling frequency [50 Hz-1000 Hz]
|
||||
* \warning supported gyroscope FSR [250 dps, 500 dps, 1000 dps, 2000 dps, 4000 dps]
|
||||
* \warning supported accelerometer FSR [1 g, 2 g, 4 g, 8 g, 16 g]
|
||||
*/
|
||||
|
||||
#define INVN_ALGO_AGM_INPUT_MASK_ACC 1 ///< Raw Accel update mask
|
||||
#define INVN_ALGO_AGM_INPUT_MASK_GYR 2 ///< Raw Gyro update mask
|
||||
#define INVN_ALGO_AGM_INPUT_MASK_MAG 4 ///< Raw Mag update mask
|
||||
|
||||
#define INVN_ALGO_AGM_OUTPUT_MASK_ACCEL_CAL 1 ///< Accel cal output update mask
|
||||
#define INVN_ALGO_AGM_OUTPUT_MASK_GYRO_CAL 2 ///< Gyro cal output update mask
|
||||
#define INVN_ALGO_AGM_OUTPUT_MASK_MAG_CAL 4 ///< Mag cal output update mask
|
||||
#define INVN_ALGO_AGM_OUTPUT_MASK_QUAT_AG 8 ///< Game Rotation Vector (Accel and Gyro Fusion) output update mask
|
||||
#define INVN_ALGO_AGM_OUTPUT_MASK_QUAT_AGM 16 ///< Rotation Vector (Accel, Gyro and Magnetometer Fusion) output update mask
|
||||
#define INVN_ALGO_AGM_OUTPUT_MASK_GRAVITY 32 ///< Gravity vector output update mask
|
||||
#define INVN_ALGO_AGM_OUTPUT_MASK_LINEARACC 64 ///< Linear acceleration vector output update mask
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
struct inv_icm426xx;
|
||||
|
||||
/*! \struct InvnAlgoAGMInput
|
||||
* AGM input structure (raw data) \ingroup AGM
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int32_t mask; /*!< mask to specify updated inputs. */
|
||||
int64_t sRimu_time_us; /*!< timestamp \f$ [\mu s]\f$ of raw accel and gyro */
|
||||
int32_t sRacc_data[3]; /*!< raw accelerometer in high resolution mode. Expect Full Scale Value coded on 20 bit (i.e. +/- FSR g = 1<<19 LSB) */
|
||||
int32_t sRgyr_data[3]; /*!< raw gyroscope in high resolution mode. Expect Full Scale Value coded on 20 bit (i.e. +/- FSR dps = 1<<19 LSB) */
|
||||
int16_t sRtemp_data; /*!< raw temperature */
|
||||
int64_t sRmag_time_us; /*!< timestamp of raw mag */
|
||||
int32_t sRmag_data[3]; /*!< raw mag */
|
||||
} InvnAlgoAGMInput;
|
||||
|
||||
|
||||
/*! \struct InvnAlgoAGMOutput
|
||||
* AGM output structure (calibrated sensors and fusion output) \ingroup AGM
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int32_t mask; /*!< mask to specify updated outputs */
|
||||
int32_t acc_uncal_q16[3]; /*!< uncalibrated accelerometer (1 g = 1<<16) */
|
||||
int32_t acc_cal_q16[3]; /*!< calibrated accelerometer (1 g = 1<<16) */
|
||||
int32_t acc_bias_q16[3]; /*!< accelerometer bias (1 g = 1<<16)*/
|
||||
int8_t acc_accuracy_flag; /*!< accelerometer accuracy from 0(non calibrated) to 3(well calibrated) */
|
||||
|
||||
int32_t gyr_uncal_q16[3]; /*!< uncalibrated gyroscope (1 dps = 1<<16) */
|
||||
int32_t gyr_cal_q16[3]; /*!< calibrated gyroscope (1 dps = 1<<16) */
|
||||
int32_t gyr_bias_q16[3]; /*!< gyro bias (1 dps = 1<<16)*/
|
||||
int8_t gyr_accuracy_flag; /*!< gyro accuracy, from 0(non calibrated) to 3(well calibrated) */
|
||||
|
||||
int32_t mag_uncal_q16[3]; /*!< uncalibrated magnetometer (1uT = 1<<16) */
|
||||
int32_t mag_cal_q16[3]; /*!< calibrated magnetometer (1uT = 1<<16) */
|
||||
int32_t mag_bias_q16[3]; /*!< magnetometer bias (1uT = 1<<16) */
|
||||
int8_t mag_accuracy_flag; /*!< magnetometer accuracy, from 0(non calibrated) to 3(well calibrated) */
|
||||
|
||||
int32_t grv_quat_q30[4]; /*!< 6-axis (accel and gyro fusion) quaternion */
|
||||
int32_t rv_quat_q30[4]; /*!< 9-axis (accel, gyro and magnetometer fusion) quaternion */
|
||||
int32_t rv_accuracy_q27; /*!< 9-axis (accel, gyro and magnetometer fusion) 3\sigma accuracy in rad */
|
||||
int32_t gravity_q16[3]; /*!< gravity estimation in sensor frame */
|
||||
int32_t linear_acc_q16[3]; /*!< linear acceleration estimation in sensor frame */
|
||||
|
||||
int32_t temp_degC_q16; /*!< temperature (1 \f$ [^{\circ}C]\f$ = 1<<16)*/
|
||||
} InvnAlgoAGMOutput;
|
||||
|
||||
|
||||
/*! \struct InvnAlgoAGMConfig
|
||||
* AGM configuration structure (sensor related settings) \ingroup AGM
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int32_t * acc_bias_q16; /*!< Previously stored accel bias pointer. If pointer is NULL or 0, offset will be set to { 0, 0, 0} */
|
||||
int32_t * gyr_bias_q16; /*!< Previously stored gyro bias pointer. If pointer is NULL or 0, offset will be set to { 0, 0, 0} */
|
||||
int32_t * mag_bias_q16; /*!< mag_bias_q16 Previously stored mag bias pointer If pointer is NULL or 0, offset will be set to { 0, 0, 0} */
|
||||
int8_t acc_accuracy; /*!< Previously stored accelerometer bias accuracy (0 to 3) */
|
||||
int8_t gyr_accuracy; /*!< Previously stored gyroscope bias accuracy (0 to 3) */
|
||||
int8_t mag_accuracy; /*!< Previously stored magnetometer bias accuracy (0 to 3) */
|
||||
|
||||
int32_t acc_fsr; /*!< accelerometer full scale range [g] */
|
||||
int32_t gyr_fsr; /*!< gyroscope full scale range [dps] */
|
||||
|
||||
uint32_t acc_odr_us; /*!< accelerometer output data rate in \f$ [\mu s]\f$ */
|
||||
uint32_t gyr_odr_us; /*!< gyroscope output data rate \f$ [\mu s]\f$ */
|
||||
|
||||
int32_t mag_sc_q16; /*!< magnetometer sensitivity (uT/LSB, e.g. mag_uT = (mag_sc_q16 * raw_mag_LSB)/65536) */
|
||||
uint32_t mag_odr_us; /*!< magnetometer output data rate \f$ [\mu s]\f$ */
|
||||
|
||||
int32_t temp_sensitivity; /*!< temperature sensitivity in q30 (if temperature(\f$ ^{\circ}C \f$) = LSB * k + z, then temp_sensitivity = k) */
|
||||
int32_t temp_offset; /*!< temperature offset in q16 (if temperature(\f$ ^{\circ}C \f$) = LSB * k + z, then temp_offset = z) */
|
||||
} InvnAlgoAGMConfig;
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Return library version x.y.z-suffix as a char array
|
||||
* \retval library version a char array "x.y.z-suffix"
|
||||
* \ingroup AGM
|
||||
*/
|
||||
const char * invn_algo_agm_version(void);
|
||||
|
||||
/*!
|
||||
* \brief Initializes algorithms with default parameters and reset states.
|
||||
* (\icm_device[in] Invensense ICM426XX device pointer. Only when gyro assisted is enabled.)
|
||||
* \config[in] algo init parameters structure.
|
||||
* \return initialization success indicator.
|
||||
* \retval 0 Success
|
||||
* \retval 1 Fail
|
||||
* \ingroup AGM
|
||||
*/
|
||||
#ifdef WITH_GYRO_ASSIST
|
||||
uint8_t invn_algo_agm_init_a(struct inv_icm426xx * icm_device, const InvnAlgoAGMConfig * config);
|
||||
#else
|
||||
uint8_t invn_algo_agm_init(const InvnAlgoAGMConfig * config);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief Sets algo config structure.
|
||||
* \config[in] config structure of the algo.
|
||||
* \ingroup AGM
|
||||
*/
|
||||
void invn_algo_agm_set_config(const InvnAlgoAGMConfig * config);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Performs algorithm computation.
|
||||
* \in inputs algorithm input. Input mask (inputs->mask) should be set with respect to new sensor data in InvnAlgoAGMInput.
|
||||
* \out outputs algorithm output. Output mask (outputs->mask) reports updated outputs in InvnAlgoAGMOutput.
|
||||
* \ingroup AGM
|
||||
*/
|
||||
void invn_algo_agm_process(const InvnAlgoAGMInput *inputs, InvnAlgoAGMOutput *outputs);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,324 @@
|
||||
/*******************************************************************************
|
||||
* @file app_raw.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#include "sdk_config.h"
|
||||
#include "app_raw.h"
|
||||
#include "inv_imu_extfunc.h"
|
||||
#include "inv_imu_driver.h"
|
||||
#include "ble_nus.h"
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
|
||||
#include "app_util_platform.h"
|
||||
#include "main.h"
|
||||
#include "meas_pd_48.h"
|
||||
#include <cmd_parse.h>
|
||||
|
||||
|
||||
/*
|
||||
* Print raw data or scaled data
|
||||
* 0 : print raw accel, gyro and temp data
|
||||
* 1 : print scaled accel, gyro and temp data in g, dps and degree Celsius
|
||||
*/
|
||||
#define SCALED_DATA_G_DPS 0
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Static and extern variables
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Just a handy variable to handle the IMU object */
|
||||
static struct inv_imu_device icm_driver;
|
||||
uint8_t imu_bin_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
/*
|
||||
* ICM mounting matrix
|
||||
* Coefficients are coded as Q30 integer
|
||||
*/
|
||||
#if (SM_BOARD_REV == SM_REVB_DB) /* when DB or EVB are used */
|
||||
static int32_t icm_mounting_matrix[9] = { 0, -(1<<30), 0,
|
||||
(1<<30), 0, 0,
|
||||
0, 0, (1<<30) };
|
||||
#else /* For SmartMotion */
|
||||
static int32_t icm_mounting_matrix[9] = {(1<<30), 0, 0,
|
||||
0, (1<<30), 0,
|
||||
0, 0, (1<<30)};
|
||||
#endif
|
||||
extern bool custom_add_data;
|
||||
extern bool motion_raw_data_enabled;
|
||||
extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
extern bool go_pdread;
|
||||
extern which_cmd_t cmd_type_t;
|
||||
uint16_t ssp_data[6]={0,};
|
||||
extern bool info4; //cmd_parse
|
||||
extern volatile uint16_t info_imu[6];
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* static function declaration
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
static void apply_mounting_matrix(const int32_t matrix[9], int32_t raw[3]);
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definition
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
int setup_imu_device(struct inv_imu_serif *icm_serif)
|
||||
{
|
||||
int rc = 0;
|
||||
uint8_t who_am_i;
|
||||
|
||||
/* Init device */
|
||||
rc = inv_imu_init(&icm_driver, icm_serif, imu_callback);
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
printf("!!! ERROR : Failed to initialize IMU!\r\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Check WHOAMI */
|
||||
rc = inv_imu_get_who_am_i(&icm_driver, &who_am_i);
|
||||
if (rc != INV_ERROR_SUCCESS) {
|
||||
printf("!!! ERROR : Failed to read whoami!\r\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (who_am_i != ICM_WHOAMI) {
|
||||
printf("!!! ERROR : Bad WHOAMI value! Read 0x%02x, expected 0x%02x\r\n", who_am_i, ICM_WHOAMI);
|
||||
return INV_ERROR;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int configure_imu_device(void)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (!USE_FIFO)
|
||||
rc |= inv_imu_configure_fifo(&icm_driver, INV_IMU_FIFO_DISABLED);
|
||||
|
||||
if (USE_HIGH_RES_MODE) {
|
||||
rc |= inv_imu_enable_high_resolution_fifo(&icm_driver);
|
||||
} else {
|
||||
rc |= inv_imu_set_accel_fsr(&icm_driver, ACCEL_CONFIG0_FS_SEL_4g);
|
||||
rc |= inv_imu_set_gyro_fsr(&icm_driver, GYRO_CONFIG0_FS_SEL_2000dps);
|
||||
}
|
||||
|
||||
if (USE_LOW_NOISE_MODE) {
|
||||
rc |= inv_imu_set_accel_frequency(&icm_driver, ACCEL_CONFIG0_ODR_800_HZ);
|
||||
rc |= inv_imu_set_gyro_frequency(&icm_driver, GYRO_CONFIG0_ODR_800_HZ);
|
||||
rc |= inv_imu_enable_accel_low_noise_mode(&icm_driver);
|
||||
} else {
|
||||
rc |= inv_imu_set_accel_frequency(&icm_driver, ACCEL_CONFIG0_ODR_100_HZ);
|
||||
rc |= inv_imu_set_gyro_frequency(&icm_driver, GYRO_CONFIG0_ODR_100_HZ);
|
||||
rc |= inv_imu_enable_accel_low_power_mode(&icm_driver);
|
||||
}
|
||||
|
||||
rc |= inv_imu_enable_gyro_low_noise_mode(&icm_driver);
|
||||
|
||||
if (!USE_FIFO)
|
||||
inv_imu_sleep_us(GYR_STARTUP_TIME_US);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int get_imu_data(void)
|
||||
{
|
||||
#if USE_FIFO
|
||||
return inv_imu_get_data_from_fifo(&icm_driver);
|
||||
#else
|
||||
|
||||
return inv_imu_get_data_from_registers(&icm_driver);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SCALED_DATA_G_DPS
|
||||
static void get_accel_and_gyr_fsr(int16_t * accel_fsr_g, int16_t * gyro_fsr_dps)
|
||||
{
|
||||
ACCEL_CONFIG0_FS_SEL_t accel_fsr_bitfield;
|
||||
GYRO_CONFIG0_FS_SEL_t gyro_fsr_bitfield;
|
||||
|
||||
inv_imu_get_accel_fsr(&icm_driver, &accel_fsr_bitfield);
|
||||
switch(accel_fsr_bitfield) {
|
||||
case ACCEL_CONFIG0_FS_SEL_2g: *accel_fsr_g = 2;
|
||||
break;
|
||||
case ACCEL_CONFIG0_FS_SEL_4g: *accel_fsr_g = 4;
|
||||
break;
|
||||
case ACCEL_CONFIG0_FS_SEL_8g: *accel_fsr_g = 8;
|
||||
break;
|
||||
case ACCEL_CONFIG0_FS_SEL_16g: *accel_fsr_g = 16;
|
||||
break;
|
||||
default: *accel_fsr_g = -1;
|
||||
}
|
||||
|
||||
inv_imu_get_gyro_fsr(&icm_driver, &gyro_fsr_bitfield);
|
||||
switch(gyro_fsr_bitfield) {
|
||||
case GYRO_CONFIG0_FS_SEL_250dps: *gyro_fsr_dps = 250;
|
||||
break;
|
||||
case GYRO_CONFIG0_FS_SEL_500dps: *gyro_fsr_dps = 500;
|
||||
break;
|
||||
case GYRO_CONFIG0_FS_SEL_1000dps: *gyro_fsr_dps = 1000;
|
||||
break;
|
||||
case GYRO_CONFIG0_FS_SEL_2000dps: *gyro_fsr_dps = 2000;
|
||||
break;
|
||||
default: *gyro_fsr_dps = -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void imu_callback(inv_imu_sensor_event_t *event)
|
||||
{
|
||||
int32_t accel[3], gyro[3];
|
||||
|
||||
#if SCALED_DATA_G_DPS
|
||||
float accel_g[3];
|
||||
float gyro_dps[3];
|
||||
float temp_degc;
|
||||
int16_t accel_fsr_g, gyro_fsr_dps;
|
||||
#endif
|
||||
|
||||
#if USE_FIFO
|
||||
static uint64_t last_fifo_timestamp = 0;
|
||||
static uint32_t rollover_num = 0;
|
||||
|
||||
// Handle rollover
|
||||
if (last_fifo_timestamp > event->timestamp_fsync)
|
||||
rollover_num++;
|
||||
last_fifo_timestamp = event->timestamp_fsync;
|
||||
|
||||
// Compute timestamp in us
|
||||
timestamp = event->timestamp_fsync + rollover_num * UINT16_MAX;
|
||||
timestamp *= inv_imu_get_fifo_timestamp_resolution_us_q24(&icm_driver);
|
||||
timestamp /= (1UL << 24);
|
||||
|
||||
if (icm_driver.fifo_highres_enabled) {
|
||||
accel[0] = (((int32_t)event->accel[0] << 4)) | event->accel_high_res[0];
|
||||
accel[1] = (((int32_t)event->accel[1] << 4)) | event->accel_high_res[1];
|
||||
accel[2] = (((int32_t)event->accel[2] << 4)) | event->accel_high_res[2];
|
||||
|
||||
gyro[0] = (((int32_t)event->gyro[0] << 4)) | event->gyro_high_res[0];
|
||||
gyro[1] = (((int32_t)event->gyro[1] << 4)) | event->gyro_high_res[1];
|
||||
gyro[2] = (((int32_t)event->gyro[2] << 4)) | event->gyro_high_res[2];
|
||||
|
||||
} else {
|
||||
accel[0] = event->accel[0];
|
||||
accel[1] = event->accel[1];
|
||||
accel[2] = event->accel[2];
|
||||
|
||||
gyro[0] = event->gyro[0];
|
||||
gyro[1] = event->gyro[1];
|
||||
gyro[2] = event->gyro[2];
|
||||
}
|
||||
#else
|
||||
|
||||
accel[0] = event->accel[0];
|
||||
accel[1] = event->accel[1];
|
||||
accel[2] = event->accel[2];
|
||||
|
||||
gyro[0] = event->gyro[0];
|
||||
gyro[1] = event->gyro[1];
|
||||
gyro[2] = event->gyro[2];
|
||||
|
||||
// Force sensor_mask so it gets displayed below
|
||||
event->sensor_mask |= (1 << INV_SENSOR_TEMPERATURE);
|
||||
event->sensor_mask |= (1 << INV_SENSOR_ACCEL);
|
||||
event->sensor_mask |= (1 << INV_SENSOR_GYRO);
|
||||
#endif
|
||||
|
||||
apply_mounting_matrix(icm_mounting_matrix, accel);
|
||||
apply_mounting_matrix(icm_mounting_matrix, gyro);
|
||||
|
||||
#if SCALED_DATA_G_DPS
|
||||
/*
|
||||
* Convert raw data into scaled data in g and dps
|
||||
*/
|
||||
get_accel_and_gyr_fsr(&accel_fsr_g, &gyro_fsr_dps);
|
||||
accel_g[0] = (float)(accel[0] * accel_fsr_g) / INT16_MAX;
|
||||
accel_g[1] = (float)(accel[1] * accel_fsr_g) / INT16_MAX;
|
||||
accel_g[2] = (float)(accel[2] * accel_fsr_g) / INT16_MAX;
|
||||
gyro_dps[0] = (float)(gyro[0] * gyro_fsr_dps) / INT16_MAX;
|
||||
gyro_dps[1] = (float)(gyro[1] * gyro_fsr_dps) / INT16_MAX;
|
||||
gyro_dps[2] = (float)(gyro[2] * gyro_fsr_dps) / INT16_MAX;
|
||||
if (USE_HIGH_RES_MODE || !USE_FIFO)
|
||||
temp_degc = 25 + ((float)event->temperature / 128);
|
||||
else
|
||||
temp_degc = 25 + ((float)event->temperature / 2);
|
||||
|
||||
/*
|
||||
* Output scaled data on UART link
|
||||
*/
|
||||
if (event->sensor_mask & (1 << INV_SENSOR_ACCEL) && event->sensor_mask & (1 << INV_SENSOR_GYRO))
|
||||
printf("%u: %.3f, \t%.3f, \t%.3f, \t%.3f, \t%.3f, \t%.3f, \t%.3f\r\n",
|
||||
(uint32_t)timestamp,
|
||||
accel_g[0], accel_g[1], accel_g[2],
|
||||
temp_degc,
|
||||
gyro_dps[0], gyro_dps[1], gyro_dps[2]);
|
||||
#else
|
||||
|
||||
/*
|
||||
* Output raw data on UART link
|
||||
*/
|
||||
if (event->sensor_mask & (1 << INV_SENSOR_ACCEL) && event->sensor_mask & (1 << INV_SENSOR_GYRO) || motion_raw_data_enabled)
|
||||
{
|
||||
motion_raw_data_enabled = false;
|
||||
|
||||
if (info4 == true)
|
||||
{
|
||||
info_imu[0] = (uint16_t)accel[0];
|
||||
info_imu[1] = (uint16_t)accel[1];
|
||||
info_imu[2] = (uint16_t) accel[2];
|
||||
info_imu[3] = (uint16_t)gyro[0];
|
||||
info_imu[4] = (uint16_t) gyro[1];
|
||||
info_imu[5] = (uint16_t)gyro[2];
|
||||
go_pdread = true;
|
||||
}
|
||||
|
||||
else if(cmd_type_t == CMD_UART) {
|
||||
printf("Tp%d,%d,%d,%d,%d,%d\r\n\r\n", accel[0], accel[1], accel[2], gyro[0], gyro[1], gyro[2]);
|
||||
} else if(cmd_type_t == CMD_BLE) {
|
||||
//sprintf(ble_tx_buffer, "Tp%d,%d,%d,%d,%d,%d\r\n\r\n", accel[0], accel[1], accel[2], gyro[0], gyro[1], gyro[2]);
|
||||
ssp_data[0] = (uint16_t)accel[0];
|
||||
ssp_data[1] = (uint16_t)accel[1];
|
||||
ssp_data[2] = (uint16_t)accel[2];
|
||||
ssp_data[3] = (uint16_t)gyro[0];
|
||||
ssp_data[4] = (uint16_t)gyro[1];
|
||||
ssp_data[5] = (uint16_t)gyro[2];
|
||||
format_data(imu_bin_buffer, "rsp:", ssp_data,12);
|
||||
printf("Tp%d,%d,%d,%d,%d,%d\r\n\r\n", accel[0], accel[1], accel[2], gyro[0], gyro[1], gyro[2]);
|
||||
binary_tx_handler(imu_bin_buffer,8);
|
||||
if(custom_add_data==true)
|
||||
{
|
||||
custom_add_data = false;
|
||||
}
|
||||
else{
|
||||
//data_tx_handler(ble_tx_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Static functions definition
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
static void apply_mounting_matrix(const int32_t matrix[9], int32_t raw[3])
|
||||
{
|
||||
unsigned i;
|
||||
int64_t data_q30[3];
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
data_q30[i] = ((int64_t)matrix[3*i+0] * raw[0]);
|
||||
data_q30[i] += ((int64_t)matrix[3*i+1] * raw[1]);
|
||||
data_q30[i] += ((int64_t)matrix[3*i+2] * raw[2]);
|
||||
}
|
||||
raw[0] = (int32_t)(data_q30[0]>>30);
|
||||
raw[1] = (int32_t)(data_q30[1]>>30);
|
||||
raw[2] = (int32_t)(data_q30[2]>>30);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*******************************************************************************
|
||||
* @file app_raw.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _APP_RAW_H_
|
||||
#define _APP_RAW_H_
|
||||
#include "sdk_config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include "inv_imu_transport.h"
|
||||
#include "inv_imu_defs.h"
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
|
||||
/*** Example configuration ***/
|
||||
|
||||
/*
|
||||
* Select communication link between SmartMotion and IMU
|
||||
*/
|
||||
#define SERIF_TYPE UI_I2C
|
||||
|
||||
/*
|
||||
* Set power mode flag
|
||||
* Set this flag to run example in low-noise mode.
|
||||
* Reset this flag to run example in low-power mode.
|
||||
* Note: low-noise mode is not available with sensor data frequencies less than 12.5Hz.
|
||||
*/
|
||||
#define USE_LOW_NOISE_MODE 1
|
||||
|
||||
/*
|
||||
* Select Fifo resolution Mode (default is low resolution mode)
|
||||
* Low resolution mode: 16 bits data format
|
||||
* High resolution mode: 20 bits data format
|
||||
* Warning: Enabling High Res mode will force FSR to 16g and 2000dps
|
||||
*/
|
||||
#define USE_HIGH_RES_MODE 0
|
||||
|
||||
/*
|
||||
* Select to use FIFO or to read data from registers
|
||||
*/
|
||||
#define USE_FIFO 0
|
||||
|
||||
|
||||
/**
|
||||
* \brief This function is in charge of reseting and initializing IMU device. It should
|
||||
* be successfully executed before any access to IMU device.
|
||||
*
|
||||
* \return 0 on success, negative value on error.
|
||||
*/
|
||||
int setup_imu_device(struct inv_imu_serif *icm_serif);
|
||||
|
||||
/**
|
||||
* \brief This function configures the device in order to output gyro and accelerometer.
|
||||
* \return 0 on success, negative value on error.
|
||||
*/
|
||||
int configure_imu_device(void);
|
||||
|
||||
/**
|
||||
* \brief This function extracts data from the IMU FIFO.
|
||||
* \return 0 on success, negative value on error.
|
||||
*/
|
||||
int get_imu_data(void);
|
||||
|
||||
/**
|
||||
* \brief This function is the custom handling packet function.
|
||||
* \param[in] event structure containing sensor data from one packet
|
||||
*/
|
||||
void imu_callback(inv_imu_sensor_event_t *event);
|
||||
|
||||
|
||||
#endif /* !_APP_RAW_H_ */
|
||||
@@ -0,0 +1,189 @@
|
||||
/*******************************************************************************
|
||||
* @file app_raw_main.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
#include "sdk_config.h"
|
||||
#include "app_raw.h"
|
||||
#include "app_raw_main.h"
|
||||
#include "RingBuffer.h"
|
||||
#include "inv_imu_driver.h"
|
||||
|
||||
#include "system_interface.h"
|
||||
|
||||
/* std */
|
||||
#include <stdio.h>
|
||||
#include "nrf.h"
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "nrf_delay.h"
|
||||
|
||||
#include "app_util_platform.h"
|
||||
#include "meas_pd_48.h"
|
||||
#include <cmd_parse.h>
|
||||
#include "i2c_manager.h"
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Global variables
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Static variables
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Flag set from IMU device irq handler */
|
||||
static volatile int irq_from_device;
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Forward declaration
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
static int setup_mcu(struct inv_imu_serif *icm_serif);
|
||||
|
||||
/*!
|
||||
* @brief Sensor general interrupt handler, calls specific handlers.
|
||||
*
|
||||
* This function is called when an external interrupt is triggered by the sensor,
|
||||
* checks interrupt registers of InvenSense Sensor to determine the source and type of interrupt
|
||||
* and calls the specific interrupt handler accordingly.
|
||||
*
|
||||
* @param[in] NULL
|
||||
*
|
||||
* @param[out] NULL
|
||||
*
|
||||
* @return NULL
|
||||
*
|
||||
*/
|
||||
static void inv_gpio_sensor_interrupt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
|
||||
{
|
||||
irq_from_device = 1;
|
||||
}
|
||||
|
||||
|
||||
void inv_gpio_sensor_irq_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
/* Initialize int pin */
|
||||
if (!nrfx_gpiote_is_init())
|
||||
{
|
||||
err_code = nrfx_gpiote_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
|
||||
in_config.pull = NRF_GPIO_PIN_PULLUP;
|
||||
|
||||
err_code = nrfx_gpiote_in_init(ICM42670_INT1_PIN, &in_config, inv_gpio_sensor_interrupt_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_gpiote_in_event_enable(ICM42670_INT1_PIN, true);
|
||||
}
|
||||
|
||||
|
||||
void inv_gpio_sensor_irq_uninit(void)
|
||||
{
|
||||
|
||||
nrfx_gpiote_in_event_disable(ICM42670_INT1_PIN);
|
||||
|
||||
nrfx_gpiote_in_uninit(ICM42670_INT1_PIN);
|
||||
|
||||
/* Initialize int pin */
|
||||
if (nrfx_gpiote_is_init())
|
||||
{
|
||||
nrfx_gpiote_uninit();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Main
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
int icm42670_init(void)
|
||||
{
|
||||
int rc = 0;
|
||||
struct inv_imu_serif icm_serif;
|
||||
|
||||
rc |= setup_mcu(&icm_serif);
|
||||
rc |= setup_imu_device(&icm_serif);
|
||||
rc |= configure_imu_device();
|
||||
|
||||
if(rc != 0){
|
||||
printf("!!!error during initialization\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
inv_gpio_sensor_irq_init();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
void icm42670_main(void)
|
||||
{
|
||||
int rc = 0;
|
||||
hw_i2c_init_once();
|
||||
/* Poll device for data */
|
||||
|
||||
if (irq_from_device) {
|
||||
rc = get_imu_data();
|
||||
|
||||
if(rc < 0) {
|
||||
printf("error while getting data\r\n");
|
||||
}
|
||||
|
||||
irq_from_device = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Functions definitions
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* This function initializes MCU on which this software is running.
|
||||
* It configures:
|
||||
* - a UART link used to print some messages
|
||||
* - interrupt priority group and GPIO so that MCU can receive interrupts from IMU
|
||||
* - a microsecond timer requested by IMU driver to compute some delay
|
||||
* - a microsecond timer used to get some timestamps
|
||||
* - a serial link to communicate from MCU to IMU
|
||||
*/
|
||||
static int setup_mcu(struct inv_imu_serif *icm_serif)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
/* Initialize serial interface between MCU and IMU */
|
||||
icm_serif->context = 0; /* no need */
|
||||
icm_serif->read_reg = inv_io_hal_read_reg;
|
||||
icm_serif->write_reg = inv_io_hal_write_reg;
|
||||
icm_serif->max_read = 1024*32; /* maximum number of bytes allowed per serial read */
|
||||
icm_serif->max_write = 1024*32; /* maximum number of bytes allowed per serial write */
|
||||
icm_serif->serif_type = SERIF_TYPE;
|
||||
rc |= inv_io_hal_init(icm_serif);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------
|
||||
* Extern functions definition
|
||||
* -------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Sleep implementation */
|
||||
void inv_imu_sleep_us(uint32_t us)
|
||||
{
|
||||
nrf_delay_us(us);
|
||||
}
|
||||
|
||||
|
||||
/* Get time implementation */
|
||||
uint64_t inv_imu_get_time_us(void)
|
||||
{
|
||||
return NRF_RTC1->COUNTER;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* @file app_raw_main.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _APP_RAW_MAIN_H_
|
||||
#define _APP_RAW_MAIN_H_
|
||||
#include "sdk_config.h"
|
||||
|
||||
int icm42670_init(void);
|
||||
void icm42670_main(void);
|
||||
int icm42670_uninit(void);
|
||||
|
||||
#endif /* !_APP_RAW_MAIN_H_ */
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
/*******************************************************************************
|
||||
* @file system_interface.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
/* board driver */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "nrfx_twi.h"
|
||||
|
||||
#include "system_interface.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "meas_pd_48.h"
|
||||
|
||||
/* I2C number and slave address for INV device */
|
||||
#define ICM_I2C_ADDR 0x68
|
||||
#define INV_MAX_SERIAL_WRITE 16
|
||||
|
||||
/* TWI instance. */
|
||||
const nrfx_twi_t m_twi_icm42670 = NRFX_TWI_INSTANCE(ICM42670_I2C_INSTANCE);
|
||||
|
||||
void inv_i2c_master_uninitialize(void){
|
||||
nrfx_twi_disable(&m_twi_icm42670);
|
||||
nrfx_twi_uninit(&m_twi_icm42670);
|
||||
}
|
||||
|
||||
static void inv_i2c_master_initialize(void){
|
||||
ret_code_t err_code;
|
||||
|
||||
const nrfx_twi_config_t twi_icm42670_config = {
|
||||
.scl = ICM42670_I2C_SCL_PIN,
|
||||
.sda = ICM42670_I2C_SDA_PIN,
|
||||
.frequency = NRF_TWI_FREQ_100K,
|
||||
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
|
||||
};
|
||||
|
||||
err_code = nrfx_twi_init(&m_twi_icm42670, &twi_icm42670_config, NULL, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_twi_enable(&m_twi_icm42670);
|
||||
}
|
||||
|
||||
|
||||
uint32_t icm42670_twi_tx( uint8_t device_id,
|
||||
uint8_t const * p_data,
|
||||
uint8_t length,
|
||||
bool no_stop)
|
||||
{
|
||||
ret_code_t ret;
|
||||
ret = nrfx_twi_tx(&m_twi_icm42670, device_id, p_data, length, no_stop);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t icm42670_twi_rx( uint8_t device_id,
|
||||
uint8_t * p_data,
|
||||
uint8_t length)
|
||||
{
|
||||
ret_code_t ret;
|
||||
ret = nrfx_twi_rx(&m_twi_icm42670, device_id, p_data, length);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static unsigned long inv_i2c_master_read_register(unsigned char Address, unsigned char RegisterAddr, unsigned short RegisterLen, unsigned char *RegisterValue){
|
||||
//ret_code_t ret;
|
||||
uint32_t ret;
|
||||
uint8_t addr8 = (uint8_t)RegisterAddr;
|
||||
|
||||
ret = icm42670_twi_tx(Address, &addr8, 1, true);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
ret = icm42670_twi_tx(Address, &addr8, 1, true);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
printf("ERR! i2c read-1\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
ret = icm42670_twi_rx(Address, RegisterValue, RegisterLen);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
ret = icm42670_twi_rx(Address, RegisterValue, RegisterLen);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
printf("ERR! i2c read-2\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static unsigned long inv_i2c_master_write_register(unsigned char Address, unsigned char RegisterAddr, unsigned short RegisterLen, const unsigned char *RegisterValue){
|
||||
uint32_t ret;
|
||||
uint8_t buffer[1 + INV_MAX_SERIAL_WRITE]; /* Addr + data */
|
||||
|
||||
buffer[0] = (uint8_t)RegisterAddr;
|
||||
memcpy(buffer+1, RegisterValue, RegisterLen);
|
||||
ret = icm42670_twi_tx(Address, buffer, RegisterLen+1, false);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
ret = icm42670_twi_tx(Address, buffer, RegisterLen+1, false);
|
||||
if(ret != NRF_SUCCESS) {
|
||||
printf("ERR! i2c write\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int inv_io_hal_init(struct inv_imu_serif *serif)
|
||||
{
|
||||
|
||||
switch (serif->serif_type) {
|
||||
case UI_SPI4:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case UI_I2C:
|
||||
inv_i2c_master_initialize();
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int inv_io_hal_read_reg(struct inv_imu_serif *serif, uint8_t reg, uint8_t * rbuffer, uint32_t rlen)
|
||||
{
|
||||
switch (serif->serif_type) {
|
||||
case UI_SPI4:
|
||||
return 0;
|
||||
|
||||
case UI_I2C:
|
||||
return inv_i2c_master_read_register(ICM_I2C_ADDR, reg, rlen, rbuffer);
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int inv_io_hal_write_reg(struct inv_imu_serif *serif, uint8_t reg, const uint8_t * wbuffer, uint32_t wlen)
|
||||
{
|
||||
switch (serif->serif_type) {
|
||||
case UI_SPI4:
|
||||
return 0;
|
||||
|
||||
case UI_I2C:
|
||||
return inv_i2c_master_write_register(ICM_I2C_ADDR, reg, wlen, wbuffer);
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
uint8_t cat_read(uint8_t device_id, uint8_t address, uint8_t *data)
|
||||
{
|
||||
|
||||
uint8_t read_data = 0;
|
||||
char adata[8];
|
||||
ret_code_t err_code;
|
||||
//address = 1|(address<<1);
|
||||
address = (address & 0xFF);
|
||||
err_code = nrfx_twi_tx(&m_twi_icm42670, device_id, &address, 1, true);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
// Handle error
|
||||
// return;
|
||||
}
|
||||
|
||||
err_code = nrfx_twi_rx(&m_twi_icm42670, device_id, data, 8);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
// Handle error
|
||||
return 0;
|
||||
}
|
||||
read_data = data[0];
|
||||
memcpy(adata,data,8);
|
||||
printf("Data %s . \r\n", adata);
|
||||
return read_data;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void cat_write(uint8_t device_id, uint8_t address, uint8_t *data){
|
||||
|
||||
uint8_t buffer[7]={0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
|
||||
address = (address & 0xFF);
|
||||
|
||||
buffer[0] = (address);
|
||||
//buffer[1] =(data & 0xFF);
|
||||
memcpy(buffer+1,data,6);
|
||||
ret_code_t err_code;
|
||||
//err_code = nrf_drv_twi_tx(&m_twi_ir, device_id, 0x00, 1, false);
|
||||
err_code = nrfx_twi_tx(&m_twi_icm42670, device_id, buffer, 2, false);
|
||||
// err_code = nrf_drv_twi_tx(&m_twi_ir, device_id, buffer, 2, false);
|
||||
// nrfx_twi_rx(&m_twi_icm42670, device_id, p_data, length);
|
||||
// nrfx_twi_tx(&m_twi_icm42670, device_id, p_data, length, no_stop);
|
||||
printf("Data %x %x %x %x. \r\n", buffer[0], buffer[1], buffer[2], buffer[3]);
|
||||
|
||||
//err_code = nrf_drv_twi_tx(&m_twi_ir, device_id, buffer, 6, false);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
|
||||
printf("TWI Error.");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*******************************************************************************
|
||||
* @file system_interface.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _SYSTEM_INTERFACE_H_
|
||||
#define _SYSTEM_INTERFACE_H_
|
||||
|
||||
#include "inv_imu_transport.h"
|
||||
#include <stdbool.h>
|
||||
/* TODO: Move that somewhere else */
|
||||
#ifndef TO_MASK
|
||||
#define TO_MASK(a) (1U << (unsigned)(a))
|
||||
#endif
|
||||
|
||||
|
||||
#define ICM42670_I2C_INSTANCE 0 /**< I2C instance index. */
|
||||
#define ICM42670_I2C_SDA_PIN NRF_GPIO_PIN_MAP(1,15)
|
||||
#define ICM42670_I2C_SCL_PIN NRF_GPIO_PIN_MAP(1,14)
|
||||
#define ICM42670_INT1_PIN NRF_GPIO_PIN_MAP(1,13)
|
||||
#define ICM42670_INT2_PIN NRF_GPIO_PIN_MAP(0,26)
|
||||
uint32_t icm42670_twi_tx( uint8_t device_id,
|
||||
uint8_t const * p_data,
|
||||
uint8_t length,
|
||||
bool no_stop);
|
||||
uint32_t icm42670_twi_rx( uint8_t device_id,
|
||||
uint8_t * p_data,
|
||||
uint8_t length);
|
||||
uint8_t cat_read (uint8_t device_id, uint8_t address, uint8_t *data);
|
||||
void cat_write (uint8_t device_id, uint8_t address, uint8_t *data);
|
||||
void inv_i2c_master_uninitialize(void);
|
||||
int inv_io_hal_init(struct inv_imu_serif *serif);
|
||||
int inv_io_hal_read_reg(struct inv_imu_serif *serif, uint8_t reg, uint8_t * rbuffer, uint32_t rlen);
|
||||
int inv_io_hal_write_reg(struct inv_imu_serif *serif, uint8_t reg, const uint8_t * wbuffer, uint32_t wlen);
|
||||
|
||||
#endif /* !_SYSTEM_INTERFACE_H_ */
|
||||
|
||||
168
project/ble_peripheral/ble_app_bladder_patch/ir_i2c.c
Normal file
168
project/ble_peripheral/ble_app_bladder_patch/ir_i2c.c
Normal file
@@ -0,0 +1,168 @@
|
||||
/*******************************************************************************
|
||||
* @file ir_i2c.c
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
/* board driver */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "nrfx_twi.h"
|
||||
#include "nrf_drv_twi.h"
|
||||
|
||||
#include "nrf_delay.h"
|
||||
#include "ir_i2c.h"
|
||||
#include "debug_print.h"
|
||||
|
||||
/* I2C number and slave address for DS39305272 */
|
||||
#define LED_1_I2C_ADDR 0x50
|
||||
#define AD5272_MAX_SERIAL_WRITE 16
|
||||
|
||||
int16_t read_from_DS3930 = 0;
|
||||
uint16_t data_160_to_write = 0;
|
||||
static volatile bool m_xfer_done = false;
|
||||
|
||||
/* TWI instance. */
|
||||
//const nrfx_twi_t m_twi_ir = NRFX_TWI_INSTANCE(IR_I2C_INSTANCE);
|
||||
const nrf_drv_twi_t m_twi_ir = NRF_DRV_TWI_INSTANCE(IR_I2C_INSTANCE);
|
||||
//void twi_handler(nrfx_twi_evt_t const * p_event, void * p_context)
|
||||
//{
|
||||
// m_xfer_done = true;
|
||||
//}
|
||||
//void ir_irq_init(void){
|
||||
// ret_code_t err_code;
|
||||
|
||||
// /* Initialize int pin */
|
||||
// if (!nrfx_gpiote_is_init())
|
||||
// {
|
||||
// err_code = nrfx_gpiote_init();
|
||||
// APP_ERROR_CHECK(err_code);
|
||||
// }
|
||||
|
||||
// nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
|
||||
// in_config.pull = NRF_GPIO_PIN_PULLDOWN;
|
||||
|
||||
// err_code = nrfx_gpiote_in_init(ADA2200_SYNCO_PIN, &in_config, NULL);
|
||||
// APP_ERROR_CHECK(err_code);
|
||||
|
||||
// nrfx_gpiote_in_event_enable(ADA2200_SYNCO_PIN, true);
|
||||
//}
|
||||
|
||||
|
||||
//void ir_irq_uninit(void){
|
||||
|
||||
// nrfx_gpiote_in_event_disable(ADA2200_SYNCO_PIN);
|
||||
// nrfx_gpiote_in_uninit(ADA2200_SYNCO_PIN);
|
||||
//}
|
||||
void ir_i2c_uninit(void){
|
||||
nrf_drv_twi_disable(&m_twi_ir);
|
||||
nrf_drv_twi_uninit(&m_twi_ir);
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
void ir_i2c_init(void){
|
||||
ret_code_t err_code;
|
||||
|
||||
const nrf_drv_twi_config_t twi_ir_config = {
|
||||
.scl = IR_I2C_SCL_PIN,
|
||||
.sda = IR_I2C_SDA_PIN,
|
||||
.frequency = NRF_DRV_TWI_FREQ_100K,
|
||||
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
|
||||
.clear_bus_init = false
|
||||
};
|
||||
|
||||
err_code = nrf_drv_twi_init(&m_twi_ir, &twi_ir_config, NULL, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
DBG_PRINTF("TWI ir_irq_init Error.");
|
||||
}
|
||||
|
||||
nrf_drv_twi_enable(&m_twi_ir);
|
||||
// ir_irq_init();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t ir_command_read(uint8_t device_id, uint8_t address, uint8_t *data)
|
||||
{
|
||||
uint8_t read_data = 0;
|
||||
char adata[8];
|
||||
ret_code_t err_code;
|
||||
//address = 1|(address<<1);
|
||||
address = (address & 0xFF);
|
||||
err_code = nrf_drv_twi_tx(&m_twi_ir, device_id, &address, 1, true);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
// Handle error
|
||||
// return;
|
||||
}
|
||||
|
||||
err_code = nrf_drv_twi_rx(&m_twi_ir, device_id, data, 8);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
// Handle error
|
||||
DBG_PRINTF("TWI read Error.");
|
||||
return 0;
|
||||
}
|
||||
read_data = data[0];
|
||||
memcpy(adata,data,8);
|
||||
// DBG_PRINTF("ir Data %x %x %x %x. \r\n", device_id, address, data[0], data[1]);
|
||||
//DBG_PRINTF("ir Data read %s . \r\n", adata);
|
||||
return read_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ir_command_write(uint8_t device_id, uint8_t address, uint8_t data)
|
||||
{
|
||||
//uint16_t data_to_write = 0;
|
||||
|
||||
uint8_t buffer[7]={0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
|
||||
address = (address & 0xFF);
|
||||
|
||||
//buffer[0] = 0x00;
|
||||
buffer[0] = (address);
|
||||
buffer[1] =(data & 0xFF);
|
||||
// buffer[2] = data1+1;
|
||||
// buffer[3] = data1+2;
|
||||
// buffer[4] = data1+3;
|
||||
// buffer[5] = data1+4;
|
||||
// buffer[6] = data1+5;
|
||||
//memcpy(&buffer[1], data, length );
|
||||
|
||||
|
||||
ret_code_t err_code;
|
||||
//err_code = nrf_drv_twi_tx(&m_twi_ir, device_id, 0x00, 1, false);
|
||||
|
||||
err_code = nrf_drv_twi_tx(&m_twi_ir, device_id, buffer, 2, false);
|
||||
|
||||
|
||||
DBG_PRINTF("ir Write Data %x %x %x %x. \r\n", device_id, buffer[0], buffer[1], buffer[2]);
|
||||
|
||||
//err_code = nrf_drv_twi_tx(&m_twi_ir, device_id, buffer, 6, false);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
|
||||
DBG_PRINTF("TWI Error.");
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
111
project/ble_peripheral/ble_app_bladder_patch/ir_i2c.h
Normal file
111
project/ble_peripheral/ble_app_bladder_patch/ir_i2c.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*******************************************************************************
|
||||
* @file ir_i2c.h
|
||||
* @date 2024-07-17
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _IR_I2C_H_
|
||||
#define _IR_I2C_H_
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
|
||||
#define IR_I2C_INSTANCE 1 /**< I2C instance index. */
|
||||
//#define IR_I2C_INSTANCE 1 /**< I2C instance index. */
|
||||
//#define IR_I2C_SDA_PIN NRF_GPIO_PIN_MAP(0,10)
|
||||
//#define IR_I2C_SCL_PIN NRF_GPIO_PIN_MAP(0,9)
|
||||
#define IR_I2C_SDA_PIN NRF_GPIO_PIN_MAP(1,15)
|
||||
#define IR_I2C_SCL_PIN NRF_GPIO_PIN_MAP(1,14)
|
||||
/**
|
||||
* COMMAND CONSTANTS
|
||||
* Commands are 16-bit writes: bits 15:14 are 0s
|
||||
* Bits 13:10 are the command value below
|
||||
* Bits 9:0 are data for the command, but not all bits are used with all commands
|
||||
*/
|
||||
|
||||
// The NOP command is included for completeness. It is a valid I2C operation.
|
||||
#define AD5272_COMMAND_NOP 0x00 // Do nothing. Why you would want to do this I don't know
|
||||
|
||||
// write the 10 or 8 data bits to the RDAC wiper register (it must be unlocked first)
|
||||
#define AD5272_RDAC_WRITE 0x01
|
||||
|
||||
#define AD5272_RDAC_READ 0x02 // read the RDAC wiper register
|
||||
|
||||
#define AD5272_50TP_WRITE 0x03 // store RDAC setting to 50-TP
|
||||
|
||||
// SW reset: refresh RDAC with last 50-TP stored value
|
||||
// If not 50-TP value, reset to 50% I think???
|
||||
// data bits are all dont cares
|
||||
#define AD5272_RDAC_REFRESH 0x04 // TODO refactor this to AD5272_SOFT_RESET
|
||||
|
||||
// read contents of 50-TP in next frame, at location in data bits 5:0,
|
||||
// see Table 16 page 22 Rev D datasheet
|
||||
// location 0x0 is reserved, 0x01 is first programmed wiper location, 0x32 is 50th programmed wiper location
|
||||
#define AD5272_50TP_WIPER_READ 0x05
|
||||
|
||||
/**
|
||||
* Read contents of last-programmed 50-TP location
|
||||
* This is the location used in SW Reset command 4 or on POR
|
||||
*/
|
||||
#define AD5272_50TP_LAST_USED 0x06
|
||||
|
||||
#define AD5272_CONTROL_WRITE 0x07 // data bits 2:0 are the control bits
|
||||
|
||||
#define AD5272_CONTROL_READ 0x08 // data bits all dont cares
|
||||
|
||||
#define AD5272_SHUTDOWN 0x09 // data bit 0 set = shutdown, cleared = normal mode
|
||||
|
||||
|
||||
/**
|
||||
* Control bits are three bits written with command 7
|
||||
*/
|
||||
// enable writing to the 50-TP memory by setting this control bit C0
|
||||
// default is cleared so 50-TP writing is disabled
|
||||
// only 50 total writes are possible!
|
||||
#define AD5272_50TP_WRITE_ENABLE 0x01
|
||||
|
||||
// enable writing to volatile RADC wiper by setting this control bit C1
|
||||
// otherwise it is frozen to the value in the 50-TP memory
|
||||
// default is cleared, can't write to the wiper
|
||||
#define AD5272_RDAC_WIPER_WRITE_ENABLE 0x02
|
||||
|
||||
// enable high precision calibration by clearing this control bit C2
|
||||
// set this bit to disable high accuracy mode (dunno why you would want to)
|
||||
// default is 0 = emabled
|
||||
#define AD5272_RDAC_CALIB_DISABLE 0x04
|
||||
|
||||
// 50TP memory has been successfully programmed if this bit is set
|
||||
#define AD5272_50TP_WRITE_SUCCESS 0x08
|
||||
|
||||
#define AD5272_NORMAL_MODE 0x01
|
||||
#define AD5272_SHUTDOWN_MODE 0x01
|
||||
#define ADA2200_SYNCO_PIN NRF_GPIO_PIN_MAP(0,17)
|
||||
void ir_i2c_uninit(void);
|
||||
void ir_i2c_init(void);
|
||||
|
||||
void ir_irq_init(void);
|
||||
void ir_irq_uninit(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t ir_command_read(uint8_t device_id, uint8_t address, uint8_t *data);
|
||||
void ir_command_write(uint8_t device_id, uint8_t address, uint8_t data);
|
||||
void ad5272_i2c_is_busy(void);
|
||||
int8_t ad5272_write_and_read_rdac (uint16_t data_16_to_write);
|
||||
int16_t ad5272_read_rdac (void);
|
||||
int8_t ad5272_write_rdac (uint16_t data_16_to_write);
|
||||
|
||||
void read_all_50tp (void);
|
||||
void ad5272_RDAC_refresh(void);
|
||||
void ad5272_shutdown_mode(void);
|
||||
void ad5272_normal_mode(void);
|
||||
|
||||
#endif /* !_ADA5272_I2C_H_ */
|
||||
|
||||
1503
project/ble_peripheral/ble_app_bladder_patch/main.c
Normal file
1503
project/ble_peripheral/ble_app_bladder_patch/main.c
Normal file
File diff suppressed because it is too large
Load Diff
70
project/ble_peripheral/ble_app_bladder_patch/main.h
Normal file
70
project/ble_peripheral/ble_app_bladder_patch/main.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* @file main.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef MAIN_H__
|
||||
#define MAIN_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include "boards.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OFF = 0,
|
||||
ON = 1
|
||||
}on_off_cont_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CMD_BLE = 0,
|
||||
CMD_UART = 1
|
||||
}which_cmd_t;
|
||||
|
||||
#if FEATURE_CHAMBER_AUTO_TEST
|
||||
typedef enum
|
||||
{
|
||||
SIMPLE_AUTO_MODE = 0,
|
||||
HALF_AUTO_MODE = 1,
|
||||
FULL_AUTO_MODE = 2,
|
||||
NONE_AUTO_MODE = 3
|
||||
}auto_meas_mode_t;
|
||||
#endif
|
||||
typedef enum
|
||||
{
|
||||
BLE_DISCONNECTED_ST = 0,
|
||||
BLE_CONNECTED_ST = 1
|
||||
}ble_status_t;
|
||||
#if FEATURE_SECURE_CONNECTION
|
||||
static void advertising_start(bool erase_bonds);
|
||||
#endif
|
||||
void sleep_mode_enter(void);
|
||||
static void t_power_off_timeout_handler(void * p_context);
|
||||
void device_power_off(void);
|
||||
static void power_control_handler(on_off_cont_t device_power_st);
|
||||
static void main_s(void * p_context);
|
||||
static void PM_s(void * p_context);
|
||||
//static void main_re(void * p_context);
|
||||
static void main_routine_handler(void * p_context);
|
||||
void received_command_process(uint8_t const *data_array, which_cmd_t cmd_t,uint8_t length);
|
||||
void data_tx_handler(char const *p_data_to_send);
|
||||
void binary_tx_handler(uint8_t const *ble_bin_buff , uint16_t length);
|
||||
void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
||||
void dr_sd_delay_ms(uint32_t ms);
|
||||
void single_format_data(uint8_t *buffer, const char *tag, const uint16_t value) ;
|
||||
void format_data(uint8_t *buffer, const char *tag, const uint16_t *data_array, size_t length);
|
||||
|
||||
void format_data_byte(uint8_t *buffer, const char *tag, const uint8_t *data_array, size_t length);
|
||||
void ascii_format_data(uint8_t *buffer, const char *tag, const char *data_ascii, size_t length);
|
||||
|
||||
extern volatile bool data_tx_in_progress;
|
||||
extern volatile bool ble_connection_st;
|
||||
extern volatile bool processing;
|
||||
#endif //MAIN_H__
|
||||
|
||||
223
project/ble_peripheral/ble_app_bladder_patch/main_timer.c
Normal file
223
project/ble_peripheral/ble_app_bladder_patch/main_timer.c
Normal file
@@ -0,0 +1,223 @@
|
||||
/*******************************************************************************
|
||||
TEST medi50 Dec 23
|
||||
******************************************************************************/
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "app_util_platform.h"
|
||||
#include "nrf_pwr_mgmt.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "app_timer.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "app_raw_main.h"
|
||||
#include "main_timer.h"
|
||||
#include "tmp235_q1.h"
|
||||
//#include "fstorage.h"
|
||||
//#include "meas_pd_voltage_custom.h"
|
||||
#include "meas_pd_imm.h"
|
||||
#include "meas_pd_voltage_full.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "power_control.h"
|
||||
#include <cmd_parse.h>
|
||||
#include "meas_pd_48.h"
|
||||
#include "debug_print.h"
|
||||
#include "i2c_manager.h" //add cj
|
||||
APP_TIMER_DEF(m_main_loop_timer_id);
|
||||
|
||||
#if FEATURE_DETAIL_VALUE_FULL
|
||||
#define MAIN_LOOP_INTERVAL 80 /* 디테일 프린트아웃이 있을경우 Full_Mode Main Prosessing 수행하는 타이머 */
|
||||
|
||||
//extern bool pd_adc_full_a_start;
|
||||
//extern bool pd_adc_full_b_start;
|
||||
//extern bool pd_adc_full_c_start;
|
||||
//extern bool pd_adc_full_d_start;
|
||||
//extern bool pd_adc_full_end;
|
||||
|
||||
extern which_cmd_t cmd_type_t;
|
||||
#else
|
||||
#define MAIN_LOOP_INTERVAL 10
|
||||
#endif
|
||||
bool go_batt= false;
|
||||
bool go_temp= false;
|
||||
bool go_pdread= false;
|
||||
bool go_device_power_off = false;
|
||||
bool go_sleep_mode_enter = false;
|
||||
bool go_NVIC_SystemReset = false;
|
||||
bool motion_raw_data_enabled = false;
|
||||
bool ble_got_new_data = false;
|
||||
bool motion_data_once = false;
|
||||
bool adc_enabled = false;
|
||||
static uint16_t cnt_adc = 0;
|
||||
void main_loop(void * p_context) /* For x ms */
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
|
||||
#if FEATURE_DETAIL_VALUE_FULL
|
||||
// if(pd_adc_full_a_start == true) { // A mode
|
||||
// main_timer_stop();
|
||||
// printf("main_loop_A\r\n");
|
||||
// full_adc_start();
|
||||
// }else if(pd_adc_full_b_start == true) { // B mode
|
||||
// main_timer_stop();
|
||||
// printf("main_loop_B\r\n");
|
||||
// full_adc_start();
|
||||
// }else if(pd_adc_full_c_start == true) { // C mode
|
||||
// main_timer_stop();
|
||||
// printf("main_loop_C\r\n");
|
||||
// full_adc_start();
|
||||
// }else if(pd_adc_full_d_start == true) { // D mode
|
||||
// main_timer_stop();
|
||||
// printf("main_loop_D\r\n");
|
||||
// full_adc_start();
|
||||
// }else if(pd_adc_full_end == true) { // Completed
|
||||
// pd_adc_full_end = false;
|
||||
// main_timer_stop();
|
||||
// printf("main_loop_END\r\n");
|
||||
|
||||
// if(cmd_type_t == CMD_BLE) {
|
||||
// full_send_timer_start();
|
||||
// }
|
||||
// }
|
||||
#endif
|
||||
|
||||
// For Motion Data Sampling
|
||||
|
||||
if(motion_raw_data_enabled == true) {
|
||||
main_timer_stop();
|
||||
if(motion_data_once == true)
|
||||
{
|
||||
|
||||
hw_i2c_init_once();
|
||||
icm42670_main();
|
||||
}
|
||||
else{
|
||||
|
||||
if(ble_got_new_data==false){
|
||||
//for(uint16_t i=0 ; i<60 ;i++)
|
||||
//{
|
||||
DBG_PRINTF("IMU \r\n");
|
||||
|
||||
icm42670_main();
|
||||
nrf_delay_ms(10);
|
||||
motion_raw_data_enabled = true;
|
||||
main_timer_start();
|
||||
}
|
||||
// else if(ble_got_new_data==true){
|
||||
// motion_data_once = true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(go_batt == true) {
|
||||
DBG_PRINTF("IMU BATT\r\n");
|
||||
main_timer_stop();
|
||||
go_batt = false;
|
||||
// go_temp = true;
|
||||
battery_level_meas();
|
||||
// nrf_delay_ms(20);
|
||||
// m48_adc_start_init();
|
||||
// main_timer_start();
|
||||
}
|
||||
|
||||
|
||||
if(go_temp == true) {
|
||||
DBG_PRINTF("IMU Temp\r\n");
|
||||
main_timer_stop();
|
||||
// go_batt = false;
|
||||
go_temp = false;
|
||||
motion_data_once = true;
|
||||
tmp235_voltage_level_meas();
|
||||
// motion_raw_data_enabled = true;
|
||||
// main_timer_start();
|
||||
|
||||
}
|
||||
if(go_pdread == true) {
|
||||
//DBG_PRINTF("PD48 ADC=%d\r\n",cnt_adc);
|
||||
main_timer_stop();
|
||||
go_pdread = false;
|
||||
m48_adc_start_init();
|
||||
}
|
||||
if(adc_enabled == true) {
|
||||
main_timer_stop();
|
||||
DBG_PRINTF("PD48 ADC=%d\r\n",cnt_adc);
|
||||
|
||||
|
||||
if(ble_got_new_data==false){
|
||||
|
||||
if (cnt_adc<500){
|
||||
cnt_adc++;
|
||||
|
||||
}
|
||||
else if (cnt_adc == 500){
|
||||
cnt_adc = 0;
|
||||
}
|
||||
|
||||
main_timer_start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* For System Control */
|
||||
|
||||
|
||||
|
||||
if(go_device_power_off == true){
|
||||
main_timer_stop();
|
||||
|
||||
DBG_PRINTF("Off main_timer\r\n");
|
||||
device_power_off();
|
||||
}
|
||||
|
||||
if(go_sleep_mode_enter == true){
|
||||
main_timer_stop();
|
||||
|
||||
DBG_PRINTF("sleep main timer\r\n");
|
||||
|
||||
|
||||
sleep_mode_enter();
|
||||
}
|
||||
|
||||
if(go_NVIC_SystemReset == true) {
|
||||
|
||||
|
||||
|
||||
main_timer_stop();
|
||||
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void main_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_main_loop_timer_id, APP_TIMER_TICKS(MAIN_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void main_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_main_loop_timer_id));
|
||||
}
|
||||
|
||||
void main_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_main_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, main_loop));
|
||||
}
|
||||
|
||||
17
project/ble_peripheral/ble_app_bladder_patch/main_timer.h
Normal file
17
project/ble_peripheral/ble_app_bladder_patch/main_timer.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*******************************************************************************
|
||||
* @file timer_routine.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef TIMER_ROUTINE_H__
|
||||
#define TIMER_ROUTINE_H__
|
||||
|
||||
void main_timer_start(void);
|
||||
void main_timer_stop(void);
|
||||
void main_timer_init(void);
|
||||
|
||||
#endif //TIMER_ROUTINE_H__
|
||||
|
||||
114
project/ble_peripheral/ble_app_bladder_patch/mcp4725_adc.c
Normal file
114
project/ble_peripheral/ble_app_bladder_patch/mcp4725_adc.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/*******************************************************************************
|
||||
* @file mcp4725_adc.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "ble_nus.h"
|
||||
#include "mcp4725_adc.h"
|
||||
#include "main.h"
|
||||
#include "debug_print.h"
|
||||
#define MCP4725_REF_VOLTAGE_IN_MILLIVOLTS 600.0f /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
|
||||
#define MCP4725_PRE_SCALING_COMPENSATION 6.0f /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
|
||||
#define MCP4725_ADC_RES_10BITS 1024.0f /**< Maximum digital value for 10-bit ADC conversion. */
|
||||
|
||||
/**@brief Macro to convert the result of ADC conversion in millivolts.
|
||||
*
|
||||
* @param[in] ADC_VALUE ADC result.
|
||||
*
|
||||
* @retval Result converted to millivolts.
|
||||
*/
|
||||
#define MCP4725_VOUT_IN_MILLI_VOLTS(ADC_VALUE)\
|
||||
((((ADC_VALUE) * MCP4725_REF_VOLTAGE_IN_MILLIVOLTS) / MCP4725_ADC_RES_10BITS) * MCP4725_PRE_SCALING_COMPENSATION)
|
||||
|
||||
#define ADC_SAMPLES_IN_BUFFER 1
|
||||
|
||||
static nrf_saadc_value_t mcp4725_adc_buf[2][ADC_SAMPLES_IN_BUFFER];
|
||||
float mcp4725_voltage_in_milli_volts = 0;
|
||||
|
||||
//extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
|
||||
extern which_cmd_t cmd_type_t;
|
||||
extern uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] ;
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
void mcp4725_voltage_handler(nrf_drv_saadc_evt_t const * p_event) /* ADC_GAIN reading */
|
||||
{
|
||||
float Vref = 3.3f; /* It same as Vdd */
|
||||
float dac_value = 0.0f;
|
||||
uint16_t dac_value_16=0;
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
nrf_saadc_value_t adc_result;
|
||||
|
||||
nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, ADC_SAMPLES_IN_BUFFER);
|
||||
adc_result = p_event->data.done.p_buffer[0];
|
||||
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
|
||||
mcp4725_voltage_in_milli_volts = MCP4725_VOUT_IN_MILLI_VOLTS(adc_result);
|
||||
#if FEATURE_DETAIL_VALUE_AGC
|
||||
DBG_PRINTF("AGC read Vol: %f(mV)\r\n", mcp4725_voltage_in_milli_volts);
|
||||
#endif
|
||||
/* For MCP4725, Dn = (Vout/Vref) x 4096, Vref = Vdd */
|
||||
dac_value = (((mcp4725_voltage_in_milli_volts/Vref) * 4096.0f)/1000.0f); /* Unit is Volt */
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
DBG_PRINTF("Te%d\r\n\r\n",(uint16_t)(dac_value + 0.5f));
|
||||
} else if(cmd_type_t == CMD_BLE) {
|
||||
dac_value_16 = (uint16_t)(dac_value + 0.5f);
|
||||
single_format_data(ble_bin_buffer, "rse:", dac_value_16);
|
||||
|
||||
|
||||
|
||||
|
||||
binary_tx_handler(ble_bin_buffer,3);
|
||||
// sprintf(ble_tx_buffer, "Te%d\r\n",(uint16_t)(dac_value + 0.5f));
|
||||
// data_tx_handler(ble_tx_buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mcp4725_adc_init(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_saadc_init(NULL, mcp4725_voltage_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_saadc_channel_config_t config =
|
||||
NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6); /* FSA5157P6X Voltage Output Measurement */
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(mcp4725_adc_buf[0], ADC_SAMPLES_IN_BUFFER);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
err_code = nrf_drv_saadc_buffer_convert(mcp4725_adc_buf[1], ADC_SAMPLES_IN_BUFFER);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_sample();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void mcp4725_voltage_level_meas(void)
|
||||
{
|
||||
mcp4725_adc_init();
|
||||
}
|
||||
|
||||
16
project/ble_peripheral/ble_app_bladder_patch/mcp4725_adc.h
Normal file
16
project/ble_peripheral/ble_app_bladder_patch/mcp4725_adc.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/*******************************************************************************
|
||||
* @file mcp4725.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MCP4725_ADC_H_
|
||||
#define _MCP4725_ADC_H_
|
||||
|
||||
void mcp4725_adc_init(void);
|
||||
void mcp4725_voltage_level_meas(void);
|
||||
|
||||
#endif /* !_MCP4725_ADC_H_ */
|
||||
|
||||
513
project/ble_peripheral/ble_app_bladder_patch/mcp4725_i2c.c
Normal file
513
project/ble_peripheral/ble_app_bladder_patch/mcp4725_i2c.c
Normal file
@@ -0,0 +1,513 @@
|
||||
/*******************************************************************************
|
||||
* @file mcp4725_i2c.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
/* board driver */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <math.h>
|
||||
#include "nrf.h"
|
||||
#include "app_error.h"
|
||||
#include "boards.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "debug_print.h"
|
||||
|
||||
/* I2C number and slave address for MCP4725 */
|
||||
#define MCP4725_I2C_ADDR_7bit 0x66
|
||||
uint8_t MCP4725_I2C_ADDR = MCP4725_I2C_ADDR_7bit << 1;
|
||||
|
||||
uint16_t _lastValue;
|
||||
uint8_t _powerDownMode;
|
||||
uint32_t _lastWriteEEPROM;
|
||||
|
||||
|
||||
void mcp4725_i2c_initialize(void)
|
||||
{
|
||||
SCL_OUT();
|
||||
SDA_OUT();
|
||||
SCL_H();
|
||||
SDA_H();
|
||||
}
|
||||
|
||||
|
||||
static uint8_t mcp4725_i2c_write(uint8_t data)
|
||||
{
|
||||
for(uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
// MSB first
|
||||
if(data & 0x80) SDA_H();
|
||||
else SDA_L();
|
||||
i2c_clock();
|
||||
data = data << 1;
|
||||
}
|
||||
|
||||
// read ACK
|
||||
SDA_H(); // leave SDA HI
|
||||
SDA_IN(); // change direction to input on SDA line
|
||||
|
||||
i2c_delay();
|
||||
SCL_H(); // clock back up
|
||||
i2c_delay();
|
||||
uint8_t ack = SDA_READ(); // get the ACK bit
|
||||
SCL_L();
|
||||
|
||||
SDA_OUT(); // change direction back to output
|
||||
|
||||
if(ack) {
|
||||
DBG_PRINTF("ACK Extra=%d,Data=%d\r\n", ack,data);
|
||||
}
|
||||
|
||||
return ack;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t mcp4725_i2c_read(bool ack)
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
SDA_H(); // leave SDA HI
|
||||
SDA_IN(); // change direction to input on SDA line
|
||||
|
||||
data = 0;
|
||||
for(uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
// MSB first
|
||||
data = data << 1;
|
||||
|
||||
SCL_H();
|
||||
do{
|
||||
}while(SCL_READ() != 0); // Wait for any SCL clock stratching
|
||||
|
||||
i2c_delay();
|
||||
if(SDA_READ()) // get the Data bit
|
||||
data |= 1;
|
||||
else
|
||||
data |= 0;
|
||||
SCL_L(); // clock LO
|
||||
i2c_delay();
|
||||
}
|
||||
|
||||
SDA_OUT(); // change direction back to output
|
||||
|
||||
// send ACK
|
||||
if(ack == ACK) SDA_L();
|
||||
else if(ack == NACK) SDA_H();
|
||||
i2c_clock();
|
||||
SDA_H(); // leave with SDA HI
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
void mcp4725_writeFastMode(const uint16_t value)
|
||||
{
|
||||
uint8_t low = value & 0xFF;
|
||||
uint8_t high = ((value >> 8) & 0x0F); // set C2,c1 == 0,0(FastMode Write) pd1,pd0 == 0,0 (Normal Mode)
|
||||
|
||||
i2c_start();
|
||||
mcp4725_i2c_write(MCP4725_I2C_ADDR|TWI_WRITE); // slave address
|
||||
|
||||
//uint8_t address = MCP4725_I2C_ADDR | TWI_WRITE;
|
||||
//DBG_PRINTF("[I2C] Write to 0x%02X\r\n", address); //oxCC
|
||||
|
||||
mcp4725_i2c_write(high); // value1 ~ 3
|
||||
mcp4725_i2c_write(low);
|
||||
i2c_stop();
|
||||
}
|
||||
|
||||
|
||||
void mcp4725_generalCall(const uint8_t gc)
|
||||
{
|
||||
i2c_start();
|
||||
mcp4725_i2c_write(0x00); // First Byte 0x00
|
||||
mcp4725_i2c_write(gc); // Second Byte, General Call Reset = 0x06, General Call Wake-Up = 0x09
|
||||
i2c_stop();
|
||||
}
|
||||
|
||||
|
||||
void mcp4725_init(void)
|
||||
{
|
||||
mcp4725_i2c_initialize();
|
||||
}
|
||||
|
||||
// DAC value is reset to EEPROM value
|
||||
// need to reflect this in cached value
|
||||
void mcp4725_powerOnReset(void)
|
||||
{
|
||||
mcp4725_generalCall(MCP4725_GC_RESET);
|
||||
}
|
||||
|
||||
|
||||
// _powerDownMode DAC resets to 0 -- PDM EEPROM stays same !!!
|
||||
// need to reflect this in cached value
|
||||
void mcp4725_powerOnWakeUp(void)
|
||||
{
|
||||
mcp4725_generalCall(MCP4725_GC_WAKEUP);
|
||||
}
|
||||
|
||||
/* 현재 DAC값 읽어서 그 값에 Power Down 넣고 Write */
|
||||
void mcp4725_PowerDownMode(void)
|
||||
{
|
||||
uint8_t low = 0x00; //read_value & 0xFF;
|
||||
uint8_t high = 0x00; //((read_value >> 8) & 0x0F);
|
||||
high = high | (MCP4725_PDMODE_1K << 4); // set C2,c1 == 0,0(FastMode Write) pd1,pd0 == 0,1 (Power Down Mode, 1Kohm to GND)
|
||||
|
||||
i2c_start();
|
||||
mcp4725_i2c_write(MCP4725_I2C_ADDR|TWI_WRITE); // slave address
|
||||
mcp4725_i2c_write(high); // value
|
||||
mcp4725_i2c_write(low);
|
||||
i2c_stop();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint16_t mcp4725_readDAC(void)
|
||||
{
|
||||
while(!mcp4725_ready());
|
||||
uint8_t buffer[3];
|
||||
mcp4725_readRegister(buffer, 3);
|
||||
uint16_t value = buffer[1];
|
||||
value = value << 4;
|
||||
value = value + (buffer[2] >> 4);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// ready checks if the last write to EEPROM has been written.
|
||||
// until ready all writes to the MCP4725 are ignored!
|
||||
bool mcp4725_ready(void)
|
||||
{
|
||||
uint8_t buffer[1];
|
||||
mcp4725_readRegister(buffer, 1);
|
||||
return ((buffer[0] & 0x80) > 0);
|
||||
}
|
||||
|
||||
|
||||
void mcp4725_writeRegisterMode(const uint16_t value, uint8_t reg)
|
||||
{
|
||||
uint8_t high = (value / 16);
|
||||
uint8_t low = (value & 0x0F) << 4;
|
||||
reg = reg | (_powerDownMode << 1);
|
||||
|
||||
i2c_start();
|
||||
mcp4725_i2c_write(MCP4725_I2C_ADDR|TWI_WRITE); // slave address
|
||||
mcp4725_i2c_write(reg); // configuration
|
||||
mcp4725_i2c_write(high); // value1 ~ 3
|
||||
mcp4725_i2c_write(low);
|
||||
i2c_stop();
|
||||
}
|
||||
|
||||
|
||||
void mcp4725_readRegister(uint8_t* buffer, const uint8_t length)
|
||||
{
|
||||
i2c_start();
|
||||
mcp4725_i2c_write(MCP4725_I2C_ADDR|TWI_READ); // slave address with READ
|
||||
switch(length) {
|
||||
case 1:
|
||||
buffer[0] = mcp4725_i2c_read(NACK); // NACK, SDA = 1;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
buffer[0] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[1] = mcp4725_i2c_read(NACK); // NACK, SDA = 1;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
buffer[0] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[1] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[2] = mcp4725_i2c_read(NACK); // NACK, SDA = 1;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
buffer[0] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[1] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[2] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[3] = mcp4725_i2c_read(NACK); // NACK, SDA = 1;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
buffer[0] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[1] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[2] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[3] = mcp4725_i2c_read(ACK); // ACK, SDA = 0;
|
||||
buffer[4] = mcp4725_i2c_read(NACK); // NACK, SDA = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ERR!! mcp4725_i2c_readregister\r\n");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
i2c_stop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void mcp4725_setValue(const uint16_t value)
|
||||
{
|
||||
if (value == _lastValue) return;
|
||||
if (value > MCP4725_MAXVALUE) return;
|
||||
mcp4725_writeFastMode(value);
|
||||
_lastValue = value;
|
||||
}
|
||||
|
||||
|
||||
uint16_t mcp4725_getValue(void)
|
||||
{
|
||||
return _lastValue;
|
||||
}
|
||||
|
||||
|
||||
void mcp4725_setPercentage(float percentage)
|
||||
{
|
||||
if ((percentage > 100) || (percentage < 0))
|
||||
DBG_PRINTF("ERR!!! mcp4725 percentage error\r\n");
|
||||
mcp4725_setValue(round(percentage * (0.01 * MCP4725_MAXVALUE)));
|
||||
}
|
||||
|
||||
|
||||
// unfortunately it is not possible to write a different value
|
||||
// to the DAC and EEPROM simultaneously or write EEPROM only.
|
||||
void mcp4725_writeDAC(const uint16_t value, const bool EEPROM)
|
||||
{
|
||||
if (value > MCP4725_MAXVALUE)
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("ERR!!! mcp4725 writeDAC error\r\n");
|
||||
#endif
|
||||
while(!mcp4725_ready());
|
||||
mcp4725_writeRegisterMode(value, EEPROM ? MCP4725_DACEEPROM : MCP4725_DAC);
|
||||
_lastValue = value;
|
||||
}
|
||||
|
||||
|
||||
uint16_t mcp4725_readEEPROM(void)
|
||||
{
|
||||
while(!mcp4725_ready());
|
||||
uint8_t buffer[5];
|
||||
mcp4725_readRegister(buffer, 5);
|
||||
uint16_t value = buffer[3] & 0x0F;
|
||||
value = value << 8;
|
||||
value = value + buffer[4];
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// depending on bool EEPROM the value of PDM is written to
|
||||
// (false) DAC or
|
||||
// (true) DAC & EEPROM,
|
||||
void mcp4725_writePowerDownMode(const uint8_t PDM, const bool EEPROM)
|
||||
{
|
||||
_powerDownMode = (PDM & 0x03); // mask PDM bits only (written later low level)
|
||||
|
||||
_lastValue = mcp4725_readDAC();
|
||||
_powerDownMode = mcp4725_readPowerDownModeDAC();
|
||||
mcp4725_writeDAC(_lastValue, EEPROM);
|
||||
}
|
||||
|
||||
|
||||
uint8_t mcp4725_readPowerDownModeEEPROM(void)
|
||||
{
|
||||
while(!mcp4725_ready());
|
||||
uint8_t buffer[4];
|
||||
mcp4725_readRegister(buffer, 4);
|
||||
uint8_t value = (buffer[3] >> 5) & 0x03;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
uint8_t mcp4725_readPowerDownModeDAC(void)
|
||||
{
|
||||
while(!mcp4725_ready()); // TODO needed?
|
||||
uint8_t buffer[1];
|
||||
mcp4725_readRegister(buffer, 1);
|
||||
uint8_t value = (buffer[0] >> 1) & 0x03;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void ds_i2c_start(void) {
|
||||
SDA_H();//nrf_gpio_pin_set(I2C_SDA_PIN);
|
||||
SCL_H();//nrf_gpio_pin_set(I2C_SCL_PIN);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
SDA_L();//nrf_gpio_pin_clear(I2C_SDA_PIN);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
SCL_L();//nrf_gpio_pin_clear(I2C_SCL_PIN);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
}
|
||||
|
||||
void ds_i2c_stop(void) {
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
SDA_L();//nrf_gpio_pin_clear(I2C_SDA_PIN);
|
||||
SCL_H();// nrf_gpio_pin_set(I2C_SCL_PIN);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
SDA_H();//nrf_gpio_pin_set(I2C_SDA_PIN);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void i2c_write_bit(uint8_t bit) {
|
||||
if (bit) {
|
||||
SDA_H();
|
||||
} else {
|
||||
SDA_L();
|
||||
}
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
SCL_H(); //nrf_gpio_pin_set(SCL_PIN);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
SCL_L();//nrf_gpio_pin_clear(SCL_PIN);
|
||||
}
|
||||
|
||||
uint8_t i2c_read_bit(void) {
|
||||
uint8_t bit;
|
||||
SDA_IN();//nrf_gpio_cfg_input(SDA_PIN, NRF_GPIO_PIN_NOPULL);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
SCL_H(); ////nrf_gpio_pin_set(SCL_PIN);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
bit = SDA_READ();//nrf_gpio_pin_read(SDA_PIN);
|
||||
SCL_L(); //nrf_gpio_pin_clear(SCL_PIN);
|
||||
SDA_OUT();//nrf_gpio_cfg_output(SDA_PIN);
|
||||
return bit;
|
||||
}
|
||||
uint8_t i2c_write_byte(uint8_t byte) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
i2c_write_bit(byte & 0x80);
|
||||
byte <<= 1;
|
||||
}
|
||||
return i2c_read_bit(); // Read ACK/NACK
|
||||
}
|
||||
|
||||
uint8_t i2c_read_byte(uint8_t ack) {
|
||||
uint8_t byte = 0;
|
||||
SDA_IN();//nrf_gpio_cfg_input(SDA_PIN, NRF_GPIO_PIN_NOPULL);
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
byte <<= 1;
|
||||
byte |= i2c_read_bit();
|
||||
}
|
||||
SDA_OUT();//nrf_gpio_cfg_output(SDA_PIN);
|
||||
i2c_write_bit(!ack); // Send ACK/NACK
|
||||
return byte;
|
||||
}
|
||||
void i2c_repeated_start(void) {
|
||||
SDA_H();//nrf_gpio_pin_set(SDA_PIN);
|
||||
SCL_H();//nrf_gpio_pin_set(SCL_PIN);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
SDA_L();////nrf_gpio_pin_clear(SDA_PIN);
|
||||
i2c_delay();//nrf_delay_us(I2C_DELAY_US);
|
||||
SCL_L();//nrf_gpio_pin_clear(SCL_PIN);
|
||||
}
|
||||
|
||||
// i2c_start();
|
||||
// i2c_write_byte(I2C_ADDRESS << 1); // Write address
|
||||
// i2c_write_byte(0x00); // Register address
|
||||
// i2c_write_byte(0xFF); // Data
|
||||
// i2c_stop();
|
||||
|
||||
// // Read example
|
||||
// i2c_start();
|
||||
// i2c_write_byte((I2C_ADDRESS << 1) | 1); // Read address
|
||||
// uint8_t data = i2c_read_byte(0); // Read data with NACK
|
||||
// i2c_stop();
|
||||
|
||||
|
||||
void DS3930_write(uint8_t id, uint8_t addr, uint8_t wdata)
|
||||
{
|
||||
//i2c_start();
|
||||
// ds_i2c_stop();
|
||||
ds_i2c_start();
|
||||
i2c_write_byte(id << 1); // Write address
|
||||
i2c_write_byte(addr); // Register address
|
||||
i2c_write_byte(wdata); // Data
|
||||
|
||||
// mcp4725_i2c_write(id << 1);
|
||||
// mcp4725_i2c_write(addr);
|
||||
// mcp4725_i2c_write(wdata);
|
||||
//
|
||||
// }
|
||||
//i2c_delay();
|
||||
//i2c_stop();
|
||||
ds_i2c_stop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t DS3930_read(uint8_t id, uint8_t addr, uint8_t* rdata)
|
||||
{
|
||||
ds_i2c_start();
|
||||
i2c_write_byte(id << 1); // Write address
|
||||
i2c_write_byte(addr); // Register address
|
||||
i2c_repeated_start();
|
||||
i2c_write_byte((id << 1) | 1); // Read address
|
||||
uint8_t data = i2c_read_byte(0); // Read data with NACK
|
||||
ds_i2c_stop();
|
||||
rdata[0] = data;
|
||||
DBG_PRINTF("Data 0x%x . \r\n", data);
|
||||
//i2c_stop();
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//void CAT24_write(uint8_t id, uint8_t addr, uint8_t* wdata)
|
||||
//{
|
||||
////i2c_start();
|
||||
//// ds_i2c_stop();
|
||||
// ds_i2c_start();
|
||||
// i2c_write_byte(id << 1); // Write address
|
||||
// i2c_write_byte(addr); // Register address
|
||||
// i2c_write_byte(wdata); // Data
|
||||
//
|
||||
//// mcp4725_i2c_write(id << 1);
|
||||
//// mcp4725_i2c_write(addr);
|
||||
//// mcp4725_i2c_write(wdata);
|
||||
////
|
||||
//// }
|
||||
////i2c_delay();
|
||||
////i2c_stop();
|
||||
// ds_i2c_stop();
|
||||
//}
|
||||
|
||||
|
||||
//uint8_t CAT24_read(uint8_t id, uint8_t addr, uint8_t* rdata,uint8_t length)
|
||||
//{
|
||||
// ds_i2c_start();
|
||||
// i2c_write_byte(id << 1); // Write address
|
||||
// i2c_write_byte(addr); // Register address
|
||||
// i2c_repeated_start();
|
||||
// i2c_write_byte((id << 1) | 1); // Read address
|
||||
// uint8_t data = i2c_read_byte(0); // Read data with NACK
|
||||
// ds_i2c_stop();
|
||||
// rdata[0] = data;
|
||||
// DBG_PRINTF("Data 0x%x . \r\n", data);
|
||||
// //i2c_stop();
|
||||
// return data;
|
||||
//}
|
||||
|
||||
92
project/ble_peripheral/ble_app_bladder_patch/mcp4725_i2c.h
Normal file
92
project/ble_peripheral/ble_app_bladder_patch/mcp4725_i2c.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*******************************************************************************
|
||||
* @file mcp4725_i2c.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
#ifndef _MCP4725_I2C_H_
|
||||
#define _MCP4725_I2C_H_
|
||||
|
||||
#define MCP4725_I2C_SDA_PIN NRF_GPIO_PIN_MAP(1,15)//cj edit
|
||||
#define MCP4725_I2C_SCL_PIN NRF_GPIO_PIN_MAP(1,14) //cd eidt
|
||||
|
||||
#define SDA_H() nrf_gpio_pin_set(MCP4725_I2C_SDA_PIN) // SDA pin high
|
||||
#define SDA_L() nrf_gpio_pin_clear(MCP4725_I2C_SDA_PIN) // SDA pin low
|
||||
#define SCL_H() nrf_gpio_pin_set(MCP4725_I2C_SCL_PIN) // SCL pin high
|
||||
#define SCL_L() nrf_gpio_pin_clear(MCP4725_I2C_SCL_PIN) // SCL pin low
|
||||
#define SDA_OUT() nrf_gpio_cfg_output(MCP4725_I2C_SDA_PIN) // SDA pin output mode
|
||||
#define SCL_OUT() nrf_gpio_cfg_output(MCP4725_I2C_SCL_PIN) // SCL pin output mode
|
||||
#define SDA_IN() nrf_gpio_cfg_input(MCP4725_I2C_SDA_PIN, NRF_GPIO_PIN_NOPULL) // SDA pin input mode
|
||||
#define SDA_READ() nrf_gpio_pin_read(MCP4725_I2C_SDA_PIN) // SDA pin read
|
||||
#define SCL_READ() nrf_gpio_pin_read(MCP4725_I2C_SCL_PIN) // SCL pin read
|
||||
#define i2c_delay() nrf_delay_us(1) // delay time for 400khz clock 1
|
||||
#define i2c_clock() { i2c_delay(); SCL_H(); i2c_delay(); SCL_L(); }
|
||||
#define i2c_start() { SDA_H(); i2c_delay(); SCL_H(); i2c_delay(); SDA_L(); i2c_delay(); SCL_L(); i2c_delay();}
|
||||
#define i2c_stop() { SDA_L(); i2c_delay(); SCL_H(); i2c_delay(); SDA_H(); i2c_delay(); }
|
||||
|
||||
#define TWI_WRITE 0x00
|
||||
#define TWI_READ 0x01
|
||||
|
||||
#define ACK true
|
||||
#define NACK false
|
||||
|
||||
#define DAC_write false
|
||||
#define EEPROM_write true
|
||||
|
||||
// constants
|
||||
#define MCP4725_MAXVALUE 4095
|
||||
|
||||
// registerMode
|
||||
#define MCP4725_DAC 0x40
|
||||
#define MCP4725_DACEEPROM 0x60
|
||||
|
||||
// reset & wake up
|
||||
#define MCP4725_GC_RESET 0x06
|
||||
#define MCP4725_GC_WAKEUP 0x09
|
||||
|
||||
// powerDown Mode - TODO ENUM?
|
||||
#define MCP4725_PDMODE_NORMAL 0x00
|
||||
#define MCP4725_PDMODE_1K 0x01
|
||||
#define MCP4725_PDMODE_100K 0x02
|
||||
#define MCP4725_PDMODE_500K 0x03
|
||||
|
||||
void mcp4725_i2c_initialize(void);
|
||||
void mcp4725_writeFastMode(const uint16_t value);
|
||||
void mcp4725_generalCall(const uint8_t gc);
|
||||
void mcp4725_init(void);
|
||||
void mcp4725_powerOnReset(void);
|
||||
void mcp4725_powerOnWakeUp(void);
|
||||
void mcp4725_PowerDownMode(void);
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
uint16_t mcp4725_readDAC(void);
|
||||
bool mcp4725_ready(void);
|
||||
uint16_t mcp4725_readDAC(void);
|
||||
bool mcp4725_ready(void);
|
||||
|
||||
void mcp4725_writeRegisterMode(const uint16_t value, uint8_t reg);
|
||||
void mcp4725_readRegister(uint8_t* buffer, const uint8_t length);
|
||||
void mcp4725_setValue(const uint16_t value);
|
||||
uint16_t mcp4725_getValue(void);
|
||||
void mcp4725_setPercentage(float percentage);
|
||||
void mcp4725_writeDAC(const uint16_t value, const bool EEPROM);
|
||||
uint16_t mcp4725_readEEPROM(void);
|
||||
void mcp4725_writePowerDownMode(const uint8_t PDM, const bool EEPROM);
|
||||
uint8_t mcp4725_readPowerDownModeEEPROM(void);
|
||||
uint8_t mcp4725_readPowerDownModeDAC(void);
|
||||
|
||||
|
||||
|
||||
void DS3930_write(uint8_t id, uint8_t addr, uint8_t wdata);
|
||||
uint8_t DS3930_read(uint8_t id, uint8_t addr, uint8_t* rdata);
|
||||
|
||||
|
||||
#endif /* !_MCP4725_I2C_H_ */
|
||||
|
||||
913
project/ble_peripheral/ble_app_bladder_patch/meas_pd_48.c
Normal file
913
project/ble_peripheral/ble_app_bladder_patch/meas_pd_48.c
Normal file
@@ -0,0 +1,913 @@
|
||||
/*******************************************************************************
|
||||
TEST medi50 Dec 23
|
||||
mmeas_pd_48.c
|
||||
******************************************************************************/
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "app_timer.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "ada2200_spi.h"
|
||||
#include "ble_nus.h"
|
||||
//#include "fstorage.h"
|
||||
#include "measurements.h"
|
||||
#include "meas_pd_48.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "main_timer.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "tmp235_q1.h"
|
||||
#include "main.h"
|
||||
#include "app_raw_main.h"
|
||||
#include <cmd_parse.h>
|
||||
#include "debug_print.h"
|
||||
|
||||
|
||||
|
||||
|
||||
extern bool info4; //cmd_parse add 3other items.
|
||||
uint8_t ADC_PD_MODE = 0; //0: Full 1: Full Continuous 2: HALF 1 3: HALF 1 Continuous 4: Half2 5: Half 2 Countiuous.
|
||||
uint8_t m48_samples_in_buffer = 8;
|
||||
uint8_t CURRENT_LED_NO = 24;//48
|
||||
//uint8_t CURRENT_list_m48[m48_LED_NO]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23, 24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47};
|
||||
uint8_t CURRENT_list_m48[m48_LED_NO]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
|
||||
//uint32_t s_cnt;
|
||||
//static const uint8_t LED_list_m48[m48_LED_NO]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23, 24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47};
|
||||
static const uint8_t LED_list_m48[m48_LED_NO]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
|
||||
static const uint8_t LED_list_m48_1h[m48_LED_NO_H] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
|
||||
static const uint8_t LED_list_m48_2h[m48_LED_NO_H] = {24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47};
|
||||
extern uint16_t m_pd_delay_us;
|
||||
//int32_t c_max;
|
||||
extern volatile bool processing;
|
||||
extern volatile bool data_tx_in_progress;
|
||||
extern volatile bool ble_connection_st;
|
||||
extern bool go_temp;
|
||||
extern bool go_batt;
|
||||
//extern bool ble_got_new_data;
|
||||
////extern bool motion_data_once;
|
||||
uint16_t volatile info_batt = 0;
|
||||
|
||||
uint16_t volatile info_temp = 0;
|
||||
|
||||
uint16_t volatile info_imu[6]={0,1,2,3,4,5};
|
||||
// new add Pressure
|
||||
uint16_t volatile info_p1 = 0;
|
||||
uint16_t volatile info_p2 = 0;
|
||||
|
||||
uint32_t m48_cnt;
|
||||
static int8_t pd_no = -1;
|
||||
static int8_t led_no = -1;
|
||||
static int8_t buf_no = 0;
|
||||
//static int8_t order = 0;
|
||||
|
||||
|
||||
//static int8_t c_max = 5;
|
||||
static int32_t t_ms = 0;
|
||||
uint8_t order_pd=0;
|
||||
|
||||
|
||||
/* /int16_t buff_m48_cycle_old[48][m48_CYCLE_CNT] =
|
||||
// {
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
//
|
||||
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
//
|
||||
//
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
//
|
||||
//
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
//
|
||||
//
|
||||
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
|
||||
// }; */
|
||||
int16_t buff_m48_cycle[m48_LED_NO][m48_CYCLE_CNT] =
|
||||
{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
|
||||
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
|
||||
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
//int16_t m48_cycle_send_buff[m48_LED_NO] = {0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0}
|
||||
int16_t m48_cycle_send_buff[m48_LED_NO] = {0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0,}; //24 size
|
||||
|
||||
//int16_t buff_cycle_send_buff1[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff2[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff3[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff4[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff5[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff6[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff7[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff8[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff9[buff_LED_NO] = {0, };
|
||||
// uint16_t bi_buff_cycle_send_buff[10][m48_LED_NO] = {
|
||||
// {0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0
|
||||
// ,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0},
|
||||
// };
|
||||
//uint16_t single_bi_m48_cycle_send_buff[m48_LED_NO] =
|
||||
//{0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0};
|
||||
uint16_t single_bi_m48_cycle_send_buff[m48_LED_NO] =
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0}; //24 ==old is 48
|
||||
#define SAMPLES_IN_BUFFER 4095+32
|
||||
static nrf_saadc_value_t pd_m48_adc_buf[2][SAMPLES_IN_BUFFER];
|
||||
//uint16_t single_info_m48_cycle_send_buff[56] ={0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0,
|
||||
// 0, 0, 0, 0,0 };
|
||||
|
||||
uint16_t single_info_m48_cycle_send_buff[24] ={0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0}; //edit cj 56-->24
|
||||
//bool pd_adc_custom_a_start = false;
|
||||
//bool pd_adc_custom_b_start = false;
|
||||
//bool pd_adc_custom_c_start = false;
|
||||
//bool pd_adc_custom_d_start = false;
|
||||
//bool pd_adc_custom_end = false;
|
||||
//bool pd_adc_custom_start = false;
|
||||
bool pd_adc_m48_start = false;
|
||||
bool pd_adc_m48_running = false;
|
||||
bool m48_testing = false;
|
||||
|
||||
//
|
||||
//bool custom_add_data;
|
||||
extern bool ble_got_new_data;
|
||||
extern bool motion_raw_data_enabled;
|
||||
//extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
uint8_t m48_bin_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
//add imu
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern which_cmd_t cmd_type_t;
|
||||
|
||||
APP_TIMER_DEF(m_m48_check_loop_timer_id);
|
||||
//APP_TIMER_DEF(m_m48_send_loop_timer_id);
|
||||
#if FEATURE_DELAY
|
||||
#define m48_SEND_LOOP_INTERVAL 500
|
||||
#else
|
||||
#define m48_SEND_LOOP_INTERVAL 100 //100 cj chun
|
||||
#endif
|
||||
#define m48_CHECK_LOOP_INTERVAL 1 //1
|
||||
|
||||
|
||||
|
||||
static nrf_ppi_channel_t m_ppi_channel;
|
||||
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void m48_ppi_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
uint32_t gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(ADA2200_SYNCO_PIN);
|
||||
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
|
||||
|
||||
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
|
||||
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
|
||||
gpiote_event_addr,
|
||||
saadc_sample_task_addr);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void m48_ppi_uninit(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_uninit();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void m48_sampling_event_enable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void m48_sampling_event_disable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_disable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void m48_voltage_handler(nrf_drv_saadc_evt_t const * p_event) /* PD Voltage reading */
|
||||
{
|
||||
ret_code_t err_code;
|
||||
int16_t sum = 0;
|
||||
|
||||
uint32_t m48_clk_delay = m_pd_delay_us/16;
|
||||
|
||||
if(ble_connection_st == 0) {
|
||||
//imm_adc_end();
|
||||
//custom_send_timer_stop();
|
||||
DBG_PRINTF("m48 ADC STOP 1\r\n");
|
||||
|
||||
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
pd_adc_m48_start=false;
|
||||
pd_adc_m48_running=false;
|
||||
m48_testing = false;
|
||||
info4 = false;
|
||||
DBG_PRINTF ("LOST_AT48\r\n");
|
||||
processing = false;
|
||||
go_batt = false;
|
||||
go_temp = false;
|
||||
m48_adc_end_final();
|
||||
}
|
||||
|
||||
else{
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, m48_samples_in_buffer + m48_clk_delay);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
if(led_no == -1) {
|
||||
led_no = 0;
|
||||
pd_no = 0;
|
||||
|
||||
led_on(CURRENT_list_m48[led_no]);
|
||||
led_pd_matching_value_set(CURRENT_list_m48[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else {
|
||||
|
||||
for(uint16_t i = m48_clk_delay; i < m48_clk_delay + m48_samples_in_buffer; i++){
|
||||
buff_m48_cycle[buf_no][i-m48_clk_delay] = p_event->data.done.p_buffer[i];
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("-----------------Read ADC // led_no = %d(%d), pd_no = %d(%d), buf_no = %d\r\n\r\n", led_no, LED_list_m48[led_no], pd_no, PD_list_m48[pd_no], buf_no);
|
||||
#endif
|
||||
|
||||
buf_no++;
|
||||
|
||||
if(pd_no >= - 1) {
|
||||
//pd_no = 0;
|
||||
|
||||
|
||||
|
||||
if(led_no < CURRENT_LED_NO - 1) {
|
||||
led_no++;
|
||||
led_on(CURRENT_list_m48[led_no]);
|
||||
led_pd_matching_value_set(CURRENT_list_m48[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else if(led_no >= CURRENT_LED_NO - 1) {
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("\r\nEnded\r\n");
|
||||
#endif
|
||||
//imm_adc_end();
|
||||
//imm_adc_end_final();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
uint8_t k =0;
|
||||
sum = 0;
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++){
|
||||
for(uint16_t j = 0; j < m48_samples_in_buffer; j++){
|
||||
sum += buff_m48_cycle[i][j];
|
||||
}
|
||||
|
||||
m48_cycle_send_buff[k++] = sum;
|
||||
sum = 0;
|
||||
}
|
||||
|
||||
buf_no = 0;
|
||||
|
||||
if(ble_connection_st == 0) {
|
||||
|
||||
DBG_PRINTF("m24 ADC STOP 1");
|
||||
// pd_adc_m48_start=false;
|
||||
// pd_adc_m48_running=false;
|
||||
// DBG_PRINTF ("FINISH SEND\r\n");
|
||||
//
|
||||
// m48_testing = false;
|
||||
// m48_adc_end_final();
|
||||
}
|
||||
else {
|
||||
pd_adc_m48_start=false;
|
||||
|
||||
DBG_PRINTF ("FINISH SEND\r\n");
|
||||
m48_testing = false;
|
||||
//m48_adc_end_final();
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
//custom_send_timer_stop();
|
||||
|
||||
}else if(cmd_type_t == CMD_BLE) {
|
||||
// DBG_PRINTF("%d ms \r\n",t_ms);
|
||||
//DBG_PRINTF("value 4: %d,%d,%d,%d \r\n",imm_cycle_send_buff[0] ,imm_cycle_send_buff[1] ,imm_cycle_send_buff[2] ,imm_cycle_send_buff[3] );
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++){
|
||||
DBG_PRINTF("%d,",m48_cycle_send_buff[i]);
|
||||
//bi_m48_cycle_send_buff[m48_cnt][i]=(uint16_t)(m48_cycle_send_buff[i]);
|
||||
|
||||
single_bi_m48_cycle_send_buff[i]=(uint16_t)(m48_cycle_send_buff[i]);
|
||||
}
|
||||
|
||||
if (info4 == true){
|
||||
|
||||
single_info_m48_cycle_send_buff[0] = info_batt;
|
||||
single_info_m48_cycle_send_buff[1] = info_temp;
|
||||
for(uint16_t i = 0; i < 6; i++)
|
||||
single_info_m48_cycle_send_buff[i+2]= info_imu[i];
|
||||
|
||||
single_info_m48_cycle_send_buff[8] = info_p1; //add cj 25/11/24
|
||||
single_info_m48_cycle_send_buff[9] = info_p2; //add cj 25/11/24
|
||||
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++){
|
||||
single_info_m48_cycle_send_buff[i+10]= single_bi_m48_cycle_send_buff[i];
|
||||
}
|
||||
if(ADC_PD_MODE==0){
|
||||
|
||||
format_data(m48_bin_buffer, "rsj:", single_info_m48_cycle_send_buff, 56); //MEASURE ADC 24 48+6+2
|
||||
binary_tx_handler(m48_bin_buffer,58);
|
||||
}
|
||||
else if(ADC_PD_MODE==2){
|
||||
|
||||
format_data(m48_bin_buffer, "rcj:", single_info_m48_cycle_send_buff, 34); //24(pd)+6(imu)+2(pressure p1p2)
|
||||
binary_tx_handler(m48_bin_buffer,36);
|
||||
}
|
||||
else if(ADC_PD_MODE==3){
|
||||
|
||||
format_data(m48_bin_buffer, "rdj:", single_info_m48_cycle_send_buff, 34); //24(pd)+6(imu)+2(pressure p1p2)
|
||||
binary_tx_handler(m48_bin_buffer,36);
|
||||
}
|
||||
else if(ADC_PD_MODE==4){
|
||||
|
||||
format_data(m48_bin_buffer, "rej:", single_info_m48_cycle_send_buff, 34); //24(pd)+6(imu)+2(pressure p1p2)
|
||||
binary_tx_handler(m48_bin_buffer,36);
|
||||
}
|
||||
else if(ADC_PD_MODE==5){
|
||||
|
||||
format_data(m48_bin_buffer, "rfj:", single_info_m48_cycle_send_buff, 34); //24(pd)+6(imu)+2(pressure p1p2)
|
||||
binary_tx_handler(m48_bin_buffer,36);
|
||||
}
|
||||
else {
|
||||
// format_data(m48_bin_buffer, "rsj:", single_info_m48_cycle_send_buff, 56);
|
||||
// binary_tx_handler(m48_bin_buffer,56);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
else{
|
||||
|
||||
char resp[4];
|
||||
|
||||
|
||||
|
||||
if(ADC_PD_MODE==2){
|
||||
|
||||
format_data(m48_bin_buffer, "rdj:", single_bi_m48_cycle_send_buff, 24);
|
||||
binary_tx_handler(m48_bin_buffer,26);
|
||||
|
||||
}
|
||||
|
||||
else if(ADC_PD_MODE==4){
|
||||
|
||||
format_data(m48_bin_buffer, "rfj:", single_bi_m48_cycle_send_buff, 24);
|
||||
binary_tx_handler(m48_bin_buffer,26);
|
||||
|
||||
}
|
||||
else if(ADC_PD_MODE==3){
|
||||
sprintf(resp,"rd%01X:", order_pd);
|
||||
format_data(m48_bin_buffer, resp, single_bi_m48_cycle_send_buff, 24);
|
||||
binary_tx_handler(m48_bin_buffer,26);
|
||||
}
|
||||
|
||||
else if(ADC_PD_MODE==4){
|
||||
|
||||
format_data(m48_bin_buffer, "rej:", single_bi_m48_cycle_send_buff, 24);
|
||||
binary_tx_handler(m48_bin_buffer,26);
|
||||
}
|
||||
|
||||
else if(ADC_PD_MODE==5){
|
||||
sprintf(resp,"rf%01X:", order_pd);
|
||||
format_data(m48_bin_buffer, resp, single_bi_m48_cycle_send_buff, 24);
|
||||
binary_tx_handler(m48_bin_buffer,26);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
else {
|
||||
// format_data(m48_bin_buffer, "rtj:", single_bi_m48_cycle_send_buff, 48);
|
||||
// binary_tx_handler(m48_bin_buffer,50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DBG_PRINTF("\r\n %d ms \r\n",t_ms);
|
||||
// format_data(buff_bin_buffer, "rjb:", bi_buff_cycle_send_buff, 200);
|
||||
// //
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
}
|
||||
|
||||
// if(ble_connection_st == 1) {
|
||||
// battery_timer_start();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
if (pd_adc_m48_running==true){
|
||||
|
||||
|
||||
|
||||
//m48_adc_end_final();
|
||||
|
||||
if(info4 == true){
|
||||
m48_adc_end_final();
|
||||
pd_adc_m48_start=true;
|
||||
go_batt = true; // BATT.TEMP IMU
|
||||
//motion_raw_data_enabled = true;//only IMU
|
||||
main_timer_start();
|
||||
|
||||
}
|
||||
else{t_ms=0;
|
||||
m48_cnt=0;
|
||||
m48_testing = true;
|
||||
//
|
||||
//processing = false;
|
||||
m48_adc_start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(info4 == true){ //for single shot
|
||||
info4 = false;
|
||||
}
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
processing = false;
|
||||
m48_adc_end_final();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void m48_check_loop(void * p_context)
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
m48_check_timer_stop();
|
||||
if ( m48_testing == false)
|
||||
{
|
||||
DBG_PRINTF("%d ms \r\n",t_ms);
|
||||
// sprintf(custom_tx_buffer, "Measure Time :%d ms \r\n",t_ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
t_ms++;
|
||||
m48_check_timer_start();
|
||||
}
|
||||
}
|
||||
//void m48_send_loop(void * p_context) /* For x ms */
|
||||
//{
|
||||
// UNUSED_PARAMETER(p_context);
|
||||
// m48_send_timer_stop();
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// order++;
|
||||
// if(ble_connection_st == BLE_DISCONNECTED_ST) {
|
||||
// // order=0;
|
||||
// // full_send_timer_stop();
|
||||
// // DBG_PRINTF("Full ADC STOP 2\r\n");
|
||||
//
|
||||
// }
|
||||
// else{
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
void m48_adc_start_init(void)
|
||||
{
|
||||
if (ble_got_new_data ==true)
|
||||
{
|
||||
if (pd_adc_m48_running==true){
|
||||
|
||||
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
pd_adc_m48_start=false;
|
||||
pd_adc_m48_running=false;
|
||||
DBG_PRINTF ("FINISH NEWDATA\r\n");
|
||||
processing = false;
|
||||
go_batt = false;
|
||||
go_temp = false;
|
||||
//pd_adc_m48_running=false;
|
||||
//motion_data_once = true;
|
||||
motion_raw_data_enabled = false;
|
||||
m48_testing = false;
|
||||
if(info4 == true){ //for complex continous
|
||||
info4 = false;
|
||||
}
|
||||
else {
|
||||
m48_adc_end_final(); //normal contuion
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if (pd_adc_m48_running==true){
|
||||
//
|
||||
// info4 = true;
|
||||
// t_ms=0;
|
||||
// m48_cnt=0;
|
||||
// m48_testing = true;
|
||||
// //
|
||||
// //processing = false;
|
||||
// m48_adc_start();
|
||||
// //m48_adc_end_final();
|
||||
//
|
||||
//
|
||||
// }
|
||||
else if (pd_adc_m48_start==true)
|
||||
{
|
||||
|
||||
|
||||
switch (ADC_PD_MODE)
|
||||
{
|
||||
case 0:
|
||||
pd_adc_m48_running=false;
|
||||
CURRENT_LED_NO = m48_LED_NO;
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++) {
|
||||
CURRENT_list_m48[i] = LED_list_m48[i];
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
pd_adc_m48_running=true;
|
||||
CURRENT_LED_NO = m48_LED_NO;
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++) {
|
||||
CURRENT_list_m48[i] = LED_list_m48[i];
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
pd_adc_m48_running=false;
|
||||
CURRENT_LED_NO = m48_LED_NO_H;
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++) {
|
||||
CURRENT_list_m48[i] = LED_list_m48_1h[i];
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
pd_adc_m48_running=true;
|
||||
CURRENT_LED_NO = m48_LED_NO_H;
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++) {
|
||||
|
||||
CURRENT_list_m48[i] = LED_list_m48_1h[i];
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
pd_adc_m48_running=false;
|
||||
CURRENT_LED_NO = m48_LED_NO_H;
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++) {
|
||||
CURRENT_list_m48[i] = LED_list_m48_2h[i];
|
||||
DBG_PRINTF("%d,",CURRENT_list_m48[i]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
pd_adc_m48_running=true;
|
||||
CURRENT_LED_NO = m48_LED_NO_H;
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++) {
|
||||
CURRENT_list_m48[i] = LED_list_m48_2h[i];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
default:
|
||||
pd_adc_m48_running=false;
|
||||
CURRENT_LED_NO = m48_LED_NO;
|
||||
for(uint16_t i = 0; i < CURRENT_LED_NO; i++) {
|
||||
CURRENT_list_m48[i] = LED_list_m48[i];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
t_ms=0;
|
||||
m48_cnt=0;
|
||||
pd_adc_m48_start=false;
|
||||
|
||||
m48_testing = true;
|
||||
// custom_check_timer_start();
|
||||
// c_cnt=0;
|
||||
// pd_adc_custom_start=false;
|
||||
// pd_adc_custom_a_start=true;
|
||||
|
||||
// static const uint8_t LED_list_m48[m48_LED_NO]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23, 24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47};
|
||||
//static const uint8_t LED_list_m48_1h[m48_LED_NO_H] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
|
||||
//static const uint8_t LED_list_m48_2h[m48_LED_NO_H] = {24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47};
|
||||
// uint8_t ADC_PD_MODE = 0; //0: Full 1: Full Continuous 2: HALF 1 3: HALF 1 Continuous 4: Half2 5: Half 2 Countiuous.
|
||||
m48_adc_start2();
|
||||
m48_check_timer_start();
|
||||
// c_cnt++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void m48_adc_start(void)
|
||||
{
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
buf_no = 0;
|
||||
|
||||
|
||||
|
||||
for(uint16_t i = 0; i < m48_LED_NO; i++) { //ok
|
||||
for(uint16_t j = 0; j < m48_CYCLE_CNT; j++) {
|
||||
buff_m48_cycle[i][j] = 0;
|
||||
|
||||
if (ble_got_new_data ==true){
|
||||
if (pd_adc_m48_running==true){
|
||||
|
||||
|
||||
// led_off(99);
|
||||
// pd_off(99);
|
||||
pd_adc_m48_start=false;
|
||||
pd_adc_m48_running=false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(order_pd>=15){
|
||||
order_pd=0;
|
||||
}
|
||||
else
|
||||
{ order_pd++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void m48_adc_start2(void)
|
||||
{
|
||||
m48_adc_start();
|
||||
m48_adc_init();
|
||||
m48_irq_init();
|
||||
m48_ppi_init();
|
||||
m48_sampling_event_enable();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void m48_adc_end(void)
|
||||
{
|
||||
|
||||
DBG_PRINTF("m48_adc_end\r\n");
|
||||
|
||||
m48_sampling_event_disable();
|
||||
|
||||
}
|
||||
|
||||
void m48_adc_end_final(void)
|
||||
{
|
||||
DBG_PRINTF("adc_end_final\r\n");
|
||||
m48_sampling_event_disable();
|
||||
m48_irq_uninit();
|
||||
m48_ppi_uninit();
|
||||
m48_adc_uninit();
|
||||
battery_timer_start();
|
||||
}
|
||||
|
||||
|
||||
void m48_adc_init(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("m48_adc_init\r\n");
|
||||
#endif
|
||||
|
||||
static nrfx_saadc_config_t default_config;
|
||||
default_config.resolution = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION; /* Resolution is 10bits */
|
||||
default_config.oversample = (nrf_saadc_oversample_t)NRFX_SAADC_CONFIG_OVERSAMPLE; /* Over Sampling Disabled */
|
||||
default_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY; /* Interrupt Priority is 0(Highest) */
|
||||
default_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE; /* Low Power Mode is Disabled */
|
||||
|
||||
static nrf_saadc_channel_config_t config;
|
||||
config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.gain = NRF_SAADC_GAIN1_6;
|
||||
config.reference = NRF_SAADC_REFERENCE_INTERNAL;
|
||||
config.acq_time = NRF_SAADC_ACQTIME_3US;
|
||||
config.mode = NRF_SAADC_MODE_DIFFERENTIAL;
|
||||
config.burst = NRF_SAADC_BURST_DISABLED;
|
||||
config.pin_p = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN0);
|
||||
config.pin_n = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN1);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_init(&default_config, m48_voltage_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(pd_m48_adc_buf[0], m48_samples_in_buffer + m_pd_delay_us/16);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void m48_adc_uninit(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("pd_m48_adc_uninit\r\n");
|
||||
#endif
|
||||
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
}
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void m48_irq_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
/* Initialize int pin */
|
||||
if (!nrfx_gpiote_is_init())
|
||||
{
|
||||
err_code = nrfx_gpiote_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
|
||||
in_config.pull = NRF_GPIO_PIN_PULLDOWN;
|
||||
|
||||
err_code = nrfx_gpiote_in_init(ADA2200_SYNCO_PIN, &in_config, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_gpiote_in_event_enable(ADA2200_SYNCO_PIN, true);
|
||||
}
|
||||
|
||||
|
||||
void m48_irq_uninit(void)
|
||||
{
|
||||
nrfx_gpiote_in_event_disable(ADA2200_SYNCO_PIN);
|
||||
nrfx_gpiote_in_uninit(ADA2200_SYNCO_PIN);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// void m48_send_timer_start(void)
|
||||
// {
|
||||
// APP_ERROR_CHECK(app_timer_start(m_m48_send_loop_timer_id, APP_TIMER_TICKS(m48_SEND_LOOP_INTERVAL), NULL));
|
||||
// }
|
||||
|
||||
|
||||
// void m48_send_timer_stop(void)
|
||||
// {
|
||||
// APP_ERROR_CHECK(app_timer_stop(m_m48_send_loop_timer_id));
|
||||
|
||||
// }
|
||||
|
||||
|
||||
// void m48_send_timer_init(void)
|
||||
// {
|
||||
// APP_ERROR_CHECK(app_timer_create(&m_m48_send_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, m48_send_loop));
|
||||
// }
|
||||
|
||||
|
||||
void m48_check_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_m48_check_loop_timer_id, APP_TIMER_TICKS(m48_CHECK_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void m48_check_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_m48_check_loop_timer_id));
|
||||
|
||||
}
|
||||
void m48_check_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_m48_check_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, m48_check_loop));
|
||||
}
|
||||
59
project/ble_peripheral/ble_app_bladder_patch/meas_pd_48.h
Normal file
59
project/ble_peripheral/ble_app_bladder_patch/meas_pd_48.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
* @file meas_pd_48.h
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MEAS_PD_48_H__
|
||||
#define _MEAS_PD_48_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
|
||||
#define ADA2200_SYNCO_PIN NRF_GPIO_PIN_MAP(0,17)
|
||||
|
||||
|
||||
#define m48_PD_NO 1 /////4
|
||||
#define m48_LED_NO 24 ////5 ///48 cj edit 25/10/14
|
||||
#define m48_LED_NO_H 24 ////5
|
||||
#define m48_CYCLE_CNT 32 ////32
|
||||
|
||||
|
||||
void m48_ppi_init(void);
|
||||
void m48_ppi_uninit(void);
|
||||
void m48_sampling_event_enable(void);
|
||||
void m48_sampling_event_disable(void);
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void m48_voltage_handler(nrf_drv_saadc_evt_t const * p_event); /* PD Voltage reading */
|
||||
void m48_adc_start_init(void);
|
||||
void m48_adc_start(void);
|
||||
void m48_adc_start2(void);
|
||||
//void custom_adc_start2(void);
|
||||
//void custom_adc_total_start(void);
|
||||
void m48_adc_end(void);
|
||||
void m48_adc_end_final(void);
|
||||
void m48_adc_init(void);
|
||||
void m48_adc_uninit(void);
|
||||
|
||||
void m48_irq_init(void);
|
||||
void m48_irq_uninit(void);
|
||||
|
||||
// void bm48_send_start(void);
|
||||
|
||||
// void m48_send_loop(void * p_context); /* For x ms */
|
||||
// void m48f_send_timer_start(void);
|
||||
// void m48_send_timer_stop(void);;
|
||||
// void m48_send_timer_init(void);
|
||||
|
||||
|
||||
void m48_check_loop(void * p_context);
|
||||
void m48_check_timer_start(void);
|
||||
void m48_check_timer_stop(void);;
|
||||
void m48_check_timer_init(void);
|
||||
|
||||
#endif /* _MEAS_PD_48_H__ */
|
||||
|
||||
785
project/ble_peripheral/ble_app_bladder_patch/meas_pd_buff.c
Normal file
785
project/ble_peripheral/ble_app_bladder_patch/meas_pd_buff.c
Normal file
@@ -0,0 +1,785 @@
|
||||
/*******************************************************************************
|
||||
TEST medi50 Dec 23
|
||||
******************************************************************************/
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "app_timer.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "ada2200_spi.h"
|
||||
#include "ble_nus.h"
|
||||
//#include "fstorage.h"
|
||||
#include "measurements.h"
|
||||
#include "meas_pd_buff.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "main_timer.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "main.h"
|
||||
#include "app_raw_main.h"
|
||||
|
||||
//#define CUSTOM_REF_VOLTAGE_IN_MILLIVOLTS 600.0f /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
|
||||
//#define CUSTOM_PRE_SCALING_COMPENSATION 6.0f /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
|
||||
//#define CUSTOM_ADC_RES_10BITS 1024.0f /**< Maximum digital value for 10-bit ADC conversion. */
|
||||
//#define st_c_max 20
|
||||
///**@brief Macro to convert the result of ADC conversion in millivolts.
|
||||
// *
|
||||
// * @param[in] ADC_VALUE ADC result.
|
||||
// *
|
||||
// * @retval Result converted to millivolts.
|
||||
// */
|
||||
//#define CUSTOM_VOUT_IN_MILLI_VOLTS(ADC_VALUE)\
|
||||
// (((((ADC_VALUE) * CUSTOM_REF_VOLTAGE_IN_MILLIVOLTS) / CUSTOM_ADC_RES_10BITS) * CUSTOM_PRE_SCALING_COMPENSATION)*2)
|
||||
|
||||
uint16_t b_t_cnt=5;
|
||||
uint8_t buff_samples_in_buffer = 8;
|
||||
|
||||
//uint32_t s_cnt;
|
||||
uint8_t LED_list_buff[buff_LED_NO]={0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0
|
||||
,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0};
|
||||
//uint8_t PD_list_custom[4];
|
||||
|
||||
//uint8_t led_custom_list_a[5] = {2,3,4,5,6};
|
||||
//uint8_t pd_custom_list_a[4] = {5,7,8,10};
|
||||
|
||||
//uint8_t led_custom_list_b[5] = {20,21,22,23,24};
|
||||
//uint8_t pd_custom_list_b[4] = {16,14,13,11};
|
||||
|
||||
//int32_t c_max;
|
||||
extern volatile bool processing;
|
||||
extern volatile bool data_tx_in_progress;
|
||||
extern volatile bool ble_connection_st;
|
||||
|
||||
|
||||
uint32_t buff_cnt;
|
||||
static int8_t pd_no = -1;
|
||||
static int8_t led_no = -1;
|
||||
static int8_t buf_no = 0;
|
||||
static int8_t order = 0;
|
||||
uint16_t bsel_led_index0 =0;
|
||||
uint16_t bsel_led_index1 =1;
|
||||
uint16_t bsel_led_index2 =2;
|
||||
uint16_t bsel_led_index3 =3;
|
||||
|
||||
|
||||
static int32_t t_ms = 0;
|
||||
int16_t buff_cycle_buff[buff_LED_NO][buff_CYCLE_CNT] =
|
||||
{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //10
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //20
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //30
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //40
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //50
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //60
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //70
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //80
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //90
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
};
|
||||
int16_t buff_cycle_send_buff[buff_LED_NO] = {0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0
|
||||
,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0};
|
||||
//int16_t buff_cycle_send_buff1[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff2[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff3[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff4[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff5[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff6[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff7[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff8[buff_LED_NO] = {0, };
|
||||
//int16_t buff_cycle_send_buff9[buff_LED_NO] = {0, };
|
||||
uint16_t bi_buff_cycle_send_buff[60][buff_LED_NO] = {
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0
|
||||
,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0},
|
||||
};
|
||||
uint16_t single_bi_buff_cycle_send_buff[buff_LED_NO] =
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0
|
||||
,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0,0, 0, 0, 0, 0, 0, 0, 0, 0,0};
|
||||
#define SAMPLES_IN_BUFFER 4095+32
|
||||
static nrf_saadc_value_t pd_buff_adc_buf[2][SAMPLES_IN_BUFFER];
|
||||
|
||||
//bool pd_adc_custom_a_start = false;
|
||||
//bool pd_adc_custom_b_start = false;
|
||||
//bool pd_adc_custom_c_start = false;
|
||||
//bool pd_adc_custom_d_start = false;
|
||||
//bool pd_adc_custom_end = false;
|
||||
//bool pd_adc_custom_start = false;
|
||||
bool pd_adc_buff_start = false;
|
||||
bool pd_adc_buff_running = false;
|
||||
bool buff_testing = false;
|
||||
extern uint16_t m_pd_delay_us;
|
||||
//
|
||||
//bool custom_add_data;
|
||||
extern bool ble_got_new_data;
|
||||
extern bool motion_raw_data_enabled;
|
||||
//extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
uint8_t buff_bin_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
//add imu
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern which_cmd_t cmd_type_t;
|
||||
|
||||
APP_TIMER_DEF(m_buff_check_loop_timer_id);
|
||||
APP_TIMER_DEF(m_buff_send_loop_timer_id);
|
||||
#if FEATURE_DELAY
|
||||
#define CUSTOM_SEND_LOOP_INTERVAL 500
|
||||
#else
|
||||
#define BUFF_SEND_LOOP_INTERVAL 100
|
||||
#endif
|
||||
#define BUFF_CHECK_LOOP_INTERVAL 1
|
||||
|
||||
|
||||
|
||||
|
||||
static nrf_ppi_channel_t m_ppi_channel;
|
||||
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void buff_ppi_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
uint32_t gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(ADA2200_SYNCO_PIN);
|
||||
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
|
||||
|
||||
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
|
||||
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
|
||||
gpiote_event_addr,
|
||||
saadc_sample_task_addr);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void buff_ppi_uninit(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_uninit();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void buff_sampling_event_enable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void buff_sampling_event_disable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_disable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void buff_voltage_handler(nrf_drv_saadc_evt_t const * p_event) /* PD Voltage reading */
|
||||
{
|
||||
ret_code_t err_code;
|
||||
int16_t sum = 0;
|
||||
|
||||
uint32_t buff_clk_delay = m_pd_delay_us/16;
|
||||
if(ble_connection_st == 0) {
|
||||
//imm_adc_end();
|
||||
//custom_send_timer_stop();
|
||||
printf("Custom ADC STOP 1\r\n");
|
||||
}
|
||||
|
||||
else{
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, buff_samples_in_buffer + buff_clk_delay);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
if(led_no == -1) {
|
||||
led_no = 0;
|
||||
pd_no = 0;
|
||||
|
||||
led_on(LED_list_buff[led_no]);
|
||||
led_pd_matching_value_set(LED_list_buff[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else {
|
||||
|
||||
for(uint16_t i = buff_clk_delay; i < buff_clk_delay + buff_samples_in_buffer; i++){
|
||||
buff_cycle_buff[buf_no][i-buff_clk_delay] = p_event->data.done.p_buffer[i];
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("-----------------Read ADC // led_no = %d(%d), pd_no = %d(%d), buf_no = %d\r\n\r\n", led_no, LED_list_custom[led_no], pd_no, PD_list_custom[pd_no], buf_no);
|
||||
#endif
|
||||
|
||||
buf_no++;
|
||||
|
||||
if(pd_no >= - 1) {
|
||||
//pd_no = 0;
|
||||
|
||||
|
||||
|
||||
if(led_no < buff_LED_NO - 1) {
|
||||
led_no++;
|
||||
led_on(LED_list_buff[led_no]);
|
||||
led_pd_matching_value_set(LED_list_buff[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else if(led_no >= buff_LED_NO - 1) {
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\nEnded\r\n");
|
||||
#endif
|
||||
//imm_adc_end();
|
||||
//imm_adc_end_final();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
uint8_t k =0;
|
||||
sum = 0;
|
||||
for(uint16_t i = 0; i < buff_LED_NO; i++){
|
||||
for(uint16_t j = 0; j < buff_samples_in_buffer; j++){
|
||||
sum += buff_cycle_buff[i][j];
|
||||
}
|
||||
|
||||
buff_cycle_send_buff[k++] = sum;
|
||||
sum = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
buf_no = 0;
|
||||
|
||||
if(ble_connection_st == 0) {
|
||||
|
||||
printf("Custom ADC STOP 1");
|
||||
pd_adc_buff_start=false;
|
||||
pd_adc_buff_running=false;
|
||||
printf ("FINISH SEND\r\n");
|
||||
processing = false;
|
||||
buff_testing = false;
|
||||
buff_adc_end_final();
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
//custom_send_timer_stop();
|
||||
|
||||
}else if(cmd_type_t == CMD_BLE) {
|
||||
// printf("%d ms \r\n",t_ms);
|
||||
//printf("value 4: %d,%d,%d,%d \r\n",imm_cycle_send_buff[0] ,imm_cycle_send_buff[1] ,imm_cycle_send_buff[2] ,imm_cycle_send_buff[3] );
|
||||
for(uint16_t i = 0; i < buff_LED_NO; i++){
|
||||
printf("%d,",buff_cycle_send_buff[i]);
|
||||
bi_buff_cycle_send_buff[buff_cnt][i]=(uint16_t)(buff_cycle_send_buff[i]);
|
||||
//single_bi_buff_cycle_send_buff[i]=(uint16_t)(buff_cycle_send_buff[i]);
|
||||
|
||||
}
|
||||
printf("%d ms \r\n",t_ms);
|
||||
// format_data(buff_bin_buffer, "rjb:", bi_buff_cycle_send_buff, 200);
|
||||
//
|
||||
//
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
}
|
||||
|
||||
// if(ble_connection_st == 1) {
|
||||
// battery_timer_start();
|
||||
// }
|
||||
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
buff_adc_start_init();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void buff_check_loop(void * p_context)
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
buff_check_timer_stop();
|
||||
if ( buff_testing == false)
|
||||
{
|
||||
printf("%d ms \r\n",t_ms);
|
||||
// sprintf(custom_tx_buffer, "Measure Time :%d ms \r\n",t_ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
t_ms++;
|
||||
buff_check_timer_start();
|
||||
}
|
||||
}
|
||||
|
||||
void buff_send_loop(void * p_context) /* For x ms */
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
buff_send_timer_stop();
|
||||
|
||||
char resp[4];
|
||||
|
||||
if(ble_connection_st == BLE_DISCONNECTED_ST) {
|
||||
// order=0;
|
||||
// full_send_timer_stop();
|
||||
buff_adc_end_final();
|
||||
printf("BUFF ADC STOP 2\r\n");
|
||||
processing = false;
|
||||
}
|
||||
|
||||
else if(order<4){
|
||||
sprintf(resp,"r%02d:", order);
|
||||
format_data(buff_bin_buffer, resp, bi_buff_cycle_send_buff[order],100);
|
||||
binary_tx_handler(buff_bin_buffer,102);
|
||||
order++;
|
||||
buff_send_timer_start();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ddddd%d ms \r\n",t_ms);
|
||||
processing = false;
|
||||
buff_adc_end_final();
|
||||
//battery_timer_start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// switch(order) {
|
||||
// case 0:
|
||||
// sprintf(resp,"r%02X:", order);
|
||||
// format_data(buff_bin_buffer, resp, bi_buff_cycle_send_buff[0],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
// break;
|
||||
|
||||
// case 1:
|
||||
// format_data(buff_bin_buffer, "rb1:", bi_buff_cycle_send_buff[1],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
//
|
||||
// break;
|
||||
// case 2:
|
||||
// format_data(buff_bin_buffer, "rb2:", bi_buff_cycle_send_buff[2],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
//
|
||||
// break;
|
||||
|
||||
// case 3:
|
||||
// format_data(buff_bin_buffer, "rb3:", bi_buff_cycle_send_buff[3],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
// break;
|
||||
|
||||
|
||||
// case 4:
|
||||
// format_data(buff_bin_buffer, "rb4:", bi_buff_cycle_send_buff[4],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
// break;
|
||||
//
|
||||
// case 5:
|
||||
// format_data(buff_bin_buffer, "rb5:", bi_buff_cycle_send_buff[5],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
// break;
|
||||
//
|
||||
//
|
||||
// case 6:
|
||||
// format_data(buff_bin_buffer, "rb6:", bi_buff_cycle_send_buff[6],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
// break;
|
||||
|
||||
// case 7:
|
||||
// format_data(buff_bin_buffer, "rb7:", bi_buff_cycle_send_buff[7],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
//
|
||||
// break;
|
||||
// case 8:
|
||||
// format_data(buff_bin_buffer, "rb8:", bi_buff_cycle_send_buff[8],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
//
|
||||
// break;
|
||||
|
||||
// case 9:
|
||||
// format_data(buff_bin_buffer, "rb9:", bi_buff_cycle_send_buff[9],100);
|
||||
// binary_tx_handler(buff_bin_buffer,102);
|
||||
// break;
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// case 10:
|
||||
// printf("Measure Time : %d ms \r\n",t_ms);
|
||||
// //sprintf(full_tx_buffer, "Measure Time :%d ms \r\n",t_ms);
|
||||
// // data_tx_handler(full_tx_buffer);
|
||||
// order = 0;
|
||||
// return;
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("full_send Completed\r\n");
|
||||
//#endif
|
||||
|
||||
|
||||
|
||||
// default:
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
void buff_adc_start_init(void)
|
||||
{
|
||||
if (ble_got_new_data ==true)
|
||||
{
|
||||
pd_adc_buff_start=false;
|
||||
pd_adc_buff_running=false;
|
||||
printf ("FINISH SEND\r\n");
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
processing = false;
|
||||
buff_testing = false;
|
||||
buff_adc_end_final();
|
||||
}
|
||||
|
||||
else if (pd_adc_buff_running==true){
|
||||
|
||||
if(buff_cnt>=b_t_cnt){
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
pd_adc_buff_start=false;
|
||||
pd_adc_buff_running=false;
|
||||
printf ("FIFNISH SEND\r\n");
|
||||
|
||||
buff_testing = false;
|
||||
|
||||
order =0;
|
||||
buff_send_timer_start();
|
||||
//buff_adc_start();
|
||||
}
|
||||
else{
|
||||
buff_adc_start();
|
||||
buff_cnt++;
|
||||
}
|
||||
}
|
||||
else if (pd_adc_buff_start==true)
|
||||
{
|
||||
// custom_testing = false;
|
||||
// motion_raw_data_enabled = true;
|
||||
// custom_add_data = true;
|
||||
// icm42670_main();
|
||||
for(uint8_t i =0; i < 25; i++) {
|
||||
LED_list_buff[i*4] = bsel_led_index0;
|
||||
LED_list_buff[i*4+1] = bsel_led_index1;
|
||||
LED_list_buff[i*4+2] = bsel_led_index2;
|
||||
LED_list_buff[i*4+3] = bsel_led_index3;
|
||||
// data_tx_handler(ble_tx_buffer);
|
||||
}
|
||||
|
||||
for(uint8_t i =0; i < 60; i++) {
|
||||
for(uint8_t j =0; j < 100; j++) {
|
||||
bi_buff_cycle_send_buff[i][j]=0;
|
||||
}
|
||||
}
|
||||
t_ms=0;
|
||||
buff_cnt=0;
|
||||
pd_adc_buff_start=false;
|
||||
pd_adc_buff_running=true;
|
||||
buff_testing = true;
|
||||
// custom_check_timer_start();
|
||||
// c_cnt=0;
|
||||
// pd_adc_custom_start=false;
|
||||
// pd_adc_custom_a_start=true;
|
||||
|
||||
buff_adc_start2();
|
||||
buff_check_timer_start();
|
||||
// c_cnt++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void buff_adc_start(void)
|
||||
{
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
buf_no = 0;
|
||||
|
||||
|
||||
|
||||
for(uint16_t i = 0; i < buff_LED_NO; i++) {
|
||||
for(uint16_t j = 0; j < buff_CYCLE_CNT; j++) {
|
||||
buff_cycle_buff[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void buff_adc_start2(void)
|
||||
{
|
||||
buff_adc_start();
|
||||
buff_adc_init();
|
||||
buff_irq_init();
|
||||
buff_ppi_init();
|
||||
buff_sampling_event_enable();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void buff_adc_end(void)
|
||||
{
|
||||
|
||||
printf("adc_end\r\n");
|
||||
|
||||
buff_sampling_event_disable();
|
||||
|
||||
}
|
||||
|
||||
void buff_adc_end_final(void)
|
||||
{
|
||||
|
||||
printf("adc_end_for_good\r\n");
|
||||
|
||||
buff_sampling_event_disable();
|
||||
buff_irq_uninit();
|
||||
buff_ppi_uninit();
|
||||
buff_adc_uninit();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void buff_adc_init(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("custom_adc_init\r\n");
|
||||
#endif
|
||||
|
||||
static nrfx_saadc_config_t default_config;
|
||||
default_config.resolution = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION; /* Resolution is 10bits */
|
||||
default_config.oversample = (nrf_saadc_oversample_t)NRFX_SAADC_CONFIG_OVERSAMPLE; /* Over Sampling Disabled */
|
||||
default_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY; /* Interrupt Priority is 0(Highest) */
|
||||
default_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE; /* Low Power Mode is Disabled */
|
||||
|
||||
static nrf_saadc_channel_config_t config;
|
||||
config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.gain = NRF_SAADC_GAIN1_6;
|
||||
config.reference = NRF_SAADC_REFERENCE_INTERNAL;
|
||||
config.acq_time = NRF_SAADC_ACQTIME_3US;
|
||||
config.mode = NRF_SAADC_MODE_DIFFERENTIAL;
|
||||
config.burst = NRF_SAADC_BURST_DISABLED;
|
||||
config.pin_p = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN0);
|
||||
config.pin_n = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN1);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_init(&default_config, buff_voltage_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(pd_buff_adc_buf[0], buff_samples_in_buffer + m_pd_delay_us/16);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void buff_adc_uninit(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("pd_custom_adc_uninit\r\n");
|
||||
#endif
|
||||
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
}
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void buff_irq_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
/* Initialize int pin */
|
||||
if (!nrfx_gpiote_is_init())
|
||||
{
|
||||
err_code = nrfx_gpiote_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
|
||||
in_config.pull = NRF_GPIO_PIN_PULLDOWN;
|
||||
|
||||
err_code = nrfx_gpiote_in_init(ADA2200_SYNCO_PIN, &in_config, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_gpiote_in_event_enable(ADA2200_SYNCO_PIN, true);
|
||||
}
|
||||
|
||||
|
||||
void buff_irq_uninit(void)
|
||||
{
|
||||
nrfx_gpiote_in_event_disable(ADA2200_SYNCO_PIN);
|
||||
nrfx_gpiote_in_uninit(ADA2200_SYNCO_PIN);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void buff_send_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_buff_send_loop_timer_id, APP_TIMER_TICKS(BUFF_SEND_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
|
||||
void buff_send_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_buff_send_loop_timer_id));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void buff_send_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_buff_send_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, buff_send_loop));
|
||||
}
|
||||
|
||||
|
||||
void buff_check_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_buff_check_loop_timer_id, APP_TIMER_TICKS(BUFF_CHECK_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void buff_check_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_buff_check_loop_timer_id));
|
||||
|
||||
}
|
||||
void buff_check_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_buff_check_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, buff_check_loop));
|
||||
}
|
||||
58
project/ble_peripheral/ble_app_bladder_patch/meas_pd_buff.h
Normal file
58
project/ble_peripheral/ble_app_bladder_patch/meas_pd_buff.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* @file meas_pd_buff.h
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MEAS_PD_BUFF_H__
|
||||
#define _MEAS_PD_BUFF_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
|
||||
#define ADA2200_SYNCO_PIN NRF_GPIO_PIN_MAP(0,17)
|
||||
|
||||
|
||||
#define buff_PD_NO 1/////4
|
||||
#define buff_LED_NO 100////5
|
||||
#define buff_CYCLE_CNT 8 ////32
|
||||
|
||||
|
||||
void buff_ppi_init(void);
|
||||
void buff_ppi_uninit(void);
|
||||
void buff_sampling_event_enable(void);
|
||||
void buff_sampling_event_disable(void);
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void buff_voltage_handler(nrf_drv_saadc_evt_t const * p_event); /* PD Voltage reading */
|
||||
void buff_adc_start_init(void);
|
||||
void buff_adc_start(void);
|
||||
void buff_adc_start2(void);
|
||||
//void custom_adc_start2(void);
|
||||
//void custom_adc_total_start(void);
|
||||
void buff_adc_end(void);
|
||||
void buff_adc_end_final(void);
|
||||
void buff_adc_init(void);
|
||||
void buff_adc_uninit(void);
|
||||
|
||||
void buff_irq_init(void);
|
||||
void buff_irq_uninit(void);
|
||||
|
||||
void buff_send_start(void);
|
||||
|
||||
void buff_send_loop(void * p_context); /* For x ms */
|
||||
void buff_send_timer_start(void);
|
||||
void buff_send_timer_stop(void);;
|
||||
void buff_send_timer_init(void);
|
||||
|
||||
|
||||
void buff_check_loop(void * p_context);
|
||||
void buff_check_timer_start(void);
|
||||
void buff_check_timer_stop(void);;
|
||||
void buff_check_timer_init(void);
|
||||
|
||||
#endif /* _MEAS_PD_buff_H__ */
|
||||
|
||||
522
project/ble_peripheral/ble_app_bladder_patch/meas_pd_imm.c
Normal file
522
project/ble_peripheral/ble_app_bladder_patch/meas_pd_imm.c
Normal file
@@ -0,0 +1,522 @@
|
||||
/*******************************************************************************
|
||||
TEST medi50 Dec 23
|
||||
******************************************************************************/
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "app_timer.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "ada2200_spi.h"
|
||||
#include "ble_nus.h"
|
||||
//#include "fstorage.h"
|
||||
#include "measurements.h"
|
||||
#include "meas_pd_imm.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "main_timer.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "main.h"
|
||||
#include "app_raw_main.h"
|
||||
#include "debug_print.h"
|
||||
//#define CUSTOM_REF_VOLTAGE_IN_MILLIVOLTS 600.0f /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
|
||||
//#define CUSTOM_PRE_SCALING_COMPENSATION 6.0f /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
|
||||
//#define CUSTOM_ADC_RES_10BITS 1024.0f /**< Maximum digital value for 10-bit ADC conversion. */
|
||||
//#define st_c_max 20
|
||||
///**@brief Macro to convert the result of ADC conversion in millivolts.
|
||||
// *
|
||||
// * @param[in] ADC_VALUE ADC result.
|
||||
// *
|
||||
// * @retval Result converted to millivolts.
|
||||
// */
|
||||
//#define CUSTOM_VOUT_IN_MILLI_VOLTS(ADC_VALUE)\
|
||||
// (((((ADC_VALUE) * CUSTOM_REF_VOLTAGE_IN_MILLIVOLTS) / CUSTOM_ADC_RES_10BITS) * CUSTOM_PRE_SCALING_COMPENSATION)*2)
|
||||
|
||||
|
||||
static const uint8_t imm_samples_in_buffer = 8;
|
||||
|
||||
//uint32_t s_cnt;
|
||||
uint8_t LED_list_imm[4];
|
||||
//uint8_t PD_list_custom[4];
|
||||
|
||||
//uint8_t led_custom_list_a[5] = {2,3,4,5,6};
|
||||
//uint8_t pd_custom_list_a[4] = {5,7,8,10};
|
||||
|
||||
//uint8_t led_custom_list_b[5] = {20,21,22,23,24};
|
||||
//uint8_t pd_custom_list_b[4] = {16,14,13,11};
|
||||
|
||||
int32_t c_max;
|
||||
extern volatile bool processing;
|
||||
extern volatile bool data_tx_in_progress;
|
||||
extern volatile bool ble_connection_st;
|
||||
|
||||
extern uint16_t m_pd_delay_us;
|
||||
uint32_t c_cnt;
|
||||
static int8_t pd_no = -1;
|
||||
static int8_t led_no = -1;
|
||||
static int8_t buf_no = 0;
|
||||
|
||||
uint16_t sel_led_index0 =0;
|
||||
uint16_t sel_led_index1 =1;
|
||||
uint16_t sel_led_index2 =2;
|
||||
uint16_t sel_led_index3 =3;
|
||||
|
||||
//static int8_t c_max = 5;
|
||||
static int32_t t_ms = 0;
|
||||
int16_t imm_cycle_buff[4][imm_CYCLE_CNT] =
|
||||
{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0} //3
|
||||
};
|
||||
int16_t imm_cycle_send_buff[imm_LED_NO] = {0, 0, 0, 0};
|
||||
uint16_t bi_imm_cycle_send_buff[imm_LED_NO] = {0, 0, 0, 0};
|
||||
|
||||
#define SAMPLES_IN_BUFFER 4095+32
|
||||
static nrf_saadc_value_t pd_imm_adc_buf[2][SAMPLES_IN_BUFFER];
|
||||
|
||||
bool pd_adc_custom_a_start = false;
|
||||
bool pd_adc_custom_b_start = false;
|
||||
bool pd_adc_custom_c_start = false;
|
||||
bool pd_adc_custom_d_start = false;
|
||||
bool pd_adc_custom_end = false;
|
||||
bool pd_adc_custom_start = false;
|
||||
bool pd_adc_imm_start = false;
|
||||
bool pd_adc_imm_running = false;
|
||||
bool custom_testing = false;
|
||||
|
||||
//
|
||||
bool custom_add_data;
|
||||
extern bool ble_got_new_data;
|
||||
extern bool motion_raw_data_enabled;
|
||||
extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
uint8_t imm_bin_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
//add imu
|
||||
uint8_t order_imm=0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern which_cmd_t cmd_type_t;
|
||||
|
||||
APP_TIMER_DEF(m_custom_check_loop_timer_id);
|
||||
//APP_TIMER_DEF(m_custom_send_loop_timer_id);
|
||||
#if FEATURE_DELAY
|
||||
#define CUSTOM_SEND_LOOP_INTERVAL 500
|
||||
#else
|
||||
#define CUSTOM_SEND_LOOP_INTERVAL 100
|
||||
#endif
|
||||
#define CUSTOM_CHECK_LOOP_INTERVAL 1
|
||||
|
||||
|
||||
|
||||
|
||||
static nrf_ppi_channel_t m_ppi_channel;
|
||||
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void imm_ppi_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
uint32_t gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(ADA2200_SYNCO_PIN);
|
||||
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
|
||||
|
||||
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
|
||||
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
|
||||
gpiote_event_addr,
|
||||
saadc_sample_task_addr);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void imm_ppi_uninit(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_uninit();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void imm_sampling_event_enable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void imm_sampling_event_disable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_disable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void imm_voltage_handler(nrf_drv_saadc_evt_t const * p_event) /* PD Voltage reading */
|
||||
{
|
||||
ret_code_t err_code;
|
||||
int16_t sum = 0;
|
||||
|
||||
uint32_t custom_clk_delay = m_pd_delay_us/16;
|
||||
if(ble_connection_st == 0) {
|
||||
//imm_adc_end();
|
||||
//custom_send_timer_stop();
|
||||
DBG_PRINTF("Custom ADC STOP 1\r\n");
|
||||
}
|
||||
|
||||
else{
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, imm_samples_in_buffer + custom_clk_delay);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
if(led_no == -1) {
|
||||
led_no = 0;
|
||||
pd_no = 0;
|
||||
|
||||
led_on(LED_list_imm[led_no]);
|
||||
led_pd_matching_value_set(LED_list_imm[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else {
|
||||
|
||||
for(uint16_t i = custom_clk_delay; i < custom_clk_delay + imm_samples_in_buffer; i++){
|
||||
imm_cycle_buff[buf_no][i-custom_clk_delay] = p_event->data.done.p_buffer[i];
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("-----------------Read ADC // led_no = %d(%d), pd_no = %d(%d), buf_no = %d\r\n\r\n", led_no, LED_list_custom[led_no], pd_no, PD_list_custom[pd_no], buf_no);
|
||||
#endif
|
||||
|
||||
buf_no++;
|
||||
|
||||
if(pd_no >= - 1) {
|
||||
//pd_no = 0;
|
||||
|
||||
|
||||
|
||||
if(led_no < imm_LED_NO - 1) {
|
||||
led_no++;
|
||||
led_on(LED_list_imm[led_no]);
|
||||
led_pd_matching_value_set(LED_list_imm[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else if(led_no >= imm_LED_NO - 1) {
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("\r\nEnded\r\n");
|
||||
#endif
|
||||
//imm_adc_end();
|
||||
//imm_adc_end_final();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
uint8_t k =0;
|
||||
sum = 0;
|
||||
for(uint16_t i = 0; i < 4; i++){
|
||||
for(uint16_t j = 0; j < imm_samples_in_buffer; j++){
|
||||
sum += imm_cycle_buff[i][j];
|
||||
}
|
||||
|
||||
imm_cycle_send_buff[k++] = sum;
|
||||
sum = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
buf_no = 0;
|
||||
|
||||
if(ble_connection_st == 0) {
|
||||
|
||||
DBG_PRINTF("Custom ADC STOP 1");
|
||||
pd_adc_imm_start=false;
|
||||
pd_adc_imm_running=false;
|
||||
DBG_PRINTF ("FINISH SEND\r\n");
|
||||
processing = false;
|
||||
custom_testing = false;
|
||||
imm_adc_end_final();
|
||||
}
|
||||
else {
|
||||
char resp[4];
|
||||
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
//custom_send_timer_stop();
|
||||
DBG_PRINTF("value 4: %d,%d,%d,%d \r\n",imm_cycle_send_buff[0] ,imm_cycle_send_buff[1] ,imm_cycle_send_buff[2] ,imm_cycle_send_buff[3] );
|
||||
}else if(cmd_type_t == CMD_BLE) {
|
||||
DBG_PRINTF("%d ms \r\n",t_ms);
|
||||
DBG_PRINTF("value 4: %d,%d,%d,%d \r\n",imm_cycle_send_buff[0] ,imm_cycle_send_buff[1] ,imm_cycle_send_buff[2] ,imm_cycle_send_buff[3] );
|
||||
for(uint16_t i = 0; i < 4; i++){
|
||||
bi_imm_cycle_send_buff[i]=(uint16_t)(imm_cycle_send_buff[i]);
|
||||
}
|
||||
sprintf(resp,"rF%01X:", order_imm);
|
||||
format_data(imm_bin_buffer, resp, bi_imm_cycle_send_buff, 4);
|
||||
|
||||
|
||||
binary_tx_handler(imm_bin_buffer,6);
|
||||
}
|
||||
|
||||
// if(ble_connection_st == 1) {
|
||||
// battery_timer_start();
|
||||
// }
|
||||
|
||||
// led_off(99);
|
||||
// pd_off(99);
|
||||
imm_adc_start_init();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void imm_check_loop(void * p_context)
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
imm_check_timer_stop();
|
||||
if ( custom_testing == false)
|
||||
{
|
||||
DBG_PRINTF("%d ms \r\n",t_ms);
|
||||
// sprintf(custom_tx_buffer, "Measure Time :%d ms \r\n",t_ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
t_ms++;
|
||||
imm_check_timer_start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void imm_adc_start_init(void)
|
||||
{
|
||||
if (ble_got_new_data ==true)
|
||||
{
|
||||
pd_adc_imm_start=false;
|
||||
pd_adc_imm_running=false;
|
||||
DBG_PRINTF ("FINISH SEND\r\n");
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
processing = false;
|
||||
custom_testing = false;
|
||||
imm_adc_end_final();
|
||||
}
|
||||
|
||||
else if (pd_adc_imm_running==true){
|
||||
imm_adc_start();
|
||||
}
|
||||
|
||||
else if (pd_adc_imm_start==true)
|
||||
{
|
||||
// custom_testing = false;
|
||||
// motion_raw_data_enabled = true;
|
||||
// custom_add_data = true;
|
||||
// icm42670_main();
|
||||
//for(uint8_t i =0; i < imm_LED_NO; i++) {
|
||||
LED_list_imm[0] = sel_led_index0;
|
||||
LED_list_imm[1] = sel_led_index1;
|
||||
LED_list_imm[2] = sel_led_index2;
|
||||
LED_list_imm[3] = sel_led_index3;
|
||||
// data_tx_handler(ble_tx_buffer);
|
||||
|
||||
t_ms=0;
|
||||
pd_adc_imm_start=false;
|
||||
pd_adc_imm_running=true;
|
||||
custom_testing = true;
|
||||
// custom_check_timer_start();
|
||||
c_cnt=0;
|
||||
// pd_adc_custom_start=false;
|
||||
// pd_adc_custom_a_start=true;
|
||||
|
||||
imm_adc_start2();
|
||||
imm_check_timer_start();
|
||||
c_cnt++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void imm_adc_start(void)
|
||||
{
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
buf_no = 0;
|
||||
t_ms=0;
|
||||
|
||||
|
||||
for(uint16_t i = 0; i < 4; i++) {
|
||||
for(uint16_t j = 0; j < imm_CYCLE_CNT; j++) {
|
||||
imm_cycle_buff[i][j] = 0;
|
||||
}
|
||||
}
|
||||
if(order_imm>=15){
|
||||
order_imm=0;
|
||||
}
|
||||
else
|
||||
{ order_imm++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void imm_adc_start2(void)
|
||||
{
|
||||
imm_adc_start();
|
||||
imm_adc_init();
|
||||
imm_irq_init();
|
||||
imm_ppi_init();
|
||||
imm_sampling_event_enable();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void imm_adc_end(void)
|
||||
{
|
||||
|
||||
DBG_PRINTF("adc_end\r\n");
|
||||
|
||||
imm_sampling_event_disable();
|
||||
|
||||
}
|
||||
|
||||
void imm_adc_end_final(void)
|
||||
{
|
||||
|
||||
DBG_PRINTF("adc_end_for_good\r\n");
|
||||
|
||||
imm_sampling_event_disable();
|
||||
imm_irq_uninit();
|
||||
imm_ppi_uninit();
|
||||
imm_adc_uninit();
|
||||
battery_timer_start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void imm_adc_init(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("custom_adc_init\r\n");
|
||||
#endif
|
||||
|
||||
static nrfx_saadc_config_t default_config;
|
||||
default_config.resolution = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION; /* Resolution is 10bits */
|
||||
default_config.oversample = (nrf_saadc_oversample_t)NRFX_SAADC_CONFIG_OVERSAMPLE; /* Over Sampling Disabled */
|
||||
default_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY; /* Interrupt Priority is 0(Highest) */
|
||||
default_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE; /* Low Power Mode is Disabled */
|
||||
|
||||
static nrf_saadc_channel_config_t config;
|
||||
config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.gain = NRF_SAADC_GAIN1_6;
|
||||
config.reference = NRF_SAADC_REFERENCE_INTERNAL;
|
||||
config.acq_time = NRF_SAADC_ACQTIME_3US;
|
||||
config.mode = NRF_SAADC_MODE_DIFFERENTIAL;
|
||||
config.burst = NRF_SAADC_BURST_DISABLED;
|
||||
config.pin_p = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN0);
|
||||
config.pin_n = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN1);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_init(&default_config, imm_voltage_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(pd_imm_adc_buf[0], imm_samples_in_buffer + m_pd_delay_us/16);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void imm_adc_uninit(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("pd_custom_adc_uninit\r\n");
|
||||
#endif
|
||||
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
}
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void imm_irq_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
/* Initialize int pin */
|
||||
if (!nrfx_gpiote_is_init())
|
||||
{
|
||||
err_code = nrfx_gpiote_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
|
||||
in_config.pull = NRF_GPIO_PIN_PULLDOWN;
|
||||
|
||||
err_code = nrfx_gpiote_in_init(ADA2200_SYNCO_PIN, &in_config, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_gpiote_in_event_enable(ADA2200_SYNCO_PIN, true);
|
||||
}
|
||||
|
||||
|
||||
void imm_irq_uninit(void)
|
||||
{
|
||||
nrfx_gpiote_in_event_disable(ADA2200_SYNCO_PIN);
|
||||
nrfx_gpiote_in_uninit(ADA2200_SYNCO_PIN);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void imm_check_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_custom_check_loop_timer_id, APP_TIMER_TICKS(CUSTOM_CHECK_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void imm_check_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_custom_check_loop_timer_id));
|
||||
|
||||
}
|
||||
void imm_check_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_custom_check_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, imm_check_loop));
|
||||
}
|
||||
58
project/ble_peripheral/ble_app_bladder_patch/meas_pd_imm.h
Normal file
58
project/ble_peripheral/ble_app_bladder_patch/meas_pd_imm.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* @file meas_pd_imm.h
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MEAS_PD_IMM_H__
|
||||
#define _MEAS_PD_IMM_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
|
||||
#define ADA2200_SYNCO_PIN NRF_GPIO_PIN_MAP(0,17)
|
||||
|
||||
|
||||
#define imm_PD_NO 1/////4
|
||||
#define imm_LED_NO 4////5
|
||||
#define imm_CYCLE_CNT 8 ////32
|
||||
|
||||
|
||||
void imm_ppi_init(void);
|
||||
void imm_ppi_uninit(void);
|
||||
void imm_sampling_event_enable(void);
|
||||
void imm_sampling_event_disable(void);
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void imm_voltage_handler(nrf_drv_saadc_evt_t const * p_event); /* PD Voltage reading */
|
||||
void imm_adc_start_init(void);
|
||||
void imm_adc_start(void);
|
||||
void imm_adc_start2(void);
|
||||
//void custom_adc_start2(void);
|
||||
//void custom_adc_total_start(void);
|
||||
void imm_adc_end(void);
|
||||
void imm_adc_end_final(void);
|
||||
void imm_adc_init(void);
|
||||
void imm_adc_uninit(void);
|
||||
|
||||
void imm_irq_init(void);
|
||||
void imm_irq_uninit(void);
|
||||
|
||||
//void custom_send_start(void);
|
||||
|
||||
//void custom_send_loop(void * p_context); /* For x ms */
|
||||
//void custom_send_timer_start(void);
|
||||
//void custom_send_timer_stop(void);;
|
||||
//void custom_send_timer_init(void);
|
||||
|
||||
|
||||
void imm_check_loop(void * p_context);
|
||||
void imm_check_timer_start(void);
|
||||
void imm_check_timer_stop(void);;
|
||||
void imm_check_timer_init(void);
|
||||
|
||||
#endif /* _MEAS_PD_VOLTAGE_CUSTOM_H__ */
|
||||
|
||||
@@ -0,0 +1,885 @@
|
||||
/*******************************************************************************
|
||||
TEST medi50 Dec 23
|
||||
******************************************************************************/
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "app_timer.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "ada2200_spi.h"
|
||||
#include "ble_nus.h"
|
||||
#include "fstorage.h"
|
||||
#include "measurements.h"
|
||||
#include "meas_pd_voltage_custom.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "main_timer.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "main.h"
|
||||
#include "app_raw_main.h"
|
||||
|
||||
#define CUSTOM_REF_VOLTAGE_IN_MILLIVOLTS 600.0f /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
|
||||
#define CUSTOM_PRE_SCALING_COMPENSATION 6.0f /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
|
||||
#define CUSTOM_ADC_RES_10BITS 1024.0f /**< Maximum digital value for 10-bit ADC conversion. */
|
||||
#define st_c_max 20
|
||||
/**@brief Macro to convert the result of ADC conversion in millivolts.
|
||||
*
|
||||
* @param[in] ADC_VALUE ADC result.
|
||||
*
|
||||
* @retval Result converted to millivolts.
|
||||
*/
|
||||
#define CUSTOM_VOUT_IN_MILLI_VOLTS(ADC_VALUE)\
|
||||
(((((ADC_VALUE) * CUSTOM_REF_VOLTAGE_IN_MILLIVOLTS) / CUSTOM_ADC_RES_10BITS) * CUSTOM_PRE_SCALING_COMPENSATION)*2)
|
||||
|
||||
|
||||
uint8_t custom_samples_in_buffer = 8;
|
||||
|
||||
uint32_t s_cnt;
|
||||
uint8_t LED_list_custom[5];
|
||||
uint8_t PD_list_custom[4];
|
||||
|
||||
uint8_t led_custom_list_a[5] = {2,3,4,5,6};
|
||||
uint8_t pd_custom_list_a[4] = {5,7,8,10};
|
||||
|
||||
uint8_t led_custom_list_b[5] = {20,21,22,23,24};
|
||||
uint8_t pd_custom_list_b[4] = {16,14,13,11};
|
||||
|
||||
int32_t c_max;
|
||||
extern volatile bool processing;
|
||||
extern volatile bool data_tx_in_progress;
|
||||
extern volatile bool ble_connection_st;
|
||||
|
||||
|
||||
uint32_t c_cnt;
|
||||
static int8_t pd_no = -1;
|
||||
static int8_t led_no = -1;
|
||||
static int8_t buf_no = 0;
|
||||
//static int8_t c_max = 5;
|
||||
static int32_t t_ms = 0;
|
||||
double custom_cycle_buff[36][CUSTOM_CYCLE_CNT] =
|
||||
{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //10
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //11
|
||||
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //12
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //13
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //14
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //15
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //16
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //17
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //18
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //19
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //20
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //21
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //22
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //23
|
||||
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //24
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //25
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //26
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //27
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //28
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //29
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //30
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //31
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //32
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //33
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //34
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //35
|
||||
};
|
||||
double custom_cycle_send_buff[CUSTOM_LED_NO][CUSTOM_PD_NO] =
|
||||
{
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
||||
#define SAMPLES_IN_BUFFER 4095+32
|
||||
static nrf_saadc_value_t pd_custom_adc_buf[2][SAMPLES_IN_BUFFER];
|
||||
|
||||
bool pd_adc_custom_a_start = false;
|
||||
bool pd_adc_custom_b_start = false;
|
||||
bool pd_adc_custom_c_start = false;
|
||||
bool pd_adc_custom_d_start = false;
|
||||
bool pd_adc_custom_end = false;
|
||||
bool pd_adc_custom_start = false;
|
||||
|
||||
bool custom_testing = false;
|
||||
|
||||
//
|
||||
bool custom_add_data;
|
||||
extern bool motion_raw_data_enabled;
|
||||
extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
//add imu
|
||||
|
||||
|
||||
|
||||
char custom_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
|
||||
|
||||
|
||||
char custom_tx_d_buffer_0[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
char custom_tx_d_buffer_1[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
char custom_tx_d_buffer_2[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
char custom_tx_d_buffer_3[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
char custom_tx_d_buffer_4[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
|
||||
char custom_tx_d_buffer_5[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
char custom_tx_d_buffer_6[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
char custom_tx_d_buffer_7[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
char custom_tx_d_buffer_8[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
char custom_tx_d_buffer_9[st_c_max][BLE_NUS_MAX_DATA_LEN];
|
||||
|
||||
|
||||
|
||||
extern which_cmd_t cmd_type_t;
|
||||
|
||||
APP_TIMER_DEF(m_custom_check_loop_timer_id);
|
||||
APP_TIMER_DEF(m_custom_send_loop_timer_id);
|
||||
#if FEATURE_DELAY
|
||||
#define CUSTOM_SEND_LOOP_INTERVAL 500
|
||||
#else
|
||||
#define CUSTOM_SEND_LOOP_INTERVAL 100
|
||||
#endif
|
||||
#define CUSTOM_CHECK_LOOP_INTERVAL 1
|
||||
|
||||
|
||||
|
||||
#if FEATURE_DEBUG_REPEAT_TEST
|
||||
extern uint32_t rpt_cnt;
|
||||
#endif
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
APP_TIMER_DEF(m_custom_loop_timer_id);
|
||||
#define CUSTOM_LOOP_INTERVAL 1
|
||||
|
||||
void custom_timer_loop(void * p_context)
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_sample();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
void custom_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_custom_loop_timer_id, APP_TIMER_TICKS(CUSTOM_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void custom_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_custom_loop_timer_id));
|
||||
}
|
||||
|
||||
void custom_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_custom_loop_timer_id, APP_TIMER_MODE_REPEATED, custom_timer_loop));
|
||||
}
|
||||
#else
|
||||
static nrf_ppi_channel_t m_ppi_channel;
|
||||
#endif
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void custom_ppi_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
uint32_t gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(ADA2200_SYNCO_PIN);
|
||||
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
|
||||
|
||||
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
|
||||
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
|
||||
gpiote_event_addr,
|
||||
saadc_sample_task_addr);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void custom_ppi_uninit(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_uninit();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void custom_sampling_event_enable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void custom_sampling_event_disable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_disable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void custom_voltage_handler(nrf_drv_saadc_evt_t const * p_event) /* PD Voltage reading */
|
||||
{
|
||||
ret_code_t err_code;
|
||||
double sum = 0.0f;
|
||||
|
||||
uint32_t custom_clk_delay = m_config.pd_delay_us/16;
|
||||
if(ble_connection_st == 0) {
|
||||
custom_adc_end();
|
||||
custom_send_timer_stop();
|
||||
printf("Custom ADC STOP 1\r\n");
|
||||
}
|
||||
|
||||
else{
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, custom_samples_in_buffer + custom_clk_delay);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
if(led_no == -1) {
|
||||
led_no = 0;
|
||||
pd_no = 0;
|
||||
|
||||
led_on(LED_list_custom[led_no]);
|
||||
led_pd_matching_value_set(LED_list_custom[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else {
|
||||
|
||||
for(uint16_t i = custom_clk_delay; i < custom_clk_delay + custom_samples_in_buffer; i++){
|
||||
custom_cycle_buff[buf_no][i-custom_clk_delay] = (CUSTOM_VOUT_IN_MILLI_VOLTS(p_event->data.done.p_buffer[i])) * -1;
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("-----------------Read ADC // led_no = %d(%d), pd_no = %d(%d), buf_no = %d\r\n\r\n", led_no, LED_list_custom[led_no], pd_no, PD_list_custom[pd_no], buf_no);
|
||||
#endif
|
||||
|
||||
buf_no++;
|
||||
|
||||
if(pd_no < CUSTOM_PD_NO - 1) {
|
||||
pd_no++;
|
||||
led_pd_matching_value_set(LED_list_custom[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
}else if(pd_no >= CUSTOM_PD_NO - 1) {
|
||||
pd_no = 0;
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
|
||||
if(led_no < CUSTOM_LED_NO - 1) {
|
||||
led_no++;
|
||||
led_on(LED_list_custom[led_no]);
|
||||
led_pd_matching_value_set(LED_list_custom[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else if(led_no >= CUSTOM_LED_NO - 1) {
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\nEnded\r\n");
|
||||
#endif
|
||||
custom_adc_end();
|
||||
|
||||
#if FEATURE_DETAIL_VALUE_CUSTOM
|
||||
sum = 0;
|
||||
printf("\r\nCustom_============custom_cycle_buff =\r\n");
|
||||
for(uint16_t i = 0; i < 36; i++){
|
||||
for(uint16_t j = 0; j < custom_samples_in_buffer; j++){
|
||||
printf("%lf\r\n", custom_cycle_buff[i][j]);
|
||||
}
|
||||
for(uint16_t k = 0; k < custom_samples_in_buffer; k++){
|
||||
sum += custom_cycle_buff[i][k];
|
||||
}
|
||||
printf("\t%lf\r\n", sum);
|
||||
sum = 0;
|
||||
}
|
||||
printf("\r\n");
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
uint8_t k =0;
|
||||
sum = 0;
|
||||
for(uint16_t i = 0; i < 20; i++){
|
||||
for(uint16_t j = 0; j < custom_samples_in_buffer; j++){
|
||||
sum += custom_cycle_buff[i][j];
|
||||
}
|
||||
|
||||
custom_cycle_send_buff[i/4][k++] = sum;
|
||||
sum = 0;
|
||||
|
||||
if(k >= 4) k = 0;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Send data */
|
||||
/*********************/
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
printf("S%dTi%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n",c_cnt, LED_list_custom[0], custom_cycle_send_buff[0][0], custom_cycle_send_buff[0][1], custom_cycle_send_buff[0][2], custom_cycle_send_buff[0][3]);//, custom_cycle_send_buff[0][4], custom_cycle_send_buff[0][5]);
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n", LED_list_custom[1], custom_cycle_send_buff[1][0], custom_cycle_send_buff[1][1], custom_cycle_send_buff[1][2], custom_cycle_send_buff[1][3]);//, custom_cycle_send_buff[1][4], custom_cycle_send_buff[1][5]);
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n", LED_list_custom[2], custom_cycle_send_buff[2][0], custom_cycle_send_buff[2][1], custom_cycle_send_buff[2][2], custom_cycle_send_buff[2][3]);//, custom_cycle_send_buff[2][4], custom_cycle_send_buff[2][5]);
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n", LED_list_custom[3], custom_cycle_send_buff[3][0], custom_cycle_send_buff[3][1], custom_cycle_send_buff[3][2], custom_cycle_send_buff[3][3]);//, custom_cycle_send_buff[3][4], custom_cycle_send_buff[3][5]);
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n", LED_list_custom[4], custom_cycle_send_buff[4][0], custom_cycle_send_buff[4][1], custom_cycle_send_buff[4][2], custom_cycle_send_buff[4][3]);//, custom_cycle_send_buff[4][4], custom_cycle_send_buff[4][5]);
|
||||
printf("\r\n");
|
||||
} else if(cmd_type_t == CMD_BLE ) {
|
||||
if(pd_adc_custom_a_start == true ) {
|
||||
sprintf(custom_tx_d_buffer_0[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n",c_cnt, LED_list_custom[0], custom_cycle_send_buff[0][0], custom_cycle_send_buff[0][1], custom_cycle_send_buff[0][2], custom_cycle_send_buff[0][3]);
|
||||
sprintf(custom_tx_d_buffer_1[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n",c_cnt, LED_list_custom[1], custom_cycle_send_buff[1][0], custom_cycle_send_buff[1][1], custom_cycle_send_buff[1][2], custom_cycle_send_buff[1][3]);
|
||||
sprintf(custom_tx_d_buffer_2[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n",c_cnt, LED_list_custom[2], custom_cycle_send_buff[2][0], custom_cycle_send_buff[2][1], custom_cycle_send_buff[2][2], custom_cycle_send_buff[2][3]);
|
||||
sprintf(custom_tx_d_buffer_3[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n",c_cnt, LED_list_custom[3], custom_cycle_send_buff[3][0], custom_cycle_send_buff[3][1], custom_cycle_send_buff[3][2], custom_cycle_send_buff[3][3]);
|
||||
sprintf(custom_tx_d_buffer_4[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\r\n",c_cnt, LED_list_custom[4], custom_cycle_send_buff[4][0], custom_cycle_send_buff[4][1], custom_cycle_send_buff[4][2], custom_cycle_send_buff[4][3]);
|
||||
|
||||
}else if(pd_adc_custom_b_start == true) {
|
||||
sprintf(custom_tx_d_buffer_5[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf\r\n",c_cnt, LED_list_custom[0], custom_cycle_send_buff[0][0], custom_cycle_send_buff[0][1], custom_cycle_send_buff[0][2], custom_cycle_send_buff[0][3]);
|
||||
sprintf(custom_tx_d_buffer_6[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf\r\n",c_cnt, LED_list_custom[1], custom_cycle_send_buff[1][0], custom_cycle_send_buff[1][1], custom_cycle_send_buff[1][2], custom_cycle_send_buff[1][3]);
|
||||
sprintf(custom_tx_d_buffer_7[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf\r\n",c_cnt, LED_list_custom[2], custom_cycle_send_buff[2][0], custom_cycle_send_buff[2][1], custom_cycle_send_buff[2][2], custom_cycle_send_buff[2][3]);
|
||||
sprintf(custom_tx_d_buffer_8[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf\r\n",c_cnt, LED_list_custom[3], custom_cycle_send_buff[3][0], custom_cycle_send_buff[3][1], custom_cycle_send_buff[3][2], custom_cycle_send_buff[3][3]);
|
||||
sprintf(custom_tx_d_buffer_9[c_cnt], "M%d,Ti%d,\t%lf,\t%lf,\t%lf,\t%lf\r\n",c_cnt, LED_list_custom[4], custom_cycle_send_buff[4][0], custom_cycle_send_buff[4][1], custom_cycle_send_buff[4][2], custom_cycle_send_buff[4][3]);
|
||||
|
||||
}
|
||||
}
|
||||
/*********************/
|
||||
|
||||
buf_no = 0;
|
||||
|
||||
if(ble_connection_st == 0) {
|
||||
custom_adc_end();
|
||||
custom_send_timer_stop();
|
||||
printf("Custom ADC STOP 1");
|
||||
}
|
||||
else if(pd_adc_custom_a_start == true) { // B mode
|
||||
pd_adc_custom_a_start = false;
|
||||
pd_adc_custom_b_start = true;
|
||||
|
||||
custom_adc_start();
|
||||
|
||||
}else if(pd_adc_custom_b_start == true) { // Completed
|
||||
pd_adc_custom_b_start = false;
|
||||
|
||||
|
||||
|
||||
// }
|
||||
// else if(pd_adc_custom_a_start == true) { // Completed
|
||||
// pd_adc_custom_a_start = false;
|
||||
|
||||
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
custom_send_timer_stop();
|
||||
|
||||
}else if(cmd_type_t == CMD_BLE) {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// if(ble_connection_st == 1) {
|
||||
// battery_timer_start();
|
||||
// }
|
||||
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
custom_adc_total_start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void custom_check_loop(void * p_context)
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
custom_check_timer_stop();
|
||||
if ( custom_testing == false)
|
||||
{
|
||||
printf("%d ms \r\n",t_ms);
|
||||
sprintf(custom_tx_buffer, "Measure Time :%d ms \r\n",t_ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
t_ms++;
|
||||
custom_check_timer_start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void custom_send_loop(void * p_context) /* For x ms */
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
custom_send_timer_stop();
|
||||
if(ble_connection_st){
|
||||
if (data_tx_in_progress==true) {
|
||||
// Data transmission is still in progress
|
||||
printf("skip \r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
static uint8_t order = 0;
|
||||
|
||||
switch(order) {
|
||||
case 0:
|
||||
data_tx_handler(custom_tx_d_buffer_0[s_cnt]);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
data_tx_handler(custom_tx_d_buffer_1[s_cnt]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
data_tx_handler(custom_tx_d_buffer_2[s_cnt]);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
data_tx_handler(custom_tx_d_buffer_3[s_cnt]);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
data_tx_handler(custom_tx_d_buffer_4[s_cnt]);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
data_tx_handler(custom_tx_d_buffer_5[s_cnt]);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
data_tx_handler(custom_tx_d_buffer_6[s_cnt]);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
data_tx_handler(custom_tx_d_buffer_7[s_cnt]);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
data_tx_handler(custom_tx_d_buffer_8[s_cnt]);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
data_tx_handler(custom_tx_d_buffer_9[s_cnt]);
|
||||
|
||||
|
||||
order = 0;
|
||||
custom_send_start();
|
||||
#if FEATURE_PRINTF
|
||||
printf("custom_send Completed\r\n");
|
||||
#endif
|
||||
|
||||
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(ble_connection_st == 0) {
|
||||
custom_send_timer_stop();
|
||||
order = 0;
|
||||
printf("Custom ADC STOP 2\r\n");}
|
||||
else{
|
||||
|
||||
|
||||
|
||||
|
||||
order++;
|
||||
custom_send_timer_start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void custom_send_start(void)
|
||||
{
|
||||
s_cnt++;
|
||||
if (s_cnt>c_max)
|
||||
{
|
||||
custom_send_timer_stop();
|
||||
|
||||
|
||||
data_tx_handler(ble_tx_buffer);
|
||||
data_tx_handler(custom_tx_buffer);
|
||||
battery_timer_start();
|
||||
}
|
||||
else
|
||||
{
|
||||
custom_send_timer_start();
|
||||
}
|
||||
}
|
||||
void custom_adc_total_start(void)
|
||||
{
|
||||
|
||||
if (pd_adc_custom_start==true)
|
||||
{
|
||||
// custom_testing = false;
|
||||
// motion_raw_data_enabled = true;
|
||||
// custom_add_data = true;
|
||||
// icm42670_main();
|
||||
//
|
||||
// data_tx_handler(ble_tx_buffer);
|
||||
|
||||
t_ms=0;
|
||||
custom_testing = true;
|
||||
custom_check_timer_start();
|
||||
c_cnt=0;
|
||||
pd_adc_custom_start=false;
|
||||
pd_adc_custom_a_start=true;
|
||||
custom_adc_start();
|
||||
c_cnt++;
|
||||
|
||||
}
|
||||
|
||||
else if (c_cnt<c_max)
|
||||
{
|
||||
pd_adc_custom_a_start=true;
|
||||
custom_adc_start();
|
||||
c_cnt++;
|
||||
}
|
||||
else if (c_cnt==c_max)
|
||||
{
|
||||
custom_testing = false;
|
||||
motion_raw_data_enabled = true;
|
||||
custom_add_data = true;
|
||||
icm42670_main();
|
||||
if(cmd_type_t == CMD_BLE){
|
||||
s_cnt=0;
|
||||
custom_send_start();
|
||||
|
||||
|
||||
}
|
||||
c_cnt++;
|
||||
printf ("FINISH SEND\r\n");
|
||||
processing = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void custom_adc_start(void)
|
||||
{
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
buf_no = 0;
|
||||
|
||||
if(pd_adc_custom_a_start == true) {
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n===== Custom_A start ====================\r\n");
|
||||
printf("LED : ");
|
||||
#endif
|
||||
for(uint8_t i =0; i < CUSTOM_LED_NO; i++) {
|
||||
LED_list_custom[i] = led_custom_list_a[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", LED_list_custom[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n");
|
||||
printf("PD : ");
|
||||
#endif
|
||||
for(uint8_t i =0; i < CUSTOM_PD_NO; i++) {
|
||||
PD_list_custom[i] = pd_custom_list_a[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", PD_list_custom[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if(pd_adc_custom_b_start == true) {
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n===== Custom_B start ====================\r\n");
|
||||
printf("LED : ");
|
||||
#endif
|
||||
for(uint8_t i =0; i < CUSTOM_LED_NO; i++) {
|
||||
LED_list_custom[i] = led_custom_list_b[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", LED_list_custom[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n");
|
||||
printf("PD : ");
|
||||
#endif
|
||||
|
||||
for(uint8_t i =0; i < CUSTOM_PD_NO; i++) {
|
||||
PD_list_custom[i] = pd_custom_list_b[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", PD_list_custom[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
// if(pd_adc_custom_c_start == true) {
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("\r\n===== Custom_C start ====================\r\n");
|
||||
// printf("LED : ");
|
||||
//#endif
|
||||
// for(uint8_t i =0; i < CUSTOM_LED_NO; i++) {
|
||||
// LED_list_custom[i] = led_custom_list_c[i];
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("%d ", LED_list_custom[i]);
|
||||
//#endif
|
||||
// }
|
||||
//
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("\r\n");
|
||||
// printf("PD : ");
|
||||
//#endif
|
||||
|
||||
// for(uint8_t i =0; i < CUSTOM_PD_NO; i++) {
|
||||
// PD_list_custom[i] = pd_custom_list_c[i];
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("%d ", PD_list_custom[i]);
|
||||
//#endif
|
||||
// }
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("\r\n\r\n");
|
||||
//#endif
|
||||
// }
|
||||
|
||||
// if(pd_adc_custom_d_start == true) {
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("\r\n===== Custom_D start ====================\r\n");
|
||||
// printf("LED : ");
|
||||
//#endif
|
||||
// for(uint8_t i =0; i < CUSTOM_LED_NO; i++) {
|
||||
// LED_list_custom[i] = led_custom_list_d[i];
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("%d ", LED_list_custom[i]);
|
||||
//#endif
|
||||
// }
|
||||
//
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("\r\n");
|
||||
// printf("PD : ");
|
||||
//#endif
|
||||
|
||||
// for(uint8_t i =0; i < CUSTOM_PD_NO; i++) {
|
||||
// PD_list_custom[i] = pd_custom_list_d[i];
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("%d ", PD_list_custom[i]);
|
||||
//#endif
|
||||
// }
|
||||
//#if FEATURE_PRINTF
|
||||
// printf("\r\n\r\n");
|
||||
//#endif
|
||||
// }
|
||||
|
||||
for(uint16_t i = 0; i < 72; i++) {
|
||||
for(uint16_t j = 0; j < CUSTOM_CYCLE_CNT; j++) {
|
||||
custom_cycle_buff[i][j] = 0.0f;
|
||||
}
|
||||
}
|
||||
for(uint8_t i = 0; i < CUSTOM_LED_NO; i++) {
|
||||
for(uint8_t j = 0; j < CUSTOM_PD_NO; j++) {
|
||||
custom_cycle_send_buff[i][j] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
custom_adc_start2();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void custom_adc_start2(void)
|
||||
{
|
||||
custom_adc_init();
|
||||
#if FEATURE_PRINTF
|
||||
custom_timer_init();
|
||||
custom_timer_start();
|
||||
#else
|
||||
custom_irq_init();
|
||||
custom_ppi_init();
|
||||
custom_sampling_event_enable();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void custom_adc_end(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("custom_adc_end\r\n");
|
||||
custom_timer_stop();
|
||||
#endif
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
custom_sampling_event_disable();
|
||||
custom_irq_uninit();
|
||||
custom_ppi_uninit();
|
||||
#endif
|
||||
custom_adc_uninit();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void custom_adc_end_2(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("custom_adc_end\r\n");
|
||||
custom_timer_stop();
|
||||
#endif
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
custom_sampling_event_disable();
|
||||
custom_irq_uninit();
|
||||
custom_ppi_uninit();
|
||||
#endif
|
||||
custom_adc_uninit();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void custom_adc_init(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("custom_adc_init\r\n");
|
||||
#endif
|
||||
|
||||
static nrfx_saadc_config_t default_config;
|
||||
default_config.resolution = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION; /* Resolution is 10bits */
|
||||
default_config.oversample = (nrf_saadc_oversample_t)NRFX_SAADC_CONFIG_OVERSAMPLE; /* Over Sampling Disabled */
|
||||
default_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY; /* Interrupt Priority is 0(Highest) */
|
||||
default_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE; /* Low Power Mode is Disabled */
|
||||
|
||||
static nrf_saadc_channel_config_t config;
|
||||
config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.gain = NRF_SAADC_GAIN1_6;
|
||||
config.reference = NRF_SAADC_REFERENCE_INTERNAL;
|
||||
config.acq_time = NRF_SAADC_ACQTIME_3US;
|
||||
config.mode = NRF_SAADC_MODE_DIFFERENTIAL;
|
||||
config.burst = NRF_SAADC_BURST_DISABLED;
|
||||
config.pin_p = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN0);
|
||||
config.pin_n = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN1);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_init(&default_config, custom_voltage_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(pd_custom_adc_buf[0], custom_samples_in_buffer + m_config.pd_delay_us/16);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void custom_adc_uninit(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("pd_custom_adc_uninit\r\n");
|
||||
#endif
|
||||
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
}
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void custom_irq_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
/* Initialize int pin */
|
||||
if (!nrfx_gpiote_is_init())
|
||||
{
|
||||
err_code = nrfx_gpiote_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
|
||||
in_config.pull = NRF_GPIO_PIN_PULLDOWN;
|
||||
|
||||
err_code = nrfx_gpiote_in_init(ADA2200_SYNCO_PIN, &in_config, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_gpiote_in_event_enable(ADA2200_SYNCO_PIN, true);
|
||||
}
|
||||
|
||||
|
||||
void custom_irq_uninit(void)
|
||||
{
|
||||
nrfx_gpiote_in_event_disable(ADA2200_SYNCO_PIN);
|
||||
nrfx_gpiote_in_uninit(ADA2200_SYNCO_PIN);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void custom_send_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_custom_send_loop_timer_id, APP_TIMER_TICKS(CUSTOM_SEND_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
|
||||
void custom_send_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_custom_send_loop_timer_id));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void custom_send_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_custom_send_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, custom_send_loop));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void custom_check_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_custom_check_loop_timer_id, APP_TIMER_TICKS(CUSTOM_CHECK_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void custom_check_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_custom_check_loop_timer_id));
|
||||
|
||||
}
|
||||
void custom_check_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_custom_check_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, custom_check_loop));
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* @file meas_pd_voltage_custom.h
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MEAS_PD_VOLTAGE_CUSTOM_H__
|
||||
#define _MEAS_PD_VOLTAGE_CUSTOM_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
|
||||
#define ADA2200_SYNCO_PIN NRF_GPIO_PIN_MAP(0,17)
|
||||
|
||||
|
||||
#define CUSTOM_PD_NO 4
|
||||
#define CUSTOM_LED_NO 5
|
||||
#define CUSTOM_CYCLE_CNT 32
|
||||
|
||||
|
||||
void custom_ppi_init(void);
|
||||
void custom_ppi_uninit(void);
|
||||
void custom_sampling_event_enable(void);
|
||||
void custom_sampling_event_disable(void);
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void imm_voltage_handler(nrf_drv_saadc_evt_t const * p_event); /* PD Voltage reading */
|
||||
void custom_adc_start(void);
|
||||
void custom_adc_start2(void);
|
||||
void custom_adc_total_start(void);
|
||||
void custom_adc_end(void);
|
||||
void custom_adc_end_2(void);
|
||||
void custom_adc_init(void);
|
||||
void custom_adc_uninit(void);
|
||||
#if !FEATURE_PRINTF
|
||||
void custom_irq_init(void);
|
||||
void custom_irq_uninit(void);
|
||||
#endif
|
||||
void custom_send_start(void);
|
||||
|
||||
|
||||
|
||||
void custom_send_loop(void * p_context); /* For x ms */
|
||||
void custom_send_timer_start(void);
|
||||
void custom_send_timer_stop(void);;
|
||||
void custom_send_timer_init(void);
|
||||
|
||||
|
||||
void custom_check_loop(void * p_context);
|
||||
void custom_check_timer_start(void);
|
||||
void custom_check_timer_stop(void);;
|
||||
void custom_check_timer_init(void);
|
||||
|
||||
#endif /* _MEAS_PD_VOLTAGE_CUSTOM_H__ */
|
||||
|
||||
@@ -0,0 +1,944 @@
|
||||
/*******************************************************************************
|
||||
TEST medi50 Dec 23
|
||||
******************************************************************************/
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "app_timer.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "ada2200_spi.h"
|
||||
#include "ble_nus.h"
|
||||
//#include "fstorage.h"
|
||||
#include "measurements.h"
|
||||
#include "meas_pd_voltage_full.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "main_timer.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "main.h"
|
||||
|
||||
|
||||
#define FULL_REF_VOLTAGE_IN_MILLIVOLTS 600.0f /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
|
||||
#define FULL_PRE_SCALING_COMPENSATION 6.0f /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
|
||||
#define FULL_ADC_RES_10BITS 1024.0f /**< Maximum digital value for 10-bit ADC conversion. */
|
||||
|
||||
/**@brief Macro to convert the result of ADC conversion in millivolts.
|
||||
*
|
||||
* @param[in] ADC_VALUE ADC result.
|
||||
*
|
||||
* @retval Result converted to millivolts.
|
||||
*/
|
||||
#define FULL_VOUT_IN_MILLI_VOLTS(ADC_VALUE)\
|
||||
(((((ADC_VALUE) * FULL_REF_VOLTAGE_IN_MILLIVOLTS) / FULL_ADC_RES_10BITS) * FULL_PRE_SCALING_COMPENSATION)*2)
|
||||
|
||||
|
||||
//nrfjprog --family NRF52 --erasepag 0x27000-0xF7000
|
||||
static const uint8_t pd_full_type0[1] = {0};
|
||||
static const uint8_t pd_full_type1[1] = {1};
|
||||
//static const uint8_t pd_full_type2[1] = {2};
|
||||
//static const uint8_t led_full_list_type0[24] = {0,1,2,3,4,5,10,11,12,13,14,15,20,21,22,23,24,25,30,31,32,33,34,35};
|
||||
static const uint8_t led_full_list_type0[24] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
|
||||
|
||||
//static const uint8_t led_full_list_type1[24] = {40,41,42,43,44,45,50,51,52,53,54,55,60,61,62,63,64,65,70,71,72,73,74,75};
|
||||
|
||||
//static const uint8_t led_full_list_type3[24] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
|
||||
static const uint8_t led_full_list_type1[24] = {24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47};
|
||||
|
||||
//static const uint16_t delay_pd_led[3][50] = { {50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,500,500,500,500,500,500,500,500,500,50,50,50,50,500,500,50,50,50,50,50,50,50,50,500,50}
|
||||
// ,{4000,4000,4000,4000,4000,4000,500,500,500,50,50,50,50,500,500,50,50,50,50,50,50,50,50,500,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50}
|
||||
// ,{100,50,50,200,50,50,50,50,50,50,50,50,50,500,500,1000,500,50,50,50,500,50,500,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50}
|
||||
// };
|
||||
bool full_testing = false;
|
||||
bool full_testing_result = false;
|
||||
static int32_t t_ms = 0;
|
||||
uint8_t full_samples_in_buffer = 8;
|
||||
|
||||
uint8_t add_cycle = 0;
|
||||
uint8_t LED_list_full[24];
|
||||
uint8_t PD_list_full[1];
|
||||
|
||||
//uint8_t led_full_list_a[25] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
uint8_t led_full_list_a[24];
|
||||
uint8_t pd_full_list_a[1];
|
||||
|
||||
uint8_t led_full_list_b[24];
|
||||
uint8_t pd_full_list_b[1];
|
||||
|
||||
|
||||
|
||||
|
||||
//uint8_t led_full_list_c[25] = {25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49};
|
||||
|
||||
//uint8_t pd_full_list_c[1] = {2};
|
||||
|
||||
extern volatile uint8_t Sj_type;
|
||||
extern volatile bool processing;
|
||||
//static int8_t pd_no = -1;
|
||||
static int8_t PD_list_full_nameA=0;
|
||||
static int8_t PD_list_full_nameB=0;
|
||||
static int8_t led_no = -1;
|
||||
static int8_t buf_no = 0;
|
||||
uint16_t buf_cnt = 0;
|
||||
uint8_t full_bin_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
static uint8_t order = 0;
|
||||
char full_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
extern uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] ;
|
||||
double full_cycle_buff[24][FULL_CYCLE_CNT] =
|
||||
{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //10
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //11
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //12
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //13
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //14
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //15
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //16
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //17
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //18
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //19
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //20
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //21
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //22
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //23
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
int16_t bi_full_cycle_buff[24][FULL_CYCLE_CNT] =
|
||||
{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //10
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //11
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //12
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //13
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //14
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //15
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //16
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //17
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //18
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //19
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //20
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //21
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //22
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //23
|
||||
|
||||
};
|
||||
|
||||
double full_cycle_send_buff[FULL_LED_NO] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
int16_t bi_full_cycle_send_buff[FULL_LED_NO] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
|
||||
uint16_t bi_full_cycle_send_buff_total[48] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
#define SAMPLES_IN_BUFFER 4095+32
|
||||
static nrf_saadc_value_t pd_full_adc_buf[2][SAMPLES_IN_BUFFER];
|
||||
|
||||
bool pd_adc_full_a_start = false;
|
||||
bool pd_adc_full_b_start = false;
|
||||
bool pd_adc_full_c_start = false;
|
||||
bool pd_adc_full_d_start = false;
|
||||
bool pd_adc_full_end = false;
|
||||
|
||||
|
||||
char full_tx_buffer_0[BLE_NUS_MAX_DATA_LEN];
|
||||
char full_tx_buffer_1[BLE_NUS_MAX_DATA_LEN];
|
||||
char full_tx_buffer_2[BLE_NUS_MAX_DATA_LEN];
|
||||
char full_tx_buffer_3[BLE_NUS_MAX_DATA_LEN];
|
||||
char full_tx_buffer_4[BLE_NUS_MAX_DATA_LEN];
|
||||
char full_tx_buffer_5[BLE_NUS_MAX_DATA_LEN];
|
||||
extern which_cmd_t cmd_type_t;
|
||||
extern uint16_t m_pd_delay_us;
|
||||
|
||||
APP_TIMER_DEF(m_full_send_loop_timer_id);
|
||||
#if FEATURE_DELAY
|
||||
#define FULL_SEND_LOOP_INTERVAL 500 /* BLE Send Timer, Full_Mode Processing은 PPI로!!! */
|
||||
#else
|
||||
#define FULL_SEND_LOOP_INTERVAL 100
|
||||
#endif
|
||||
extern volatile bool ble_connection_st;
|
||||
|
||||
|
||||
|
||||
APP_TIMER_DEF(m_full_check_loop_timer_id);
|
||||
|
||||
#define FULL_CHECK_LOOP_INTERVAL 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
APP_TIMER_DEF(m_full_loop_timer_id);
|
||||
#define FULL_LOOP_INTERVAL 1
|
||||
|
||||
void full_timer_loop(void * p_context)
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_sample();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
void full_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_full_loop_timer_id, APP_TIMER_TICKS(FULL_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void full_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_full_loop_timer_id));
|
||||
}
|
||||
|
||||
void full_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_full_loop_timer_id, APP_TIMER_MODE_REPEATED, full_timer_loop));
|
||||
}
|
||||
#else
|
||||
static nrf_ppi_channel_t m_ppi_channel;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void full_ppi_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
uint32_t gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(ADA2200_SYNCO_PIN);
|
||||
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
|
||||
|
||||
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
|
||||
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
|
||||
gpiote_event_addr,
|
||||
saadc_sample_task_addr);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
void full_check_loop(void * p_context)
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
full_check_timer_stop();
|
||||
if ( full_testing == false)
|
||||
{
|
||||
// printf("%d ms \r\n",t_ms);
|
||||
// sprintf(full_tx_buffer, "Measure Time :%d ms \r\n",t_ms);
|
||||
// data_tx_handler(full_tx_buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
t_ms++;
|
||||
full_check_timer_start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void full_ppi_uninit(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_uninit();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void full_sampling_event_enable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void full_sampling_event_disable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_disable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void full_voltage_handler(nrf_drv_saadc_evt_t const * p_event) /* PD Voltage reading */
|
||||
{
|
||||
ret_code_t err_code;
|
||||
double sum = 0.0f;
|
||||
int16_t bi_sum = 0;
|
||||
uint32_t full_clk_delay;
|
||||
|
||||
|
||||
|
||||
//full_clk_delay = delay_pd_led[PD_list_full[pd_no]][LED_list_full[led_no]];
|
||||
//printf("index %d,%d, %d \r\n",PD_list_full[pd_no],LED_list_full[led_no],led_no);
|
||||
|
||||
full_clk_delay = m_pd_delay_us/16;
|
||||
|
||||
|
||||
// printf("m: %d \r\n",full_clk_delay);
|
||||
|
||||
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, full_samples_in_buffer + full_clk_delay);
|
||||
// err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, full_samples_in_buffer );
|
||||
APP_ERROR_CHECK(err_code);
|
||||
//buf_cnt++;
|
||||
|
||||
if(led_no == -1) {
|
||||
|
||||
//pd_no = 0;
|
||||
|
||||
// printf("WHY %d\r\n",led_no);
|
||||
led_no = 0;
|
||||
led_on(LED_list_full[led_no]);
|
||||
led_pd_matching_value_set(LED_list_full[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
nrf_delay_ms(5);
|
||||
} else {
|
||||
|
||||
|
||||
for(uint16_t i = full_clk_delay; i < full_clk_delay + full_samples_in_buffer; i++){
|
||||
bi_full_cycle_buff[buf_no][i-full_clk_delay] =(p_event->data.done.p_buffer[i]) * 1; //-1
|
||||
full_cycle_buff[buf_no][i-full_clk_delay] = (FULL_VOUT_IN_MILLI_VOLTS(p_event->data.done.p_buffer[i])) * 1; //-1
|
||||
//printf("buff %d\r\n",sizeof(p_event->data.done.p_buffer));
|
||||
|
||||
//printf("BUFF ,%f,%f,%d,%d, %d %d\r\n", FULL_VOUT_IN_MILLI_VOLTS(p_event->data.done.p_buffer[i]),FULL_VOUT_IN_MILLI_VOLTS(p_event->data.done.p_buffer[full_clk_delay]),buf_no,i-full_clk_delay,i,full_clk_delay);
|
||||
|
||||
if(i-full_clk_delay ==7)
|
||||
{
|
||||
// nrf_delay_us(1);
|
||||
// printf("\r\n");
|
||||
if(buf_no==0)
|
||||
{
|
||||
// full_testing = false;
|
||||
// printf("BUFF ,%f,%d,%d,%d, %d %d\r\n", FULL_VOUT_IN_MILLI_VOLTS(p_event->data.done.p_buffer[i]),p_event->data.done.p_buffer[i],buf_no,i-full_clk_delay,i,full_clk_delay);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
buf_no++;
|
||||
|
||||
//if(pd_no >= FULL_PD_NO -1) {
|
||||
//pd_no = 0;
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
|
||||
if(led_no < FULL_LED_NO-1 ) {
|
||||
led_no++;
|
||||
led_on(LED_list_full[led_no]);
|
||||
led_pd_matching_value_set(LED_list_full[led_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else if(led_no >= FULL_LED_NO -1) {
|
||||
//pd_no = -1;
|
||||
led_no = -1;
|
||||
printf("noled\r\n");
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\nEnded\r\n");
|
||||
#endif
|
||||
full_adc_end();
|
||||
|
||||
|
||||
// uint8_t k =0;
|
||||
sum = 0;
|
||||
for(uint16_t i = 0; i < 24; i++){
|
||||
for(uint16_t j = 0; j < full_samples_in_buffer; j++){
|
||||
sum += full_cycle_buff[i][j];
|
||||
}
|
||||
full_cycle_send_buff[i] = sum;
|
||||
sum = 0;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
bi_sum = 0;
|
||||
for(uint16_t i = 0; i < 24; i++){
|
||||
for(uint16_t j = 0; j < full_samples_in_buffer; j++){
|
||||
bi_sum += bi_full_cycle_buff[i][j];
|
||||
}
|
||||
bi_full_cycle_send_buff[i] = bi_sum;
|
||||
bi_sum = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Send data */
|
||||
/*********************/
|
||||
|
||||
|
||||
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
printf("Tj%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", PD_list_full[0], full_cycle_send_buff[0],full_cycle_send_buff[1],full_cycle_send_buff[2],full_cycle_send_buff[3],full_cycle_send_buff[4],full_cycle_send_buff[5],full_cycle_send_buff[6],full_cycle_send_buff[7],full_cycle_send_buff[8],full_cycle_send_buff[9],full_cycle_send_buff[10],
|
||||
full_cycle_send_buff[11],full_cycle_send_buff[12],full_cycle_send_buff[13],full_cycle_send_buff[14],full_cycle_send_buff[15],full_cycle_send_buff[16],full_cycle_send_buff[17],full_cycle_send_buff[18],full_cycle_send_buff[19],full_cycle_send_buff[20],
|
||||
full_cycle_send_buff[21],full_cycle_send_buff[22],full_cycle_send_buff[23]);
|
||||
printf("\r\n");
|
||||
} else if(cmd_type_t == CMD_BLE) {
|
||||
if(pd_adc_full_a_start == true) {
|
||||
|
||||
for(uint8_t i=0 ; i<24 ;i++)
|
||||
{
|
||||
bi_full_cycle_send_buff_total[i] = (uint16_t)bi_full_cycle_send_buff[i];
|
||||
}
|
||||
|
||||
|
||||
sprintf(full_tx_buffer_0,"Tj%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", PD_list_full_nameA, full_cycle_send_buff[0],full_cycle_send_buff[1],full_cycle_send_buff[2],full_cycle_send_buff[3],full_cycle_send_buff[4],full_cycle_send_buff[5],full_cycle_send_buff[6],full_cycle_send_buff[7],full_cycle_send_buff[8],full_cycle_send_buff[9],full_cycle_send_buff[10],
|
||||
full_cycle_send_buff[11]);
|
||||
if(Sj_type==0){
|
||||
sprintf(full_tx_buffer_1,"%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%1f,\r\n", full_cycle_send_buff[12],full_cycle_send_buff[13],full_cycle_send_buff[14],full_cycle_send_buff[15],full_cycle_send_buff[16],full_cycle_send_buff[17],full_cycle_send_buff[18],full_cycle_send_buff[19],full_cycle_send_buff[20],
|
||||
full_cycle_send_buff[21],full_cycle_send_buff[22],full_cycle_send_buff[23]);
|
||||
}
|
||||
else if(Sj_type==1){
|
||||
sprintf(full_tx_buffer_1,"%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%1fend\r\n", full_cycle_send_buff[12],full_cycle_send_buff[13],full_cycle_send_buff[14],full_cycle_send_buff[15],full_cycle_send_buff[16],full_cycle_send_buff[17],full_cycle_send_buff[18],full_cycle_send_buff[19],full_cycle_send_buff[20],
|
||||
full_cycle_send_buff[21],full_cycle_send_buff[22],full_cycle_send_buff[23]);
|
||||
}
|
||||
}
|
||||
else if(pd_adc_full_b_start == true){
|
||||
|
||||
for(uint8_t i=0 ; i<24 ;i++)
|
||||
{
|
||||
bi_full_cycle_send_buff_total[i+24] = (uint16_t)bi_full_cycle_send_buff[i];
|
||||
}
|
||||
sprintf(full_tx_buffer_2,"Tj%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", PD_list_full_nameB, full_cycle_send_buff[0],full_cycle_send_buff[1],full_cycle_send_buff[2],full_cycle_send_buff[3],full_cycle_send_buff[4],full_cycle_send_buff[5],full_cycle_send_buff[6],full_cycle_send_buff[7],full_cycle_send_buff[8],full_cycle_send_buff[9],full_cycle_send_buff[10],
|
||||
full_cycle_send_buff[11]);
|
||||
|
||||
sprintf(full_tx_buffer_3,"%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%1fend\r\n", full_cycle_send_buff[12],full_cycle_send_buff[13],full_cycle_send_buff[14],full_cycle_send_buff[15],full_cycle_send_buff[16],full_cycle_send_buff[17],full_cycle_send_buff[18],full_cycle_send_buff[19],full_cycle_send_buff[20],
|
||||
full_cycle_send_buff[21],full_cycle_send_buff[22],full_cycle_send_buff[23]);
|
||||
|
||||
// }else if(pd_adc_full_c_start == true) {
|
||||
// sprintf(full_tx_buffer_4,"Tj%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", PD_list_full[0], full_cycle_send_buff[0],full_cycle_send_buff[1],full_cycle_send_buff[2],full_cycle_send_buff[3],full_cycle_send_buff[4],full_cycle_send_buff[5],full_cycle_send_buff[6],full_cycle_send_buff[7],full_cycle_send_buff[8],full_cycle_send_buff[9],full_cycle_send_buff[10],
|
||||
// full_cycle_send_buff[11]);
|
||||
// sprintf(full_tx_buffer_5,"%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%1f,\t%1f\r\n", full_cycle_send_buff[12],full_cycle_send_buff[13],full_cycle_send_buff[14],full_cycle_send_buff[15],full_cycle_send_buff[16],full_cycle_send_buff[17],full_cycle_send_buff[18],full_cycle_send_buff[19],full_cycle_send_buff[20],
|
||||
// full_cycle_send_buff[21],full_cycle_send_buff[22],full_cycle_send_buff[23],full_cycle_send_buff[24]);
|
||||
}
|
||||
/*********************/
|
||||
|
||||
buf_no =0;
|
||||
|
||||
}
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
full_send_timer_stop();
|
||||
|
||||
}else if(cmd_type_t == CMD_BLE) {
|
||||
printf("Send\r\n");
|
||||
|
||||
printf("Tj%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", PD_list_full[0], full_cycle_send_buff[0],full_cycle_send_buff[1],full_cycle_send_buff[2],full_cycle_send_buff[3],full_cycle_send_buff[4],full_cycle_send_buff[5],full_cycle_send_buff[6],full_cycle_send_buff[7],full_cycle_send_buff[8],full_cycle_send_buff[9],full_cycle_send_buff[10],
|
||||
full_cycle_send_buff[11],full_cycle_send_buff[12],full_cycle_send_buff[13],full_cycle_send_buff[14],full_cycle_send_buff[15],full_cycle_send_buff[16],full_cycle_send_buff[17],full_cycle_send_buff[18],full_cycle_send_buff[19],full_cycle_send_buff[20],
|
||||
full_cycle_send_buff[21],full_cycle_send_buff[22],full_cycle_send_buff[23]);
|
||||
printf("\r\n");
|
||||
|
||||
|
||||
|
||||
printf("Tj%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n",
|
||||
PD_list_full[0],
|
||||
bi_full_cycle_send_buff[0], bi_full_cycle_send_buff[1], bi_full_cycle_send_buff[2], bi_full_cycle_send_buff[3],
|
||||
bi_full_cycle_send_buff[4], bi_full_cycle_send_buff[5], bi_full_cycle_send_buff[6], bi_full_cycle_send_buff[7],
|
||||
bi_full_cycle_send_buff[8], bi_full_cycle_send_buff[9], bi_full_cycle_send_buff[10], bi_full_cycle_send_buff[11],
|
||||
bi_full_cycle_send_buff[12], bi_full_cycle_send_buff[13], bi_full_cycle_send_buff[14], bi_full_cycle_send_buff[15],
|
||||
bi_full_cycle_send_buff[16], bi_full_cycle_send_buff[17], bi_full_cycle_send_buff[18], bi_full_cycle_send_buff[19],
|
||||
bi_full_cycle_send_buff[20], bi_full_cycle_send_buff[21], bi_full_cycle_send_buff[22], bi_full_cycle_send_buff[23]);
|
||||
|
||||
printf("\r\n");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//full_send_timer_start();
|
||||
}
|
||||
if(pd_adc_full_a_start == true) { // A mode
|
||||
pd_adc_full_a_start = false;
|
||||
|
||||
// if(Sj_type == 0){
|
||||
// full_adc_start();}
|
||||
// else{pd_adc_full_end = true;}
|
||||
if(Sj_type==0){
|
||||
pd_adc_full_b_start = true;
|
||||
full_adc_start();
|
||||
}
|
||||
else
|
||||
{ pd_adc_full_b_start = false;
|
||||
pd_adc_full_end = true;}
|
||||
|
||||
}else if(pd_adc_full_b_start == true) { // B mode
|
||||
pd_adc_full_b_start = false;
|
||||
pd_adc_full_end = true;
|
||||
|
||||
|
||||
if(ble_connection_st == 1) {
|
||||
battery_timer_start();
|
||||
}
|
||||
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
format_data(full_bin_buffer, "rsj:", bi_full_cycle_send_buff_total, 96);
|
||||
|
||||
|
||||
binary_tx_handler(full_bin_buffer,50);
|
||||
processing = false;
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void full_send_loop(void * p_context) /* For x ms */
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
full_send_timer_stop();
|
||||
|
||||
|
||||
|
||||
|
||||
switch(order) {
|
||||
case 0:
|
||||
data_tx_handler(full_tx_buffer_0);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
data_tx_handler(full_tx_buffer_1);
|
||||
if(Sj_type == 1)
|
||||
{order = 5;
|
||||
// full_testing = false;
|
||||
//return;
|
||||
break;}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
if(Sj_type == 0)
|
||||
{data_tx_handler(full_tx_buffer_2);}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if(Sj_type == 0)
|
||||
{data_tx_handler(full_tx_buffer_3);}
|
||||
order = 5;
|
||||
break;
|
||||
// sprintf(full_tx_buffer, "Measure Time :%d ms \r\n",t_ms);
|
||||
// data_tx_handler(full_tx_buffer);
|
||||
//
|
||||
//full_testing = false;
|
||||
// return;}
|
||||
|
||||
case 4:
|
||||
//data_tx_handler(full_tx_buffer_4);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
//data_tx_handler(full_tx_buffer_5);
|
||||
// order = 0;
|
||||
case 6:
|
||||
printf("Measure Time : %d ms \r\n",t_ms);
|
||||
//sprintf(full_tx_buffer, "Measure Time :%d ms \r\n",t_ms);
|
||||
// data_tx_handler(full_tx_buffer);
|
||||
order = 0;
|
||||
return;
|
||||
#if FEATURE_PRINTF
|
||||
printf("full_send Completed\r\n");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
order++;
|
||||
if(ble_connection_st == BLE_DISCONNECTED_ST) {
|
||||
// order=0;
|
||||
// full_send_timer_stop();
|
||||
// printf("Full ADC STOP 2\r\n");
|
||||
|
||||
}
|
||||
else{
|
||||
full_send_timer_start();
|
||||
}
|
||||
}
|
||||
void full_adc_start_first(uint8_t type,uint8_t PD_PICK ,uint8_t LED_PICK)
|
||||
{
|
||||
|
||||
|
||||
|
||||
switch(type){
|
||||
case 0:
|
||||
pd_full_list_a[0] = pd_full_type0[0];
|
||||
pd_full_list_b[0] = pd_full_type1[0];
|
||||
PD_list_full_nameA = 0;
|
||||
PD_list_full_nameB = 1;
|
||||
Sj_type =0;
|
||||
for (uint8_t i=0 ; i<24 ;i++)
|
||||
{
|
||||
led_full_list_a[i]= led_full_list_type0[i];
|
||||
led_full_list_b[i]= led_full_list_type1[i];
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
pd_full_list_a[0] = pd_full_type0[0];
|
||||
pd_full_list_b[0] = pd_full_type0[0];
|
||||
Sj_type =1;
|
||||
PD_list_full_nameA = 0;
|
||||
PD_list_full_nameB = 0;
|
||||
for (uint8_t i=0 ; i<24 ;i++)
|
||||
{
|
||||
led_full_list_a[i]= led_full_list_type1[i];
|
||||
led_full_list_b[i]= led_full_list_type1[i];
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
pd_full_list_a[0] = pd_full_type1[0];
|
||||
pd_full_list_b[0] = pd_full_type1[0];
|
||||
Sj_type =1;
|
||||
PD_list_full_nameA = 1;
|
||||
PD_list_full_nameB = 1;
|
||||
for (uint8_t i=0 ; i<24 ;i++)
|
||||
{
|
||||
led_full_list_a[i]= led_full_list_type0[i];
|
||||
led_full_list_b[i]= led_full_list_type0[i];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case 4:
|
||||
pd_full_list_a[0] =PD_PICK;
|
||||
pd_full_list_b[0] =PD_PICK;
|
||||
Sj_type =0;
|
||||
PD_list_full_nameA = PD_PICK*10;
|
||||
PD_list_full_nameB = PD_PICK*10+1;
|
||||
for (uint8_t i=0 ; i<24 ;i++)
|
||||
{
|
||||
led_full_list_a[i]= LED_PICK;
|
||||
led_full_list_b[i]= LED_PICK;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
pd_full_list_a[0] = pd_full_type1[0];
|
||||
pd_full_list_b[0] = pd_full_type0[0];
|
||||
Sj_type =0;
|
||||
PD_list_full_nameA = 1;
|
||||
PD_list_full_nameB = 0;
|
||||
for (uint8_t i=0 ; i<24 ;i++)
|
||||
{
|
||||
led_full_list_a[i]= led_full_list_type0[i];
|
||||
led_full_list_b[i]= led_full_list_type1[i];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
full_adc_start();
|
||||
|
||||
}
|
||||
void full_adc_start()
|
||||
{
|
||||
t_ms=0;
|
||||
full_check_timer_start();
|
||||
full_testing =true;
|
||||
|
||||
|
||||
//pd_no = 0;
|
||||
led_no = -1;
|
||||
buf_no = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(pd_adc_full_a_start == true) {
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n===== Full_A start ====================\r\n");
|
||||
printf("LED : ");
|
||||
#endif
|
||||
|
||||
for(uint8_t i =0; i < FULL_LED_NO; i++) {
|
||||
LED_list_full[i] = led_full_list_a[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", LED_list_full[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n");
|
||||
printf("PD : ");
|
||||
#endif
|
||||
// for(uint8_t i =0; i < FULL_PD_NO; i++) {
|
||||
PD_list_full[0] = pd_full_list_a[0];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", PD_list_full[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
// }
|
||||
|
||||
if(pd_adc_full_b_start == true) {
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n===== Full_B start ====================\r\n");
|
||||
printf("LED : ");
|
||||
|
||||
#endif
|
||||
for(uint8_t i =0; i < FULL_LED_NO; i++) {
|
||||
LED_list_full[i] = led_full_list_b[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", LED_list_full[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n");
|
||||
printf("PD : ");
|
||||
#endif
|
||||
|
||||
// for(uint8_t i =0; i < FULL_PD_NO; i++) {
|
||||
PD_list_full[0] = pd_full_list_b[0];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", PD_list_full[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(uint16_t i = 0; i < 24; i++) {
|
||||
for(uint16_t j = 0; j < FULL_CYCLE_CNT; j++) {
|
||||
full_cycle_buff[i][j] = 0.0f;
|
||||
}
|
||||
}
|
||||
for(uint8_t i = 0; i < FULL_LED_NO; i++) {
|
||||
|
||||
full_cycle_send_buff[i] = 0.0f;
|
||||
|
||||
}
|
||||
|
||||
|
||||
for(uint16_t i = 0; i < 24; i++) {
|
||||
for(uint16_t j = 0; j < FULL_CYCLE_CNT; j++) {
|
||||
bi_full_cycle_buff[i][j] = 0;
|
||||
}
|
||||
}
|
||||
for(uint8_t i = 0; i < FULL_LED_NO; i++) {
|
||||
|
||||
bi_full_cycle_send_buff[i] = 0;
|
||||
|
||||
}
|
||||
|
||||
full_adc_start2();
|
||||
order = 0;
|
||||
}
|
||||
|
||||
|
||||
void full_adc_start2(void)
|
||||
{
|
||||
full_adc_init();
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
full_timer_start();
|
||||
#else
|
||||
full_irq_init();
|
||||
full_ppi_init();
|
||||
full_sampling_event_enable();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void full_adc_end(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("full_adc_end\r\n");
|
||||
full_timer_stop();
|
||||
#endif
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
full_sampling_event_disable();
|
||||
full_irq_uninit();
|
||||
full_ppi_uninit();
|
||||
#endif
|
||||
full_adc_uninit();
|
||||
full_testing = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void full_adc_init(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("full_adc_init\r\n");
|
||||
#endif
|
||||
|
||||
static nrfx_saadc_config_t default_config;
|
||||
default_config.resolution = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION; /* Resolution is 10bits */
|
||||
default_config.oversample = (nrf_saadc_oversample_t)NRFX_SAADC_CONFIG_OVERSAMPLE; /* Over Sampling Disabled */
|
||||
default_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY; /* Interrupt Priority is 0(Highest) */
|
||||
default_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE; /* Low Power Mode is Disabled */
|
||||
|
||||
static nrf_saadc_channel_config_t config;
|
||||
config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.gain = NRF_SAADC_GAIN1_6;
|
||||
config.reference = NRF_SAADC_REFERENCE_INTERNAL;
|
||||
config.acq_time = NRF_SAADC_ACQTIME_3US; //3-->20
|
||||
config.mode = NRF_SAADC_MODE_DIFFERENTIAL;
|
||||
config.burst = NRF_SAADC_BURST_DISABLED;
|
||||
config.pin_p = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN0);
|
||||
config.pin_n = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN1);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_init(&default_config, full_voltage_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(pd_full_adc_buf[0], full_samples_in_buffer + m_pd_delay_us/16);//16
|
||||
APP_ERROR_CHECK(err_code);
|
||||
//printf("init");
|
||||
}
|
||||
|
||||
|
||||
void full_adc_uninit(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("pd_full_adc_uninit\r\n");
|
||||
#endif
|
||||
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
}
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void full_irq_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
/* Initialize int pin */
|
||||
if (!nrfx_gpiote_is_init())
|
||||
{
|
||||
err_code = nrfx_gpiote_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
|
||||
in_config.pull = NRF_GPIO_PIN_PULLDOWN;
|
||||
|
||||
err_code = nrfx_gpiote_in_init(ADA2200_SYNCO_PIN, &in_config, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_gpiote_in_event_enable(ADA2200_SYNCO_PIN, true);
|
||||
}
|
||||
|
||||
|
||||
void full_irq_uninit(void)
|
||||
{
|
||||
nrfx_gpiote_in_event_disable(ADA2200_SYNCO_PIN);
|
||||
nrfx_gpiote_in_uninit(ADA2200_SYNCO_PIN);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void full_send_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_full_send_loop_timer_id, APP_TIMER_TICKS(FULL_SEND_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
|
||||
void full_send_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_full_send_loop_timer_id));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void full_send_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_full_send_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, full_send_loop));
|
||||
}
|
||||
|
||||
void full_check_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_full_check_loop_timer_id, APP_TIMER_TICKS(FULL_CHECK_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void full_check_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_full_check_loop_timer_id));
|
||||
|
||||
}
|
||||
void full_check_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_full_check_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, full_check_loop));
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*******************************************************************************
|
||||
* @file meas_pd_voltage_full.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MEAS_PD_VOLTAGE_FULL_H__
|
||||
#define _MEAS_PD_VOLTAGE_FULL_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
|
||||
#define ADA2200_SYNCO_PIN NRF_GPIO_PIN_MAP(0,17)
|
||||
|
||||
|
||||
#define FULL_PD_NO 1
|
||||
#define FULL_LED_NO 24
|
||||
#define FULL_CYCLE_CNT 32 /* Dummy=65535/16us(Max Delay), Cycle_Max_Cnt=32*/
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
void full_timer_loop(void * p_context);
|
||||
void full_timer_start(void);
|
||||
void full_timer_stop(void);
|
||||
void full_timer_init(void);
|
||||
#endif
|
||||
|
||||
void full_ppi_init(void);
|
||||
void full_ppi_uninit(void);
|
||||
void full_sampling_event_enable(void);
|
||||
void full_sampling_event_disable(void);
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void full_voltage_handler(nrf_drv_saadc_evt_t const * p_event); /* PD Voltage reading */
|
||||
void full_adc_start_first(uint8_t type,uint8_t PD_PICK ,uint8_t LED_PICK);
|
||||
void full_adc_start(void);
|
||||
void full_adc_start2(void);
|
||||
void full_adc_end(void);
|
||||
void full_adc_init(void);
|
||||
void full_adc_uninit(void);
|
||||
#if !FEATURE_PRINTF
|
||||
void full_irq_init(void);
|
||||
void full_irq_uninit(void);
|
||||
#endif
|
||||
|
||||
void ble_Tx_process(void);
|
||||
void full_send_loop(void * p_context); /* For x ms */
|
||||
void full_send_timer_start(void);
|
||||
void full_send_timer_stop(void);;
|
||||
void full_send_timer_init(void);
|
||||
|
||||
|
||||
void full_check_loop(void * p_context);
|
||||
void full_check_timer_start(void);
|
||||
void full_check_timer_stop(void);;
|
||||
void full_check_timer_init(void);
|
||||
|
||||
#endif /* _MEAS_PD_VOLTAGE_FULL_H__ */
|
||||
|
||||
@@ -0,0 +1,836 @@
|
||||
/*******************************************************************************
|
||||
TEST medi50 Dec 23
|
||||
******************************************************************************/
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "app_timer.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "ada2200_spi.h"
|
||||
#include "ble_nus.h"
|
||||
#include "fstorage.h"
|
||||
#include "measurements.h"
|
||||
#include "meas_pd_voltage_half.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "main_timer.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "main.h"
|
||||
#include "power_control.h"
|
||||
#define HALF_REF_VOLTAGE_IN_MILLIVOLTS 600.0f /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
|
||||
#define HALF_PRE_SCALING_COMPENSATION 6.0f /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
|
||||
#define HALF_ADC_RES_10BITS 1024.0f /**< Maximum digital value for 10-bit ADC conversion. */
|
||||
|
||||
/**@brief Macro to convert the result of ADC conversion in millivolts.
|
||||
*
|
||||
* @param[in] ADC_VALUE ADC result.
|
||||
*
|
||||
* @retval Result converted to millivolts.
|
||||
*/
|
||||
#define HALF_VOUT_IN_MILLI_VOLTS(ADC_VALUE)\
|
||||
(((((ADC_VALUE) * HALF_REF_VOLTAGE_IN_MILLIVOLTS) / HALF_ADC_RES_10BITS) * HALF_PRE_SCALING_COMPENSATION)*2)
|
||||
|
||||
|
||||
uint8_t half_samples_in_buffer = 8;
|
||||
|
||||
|
||||
uint8_t LED_list_half[6];
|
||||
uint8_t PD_list_half[6];
|
||||
|
||||
uint8_t led_half_list_a[6] = {1,2,3,4,5,6};
|
||||
uint8_t pd_half_list_a[6] = {5,6,7,8,9,10};
|
||||
|
||||
uint8_t led_half_list_b[6] = {7,8,9,10,11,12};
|
||||
uint8_t pd_half_list_b[6] = {6,5,4,3,2,1};
|
||||
|
||||
uint8_t led_half_list_c[6] = {13,14,15,16,17,18};
|
||||
uint8_t pd_half_list_c[6] = {15,16,17,18,19,20};
|
||||
|
||||
uint8_t led_half_list_d[6] = {19,20,21,22,23,24};
|
||||
uint8_t pd_half_list_d[6] = {16,15,14,13,12,11};
|
||||
|
||||
bool prestatus;
|
||||
static int8_t pd_no = -1;
|
||||
static int8_t led_no = -1;
|
||||
static int8_t buf_no = 0;
|
||||
static uint8_t order = 0;
|
||||
double half_cycle_buff[36][HALF_CYCLE_CNT] =
|
||||
{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //10
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //11
|
||||
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //12
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //13
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //14
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //15
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //16
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //17
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //18
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //19
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //20
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //21
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //22
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //23
|
||||
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //24
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //25
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //26
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //27
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //28
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //29
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //30
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //31
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //32
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //33
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //34
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //35
|
||||
};
|
||||
double half_cycle_send_buff[HALF_LED_NO][HALF_PD_NO] =
|
||||
{
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
|
||||
#define SAMPLES_IN_BUFFER 4095+32
|
||||
static nrf_saadc_value_t pd_half_adc_buf[2][SAMPLES_IN_BUFFER];
|
||||
|
||||
bool pd_adc_half_a_start = false;
|
||||
bool pd_adc_half_b_start = false;
|
||||
bool pd_adc_half_c_start = false;
|
||||
bool pd_adc_half_d_start = false;
|
||||
bool pd_adc_half_end = false;
|
||||
|
||||
|
||||
char half_tx_buffer_0[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_1[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_2[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_3[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_4[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_5[BLE_NUS_MAX_DATA_LEN];
|
||||
|
||||
char half_tx_buffer_6[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_7[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_8[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_9[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_10[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_11[BLE_NUS_MAX_DATA_LEN];
|
||||
|
||||
char half_tx_buffer_12[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_13[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_14[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_15[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_16[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_17[BLE_NUS_MAX_DATA_LEN];
|
||||
|
||||
char half_tx_buffer_18[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_19[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_20[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_21[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_22[BLE_NUS_MAX_DATA_LEN];
|
||||
char half_tx_buffer_23[BLE_NUS_MAX_DATA_LEN];
|
||||
|
||||
extern which_cmd_t cmd_type_t;
|
||||
|
||||
|
||||
APP_TIMER_DEF(m_half_send_loop_timer_id);
|
||||
#if FEATURE_DELAY
|
||||
#define HALF_SEND_LOOP_INTERVAL 500
|
||||
#else
|
||||
#define HALF_SEND_LOOP_INTERVAL 100
|
||||
#endif
|
||||
|
||||
extern volatile bool ble_connection_st;
|
||||
#if FEATURE_DEBUG_REPEAT_TEST
|
||||
extern uint32_t rpt_cnt;
|
||||
#endif
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
APP_TIMER_DEF(m_half_loop_timer_id);
|
||||
#define HALF_LOOP_INTERVAL 1
|
||||
|
||||
void half_timer_loop(void * p_context)
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_sample();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
void half_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_half_loop_timer_id, APP_TIMER_TICKS(HALF_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
void half_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_half_loop_timer_id));
|
||||
}
|
||||
|
||||
void half_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_half_loop_timer_id, APP_TIMER_MODE_REPEATED, half_timer_loop));
|
||||
}
|
||||
#else
|
||||
static nrf_ppi_channel_t m_ppi_channel;
|
||||
#endif
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void half_ppi_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
uint32_t gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(ADA2200_SYNCO_PIN);
|
||||
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
|
||||
|
||||
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
|
||||
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
|
||||
gpiote_event_addr,
|
||||
saadc_sample_task_addr);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void half_ppi_uninit(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_uninit();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void half_sampling_event_enable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void half_sampling_event_disable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_disable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void half_voltage_handler(nrf_drv_saadc_evt_t const * p_event) /* PD Voltage reading */
|
||||
{
|
||||
ret_code_t err_code;
|
||||
double sum = 0.0f;
|
||||
|
||||
uint32_t half_clk_delay = m_config.pd_delay_us/16;
|
||||
if (prestatus==true)
|
||||
{ half_clk_delay =10;}
|
||||
if(ble_connection_st == 0) {
|
||||
half_adc_end();
|
||||
half_send_timer_stop();
|
||||
printf("Half ADC STOP 1\r\n");
|
||||
}
|
||||
|
||||
else{
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, half_samples_in_buffer + half_clk_delay);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
if(led_no == -1) {
|
||||
led_no = 0;
|
||||
pd_no = 0;
|
||||
|
||||
led_on(LED_list_half[led_no]);
|
||||
led_pd_matching_value_set(LED_list_half[led_no], PD_list_half[pd_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else {
|
||||
#if FEATURE_FOR_SCOPE
|
||||
nrf_gpio_pin_set(ADC_CLK_18);
|
||||
nrf_gpio_pin_clear(ADC_CLK_18);
|
||||
#endif
|
||||
for(uint16_t i = half_clk_delay; i < half_clk_delay + half_samples_in_buffer; i++){
|
||||
half_cycle_buff[buf_no][i-half_clk_delay] = (HALF_VOUT_IN_MILLI_VOLTS(p_event->data.done.p_buffer[i])) * -1;
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("-----------------Read ADC // led_no = %d(%d), pd_no = %d(%d), buf_no = %d\r\n\r\n", led_no, LED_list_half[led_no], pd_no, PD_list_half[pd_no], buf_no);
|
||||
#endif
|
||||
|
||||
buf_no++;
|
||||
|
||||
if(pd_no < HALF_PD_NO - 1) {
|
||||
pd_no++;
|
||||
led_pd_matching_value_set(LED_list_half[led_no], PD_list_half[pd_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
}else if(pd_no >= HALF_PD_NO - 1) {
|
||||
pd_no = 0;
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
|
||||
if(led_no < HALF_LED_NO - 1) {
|
||||
led_no++;
|
||||
led_on(LED_list_half[led_no]);
|
||||
led_pd_matching_value_set(LED_list_half[led_no], PD_list_half[pd_no]); /* MCP4725 DAC setting and PD on */
|
||||
|
||||
} else if(led_no >= HALF_LED_NO - 1) {
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\nEnded\r\n");
|
||||
#endif
|
||||
half_adc_end();
|
||||
|
||||
#if FEATURE_DETAIL_VALUE_HALF
|
||||
sum = 0;
|
||||
printf("\r\nHalf_============half_cycle_buff =\r\n");
|
||||
for(uint16_t i = 0; i < 36; i++){
|
||||
for(uint16_t j = 0; j < half_samples_in_buffer; j++){
|
||||
printf("%lf\r\n", half_cycle_buff[i][j]);
|
||||
}
|
||||
for(uint16_t k = 0; k < half_samples_in_buffer; k++){
|
||||
sum += half_cycle_buff[i][k];
|
||||
}
|
||||
printf("\t%lf\r\n", sum);
|
||||
sum = 0;
|
||||
}
|
||||
printf("\r\n");
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
uint8_t k =0;
|
||||
sum = 0;
|
||||
for(uint16_t i = 0; i < 36; i++){
|
||||
for(uint16_t j = 0; j < half_samples_in_buffer; j++){
|
||||
sum += half_cycle_buff[i][j];
|
||||
}
|
||||
|
||||
half_cycle_send_buff[i/6][k++] = sum;
|
||||
sum = 0;
|
||||
|
||||
if(k >= 6) k = 0;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* Send data */
|
||||
/*********************/
|
||||
if(cmd_type_t == CMD_UART && prestatus==false) {
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[0], half_cycle_send_buff[0][0], half_cycle_send_buff[0][1], half_cycle_send_buff[0][2], half_cycle_send_buff[0][3], half_cycle_send_buff[0][4], half_cycle_send_buff[0][5]);
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[1], half_cycle_send_buff[1][0], half_cycle_send_buff[1][1], half_cycle_send_buff[1][2], half_cycle_send_buff[1][3], half_cycle_send_buff[1][4], half_cycle_send_buff[1][5]);
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[2], half_cycle_send_buff[2][0], half_cycle_send_buff[2][1], half_cycle_send_buff[2][2], half_cycle_send_buff[2][3], half_cycle_send_buff[2][4], half_cycle_send_buff[2][5]);
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[3], half_cycle_send_buff[3][0], half_cycle_send_buff[3][1], half_cycle_send_buff[3][2], half_cycle_send_buff[3][3], half_cycle_send_buff[3][4], half_cycle_send_buff[3][5]);
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[4], half_cycle_send_buff[4][0], half_cycle_send_buff[4][1], half_cycle_send_buff[4][2], half_cycle_send_buff[4][3], half_cycle_send_buff[4][4], half_cycle_send_buff[4][5]);
|
||||
printf("Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[5], half_cycle_send_buff[5][0], half_cycle_send_buff[5][1], half_cycle_send_buff[5][2], half_cycle_send_buff[5][3], half_cycle_send_buff[5][4], half_cycle_send_buff[5][5]);
|
||||
printf("\r\n");
|
||||
} else if(cmd_type_t == CMD_BLE && prestatus==false) {
|
||||
if(pd_adc_half_a_start == true) {
|
||||
sprintf(half_tx_buffer_0, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[0], half_cycle_send_buff[0][0], half_cycle_send_buff[0][1], half_cycle_send_buff[0][2], half_cycle_send_buff[0][3], half_cycle_send_buff[0][4], half_cycle_send_buff[0][5]);
|
||||
sprintf(half_tx_buffer_1, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[1], half_cycle_send_buff[1][0], half_cycle_send_buff[1][1], half_cycle_send_buff[1][2], half_cycle_send_buff[1][3], half_cycle_send_buff[1][4], half_cycle_send_buff[1][5]);
|
||||
sprintf(half_tx_buffer_2, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[2], half_cycle_send_buff[2][0], half_cycle_send_buff[2][1], half_cycle_send_buff[2][2], half_cycle_send_buff[2][3], half_cycle_send_buff[2][4], half_cycle_send_buff[2][5]);
|
||||
sprintf(half_tx_buffer_3, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[3], half_cycle_send_buff[3][0], half_cycle_send_buff[3][1], half_cycle_send_buff[3][2], half_cycle_send_buff[3][3], half_cycle_send_buff[3][4], half_cycle_send_buff[3][5]);
|
||||
sprintf(half_tx_buffer_4, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[4], half_cycle_send_buff[4][0], half_cycle_send_buff[4][1], half_cycle_send_buff[4][2], half_cycle_send_buff[4][3], half_cycle_send_buff[4][4], half_cycle_send_buff[4][5]);
|
||||
sprintf(half_tx_buffer_5, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[5], half_cycle_send_buff[5][0], half_cycle_send_buff[5][1], half_cycle_send_buff[5][2], half_cycle_send_buff[5][3], half_cycle_send_buff[5][4], half_cycle_send_buff[5][5]);
|
||||
}else if(pd_adc_half_b_start == true) {
|
||||
sprintf(half_tx_buffer_6, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[0], half_cycle_send_buff[0][0], half_cycle_send_buff[0][1], half_cycle_send_buff[0][2], half_cycle_send_buff[0][3], half_cycle_send_buff[0][4], half_cycle_send_buff[0][5]);
|
||||
sprintf(half_tx_buffer_7, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[1], half_cycle_send_buff[1][0], half_cycle_send_buff[1][1], half_cycle_send_buff[1][2], half_cycle_send_buff[1][3], half_cycle_send_buff[1][4], half_cycle_send_buff[1][5]);
|
||||
sprintf(half_tx_buffer_8, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[2], half_cycle_send_buff[2][0], half_cycle_send_buff[2][1], half_cycle_send_buff[2][2], half_cycle_send_buff[2][3], half_cycle_send_buff[2][4], half_cycle_send_buff[2][5]);
|
||||
sprintf(half_tx_buffer_9, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[3], half_cycle_send_buff[3][0], half_cycle_send_buff[3][1], half_cycle_send_buff[3][2], half_cycle_send_buff[3][3], half_cycle_send_buff[3][4], half_cycle_send_buff[3][5]);
|
||||
sprintf(half_tx_buffer_10, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[4], half_cycle_send_buff[4][0], half_cycle_send_buff[4][1], half_cycle_send_buff[4][2], half_cycle_send_buff[4][3], half_cycle_send_buff[4][4], half_cycle_send_buff[4][5]);
|
||||
sprintf(half_tx_buffer_11, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[5], half_cycle_send_buff[5][0], half_cycle_send_buff[5][1], half_cycle_send_buff[5][2], half_cycle_send_buff[5][3], half_cycle_send_buff[5][4], half_cycle_send_buff[5][5]);
|
||||
}else if(pd_adc_half_c_start == true) {
|
||||
sprintf(half_tx_buffer_12, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[0], half_cycle_send_buff[0][0], half_cycle_send_buff[0][1], half_cycle_send_buff[0][2], half_cycle_send_buff[0][3], half_cycle_send_buff[0][4], half_cycle_send_buff[0][5]);
|
||||
sprintf(half_tx_buffer_13, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[1], half_cycle_send_buff[1][0], half_cycle_send_buff[1][1], half_cycle_send_buff[1][2], half_cycle_send_buff[1][3], half_cycle_send_buff[1][4], half_cycle_send_buff[1][5]);
|
||||
sprintf(half_tx_buffer_14, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[2], half_cycle_send_buff[2][0], half_cycle_send_buff[2][1], half_cycle_send_buff[2][2], half_cycle_send_buff[2][3], half_cycle_send_buff[2][4], half_cycle_send_buff[2][5]);
|
||||
sprintf(half_tx_buffer_15, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[3], half_cycle_send_buff[3][0], half_cycle_send_buff[3][1], half_cycle_send_buff[3][2], half_cycle_send_buff[3][3], half_cycle_send_buff[3][4], half_cycle_send_buff[3][5]);
|
||||
sprintf(half_tx_buffer_16, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[4], half_cycle_send_buff[4][0], half_cycle_send_buff[4][1], half_cycle_send_buff[4][2], half_cycle_send_buff[4][3], half_cycle_send_buff[4][4], half_cycle_send_buff[4][5]);
|
||||
sprintf(half_tx_buffer_17, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[5], half_cycle_send_buff[5][0], half_cycle_send_buff[5][1], half_cycle_send_buff[5][2], half_cycle_send_buff[5][3], half_cycle_send_buff[5][4], half_cycle_send_buff[5][5]);
|
||||
}else if(pd_adc_half_d_start == true) {
|
||||
sprintf(half_tx_buffer_18, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[0], half_cycle_send_buff[0][0], half_cycle_send_buff[0][1], half_cycle_send_buff[0][2], half_cycle_send_buff[0][3], half_cycle_send_buff[0][4], half_cycle_send_buff[0][5]);
|
||||
sprintf(half_tx_buffer_19, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[1], half_cycle_send_buff[1][0], half_cycle_send_buff[1][1], half_cycle_send_buff[1][2], half_cycle_send_buff[1][3], half_cycle_send_buff[1][4], half_cycle_send_buff[1][5]);
|
||||
sprintf(half_tx_buffer_20, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[2], half_cycle_send_buff[2][0], half_cycle_send_buff[2][1], half_cycle_send_buff[2][2], half_cycle_send_buff[2][3], half_cycle_send_buff[2][4], half_cycle_send_buff[2][5]);
|
||||
sprintf(half_tx_buffer_21, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[3], half_cycle_send_buff[3][0], half_cycle_send_buff[3][1], half_cycle_send_buff[3][2], half_cycle_send_buff[3][3], half_cycle_send_buff[3][4], half_cycle_send_buff[3][5]);
|
||||
sprintf(half_tx_buffer_22, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[4], half_cycle_send_buff[4][0], half_cycle_send_buff[4][1], half_cycle_send_buff[4][2], half_cycle_send_buff[4][3], half_cycle_send_buff[4][4], half_cycle_send_buff[4][5]);
|
||||
sprintf(half_tx_buffer_23, "Ti%d,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf,\t%lf\r\n", LED_list_half[5], half_cycle_send_buff[5][0], half_cycle_send_buff[5][1], half_cycle_send_buff[5][2], half_cycle_send_buff[5][3], half_cycle_send_buff[5][4], half_cycle_send_buff[5][5]);
|
||||
}
|
||||
}
|
||||
/*********************/
|
||||
|
||||
buf_no = 0;
|
||||
|
||||
if(ble_connection_st == 0) {
|
||||
half_adc_end();
|
||||
half_send_timer_stop();
|
||||
printf("Half ADC STOP 1\r\n");
|
||||
}
|
||||
else if(pd_adc_half_a_start == true) { // B mode
|
||||
pd_adc_half_a_start = false;
|
||||
pd_adc_half_b_start = true;
|
||||
|
||||
half_adc_start();
|
||||
}else if(pd_adc_half_b_start == true) { // C mode
|
||||
pd_adc_half_b_start = false;
|
||||
pd_adc_half_c_start = true;
|
||||
|
||||
half_adc_start();
|
||||
}else if(pd_adc_half_c_start == true) { // D mode
|
||||
pd_adc_half_c_start = false;
|
||||
pd_adc_half_d_start = true;
|
||||
|
||||
half_adc_start();
|
||||
}else if(pd_adc_half_d_start == true) { // Completed
|
||||
pd_adc_half_d_start = false;
|
||||
|
||||
if(cmd_type_t == CMD_UART && prestatus==false) {
|
||||
half_send_timer_stop();
|
||||
|
||||
}else if(cmd_type_t == CMD_BLE && prestatus==false) {
|
||||
half_send_timer_start();
|
||||
|
||||
}
|
||||
|
||||
if(ble_connection_st == BLE_CONNECTED_ST) {
|
||||
battery_timer_start();
|
||||
}
|
||||
|
||||
led_off(99);
|
||||
pd_off(99);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void half_send_loop(void * p_context) /* For x ms */
|
||||
{
|
||||
UNUSED_PARAMETER(p_context);
|
||||
half_send_timer_stop();
|
||||
|
||||
|
||||
|
||||
switch(order) {
|
||||
case 0:
|
||||
data_tx_handler(half_tx_buffer_0);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
data_tx_handler(half_tx_buffer_1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
data_tx_handler(half_tx_buffer_2);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
data_tx_handler(half_tx_buffer_3);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
data_tx_handler(half_tx_buffer_4);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
data_tx_handler(half_tx_buffer_5);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
data_tx_handler(half_tx_buffer_6);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
data_tx_handler(half_tx_buffer_7);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
data_tx_handler(half_tx_buffer_8);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
data_tx_handler(half_tx_buffer_9);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
data_tx_handler(half_tx_buffer_10);
|
||||
break;
|
||||
|
||||
case 11:
|
||||
data_tx_handler(half_tx_buffer_11);
|
||||
break;
|
||||
|
||||
case 12:
|
||||
data_tx_handler(half_tx_buffer_12);
|
||||
break;
|
||||
|
||||
case 13:
|
||||
data_tx_handler(half_tx_buffer_13);
|
||||
break;
|
||||
|
||||
case 14:
|
||||
data_tx_handler(half_tx_buffer_14);
|
||||
break;
|
||||
|
||||
case 15:
|
||||
data_tx_handler(half_tx_buffer_15);
|
||||
break;
|
||||
|
||||
case 16:
|
||||
data_tx_handler(half_tx_buffer_16);
|
||||
break;
|
||||
|
||||
case 17:
|
||||
data_tx_handler(half_tx_buffer_17);
|
||||
break;
|
||||
|
||||
case 18:
|
||||
data_tx_handler(half_tx_buffer_18);
|
||||
break;
|
||||
|
||||
case 19:
|
||||
data_tx_handler(half_tx_buffer_19);
|
||||
break;
|
||||
|
||||
case 20:
|
||||
data_tx_handler(half_tx_buffer_20);
|
||||
break;
|
||||
|
||||
case 21:
|
||||
data_tx_handler(half_tx_buffer_21);
|
||||
break;
|
||||
|
||||
case 22:
|
||||
data_tx_handler(half_tx_buffer_22);
|
||||
break;
|
||||
|
||||
case 23:
|
||||
data_tx_handler(half_tx_buffer_23);
|
||||
|
||||
order = 0;
|
||||
#if FEATURE_PRINTF
|
||||
printf("half_send Completed\r\n");
|
||||
#endif
|
||||
|
||||
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
order++;
|
||||
if(ble_connection_st == 0) {
|
||||
half_send_timer_stop();
|
||||
order = 0;
|
||||
printf("Half ADC STOP 2\r\n");}
|
||||
else{
|
||||
half_send_timer_start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void half_adc_start(void)
|
||||
{
|
||||
pd_no = -1;
|
||||
led_no = -1;
|
||||
buf_no = 0;
|
||||
|
||||
|
||||
if(pd_adc_half_a_start == true) {
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n===== Half_A start ====================\r\n");
|
||||
printf("LED : ");
|
||||
#endif
|
||||
for(uint8_t i =0; i < HALF_LED_NO; i++) {
|
||||
LED_list_half[i] = led_half_list_a[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", LED_list_half[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n");
|
||||
printf("PD : ");
|
||||
#endif
|
||||
for(uint8_t i =0; i < HALF_PD_NO; i++) {
|
||||
PD_list_half[i] = pd_half_list_a[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", PD_list_half[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if(pd_adc_half_b_start == true) {
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n===== Half_B start ====================\r\n");
|
||||
printf("LED : ");
|
||||
#endif
|
||||
for(uint8_t i =0; i < HALF_LED_NO; i++) {
|
||||
LED_list_half[i] = led_half_list_b[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", LED_list_half[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n");
|
||||
printf("PD : ");
|
||||
#endif
|
||||
|
||||
for(uint8_t i =0; i < HALF_PD_NO; i++) {
|
||||
PD_list_half[i] = pd_half_list_b[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", PD_list_half[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if(pd_adc_half_c_start == true) {
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n===== Half_C start ====================\r\n");
|
||||
printf("LED : ");
|
||||
#endif
|
||||
for(uint8_t i =0; i < HALF_LED_NO; i++) {
|
||||
LED_list_half[i] = led_half_list_c[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", LED_list_half[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n");
|
||||
printf("PD : ");
|
||||
#endif
|
||||
|
||||
for(uint8_t i =0; i < HALF_PD_NO; i++) {
|
||||
PD_list_half[i] = pd_half_list_c[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", PD_list_half[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if(pd_adc_half_d_start == true) {
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n===== Half_D start ====================\r\n");
|
||||
printf("LED : ");
|
||||
#endif
|
||||
for(uint8_t i =0; i < HALF_LED_NO; i++) {
|
||||
LED_list_half[i] = led_half_list_d[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", LED_list_half[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n");
|
||||
printf("PD : ");
|
||||
#endif
|
||||
|
||||
for(uint8_t i =0; i < HALF_PD_NO; i++) {
|
||||
PD_list_half[i] = pd_half_list_d[i];
|
||||
#if FEATURE_PRINTF
|
||||
printf("%d ", PD_list_half[i]);
|
||||
#endif
|
||||
}
|
||||
#if FEATURE_PRINTF
|
||||
printf("\r\n\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
for(uint16_t i = 0; i < 72; i++) {
|
||||
for(uint16_t j = 0; j < HALF_CYCLE_CNT; j++) {
|
||||
half_cycle_buff[i][j] = 0.0f;
|
||||
}
|
||||
}
|
||||
for(uint8_t i = 0; i < HALF_LED_NO; i++) {
|
||||
for(uint8_t j = 0; j < HALF_PD_NO; j++) {
|
||||
half_cycle_send_buff[i][j] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
half_adc_start2();
|
||||
order =0;
|
||||
}
|
||||
|
||||
|
||||
void half_adc_start2(void)
|
||||
{
|
||||
half_adc_init();
|
||||
#if FEATURE_PRINTF
|
||||
half_timer_init();
|
||||
half_timer_start();
|
||||
#else
|
||||
half_irq_init();
|
||||
half_ppi_init();
|
||||
half_sampling_event_enable();
|
||||
//ada2200_start();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void half_adc_end(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("half_adc_end\r\n");
|
||||
half_timer_stop();
|
||||
#endif
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
half_sampling_event_disable();
|
||||
half_irq_uninit();
|
||||
half_ppi_uninit();
|
||||
#endif
|
||||
half_adc_uninit();
|
||||
//ada2200_stop();
|
||||
nrf_delay_ms(5);
|
||||
if(prestatus == true){
|
||||
printf("1st\r\n");
|
||||
if(device_activated() == 0)
|
||||
{printf("2nd\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void half_adc_init(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("half_adc_init\r\n");
|
||||
#endif
|
||||
|
||||
static nrfx_saadc_config_t default_config;
|
||||
default_config.resolution = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION; /* Resolution is 10bits */
|
||||
default_config.oversample = (nrf_saadc_oversample_t)NRFX_SAADC_CONFIG_OVERSAMPLE; /* Over Sampling Disabled */
|
||||
default_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY; /* Interrupt Priority is 0(Highest) */
|
||||
default_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE; /* Low Power Mode is Disabled */
|
||||
|
||||
static nrf_saadc_channel_config_t config;
|
||||
config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.gain = NRF_SAADC_GAIN1_6;
|
||||
config.reference = NRF_SAADC_REFERENCE_INTERNAL;
|
||||
config.acq_time = NRF_SAADC_ACQTIME_3US;
|
||||
config.mode = NRF_SAADC_MODE_DIFFERENTIAL;
|
||||
config.burst = NRF_SAADC_BURST_DISABLED;
|
||||
config.pin_p = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN0);
|
||||
config.pin_n = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN1);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_init(&default_config, half_voltage_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
if (prestatus==true)
|
||||
{
|
||||
err_code = nrf_drv_saadc_buffer_convert(pd_half_adc_buf[0], half_samples_in_buffer + 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
err_code = nrf_drv_saadc_buffer_convert(pd_half_adc_buf[0], half_samples_in_buffer + m_config.pd_delay_us/16);
|
||||
}
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void half_adc_uninit(void)
|
||||
{
|
||||
#if FEATURE_PRINTF
|
||||
printf("pd_half_adc_uninit\r\n");
|
||||
#endif
|
||||
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
}
|
||||
|
||||
|
||||
#if !FEATURE_PRINTF
|
||||
void half_irq_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
/* Initialize int pin */
|
||||
if (!nrfx_gpiote_is_init())
|
||||
{
|
||||
err_code = nrfx_gpiote_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
|
||||
in_config.pull = NRF_GPIO_PIN_PULLDOWN;
|
||||
|
||||
err_code = nrfx_gpiote_in_init(ADA2200_SYNCO_PIN, &in_config, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_gpiote_in_event_enable(ADA2200_SYNCO_PIN, true);
|
||||
}
|
||||
|
||||
|
||||
void half_irq_uninit(void)
|
||||
{
|
||||
nrfx_gpiote_in_event_disable(ADA2200_SYNCO_PIN);
|
||||
nrfx_gpiote_in_uninit(ADA2200_SYNCO_PIN);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void half_send_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_half_send_loop_timer_id, APP_TIMER_TICKS(HALF_SEND_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
|
||||
void half_send_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_half_send_loop_timer_id));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void half_send_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_half_send_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, half_send_loop));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*******************************************************************************
|
||||
* @file meas_pd_voltage_half.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MEAS_PD_VOLTAGE_HALF_H__
|
||||
#define _MEAS_PD_VOLTAGE_HALF_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
|
||||
#define ADA2200_SYNCO_PIN NRF_GPIO_PIN_MAP(0,17)
|
||||
|
||||
#define HALF_PD_NO 6
|
||||
#define HALF_LED_NO 6
|
||||
#define HALF_CYCLE_CNT 32
|
||||
|
||||
|
||||
void half_ppi_init(void);
|
||||
void half_ppi_uninit(void);
|
||||
void half_sampling_event_enable(void);
|
||||
void half_sampling_event_disable(void);
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
static void half_voltage_handler(nrf_drv_saadc_evt_t const * p_event); /* PD Voltage reading */
|
||||
void half_adc_start(void);
|
||||
void half_adc_start2(void);
|
||||
void half_adc_end(void);
|
||||
void half_adc_init(void);
|
||||
void half_adc_uninit(void);
|
||||
#if !FEATURE_PRINTF
|
||||
void half_irq_init(void);
|
||||
void half_irq_uninit(void);
|
||||
#endif
|
||||
|
||||
void half_send_loop(void * p_context); /* For x ms */
|
||||
void half_send_timer_start(void);
|
||||
void half_send_timer_stop(void);;
|
||||
void half_send_timer_init(void);
|
||||
|
||||
#endif /* _MEAS_PD_VOLTAGE_HALF_H__ */
|
||||
|
||||
@@ -0,0 +1,421 @@
|
||||
/*******************************************************************************
|
||||
TEST medi50 Dec 23
|
||||
if(resetCount>=3) return true; 3 COUNT 25/11/04 CJ CHUN
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include "sdk_common.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "boards.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "app_timer.h"
|
||||
#include "nrfx_gpiote.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "ada2200_spi.h"
|
||||
#include "battery_saadc.h"
|
||||
#include "ble_nus.h"
|
||||
#include "meas_pd_voltage_simple.h"
|
||||
#include "main.h"
|
||||
#include <cmd_parse.h>
|
||||
//#include "fstorage.h"
|
||||
#include "power_control.h"
|
||||
#include "debug_print.h"
|
||||
|
||||
#define PD_REF_VOLTAGE_IN_MILLIVOLTS 600.0f /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
|
||||
#define PD_PRE_SCALING_COMPENSATION 6.0f /**< The ADC is configured to use VDD with 1/3 prescaling as input. And hence the result of conversion is to be multiplied by 3 to get the actual value of the battery voltage.*/
|
||||
#define PD_ADC_RES_10BITS 1023.0f /**< Maximum digital value for 10-bit ADC conversion. */
|
||||
|
||||
|
||||
|
||||
// remark for avoid warning error
|
||||
// static nrf_saadc_value_t pressure_adc_buf[2]; // chanul 2ea for simple each 1ea
|
||||
|
||||
|
||||
|
||||
/**@brief Macro to convert the result of ADC conversion in millivolts.
|
||||
|
||||
|
||||
|
||||
*
|
||||
* @param[in] ADC_VALUE ADC result.
|
||||
*
|
||||
* @retval Result converted to millivolts.
|
||||
*/
|
||||
#define PD_VOUT_IN_MILLI_VOLTS(ADC_VALUE)\
|
||||
(((((ADC_VALUE) * PD_REF_VOLTAGE_IN_MILLIVOLTS) / PD_ADC_RES_10BITS) * PD_PRE_SCALING_COMPENSATION)*2)
|
||||
|
||||
#define SIM_SAMPLES_IN_BUFFER 128
|
||||
static nrf_saadc_value_t pd_adc_buf[2][SIM_SAMPLES_IN_BUFFER];
|
||||
|
||||
uint8_t simple_samples_in_buffer = 8;
|
||||
|
||||
#define SAMPLE_CYCLE_CNT 128
|
||||
|
||||
float simple_cycle_buff[SAMPLE_CYCLE_CNT]; /* For Cycle-8, Cycle-16, Cycle-24, Cycle-32 */
|
||||
float simple_cycle_send_buff = 0.0f;
|
||||
int16_t bi_simple_cycle_buff[SAMPLE_CYCLE_CNT];
|
||||
uint16_t ubi_simple_cycle_buff[SAMPLE_CYCLE_CNT];/* For Cycle-8, Cycle-16, Cycle-24, Cycle-32 */
|
||||
int16_t bi_simple_cycle_send_buff = 0;
|
||||
extern uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] ;
|
||||
static nrf_ppi_channel_t m_ppi_channel;
|
||||
extern uint8_t m_pd_adc_cnt;
|
||||
extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
extern bool lock_check;
|
||||
extern which_cmd_t cmd_type_t;
|
||||
#if FEATURE_CHAMBER_AUTO_TEST
|
||||
extern auto_meas_mode_t auto_test_mode;
|
||||
#endif
|
||||
extern volatile bool ble_connection_st;
|
||||
extern bool ble_got_new_data;
|
||||
bool con_single;
|
||||
uint8_t rep = 0;
|
||||
extern uint8_t resetCount; //cj add
|
||||
//APP_TIMER_DEF(m_simple_send_loop_timer_id);
|
||||
|
||||
//#define SIMPLE_SEND_LOOP_INTERVAL 100
|
||||
|
||||
#define PATTERN_LENGTH 8
|
||||
#define NORMAL_AMPLITUDE_THRESHOLD 40 // values above ~50 in magnitude are normal
|
||||
|
||||
bool is_lockin_pattern(int16_t *pattern, uint8_t length) {
|
||||
int16_t avg_amplitude = 0;
|
||||
uint8_t positive_count = 0;
|
||||
uint8_t negative_count = 0;
|
||||
|
||||
// Calculate average amplitude and count positives/negatives
|
||||
for (uint8_t i = 0; i < length; i++) {
|
||||
int16_t value = pattern[i];
|
||||
avg_amplitude += abs(value);
|
||||
|
||||
if (value >= 0) {
|
||||
positive_count++;
|
||||
} else {
|
||||
negative_count++;
|
||||
}
|
||||
}
|
||||
|
||||
avg_amplitude /= length;
|
||||
DBG_PRINTF("lock avg amplitude=%d,p_c=%d,n_c=%d\r\n\r\n", avg_amplitude,positive_count,negative_count);
|
||||
// Check conditions:
|
||||
// - Large enough average amplitude
|
||||
// - Exactly 1 positive and (length - 1) negative values
|
||||
if(resetCount>=3) return true;
|
||||
|
||||
if (avg_amplitude > NORMAL_AMPLITUDE_THRESHOLD &&
|
||||
positive_count == 1 && negative_count == (length - 1)) {
|
||||
return true; // lock-in (normal) pattern
|
||||
} else {
|
||||
|
||||
return false; // abnormal pattern
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void simple_ppi_init(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
uint32_t gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(ADA2200_SYNCO_PIN);
|
||||
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
|
||||
|
||||
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
|
||||
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
|
||||
gpiote_event_addr,
|
||||
saadc_sample_task_addr);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void simple_ppi_uninit(void)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
err_code = nrf_drv_ppi_uninit();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void simple_sampling_event_enable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
void simple_sampling_event_disable(void)
|
||||
{
|
||||
ret_code_t err_code = nrf_drv_ppi_channel_disable(m_ppi_channel);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
|
||||
/**@brief Function for handling the ADC interrupt.
|
||||
*
|
||||
* @details This function will fetch the conversion result from the ADC, convert the value into
|
||||
* percentage and send it to peer.
|
||||
*/
|
||||
|
||||
|
||||
static void simple_voltage_handler(nrf_drv_saadc_evt_t const * p_event)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
// ? ??? ??
|
||||
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, simple_samples_in_buffer);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
for(uint8_t i = 0; i < simple_samples_in_buffer; i++) {
|
||||
bi_simple_cycle_buff[i] = p_event->data.done.p_buffer[i];
|
||||
}
|
||||
|
||||
simple_mesurement_stop();
|
||||
|
||||
simple_cycle_send_buff = 0;
|
||||
bi_simple_cycle_send_buff = 0;
|
||||
|
||||
for(uint8_t i = 0; i < simple_samples_in_buffer; i++) {
|
||||
simple_cycle_buff[i] = PD_VOUT_IN_MILLI_VOLTS(bi_simple_cycle_buff[i]);
|
||||
bi_simple_cycle_send_buff += bi_simple_cycle_buff[i];
|
||||
simple_cycle_send_buff += simple_cycle_buff[i];
|
||||
}
|
||||
|
||||
// ? BLE ?? (if? ??? ??!)
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
DBG_PRINTF("Th%f\r\n\r\n", simple_cycle_send_buff);
|
||||
DBG_PRINTF("MOD: %f,%f,%f,%f,%f,%f,%f,%f\r\n",
|
||||
simple_cycle_buff[0], simple_cycle_buff[1],
|
||||
simple_cycle_buff[2], simple_cycle_buff[3],
|
||||
simple_cycle_buff[4], simple_cycle_buff[5],
|
||||
simple_cycle_buff[6], simple_cycle_buff[7]);
|
||||
|
||||
} else if(cmd_type_t == CMD_BLE) {
|
||||
DBG_PRINTF("Th%f\r\n\r\n", simple_cycle_send_buff);
|
||||
DBG_PRINTF("MOD: %f,%f,%f,%f,%f,%f,%f,%f\r\n",
|
||||
simple_cycle_buff[0], simple_cycle_buff[1],
|
||||
simple_cycle_buff[2], simple_cycle_buff[3],
|
||||
simple_cycle_buff[4], simple_cycle_buff[5],
|
||||
simple_cycle_buff[6], simple_cycle_buff[7]);
|
||||
|
||||
// ? BLE ??
|
||||
for(uint8_t i = 0; i < simple_samples_in_buffer; i++) {
|
||||
ubi_simple_cycle_buff[i] = (uint16_t)bi_simple_cycle_buff[i];
|
||||
}
|
||||
|
||||
format_data(ble_bin_buffer, "rsh:", ubi_simple_cycle_buff, (m_pd_adc_cnt*2));
|
||||
binary_tx_handler(ble_bin_buffer, (m_pd_adc_cnt+2));
|
||||
}
|
||||
|
||||
// ? Lock-in ?? ??
|
||||
if (lock_check == true) {
|
||||
if (is_lockin_pattern(bi_simple_cycle_buff, 8) == false) {
|
||||
if(device_reactivated() == 0) {
|
||||
DBG_PRINTF("reset!!\r\n");
|
||||
}
|
||||
}
|
||||
resetCount++;
|
||||
DBG_PRINTF("Reset Count :%d\r\n", resetCount);
|
||||
}
|
||||
|
||||
} // ? if (NRF_DRV_SAADC_EVT_DONE) ??? ??
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
static void simple_voltage_handler(nrf_drv_saadc_evt_t const * p_event)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
|
||||
{
|
||||
|
||||
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, simple_samples_in_buffer);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
for(uint8_t i = 0; i < simple_samples_in_buffer; i++) {
|
||||
bi_simple_cycle_buff[i] = p_event->data.done.p_buffer[i];
|
||||
}
|
||||
|
||||
simple_mesurement_stop();
|
||||
|
||||
simple_cycle_send_buff = 0;
|
||||
bi_simple_cycle_send_buff = 0;
|
||||
|
||||
for(uint8_t i = 0; i < simple_samples_in_buffer; i++) {
|
||||
|
||||
simple_cycle_buff[i] = PD_VOUT_IN_MILLI_VOLTS(bi_simple_cycle_buff[i]);
|
||||
//simple_cycle_buff[i] = simple_cycle_buff[i] * -1;
|
||||
bi_simple_cycle_send_buff += bi_simple_cycle_buff[i];
|
||||
simple_cycle_send_buff += simple_cycle_buff[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(con_single==true)
|
||||
{
|
||||
//return;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if(cmd_type_t == CMD_UART) {
|
||||
DBG_PRINTF("Th%f\r\n\r\n", simple_cycle_send_buff);
|
||||
DBG_PRINTF( "MOD: %f,%f,%f,%f,%f,%f,%f,%f\r\n", simple_cycle_buff[0], simple_cycle_buff[1], simple_cycle_buff[2], simple_cycle_buff[3], simple_cycle_buff[4]
|
||||
, simple_cycle_buff[5], simple_cycle_buff[6], simple_cycle_buff[7]);
|
||||
} else if(cmd_type_t == CMD_BLE) {
|
||||
// if(lock_check == true){
|
||||
DBG_PRINTF("Th%f\r\n\r\n", simple_cycle_send_buff);
|
||||
DBG_PRINTF( "MOD: %f,%f,%f,%f,%f,%f,%f,%f\r\n", simple_cycle_buff[0], simple_cycle_buff[1], simple_cycle_buff[2], simple_cycle_buff[3], simple_cycle_buff[4]
|
||||
, simple_cycle_buff[5], simple_cycle_buff[6], simple_cycle_buff[7]);
|
||||
|
||||
for(uint8_t i = 0; i < simple_samples_in_buffer; i++) {
|
||||
ubi_simple_cycle_buff[i] = (uint16_t)bi_simple_cycle_buff[i];
|
||||
}
|
||||
|
||||
format_data(ble_bin_buffer, "rsh:", ubi_simple_cycle_buff, (m_pd_adc_cnt*2));
|
||||
|
||||
binary_tx_handler(ble_bin_buffer,(m_pd_adc_cnt+2));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
if (lock_check == true) {
|
||||
if (is_lockin_pattern(bi_simple_cycle_buff,8) == false){
|
||||
|
||||
if(device_reactivated() == 0)
|
||||
{
|
||||
DBG_PRINTF("reset!!\r\n");
|
||||
}
|
||||
|
||||
}
|
||||
resetCount++;
|
||||
DBG_PRINTF("Reset Count :%d \r\n",resetCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
void simple_adc_init(void)
|
||||
{
|
||||
static nrfx_saadc_config_t default_config;
|
||||
default_config.resolution = (nrf_saadc_resolution_t)NRFX_SAADC_CONFIG_RESOLUTION; /* Resolution is 10bits */
|
||||
default_config.oversample = (nrf_saadc_oversample_t)NRFX_SAADC_CONFIG_OVERSAMPLE; /* Over Sampling Disabled */
|
||||
default_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY; /* Interrupt Priority is 0(Highest) */
|
||||
default_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE; /* Low Power Mode is Disabled */
|
||||
|
||||
static nrf_saadc_channel_config_t config;
|
||||
config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
|
||||
config.gain = NRF_SAADC_GAIN1_6;
|
||||
config.reference = NRF_SAADC_REFERENCE_INTERNAL;
|
||||
config.acq_time = NRF_SAADC_ACQTIME_3US;
|
||||
config.mode = NRF_SAADC_MODE_DIFFERENTIAL;
|
||||
config.burst = NRF_SAADC_BURST_DISABLED;
|
||||
config.pin_p = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN0);
|
||||
config.pin_n = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN1);
|
||||
|
||||
ret_code_t err_code = nrf_drv_saadc_init(&default_config, simple_voltage_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
err_code = nrf_drv_saadc_channel_init(0, &config);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
if(con_single==true){
|
||||
err_code = nrf_drv_saadc_buffer_convert(pd_adc_buf[0], SIM_SAMPLES_IN_BUFFER);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
else{
|
||||
err_code = nrf_drv_saadc_buffer_convert(pd_adc_buf[0], simple_samples_in_buffer);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void simple_adc_uninit(void)
|
||||
{
|
||||
nrf_drv_saadc_uninit();
|
||||
nrf_drv_saadc_channel_uninit(0);
|
||||
}
|
||||
|
||||
|
||||
void simple_irq_init(void){
|
||||
ret_code_t err_code;
|
||||
|
||||
/* Initialize int pin */
|
||||
if (!nrfx_gpiote_is_init())
|
||||
{
|
||||
err_code = nrfx_gpiote_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
|
||||
in_config.pull = NRF_GPIO_PIN_PULLDOWN;
|
||||
|
||||
err_code = nrfx_gpiote_in_init(ADA2200_SYNCO_PIN, &in_config, NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrfx_gpiote_in_event_enable(ADA2200_SYNCO_PIN, true);
|
||||
}
|
||||
|
||||
|
||||
void simple_irq_uninit(void){
|
||||
|
||||
nrfx_gpiote_in_event_disable(ADA2200_SYNCO_PIN);
|
||||
nrfx_gpiote_in_uninit(ADA2200_SYNCO_PIN);
|
||||
}
|
||||
|
||||
|
||||
void simple_mesurement_start(void){
|
||||
|
||||
battery_timer_stop();
|
||||
nrf_delay_ms(10);
|
||||
memset(simple_cycle_buff, 0, SAMPLE_CYCLE_CNT);
|
||||
nrf_delay_ms(10);
|
||||
simple_irq_init();
|
||||
nrf_delay_ms(10);
|
||||
simple_adc_init();
|
||||
nrf_delay_ms(10);
|
||||
simple_ppi_init();
|
||||
nrf_delay_ms(10);
|
||||
simple_sampling_event_enable();
|
||||
nrf_delay_ms(10);
|
||||
}
|
||||
|
||||
|
||||
void simple_mesurement_stop(void){
|
||||
|
||||
if(ble_connection_st == 1) {
|
||||
battery_timer_start();
|
||||
}
|
||||
|
||||
|
||||
simple_sampling_event_disable();
|
||||
simple_adc_uninit();
|
||||
simple_ppi_uninit();
|
||||
simple_irq_uninit();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*******************************************************************************
|
||||
* @file meas_pd_voltage_simple.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MEAS_PD_VOLTAGE_SIMPLE_H__
|
||||
#define _MEAS_PD_VOLTAGE_SIMPLE_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#define ADA2200_SYNCO_PIN NRF_GPIO_PIN_MAP(0,17)
|
||||
|
||||
|
||||
void simple_ppi_init(void);
|
||||
void simple_ppi_uninit(void);
|
||||
void simple_sampling_event_enable(void);
|
||||
void simple_sampling_event_disable(void);
|
||||
void simple_adc_init(void);
|
||||
void simple_adc_uninit(void);
|
||||
void simple_irq_init(void);
|
||||
void simple_irq_uninit(void);
|
||||
void simple_mesurement_start(void);
|
||||
void simple_mesurement_stop(void);
|
||||
|
||||
|
||||
void simple_send_loop(void * p_context); /* For x ms */
|
||||
void simple_send_timer_start(void);
|
||||
void simple_send_timer_stop(void);;
|
||||
void simple_send_timer_init(void);
|
||||
#endif /* _MEAS_PD_VOLTAGE_SIMPLE_H__ */
|
||||
|
||||
867
project/ble_peripheral/ble_app_bladder_patch/measurements.c
Normal file
867
project/ble_peripheral/ble_app_bladder_patch/measurements.c
Normal file
@@ -0,0 +1,867 @@
|
||||
/*******************************************************************************
|
||||
* @file measurements.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
#include "nrf_drv_spi.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "boards.h"
|
||||
#include "bsp.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "app_util_platform.h"
|
||||
#include "nrf_pwr_mgmt.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "ble_nus.h"
|
||||
#include "LED_Parse.h"
|
||||
#include "app_timer.h"
|
||||
#include "measurements.h"
|
||||
#include "main.h"
|
||||
//#include "fstorage.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include <cmd_parse.h>
|
||||
#include "debug_print.h"
|
||||
#include "i2c_manager.h"
|
||||
//#define trig_18 NRF_GPIO_PIN_MAP(0,18)
|
||||
//#define tris_18_CONFIG() nrf_gpio_cfg_output(trig_18)
|
||||
//#define trig_on() nrf_gpio_pin_set(trig_18)
|
||||
//#define trig_off() nrf_gpio_pin_clear(trig_18)
|
||||
#define LED_NUM 24 //
|
||||
uint8_t activated_led = 99;
|
||||
uint8_t activated_pd = 99;
|
||||
APP_TIMER_DEF(m_mea_send_loop_timer_id);
|
||||
static uint8_t cnt =0;
|
||||
#define MEA_SEND_LOOP_INTERVAL 100
|
||||
char mea_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
extern volatile bool processing;
|
||||
/* Default Value before initialized. Set value for Default!!! */ /* 초기값 설정 */
|
||||
/* 0번은 사용하지 않음 = NULL, 1 ~ 24까지 사용 */
|
||||
/*AD5272 DP에 쓸수 있는 값 범위는 0 ~ 1023 */
|
||||
//uint16_t led_power_dp[LED_NUM] = {
|
||||
//
|
||||
// 0,25,25,18,19,24,24,25,25,18,19,25,23,25,25,18,19,24,24,25,25,19,20,25
|
||||
//};
|
||||
//uint16_t led_power_dp[48] =
|
||||
// {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47};
|
||||
//
|
||||
/*LED0 = NULL 사용하지 않음, LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8, LED9, LED10, LED11, LED12, LED13, LED14, LED15, LED16, LED17, LED18, LED19, LED20, LED21, LED22, LED23, LED24 */
|
||||
/*MCP4725 를 0.1V(125) ~ 1.1V(1366) 값을 사용 */
|
||||
//uint16_t led_pd_dac_v[LED_NUM] =
|
||||
// {1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, /* PD0 */
|
||||
// 1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000}; /* PD1 */
|
||||
//
|
||||
uint16_t led_pd_dac_v[LED_NUM] =
|
||||
{1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000, 1000, 1000, 1000, 1000,1000, 1000, 1000}; /* PD0 */ // 48 에서 24 변경 cj chun
|
||||
|
||||
uint16_t led_off_dac_v =1360;
|
||||
uint8_t led_off_pd = 0;
|
||||
|
||||
/*ello Annapalu
|
||||
|
||||
As Wojtek already stated you cannot use the nrf_gpio_pin_read to read a pin set as an output. If you look at figure 21, page 112 in the nRF52832 product specification you can see the PIN(0).IN register, it is this register that is read by the gpio_pin_read function. When a pin is set as an output the PIN(0).CNF.DIR switch will close on the output side and open on the input side, meaning it is physically impossible to read the actual output value of the pin with the input register.
|
||||
|
||||
Wojtek is also correct that the NRF_GPIO->OUT only shows whether you have set the register, and not the actual pin state.
|
||||
|
||||
To achieve what you want you could connect a second GPIO, configured as an input, to the same circuit. This would tell you whether the voltage is high or low.
|
||||
|
||||
If you need to see a more accurate reading of the voltage level, to detect deviation, you could use the ADC or Comparator.
|
||||
|
||||
EDIT: 23.03.17 14:40
|
||||
|
||||
I have looked further into this and it seems I was a bit hasty in my reply. The product specification shows the control signal of the two above mentioned switches are different. PIN(0).CNF.DIR for the output and PIN(0).CNF.INPUT for the input buffer.So it seems it is possible to read the output value (high or low) of an output pin using the nrf_gpio_pin_read function, if you both set the direction of the pin to output, and connect the input buffer. This can be done with the nrf_gpio_cfg() function. Note that the nrf_gpio_cfg_output() function disconnects the input buffer.
|
||||
|
||||
I have tested it on the PCA10040 both with a led toggling based on it's own pin_read value, and with 4 leds switching based on the input value of one of the other led pins, all are configured as outputs.
|
||||
*/
|
||||
|
||||
|
||||
void led_pd_gain_array_printout(void)
|
||||
{
|
||||
|
||||
|
||||
cnt=0;
|
||||
|
||||
mea_send_timer_start();
|
||||
}
|
||||
void mea_send_loop(void * p_context) /* For x ms */
|
||||
{
|
||||
|
||||
|
||||
UNUSED_PARAMETER(p_context);
|
||||
DBG_PRINTF("\r\n1CNT =%d\r\n",cnt);
|
||||
mea_send_timer_stop();
|
||||
|
||||
|
||||
if (cnt < 6)
|
||||
{
|
||||
uint8_t i = (int)(cnt);
|
||||
if (cnt<3){
|
||||
// sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, led_pd_dac_v[i][0], led_pd_dac_v[i][1], led_pd_dac_v[i][2], led_pd_dac_v[i][3], led_pd_dac_v[i][4], led_pd_dac_v[i][5], led_pd_dac_v[i][6], led_pd_dac_v[i][7],led_pd_dac_v[i][8], led_pd_dac_v[i][9], led_pd_dac_v[i][10],
|
||||
// led_pd_dac_v[i][11], led_pd_dac_v[i][12], led_pd_dac_v[i][13], led_pd_dac_v[i][14], led_pd_dac_v[i][15], led_pd_dac_v[i][16], led_pd_dac_v[i][17],led_pd_dac_v[i][18], led_pd_dac_v[i][19], led_pd_dac_v[i][20], led_pd_dac_v[i][21],led_pd_dac_v[i][22], led_pd_dac_v[i][23]);
|
||||
// data_tx_handler(mea_tx_buffer); }
|
||||
sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, led_pd_dac_v[0], led_pd_dac_v[1], led_pd_dac_v[2], led_pd_dac_v[3], led_pd_dac_v[4], led_pd_dac_v[5], led_pd_dac_v[6], led_pd_dac_v[7],led_pd_dac_v[8], led_pd_dac_v[9], led_pd_dac_v[10],
|
||||
|
||||
|
||||
led_pd_dac_v[11], led_pd_dac_v[12], led_pd_dac_v[13], led_pd_dac_v[14], led_pd_dac_v[15], led_pd_dac_v[16], led_pd_dac_v[17],led_pd_dac_v[18], led_pd_dac_v[19], led_pd_dac_v[20], led_pd_dac_v[21],led_pd_dac_v[22], led_pd_dac_v[23]);
|
||||
|
||||
|
||||
data_tx_handler(mea_tx_buffer); }
|
||||
else{
|
||||
|
||||
|
||||
|
||||
}
|
||||
DBG_PRINTF("\r\n2CNT =%d\r\n",cnt);
|
||||
|
||||
mea_send_timer_start();
|
||||
|
||||
// switch(cnt){
|
||||
// case 0:
|
||||
// break;
|
||||
// case 1:
|
||||
// sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, 0,led_pd_dac_v_led_1[1], led_pd_dac_v_led_2[1], led_pd_dac_v_led_3[1], led_pd_dac_v_led_4[1], led_pd_dac_v_led_5[1], led_pd_dac_v_led_6[1], led_pd_dac_v_led_7[1], led_pd_dac_v_led_8[1],
|
||||
// led_pd_dac_v_led_9[1], led_pd_dac_v_led_10[1], led_pd_dac_v_led_11[1], led_pd_dac_v_led_12[1], led_pd_dac_v_led_13[1], led_pd_dac_v_led_14[1], led_pd_dac_v_led_15[1], led_pd_dac_v_led_16[1], led_pd_dac_v_led_17[1],led_pd_dac_v_led_18[1],
|
||||
// led_pd_dac_v_led_19[1], led_pd_dac_v_led_20[1],led_pd_dac_v_led_21[1], led_pd_dac_v_led_22[1],led_pd_dac_v_led_23[1], led_pd_dac_v_led_24[1]);
|
||||
// break;
|
||||
// case 2:
|
||||
// sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, 0, led_pd_dac_v_led_1[1], led_pd_dac_v_led_2[1], led_pd_dac_v_led_3[1], led_pd_dac_v_led_4[1], led_pd_dac_v_led_5[1], led_pd_dac_v_led_6[1], led_pd_dac_v_led_7[1], led_pd_dac_v_led_8[1],
|
||||
// led_pd_dac_v_led_9[1], led_pd_dac_v_led_10[1], led_pd_dac_v_led_11[1], led_pd_dac_v_led_12[1], led_pd_dac_v_led_13[1], led_pd_dac_v_led_14[1], led_pd_dac_v_led_15[1], led_pd_dac_v_led_16[1], led_pd_dac_v_led_17[1],led_pd_dac_v_led_18[1],
|
||||
// led_pd_dac_v_led_19[1], led_pd_dac_v_led_20[1],led_pd_dac_v_led_21[1], led_pd_dac_v_led_22[1],led_pd_dac_v_led_23[1], led_pd_dac_v_led_24[1]);
|
||||
// break;
|
||||
// case 3:
|
||||
// sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i,0, led_pd_dac_v_led_1[1], led_pd_dac_v_led_2[1], led_pd_dac_v_led_3[1], led_pd_dac_v_led_4[1], led_pd_dac_v_led_5[1], led_pd_dac_v_led_6[1], led_pd_dac_v_led_7[1], led_pd_dac_v_led_8[1],
|
||||
// led_pd_dac_v_led_9[1], led_pd_dac_v_led_10[1], led_pd_dac_v_led_11[1], led_pd_dac_v_led_12[1], led_pd_dac_v_led_13[1], led_pd_dac_v_led_14[1], led_pd_dac_v_led_15[1], led_pd_dac_v_led_16[1], led_pd_dac_v_led_17[1],led_pd_dac_v_led_18[1],
|
||||
// led_pd_dac_v_led_19[1], led_pd_dac_v_led_20[1],led_pd_dac_v_led_21[1], led_pd_dac_v_led_22[1],led_pd_dac_v_led_23[1], led_pd_dac_v_led_24[1]);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
//// }
|
||||
|
||||
// sprintf(mea_tx_buffer,"CNT_%d\r\n",cnt);
|
||||
// data_tx_handler(mea_tx_buffer);
|
||||
//
|
||||
// mea_send_timer_start();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//battery_timer_start();
|
||||
// sprintf(mea_tx_buffer,"END \r\n");
|
||||
// data_tx_handler(mea_tx_buffer);
|
||||
// printf("\r\nLED-DP Gain Array =\r\n");
|
||||
// for(uint16_t i = 0; i < LED_NUM; i++){
|
||||
// printf("%d,\t", m_config.led_power_dp[i]);
|
||||
// }
|
||||
// printf("\r\n");
|
||||
|
||||
DBG_PRINTF("\r\nLED-PD Gain Array =\r\n");
|
||||
// for(uint16_t i = 0; i < PD_NUM; i++){
|
||||
for(uint16_t j = 0; j < LED_NUM; j++){
|
||||
DBG_PRINTF("%d,\t", led_pd_dac_v[j]);
|
||||
// }
|
||||
// ///break;
|
||||
// DBG_PRINTF("\r\n");
|
||||
}
|
||||
DBG_PRINTF("\r\n");
|
||||
processing = false ;
|
||||
}
|
||||
|
||||
cnt++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
ret_code_t led_on(uint8_t led_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("\tled_on, %d =====================\r\n", led_index);
|
||||
#endif
|
||||
|
||||
// if((led_index >= 0)&&(led_index <= 49)){
|
||||
if(led_index <= 100){
|
||||
activated_led = led_index; //LED off 적용을 위해
|
||||
|
||||
/* LED켤때 파워 셋팅한후 켜는지 결정요 */
|
||||
// if(NRF_SUCCESS != led_power_set(led_index)) {
|
||||
// DBG_PRINTF("ERR!!! LED Power set\r\n");
|
||||
// return NRF_ERROR_INTERNAL;
|
||||
// }
|
||||
//nrf_gpio_pin_set(trig_18);
|
||||
trig_SW(true);
|
||||
|
||||
|
||||
if(NRF_SUCCESS != led_select(led_index)){
|
||||
DBG_PRINTF("ERR!!! LED Select\r\n");
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
// VCSEL_SW(true);
|
||||
|
||||
}else{
|
||||
DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t led_off(uint8_t led_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
trig_SW(false);
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("led_off\r\n");
|
||||
#endif
|
||||
|
||||
if(led_index == 99){
|
||||
LED_ALLOFF();
|
||||
|
||||
activated_led = 99;
|
||||
}
|
||||
else if(led_index == 98){
|
||||
LED99();
|
||||
DBG_PRINTF("clear \r\n");
|
||||
activated_led = 98;
|
||||
}
|
||||
else{
|
||||
DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
uint32_t port_state0 = nrf_gpio_port_out_read(NRF_P0);
|
||||
uint32_t port_state1 = nrf_gpio_port_out_read(NRF_P1);
|
||||
// DBG_PRINTF("test : %d, %d \r\n",port_state0,port_state1);
|
||||
// DBG_PRINTF("LIGHT ON1 : %d \r\n",port_state0>>22&1);
|
||||
// DBG_PRINTF("LIGHT ON2 : %d \r\n",port_state0>>23&1);
|
||||
// DBG_PRINTF("LED_SEL_SW1 : %d \r\n",port_state1>>4&1);
|
||||
// DBG_PRINTF("LED_SEL_SW2 : %d \r\n",port_state1>>5&1);
|
||||
// DBG_PRINTF("LED_SEL_SW3 : %d \r\n",port_state1>>6&1);
|
||||
// DBG_PRINTF("LED_INDIV_SEL_SW1 : %d \r\n",port_state1>>1&1);
|
||||
// DBG_PRINTF("LED_INDIV_SEL_SW2 : %d \r\n",port_state1>>2&1);
|
||||
// DBG_PRINTF("LED_INDIV_SEL_SW3 : %d \r\n",port_state1>>3&1);
|
||||
return err_code;
|
||||
}
|
||||
ret_code_t led_pd_mod_set(uint16_t mod_gain)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
// if(((led_index >= 0)&&(led_index <= 49))||((pd_index >= 0)&&(pd_index <= 2))){
|
||||
if(mod_gain <= 2000){
|
||||
|
||||
sw_i2c_init_once();
|
||||
|
||||
mcp4725_writeFastMode( mod_gain);
|
||||
|
||||
|
||||
if(NRF_SUCCESS != pd_on(2)){ //0~23 ==pd0 24~47 == pd1
|
||||
DBG_PRINTF("ERR!!! MOD_on\r\n");
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
}else{
|
||||
DBG_PRINTF("ERR!!! lockin Test Failed! \r\n");
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
ret_code_t led_pd_matching_value_set(uint8_t led_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
|
||||
|
||||
// if(((led_index >= 0)&&(led_index <= 49))||((pd_index >= 0)&&(pd_index <= 2))){
|
||||
if(led_index <= 100){
|
||||
|
||||
|
||||
if(NRF_SUCCESS != pd_gain_set(led_index)){
|
||||
DBG_PRINTF("ERR!!! pd_gain_set\r\n");
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
uint8_t pd_index;
|
||||
|
||||
if(led_index<24)
|
||||
{pd_index =0;
|
||||
}
|
||||
else if ((led_index<48) && (led_index>23) )
|
||||
{pd_index =1;
|
||||
}
|
||||
else if (led_index==99)
|
||||
{
|
||||
pd_index = led_off_pd;
|
||||
}
|
||||
|
||||
if(NRF_SUCCESS != pd_on(pd_index)){ //0~23 ==pd0 24~47 == pd1
|
||||
DBG_PRINTF("ERR!!! pd_on\r\n");
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
}else{
|
||||
DBG_PRINTF("ERR!!! led_indexFailed! %d\r\n", led_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t pd_on(uint8_t pd_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
#if FEATURE_FOR_SCOPE
|
||||
nrf_gpio_pin_set(PD_CLK_26);
|
||||
nrf_gpio_pin_clear(PD_CLK_26);
|
||||
#endif
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("pd_on, %d ===== \r\n", pd_index);
|
||||
#endif
|
||||
|
||||
// if((pd_index >= 0)&&(pd_index <= 2)){
|
||||
if(pd_index <= 3){
|
||||
activated_pd = pd_index;
|
||||
//DBG_PRINTF("pd_on %d\r\n", pd_index);
|
||||
if(NRF_SUCCESS != pd_select(pd_index)){
|
||||
DBG_PRINTF("ERR!!! pd_on Failed! %d\r\n", pd_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
}else{
|
||||
DBG_PRINTF("ERR!!! pd_index Failed! %d\r\n", pd_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t pd_off(uint8_t pd_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("pd_off\r\n");
|
||||
#endif
|
||||
|
||||
if(pd_index == 99){
|
||||
PD_ALLOFF();
|
||||
activated_pd = 99;
|
||||
}else{
|
||||
DBG_PRINTF("ERR!!! PD Off Failed! %d\r\n", pd_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
void led_power_read_48(uint16_t *data)
|
||||
{
|
||||
|
||||
|
||||
|
||||
for(uint8_t i = 0 ; i<24 ;i++){ //48 >24
|
||||
|
||||
data[i] = LED_READ_ROM(i);
|
||||
|
||||
nrf_delay_ms(1);
|
||||
}
|
||||
// nrf_delay_ms(20);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
int16_t led_power_read(uint8_t led_index)
|
||||
{
|
||||
int16_t led_power;
|
||||
// if((led_index >= 0)&&(led_index <= 49)){
|
||||
if(led_index <= 47){
|
||||
//led_power = led_power_dp[led_index];
|
||||
led_power = LED_READ_ROM(led_index);
|
||||
}else{
|
||||
DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return led_power;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t led_power_save_mem(uint8_t led_index, int16_t led_power) /* 커맨드에 의해서 LED파워 값을 저장할때 */
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
// if(((led_index >= 0)&&(led_index <= 49))||((led_power >= 0)&&(led_power <= 255))){
|
||||
if((led_index <= 47)||(led_power <= 255)){
|
||||
// led_power_dp[led_index] = led_power;
|
||||
|
||||
|
||||
if(NRF_SUCCESS != LED_WRITE_ROM(led_index,led_power)){
|
||||
DBG_PRINTF("ERR!!! DS3930 1\r\n");
|
||||
err_code = NRF_ERROR_INTERNAL;
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
DBG_PRINTF("ERR!!! led_index || pd_index Failed! %d, %d\r\n", led_index, led_power);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
ret_code_t led_power_save_mem_6(uint8_t led_index, int16_t led_power) /* 커맨드에 의해서 LED파워 값을 저장할때 */
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
// if(((led_index >= 0)&&(led_index <= 49))||((led_power >= 0)&&(led_power <= 255))){
|
||||
// if((led_index <= 47)||(led_power <= 255)){
|
||||
// led_power_dp[led_index] = led_power;
|
||||
|
||||
// for(uint8_t i = 0 ; i<48 ;i++){
|
||||
// if(NRF_SUCCESS != LED_WRITE_ROM(led_index,led_power)){
|
||||
// DBG_PRINTF("ERR!!! DS3930 1\r\n");
|
||||
// err_code = NRF_ERROR_INTERNAL;
|
||||
for(uint8_t i = 0 ; i<48 ;i++){
|
||||
|
||||
// led_power_dp[i] = led_power; Fstorage garbage
|
||||
if(NRF_SUCCESS != LED_WRITE_ROM(i,led_power)){
|
||||
DBG_PRINTF("ERR!!! DS3930 1\r\n");
|
||||
err_code = NRF_ERROR_INTERNAL;
|
||||
|
||||
}
|
||||
// nrf_delay_ms(20);
|
||||
|
||||
|
||||
else{
|
||||
// DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
// return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
nrf_delay_ms(10);
|
||||
}
|
||||
return err_code;
|
||||
}
|
||||
ret_code_t led_power_save_mem_48(uint8_t *led_power) /* 커맨드에 의해서 LED파워 값을 저장할때 */
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
// if(((led_index >= 0)&&(led_index <= 49))||((led_power >= 0)&&(led_power <= 255))){
|
||||
// if((led_index <= 47)||(led_power <= 255)){
|
||||
// led_power_dp[led_index] = led_power;
|
||||
|
||||
// for(uint8_t i = 0 ; i<48 ;i++){
|
||||
// if(NRF_SUCCESS != LED_WRITE_ROM(led_index,led_power)){
|
||||
// DBG_PRINTF("ERR!!! DS3930 1\r\n");
|
||||
// err_code = NRF_ERROR_INTERNAL;
|
||||
for(uint8_t i = 0 ; i<48 ;i++){
|
||||
|
||||
//led_power_dp[i] = led_power;
|
||||
if(NRF_SUCCESS != LED_WRITE_ROM(i,(int16_t)(led_power[i]))){
|
||||
DBG_PRINTF("ERR!!! DS3930 1\r\n");
|
||||
err_code = NRF_ERROR_INTERNAL;
|
||||
|
||||
}
|
||||
// nrf_delay_ms(20);
|
||||
|
||||
|
||||
else{
|
||||
// DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
// return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
nrf_delay_ms(10);
|
||||
}
|
||||
return err_code;
|
||||
}
|
||||
//void led_power_span(uint8_t led_index)
|
||||
//{
|
||||
// uint32_t err_code = NRF_SUCCESS;
|
||||
//
|
||||
// for(uint8_t i= 0 ;i<255 ;i++){
|
||||
// if(NRF_SUCCESS != LED_WRITE_ROM(led_index,i)){
|
||||
// DBG_PRINTF("ERR!!! DS3930 1\r\n");
|
||||
// err_code = NRF_ERROR_INTERNAL;
|
||||
// }
|
||||
// nrf_delay_ms(20);
|
||||
// }
|
||||
// DBG_PRINTF("DS3930 1\r\n");
|
||||
// }
|
||||
ret_code_t led_power_set(uint8_t led_index) /* LED켤때 사용, 메모리 값을 디지털포텐셔미터에 입력 */
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
// int16_t led_power; //no need
|
||||
|
||||
// if((led_index >= 1)&&(led_index <= 24)){
|
||||
|
||||
// led_power = led_power_dp[led_index];
|
||||
|
||||
// if(NRF_SUCCESS != ad5272_write_rdac(led_power)) { /* LED를 켜기전에 메모리에 저장된 파워값을 DAC에 설정 */
|
||||
// DBG_PRINTF("ERR!!! ad5272_write_rdac 2\r\n");
|
||||
// err_code = NRF_ERROR_INTERNAL;
|
||||
// }
|
||||
|
||||
// }else{
|
||||
// DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
// return NRF_ERROR_INTERNAL;
|
||||
// }
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t pd_gain_set(uint8_t activated_led) /* LED와 PD 매칭 값으로 On */
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
DBG_PRINTF("<<pd_gain_set L%d, P%d>>\r\n",activated_led ,pd_index);
|
||||
#endif
|
||||
|
||||
// if(((activated_led >= 0)&&(activated_led <= 49))||((pd_index >= 0)&&(pd_index <= 2))){
|
||||
if((activated_led <= 47)){
|
||||
|
||||
sw_i2c_init_once();
|
||||
|
||||
mcp4725_writeFastMode( led_pd_dac_v[activated_led]); /* LED는 먼저 ON되어 있어 하며 그 LED번호와 PD배칭 값으로 DAC에 설정 */
|
||||
//DBG_PRINTF("dac_v %d\r\n", led_pd_dac_v[pd_index][activated_led]);
|
||||
}
|
||||
else if(activated_led == 99){
|
||||
mcp4725_writeFastMode( led_off_dac_v); /* LED_OFF 배칭 값으로 DAC에 설정 */
|
||||
}
|
||||
else{
|
||||
DBG_PRINTF("ERR!!! led_index Failed! %d\r\n", activated_led);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
ret_code_t imm_gain_set(uint16_t imm_dac) /* LED와 PD 매칭 값으로 On */
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
|
||||
if((imm_dac <= 2000)){
|
||||
sw_i2c_init_once();//ad cj
|
||||
|
||||
mcp4725_writeFastMode( imm_dac); /* LED는 먼저 ON되어 있어 하며 그 LED번호와 PD배칭 값으로 DAC에 설정 */
|
||||
DBG_PRINTF("dac_v %d\r\n", imm_dac);
|
||||
}else{
|
||||
DBG_PRINTF("ERR!!! range Failed! %d\r\n", activated_led);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
ret_code_t led_select(uint8_t led_index)
|
||||
{
|
||||
|
||||
|
||||
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
//LED_ALLOFF();
|
||||
|
||||
|
||||
switch(led_index) {
|
||||
case 0:
|
||||
LED0();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
LED1();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
LED2();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
LED3();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
LED4();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
LED5();
|
||||
break;
|
||||
|
||||
|
||||
case 6:
|
||||
LED6();
|
||||
break;
|
||||
|
||||
case 7:
|
||||
LED7();
|
||||
break;
|
||||
|
||||
case 8:
|
||||
LED8();
|
||||
break;
|
||||
|
||||
case 9:
|
||||
LED9();
|
||||
break;
|
||||
|
||||
case 10:
|
||||
LED10();
|
||||
break;
|
||||
|
||||
case 11:
|
||||
LED11();
|
||||
break;
|
||||
|
||||
case 12:
|
||||
LED12();
|
||||
break;
|
||||
|
||||
case 13:
|
||||
LED13();
|
||||
break;
|
||||
|
||||
case 14:
|
||||
LED14();
|
||||
break;
|
||||
|
||||
case 15:
|
||||
LED15();
|
||||
break;
|
||||
|
||||
case 16:
|
||||
LED16();
|
||||
break;
|
||||
|
||||
case 17:
|
||||
LED17();
|
||||
break;
|
||||
|
||||
case 18:
|
||||
LED18();
|
||||
break;
|
||||
|
||||
case 19:
|
||||
LED19();
|
||||
break;
|
||||
|
||||
case 20:
|
||||
LED20();
|
||||
break;
|
||||
|
||||
case 21:
|
||||
LED21();
|
||||
break;
|
||||
|
||||
case 22:
|
||||
LED22();
|
||||
break;
|
||||
|
||||
case 23:
|
||||
LED23();
|
||||
break;
|
||||
|
||||
case 24:
|
||||
LED24();
|
||||
break;
|
||||
|
||||
case 25:
|
||||
LED25();
|
||||
break;
|
||||
|
||||
case 26:
|
||||
LED26();
|
||||
break;
|
||||
|
||||
case 27:
|
||||
LED27();
|
||||
break;
|
||||
|
||||
case 28:
|
||||
LED28();
|
||||
break;
|
||||
|
||||
case 29:
|
||||
LED29();
|
||||
break;
|
||||
|
||||
case 30:
|
||||
LED30();
|
||||
break;
|
||||
|
||||
case 31:
|
||||
LED31();
|
||||
break;
|
||||
|
||||
case 32:
|
||||
LED32();
|
||||
break;
|
||||
|
||||
case 33:
|
||||
LED33();
|
||||
break;
|
||||
|
||||
case 34:
|
||||
LED34();
|
||||
break;
|
||||
|
||||
case 35:
|
||||
LED35();
|
||||
break;
|
||||
|
||||
case 36:
|
||||
LED36();
|
||||
break;
|
||||
|
||||
case 37:
|
||||
LED37();
|
||||
break;
|
||||
|
||||
case 38:
|
||||
LED38();
|
||||
break;
|
||||
|
||||
case 39:
|
||||
LED39();
|
||||
break;
|
||||
|
||||
case 40:
|
||||
LED40();
|
||||
break;
|
||||
|
||||
case 41:
|
||||
LED41();
|
||||
break;
|
||||
|
||||
case 42:
|
||||
LED42();
|
||||
break;
|
||||
|
||||
case 43:
|
||||
LED43();
|
||||
break;
|
||||
|
||||
case 44:
|
||||
LED44();
|
||||
break;
|
||||
|
||||
case 45:
|
||||
LED45();
|
||||
break;
|
||||
|
||||
case 46:
|
||||
LED46();
|
||||
break;
|
||||
|
||||
case 47:
|
||||
LED47();
|
||||
break;
|
||||
|
||||
case 99:
|
||||
LED99();
|
||||
break;
|
||||
default:
|
||||
err_code = NRF_ERROR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
nrf_delay_ms(1);
|
||||
// DBG_PRINTF("LIGHT ON1 : %d \r\n",nrf_gpio_pin_read(LIGHT_ON1));
|
||||
// DBG_PRINTF("LIGHT ON2 : %d \r\n",nrf_gpio_pin_read(LIGHT_ON2));
|
||||
// DBG_PRINTF("LED_SEL_SW1 : %d \r\n",nrf_gpio_pin_read(LED_SEL_SW1));
|
||||
// DBG_PRINTF("LED_SEL_SW2 : %d \r\n",nrf_gpio_pin_read(LED_SEL_SW2));
|
||||
// DBG_PRINTF("LED_SEL_SW3 : %d \r\n",nrf_gpio_pin_read(LED_SEL_SW3));
|
||||
// DBG_PRINTF("LED_INDIV_SEL_SW1 : %d \r\n",nrf_gpio_pin_read(LED_INDIV_SEL_SW1));
|
||||
// DBG_PRINTF("LED_INDIV_SEL_SW2 : %d \r\n",nrf_gpio_pin_read(LED_INDIV_SEL_SW2));
|
||||
// DBG_PRINTF("LED_INDIV_SEL_SW3 : %d \r\n",nrf_gpio_pin_read(LED_INDIV_SEL_SW3));
|
||||
uint32_t port_state0 = nrf_gpio_port_out_read(NRF_P0);
|
||||
uint32_t port_state1 = nrf_gpio_port_out_read(NRF_P1);
|
||||
// DBG_PRINTF("test : %d, %d \r\n",port_state0,port_state1);
|
||||
|
||||
|
||||
// DBG_PRINTF("LIGHT ON1 : %d \r\n",port_state0>>22&1);
|
||||
// DBG_PRINTF("LIGHT ON2 : %d \r\n",port_state0>>23&1);
|
||||
// DBG_PRINTF("LED_SEL_SW1 : %d \r\n",port_state1>>4&1);
|
||||
// DBG_PRINTF("LED_SEL_SW2 : %d \r\n",port_state1>>5&1);
|
||||
// DBG_PRINTF("LED_SEL_SW3 : %d \r\n",port_state1>>6&1);
|
||||
// DBG_PRINTF("LED_INDIV_SEL_SW1 : %d \r\n",port_state1>>1&1);
|
||||
// DBG_PRINTF("LED_INDIV_SEL_SW2 : %d \r\n",port_state1>>2&1);
|
||||
// DBG_PRINTF("LED_INDIV_SEL_SW3 : %d \r\n",port_state1>>3&1);
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t pd_select(uint8_t pd_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
PD_ALLOFF();
|
||||
|
||||
switch(pd_index) {
|
||||
case 0:
|
||||
PD0();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
PD1();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
MOD();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
MOD2();
|
||||
break;
|
||||
|
||||
default:
|
||||
err_code = NRF_ERROR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return err_code;
|
||||
}
|
||||
void mea_send_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_mea_send_loop_timer_id, APP_TIMER_TICKS(MEA_SEND_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
|
||||
void mea_send_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_mea_send_loop_timer_id));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void mea_send_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_mea_send_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, mea_send_loop));
|
||||
}
|
||||
|
||||
666
project/ble_peripheral/ble_app_bladder_patch/measurements.h
Normal file
666
project/ble_peripheral/ble_app_bladder_patch/measurements.h
Normal file
@@ -0,0 +1,666 @@
|
||||
/*******************************************************************************
|
||||
* @file measurements.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MEASUREMENTS_H__
|
||||
#define _MEASUREMENTS_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
|
||||
#define trig_r NRF_GPIO_PIN_MAP(0,18)
|
||||
#define trig_r_CONFIG() nrf_gpio_cfg_output(trig_r)
|
||||
#define trig_SW(x) if(x == true) nrf_gpio_pin_set(trig_r);\
|
||||
else if(x == false) nrf_gpio_pin_clear(trig_r)
|
||||
/* For NIR LED */
|
||||
|
||||
//#define LIGHT_ON1 NRF_GPIO_PIN_MAP(0,28)
|
||||
//#define LIGHT_ON2 NRF_GPIO_PIN_MAP(0,29)
|
||||
//#define LIGHT_ON3 NRF_GPIO_PIN_MAP(0,31)
|
||||
//#define LIGHT_ON4 NRF_GPIO_PIN_MAP(0,19)
|
||||
//may work below.
|
||||
//#define VCSEL_SW1 NRF_GPIO_PIN_MAP(1,1)
|
||||
//#define VCSEL_SW2 NRF_GPIO_PIN_MAP(1,2)
|
||||
//#define VCSEL_SW3 NRF_GPIO_PIN_MAP(1,3)
|
||||
|
||||
|
||||
|
||||
#define LIGHT_ON NRF_GPIO_PIN_MAP(0,22)
|
||||
#define NIR_PART_SEL NRF_GPIO_PIN_MAP(1,7)
|
||||
|
||||
#define NIRLED_SEL0 NRF_GPIO_PIN_MAP(1,4)
|
||||
#define NIRLED_SEL1 NRF_GPIO_PIN_MAP(1,5)
|
||||
|
||||
#define NIR_WAV_SEL0 NRF_GPIO_PIN_MAP(1,1)
|
||||
#define NIR_WAV_SEL1 NRF_GPIO_PIN_MAP(1,2)
|
||||
#define NIR_WAV_SEL2 NRF_GPIO_PIN_MAP(1,3)
|
||||
|
||||
|
||||
|
||||
//#define LED_CONFIG() nrf_gpio_cfg(LIGHT_ON1, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT,NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0D1,NRF_GPIO_PIN_NOSENSE);\
|
||||
// nrf_gpio_cfg(LIGHT_ON2, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT,NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0D1,NRF_GPIO_PIN_NOSENSE);\
|
||||
// nrf_gpio_cfg(LED_SEL_SW1, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT,NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0D1,NRF_GPIO_PIN_NOSENSE);\
|
||||
// nrf_gpio_cfg(LED_SEL_SW2, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT,NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0D1,NRF_GPIO_PIN_NOSENSE);\
|
||||
// nrf_gpio_cfg(LED_SEL_SW3, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT,NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0D1,NRF_GPIO_PIN_NOSENSE);\
|
||||
// nrf_gpio_cfg(LED_INDIV_SEL_SW1, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT,NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0D1,NRF_GPIO_PIN_NOSENSE);\
|
||||
// nrf_gpio_cfg(LED_INDIV_SEL_SW2, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT,NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0D1,NRF_GPIO_PIN_NOSENSE);\
|
||||
// nrf_gpio_cfg(LED_INDIV_SEL_SW3, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_CONNECT,NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_S0D1,NRF_GPIO_PIN_NOSENSE);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define LED_CONFIG()nrf_gpio_cfg_output(LIGHT_ON);\
|
||||
nrf_gpio_cfg_output(NIR_PART_SEL);\
|
||||
nrf_gpio_cfg_output(NIRLED_SEL0);\
|
||||
nrf_gpio_cfg_output(NIRLED_SEL1);\
|
||||
nrf_gpio_cfg_output(NIR_WAV_SEL0);\
|
||||
nrf_gpio_cfg_output(NIR_WAV_SEL1);\
|
||||
nrf_gpio_cfg_output(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
|
||||
|
||||
// Macros for LEDs 0 to 5 ( LIGHT_ON -->0)
|
||||
#define LED0() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
#define LED1() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED2() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED3() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED4() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
#define LED5() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
|
||||
|
||||
// Macros for LEDs 10 to 15 ( LIGHT_ON -->0)
|
||||
#define LED6() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
#define LED7() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED8() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED9() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED10() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
#define LED11() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
// Macros for LEDs 20 to 25 ( LIGHT_ON -->0)
|
||||
#define LED12() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
#define LED13() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED14() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED15() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED16() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
#define LED17() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
// Macros for LEDs 30 to 35 ( LIGHT_ON -->0)
|
||||
#define LED18() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
#define LED19() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED20() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED21() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED22() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
#define LED23() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Macros for LEDs 40 to 45 ( LIGHT_ON -->0)
|
||||
#define LED24() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
#define LED25() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED26() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED27() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED28() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
#define LED29() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
|
||||
// Macros for LEDs 50 to 55 ( LIGHT_ON -->0)
|
||||
#define LED30() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
#define LED31() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED32() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED33() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED34() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
#define LED35() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
|
||||
// Macros for LEDs 60 to 65 ( LIGHT_ON -->0)
|
||||
#define LED36() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
#define LED37() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED38() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED39() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED40() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
#define LED41() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_clear(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Macros for LEDs 70 to 75 ( LIGHT_ON -->0)
|
||||
#define LED42() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
#define LED43() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED44() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED45() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
#define LED46() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
#define LED47() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_set(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_clear(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
|
||||
#define LED_ALLOFF() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
|
||||
#define LED99() nrf_gpio_pin_clear(LIGHT_ON); \
|
||||
nrf_gpio_pin_clear(NIR_PART_SEL); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL0); \
|
||||
nrf_gpio_pin_set(NIRLED_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL0); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL1); \
|
||||
nrf_gpio_pin_set(NIR_WAV_SEL2)
|
||||
|
||||
|
||||
/*
|
||||
#define LED23() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
#define LED24() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
|
||||
|
||||
#define LED_ALLOFF() nrf_gpio_pin_clear(LIGHT_ON1);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON2);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* For Photo Diode */
|
||||
|
||||
//#define MUX_EN_RDATA1 NRF_GPIO_PIN_MAP(1,6)
|
||||
//#define MUX_EN_RDATA2 NRF_GPIO_PIN_MAP(1,5)
|
||||
//#define MUX_EN_RDATA3 NRF_GPIO_PIN_MAP(1,4)
|
||||
//
|
||||
//#define RDATA_SW1 NRF_GPIO_PIN_MAP(0,23)
|
||||
//#define RDATA_SW2 NRF_GPIO_PIN_MAP(0,22)
|
||||
//#define RDATA_SW3 NRF_GPIO_PIN_MAP(0,21)
|
||||
|
||||
#define PD_SEL0 NRF_GPIO_PIN_MAP(1,12)
|
||||
#define PD_SEL1 NRF_GPIO_PIN_MAP(1,11)
|
||||
//#define PD_SEL3 NRF_GPIO_PIN_MAP(1,10) no use
|
||||
|
||||
#define PD_CONFIG() nrf_gpio_cfg_output(PD_SEL0);\
|
||||
nrf_gpio_cfg_output(PD_SEL1)
|
||||
|
||||
#define PD0() nrf_gpio_pin_clear(PD_SEL0);\
|
||||
nrf_gpio_pin_clear(PD_SEL1)
|
||||
|
||||
#define PD1() nrf_gpio_pin_set(PD_SEL0);\
|
||||
nrf_gpio_pin_clear(PD_SEL1)
|
||||
|
||||
#define MOD() nrf_gpio_pin_clear(PD_SEL0);\
|
||||
nrf_gpio_pin_set(PD_SEL1)
|
||||
#define MOD2() nrf_gpio_pin_set(PD_SEL0);\
|
||||
nrf_gpio_pin_set(PD_SEL1)
|
||||
/*
|
||||
#define PD4() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD5() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_set(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
|
||||
|
||||
|
||||
#define PD_ALLOFF() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_set(PD_SEL2);\
|
||||
nrf_gpio_pin_set(PD_SEL3)
|
||||
*/
|
||||
#define PD_ALLOFF() nrf_gpio_pin_set(PD_SEL0);\
|
||||
nrf_gpio_pin_set(PD_SEL1)
|
||||
|
||||
|
||||
/* For IC_NZP */ // No USE for 3.0
|
||||
//#define VCSEL_EN_PIN NRF_GPIO_PIN_MAP(1,7)
|
||||
//#define VCSEL_CONFIG() nrf_gpio_cfg_output(VCSEL_EN_PIN)
|
||||
//#define VCSEL_SW(x) if(x == true) nrf_gpio_pin_set(VCSEL_EN_PIN);\
|
||||
// else if(x == false) nrf_gpio_pin_clear(VCSEL_EN_PIN)
|
||||
|
||||
|
||||
/* For AGC SW FSA5157L6X */
|
||||
#define GAIN_SW_PIN NRF_GPIO_PIN_MAP(0,20)
|
||||
#define GAIN_SW_CONFIG() nrf_gpio_cfg_output(GAIN_SW_PIN)
|
||||
#define AGC_GAIN_SW(x) if(x == true) nrf_gpio_pin_set(GAIN_SW_PIN);\
|
||||
else if(x == false) nrf_gpio_pin_clear(GAIN_SW_PIN)
|
||||
|
||||
|
||||
|
||||
|
||||
void led_pd_gain_array_printout(void);
|
||||
ret_code_t led_on(uint8_t led_index);
|
||||
ret_code_t led_off(uint8_t led_index);
|
||||
ret_code_t led_pd_matching_value_set(uint8_t led_index);
|
||||
|
||||
|
||||
|
||||
ret_code_t led_pd_mod_set(uint16_t mod_gain);
|
||||
ret_code_t pd_on(uint8_t pd_index);
|
||||
ret_code_t pd_off(uint8_t pd_index);
|
||||
int16_t led_power_read(uint8_t led_index);
|
||||
void led_power_read_48(uint16_t *data);
|
||||
ret_code_t led_power_save_mem(uint8_t led_index, int16_t led_power);
|
||||
ret_code_t led_power_save_mem_6(uint8_t led_index, int16_t led_power);
|
||||
ret_code_t led_power_save_mem_48( uint8_t *led_power);
|
||||
ret_code_t led_power_set(uint8_t led_index);
|
||||
ret_code_t pd_gain_set(uint8_t activated_led); //version B change 2025.04.27
|
||||
ret_code_t imm_gain_set(uint16_t imm_dac); //version B add 2025.05.07
|
||||
ret_code_t led_select(uint8_t led_index);
|
||||
ret_code_t pd_select(uint8_t pd_index);
|
||||
void led_power_span(uint8_t led_index);
|
||||
void mea_send_loop(void * p_context); /* For x ms */
|
||||
void mea_send_timer_start(void);
|
||||
void mea_send_timer_stop(void);
|
||||
void mea_send_timer_init(void);
|
||||
#endif //_MEASUREMENTS_H__
|
||||
|
||||
657
project/ble_peripheral/ble_app_bladder_patch/measurements_20.c
Normal file
657
project/ble_peripheral/ble_app_bladder_patch/measurements_20.c
Normal file
@@ -0,0 +1,657 @@
|
||||
/*******************************************************************************
|
||||
* @file measurements.c
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
#include "nrf_drv_spi.h"
|
||||
#include "nrf_drv_saadc.h"
|
||||
#include "nrf_drv_ppi.h"
|
||||
#include "nrf_drv_timer.h"
|
||||
#include "boards.h"
|
||||
#include "bsp.h"
|
||||
#include "app_error.h"
|
||||
#include "nrf_delay.h"
|
||||
#include "app_util_platform.h"
|
||||
#include "nrf_pwr_mgmt.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
|
||||
#include "ble_nus.h"
|
||||
#include "app_timer.h"
|
||||
#include "measurements.h"
|
||||
#include "main.h"
|
||||
#include "fstorage.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
|
||||
|
||||
uint8_t activated_led = 99;
|
||||
uint8_t activated_pd = 99;
|
||||
APP_TIMER_DEF(m_mea_send_loop_timer_id);
|
||||
static uint8_t cnt =0;
|
||||
#define MEA_SEND_LOOP_INTERVAL 100
|
||||
char mea_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||
extern volatile bool processing;
|
||||
/* Default Value before initialized. Set value for Default!!! */ /* 초기값 설정 */
|
||||
/* 0번은 사용하지 않음 = NULL, 1 ~ 24까지 사용 */
|
||||
/*AD5272 DP에 쓸수 있는 값 범위는 0 ~ 1023 */
|
||||
//uint16_t led_power_dp[LED_NUM] = {
|
||||
// //NULL, 42, 29, 41, 31, 28, 28, 42, 28, 39, 29, 27, 27, 42, 29, 40, 30, 28, 28, 40, 27, 38, 28, 25, 22
|
||||
// 0,25,25,18,19,24,24,25,25,18,19,25,23,25,25,18,19,24,24,25,25,19,20,25,24
|
||||
//};
|
||||
|
||||
/*LED0 = NULL 사용하지 않음, LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8, LED9, LED10, LED11, LED12, LED13, LED14, LED15, LED16, LED17, LED18, LED19, LED20, LED21, LED22, LED23, LED24 */
|
||||
/*MCP4725 를 0.1V(125) ~ 1.1V(1366) 값을 사용 */
|
||||
//uint16_t led_pd_dac_v[PD_NUM][LED_NUM] = {
|
||||
// {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, /*PD0 사용 않음 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD1 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD2 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD3 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD4 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD5 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD6 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD7 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD8 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD9 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD10 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD11 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD12 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD13 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD14 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD15 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD16 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD17 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD18 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD19 */
|
||||
// {NULL, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* PD20 */
|
||||
//};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void led_pd_gain_array_printout(void)
|
||||
{
|
||||
// printf("\r\nLED-DP Gain Array =\r\n");
|
||||
// for(uint16_t i = 0; i < LED_NUM; i++){
|
||||
// printf("%d,\t", led_power_dp[i]);
|
||||
// }
|
||||
// printf("\r\n");
|
||||
|
||||
// printf("\r\nLED-PD Gain Array =\r\n");
|
||||
// for(uint16_t i = 0; i < PD_NUM; i++){
|
||||
// for(uint16_t j = 0; j < LED_NUM; j++){
|
||||
// printf("%d,\t", led_pd_dac_v[i][j]);
|
||||
// }
|
||||
// break;
|
||||
// printf("\r\n");
|
||||
// }
|
||||
// printf("\r\n");
|
||||
// nrf_delay_ms(5);
|
||||
cnt=0;
|
||||
|
||||
mea_send_timer_start();
|
||||
}
|
||||
|
||||
|
||||
void mea_send_loop(void * p_context) /* For x ms */
|
||||
{
|
||||
|
||||
|
||||
UNUSED_PARAMETER(p_context);
|
||||
printf("\r\n1CNT =%d\r\n",cnt);
|
||||
mea_send_timer_stop();
|
||||
|
||||
|
||||
if (cnt < 21)
|
||||
{
|
||||
uint8_t i = cnt;
|
||||
sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, m_config.led_pd_dac_v[i][0], m_config.led_pd_dac_v[i][1], m_config.led_pd_dac_v[i][2], m_config.led_pd_dac_v[i][3], m_config.led_pd_dac_v[i][4], m_config.led_pd_dac_v[i][5], m_config.led_pd_dac_v[i][6], m_config.led_pd_dac_v[i][7],m_config.led_pd_dac_v[i][8], m_config.led_pd_dac_v[i][9], m_config.led_pd_dac_v[i][10],
|
||||
m_config.led_pd_dac_v[i][11], m_config.led_pd_dac_v[i][12], m_config.led_pd_dac_v[i][13], m_config.led_pd_dac_v[i][14], m_config.led_pd_dac_v[i][15], m_config.led_pd_dac_v[i][16], m_config.led_pd_dac_v[i][17],m_config.led_pd_dac_v[i][18], m_config.led_pd_dac_v[i][19], m_config.led_pd_dac_v[i][20], m_config.led_pd_dac_v[i][21],m_config.led_pd_dac_v[i][22], m_config.led_pd_dac_v[i][23], m_config.led_pd_dac_v[i][24]);
|
||||
data_tx_handler(mea_tx_buffer);
|
||||
printf("\r\n2CNT =%d\r\n",cnt);
|
||||
|
||||
mea_send_timer_start();
|
||||
|
||||
// switch(cnt){
|
||||
// case 0:
|
||||
// break;
|
||||
// case 1:
|
||||
// sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, 0,m_config.led_pd_dac_v_led_1[1], m_config.led_pd_dac_v_led_2[1], m_config.led_pd_dac_v_led_3[1], m_config.led_pd_dac_v_led_4[1], m_config.led_pd_dac_v_led_5[1], m_config.led_pd_dac_v_led_6[1], m_config.led_pd_dac_v_led_7[1], m_config.led_pd_dac_v_led_8[1],
|
||||
// m_config.led_pd_dac_v_led_9[1], m_config.led_pd_dac_v_led_10[1], m_config.led_pd_dac_v_led_11[1], m_config.led_pd_dac_v_led_12[1], m_config.led_pd_dac_v_led_13[1], m_config.led_pd_dac_v_led_14[1], m_config.led_pd_dac_v_led_15[1], m_config.led_pd_dac_v_led_16[1], m_config.led_pd_dac_v_led_17[1],m_config.led_pd_dac_v_led_18[1],
|
||||
// m_config.led_pd_dac_v_led_19[1], m_config.led_pd_dac_v_led_20[1],m_config.led_pd_dac_v_led_21[1], m_config.led_pd_dac_v_led_22[1],m_config.led_pd_dac_v_led_23[1], m_config.led_pd_dac_v_led_24[1]);
|
||||
// break;
|
||||
// case 2:
|
||||
// sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i, 0, m_config.led_pd_dac_v_led_1[1], m_config.led_pd_dac_v_led_2[1], m_config.led_pd_dac_v_led_3[1], m_config.led_pd_dac_v_led_4[1], m_config.led_pd_dac_v_led_5[1], m_config.led_pd_dac_v_led_6[1], m_config.led_pd_dac_v_led_7[1], m_config.led_pd_dac_v_led_8[1],
|
||||
// m_config.led_pd_dac_v_led_9[1], m_config.led_pd_dac_v_led_10[1], m_config.led_pd_dac_v_led_11[1], m_config.led_pd_dac_v_led_12[1], m_config.led_pd_dac_v_led_13[1], m_config.led_pd_dac_v_led_14[1], m_config.led_pd_dac_v_led_15[1], m_config.led_pd_dac_v_led_16[1], m_config.led_pd_dac_v_led_17[1],m_config.led_pd_dac_v_led_18[1],
|
||||
// m_config.led_pd_dac_v_led_19[1], m_config.led_pd_dac_v_led_20[1],m_config.led_pd_dac_v_led_21[1], m_config.led_pd_dac_v_led_22[1],m_config.led_pd_dac_v_led_23[1], m_config.led_pd_dac_v_led_24[1]);
|
||||
// break;
|
||||
// case 3:
|
||||
// sprintf(mea_tx_buffer, "Tag-Currrnt %d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d,\t%d\r\n", i,0, m_config.led_pd_dac_v_led_1[1], m_config.led_pd_dac_v_led_2[1], m_config.led_pd_dac_v_led_3[1], m_config.led_pd_dac_v_led_4[1], m_config.led_pd_dac_v_led_5[1], m_config.led_pd_dac_v_led_6[1], m_config.led_pd_dac_v_led_7[1], m_config.led_pd_dac_v_led_8[1],
|
||||
// m_config.led_pd_dac_v_led_9[1], m_config.led_pd_dac_v_led_10[1], m_config.led_pd_dac_v_led_11[1], m_config.led_pd_dac_v_led_12[1], m_config.led_pd_dac_v_led_13[1], m_config.led_pd_dac_v_led_14[1], m_config.led_pd_dac_v_led_15[1], m_config.led_pd_dac_v_led_16[1], m_config.led_pd_dac_v_led_17[1],m_config.led_pd_dac_v_led_18[1],
|
||||
// m_config.led_pd_dac_v_led_19[1], m_config.led_pd_dac_v_led_20[1],m_config.led_pd_dac_v_led_21[1], m_config.led_pd_dac_v_led_22[1],m_config.led_pd_dac_v_led_23[1], m_config.led_pd_dac_v_led_24[1]);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
//// }
|
||||
|
||||
// sprintf(mea_tx_buffer,"CNT_%d\r\n",cnt);
|
||||
// data_tx_handler(mea_tx_buffer);
|
||||
//
|
||||
// mea_send_timer_start();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//battery_timer_start();
|
||||
sprintf(mea_tx_buffer,"END \r\n");
|
||||
data_tx_handler(mea_tx_buffer);
|
||||
printf("\r\nLED-DP Gain Array =\r\n");
|
||||
for(uint16_t i = 0; i < LED_NUM; i++){
|
||||
printf("%d,\t", m_config.led_power_dp[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
printf("\r\nLED-PD Gain Array =\r\n");
|
||||
for(uint16_t i = 0; i < PD_NUM; i++){
|
||||
for(uint16_t j = 0; j < LED_NUM; j++){
|
||||
printf("%d,\t", m_config.led_pd_dac_v[i][j]);
|
||||
}
|
||||
///break;
|
||||
printf("\r\n");
|
||||
}
|
||||
printf("\r\n");
|
||||
processing = false ;
|
||||
}
|
||||
|
||||
cnt++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ret_code_t led_on(uint8_t led_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("\tled_on, %d =====================\r\n", led_index);
|
||||
#endif
|
||||
|
||||
if((led_index >= 1)&&(led_index <= 24)){
|
||||
|
||||
activated_led = led_index;
|
||||
|
||||
/* LED켤때 파워 셋팅한후 켜는지 결정요 */
|
||||
if(NRF_SUCCESS != led_power_set(led_index)) {
|
||||
printf("ERR!!! LED Power set\r\n");
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
#if FEATURE_FOR_SCOPE
|
||||
nrf_gpio_pin_set(LED_CLK_15);
|
||||
nrf_gpio_pin_clear(LED_CLK_15);
|
||||
#endif
|
||||
|
||||
if(NRF_SUCCESS != led_select(led_index)){
|
||||
printf("ERR!!! LED Select\r\n");
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
VCSEL_SW(true);
|
||||
|
||||
}else{
|
||||
printf("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t led_off(uint8_t led_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("led_off\r\n");
|
||||
#endif
|
||||
|
||||
if(led_index == 99){
|
||||
LED_ALLOFF();
|
||||
VCSEL_SW(false);
|
||||
|
||||
activated_led = 99;
|
||||
}else{
|
||||
printf("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t led_pd_matching_value_set(uint8_t led_index, uint8_t pd_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
if(((led_index >= 1)&&(led_index <= 24))||((pd_index >= 1)&&(pd_index <= 20))){
|
||||
|
||||
if(NRF_SUCCESS != pd_gain_set(led_index, pd_index)){
|
||||
printf("ERR!!! pd_gain_set\r\n");
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
if(NRF_SUCCESS != pd_on(pd_index)){
|
||||
printf("ERR!!! pd_on\r\n");
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
}else{
|
||||
printf("ERR!!! led_index || pd_index Failed! %d, %d\r\n", led_index, pd_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t pd_on(uint8_t pd_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
#if FEATURE_FOR_SCOPE
|
||||
nrf_gpio_pin_set(PD_CLK_26);
|
||||
nrf_gpio_pin_clear(PD_CLK_26);
|
||||
#endif
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("pd_on, %d ===== \r\n", pd_index);
|
||||
#endif
|
||||
|
||||
if((pd_index >= 1)&&(pd_index <= 20)){
|
||||
|
||||
activated_pd = pd_index;
|
||||
|
||||
if(NRF_SUCCESS != pd_select(pd_index)){
|
||||
printf("ERR!!! pd_on Failed! %d\r\n", pd_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
}else{
|
||||
printf("ERR!!! pd_index Failed! %d\r\n", pd_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t pd_off(uint8_t pd_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("pd_off\r\n");
|
||||
#endif
|
||||
|
||||
if(pd_index == 99){
|
||||
PD_ALLOFF();
|
||||
activated_pd = 99;
|
||||
}else{
|
||||
printf("ERR!!! PD Off Failed! %d\r\n", pd_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
int16_t led_power_read(uint8_t led_index)
|
||||
{
|
||||
int16_t led_power;
|
||||
|
||||
if((led_index >= 1)&&(led_index <= 24)){
|
||||
led_power = m_config.led_power_dp[led_index];
|
||||
}else{
|
||||
printf("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return led_power;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t led_power_save_mem(uint8_t led_index, int16_t led_power) /* 커맨드에 의해서 LED파워 값을 저장할때 */
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
if(((led_index >= 1)&&(led_index <= 24))||((led_power >= 0)&&(led_power <= 1023))){
|
||||
m_config.led_power_dp[led_index] = led_power;
|
||||
|
||||
if(activated_led == led_index) { /* LED파워 값을 RDAC에도 설정함. */
|
||||
if(NRF_SUCCESS != ad5272_write_rdac(led_power)){
|
||||
printf("ERR!!! ad5272_write_rdac 1\r\n");
|
||||
err_code = NRF_ERROR_INTERNAL;
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
printf("ERR!!! led_index || pd_index Failed! %d, %d\r\n", led_index, led_power);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t led_power_set(uint8_t led_index) /* LED켤때 사용, 메모리 값을 디지털포텐셔미터에 입력 */
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
int16_t led_power;
|
||||
|
||||
if((led_index >= 1)&&(led_index <= 24)){
|
||||
|
||||
led_power = m_config.led_power_dp[led_index];
|
||||
|
||||
if(NRF_SUCCESS != ad5272_write_rdac(led_power)) { /* LED를 켜기전에 메모리에 저장된 파워값을 DAC에 설정 */
|
||||
printf("ERR!!! ad5272_write_rdac 2\r\n");
|
||||
err_code = NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
}else{
|
||||
printf("ERR!!! led_index Failed! %d\r\n", led_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t pd_gain_set(uint8_t activated_led, uint8_t pd_index) /* LED와 PD 매칭 값으로 On */
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
#if FEATURE_PRINTF
|
||||
printf("<<pd_gain_set L%d, P%d>>\r\n",activated_led ,pd_index);
|
||||
#endif
|
||||
|
||||
if(((activated_led >= 1)&&(activated_led <= 24))||((pd_index >= 1)&&(pd_index <= 20))){
|
||||
mcp4725_writeFastMode( m_config.led_pd_dac_v[pd_index][activated_led]); /* LED는 먼저 ON되어 있어 하며 그 LED번호와 PD배칭 값으로 DAC에 설정 */
|
||||
|
||||
}else{
|
||||
printf("ERR!!! led_index || pd_index Failed! %d, %d\r\n", activated_led, pd_index);
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t led_select(uint8_t led_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
LED_ALLOFF();
|
||||
VCSEL_SW(false);
|
||||
|
||||
switch(led_index) {
|
||||
case 1:
|
||||
LED1();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
LED2();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
LED3();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
LED4();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
LED5();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
LED6();
|
||||
break;
|
||||
|
||||
case 7:
|
||||
LED7();
|
||||
break;
|
||||
|
||||
case 8:
|
||||
LED8();
|
||||
break;
|
||||
|
||||
case 9:
|
||||
LED9();
|
||||
break;
|
||||
|
||||
case 10:
|
||||
LED10();
|
||||
break;
|
||||
|
||||
case 11:
|
||||
LED11();
|
||||
break;
|
||||
|
||||
case 12:
|
||||
LED12();
|
||||
break;
|
||||
|
||||
case 13:
|
||||
LED13();
|
||||
break;
|
||||
|
||||
case 14:
|
||||
LED14();
|
||||
break;
|
||||
|
||||
case 15:
|
||||
LED15();
|
||||
break;
|
||||
|
||||
case 16:
|
||||
LED16();
|
||||
break;
|
||||
|
||||
case 17:
|
||||
LED17();
|
||||
break;
|
||||
|
||||
case 18:
|
||||
LED18();
|
||||
break;
|
||||
|
||||
case 19:
|
||||
LED19();
|
||||
break;
|
||||
|
||||
case 20:
|
||||
LED20();
|
||||
break;
|
||||
|
||||
case 21:
|
||||
LED21();
|
||||
break;
|
||||
|
||||
case 22:
|
||||
LED22();
|
||||
break;
|
||||
|
||||
case 23:
|
||||
LED23();
|
||||
break;
|
||||
|
||||
case 24:
|
||||
LED24();
|
||||
break;
|
||||
|
||||
default:
|
||||
err_code = NRF_ERROR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
ret_code_t pd_select(uint8_t pd_index)
|
||||
{
|
||||
uint32_t err_code = NRF_SUCCESS;
|
||||
|
||||
PD_ALLOFF();
|
||||
|
||||
switch(pd_index) {
|
||||
case 1:
|
||||
PD1();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
PD2();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
PD3();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
PD4();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
PD5();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
PD6();
|
||||
break;
|
||||
|
||||
case 7:
|
||||
PD7();
|
||||
break;
|
||||
|
||||
case 8:
|
||||
PD8();
|
||||
break;
|
||||
|
||||
case 9:
|
||||
PD9();
|
||||
break;
|
||||
|
||||
case 10:
|
||||
PD10();
|
||||
break;
|
||||
|
||||
case 11:
|
||||
PD11();
|
||||
break;
|
||||
|
||||
case 12:
|
||||
PD12();
|
||||
break;
|
||||
|
||||
case 13:
|
||||
PD13();
|
||||
break;
|
||||
|
||||
case 14:
|
||||
PD14();
|
||||
break;
|
||||
|
||||
case 15:
|
||||
PD15();
|
||||
break;
|
||||
|
||||
case 16:
|
||||
PD16();
|
||||
break;
|
||||
|
||||
case 17:
|
||||
PD17();
|
||||
break;
|
||||
|
||||
case 18:
|
||||
PD18();
|
||||
break;
|
||||
|
||||
case 19:
|
||||
PD19();
|
||||
break;
|
||||
|
||||
case 20:
|
||||
PD20();
|
||||
break;
|
||||
|
||||
default:
|
||||
err_code = NRF_ERROR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
void mea_send_timer_start(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_start(m_mea_send_loop_timer_id, APP_TIMER_TICKS(MEA_SEND_LOOP_INTERVAL), NULL));
|
||||
}
|
||||
|
||||
|
||||
void mea_send_timer_stop(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_stop(m_mea_send_loop_timer_id));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void mea_send_timer_init(void)
|
||||
{
|
||||
APP_ERROR_CHECK(app_timer_create(&m_mea_send_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, mea_send_loop));
|
||||
}
|
||||
|
||||
519
project/ble_peripheral/ble_app_bladder_patch/measurements_20.h
Normal file
519
project/ble_peripheral/ble_app_bladder_patch/measurements_20.h
Normal file
@@ -0,0 +1,519 @@
|
||||
/*******************************************************************************
|
||||
* @file measurements.h
|
||||
* @author CandyPops Co.
|
||||
* @version V1.0.0
|
||||
* @date 2022-09-05
|
||||
* @brief
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _MEASUREMENTS_H__
|
||||
#define _MEASUREMENTS_H__
|
||||
|
||||
#include "sdk_common.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nrf.h"
|
||||
#include "nrf_drv_gpiote.h"
|
||||
|
||||
|
||||
/* For NIR LED */
|
||||
|
||||
#define LIGHT_ON1 NRF_GPIO_PIN_MAP(0,28)
|
||||
#define LIGHT_ON2 NRF_GPIO_PIN_MAP(0,29)
|
||||
#define LIGHT_ON3 NRF_GPIO_PIN_MAP(0,31)
|
||||
#define LIGHT_ON4 NRF_GPIO_PIN_MAP(0,19)
|
||||
|
||||
#define VCSEL_SW1 NRF_GPIO_PIN_MAP(1,1)
|
||||
#define VCSEL_SW2 NRF_GPIO_PIN_MAP(1,2)
|
||||
#define VCSEL_SW3 NRF_GPIO_PIN_MAP(1,3)
|
||||
|
||||
#define LED_CONFIG() nrf_gpio_cfg_output(LIGHT_ON1);\
|
||||
nrf_gpio_cfg_output(LIGHT_ON2);\
|
||||
nrf_gpio_cfg_output(LIGHT_ON3);\
|
||||
nrf_gpio_cfg_output(LIGHT_ON4);\
|
||||
nrf_gpio_cfg_output(VCSEL_SW1);\
|
||||
nrf_gpio_cfg_output(VCSEL_SW2);\
|
||||
nrf_gpio_cfg_output(VCSEL_SW3)
|
||||
|
||||
#define LED1() nrf_gpio_pin_clear(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED2() nrf_gpio_pin_clear(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED3() nrf_gpio_pin_clear(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED4() nrf_gpio_pin_clear(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED5() nrf_gpio_pin_clear(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
#define LED6() nrf_gpio_pin_clear(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
|
||||
|
||||
#define LED7() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED8() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED9() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED10() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED11() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
#define LED12() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
|
||||
#define LED13() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED14() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED15() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED16() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED17() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
#define LED18() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON3);\
|
||||
nrf_gpio_pin_set(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
|
||||
#define LED19() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED20() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED21() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED22() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW3)
|
||||
|
||||
#define LED23() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
#define LED24() nrf_gpio_pin_set(LIGHT_ON1);\
|
||||
nrf_gpio_pin_set(LIGHT_ON2);\
|
||||
nrf_gpio_pin_set(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_clear(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
|
||||
|
||||
#define LED_ALLOFF() nrf_gpio_pin_clear(LIGHT_ON1);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON2);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON3);\
|
||||
nrf_gpio_pin_clear(LIGHT_ON4);\
|
||||
nrf_gpio_pin_set(VCSEL_SW1);\
|
||||
nrf_gpio_pin_set(VCSEL_SW2);\
|
||||
nrf_gpio_pin_set(VCSEL_SW3)
|
||||
|
||||
|
||||
/* For Photo Diode */
|
||||
|
||||
#define MUX_EN_RDATA1 NRF_GPIO_PIN_MAP(1,6)
|
||||
#define MUX_EN_RDATA2 NRF_GPIO_PIN_MAP(1,5)
|
||||
#define MUX_EN_RDATA3 NRF_GPIO_PIN_MAP(1,4)
|
||||
|
||||
#define RDATA_SW1 NRF_GPIO_PIN_MAP(0,23)
|
||||
#define RDATA_SW2 NRF_GPIO_PIN_MAP(0,22)
|
||||
#define RDATA_SW3 NRF_GPIO_PIN_MAP(0,21)
|
||||
|
||||
#define PD_SEL1 NRF_GPIO_PIN_MAP(1,12)
|
||||
#define PD_SEL2 NRF_GPIO_PIN_MAP(1,11)
|
||||
#define PD_SEL3 NRF_GPIO_PIN_MAP(1,10)
|
||||
|
||||
#define PD_CONFIG() nrf_gpio_cfg_output(MUX_EN_RDATA1);\
|
||||
nrf_gpio_cfg_output(MUX_EN_RDATA2);\
|
||||
nrf_gpio_cfg_output(MUX_EN_RDATA3);\
|
||||
nrf_gpio_cfg_output(RDATA_SW1);\
|
||||
nrf_gpio_cfg_output(RDATA_SW2);\
|
||||
nrf_gpio_cfg_output(RDATA_SW3);\
|
||||
nrf_gpio_cfg_output(PD_SEL1);\
|
||||
nrf_gpio_cfg_output(PD_SEL2);\
|
||||
nrf_gpio_cfg_output(PD_SEL3)
|
||||
|
||||
#define PD1() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD2() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD3() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD4() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD5() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_set(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD6() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_set(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD7() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_set(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD8() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_set(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD9() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD10() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD11() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD12() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD13() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_set(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD14() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_set(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD15() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_set(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD16() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_set(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_clear(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD17() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_set(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD18() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_set(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD19() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_set(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
#define PD20() nrf_gpio_pin_set(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_set(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_set(RDATA_SW1);\
|
||||
nrf_gpio_pin_set(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_clear(PD_SEL1);\
|
||||
nrf_gpio_pin_set(PD_SEL2);\
|
||||
nrf_gpio_pin_clear(PD_SEL3)
|
||||
|
||||
|
||||
#define PD_ALLOFF() nrf_gpio_pin_clear(MUX_EN_RDATA1);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA2);\
|
||||
nrf_gpio_pin_clear(MUX_EN_RDATA3);\
|
||||
nrf_gpio_pin_clear(RDATA_SW1);\
|
||||
nrf_gpio_pin_clear(RDATA_SW2);\
|
||||
nrf_gpio_pin_clear(RDATA_SW3);\
|
||||
nrf_gpio_pin_set(PD_SEL1);\
|
||||
nrf_gpio_pin_set(PD_SEL2);\
|
||||
nrf_gpio_pin_set(PD_SEL3)
|
||||
|
||||
|
||||
/* For IC_NZP */
|
||||
#define VCSEL_EN_PIN NRF_GPIO_PIN_MAP(1,7)
|
||||
#define VCSEL_CONFIG() nrf_gpio_cfg_output(VCSEL_EN_PIN)
|
||||
#define VCSEL_SW(x) if(x == true) nrf_gpio_pin_set(VCSEL_EN_PIN);\
|
||||
else if(x == false) nrf_gpio_pin_clear(VCSEL_EN_PIN)
|
||||
|
||||
|
||||
/* For AGC SW FSA5157L6X */
|
||||
#define GAIN_SW_PIN NRF_GPIO_PIN_MAP(0,20)
|
||||
#define GAIN_SW_CONFIG() nrf_gpio_cfg_output(GAIN_SW_PIN)
|
||||
#define AGC_GAIN_SW(x) if(x == true) nrf_gpio_pin_set(GAIN_SW_PIN);\
|
||||
else if(x == false) nrf_gpio_pin_clear(GAIN_SW_PIN)
|
||||
|
||||
#if FEATURE_FOR_SCOPE
|
||||
#define ADC_CLK_18 18
|
||||
#define PD_CLK_26 26
|
||||
#define LED_CLK_15 15
|
||||
#endif
|
||||
|
||||
|
||||
void led_pd_gain_array_printout(void);
|
||||
ret_code_t led_on(uint8_t led_index);
|
||||
ret_code_t led_off(uint8_t led_index);
|
||||
ret_code_t led_pd_matching_value_set(uint8_t led_index, uint8_t pd_index);
|
||||
ret_code_t pd_on(uint8_t pd_index);
|
||||
ret_code_t pd_off(uint8_t pd_index);
|
||||
int16_t led_power_read(uint8_t led_index);
|
||||
ret_code_t led_power_save_mem(uint8_t led_index, int16_t led_power);
|
||||
ret_code_t led_power_set(uint8_t led_index);
|
||||
ret_code_t pd_gain_set(uint8_t activated_led, uint8_t pd_index);
|
||||
ret_code_t led_select(uint8_t led_index);
|
||||
ret_code_t pd_select(uint8_t pd_index);
|
||||
void mea_send_loop(void * p_context); /* For x ms */
|
||||
void mea_send_timer_start(void);
|
||||
void mea_send_timer_stop(void);
|
||||
void mea_send_timer_init(void);
|
||||
|
||||
#endif //_MEASUREMENTS_H__
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
..\..\..\..\..\..\..\pc_firm\dr_adc121s051\dr_adc121s051.c,
|
||||
..\..\..\..\..\..\..\pc_firm\dr_adc121s051\dr_adc121s051.h
|
||||
TO nrf52840_xxaa.hex RTE NOPRINT
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
|
||||
|
||||
<component name="EventRecorderStub" version="1.0.0"/> <!--name and version of the component-->
|
||||
<events>
|
||||
</events>
|
||||
|
||||
</component_viewer>
|
||||
@@ -0,0 +1,68 @@
|
||||
T17578 000:016.299 SEGGER J-Link V7.22b Log File
|
||||
T17578 000:016.864 DLL Compiled: Jun 17 2021 17:22:49
|
||||
T17578 000:016.869 Logging started @ 2026-01-24 07:30
|
||||
T17578 000:016.873 - 16.875ms
|
||||
T17578 000:017.062 JLINK_SetWarnOutHandler(...)
|
||||
T17578 000:017.200 - 0.139ms
|
||||
T17578 000:017.206 JLINK_OpenEx(...)
|
||||
T17578 000:021.737 Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jul 8 2025 10:14:41
|
||||
T17578 000:021.932 Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jul 8 2025 10:14:41
|
||||
T17578 000:023.526 Hardware: V1.00
|
||||
T17578 000:023.541 S/N: 682060510
|
||||
T17578 000:023.553 OEM: SEGGER
|
||||
T17578 000:023.584 Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB
|
||||
T17578 000:024.858 TELNET listener socket opened on port 19021
|
||||
T17578 000:025.175 WEBSRV Starting webserver
|
||||
T17578 000:025.338 WEBSRV Webserver running on local port 19080
|
||||
T17578 000:025.348 - 8.144ms returns "O.K."
|
||||
T17578 000:025.367 JLINK_GetEmuCaps()
|
||||
T17578 000:025.371 - 0.007ms returns 0xB8EA5A33
|
||||
T17578 000:025.659 JLINK_TIF_GetAvailable(...)
|
||||
T17578 000:025.792 - 0.142ms
|
||||
T17578 000:025.810 JLINK_SetErrorOutHandler(...)
|
||||
T17578 000:025.815 - 0.006ms
|
||||
T17578 000:026.191 JLINK_ExecCommand("ProjectFile = "D:\mt_project\mt_firmware\project\ble_peripheral\ble_app_bladder_patch\pca10056\s140\arm5_no_packs\JLinkSettings.ini"", ...).
|
||||
T17578 000:042.853 - 16.685ms returns 0x00
|
||||
T17578 000:050.030 JLINK_ExecCommand("Device = nRF52840_xxAA", ...).
|
||||
T17578 000:056.080 Device "NRF52840_XXAA" selected.
|
||||
T17578 000:056.499 - 6.440ms returns 0x00
|
||||
T17578 000:056.983 JLINK_GetHardwareVersion()
|
||||
T17578 000:056.998 - 0.017ms returns 10000
|
||||
T17578 000:057.003 JLINK_GetDLLVersion()
|
||||
T17578 000:057.007 - 0.005ms returns 72202
|
||||
T17578 000:057.013 JLINK_GetOEMString(...)
|
||||
T17578 000:057.018 JLINK_GetFirmwareString(...)
|
||||
T17578 000:057.027 - 0.011ms
|
||||
T17578 000:067.210 JLINK_GetDLLVersion()
|
||||
T17578 000:067.242 - 0.034ms returns 72202
|
||||
T17578 000:067.248 JLINK_GetCompileDateTime()
|
||||
T17578 000:067.253 - 0.006ms
|
||||
T17578 000:070.610 JLINK_GetFirmwareString(...)
|
||||
T17578 000:070.630 - 0.022ms
|
||||
T17578 000:076.118 JLINK_GetHardwareVersion()
|
||||
T17578 000:076.149 - 0.036ms returns 10000
|
||||
T17578 000:081.686 JLINK_GetSN()
|
||||
T17578 000:081.735 - 0.054ms returns 682060510
|
||||
T17578 000:086.288 JLINK_GetOEMString(...)
|
||||
T17578 000:096.973 JLINK_TIF_Select(JLINKARM_TIF_SWD)
|
||||
T17578 000:097.628 - 0.671ms returns 0x00
|
||||
T17578 000:097.653 JLINK_HasError()
|
||||
T17578 000:099.547 JLINK_SetSpeed(5000)
|
||||
T17578 000:099.820 - 0.282ms
|
||||
T17578 000:099.835 JLINK_GetId()
|
||||
T17578 000:105.067 InitTarget() start
|
||||
T17578 000:105.093 J-Link Script File: Executing InitTarget()
|
||||
T17578 000:108.737 Looking for J-Link GUI Server exe at: C:\Keil_v5\ARM\Segger\JLinkGUIServer.exe
|
||||
T17578 000:108.890 Looking for J-Link GUI Server exe at: C:\Program Files\SEGGER\JLink_V818\JLinkGUIServer.exe
|
||||
T17578 000:108.954 Forking J-Link GUI Server: C:\Program Files\SEGGER\JLink_V818\JLinkGUIServer.exe
|
||||
T17578 000:181.575 J-Link GUI Server info: "J-Link GUI server V8.18 "
|
||||
T17578 002:406.198 Device will be unsecured now.
|
||||
T17578 002:631.975 InitTarget() end
|
||||
T17578 002:796.797 InitTarget() start
|
||||
T17578 002:796.830 J-Link Script File: Executing InitTarget()
|
||||
T17578 002:911.808 InitTarget() end
|
||||
T17578 003:014.808 - 2915.023ms returns 0x00000000
|
||||
T17578 006:160.609 JLINK_Close()
|
||||
T17578 006:185.982 - 25.395ms
|
||||
T17578 006:186.008
|
||||
T17578 006:186.012 Closed
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user