From 5dc35425d5e255daf4aa9710d6b5d2a4e4e2b39d Mon Sep 17 00:00:00 2001 From: JayC319 Date: Fri, 22 Jul 2022 09:26:12 +0800 Subject: [PATCH] [update] ADC modulized done and ADC rx buffer revised --- .../cc26xx/app/hardware/adc_ads1118.h | 2 +- .../cc26xx/app/hardware/adc_ads1118_c.h | 11 ++-- .../app/headstage/EliteDeviceCorrection.h | 8 +-- .../cc26xx/app/headstage/EliteReset.h | 23 +------ .../cc26xx/app/headstage/EliteSPI.h | 12 +--- .../cc26xx/app/headstage/Elite_batt.h | 8 +-- .../cc26xx/app/headstage/Elite_mode_ADC_DAC.h | 62 +++++++++---------- .../cc26xx/app/headstage/Elite_version.h | 6 +- .../cc26xx/app/headstage/headstage.h | 8 +-- 9 files changed, 55 insertions(+), 85 deletions(-) diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/hardware/adc_ads1118.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/hardware/adc_ads1118.h index 3a31061..91daedb 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/hardware/adc_ads1118.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/hardware/adc_ads1118.h @@ -24,7 +24,7 @@ extern "C" { -uint8_t * read_adc_data(uint8_t AdcChannel); +uint16_t read_adc_data(uint8_t AdcChannel); #ifdef __cplusplus diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/hardware/adc_ads1118_c.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/hardware/adc_ads1118_c.h index 342aeb3..8afe158 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/hardware/adc_ads1118_c.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/hardware/adc_ads1118_c.h @@ -1,7 +1,7 @@ #include "hardware/adc_ads1118.h" -static uint8_t spi_ADC_txbuf_l[SPI_ADC_SIZE] = {0}; -static uint8_t spi_ADC_rxbuf_l[SPI_ADC_SIZE] = {0}; +static uint8_t spi_ADC_txbuf_l[2] = {0}; +static uint8_t spi_ADC_rxbuf_l[2] = {0}; static void __ADC_write(uint8_t ADCin) @@ -45,7 +45,7 @@ static void __ADC_read() uint8_t *rx = spi_ADC_rxbuf_l; uint8_t *tx = spi_ADC_txbuf_l; - for (int i=0; i 1) return; - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); - MEAS_CURR(wm) = DecodeADCValue(instru.IinADCGainLv, RIS_ADC_IIN, spi_ADC_rxbuf); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); + MEAS_CURR(wm) = DecodeADCValue(instru.IinADCGainLv, RIS_ADC_IIN, ADC_rxbuf); if (instru.IinADCAutoGainEn) { AutoGainChangeIin(MEAS_CURR(wm), plot, &no_rec_time); @@ -223,8 +223,8 @@ static void read_Vin_change_gain(void) return; /* read Vin and do NOT record the Vin after changing gain twice */ - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VIN), sizeof(spi_ADC_rxbuf)); - MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLv, RIS_ADC_VIN, spi_ADC_rxbuf); + ADC_rxbuf = read_adc_data(ADC_CH_VIN); + MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLv, RIS_ADC_VIN, ADC_rxbuf); if (instru.VinADCAutoGainEn) { AutoGainChangeVin(MEAS_VIN(wm)); } else { @@ -251,8 +251,8 @@ static void read_Vout_change_gain(void) void *wm = wm_get(); /* read Vout and do NOT record the Vout after changing gain twice */ - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VOUT), sizeof(spi_ADC_rxbuf)); - MEAS_VOUT(wm) = DecodeADCValue(0, RIS_ADC_VOUT, spi_ADC_rxbuf); + ADC_rxbuf = read_adc_data(ADC_CH_VOUT); + MEAS_VOUT(wm) = DecodeADCValue(0, RIS_ADC_VOUT, ADC_rxbuf); if (volt_rec_en == false) { rec_cnt++; @@ -429,7 +429,7 @@ static void Iin_Vin_Vout_Plot(uint32_t time) if (batteryCheck_flag && tempCheck_flag) { read_adc_flag = EliteADCBattery(); if (!read_adc_flag) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); ADC_cnt = 5; } @@ -461,7 +461,7 @@ static void Iin_Vin_Vout_Plot(uint32_t time) ADC_cnt++; } else if (ADC_cnt == 1) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VIN), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VIN); ADC_cnt++; } else if (ADC_cnt == 2) { @@ -470,7 +470,7 @@ static void Iin_Vin_Vout_Plot(uint32_t time) ADC_cnt++; } else if (ADC_cnt == 3) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VOUT), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VOUT); ADC_cnt++; } else if (ADC_cnt == 4) { @@ -479,7 +479,7 @@ static void Iin_Vin_Vout_Plot(uint32_t time) ADC_cnt++; } else if (ADC_cnt == 5) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); ADC_cnt = 0; } @@ -496,7 +496,7 @@ static void Iin_Vin_Plot(void) if (batteryCheck_flag && tempCheck_flag) { read_adc_flag = EliteADCBattery(); if (!read_adc_flag) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); ADC_cnt = 3; } @@ -517,7 +517,7 @@ static void Iin_Vin_Plot(void) ADC_cnt++; } else if (ADC_cnt == 1) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VIN), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VIN); ADC_cnt++; } else if (ADC_cnt == 2) { @@ -526,7 +526,7 @@ static void Iin_Vin_Plot(void) ADC_cnt++; } else if (ADC_cnt == 3) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); ADC_cnt = 0; } @@ -547,7 +547,7 @@ static void IT_Plot(uint32_t time) if (batteryCheck_flag || tempCheck_flag) { read_adc_flag = EliteADCBattery(); if (!read_adc_flag) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); ADC_cnt = 1; } @@ -558,7 +558,7 @@ static void IT_Plot(uint32_t time) * 1 - read Iin and reset ADC_cnt */ if (ADC_cnt == 0) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); ADC_cnt++; return; @@ -590,7 +590,7 @@ static void VT_Plot(void) if (batteryCheck_flag && tempCheck_flag) { EliteADCBattery(); if (!batteryCheck_flag) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VIN), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VIN); ADC_cnt = 1; } @@ -601,7 +601,7 @@ static void VT_Plot(void) * 1 - read Vin and reset ADC_cnt */ if (ADC_cnt == 0) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VIN), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VIN); ADC_cnt++; return; @@ -627,7 +627,7 @@ static void Vout_Plot(void) if (batteryCheck_flag && tempCheck_flag) { EliteADCBattery(); if (!batteryCheck_flag) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VOUT), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VOUT); ADC_cnt = 1; } @@ -638,7 +638,7 @@ static void Vout_Plot(void) * 1 - read Vout and reset ADC_cnt */ if (ADC_cnt == 0) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VOUT), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VOUT); ADC_cnt++; return; @@ -673,8 +673,8 @@ static void cali_IT_plot(void) { if (instru.IinADCAutoGainEn) { MEAS_CURR(wm) = 0xFFFF; } else { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); - MEAS_CURR(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); + MEAS_CURR(wm) = (int32_t) ADC_rxbuf; if (lastIinADCGainLevel != instru.IinADCGainLv) { IinADCGainCtrl(instru.IinADCGainLv); } @@ -727,14 +727,14 @@ static void cali_IT_plot(void) { } if (ADC_cnt == 1) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); ADC_cnt++; return; } if (ADC_cnt == 2) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_CURR), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_CURR); ADC_cnt = 0; return; @@ -761,8 +761,8 @@ static void cali_VT_plot(void) { if (instru.VinADCAutoGainEn) { MEAS_VIN(wm) = 0xFFFF; } else { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VIN), sizeof(spi_ADC_rxbuf)); - MEAS_VIN(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]); + ADC_rxbuf = read_adc_data(ADC_CH_VIN); + MEAS_VIN(wm) = (int32_t) ADC_rxbuf; if (lastVinADCGainLv != instru.VinADCGainLv) VinADCGainCtrl(instru.VinADCGainLv); } @@ -813,14 +813,14 @@ static void cali_VT_plot(void) { } if (ADC_cnt == 1) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VIN), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VIN); ADC_cnt++; return; } if (ADC_cnt == 2) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VIN), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VIN); ADC_cnt = 0; return; @@ -844,8 +844,8 @@ static void cali_Vout_plot(void) { */ if (ADC_cnt == 0) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VOUT), sizeof(spi_ADC_rxbuf)); - MEAS_VOUT(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]); + ADC_rxbuf = read_adc_data(ADC_CH_VOUT); + MEAS_VOUT(wm) = (int32_t) ADC_rxbuf; if (volt_rec_en == false) { rec_cnt++; @@ -888,14 +888,14 @@ static void cali_Vout_plot(void) { } if (ADC_cnt == 1) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VOUT), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VOUT); ADC_cnt++; return; } if (ADC_cnt == 2) { - memcpy(spi_ADC_rxbuf, read_adc_data(ADC_CH_VOUT), sizeof(spi_ADC_rxbuf)); + ADC_rxbuf = read_adc_data(ADC_CH_VOUT); ADC_cnt = 0; return; diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h index b15ac14..d108840 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h @@ -4,9 +4,9 @@ #define VERSION_DATE_YEAR 22 #define VERSION_DATE_MONTH 7 -#define VERSION_DATE_DAY 19 -#define VERSION_DATE_HOUR 17 -#define VERSION_DATE_MINUTE 47 +#define VERSION_DATE_DAY 22 +#define VERSION_DATE_HOUR 9 +#define VERSION_DATE_MINUTE 26 // this is NOT the version hash !! // it's the last version hash diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h index c25341f..fd42850 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h @@ -1389,8 +1389,8 @@ static void update_ZM_instruction(uint8 *ins) { initCISBuf(); cis_buf[0] = 2; - cis_buf[1] = spi_ADC_rxbuf[0]; - cis_buf[2] = spi_ADC_rxbuf[1]; + cis_buf[1] = (uint8_t) ADC_rxbuf >> 8; + cis_buf[2] = (uint8_t) ADC_rxbuf; SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf); break; } @@ -1399,8 +1399,8 @@ static void update_ZM_instruction(uint8 *ins) { case 0x51: { initCISBuf(); cis_buf[0] = 2; - cis_buf[1] = spi_ADC_rxbuf[0]; - cis_buf[2] = spi_ADC_rxbuf[1]; + cis_buf[1] = (uint8_t) ADC_rxbuf >> 8; + cis_buf[2] = (uint8_t) ADC_rxbuf; SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf); break; }