fix: BLE TX 먹통 해결 및 메모리 안전성 개선
- binary_tx_handler를 dr_binary_tx_safe로 전체 교체 (APP_ERROR_CHECK 제거) - data_tx_handler APP_ERROR_CHECK → DBG_PRINTF 교체 - memset/memcpy 하드코딩 크기를 define 상수로 교체 (버퍼 오버런 수정) - SERIAL_NO_LENGTH, HW_NO_LENGTH, PASSKEY_LENGTH를 main.h로 통합 - 미사용 HW 드라이버/EEPROM 코드 삭제, TWI를 i2c_manager.c로 통합 - EEPROM → FDS 전환, 코드 리뷰 현황 문서 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -47,16 +47,16 @@ extern "C" {
|
|||||||
#include "nrf_gpio.h"
|
#include "nrf_gpio.h"
|
||||||
|
|
||||||
// LEDs definitions for PCA10056
|
// LEDs definitions for PCA10056
|
||||||
#define LEDS_NUMBER 1
|
#define LEDS_NUMBER 2
|
||||||
|
|
||||||
#define LED_1 NRF_GPIO_PIN_MAP(0,12) //Green LED for Advertise
|
#define LED_GR NRF_GPIO_PIN_MAP(0,12) //Green LED for Advertise
|
||||||
#define LED_START LED_1
|
#define LED_YL_TEST NRF_GPIO_PIN_MAP(0,29) // Yello LED for Function 260311
|
||||||
#define LED_STOP LED_1
|
|
||||||
|
|
||||||
#define LEDS_ACTIVE_STATE 0
|
#define LEDS_ACTIVE_STATE 0
|
||||||
#define LEDS_LIST { LED_1 }
|
#define LEDS_LIST { LED_GR, LED_YL_TEST }
|
||||||
#define LEDS_INV_MASK LEDS_MASK
|
#define LEDS_INV_MASK LEDS_MASK
|
||||||
#define BSP_LED_0 LED_1
|
#define BSP_LED_0 LED_GR
|
||||||
|
#define BSP_LED_1 LED_YL_TEST // 260311
|
||||||
|
|
||||||
#define BUTTONS_NUMBER 3
|
#define BUTTONS_NUMBER 3
|
||||||
|
|
||||||
|
|||||||
342
data/260311 VesiScan-Basic_VB0HW0100_Firmware Dev 버전 개발 사양.md
Normal file
342
data/260311 VesiScan-Basic_VB0HW0100_Firmware Dev 버전 개발 사양.md
Normal file
@@ -0,0 +1,342 @@
|
|||||||
|
# VB0HW0100 — Firmware Dev. 버전 개발 사양서
|
||||||
|
|
||||||
|
## 1. 시스템 개요
|
||||||
|
|
||||||
|
### 1-1. 보드 기능
|
||||||
|
|
||||||
|
초음파 방광 모니터링을 위한 웨어러블 디바이스.
|
||||||
|
6채널 Piezo 트랜스듀서를 순차 구동하여 A-mode 초음파 측정을 수행하고, BLE를 통해 데이터를 전송한다.
|
||||||
|
Dev. 버전은 모든 명령이 앱에서 내려지도록 개발.
|
||||||
|
|
||||||
|
### 1-2. 기능 블록 구분
|
||||||
|
|
||||||
|
| 블록 | 명칭 | 주요 IC | 역할 |
|
||||||
|
|------|------|---------|------|
|
||||||
|
| 제어부 | Control | nRF52840 (U26) | MCU, BLE, 전체 제어 |
|
||||||
|
| | | W25Q32 (U16) | Flash Memory (데이터 저장) |
|
||||||
|
| | | ICM-42670 (U10) | IMU 센서 (6축) |
|
||||||
|
| TX | Transmit | MD1822 (U27) | MOSFET Driver |
|
||||||
|
| | | TC7920 (U30) | MOSFET (고전압 스위칭) |
|
||||||
|
| | | MAX14778 (U31) | 8채널 MUX (채널 선택) |
|
||||||
|
| | | Misc | TMP235 (U22) | 온도 센서 |
|
||||||
|
| RX | Receive | MD0100 (U34) | T/R 스위치 (수신 보호) |
|
||||||
|
| | | OPA2836 (U2) | 2단 수신 증폭기 |
|
||||||
|
| | | ADL5513 (U23) | 로그 디텍터 (AGC) |
|
||||||
|
| | | ADC121S051 (U37) | 12비트 SPI ADC |
|
||||||
|
| 전원 | Power | MIC5528 (U5) | LDO → +3.3V_M (제어부) |
|
||||||
|
| | | MIC5528 (U42) | LDO → +3.3V_PZT_TX (TX) |
|
||||||
|
| | | MIC5528 (U41) | LDO → +3.3V_PZT_RX (RX) |
|
||||||
|
| | | LT3463 (U32) | DC-DC → ±25V (펄서 전원) |
|
||||||
|
| | | MCP1804 (U33) | LDO → +10V |
|
||||||
|
| | | LM27762 (U38) | Charge Pump → ±2.75V (Op-Amp 전원) |
|
||||||
|
| | | MCP73838 (U3) | 배터리 충전 IC |
|
||||||
|
|
||||||
|
### 1-3. 신호 흐름
|
||||||
|
|
||||||
|
```
|
||||||
|
[TX 경로]
|
||||||
|
nRF52840 → MD1822 (Driver) → TC7920 (MOSFET) → MAX14778 (MUX) → Piezo (6ch 중 1개)
|
||||||
|
|
||||||
|
[RX 경로]
|
||||||
|
Piezo (6ch 중 1개) → MAX14778 (MUX) → MD0100 (T/R 보호) → OPA2836 (2단 증폭) → ADL5513 (로그 디텍터) → ADC121S051 → nRF52840
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 전원 시퀀싱
|
||||||
|
|
||||||
|
### 2-1. 전원 도메인
|
||||||
|
|
||||||
|
| 도메인 | 전원넷 | LDO | Enable 신호 | 공급 대상 |
|
||||||
|
|--------|--------|-----|-------------|-----------|
|
||||||
|
| 제어부 | +3.3V_M | U5 (MIC5528) | PWR_MCU_EN | nRF52840, W25Q32, ICM-42670 |
|
||||||
|
| TX | +3.3V_PZT_TX | U42 (MIC5528) | PZT_PWR_EN | 펄서 관련 회로 (MD1822, TC7920 등) |
|
||||||
|
| RX | +3.3V_PZT_RX | U41 (MIC5528) | PZT_PWR_EN | 수신 회로 (OPA2836, ADC121S051 등) |
|
||||||
|
|
||||||
|
- TX와 RX는 **동일한 PZT_PWR_EN** 신호로 동시에 ON/OFF
|
||||||
|
|
||||||
|
### 2-2. 전원 켜기 (Power ON)
|
||||||
|
|
||||||
|
1. 사용자가 **SW2**를 누름
|
||||||
|
2. PWR_MCU_EN = **High** → U5 활성화 → +3.3V_M 출력
|
||||||
|
3. nRF52840 부팅 시작
|
||||||
|
4. MCU가 SW2 눌림 상태를 확인하며 **2초간** 유지 여부 판단
|
||||||
|
5. 조건 충족 시 MCU가 **PWR_HOLD = High** 출력 → 자기유지 (Self-Latch)
|
||||||
|
6. 이후 SW2를 놓아도 전원 유지됨
|
||||||
|
|
||||||
|
### 2-3. 전원 끄기 (Power OFF)
|
||||||
|
|
||||||
|
1. MCU는 **BUTTON_CHECK** 핀으로 SW2 상태를 상시 감시
|
||||||
|
2. SW2가 **3초간** 눌림 유지 감지
|
||||||
|
3. MCU가 **PWR_HOLD = Low** 출력
|
||||||
|
4. U5 이네이블 해제 → +3.3V_M 차단 → 전체 전원 OFF
|
||||||
|
|
||||||
|
### 2-4. 동작 모드
|
||||||
|
|
||||||
|
| 모드 | 제어부 (+3.3V_M) | TX (+3.3V_PZT_TX) | RX (+3.3V_PZT_RX) | 설명 |
|
||||||
|
|------|:-:|:-:|:-:|------|
|
||||||
|
| **Sleep Mode** | ON | OFF | OFF | 모든 IC 저전력 모드 동작, MCU BLE 유지, 명령 대기 |
|
||||||
|
| **Active Mode** | ON | ON | ON | 초음파 측정 가능 상태 |
|
||||||
|
|
||||||
|
- Sleep → Active: MCU가 **PZT_PWR_EN = High**
|
||||||
|
- Active → Sleep: MCU가 **PZT_PWR_EN = Low**
|
||||||
|
- 기본 상태는 항상 **Sleep Mode**
|
||||||
|
- W25Q32와 ICM-42670는 초기설정을 **Deep Power-Down** 모드로 세팅
|
||||||
|
- 모든 측정 후에는 항상 **Sleep Mode**로 복귀
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 측정 명령
|
||||||
|
|
||||||
|
### 3-1. 측정 명령 종류
|
||||||
|
|
||||||
|
| 측정 명령 | 측정 대상 | 필요 모드 | 비고 |
|
||||||
|
|-----------|-----------|:-:|------|
|
||||||
|
| 배터리 전압 측정 | ADC_BAT | Sleep | +3.3V_M 도메인, Active 전환 불필요 |
|
||||||
|
| IMU 측정 | ICM-42670 (I2C) | Sleep | +3.3V_M 도메인, Active 전환 불필요 |
|
||||||
|
| 온도 측정 | TMP235 (ADC_TEMP) | **Active** | TX/RX 전원 필요 |
|
||||||
|
| 초음파 측정 | Piezo 6ch | **Active** | TX/RX 전원 필요 |
|
||||||
|
| 모두 측정 | 전체 | **Active** | TX/RX 전원 필요 |
|
||||||
|
|
||||||
|
-
|
||||||
|
|
||||||
|
### 3-2. 명령별 동작 흐름
|
||||||
|
|
||||||
|
**Sleep Mode에서 처리 (Active 전환 불필요)**
|
||||||
|
|
||||||
|
```
|
||||||
|
배터리 측정 명령 → 동작모드 전환 → ADC_BAT 읽기 → BLE 전송 → Deep Power-Down 모드 전환
|
||||||
|
IMU 측정 명령 → 동작모드 전환 → I2C로 ICM-42670 읽기 → BLE 전송 → Deep Power-Down 모드 또는 필요 모드 전환
|
||||||
|
```
|
||||||
|
|
||||||
|
**Active Mode 필요**
|
||||||
|
|
||||||
|
```
|
||||||
|
온도 측정 명령 → Active 진입 → ADC_TEMP 읽기 → BLE 전송 → Sleep 복귀
|
||||||
|
초음파 측정 명령 → Active 진입 → 6ch 스캔 → BLE 전송 → Sleep 복귀
|
||||||
|
모두 측정 명령 → Active 진입 → 배터리 + IMU + 온도 + 초음파 → BLE 전송 → Sleep 복귀
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Piezo 초음파 측정
|
||||||
|
|
||||||
|
### 4-1. 측정 파라미터
|
||||||
|
|
||||||
|
| 파라미터 | 범위 | 설명 |
|
||||||
|
|----------|------|------|
|
||||||
|
| Frequency | 1.8 / 1.9 / 2.0 / 2.1 / 2.2 MHz | 송신 펄스 주파수 |
|
||||||
|
| Cycle | 3 ~ 7 | 송신 펄스 사이클 수 |
|
||||||
|
| 평균화 수 (Avg) | 1 ~ 10 | 채널당 반복 측정 횟수 |
|
||||||
|
| 측정 Channel 개수 (N) | 1 ~ 6 | 측정 대상 채널 수 |
|
||||||
|
| 대기 시간 (Delay) | 0~30 (default: 10) | TX 펄수 출력 후 ADC 시작 시까지 대기 시간 (μs) |
|
||||||
|
| 측정 샘플 수 (Num_samples) | 80 ~ 140 | 측정 ADC 샘플 개수 |
|
||||||
|
|
||||||
|
### 4-2. 채널 정의
|
||||||
|
|
||||||
|
- 총 **6채널**: CH0, CH1, CH2, CH3, CH4, CH5
|
||||||
|
- Channel 개수 = N이면 **CH0 ~ CH(N-1)** 을 순차 측정
|
||||||
|
- 예: N=4 → CH0, CH1, CH2, CH3만 측정
|
||||||
|
|
||||||
|
### 4-3. 평균화 동작
|
||||||
|
|
||||||
|
각 채널별로 평균화 수(Avg)만큼 반복 측정한 후, 평균값을 해당 채널의 최종 측정값으로 사용한다.
|
||||||
|
|
||||||
|
예: Avg=5, N=3인 경우
|
||||||
|
|
||||||
|
```
|
||||||
|
CH0: 측정①②③④⑤ → 평균 → CH0 최종값
|
||||||
|
CH1: 측정①②③④⑤ → 평균 → CH1 최종값
|
||||||
|
CH2: 측정①②③④⑤ → 평균 → CH2 최종값
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4-4. TX 송신 절차
|
||||||
|
|
||||||
|
1. **MAX14778 (MUX)** 채널 선택 (해당 Piezo 연결)
|
||||||
|
2. **1.3ms 대기** (MAX14778 채널 스위칭 안정화 시간)
|
||||||
|
3. **PZT_PE = High** (펄서 활성화)
|
||||||
|
4. **MD1822**에 설정된 Frequency / Cycle로 펄스 신호 입력
|
||||||
|
5. **TC7920 (MOSFET)** 이 ±25V 펄스를 Piezo에 인가
|
||||||
|
|
||||||
|
| 관련 핀/넷 | 연결 |
|
||||||
|
|------------|------|
|
||||||
|
| PZT_CH_SEL0 | U26.A20 → U31 (MUX 채널 선택 비트 0) |
|
||||||
|
| PZT_CH_SEL1 | U26.B11 → U31 (MUX 채널 선택 비트 1) |
|
||||||
|
| PZT_EN_MUXA | U26.AC17 → U31 (MUX A 활성화) |
|
||||||
|
| PZT_EN_MUXB | U26.AC19 → U31 (MUX B 활성화) |
|
||||||
|
| PZT_PE | U26.AC21 → U27.15 (펄서 이네이블) |
|
||||||
|
| PZT_P_PULSE | U26.P23 → R30 (48.7Ω) → U27 (양의 펄스) |
|
||||||
|
| PZT_N_PULSE | U26.R24 → R40 (48.7Ω) → U27 (음의 펄스) |
|
||||||
|
| PZT_DMP | U26.AD22 → R12 (48.7Ω) → U27 (댐핑 제어) |
|
||||||
|
|
||||||
|
### 4-5. RX 수신 절차
|
||||||
|
|
||||||
|
1. TX 펄스 출력 후 약 **10μs 대기** (근거리 잔향 회피)
|
||||||
|
2. 에코 신호 경로:
|
||||||
|
Piezo → MAX14778 (MUX) → MD0100 (T/R 보호) → OPA2836 (2단 증폭, 총 ~40dB) → ADL5513 (로그 디텍터)
|
||||||
|
3. **ADC121S051**에서 약 **300μs 동안** ADC 값 연속 수집
|
||||||
|
4. MCU가 SPI를 통해 ADC 데이터 읽기
|
||||||
|
|
||||||
|
| 관련 핀/넷 | 연결 |
|
||||||
|
|------------|------|
|
||||||
|
| \PZT_SPI_CS | U26.AC15 → U37 (ADC 칩셀렉트) |
|
||||||
|
| SPI_SCK | U26.AC9 (Flash와 공유) |
|
||||||
|
| SPI_MISO | U26.AD10 (Flash와 공유) |
|
||||||
|
|
||||||
|
### 4-6. 단일 측정 타이밍
|
||||||
|
|
||||||
|
```
|
||||||
|
|←── TX ──→|← 10μs →|←─────── 300μs RX 수집 ───────→|
|
||||||
|
펄스 출력 대기 ADC121S051 연속 샘플링
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4-7. 전체 스캔 시퀀스 (예: Avg=5, N=3)
|
||||||
|
|
||||||
|
```
|
||||||
|
측정 명령 수신
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
Active Mode 진입 (PZT_PWR_EN = High)
|
||||||
|
│
|
||||||
|
├─ CH0 선택 (MUX → A0) → 1.3ms 대기
|
||||||
|
│ ├─ 1회: TX → 10μs → 300μs RX
|
||||||
|
│ ├─ 2회: TX → 10μs → 300μs RX
|
||||||
|
│ ├─ 3회: TX → 10μs → 300μs RX
|
||||||
|
│ ├─ 4회: TX → 10μs → 300μs RX
|
||||||
|
│ └─ 5회: TX → 10μs → 300μs RX
|
||||||
|
│ → CH0 평균값 산출
|
||||||
|
│
|
||||||
|
├─ CH1 선택 (MUX → A1) → 1.3ms 대기
|
||||||
|
│ └─ 5회 반복 → CH1 평균값 산출
|
||||||
|
│
|
||||||
|
├─ CH2 선택 (MUX → A2) → 1.3ms 대기
|
||||||
|
│ └─ 5회 반복 → CH2 평균값 산출
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
BLE 전송
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
Sleep Mode 복귀 (PZT_PWR_EN = Low)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 참고 사항
|
||||||
|
|
||||||
|
### 5-1. 배터리 전압 측정
|
||||||
|
|
||||||
|
- R28 (806kΩ) / R29 (2MΩ) 분압 → ADC_BAT
|
||||||
|
- 분압비: 2M / (806k + 2M) ≈ 0.713
|
||||||
|
- nRF52840 내장 ADC로 읽기
|
||||||
|
|
||||||
|
### 5-2. 충전 / 동작 상태 표시 LED
|
||||||
|
|
||||||
|
| LED | 색상 | 연결 네트 | 상태 | 표시 |
|
||||||
|
|-----|------|------|------|------|
|
||||||
|
| LED1 | 오렌지 | U3.STAT1 | 충전중 | 상시 점등 |
|
||||||
|
| LED2 | 블루 | U3.STAT2 | 충전 완료 | 상시 점등 |
|
||||||
|
| LED3 | 초록 | LED_BLE | BLE Advertising | 1초 간격 점멸 |
|
||||||
|
| LED3 | 초록 | LED_BLE | BLE 연결 후, Piezo 초음파 측정 후 복부 부착으로 감지된 경우 | 소등 |
|
||||||
|
| LED3 | 초록 | LED_BLE | Piezo 초음파 측정 후 탈착으로 감지된 경우 | 점등 1초 소등 3초 반복 |
|
||||||
|
| LED4 | 오렌지 | FUNCTION_LED | 기기 정렬모드에서 방광위치를 탐지하지 못하고 있을 경우 | 1초 간격 점멸 |
|
||||||
|
| LED3 | 초록 | LED_BLE | 기기 정렬모드에서 방광위치를 탐지하고 있을 경우 | 점등 3초 소등 1초 반복 |
|
||||||
|
|
||||||
|
- 기기 정렬 모드 : 빠른 주기로 초음파 측정
|
||||||
|
- 복부 부착, 탈착, 방광위치 탐지 유무는 앱에서 판단, LED 동작 모드 명령 송신
|
||||||
|
|
||||||
|
### 5-3. 펄서 고전압 전원
|
||||||
|
|
||||||
|
| 전원 | 생성 IC | 전압 | 용도 |
|
||||||
|
|------|---------|------|------|
|
||||||
|
| PZT_+25V | LT3463 (U32) | +25V | 양의 펄스 전압 |
|
||||||
|
| PZT_-25V | LT3463 (U32) | -25V | 음의 펄스 전압 |
|
||||||
|
| PZT_+10V | MCP1804 (U33) | +10V | MD1822 공급 전원 |
|
||||||
|
|
||||||
|
### 5-4. 수신부 아날로그 전원
|
||||||
|
|
||||||
|
| 전원 | 생성 IC | 전압 | 용도 |
|
||||||
|
|------|---------|------|------|
|
||||||
|
| +2.75V_CP | LM27762 (U38) | +2.75V | OPA2836 양전원 |
|
||||||
|
| -2.75V_CP | LM27762 (U38) | -2.75V | OPA2836 음전원 |
|
||||||
|
|
||||||
|
### 5-5. DFU 관련 주의사항
|
||||||
|
|
||||||
|
- nRF52840 DFU(Device Firmware Update) 부트로더에서 **P0.25를 사용하지 않도록** 수정 필요
|
||||||
|
- 기본 DFU 부트로더가 P0.25를 버튼 입력 등으로 사용할 수 있으므로, 커스텀 DFU 빌드 시 해당 핀 설정을 제거 또는 변경할 것
|
||||||
|
|
||||||
|
### 5-6. MAX14778 채널 스위칭 지연
|
||||||
|
|
||||||
|
- MAX14778 채널 전환 후 신호 경로가 안정되기까지 **1.3ms delay** 필요
|
||||||
|
- MUX_SelectChannel() 호출 후 반드시 1.3ms 대기 후 TX 펄스를 출력할 것
|
||||||
|
- 동일 채널 내 반복 측정 시에는 추가 delay 불필요 (채널 전환 시에만 적용)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 전력 절감 방안
|
||||||
|
|
||||||
|
### 6-1. Sleep Mode 소비 전류 줄이기
|
||||||
|
|
||||||
|
Sleep Mode에서 +3.3V_M에 상시 전원을 받는 IC는 3개이며, 각각에 대해 저전력 제어가 가능하다.
|
||||||
|
|
||||||
|
**nRF52840 (MCU)**
|
||||||
|
|
||||||
|
- BLE 연결 유지를 위해 System ON 슬립 상태를 사용
|
||||||
|
- 사용하지 않는 peripheral 클럭을 모두 비활성화
|
||||||
|
- RAM 리텐션 영역을 최소한으로 설정
|
||||||
|
- 위 조치를 통해 수 μA 수준까지 소비 전류 절감 가능
|
||||||
|
|
||||||
|
**W25Q32 (Flash Memory)**
|
||||||
|
|
||||||
|
- 대기 상태에서도 수 μA 소모
|
||||||
|
- 측정/저장 시에만 깨우고, 평소에는 **Deep Power-Down** 모드 사용
|
||||||
|
- Deep Power-Down 진입: SPI로 0xB9 커맨드 전송 → 소비 전류 약 1μA 이하
|
||||||
|
- 복귀: 0xAB 커맨드 전송 후 수 μs 대기
|
||||||
|
- \SPI_CS_FLASH를 High로 유지하는 것만으로는 불충분하며, 명시적으로 커맨드를 전송해야 함
|
||||||
|
|
||||||
|
| 상태 | 소비 전류 (대략) | 진입 방법 |
|
||||||
|
|------|:-:|------|
|
||||||
|
| Normal Standby | ~수 μA | 기본 상태 |
|
||||||
|
| Deep Power-Down | ~1μA 이하 | SPI 커맨드 0xB9 |
|
||||||
|
|
||||||
|
**ICM-42670 (IMU Sensor)**
|
||||||
|
|
||||||
|
- IMU를 상시 켜둘 필요 없음
|
||||||
|
- 측정 명령이 올 때만 Wake → 측정 → 다시 Sleep 시키는 방식 사용
|
||||||
|
- I2C로 슬립 모드 진입 또는 ODR(Output Data Rate)을 최소로 설정
|
||||||
|
|
||||||
|
| 상태 | 소비 전류 (대략) | 비고 |
|
||||||
|
|------|:-:|------|
|
||||||
|
| Full Rate 동작 | ~수백 μA | 가속도 + 자이로 활성 |
|
||||||
|
| Low Power / Sleep | ~수 μA 이하 | 측정 시에만 Wake |
|
||||||
|
|
||||||
|
### 6-2. Active Mode 체류 시간 최소화
|
||||||
|
|
||||||
|
Active Mode에서는 TX/RX LDO(U42, U41)뿐 아니라 LT3463(±25V), MCP1804(+10V), LM27762(±2.75V) 등 고전압/아날로그 전원이 모두 켜지므로 소비 전류가 크게 증가한다. 따라서 Active Mode 체류 시간을 최소화하는 것이 전력 절감에 가장 효과적이다.
|
||||||
|
|
||||||
|
**원칙: 측정 직전에 Active 진입, 측정 직후 즉시 Sleep 복귀**
|
||||||
|
|
||||||
|
**전원 안정화 시간 관리**
|
||||||
|
|
||||||
|
- PZT_PWR_EN = High 후 LDO/DC-DC 출력이 안정될 때까지 대기 필요
|
||||||
|
- 이 안정화 시간을 실측하여 필요 최소한으로 설정
|
||||||
|
- 불필요하게 긴 마진을 두지 않도록 주의
|
||||||
|
|
||||||
|
**스캔 시간 분석**
|
||||||
|
|
||||||
|
| 항목 | 시간 |
|
||||||
|
|------|------|
|
||||||
|
| MUX 채널 스위칭 안정화 | 1.3ms (채널 전환 시 1회) |
|
||||||
|
| 1회 측정 (TX + 10μs 대기 + 300μs RX) | ~310μs |
|
||||||
|
| 1채널 (Avg=5) | 1.3ms + 5 × 310μs ≈ 2.85ms |
|
||||||
|
| 6채널 전체 (Avg=5, N=6) | 6 × 2.85ms ≈ 17.1ms |
|
||||||
|
|
||||||
|
- 6채널 전체 스캔 자체는 약 17ms 이내로 완료 가능
|
||||||
|
- 전원 안정화 대기 시간이 오히려 더 큰 비중을 차지할 수 있음
|
||||||
|
- 채널 전환 → TX → RX를 타이트하게 구성하여 불필요한 간격 제거
|
||||||
|
|
||||||
|
**측정 파라미터에 의한 시간 절감**
|
||||||
|
|
||||||
|
| 파라미터 조절 | 효과 |
|
||||||
|
|--------------|------|
|
||||||
|
| Channel 개수 줄이기 | 측정 채널 수에 비례하여 Active 시간 단축 |
|
||||||
|
| 평균화 수 줄이기 | 반복 횟수에 비례하여 Active 시간 단축 |
|
||||||
|
| 간헐 측정 (측정 주기 늘리기) | Active 진입 빈도 자체를 줄임 |
|
||||||
37662
data/CODE_REVIEW.pdf
Normal file
37662
data/CODE_REVIEW.pdf
Normal file
File diff suppressed because it is too large
Load Diff
473
data/CODE_REVIEW_STATUS.md
Normal file
473
data/CODE_REVIEW_STATUS.md
Normal file
@@ -0,0 +1,473 @@
|
|||||||
|
# VesiScan-Basic 코드 리뷰 현황 보고서
|
||||||
|
|
||||||
|
작성일: 2026-03-16
|
||||||
|
대상: VesiScan BASIC 펌웨어 전체 (nRF52840 + S140 SoftDevice)
|
||||||
|
기준 문서: CODE_REVIEW.pdf (2026-03-15)
|
||||||
|
현재 빌드: DEBUG_MINIMAL_BOOT=1, BLE_DEV_MODE=1
|
||||||
|
|
||||||
|
## 목차
|
||||||
|
|
||||||
|
1. 삭제 대상: 미사용 하드웨어 드라이버
|
||||||
|
2. 삭제 대상: 미사용 코드
|
||||||
|
3. DEBUG_MINIMAL_BOOT 조건부 컴파일 정리
|
||||||
|
4. Keil 프로젝트 파일 정리
|
||||||
|
5. 버그 및 오류 수정
|
||||||
|
6. 저전력 최적화
|
||||||
|
7. 코드 품질 개선
|
||||||
|
8. 작업 우선순위 요약
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 삭제 대상: 미사용 하드웨어 드라이버
|
||||||
|
|
||||||
|
### 1.1 회로 기반 분석
|
||||||
|
|
||||||
|
변경 없음. VB0HW0100 회로 기준 IC 목록은 CODE_REVIEW.pdf 1.1절과 동일.
|
||||||
|
|
||||||
|
### 1.2 회로에 없는 IC의 드라이버 (삭제 대상)
|
||||||
|
|
||||||
|
| 파일 | IC/기능 | 판정 | 현재 상태 |
|
||||||
|
|------|--------|------|----------|
|
||||||
|
| ad5272_i2c.c/h | AD5272 디지털 포텐시오미터 | 삭제 | **완료** |
|
||||||
|
| ada2200_spi.c/h | ADA2200 동기 복조기 | 삭제 | **완료** |
|
||||||
|
| mcp4725_i2c.c/h | MCP4725 DAC | 삭제 | **완료** |
|
||||||
|
| mcp4725_adc.c/h | MCP4725 ADC 피드백 | 삭제 | **완료** |
|
||||||
|
| ir_i2c.c/h | IR LED 센서 (0x50~0x57) | 삭제 | **완료** |
|
||||||
|
| LED_Parse.c/h | LED ROM 파싱 | 삭제 | **완료** |
|
||||||
|
|
||||||
|
### 1.3 기능적으로 미사용인 드라이버 (삭제 대상)
|
||||||
|
|
||||||
|
| 파일 | 기능 | 판정 | 현재 상태 |
|
||||||
|
|------|------|------|----------|
|
||||||
|
| measurements.c/h | 레거시 측정 루프 | 삭제 | **완료** |
|
||||||
|
| measurements_20.c/h | 20-샘플 측정 변형 | 삭제 | **완료** |
|
||||||
|
| meas_pd_imm.c/h | 즉시 PD 측정 | 삭제 | **완료** |
|
||||||
|
| meas_pd_buff.c/h | 버퍼드 PD 측정 | 삭제 | **완료** |
|
||||||
|
| meas_pd_voltage_simple.c/h | 단순 전압 측정 | 삭제 | **완료** |
|
||||||
|
| meas_pd_voltage_half.c/h | 반파 전압 측정 | 삭제 | **완료** |
|
||||||
|
| meas_pd_voltage_full.c/h | 전파 전압 측정 | 삭제 | **완료** |
|
||||||
|
| meas_pd_voltage_custom.c/h | 커스텀 전압 측정 | 삭제 | **완료** |
|
||||||
|
| full_agc.c/h | 자동 이득 제어 | 삭제 | **완료** |
|
||||||
|
| debuf_print.h | 오타 파일 | 삭제 | **완료** |
|
||||||
|
|
||||||
|
### 1.4 삭제 시 의존성 영향
|
||||||
|
|
||||||
|
cmd_parse.h에서 제거할 include 목록:
|
||||||
|
|
||||||
|
| include | 현재 상태 |
|
||||||
|
|---------|----------|
|
||||||
|
| #include "ir_i2c.h" | **완료** (제거됨) |
|
||||||
|
| #include "ad5272_i2c.h" | **완료** (제거됨) |
|
||||||
|
| #include "ada2200_spi.h" | **완료** (제거됨) |
|
||||||
|
| #include "mcp4725_i2c.h" | **완료** (제거됨) |
|
||||||
|
| #include "measurements.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_imm.h" | **완료** (제거됨) |
|
||||||
|
|
||||||
|
### 1.5 cat_interface.c (EEPROM 드라이버) 삭제 분석
|
||||||
|
|
||||||
|
#### 1.5.1 결론: EEPROM 삭제 완료, TWI는 i2c_manager.c로 통합
|
||||||
|
|
||||||
|
현재 상태: **완료** - jhChun 26.03.16
|
||||||
|
|
||||||
|
cat_interface.c 삭제(EEPROM/AES 코드 전체 삭제). TWI 인스턴스(m_twi) 및 초기화/해제 함수는 i2c_manager.c로 통합.
|
||||||
|
|
||||||
|
|
||||||
|
#### 1.5.2 cat_interface.c가 제공하는 것
|
||||||
|
|
||||||
|
| 기능 | 판정 | 현재 상태 |
|
||||||
|
|------|------|----------|
|
||||||
|
| m_eeprom TWI 인스턴스 | i2c_manager.c로 이동, m_twi로 리네이밍 | **완료** |
|
||||||
|
| eeprom_initialize() / uninitialize() | i2c_manager.c로 이동, twi_initialize/uninitialize로 리네이밍 (static) | **완료** |
|
||||||
|
| eeprom_read/write_byte/word/page/bytes | 삭제 | **완료** |
|
||||||
|
| eeprom_read/write_uint16_array | 삭제 | **완료** |
|
||||||
|
| eeprom_read/write_uint32 | 삭제 | **완료** |
|
||||||
|
| eeprom_write_encrypted() / read_decrypted() | 삭제 | **완료** |
|
||||||
|
| encrypt_data() / decrypt_data() | 삭제 | **완료** |
|
||||||
|
| aes_key[16], aes_iv[16] | 삭제 | **완료** |
|
||||||
|
|
||||||
|
#### 1.5.3 권장 작업
|
||||||
|
|
||||||
|
| # | 작업 | 현재 상태 |
|
||||||
|
|---|------|----------|
|
||||||
|
| 1 | TWI 인스턴스/init/uninit → i2c_manager.c로 통합 | **완료** |
|
||||||
|
| 2 | m_eeprom → m_twi 리네이밍 | **완료** |
|
||||||
|
| 3 | EEPROM read/write 전체 삭제, AES 전체 삭제 | **완료** |
|
||||||
|
| 4 | cmd_parse.c EEPROM 호출 -> FDS 전환 | **완료** |
|
||||||
|
| 5 | main.c 버튼 롱프레스 리셋: EEPROM -> FDS | **완료** |
|
||||||
|
| 6 | power_control.c: cat_interface.h include 제거 | **완료** |
|
||||||
|
|
||||||
|
#### 1.5.4 cmd_parse.c EEPROM -> FDS 전환 목록
|
||||||
|
|
||||||
|
| EEPROM 호출 | 위치 | FDS 대체 방법 | 현재 상태 |
|
||||||
|
|------------|------|------------|----------|
|
||||||
|
| eeprom_init_values_read() | cmd_parse.c | 삭제 (FDS config_load 대체) | **완료** |
|
||||||
|
| eeprom_write_byte(0x0070, m_pd_adc_cnt) | cmd_parse.c | m_config.pd_adc_cnt = val; config_save(); | **완료** |
|
||||||
|
| eeprom_write_word(0x0080, m_pd_delay_us) | cmd_parse.c | m_config.pd_delay_us = val; config_save(); | **완료** |
|
||||||
|
| eeprom_write_byte(0x0060, bond_data_delete) | cmd_parse.c | m_config.bond_data_delete = val; config_save(); | **완료** |
|
||||||
|
| eeprom_write_byte(0x0065, m_reset_status) | cmd_parse.c | m_config.reset_status = val; config_save(); | **완료** |
|
||||||
|
| eeprom_write_encrypted(0x0020, passkey, 6) | cmd_parse.c | memcpy(m_config.static_passkey, val, 6); config_save(); | **완료** |
|
||||||
|
| eeprom_read_decrypted(0x0020, passkey, 6) | cmd_parse.c | memcpy(buf, m_config.static_passkey, 6); | **완료** |
|
||||||
|
| eeprom_write_uint32(0x0090, m_life_cycle) | cmd_parse.c | m_config.life_cycle = val; config_save(); (FDS 필드 추가 완료) | **완료** |
|
||||||
|
| eeprom_read_uint32(0x0090, &m_life_cycle) | cmd_parse.c | m_life_cycle = m_config.life_cycle; | **완료** |
|
||||||
|
| eeprom_write/read_uint16_array(0x0480, ...) | cmd_parse.c | AGC gain — HW 제거됨, 명령 비활성화 | **완료** |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 삭제 대상: 미사용 코드
|
||||||
|
|
||||||
|
### 2.1 AES 암호화 (cat_interface.c)
|
||||||
|
|
||||||
|
판정 변경: 전체 삭제
|
||||||
|
|
||||||
|
| 항목 | 위치 | 판정 | 현재 상태 |
|
||||||
|
|------|------|------|----------|
|
||||||
|
| aes_key[16] 하드코딩 | cat_interface.c | 삭제 | **완료** |
|
||||||
|
| aes_iv[16] (고정 IV = 0) | cat_interface.c | 삭제 | **완료** |
|
||||||
|
| encrypt_data() | cat_interface.c | 삭제 | **완료** |
|
||||||
|
| decrypt_data() | cat_interface.c | 삭제 | **완료** |
|
||||||
|
| eeprom_write_encrypted() | cat_interface.c | 삭제 | **완료** |
|
||||||
|
| eeprom_read_decrypted() | cat_interface.c | 삭제 | **완료** |
|
||||||
|
|
||||||
|
### 2.2 Serial Number / Passkey / HW Version 중복 선언 분석
|
||||||
|
|
||||||
|
| 데이터 | 전역 변수 (런타임) | FDS (내장 Flash) | EEPROM (외부, 제거됨) | 현재 상태 |
|
||||||
|
|--------|----------------|----------------|-------------------|----------|
|
||||||
|
| Serial Number | SERIAL_NO[12] | m_config.serial_no[12] | ~~addr 0x0030~~ | **EEPROM 경로 삭제 완료** |
|
||||||
|
| Passkey | m_static_passkey[6] | m_config.static_passkey[6] | ~~addr 0x0020~~ | **EEPROM 경로 삭제 완료** |
|
||||||
|
| HW Version | HW_NO[12] | m_config.hw_no[12] | ~~addr 0x0010~~ | **HW_NO 미삭제** |
|
||||||
|
|
||||||
|
권장 작업 현황:
|
||||||
|
|
||||||
|
| # | 작업 | 현재 상태 |
|
||||||
|
|---|------|----------|
|
||||||
|
| 1 | EEPROM 경로 삭제 -> eeprom_init_values_read() 삭제 | **완료** |
|
||||||
|
| 2 | HW_NO[12] 삭제 -> m_config.hw_no 직접 사용 | **미완료** |
|
||||||
|
| 3 | SERIAL_NO, m_static_passkey 유지 (BLE 스택 필요) | 해당없음 |
|
||||||
|
| 4 | 데이터 흐름 단순화: FDS -> 전역변수 -> BLE 스택 | **미완료** |
|
||||||
|
|
||||||
|
### 2.3 미사용 전역 변수
|
||||||
|
|
||||||
|
| 변수 | 위치 | 판정 | 현재 상태 |
|
||||||
|
|------|------|------|----------|
|
||||||
|
| roles_str[] | main.c:189 | 삭제 | **미완료** |
|
||||||
|
| m_encrypted_text[16] | main.c:194 | 삭제 | **미완료** |
|
||||||
|
| m_encrypted_text2[16] | main.c:195 | 삭제 | **미완료** |
|
||||||
|
| m_decrypted_text[16] | main.c:196 | 삭제 | **미완료** |
|
||||||
|
| DEVICE_NAME | cmd_parse.c | 삭제 | 확인 필요 |
|
||||||
|
| HW_NO[12] | cmd_parse.c | 삭제 | **미완료** |
|
||||||
|
| AES_KEY_SIZE | main.c:154 | 삭제 | **미완료** |
|
||||||
|
| AES_BLOCK_SIZE | main.c:155 | 삭제 | **미완료** |
|
||||||
|
| suppress_unused_warnings() | main.c:239 | 삭제 | **미완료** |
|
||||||
|
| c_addr[6] | main.c:187 | 삭제 | **미완료** |
|
||||||
|
| led_pd_dac_v[LED_NUM] | 참조 다수 | 삭제 | 확인 필요 |
|
||||||
|
|
||||||
|
### 2.4 주석 처리된 코드
|
||||||
|
|
||||||
|
| 위치 | 내용 | 판정 | 현재 상태 |
|
||||||
|
|------|------|------|----------|
|
||||||
|
| main_timer.c:37-88 | FEATURE_DETAIL_VALUE_FULL 주석 블록 | 삭제 | **미완료** |
|
||||||
|
| cmd_parse.c:282-317 | serial_to_passkey_hash, test_eeprom_page_rw | 삭제 | **미완료** |
|
||||||
|
| cmd_parse.c:87-88 | pd_adc_half/full_a_start extern | 삭제 | 확인 필요 |
|
||||||
|
| battery_saadc.c:22 | //#include "fstorage.h" | 삭제 | **미완료** |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. DEBUG_MINIMAL_BOOT 조건부 컴파일 정리
|
||||||
|
|
||||||
|
현재 DEBUG_MINIMAL_BOOT=1로 MINIMAL 모드만 사용. Full boot 경로는 실행되지 않음.
|
||||||
|
|
||||||
|
### 3.1 제거 대상 #if 블록
|
||||||
|
|
||||||
|
| 파일 | 블록 | 판정 | 현재 상태 |
|
||||||
|
|------|------|------|----------|
|
||||||
|
| main.c:280-281 | #if !DEBUG_MINIMAL_BOOT full_gpio_init() | 삭제 (함수 전체) | **미완료** |
|
||||||
|
| main.c:354-355 | #if !DEBUG_MINIMAL_BOOT load_eeprom_config() | 삭제 (함수 전체, EEPROM 제거 완료) | **완료** (함수 삭제됨) |
|
||||||
|
| main.c:1437-1439 | Full boot 경로 (ada2200_init, mcp4725_init 등) | 삭제 | **미완료** |
|
||||||
|
| main.c GPIO init 분기 | GPIO init 분기 | MINIMAL 코드만 유지 | **미완료** |
|
||||||
|
| power_control.c | Full boot power sequence | 삭제 (minimal 경로만 유지) | **미완료** |
|
||||||
|
|
||||||
|
### 3.3 DEBUG_MINIMAL_BOOT 제거 시 함께 정리
|
||||||
|
|
||||||
|
| 항목 | 현재 상태 |
|
||||||
|
|------|----------|
|
||||||
|
| #define DEBUG_MINIMAL_BOOT 1 삭제 (main.c:96) | **미완료** (여전히 활성) |
|
||||||
|
| 모든 #if 조건 제거, MINIMAL 코드만 유지 | **미완료** |
|
||||||
|
| BLE_DEV_MODE define 유지 | 해당없음 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Keil 프로젝트 파일 정리
|
||||||
|
|
||||||
|
### 4.1 삭제할 소스 참조 (uvprojx)
|
||||||
|
|
||||||
|
현재 상태: **정리 불필요**
|
||||||
|
|
||||||
|
ble_app_bladder_patch_s140.uvprojx 확인 결과, 아래 삭제 대상 파일들은 이미 프로젝트에 등록되어 있지 않음:
|
||||||
|
|
||||||
|
- ad5272_i2c.c, ada2200_spi.c, mcp4725_i2c.c, mcp4725_adc.c
|
||||||
|
- ir_i2c.c, LED_Parse.c, measurements.c, measurements_20.c
|
||||||
|
- full_agc.c, meas_pd_voltage_custom.c, cat_interface.c
|
||||||
|
|
||||||
|
uvprojx 수정 작업 없음.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 버그 및 오류 수정
|
||||||
|
|
||||||
|
### 5.1 심각도 높음 (HIGH)
|
||||||
|
|
||||||
|
#### B1: BLE TX 큐 풀 시 APP_ERROR_CHECK로 인한 시스템 먹통 현상
|
||||||
|
|
||||||
|
파일: main.c (구 binary_tx_handler)
|
||||||
|
|
||||||
|
현재 상태: **완료**
|
||||||
|
|
||||||
|
- `binary_tx_handler()` 함수 본체 삭제
|
||||||
|
- 모든 호출처를 `dr_binary_tx_safe()`로 교체 완료
|
||||||
|
- cmd_parse.c (22곳 + 함수 포인터 1곳)
|
||||||
|
- battery_saadc.c (2곳)
|
||||||
|
- app_raw.c (2곳)
|
||||||
|
- tmp235_q1.c (1곳)
|
||||||
|
- parser.c (17곳)
|
||||||
|
- main.h 선언 제거, dr_util.c/dr_adc121s051.c의 옛날 extern 선언 제거
|
||||||
|
- `dr_binary_tx_safe()`는 NRF_ERROR_RESOURCES 시 최대 100회 재시도 후 패킷 드롭, 연결 에러 시 graceful 리턴
|
||||||
|
- `data_tx_handler()`의 APP_ERROR_CHECK도 DBG_PRINTF로 교체 — 예상치 못한 에러 시에도 패킷 드롭 후 정상 동작 유지
|
||||||
|
|
||||||
|
#### B2: nrf_delay_ms(10) 블로킹 대기 (BLE TX)
|
||||||
|
|
||||||
|
파일: main.c:1221-1228
|
||||||
|
|
||||||
|
현재 상태: **완료**
|
||||||
|
|
||||||
|
조건문 로직이 정상 수정됨. NRF_ERROR_RESOURCES가 아닌 경우에만 delay 실행.
|
||||||
|
|
||||||
|
#### B3: extern + 초기화 동시 사용
|
||||||
|
|
||||||
|
파일: cmd_parse.c
|
||||||
|
|
||||||
|
현재 상태: **완료**
|
||||||
|
|
||||||
|
`extern int8_t pd_adc_counts[4] = {8, 16, 24, 32};` 선언이 제거됨.
|
||||||
|
|
||||||
|
#### B4: memset/memcpy 버퍼 크기 불일치 및 매직 넘버
|
||||||
|
|
||||||
|
파일: main.c config_apply_to_globals()
|
||||||
|
|
||||||
|
현재 상태: **완료**
|
||||||
|
|
||||||
|
- memset 오버런 수정: 하드코딩 `16` → `sizeof(SERIAL_NO)`, `PASSKEY_LENGTH` 사용
|
||||||
|
- memcpy 매직 넘버 수정: 하드코딩 `12` → `sizeof(m_config.hw_no)`, `sizeof(m_config.serial_no)`, `sizeof(SERIAL_NO)` 등으로 교체
|
||||||
|
- m_static_passkey memset/memcpy: `PASSKEY_LENGTH` define 활용
|
||||||
|
|
||||||
|
스택/힙 오버플로우로 인한 메모리 손상 가능성이 있는 심각한 버그.
|
||||||
|
|
||||||
|
### 5.2 심각도 중간 (MEDIUM)
|
||||||
|
|
||||||
|
#### B6: battery_event_handler에서 floating-point 연산
|
||||||
|
|
||||||
|
파일: battery_saadc.c:167
|
||||||
|
|
||||||
|
현재 상태: **미완료**
|
||||||
|
|
||||||
|
여전히 부동소수점 연산 사용 중:
|
||||||
|
```c
|
||||||
|
batt_lvl_in_milli_volt_1 = (batt_lvl_in_milli_volt_0) *1.42;
|
||||||
|
```
|
||||||
|
|
||||||
|
수정 필요:
|
||||||
|
```c
|
||||||
|
batt_lvl_in_milli_volt_1 = (batt_lvl_in_milli_volt_0 * 142) / 100;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### B7: main_timer 단발 모드 문제
|
||||||
|
|
||||||
|
현재 상태: **해당없음** (의도적 설계로 판단)
|
||||||
|
|
||||||
|
#### B8: processing_start_tick 미사용
|
||||||
|
|
||||||
|
파일: cmd_parse.c:57
|
||||||
|
|
||||||
|
현재 상태: **완료** (해결됨)
|
||||||
|
|
||||||
|
변수가 5초 타임아웃 추적에 활용되고 있음:
|
||||||
|
- cmd_parse.c:483에서 초기값 확인
|
||||||
|
- cmd_parse.c:489에서 5초 경과 비교
|
||||||
|
|
||||||
|
#### B9: config_load() goto 기반 흐름
|
||||||
|
|
||||||
|
파일: fstorage.c:157-261
|
||||||
|
|
||||||
|
현재 상태: **미완료**
|
||||||
|
|
||||||
|
`goto cfg_load_start` 패턴이 여전히 존재. 3개의 goto 문과 2개의 레이블로 복잡한 흐름 유지 중. FDS 초기화 실패 시 무한 루프 가능성 여전.
|
||||||
|
|
||||||
|
### 5.3 심각도 낮음 (LOW)
|
||||||
|
|
||||||
|
#### B11: debuf_print.h 파일명 오타
|
||||||
|
|
||||||
|
현재 상태: **완료** (파일 삭제)
|
||||||
|
|
||||||
|
#### B12: 함수 중복 선언
|
||||||
|
|
||||||
|
파일: main.h:44-54
|
||||||
|
|
||||||
|
현재 상태: **미완료**
|
||||||
|
|
||||||
|
static 함수 프로토타입 6개가 헤더에 여전히 선언됨:
|
||||||
|
- advertising_start (FEATURE_SECURE_CONNECTION 내)
|
||||||
|
- t_power_off_timeout_handler
|
||||||
|
- power_control_handler
|
||||||
|
- main_s
|
||||||
|
- PM_s
|
||||||
|
- main_routine_handler
|
||||||
|
|
||||||
|
#### B13: LED_ALLOFF, PD_ALLOFF 매크로 정의 위치
|
||||||
|
|
||||||
|
현재 상태: 확인 필요
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 저전력 최적화
|
||||||
|
|
||||||
|
### 6.1 현재 전력 구조 분석
|
||||||
|
|
||||||
|
변경 없음. CODE_REVIEW.pdf 6.1절과 동일.
|
||||||
|
|
||||||
|
### 6.2 개선 항목
|
||||||
|
|
||||||
|
#### P1: UART 비활성화 (가장 큰 절약 -- 예상 ~1mA 절감)
|
||||||
|
|
||||||
|
파일: main.c:1427
|
||||||
|
|
||||||
|
현재 상태: **미완료**
|
||||||
|
|
||||||
|
`uart_init()`이 무조건 호출됨. `#if BLE_DEV_MODE` 조건으로 감싸져 있지 않음.
|
||||||
|
|
||||||
|
수정 필요:
|
||||||
|
```c
|
||||||
|
#if BLE_DEV_MODE
|
||||||
|
uart_init();
|
||||||
|
#endif
|
||||||
|
```
|
||||||
|
|
||||||
|
#### P2: SEGGER RTT 비활성화 (프로덕션)
|
||||||
|
|
||||||
|
파일: debug_print.h
|
||||||
|
|
||||||
|
현재 상태: **미완료**
|
||||||
|
|
||||||
|
`ENABLE_PRINTF`가 `1`로 하드코딩되어 있음. `BLE_DEV_MODE`와 연동되지 않음.
|
||||||
|
|
||||||
|
수정 필요:
|
||||||
|
```c
|
||||||
|
#if BLE_DEV_MODE
|
||||||
|
#define ENABLE_PRINTF 1
|
||||||
|
#else
|
||||||
|
#define ENABLE_PRINTF 0
|
||||||
|
#endif
|
||||||
|
```
|
||||||
|
|
||||||
|
#### P3: 배터리 타이머 주기 최적화
|
||||||
|
|
||||||
|
파일: battery_saadc.c:48
|
||||||
|
|
||||||
|
현재 상태: **미완료**
|
||||||
|
|
||||||
|
`BATTERY_LOOP_INTERVAL = 5000ms` 고정. 동적 조절 로직 없음.
|
||||||
|
|
||||||
|
#### P4: IMU 타이머 조건부 시작
|
||||||
|
|
||||||
|
파일: main.c BLE 이벤트 핸들러
|
||||||
|
|
||||||
|
현재 상태: **미완료**
|
||||||
|
|
||||||
|
BLE_GAP_EVT_CONNECTED/DISCONNECTED 핸들러에 IMU 타이머 start/stop 로직 없음. BLE 미연결 시에도 IMU를 읽을 수 있는 상태.
|
||||||
|
|
||||||
|
#### P5: main_loop() 타이머 폴링 효율화
|
||||||
|
|
||||||
|
현재 상태: **미완료**
|
||||||
|
|
||||||
|
플래그 기반 폴링 패턴 그대로 유지 중.
|
||||||
|
|
||||||
|
#### P6: NRF_LOG 비활성화 고려
|
||||||
|
|
||||||
|
현재 상태: **미완료** (확인 필요)
|
||||||
|
|
||||||
|
### 6.3 예상 절감 효과
|
||||||
|
|
||||||
|
| 최적화 | 예상 절감 | 난이도 | 현재 상태 |
|
||||||
|
|--------|----------|--------|----------|
|
||||||
|
| P1: UART 비활성화 | ~1mA | 쉬움 | **미완료** |
|
||||||
|
| P2: RTT 비활성화 | ~0.1-0.5mA | 쉬움 | **미완료** |
|
||||||
|
| P4: IMU 타이머 조건부 시작 | ~41uA (미연결 시) | 쉬움 | **미완료** |
|
||||||
|
| P3: 배터리 타이머 동적 | ~5uA | 보통 | **미완료** |
|
||||||
|
| P5-A: 단발->직접호출 | 응답 개선 | 쉬움 | **미완료** |
|
||||||
|
| P5-B: app_scheduler | 코드 품질 + 확장성 | 보통 | **미완료** |
|
||||||
|
| P5-C: IMU FIFO+인터럽트 | 연속측정 시 ~50uA | 어려움 | **미완료** |
|
||||||
|
| P6: NRF_LOG 비활성화 | ~10uA | 쉬움 | **미완료** |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 코드 품질 개선
|
||||||
|
|
||||||
|
### 7.1 구조 개선
|
||||||
|
|
||||||
|
| # | 항목 | 현재 상태 |
|
||||||
|
|---|------|----------|
|
||||||
|
| Q1 | main.h에서 static 함수 선언 제거 | **미완료** (6개 잔존) |
|
||||||
|
| Q2 | cat_interface.c -> i2c_manager.c로 TWI 통합 | **완료** |
|
||||||
|
| Q3 | extern 변수 과다 사용 | **미완료** (30개 이상) |
|
||||||
|
| Q4 | main_timer.c main_loop() 플래그 기반 폴링 | **미완료** |
|
||||||
|
| Q5 | 매직 넘버 제거 | **미완료** |
|
||||||
|
|
||||||
|
### 7.2 코딩 스타일
|
||||||
|
|
||||||
|
변경 없음. CODE_REVIEW.pdf 7.2절과 동일.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 작업 우선순위 요약
|
||||||
|
|
||||||
|
### 즉시 수정 (안전/안정성)
|
||||||
|
|
||||||
|
| # | 항목 | 심각도 | 현재 상태 |
|
||||||
|
|---|------|--------|----------|
|
||||||
|
| 1 | B4: memset/memcpy 버퍼 크기 불일치 및 매직 넘버 | CRITICAL | **완료** |
|
||||||
|
| 2 | B1: BLE TX 큐 풀 시 시스템 먹통 (binary_tx_handler → dr_binary_tx_safe 교체) | HIGH | **완료** |
|
||||||
|
| 3 | B2: BLE TX 에러 핸들링 로직 반전 | HIGH | **완료** |
|
||||||
|
| 4 | B3: extern + 초기화 동시 사용 | HIGH | **완료** |
|
||||||
|
|
||||||
|
### 1차 정리 (미사용 코드/EEPROM 삭제)
|
||||||
|
|
||||||
|
| # | 항목 | 현재 상태 |
|
||||||
|
|---|------|----------|
|
||||||
|
| 5 | 미사용 HW 드라이버 삭제 (1.2절) | **완료** |
|
||||||
|
| 6 | cat_interface.c EEPROM 기능 삭제 + TWI를 i2c_manager.c로 통합 (1.5절) | **완료** |
|
||||||
|
| 7 | cmd_parse.c EEPROM 호출 -> FDS 전환 (1.5.4절) | **완료** |
|
||||||
|
| 8 | 미사용 전역변수 + HW_NO 삭제 (2.2-2.3절) | **미완료** |
|
||||||
|
| 9 | DEBUG_MINIMAL_BOOT 조건 제거 (3절) | **미완료** |
|
||||||
|
| 10 | Keil uvprojx 소스 참조 제거 (4절) | 확인 필요 |
|
||||||
|
| 11 | 주석 처리된 코드 삭제 (2.4절) | **미완료** |
|
||||||
|
|
||||||
|
### 2차 정리 (저전력 최적화)
|
||||||
|
|
||||||
|
| # | 항목 | 예상 절감 | 현재 상태 |
|
||||||
|
|---|------|----------|----------|
|
||||||
|
| 12 | P1: UART 비활성화 | ~1mA | **미완료** |
|
||||||
|
| 13 | P2: RTT 비활성화 | ~0.1-0.5mA | **미완료** |
|
||||||
|
| 14 | P4: IMU 타이머 BLE 연결 시에만 동작 | ~41uA | **미완료** |
|
||||||
|
| 15 | P5-A: main_loop 단발 이벤트 직접 호출로 전환 | 응답 개선 | **미완료** |
|
||||||
|
| 16 | P5-B: app_scheduler 도입 (선택) | 코드 품질 | **미완료** |
|
||||||
|
| 17 | P3: 배터리 타이머 동적 조절 | ~5uA | **미완료** |
|
||||||
|
|
||||||
|
### 3차 정리 (코드 품질)
|
||||||
|
|
||||||
|
| # | 항목 | 현재 상태 |
|
||||||
|
|---|------|----------|
|
||||||
|
| 18 | Q1: main.h static 함수 제거 | **미완료** |
|
||||||
|
| 19 | Q5: 매직 넘버 define화 | **미완료** |
|
||||||
|
| 20 | B9: config_load() goto 제거 | **미완료** |
|
||||||
BIN
data/CODE_REVIEW_STATUS.pdf
Normal file
BIN
data/CODE_REVIEW_STATUS.pdf
Normal file
Binary file not shown.
3521
data/curcuit/20305 VB0HW0100 (1).asc
Normal file
3521
data/curcuit/20305 VB0HW0100 (1).asc
Normal file
File diff suppressed because it is too large
Load Diff
BIN
data/curcuit/20305 VB0HW0100.sch
Normal file
BIN
data/curcuit/20305 VB0HW0100.sch
Normal file
Binary file not shown.
BIN
data/curcuit/VesiScan-Basic_curcuit.pdf
Normal file
BIN
data/curcuit/VesiScan-Basic_curcuit.pdf
Normal file
Binary file not shown.
BIN
data/datasheet/W25Q32RV.pdf
Normal file
BIN
data/datasheet/W25Q32RV.pdf
Normal file
Binary file not shown.
@@ -710,7 +710,6 @@ void dr_adc_print_buffer(const uint16_t *buffer, uint16_t num_samples)
|
|||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
|
|
||||||
/* External BLE NUS functions and variables from main.c */
|
/* External BLE NUS functions and variables from main.c */
|
||||||
extern void binary_tx_handler(uint8_t const *ble_bin_buff, uint16_t length);
|
|
||||||
extern void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
extern void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
||||||
extern void dr_sd_delay_ms(uint32_t ms);
|
extern void dr_sd_delay_ms(uint32_t ms);
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,7 @@
|
|||||||
|
|
||||||
extern void single_format_data(uint8_t *buffer, const char *tag, uint16_t value);
|
extern void single_format_data(uint8_t *buffer, const char *tag, uint16_t value);
|
||||||
extern void format_data(uint8_t *buffer, const char *tag, uint16_t *data, uint8_t length);
|
extern void format_data(uint8_t *buffer, const char *tag, uint16_t *data, uint8_t length);
|
||||||
extern void binary_tx_handler(uint8_t *buffer, uint8_t length);
|
|
||||||
extern uint8_t ble_bin_buffer[];
|
extern uint8_t ble_bin_buffer[];
|
||||||
|
|
||||||
/* Use dr_binary_tx_safe from main.c - has retry logic for BLE TX queue */
|
|
||||||
extern void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
extern void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
||||||
|
|
||||||
void dr_ble_return_1(const char *tag, uint16_t value)
|
void dr_ble_return_1(const char *tag, uint16_t value)
|
||||||
|
|||||||
533
pc_firm/dr_w25q32/dr_w25q32.c
Normal file
533
pc_firm/dr_w25q32/dr_w25q32.c
Normal file
@@ -0,0 +1,533 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* @file dr_w25q32.c
|
||||||
|
* @brief W25Q32 SPI Flash Driver for nRF52840
|
||||||
|
* Software SPI (bit-bang) implementation
|
||||||
|
* @date 2026-03-12
|
||||||
|
*
|
||||||
|
* @details Bit-bang SPI driver for W25Q32 NOR Flash.
|
||||||
|
* SPI Mode 0 (CPOL=0, CPHA=0):
|
||||||
|
* - SCLK idle LOW
|
||||||
|
* - Data sampled on rising edge
|
||||||
|
* - Data shifted out on falling edge
|
||||||
|
*
|
||||||
|
* W25Q32 SPI timing:
|
||||||
|
* CS ──┐ ┌──
|
||||||
|
* └────────────────────────────────────┘
|
||||||
|
* CLK ┌──┐ ┌──┐ ┌──┐ ┌──┐ ┌──┐
|
||||||
|
* ─────┘ └──┘ └──┘ └── ... ┘ └──┘ └────
|
||||||
|
* DI <CMD7><CMD6><CMD5>...<D1 ><D0 >
|
||||||
|
* DO <Z ><Z ><Z >...<D1 ><D0 >
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "dr_w25q32.h"
|
||||||
|
#include "nrf_gpio.h"
|
||||||
|
#include "nrf_delay.h"
|
||||||
|
#include "debug_print.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PRIVATE DEFINES
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
#define DR_PIN_NUM(pin) ((pin) & 0x1F)
|
||||||
|
#define DR_PIN_PORT(pin) (((pin) >> 5) & 0x01)
|
||||||
|
|
||||||
|
/* Pin masks for direct register access */
|
||||||
|
#define FLASH_CS_MASK (1UL << DR_PIN_NUM(DR_FLASH_PIN_CS))
|
||||||
|
#define FLASH_SCLK_MASK (1UL << DR_PIN_NUM(DR_FLASH_PIN_SCLK))
|
||||||
|
#define FLASH_MISO_MASK (1UL << DR_PIN_NUM(DR_FLASH_PIN_MISO))
|
||||||
|
#define FLASH_MOSI_MASK (1UL << DR_PIN_NUM(DR_FLASH_PIN_MOSI))
|
||||||
|
|
||||||
|
/* Port registers - all pins on P0 */
|
||||||
|
#define FLASH_PORT NRF_P0 // NRF_P0: 포트 레지스터에 접근하는 베이스 포인터(포트 전체 제어 X)
|
||||||
|
|
||||||
|
/* Timeout for busy wait (ms) */
|
||||||
|
#define BUSY_TIMEOUT_PAGE_PROGRAM 10
|
||||||
|
#define BUSY_TIMEOUT_SECTOR_ERASE 500
|
||||||
|
#define BUSY_TIMEOUT_BLOCK_ERASE 2000
|
||||||
|
#define BUSY_TIMEOUT_CHIP_ERASE 60000
|
||||||
|
|
||||||
|
/* W25Q32 JEDEC ID expected values */
|
||||||
|
#define W25Q32_MANUFACTURER_ID 0xEF
|
||||||
|
#define W25Q32_MEMORY_TYPE 0x40
|
||||||
|
#define W25Q32_CAPACITY 0x16
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PRIVATE VARIABLES
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
static bool m_initialized = false;
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* LOW-LEVEL SPI BIT-BANG
|
||||||
|
*
|
||||||
|
* W25Q32 uses SPI Mode 0:
|
||||||
|
* - CPOL=0: Clock idle LOW
|
||||||
|
* - CPHA=0: Data sampled on rising edge, shifted on falling edge
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
static inline void flash_cs_low(void)
|
||||||
|
{
|
||||||
|
FLASH_PORT->OUTCLR = FLASH_CS_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void flash_cs_high(void)
|
||||||
|
{
|
||||||
|
FLASH_PORT->OUTSET = FLASH_CS_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void flash_sclk_low(void)
|
||||||
|
{
|
||||||
|
FLASH_PORT->OUTCLR = FLASH_SCLK_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void flash_sclk_high(void)
|
||||||
|
{
|
||||||
|
FLASH_PORT->OUTSET = FLASH_SCLK_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void flash_mosi_high(void)
|
||||||
|
{
|
||||||
|
FLASH_PORT->OUTSET = FLASH_MOSI_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void flash_mosi_low(void)
|
||||||
|
{
|
||||||
|
FLASH_PORT->OUTCLR = FLASH_MOSI_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t flash_read_miso(void)
|
||||||
|
{
|
||||||
|
return (FLASH_PORT->IN & FLASH_MISO_MASK) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Send one byte via SPI (MSB first)
|
||||||
|
*/
|
||||||
|
static void spi_send_byte(uint8_t byte)
|
||||||
|
{
|
||||||
|
for (int i = 7; i >= 0; i--)
|
||||||
|
{
|
||||||
|
/* Set MOSI */
|
||||||
|
if (byte & (1 << i))
|
||||||
|
flash_mosi_high();
|
||||||
|
else
|
||||||
|
flash_mosi_low();
|
||||||
|
|
||||||
|
/* Rising edge - data sampled by slave */
|
||||||
|
flash_sclk_high();
|
||||||
|
__NOP();
|
||||||
|
__NOP();
|
||||||
|
|
||||||
|
/* Falling edge */
|
||||||
|
flash_sclk_low();
|
||||||
|
__NOP();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Receive one byte via SPI (MSB first)
|
||||||
|
* @note Sends 0xFF (MOSI high) while reading
|
||||||
|
*/
|
||||||
|
static uint8_t spi_recv_byte(void)
|
||||||
|
{
|
||||||
|
uint8_t byte = 0;
|
||||||
|
|
||||||
|
flash_mosi_high(); /* Keep MOSI high during read */
|
||||||
|
|
||||||
|
for (int i = 7; i >= 0; i--)
|
||||||
|
{
|
||||||
|
/* Rising edge - sample MISO */
|
||||||
|
flash_sclk_high();
|
||||||
|
__NOP();
|
||||||
|
__NOP();
|
||||||
|
|
||||||
|
if (flash_read_miso())
|
||||||
|
byte |= (1 << i);
|
||||||
|
|
||||||
|
/* Falling edge */
|
||||||
|
flash_sclk_low();
|
||||||
|
__NOP();
|
||||||
|
}
|
||||||
|
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize GPIO pins
|
||||||
|
*/
|
||||||
|
static void flash_gpio_init(void)
|
||||||
|
{
|
||||||
|
/* CS: Output, HIGH (deselected) */
|
||||||
|
nrf_gpio_cfg_output(DR_FLASH_PIN_CS);
|
||||||
|
nrf_gpio_pin_set(DR_FLASH_PIN_CS);
|
||||||
|
|
||||||
|
/* SCLK: Output, LOW (idle for Mode 0) */
|
||||||
|
nrf_gpio_cfg_output(DR_FLASH_PIN_SCLK);
|
||||||
|
nrf_gpio_pin_clear(DR_FLASH_PIN_SCLK);
|
||||||
|
|
||||||
|
/* MOSI: Output, HIGH */
|
||||||
|
nrf_gpio_cfg_output(DR_FLASH_PIN_MOSI);
|
||||||
|
nrf_gpio_pin_set(DR_FLASH_PIN_MOSI);
|
||||||
|
|
||||||
|
/* MISO: Input, no pull */
|
||||||
|
nrf_gpio_cfg_input(DR_FLASH_PIN_MISO, NRF_GPIO_PIN_NOPULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Send Write Enable command (0x06)
|
||||||
|
*/
|
||||||
|
static void flash_write_enable(void)
|
||||||
|
{
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_WRITE_ENABLE);
|
||||||
|
flash_cs_high();
|
||||||
|
__NOP(); __NOP(); __NOP(); __NOP();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PUBLIC FUNCTIONS - INITIALIZATION
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_init(void)
|
||||||
|
{
|
||||||
|
DBG_PRINTF("[FLASH] Init\n");
|
||||||
|
flash_gpio_init();
|
||||||
|
m_initialized = true;
|
||||||
|
DBG_PRINTF("[FLASH] Init OK\n");
|
||||||
|
return DR_FLASH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dr_w25q32_uninit(void)
|
||||||
|
{
|
||||||
|
if (!m_initialized) return;
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Uninit\n");
|
||||||
|
|
||||||
|
/* CS high (deselect) */
|
||||||
|
nrf_gpio_pin_set(DR_FLASH_PIN_CS);
|
||||||
|
|
||||||
|
/* Release pins to default */
|
||||||
|
nrf_gpio_cfg_default(DR_FLASH_PIN_CS);
|
||||||
|
|
||||||
|
/* Don't release shared pins (SCLK, MISO, MOSI) -
|
||||||
|
they may be in use by ADC121S051 */
|
||||||
|
|
||||||
|
m_initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dr_w25q32_is_initialized(void)
|
||||||
|
{
|
||||||
|
return m_initialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PUBLIC FUNCTIONS - IDENTIFICATION
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_read_jedec_id(dr_flash_jedec_t *jedec) //JEDEC ID 읽기 (0xEF, 0x40, 0x16)
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
if (!jedec) return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_READ_JEDEC_ID);
|
||||||
|
jedec->manufacturer_id = spi_recv_byte();
|
||||||
|
jedec->memory_type = spi_recv_byte();
|
||||||
|
jedec->capacity = spi_recv_byte();
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] JEDEC ID: 0x%02X 0x%02X 0x%02X\n",
|
||||||
|
jedec->manufacturer_id, jedec->memory_type, jedec->capacity);
|
||||||
|
|
||||||
|
return DR_FLASH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_read_uid(uint8_t *uid) // 8바이트 고유 ID 읽기
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
if (!uid) return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_READ_UID);
|
||||||
|
|
||||||
|
/* 4 dummy bytes */
|
||||||
|
spi_send_byte(0x00);
|
||||||
|
spi_send_byte(0x00);
|
||||||
|
spi_send_byte(0x00);
|
||||||
|
spi_send_byte(0x00);
|
||||||
|
|
||||||
|
/* 8-byte unique ID */
|
||||||
|
for (int i = 0; i < DR_FLASH_UID_LENGTH; i++)
|
||||||
|
{
|
||||||
|
uid[i] = spi_recv_byte();
|
||||||
|
}
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] UID: %02X%02X%02X%02X%02X%02X%02X%02X\n",
|
||||||
|
uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[6], uid[7]);
|
||||||
|
|
||||||
|
return DR_FLASH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PUBLIC FUNCTIONS - STATUS
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_read_status(uint8_t *status)
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
if (!status) return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_READ_STATUS1);
|
||||||
|
*status = spi_recv_byte();
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
return DR_FLASH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dr_w25q32_is_busy(void)
|
||||||
|
{
|
||||||
|
uint8_t status = 0;
|
||||||
|
dr_w25q32_read_status(&status);
|
||||||
|
return (status & DR_FLASH_SR1_BUSY) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_wait_busy(uint32_t timeout_ms)
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
|
||||||
|
while (timeout_ms > 0)
|
||||||
|
{
|
||||||
|
if (!dr_w25q32_is_busy())
|
||||||
|
return DR_FLASH_OK;
|
||||||
|
|
||||||
|
nrf_delay_ms(1);
|
||||||
|
timeout_ms--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DR_FLASH_ERR_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PUBLIC FUNCTIONS - READ
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_read(uint32_t addr, uint8_t *buf, uint32_t len) // 데이터 읽기 (주소, 길이)
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
if (!buf || len == 0) return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
if (addr + len > DR_FLASH_TOTAL_SIZE) return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Read addr=0x%06X len=%d\n", addr, len);
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
|
||||||
|
/* Command + 24-bit address */
|
||||||
|
spi_send_byte(DR_FLASH_CMD_READ_DATA);
|
||||||
|
spi_send_byte((addr >> 16) & 0xFF);
|
||||||
|
spi_send_byte((addr >> 8) & 0xFF);
|
||||||
|
spi_send_byte((addr ) & 0xFF);
|
||||||
|
|
||||||
|
/* Read data */
|
||||||
|
for (uint32_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
buf[i] = spi_recv_byte();
|
||||||
|
}
|
||||||
|
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
return DR_FLASH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PUBLIC FUNCTIONS - WRITE
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_write(uint32_t addr, const uint8_t *data, uint32_t len) // 페이지 쓰기 (최대 256B)
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
if (!data || len == 0 || len > DR_FLASH_PAGE_SIZE)
|
||||||
|
return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
if (addr + len > DR_FLASH_TOTAL_SIZE)
|
||||||
|
return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
|
||||||
|
/* Check page boundary crossing */
|
||||||
|
uint32_t page_offset = addr % DR_FLASH_PAGE_SIZE;
|
||||||
|
if (page_offset + len > DR_FLASH_PAGE_SIZE)
|
||||||
|
return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Write addr=0x%06X len=%d\n", addr, len);
|
||||||
|
|
||||||
|
/* Write Enable */
|
||||||
|
flash_write_enable();
|
||||||
|
|
||||||
|
/* Page Program */
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_PAGE_PROGRAM);
|
||||||
|
spi_send_byte((addr >> 16) & 0xFF);
|
||||||
|
spi_send_byte((addr >> 8) & 0xFF);
|
||||||
|
spi_send_byte((addr ) & 0xFF);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
spi_send_byte(data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
/* Wait for programming to complete */
|
||||||
|
dr_flash_err_t err = dr_w25q32_wait_busy(BUSY_TIMEOUT_PAGE_PROGRAM);
|
||||||
|
if (err != DR_FLASH_OK)
|
||||||
|
DBG_PRINTF("[FLASH] Write TIMEOUT!\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PUBLIC FUNCTIONS - ERASE
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_erase_sector(uint32_t addr) // 4KB 섹터 삭제
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
if (addr >= DR_FLASH_TOTAL_SIZE) return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Erase sector addr=0x%06X\n", addr);
|
||||||
|
|
||||||
|
flash_write_enable();
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_SECTOR_ERASE);
|
||||||
|
spi_send_byte((addr >> 16) & 0xFF);
|
||||||
|
spi_send_byte((addr >> 8) & 0xFF);
|
||||||
|
spi_send_byte((addr ) & 0xFF);
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
dr_flash_err_t err = dr_w25q32_wait_busy(BUSY_TIMEOUT_SECTOR_ERASE);
|
||||||
|
if (err != DR_FLASH_OK)
|
||||||
|
DBG_PRINTF("[FLASH] Erase sector TIMEOUT!\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_erase_block_32k(uint32_t addr) // 블록 삭제
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
if (addr >= DR_FLASH_TOTAL_SIZE) return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Erase block 32K addr=0x%06X\n", addr);
|
||||||
|
|
||||||
|
flash_write_enable();
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_BLOCK_ERASE_32K);
|
||||||
|
spi_send_byte((addr >> 16) & 0xFF);
|
||||||
|
spi_send_byte((addr >> 8) & 0xFF);
|
||||||
|
spi_send_byte((addr ) & 0xFF);
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
dr_flash_err_t err = dr_w25q32_wait_busy(BUSY_TIMEOUT_BLOCK_ERASE);
|
||||||
|
if (err != DR_FLASH_OK)
|
||||||
|
DBG_PRINTF("[FLASH] Erase block 32K TIMEOUT!\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_erase_block_64k(uint32_t addr) // 블록 삭제
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
if (addr >= DR_FLASH_TOTAL_SIZE) return DR_FLASH_ERR_INVALID_PARAM;
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Erase block 64K addr=0x%06X\n", addr);
|
||||||
|
|
||||||
|
flash_write_enable();
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_BLOCK_ERASE_64K);
|
||||||
|
spi_send_byte((addr >> 16) & 0xFF);
|
||||||
|
spi_send_byte((addr >> 8) & 0xFF);
|
||||||
|
spi_send_byte((addr ) & 0xFF);
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
dr_flash_err_t err = dr_w25q32_wait_busy(BUSY_TIMEOUT_BLOCK_ERASE);
|
||||||
|
if (err != DR_FLASH_OK)
|
||||||
|
DBG_PRINTF("[FLASH] Erase block 64K TIMEOUT!\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_chip_erase(void) // 전체 삭제
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Chip erase...\n");
|
||||||
|
|
||||||
|
flash_write_enable();
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_CHIP_ERASE);
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
dr_flash_err_t err = dr_w25q32_wait_busy(BUSY_TIMEOUT_CHIP_ERASE);
|
||||||
|
if (err == DR_FLASH_OK)
|
||||||
|
DBG_PRINTF("[FLASH] Chip erase OK\n");
|
||||||
|
else
|
||||||
|
DBG_PRINTF("[FLASH] Chip erase TIMEOUT!\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PUBLIC FUNCTIONS - POWER MANAGEMENT
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_deep_powerdown(void) // 저전력 모드 (~1uA)
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Deep power-down\n");
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_POWER_DOWN);
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
/* tDP: CS high to deep power-down = 3us max */
|
||||||
|
nrf_delay_us(5);
|
||||||
|
|
||||||
|
return DR_FLASH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
dr_flash_err_t dr_w25q32_wakeup(void) // 저전력 모드 해제(깨우기)
|
||||||
|
{
|
||||||
|
if (!m_initialized) return DR_FLASH_ERR_NOT_INIT;
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Wakeup\n");
|
||||||
|
|
||||||
|
flash_cs_low();
|
||||||
|
spi_send_byte(DR_FLASH_CMD_RELEASE_PD);
|
||||||
|
flash_cs_high();
|
||||||
|
|
||||||
|
/* tRES1: CS high to standby = 3us max */
|
||||||
|
nrf_delay_us(5);
|
||||||
|
|
||||||
|
return DR_FLASH_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PUBLIC FUNCTIONS - DEBUG / TEST
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
bool dr_w25q32_test(void) // JEDEC ID로 통신 테스트
|
||||||
|
{
|
||||||
|
dr_flash_jedec_t jedec;
|
||||||
|
|
||||||
|
if (dr_w25q32_read_jedec_id(&jedec) != DR_FLASH_OK)
|
||||||
|
{
|
||||||
|
DBG_PRINTF("[FLASH] Test FAIL - read error\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pass = (jedec.manufacturer_id == W25Q32_MANUFACTURER_ID &&
|
||||||
|
jedec.memory_type == W25Q32_MEMORY_TYPE &&
|
||||||
|
jedec.capacity == W25Q32_CAPACITY);
|
||||||
|
|
||||||
|
DBG_PRINTF("[FLASH] Test %s\n", pass ? "PASS" : "FAIL");
|
||||||
|
return pass;
|
||||||
|
}
|
||||||
245
pc_firm/dr_w25q32/dr_w25q32.h
Normal file
245
pc_firm/dr_w25q32/dr_w25q32.h
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* @file dr_w25q32.h
|
||||||
|
* @brief W25Q32 SPI Flash Driver for nRF52840
|
||||||
|
* 32Mbit (4MB) Serial NOR Flash Memory
|
||||||
|
* @date 2026-03-12
|
||||||
|
*
|
||||||
|
* @details Software SPI (bit-bang) driver for W25Q32RVXHJQ.
|
||||||
|
* Shares SPI bus (SCK/MISO/MOSI) with ADC121S051.
|
||||||
|
* Only CS pin is unique (P0.24).
|
||||||
|
*
|
||||||
|
* Pin connections:
|
||||||
|
* nRF52840 W25Q32 (U16)
|
||||||
|
* P0.24 -----> /CS (pin 1)
|
||||||
|
* P0.15 <----- DO (pin 2, MISO)
|
||||||
|
* P0.16 -----> DI (pin 5, MOSI)
|
||||||
|
* P0.14 -----> CLK (pin 6)
|
||||||
|
*
|
||||||
|
* @note WP (pin 3) and HOLD (pin 7) are pulled HIGH via 10k resistors.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef DR_W25Q32_H
|
||||||
|
#define DR_W25Q32_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "nrf_gpio.h"
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* PIN CONFIGURATION
|
||||||
|
*============================================================================*/
|
||||||
|
#define DR_FLASH_PIN_CS NRF_GPIO_PIN_MAP(0, 24) /* Chip Select - SPI_CS_FLASH(P0.24) */
|
||||||
|
#define DR_FLASH_PIN_SCLK NRF_GPIO_PIN_MAP(0, 14) /* Serial Clock(shared) - SPI_SCK(P0.14) */
|
||||||
|
#define DR_FLASH_PIN_MISO NRF_GPIO_PIN_MAP(0, 15) /* DI_(IO0)(shared) - SPI_MOSI(P0.15) */
|
||||||
|
#define DR_FLASH_PIN_MOSI NRF_GPIO_PIN_MAP(0, 16) /* DO_(IO1)(shared) - SPI_MISO(P0.16) */
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* W25Q32 SPECIFICATIONS
|
||||||
|
*============================================================================*/
|
||||||
|
#define DR_FLASH_PAGE_SIZE 256 /**< Page size (bytes) */
|
||||||
|
#define DR_FLASH_SECTOR_SIZE 4096 /**< Sector size (bytes, 4KB) */
|
||||||
|
#define DR_FLASH_BLOCK_32K (32*1024) /**< 32KB block */
|
||||||
|
#define DR_FLASH_BLOCK_64K (64*1024) /**< 64KB block */
|
||||||
|
#define DR_FLASH_TOTAL_SIZE (4*1024*1024) /**< 4MB total */
|
||||||
|
#define DR_FLASH_UID_LENGTH 8 /**< Unique ID length (bytes) */
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* W25Q32 COMMAND OPCODES
|
||||||
|
*============================================================================*/
|
||||||
|
#define DR_FLASH_CMD_WRITE_ENABLE 0x06
|
||||||
|
#define DR_FLASH_CMD_WRITE_DISABLE 0x04
|
||||||
|
#define DR_FLASH_CMD_READ_STATUS1 0x05
|
||||||
|
#define DR_FLASH_CMD_READ_STATUS2 0x35
|
||||||
|
#define DR_FLASH_CMD_WRITE_STATUS 0x01
|
||||||
|
#define DR_FLASH_CMD_READ_DATA 0x03
|
||||||
|
#define DR_FLASH_CMD_PAGE_PROGRAM 0x02
|
||||||
|
#define DR_FLASH_CMD_SECTOR_ERASE 0x20 /**< 4KB erase */
|
||||||
|
#define DR_FLASH_CMD_BLOCK_ERASE_32K 0x52 /**< 32KB erase */
|
||||||
|
#define DR_FLASH_CMD_BLOCK_ERASE_64K 0xD8 /**< 64KB erase */
|
||||||
|
#define DR_FLASH_CMD_CHIP_ERASE 0xC7 /**< Full chip erase */
|
||||||
|
#define DR_FLASH_CMD_POWER_DOWN 0xB9 /**< Deep power-down */
|
||||||
|
#define DR_FLASH_CMD_RELEASE_PD 0xAB /**< Release from deep power-down */
|
||||||
|
#define DR_FLASH_CMD_READ_UID 0x4B /**< Read unique ID */
|
||||||
|
#define DR_FLASH_CMD_READ_JEDEC_ID 0x9F /**< Read JEDEC ID */
|
||||||
|
#define DR_FLASH_CMD_READ_MFR_ID 0x90 /**< Read manufacturer/device ID */
|
||||||
|
|
||||||
|
/* Status Register 1 bits */
|
||||||
|
#define DR_FLASH_SR1_BUSY 0x01 /**< Erase/Write in progress */
|
||||||
|
#define DR_FLASH_SR1_WEL 0x02 /**< Write enable latch */
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* ERROR CODES
|
||||||
|
*============================================================================*/
|
||||||
|
typedef enum {
|
||||||
|
DR_FLASH_OK = 0,
|
||||||
|
DR_FLASH_ERR_NOT_INIT,
|
||||||
|
DR_FLASH_ERR_INVALID_PARAM,
|
||||||
|
DR_FLASH_ERR_TIMEOUT,
|
||||||
|
DR_FLASH_ERR_WRITE_FAILED,
|
||||||
|
DR_FLASH_ERR_JEDEC_MISMATCH
|
||||||
|
} dr_flash_err_t;
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* DATA STRUCTURES
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
/** @brief JEDEC ID structure */
|
||||||
|
typedef struct {
|
||||||
|
uint8_t manufacturer_id; /**< 0xEF = Winbond */
|
||||||
|
uint8_t memory_type; /**< 0x40 = SPI */
|
||||||
|
uint8_t capacity; /**< 0x16 = 32Mbit */
|
||||||
|
} dr_flash_jedec_t;
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* INITIALIZATION
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize W25Q32 Flash driver
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
* @note Sets up GPIO pins. Does NOT wake chip from deep power-down.
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_init(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Uninitialize driver, release GPIO pins
|
||||||
|
*/
|
||||||
|
void dr_w25q32_uninit(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if driver is initialized
|
||||||
|
*/
|
||||||
|
bool dr_w25q32_is_initialized(void);
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* IDENTIFICATION
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read JEDEC ID (manufacturer, type, capacity)
|
||||||
|
* @param jedec Pointer to JEDEC ID structure
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
* @note Expected: manufacturer=0xEF, type=0x40, capacity=0x16
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_read_jedec_id(dr_flash_jedec_t *jedec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read 8-byte unique ID
|
||||||
|
* @param uid Buffer to store 8-byte UID (must be >= 8 bytes)
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_read_uid(uint8_t *uid);
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* READ
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read data from flash
|
||||||
|
* @param addr 24-bit start address (0x000000 ~ 0x3FFFFF)
|
||||||
|
* @param buf Buffer to store read data
|
||||||
|
* @param len Number of bytes to read
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_read(uint32_t addr, uint8_t *buf, uint32_t len);
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* WRITE
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Write data to flash (page program, max 256 bytes)
|
||||||
|
* @param addr 24-bit start address (must be page-aligned for best results)
|
||||||
|
* @param data Data to write
|
||||||
|
* @param len Number of bytes (1~256, must not cross page boundary)
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
* @note Automatically sends Write Enable before programming.
|
||||||
|
* Waits for completion (BUSY flag).
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_write(uint32_t addr, const uint8_t *data, uint32_t len);
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* ERASE
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Erase 4KB sector
|
||||||
|
* @param addr Any address within the sector to erase
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
* @note Typical 45ms, max 400ms. Waits for completion.
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_erase_sector(uint32_t addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Erase 32KB block
|
||||||
|
* @param addr Any address within the block
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_erase_block_32k(uint32_t addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Erase 64KB block
|
||||||
|
* @param addr Any address within the block
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_erase_block_64k(uint32_t addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Erase entire chip
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
* @note Takes 6~50 seconds. Use with caution.
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_chip_erase(void);
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* POWER MANAGEMENT
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enter deep power-down mode (~1uA)
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_deep_powerdown(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Release from deep power-down
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
* @note Requires ~3us recovery time (handled internally)
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_wakeup(void);
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* STATUS
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read Status Register 1
|
||||||
|
* @param status Pointer to store status byte
|
||||||
|
* @return dr_flash_err_t Error code
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_read_status(uint8_t *status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if flash is busy (erase/write in progress)
|
||||||
|
* @return true if busy
|
||||||
|
*/
|
||||||
|
bool dr_w25q32_is_busy(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Wait until flash is not busy
|
||||||
|
* @param timeout_ms Maximum wait time in milliseconds
|
||||||
|
* @return dr_flash_err_t DR_FLASH_OK or DR_FLASH_ERR_TIMEOUT
|
||||||
|
*/
|
||||||
|
dr_flash_err_t dr_w25q32_wait_busy(uint32_t timeout_ms);
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* DEBUG / TEST
|
||||||
|
*============================================================================*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Test flash communication by reading JEDEC ID
|
||||||
|
* @return true if JEDEC ID matches W25Q32 (0xEF, 0x40, 0x16)
|
||||||
|
*/
|
||||||
|
bool dr_w25q32_test(void);
|
||||||
|
|
||||||
|
#endif /* DR_W25Q32_H */
|
||||||
@@ -39,7 +39,7 @@ extern void param_error(const char *cmd);
|
|||||||
/* BLE transmission */
|
/* BLE transmission */
|
||||||
extern void single_format_data(uint8_t *buffer, const char *tag, uint16_t value);
|
extern void single_format_data(uint8_t *buffer, const char *tag, uint16_t value);
|
||||||
extern void ascii_format_data(uint8_t *buffer, const char *tag, const char *ascii, uint8_t len);
|
extern void ascii_format_data(uint8_t *buffer, const char *tag, const char *ascii, uint8_t len);
|
||||||
extern void binary_tx_handler(const uint8_t *buffer, uint16_t length);
|
extern void dr_binary_tx_safe(const uint8_t *buffer, uint16_t length);
|
||||||
extern void dr_sd_delay_ms(uint32_t ms); /* Softdevice-friendly delay */
|
extern void dr_sd_delay_ms(uint32_t ms); /* Softdevice-friendly delay */
|
||||||
|
|
||||||
/* FDS config (fstorage) */
|
/* FDS config (fstorage) */
|
||||||
@@ -83,7 +83,8 @@ extern bool go_device_power_off;
|
|||||||
extern bool go_NVIC_SystemReset;
|
extern bool go_NVIC_SystemReset;
|
||||||
extern bool bond_data_delete;
|
extern bool bond_data_delete;
|
||||||
extern uint8_t m_reset_status;
|
extern uint8_t m_reset_status;
|
||||||
extern ret_code_t eeprom_write_byte(uint16_t mem_address, uint8_t data);
|
extern void config_save(void);
|
||||||
|
extern config_data_t m_config;
|
||||||
|
|
||||||
/* AGC_GAIN_SW is a macro in measurements.h - replicate here */
|
/* AGC_GAIN_SW is a macro in measurements.h - replicate here */
|
||||||
#include "nrf_gpio.h"
|
#include "nrf_gpio.h"
|
||||||
@@ -302,7 +303,7 @@ static int Cmd_mfv(const ParsedCmd *cmd);
|
|||||||
static int Cmd_msp(const ParsedCmd *cmd); /* IMU 6-axis raw data (single shot) */
|
static int Cmd_msp(const ParsedCmd *cmd); /* IMU 6-axis raw data (single shot) */
|
||||||
|
|
||||||
static int Cmd_mpa(const ParsedCmd *cmd); /* Piezo TX/RX Activate */
|
static int Cmd_mpa(const ParsedCmd *cmd); /* Piezo TX/RX Activate */
|
||||||
static int Cmd_mpb(const ParsedCmd *cmd); /* Piezo TX/RX Deactivate 26.03.13 */
|
static int Cmd_mpb(const ParsedCmd *cmd); /* Piezo TX/RX Deactivate */
|
||||||
static int Cmd_mpc(const ParsedCmd *cmd); /* Piezo Burst Capture */
|
static int Cmd_mpc(const ParsedCmd *cmd); /* Piezo Burst Capture */
|
||||||
static int Cmd_mdc(const ParsedCmd *cmd); /* Piezo ADC Capture */
|
static int Cmd_mdc(const ParsedCmd *cmd); /* Piezo ADC Capture */
|
||||||
static int Cmd_mec(const ParsedCmd *cmd); /* Piezo Burst + ADC capture */
|
static int Cmd_mec(const ParsedCmd *cmd); /* Piezo Burst + ADC capture */
|
||||||
@@ -427,7 +428,7 @@ int dr_cmd_parser(const uint8_t *buf, uint8_t len)
|
|||||||
/* CRC 실패 시 에러 응답 전송 */
|
/* CRC 실패 시 에러 응답 전송 */
|
||||||
if (g_plat.crc_check && g_plat.tx_bin) {
|
if (g_plat.crc_check && g_plat.tx_bin) {
|
||||||
single_format_data(ble_bin_buffer, "crc!", 65530);
|
single_format_data(ble_bin_buffer, "crc!", 65530);
|
||||||
binary_tx_handler(ble_bin_buffer, 3);
|
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||||
}
|
}
|
||||||
return -1; /* CRC 실패 또는 파싱 실패 → 음수로 old parser에 위임 */
|
return -1; /* CRC 실패 또는 파싱 실패 → 음수로 old parser에 위임 */
|
||||||
}
|
}
|
||||||
@@ -474,7 +475,7 @@ static int Cmd_mta(const ParsedCmd *cmd)
|
|||||||
|
|
||||||
if (g_plat.tx_bin) {
|
if (g_plat.tx_bin) {
|
||||||
single_format_data(ble_bin_buffer, "rta:", mode);
|
single_format_data(ble_bin_buffer, "rta:", mode);
|
||||||
binary_tx_handler(ble_bin_buffer, 3);
|
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -515,7 +516,7 @@ static int Cmd_sta(const ParsedCmd *cmd)
|
|||||||
|
|
||||||
if (g_plat.tx_bin) {
|
if (g_plat.tx_bin) {
|
||||||
single_format_data(ble_bin_buffer, "sta:", mode);
|
single_format_data(ble_bin_buffer, "sta:", mode);
|
||||||
binary_tx_handler(ble_bin_buffer, 3);
|
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -683,7 +684,7 @@ static int Cmd_ssq(const ParsedCmd *cmd)
|
|||||||
g_plat.log("[Cmd_ssq] Power off\r\n");
|
g_plat.log("[Cmd_ssq] Power off\r\n");
|
||||||
}
|
}
|
||||||
single_format_data(ble_bin_buffer, "rsq:", val);
|
single_format_data(ble_bin_buffer, "rsq:", val);
|
||||||
binary_tx_handler(ble_bin_buffer, 2);
|
dr_binary_tx_safe(ble_bin_buffer, 2);
|
||||||
go_device_power_off = true;
|
go_device_power_off = true;
|
||||||
main_timer_start();
|
main_timer_start();
|
||||||
return 1;
|
return 1;
|
||||||
@@ -698,11 +699,12 @@ static int Cmd_ssr(const ParsedCmd *cmd)
|
|||||||
g_plat.log("[Cmd_ssr] Bond delete + reset\r\n");
|
g_plat.log("[Cmd_ssr] Bond delete + reset\r\n");
|
||||||
}
|
}
|
||||||
single_format_data(ble_bin_buffer, "rsr:", val);
|
single_format_data(ble_bin_buffer, "rsr:", val);
|
||||||
binary_tx_handler(ble_bin_buffer, 2);
|
dr_binary_tx_safe(ble_bin_buffer, 2);
|
||||||
bond_data_delete = true;
|
bond_data_delete = true;
|
||||||
eeprom_write_byte(0x0060, (uint8_t)bond_data_delete);
|
m_config.bond_data_delete = (uint8_t)bond_data_delete;
|
||||||
m_reset_status = 2;
|
m_reset_status = 2;
|
||||||
eeprom_write_byte(0x0065, m_reset_status);
|
m_config.reset_status = m_reset_status;
|
||||||
|
config_save();
|
||||||
nrf_delay_ms(5);
|
nrf_delay_ms(5);
|
||||||
go_NVIC_SystemReset = true;
|
go_NVIC_SystemReset = true;
|
||||||
main_timer_start();
|
main_timer_start();
|
||||||
@@ -718,9 +720,10 @@ static int Cmd_sss(const ParsedCmd *cmd)
|
|||||||
g_plat.log("[Cmd_sss] Device reset\r\n");
|
g_plat.log("[Cmd_sss] Device reset\r\n");
|
||||||
}
|
}
|
||||||
single_format_data(ble_bin_buffer, "rss:", val);
|
single_format_data(ble_bin_buffer, "rss:", val);
|
||||||
binary_tx_handler(ble_bin_buffer, 2);
|
dr_binary_tx_safe(ble_bin_buffer, 2);
|
||||||
m_reset_status = 2;
|
m_reset_status = 2;
|
||||||
eeprom_write_byte(0x0065, m_reset_status);
|
m_config.reset_status = m_reset_status;
|
||||||
|
config_save();
|
||||||
nrf_delay_ms(5);
|
nrf_delay_ms(5);
|
||||||
go_NVIC_SystemReset = true;
|
go_NVIC_SystemReset = true;
|
||||||
main_timer_start();
|
main_timer_start();
|
||||||
@@ -736,7 +739,7 @@ static int Cmd_sst(const ParsedCmd *cmd)
|
|||||||
g_plat.log("[Cmd_sst] Ready\r\n");
|
g_plat.log("[Cmd_sst] Ready\r\n");
|
||||||
}
|
}
|
||||||
single_format_data(ble_bin_buffer, "rst:", val);
|
single_format_data(ble_bin_buffer, "rst:", val);
|
||||||
binary_tx_handler(ble_bin_buffer, 2);
|
dr_binary_tx_safe(ble_bin_buffer, 2);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -747,7 +750,7 @@ static int Cmd_mfv(const ParsedCmd *cmd)
|
|||||||
g_plat.log("[Cmd_mfv] FW=%s\r\n", DR_DEVICE_VERSION);
|
g_plat.log("[Cmd_mfv] FW=%s\r\n", DR_DEVICE_VERSION);
|
||||||
}
|
}
|
||||||
ascii_format_data(ble_bin_buffer, "rfv:", DR_DEVICE_VERSION, 12);
|
ascii_format_data(ble_bin_buffer, "rfv:", DR_DEVICE_VERSION, 12);
|
||||||
binary_tx_handler(ble_bin_buffer, 8);
|
dr_binary_tx_safe(ble_bin_buffer, 8);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -764,7 +767,7 @@ static int Cmd_mpa(const ParsedCmd *cmd)
|
|||||||
|
|
||||||
if (g_plat.tx_bin) {
|
if (g_plat.tx_bin) {
|
||||||
single_format_data(ble_bin_buffer, "rpa:", 1);
|
single_format_data(ble_bin_buffer, "rpa:", 1);
|
||||||
binary_tx_handler(ble_bin_buffer, 3);
|
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -783,7 +786,7 @@ static int Cmd_mpb(const ParsedCmd *cmd)
|
|||||||
|
|
||||||
if (g_plat.tx_bin) {
|
if (g_plat.tx_bin) {
|
||||||
single_format_data(ble_bin_buffer, "rpb:", 1);
|
single_format_data(ble_bin_buffer, "rpb:", 1);
|
||||||
binary_tx_handler(ble_bin_buffer, 3);
|
dr_binary_tx_safe(ble_bin_buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -856,9 +859,9 @@ static int Cmd_mpc(const ParsedCmd *cmd)
|
|||||||
case 4:
|
case 4:
|
||||||
dr_piezo_burst_sw_22mhz((uint8_t)cycles);
|
dr_piezo_burst_sw_22mhz((uint8_t)cycles);
|
||||||
break;
|
break;
|
||||||
case 9:
|
/*case 9:
|
||||||
dr_piezo_burst_sw_19mhz((uint8_t)cycles);
|
dr_piezo_burst_sw_19mhz((uint8_t)cycles);
|
||||||
break;
|
break;*/
|
||||||
case 1:
|
case 1:
|
||||||
default:
|
default:
|
||||||
dr_piezo_burst_sw((uint8_t)cycles); /* 2.1MHz */
|
dr_piezo_burst_sw((uint8_t)cycles); /* 2.1MHz */
|
||||||
@@ -982,7 +985,7 @@ static int Cmd_mdc(const ParsedCmd *cmd)
|
|||||||
ble_bin_buffer[11] = (uint8_t)(echo.baseline_raw >> 8);
|
ble_bin_buffer[11] = (uint8_t)(echo.baseline_raw >> 8);
|
||||||
ble_bin_buffer[12] = (uint8_t)(echo.num_samples & 0xFF);
|
ble_bin_buffer[12] = (uint8_t)(echo.num_samples & 0xFF);
|
||||||
ble_bin_buffer[13] = (uint8_t)(echo.num_samples >> 8);
|
ble_bin_buffer[13] = (uint8_t)(echo.num_samples >> 8);
|
||||||
binary_tx_handler(ble_bin_buffer, 7); /* 14 bytes = 7 words */
|
dr_binary_tx_safe(ble_bin_buffer, 7); /* 14 bytes = 7 words */
|
||||||
nrf_delay_ms(100); /* Wait for BLE stack */
|
nrf_delay_ms(100); /* Wait for BLE stack */
|
||||||
|
|
||||||
/* Packet 2~N: rdd: data packets with packed 12-bit samples */
|
/* Packet 2~N: rdd: data packets with packed 12-bit samples */
|
||||||
@@ -1009,7 +1012,7 @@ static int Cmd_mdc(const ParsedCmd *cmd)
|
|||||||
|
|
||||||
/* Ensure even byte count for word alignment */
|
/* Ensure even byte count for word alignment */
|
||||||
if (dst_idx & 1) ble_bin_buffer[dst_idx++] = 0;
|
if (dst_idx & 1) ble_bin_buffer[dst_idx++] = 0;
|
||||||
binary_tx_handler(ble_bin_buffer, dst_idx / 2); /* bytes to words */
|
dr_binary_tx_safe(ble_bin_buffer, dst_idx / 2); /* bytes to words */
|
||||||
nrf_delay_ms(100); /* Inter-packet delay */
|
nrf_delay_ms(100); /* Inter-packet delay */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1020,7 +1023,7 @@ static int Cmd_mdc(const ParsedCmd *cmd)
|
|||||||
ble_bin_buffer[3] = ':';
|
ble_bin_buffer[3] = ':';
|
||||||
ble_bin_buffer[4] = (uint8_t)(total_packets & 0xFF);
|
ble_bin_buffer[4] = (uint8_t)(total_packets & 0xFF);
|
||||||
ble_bin_buffer[5] = (uint8_t)(total_packets >> 8);
|
ble_bin_buffer[5] = (uint8_t)(total_packets >> 8);
|
||||||
binary_tx_handler(ble_bin_buffer, 3); /* 6 bytes = 3 words */
|
dr_binary_tx_safe(ble_bin_buffer, 3); /* 6 bytes = 3 words */
|
||||||
|
|
||||||
if (g_plat.log && g_log_enable) {
|
if (g_plat.log && g_log_enable) {
|
||||||
g_plat.log("[Cmd_mdc] sent rdb+rdd*%u+rde (%u samples)\r\n",
|
g_plat.log("[Cmd_mdc] sent rdb+rdd*%u+rde (%u samples)\r\n",
|
||||||
@@ -1295,7 +1298,7 @@ static int Cmd_mwh(const ParsedCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ascii_format_data(ble_bin_buffer, "rwh:", buf, 12);
|
ascii_format_data(ble_bin_buffer, "rwh:", buf, 12);
|
||||||
binary_tx_handler(ble_bin_buffer, 8);
|
dr_binary_tx_safe(ble_bin_buffer, 8);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1321,7 +1324,7 @@ static int Cmd_mws(const ParsedCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ascii_format_data(ble_bin_buffer, "rws:", buf, 12);
|
ascii_format_data(ble_bin_buffer, "rws:", buf, 12);
|
||||||
binary_tx_handler(ble_bin_buffer, 8);
|
dr_binary_tx_safe(ble_bin_buffer, 8);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1331,7 +1334,7 @@ static int Cmd_mrh(const ParsedCmd *cmd)
|
|||||||
(void)cmd;
|
(void)cmd;
|
||||||
memcpy(HW_NO, m_config.hw_no, 12);
|
memcpy(HW_NO, m_config.hw_no, 12);
|
||||||
ascii_format_data(ble_bin_buffer, "rrh:", HW_NO, 12);
|
ascii_format_data(ble_bin_buffer, "rrh:", HW_NO, 12);
|
||||||
binary_tx_handler(ble_bin_buffer, 8);
|
dr_binary_tx_safe(ble_bin_buffer, 8);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1341,7 +1344,7 @@ static int Cmd_mrs(const ParsedCmd *cmd)
|
|||||||
(void)cmd;
|
(void)cmd;
|
||||||
memcpy(SERIAL_NO, m_config.serial_no, 12);
|
memcpy(SERIAL_NO, m_config.serial_no, 12);
|
||||||
ascii_format_data(ble_bin_buffer, "rrs:", SERIAL_NO, 12);
|
ascii_format_data(ble_bin_buffer, "rrs:", SERIAL_NO, 12);
|
||||||
binary_tx_handler(ble_bin_buffer, 8);
|
dr_binary_tx_safe(ble_bin_buffer, 8);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,158 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#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 */
|
|
||||||
|
|
||||||
@@ -1,299 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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_ */
|
|
||||||
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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_
|
|
||||||
|
|
||||||
@@ -22,7 +22,6 @@
|
|||||||
//#include "fstorage.h"
|
//#include "fstorage.h"
|
||||||
#include "battery_saadc.h"
|
#include "battery_saadc.h"
|
||||||
#include "main_timer.h"
|
#include "main_timer.h"
|
||||||
#include "meas_pd_48.h"
|
|
||||||
#include <cmd_parse.h>
|
#include <cmd_parse.h>
|
||||||
#include "debug_print.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_REF_VOLTAGE_IN_MILLIVOLTS 600 /**< Reference voltage (in milli volts) used by ADC while doing conversion. */
|
||||||
@@ -52,8 +51,8 @@ bool low_battery_check = false;
|
|||||||
extern bool info4; //cmd_parse
|
extern bool info4; //cmd_parse
|
||||||
|
|
||||||
// cj add edit 25/11/24
|
// cj add edit 25/11/24
|
||||||
extern volatile uint16_t info_p1;
|
volatile uint16_t info_p1;
|
||||||
extern volatile uint16_t info_p2;
|
volatile uint16_t info_p2;
|
||||||
|
|
||||||
|
|
||||||
extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
extern char ble_tx_buffer[BLE_NUS_MAX_DATA_LEN];
|
||||||
@@ -63,7 +62,7 @@ extern volatile bool processing;
|
|||||||
extern which_cmd_t cmd_type_t;
|
extern which_cmd_t cmd_type_t;
|
||||||
|
|
||||||
extern uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] ;
|
extern uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] ;
|
||||||
extern volatile uint16_t info_batt; //48_c
|
volatile uint16_t info_batt; //48_c
|
||||||
extern bool go_temp; //
|
extern bool go_temp; //
|
||||||
extern bool go_batt; //cmd_parse
|
extern bool go_batt; //cmd_parse
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@ void pressure_all_event_handler(nrf_drv_saadc_evt_t const * p_event)
|
|||||||
result_data[0] = p1_mV;
|
result_data[0] = p1_mV;
|
||||||
result_data[1] = p2_mV;
|
result_data[1] = p2_mV;
|
||||||
format_data(ble_bin_buffer, "rpn:", result_data,2);
|
format_data(ble_bin_buffer, "rpn:", result_data,2);
|
||||||
binary_tx_handler(ble_bin_buffer,4);
|
dr_binary_tx_safe(ble_bin_buffer,4);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -199,7 +198,7 @@ void battery_event_handler( nrf_drv_saadc_evt_t const * p_event )
|
|||||||
|
|
||||||
single_format_data(ble_bin_buffer, "rsn:", batt_lvl_in_milli_volt_1);
|
single_format_data(ble_bin_buffer, "rsn:", batt_lvl_in_milli_volt_1);
|
||||||
|
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
//data_tx_handler(ble_tx_buffer);
|
//data_tx_handler(ble_tx_buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,163 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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_ */
|
|
||||||
|
|
||||||
@@ -1,522 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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 /* */
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,505 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @file dr_adc121s051.h
|
|
||||||
* @brief ADC121S051 12-bit ADC Driver for nRF52840
|
|
||||||
* For 1.2MHz Piezo Echo Envelope Detection
|
|
||||||
* @author Charles KWON
|
|
||||||
* @date 2025-12-15
|
|
||||||
*
|
|
||||||
* @details This driver reads the envelope-detected DC level from piezo echo.
|
|
||||||
*
|
|
||||||
* Signal Flow:
|
|
||||||
*
|
|
||||||
* [Piezo TX] [Echo RX] [Envelope] [ADC] [MCU]
|
|
||||||
* 1.2MHz --> Reflect --> Detector --> DC Level --> Digital
|
|
||||||
* burst signal (hardware) reading value
|
|
||||||
*
|
|
||||||
* The envelope detector circuit converts the 1.2MHz echo burst
|
|
||||||
* into a DC voltage proportional to the echo amplitude.
|
|
||||||
* ADC samples this DC level for amplitude measurement.
|
|
||||||
*
|
|
||||||
* @note Hardware: Texas Instruments ADC121S051
|
|
||||||
* - 12-bit resolution (0-4095)
|
|
||||||
* - Sample rate: 200-500 ksps
|
|
||||||
* - Input range: 0V to VA
|
|
||||||
* - SPI interface (software bit-bang)
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef DR_ADC121S051_H
|
|
||||||
#define DR_ADC121S051_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "nrf_gpio.h"
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* PIN CONFIGURATION
|
|
||||||
*
|
|
||||||
* WARNING: Never hardcode pin numbers!
|
|
||||||
* Hardcoding may save a developer's time momentarily,
|
|
||||||
* but it will also shorten their lifespan.
|
|
||||||
*============================================================================*/
|
|
||||||
#define DR_ADC_PIN_SCLK NRF_GPIO_PIN_MAP(0, 14) /**< Serial Clock */
|
|
||||||
#define DR_ADC_PIN_SDATA NRF_GPIO_PIN_MAP(0, 15) /**< Serial Data (MISO) */
|
|
||||||
#define DR_ADC_PIN_CS NRF_GPIO_PIN_MAP(0, 19) /**< Chip Select P0.13 -> P0.19 */
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* ADC SPECIFICATIONS
|
|
||||||
*============================================================================*/
|
|
||||||
#define DR_ADC_RESOLUTION 12 /**< Bits */
|
|
||||||
#define DR_ADC_MAX_VALUE 4095 /**< 2^12 - 1 */
|
|
||||||
#define DR_ADC_VREF_MV 3300 /**< Reference voltage (mV) */
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* ECHO DETECTION CONFIGURATION
|
|
||||||
*
|
|
||||||
* Bladder Measurement Requirements:
|
|
||||||
* - Target measurement range: 20cm (200mm)
|
|
||||||
* - SCLK frequency: 8.6MHz (bit-bang SPI)
|
|
||||||
* - ADC121S051 requires 16 SCLK cycles per sample
|
|
||||||
* - Actual sample rate: 8.6MHz / 16 = 0.5375MHz = 537.5kHz
|
|
||||||
* - Actual sample interval: 16 / 8.6MHz = 1.86us
|
|
||||||
* - Sound speed in tissue: 1540m/s = 1.54mm/us
|
|
||||||
*
|
|
||||||
* Formula: samples = distance(mm) * 2 / (1.86us * 1.54mm/us)
|
|
||||||
* = distance(mm) * 2 / 2.86
|
|
||||||
* = distance(mm) * 0.7
|
|
||||||
*
|
|
||||||
* 10cm = 100mm -> 100 * 0.7 = 70 samples (round-trip 130us)
|
|
||||||
* 17cm = 170mm -> 170 * 0.7 = 119 samples (round-trip 221us)
|
|
||||||
* 20cm = 200mm -> 200 * 0.7 = 140 samples (round-trip 260us)
|
|
||||||
*
|
|
||||||
* Buffer size: 200 samples * 2 bytes = 400 bytes (RAM 256KB, OK)
|
|
||||||
* BLE transmission: 140 samples * 2 bytes = 280 bytes (16-bit raw, no packing)
|
|
||||||
*============================================================================*/
|
|
||||||
#define DR_ADC_SCLK_MHZ 8.6f /**< SPI bit-bang SCLK frequency */
|
|
||||||
#define DR_ADC_CLOCKS_PER_SAMPLE 16 /**< ADC121S051: 16 SCLK per sample */
|
|
||||||
#define DR_ADC_ECHO_SAMPLES_MAX 200 /**< Maximum samples (20cm+ with margin) */
|
|
||||||
#define DR_ADC_ECHO_SAMPLES_DEFAULT 140 /**< Default samples (20cm depth target) */
|
|
||||||
#define DR_ADC_SAMPLE_INTERVAL_US 1.86f /**< 16 / 8.6MHz = 1.86us per sample */
|
|
||||||
#define DR_ADC_SOUND_SPEED_MM_US 1.54f /**< Sound speed in tissue (mm/us) */
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* ERROR CODES
|
|
||||||
*============================================================================*/
|
|
||||||
typedef enum {
|
|
||||||
DR_ADC_OK = 0,
|
|
||||||
DR_ADC_ERR_NOT_INIT,
|
|
||||||
DR_ADC_ERR_INVALID_PARAM,
|
|
||||||
DR_ADC_ERR_NO_ECHO
|
|
||||||
} dr_adc_err_t;
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* DATA STRUCTURES
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Single ADC reading result
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint16_t raw; /**< Raw 12-bit value (0-4095) */
|
|
||||||
uint32_t voltage_mv; /**< Voltage in millivolts */
|
|
||||||
} dr_adc_result_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Echo measurement result
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint16_t peak_raw; /**< Peak amplitude (raw) */
|
|
||||||
uint32_t peak_mv; /**< Peak amplitude (mV) */
|
|
||||||
uint16_t peak_index; /**< Sample index of peak */
|
|
||||||
uint32_t peak_time_us; /**< Time to peak (us) */
|
|
||||||
uint16_t baseline_raw; /**< Baseline level before echo */
|
|
||||||
uint16_t num_samples; /**< Number of samples captured */
|
|
||||||
} dr_adc_echo_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Echo capture configuration
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint16_t num_samples; /**< Samples to capture (1-200) */
|
|
||||||
uint16_t threshold_raw; /**< Minimum peak threshold */
|
|
||||||
uint16_t delay_us; /**< Delay before capture starts */
|
|
||||||
} dr_adc_echo_config_t;
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* INITIALIZATION
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialize ADC driver
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_init(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Uninitialize ADC driver
|
|
||||||
*/
|
|
||||||
void dr_adc_uninit(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if initialized
|
|
||||||
*/
|
|
||||||
bool dr_adc_is_initialized(void);
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* BASIC READ FUNCTIONS
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Read single ADC value
|
|
||||||
* @param result Pointer to result structure
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_read(dr_adc_result_t *result);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Read raw 12-bit value only
|
|
||||||
* @param raw_value Pointer to store value
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_read_raw(uint16_t *raw_value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Read averaged value
|
|
||||||
* @param result Pointer to result structure
|
|
||||||
* @param num_samples Number of samples to average (1-256)
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_read_averaged(dr_adc_result_t *result, uint16_t num_samples);
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* ECHO DETECTION FUNCTIONS
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Capture echo envelope after piezo burst
|
|
||||||
* @param buffer Array to store samples (must be pre-allocated)
|
|
||||||
* @param num_samples Number of samples to capture
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*
|
|
||||||
* @note Call this immediately after dr_piezo_burst_sw()
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_capture_echo(uint16_t *buffer, uint16_t num_samples);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Capture and analyze echo in one call
|
|
||||||
* @param echo Pointer to echo result structure
|
|
||||||
* @param config Pointer to capture configuration (NULL for defaults)
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_measure_echo(dr_adc_echo_t *echo, const dr_adc_echo_config_t *config);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Piezo burst + Echo capture in one call
|
|
||||||
* @param cycles Number of burst cycles (3~9)
|
|
||||||
* @param delay_us Delay before capture (us)
|
|
||||||
* @param num_samples Number of samples to capture
|
|
||||||
* @param echo Pointer to echo result structure
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_burst_and_capture(uint8_t cycles, uint16_t delay_us,
|
|
||||||
uint16_t num_samples, dr_adc_echo_t *echo);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get pointer to last captured echo buffer
|
|
||||||
* @return Pointer to internal buffer (valid until next capture)
|
|
||||||
* @note Buffer contains num_samples values from last burst_and_capture call
|
|
||||||
*/
|
|
||||||
const uint16_t* dr_adc_get_echo_buffer(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Analyze captured echo buffer
|
|
||||||
* @param buffer Sample buffer
|
|
||||||
* @param num_samples Number of samples in buffer
|
|
||||||
* @param echo Pointer to echo result structure
|
|
||||||
* @param threshold Minimum threshold for valid peak
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_analyze_echo(const uint16_t *buffer, uint16_t num_samples,
|
|
||||||
dr_adc_echo_t *echo, uint16_t threshold);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Find peak in buffer
|
|
||||||
* @param buffer Sample buffer
|
|
||||||
* @param num_samples Number of samples
|
|
||||||
* @param peak_value Pointer to store peak value
|
|
||||||
* @param peak_index Pointer to store peak index (can be NULL)
|
|
||||||
*/
|
|
||||||
void dr_adc_find_peak(const uint16_t *buffer, uint16_t num_samples,
|
|
||||||
uint16_t *peak_value, uint16_t *peak_index);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Calculate baseline (average of first N samples)
|
|
||||||
* @param buffer Sample buffer
|
|
||||||
* @param num_samples Number of samples to average for baseline
|
|
||||||
* @return Baseline value
|
|
||||||
*/
|
|
||||||
uint16_t dr_adc_calc_baseline(const uint16_t *buffer, uint16_t num_samples);
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* UTILITY FUNCTIONS
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Convert raw value to millivolts
|
|
||||||
* @param raw_value Raw 12-bit value
|
|
||||||
* @return Voltage in millivolts
|
|
||||||
*/
|
|
||||||
uint32_t dr_adc_raw_to_mv(uint16_t raw_value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set reference voltage
|
|
||||||
* @param vref_mv Reference voltage in millivolts
|
|
||||||
*/
|
|
||||||
void dr_adc_set_vref(uint32_t vref_mv);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get reference voltage
|
|
||||||
* @return Reference voltage in millivolts
|
|
||||||
*/
|
|
||||||
uint32_t dr_adc_get_vref(void);
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* DEBUG FUNCTIONS
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Test ADC communication
|
|
||||||
* @return true if OK
|
|
||||||
*/
|
|
||||||
bool dr_adc_test(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Print echo buffer to debug output
|
|
||||||
* @param buffer Sample buffer
|
|
||||||
* @param num_samples Number of samples
|
|
||||||
*/
|
|
||||||
void dr_adc_print_buffer(const uint16_t *buffer, uint16_t num_samples);
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* POWER CONTROL
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* BLE TRANSMISSION CALLBACK
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* INTEGRATED BURST + CAPTURE + TRANSMIT
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Piezo burst + ADC capture + BLE transmission (all-in-one)
|
|
||||||
*
|
|
||||||
* This function performs the complete measurement cycle internally:
|
|
||||||
* 1. Power on ADC
|
|
||||||
* 2. Select piezo channel (0~7)
|
|
||||||
* 3. Execute piezo burst (frequency based on freq_option)
|
|
||||||
* 4. Capture echo samples (after delay_us) - repeated 'averaging' times
|
|
||||||
* 5. Average the captured samples (firmware-level noise reduction)
|
|
||||||
* 6. Analyze peak/baseline
|
|
||||||
* 7. Transmit data via BLE with proper packet timing
|
|
||||||
*
|
|
||||||
* @param freq_option Frequency option: 0=1.8MHz (default), 1=2.1MHz, 2=2.0MHz, 3=1.7MHz
|
|
||||||
* @param delay_us Delay before capture (us), default 20
|
|
||||||
* @param num_samples Number of samples to capture (1~200)
|
|
||||||
* @param cycles Number of burst cycles (3~7), default 5
|
|
||||||
* @param averaging Number of measurements to average (1~1000), default 1
|
|
||||||
* @param piezo_ch Piezo channel to use (0~7), default 0
|
|
||||||
* @param ble_buffer Working buffer for BLE packets (must be >= 240 bytes)
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*
|
|
||||||
* @note Must call dr_adc_register_ble_tx() before using this function
|
|
||||||
* @note BLE packets: reb: (header), red: (data), ree: (end)
|
|
||||||
* @note Higher averaging reduces noise but increases measurement time (~0.3ms per avg)
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_burst_capture_transmit(uint8_t freq_option, uint16_t delay_us,
|
|
||||||
uint16_t num_samples, uint8_t cycles,
|
|
||||||
uint16_t averaging, uint8_t piezo_ch,
|
|
||||||
uint8_t *ble_buffer, uint8_t skip_raa);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Select piezo channel (0~7)
|
|
||||||
* @param channel Piezo channel number (0~7)
|
|
||||||
*
|
|
||||||
* @note Hardware-dependent: requires MUX or individual GPIO control
|
|
||||||
* Currently uses placeholder - implement based on actual hardware
|
|
||||||
*/
|
|
||||||
void dr_piezo_select_channel(uint8_t channel);
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* 4-CHANNEL CAPTURE (maa? command support)
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 8-channel echo buffer for maa? command
|
|
||||||
* Memory: 140 samples × 2 bytes × 8 channels = 2,240 bytes
|
|
||||||
*/
|
|
||||||
#define MAA_NUM_CHANNELS 8 /* 4 -> 8 jhChun 26.02.12*/
|
|
||||||
#define MAA_SAMPLES_MAX 200
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Echo data for one channel
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
uint16_t samples[MAA_SAMPLES_MAX]; /**< Raw sample data */
|
|
||||||
uint16_t num_samples; /**< Actual sample count */
|
|
||||||
uint16_t peak_raw; /**< Peak amplitude */
|
|
||||||
uint16_t peak_index; /**< Peak sample index */
|
|
||||||
uint16_t baseline_raw; /**< Baseline level */
|
|
||||||
} dr_maa_channel_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Capture echo from one channel (no BLE transmission)
|
|
||||||
*
|
|
||||||
* Captures averaged echo data for a single channel and stores
|
|
||||||
* in the provided channel buffer. Does NOT transmit via BLE.
|
|
||||||
*
|
|
||||||
* @param freq_option Frequency: 0=1.8MHz, 1=2.1MHz, 2=2.0MHz, 3=1.7MHz
|
|
||||||
* @param delay_us Delay before capture (us)
|
|
||||||
* @param num_samples Number of samples (1~200)
|
|
||||||
* @param cycles Burst cycles (3~7)
|
|
||||||
* @param averaging Number of averages (1~1000)
|
|
||||||
* @param piezo_ch Piezo channel (0~7)
|
|
||||||
* @param out_channel Output channel data structure
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_capture_channel_only(uint8_t freq_option, uint16_t delay_us,
|
|
||||||
uint16_t num_samples, uint8_t cycles,
|
|
||||||
uint16_t averaging, uint8_t piezo_ch,
|
|
||||||
dr_maa_channel_t *out_channel);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Transmit captured channel data via BLE
|
|
||||||
*
|
|
||||||
* Sends previously captured channel data using reb:/red:/ree: protocol.
|
|
||||||
*
|
|
||||||
* @param ch_data Pointer to captured channel data
|
|
||||||
* @param ble_buffer Working buffer for BLE packets (>= 240 bytes)
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_transmit_channel(const dr_maa_channel_t *ch_data,
|
|
||||||
uint8_t *ble_buffer);
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* DELTA COMPRESSION (maa? mode=1)
|
|
||||||
*
|
|
||||||
* Format:
|
|
||||||
* Byte 0-1: First sample (16-bit, little endian)
|
|
||||||
* Byte 2+: Delta values (8-bit signed)
|
|
||||||
* If delta > 127 or < -127: escape (0x80) + 16-bit value
|
|
||||||
*
|
|
||||||
* Expected compression: ~50% (280 bytes -> ~140 bytes)
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
#define DELTA_ESCAPE_BYTE 0x80 /**< Escape marker for out-of-range delta */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Compress sample data using delta encoding
|
|
||||||
*
|
|
||||||
* @param samples Input sample array (16-bit values)
|
|
||||||
* @param num_samples Number of samples
|
|
||||||
* @param out_buffer Output buffer for compressed data
|
|
||||||
* @param out_size Output: number of bytes written
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_delta_compress(const uint16_t *samples, uint16_t num_samples,
|
|
||||||
uint8_t *out_buffer, uint16_t *out_size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Transmit captured channel data via BLE with delta compression
|
|
||||||
*
|
|
||||||
* Uses rdb:/rdd:/rde: protocol (delta variant of reb:/red:/ree:)
|
|
||||||
*
|
|
||||||
* @param ch_data Pointer to captured channel data
|
|
||||||
* @param ble_buffer Working buffer for BLE packets (>= 240 bytes)
|
|
||||||
* @return dr_adc_err_t Error code
|
|
||||||
*/
|
|
||||||
dr_adc_err_t dr_adc_transmit_channel_delta(const dr_maa_channel_t *ch_data,
|
|
||||||
uint8_t *ble_buffer);
|
|
||||||
|
|
||||||
/*==============================================================================
|
|
||||||
* ASYNC MAA - Non-blocking 8-channel capture
|
|
||||||
*
|
|
||||||
* Design: State machine driven by BLE TX complete events
|
|
||||||
* Flow:
|
|
||||||
* maa? cmd -> maa_async_start() -> capture CH0 -> TX reb: -> TX red: ...
|
|
||||||
* BLE_NUS_EVT_TX_RDY -> maa_async_continue() -> TX next packet or next channel
|
|
||||||
* All done -> TX raa: -> state=IDLE
|
|
||||||
*============================================================================*/
|
|
||||||
|
|
||||||
/** @brief MAA async state machine states */
|
|
||||||
typedef enum {
|
|
||||||
MAA_ASYNC_IDLE = 0, /**< Not active */
|
|
||||||
MAA_ASYNC_CAPTURING, /**< ADC capture in progress */
|
|
||||||
MAA_ASYNC_TX_HEADER, /**< Sending reb: header */
|
|
||||||
MAA_ASYNC_TX_DATA, /**< Sending red: data packets */
|
|
||||||
MAA_ASYNC_NEXT_CHANNEL, /**< Preparing next channel */
|
|
||||||
MAA_ASYNC_COMPLETE /**< Sending raa: and finishing */
|
|
||||||
} maa_async_state_t;
|
|
||||||
|
|
||||||
/** @brief MAA async context */
|
|
||||||
typedef struct {
|
|
||||||
maa_async_state_t state; /**< Current state */
|
|
||||||
uint8_t current_ch; /**< Current channel (0~7) */
|
|
||||||
uint8_t current_pkt; /**< Current packet index */
|
|
||||||
uint16_t data_offset; /**< Bytes sent so far for current channel */
|
|
||||||
uint8_t freq_option; /**< Frequency option */
|
|
||||||
uint16_t delay_us; /**< Capture delay */
|
|
||||||
uint16_t num_samples; /**< Samples per channel */
|
|
||||||
uint8_t cycles; /**< Burst cycles */
|
|
||||||
uint16_t averaging; /**< Averaging count */
|
|
||||||
uint8_t *ble_buffer; /**< Working buffer for BLE packets */
|
|
||||||
dr_maa_channel_t channels[MAA_NUM_CHANNELS]; /**< Captured data for each channel */
|
|
||||||
uint16_t total_packets; /**< Total packets for current channel */
|
|
||||||
uint16_t data_packets; /**< Data packets for current channel */
|
|
||||||
} maa_async_ctx_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Start async MAA 8-channel capture
|
|
||||||
*
|
|
||||||
* Initiates the async state machine. Captures CH0 and begins transmission.
|
|
||||||
* Subsequent packets are sent when maa_async_on_tx_ready() is called.
|
|
||||||
*
|
|
||||||
* @param freq_option Frequency: 0=1.8MHz, 1=2.1MHz, 2=2.0MHz, 3=1.7MHz
|
|
||||||
* @param delay_us Capture delay (us)
|
|
||||||
* @param num_samples Samples per channel (1~200)
|
|
||||||
* @param cycles Burst cycles (3~9)
|
|
||||||
* @param averaging Averaging count (1~1000)
|
|
||||||
* @param ble_buffer Working buffer (>= 240 bytes)
|
|
||||||
* @return dr_adc_err_t DR_ADC_OK if started successfully
|
|
||||||
*/
|
|
||||||
dr_adc_err_t maa_async_start(uint8_t freq_option, uint16_t delay_us,
|
|
||||||
uint16_t num_samples, uint8_t cycles,
|
|
||||||
uint16_t averaging, uint8_t *ble_buffer);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Handle BLE TX ready event
|
|
||||||
*
|
|
||||||
* Called from BLE_NUS_EVT_TX_RDY handler. Sends next packet or
|
|
||||||
* transitions to next state.
|
|
||||||
*
|
|
||||||
* @return true if more work pending, false if complete or idle
|
|
||||||
*/
|
|
||||||
bool maa_async_on_tx_ready(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Check if async MAA is active
|
|
||||||
* @return true if state != IDLE
|
|
||||||
*/
|
|
||||||
bool maa_async_is_busy(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get current async state (for debugging)
|
|
||||||
* @return Current state
|
|
||||||
*/
|
|
||||||
maa_async_state_t maa_async_get_state(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Abort async MAA operation
|
|
||||||
*/
|
|
||||||
void maa_async_abort(void);
|
|
||||||
|
|
||||||
#endif /* DR_ADC121S051_H */
|
|
||||||
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
#include "dr_util.h"
|
|
||||||
#include "parser.h"
|
|
||||||
|
|
||||||
extern void single_format_data(uint8_t *buffer, const char *tag, uint16_t value);
|
|
||||||
extern void format_data(uint8_t *buffer, const char *tag, uint16_t *data, uint8_t length);
|
|
||||||
extern void binary_tx_handler(uint8_t *buffer, uint8_t length);
|
|
||||||
extern uint8_t ble_bin_buffer[];
|
|
||||||
|
|
||||||
/* Use dr_binary_tx_safe from main.c - has retry logic for BLE TX queue */
|
|
||||||
extern void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
|
||||||
|
|
||||||
void dr_ble_return_1(const char *tag, uint16_t value)
|
|
||||||
{
|
|
||||||
single_format_data(ble_bin_buffer, tag, value);
|
|
||||||
dr_binary_tx_safe(ble_bin_buffer, 3); /* Use safe TX with retry */
|
|
||||||
}
|
|
||||||
|
|
||||||
void dr_ble_return_2(const char *tag, uint16_t v1, uint16_t v2)
|
|
||||||
{
|
|
||||||
ble_bin_buffer[0] = tag[0];
|
|
||||||
ble_bin_buffer[1] = tag[1];
|
|
||||||
ble_bin_buffer[2] = tag[2];
|
|
||||||
ble_bin_buffer[3] = tag[3];
|
|
||||||
|
|
||||||
ble_bin_buffer[4] = (uint8_t)(v1 >> 8);
|
|
||||||
ble_bin_buffer[5] = (uint8_t)(v1 & 0xFF);
|
|
||||||
ble_bin_buffer[6] = (uint8_t)(v2 >> 8);
|
|
||||||
ble_bin_buffer[7] = (uint8_t)(v2 & 0xFF);
|
|
||||||
|
|
||||||
dr_binary_tx_safe(ble_bin_buffer, 4); /* Use safe TX with retry */
|
|
||||||
}
|
|
||||||
|
|
||||||
void dr_ble_return_3(const char *tag, uint16_t v1, uint16_t v2, uint16_t v3)
|
|
||||||
{
|
|
||||||
ble_bin_buffer[0] = tag[0];
|
|
||||||
ble_bin_buffer[1] = tag[1];
|
|
||||||
ble_bin_buffer[2] = tag[2];
|
|
||||||
ble_bin_buffer[3] = tag[3];
|
|
||||||
|
|
||||||
ble_bin_buffer[4] = (uint8_t)(v1 >> 8);
|
|
||||||
ble_bin_buffer[5] = (uint8_t)(v1 & 0xFF);
|
|
||||||
ble_bin_buffer[6] = (uint8_t)(v2 >> 8);
|
|
||||||
ble_bin_buffer[7] = (uint8_t)(v2 & 0xFF);
|
|
||||||
ble_bin_buffer[8] = (uint8_t)(v3 >> 8);
|
|
||||||
ble_bin_buffer[9] = (uint8_t)(v3 & 0xFF);
|
|
||||||
|
|
||||||
dr_binary_tx_safe(ble_bin_buffer, 5); /* Use safe TX with retry */
|
|
||||||
}
|
|
||||||
|
|
||||||
void dr_ble_debug(uint16_t point_id, uint16_t value)
|
|
||||||
{
|
|
||||||
/* Use dedicated buffer to avoid conflicts with ble_bin_buffer */
|
|
||||||
static uint8_t dbg_buffer[8];
|
|
||||||
|
|
||||||
dbg_buffer[0] = 'd';
|
|
||||||
dbg_buffer[1] = 'b';
|
|
||||||
dbg_buffer[2] = 'g';
|
|
||||||
dbg_buffer[3] = ':';
|
|
||||||
|
|
||||||
dbg_buffer[4] = (uint8_t)(point_id >> 8);
|
|
||||||
dbg_buffer[5] = (uint8_t)(point_id & 0xFF);
|
|
||||||
dbg_buffer[6] = (uint8_t)(value >> 8);
|
|
||||||
dbg_buffer[7] = (uint8_t)(value & 0xFF);
|
|
||||||
|
|
||||||
dr_binary_tx_safe(dbg_buffer, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dr_ble_return_piezo_1(const char *tag, uint16_t value)
|
|
||||||
{
|
|
||||||
/* Use dedicated buffer for piezo responses to avoid conflicts with ble_bin_buffer */
|
|
||||||
static uint8_t piezo_buffer[8];
|
|
||||||
|
|
||||||
piezo_buffer[0] = tag[0];
|
|
||||||
piezo_buffer[1] = tag[1];
|
|
||||||
piezo_buffer[2] = tag[2];
|
|
||||||
piezo_buffer[3] = tag[3];
|
|
||||||
|
|
||||||
piezo_buffer[4] = (uint8_t)(value >> 8);
|
|
||||||
piezo_buffer[5] = (uint8_t)(value & 0xFF);
|
|
||||||
|
|
||||||
dr_binary_tx_safe(piezo_buffer, 3); /* 6 bytes = 3 words */
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#ifndef DR_UTIL_H
|
|
||||||
#define DR_UTIL_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
void dr_ble_return_1(const char *tag, uint16_t value);
|
|
||||||
void dr_ble_return_2(const char *tag, uint16_t v1, uint16_t v2);
|
|
||||||
void dr_ble_return_3(const char *tag, uint16_t v1, uint16_t v2, uint16_t v3);
|
|
||||||
void dr_ble_return_3_be(const char *tag, uint16_t v1, uint16_t v2, uint16_t v3);
|
|
||||||
|
|
||||||
/* Piezo dedicated BLE return - uses separate buffer to avoid conflicts */
|
|
||||||
void dr_ble_return_piezo_1(const char *tag, uint16_t value);
|
|
||||||
|
|
||||||
/* BLE debug output - sends "dbg:" + point_id + value */
|
|
||||||
void dr_ble_debug(uint16_t point_id, uint16_t value);
|
|
||||||
|
|
||||||
#endif /* DR_UTIL_H */
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,24 +0,0 @@
|
|||||||
/* parser.h */
|
|
||||||
#ifndef PARSER_H
|
|
||||||
#define PARSER_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
/* Platform-dependent function pointer set */
|
|
||||||
typedef struct {
|
|
||||||
void (*log)(const char *fmt, ...);
|
|
||||||
void (*tx_bin)(const uint8_t *buf, uint16_t len);
|
|
||||||
bool crc_check;
|
|
||||||
} dr_platform_if_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* Global interface & log flag */
|
|
||||||
extern dr_platform_if_t g_plat;
|
|
||||||
extern bool g_log_enable;
|
|
||||||
|
|
||||||
/* Main parser entry point */
|
|
||||||
int dr_cmd_parser(const uint8_t *buf, uint8_t len);
|
|
||||||
|
|
||||||
#endif /* PARSER_H */
|
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ bool length_error(const char *cmd , uint8_t target_length, uint8_t length)
|
|||||||
resp_error[3] = '!';
|
resp_error[3] = '!';
|
||||||
|
|
||||||
single_format_data(ble_bin_buffer, resp_error, err_code1);
|
single_format_data(ble_bin_buffer, resp_error, err_code1);
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +228,7 @@ bool activate_error(const char *cmd , bool device_status)
|
|||||||
resp_error[3] = '!';
|
resp_error[3] = '!';
|
||||||
|
|
||||||
single_format_data(ble_bin_buffer, resp_error, err_code2);
|
single_format_data(ble_bin_buffer, resp_error, err_code2);
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ void param_error(const char *cmd )
|
|||||||
resp_error[3] = '!';
|
resp_error[3] = '!';
|
||||||
|
|
||||||
single_format_data(ble_bin_buffer, resp_error, err_code3);
|
single_format_data(ble_bin_buffer, resp_error, err_code3);
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,10 +253,8 @@ void quest_error(const char *cmd )
|
|||||||
char resp_error[4];
|
char resp_error[4];
|
||||||
const char pass_init[6] = "123456";
|
const char pass_init[6] = "123456";
|
||||||
if( (cmd[0] == '*') && (cmd[1] == '*') && (cmd[2] == '*') && (cmd[3] == '*')){
|
if( (cmd[0] == '*') && (cmd[1] == '*') && (cmd[2] == '*') && (cmd[3] == '*')){
|
||||||
if(eeprom_write_encrypted(0x0020, (uint8_t *)pass_init, 6)!= NRF_SUCCESS)
|
memcpy(m_config.static_passkey, pass_init, 6);
|
||||||
{
|
config_save();
|
||||||
DBG_PRINTF("ERR!!! EEP_passkey 6\r\n\r\n");;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
resp_error[0] = '*';
|
resp_error[0] = '*';
|
||||||
@@ -264,7 +262,7 @@ void quest_error(const char *cmd )
|
|||||||
resp_error[2] = cmd[2]; // 3rd letter (index 2)
|
resp_error[2] = cmd[2]; // 3rd letter (index 2)
|
||||||
resp_error[3] = '*';
|
resp_error[3] = '*';
|
||||||
single_format_data(ble_bin_buffer, resp_error, err_code4);
|
single_format_data(ble_bin_buffer, resp_error, err_code4);
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
||||||
@@ -275,7 +273,7 @@ void quest_error(const char *cmd )
|
|||||||
resp_error[3] = '!';
|
resp_error[3] = '!';
|
||||||
|
|
||||||
single_format_data(ble_bin_buffer, resp_error, err_code4);
|
single_format_data(ble_bin_buffer, resp_error, err_code4);
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,83 +313,7 @@ void quest_error(const char *cmd )
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
ret_code_t eeprom_read_bool(uint16_t mem_address, bool *value_out)
|
/* eeprom_init_values_read() 삭제됨 — FDS config_load()가 동일 역할 수행 - jhChun 26.03.16 */
|
||||||
{
|
|
||||||
uint8_t raw;
|
|
||||||
ret_code_t ret = eeprom_read_byte(mem_address, &raw);
|
|
||||||
if (ret != NRF_SUCCESS) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
*value_out = (raw != 0);
|
|
||||||
return NRF_SUCCESS;
|
|
||||||
}
|
|
||||||
ret_code_t eeprom_init_values_read(void)
|
|
||||||
{
|
|
||||||
ret_code_t err_code;
|
|
||||||
//uint8_t *data_bond;
|
|
||||||
// Read 11 bytes from EEPROM
|
|
||||||
err_code = eeprom_read_decrypted(0x0030, (uint8_t *)SERIAL_NO, 12);
|
|
||||||
if (err_code != NRF_SUCCESS)
|
|
||||||
{
|
|
||||||
return err_code;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
DBG_PRINTF("\r\n SN:%s \r\n", SERIAL_NO);
|
|
||||||
|
|
||||||
}
|
|
||||||
err_code = eeprom_read_decrypted(0x0020, (uint8_t *)m_static_passkey, 6);
|
|
||||||
if (err_code != NRF_SUCCESS)
|
|
||||||
{
|
|
||||||
return err_code;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
DBG_PRINTF("\r\n passkey-0 :%s \n", m_static_passkey);
|
|
||||||
|
|
||||||
}
|
|
||||||
//err_code = eeprom_read_bytes(0x0060, data_bond,16);
|
|
||||||
err_code = eeprom_read_bool(0x0060, &bond_data_delete);
|
|
||||||
if (err_code != NRF_SUCCESS)
|
|
||||||
{
|
|
||||||
return err_code;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// bond_data_delete = data_bond[0];
|
|
||||||
DBG_PRINTF("\r\n bond_data_delete :%d \n", bond_data_delete);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
err_code = eeprom_read_byte(0x0065, &m_reset_status);
|
|
||||||
if (err_code != NRF_SUCCESS)
|
|
||||||
{
|
|
||||||
return err_code;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(m_reset_status){
|
|
||||||
//DBG_PRINTF("\r\n status :%d \n", m_reset_status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DBG_PRINTF("m_life_cycle eprom read\n"); //ad cj
|
|
||||||
err_code = eeprom_read_uint32(0x0090, &m_life_cycle);
|
|
||||||
if (err_code != NRF_SUCCESS)
|
|
||||||
{
|
|
||||||
return err_code;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(m_life_cycle){
|
|
||||||
DBG_PRINTF("\r\n m_life_cycle :%1u \r\n", m_life_cycle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NRF_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void log_printf(const char *fmt, ...)
|
static void log_printf(const char *fmt, ...)
|
||||||
@@ -428,7 +350,7 @@ void received_command_process (uint8_t const *data_array, which_cmd_t cmd_t, uin
|
|||||||
if (!parser_initialized) {
|
if (!parser_initialized) {
|
||||||
// Setup platform interface
|
// Setup platform interface
|
||||||
g_plat.log = log_printf; // printf
|
g_plat.log = log_printf; // printf
|
||||||
g_plat.tx_bin = binary_tx_handler;
|
g_plat.tx_bin = dr_binary_tx_safe;
|
||||||
g_plat.crc_check = true; // CRC
|
g_plat.crc_check = true; // CRC
|
||||||
g_log_enable = true;
|
g_log_enable = true;
|
||||||
|
|
||||||
@@ -471,7 +393,7 @@ void received_command_process (uint8_t const *data_array, which_cmd_t cmd_t, uin
|
|||||||
resp_error[3] = '!';
|
resp_error[3] = '!';
|
||||||
|
|
||||||
single_format_data(ble_bin_buffer, resp_error, err_code6);
|
single_format_data(ble_bin_buffer, resp_error, err_code6);
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
else if(processing == true)
|
else if(processing == true)
|
||||||
@@ -588,7 +510,7 @@ if((scmd.tag[0] == 's')&&(scmd.tag[1] == 't')&&(scmd.tag[2] == 'a')&&(scmd.tag[3
|
|||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
|
|
||||||
single_format_data(ble_bin_buffer, "rta:", scmd.value0);
|
single_format_data(ble_bin_buffer, "rta:", scmd.value0);
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -617,7 +539,7 @@ else if((scmd.tag[0] == 's')&&(scmd.tag[1] == 't')&&(scmd.tag[2] == 'r')&&(scmd.
|
|||||||
|
|
||||||
|
|
||||||
single_format_data(ble_bin_buffer, "rtr:", (uint8_t)device_status);
|
single_format_data(ble_bin_buffer, "rtr:", (uint8_t)device_status);
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -684,7 +606,7 @@ else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'q')){ // Device power off
|
|||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
|
|
||||||
single_format_data(ble_bin_buffer, "rsq:", scmd.value0);
|
single_format_data(ble_bin_buffer, "rsq:", scmd.value0);
|
||||||
binary_tx_handler(ble_bin_buffer,2);
|
dr_binary_tx_safe(ble_bin_buffer,2);
|
||||||
// sprintf(ble_tx_buffer, "Tq\r\n");
|
// sprintf(ble_tx_buffer, "Tq\r\n");
|
||||||
// data_tx_handler(ble_tx_buffer);
|
// data_tx_handler(ble_tx_buffer);
|
||||||
}
|
}
|
||||||
@@ -701,16 +623,14 @@ else if((scmd.tag[1] == 's') && (scmd.tag[2] == 'r')){ // Bond Info Delete
|
|||||||
DBG_PRINTF("Tr\r\n\r\n");
|
DBG_PRINTF("Tr\r\n\r\n");
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
single_format_data(ble_bin_buffer, "rsr:", scmd.value0);
|
single_format_data(ble_bin_buffer, "rsr:", scmd.value0);
|
||||||
binary_tx_handler(ble_bin_buffer,2);
|
dr_binary_tx_safe(ble_bin_buffer,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bond_data_delete = true;
|
bond_data_delete = true;
|
||||||
eeprom_write_byte(0x0060, (uint8_t)bond_data_delete);
|
m_config.bond_data_delete = (uint8_t)bond_data_delete;
|
||||||
|
|
||||||
//m_config.reset_status = 2;
|
|
||||||
m_reset_status = 2;
|
m_reset_status = 2;
|
||||||
eeprom_write_byte(0x0065, m_reset_status);
|
m_config.reset_status = m_reset_status;
|
||||||
//config_save();
|
config_save();
|
||||||
nrf_delay_ms(5);
|
nrf_delay_ms(5);
|
||||||
go_NVIC_SystemReset = true;
|
go_NVIC_SystemReset = true;
|
||||||
main_timer_start();
|
main_timer_start();
|
||||||
@@ -726,14 +646,14 @@ else if((scmd.tag[1] == 's') && (scmd.tag[2] == 's')){ //Device reset(Reboot)
|
|||||||
DBG_PRINTF("Ts\r\n\r\n");
|
DBG_PRINTF("Ts\r\n\r\n");
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
single_format_data(ble_bin_buffer, "rss:", scmd.value0);
|
single_format_data(ble_bin_buffer, "rss:", scmd.value0);
|
||||||
binary_tx_handler(ble_bin_buffer,2);
|
dr_binary_tx_safe(ble_bin_buffer,2);
|
||||||
}
|
}
|
||||||
go_NVIC_SystemReset = true;
|
go_NVIC_SystemReset = true;
|
||||||
//m_config.reset_status = 2;
|
//m_config.reset_status = 2;
|
||||||
|
|
||||||
m_reset_status = 2;
|
m_reset_status = 2;
|
||||||
eeprom_write_byte(0x0065, m_reset_status);
|
m_config.reset_status = m_reset_status;
|
||||||
// config_save();
|
config_save();
|
||||||
nrf_delay_ms(5);
|
nrf_delay_ms(5);
|
||||||
go_NVIC_SystemReset = true;
|
go_NVIC_SystemReset = true;
|
||||||
main_timer_start();
|
main_timer_start();
|
||||||
@@ -745,7 +665,7 @@ else if((scmd.tag[1] == 's') && (scmd.tag[2] == 't')){ // Auto Gain Control
|
|||||||
DBG_PRINTF("Ready\r\n\r\nREADY\r\n");
|
DBG_PRINTF("Ready\r\n\r\nREADY\r\n");
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
single_format_data(ble_bin_buffer, "rst:", scmd.value0);
|
single_format_data(ble_bin_buffer, "rst:", scmd.value0);
|
||||||
binary_tx_handler(ble_bin_buffer,2);
|
dr_binary_tx_safe(ble_bin_buffer,2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -759,7 +679,7 @@ else if(0 && (scmd.tag[1] == 's') && (scmd.tag[2] == 'v')){ // Auto Gain Cont
|
|||||||
DBG_PRINTF("%s\r\n",DEVICE_VERSION);
|
DBG_PRINTF("%s\r\n",DEVICE_VERSION);
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
ascii_format_data(ble_bin_buffer, "rsv:", DEVICE_VERSION,12);
|
ascii_format_data(ble_bin_buffer, "rsv:", DEVICE_VERSION,12);
|
||||||
binary_tx_handler(ble_bin_buffer,8);
|
dr_binary_tx_safe(ble_bin_buffer,8);
|
||||||
//test_eeprom_page_rw();
|
//test_eeprom_page_rw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,7 +699,7 @@ else if(0 && (scmd.tag[1] == 's') && (scmd.tag[2] == 'z')){
|
|||||||
config_save();
|
config_save();
|
||||||
DBG_PRINTF("[ssz] S/N=%s saved to FDS\r\n", m_config.serial_no);
|
DBG_PRINTF("[ssz] S/N=%s saved to FDS\r\n", m_config.serial_no);
|
||||||
ascii_format_data(ble_bin_buffer, "rsz:", scmd.value_ascii,12);
|
ascii_format_data(ble_bin_buffer, "rsz:", scmd.value_ascii,12);
|
||||||
binary_tx_handler(ble_bin_buffer,8);
|
dr_binary_tx_safe(ble_bin_buffer,8);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
DBG_PRINTF("ERR!!! Serial_number 12\r\n\r\n");
|
DBG_PRINTF("ERR!!! Serial_number 12\r\n\r\n");
|
||||||
@@ -796,42 +716,16 @@ else if((scmd.tag[1] == 'p') && (scmd.tag[2] == 'z')){ //Write, passkey
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint8_t tx_data[EEPROM_PAGE_SIZE];
|
|
||||||
uint8_t rx_data[EEPROM_PAGE_SIZE];
|
|
||||||
uint8_t raw_data[EEPROM_PAGE_SIZE];
|
|
||||||
if(cmd_t == CMD_UART) {
|
if(cmd_t == CMD_UART) {
|
||||||
DBG_PRINTF("Tz0\r\n\r\n");
|
DBG_PRINTF("Tz0\r\n\r\n");
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
|
memcpy(m_static_passkey, scmd.value_ascii, 6);
|
||||||
|
memcpy(m_config.static_passkey, m_static_passkey, 6);
|
||||||
//memcpy(SERIAL_NO, scmd.value_ascii, 6);
|
config_save();
|
||||||
//eeprom_write_bytes(uint16_t mem_address, const uint8_t *data, size_t length)
|
DBG_PRINTF("Passkey saved: %.6s\n", m_static_passkey);
|
||||||
for (uint8_t i=0 ; i<6 ;i++)
|
|
||||||
{
|
|
||||||
tx_data[i] = (uint8_t)(scmd.value_ascii[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(eeprom_write_encrypted(0x0020, tx_data, 6)!= NRF_SUCCESS)
|
|
||||||
{
|
|
||||||
DBG_PRINTF("ERR!!! EEP_passkey 6\r\n\r\n");;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(eeprom_read_bytes(0x0020, raw_data, 6)!= NRF_SUCCESS)
|
|
||||||
{
|
|
||||||
DBG_PRINTF("ERR!!! EEP_passkey 6\r\n\r\n");;
|
|
||||||
}
|
|
||||||
|
|
||||||
nrf_delay_ms(10);
|
|
||||||
DBG_PRINTF("encrypted: %s\n", raw_data);
|
|
||||||
if(eeprom_read_decrypted(0x0020, rx_data, 6)!= NRF_SUCCESS)
|
|
||||||
{
|
|
||||||
DBG_PRINTF("ERR!!! EEP_passkey 6\r\n\r\n");;
|
|
||||||
}
|
|
||||||
DBG_PRINTF("Decrypted: %s\n", rx_data);
|
|
||||||
|
|
||||||
ascii_format_data(ble_bin_buffer, "rpz:", scmd.value_ascii,6);
|
ascii_format_data(ble_bin_buffer, "rpz:", scmd.value_ascii,6);
|
||||||
binary_tx_handler(ble_bin_buffer,5);
|
dr_binary_tx_safe(ble_bin_buffer,5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -852,30 +746,12 @@ else if((scmd.tag[1] == 'p') && (scmd.tag[2] == 'z')){ //Write, passkey
|
|||||||
// sqz
|
// sqz
|
||||||
else if((scmd.tag[1] == 'q') && (scmd.tag[2] == 'z')){ // Read, Serial Number
|
else if((scmd.tag[1] == 'q') && (scmd.tag[2] == 'z')){ // Read, Serial Number
|
||||||
|
|
||||||
uint8_t rx_data[EEPROM_PAGE_SIZE];
|
|
||||||
|
|
||||||
if(cmd_t == CMD_UART) {
|
if(cmd_t == CMD_UART) {
|
||||||
DBG_PRINTF("Tz1,%s\r\n\r\n", SERIAL_NO);
|
DBG_PRINTF("Tz1,%s\r\n\r\n", SERIAL_NO);
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
|
memcpy(m_static_passkey, m_config.static_passkey, 6);
|
||||||
hw_i2c_init_once();
|
|
||||||
if(eeprom_read_decrypted(0x0020, rx_data, 6)!= NRF_SUCCESS)
|
|
||||||
{
|
|
||||||
DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");;
|
|
||||||
}
|
|
||||||
DBG_PRINTF("Decrypted: %s\n", rx_data);
|
|
||||||
// if (eeprom_read_bytes(0x0030 , rx_data ,12) !=NRF_SUCCESS)
|
|
||||||
// {
|
|
||||||
// DBG_PRINTF("ERR!!! EEP_Serial_number 12\r\n\r\n");
|
|
||||||
// }
|
|
||||||
// sprintf(ble_tx_buffer, "Tz1,%s\r\n", m_config.serial_number);
|
|
||||||
// data_tx_handler(ble_tx_buffer);
|
|
||||||
for (uint8_t i=0 ; i<6 ;i++)
|
|
||||||
{
|
|
||||||
(m_static_passkey[i]) = (char)rx_data[i] ;
|
|
||||||
}
|
|
||||||
ascii_format_data(ble_bin_buffer, "rqz:", m_static_passkey,6);
|
ascii_format_data(ble_bin_buffer, "rqz:", m_static_passkey,6);
|
||||||
binary_tx_handler(ble_bin_buffer,5);
|
dr_binary_tx_safe(ble_bin_buffer,5);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -886,7 +762,7 @@ else if(0 && (scmd.tag[1] == 'r') && (scmd.tag[2] == 'z')){
|
|||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
memcpy(SERIAL_NO, m_config.serial_no, 12);
|
memcpy(SERIAL_NO, m_config.serial_no, 12);
|
||||||
ascii_format_data(ble_bin_buffer, "rrz:", SERIAL_NO, 12);
|
ascii_format_data(ble_bin_buffer, "rrz:", SERIAL_NO, 12);
|
||||||
binary_tx_handler(ble_bin_buffer, 8);
|
dr_binary_tx_safe(ble_bin_buffer, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 // ===== EEPROM start block =====
|
#if 0 // ===== EEPROM start block =====
|
||||||
@@ -941,7 +817,7 @@ else if(0 && (scmd.tag[1] == 'r') && (scmd.tag[2] == 'z')){
|
|||||||
// } else if(cmd_t == CMD_BLE) {
|
// } else if(cmd_t == CMD_BLE) {
|
||||||
//// sprintf(ble_tx_buffer, "Tz3,%s\r\n",read_data
|
//// sprintf(ble_tx_buffer, "Tz3,%s\r\n",read_data
|
||||||
// ascii_format_data(ble_bin_buffer, "rcz:", "ok",3);
|
// ascii_format_data(ble_bin_buffer, "rcz:", "ok",3);
|
||||||
// binary_tx_handler(ble_bin_buffer,5);
|
// dr_binary_tx_safe(ble_bin_buffer,5);
|
||||||
//// data_tx_handler(ble_tx_buffer);
|
//// data_tx_handler(ble_tx_buffer);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@@ -969,7 +845,7 @@ else if(0 && (scmd.tag[1] == 'r') && (scmd.tag[2] == 'z')){
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// format_data_byte(ble_bin_buffer, "rdz:", read_data,64);
|
// format_data_byte(ble_bin_buffer, "rdz:", read_data,64);
|
||||||
// binary_tx_handler(ble_bin_buffer,34);
|
// dr_binary_tx_safe(ble_bin_buffer,34);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
@@ -981,26 +857,11 @@ else if(0 && (scmd.tag[1] == 'r') && (scmd.tag[2] == 'z')){
|
|||||||
// sez
|
// sez
|
||||||
else if((scmd.tag[1] == 'e') && (scmd.tag[2] == 'z')){ // Read, Serial Number
|
else if((scmd.tag[1] == 'e') && (scmd.tag[2] == 'z')){ // Read, Serial Number
|
||||||
|
|
||||||
hw_i2c_init_once();
|
/* AGC gain array — AD5272/MCP4725 HW 제거됨, 명령 비활성화 - jhChun 26.03.16 */
|
||||||
|
|
||||||
uint16_t write_data[64];
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < 48; i++) {
|
|
||||||
write_data[i]= (uint16_t)(scmd.values[i*2+7] | (uint16_t)(scmd.values[i*2+6] << 8));
|
|
||||||
}
|
|
||||||
|
|
||||||
eeprom_write_uint16_array(scmd.value0,write_data,48);
|
|
||||||
|
|
||||||
|
|
||||||
if(cmd_t == CMD_UART) {
|
if(cmd_t == CMD_UART) {
|
||||||
DBG_PRINTF("rez,%s\r\n\r\n", scmd.value_ascii);
|
DBG_PRINTF("sez: HW not present\r\n");
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
|
param_error(scmd.tag);
|
||||||
|
|
||||||
|
|
||||||
format_data(ble_bin_buffer, "rez:", write_data,48);
|
|
||||||
binary_tx_handler(ble_bin_buffer,50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1016,26 +877,11 @@ else if((scmd.tag[1] == 'f') && (scmd.tag[2] == 'z')){ // Read, Ser
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
else{
|
else{
|
||||||
|
/* AGC gain array — AD5272/MCP4725 HW 제거됨, 명령 비활성화 - jhChun 26.03.16 */
|
||||||
hw_i2c_init_once();
|
|
||||||
uint16_t read_data[64];
|
|
||||||
//uint8_t EEPread_data[64];
|
|
||||||
|
|
||||||
|
|
||||||
eeprom_read_uint16_array(scmd.value0,read_data,48); //int16(48ea) DP Preset 0~6
|
|
||||||
// for (int i = 0; i < 48; i++) {
|
|
||||||
// EEPread_data[i]= (uint8_t)(read_data[i]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
if(cmd_t == CMD_UART) {
|
if(cmd_t == CMD_UART) {
|
||||||
DBG_PRINTF("ref,%s\r\n\r\n", scmd.value_ascii);
|
DBG_PRINTF("sfz: HW not present\r\n");
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
|
param_error(scmd.tag);
|
||||||
|
|
||||||
|
|
||||||
format_data(ble_bin_buffer, "rfz:", read_data,48);
|
|
||||||
binary_tx_handler(ble_bin_buffer,50);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1046,7 +892,7 @@ else if(0 && (scmd.tag[1] == 'i') && (scmd.tag[2] == 'z')){
|
|||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
memcpy(HW_NO, m_config.hw_no, 12);
|
memcpy(HW_NO, m_config.hw_no, 12);
|
||||||
ascii_format_data(ble_bin_buffer, "riz:", HW_NO, 12);
|
ascii_format_data(ble_bin_buffer, "riz:", HW_NO, 12);
|
||||||
binary_tx_handler(ble_bin_buffer, 8);
|
dr_binary_tx_safe(ble_bin_buffer, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// shz - Write HW Number (FDS only) — DISABLED: use mwh? in pc_firm/parser.c
|
// shz - Write HW Number (FDS only) — DISABLED: use mwh? in pc_firm/parser.c
|
||||||
@@ -1063,7 +909,7 @@ else if(0 && (scmd.tag[1] == 'h') && (scmd.tag[2] == 'z')){
|
|||||||
config_save();
|
config_save();
|
||||||
DBG_PRINTF("[shz] HW=%s saved to FDS\r\n", m_config.hw_no);
|
DBG_PRINTF("[shz] HW=%s saved to FDS\r\n", m_config.hw_no);
|
||||||
ascii_format_data(ble_bin_buffer, "rhz:", scmd.value_ascii,12);
|
ascii_format_data(ble_bin_buffer, "rhz:", scmd.value_ascii,12);
|
||||||
binary_tx_handler(ble_bin_buffer,8);
|
dr_binary_tx_safe(ble_bin_buffer,8);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
DBG_PRINTF("ERR!!! HW_NO 12\r\n\r\n");
|
DBG_PRINTF("ERR!!! HW_NO 12\r\n\r\n");
|
||||||
@@ -1091,10 +937,10 @@ else if((scmd.tag[1] == 'x') && (scmd.tag[2] == 'z')){ // Set the delay for
|
|||||||
if(cmd_t == CMD_UART) {
|
if(cmd_t == CMD_UART) {
|
||||||
DBG_PRINTF("rxz\r\n\r\n");
|
DBG_PRINTF("rxz\r\n\r\n");
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
hw_i2c_init_once();
|
m_config.life_cycle = m_life_cycle;
|
||||||
eeprom_write_uint32(0x0090, m_life_cycle);
|
config_save();
|
||||||
format_data(ble_bin_buffer, "rxz:", result_data,2);
|
format_data(ble_bin_buffer, "rxz:", result_data,2);
|
||||||
binary_tx_handler(ble_bin_buffer,4);
|
dr_binary_tx_safe(ble_bin_buffer,4);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(cmd_t == CMD_UART) {
|
if(cmd_t == CMD_UART) {
|
||||||
@@ -1121,7 +967,7 @@ else if((scmd.tag[1] == 'y') && (scmd.tag[2] == 'z')){ //
|
|||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
||||||
eeprom_read_uint32(0x0090, &m_life_cycle); //thnk cj
|
m_life_cycle = m_config.life_cycle;
|
||||||
|
|
||||||
result_data[0] = (uint16_t)(m_life_cycle >> 16);
|
result_data[0] = (uint16_t)(m_life_cycle >> 16);
|
||||||
result_data[1] = (uint16_t)(m_life_cycle & 0xFFFF);
|
result_data[1] = (uint16_t)(m_life_cycle & 0xFFFF);
|
||||||
@@ -1132,7 +978,7 @@ else if((scmd.tag[1] == 'y') && (scmd.tag[2] == 'z')){ //
|
|||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
|
|
||||||
format_data(ble_bin_buffer, "ryz:", result_data,4);
|
format_data(ble_bin_buffer, "ryz:", result_data,4);
|
||||||
binary_tx_handler(ble_bin_buffer,4);
|
dr_binary_tx_safe(ble_bin_buffer,4);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1145,7 +991,7 @@ else if((scmd.tag[1] == 'y') && (scmd.tag[2] == 'z')){ //
|
|||||||
DBG_PRINTF("ERR!!! UART Command Failed, %c%c%c%c\r\n",data_array[0], data_array[1], data_array[2], data_array[3]);
|
DBG_PRINTF("ERR!!! UART Command Failed, %c%c%c%c\r\n",data_array[0], data_array[1], data_array[2], data_array[3]);
|
||||||
} else if(cmd_t == CMD_BLE) {
|
} else if(cmd_t == CMD_BLE) {
|
||||||
single_format_data(ble_bin_buffer, "err!", err_code5);
|
single_format_data(ble_bin_buffer, "err!", err_code5);
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,6 @@
|
|||||||
#include "math.h"
|
#include "math.h"
|
||||||
#include "crc16.h" //add 25.04.23
|
#include "crc16.h" //add 25.04.23
|
||||||
#include "nrf_ble_lesc.h"
|
#include "nrf_ble_lesc.h"
|
||||||
#include "cat_interface.h"
|
|
||||||
#include "ir_i2c.h"
|
|
||||||
#include "nrf_crypto.h"
|
#include "nrf_crypto.h"
|
||||||
#include "nrf_pwr_mgmt.h"
|
#include "nrf_pwr_mgmt.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -43,23 +41,10 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "app_raw_main.h" //0117
|
#include "app_raw_main.h" //0117
|
||||||
#include "main_timer.h"
|
#include "main_timer.h"
|
||||||
#include "ad5272_i2c.h"
|
|
||||||
#include "ada2200_spi.h"
|
|
||||||
#include "power_control.h"
|
#include "power_control.h"
|
||||||
#include "tmp235_q1.h"
|
#include "tmp235_q1.h"
|
||||||
#include "mcp4725_i2c.h"
|
|
||||||
#include "measurements.h"
|
|
||||||
//#include "fstorage.h"
|
//#include "fstorage.h"
|
||||||
#include "battery_saadc.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 {
|
typedef struct {
|
||||||
char tag[5]; // Null-terminated 4-char command
|
char tag[5]; // Null-terminated 4-char command
|
||||||
uint16_t value0; // Data value
|
uint16_t value0; // Data value
|
||||||
@@ -82,7 +67,6 @@ bool is_valid_serial_no(const char *serial);
|
|||||||
|
|
||||||
|
|
||||||
bool is_valid_passkey(const char *passkey);
|
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(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);
|
bool crc16_check_packet(uint8_t const * packet, uint32_t packet_len);
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
// 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
|
|
||||||
@@ -78,6 +78,9 @@ void fds_default_value_set(void)
|
|||||||
/* Measurement parameters */
|
/* Measurement parameters */
|
||||||
m_config.pd_adc_cnt = 8;
|
m_config.pd_adc_cnt = 8;
|
||||||
m_config.pd_delay_us = 8000;
|
m_config.pd_delay_us = 8000;
|
||||||
|
|
||||||
|
/* Device usage count */
|
||||||
|
m_config.life_cycle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ typedef struct
|
|||||||
int8_t reset_status; /* 1B - Reset status */
|
int8_t reset_status; /* 1B - Reset status */
|
||||||
uint8_t pd_adc_cnt; /* 1B - ADC sample count */
|
uint8_t pd_adc_cnt; /* 1B - ADC sample count */
|
||||||
uint16_t pd_delay_us; /* 2B - PD delay (us) */
|
uint16_t pd_delay_us; /* 2B - PD delay (us) */
|
||||||
} config_data_t; /* Total: 41 bytes - FDS에 저장하는 디바이스 설정 */
|
uint32_t life_cycle; /* 4B - Device usage count (sxz/syz command) */
|
||||||
|
} config_data_t; /* Total: 45 bytes - FDS에 저장하는 디바이스 설정 */
|
||||||
|
|
||||||
extern config_data_t m_config;
|
extern config_data_t m_config;
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,34 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__ */
|
|
||||||
|
|
||||||
|
|
||||||
@@ -7,14 +7,41 @@
|
|||||||
#include "debug_print.h"
|
#include "debug_print.h"
|
||||||
#include "nrf_delay.h"
|
#include "nrf_delay.h"
|
||||||
|
|
||||||
#include "mcp4725_i2c.h"
|
|
||||||
#include "nrf_drv_twi.h"
|
#include "nrf_drv_twi.h"
|
||||||
#include "cat_interface.h"
|
#include "nrfx_twi.h"
|
||||||
|
#include "boards.h"
|
||||||
|
#include "system_interface.h"
|
||||||
|
|
||||||
bool HW_I2C_FRQ = true;
|
bool HW_I2C_FRQ = true;
|
||||||
bool SW_I2C_FRQ = false;
|
bool SW_I2C_FRQ = false;
|
||||||
|
|
||||||
/* 외부 EEPROM TWI 인스턴스 */
|
#define TWI_INSTANCE 0
|
||||||
extern const nrf_drv_twi_t m_eeprom;
|
|
||||||
|
/* TWI (I2C) 하드웨어 인스턴스 : IMU 드라이버에서 사용 - jhChun 26.03.16 */
|
||||||
|
const nrfx_twi_t m_twi = NRFX_TWI_INSTANCE(TWI_INSTANCE);
|
||||||
|
|
||||||
|
/* TWI (I2C) 해제 - jhChun 26.03.16 */
|
||||||
|
static void twi_uninitialize(void){
|
||||||
|
nrfx_twi_disable(&m_twi);
|
||||||
|
nrfx_twi_uninit(&m_twi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TWI (I2C) 하드웨어 초기화 (SCL/SDA핀, 400kHz) - jhChun 26.03.16 */
|
||||||
|
static void twi_initialize(void){
|
||||||
|
ret_code_t err_code;
|
||||||
|
|
||||||
|
const nrfx_twi_config_t twi_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_twi, &twi_config, NULL, NULL);
|
||||||
|
APP_ERROR_CHECK(err_code);
|
||||||
|
|
||||||
|
nrfx_twi_enable(&m_twi);
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* HW (TWI) 초기화 */
|
/* HW (TWI) 초기화 */
|
||||||
@@ -39,7 +66,7 @@ void hw_i2c_init_once(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 실제 HW 초기화
|
// 실제 HW 초기화
|
||||||
eeprom_initialize();
|
twi_initialize();
|
||||||
nrf_delay_ms(2);
|
nrf_delay_ms(2);
|
||||||
|
|
||||||
HW_I2C_FRQ = true;
|
HW_I2C_FRQ = true;
|
||||||
@@ -58,8 +85,8 @@ void sw_i2c_init_once(void)
|
|||||||
{
|
{
|
||||||
//DBG_PRINTF("[I2C]HW→SW\r\n");
|
//DBG_PRINTF("[I2C]HW→SW\r\n");
|
||||||
|
|
||||||
nrf_drv_twi_disable(&m_eeprom);
|
nrfx_twi_disable(&m_twi);
|
||||||
nrf_drv_twi_uninit(&m_eeprom);
|
nrfx_twi_uninit(&m_twi);
|
||||||
nrf_delay_ms(2);
|
nrf_delay_ms(2);
|
||||||
|
|
||||||
HW_I2C_FRQ = false;
|
HW_I2C_FRQ = false;
|
||||||
@@ -73,9 +100,8 @@ void sw_i2c_init_once(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 실제 SW 초기화
|
// 실제 SW 초기화
|
||||||
eeprom_uninitialize(); // TWI 라인 해제
|
twi_uninitialize(); // TWI 라인 해제
|
||||||
nrf_delay_ms(1);
|
nrf_delay_ms(1);
|
||||||
mcp4725_init(); // Port BangBang 방식 DAC init
|
|
||||||
|
|
||||||
SW_I2C_FRQ = true;
|
SW_I2C_FRQ = true;
|
||||||
HW_I2C_FRQ = false;
|
HW_I2C_FRQ = false;
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ void imu_callback(inv_imu_sensor_event_t *event)
|
|||||||
ssp_data[5] = (uint16_t)gyro[2];
|
ssp_data[5] = (uint16_t)gyro[2];
|
||||||
format_data(imu_bin_buffer, "rsp:", ssp_data,12);
|
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]);
|
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);
|
dr_binary_tx_safe(imu_bin_buffer,8);
|
||||||
if(custom_add_data==true)
|
if(custom_add_data==true)
|
||||||
{
|
{
|
||||||
custom_add_data = false;
|
custom_add_data = false;
|
||||||
@@ -405,7 +405,7 @@ int imu_read_direct(void)
|
|||||||
ssp_data[5] = (uint16_t)gyro[2];
|
ssp_data[5] = (uint16_t)gyro[2];
|
||||||
|
|
||||||
format_data(imu_bin_buffer, "rsp:", ssp_data, 12);
|
format_data(imu_bin_buffer, "rsp:", ssp_data, 12);
|
||||||
binary_tx_handler(imu_bin_buffer, 8);
|
dr_binary_tx_safe(imu_bin_buffer, 8);
|
||||||
|
|
||||||
/* Put IMU back to sleep: accel OFF + gyro OFF */
|
/* Put IMU back to sleep: accel OFF + gyro OFF */
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
#include "nrf_delay.h"
|
#include "nrf_delay.h"
|
||||||
|
|
||||||
#include "app_util_platform.h"
|
#include "app_util_platform.h"
|
||||||
#include "meas_pd_48.h"
|
|
||||||
#include <cmd_parse.h>
|
#include <cmd_parse.h>
|
||||||
#include "i2c_manager.h"
|
#include "i2c_manager.h"
|
||||||
/* --------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include "system_interface.h"
|
#include "system_interface.h"
|
||||||
#include "nrf_delay.h"
|
#include "nrf_delay.h"
|
||||||
#include "meas_pd_48.h"
|
|
||||||
|
|
||||||
/* I2C number and slave address for INV device */
|
/* I2C number and slave address for INV device */
|
||||||
#define ICM_I2C_ADDR 0x68
|
#define ICM_I2C_ADDR 0x68
|
||||||
|
|||||||
@@ -1,168 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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.");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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_ */
|
|
||||||
|
|
||||||
@@ -64,29 +64,16 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "app_raw_main.h"
|
#include "app_raw_main.h"
|
||||||
#include "main_timer.h"
|
#include "main_timer.h"
|
||||||
#include "ad5272_i2c.h"
|
|
||||||
#include "ada2200_spi.h"
|
|
||||||
#include "power_control.h"
|
#include "power_control.h"
|
||||||
#include "tmp235_q1.h"
|
#include "tmp235_q1.h"
|
||||||
#include "mcp4725_i2c.h"
|
|
||||||
#include "measurements.h"
|
|
||||||
#include "fds.h"
|
#include "fds.h"
|
||||||
#include "battery_saadc.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"
|
|
||||||
|
|
||||||
#if FEATURE_SECURE_CONNECTION
|
#if FEATURE_SECURE_CONNECTION
|
||||||
#include "peer_manager.h"
|
#include "peer_manager.h"
|
||||||
#include "peer_manager_handler.h"
|
#include "peer_manager_handler.h"
|
||||||
#include "nrf_ble_lesc.h"
|
#include "nrf_ble_lesc.h"
|
||||||
#include "ble_quick_security.h"
|
#include "ble_quick_security.h"
|
||||||
#include "cat_interface.h"
|
|
||||||
#include "ir_i2c.h"
|
|
||||||
#include "i2c_manager.h"
|
#include "i2c_manager.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -150,7 +137,6 @@
|
|||||||
#define SEC_PARAM_MIN_KEY_SIZE 7
|
#define SEC_PARAM_MIN_KEY_SIZE 7
|
||||||
#define SEC_PARAM_MAX_KEY_SIZE 16
|
#define SEC_PARAM_MAX_KEY_SIZE 16
|
||||||
#define PASSKEY_TXT_LENGTH 8
|
#define PASSKEY_TXT_LENGTH 8
|
||||||
#define PASSKEY_LENGTH 6
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
@@ -217,18 +203,8 @@ extern bool go_sleep_mode_enter;
|
|||||||
extern bool go_NVIC_SystemReset;
|
extern bool go_NVIC_SystemReset;
|
||||||
extern bool ble_got_new_data;
|
extern bool ble_got_new_data;
|
||||||
extern bool motion_data_once;
|
extern bool motion_data_once;
|
||||||
extern bool adc_enabled;
|
|
||||||
extern bool con_single;
|
extern bool con_single;
|
||||||
extern bool info4;
|
extern bool info4;
|
||||||
extern uint16_t led_pd_dac_v[LED_NUM];
|
|
||||||
extern uint8_t pd_adc_count;
|
|
||||||
extern int8_t c_max;
|
|
||||||
extern uint8_t simple_samples_in_buffer;
|
|
||||||
extern uint8_t full_samples_in_buffer;
|
|
||||||
extern uint8_t custom_samples_in_buffer;
|
|
||||||
extern bool pd_adc_custom_a_start;
|
|
||||||
extern bool pd_adc_custom_start;
|
|
||||||
extern bool full_agc_a_start;
|
|
||||||
extern uint8_t add_cycle;
|
extern uint8_t add_cycle;
|
||||||
extern bool motion_raw_data_enabled;
|
extern bool motion_raw_data_enabled;
|
||||||
|
|
||||||
@@ -247,13 +223,11 @@ bool erase_bonds;
|
|||||||
volatile bool ble_connection_st;
|
volatile bool ble_connection_st;
|
||||||
volatile bool data_tx_in_progress = false;
|
volatile bool data_tx_in_progress = false;
|
||||||
|
|
||||||
extern char m_static_passkey[6];
|
extern char m_static_passkey[PASSKEY_LENGTH];
|
||||||
extern char SERIAL_NO[12];
|
extern char SERIAL_NO[SERIAL_NO_LENGTH];
|
||||||
extern bool bond_data_delete;
|
extern bool bond_data_delete;
|
||||||
uint8_t m_reset_status;
|
uint8_t m_reset_status;
|
||||||
|
|
||||||
extern uint8_t m_pd_adc_cnt;
|
|
||||||
extern uint16_t m_pd_delay_us;
|
|
||||||
extern uint32_t m_life_cycle;
|
extern uint32_t m_life_cycle;
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
@@ -306,14 +280,6 @@ static void full_gpio_init(void)
|
|||||||
{
|
{
|
||||||
minimal_gpio_init();
|
minimal_gpio_init();
|
||||||
|
|
||||||
LED_CONFIG();
|
|
||||||
LED_ALLOFF();
|
|
||||||
PD_CONFIG();
|
|
||||||
PD_ALLOFF();
|
|
||||||
trig_r_CONFIG();
|
|
||||||
trig_SW(false);
|
|
||||||
GAIN_SW_CONFIG();
|
|
||||||
AGC_GAIN_SW(false);
|
|
||||||
eeprom_control(OFF);
|
eeprom_control(OFF);
|
||||||
|
|
||||||
DBG_PRINTF("[GPIO] Full OK\r\n");
|
DBG_PRINTF("[GPIO] Full OK\r\n");
|
||||||
@@ -325,14 +291,12 @@ static void full_gpio_init(void)
|
|||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
static void load_default_config(void)
|
static void load_default_config(void)
|
||||||
{
|
{
|
||||||
memset(SERIAL_NO, 0, 16);
|
memset(SERIAL_NO, 0, SERIAL_NO_LENGTH);
|
||||||
memcpy(SERIAL_NO, FIRMWARE_SERIAL_NO, strlen(FIRMWARE_SERIAL_NO));
|
memcpy(SERIAL_NO, FIRMWARE_SERIAL_NO, strlen(FIRMWARE_SERIAL_NO));
|
||||||
|
|
||||||
memset(m_static_passkey, 0, 16);
|
memset(m_static_passkey, 0, PASSKEY_LENGTH);
|
||||||
memcpy(m_static_passkey, "123456", 6);
|
memcpy(m_static_passkey, "123456", PASSKEY_LENGTH);
|
||||||
|
|
||||||
m_pd_delay_us = 8000;
|
|
||||||
m_pd_adc_cnt = 8;
|
|
||||||
m_reset_status = 1;
|
m_reset_status = 1;
|
||||||
bond_data_delete = 1;
|
bond_data_delete = 1;
|
||||||
|
|
||||||
@@ -352,7 +316,7 @@ static void load_flash_config(void)
|
|||||||
|
|
||||||
/* Hardware Number — fill default if empty */
|
/* Hardware Number — fill default if empty */
|
||||||
if (m_config.hw_no[0] == 0 || m_config.hw_no[0] == (char)0xFF) {
|
if (m_config.hw_no[0] == 0 || m_config.hw_no[0] == (char)0xFF) {
|
||||||
memset(m_config.hw_no, 0, 12);
|
memset(m_config.hw_no, 0, HW_NO_LENGTH);
|
||||||
memcpy(m_config.hw_no, HARDWARE_VERSION, strlen(HARDWARE_VERSION));
|
memcpy(m_config.hw_no, HARDWARE_VERSION, strlen(HARDWARE_VERSION));
|
||||||
DBG_PRINTF("[CFG] HW empty, set default: %s\r\n", HARDWARE_VERSION);
|
DBG_PRINTF("[CFG] HW empty, set default: %s\r\n", HARDWARE_VERSION);
|
||||||
m_need_save_defaults = true;
|
m_need_save_defaults = true;
|
||||||
@@ -360,19 +324,19 @@ static void load_flash_config(void)
|
|||||||
|
|
||||||
/* Serial Number — fill default if empty */
|
/* Serial Number — fill default if empty */
|
||||||
if (m_config.serial_no[0] == 0 || m_config.serial_no[0] == (char)0xFF) {
|
if (m_config.serial_no[0] == 0 || m_config.serial_no[0] == (char)0xFF) {
|
||||||
memset(m_config.serial_no, 0, 12);
|
memset(m_config.serial_no, 0, SERIAL_NO_LENGTH);
|
||||||
memcpy(m_config.serial_no, FIRMWARE_SERIAL_NO, strlen(FIRMWARE_SERIAL_NO));
|
memcpy(m_config.serial_no, FIRMWARE_SERIAL_NO, strlen(FIRMWARE_SERIAL_NO));
|
||||||
DBG_PRINTF("[CFG] S/N empty, set default: %s\r\n", FIRMWARE_SERIAL_NO);
|
DBG_PRINTF("[CFG] S/N empty, set default: %s\r\n", FIRMWARE_SERIAL_NO);
|
||||||
m_need_save_defaults = true;
|
m_need_save_defaults = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Serial Number → BLE device name */
|
/* Serial Number → BLE device name */
|
||||||
memset(SERIAL_NO, 0, 16);
|
memset(SERIAL_NO, 0, SERIAL_NO_LENGTH);
|
||||||
memcpy(SERIAL_NO, m_config.serial_no, 12);
|
memcpy(SERIAL_NO, m_config.serial_no, SERIAL_NO_LENGTH);
|
||||||
|
|
||||||
/* Passkey */
|
/* Passkey */
|
||||||
memset(m_static_passkey, 0, 16);
|
memset(m_static_passkey, 0, PASSKEY_LENGTH);
|
||||||
memcpy(m_static_passkey, m_config.static_passkey, 6);
|
memcpy(m_static_passkey, m_config.static_passkey, PASSKEY_LENGTH);
|
||||||
|
|
||||||
/* Bond data delete flag */
|
/* Bond data delete flag */
|
||||||
bond_data_delete = m_config.bond_data_delete;
|
bond_data_delete = m_config.bond_data_delete;
|
||||||
@@ -380,52 +344,12 @@ static void load_flash_config(void)
|
|||||||
/* Reset status */
|
/* Reset status */
|
||||||
m_reset_status = m_config.reset_status;
|
m_reset_status = m_config.reset_status;
|
||||||
|
|
||||||
/* Measurement parameters (with validation) */
|
DBG_PRINTF("[CFG] HW=%.12s S/N=%s passkey=%.6s bond=%d rst=%d\r\n",
|
||||||
m_pd_adc_cnt = (m_config.pd_adc_cnt > 0 && m_config.pd_adc_cnt <= 32)
|
|
||||||
? m_config.pd_adc_cnt : 8;
|
|
||||||
m_pd_delay_us = (m_config.pd_delay_us > 0)
|
|
||||||
? m_config.pd_delay_us : 8000;
|
|
||||||
|
|
||||||
DBG_PRINTF("[CFG] HW=%.12s S/N=%s passkey=%.6s bond=%d rst=%d adc=%d delay=%u\r\n",
|
|
||||||
m_config.hw_no, SERIAL_NO, m_static_passkey, bond_data_delete,
|
m_config.hw_no, SERIAL_NO, m_static_passkey, bond_data_delete,
|
||||||
m_reset_status, m_pd_adc_cnt, m_pd_delay_us);
|
m_reset_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !DEBUG_MINIMAL_BOOT
|
/* load_eeprom_config() 삭제 — EEPROM 제거됨, FDS가 대체 - jhChun 26.03.16 */
|
||||||
static void load_eeprom_config(void)
|
|
||||||
{
|
|
||||||
DBG_PRINTF("[CFG] EEPROM loading...\r\n");
|
|
||||||
|
|
||||||
eeprom_initialize();
|
|
||||||
nrf_delay_us(10);
|
|
||||||
eeprom_init_values_read();
|
|
||||||
eeprom_uninitialize();
|
|
||||||
nrf_delay_us(50);
|
|
||||||
|
|
||||||
#if BLE_DEV_MODE
|
|
||||||
memset(SERIAL_NO, 0, 16);
|
|
||||||
memcpy(SERIAL_NO, FIRMWARE_SERIAL_NO, strlen(FIRMWARE_SERIAL_NO));
|
|
||||||
DBG_PRINTF("[CFG] DEV S/N=%s\r\n", SERIAL_NO);
|
|
||||||
#else
|
|
||||||
if (!is_valid_serial_no(SERIAL_NO))
|
|
||||||
{
|
|
||||||
memset(SERIAL_NO, 0, 16);
|
|
||||||
memcpy(SERIAL_NO, FIRMWARE_SERIAL_NO, strlen(FIRMWARE_SERIAL_NO));
|
|
||||||
}
|
|
||||||
|
|
||||||
char const init_pass[6] = "123456";
|
|
||||||
memset(m_static_passkey, 0, 16);
|
|
||||||
memcpy(m_static_passkey, (uint8_t *)init_pass, 6);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_pd_delay_us = 8000;
|
|
||||||
m_pd_adc_cnt = 8;
|
|
||||||
m_reset_status = 1;
|
|
||||||
bond_data_delete = BLE_DEV_MODE ? 1 : 0;
|
|
||||||
|
|
||||||
DBG_PRINTF("[CFG] EEPROM OK\r\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
* TIMER CALLBACKS
|
* TIMER CALLBACKS
|
||||||
@@ -468,11 +392,6 @@ static void timers_init(void)
|
|||||||
|
|
||||||
main_timer_init();
|
main_timer_init();
|
||||||
battery_timer_init();
|
battery_timer_init();
|
||||||
imm_check_timer_init();
|
|
||||||
m48_check_timer_init();
|
|
||||||
full_agc_timer_init();
|
|
||||||
full_agc_send_timer_init();
|
|
||||||
mea_send_timer_init();
|
|
||||||
power_timer_init();
|
power_timer_init();
|
||||||
|
|
||||||
#if FEATURE_PRINTF
|
#if FEATURE_PRINTF
|
||||||
@@ -879,8 +798,6 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
|
|||||||
|
|
||||||
if (device_status == true)
|
if (device_status == true)
|
||||||
{
|
{
|
||||||
LED_ALLOFF();
|
|
||||||
PD_ALLOFF();
|
|
||||||
if (device_sleep_mode() == 0)
|
if (device_sleep_mode() == 0)
|
||||||
{
|
{
|
||||||
device_status = false;
|
device_status = false;
|
||||||
@@ -1150,7 +1067,7 @@ void device_power_off(void)
|
|||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
* DATA TRANSMISSION
|
* DATA TRANSMISSION
|
||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
void data_tx_handler(char const *p_data_to_send)
|
void data_tx_handler(char const *p_data_to_send) // 문자열 (ASCII 텍스트) 전송 함수
|
||||||
{
|
{
|
||||||
if (m_tx_in_progress) return;
|
if (m_tx_in_progress) return;
|
||||||
|
|
||||||
@@ -1180,8 +1097,9 @@ void data_tx_handler(char const *p_data_to_send)
|
|||||||
m_conn_handle = BLE_CONN_HANDLE_INVALID;
|
m_conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||||
m_tx_in_progress = false;
|
m_tx_in_progress = false;
|
||||||
} else {
|
} else {
|
||||||
|
DBG_PRINTF("[BLE TX] Err:0x%X\r\n", err_code); // APP_ERROR_CHECK 대신 로그 - jhChun 26.03.16
|
||||||
m_tx_in_progress = false;
|
m_tx_in_progress = false;
|
||||||
APP_ERROR_CHECK(err_code);
|
//APP_ERROR_CHECK(err_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1245,46 +1163,10 @@ void ascii_format_data(uint8_t *buffer, const char *tag, const char *data_ascii,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void binary_tx_handler(uint8_t const *ble_bin_buff, uint16_t length)
|
|
||||||
{
|
|
||||||
uint32_t err_code;
|
|
||||||
static uint8_t tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0};
|
|
||||||
|
|
||||||
if (ble_connection_st == 0) return;
|
|
||||||
|
|
||||||
data_tx_in_progress = true;
|
|
||||||
|
|
||||||
if (length * sizeof(uint16_t) > (BLE_NUS_MAX_DATA_LEN - 2)) return;
|
|
||||||
|
|
||||||
if (ble_connection_st == BLE_CONNECTED_ST)
|
|
||||||
{
|
|
||||||
memcpy(tx_buffer, ble_bin_buff, length * sizeof(uint16_t));
|
|
||||||
uint16_t crc = crc16_compute(tx_buffer, length * sizeof(uint16_t), NULL);
|
|
||||||
tx_buffer[length * sizeof(uint16_t)] = (uint8_t)(crc & 0xFF);
|
|
||||||
tx_buffer[length * sizeof(uint16_t) + 1] = (uint8_t)((crc >> 8) & 0xFF);
|
|
||||||
|
|
||||||
uint16_t total_len = length * sizeof(uint16_t) + 2;
|
|
||||||
|
|
||||||
do {
|
|
||||||
err_code = ble_nus_data_send(&m_nus, tx_buffer, &total_len, m_conn_handle);
|
|
||||||
if ((err_code != NRF_ERROR_INVALID_STATE) &&
|
|
||||||
(err_code != NRF_ERROR_RESOURCES) &&
|
|
||||||
(err_code != NRF_ERROR_NOT_FOUND))
|
|
||||||
{
|
|
||||||
nrf_delay_ms(10);
|
|
||||||
}
|
|
||||||
APP_ERROR_CHECK(err_code);
|
|
||||||
} while (err_code == NRF_ERROR_RESOURCES);
|
|
||||||
|
|
||||||
data_tx_in_progress = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Safe BLE binary transmission with proper error handling
|
* @brief Safe BLE binary transmission with proper error handling
|
||||||
*
|
*
|
||||||
* Unlike binary_tx_handler which may assert on errors,
|
* Properly handles NRF_ERROR_RESOURCES by retrying
|
||||||
* this function properly handles NRF_ERROR_RESOURCES by retrying
|
|
||||||
* and returns gracefully on connection errors.
|
* and returns gracefully on connection errors.
|
||||||
*
|
*
|
||||||
* @param ble_bin_buff Data buffer to send
|
* @param ble_bin_buff Data buffer to send
|
||||||
@@ -1309,18 +1191,19 @@ void dr_sd_delay_ms(uint32_t ms)
|
|||||||
nrf_delay_ms(ms);
|
nrf_delay_ms(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length)
|
/* 기존 binary_tx_handler 함수 삭제 및 호출처 교체 - jhChun 26.03.16 */
|
||||||
|
void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length) // BLE로 바이너리 데이터를 안전하게 전송하는 함수
|
||||||
{
|
{
|
||||||
uint32_t err_code;
|
uint32_t err_code;
|
||||||
static uint8_t tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0};
|
static uint8_t tx_buffer[BLE_NUS_MAX_DATA_LEN] = {0};
|
||||||
uint16_t retry_count = 0;
|
uint16_t retry_count = 0;
|
||||||
const uint16_t MAX_RETRIES = 100; /* Max retries (~500ms at 5ms each) */
|
const uint16_t MAX_RETRIES = 100; /* Max retries (~500ms at 5ms each) */
|
||||||
|
|
||||||
if (ble_connection_st == 0) return;
|
if (ble_connection_st == 0) return; // 연결 확인
|
||||||
|
|
||||||
data_tx_in_progress = true;
|
data_tx_in_progress = true;
|
||||||
|
|
||||||
if (length * sizeof(uint16_t) > (BLE_NUS_MAX_DATA_LEN - 2)) {
|
if (length * sizeof(uint16_t) > (BLE_NUS_MAX_DATA_LEN - 2)) { // 길이 검증 (CRC 2바이트 공간 확보)
|
||||||
data_tx_in_progress = false;
|
data_tx_in_progress = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1328,9 +1211,9 @@ void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length)
|
|||||||
if (ble_connection_st == BLE_CONNECTED_ST)
|
if (ble_connection_st == BLE_CONNECTED_ST)
|
||||||
{
|
{
|
||||||
memcpy(tx_buffer, ble_bin_buff, length * sizeof(uint16_t));
|
memcpy(tx_buffer, ble_bin_buff, length * sizeof(uint16_t));
|
||||||
uint16_t crc = crc16_compute(tx_buffer, length * sizeof(uint16_t), NULL);
|
uint16_t crc = crc16_compute(tx_buffer, length * sizeof(uint16_t), NULL); // 버퍼 복사
|
||||||
tx_buffer[length * sizeof(uint16_t)] = (uint8_t)(crc & 0xFF);
|
tx_buffer[length * sizeof(uint16_t)] = (uint8_t)(crc & 0xFF);
|
||||||
tx_buffer[length * sizeof(uint16_t) + 1] = (uint8_t)((crc >> 8) & 0xFF);
|
tx_buffer[length * sizeof(uint16_t) + 1] = (uint8_t)((crc >> 8) & 0xFF); // CRC16 2바이트 추가
|
||||||
|
|
||||||
uint16_t total_len = length * sizeof(uint16_t) + 2;
|
uint16_t total_len = length * sizeof(uint16_t) + 2;
|
||||||
|
|
||||||
@@ -1339,27 +1222,26 @@ void dr_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length)
|
|||||||
uint16_t send_len = total_len; /* MUST reset each iteration - ble_nus_data_send modifies it! */
|
uint16_t send_len = total_len; /* MUST reset each iteration - ble_nus_data_send modifies it! */
|
||||||
err_code = ble_nus_data_send(&m_nus, tx_buffer, &send_len, m_conn_handle);
|
err_code = ble_nus_data_send(&m_nus, tx_buffer, &send_len, m_conn_handle);
|
||||||
|
|
||||||
if (err_code == NRF_SUCCESS) {
|
if (err_code == NRF_SUCCESS) { // 전송 성공 -> 루프 탈출
|
||||||
/* TX queued successfully */
|
/* TX queued successfully */
|
||||||
break;
|
break;
|
||||||
} else if (err_code == NRF_ERROR_RESOURCES) {
|
} else if (err_code == NRF_ERROR_RESOURCES) { // TX 큐가 가득 찬 경우 5ms 대기 후 재시도 (최대 100회, ~500ms)
|
||||||
/* BLE TX queue full - wait for connection event to complete TX */
|
/* BLE TX queue full - wait for connection event to complete TX */
|
||||||
/* Use small delay to allow BLE stack to process TX complete events */
|
/* Use small delay to allow BLE stack to process TX complete events */
|
||||||
nrf_delay_ms(5); /* Wait ~5ms for TX slot to free up */
|
nrf_delay_ms(5); /* Wait ~5ms for TX slot to free up */
|
||||||
retry_count++;
|
retry_count++;
|
||||||
} else if (err_code == NRF_ERROR_INVALID_STATE ||
|
} else if (err_code == NRF_ERROR_INVALID_STATE || err_code == NRF_ERROR_NOT_FOUND) { // 연결 끊김, 리턴
|
||||||
err_code == NRF_ERROR_NOT_FOUND) {
|
|
||||||
DBG_PRINTF("[BLE TX] Disconnected\r\n");
|
DBG_PRINTF("[BLE TX] Disconnected\r\n");
|
||||||
data_tx_in_progress = false;
|
data_tx_in_progress = false;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else { // 기타 에러 -> 로그 출력 후 리턴
|
||||||
DBG_PRINTF("[BLE TX] Err:0x%X\r\n", err_code);
|
DBG_PRINTF("[BLE TX] Err:0x%X\r\n", err_code);
|
||||||
data_tx_in_progress = false;
|
data_tx_in_progress = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} while (retry_count < MAX_RETRIES);
|
} while (retry_count < MAX_RETRIES);
|
||||||
|
|
||||||
if (retry_count >= MAX_RETRIES) {
|
if (retry_count >= MAX_RETRIES) { // 최대 재시도(100회) 초과 시 해당 패킷 드롭, 연결은 유지
|
||||||
DBG_PRINTF("[BLE TX] FAIL %u retries\r\n", retry_count);
|
DBG_PRINTF("[BLE TX] FAIL %u retries\r\n", retry_count);
|
||||||
data_tx_in_progress = false;
|
data_tx_in_progress = false;
|
||||||
/* Don't set ble_connection_st = 0 here - just drop this packet and continue */
|
/* Don't set ble_connection_st = 0 here - just drop this packet and continue */
|
||||||
@@ -1395,15 +1277,10 @@ static void main_s(void * p_context)
|
|||||||
power_control_handler(ON);
|
power_control_handler(ON);
|
||||||
nrf_delay_ms(100);
|
nrf_delay_ms(100);
|
||||||
bond_data_delete = true;
|
bond_data_delete = true;
|
||||||
eeprom_initialize();
|
m_config.bond_data_delete = (uint8_t)bond_data_delete;
|
||||||
nrf_delay_ms(10);
|
const char pass_init[PASSKEY_LENGTH] = "123456";
|
||||||
eeprom_write_byte(0x0060, (uint8_t)bond_data_delete);
|
memcpy(m_config.static_passkey, pass_init, PASSKEY_LENGTH);
|
||||||
nrf_delay_ms(20);
|
config_save();
|
||||||
const char pass_init[6] = "123456";
|
|
||||||
eeprom_write_encrypted(0x0020, (uint8_t *)pass_init, 6);
|
|
||||||
nrf_delay_ms(10);
|
|
||||||
eeprom_init_values_read();
|
|
||||||
eeprom_uninitialize();
|
|
||||||
nrf_delay_ms(1000);
|
nrf_delay_ms(1000);
|
||||||
go_device_power_off = true;
|
go_device_power_off = true;
|
||||||
main_timer_start();
|
main_timer_start();
|
||||||
@@ -1435,16 +1312,10 @@ static void main_s(void * p_context)
|
|||||||
advertising_start();
|
advertising_start();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ada2200_init();
|
|
||||||
nrf_delay_ms(1);
|
|
||||||
mcp4725_init();
|
|
||||||
nrf_delay_ms(1);
|
|
||||||
ad5272_i2c_init();
|
|
||||||
|
|
||||||
m_reset_status = 1;
|
m_reset_status = 1;
|
||||||
eeprom_write_byte(0x0065, m_reset_status);
|
m_config.reset_status = m_reset_status;
|
||||||
nrf_delay_ms(10);
|
config_save();
|
||||||
eeprom_init_values_read();
|
|
||||||
#endif
|
#endif
|
||||||
m_reset_status = 1;
|
m_reset_status = 1;
|
||||||
DBG_PRINTF("[BOOT] Ready\r\n");
|
DBG_PRINTF("[BOOT] Ready\r\n");
|
||||||
|
|||||||
@@ -9,6 +9,13 @@
|
|||||||
#ifndef MAIN_H__
|
#ifndef MAIN_H__
|
||||||
#define MAIN_H__
|
#define MAIN_H__
|
||||||
|
|
||||||
|
/*==============================================================================
|
||||||
|
* DATA LENGTH CONSTANTS
|
||||||
|
*============================================================================*/
|
||||||
|
#define SERIAL_NO_LENGTH 12
|
||||||
|
#define HW_NO_LENGTH 12
|
||||||
|
#define PASSKEY_LENGTH 6
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -54,7 +61,6 @@ static void PM_s(void * p_context);
|
|||||||
static void main_routine_handler(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 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 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_binary_tx_safe(uint8_t const *ble_bin_buff, uint16_t length);
|
||||||
void dr_sd_delay_ms(uint32_t ms);
|
void dr_sd_delay_ms(uint32_t ms);
|
||||||
void single_format_data(uint8_t *buffer, const char *tag, const uint16_t value) ;
|
void single_format_data(uint8_t *buffer, const char *tag, const uint16_t value) ;
|
||||||
|
|||||||
@@ -28,14 +28,8 @@
|
|||||||
#include "main_timer.h"
|
#include "main_timer.h"
|
||||||
#include "tmp235_q1.h"
|
#include "tmp235_q1.h"
|
||||||
//#include "fstorage.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 "power_control.h"
|
||||||
#include <cmd_parse.h>
|
#include <cmd_parse.h>
|
||||||
#include "meas_pd_48.h"
|
|
||||||
#include "debug_print.h"
|
#include "debug_print.h"
|
||||||
#include "i2c_manager.h" //add cj
|
#include "i2c_manager.h" //add cj
|
||||||
APP_TIMER_DEF(m_main_loop_timer_id);
|
APP_TIMER_DEF(m_main_loop_timer_id);
|
||||||
@@ -55,15 +49,12 @@ extern which_cmd_t cmd_type_t;
|
|||||||
#endif
|
#endif
|
||||||
bool go_batt= false;
|
bool go_batt= false;
|
||||||
bool go_temp= false;
|
bool go_temp= false;
|
||||||
bool go_pdread= false;
|
|
||||||
bool go_device_power_off = false;
|
bool go_device_power_off = false;
|
||||||
bool go_sleep_mode_enter = false;
|
bool go_sleep_mode_enter = false;
|
||||||
bool go_NVIC_SystemReset = false;
|
bool go_NVIC_SystemReset = false;
|
||||||
bool motion_raw_data_enabled = false;
|
bool motion_raw_data_enabled = false;
|
||||||
bool ble_got_new_data = false;
|
bool ble_got_new_data = false;
|
||||||
bool motion_data_once = 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 */
|
void main_loop(void * p_context) /* For x ms */
|
||||||
{
|
{
|
||||||
UNUSED_PARAMETER(p_context);
|
UNUSED_PARAMETER(p_context);
|
||||||
@@ -148,30 +139,6 @@ void main_loop(void * p_context) /* For x ms */
|
|||||||
// main_timer_start();
|
// 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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();
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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_ */
|
|
||||||
|
|
||||||
@@ -1,513 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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;
|
|
||||||
//}
|
|
||||||
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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_ */
|
|
||||||
|
|
||||||
@@ -1,913 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__ */
|
|
||||||
|
|
||||||
@@ -1,785 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__ */
|
|
||||||
|
|
||||||
@@ -1,522 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__ */
|
|
||||||
|
|
||||||
@@ -1,885 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__ */
|
|
||||||
|
|
||||||
@@ -1,944 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__ */
|
|
||||||
|
|
||||||
@@ -1,836 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__ */
|
|
||||||
|
|
||||||
@@ -1,421 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__ */
|
|
||||||
|
|
||||||
@@ -1,867 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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));
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,666 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__
|
|
||||||
|
|
||||||
@@ -1,657 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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));
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,519 +0,0 @@
|
|||||||
/*******************************************************************************
|
|
||||||
* @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__
|
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -6,14 +6,41 @@
|
|||||||
#include "i2c_manager.h"
|
#include "i2c_manager.h"
|
||||||
#include "debug_print.h"
|
#include "debug_print.h"
|
||||||
#include "nrf_delay.h"
|
#include "nrf_delay.h"
|
||||||
#include "eeprom_driver.h"
|
|
||||||
#include "mcp4725_i2c.h"
|
|
||||||
#include "nrf_drv_twi.h"
|
#include "nrf_drv_twi.h"
|
||||||
#include "cat_interface.h"
|
#include "nrfx_twi.h"
|
||||||
|
#include "boards.h"
|
||||||
|
#include "system_interface.h"
|
||||||
|
|
||||||
bool HW_I2C_FRQ = false;
|
bool HW_I2C_FRQ = false;
|
||||||
bool SW_I2C_FRQ = false;
|
bool SW_I2C_FRQ = false;
|
||||||
|
|
||||||
extern const nrf_drv_twi_t m_eeprom;
|
#define TWI_INSTANCE 0
|
||||||
|
|
||||||
|
/* TWI (I2C) 하드웨어 인스턴스 : IMU 드라이버에서 사용 - jhChun 26.03.16 */
|
||||||
|
const nrfx_twi_t m_twi = NRFX_TWI_INSTANCE(TWI_INSTANCE);
|
||||||
|
|
||||||
|
/* TWI (I2C) 해제 - jhChun 26.03.16 */
|
||||||
|
static void twi_uninitialize(void){
|
||||||
|
nrfx_twi_disable(&m_twi);
|
||||||
|
nrfx_twi_uninit(&m_twi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TWI (I2C) 하드웨어 초기화 (SCL/SDA핀, 400kHz) - jhChun 26.03.16 */
|
||||||
|
static void twi_initialize(void){
|
||||||
|
ret_code_t err_code;
|
||||||
|
|
||||||
|
const nrfx_twi_config_t twi_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_twi, &twi_config, NULL, NULL);
|
||||||
|
APP_ERROR_CHECK(err_code);
|
||||||
|
|
||||||
|
nrfx_twi_enable(&m_twi);
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* HW (TWI) 초기화 */
|
/* HW (TWI) 초기화 */
|
||||||
@@ -34,7 +61,7 @@ void hw_i2c_init_once(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DBG_PRINTF("[I2C] Initializing HW (TWI) I2C...\r\n");
|
DBG_PRINTF("[I2C] Initializing HW (TWI) I2C...\r\n");
|
||||||
eeprom_initialize();
|
twi_initialize();
|
||||||
nrf_delay_ms(2);
|
nrf_delay_ms(2);
|
||||||
|
|
||||||
HW_I2C_FRQ = true;
|
HW_I2C_FRQ = true;
|
||||||
@@ -53,8 +80,8 @@ void sw_i2c_init_once(void)
|
|||||||
DBG_PRINTF("[I2C] HW I2C active -> switching to SW I2C\r\n");
|
DBG_PRINTF("[I2C] HW I2C active -> switching to SW I2C\r\n");
|
||||||
|
|
||||||
// HW 완전 종료
|
// HW 완전 종료
|
||||||
nrf_drv_twi_disable(&m_eeprom);
|
nrfx_twi_disable(&m_twi);
|
||||||
nrf_drv_twi_uninit(&m_eeprom);
|
nrfx_twi_uninit(&m_twi);
|
||||||
nrf_delay_ms(3);
|
nrf_delay_ms(3);
|
||||||
|
|
||||||
HW_I2C_FRQ = false; // 반드시 false로 갱신
|
HW_I2C_FRQ = false; // 반드시 false로 갱신
|
||||||
@@ -65,9 +92,8 @@ void sw_i2c_init_once(void)
|
|||||||
{
|
{
|
||||||
DBG_PRINTF("[I2C] Initializing SW (Port Bang-Bang) I2C...\r\n");
|
DBG_PRINTF("[I2C] Initializing SW (Port Bang-Bang) I2C...\r\n");
|
||||||
|
|
||||||
eeprom_uninitialize(); // SDA/SCL 해제
|
twi_uninitialize(); // SDA/SCL 해제
|
||||||
nrf_delay_ms(1);
|
nrf_delay_ms(1);
|
||||||
mcp4725_init(); // 소프트 I2C 초기화
|
|
||||||
|
|
||||||
SW_I2C_FRQ = true;
|
SW_I2C_FRQ = true;
|
||||||
HW_I2C_FRQ = false;
|
HW_I2C_FRQ = false;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
#include "nrf_log.h"
|
#include "nrf_log.h"
|
||||||
#include "app_timer.h"
|
#include "app_timer.h"
|
||||||
#include "debug_print.h"
|
#include "debug_print.h"
|
||||||
#include "cat_interface.h"
|
|
||||||
#include "i2c_manager.h"
|
#include "i2c_manager.h"
|
||||||
#define EEP_WP NRF_GPIO_PIN_MAP(0, 24)
|
#define EEP_WP NRF_GPIO_PIN_MAP(0, 24)
|
||||||
APP_TIMER_DEF(m_power_timer_id);
|
APP_TIMER_DEF(m_power_timer_id);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
#include "ble_nus.h"
|
#include "ble_nus.h"
|
||||||
#include "tmp235_q1.h"
|
#include "tmp235_q1.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "meas_pd_48.h"
|
|
||||||
#include <cmd_parse.h>
|
#include <cmd_parse.h>
|
||||||
#include "main_timer.h"
|
#include "main_timer.h"
|
||||||
#include "debug_print.h"
|
#include "debug_print.h"
|
||||||
@@ -42,7 +41,7 @@ extern uint8_t ble_bin_buffer[BLE_NUS_MAX_DATA_LEN] ;
|
|||||||
extern which_cmd_t cmd_type_t;
|
extern which_cmd_t cmd_type_t;
|
||||||
extern bool info4; //cmd_parse
|
extern bool info4; //cmd_parse
|
||||||
extern bool go_temp; //cmd_parse
|
extern bool go_temp; //cmd_parse
|
||||||
extern volatile uint16_t info_temp; //48_C
|
volatile uint16_t info_temp; //48_C
|
||||||
extern bool motion_raw_data_enabled;
|
extern bool motion_raw_data_enabled;
|
||||||
|
|
||||||
/**@brief Function for handling the ADC interrupt.
|
/**@brief Function for handling the ADC interrupt.
|
||||||
@@ -87,7 +86,7 @@ void tmp235_voltage_handler(nrf_drv_saadc_evt_t const * p_event) /* TMP325 Vout
|
|||||||
led_temp_16 = (uint16_t)(led_temp*100);
|
led_temp_16 = (uint16_t)(led_temp*100);
|
||||||
single_format_data(ble_bin_buffer, "rso:", led_temp_16);
|
single_format_data(ble_bin_buffer, "rso:", led_temp_16);
|
||||||
|
|
||||||
binary_tx_handler(ble_bin_buffer,3);
|
dr_binary_tx_safe(ble_bin_buffer,3);
|
||||||
|
|
||||||
// sprintf(ble_tx_buffer, "To%.2f\r\n",led_temp);
|
// sprintf(ble_tx_buffer, "To%.2f\r\n",led_temp);
|
||||||
// data_tx_handler(ble_tx_buffer);
|
// data_tx_handler(ble_tx_buffer);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
#define DR_PIEZO_FREQ_HZ 2100000 /**< Target frequency (set PIEZO_FREQ_MHZ in .c) */
|
#define DR_PIEZO_FREQ_HZ 2100000 /**< Target frequency (set PIEZO_FREQ_MHZ in .c) */
|
||||||
#define DR_PIEZO_DEFAULT_CYCLES 5 /**< Default burst cycles (3~5) */
|
#define DR_PIEZO_DEFAULT_CYCLES 5 /**< Default burst cycles (3~5) */
|
||||||
#define DR_PIEZO_MIN_CYCLES 3
|
#define DR_PIEZO_MIN_CYCLES 3
|
||||||
#define DR_PIEZO_MAX_CYCLES 10
|
#define DR_PIEZO_MAX_CYCLES 7 /* 3 -> 7 jhChun 26.03.12 */
|
||||||
#define DR_PIEZO_MUX_SETTLING_US 1300 /**< MUX settling delay (us) */
|
#define DR_PIEZO_MUX_SETTLING_US 1300 /**< MUX settling delay (us) */
|
||||||
|
|
||||||
/*==============================================================================
|
/*==============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user