├── nbproject
├── private
│ ├── Default.properties
│ ├── CodeAssistancePathMapper.properties
│ ├── private.xml
│ ├── launcher.properties
│ ├── configurations.xml
│ ├── c_standard_headers_indexer.c
│ ├── Default-build.log
│ └── cpp_standard_headers_indexer.cpp
└── project.xml
├── .gitignore
├── AD5593R.h
├── ADC.h
├── FDC1004.h
├── BME280.h
├── pca10040
└── s132
│ └── armgcc
│ ├── mentaid.ld
│ └── Makefile
├── ics43434.h
├── I2C.h
├── README.md
├── VEML6040.h
├── SPIFlash.h
├── BMA280.h
├── ADC.c
├── AD5593R.c
├── VEML6040.c
├── I2C.c
├── FDC1004.c
├── BMA280.c
├── ble_ma.h
├── BME280.c
├── ics43434.c
├── app_pwm.h
├── SPIFlash.c
├── ble_ma.c
└── app_pwm.c
/nbproject/private/Default.properties:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/nbproject/private/CodeAssistancePathMapper.properties:
--------------------------------------------------------------------------------
1 | # Automatic path mapper. CRC = 1
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.o
3 | *.d
4 | *.bin
5 | *.hex
6 | *.map
7 | *.out
8 | *.in
--------------------------------------------------------------------------------
/AD5593R.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef MA_AD5593R_H_
3 | #define MA_AD5593R_H_
4 |
5 | #include "I2C.h"
6 | #include "SEGGER_RTT.h"
7 |
8 | void AD5593R_Turn_On( void );
9 | void AD5593R_Configure( void );
10 | void AD5593R_Get_Data( float * result) ;
11 |
12 | #endif /* MA_AD5593R_H_ */
13 |
--------------------------------------------------------------------------------
/ADC.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef MA_ADC_H__
3 | #define MA_ADC_H__
4 |
5 | #ifdef __cplusplus
6 | extern "C" {
7 | #endif
8 |
9 | #include "nrf_drv_saadc.h"
10 | void ADC_init(void);
11 | int16_t Current_VBATT( void );
12 | void ADC_callback(nrf_drv_saadc_evt_t const * p_event);
13 |
14 | #ifdef __cplusplus
15 | }
16 | #endif
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/FDC1004.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef MA_FDC1004_H_
3 | #define MA_FDC1004_H_
4 |
5 | #include "I2C.h"
6 | #include "SEGGER_RTT.h"
7 |
8 | void FDC1004_Configure( void );
9 | void FDC1004_Turn_On( void );
10 | void FDC1004_Get_Data( float * result) ;
11 | float ConvertFDCToFloat( uint8_t * dM, uint8_t * dL );
12 |
13 | #endif /* MA_FDC1004_H_ */
14 |
--------------------------------------------------------------------------------
/BME280.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef MA_BME280_H_
3 | #define MA_BME280_H_
4 |
5 | #include "I2C.h"
6 | #include "app_error.h"
7 | #include "nrf_delay.h"
8 | #include "SEGGER_RTT.h"
9 |
10 | void BME280_Configure( uint8_t address );
11 | void BME280_Turn_On( void );
12 | void BME280_Get_Data(int32_t * resultPTH);
13 |
14 | int32_t BME280_Compensate_T(int32_t t_fine);
15 | uint32_t BME280_Compensate_P(int32_t adc_P, int32_t t_fine);
16 | uint32_t BME280_Compensate_H(int32_t adc_H, int32_t t_fine);
17 |
18 | #endif /* MA_BME280_H_ */
19 |
--------------------------------------------------------------------------------
/pca10040/s132/armgcc/mentaid.ld:
--------------------------------------------------------------------------------
1 | /* Linker script to configure memory regions. */
2 |
3 | SEARCH_DIR(.)
4 | GROUP(-lgcc -lc -lnosys)
5 |
6 | MEMORY
7 | {
8 | FLASH (rx) : ORIGIN = 0x1f000, LENGTH = 0x61000
9 | RAM (rwx) : ORIGIN = 0x20002558, LENGTH = 0xdaa8
10 | }
11 |
12 | SECTIONS
13 | {
14 | .fs_data :
15 | {
16 | PROVIDE(__start_fs_data = .);
17 | KEEP(*(.fs_data))
18 | PROVIDE(__stop_fs_data = .);
19 | } > RAM
20 | } INSERT AFTER .data;
21 |
22 | SECTIONS
23 | {
24 | .pwr_mgmt_data :
25 | {
26 | PROVIDE(__start_pwr_mgmt_data = .);
27 | KEEP(*(SORT(.pwr_mgmt_data*)))
28 | PROVIDE(__stop_pwr_mgmt_data = .);
29 | } > FLASH
30 | } INSERT AFTER .text
31 |
32 | INCLUDE "nrf5x_common.ld"
33 |
--------------------------------------------------------------------------------
/ics43434.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef MA_ICS43434_H_
3 | #define MA_ICS43434_H_
4 |
5 | #include "arm_const_structs.h"
6 |
7 | #define I2S_BUFFER_SIZE 2048 // Data handler is called when I2S data bufffer contains (I2S_BUFFER_SIZE/2) 32bit words
8 | #define AUDIO_RATE 10000L // Audio frame rate; 16000000/AUDIO_RATE must be an integral multiple of 64!
9 | #define FPU_EXCEPTION_MASK 0x0000009F // FPU exception mask used to clear exceptions in FPSCR register
10 |
11 | typedef struct
12 | {
13 | float max;
14 | float avg;
15 | float32_t freq[3];
16 | float32_t complex_mag[3];
17 | } fft_results_t;
18 |
19 | void ICS_Sample(void);
20 | void ICS_Configure(void);
21 | void ICS_Get_Data(float * dest);
22 |
23 | #endif /* MA_ICS43434_H_ */
24 |
--------------------------------------------------------------------------------
/I2C.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef MA_I2C_H__
3 | #define MA_I2C_H__
4 |
5 | #ifdef __cplusplus
6 | extern "C" {
7 | #endif
8 |
9 | #include "nrf_drv_twi.h"
10 | #include "app_error.h" //for APP_ERROR_CHECK(err_code);
11 | #include "SEGGER_RTT.h"
12 |
13 | void I2C_init( void );
14 |
15 | void writeByte( uint8_t address, uint8_t subAddress, uint8_t data);
16 |
17 | void writeBytes(uint8_t address, uint8_t * data, uint8_t n_bytes);
18 |
19 | void readBytes( uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t n_bytes);
20 |
21 | uint8_t readByte(uint8_t address, uint8_t subAddress);
22 |
23 | void I2C_handler(nrf_drv_twi_evt_t const * p_event, void * p_context);
24 |
25 | #ifdef __cplusplus
26 | }
27 | #endif
28 |
29 | #endif /* MA_I2C_H__ */
30 |
--------------------------------------------------------------------------------
/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.cnd.makeproject
4 |
5 |
6 | mentaid
7 | c
8 |
9 | h
10 | UTF-8
11 |
12 |
13 | .
14 |
15 |
16 |
17 | Default
18 | 0
19 |
20 |
21 |
22 | false
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MENTAID firmware
2 |
3 | This is the firmware for a Stanford University-funded wearable. The wearable collects information from about 10 sensors, logs this information, and can send it into the cloud if and when the wearer wishes to do so. The iOS code is also available, please see https://github.com/jliphard/wearable_nRF52_iOS. The code is under very active development, so expect things to change rapidly without notice.
4 |
5 | 1/ The ADC, I2C/TWI, BME280, and the SPI FLASH are functional and tested.
6 |
7 | 2/ The goal right now is to have the device:
8 |
9 | _Goal 1_ - Baseline/robust datalogging
10 | *Sample all sensors once per min
11 | *Write the data to flash in units of 256 bytes
12 | *Sleep for most of the time (i.e. between the sampling events)
13 | *Do that until it drains the battery.
14 |
15 | _Goal 2_ - Minimal BLE functionality. Upon system start, advertize BLE for 100 secs. If connect, then allow iOS BLE app to send commands, such as Erase Memory, or Upload all data. If not connect, just datalog as in use case 1. Once BLE connection drops, begin to datalog.
16 |
17 | _Goal 3_ - Get time/date/velocity from iPhone once in while to facilitate data analysis. Key for the GPS is velocity, since that helps us to understand if the wearer is cycling, driving, walking and so forth. Out of privacy concerns, we do not save or transmit GPS lat/lon location data.
18 |
--------------------------------------------------------------------------------
/nbproject/private/private.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
6 |
7 | 0
8 | 0
9 |
10 |
11 |
12 |
13 | file:/Users/janliphardt/Documents/GitHub/wearable_nRF52_Firmware/main.c
14 | file:/Users/janliphardt/Documents/GitHub/wearable_nRF52_Firmware/VEML6040.c
15 | file:/Users/janliphardt/Documents/GitHub/wearable_nRF52_Firmware/ics43434.c
16 | file:/Users/janliphardt/Documents/GitHub/wearable_nRF52_Firmware/ics43434.h
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/nbproject/private/launcher.properties:
--------------------------------------------------------------------------------
1 | # Launchers File syntax:
2 | #
3 | # [Must-have property line]
4 | # launcher1.runCommand=
5 | # [Optional extra properties]
6 | # launcher1.displayName=
7 | # launcher1.hide=
8 | # launcher1.buildCommand=
9 | # launcher1.runDir=
10 | # launcher1.runInOwnTab=
11 | # launcher1.symbolFiles=
12 | # launcher1.env.=
13 | # (If this value is quoted with ` it is handled as a native command which execution result will become the value)
14 | # [Common launcher properties]
15 | # common.runDir=
16 | # (This value is overwritten by a launcher specific runDir value if the latter exists)
17 | # common.env.=
18 | # (Environment variables from common launcher are merged with launcher specific variables)
19 | # common.symbolFiles=
20 | # (This value is overwritten by a launcher specific symbolFiles value if the latter exists)
21 | #
22 | # In runDir, symbolFiles and env fields you can use these macroses:
23 | # ${PROJECT_DIR} - project directory absolute path
24 | # ${OUTPUT_PATH} - linker output path (relative to project directory path)
25 | # ${OUTPUT_BASENAME}- linker output filename
26 | # ${TESTDIR} - test files directory (relative to project directory path)
27 | # ${OBJECTDIR} - object files directory (relative to project directory path)
28 | # ${CND_DISTDIR} - distribution directory (relative to project directory path)
29 | # ${CND_BUILDDIR} - build directory (relative to project directory path)
30 | # ${CND_PLATFORM} - platform name
31 | # ${CND_CONF} - configuration name
32 | # ${CND_DLIB_EXT} - dynamic library extension
33 | #
34 | # All the project launchers must be listed in the file!
35 | #
36 | # launcher1.runCommand=...
37 | # launcher2.runCommand=...
38 | # ...
39 | # common.runDir=...
40 | # common.env.KEY=VALUE
41 |
42 | # launcher1.runCommand=
--------------------------------------------------------------------------------
/VEML6040.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2017, Stanford University
2 | * All rights reserved.
3 | *
4 | * The point of contact for the MENTAID wearables dev team is
5 | * Jan Liphardt (jan.liphardt@stanford.edu)
6 | *
7 | * The code is modified from a reference implementation by Kris Winer
8 | * (tleracorp@gmail.com)
9 | * Copyright (c) 2017, Tlera Corporation
10 | * The license terms of the TLERACORP material are:
11 | * "Library may be used freely and without limit with attribution."
12 | *
13 | * Redistribution and use in source and binary forms, with or without
14 | * modification, are permitted provided that the following conditions are met:
15 | * 1. Redistributions of source code must retain the above copyright
16 | * notice, this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright
18 | * notice, this list of conditions and the following disclaimer in the
19 | * documentation and/or other materials provided with the distribution.
20 | * 3. Neither the name of STANFORD UNIVERSITY nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software
22 | * without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY "AS IS" AND ANY EXPRESS
25 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY OR ITS CONTRIBUTORS BE
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 | #ifndef MA_VEML6040_H_
37 | #define MA_VEML6040_H_
38 |
39 | #include "I2C.h"
40 | #include "app_error.h"
41 | #include "nrf_delay.h"
42 | #include "SEGGER_RTT.h"
43 |
44 | void VEML6040_Turn_On( void );
45 | void VEML6040_Turn_Off( void );
46 | void VEML6040_Get_Data(int16_t * dest);
47 |
48 | #endif /* MA_VEML6040_ */
49 |
--------------------------------------------------------------------------------
/SPIFlash.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2017, Stanford University
2 | * All rights reserved.
3 | *
4 | * The point of contact for the MENTAID wearables dev team is
5 | * Jan Liphardt (jan.liphardt@stanford.edu)
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of STANFORD UNIVERSITY nor the names of its contributors
15 | * may be used to endorse or promote products derived from this software
16 | * without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY "AS IS" AND ANY EXPRESS
19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY OR ITS CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | #ifndef SPIFlash_h
31 | #define SPIFlash_h
32 |
33 | #ifdef __cplusplus
34 | extern "C" {
35 | #endif
36 |
37 | #include
38 | #include "nrf_drv_spi.h"
39 | #include "app_error.h"
40 |
41 | void FLASH_Init( void );
42 | void FLASH_Print_ID( void );
43 | uint16_t FLASH_Get_First_Available_Location( void );
44 | void FLASH_Write_Record( uint8_t wp[] );
45 | uint8_t * FLASH_Page_Read( uint16_t pageN );
46 | void FLASH_Line_Read( uint16_t lineN, uint8_t *line );
47 | void FLASH_Erase( void );
48 | void FLASH_Page_Write( uint16_t pageN, uint8_t *wp );
49 | bool FLASH_Set_Write_Enable( void );
50 | bool FLASH_Page_Is_Empty( uint16_t pageN );
51 | int page_to_address( int pn );
52 | int address_to_page( int addr );
53 |
54 | #ifdef __cplusplus
55 | }
56 | #endif
57 |
58 | #endif /* SPIFlash_h */
59 |
60 |
--------------------------------------------------------------------------------
/BMA280.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2017, Stanford University
2 | * All rights reserved.
3 | *
4 | * The point of contact for the MENTAID wearables dev team is
5 | * Jan Liphardt (jan.liphardt@stanford.edu)
6 | *
7 | * The code is modified from a reference implementation by Kris Winer
8 | * (tleracorp@gmail.com)
9 | * Copyright (c) 2017, Tlera Corporation
10 | * The license terms of the TLERACORP material are:
11 | * "Library may be used freely and without limit with attribution."
12 | *
13 | * Redistribution and use in source and binary forms, with or without
14 | * modification, are permitted provided that the following conditions are met:
15 | * 1. Redistributions of source code must retain the above copyright
16 | * notice, this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright
18 | * notice, this list of conditions and the following disclaimer in the
19 | * documentation and/or other materials provided with the distribution.
20 | * 3. Neither the name of STANFORD UNIVERSITY nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software
22 | * without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY "AS IS" AND ANY EXPRESS
25 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY OR ITS CONTRIBUTORS BE
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 | #ifndef MA_BMA280_H_
37 | #define MA_BMA280_H_
38 |
39 | #ifdef __cplusplus
40 | extern "C" {
41 | #endif
42 |
43 | #include "I2C.h"
44 | #include "app_error.h"
45 | #include "nrf_delay.h"
46 | #include "SEGGER_RTT.h"
47 |
48 | void BMA280_Turn_On_Fast( void );
49 | void BMA280_Turn_On_Slow( void );
50 | void BMA280_Turn_Off( void );
51 | void BMA280_Get_Data(int16_t * dest);
52 | void BMA280_Calibrate( void );
53 |
54 | #ifdef __cplusplus
55 | }
56 | #endif
57 |
58 | #endif /* MA_BMA280_H_ */
59 |
--------------------------------------------------------------------------------
/ADC.c:
--------------------------------------------------------------------------------
1 |
2 | #include "ADC.h"
3 |
4 | #define ADC_SAMPLES_IN_BUFFER 1
5 | static nrf_saadc_value_t m_buffer[ADC_SAMPLES_IN_BUFFER];
6 | float VBATT = 0.0;
7 | static int16_t batteryVoltage = 0;
8 |
9 | /*
10 | 5, // AIN3 (P0.05)
11 | 2, // AIN0 (P0.02)
12 | VBAT = (127.0f/100.0f) * 3.30f * ((float)analogRead(VbatMon))/4095.0f; //actual battery voltage
13 | */
14 |
15 | void ADC_init(void)
16 | {
17 | ret_code_t err_code;
18 |
19 | nrf_saadc_channel_config_t channel_config =
20 | NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4);
21 | /*
22 | nrf_saadc_config_t adc_config;
23 | adc_config.resolution = NRF_SAADC_RESOLUTION_8BIT;
24 | adc_config.buffer = m_buffer;
25 | adc_config.buffer_size = ADC_SAMPLES_IN_BUFFER;
26 | adc_config.oversample = ;
27 |
28 | nrf_saadc_channel_config_t channel_0_config;
29 | channel_0_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
30 | channel_0_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
31 | channel_0_config.gain = NRF_SAADC_GAIN1_6;
32 | channel_0_config.reference = NRF_SAADC_REFERENCE_INTERNAL;
33 | channel_0_config.acq_time = NRF_SAADC_ACQTIME_10US;
34 | channel_0_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;
35 | channel_0_config.pin_p = NRF_SAADC_INPUT_VDD;
36 | channel_0_config.pin_n = NRF_SAADC_INPUT_DISABLED;
37 | */
38 |
39 | //channel_config.
40 | //nrf_saadc_resolution_set( NRF_SAADC_RESOLUTION_8BIT );
41 | //APP_ERROR_CHECK(err_code);
42 | //NRF_SAADC_RESOLUTION_12BIT
43 |
44 | err_code = nrf_drv_saadc_init(NULL, ADC_callback);
45 | APP_ERROR_CHECK(err_code);
46 |
47 | err_code = nrf_drv_saadc_channel_init(0, &channel_config);
48 | APP_ERROR_CHECK(err_code);
49 |
50 | err_code = nrf_drv_saadc_buffer_convert(m_buffer, ADC_SAMPLES_IN_BUFFER);
51 | APP_ERROR_CHECK(err_code);
52 | }
53 |
54 | void ADC_callback(nrf_drv_saadc_evt_t const * p_event)
55 | {
56 | if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
57 | {
58 | ret_code_t err_code;
59 |
60 | err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, ADC_SAMPLES_IN_BUFFER);
61 | APP_ERROR_CHECK(err_code);
62 |
63 | VBATT = ((float)p_event->data.done.p_buffer[0]) / 4096.0f;
64 | //NRF_LOG_INFO("ADC returned R: %d\r\n", p_event->data.done.p_buffer[0]);
65 | VBATT = VBATT * (139.0f/100.0f) * 3.30f;
66 | batteryVoltage = (uint16_t)(VBATT * 100.0f);
67 | }
68 | }
69 |
70 | int16_t Current_VBATT( void )
71 | {
72 | return batteryVoltage;
73 | }
74 |
--------------------------------------------------------------------------------
/AD5593R.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2017, Stanford University
2 | * All rights reserved.
3 | *
4 | * The point of contact for the MENTAID wearables dev team is
5 | * Jan Liphardt (jan.liphardt@stanford.edu)
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of STANFORD UNIVERSITY nor the names of its contributors
15 | * may be used to endorse or promote products derived from this software
16 | * without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY "AS IS" AND ANY EXPRESS
19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY OR ITS CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | /*
31 | Datasheet -
32 | http://www.analog.com/media/en/technical-documentation/data-sheets/AD5593R.pdf
33 | */
34 |
35 | #include "AD5593R.h"
36 |
37 | #define AD5593R_ADDRESS 0x10
38 |
39 | // * @brief Function for setting active
40 | void AD5593R_Turn_On(void)
41 | {
42 |
43 | //to confirm ID let's read back the pull down configuration register = default is 0x00FF
44 | //AD5593R
45 | //readback = 0111____
46 | //so command is
47 | //0111 0110 = 0x76
48 | //all other registers are 0 by default; only the PDCR has nonzero default useful for checcking
49 | //chip ID
50 |
51 | uint8_t devID[2];
52 |
53 | readBytes(AD5593R_ADDRESS, 0x76, devID, 2);
54 |
55 | uint16_t devID_16;
56 |
57 | devID_16 = (uint16_t) devID[0] << 8 | devID[1];
58 |
59 | SEGGER_RTT_printf(0, "AD5593R ID:%d Should be = 255\n", devID_16);
60 |
61 | if( devID_16 == 255 )
62 | AD5593R_Configure();
63 |
64 | }
65 |
66 | void AD5593R_Configure( void )
67 | {
68 | //Depends on what you are trying to do - thousands of choices
69 | }
70 |
71 | void AD5593R_Get_Data( float * result )
72 | {
73 | //Depends on what you are trying to do - thousands of choices
74 | }
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/nbproject/private/configurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | sdk_config.h
13 |
14 |
15 |
16 | AD5593R.c
17 | AD5593R.h
18 | ADC.c
19 | ADC.h
20 | BMA280.c
21 | BMA280.h
22 | BME280.c
23 | BME280.h
24 | FDC1004.c
25 | FDC1004.h
26 | I2C.c
27 | I2C.h
28 | SPIFlash.c
29 | SPIFlash.h
30 | VEML6040.c
31 | VEML6040.h
32 | app_pwm.c
33 | app_pwm.h
34 | ble_ma.c
35 | ble_ma.h
36 | ics43434.c
37 | ics43434.h
38 | main.c
39 |
40 |
41 | pca10040/s132/armgcc/Makefile
42 |
43 |
44 |
45 | localhost
46 | 4
47 |
48 |
49 |
50 | .
51 | ${AUTO_FOLDER}
52 |
53 | ${AUTO_FOLDER}
54 |
55 | ${MAKE} ${ITEM_NAME}.o
56 | ${AUTO_COMPILE}
57 |
58 | ${AUTO_COMPILE}
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | gdb
74 |
75 |
76 |
77 | "${OUTPUT_PATH}"
78 | make flash_softdevice flash
79 |
80 | make flash_softdevice flash
81 | pca10040/s132/armgcc
82 | false
83 | 0
84 | 0
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/VEML6040.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2017, Stanford University
2 | * All rights reserved.
3 | *
4 | * The point of contact for the MENTAID wearables dev team is
5 | * Jan Liphardt (jan.liphardt@stanford.edu)
6 | *
7 | * The code is modified from a reference implementation by Kris Winer
8 | * (tleracorp@gmail.com)
9 | * Copyright (c) 2017, Tlera Corporation
10 | * The license terms of the TLERACORP material are:
11 | * "Library may be used freely and without limit with attribution."
12 | *
13 | * Redistribution and use in source and binary forms, with or without
14 | * modification, are permitted provided that the following conditions are met:
15 | * 1. Redistributions of source code must retain the above copyright
16 | * notice, this list of conditions and the following disclaimer.
17 | * 2. Redistributions in binary form must reproduce the above copyright
18 | * notice, this list of conditions and the following disclaimer in the
19 | * documentation and/or other materials provided with the distribution.
20 | * 3. Neither the name of STANFORD UNIVERSITY nor the names of its contributors
21 | * may be used to endorse or promote products derived from this software
22 | * without specific prior written permission.
23 | *
24 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY "AS IS" AND ANY EXPRESS
25 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY OR ITS CONTRIBUTORS BE
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 | */
35 |
36 | #include "VEML6040.h"
37 |
38 | // http://www.mouser.com/pdfdocs/veml6040.PDF
39 |
40 | ////////////////////////////
41 | // VEML6040 Command Codes //
42 | ////////////////////////////
43 | #define VEML6040_CONF 0x00 // command codes
44 | #define VEML6040_R_DATA 0x08
45 | #define VEML6040_G_DATA 0x09
46 | #define VEML6040_B_DATA 0x0A
47 | #define VEML6040_W_DATA 0x0B
48 |
49 | #define VEML6040_ADDRESS 0x10
50 |
51 | #define IT_40 0 // 40 ms
52 | #define IT_80 1 // 80 ms
53 | #define IT_160 2 // 160 ms
54 | #define IT_320 3 // 320 ms
55 | #define IT_640 4 // 640 ms
56 | #define IT_1280 5 // 1280 ms
57 |
58 | void VEML6040_Turn_On( void )
59 | {
60 | uint8_t packet[3];
61 | packet[0] = (uint8_t)VEML6040_CONF;
62 | packet[1] = (uint8_t)IT_1280 << 4; // Bit 3 must be 0, bit 0 is 0 for run and 1 for shutdown, LS Byte
63 | packet[2] = (uint8_t)0x00;
64 | writeBytes(VEML6040_ADDRESS, packet, 3);
65 | }
66 |
67 | void VEML6040_Turn_Off( void )
68 | {
69 | uint8_t packet[3];
70 | packet[0] = (uint8_t)VEML6040_CONF;
71 | packet[1] = (uint8_t)(IT_1280 << 4 | 0x01); // Bit 3 must be 0, bit 0 is 0 for run and 1 for shutdown, LS Byte
72 | packet[2] = (uint8_t)0x00;
73 | writeBytes(VEML6040_ADDRESS, packet, 3);
74 | }
75 |
76 | void VEML6040_Get_Data(int16_t * dest)
77 | {
78 | uint8_t rawData[2] = {0, 0};
79 |
80 | readBytes(VEML6040_ADDRESS, VEML6040_R_DATA, rawData, 2);
81 | dest[0] = ((int16_t) rawData[1] << 8) | rawData[0];
82 |
83 | readBytes(VEML6040_ADDRESS, VEML6040_G_DATA, rawData, 2);
84 | dest[1] = ((int16_t) rawData[1] << 8) | rawData[0];
85 |
86 | readBytes(VEML6040_ADDRESS, VEML6040_B_DATA, rawData, 2);
87 | dest[2] = ((int16_t) rawData[1] << 8) | rawData[0];
88 |
89 | readBytes(VEML6040_ADDRESS, VEML6040_W_DATA, rawData, 2);
90 | dest[3] = ((int16_t) rawData[1] << 8) | rawData[0];
91 |
92 | if( SEGGER_VEML )
93 | SEGGER_RTT_printf(0, "VEML6040:%d %d %d %d\n", dest[0], dest[1], dest[2], dest[3]);
94 | }
95 |
96 |
--------------------------------------------------------------------------------
/nbproject/private/c_standard_headers_indexer.c:
--------------------------------------------------------------------------------
1 | /*
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 | *
4 | * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
5 | *
6 | * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7 | * Other names may be trademarks of their respective owners.
8 | *
9 | * The contents of this file are subject to the terms of either the GNU
10 | * General Public License Version 2 only ("GPL") or the Common
11 | * Development and Distribution License("CDDL") (collectively, the
12 | * "License"). You may not use this file except in compliance with the
13 | * License. You can obtain a copy of the License at
14 | * http://www.netbeans.org/cddl-gplv2.html
15 | * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16 | * specific language governing permissions and limitations under the
17 | * License. When distributing the software, include this License Header
18 | * Notice in each file and include the License file at
19 | * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20 | * particular file as subject to the "Classpath" exception as provided
21 | * by Oracle in the GPL Version 2 section of the License file that
22 | * accompanied this code. If applicable, add the following below the
23 | * License Header, with the fields enclosed by brackets [] replaced by
24 | * your own identifying information:
25 | * "Portions Copyrighted [year] [name of copyright owner]"
26 | *
27 | * If you wish your version of this file to be governed by only the CDDL
28 | * or only the GPL Version 2, indicate your decision by adding
29 | * "[Contributor] elects to include this software in this distribution
30 | * under the [CDDL or GPL Version 2] license." If you do not indicate a
31 | * single choice of license, a recipient has the option to distribute
32 | * your version of this file under either the CDDL, the GPL Version 2 or
33 | * to extend the choice of license to its licensees as provided above.
34 | * However, if you add GPL Version 2 code and therefore, elected the GPL
35 | * Version 2 license, then the option applies only if the new code is
36 | * made subject to such option by the copyright holder.
37 | *
38 | * Contributor(s):
39 | */
40 |
41 | // List of standard headers was taken in http://en.cppreference.com/w/c/header
42 |
43 | #include // Conditionally compiled macro that compares its argument to zero
44 | #include // Functions to determine the type contained in character data
45 | #include // Macros reporting error conditions
46 | #include // Limits of float types
47 | #include // Sizes of basic types
48 | #include // Localization utilities
49 | #include // Common mathematics functions
50 | #include // Nonlocal jumps
51 | #include // Signal handling
52 | #include // Variable arguments
53 | #include // Common macro definitions
54 | #include // Input/output
55 | #include // String handling
56 | #include // General utilities: memory management, program utilities, string conversions, random numbers
57 | #include // Time/date utilities
58 | #include // (since C95) Alternative operator spellings
59 | #include // (since C95) Extended multibyte and wide character utilities
60 | #include // (since C95) Wide character classification and mapping utilities
61 | #ifdef _STDC_C99
62 | #include // (since C99) Complex number arithmetic
63 | #include // (since C99) Floating-point environment
64 | #include // (since C99) Format conversion of integer types
65 | #include // (since C99) Boolean type
66 | #include // (since C99) Fixed-width integer types
67 | #include // (since C99) Type-generic math (macros wrapping math.h and complex.h)
68 | #endif
69 | #ifdef _STDC_C11
70 | #include // (since C11) alignas and alignof convenience macros
71 | #include // (since C11) Atomic types
72 | #include // (since C11) noreturn convenience macros
73 | #include // (since C11) Thread library
74 | #include // (since C11) UTF-16 and UTF-32 character utilities
75 | #endif
76 |
--------------------------------------------------------------------------------
/I2C.c:
--------------------------------------------------------------------------------
1 |
2 | #include "I2C.h"
3 | #include "nrf_drv_twi.h"
4 |
5 | #define NRF_LOG_MODULE_NAME "I2C"
6 |
7 | // I2C instance.
8 | #define TWI_INSTANCE_ID 0
9 | #define APP_IRQ_PRIORITY_LOW 3 //overrides definition elsewhere
10 | #define BA_SDA_PIN 5 // SDA signal pin
11 | #define BA_SCL_PIN 8 // SCL signal pin
12 |
13 | static const nrf_drv_twi_t i2c = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
14 |
15 | // Indicates if operation on TWI has ended.
16 | static volatile bool m_xfer_done = false;
17 |
18 | // @brief UART initialization.
19 | void I2C_init(void)
20 | {
21 | //NRF_LOG_DEBUG("twi_init(void)\r\n");
22 |
23 | ret_code_t err_code;
24 |
25 | const nrf_drv_twi_config_t i2c_config =
26 | {
27 | .scl = BA_SCL_PIN,
28 | .sda = BA_SDA_PIN,
29 | .frequency = NRF_TWI_FREQ_100K,
30 | .interrupt_priority = APP_IRQ_PRIORITY_LOW,
31 | .clear_bus_init = false
32 | };
33 |
34 | //last one is some kind of context - no idea what that is....
35 | //documentation is vague/nonexistant
36 | err_code = nrf_drv_twi_init(&i2c, &i2c_config, I2C_handler, NULL);
37 | APP_ERROR_CHECK(err_code);
38 |
39 | nrf_drv_twi_enable(&i2c);
40 |
41 | //NRF_LOG_DEBUG("I2C_init(void) done\r\n");
42 | }
43 |
44 | void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
45 | {
46 | uint8_t temp[2];
47 |
48 | temp[0] = subAddress;
49 | temp[1] = data;
50 |
51 | ret_code_t err_code;
52 | m_xfer_done = false;
53 | err_code = nrf_drv_twi_tx(&i2c, address, &temp[0], 2, true);
54 | APP_ERROR_CHECK(err_code);
55 | while (m_xfer_done == false); //wait until end of transfer
56 | }
57 |
58 | void writeBytes(uint8_t address, uint8_t * data, uint8_t n_bytes)
59 | {
60 | ret_code_t err_code;
61 | m_xfer_done = false;
62 | err_code = nrf_drv_twi_tx(&i2c, address, data, n_bytes, false); //false = close the channel - not waiting for response
63 | APP_ERROR_CHECK(err_code);
64 | while (m_xfer_done == false); //wait until end of transfer -- seriously??
65 | }
66 |
67 | uint8_t readByte(uint8_t address, uint8_t subAddress)
68 | {
69 | ret_code_t err_code = 0;
70 |
71 | uint8_t value;
72 |
73 | m_xfer_done = false;
74 | //NRF_LOG_DEBUG("readByte - Writing\r\n");
75 | //last position is the transfer pending flag
76 | err_code = nrf_drv_twi_tx(&i2c, address, &subAddress, 1, true);
77 |
78 | APP_ERROR_CHECK(err_code);
79 |
80 | while (m_xfer_done == false); //wait until end of transfer
81 |
82 | if (err_code == NRF_SUCCESS)
83 | {
84 | m_xfer_done = false;
85 | //NRF_LOG_DEBUG("readByte - Reading\r\n");
86 | err_code = nrf_drv_twi_rx(&i2c, address, &value, 1);
87 | APP_ERROR_CHECK(err_code);
88 |
89 | while (m_xfer_done == false);
90 | };
91 |
92 | //NRF_LOG_DEBUG("readByte done, returned 0x\r\n");
93 | //NRF_LOG_HEXDUMP_DEBUG(&value, 1);
94 | //NRF_LOG_FLUSH();
95 | return value;
96 | }
97 |
98 | // @brief TWI events handler.
99 | void I2C_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
100 | {
101 | switch (p_event->type)
102 | {
103 | case NRF_DRV_TWI_EVT_DONE:
104 |
105 | //todo -difference between read and write???
106 | m_xfer_done = true;
107 |
108 | if (p_event->xfer_desc.type == NRF_DRV_TWI_XFER_RX)
109 | {
110 | //SEGGER_RTT_WriteString(0, "Data just came back!\n");
111 | }
112 |
113 | //NRF_LOG_DEBUG("I2C_handler responding to NRF_DRV_TWI_EVT_DONE\r\n");
114 | break;
115 | default:
116 | break;
117 | }
118 | }
119 |
120 | //readBytes(BME280_ADDRESS_1, BME280_PRESS_MSB, 8, &rawData[0]);
121 |
122 | void readBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t n_bytes )
123 | {
124 | ret_code_t err_code = 0;
125 | //0xF7 to 0xFE (temperature, pressure and humidity)
126 | //readBytes(BME280_ADDRESS_1, BME280_PRESS_MSB, 9, &rawData[0]);
127 |
128 | m_xfer_done = false;
129 |
130 | err_code = nrf_drv_twi_tx(&i2c, address, &subAddress, 1, true);
131 |
132 | while (m_xfer_done == false) {};
133 |
134 | //comes back with error code
135 | //SEGGER_RTT_printf(0, "ReadBytes code: %d\n", err_code);
136 | //here is the problem????
137 | //APP_ERROR_CHECK(err_code);
138 |
139 | if (err_code == NRF_SUCCESS)
140 | {
141 | m_xfer_done = false;
142 | //NRF_LOG_DEBUG("readBytes - Reading\r\n");
143 | err_code = nrf_drv_twi_rx(&i2c, address, dest, n_bytes);
144 | //SEGGER_RTT_printf(0, "ReadBytes RX code: %d\n", err_code);
145 | //APP_ERROR_CHECK(err_code);
146 | while (m_xfer_done == false) {};
147 | };
148 |
149 | //NRF_LOG_DEBUG("readBytes done\r\n");
150 | //NRF_LOG_FLUSH();
151 | }
152 |
153 |
--------------------------------------------------------------------------------
/nbproject/private/Default-build.log:
--------------------------------------------------------------------------------
1 | mkdir _build
2 | Compiling file: boards.c
3 | Compiling file: main.c
4 | ../../../main.c: In function 'main':
5 | ../../../main.c:1249:5: warning: implicit declaration of function 'SEGGER_RTT_WriteString' [-Wimplicit-function-declaration]
6 | SEGGER_RTT_WriteString(0, "\n\n***********\n");
7 | ^~~~~~~~~~~~~~~~~~~~~~
8 | ../../../main.c:1251:10: warning: unused variable 'erase_bonds' [-Wunused-variable]
9 | bool erase_bonds;
10 | ^~~~~~~~~~~
11 | At top level:
12 | ../../../main.c:1162:13: warning: 'update_battery' defined but not used [-Wunused-function]
13 | static void update_battery(void)
14 | ^~~~~~~~~~~~~~
15 | ../../../main.c:976:13: warning: 'power_manage' defined but not used [-Wunused-function]
16 | static void power_manage(void)
17 | ^~~~~~~~~~~~
18 | ../../../main.c:952:13: warning: 'buttons_leds_init' defined but not used [-Wunused-function]
19 | static void buttons_leds_init(bool * p_erase_bonds)
20 | ^~~~~~~~~~~~~~~~~
21 | ../../../main.c:922:13: warning: 'advertising_init' defined but not used [-Wunused-function]
22 | static void advertising_init(void)
23 | ^~~~~~~~~~~~~~~~
24 | ../../../main.c:888:13: warning: 'peer_manager_init' defined but not used [-Wunused-function]
25 | static void peer_manager_init(void)
26 | ^~~~~~~~~~~~~~~~~
27 | ../../../main.c:792:13: warning: 'ble_stack_init' defined but not used [-Wunused-function]
28 | static void ble_stack_init(void)
29 | ^~~~~~~~~~~~~~
30 | ../../../main.c:593:13: warning: 'conn_params_init' defined but not used [-Wunused-function]
31 | static void conn_params_init(void)
32 | ^~~~~~~~~~~~~~~~
33 | ../../../main.c:503:13: warning: 'ble_services_init' defined but not used [-Wunused-function]
34 | static void ble_services_init(void)
35 | ^~~~~~~~~~~~~~~~~
36 | ../../../main.c:492:13: warning: 'gatt_init' defined but not used [-Wunused-function]
37 | static void gatt_init(void)
38 | ^~~~~~~~~
39 | ../../../main.c:447:13: warning: 'gap_params_init' defined but not used [-Wunused-function]
40 | static void gap_params_init(void)
41 | ^~~~~~~~~~~~~~~
42 | ../../../main.c:430:13: warning: 'RTC1_timer_stop' defined but not used [-Wunused-function]
43 | static void RTC1_timer_stop(void)
44 | ^~~~~~~~~~~~~~~
45 | Compiling file: I2C.c
46 | ../../../I2C.c:5:0: warning: "NRF_LOG_MODULE_NAME" redefined
47 | #define NRF_LOG_MODULE_NAME "I2C"
48 |
49 | In file included from ../../../I2C.h:11:0,
50 | from ../../../I2C.c:2:
51 | ../../../../../../components/libraries/log/nrf_log.h:70:0: note: this is the location of the previous definition
52 | #define NRF_LOG_MODULE_NAME ""
53 |
54 | Compiling file: BME280.c
55 | ../../../BME280.c:6:0: warning: "NRF_LOG_MODULE_NAME" redefined
56 | #define NRF_LOG_MODULE_NAME "BME"
57 |
58 | In file included from ../../../I2C.h:11:0,
59 | from ../../../BME280.c:2:
60 | ../../../../../../components/libraries/log/nrf_log.h:70:0: note: this is the location of the previous definition
61 | #define NRF_LOG_MODULE_NAME ""
62 |
63 | Compiling file: ADC.c
64 | Compiling file: SPIFlash.c
65 | ../../../SPIFlash.c:10:0: warning: "NRF_LOG_MODULE_NAME" redefined
66 | #define NRF_LOG_MODULE_NAME "FLASH"
67 |
68 | In file included from ../../../SPIFlash.c:7:0:
69 | ../../../../../../components/libraries/log/nrf_log.h:70:0: note: this is the location of the previous definition
70 | #define NRF_LOG_MODULE_NAME ""
71 |
72 | Compiling file: nrf_log_backend_serial.c
73 | Compiling file: nrf_log_frontend.c
74 | Compiling file: app_button.c
75 | Compiling file: app_scheduler.c
76 | Compiling file: app_timer.c
77 | Compiling file: crc16.c
78 | Compiling file: fds.c
79 | Compiling file: fstorage.c
80 | Compiling file: hardfault_implementation.c
81 | Compiling file: nrf_strerror.c
82 | Compiling file: sensorsim.c
83 | Compiling file: app_error.c
84 | Compiling file: app_error_weak.c
85 | Compiling file: app_util_platform.c
86 | Compiling file: nrf_assert.c
87 | Compiling file: sdk_mapped_flags.c
88 | Compiling file: bsp.c
89 | Compiling file: bsp_btn_ble.c
90 | Compiling file: bsp_nfc.c
91 | Compiling file: nrf_queue.c
92 | Compiling file: nrf_spi_mngr.c
93 | Compiling file: nrf_drv_spi.c
94 | Compiling file: nrf_drv_clock.c
95 | Compiling file: nrf_drv_common.c
96 | Compiling file: nrf_drv_gpiote.c
97 | Compiling file: nrf_drv_twi.c
98 | Compiling file: nrf_drv_uart.c
99 | Compiling file: nrf_drv_saadc.c
100 | Compiling file: nrf_saadc.c
101 | Compiling file: nrf_drv_ppi.c
102 | Compiling file: nrf_drv_timer.c
103 | Compiling file: ble_advertising.c
104 | Compiling file: ble_advdata.c
105 | Compiling file: ble_conn_params.c
106 | Compiling file: ble_conn_state.c
107 | Compiling file: ble_srv_common.c
108 | Compiling file: gatt_cache_manager.c
109 | Compiling file: gatts_cache_manager.c
110 | Compiling file: id_manager.c
111 | Compiling file: nrf_ble_gatt.c
112 | Compiling file: peer_data_storage.c
113 | Compiling file: peer_database.c
114 | Compiling file: peer_id.c
115 | Compiling file: peer_manager.c
116 | Compiling file: pm_buffer.c
117 | Compiling file: pm_mutex.c
118 | Compiling file: security_dispatcher.c
119 | Compiling file: security_manager.c
120 | Compiling file: ble_bas.c
121 | Compiling file: ble_dis.c
122 | Compiling file: ble_hrs.c
123 | ../../../../../../components/ble/ble_services/ble_hrs/ble_hrs.c: In function 'hrm_encode_3':
124 | ../../../../../../components/ble/ble_services/ble_hrs/ble_hrs.c:229:13: warning: unused variable 'i' [-Wunused-variable]
125 | int i;
126 | ^
127 | Compiling file: softdevice_handler.c
128 | Assembling file: gcc_startup_nrf52.S
129 | Compiling file: system_nrf52.c
130 | Compiling file: RTT_Syscalls_GCC.c
131 | Compiling file: SEGGER_RTT.c
132 | Compiling file: SEGGER_RTT_printf.c
133 | Linking target: _build/nrf52832_xxaa.out
134 |
135 | text data bss dec hex filename
136 | 51332 516 19848 71696 11810 _build/nrf52832_xxaa.out
137 |
138 | Preparing: _build/nrf52832_xxaa.hex
139 | Preparing: _build/nrf52832_xxaa.bin
140 |
--------------------------------------------------------------------------------
/FDC1004.c:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2017, Stanford University
2 | * All rights reserved.
3 | *
4 | * The point of contact for the MENTAID wearables dev team is
5 | * Jan Liphardt (jan.liphardt@stanford.edu)
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of STANFORD UNIVERSITY nor the names of its contributors
15 | * may be used to endorse or promote products derived from this software
16 | * without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY "AS IS" AND ANY EXPRESS
19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | * DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY OR ITS CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | /*
31 | Datasheet - note that TI datasheet has key typo/error re. single/repeated measurement setup.
32 | http://www.ti.com/lit/ds/symlink/fdc1004.pdf
33 | */
34 |
35 | #include "FDC1004.h"
36 |
37 | #define FDC1004_ADDRESS 0x50
38 |
39 | // * @brief Function for setting active
40 | void FDC1004_Turn_On(void)
41 | {
42 |
43 | uint8_t devID[2];
44 | readBytes(FDC1004_ADDRESS, 0xFF, devID, 2);
45 |
46 | uint16_t devID_16;
47 | devID_16 = (uint16_t) devID[0] << 8 | devID[1];
48 |
49 | SEGGER_RTT_printf(0, "FDC1004 ID:%d Should be = 4100\n", devID_16);
50 |
51 | if( devID_16 == 4100 ) FDC1004_Configure( );
52 |
53 | }
54 |
55 | void FDC1004_Configure( void )
56 | {
57 | uint8_t CH_config[3];
58 |
59 | //CH_config[2] = 0x40; //= 6.4 pF
60 | //CH_config[2] = 0x20; //= 3.175 pF
61 | CH_config[2] = 0x00; //= 0 pF
62 |
63 | CH_config[0] = 0x08; //Measurement 1 Configuration
64 | CH_config[1] = 0x10; //000 100 00
65 | writeBytes( FDC1004_ADDRESS, CH_config, 3);
66 |
67 | CH_config[0] = 0x09; //Measurement 2 Configuration
68 | CH_config[1] = 0x30; //001 100 00
69 | writeBytes( FDC1004_ADDRESS, CH_config, 3);
70 |
71 | CH_config[0] = 0x0A; //Measurement 3 Configuration
72 | CH_config[1] = 0x50; //010 100 00
73 | writeBytes( FDC1004_ADDRESS, CH_config, 3);
74 |
75 | CH_config[0] = 0x0B; //Measurement 4 Configuration
76 | CH_config[1] = 0x70; //011 100 00
77 | writeBytes( FDC1004_ADDRESS, CH_config, 3);
78 |
79 | /*
80 | The FDC1004 can trigger a new measurement on the completion of the previous measurement (repeated measurements).
81 | This is setup by:
82 | 1. Setting REPEAT(Register0x0C:bit[8]) to 1.
83 | 2. Setting the corresponding MEAS_x field (Register0x0C:bit[7:4]) to 1.
84 | When the FDC1004 is setup for repeated measurements, multiple configured measurements
85 | (up to a maximum of 4) can be performed in this manner,
86 | but Register 0x0C must be written in a single transaction.
87 | */
88 |
89 | //note the the data sheet is wrong. 0540 is repeated measurement, not single measurement!
90 |
91 | CH_config[0] = 0x0C; // FDC Register Description
92 | //CH_config[1] = 0x11; // 0 00 10 0 0 1 // 200S/s, with repeat == 0x11
93 | CH_config[1] = 0x19; // 0 00 11 0 0 1 // 400S/s, with repeat == 0x19
94 | CH_config[2] = 0xF0; // 1111 0000 = all 4 channels
95 |
96 | //let's go!
97 | writeBytes( FDC1004_ADDRESS, CH_config, 3);
98 | }
99 |
100 | float ConvertFDCToFloat( uint8_t * dM, uint8_t * dL )
101 | {
102 | uint32_t resultR = (uint32_t)dM[0] << 16 | (uint32_t)dM[1] << 8 | dL[0];
103 | int8_t negative = (resultR & (1 << 22)) != 0;
104 | int32_t nativeInt = 0;
105 |
106 | if (negative)
107 | nativeInt = resultR | ~((1 << 23) - 1);
108 | else
109 | nativeInt = resultR;
110 |
111 | return ((float)nativeInt / 524288.0);
112 | }
113 |
114 | void FDC1004_Get_Data( float * result )
115 | {
116 |
117 | uint8_t dM[2];
118 | uint8_t dL[2];
119 |
120 | readBytes(FDC1004_ADDRESS, 0x00, dM, 2);
121 | readBytes(FDC1004_ADDRESS, 0x01, dL, 2);
122 | result[0] = ConvertFDCToFloat( dM, dL );
123 |
124 | if( SEGGER_FDC )
125 | {
126 | //SEGGER_RTT_printf(0, "FDC1004.1:%d %d %d\n", dM[0], dM[1], dL[0], dL[1]);
127 | SEGGER_RTT_printf(0, "FDC:%d ", (int32_t)(result[0]*1000));
128 | }
129 |
130 | readBytes(FDC1004_ADDRESS, 0x02, dM, 2);
131 | readBytes(FDC1004_ADDRESS, 0x03, dL, 2);
132 | result[1] = ConvertFDCToFloat( dM, dL );
133 |
134 | if( SEGGER_FDC )
135 | {
136 | //SEGGER_RTT_printf(0, "FDC1004.2:%d %d %d\n", dM[0], dM[1], dL[0], dL[1]);
137 | SEGGER_RTT_printf(0, "%d ", (int32_t)(result[1]*1000));
138 | }
139 |
140 | readBytes(FDC1004_ADDRESS, 0x04, dM, 2);
141 | readBytes(FDC1004_ADDRESS, 0x05, dL, 2);
142 | result[2] = ConvertFDCToFloat( dM, dL );
143 |
144 | if( SEGGER_FDC )
145 | {
146 | //SEGGER_RTT_printf(0, "FDC1004.3:%d %d %d\n", dM[0], dM[1], dL[0], dL[1]);
147 | SEGGER_RTT_printf(0, "%d ", (int32_t)(result[2]*1000));
148 | }
149 |
150 | readBytes(FDC1004_ADDRESS, 0x06, dM, 2);
151 | readBytes(FDC1004_ADDRESS, 0x07, dL, 2);
152 | result[3] = ConvertFDCToFloat( dM, dL );
153 |
154 | if( SEGGER_FDC )
155 | {
156 | //SEGGER_RTT_printf(0, "FDC1004.4:%d %d %d\n", dM[0], dM[1], dL[0], dL[1]);
157 | SEGGER_RTT_printf(0, "%d\n", (int32_t)(result[3]*1000));
158 | }
159 |
160 | }
161 |
162 |
163 |
164 |
--------------------------------------------------------------------------------
/nbproject/private/cpp_standard_headers_indexer.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 | *
4 | * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
5 | *
6 | * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7 | * Other names may be trademarks of their respective owners.
8 | *
9 | * The contents of this file are subject to the terms of either the GNU
10 | * General Public License Version 2 only ("GPL") or the Common
11 | * Development and Distribution License("CDDL") (collectively, the
12 | * "License"). You may not use this file except in compliance with the
13 | * License. You can obtain a copy of the License at
14 | * http://www.netbeans.org/cddl-gplv2.html
15 | * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16 | * specific language governing permissions and limitations under the
17 | * License. When distributing the software, include this License Header
18 | * Notice in each file and include the License file at
19 | * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20 | * particular file as subject to the "Classpath" exception as provided
21 | * by Oracle in the GPL Version 2 section of the License file that
22 | * accompanied this code. If applicable, add the following below the
23 | * License Header, with the fields enclosed by brackets [] replaced by
24 | * your own identifying information:
25 | * "Portions Copyrighted [year] [name of copyright owner]"
26 | *
27 | * If you wish your version of this file to be governed by only the CDDL
28 | * or only the GPL Version 2, indicate your decision by adding
29 | * "[Contributor] elects to include this software in this distribution
30 | * under the [CDDL or GPL Version 2] license." If you do not indicate a
31 | * single choice of license, a recipient has the option to distribute
32 | * your version of this file under either the CDDL, the GPL Version 2 or
33 | * to extend the choice of license to its licensees as provided above.
34 | * However, if you add GPL Version 2 code and therefore, elected the GPL
35 | * Version 2 license, then the option applies only if the new code is
36 | * made subject to such option by the copyright holder.
37 | *
38 | * Contributor(s):
39 | */
40 |
41 | // List of standard headers was taken in http://en.cppreference.com/w/cpp/header
42 |
43 | #include // General purpose utilities: program control, dynamic memory allocation, random numbers, sort and search
44 | #include // Functions and macro constants for signal management
45 | #include // Macro (and function) that saves (and jumps) to an execution context
46 | #include // Handling of variable length argument lists
47 | #include // Runtime type information utilities
48 | #include // std::bitset class template
49 | #include // Function objects, designed for use with the standard algorithms
50 | #include // Various utility components
51 | #include // C-style time/date utilites
52 | #include // typedefs for types such as size_t, NULL and others
53 | #include // Low-level memory management utilities
54 | #include // Higher level memory management utilities
55 | #include // limits of integral types
56 | #include // limits of float types
57 | #include // standardized way to query properties of arithmetic types
58 | #include // Exception handling utilities
59 | #include // Standard exception objects
60 | #include // Conditionally compiled macro that compares its argument to zero
61 | #include // Macro containing the last error number
62 | #include // functions to determine the type contained in character data
63 | #include // functions for determining the type of wide character data
64 | #include // various narrow character string handling functions
65 | #include // various wide and multibyte string handling functions
66 | #include // std::basic_string class template
67 | #include // std::vector container
68 | #include // std::deque container
69 | #include // std::list container
70 | #include // std::set and std::multiset associative containers
71 | #include