Compare commits

..

224 Commits

Author SHA1 Message Date
Roy_01 44e886e5b5 [cali] new BOARD_EIS007/EIS010/EISM007/EISM008/EISM010/EISM011/EISM012/EISM013 calibration data. 2023-11-17 10:41:12 +08:00
Roy_01 1df00344cb [cali] new BOARD_EISM004/EISM005 calibration data. 2023-11-17 10:15:16 +08:00
Roy_01 dd7711dbcd [cali] new BOARD_EISM006 calibration data. 2023-10-04 14:00:48 +08:00
Roy_01 56a62a7832 [cali] new BOARD_EISM005 calibration data. 2023-10-03 09:45:21 +08:00
Roy_01 01fe904788 [cali] new BOARD_EIS006 calibration data. 2023-10-02 14:27:28 +08:00
Roy_01 c5bdf51133 [cali] new BOARD_EIS002 calibration data. 2023-09-28 11:26:20 +08:00
Roy 92ba1effda [cali] new BOARD_EIS007/EISM006/EISM007/EISM008 calibration data. 2023-06-28 09:04:03 +08:00
Roy e64054876e [cali] new BOARD_EIS08/EIS005/EIS006/EIS010 calibration data. 2023-06-16 10:04:43 +08:00
Roy d64c0e3e9c [cali] new BOARD_EISM005/EISM010/EISM011/EISM012/EISM013 calibration data. 2023-06-14 11:42:47 +08:00
Roy 1ef277eb20 [cali] update BOARD_EIS01/EIS07 calibration data. 2023-06-12 16:07:56 +08:00
Roy 86bd9a3bf5 [cali] clean cali data 2023-06-02 14:12:22 +08:00
Roy b6e46036fd [cali] update BOARD_EIS001/EIS002/EIS004 calibration data. 2023-06-02 13:55:49 +08:00
Roy 3f01eb24b0 Feat(#3): calibration data use CRC and cali version
https://www.notion.so/3-EIS-Controller-EIS-Controller-check-sum-5426fe5ccb024a9da73770bed559df65
2023-04-21 14:33:10 +08:00
Roy 38114fb6d2 Style: formatting notify info 2023-04-21 14:30:42 +08:00
Roy eee7b9f956 Other feat: new update elite version code 2023-04-21 14:09:37 +08:00
Roy 01bf272bbc [cali] update BOARD_EIS002/004/005/006/008/009/010/01/02/04/05 calibration data. 2023-04-17 16:03:24 +08:00
Roy 0904539315 [update] auto change gain for 8 hstia 2023-04-12 14:14:19 +08:00
Roy 10424c29a6 [cali] update BOARD_EIS001/03/06 calibration data. 2023-04-12 14:12:10 +08:00
Roy 125f007998 [update] update BOARD_CALI_BOARD parameter 2023-04-11 13:05:05 +08:00
Roy d10083ea05 [update] add to 8hstia 2023-04-10 18:23:49 +08:00
Roy d75d3ca15c [update] update cali package 2023-04-10 18:06:16 +08:00
Roy ad275857f4 [cali] update BOARD_EIS001/4/5/6/9/10 calibration data. 2023-04-10 11:49:02 +08:00
Roy 29ac10648a [update] update value of phase[gain][freq] & hstia_current[gain][freq] 2023-04-10 11:48:13 +08:00
Roy ce4587d58a [cali] update BOARD_EIS001/4/5/6/9/10 calibration data. 2023-04-07 12:54:55 +08:00
Roy deb08e758a [update] light green yellow when device disconnect 2023-04-06 14:59:19 +08:00
ROY f4f5afa2ca [update] update cali packet, use 4hstia calibration down 2023-03-31 16:12:01 +08:00
ROY 54aa4e44e1 [update] update hstia regeist value 2023-03-31 14:54:07 +08:00
ROY fff2e0ebfe [update] update cali packet 2023-03-31 14:39:02 +08:00
ROY 1001ce1964 [update] remove OffsetZero & CutoffFreq 2023-03-31 13:45:34 +08:00
ROY 7655469149 [update] remove setEIS_EIS() function 2023-03-31 13:40:42 +08:00
ROY c816d411d1 [update] cali LPTIA is purple light 2023-03-31 13:39:16 +08:00
ROY 23004fd4c3 [update] update parameter name of cali table 2023-03-31 13:37:28 +08:00
ROY ed414956ca [update] hstia pA->nA & hsrtia_b is 8bytes 2023-03-31 10:24:06 +08:00
ROY 4cc7989df9 [revert] go back to f2f1811eba 2023-03-31 09:43:48 +08:00
ROY 0aa7312a5e [update] fix 4 hstia 2023-03-27 11:11:08 +08:00
ROY 6da3c7881a [update] fix cali table for 4 hstia 2023-03-25 16:22:39 +08:00
ROY a69dad5b4a temp 2023-03-24 18:03:44 +08:00
ROY f2f1811eba [update] update hstia gain boundary 2023-03-23 14:21:34 +08:00
lai8928 5349be923d [update] add EIS002 cali data 2023-03-22 14:28:28 +08:00
ROY ffb14c3bca [update] hsrtia_a & hsrtia_b & hsrtia_c receive from elite is 5bytes 2023-03-22 13:41:40 +08:00
lai8928 19905f384a [update] add EIS001 & EIS010 cali data 2023-03-21 10:31:50 +08:00
lai8928 47046586c3 [update] fix DAC amp rolloff function 2023-03-16 11:16:26 +08:00
ROY 3dd5e2d8c4 [update] new cali amp function on 0xF8 2023-03-10 13:08:03 +08:00
lai8928 e4c16e003e [update] HSDAC_outputV func fix 2023-03-10 12:48:25 +08:00
ROY ed9010368f [update] DC bias Set Nzero = 30 2023-03-09 12:52:30 +08:00
ROY b45c6a7fa6 [update] update cali function and update eis/cf mode 2023-03-09 11:09:17 +08:00
ROY fcc1ac3020 cali AC dcbias 2023-03-07 11:40:54 +08:00
ROY 7ec507fc2e cali AC dcbias 2023-03-07 11:39:18 +08:00
ROY 9fdedc46d3 [update] add BOARD_EIS005_100K calibration data. 2023-02-23 09:41:15 +08:00
ROY 14d3f3730e [update] 230221 cali version 2023-02-23 09:28:33 +08:00
lai8928 13255847bb add ; in cali table 2023-02-22 14:25:03 +08:00
ROY 21285397fc add test function 2023-02-13 16:06:31 +08:00
lai8928 c9d46e2596 [update] add BOARD_EIS008 calibration data. 2023-02-09 18:02:05 +08:00
lai8928 45a0fd2407 [update] fix DC offset calibration gain(f5) add f6 2023-02-03 10:18:33 +08:00
lai8928 12448e324b [update] fix DC offset calibration gain 2023-02-02 10:24:22 +08:00
lai8928 f902b3b892 [update] LPTIA don't * (-1) 2023-01-12 15:40:01 +08:00
ROY a1172a93b8 [cali] add BOARD_EISM003 calibration data. 2022-12-29 18:14:10 +08:00
ROY ede480baf1 [cali] add BOARD_EISM001 calibration data. 2022-12-29 18:13:27 +08:00
ROY 26f51a9427 [cali] add BOARD_EIS002 calibration data. 2022-12-29 18:10:59 +08:00
ROY 570fae8f5f [update] Cali_LPTIA * (-1) 2022-12-23 12:04:18 +08:00
ROY f542b25e2e [update] update BOARD_CALI_BOARD value 2022-12-23 10:01:40 +08:00
ROY a64fa32d0b [update] reset hstia gain when using error gain 2022-12-23 09:51:09 +08:00
ROY 9b3891689d [update] eis -> cf in CF mode 2022-12-23 09:50:03 +08:00
ROY ad7cb37a20 [update] imagSum->avg_imag, realSum->avg_real 2022-12-20 17:39:11 +08:00
ROY b1a127d6a8 [update] fix automatic current stalls 2022-12-07 16:34:21 +08:00
ROY 412d18f559 [update] change gain 2022-12-07 16:33:22 +08:00
ROY 8953b0a64c [update] send Amplitude to master 2022-12-07 14:26:29 +08:00
ROY 3cd58a0aab [update] change gain flag 2022-12-06 10:33:42 +08:00
ROY e2602ef2da [update] fix DFT average value on cf mode 2022-12-05 17:16:06 +08:00
ROY 57e3f5573d [update] fix Cali_HSAMP data type 2022-11-29 17:44:45 +08:00
ROY 262df2b662 [update] fix 0xF5 instruction 2022-11-29 11:23:47 +08:00
ROY 23349cc4ba [cali] add BOARD_EIS02 calibration data. 2022-11-29 11:23:11 +08:00
ROY fcf1dd5d6b [update] set Amp register can't > 2047 2022-11-29 09:26:40 +08:00
ROY 014a2aded3 [update] fix 0xF5 instruction 2022-11-29 09:25:21 +08:00
ROY c7ed0f9be3 [update] use cali Amp 2022-11-29 09:24:12 +08:00
ROY f2db9cdac8 [update] note setting of eis mode 2022-11-25 14:40:32 +08:00
ROY 98a98120a2 [update] fix avg_real & avg_imag formula 2022-11-25 11:43:05 +08:00
ROY 4fa47c35c9 [update] change sort eis/cf plot 2022-11-23 10:35:50 +08:00
ROY 70f758c3b9 [update] to sort hstia's DFT register 2022-11-22 17:20:10 +08:00
ROY 8b367de5bb [update] add BOARD_EISM008 & BOARD_EISM009 calibration data. 2022-11-22 11:48:39 +08:00
ROY 80c84295b3 [update] fix dely time of eis mode & hstia formula 2022-11-22 11:03:04 +08:00
ROY 9c67a4e2b7 [update] add BOARD_EIS008 & BOARD_EIS01 calibration data. 2022-11-22 09:16:03 +08:00
lai8928 14ef751386 add BOARD_EIS004 calibration data. 2022-11-18 09:53:54 +08:00
lai8928 927bef21bf add BOARD_EIS002 & BOARD_EIS006 calibration data. 2022-11-17 16:49:35 +08:00
lai8928 8bfea5cb38 [cali] add BOARD_EIS001 calibration data. 2022-11-16 11:17:00 +08:00
ROY 71272c6f8d [update] new cf mode 2022-11-16 11:09:32 +08:00
ROY ebc30595e5 [update] update highz instruction 2022-11-15 17:30:02 +08:00
ROY 4243614dd8 [update] remove EIS_LPTIA instruction 2022-11-15 17:20:48 +08:00
ROY 7713cb57d3 [update] new lprtia function 2022-11-15 15:41:08 +08:00
ROY 245a5919ff [update] fix img & real value 2022-11-15 11:07:28 +08:00
ROY 3d8068fb18 [update] modify cali instruction 2022-11-09 17:47:04 +08:00
ROY d2b88920a0 Merge commit '7938d72e1625c1c48bb8784b13b54d1185348658' into dev/merge-eis_mode-cali-func 2022-11-09 17:28:46 +08:00
ROY 2c51a41cb8 [update] send hsrtia & lprtia gain level 2022-11-09 17:18:44 +08:00
lai8928 7938d72e16 cali table set 2022-11-09 16:32:53 +08:00
ROY ee3b6c8f6f [update] new hsrtia function 2022-11-09 16:02:38 +08:00
ROY c617910ea5 [update] update eis instruction 2022-11-08 17:54:42 +08:00
ROY 8e414f717d [update] update number of mode 2022-11-08 17:28:29 +08:00
lai8928 e2c255107d elite ADC hstia_c 2022-11-07 15:26:04 +08:00
ROY acca41ac6b [update] fix freq for eis mode 2022-11-04 17:30:17 +08:00
ROY a3eda0b1e0 [update] update workmode 2022-11-04 10:35:42 +08:00
ROY a63818ce44 [update] update workmode 2022-11-04 09:56:38 +08:00
ROY 584e17b3b9 [update] update workmode 2022-11-04 09:36:25 +08:00
ROY 1a2f0ba813 [update] update workmode 2022-11-03 17:48:06 +08:00
ROY a63a085ff3 [update] update workmode 2022-11-03 17:28:03 +08:00
lai8928 3121aa49f2 add EIS002 amp rolloff 2022-11-03 11:48:04 +08:00
lai8928 7a8d7aa14f p 2022-11-02 16:41:38 +08:00
lai8928 5b0c38159a Merge remote-tracking branch 'origin/elite/eis1.1' into eis_10test 2022-11-02 15:34:09 +08:00
lai8928 7a4c7ef02c SetWGAmp 2022-11-02 13:38:51 +08:00
ROY d9a7152d73 [update] update headstage file 2022-10-31 17:20:04 +08:00
ROY 166b466776 [update] short instruction for RT mode 2022-10-27 17:08:40 +08:00
ROY 32a7580115 [update] update RT mode 2022-10-27 16:13:58 +08:00
ROY c6aca9c17b [update] update cali_table define 2022-10-27 11:13:20 +08:00
ROY 2eddaf000b [update] update cali value for BOARD_EIS002, BOARD_EIS005, BOARD_EIS006, BOARD_EIS007 and BOARD_EISM001~BOARD_EISM008. 2022-10-27 11:11:04 +08:00
ROY 472b559293 [update] new RT mode 2022-10-25 13:40:21 +08:00
lai8928 b0076cb246 DAC rolloff (uncomplete) 2022-10-24 17:21:34 +08:00
lai8928 ed48823e10 cali value 2022-10-24 10:07:59 +08:00
lai8928 8a72c5a150 [cali] update cali table 2022-10-07 14:50:25 +08:00
ROY f32584d6e8 [cali] update cali table 2022-10-07 10:50:23 +08:00
ROY da7d227ee4 [cali] update cali table 2022-10-07 10:49:08 +08:00
ROY 01d5f76223 [update] new VT mode 2022-10-06 16:24:11 +08:00
ROY 1a2e85ccad [update] update instruction 2022-10-04 18:06:23 +08:00
ROY 995b8033b6 [cali] cali DAC 2022-10-04 17:11:37 +08:00
ROY 6c204ad3fd [cali] cali v1 2022-10-03 16:36:53 +08:00
ROY cb8590933e [update] fix RTIA gain 2022-09-30 14:28:27 +08:00
ROY e48d8c8d2f [cali] remove not correct cali data 2022-09-30 14:27:15 +08:00
ROY 80929a01a8 [update] update cali value 2022-09-28 14:52:24 +08:00
ROY ca9a6bba52 [cali] update BOARD_EIS003 calibration data. 2022-09-27 15:03:46 +08:00
ROY 991dfa7768 [cali] add DAC cali value 2022-09-26 11:02:18 +08:00
ROY 18954b9fbd [cali] add DAC cali value 2022-09-23 10:17:12 +08:00
ROY 65326acda2 [cali] add DAC cali value 2022-09-23 10:10:18 +08:00
ROY ca7da62fad [update] cali mode of eis on CS2.0 v1 2022-09-19 17:16:08 +08:00
ROY 18201de597 [update] fix cali function 2022-09-19 16:17:48 +08:00
ROY a52486e9da [update] fix cali function 2022-09-19 16:16:30 +08:00
ROY 79dc88a9d7 [update] update BOARD_3 cali info, but LPTIA isn't well. 2022-09-19 11:36:28 +08:00
ROY fd6b005b02 [update] update BOARD_E7DD cali info 2022-09-16 17:42:00 +08:00
ROY 4181dae796 [update] fix cali function 2022-09-16 10:51:36 +08:00
ROY 505d5b9922 [update] fix amp 2022-09-07 12:07:54 +08:00
ROY eb8d745280 [update] fix amp 2022-09-05 11:34:04 +08:00
ROY effca2053f [update] fix amp 2022-09-05 10:58:16 +08:00
ROY 59f39871d3 [update] fix dcbias on eis mode finished 2022-09-01 18:56:12 +08:00
ROY 1dcc8772b5 [update] fix dcbias on eis mode 2022-09-01 18:13:11 +08:00
ROY cf417afd16 [update] fix dcbias on eis mode 2022-09-01 11:23:16 +08:00
ROY 60d135cd03 [update] fix hstia gain 2022-08-19 19:17:29 +08:00
ROY 1d1bd518f0 [update] update gain name 2022-08-19 17:29:06 +08:00
ROY 8409c0b700 [update] update gain name 2022-08-19 16:16:10 +08:00
ROY 3f034761d6 [update] update version time 2022-08-18 11:36:24 +08:00
ROY 48a8bae1ea Merge branch 'dev/eis1.1/fix_auto_gain' into elite/eis1.1 2022-08-18 10:59:48 +08:00
ROY 625a8c74e3 [update] fix Cali_LPTIA positive and negative current 2022-08-18 10:57:29 +08:00
ROY b343d3d932 [update] fix LPDAC positive and negative voltage 2022-08-18 09:55:07 +08:00
ROY 2aa566c0d4 [update] fix auto gain 2022-08-17 16:50:13 +08:00
ROY 4e56f8dfef [update] merge eis mini 1.0 code 2022-08-05 17:37:11 +08:00
ROY 853ba4008e [update] fix SET_ADC_DAC_GAIN instruction 2022-08-05 17:18:03 +08:00
ROY 843e5e98de [update] update model name 2022-08-05 16:31:04 +08:00
Benny Liu 6fcace98b2 Clean up code. 2022-08-05 15:37:00 +08:00
ROY 8bbc749529 [update] clean up the code 2022-08-05 12:02:46 +08:00
ROY 466df110c9 Merge branch 'dev/fix_eis1.1' into elite/eis1.1 2022-08-04 15:39:34 +08:00
ROY 7d4927b77f [update] ca mode 2022-08-04 14:20:19 +08:00
ROY 640b39b4be [update] clean up the code 2022-08-03 18:36:21 +08:00
ROY dcc71e2eee [update] update ctrl pin function 2022-08-03 18:10:27 +08:00
ROY 03910fce31 [update] clean up the code 2022-08-03 17:20:08 +08:00
ROY 8fb81fa0b6 [update] clean up the code 2022-08-03 17:01:31 +08:00
ROY 7e71e2d1a2 [update] clean up the code 2022-08-03 16:01:11 +08:00
ROY 397675b555 [update] clean up the code 2022-08-03 15:23:09 +08:00
ROY ffd84804d7 [update] clean up the code 2022-08-03 14:13:37 +08:00
ROY e4b67e14c6 [update] clean up the code 2022-08-03 12:05:47 +08:00
ROY 032efebe2a [update] update spi code 2022-08-03 11:10:29 +08:00
ROY 7b640757c8 [update] clean up the code 2022-08-03 11:00:21 +08:00
ROY 7951610b95 [update] update board name and product number 2022-08-03 10:32:26 +08:00
ROY 128ea6900f [update] update device info 2022-07-08 09:46:04 +08:00
ROY f3a0b38a67 [update] update device info function 2022-07-05 17:41:09 +08:00
ROY b914c1a191 [update] update board select file 2022-07-05 14:53:06 +08:00
ROY 94818213a3 [update] update device info function 2022-07-05 14:22:44 +08:00
ROY d63ecf71c5 [update] update ad5941 function 2022-06-30 18:39:15 +08:00
ROY 06bf610897 [update] update ad5941 function 2022-06-30 11:20:33 +08:00
ROY 58da7b6357 [update] take away edc correction 2022-06-23 09:55:23 +08:00
ROY 9bf87de46b [update] take away battery 2022-06-22 14:41:28 +08:00
ROY 95b5c11e95 [update] update ad5941 function 2022-06-22 13:55:28 +08:00
ROY a30e569738 [update] update led function 2022-06-22 10:10:19 +08:00
ROY d15afc6ab6 [update] update led function 2022-06-21 17:21:48 +08:00
ROY cf2a19d24e [update] update led function not ok 2022-06-20 16:39:12 +08:00
ROY fc89183fee [update] update led function 2022-06-20 14:41:13 +08:00
ROY 1aa26d9e1c [update] update spi function 2022-06-17 18:29:21 +08:00
ROY cac96f617f [update] update spi function 2022-06-17 16:48:51 +08:00
ROY 250a5e9d87 [update] update event 2022-06-17 16:30:30 +08:00
ROY 19a42da849 [update] update gp timer 2022-06-17 16:13:22 +08:00
ROY c9194c804e [update] update timer function 2022-06-17 15:59:52 +08:00
ROY 1ee6b2f434 [update] function of eis1.1 ctrl pin is finished 2022-06-16 18:19:52 +08:00
ROY 85c884ffb9 [update] include <Board.h> 2022-06-16 16:10:08 +08:00
ROY ec9050a090 [update] function of eis1.1 ctrl pin is finished 2022-06-16 14:54:25 +08:00
Benny Liu ef9271239a Modify calibration data 2022-06-15 18:09:13 +08:00
ROY a299a3e1c1 [update] update gpio ctrl 2022-06-15 16:02:09 +08:00
ROY 9cf2e2301d [update] gpio not finished 2022-06-15 11:53:33 +08:00
ROY fb6a437db8 Merge branch 'dev/elite/eis1.0/spi_2' into dev/elite/eis1.0/spi 2022-06-15 10:35:09 +08:00
Benny Liu 6bac8b436e Update E6F5 calibration data 2022-06-14 17:58:24 +08:00
ROY f09f3aa4a6 [update] pin config for eis 1.1 2022-06-14 14:49:11 +08:00
Benny Liu d7535075fd Update board calibration data 2022-06-14 14:04:07 +08:00
ROY 7ce59c43fe [update] pin config for eis 1.1 2022-06-14 13:34:19 +08:00
Benny Liu b54f79d51b Update board calibration data 2022-06-13 17:38:57 +08:00
ROY 91d71eabdc [update] pin config 2022-06-13 17:30:06 +08:00
ROY 34861b98af [update] pin config 2022-06-13 17:23:17 +08:00
ROY 7f8734d646 [update] pin config 2022-06-13 17:22:58 +08:00
Benny Liu 5922e8f2a1 LPDAC calibration function okay. 2022-06-09 18:24:05 +08:00
Benny Liu 7d93ed55bf Clean up calibration parameter name. 2022-06-09 13:46:27 +08:00
Benny Liu fe37d6a6eb EIS mode DC bias not working.
CV mode calibration and function okay.
2022-06-09 10:35:42 +08:00
Benny Liu 240c869347 calibration board 2022-06-07 18:09:51 +08:00
Benny Liu 75c8a9d985 Disconnect Vbias and Vzero. Modify comments. 2022-06-07 14:13:00 +08:00
Benny Liu c688ee4fda Add CV mode calibration parameters and modify calibration functions. 2022-06-06 18:17:48 +08:00
ROY d7c86b86a5 [update] calibrate SINC2 2022-06-06 09:56:15 +08:00
ROY 3174740201 not ok 2022-06-01 10:20:14 +08:00
Benny Liu b33ef1b345 Merge remote-tracking branch 'origin/elite/eis1.0' into elite/eis1.0
# Conflicts:
#	simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h
#	simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h
2022-05-31 09:48:14 +08:00
ROY 06b7317e31 [update] update current gain code 2022-05-30 14:14:05 +08:00
ROY fcbbee1dbe [update] update current gain code 2022-05-30 14:11:44 +08:00
Benny Liu 6d044e1fb8 LPTIA feedback resistor modify 2022-05-30 12:11:00 +08:00
ROY c58e30d973 [update] fix current gain 2022-05-30 10:36:38 +08:00
Benny Liu a7fb922fa0 Calibration factors for LPTIA. 2022-05-27 16:55:56 +08:00
Benny Liu 0d9e844383 TIA CV mode calibration. 2022-05-27 16:05:10 +08:00
Benny Liu 9b8307c0e2 Add DC bias for CV mode calibration. 2022-05-26 14:31:22 +08:00
Benny Liu 14d306e62c change reset pin to hardware EIS1.1 2022-05-26 10:07:54 +08:00
Benny Liu 8fd201751d clean up define 2022-05-26 10:00:40 +08:00
ROY be044cccb3 [update] DAC ok 2022-05-25 17:43:26 +08:00
ROY 7ea34044c8 fixed n_zero 2022-05-25 16:33:22 +08:00
ROY 09eeec1593 [update] fix DAC output of CV mode 2022-05-25 14:27:54 +08:00
Roy f3ddef1a3d [rel] elite/eis1.0 v.1.0.0 2022-05-04 10:15:21 +08:00
Roy fd966a503b [copy] copy af79c7fcac2237f25f92478b61e78b30f073dece version from wtp_cc2650_simple_func project 2022-05-03 11:35:36 +08:00
63 changed files with 24926 additions and 10351 deletions
-3
View File
@@ -1,4 +1 @@
simplelink/ble_sdk_2_02_02_25/examples/
simplelink/ble_sdk_2_02_02_25/src/common/cc26xx/ccs/
simplelink/ble_sdk_2_02_02_25/src/components/npi/src/
.vscode
@@ -50,7 +50,7 @@ extern "C" {
* ==========================================================================*/
#include <ti/drivers/PIN.h>
#include <driverlib/ioc.h>
#include "application_config/application_config.h"
#include "boards_config/elite_boards_select.h"
/** ============================================================================
* Externs
@@ -146,6 +146,12 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_UART_TX Board_BP_UART_Rx /* RXD */
#define Board_UART_RX Board_BP_UART_Tx /* TXD */
// /* SPI Board */
// #define Board_SPI0_MISO Board_BP_SPI_MISO
// #define Board_SPI0_MOSI Board_BP_SPI_MOSI
// #define Board_SPI0_CLK Board_BP_SPI_CLK
// #define Board_SPI0_CS Board_BP_SPI_CS_Wireless
/* Power Management Board */
#define Board_SRDY Board_BP_Pin_J2_19
#define Board_MRDY Board_BP_Pin_J1_2
@@ -160,27 +166,6 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_PWMPIN6 PIN_UNASSIGNED
#define Board_PWMPIN7 PIN_UNASSIGNED
/* SPI & I2C Board */
#ifndef DEF_ELITE_MODEL
#define Board_SPI0_MISO Board_BP_SPI_MISO
#define Board_SPI0_MOSI Board_BP_SPI_MOSI
#define Board_SPI0_CLK Board_BP_SPI_CLK
#define Board_SPI0_CS Board_BP_SPI_CS_Wireless
#else
#define Board_SPI0_MISO E_SPI0_MISO
#define Board_SPI0_MOSI E_SPI0_MOSI
#define Board_SPI0_CLK E_SPI0_CLK
#define Board_SPI0_CS E_SPI0_CS
#define Board_SPI1_MISO E_SPI1_MISO
#define Board_SPI1_MOSI E_SPI1_MOSI
#define Board_SPI1_CLK E_SPI1_CLK
#define Board_SPI1_CS E_SPI1_CS
#define Board_I2C0_SCL0 E_I2C0_SCL0
#define Board_I2C0_SDA0 E_I2C0_SDA0
#endif
/** ============================================================================
* Instance identifiers
* ==========================================================================*/
@@ -1,65 +0,0 @@
#ifndef ADGS1412X2_H
#define ADGS1412X2_H
#ifdef __cplusplus
extern "C" {
#endif
#define SIZE_OF_DAISY_CHAIN_COMMAND 2
struct switch_series_data_t {
uint8_t device8_switch;
uint8_t device7_switch;
uint8_t device6_switch;
uint8_t device5_switch;
uint8_t device4_switch;
uint8_t device3_switch;
uint8_t device2_switch;
uint8_t device1_switch;
}__attribute__((packed));
enum ADGS1412_SWITCH_ENABLE_e {
ALL_OPEN = 0x00, // 0b00000000
SINGLE_S1 = 0x01, // 0b00000001
SINGLE_S2 = 0x02, // 0b00000010
S1_S2_ON = 0x03, // 0b00000011
SINGLE_S3 = 0x04, // 0b00000100
S3_S1_ON = 0x05, // 0b00000101
S3_S2_ON = 0x06, // 0b00000110
S3_S2_S1_ON = 0x07, // 0b00000111
SINGLE_S4 = 0x08, // 0b00001000
S4_S1_ON = 0x09, // 0b00001001
S4_S2_ON = 0x0A, // 0b00001010
S4_S2_S1_ON = 0x0B, // 0b00001011
S4_S3_ON = 0x0C, // 0b00001100
S4_S3_S1_ON = 0x0D, // 0b00001101
S4_S3_S2_ON = 0x0E, // 0b00001110
ALL_ON = 0x0F, // 0b00001111
};
enum ADGS1412_module_e {
ADGS1412_MODULE_U14 = 0,
ADGS1412_MODULE_U13,
ADGS1412_MODULE_U18,
ADGS1412_MODULE_U20,
ADGS1412_MODULE_U26,
ADGS1412_MODULE_U29,
ADGS1412_MODULE_U22,
ADGS1412_MODULE_U24,
ADGS1412_MODULE_MAX,
};
static struct switch_series_data_t switch_series_data_g = {0};
int switch_ctrl(uint8_t switch_module_number, uint8_t enable_type);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,107 +0,0 @@
#include "application_config/application_config.h"
#include "HAL/cc2650_driver/spi_ctrl.h"
#include "HAL/ADGS1412x9.h"
static const uint8_t SPI_DAISY_CHAIN_COMMAND[2] = {0x25, 0x00};
static int __switch_transfer(struct switch_series_data_t *sd)
{
spi1_close();
spi1_open(SPI_CLK_4M, POL0, PHA0);
pin_set(E_PIN_SWCSBB, 0);
spi1_write(NULL, (uint8_t *)(sd), 8);
pin_set(E_PIN_SWCSBB, 1);
return 0;
}
static int __switch_daisy_chain_mode() {
spi1_close();
spi1_open(SPI_CLK_4M, POL0, PHA0);
pin_set(E_PIN_SWCSBB, 0);
spi1_write(NULL, SPI_DAISY_CHAIN_COMMAND, 2);
pin_set(E_PIN_SWCSBB, 1);
return 0;
}
static int __set_switch_param(enum ADGS1412_module_e switch_module, enum ADGS1412_SWITCH_ENABLE_e enable_type, struct switch_series_data_t *switch_data)
{
struct switch_series_data_t *sd = switch_data;
enum ADGS1412_module_e sw_module = switch_module;
enum ADGS1412_SWITCH_ENABLE_e en_type = enable_type;
switch(sw_module) {
case ADGS1412_MODULE_U14:
sd->device8_switch = (uint8_t)en_type;
break;
case ADGS1412_MODULE_U13:
sd->device7_switch = (uint8_t)en_type;
break;
case ADGS1412_MODULE_U18:
sd->device6_switch = (uint8_t)en_type;
break;
case ADGS1412_MODULE_U20:
sd->device5_switch = (uint8_t)en_type;
break;
case ADGS1412_MODULE_U26:
sd->device4_switch = (uint8_t)en_type;
break;
case ADGS1412_MODULE_U29:
sd->device3_switch = (uint8_t)en_type;
break;
case ADGS1412_MODULE_U22:
sd->device2_switch = (uint8_t)en_type;
break;
case ADGS1412_MODULE_U24:
sd->device1_switch = (uint8_t)en_type;
break;
case ADGS1412_MODULE_MAX:
*sd = (struct switch_series_data_t) {.device8_switch = (uint8_t)en_type,
.device7_switch = (uint8_t)en_type,
.device6_switch = (uint8_t)en_type,
.device5_switch = (uint8_t)en_type,
.device4_switch = (uint8_t)en_type,
.device3_switch = (uint8_t)en_type,
.device2_switch = (uint8_t)en_type,
.device1_switch = (uint8_t)en_type,
};
break;
}
return 0;
}
int switch_ctrl(uint8_t switch_module_number, uint8_t enable_type)
{
struct switch_series_data_t *sd = &switch_series_data_g;
enum ADGS1412_module_e sw_module = (enum ADGS1412_module_e) switch_module_number;
enum ADGS1412_SWITCH_ENABLE_e en_type = (enum ADGS1412_SWITCH_ENABLE_e) enable_type;
if(sw_module > ADGS1412_MODULE_MAX)
return -1;
if(en_type > ALL_ON)
return -2;
if (sw_module == ADGS1412_MODULE_U24 && en_type == S1_S2_ON)
return -3;
__switch_daisy_chain_mode();
__set_switch_param(sw_module, en_type, sd);
__switch_transfer(sd);
return 0;
}
@@ -1,63 +0,0 @@
#ifndef APA102_2020_256_8X4_H
#define APA102_2020_256_8X4_H
#ifdef __cplusplus
extern "C" {
#endif
#define LED_TANDEM_N 4
enum led_series_nb_e {
LED_NB_1 = 0,
LED_NB_2,
LED_NB_3,
LED_NB_4,
LED_NB_MAX = LED_TANDEM_N,
};
enum led_bright_e {
LED_BR_LV0 = 0x00,
LED_BR_LV1 = 0x01,
LED_BR_LV8 = 0x08,
LED_BR_MAX = 0x1F,
};
enum led_color_e {
LED_CLR_BLACK = 0,
LED_CLR_WHITE,
LED_CLR_RED,
LED_CLR_ORANGE,
LED_CLR_YELLOW,
LED_CLR_GREEN,
LED_CLR_CYAN,
LED_CLR_BLUE,
LED_CLR_PURPLE,
LED_CLR_MAGENTA,
LED_CLR_YELLOWGREEN,
LED_CLR_EMERALD,
LED_CLR_MAX,
};
struct led_color_t {
uint8_t b;
uint8_t g;
uint8_t r;
};
struct led_frame_t {
uint8_t bright: 5,
rsvd: 3;
struct led_color_t color;
};
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color);
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color);
int led_rainbow(enum led_bright_e bright);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,61 +0,0 @@
#ifndef MAX5136X2_H
#define MAX5136X2_H
#ifdef __cplusplus
extern "C" {
#endif
#define REVERT_2_BYTE(_b) ((_b) >> 8 | (((_b) & 0xFF) << 8))
#define MAX5136_NUM_MAX 2
#define SIZEOFDAC_SPI MAX5136_NUM_MAX*3
#define CTRL_B_LDAC 0x01
#define CTRL_B_CLR 0x02
#define CTRL_B_POW_CTRL 0x03
#define CTRL_B_LINEARITY 0x05
#define CTRL_B_WRT(_d0, _d1) (0x10 | ((_d1) << 1) | (_d0))
#define CTRL_B_WRT_THR(_d0, _d1) (0x30 | ((_d1) << 1) | (_d0))
#define DATA_B_LDAC(_d0, _d1) ((_d1) << 9 | (_d0) << 8)
#define DATA_B_POW_CT(_d0, _d1, _rd) ((_d1) << 9 | (_d0) << 8 | (_rd) << 7)
#define DATA_B_LINE(_en) ((_en) << 9)
#define DAC0_EN 1
#define DAC0_DIS 0
#define DAC1_EN 1
#define DAC1_DIS 0
enum MAX5136_num_e {
DAC_NB_0 = 0x00,
DAC_NB_1,
DAC_NB_MAX = 0x02,
};
struct dac_series_control_t
{
uint8_t dac0_enable;
uint8_t dac1_enable;
uint16_t volts;
}__attribute__((packed));
struct dac_series_control_t dac_series_control_g[MAX5136_NUM_MAX] = {0};
//int dac_write_through_mode(uint8_t dac0_enable, uint8_t dac1_enable, uint16_t volts, struct dac_series_data_t *sd_dac);
// int dac_series_control_clear();
int dac_enable_all_output(struct dac_series_control_t *seriesPtr);
int dac_enable_single_output(uint8_t dac0_enable, uint8_t dac1_enable, uint16_t volts, enum MAX5136_num_e dac_num);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,120 +0,0 @@
/*
* MAX5136
* CLR: Software clear.
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |0 0 0 0 0 0 1 0|x x x x x x x x|x x x x x x x x|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
* Write-through: Write to selected input and DAC registers, DAC outputs updated(writethrough).
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |0 0 1 1 D3 D2 D1 D0| DAC data |
* +-+-+-+-+--+--+--+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#include "application_config/application_config.h"
#include "HAL/cc2650_driver/spi_ctrl.h"
#include "HAL/MAX5136x2.h"
struct dac_series_data_t {
uint8_t control_bits;
uint16_t data_bits;
}__attribute__((packed));
static struct dac_series_data_t dac_series_data_g[MAX5136_NUM_MAX] = {0};
static int __dac_transfer(struct dac_series_data_t *sd)
{
spi1_close();
spi1_open(SPI_CLK_4M, POL1, PHA0);
pin_set(E_PIN_DACCS, 0);
spi1_write(NULL, (uint8_t *)(sd), SIZEOFDAC_SPI);
pin_set(E_PIN_DACCS, 1);
return 0;
}
static int __dac_write_through_mode(uint8_t dac0_enable, uint8_t dac1_enable, uint16_t volts, struct dac_series_data_t *sd_dac)
{
uint8_t d0 = dac0_enable;
uint8_t d1 = dac1_enable;
uint16_t v = volts;
struct dac_series_data_t *sd = sd_dac;
sd->control_bits = CTRL_B_WRT_THR(d0, d1);
sd->data_bits = REVERT_2_BYTE(v);
return 0;
}
static int dac_series_control_clear() {
for(int i = DAC_NB_0; i < DAC_NB_MAX; i++) {
dac_series_control_g[i].dac0_enable = 0;
dac_series_control_g[i].dac1_enable = 0;
dac_series_control_g[i].volts = 0;
}
return 0;
}
int dac_enable_all_output(struct dac_series_control_t *seriesPtr)
{
struct dac_series_data_t *sd = dac_series_data_g;
for(int i = DAC_NB_0; i < DAC_NB_MAX; i++) {
if (seriesPtr[i].dac0_enable || seriesPtr[i].dac1_enable) {
uint8_t dac0_en = seriesPtr[i].dac0_enable;
uint8_t dac1_en = seriesPtr[i].dac1_enable;
uint16_t v = seriesPtr[i].volts;
__dac_write_through_mode(dac0_en, dac1_en, v, (sd + i));
}
}
__dac_transfer(sd);
dac_series_control_clear();
return 0;
}
int dac_enable_single_output(uint8_t dac0_enable, uint8_t dac1_enable, uint16_t volts, enum MAX5136_num_e dac_num) {
uint8_t dac0_en = dac0_enable;
uint8_t dac1_en = dac1_enable;
uint16_t v = volts;
enum MAX5136_num_e dac_n = dac_num;
struct dac_series_data_t *sd = dac_series_data_g;
if(dac_n >= DAC_NB_MAX)
return -1;
for(int i = DAC_NB_0; i < DAC_NB_MAX; i++) {
if(i == dac_n)
__dac_write_through_mode(dac0_en, dac1_en, v, (sd+i));
}
return 0;
}
@@ -1,75 +0,0 @@
#ifndef MCP23008X2_H
#define MCP23008X2_H
#ifdef __cplusplus
extern "C" {
#endif
//i2c addr
/************************************************************************************************
* .h
************************************************************************************************/
#define GET_INPUT_SW_SEN() ((chip_MCP23008_rd_reg_stat(MCP23008_PB, MCP23008_REG_GPIO) & 0x40) >> 6)
#define PUSH_KEY (GET_INPUT_SW_SEN() == 0)
#define SET_VLOGIC_EN_GPIO(_v) (chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P4, _v))
#define SET_VLOGIC_EN_IODIR(_v) (chip_MCP23008_set(MCP23008_PB, MCP23008_REG_IODIR, MCP23008_P4, _v))
#define SET_SW_EN_GPIO(_v) (chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P5, _v))
enum mcp23008_module_e {
MCP23008_PA = 0,
MCP23008_PB,
MCP23008_MODULE_MAX,
};
enum mcp23008_reg_name_e {
MCP23008_REG_IODIR = 0x00, /*IODIR I/O DIRECTION REGISTER (ADDR 0x00)*/
MCP23008_REG_IPOL, /*IPOL INPUT POLARITY PORT REGISTER (ADDR 0x01)*/
MCP23008_REG_GPINTEN, /*GPINTEN INTERRUPT-ON-CHANGE PINS (ADDR 0x02)*/
MCP23008_REG_DEFVAL, /*DEFVAL DEFAULT VALUE REGISTER (ADDR 0x03)*/
MCP23008_REG_INTCON, /*INTCON INTERRUPT-ON-CHANGE CONTROL REGISTER (ADDR 0x04)*/
MCP23008_REG_IOCON, /*IOCON I/O EXPANDER CONFIGURATION REGISTER (ADDR 0x05)*/
MCP23008_REG_GPPU, /*GPPU GPIO PULL-UP RESISTOR REGISTER (ADDR 0x06)*/
MCP23008_REG_INTF, /*INTF INTERRUPT FLAG REGISTER (ADDR 0x07)*/
MCP23008_REG_INTCAP, /*INTCAP INTERRUPT CAPTURED VALUE FOR PORT REGISTER (ADDR 0x08)*/
MCP23008_REG_GPIO, /*GPIO GENERAL PURPOSE I/O PORT REGISTER (ADDR 0x09)*/
MCP23008_REG_OLAT, /*OLAT OUTPUT LATCH REGISTER 0 (ADDR 0x0A)*/
MCP23008_REG_MAX,
};
enum mcp23008_gpio_e {
MCP23008_P0 = 0,
MCP23008_P1,
MCP23008_P2,
MCP23008_P3,
MCP23008_P4,
MCP23008_P5,
MCP23008_P6,
MCP23008_P7,
MCP23008_PIN_ALL,
};
struct mcp23008_reg_name_t {
uint8_t iodir;
uint8_t gpio;
};
struct mcp23008_set_para_t {
enum mcp23008_module_e chip_module;
enum mcp23008_reg_name_e reg_addr;
uint8_t val;
};
int chip_MCP23008_set(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address, enum mcp23008_gpio_e wt_bit, uint8_t value);
uint8_t chip_MCP23008_rd_reg_stat(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,205 +0,0 @@
/*
* MCP23008: Series data structure
* I2C
* -Write:
* +---------------------+------------------------+-------------+
* | Device Opcode(1B) | Register Address(1B) | Value(1B) |
* +---------------------+------------------------+-------------+
* / \
* / Device Opcode(1B)\
* / \
* 0 1 2 3 4 5 6 7
* +-+-+-+-+--+--+--+---+
* | 0100 |A2 A1 A0 R/W|
* +-+-+-+-+--+--+--+---+
* ps.CC2650 I2C parameter:I2C_addr、tx、txlen、rxlen,
* I2C_addr = 0b 0 1 0 0 A2 A1 A0
* tx = Register Address + Value
* txlen=2
* rxlen=1
*
*
* -Read:
* +---------------------+------------------------+
* | Device Opcode(1B) | Register Address(1B) |
* +---------------------+------------------------+
* / \
* / Device Opcode(1B)\
* / \
* 0 1 2 3 4 5 6 7
* +-+-+-+-+--+--+--+---+
* | 0100 |A2 A1 A0 R/W|
* +-+-+-+-+--+--+--+---+
* ps.CC2650 I2C parameter:I2C_addr、tx、txlen、rxlen,
* I2C_addr = 0b 0 1 0 0 A2 A1 A0
* tx = Register Address
* txlen=1
* rxlen=1
*
*/
#include "HAL/cc2650_driver/i2c_ctrl.h"
#include "HAL/MCP23008x2.h"
#define MCP23008_WT_BIT 0
#define MCP23008_RD_BIT 1
static uint8_t module_addr_g[MCP23008_MODULE_MAX] = {
0x4C, // MCP23008_PA
0x46, // MCP23008_PB
};
static struct mcp23008_reg_name_t mcp23008_reg_name_g[MCP23008_MODULE_MAX] = {0};
static uint8_t __mcp23008_reg_value_get(struct mcp23008_set_para_t *mcp23008_ctrl_para)
{
struct mcp23008_set_para_t *para = mcp23008_ctrl_para;
struct mcp23008_reg_name_t *p;
uint8_t ret;
p = mcp23008_reg_name_g + para->chip_module;
switch(para->reg_addr) {
case MCP23008_REG_GPIO:
ret = p->gpio;
break;
case MCP23008_REG_IODIR:
ret = p->iodir;
break;
default:
ret = 0;
break;
}
return ret;
}
static void __mcp23008_reg_value_set(struct mcp23008_set_para_t *mcp23008_ctrl_para)
{
struct mcp23008_set_para_t *para = mcp23008_ctrl_para;
struct mcp23008_reg_name_t *p;
p = mcp23008_reg_name_g + para->chip_module;
switch(para->reg_addr) {
case MCP23008_REG_GPIO:
p->gpio = para->val;
break;
case MCP23008_REG_IODIR:
p->iodir = para->val;
break;
default:
break;
}
return;
}
static int __chip_MCP23008_i2c_write(struct mcp23008_set_para_t *mcp23008_ctrl_para)
{
struct mcp23008_set_para_t *para = mcp23008_ctrl_para;
struct i2c_para_t i2c_send;
struct i2c_para_t *send = &i2c_send;
int ret;
send->i2c_txlen = 2;
send->i2c_rxlen = 1;
send->i2c_addr = module_addr_g[para->chip_module] | MCP23008_WT_BIT;
memcpy(send->i2c_tx, &para->reg_addr, 1);
memcpy(&send->i2c_tx[1], &para->val, 1);
ret = i2c0_write(send);
return ret;
}
static uint8_t __chip_MCP23008_i2c_read(struct mcp23008_set_para_t *mcp23008_ctrl_para)
{
struct mcp23008_set_para_t *para = mcp23008_ctrl_para;
struct i2c_para_t i2c_read;
struct i2c_para_t *read = &i2c_read;
read->i2c_txlen = 1;
read->i2c_rxlen = 1;
read->i2c_addr = module_addr_g[para->chip_module] | MCP23008_RD_BIT;
memcpy(read->i2c_tx, &para->reg_addr, 1);
if (i2c0_write(read) == 0) {
para->val = read->i2c_rx[0];
return 0;
}
return 1;
}
int chip_MCP23008_set(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address, enum mcp23008_gpio_e wt_bit, uint8_t value)
{
struct mcp23008_set_para_t mcp23008_ctrl_para;
struct mcp23008_set_para_t *para = &mcp23008_ctrl_para;
enum mcp23008_module_e modul = i2c_module;
enum mcp23008_reg_name_e reg = reg_address; // for current version, it selects IODIR or GPIO
enum mcp23008_gpio_e wt_b = wt_bit; //
uint8_t v = value;
uint8_t set_val = 0;
if (modul >= MCP23008_MODULE_MAX)
return -1;
if (reg >= MCP23008_REG_MAX)
return -2;
if (wt_b > MCP23008_PIN_ALL)
return -3;
if (wt_b < MCP23008_PIN_ALL && v > 1)
return -4;
para->chip_module = modul;
para->reg_addr = reg;
para->val = v;
if (wt_b < MCP23008_PIN_ALL) {
set_val = __mcp23008_reg_value_get(para);
set_val &= ~(1 << wt_b);
set_val |= v << wt_b;
para->val = set_val;
}
if (__chip_MCP23008_i2c_write(para) == 0) {
__mcp23008_reg_value_set(para);
return 0;
}
return -1;
}
uint8_t chip_MCP23008_rd_reg_stat(enum mcp23008_module_e i2c_module, enum mcp23008_reg_name_e reg_address)
{
struct mcp23008_set_para_t mcp23008_ctrl_para;
struct mcp23008_set_para_t *para = &mcp23008_ctrl_para;
enum mcp23008_module_e modul = i2c_module;
enum mcp23008_reg_name_e reg = reg_address;
if (modul >= MCP23008_MODULE_MAX)
return 0;
if (reg >= MCP23008_REG_MAX)
return 0;
para->chip_module = modul;
para->reg_addr = reg;
__chip_MCP23008_i2c_read(para);
return para->val;
}
@@ -1,25 +0,0 @@
#ifndef I2C_CTRL_H
#define I2C_CTRL_H
#ifdef __cplusplus
extern "C" {
#endif
#define I2C_100K 0
#define I2C_400K 1
struct i2c_para_t {
uint8_t i2c_addr;
uint8_t i2c_txlen;
uint8_t i2c_rxlen;
uint8_t i2c_tx[256];
uint8_t i2c_rx[256];
};
int i2c0_open(uint8_t bitRate);
int i2c0_write(struct i2c_para_t *i2c_para);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,53 +0,0 @@
#include <Board.h>
#include <ti/drivers/I2C.h>
#include "HAL/cc2650_driver/i2c_ctrl.h"
/* system use I2C parameters */
static I2C_Handle I2Chandle0 = NULL;
static I2C_Params I2CParams0;
/* Open the I2C driver */
int i2c0_open(uint8_t speed)
{
//ret=0 -> success
// =1 -> already exists
// =2 -> open fail
uint8_t s = speed;
I2C_BitRate rate;
if (I2Chandle0 != NULL)
return 1;
if (s == I2C_100K)
rate = I2C_100kHz;
else
rate = I2C_400kHz;
/* Configure I2C */
Board_initI2C();
I2C_Params_init(&I2CParams0);
I2CParams0.bitRate = rate;
/* Attempt to open I2C. */
I2Chandle0 = I2C_open(Board_I2C0, &I2CParams0);
if (I2Chandle0 == NULL)
return 2;
return 0;
}
int i2c0_write(struct i2c_para_t *i2c_para)
{
struct i2c_para_t *p = i2c_para;
I2C_Transaction I2C0Transaction;
I2C0Transaction.writeCount = p->i2c_txlen;
I2C0Transaction.writeBuf = p->i2c_tx;
I2C0Transaction.readCount = p->i2c_rxlen;
I2C0Transaction.readBuf = p->i2c_rx;
I2C0Transaction.slaveAddress = p->i2c_addr>>1;
return I2C_transfer(I2Chandle0, &I2C0Transaction) ? 0 : -1;
}
@@ -1,27 +0,0 @@
#ifndef SPI_CTRL_H
#define SPI_CTRL_H
#ifdef __cplusplus
extern "C" {
#endif
#define POL0 0
#define POL1 1
#define PHA0 0
#define PHA1 1
#define SPI_CLK_10M 10000000
#define SPI_CLK_4M 4000000
int spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
void spi0_close(void);
int spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
int spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
void spi1_close(void);
int spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
#ifdef __cplusplus
}
#endif
#endif
@@ -1,162 +0,0 @@
#include <Board.h>
#include <ti/drivers/SPI.h>
#include "HAL/cc2650_driver/spi_ctrl.h"
/*
SPI bit rate in Hz.
Maximum bit rates supported by hardware:
+---------------+-----------------+------------------+
| Device Family | Slave Max (MHz) | Master Max (MHz) |
+---------------+-----------------+------------------+
| MSP432P4 | 16 MHz | 24 MHz |
| MSP432E4 | 10 MHz | 60 MHz |
| CC13XX/CC26XX | 4 MHz | 12 MHz |
| CC32XX | 20 MHz | 20 MHz |
+---------------+-----------------+------------------+
Please note that depending on the specific use case, the driver may not support the hardware's maximum bit rate.
*/
/* system use SPI parameters */
static SPI_Handle spiHandle0 = NULL;
static SPI_Params spiParams0;
static SPI_Handle spiHandle1 = NULL;
static SPI_Params spiParams1;
/* Open the RTOS SPI driver */
int spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
{
//ret=0 -> success
// =1 -> already exists
// =2 -> open fail
uint32_t rate = bitRate;
uint8_t pol = polarity;
uint8_t pha = phase;
SPI_FrameFormat frameFormat;
if (spiHandle0 != NULL)
return 1;
if (pol == 0 && pha == 0)
frameFormat = SPI_POL0_PHA0;
else if (pol == 0 && pha == 1)
frameFormat = SPI_POL0_PHA1;
else if (pol == 1 && pha == 0)
frameFormat = SPI_POL1_PHA0;
else if (pol == 1 && pha == 1)
frameFormat = SPI_POL1_PHA1;
/* Configure SPI as master */
Board_initSPI();
SPI_Params_init(&spiParams0);
spiParams0.bitRate = rate;
spiParams0.mode = SPI_MASTER;
spiParams0.dataSize = 8;
spiParams0.frameFormat = frameFormat;
/* Attempt to open SPI. */
spiHandle0 = SPI_open(Board_SPI0, &spiParams0);
if (spiHandle0 == NULL)
return 2;
return 0;
}
/* Close the RTOS SPI driver */
void spi0_close(void)
{
if (spiHandle0 != NULL)
{
SPI_close(spiHandle0);
spiHandle0 = NULL;
}
return;
}
int spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
{
//ret=0 -> success
// =1 -> fail
SPI_Transaction spi0Transaction;
spi0Transaction.count = len;
spi0Transaction.txBuf = txBuf;
spi0Transaction.arg = NULL;
spi0Transaction.rxBuf = NULL;
if (SPI_transfer(spiHandle0, &spi0Transaction) == FALSE) //TRUE->sucess, FALSE->fail
return 1;
return 0;
}
/* Open the RTOS SPI driver */
int spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
{
//ret=0 -> success
// =1 -> already exists
// =2 -> open fail
uint32_t rate = bitRate;
uint8_t pol = polarity;
uint8_t pha = phase;
SPI_FrameFormat frameFormat;
if (spiHandle1 != NULL)
return 1;
if (pol == 0 && pha == 0)
frameFormat = SPI_POL0_PHA0;
else if (pol == 0 && pha == 1)
frameFormat = SPI_POL0_PHA1;
else if (pol == 1 && pha == 0)
frameFormat = SPI_POL1_PHA0;
else if (pol == 1 && pha == 1)
frameFormat = SPI_POL1_PHA1;
/* Configure SPI as master */
Board_initSPI();
SPI_Params_init(&spiParams1);
spiParams1.bitRate = rate;
spiParams1.mode = SPI_MASTER;
spiParams1.dataSize = 8;
spiParams1.frameFormat = frameFormat;
/* Attempt to open SPI. */
spiHandle1 = SPI_open(Board_SPI1, &spiParams1);
if (spiHandle1 == NULL)
return 2;
return spiHandle1 != NULL;
}
/* Close the RTOS SPI driver */
void spi1_close(void)
{
if (spiHandle1 != NULL)
{
SPI_close(spiHandle1);
spiHandle1 = NULL;
}
return;
}
int spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
{
//ret=0 -> success
// =1 -> fail
SPI_Transaction spi1Transaction;
spi1Transaction.count = len;
spi1Transaction.txBuf = txBuf;
spi1Transaction.arg = NULL;
spi1Transaction.rxBuf = rxBuf;
if (SPI_transfer(spiHandle1, &spi1Transaction) == FALSE) //TRUE->sucess, FALSE->fail
return 1;
return 0;
}
@@ -1,92 +0,0 @@
#ifndef BAT_10_CONF_H
#define BAT_10_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* --------------------
* define device name
* ------------------*/
#define DEVICE_NAME "Elite-BAT"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 3
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 1
/* ---------------------------
* define device buffer size
* -------------------------*/
#define CUSTOM_GATT_LENGTH
#define BLE_CIS_BUFF_SIZE 20
#define BLE_INS_BUFF_SIZE 20
#define BLE_DAT_BUFF_SIZE 40
/* -------------------
* define device pin
* -----------------*/
// Elite Pin Board
#define E_PIN_LED_SPI_CLK DIO5
#define E_PIN_LED_SPI_SDI DIO6
#define E_PIN_ADCA0 DIO0
#define E_PIN_ADCA1 DIO1
#define E_PIN_ADCA2 DIO7
#define E_PIN_SWCSBB DIO2
#define E_PIN_MEMCS DIO3
#define E_PIN_DIO4 DIO4
#define E_PIN_I2C_SCK DIO8
#define E_PIN_I2C_SDA DIO9
#define E_PIN_DACCS DIO10
#define E_PIN_ADCCS DIO11
#define E_PIN_SCLK0 DIO12
#define E_PIN_MOSI DIO13
#define E_PIN_MISO DIO14
// SPI & I2C Board
#define E_SPI0_MISO PIN_UNASSIGNED
#define E_SPI0_MOSI E_PIN_LED_SPI_SDI
#define E_SPI0_CLK E_PIN_LED_SPI_CLK
#define E_SPI0_CS PIN_UNASSIGNED
#define E_SPI1_MISO E_PIN_MISO
#define E_SPI1_MOSI E_PIN_MOSI
#define E_SPI1_CLK E_PIN_SCLK0
#define E_SPI1_CS PIN_UNASSIGNED
#define E_I2C0_SCL0 E_PIN_I2C_SCK
#define E_I2C0_SDA0 E_PIN_I2C_SDA
// no use
#define D0 PIN_UNASSIGNED
#define D1 PIN_UNASSIGNED
#define D2 PIN_UNASSIGNED
#define D3 PIN_UNASSIGNED
#define D4 PIN_UNASSIGNED
#define D5 PIN_UNASSIGNED
#define D6 PIN_UNASSIGNED
#define D7 PIN_UNASSIGNED
#define LOAD0 PIN_UNASSIGNED
#define LOAD1 PIN_UNASSIGNED
#define LOAD2 PIN_UNASSIGNED
#define SHUT_DOWN PIN_UNASSIGNED //switch_on
#define HIGH_Z LOAD0, PIN_UNASSIGNED
#define CS_MEM LOAD0, PIN_UNASSIGNED
#define CS_ADC LOAD0, PIN_UNASSIGNED
#define CS_DAC LOAD0, PIN_UNASSIGNED
#define MEM_HOLD LOAD1, PIN_UNASSIGNED
#define P_10V_enable LOAD1, PIN_UNASSIGNED
#define P_5V_enable LOAD1, PIN_UNASSIGNED
#define I_MID_ON LOAD2, PIN_UNASSIGNED
#define I_LARGE_ON LOAD2, PIN_UNASSIGNED
#define V_SMALL_ON LOAD2, PIN_UNASSIGNED
#define V_MID_ON LOAD2, PIN_UNASSIGNED
#define I_SMALL_ON LOAD2, PIN_UNASSIGNED
#define OFF LOAD2, PIN_UNASSIGNED //6994
#define VOUT_SMALL_ON LOAD2, PIN_UNASSIGNED
#ifdef __cplusplus
}
#endif
#endif
@@ -1,159 +0,0 @@
#ifndef APPLICATION_CONFIG_H
#define APPLICATION_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
// !!! define DEF_ELITE_MODEL first please !!!
/*
*
* product number: MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER
* MAJOR_PRODUCT_NUMBER -> 0:Elite, 1:other serial
* Elite:
* MINOR_PRODUCT_NUMBER -> 1:legacy, 2:EDC, 3:BAT, 4:EIS, 5:TRIG, 6:MEGAFLY
*
* |------------------+------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
* | hardware | model name | hw upper board | hw lower board | product number | device name | data server lib name | UI |
* |------------------+------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
* | Elite EDC1.4 | DEF_ELITE_EDC_14 | Elite1.4-re Jun.2019 | Elite1.4-re Jun. 2019 | 0, 2, 1, 5 | "Elite-EDC" | Elite_EDC_1.4 | null |
* | Elite EDC1.5 | DEF_ELITE_EDC_15 | Elite1.5 Dec. 2019 | Elite1.5 Dec. 2019 | 0, 2, 1, 6 | "Elite-EDC" | Elite_EDC_1.5 | EliteEDC |
* | Elite EDC1.5re | DEF_ELITE_EDC_15RE | Elite1.5 Dec. 2019 | Elite1.5-re Jan. 2021 | 0, 2, 1, 7 | "Elite-EDC" | Elite_EDC_1.5re | EliteEDC |
* | Elite EDC1.5r2 | DEF_ELITE_EDC_15R2 | Elite1.5 Dec. 2019 | Elite1.5-r2 May. 2022 | 0, 2, 1, 8 | "Elite-EDC" | Elite_EDC_1.5r2 | EliteEDC |
* | Elite BAT0.1 | DEF_ELITE_BAT_01 | Elite2.0 Feb. 2022 | 0, 3, 1, 0 | "Elite-BAT" | Elite_BAT_0.1 | EliteEDC |
* | Elite BAT1.0 | DEF_ELITE_BAT_10 | BAT SMC V1.0 Aug.2022| BAT PWR V1.0 Aug. 2022 | 0, 3, 1, 1 | "Elite-BAT" | Elite_BAT_1.0 | EliteEDC |
* | Elite EIS1.0 | DEF_ELITE_EIS_10 | Elite1.5 Dec. 2019 | Elite EIS1.0 Aug. 2020 | 0, 4, 1, 0 | "Elite-EIS" | Elite_EIS_1.0 | EliteEIS |
* | Elite EIS1.1 | DEF_ELITE_EIS_11 | Elite1.5 Dec. 2019 | Elite EIS1.1 Feb. 2022 | 0, 4, 1, 1 | "Elite-EIS" | Elite_EIS_1.1 | EliteEIS |
* | Elite EISmini1.0 | DEF_ELITE_EIS_MINI_10 | EIS MINI May. 2022 | 0, 4, 1, 2 | "Elite-EIS-MINI" | Elite_EIS_MINI_1.0 | EliteEIS |
* | Elite TRIG0.1 | DEF_ELITE_TRIG_01 | Elite TRIG01 Jan. 2021 | 0, 5, 1, 0 | "Elite-TRIG" | Elite_TRIG_0.1 | EliteTrigger |
* | Elite MEGAFLY0.1 | DEF_ELITE_MEGAFLY_01 | Elite1.5 Dec. 2019 | Elite Megafly Sep. 2020 | 0, 6, 1, 0 | "Elite-MEGAFLY" | Elite_MEGAFLY_0.1 | null |
* |-----------------+------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
* ps.
* model name is FW engineer defined
* device name is used for controller
*/
#define DEF_ELITE_EDC_14 0
#define DEF_ELITE_EDC_15 1
#define DEF_ELITE_EDC_15RE 2
#define DEF_ELITE_EDC_15R2 3
#define DEF_ELITE_BAT_01 4
#define DEF_ELITE_BAT_10 5
#define DEF_ELITE_EIS_10 6
#define DEF_ELITE_EIS_11 7
#define DEF_ELITE_EIS_MINI_10 8
#define DEF_ELITE_TRIG_01 9
#define DEF_ELITE_MEGAFLY_01 10
#define DEF_ELITE_MAX 11
#define DEF_ELITE_MODEL DEF_ELITE_BAT_10
#ifndef DEF_ELITE_MODEL
#error "DEF_ELITE_MODEL not defined"
#endif
// model information
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_01)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
#include "BAT_10_conf.h"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
#error "code no support"
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
#error "code no support"
#else
#error "no this model"
#endif
// model information
// #if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
// #define DEVICE_NAME "Elite-EDC"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 2
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 5
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
// #define DEVICE_NAME "Elite-EDC"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 2
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 6
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
// #define DEVICE_NAME "Elite-EDC"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 2
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 7
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
// #define DEVICE_NAME "Elite-EDC"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 2
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 8
// #elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_01)
// #define DEVICE_NAME "Elite-BAT"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 3
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 0
// #elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
// #define DEVICE_NAME "Elite-BAT"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 3
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 1
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
// #define DEVICE_NAME "Elite-EIS"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 4
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 0
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
// #define DEVICE_NAME "Elite-EIS"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 4
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 1
// #elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
// #define DEVICE_NAME "Elite-EIS"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 4
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 2
// #elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
// #define DEVICE_NAME "Elite-TRIG"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 5
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 0
// #elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
// #define DEVICE_NAME "Elite-MEGAFLY"
// #define MAJOR_PRODUCT_NUMBER 0
// #define MINOR_PRODUCT_NUMBER 6
// #define MAJOR_VERSION_NUMBER 1
// #define MINOR_VERSION_NUMBER 0
// #else
// #error "no this model"
// #endif
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,143 @@
#ifndef ELITE_BOARDS_SELECT_H
#define ELITE_BOARDS_SELECT_H
#ifdef __cplusplus
extern "C" {
#endif
/*
*
* product number: MAJOR_PRODUCT_NUMBER, MINOR_PRODUCT_NUMBER, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER
* MAJOR_PRODUCT_NUMBER -> 0:Elite, 1:other serial
* Elite:
* MINOR_PRODUCT_NUMBER -> 1:legacy, 2:EDC, 3:BAT, 4:EIS, 5:TRIG, 6:MEGAFLY
*
* +------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
* | model name | hw upper board | hw lower board | product number | device name | data server lib name | UI |
* +------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
* | DEF_ELITE_EDC_14 | Elite1.4-re Jun.2019 | Elite1.4-re Jun. 2019 | 0, 2, 1, 5 | "Elite-EDC" | Elite_EDC_1.4 | null |
* | DEF_ELITE_EDC_15 | Elite1.5 Dec. 2019 | Elite1.5 Dec. 2019 | 0, 2, 1, 6 | "Elite-EDC" | Elite_EDC_1.5 | EliteEDC |
* | DEF_ELITE_EDC_15RE | Elite1.5 Dec. 2019 | Elite1.5-re Jan. 2021 | 0, 2, 1, 7 | "Elite-EDC" | Elite_EDC_1.5re | EliteEDC |
* | DEF_ELITE_EDC_15R2 | Elite1.5 Dec. 2019 | Elite1.5-r2 May. 2022 | 0, 2, 1, 8 | "Elite-EDC" | Elite_EDC_1.5r2 | EliteEDC |
* | DEF_ELITE_BAT_10 | Elite2.0 Feb. 2022 | 0, 3, 1, 0 | "Elite-BAT" | Elite_BAT_1.0 | EliteEDC |
* | DEF_ELITE_EIS_10 | Elite1.5 Dec. 2019 | Elite EIS1.0 Aug. 2020 | 0, 4, 1, 0 | "Elite-EIS" | Elite_EIS_1.0 | EliteEIS |
* | DEF_ELITE_EIS_11 | Elite1.5 Dec. 2019 | Elite EIS1.1 Feb. 2022 | 0, 4, 1, 1 | "Elite-EIS" | Elite_EIS_1.1 | EliteEIS |
* | DEF_ELITE_EIS_MINI_10 | EIS MINI May. 2022 | 0, 4, 1, 2 | "Elite-EIS-MINI" | Elite_EIS_MINI_1.0 | EliteEIS |
* | DEF_ELITE_TRIG_01 | Elite TRIG01 Jan. 2021 | 0, 5, 1, 0 | "Elite-TRIG" | Elite_TRIG_0.1 | null |
* | DEF_ELITE_MEGAFLY_01 | Elite1.5 Dec. 2019 | Elite Megafly Sep. 2020 | 0, 6, 1, 0 | "Elite-MEGAFLY" | Elite_MEGAFLY_0.1 | null |
* +------------------------+----------------------+-------------------------+----------------+----------------------+----------------------+----------+
* ps.
* model name is FW engineer defined
* device name is used for controller
*/
#define DEF_ELITE_EDC_14 0
#define DEF_ELITE_EDC_15 1
#define DEF_ELITE_EDC_15RE 2
#define DEF_ELITE_EDC_15R2 3
#define DEF_ELITE_BAT_10 4
#define DEF_ELITE_EIS_10 5
#define DEF_ELITE_EIS_11 6
#define DEF_ELITE_EIS_MINI_10 7
#define DEF_ELITE_TRIG_01 8
#define DEF_ELITE_MEGAFLY_01 9
#define DEF_ELITE_MAX 10
#define DEF_ELITE_MODEL DEF_ELITE_EIS_11
#ifndef DEF_ELITE_MODEL
#error "DEF_ELITE_MODEL not defined"
#endif
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
#error "code no support" // need fix
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
#error "code no support" // need fix
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
#include "boards_config/pin_def_edc15re.h"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
#error "code no support" // need fix
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
#error "code no support" // need fix
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
#include "boards_config/pin_def_eis11.h"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
#include "boards_config/pin_config_eis_mini_10.h"
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
#error "code no support" // need fix
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
#error "code no support" // need fix
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
#error "code no support" // need fix
#else
#error "no this model"
#endif
// model information
#if (DEF_ELITE_MODEL == DEF_ELITE_EDC_14)
#define DEVICE_NAME "Elite-EDC"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 2
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 5
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15)
#define DEVICE_NAME "Elite-EDC"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 2
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 6
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15RE)
#define DEVICE_NAME "Elite-EDC"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 2
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 7
#elif (DEF_ELITE_MODEL == DEF_ELITE_EDC_15R2)
#define DEVICE_NAME "Elite-EDC"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 2
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 8
#elif (DEF_ELITE_MODEL == DEF_ELITE_BAT_10)
#define DEVICE_NAME "Elite-BAT"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 3
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 0
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_10)
#define DEVICE_NAME "Elite-EIS"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 4
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 0
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
#define DEVICE_NAME "Elite-EIS"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 4
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 1
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
#define DEVICE_NAME "Elite-EIS"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 4
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 2
#elif (DEF_ELITE_MODEL == DEF_ELITE_TRIG_01)
#define DEVICE_NAME "Elite-TRIG"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 5
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 0
#elif (DEF_ELITE_MODEL == DEF_ELITE_MEGAFLY_01)
#define DEVICE_NAME "Elite-MEGAFLY"
#define MAJOR_PRODUCT_NUMBER 0
#define MINOR_PRODUCT_NUMBER 6
#define MAJOR_VERSION_NUMBER 1
#define MINOR_VERSION_NUMBER 0
#endif
#ifdef __cplusplus
}
#endif
#endif // ELITE_BOARDS_SELECT_H
@@ -0,0 +1,81 @@
/*
* +------------------------------+
* | CC2650moda |
* +-------------+----------------+
* | MISO | DIO1 |
* | D0 | DIO3 |
* | D1 | DIO4 |
* | D2/JTAG_TDO | DIO5/JTAG_TDO |
* | D3/JTAG_TDI | DIO6/JTAG_TDI |
* | D4 | DIO7 |
* | D5 | DIO8 |
* | D6 | DIO9 |
* | D7 | DIO10 |
* | LOAD2 | DIO11 |
* | LOAD1 | DIO12 |
* | LOAD0 | DIO13 |
* | SHUT_DOWN | DIO14 |
* +-------------+----------------+
*
* +-----------------------------+
* | Elite Pin for EIS1.1 Board |
* +------------+----------------+
* | AD_GPIO2 | D0 |
* | AD_GPIO1 | D1 |
* | AD_CLK | D2 |
* | AD_MOSI | D3 |
* | AD_RST | D4 |
* | MEM_CS | D5 |
* | 5V_ENABLE | D6 |
* | AD_CS | D7 |
* | AD_GPIO0 | LOAD2 |
* | OFF | LOAD0 |<--OFF:shutdown_6994
* | AD_MISO | MISO |
* | SHUT_DOWN | SHUT_DOWN |<--SHUT_DOWN:switch on/off
* +------------+----------------+
* | LED_SCLK_A | E_PIN_AD_GPIO2 |<--jumper
* | LED_MOSI_A | E_PIN_AD_GPIO1 |<--jumper
* +------------+----------------+
*/
/* CC2650moda */
/* Elite Pin for EIS1.1 Board */
#define E_PIN_AD_GPIO2 DIO3
#define E_PIN_AD_GPIO1 DIO4
#define E_PIN_AD_CLK DIO5
#define E_PIN_AD_MOSI DIO6
#define E_PIN_AD_RST DIO7
#define E_PIN_MEM_CS DIO8
#define E_PIN_AD_CS DIO10
#define E_PIN_AD_GPIO0 DIO11
#define E_PIN_BAT DIO12
#define E_PIN_AD_MISO DIO1
#define E_PIN_SHUT_DOWN DIO14
#define E_PIN_5V_ENABLE PIN_UNASSIGNED
#define E_PIN_LED_SCLK_A DIO2
#define E_PIN_LED_MOSI_A DIO0
/* SPI Board */
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI E_PIN_LED_MOSI_A
#define Board_SPI0_CLK E_PIN_LED_SCLK_A
#define Board_SPI0_CS PIN_UNASSIGNED
#define Board_SPI1_MISO E_PIN_AD_MISO
#define Board_SPI1_MOSI E_PIN_AD_MOSI
#define Board_SPI1_CLK E_PIN_AD_CLK
#define Board_SPI1_CS PIN_UNASSIGNED
/* I2C */
#define Board_I2C0_SCL0 PIN_UNASSIGNED
#define Board_I2C0_SDA0 PIN_UNASSIGNED
// delete in the future
#define Turnon_I_LARGE PIN_UNASSIGNED
#define Turnon_I_MID PIN_UNASSIGNED
#define Turnon_I_SMALL PIN_UNASSIGNED
#define Turnon_V_MID PIN_UNASSIGNED
#define Turnon_V_SMALL PIN_UNASSIGNED
#define Turon_VOUT_SMALL PIN_UNASSIGNED
@@ -0,0 +1,98 @@
#ifndef PIN_DEF_EIS11_H
#define PIN_DEF_EIS11_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* +------------------------------+
* | CC2650moda |
* +-------------+----------------+
* | MISO | DIO1 |
* | D0 | DIO3 |
* | D1 | DIO4 |
* | D2/JTAG_TDO | DIO5/JTAG_TDO |
* | D3/JTAG_TDI | DIO6/JTAG_TDI |
* | D4 | DIO7 |
* | D5 | DIO8 |
* | D6 | DIO9 |
* | D7 | DIO10 |
* | LOAD2 | DIO11 |
* | LOAD1 | DIO12 |
* | LOAD0 | DIO13 |
* | SHUT_DOWN | DIO14 |
* +-------------+----------------+
*
* +------------------------------------+
* | Elite Pin for ELITE_EIS_1_1 Board |
* +------------+-----------------------+
* | AD_GPIO2 | D0 |
* | AD_GPIO1 | D1 |
* | AD_CLK | D2 |
* | AD_MOSI | D3 |
* | AD_RST | D4 |
* | MEM_CS | D5 |
* | 5V_ENABLE | D6 |
* | AD_CS | D7 |
* | AD_GPIO0 | LOAD2 |
* | OFF | LOAD0 |<--OFF: shutdown_6994
* | AD_MISO | MISO |
* | SHUT_DOWN | SHUT_DOWN |<--SHUT_DOWN: switch on/off
* +------------+-----------------------+
* | LED_SCLK_A | AD_GPIO2 |<--jumper
* | LED_MOSI_A | AD_GPIO1 |<--jumper
* +------------+-----------------------+
*/
/* CC2650moda */
#define MISO DIO1
#define D0 DIO3
#define D1 DIO4
#define D2 DIO5
#define D3 DIO6
#define D4 DIO7
#define D5 DIO8
#define D6 DIO9
#define D7 DIO10
#define LOAD2 DIO11
#define LOAD1 DIO12
#define LOAD0 DIO13
#define SHUT_DOWN DIO14
/* Elite Pin for ELITE_EIS_1_1 Board */
#define E_PIN_AD_GPIO2 D0
#define E_PIN_AD_GPIO1 D1
#define E_PIN_AD_CLK D2
#define E_PIN_AD_MOSI D3
#define E_PIN_AD_RST D4 //eis1.1-> use D4; eis1.0-> use LOAD0
#define E_PIN_MEM_CS D5
#define E_PIN_5V_ENABLE D6
#define E_PIN_AD_CS D7
#define E_PIN_AD_GPIO0 LOAD2
#define E_PIN_OFF LOAD0
#define E_PIN_AD_MISO MISO
#define E_PIN_SHUT_DOWN SHUT_DOWN
#define E_PIN_LED_SCLK_A E_PIN_AD_GPIO2
#define E_PIN_LED_MOSI_A E_PIN_AD_GPIO1
/* SPI Board */
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI E_PIN_LED_MOSI_A
#define Board_SPI0_CLK E_PIN_LED_SCLK_A
#define Board_SPI0_CS PIN_UNASSIGNED
#define Board_SPI1_MISO E_PIN_AD_MISO
#define Board_SPI1_MOSI E_PIN_AD_MOSI
#define Board_SPI1_CLK E_PIN_AD_CLK
#define Board_SPI1_CS PIN_UNASSIGNED
/* I2C */
#define Board_I2C0_SCL0 PIN_UNASSIGNED
#define Board_I2C0_SDA0 PIN_UNASSIGNED
#ifdef __cplusplus
}
#endif
#endif // PIN_DEF_EIS11_H
@@ -0,0 +1,14 @@
#ifndef GPIO_EIS11_H
#define GPIO_EIS11_H
#ifdef __cplusplus
extern "C" {
#endif
uint8_t gpio_create(void);
int8_t pin_set(uint8_t pin, uint8_t set_value);
#ifdef __cplusplus
}
#endif
#endif // GPIO_EIS11_H
@@ -0,0 +1,58 @@
#include "board.h"
#include <ti/drivers/pin/PINCC26XX.h>
#include "driver/gpio_eis11.h"
static PIN_Handle PinHandle;
static PIN_State PinStatus;
const PIN_Config BLE_IO[] = {
E_PIN_5V_ENABLE | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
E_PIN_AD_RST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
E_PIN_AD_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
E_PIN_OFF | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, // E_PIN_OFF = 1: turn off 6994
E_PIN_SHUT_DOWN | PIN_INPUT_EN | PIN_PULLDOWN,
PIN_TERMINATE
};
static PIN_Handle __get_gpio_handle(void)
{
return PinHandle;
}
static void __set_gpio_handle(PIN_Handle handle)
{
PinHandle = handle;
return;
}
int8_t pin_set(uint8_t pin, uint8_t set_value)
{
/*
* if status = 0: success
* else: fail
*/
uint8_t p = pin;
uint8_t v = set_value;
PIN_Status status;
PIN_Handle handle = __get_gpio_handle();
status = PIN_setOutputValue(handle, p, v);
return status;
}
uint8_t gpio_create(void)
{
PIN_Handle h;
h = PIN_open(&PinStatus, BLE_IO);
__set_gpio_handle(h);
if (h == NULL)
return 1;
return 0;
}
@@ -0,0 +1,14 @@
#ifndef GPIO_EIS_MINI10_H
#define GPIO_EIS_MINI10_H
#ifdef __cplusplus
extern "C" {
#endif
uint8_t gpio_create(void);
int8_t pin_set(uint8_t pin, uint8_t set_value);
#ifdef __cplusplus
}
#endif
#endif // GPIO_EIS_MINI10_H
@@ -0,0 +1,57 @@
#include "board.h"
#include <ti/drivers/pin/PINCC26XX.h>
#include "driver/gpio_eis_mini10.h"
static PIN_Handle PinHandle;
static PIN_State PinStatus;
const PIN_Config BLE_IO[] = {
E_PIN_5V_ENABLE | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
E_PIN_AD_RST | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
E_PIN_AD_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
E_PIN_SHUT_DOWN | PIN_INPUT_EN | PIN_PULLDOWN,
PIN_TERMINATE
};
static PIN_Handle __get_gpio_handle(void)
{
return PinHandle;
}
static void __set_gpio_handle(PIN_Handle handle)
{
PinHandle = handle;
return;
}
int8_t pin_set(uint8_t pin, uint8_t set_value)
{
/*
* if status = 0: success
* else: fail
*/
uint8_t p = pin;
uint8_t v = set_value;
PIN_Status status;
PIN_Handle handle = __get_gpio_handle();
status = PIN_setOutputValue(handle, p, v);
return status;
}
uint8_t gpio_create(void)
{
PIN_Handle h;
h = PIN_open(&PinStatus, BLE_IO);
__set_gpio_handle(h);
if (h == NULL)
return 1;
return 0;
}
@@ -0,0 +1,27 @@
#ifndef SPI_CTRL_H
#define SPI_CTRL_H
#ifdef __cplusplus
extern "C" {
#endif
#define POL0 0
#define POL1 1
#define PHA0 0
#define PHA1 1
#define SPI_CLK_1M 1000000
#define SPI_CLK_4M 4000000
uint8_t spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
uint8_t spi0_close(void);
uint8_t spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
uint8_t spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase);
uint8_t spi1_close(void);
uint8_t spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len);
#ifdef __cplusplus
}
#endif
#endif // SPI_CTRL_H
@@ -0,0 +1,208 @@
#include "board.h"
#include <ti/drivers/SPI.h>
#include "driver/spi_ctrl.h"
#define CC2650_SPI_BITRATE_MAX 4000000 //4M
static SPI_Handle SpiHandle0 = NULL;
static SPI_Params SpiParams0;
static SPI_Handle SpiHandle1 = NULL;
static SPI_Params SpiParams1;
static SPI_Handle __get_spi_handle(uint8_t spi_channel)
{
uint8_t c = spi_channel;
if (c >= BOOSTXL_CC2650MA_SPICOUNT)
return NULL;
if (c == Board_SPI0)
return SpiHandle0;
if (c == Board_SPI1)
return SpiHandle1;
return 0;
}
static void __set_spi_handle(uint8_t spi_channel, SPI_Handle handle)
{
uint8_t c = spi_channel;
if (c == Board_SPI0)
SpiHandle0 = handle;
else if (c == Board_SPI1)
SpiHandle1 = handle;
return;
}
static SPI_FrameFormat __get_spi_mode(uint8_t polarity, uint8_t phase)
{
uint8_t pol = polarity;
uint8_t pha = phase;
SPI_FrameFormat mode;
if (pol == 0 && pha == 0)
mode = SPI_POL0_PHA0;
else if (pol == 0 && pha == 1)
mode = SPI_POL0_PHA1;
else if (pol == 1 && pha == 0)
mode = SPI_POL1_PHA0;
else if (pol == 1 && pha == 1)
mode = SPI_POL1_PHA1;
return mode;
}
uint8_t spi0_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
{
uint32_t rate = bitRate;
uint8_t pol = polarity;
uint8_t pha = phase;
SPI_Handle h = __get_spi_handle(Board_SPI0);
SPI_Params *para = &SpiParams0;
if (rate > CC2650_SPI_BITRATE_MAX)
return 1;
if (pol > 1 || pha > 1)
return 2;
if (h != NULL)
return 3;
SPI_Params_init(para);
para->bitRate = rate;
para->mode = SPI_MASTER;
para->dataSize = 8;
para->frameFormat = __get_spi_mode(pol, pha);
h = SPI_open(Board_SPI0, para);
__set_spi_handle(Board_SPI0, h);
if (h == NULL)
return 4;
return 0;
}
uint8_t spi0_close(void)
{
SPI_Handle h = __get_spi_handle(Board_SPI0);
if (h == NULL)
return 1;
SPI_close(h);
__set_spi_handle(Board_SPI0, NULL);
return 0;
}
uint8_t spi0_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
{
SPI_Handle h = __get_spi_handle(Board_SPI0);
SPI_Transaction spi0_tran;
uint8_t ret;
if (h == NULL)
return 1;
spi0_tran.count = len;
spi0_tran.txBuf = txBuf;
spi0_tran.arg = NULL;
spi0_tran.rxBuf = NULL;
ret = SPI_transfer(h, &spi0_tran);
if (ret == false)
return 2;
return 0;
}
uint8_t spi1_open(uint32_t bitRate, uint8_t polarity, uint8_t phase)
{
uint32_t rate = bitRate;
uint8_t pol = polarity;
uint8_t pha = phase;
SPI_Handle h = __get_spi_handle(Board_SPI1);
SPI_Params *para = &SpiParams1;
if (rate > CC2650_SPI_BITRATE_MAX)
return 1;
if (pol > 1 || pha > 1)
return 2;
if (h != NULL)
return 3;
SPI_Params_init(para);
para->bitRate = rate;
para->mode = SPI_MASTER;
para->dataSize = 8;
para->frameFormat = __get_spi_mode(pol, pha);
h = SPI_open(Board_SPI1, para);
__set_spi_handle(Board_SPI1, h);
if (h == NULL)
return 4;
return 0;
}
uint8_t spi1_close(void)
{
SPI_Handle h = __get_spi_handle(Board_SPI1);
if (h == NULL)
return 1;
SPI_close(h);
__set_spi_handle(Board_SPI1, NULL);
return 0;
}
uint8_t spi1_write(uint8_t *rxBuf, uint8_t *txBuf, uint8_t len)
{
SPI_Handle h = __get_spi_handle(Board_SPI1);
SPI_Transaction spi1_tran;
uint8_t ret;
if (h == NULL)
return 1;
spi1_tran.count = len;
spi1_tran.txBuf = txBuf;
spi1_tran.arg = NULL;
spi1_tran.rxBuf = rxBuf;
ret = SPI_transfer(h, &spi1_tran);
if (ret == false)
return 2;
return 0;
}
/* utils.c.h */
/*
#include <stdio.h>
#include <stdint.h>
static void ___print_hex(uint8_t* p, int len)
{
// ___print_hex((uint8_t *)p, sizeof(struct led_series_data_t));
int i;
for (i = 0; i < len; i++) {
printf("0x%x, ", *p++);
}
printf("\n\n");
return;
}
*/
@@ -0,0 +1,40 @@
#ifndef TIMERS_H
#define TIMERS_H
#ifdef __cplusplus
extern "C" {
#endif
//timer
enum gptimer0_ctrl_e {
GPT_CTRL_START = 0,
GPT_CTRL_STOP,
GPT_CTRL_CLOSE,
GPT_CTRL_MAX,
};
void elite_gptimer_open();
uint8_t gptimer0_ctrl(enum gptimer0_ctrl_e gpt_ctrl);
//clock
/***************************************************
* Q: Why define CPU_1us = 16?
* A:
* 3 cycles per loop: 16 loops @ 48 Mhz ~= 1 us
* 3 cycles * X loops / 48Mhz = 1us(ideal value)
* 3 cycles * X loops / 48us = 1us(ideal value)
* X = 48 / 3 => X = 16 loops
***************************************************/
#define CPU_1us 16
#define CPU_1ms 16000
void CPUdelay_us(uint32_t delay_t);
void CPUdelay_ms(uint32_t delay_t);
void GPT_timerIncrement();
#ifdef __cplusplus
}
#endif
#endif // TIMERS_H
@@ -0,0 +1,90 @@
#include "board.h"
#include <ti/drivers/timer/GPTimerCC26XX.h>
#include <xdc/runtime/Types.h>
#include <ti/sysbios/BIOS.h>
#include "driver/timers.h"
#include "simple_peripheral.h"
static GPTimerCC26XX_Handle gptimer_handle; // was defined static
#define CLOCK_FREQ 4769 // clock freq = 0.1 ms(4800), Measured(4769)
static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {
elite_gptimer_task();
return;
}
void elite_gptimer_open()
{
GPTimerCC26XX_Params params;
GPTimerCC26XX_Params_init(&params);
params.width = GPT_CONFIG_16BIT;
params.mode = GPT_MODE_PERIODIC_UP;
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
gptimer_handle = GPTimerCC26XX_open(Board_GPTIMER0A, &params);
if (gptimer_handle == NULL) {
Task_exit();
}
Types_FreqHz freq;
BIOS_getCpuFreq(&freq);
GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; //47999 = 1ms
loadVal = CLOCK_FREQ; //0.1ms
GPTimerCC26XX_setLoadValue(gptimer_handle, loadVal);
GPTimerCC26XX_registerInterrupt(gptimer_handle, elite_gptimer_callback, GPT_INT_TIMEOUT);
GPTimerCC26XX_start(gptimer_handle);
return;
}
uint8_t gptimer0_ctrl(enum gptimer0_ctrl_e gpt_ctrl)
{
enum gptimer0_ctrl_e gc = gpt_ctrl;
if (gc > GPT_CTRL_MAX)
return 1;
switch (gc) {
case GPT_CTRL_START:
GPTimerCC26XX_start(gptimer_handle);
break;
case GPT_CTRL_STOP:
GPTimerCC26XX_stop(gptimer_handle);
break;
case GPT_CTRL_CLOSE:
GPTimerCC26XX_close(gptimer_handle);
break;
}
return 0;
}
/*******************************************************************************************/
//clock
void CPUdelay_us(uint32_t delay_t)
{
uint32_t t = delay_t;
CPUdelay(t * CPU_1us);
return;
}
void CPUdelay_ms(uint32_t delay_t)
{
uint32_t t = delay_t;
CPUdelay(t * CPU_1ms);
return;
}
void GPT_timerIncrement() {
GPT.cnt_gpt_delta = GPT.cnt_gpt - GPT.cnt_gpt0;
GPT.cnt_gpt0 = GPT.cnt_gpt;
}
@@ -0,0 +1,26 @@
#ifndef ELITE_GPTIMER_H
#define ELITE_GPTIMER_H
#ifdef __cplusplus
extern "C" {
#endif
struct gptimer0_t{
uint32_t cnt_gpt;
uint32_t cnt_gpt0;
uint8_t cnt_gpt_delta;
uint32_t cnt_adc_rate;
uint32_t cnt_notify_rate;
uint32_t cnt_v_scan_rate;
uint32_t cnt_lead_time;
uint32_t BatteryADCCounter;
uint32_t BatteryCheckCounter;
uint32_t GptimerMultiple;
};
void InitGPT();
#ifdef __cplusplus
}
#endif
#endif // ELITE_GPTIMER_H
@@ -0,0 +1,16 @@
#include "elite_task/elite_GPtimer.h"
void InitGPT()
{
GPT.cnt_gpt = 0;
GPT.cnt_gpt0 = 0;
GPT.cnt_gpt_delta = 0;
GPT.cnt_adc_rate = 0;
GPT.cnt_notify_rate = 0;
GPT.cnt_v_scan_rate = 0;
GPT.cnt_lead_time = 0;
GPT.BatteryADCCounter = 0;
GPT.BatteryCheckCounter = 0;
return;
}
@@ -0,0 +1,97 @@
#ifndef LED_APA_102_H
#define LED_APA_102_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* APA-102-2020-256-8A-20190612: Series data structure
* +-------------------+------------------------- ... -+-----------------+
* | start_frame(4B) | led_frame(4B) *LED_TANDEM_N | end_frame(4B) |
* +-------------------+------------------------- ... -+-----------------+
* / \
* / led_frame(4B) \
* / \
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | 111 | bright | blue | green | red |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#include "driver/spi_ctrl.h"
#if (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
#define DEF_LED_TANDEN_N 12
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
#define DEF_LED_TANDEN_N 1
#endif
#ifdef DEF_LED_TANDEN_N
#define LED_TANDEM_N DEF_LED_TANDEN_N
#else
#define LED_TANDEM_N 12
#endif
enum led_series_nb_e {
LED_NB_1 = 0,
LED_NB_2,
LED_NB_3,
LED_NB_4,
LED_NB_5,
LED_NB_6,
LED_NB_7,
LED_NB_8,
LED_NB_9,
LED_NB_10,
LED_NB_11,
LED_NB_12,
LED_NB_MAX = LED_TANDEM_N,
};
enum led_bright_e {
LED_BR_LV0 = 0x00,
LED_BR_LV1 = 0x01,
LED_BR_LV8 = 0x08,
LED_BR_MAX = 0x1F,
};
enum led_color_e {
LED_CLR_BLACK = 0,
LED_CLR_WHITE,
LED_CLR_RED,
LED_CLR_ORANGE,
LED_CLR_YELLOW,
LED_CLR_GREEN,
LED_CLR_CYAN,
LED_CLR_BLUE,
LED_CLR_PURPLE,
LED_CLR_MAGENTA,
LED_CLR_YELLOWGREEN,
LED_CLR_EMERALD,
LED_CLR_MAX,
};
struct led_color_t {
uint8_t b;
uint8_t g;
uint8_t r;
};
struct led_frame_t {
uint8_t bright: 5,
rsvd: 3;
struct led_color_t color;
};
int led_color_set(enum led_series_nb_e led_nb, enum led_bright_e bright, enum led_color_e color);
int led_color_code_set(enum led_series_nb_e led_nb, enum led_bright_e bright, struct led_color_t *color);
int led_rainbow(enum led_bright_e bright);
#ifdef __cplusplus
}
#endif
#endif // LED_APA_102_H
@@ -1,20 +1,4 @@
/*
* APA-102-2020-256-8A-20190612: Series data structure
* +-------------------+------------------------- ... -+-----------------+
* | start_frame(4B) | led_frame(4B) *LED_TANDEM_N | end_frame(4B) |
* +-------------------+------------------------- ... -+-----------------+
* / \
* / led_frame(4B) \
* / \
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | 111 | bright | blue | green | red |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
#include "application_config/application_config.h"
#include "HAL/cc2650_driver/spi_ctrl.h"
#include "HAL/APA102_2020_256_8x4.h"
#include "hardware/led_APA_102.h"
#define LED_FRME_FILL_RSVD(_f) (_f)->rsvd = 0x07 // 0x11100000 || bright
#define LED_SERIES_D_START 0x00000000
@@ -115,7 +99,8 @@ static int __led_color_set(enum led_series_nb_e led_nb, struct led_frame_t *led_
__led_complete(sd);
spi0_write(NULL, (void *)(sd), sizeof(struct led_series_data_t));
#define WRITE_TO_HW(_d, _l) spi0_write(NULL, (uint8_t *)(_d), (_l))
WRITE_TO_HW(sd, sizeof(struct led_series_data_t));
return 0;
}
@@ -0,0 +1,137 @@
#ifndef AD5940
#define AD5940
#define NV2USC(_n) (n / 1e7 * 625 + 25000) // [5nV] / 1e6 * 5 * 12.5 + 25000
static void setEIS_EIS_cali(void)
{
AD5940_SPIWriteReg(LPDACCON0, 0x00000001); // Direct from LPDACDAT0 | Vzero(6bit) & Vbias(12bit) | LP 2.5v as ref
AD5940_SPIWriteReg(LPDACSW0, 0b111111); // orverride LPDACCON0[5] | LPDACSW0[0~5] close
AD5940_SPIWriteReg(HSRTIACON, 0x00000000); // CTIA=1pF | SW6 off(open) | RTIA=200R
AD5940_SPIWriteReg(HSTIACON, 0x00000001); // Vzero
AD5940_SPIWriteReg(ADCCON, 0x00000101); // PGA=1 | HSTIA neg input | HSTIA pos signal
AD5940_SPIWriteReg(DFTCON, 0x00000091); // DFTNUM=2048 | enable hanning window | SINC2
AD5940_SPIWriteReg(SWCON, 0x00026355); // D5 | P5 | N3 | T6 | T9 close
if (instru.gain_lv_hstia < HSRTIA_MAX) {
instru.HSTIAAutoGainEnable = 0;
HSTIAGainCtrl(instru.gain_lv_hstia);
} else {
instru.HSTIAAutoGainEnable = 1;
instru.gain_lv_hstia = HSRTIA_200R;
HSTIAGainCtrl(instru.gain_lv_hstia);
}
int32_t LPVolt = 0;
LPVolt = (instru.dcbias - 25000) * 4 * 4000;
DAC_outputV(LPVolt);
cali_SetWGAmp(instru.acamp);
AD5940_SPIWriteReg(AFECON, 0x0031CFC0); // en dc DAC buf | HSDAC ref disable | LDO buf current limit enable | en SINC2 |
// DFT hardware accelerator enable | waveform generator enable | HSTIA enable |
// intru amplifier enable | excitation buf enable | ADC conversions enable |
// ADC power enable | HSDAC enable | HP ref enable
//HIGH POWER MODE
AD5940_SPIWriteReg(PMBW, 0x0000000D); // HS mode | Set cutooff frequency to 250kHz, -3 dB bandwidth
AD5940_SPIWriteReg(CLKSEL, 0x0000);
AD5940_SPIWriteReg(CLKCON0KEY, 0xA815); // !!!Write 0xA815 to this register before accessing the CLKCON0 register
AD5940_SPIWriteReg(CLKCON0, 0x0442); //6bit system clock divider //set divider = 2
AD5940_SPIWriteReg(HSOSCCON, 0x00000000); // HP osc select 32MHz output
AD5940_SPIWriteReg(ADCFILTERCON, 0x00000311); // en DFT clk | en DAC wave clk | en SINC2 filter clk | 2 ADC samples used for average function |
// SINC3 filter oversampling rate is 800kSPS |
// SINC2 filter oversampling rate is 178 samples |
// disable average | SINC3 filter enable |
// Bypass 50/60Hz | ADC data rate 800kHz
AD5940_SPIWriteReg(HSDACCON, 0x0000000E); // HSDAC gain = 2, DAC update rate = ACLK/HSDACCON = 32Mhz/7
AD5940_SPIWriteReg(ADCBUFCON, 0x005F3D0F); //recommended
SetEISHIGHZ(0);
}
static void setEIS_CV (void)
{
//Clock and Ref
AD5940_SPIWriteReg(CLKSEL, 0x0);
AD5940_SPIWriteReg(HSOSCCON, 0x00000004); //16 MHz output
AD5940_SPIWriteReg(0x2180, 0x00000037); //0b110110
//Configure LPDAC LPTIA
AD5940_SPIWriteReg(LPREFBUFCON, 0x0); //enable lpref and lp 2.5V buffer
AD5940_SPIWriteReg(LPDACSW0, 0x00000034); // disconnect Vbias and Vzero
AD5940_SPIWriteReg(LPTIASW0, 0x00000034); // SW2 | SW4 | SW5
LPTIAGainCtrl(instru.gain_lv_lptia);
AD5940_SPIWriteReg(LPDACCON0, 0x00000001);
//Configure ADC | ADCDAT (0x2074)
AD5940_SPIWriteReg(ADCCON, 0x00010221); //PGA = 1.5 | LPTIA- | LPTIA_OUT
AD5940_SPIWriteReg(ADCFILTERCON, 0x00002011); // Sinc3 En | SINC3OSR2 | SINC2OSR22
AD5940_SPIWriteReg(DFTCON, 0x00000001); // Sinc2 to DFT | DFTNUM4
// mean function for calibration
AD5940_SPIWriteReg(RRR_AFE_STATSCON, 0x00000001); // don't use mean function // dev | 128 samples | enable statistics
//AFE and PWMB
AD5940_SPIWriteReg(AFECON, 0x00098780); //ADC on //0b10011000011110000000
AD5940_SPIWriteReg(PMBW, 0x00000005); //fc 50kHz, low power mode
}
static void set_hs_only(void)
{
AD5940_SPIWriteReg(LPDACCON0, 0x00000001); // Direct from LPDACDAT0 | Vzero(6bit) & Vbias(12bit) | LP 2.5v as ref
AD5940_SPIWriteReg(LPDACSW0, 0b111111); // orverride LPDACCON0[5] | LPDACSW0[0~5] close
AD5940_SPIWriteReg(HSRTIACON, 0x00000000); // CTIA=1pF | SW6 off(open) | RTIA=200R
AD5940_SPIWriteReg(HSTIACON, 0x00000001); // Vzero
AD5940_SPIWriteReg(ADCCON, 0x00000101); // PGA=1 | HSTIA neg input | HSTIA pos signal
AD5940_SPIWriteReg(DFTCON, 0x00000091); // DFTNUM=2048 | enable hanning window | SINC2
AD5940_SPIWriteReg(SWCON, 0x00026355); // D5 | P5 | N3 | T6 | T9 close
AD5940_SPIWriteReg(AFECON, 0x0031CFC0); // en dc DAC buf | HSDAC ref disable | LDO buf current limit enable | en SINC2 |
// DFT hardware accelerator enable | waveform generator enable | HSTIA enable |
// intru amplifier enable | excitation buf enable | ADC conversions enable |
// ADC power enable | HSDAC enable | HP ref enable
//HIGH POWER MODE
AD5940_SPIWriteReg(PMBW, 0x0000000D); // HS mode | Set cutooff frequency to 250kHz, -3 dB bandwidth
AD5940_SPIWriteReg(CLKSEL, 0x0000);
AD5940_SPIWriteReg(CLKCON0KEY, 0xA815); // !!!Write 0xA815 to this register before accessing the CLKCON0 register
AD5940_SPIWriteReg(CLKCON0, 0x0442); //6bit system clock divider //set divider = 2
AD5940_SPIWriteReg(HSOSCCON, 0x00000000); // HP osc select 32MHz output
AD5940_SPIWriteReg(ADCFILTERCON, 0x00000311); // en DFT clk | en DAC wave clk | en SINC2 filter clk | 2 ADC samples used for average function |
// SINC3 filter oversampling rate is 800kSPS |
// SINC2 filter oversampling rate is 178 samples |
// disable average | SINC3 filter enable |
// Bypass 50/60Hz | ADC data rate 800kHz
AD5940_SPIWriteReg(HSDACCON, 0x0000000E); // HSDAC gain = 2, DAC update rate = ACLK/HSDACCON = 32Mhz/7
AD5940_SPIWriteReg(ADCBUFCON, 0x005F3D0F); //recommended
SetEISHIGHZ(0);
return;
}
// static void AD5940_Initialize() {
// AD5940_SPIWriteReg(0x0908, 0x02C9);//initiation
// AD5940_SPIWriteReg(0x0C08, 0x206C);
// AD5940_SPIWriteReg(0x21F0, 0x0010);
// AD5940_SPIWriteReg(0x0410, 0x02C9);
// AD5940_SPIWriteReg(0x0A28, 0x0009);
// AD5940_SPIWriteReg(ADCBUFCON, 0x0104);
// AD5940_SPIWriteReg(0x0A04, 0x4859);
// AD5940_SPIWriteReg(0x0A04, 0xF27B);
// AD5940_SPIWriteReg(0x0A00, 0x8009);
// AD5940_SPIWriteReg(PMBW, 0x0000);
// }
// static void AD5940_sftreset(){
// AD5940_SPIWriteReg(0x0424, 0xA158);
// CPUdelay_us(200);
// }
#endif
@@ -0,0 +1,903 @@
#include <math.h>
#ifndef EliteADC
#define EliteADC
#include "board.h"
#include "EliteSPI.h"
#include "EliteNotify.h"
#include "eis_cali_table.h"
// Elite ADC macro
// ADC command, Elite will use these cmd to control ADC
#define CMD_CURRENT_MEASURE 0xC5 //0b11000101
#define CMD_VOLT_MEASURE 0xD5 //0b11010101
#define CMD_DAC_MEASURE 0xE5 //0b11100101
#define CMD_BATTERY_MEASURE 0xF1 //0b11110001
// controller command, these are command from control box
#define ADC_CH_CURRENT 0x00
#define ADC_CH_VOLT 0x01
#define ADC_CH_DAC 0x02
#define ADC_CH_BAT 0x03
/* Gain Control for Vin & Iin */
static void IinADCGainControl(uint8_t IinADCLevel){
// if(IinADCLevel == 0){
// // ADC gain level = 0, using 3M resister
// PIN_setOutputValue(pin_handle, Turnon_I_LARGE, 0);
// PIN_setOutputValue(pin_handle, Turnon_I_MID, 0);
// PIN_setOutputValue(pin_handle, Turnon_I_SMALL, 0);
// }
// else if(IinADCLevel == 1){
// // ADC gain level = 1, using 100K resister
// PIN_setOutputValue(pin_handle, Turnon_I_LARGE, 0);
// PIN_setOutputValue(pin_handle, Turnon_I_MID, 0);
// PIN_setOutputValue(pin_handle, Turnon_I_SMALL, 1);
// }
// else if(IinADCLevel == 2){
// // ADC gain level = 2, using 3K resister
// PIN_setOutputValue(pin_handle, Turnon_I_LARGE, 0);
// PIN_setOutputValue(pin_handle, Turnon_I_MID, 1);
// PIN_setOutputValue(pin_handle, Turnon_I_SMALL, 0);
// }
// else if(IinADCLevel == 3){
// // ADC gain level = 3, using 100R resistor
// PIN_setOutputValue(pin_handle, Turnon_I_LARGE, 1);
// PIN_setOutputValue(pin_handle, Turnon_I_MID, 0);
// PIN_setOutputValue(pin_handle, Turnon_I_SMALL, 0);
// }
// else if(IinADCLevel == 4){
// // ADC gain level = 3, auto gain (using 100R resister)
// PIN_setOutputValue(pin_handle, Turnon_I_LARGE, 1);
// PIN_setOutputValue(pin_handle, Turnon_I_MID, 0);
// PIN_setOutputValue(pin_handle, Turnon_I_SMALL, 0);
// }
// else{
// // default using 100R resister
// PIN_setOutputValue(pin_handle, Turnon_I_LARGE, 1);
// PIN_setOutputValue(pin_handle, Turnon_I_MID, 0);
// PIN_setOutputValue(pin_handle, Turnon_I_SMALL, 0);
// }
// if(IinADCLevel == 0 || IinADCLevel == 1 || IinADCLevel == 2 || IinADCLevel == 3){
// lastIinADCGainLevel = IinADCLevel;
// }else{
// lastIinADCGainLevel = 3;
// }
// record_flag = false;
}
static void VinADCGainCtrl(uint8_t VinADCLevel){
// if(VinADCLevel == 0){
// // Vin ADC gain level = 0, using 1M resister
// PIN_setOutputValue(pin_handle, Turnon_V_SMALL, 0);
// PIN_setOutputValue(pin_handle, Turnon_V_MID, 0);
// }
// else if(VinADCLevel == 1){
// // Vin ADC gain level = 1, using 30K resister
// PIN_setOutputValue(pin_handle, Turnon_V_SMALL, 0);
// PIN_setOutputValue(pin_handle, Turnon_V_MID, 1);
// }
// else if(VinADCLevel == 2){
// // Vin ADC gain level = 2, using 1K resister
// PIN_setOutputValue(pin_handle, Turnon_V_SMALL, 1);
// PIN_setOutputValue(pin_handle, Turnon_V_MID, 0);
// }
// else if(VinADCLevel == 3){
// // Vin ADC gain level = 3, auto gain (using 1K resister)
// PIN_setOutputValue(pin_handle, Turnon_V_SMALL, 1);
// PIN_setOutputValue(pin_handle, Turnon_V_MID, 0);
// }
// else{
// // default using 1K resister
// PIN_setOutputValue(pin_handle, Turnon_V_SMALL, 1);
// PIN_setOutputValue(pin_handle, Turnon_V_MID, 0);
// }
// if(VinADCLevel == 0 || VinADCLevel == 1 || VinADCLevel == 2){
// lastVinADCGainLv = VinADCLevel;
// }else{
// lastVinADCGainLv = 2;
// }
// record_flag = false;
}
#define RTIACON_200R 0b0000
#define RTIACON_1K 0b0001
#define RTIACON_5K 0b0010
#define RTIACON_10K 0b0011
#define RTIACON_20K 0b0100
#define RTIACON_40K 0b0101
#define RTIACON_80K 0b0110
#define RTIACON_160K 0b0111
#define RTIACON_OPEN 0b1111
static void HSTIAGainCtrl(uint8_t HSTIALevel)
{
/* HSRTIACON[12:5] = CTIACON, disconnect;
HSRTIACON[4] = TIASW6CON, diode not in parallel with RTIA;
HSRTIACON[3:0] = RTIA */
uint32_t reg;
uint8_t data;
uint8_t g = HSTIALevel;
if (g >= HSRTIA_MAX)
return;
reg = 0x00000000;
switch(g) {
case HSRTIA_160K:
data = RTIACON_160K;
break;
case HSRTIA_80K:
data = RTIACON_80K;
break;
case HSRTIA_40K:
data = RTIACON_40K;
break;
case HSRTIA_20K:
data = RTIACON_20K;
break;
case HSRTIA_10K:
data = RTIACON_10K;
break;
case HSRTIA_5K:
data = RTIACON_5K;
break;
case HSRTIA_1K:
data = RTIACON_1K;
break;
case HSRTIA_200R:
data = RTIACON_200R;
break;
default:
break;
}
AD5940_SPIWriteReg(HSRTIACON, reg | (uint32_t)data);
last_gain_hstia = g;
record_flag = false;
gainChange_flag = true;
return;
}
static void LPTIAGainCtrl(uint8_t LPTIALevel){
/* LPTIACON0[15:13] = RLPF, disconnect low pass filter;
LPTIACON0[12:10] = RLOAD, set at 0R;
LPTIACON0[9:5] = RTIA;
LPTIACON0[4:3] = IBOOST, High current mode; */
uint32_t code = 0x00000018; // disconnect LPF | RL 0R | RTIA = LPTIALevel | high I mode
uint8_t data = 1; // RTIA = 200R
if (LPTIALevel == LPRTIA_64K) {
data = 17; //64k
}
else if (LPTIALevel == LPRTIA_8K) {
data = 7; //8K
}
else if (LPTIALevel == LPRTIA_1K) {
data = 2; //1K
}
else if (LPTIALevel == LPRTIA_200R) {
data = 1; //200R
}
else if (LPTIALevel == LPRTIA_GAIN_AUTO) {
data = 1;
}
code = (code & ~(0b11111 << 5)) | (data << 5);
AD5940_SPIWriteReg(LPTIACON0, code); //LPTIACON0
if(LPTIALevel == 0 || LPTIALevel == 1 || LPTIALevel == 2 || LPTIALevel == 3){
last_gain_lptia = LPTIALevel;
}else{
last_gain_lptia = 3;
}
record_flag = false;
}
static void disconnect_rtia(){
/* LPTIACON0[15:13] = RLPF, disconnect low pass filter;
LPTIACON0[12:10] = RLOAD, set at 0R;
LPTIACON0[9:5] = RTIA;
LPTIACON0[4:3] = IBOOST, High current mode; */
uint32_t code = 0x00000018; // disconnect LPF | RL 0R | RTIA = LPTIALevel | high I mode
uint8_t data = 0; // RTIA = disconnect
code = (code & ~(0b11111 << 5)) | (data << 5);
AD5940_SPIWriteReg(LPTIACON0, code); //LPTIACON0
return;
}
// static void ADCChannelSelect(uint8_t ADCChannel){
// // set ADC parameter
// // 0xC1~F1 = reading AIN0~AIN3. Using FSR+-6V, resolution = 187.5uV
// // 0xC5~F5 = reading AIN0~AIN3. Using FSR+-2V, resolution = 62.5 uV
// switch(ADCChannel){
// // AINp is AIN0; AINn is GND
// // measure AIN0, which is a current measure
// case ADC_CH_CURRENT :{
// ADC_write(CMD_CURRENT_MEASURE);
// break;
// }
// // AINp is AIN1; AINn is GND
// // AIN1, which is a volt measure
// case ADC_CH_VOLT :{
// ADC_write(CMD_VOLT_MEASURE);
// break;
// }
// // AINp is AIN2; AINn is GND
// // AIN2, measure DAC voltage (Note that this is NOT DAC real output value!!)
// case ADC_CH_DAC :{
// ADC_write(CMD_DAC_MEASURE);
// break;
// }
// // measure battery volt
// case ADC_CH_BAT :{
// ADC_write(CMD_BATTERY_MEASURE);
// break;
// }
// default :{
// break;
// }
// }
// }
// static void ReadADCIin(uint8_t *buf){
// // Read data twice since the first data we get is previous data
// ADCChannelSelect(ADC_CH_CURRENT);
// ADC_read(buf);
// ADCChannelSelect(ADC_CH_CURRENT);
// ADC_read(buf);
// }
// static void ReadADCVin(uint8_t *buf){
// // Read data twice since the first data we get is previous data
// // VinADCGainControl(INSTRUCTION.VinADCGainLevel);
// ADCChannelSelect(ADC_CH_VOLT);
// ADC_read(buf);
// ADCChannelSelect(ADC_CH_VOLT);
// ADC_read(buf);
// }
// static void ReadADCVout(uint8_t *buf){
// // Read data twice since the first data we get is previous data
// ADCChannelSelect(ADC_CH_DAC);
// ADC_read(buf);
// ADCChannelSelect(ADC_CH_DAC);
// ADC_read(buf);
// }
// static void ReadADCBat(uint8_t *buf){
// // Read data twice since the first data we get is previous data
// ADCChannelSelect(ADC_CH_BAT);
// ADC_read(buf);
// ADCChannelSelect(ADC_CH_BAT);
// ADC_read(buf);
// }
static int32_t ReadRawADC() {
// select_REG_RRR(ADCDAT);
return AD5940_SPIReadReg(ADCDAT);
}
static int32_t ReadRealZ() {
// select_REG_RRR(DFTREAL);
return AD5940_SPIReadReg(DFTREAL);
}
static int32_t ReadImagZ() {
// select_REG_RRR(DFTIMAG);
return AD5940_SPIReadReg(DFTIMAG);
}
static uint32_t ReadSINC2() {
// select_REG_RRR(0x2080);
return AD5940_SPIReadReg(0x2080);
}
/* for Elite1.5-re */
// Iin theoretical boundary <2.67, 1.89~80, 63~2600, >1900 (uA)
#define I_GAIN_SMALL_BOUNDARY 4000 // 4 uA = 4,000,000 pA
#define I_GAIN_MID1_BOUNDARY1 2500 // 2.5 uA = 2,500,000 pA
#define I_GAIN_MID1_BOUNDARY2 100000 // 100 uA = 100,000,000 pA
#define I_GAIN_MID2_BOUNDARY1 85000 // 85 uA = 85,000,000 pA
#define I_GAIN_MID2_BOUNDARY2 2050000 // 2050 uA = 2,050,000 nA
#define I_GAIN_LARGE_BOUNDARY 1800000 // 1800 uA = 1,800,000 nA
// Vin theoretical boundary <7, 5~200, >100 (mV)
#define VIN_GAIN_SMALL_BOUNDARY 7000 // 7 mV = 7,000,000 nV
#define VIN_GAIN_MID1_BOUNDARY1 5000 // 5 mV = 5,000,000 nV
#define VIN_GAIN_MID1_BOUNDARY2 300000 // 300 mV = 300,000,000 nV
#define VIN_GAIN_LARGE_BOUNDARY 250000 // 250 mV = 250,000,000 nV
#define LPTIA_GAIN_SMALL_BOUNDARY 6000 // 6 uA = 1,500,000 pA
#define LPTIA_GAIN_MID1_BOUNDARY1 5000 // 5 uA = 1,000,000 pA
#define LPTIA_GAIN_MID1_BOUNDARY2 60000 // 60 uA = 60,000,000 pA
#define LPTIA_GAIN_MID2_BOUNDARY1 50000 // 50 uA = 40,000,000 pA
#define LPTIA_GAIN_MID2_BOUNDARY2 600000 // 600 uA = 175,000 nA
#define LPTIA_GAIN_LARGE_BOUNDARY 500000 // 500 uA = 120,000 nA
#define HSTIA_G0_MAX_BOUNDARY (3740*9/10)// = 3366 nA
#define HSTIA_G1_MIN_BOUNDARY (3740*8/10)// = 2992 nA
#define HSTIA_G1_MAX_BOUNDARY (9580*9/10)// = 8622 nA
#define HSTIA_G2_MIN_BOUNDARY (9580*8/10)// = 7664 nA
#define HSTIA_G2_MAX_BOUNDARY (19694*9/10)// = 17724 nA
#define HSTIA_G3_MIN_BOUNDARY (19694*8/10)// = 15755 nA
#define HSTIA_G3_MAX_BOUNDARY (38856*9/10)// = 34970 nA
#define HSTIA_G4_MIN_BOUNDARY (38856*8/10)// = 31084 nA
#define HSTIA_G4_MAX_BOUNDARY (76553*9/10)// = 68897 nA
#define HSTIA_G5_MIN_BOUNDARY (76553*8/10)// = 61242 nA
#define HSTIA_G5_MAX_BOUNDARY (155069*9/10)// = 139562 nA
#define HSTIA_G6_MIN_BOUNDARY (155069*8/10)// = 124055 nA
#define HSTIA_G6_MAX_BOUNDARY (396902*9/10)// = 357211 nA
#define HSTIA_G7_MIN_BOUNDARY (396902*8/10)// = 317521 nA
static int32_t Cali_LPTIA (uint32_t value, uint8_t gain_level)
{
/* res = a*x^2 + b*x + c */
int64_t res;
res = (CaliTable.lptia_current[gain_level].lptia_a * value * value +
CaliTable.lptia_current[gain_level].lptia_b * value +
CaliTable.lptia_current[gain_level].lptia_c * 1e4) / 1e8;
return (int32_t)res;
}
//EIS Function//
static int32_t read_LPTIA_Iin(){
static int32_t ADCraw, Iin;
// select_REG_RRR(ADCDAT);
ADCraw = AD5940_SPIReadReg(ADCDAT);
Iin = Cali_LPTIA(ADCraw, instru.gain_lv_lptia);
InputNotify(NOTIFY_CURRENT, Iin);
// InputNotify(NOTIFY_IMPEDANCE, instru.gain_lv_lptia);
return Iin;
}
static int32_t read_LPTIA_Vin(){
static int32_t ADCraw, Vin;
int64_t res, cali_a, cali_b;
ADCraw = AD5940_SPIReadReg(ADCDAT);
/* res = a*x + b */
if (instru.measure_vin_range == 0) { //measure +volt (zero = 0,bias = 0)
cali_a = 3724236303;
cali_b = -31038393762537;
} else if (instru.measure_vin_range == 1) { //measure +-1V (zero = 32,bias = 2048)
cali_a = 3722206919;
cali_b = -140964299129767;
} else if (instru.measure_vin_range == 2) { //measure -volt (zero = 62,bias = 3910)
cali_a = 3720451376;
cali_b = -240791817290944;
}
res = ((int64_t)cali_a * ADCraw + cali_b) / 1e8;
Vin = (int32_t)res;
InputNotify(NOTIFY_VOLT, Vin);
// InputNotify(NOTIFY_IMPEDANCE, ADCraw);
return (int32_t)Vin;
}
/* phase[4][4]; hstia_current[4][4] */
/* [Phase][HSTIA] */
static int32_t Cali_LPDAC (uint32_t value)
{
int64_t res;
if (value == 25000) { // if DC offset = 0V; force DC bias to OffsetZero
res = (22707 - 25000) * 4 * 4000;
} else {
res = (value * CaliTable.ac_dcbais.up_a + CaliTable.ac_dcbais.up_b) / 1e7;
}
return (int32_t)res;
}
static uint32_t Cali_HSAMP (uint16_t value, uint32_t freq)
{
int64_t res;
float temp;
long long m = CaliTable.ac_amp.amp_m;
long long w = CaliTable.ac_amp.amp_w;
float fr = freq / 100;
temp = 1 / (1 + fr / w * fr / w);
res = value * 1e7 / m / temp;
if (res > 2047)
res = 2047;
else if (res < 0)
res = 0;
return (uint32_t) res;
}
static int32_t Cali_HSTIA (uint64_t value, uint8_t gain_level)
{
/* res = a*x^2 + b*x + c */
int64_t res;
res = (CaliTable.hstia_current[gain_level][0].hstia_a * value * value +
CaliTable.hstia_current[gain_level][0].hstia_b * value ) / 1e8;//nA
return (int32_t)res;
}
static int32_t read_HSTIA_Iin(){
uint32_t originalDFT;
int64_t mag;
int32_t RealCurrent;
int64_t i;
int64_t r;
int64_t f;
int64_t rolloff_cali = CaliTable.hstia_current[instru.gain_lv_hstia][0].rolloff;
instru.real = neg_18bit(ReadRealZ());
instru.imag = neg_18bit(ReadImagZ());
i = (int64_t)instru.imag;
r = (int64_t)instru.real;
f = (int64_t)instru.fset;
originalDFT = sqrt(i * i + r * r);
mag = (int64_t)originalDFT * (1 + (f * f) / (rolloff_cali * rolloff_cali) / 1e4);
RealCurrent = Cali_HSTIA(mag, instru.gain_lv_hstia);
return RealCurrent;
}
static void AutoChangeLPTIAGain(int32_t RealCurrent){
if(instru.gain_lv_lptia == LPRTIA_200R){
if(RealCurrent < LPTIA_GAIN_LARGE_BOUNDARY && RealCurrent > -1*LPTIA_GAIN_LARGE_BOUNDARY){
// switch to 1 level current(small)
if (RealCurrent < LPTIA_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*LPTIA_GAIN_MID1_BOUNDARY1){
I_GAIN_3M_counter++;
if(I_GAIN_3M_counter > 2){
instru.gain_lv_lptia = LPRTIA_64K;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_3M_counter = 0;
}
}
// switch to 2 level current
else if (RealCurrent < LPTIA_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*LPTIA_GAIN_MID2_BOUNDARY1){
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
instru.gain_lv_lptia = LPRTIA_8K;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_100K_counter = 0;
}
}
// switch to 3 level current
else{
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
instru.gain_lv_lptia = LPRTIA_1K;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_3K_counter = 0;
}
}
}else{
if(I_GAIN_3K_counter > 0){
I_GAIN_3K_counter--;
}
if(I_GAIN_100K_counter > 0){
I_GAIN_100K_counter--;
}
if(I_GAIN_3M_counter > 0){
I_GAIN_3M_counter--;
}
}
}
else if(instru.gain_lv_lptia == LPRTIA_1K){
// switch to 4 level current(large)
if(RealCurrent > LPTIA_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*LPTIA_GAIN_MID2_BOUNDARY2){
I_GAIN_100R_counter++;
if(I_GAIN_100R_counter > 2){
instru.gain_lv_lptia = LPRTIA_200R;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_100R_counter = 0;
}
}
else if (RealCurrent < LPTIA_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*LPTIA_GAIN_MID2_BOUNDARY1){
// switch to 1 level current(small)
if(RealCurrent < LPTIA_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*LPTIA_GAIN_MID1_BOUNDARY1){
I_GAIN_3M_counter++;
if(I_GAIN_3M_counter > 2){
instru.gain_lv_lptia = LPRTIA_64K;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_3M_counter = 0;
}
}
// switch to 2 level current
else{
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
instru.gain_lv_lptia = LPRTIA_8K;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_100K_counter = 0;
}
}
}else{
if(I_GAIN_100R_counter > 0){
I_GAIN_100R_counter--;
}
if(I_GAIN_100K_counter > 0){
I_GAIN_100K_counter--;
}
if(I_GAIN_3M_counter > 0){
I_GAIN_3M_counter--;
}
}
}
else if(instru.gain_lv_lptia == LPRTIA_8K){
// switch to 1 level current(small)
if(RealCurrent < LPTIA_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*LPTIA_GAIN_MID1_BOUNDARY1){
I_GAIN_3M_counter++;
if(I_GAIN_3M_counter > 2){
instru.gain_lv_lptia = LPRTIA_64K;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_3M_counter = 0;
}
}
else if (RealCurrent > LPTIA_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*LPTIA_GAIN_MID1_BOUNDARY2){
// switch to 4 level current(large)
if(RealCurrent > LPTIA_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*LPTIA_GAIN_MID2_BOUNDARY2){
I_GAIN_100R_counter++;
if(I_GAIN_100R_counter > 2){
instru.gain_lv_lptia = LPRTIA_200R;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_100R_counter = 0;
}
}
// switch to 3 level current
else{
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
instru.gain_lv_lptia = LPRTIA_1K;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_3K_counter = 0;
}
}
}else{
if(I_GAIN_100R_counter > 0){
I_GAIN_100R_counter--;
}
if(I_GAIN_3K_counter > 0){
I_GAIN_3K_counter--;
}
if(I_GAIN_3M_counter > 0){
I_GAIN_3M_counter--;
}
}
}
else if(instru.gain_lv_lptia == LPRTIA_64K){
if(RealCurrent > LPTIA_GAIN_SMALL_BOUNDARY || RealCurrent < -1*LPTIA_GAIN_SMALL_BOUNDARY){
// switch to 4 level current(large)
if(RealCurrent > LPTIA_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*LPTIA_GAIN_MID2_BOUNDARY2){
I_GAIN_100R_counter++;
if(I_GAIN_100R_counter > 2){
instru.gain_lv_lptia = LPRTIA_200R;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_100R_counter = 0;
}
}
// switch to 3 level current
else if(RealCurrent > LPTIA_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*LPTIA_GAIN_MID1_BOUNDARY2){
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
instru.gain_lv_lptia = LPRTIA_1K;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_3K_counter = 0;
}
}
// switch to 2 level current
else{
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
instru.gain_lv_lptia = LPRTIA_8K;
LPTIAGainCtrl(instru.gain_lv_lptia);
I_GAIN_100K_counter = 0;
}
}
}else{
if(I_GAIN_100R_counter > 0){
I_GAIN_100R_counter--;
}
if(I_GAIN_3K_counter > 0){
I_GAIN_3K_counter--;
}
if(I_GAIN_100K_counter > 0){
I_GAIN_100K_counter--;
}
}
}
}
static void change_hstia_gain(uint8_t gain)
{
uint8_t g = gain;
static uint8_t gain_cnt = 0;
gain_cnt++;
if (gain_cnt > 2) {
instru.gain_lv_hstia = g;
HSTIAGainCtrl(g);
gain_cnt = 0;
}
return;
}
static void AutoChangeHSTIAGain(int32_t RealCurrent)
{
int64_t g0_max = HSTIA_G0_MAX_BOUNDARY;
int64_t g1_min = HSTIA_G1_MIN_BOUNDARY;
int64_t g1_max = HSTIA_G1_MAX_BOUNDARY;
int64_t g2_min = HSTIA_G2_MIN_BOUNDARY;
int64_t g2_max = HSTIA_G2_MAX_BOUNDARY;
int64_t g3_min = HSTIA_G3_MIN_BOUNDARY;
int64_t g3_max = HSTIA_G3_MAX_BOUNDARY;
int64_t g4_min = HSTIA_G4_MIN_BOUNDARY;
int64_t g4_max = HSTIA_G4_MAX_BOUNDARY;
int64_t g5_min = HSTIA_G5_MIN_BOUNDARY;
int64_t g5_max = HSTIA_G5_MAX_BOUNDARY;
int64_t g6_min = HSTIA_G6_MIN_BOUNDARY;
int64_t g6_max = HSTIA_G6_MAX_BOUNDARY;
int64_t g7_min = HSTIA_G7_MIN_BOUNDARY;
uint8_t gain = instru.gain_lv_hstia;
int32_t curr = RealCurrent;
if (gain == HSRTIA_200R) {
if (curr < g7_min && curr > -1 * g7_min)
change_hstia_gain(HSRTIA_1K);
return;
}
if (gain == HSRTIA_1K) {
if (curr > g6_max || curr < -1 * g6_max)
change_hstia_gain(HSRTIA_200R);
else if (curr < g6_min && curr > -1 * g6_min)
change_hstia_gain(HSRTIA_5K);
return;
}
if (gain == HSRTIA_5K) {
if (curr > g5_max || curr < -1 * g5_max)
change_hstia_gain(HSRTIA_1K);
else if (curr < g5_min && curr > -1 * g5_min)
change_hstia_gain(HSRTIA_10K);
return;
}
if (gain == HSRTIA_10K) {
if (curr > g4_max || curr < -1 * g4_max)
change_hstia_gain(HSRTIA_5K);
else if (curr < g4_min && curr > -1 * g4_min)
change_hstia_gain(HSRTIA_20K);
return;
}
if (gain == HSRTIA_20K) {
if (curr > g3_max || curr < -1 * g3_max)
change_hstia_gain(HSRTIA_10K);
else if (curr < g3_min && curr > -1 * g3_min)
change_hstia_gain(HSRTIA_40K);
return;
}
if (gain == HSRTIA_40K) {
if (curr > g2_max || curr < -1 * g2_max)
change_hstia_gain(HSRTIA_20K);
else if (curr < g2_min && curr > -1 * g2_min)
change_hstia_gain(HSRTIA_80K);
return;
}
if (gain == HSRTIA_80K) {
if (curr > g1_max || curr < -1 * g1_max)
change_hstia_gain(HSRTIA_40K);
else if (curr < g1_min && curr > -1 * g1_min)
change_hstia_gain(HSRTIA_160K);
return;
}
if (gain == HSRTIA_160K) {
if (curr > g0_max || curr < -1 * g1_max)
change_hstia_gain(HSRTIA_80K);
return;
}
return;
}
static void SetCTIA(uint8_t ret){
uint64_t code;
// select_REG_RRR(HSRTIACON);
code = AD5940_SPIReadReg(HSRTIACON);
code = (code & (~(0x7F << 5))) | (ret << 5);
AD5940_SPIWriteReg(HSRTIACON, code);
}
static void EnDFTnADC(uint8_t ret){
uint32_t code;
// select_REG_RRR(AFECON);
code = AD5940_SPIReadReg(AFECON);
code = (code & (~0x00008100)) | (ret << 15) | (ret << 8);
AD5940_SPIWriteReg(AFECON, code);
}
static void SetADCDataRate(uint8_t dataRate){ //1: 800k | 0: 1.6M
uint32_t code;
// select_REG_RRR(ADCFILTERCON); //0x2044
code = AD5940_SPIReadReg(ADCFILTERCON);
code = (code & (~1)) | (dataRate);
AD5940_SPIWriteReg(ADCFILTERCON, code);
}
static void SelDFTin(uint8_t ret){ // 1: SINC3 | 2: raw | 0 or 3: SINC2
uint32_t code;
// select_REG_RRR(DFTCON);
code = AD5940_SPIReadReg(DFTCON);
code = (code & (~(3 << 20))) | (ret << 20);
AD5940_SPIWriteReg(DFTCON, code);
}
static void BpNotch(uint8_t ret){ // 1: bypass notch
uint32_t code;
// select_REG_RRR(ADCFILTERCON);
code = AD5940_SPIReadReg(ADCFILTERCON);
code = (code & (~(1 << 4))) | (!ret << 4);
AD5940_SPIWriteReg(ADCFILTERCON, code);
}
static void BpSINC3(uint8_t ret){ // 1: bypass sinc3
uint32_t code;
// select_REG_RRR(ADCFILTERCON);
code = AD5940_SPIReadReg(ADCFILTERCON);
code = (code & (~(1 << 6))) | (ret << 6);
AD5940_SPIWriteReg(ADCFILTERCON, code);
}
static void EnNotch(uint8_t ret){
uint32_t code;
// select_REG_RRR(AFECON);
code = AD5940_SPIReadReg(AFECON);
code = (code & (~(1 << 16))) | (ret << 16);
AD5940_SPIWriteReg(AFECON, code);
}
static void SetSinc3OSR(uint8_t osr){ //0, 1, 2, 3
uint32_t code;
// select_REG_RRR(ADCFILTERCON); //0x2044
code = AD5940_SPIReadReg(ADCFILTERCON);
code = (code & (~(3 << 12))) | (osr << 12);
AD5940_SPIWriteReg(ADCFILTERCON, code);
}
static void SetSinc2OSR(uint8_t osr){ //0~11 2^i
uint32_t code;
// select_REG_RRR(ADCFILTERCON); //0x2044
code = AD5940_SPIReadReg(ADCFILTERCON);
code = (code & (~(15 << 8))) | (osr << 8);
AD5940_SPIWriteReg(ADCFILTERCON, code);
}
static void SetDFTNUM(uint8_t dft_num){
uint32_t code;
// select_REG_RRR(DFTCON); //20D0
code = AD5940_SPIReadReg(DFTCON);
code = (code & (~(15 << 4))) | (dft_num << 4);
AD5940_SPIWriteReg(DFTCON, code);
}
static void SetSamplingTime(uint32_t freq){ // freq [10mHz]
// freq > 10kHz
if (freq >= 1000000 && instru.settingIndex != 1) {
SelDFTin(1);
SetADCDataRate(ADC1M6sps);
BpSINC3(1);
SetDFTNUM(DFTNUM16384);
instru.settingIndex = 1;
}
// 10kHz > freq > 1kHz
else if (freq >= 100000 && freq < 1000000 && instru.settingIndex != 2) {
SelDFTin(1);
SetADCDataRate(ADC1M6sps);
BpSINC3(0);
SetSinc3OSR(Sinc3OSR4);
SetDFTNUM(DFTNUM8192);
instru.settingIndex = 2;
}
// 1kHz > freq > 100Hz
else if (freq >= 10000 && freq < 100000 && instru.settingIndex != 3) {
SelDFTin(1);
SetADCDataRate(ADC800Ksps);
BpSINC3(0);
SetSinc3OSR(Sinc3OSR5);
SetDFTNUM(DFTNUM16384);
instru.settingIndex = 3;
}
// 100Hz > freq > 10Hz
else if (freq >= 1000 && freq < 10000 && instru.settingIndex != 4) {
SelDFTin(0);
SetADCDataRate(ADC800Ksps);
BpSINC3(0);
SetSinc3OSR(Sinc3OSR5);
SetSinc2OSR(Sinc2OSR178);
SetDFTNUM(DFTNUM1024);
instru.settingIndex = 4;
}
// 10Hz > freq > 1Hz
else if (freq >= 100 && freq < 1000 && instru.settingIndex != 5) {
SelDFTin(0);
SetADCDataRate(ADC800Ksps);
BpSINC3(0);
SetSinc3OSR(Sinc3OSR5);
SetSinc2OSR(Sinc2OSR889);
SetDFTNUM(DFTNUM1024);
instru.settingIndex = 5;
}
// 1Hz > freq > 0.1Hz
else if (freq >= 10 && freq < 100 && instru.settingIndex != 6) {
SelDFTin(0);
SetADCDataRate(ADC800Ksps);
BpSINC3(0);
SetSinc3OSR(Sinc3OSR2);
SetSinc2OSR(Sinc2OSR1333);
SetDFTNUM(DFTNUM16384);
instru.settingIndex = 6;
}
// 0.015Hz | 136s
// 0.1Hz > freq > 0.01Hz
else if (freq >= 1 && freq < 10 && instru.settingIndex != 7) {
SelDFTin(0);
SetADCDataRate(ADC800Ksps);
BpSINC3(0);
SetSinc3OSR(Sinc3OSR5);
SetSinc2OSR(Sinc2OSR1333);
SetDFTNUM(DFTNUM16384);
instru.settingIndex = 7;
}
}
//EIS function//
#endif
@@ -0,0 +1,259 @@
#ifndef EliteDAC
#define EliteDAC
static bool DACReset;
#define VBIAS_LSB 107422 // 2200/4096 [mV] = 107422 [5nV]
#define VZERO_LSB 6875008 // VBIAS_LSB * 64
#define DAC12BIT_LSB 107422
#define VOLT_MV_TO_5NV(_v) (_v * 200000)
#define V_5nV(_v) VOLT_MV_TO_5NV(_v)
/* user code: 0 ~ 35000; LPDAC bias value: -1.5V ~ +1.5V */
static int32_t DAC_outputV(int32_t voltLVraw) { // LPDAC output, voltLV = Vbias-Vzero
/* new code*/
int32_t ret;
int32_t vscan;
int64_t v_z;
int64_t v_zero;
int64_t v_bias;
uint8_t n_zero;//6btit
uint16_t n_bias;//12bit
uint32_t DACOutCode;
vscan = voltLVraw * (-1);
v_z = (V_5nV(2200) - (int64_t)vscan) * 200000 / 431579 + V_5nV(200); // v_z = (V_5nV(2200) - vscan)/2.157895 + V_5nV(200);
n_zero = v_z * 100 / V_5nV(3438); // n_zero = v_z / V_5nV(34.38);
v_zero = (int64_t)n_zero * V_5nV(3438) / 100; // v_zero = n_zero * V_5nV(34.38);
//
if (vscan < 0) { //
v_zero -= V_5nV(5372) / 10000; // v_zero -= V_5nV(0.5372);
} //
//
v_bias = vscan + v_zero; // v_bias = vscan + v_zero;
n_bias = v_bias * 10000 / V_5nV(5372); // n_bias = v_bias / V_5nV(0.5372);
while (n_bias > 4095) {
n_zero--;
v_zero = (int64_t)n_zero * V_5nV(3438) / 100;
if (vscan < 0) {
v_zero -= V_5nV(5372) / 10000;
}
v_bias = vscan + v_zero;
n_bias = v_bias * 10000 / V_5nV(5372);
if ((n_bias <= 4095) || ( n_bias > 4095 && n_zero > 63))
break;
}
if(n_bias > 4095) n_bias = 4095;
if(n_zero > 63) n_zero = 63;
DACOutCode = (0x0003FFFF & ((n_zero << 12) + n_bias));
AD5940_SPIWriteReg(LPDACDAT0, DACOutCode);
ret = (int32_t)(v_bias - v_zero); //vscan
return ret;
}
/* user code: 0 ~ 50000: -2V ~ +2V */
static void HSDAC_outputV(int32_t voltLVraw)
{
uint8_t n_zero;//6btit
uint16_t n_bias;//12bit
uint32_t DACOutCode;
int64_t value = ((int64_t)voltLVraw * voltLVraw * CaliTable.ac_dcbais.up_a + voltLVraw * CaliTable.ac_dcbais.up_b + CaliTable.ac_dcbais.up_c + 5e11) / 1e12;
if ( value < 1920)
value = ((int64_t)voltLVraw * voltLVraw * CaliTable.ac_dcbais.down_a + voltLVraw * CaliTable.ac_dcbais.down_b + CaliTable.ac_dcbais.down_c + 5e11) / 1e12;
n_zero = 30;
n_bias = (uint16_t)value;
if(n_bias > 4095) n_bias = 4095;
if(n_zero > 63) n_zero = 63;
DACOutCode = (0x0003FFFF & ((n_zero << 12) + n_bias));
AD5940_SPIWriteReg(LPDACDAT0, DACOutCode);
return;
}
/* user code: 0 ~ 50000; LPDAC bias value: -2V ~ +2V */
static void set_lpdac_ce_1100mv(uint8_t z, uint16_t b) { // LPDAC output, voltLV = Vbias-Vzero
/* new code*/
uint8_t n_zero = z;//6btit
uint16_t n_bias = b;//12bit
uint32_t DACOutCode;
DACOutCode = (0x0003FFFF & ((n_zero << 12) + n_bias));
AD5940_SPIWriteReg(LPDACDAT0, DACOutCode);
return;
}
static uint32_t DAC_outputF(uint32_t freq) {
AD5940_SPIWriteReg(WGFCW, freq);
return freq;
}
static void VoutGainControl(uint8_t VOUTLevel){
// if(VOUTLevel == 0){
// // VOUT gain level = 0, using 240K resister
// PIN_setOutputValue(pin_handle, Turon_VOUT_SMALL, 0);
// }
// else if(VOUTLevel == 1){
// // VOUT gain level = 1, using 15K resister
// PIN_setOutputValue(pin_handle, Turon_VOUT_SMALL, 1);
// }
// else if(VOUTLevel == 2){
// // VOUT gain level = 2, using 15K resister
// PIN_setOutputValue(pin_handle, Turon_VOUT_SMALL, 1);
// }
// else{
// // default using 15K resister
// PIN_setOutputValue(pin_handle, Turon_VOUT_SMALL, 1);
// }
// record_flag = false;
}
static uint32_t CalcPeriod(uint32_t freq){ //One Second = 10000
uint32_t period;
if (freq == 1) {
period = 666667;
} else {
period = (1000000 + freq / 2) / freq; // [sec]
}
if (period < 20){
period = 20;
}
return period;
}
static uint32_t CalcDelayTime(uint32_t freq){ //freq[10mHz]
uint32_t delayTime, decadeSamplingTime;
delayTime = CalcPeriod(freq) * instru.delay; //get delay time
if (delayTime < 20) {
delayTime = 20;
} else {
delayTime = (delayTime + 5) / 10;
}
// 10kHz
if (freq >= 1000000) {
decadeSamplingTime = 1025;
}
// 1kHz
else if (freq >= 100000) {
decadeSamplingTime = 1025;
}
// 100Hz
else if (freq >= 10000) {
decadeSamplingTime = 1025;
}
// 10Hz
else if (freq >= 1000) {
decadeSamplingTime = 11395;
}
// 1Hz
else if (freq >= 100) {
decadeSamplingTime = 56900;
}
//0.1Hz
else if (freq >= 10) {
decadeSamplingTime = 546000;
}
// 0.015Hz | 136s
else if (freq >= 1) {
decadeSamplingTime = 1364995;
}
delayTime += decadeSamplingTime; //delay+reading time
return delayTime;
}
static uint32_t User2Freq(uint32_t UserCode){
uint32_t freq;
freq = UserCode * 15 / 10;
return freq; //[10mHz]
}
static uint32_t Freq2DAC(uint32_t freq){
uint32_t code;
code = freq * 10 / 15;
return code; //return code
}
// DAC Vout theoretical boundary <300, 100~ (mV)
#define DAC_VOUT_GAIN_SMALL_BOUNDARY 100000 // 25500(usercode) = 100 mV
#define DAC_VOUT_GAIN_LARGE_BOUNDARY 300000 // 26500(usercode) = 300 mV
#define DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE 26500 // 26500(usercode) = 300 mV
#define DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE 23500 // 23500(usercode) = -300 mV
static void AutoGainChangeVout(int32_t userCode){
int32_t RealVolt = (userCode - 25000) * 200; // (userCode - 25000) / 5 * 1000 [1uV]
// switch to 1 level volt(small) 15K
// switch to 2 level volt(large) 240K
if(instru.VoutGainLevel == VOUT_GAIN_AUTO){
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
}
if(instru.VoutGainLevel == VOUT_GAIN_15K){
if(RealVolt > DAC_VOUT_GAIN_LARGE_BOUNDARY || RealVolt < -1 * DAC_VOUT_GAIN_LARGE_BOUNDARY){
// switch to 2 level volt(large)
instru.VoutGainLevel = VOUT_GAIN_240K;
VoutGainControl(instru.VoutGainLevel);
}
}
else if(instru.VoutGainLevel == VOUT_GAIN_240K){
if(RealVolt < DAC_VOUT_GAIN_SMALL_BOUNDARY && RealVolt > -1 * DAC_VOUT_GAIN_SMALL_BOUNDARY ){
// switch to 1 level volt(small)
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
}
}
}
static void cali_SetWGAmp(uint32_t ampcode){
AD5940_SPIWriteReg(WGCON, 0x0); // 0x0: DC disable ac first
AD5940_SPIWriteReg(WGAMPLITUDE, ampcode);
AD5940_SPIWriteReg(WGCON, 0x00000004); //0x4: Sinusoid
}
static void SetWGAmp(uint16_t ampcode, uint32_t freq){
uint32_t amplitude = 0;
amplitude = Cali_HSAMP(ampcode, freq);
cali_SetWGAmp(amplitude);
}
static void SetEISHIGHZ(uint8_t ret){
uint32_t code;
// select_REG_RRR(LPTIASW0); //LPTIASW0
code = AD5940_SPIReadReg(LPTIASW0);
code = (code & (~(1 << 2))) | (ret << 2); //ret = 0 HighZ on | ret = 1 HighZ off
AD5940_SPIWriteReg(LPTIASW0, code);
}
#endif
@@ -0,0 +1,291 @@
#ifndef __INSTR_H__
#define __INSTR_H__
#ifdef __cpulsplus
extern "C" {
#endif
/*==============================
==== headstage instruction ====
=============================*/
struct HEADSTAGE_INSTRUCTION {
uint8_t chip_id;
uint8_t eliteFxn;
/** DAC parameter **/
uint8_t VsetRateIndex;
uint32_t VsetRate;
int32_t Vset;
uint16_t VoltConstant;
uint8_t directionInit;
uint32_t step;
uint16_t Ve1;
uint16_t Ve2;
int32_t Vinit;
int32_t Vmax;
int32_t Vmin;
/** EIS **/
uint32_t f1;
uint32_t f2;
uint32_t fmax;
uint32_t fmin;
uint32_t fset;
uint16_t dcbias;
uint16_t delay;
uint16_t acamp;
uint8_t avgnum;
uint8_t rtia;
uint16_t ppd;
uint8_t scale;
int32_t real;
int32_t imag;
uint8_t periodIndex;
uint32_t delayTime;
uint8_t settingIndex;
/** ADC parameter **/
uint8_t notifyRateIndex;
uint32_t sampleRate;
uint8_t VoViSwitch;
uint8_t VinAutoGainEnable;
uint8_t VoutAutoGainEnable;
uint8_t ADCGainLv;
// voltage output gain
uint16_t VoutGainLevel;
uint8_t VinADCGainLv;
/** Notify parameter **/
uint32_t notifyRate;
/** mode parameter **/
uint16_t cycleNumber;
uint8_t charge;
int32_t constantCurrent;
int32_t Currentmax;
int32_t sti_v1;
int32_t sti_v2;
int32_t sti_v3;
int32_t sti_v4;
int32_t sti_v5;
int32_t sti_v6;
int32_t sti_v7;
int32_t sti_t1;
int32_t sti_t2;
int32_t sti_t3;
int32_t sti_t4;
int32_t sti_t5;
int32_t sti_t6;
int32_t sti_t7;
uint16_t sti_cy;
uint16_t sti_loop;
uint16_t StepTime;
uint8_t AdcChannel;
/* EIS DAC parameter */
uint8_t DAC_type;
uint16_t VAmpSet; // DAC Voltage Amplitude
/* EIS ADC parameter */
uint8_t gain_lv_hstia;
uint8_t HSTIAAutoGainEnable;
uint8_t gain_lv_lptia;
uint8_t LPTIAAutoGainEnable;
//VT mode
uint8_t measure_vin_range;
} instru = {0};
/** ADC Iin gain level **/
#define I_GAIN_3M 0x07 // largest gain
#define I_GAIN_100K 0x08
#define I_GAIN_3K 0x09
#define I_GAIN_100R 0x0A // the least gain
#define I_GAIN_AUTO 0x04
// EIS LPTIA Iin Gain Level //
//#define LPRTIA_512K 0x00
#define LPRTIA_64K 0x00
#define LPRTIA_8K 0x01
#define LPRTIA_1K 0x02
#define LPRTIA_200R 0x03
#define LPRTIA_GAIN_AUTO 0x04
#define DISCONNECT_RTIA 0x05
// EIS HSTIA Iin Gain Level
enum hsrtia_gain_e {
HSRTIA_160K = 0,
HSRTIA_80K,
HSRTIA_40K,
HSRTIA_20K,
HSRTIA_10K,
HSRTIA_5K,
HSRTIA_1K,
HSRTIA_200R,
HSRTIA_MAX,
};
/** ADC Vin gain level **/
#define VIN_GAIN_1M 0x00
#define VIN_GAIN_30K 0x01
#define VIN_GAIN_1K 0x02
#define VIN_GAIN_AUTO 0x03
/** Vout gain level **/
#define VOUT_GAIN_240K 0x00
#define VOUT_GAIN_15K 0x01
#define VOUT_GAIN_AUTO 0x02
/* DAC reset parameter */
#define DAC_ZERO 25000
#define EIS_HSDAC_ZERO 0x0800
// Step time macro
#define STEPTIME_HALF_SEC 5000
#define STEPTIME_ONE_SEC 10000
#define STEPTIME_TWO_SEC 20000
/* AVG Number */
#define AVG2 0
#define AVG4 1
#define AVG8 2
#define AVG16 3
#define ADC1M6sps 0
#define ADC800Ksps 1
#define Sinc3OSR5 0
#define Sinc3OSR4 1
#define Sinc3OSR2 2
#define Sinc2OSR22 0
#define Sinc2OSR44 1
#define Sinc2OSR89 2
#define Sinc2OSR178 3
#define Sinc2OSR267 4
#define Sinc2OSR533 5
#define Sinc2OSR640 6
#define Sinc2OSR667 7
#define Sinc2OSR800 8
#define Sinc2OSR889 9
#define Sinc2OSR1067 10
#define Sinc2OSR1333 11
#define DFTNUM4 0
#define DFTNUM8 1
#define DFTNUM16 2
#define DFTNUM32 3
#define DFTNUM64 4
#define DFTNUM128 5
#define DFTNUM256 6
#define DFTNUM512 7
#define DFTNUM1024 8
#define DFTNUM2048 9
#define DFTNUM4096 10
#define DFTNUM8192 11
#define DFTNUM16384 12
#define AD5940_SYS_CLOCK 16000000
#define Cutoff_Freq 37000000 // 210kHz
static uint32_t HSRTIATable[4] = {160000, 20000, 5000, 200};
/*********************************************************************
* @fn InitEliteInstruction
*
* @brief Init all INSTRUCTION variable.
*
* @param None.
*
* @return None.
*/
static void InitEliteInstruction(){
instru.chip_id = 0;
instru.eliteFxn = 0; //default is a null event
instru.VsetRateIndex = 0;
instru.VsetRate = 2;
instru.Vset = 0;
instru.VoltConstant = DAC_ZERO; //DAC_ZERO is about 0V
instru.directionInit = 1; //0:reverse 1:forward
instru.step = 0;
instru.Ve1 = DAC_ZERO;
instru.Ve2 = DAC_ZERO;
instru.Vinit = 0;
instru.Vmax = 0;
instru.Vmin = 0;
instru.notifyRateIndex = 100;
instru.sampleRate = 15;
instru.VoViSwitch = 0x01; //0:user see Vo 1: user see Vi
instru.VinAutoGainEnable = 1;
instru.VoutAutoGainEnable = 1;
instru.VoutGainLevel = VOUT_GAIN_AUTO;
instru.VinADCGainLv = VIN_GAIN_AUTO;
instru.notifyRate = STEPTIME_ONE_SEC;
instru.cycleNumber = 1;
instru.charge = 1; //0:discharge 1:charge
instru.constantCurrent = 0;
instru.Currentmax = 0;
instru.StepTime = STEPTIME_ONE_SEC;
instru.AdcChannel = 0;
//EIS
instru.f1 = 0;
instru.f2 = 0;
instru.fset = 0;
instru.fmax = 0;
instru.fmin = 0;
instru.delay = 0;
instru.scale = 0;
instru.avgnum = 0;
instru.dcbias = 0;
instru.acamp = 0;
instru.ppd = 1;
instru.periodIndex = 0;
instru.delayTime = 0;
instru.settingIndex = 0;
//pulse mode
instru.sti_t1 = 0;
instru.sti_t2 = 0;
instru.sti_t3 = 0;
instru.sti_t4 = 0;
instru.sti_t5 = 0;
instru.sti_t6 = 0;
instru.sti_t7 = 0;
instru.sti_v1 = DAC_ZERO;
instru.sti_v2 = DAC_ZERO;
instru.sti_v3 = DAC_ZERO;
instru.sti_v4 = DAC_ZERO;
instru.sti_v5 = DAC_ZERO;
instru.sti_v6 = DAC_ZERO;
instru.sti_v7 = DAC_ZERO;
instru.sti_loop = 1;
instru.sti_cy = 0;
//General
// EIS DAC
instru.VAmpSet = EIS_HSDAC_ZERO;
instru.DAC_type = 0;
// EIS ADC
instru.gain_lv_hstia = HSRTIA_200R;
instru.HSTIAAutoGainEnable = 1;
instru.gain_lv_lptia = LPRTIA_200R;
instru.LPTIAAutoGainEnable = 1;
// VT mode
instru.measure_vin_range = 0;
}
#ifdef __cpulsplus
}
#endif
#endif
@@ -0,0 +1,84 @@
#ifndef ELITELED
#define ELITELED
static bool btWaitLedFlag = 0;
static bool noEventLedFlag = 0;
static bool preWorkLedFlag = 0;
static bool workingLedFlag = 0;
static bool postWorkLedFlag = 0;
static void WorkModeLED();
static void ModeLED(uint16_t modeStatus) {
btWaitLedFlag = 0;
noEventLedFlag = 0;
preWorkLedFlag = 0;
workingLedFlag = 0;
postWorkLedFlag = 0;
switch (modeStatus) {
case BT_WAIT:
btWaitLedFlag = 1;
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_YELLOWGREEN);
break;
case NO_EVENT:
noEventLedFlag = 1;
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_GREEN);
break;
case PRE_WORK:
preWorkLedFlag = 1;
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
break;
case WORKING:
workingLedFlag = 1;
WorkModeLED();
break;
case POST_WORK:
postWorkLedFlag = 1;
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
break;
default:
break;
}
}
static void checkFlafLED()
{
if(btWaitLedFlag == 1) {
ModeLED(BT_WAIT);
} else if(noEventLedFlag == 1) {
ModeLED(NO_EVENT);
} else if(preWorkLedFlag == 1) {
ModeLED(PRE_WORK);
} else if(workingLedFlag == 1) {
ModeLED(WORKING);
} else if(postWorkLedFlag == 1) {
ModeLED(POST_WORK);
}
}
static void WorkModeLED()
{
switch (instru.eliteFxn) {
case CURVE_EIS:
case CURVE_CV:
case CURVE_CA:
case CURVE_VT:
case CURVE_RT:
case CURVE_CF:
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_CYAN);
break;
default:
break;
}
}
#endif
@@ -0,0 +1,202 @@
/**
* notify data buffer.
* the length equals to the characteristic 4 which value is 20 bytes.
*
*/
#ifndef ELITENOTIFY
#define ELITENOTIFY
#include "headstage.h"
/*notify's input type*/
#define NOTIFY_CURRENT 0
#define NOTIFY_VOLT 1
#define NOTIFY_IMPEDANCE 2
#define NOTIFY_VOLT_BAT 3
static uint32_t not_time_stamp;
static uint8_t NotifyCh1[4] = {0};
static uint8_t NotifyCh2[4] = {0};
static uint8_t NotifyCh3[4] = {0};
static uint8_t NotifyVoltBat[4] = {0};
static uint16_t NotifyCycleNumber = 0;
static uint8_t finishMode = 0;
static uint8_t gain = 0;
static int32_t notify_one = 0;
static int32_t notify_two = 0;
static int32_t notify_three = 0;
static uint32_t NotifyCh4 = 0;
// ****************** New Notify Format ******************************** //
/*
* Notify format
*
*
| | 1 | 2 | 3 |
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
-----------------------------------------------------------------
| header |
| current |
| voltage or impedance |
| mode & gain |
| time stamp |
| cycle number |
mode & gain
this byte include Elite working mode and ADC gain level
we use "(mode & 0xF0) | (gain & 0x0F)" to encode these two information
cycle number
for cyclic voltammetry use, we save it as channel number.
0xFF
* header = device ID
* I = current (0.001nA), V = voltage (mV),
* Z = impedance (k ohm), T = time (ms)
*
*
*/
// ********* End New Format Notify ***************************************** //
/*
* Notify format
*
*
| | 1 | 2 | 3 |
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
-----------------------------------------------------------------
| header |
| current |
| voltage |
| impedance |
| time stamp |
| cycle number |
cycle number
for cyclic voltammetry use, we save it as channel number.
0xFF
* header = device ID
* I = current (nA), V = voltage (uV),
* Z = impedance (ohm), T = time (ms)
*
*
*/
static void initDATBuf(void)
{
memset(not_buf, 0, BLE_DAT_BUFF_SIZE);
return;
}
static void initINSBuf(void)
{
memset(ins_buf, 0, BLE_INS_BUFF_SIZE);
return;
}
static void initCISBuf(void)
{
memset(cis_buf, 0, BLE_CIS_BUFF_SIZE);
return;
}
static void SendNotify() {
initDATBuf();
not_buf[0] = instru.chip_id;
for (int i = 0; i < 4; i++) {
not_buf[i + 1] = NotifyCh1[i]; // 1 2 3 4
not_buf[i + 5] = NotifyCh2[i]; // 5 6 7 8
not_buf[i + 9] = NotifyCh3[i]; //9 10 11 12
}
// 1 Timestamp = 32 usec; 31 Timestamp ~= 1 msec
not_time_stamp = (Timestamp_get32()) / 31; // msec
not_buf[13] = not_time_stamp & 0xff;
not_buf[14] = (not_time_stamp >> 8) & 0xff;
not_buf[15] = (not_time_stamp >> 16) & 0xff;
not_buf[16] = (not_time_stamp >> 24) & 0xff;
not_buf[17] = (NotifyCycleNumber >> 8) & 0xff;
not_buf[18] = NotifyCycleNumber & 0xff;
not_buf[19] = (finishMode << 7) & 0x80;
not_buf[20] = gain;
memcpy(not_buf+21, (uint8_t *)&NotifyCh4, sizeof(NotifyCh4));
memcpy(not_buf+25, (uint8_t *)&notify_one, sizeof(notify_one));
memcpy(not_buf+29, (uint8_t *)&notify_two, sizeof(notify_two));
memcpy(not_buf+33, (uint8_t *)&notify_three, sizeof(notify_three));
for (int i = 37; i < BLE_DAT_BUFF_SIZE; i++){
not_buf[i] = 0;
}
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
}
static void initRawDataBuf(){
not_time_stamp = 0;
NotifyCycleNumber = 0;
finishMode = 0;
for (int i = 0; i < 4; i++){
NotifyCh1[i] = 0;
NotifyCh2[i] = 0;
NotifyCh3[i] = 0;
}
}
static void FlushNotify(){
initRawDataBuf();
initDATBuf();
not_buf[0] = instru.chip_id;
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
}
static void InputNotify(int NotifyType, int32_t Data){
switch (NotifyType) {
case NOTIFY_CURRENT:
NotifyCh1[0] = (uint8_t)((Data & 0xFF000000) >> 24);
NotifyCh1[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
NotifyCh1[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
NotifyCh1[3] = (uint8_t)(Data & 0x000000FF);
break;
case NOTIFY_IMPEDANCE:
NotifyCh3[0] = (uint8_t)((Data & 0xFF000000) >> 24);
NotifyCh3[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
NotifyCh3[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
NotifyCh3[3] = (uint8_t)(Data & 0x000000FF);
break;
case NOTIFY_VOLT :
NotifyCh2[0] = (uint8_t)((Data & 0xFF000000) >> 24);
NotifyCh2[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
NotifyCh2[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
NotifyCh2[3] = (uint8_t)(Data & 0x000000FF);
break;
case NOTIFY_VOLT_BAT :
NotifyVoltBat[0] = (uint8_t)((Data & 0xFF000000) >> 24);
NotifyVoltBat[1] = (uint8_t)((Data & 0x00FF0000) >> 16);
NotifyVoltBat[2] = (uint8_t)((Data & 0x0000FF00) >> 8);
NotifyVoltBat[3] = (uint8_t)(Data & 0x000000FF);
break;
}
}
#endif
@@ -0,0 +1,22 @@
#ifndef ELITERESET
#define ELITERESET
static void reset() {
mode_init = true;
megaStiEnable = false;
PeriodicEvent = false; // is there an PeriodicEvent?
Free_Work_Mode = true; // Free(WorkModeData)
InitPeriodicEvent = true; // need to create a WorkModeData?
initINSBuf();
initDATBuf();
AD5940_HWReset();
AD5940_Initialize();
ModeLED(NO_EVENT);
CPUdelay_us(500);
}
#endif
@@ -0,0 +1,66 @@
#ifndef ELITE_SPI
#define ELITE_SPI
/*
* Read SPI example in
* http://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/tirtos/2_14_02_22/
* exports/tirtos_full_2_14_02_22/docs/doxygen/html/_s_p_i_c_c26_x_x_d_m_a_8h.html
*/
#include "board.h"
#include <ti/drivers/SPI.h>
#include <ti/drivers/dma/UDMACC26XX.h>
#include <ti/drivers/spi/SPICC26XXDMA.h>
#define ELITE_VERSION_EIS
#ifdef ELITE_VERSION_EIS
/* define SPI command */
// datasheet page 98
//#define SPICMD_SETADDR 0x20
//#define SPICMD_WRITEREG 0x2D
//#define SPICMD_READREG 0x6D
//define REG
#define LPDACCON0 0x2128
#define LPDACSW0 0x2124
#define LPDACDAT0 0x2120
#define LPREFBUFCON 0x2050
#define SWMUX 0x235C
#define LPTIASW0 0x20E4
#define SWCON 0x200C
#define HSDACCON 0x2010
#define HSDACDAT 0x2048
#define LPTIACON0 0x20EC
#define HSTIACON 0x20FC
#define AFECON 0x2000
#define DSWFULLCON 0x2150
#define NSWFULLCON 0x2154
#define PSWFULLCON 0x2158
#define TSWFULLCON 0x215C
#define WGFCW 0x2030
#define WGPHASE 0x2034
#define WGOFFSET 0x2038
#define WGAMPLITUDE 0x203C
#define WGCON 0x2014
#define DE0RESCON 0x20F8
#define ADCCON 0x21A8
#define DFTCON 0x20D0
#define ADCFILTERCON 0x2044
#define PMBW 0x22F0
#define CLKSEL 0x0414
#define CLKCON0 0x0408
#define CLKCON0KEY 0x0420
#define HSOSCCON 0x20BC
#define ADCBUFCON 0x238C
#define HSRTIACON 0x20F0
#define DFTREAL 0x2078
#define DFTIMAG 0x207C
#define ADCDAT 0x2074
#define RRR_AFE_STATSCON 0x21C4 /* AFE Statistics Control */
#endif // ELITE_EIS
#endif // ELITE_SPI
@@ -0,0 +1,478 @@
/*=============================================================================
= wm.h =
=============================================================================*/
#ifndef ELITE_WORK_DATA
#define ELITE_WORK_DATA
#define CLOCK_ONE_SECOND 10000 // 1s
#include "EliteInstruction.h"
/***** Template of Measure and VoltOut parameter *****/
#define VOUT_PARA \
int32_t _Vinit; \
int32_t _Vmax; \
int32_t _Vmin; \
int32_t _Vset; \
uint32_t _Vstep; \
bool _direction_up; \
bool _current_direction_up; \
uint16_t _cycleNumber
/* member of mode */
struct wm_eis_ctx_t {
uint32_t _f1;
uint32_t _f2;
uint32_t _fd1;
uint32_t _fd2;
uint32_t _fmax;
uint32_t _fmin;
uint8_t _decades; //num of decades in whole
uint16_t _ppd;
int8_t _decadeIndex; //index of decade max is 8
int16_t _sweepIndex; //index of smaller decade max is 10
bool _direction_up;
bool _in_reset_flag;
uint16_t _amp;
};
struct wm_cf_ctx_t {
uint32_t _f1;
bool _in_reset_flag;
uint16_t _amp;
};
struct wm_vo_ctx_t {
/* WARNING: please keep MEASURE at first!! */
int32_t _Vset;
int32_t _Vinit;
};
struct wm_it_ctx_t {
/* WARNING: please keep MEASURE at first!! */
};
struct wm_vt_ctx_t {
/* WARNING: please keep MEASURE at first!! */
};
struct wm_rt_ctx_t {
/* WARNING: please keep MEASURE at first!! */
int32_t _Vset;
int32_t _Vinit;
};
struct wm_iv_ctx_t {
/* WARNING: please keep MEASURE at first!! */
VOUT_PARA;
};
struct wm_iv_cy_ctx_t {
/* WARNING: please keep MEASURE at first!! */
VOUT_PARA;
};
struct wm_cc_ctx_t {
/* WARNING: please keep MEASURE at first!! */
int32_t _Vmax;
int32_t _Vmin;
int32_t _Vset;
int32_t _Iset;
uint8_t _charge;
};
struct wm_cv_ctx_t {
/* WARNING: please keep MEASURE at first!! */
VOUT_PARA;
int32_t _LPRtia;
};
struct wm_lsv_ctx_t {
/* WARNING: please keep MEASURE at first!! */
VOUT_PARA;
};
struct wm_ca_ctx_t {
/* WARNING: please keep MEASURE at first!! */
int32_t _Vinit;
int32_t _Vset;
};
struct wm_pulse_ctx_t {
/* WARNING: please keep MEASURE at first!! */
int32_t _Vset;
int32_t _sti_v1;
int32_t _sti_v2;
int32_t _sti_v3;
int32_t _sti_v4;
int32_t _sti_v5;
int32_t _sti_v6;
int32_t _sti_v7;
int32_t _sti_t1;
int32_t _sti_t2;
int32_t _sti_t3;
int32_t _sti_t4;
int32_t _sti_t5;
int32_t _sti_t6;
int32_t _sti_t7;
int32_t _sti_t;
int32_t _sti_v; //output voltage now
int32_t _sti_t_flag; //Where's the time stage turn
uint16_t _sti_cy;
uint16_t _sti_lp;
};
struct wm_ocp_ctx_t {
/* WARNING: please keep MEASURE at first!! */
};
int wm_init(void); //(void *instr_ctx);
int wm_deinit(void);
void *wm_get(void);
/*=============================================================================
= wm.c =
=============================================================================*/
static void *workMode_p = NULL;
static bool Free_Work_Mode = false;
/* init mode func */
static int __eis_create(void)
{
struct wm_eis_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_eis_ctx_t));
if (!p) return -1;
p->_f1 = instru.f1;
p->_f2 = instru.f2;
p->_fmax = instru.fmax;
p->_fmin = instru.fmin;
p->_fd1 = 0; //decade freq 1
p->_fd2 = 0; //decade freq 2
p->_ppd = instru.ppd; //points per decade
p->_decades = 0;
p->_sweepIndex = 0;
p->_decadeIndex = 0;
p->_direction_up = true;
p->_in_reset_flag = false;
p->_amp = instru.acamp;
*wm = p;
return 0;
}
static int __cf_create(void)
{
struct wm_cf_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_cf_ctx_t));
if (!p) return -1;
p->_f1 = instru.f1; //[reg's value]
p->_in_reset_flag = false;
p->_amp = instru.acamp;
*wm = p;
return 0;
}
static int __ca_create(void)
{
struct wm_ca_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_ca_ctx_t));
if (!p) return -1;
p->_Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
p->_Vset = 0;
*wm = p;
return 0;
}
static int __vo_create(void)
{
struct wm_vo_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_vo_ctx_t));
if (!p) return -1;
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
p->_Vset = 0;
*wm = p;
return 0;
}
static int __it_create(void)
{
struct wm_it_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_it_ctx_t));
if (!p) return -1;
*wm = p;
return 0;
}
static int __vt_create(void)
{
struct wm_vt_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_vt_ctx_t));
if (!p) return -1;
*wm = p;
return 0;
}
static int __rt_create(void)
{
struct wm_rt_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_rt_ctx_t));
if (!p) return -1;
p->_Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
p->_Vset = 0;
*wm = p;
return 0;
}
static int __iv_create(void)
{
struct wm_iv_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_iv_ctx_t));
if (!p) return -1;
p->_Vinit = instru.Vinit; //(instru.Vinit - 25000) * 4 * 10000; //[5nV]
p->_Vmax = instru.Vmax; //(instru.Vmax - 25000) * 4 * 10000; //[5nV]
p->_Vmin = instru.Vmin; //(instru.Vmin - 25000) * 4 * 10000; //[5nV]
p->_Vset = 0;
p->_Vstep = 0;
p->_direction_up = true;
p->_current_direction_up = true;
p->_cycleNumber = instru.cycleNumber;
*wm = p;
return 0;
}
static int __iv_cy_create(void)
{
struct wm_iv_cy_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_iv_cy_ctx_t));
if (!p) return -1;
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
p->_Vset = 0;
p->_Vstep = 0;
p->_direction_up = true;
p->_current_direction_up = true;
p->_cycleNumber = instru.cycleNumber;
*wm = p;
return 0;
}
static int __cc_create(void)
{
struct wm_cc_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_cc_ctx_t));
if (!p) return -1;
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
p->_Vset = 0;
p->_charge = instru.charge;
p->_Iset = instru.constantCurrent * 200 ;
//[50pA] //controller UI 15000uA => Elite 1500000 => 1500000 * 10 * 1000 / 50 [50pA]
*wm = p;
return 0;
}
static int __cv_create(void)
{
struct wm_cv_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_cv_ctx_t));
if (!p) return -1;
p->_Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
p->_Vmax = (instru.Vmax - 25000) * 4 * 4000; //[5nV]
p->_Vmin = (instru.Vmin - 25000) * 4 * 4000; //[5nV]
// p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
// p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
// p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
p->_Vset = 0;
p->_Vstep = 0;
p->_direction_up = true;
p->_current_direction_up = true;
p->_cycleNumber = instru.cycleNumber;
*wm = p;
return 0;
}
static int __lsv_create(void)
{
struct wm_lsv_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_lsv_ctx_t));
if (!p) return -1;
p->_Vinit = (instru.Vinit - 25000) * 4 * 10000; //[5nV]
p->_Vmax = (instru.Vmax - 25000) * 4 * 10000; //[5nV]
p->_Vmin = (instru.Vmin - 25000) * 4 * 10000; //[5nV]
p->_Vset = 0;
p->_Vstep = 0;
p->_direction_up = true;
p->_current_direction_up = true;
p->_cycleNumber = instru.cycleNumber;
*wm = p;
return 0;
}
static int __pulse_create(void)
{
struct wm_pulse_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_pulse_ctx_t));
if (!p) return -1;
p->_Vset = 0;
p->_sti_v1 = instru.sti_v1;
p->_sti_v2 = instru.sti_v2;
p->_sti_v3 = instru.sti_v3;
p->_sti_v4 = instru.sti_v4;
p->_sti_v5 = instru.sti_v5;
p->_sti_v6 = instru.sti_v6;
p->_sti_v7 = instru.sti_v7;
p->_sti_t1 = instru.sti_t1;
p->_sti_t2 = instru.sti_t2;
p->_sti_t3 = instru.sti_t3;
p->_sti_t4 = instru.sti_t4;
p->_sti_t5 = instru.sti_t5;
p->_sti_t6 = instru.sti_t6;
p->_sti_t7 = instru.sti_t7;
p->_sti_t = instru.sti_t1;
p->_sti_v = instru.sti_v1;
p->_sti_t_flag = 1;
p->_sti_cy = instru.sti_cy;
p->_sti_lp = instru.sti_loop;
*wm = p;
return 0;
}
static int __ocp_create(void)
{
struct wm_ocp_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_ocp_ctx_t));
if (!p) return -1;
*wm = p;
return 0;
}
int wm_init(void)
{
int mode = instru.eliteFxn;
void **wm = &workMode_p;
if (*wm) return -1;
switch (mode) {
case CURVE_EIS:
if (__eis_create()) return -2;
break;
case CURVE_CF:
if (__cf_create()) return -2;
break;
case CURVE_CV:
if (__cv_create()) return -2;
break;
case CURVE_CA:
if (__ca_create()) return -2;
break;
case CURVE_VT:
if (__vt_create()) return -2;
break;
case CURVE_RT:
if (__rt_create()) return -2;
break;
default:
// printf("DO NOT support!!");
return -3;
};
return 0;
}
int wm_deinit(void)
{
void **wm = &workMode_p;
if (*wm) {
free(*wm);
*wm = NULL;
} else {
return -1;
}
return 0;
}
void *wm_get(void)
{
void *wm = workMode_p;
return wm;
}
#endif
@@ -0,0 +1,103 @@
#ifndef ELITE_DEF
#define ELITE_DEF
// define BT instruction
#define INS_TYPE_RIS 0x30
#define INS_TYPE_VIS 0xC0
#define INS_TYPE_CIS 0x70
// VIS (virtual instruction)
#define VIS_RST 0xF0
#define VIS_ASK 0x30
#define VIS_STI 0xC0
#define VIS_INT 0x60
#define VIS_DEVICE_SHINY 0x10
#define VIS_SHINY_DIS 0x20
// RIS (real instruction)
enum all_mode_e {
CURVE_IV = 0x01, // I-V Curve
CURVE_IV_CY = 0x02, // Cycle I-V
CURVE_VO = 0x03, // Function Generator
CURVE_RT = 0x04, // R-T Graph
CURVE_VT = 0x05, // V-T Graph
CURVE_IT = 0x06, // I-T Graph
CURVE_CC = 0x07, // Constant Current (CC)
CURVE_OCP = 0x08, // Open Circuit Potential (OCP)
CURVE_CV = 0x09, // Cyclic Voltammetry (CV)
CURVE_LSV = 0x0A, // Linear Sweep Voltammetry (LSV)
CURVE_CA = 0x0B, // Chronoamperometric Graph (CA)
CURVE_CP = 0x0C, // Chronopotentiometry (CP)
CURVE_UNI_PULSE = 0x0D, // Pulse Sensing (universal pulse)
CURVE_DPV = 0x0E, // Differential Pulse Voltammetry (DPV)
CURVE_DPV_ADVANCE = 0x0F,
CURVE_DPV_SMPRATE = 0x10,
CURVE_DPV_ADVANCE_SMPRATE = 0x11,
CURVE_EIS = 0x12,
CURVE_CF = 0x13, // Constant Frequency(CF)
CURVE_CALI = 0xF1,
////
SET_SAMPLE_RATE = 0xE0,
};
// CIS (control instruction)
#define CIS_VERSION 0x40
#define CIS_VOLT 0x10
#define CIS_LED_TEST 0x70
#define CIS_CALI 0x30
#define CIS_CALI2 0x90
#define CTL_WRT 0x20
#define CTL_RD 0x21
#define CTL_RD_DFTR 0x78
#define CTL_RD_DFTI 0x7C
#define CTL_RD_ADC 0x7A
#define CTL_RESET 0x11
// mode parameter
#define VMAX(v1,v2) ((v1 >= v2) ? v1 : v2)
#define VMIN(v1,v2) ((v1 < v2) ? v1 : v2)
#define VDIRECTION(v1,v2) ((v1 > v2) ? 0 : 1)
#define AFTER_READ_I 0
#define AFTER_READ_V 1
#define PARA_1 0x01
#define PARA_2 0x02
#define PARA_3 0x03
#define PARA_4 0x04
#define PARA_5 0x05
#define PARA_6 0x06
#define PARA_7 0x07
#define PARA_8 0x08
#define PARA_9 0x09
#define PARA_10 0x0A
#define PARA_11 0x0B
#define PARA_12 0x0C
#define PARA_13 0x0D
#define PARA_14 0x0E
#define PARA_15 0x0F
#define PARA_16 0x10
#define PARA_17 0x11
//Elite LED
#define COLOR_BLACK 0x00
#define COLOR_RED 0x01
#define COLOR_ORANGE 0x02
#define COLOR_YELLOW 0x03
#define COLOR_GREEN 0x04
#define COLOR_BLUE 0x05
#define COLOR_CYAN 0x06
#define COLOR_MAGENTA 0x07
#define COLOR_PURPLE 0x08
#define COLOR_WHITE 0x09
#define COLOR_YELLOWGREEN 0x0A
#define BT_WAIT 0x01
#define NO_EVENT 0x02
#define PRE_WORK 0x03
#define WORKING 0x04
#define POST_WORK 0x05
#endif
@@ -0,0 +1,151 @@
#include <math.h>
#ifndef ELITE_MODE_ADC_DAC
#define ELITE_MODE_ADC_DAC
static void freq_out()
{
DAC_outputF(instru.fset);
return;
}
static void vscan_volt_out(void)
{
if (instru.eliteFxn == CURVE_CV) {
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
void *wm = wm_get();
/* in [5nV] ver */
DAC_outputV(instru.Vset);
InputNotify(NOTIFY_VOLT, instru.Vset/200);
} else if (instru.eliteFxn == CURVE_CA) {
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
void *wm = wm_get();
/* in [5nV] ver */
DAC_outputV(instru.Vset);
InputNotify(NOTIFY_VOLT, instru.Vset/200);
} else if (instru.eliteFxn == CURVE_RT) {
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
void *wm = wm_get();
/* in [5nV] ver */
DAC_outputV(instru.Vset);
InputNotify(NOTIFY_VOLT, instru.Vset/200);
}
return;
}
static int32_t neg_18bit(int32_t ret)
{
// if (ret > 131072) {
// ret = ret - 262144;
// }
ret &= 0x3FFFF;
if (ret & (1 << 17)) {
ret |= 0xFFFC0000;
}
return ret;
}
//////EIS PLOT RELATED FUNCTION END//////
static void DACenable(uint8_t afterRead)
{
void *wm = wm_get();
if (afterRead == AFTER_READ_I) {
switch (instru.eliteFxn) {
default:
break;
}
} else if (afterRead == AFTER_READ_V) {
switch (instru.eliteFxn) {
case CURVE_EIS:
case CURVE_CF:
freq_out();
break;
case CURVE_CV:
case CURVE_CA:
break;
default:{
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_MAGENTA);
break;
}
}
}
}
static void LPTIA_change_gain(void)
{
static uint8_t rec_cnt = 0;
void *wm = wm_get();
if (instru.LPTIAAutoGainEnable > 1)
return;
/* read Iin and do NOT record the Iin after changing gain twice */
int32_t i;
i = read_LPTIA_Iin();
if (instru.LPTIAAutoGainEnable) {
AutoChangeLPTIAGain(i);
} else {
if (last_gain_lptia != instru.gain_lv_lptia) {
LPTIAGainCtrl(instru.gain_lv_lptia);
}
}
if (record_flag == false) {
rec_cnt++;
}
if (rec_cnt == 2) {
record_flag = true;
rec_cnt = 0;
}
return;
}
static void HSTIA_change_gain(void)
{
// static uint8_t rec_cnt = 0;
void *wm = wm_get();
if (instru.HSTIAAutoGainEnable > 1)
return;
/* read Iin and do NOT record the Iin after changing gain twice */
int32_t i;
i = read_HSTIA_Iin();
if (instru.HSTIAAutoGainEnable) {
AutoChangeHSTIAGain(i);
} else {
if (last_gain_hstia != instru.gain_lv_hstia) {
HSTIAGainCtrl(instru.gain_lv_hstia);
}
}
return;
}
#endif
@@ -1,15 +1,10 @@
#ifndef VERSION_DATE
#define VERSION_DATE
#ifndef VERSION_DATE
#define VERSION_DATE
#define VERSION_DATE_YEAR 23
#define VERSION_DATE_MONTH 3
#define VERSION_DATE_DAY 16
#define VERSION_DATE_HOUR 13
#define VERSION_DATE_MINUTE 40
// this is NOT the version hash !!
// it's the last version hash
#define VERSION_HASH 8808490caa465cc94d14896de28763a5e5c4672b
#define VERSION_GIT_BRANCH Elite_OBJ_0.2mv
#define VERSION_DATE_YEAR 23
#define VERSION_DATE_MONTH 4
#define VERSION_DATE_DAY 21
#define VERSION_DATE_HOUR 14
#define VERSION_DATE_MINUTE 33
#endif
@@ -0,0 +1,712 @@
#include "eis_cali_table.h"
#define CALI_SIZE BLE_CIS_BUFF_SIZE
uint8_t check_sum(uint8_t message[], int nBytes)
{
uint8_t sum = 0;
while (nBytes-- > 0) {
sum += *(message++);
}
return sum;
}
static void send_cali_version(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
ctx[index++] = len-1;
ctx[index++] = instru.chip_id;
ctx[index++] = (uint8_t)(CALI_VERSION >> 8);
ctx[index++] = (uint8_t)(CALI_VERSION);
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain0_hstia(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_a >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_a >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_a >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_a);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 56);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 48);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 40);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 32);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].hstia_b);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].rolloff >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].rolloff >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].rolloff >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[0][0].rolloff);
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain0_phase_freq0_freq1(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 0;
uint8_t freq_lv_to = 1;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain0_phase_freq2_freq3(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 2;
uint8_t freq_lv_to = 3;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[0][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain1_hstia(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_a >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_a >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_a >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_a);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 56);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 48);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 40);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 32);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].hstia_b);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].rolloff >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].rolloff >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].rolloff >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[1][0].rolloff);
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain1_phase_freq0_freq1(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 0;
uint8_t freq_lv_to = 1;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain1_phase_freq2_freq3(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 2;
uint8_t freq_lv_to = 3;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[1][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain2_hstia(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_a >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_a >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_a >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_a);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 56);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 48);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 40);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 32);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].hstia_b);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].rolloff >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].rolloff >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].rolloff >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[2][0].rolloff);
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain2_phase_freq0_freq1(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 0;
uint8_t freq_lv_to = 1;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[2][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain2_phase_freq2_freq3(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 2;
uint8_t freq_lv_to = 3;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].coeff >> 24);
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].coeff >> 16);
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].coeff >> 8);
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].coeff);
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].offset >> 24);
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].offset >> 16);
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].offset >> 8);
ctx[index++] = (uint8_t) (CaliTable.phase[2][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain3_hstia(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_a >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_a >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_a >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_a);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 56);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 48);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 40);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 32);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].hstia_b);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].rolloff >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].rolloff >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].rolloff >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[3][0].rolloff);
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain3_phase_freq0_freq1(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 0;
uint8_t freq_lv_to = 1;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain3_phase_freq2_freq3(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 2;
uint8_t freq_lv_to = 3;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[3][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain4_hstia(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_a >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_a >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_a >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_a);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 56);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 48);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 40);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 32);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].hstia_b);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].rolloff >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].rolloff >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].rolloff >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[4][0].rolloff);
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain4_phase_freq0_freq1(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 0;
uint8_t freq_lv_to = 1;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain4_phase_freq2_freq3(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 2;
uint8_t freq_lv_to = 3;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[4][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain5_hstia(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_a >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_a >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_a >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_a);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 56);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 48);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 40);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 32);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].hstia_b);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].rolloff >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].rolloff >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].rolloff >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[5][0].rolloff);
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain5_phase_freq0_freq1(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 0;
uint8_t freq_lv_to = 1;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain5_phase_freq2_freq3(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 2;
uint8_t freq_lv_to = 3;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[5][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain6_hstia(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_a >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_a >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_a >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_a);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 56);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 48);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 40);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 32);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].hstia_b);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].rolloff >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].rolloff >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].rolloff >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[6][0].rolloff);
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain6_phase_freq0_freq1(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 0;
uint8_t freq_lv_to = 1;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain6_phase_freq2_freq3(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 2;
uint8_t freq_lv_to = 3;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[6][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain7_hstia(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_a >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_a >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_a >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_a);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 56);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 48);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 40);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 32);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].hstia_b);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].rolloff >> 24);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].rolloff >> 16);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].rolloff >> 8);
ctx[index++] = (uint8_t)(CaliTable.hstia_current[7][0].rolloff);
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain7_phase_freq0_freq1(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 0;
uint8_t freq_lv_to = 1;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
static void send_cali_gain7_phase_freq2_freq3(void)
{
uint8_t len = CALI_SIZE;
uint8_t ctx[CALI_SIZE] = {0};
uint8_t index = 0;
uint8_t freq_lv_from = 2;
uint8_t freq_lv_to = 3;
ctx[index++] = len - 1;
ctx[index++] = instru.chip_id;
for (int i=freq_lv_from; i<=freq_lv_to; i++) {
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].coeff);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 24);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 16);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset >> 8);
ctx[index++] = (uint8_t)(CaliTable.phase[7][i].offset);
}
ctx[len-1] = check_sum(ctx, len);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, CALI_SIZE, ctx);
return;
}
@@ -0,0 +1,809 @@
#ifndef HEADSTAGE_H
#define HEADSTAGE_H
#include <driverlib/timer.h>
#include <ti/drivers/SPI.h>
#include <ti/drivers/dma/UDMACC26XX.h>
#include <ti/drivers/spi/SPICC26XXDMA.h>
#include <ti/drivers/timer/GPTimerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <xdc/runtime/Timestamp.h>
#include <xdc/runtime/Types.h>
#include <stdbool.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/hal/Hwi.h>
#include <ti/sysbios/knl/Queue.h>
#ifdef ICALL_EVENTS
#include <ti/sysbios/knl/Event.h>
#else //! ICALL_EVENTS
#include <ti/sysbios/knl/Semaphore.h>
#endif // ICALL_EVENTS
#ifdef USE_ICALL
#include <icall.h>
#else
#include <stdlib.h>
#endif
#include "bcomdef.h"
#include "simple_gatt_profile.h"
/*===================================
==== headstage general variable ====
==================================*/
enum send_ins_para_order_e {
PARA_1 = 0x01,
PARA_2 = 0x02,
PARA_3 = 0x03,
PARA_4 = 0x04,
PARA_5 = 0x05,
PARA_6 = 0x06,
PARA_7 = 0x07,
PARA_8 = 0x08,
PARA_9 = 0x09,
PARA_10 = 0x0A,
PARA_11 = 0x0B,
PARA_12 = 0x0C,
PARA_13 = 0x0D,
PARA_14 = 0x0E,
PARA_15 = 0x0F,
PARA_16 = 0x10,
PARA_17 = 0x11,
PARA_FINAL = 0xFF,
};
#define UC_TO_5NV(_v) (_v - 25000) * 4 * 10000; //userode to 5nv per unit
#include "Elite_def.h"
#include "EliteWorkData.h"
/**
* application use instruction receive buffer.
* the length equals to the characteristic 3 which value is 12 bytes.
*/
static uint8_t ins_buf[BLE_INS_BUFF_SIZE] = {0};
static uint8_t not_buf[BLE_DAT_BUFF_SIZE] = {0};
static uint8_t cis_buf[BLE_CIS_BUFF_SIZE] = {0};
static bool PeriodicEvent = false;
static bool InitPeriodicEvent = true;
static bool megaStiEnable = false;
/*=====================================
==== headstage function prototype ====
====================================*/
/**
* ZM function
*/
static uint32_t VsetRateTable[5] = {2, 10, 100, 1000, 10000}; //0.2ms
static bool batteryCheck_flag;
static bool batteryADC_flag;
static bool notify_flag;
static bool record_flag;
static bool vscanReset;
static bool mode_init;
static bool fout_flag;
static bool gainChange_flag;
static bool firstFreq_flag;
//pulse mode variable
static int16_t I_GAIN_100R_counter;
static int16_t I_GAIN_3K_counter;
static int16_t I_GAIN_100K_counter;
static int16_t I_GAIN_3M_counter;
static int16_t VIN_GAIN_1M_counter;
static int16_t VIN_GAIN_30K_counter;
static int16_t VIN_GAIN_1K_counter;
static int16_t VOUT_GAIN_240K_counter;
static int16_t VOUT_GAIN_15K_counter;
static uint8_t lastVinADCGainLv;
static uint8_t lastIinADCGainLevel;
static uint8_t last_gain_lptia;
static uint8_t last_gain_hstia;
static void VinADCGainCtrl(uint8_t VinADCLevel);
static void VoutGainControl(uint8_t VOUTLevel);
static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool highlow);
// Elite key detection & turn on/ shutdown function (peripheral hardware control)
static void ModeLED(uint16_t modeStatus);
// periodic event control
static void EliteADCControl(void);
// static void cv_vscan(void);
// static void ca_vscan(void);
// static void rt_vscan(void);
static void mode_done(void);
//mode (DAC)
static void DACenable(uint8_t afterRead);
static void freq_out();
static void vscan_volt_out(void);
static uint32_t User2Freq(uint32_t UserCode);
static int32_t neg_18bit(int32_t ret);
//mode (notify)
// static void initDATBuf();
#include "EliteInstruction.h"
#include "EliteADC.h"
#include "EliteDAC.h"
#include "EliteSPI.h"
#include "board.h"
#include "EliteNotify.h"
#include "AD5940.h"
#include "EliteReset.h"
#include "EliteLED.h"
#include "Elite_mode_ADC_DAC.h"
#include "mode_ca.h"
#include "mode_vt.h"
#include "mode_rt.h"
#include "mode_cv.h"
#include "mode_eis.h"
#include "mode_cf.h"
#include "impedance_meter.h"
#include "Elite_version.h"
#include "eis_cali_cis.h"
static void decode_ris_ins(uint8 *ins)
{
switch (ins[2]) {
case CURVE_EIS:
decode_eis_mode(ins);
break;
case CURVE_CV:
decode_cv_mode(ins);
break;
case CURVE_CA:
decode_ca_mode(ins);
break;
case CURVE_VT:
decode_vt_mode(ins);
break;
case CURVE_RT:
decode_rt_mode(ins);
break;
case CURVE_CF:
decode_cf_mode(ins);
break;
case 0xE2:{ //SET_PARA: { 0xE2
if (ins[3] == 0x01) {
int32_t volt;
volt = (int32_t)ins[4] << 8 | (int32_t)ins[5];
set_rt_volt(volt);
} else if (ins[3] == 0x02) {
struct wm_cf_ctx_t *cf = (struct wm_cf_ctx_t *)wm_get();
cf->_amp = (uint16_t)ins[4] << 8 | (uint16_t)ins[5]; //0~2047
SetWGAmp(cf->_amp,instru.fset);
DAC_outputF(Freq2DAC(instru.fset)); //[10mHz->Reg's]
fset_flag = true;
}
break;
}
case SET_SAMPLE_RATE: {
instru.notifyRate = (uint32_t)ins[3] << 8 | (uint32_t)ins[4];
instru.notifyRate = 10000 / instru.notifyRate * 10;
break;
}
case 0xFF: { // 0x3000FF DEV_MODE
switch (ins[3]) {
case 0x01: {
uint8_t ctx[BLE_CIS_BUFF_SIZE] = {0};
uint8_t len = BLE_CIS_BUFF_SIZE;
ctx[0] = len-1;
ctx[1] = 0xFF;
ctx[2] = NotifyVoltBat[0];
ctx[3] = NotifyVoltBat[1];
ctx[4] = NotifyVoltBat[2];
ctx[5] = NotifyVoltBat[3];
ctx[6] = 0x00;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ctx);
break;
}
case 0x03: { // ble write: 0x3000FF 03
if (ins[4] == 1) {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_RED);
} else if (ins[4] == 2){
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_ORANGE);
} else if (ins[4] == 3){
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_YELLOW);
} else if (ins[4] == 4){
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_GREEN);
} else if (ins[4] == 5){
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
} else if (ins[4] == 6){
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_MAGENTA);
} else if (ins[4] == 7){
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_RED);
}
break;
}
case 0x70: { // SET_GENERAL_HS_RTIA
instru.gain_lv_hstia = ins[4];
if (instru.gain_lv_hstia < HSRTIA_MAX) {
instru.HSTIAAutoGainEnable = 0;
HSTIAGainCtrl(instru.gain_lv_hstia);
} else {
instru.HSTIAAutoGainEnable = 1;
instru.gain_lv_hstia = HSRTIA_200R;
HSTIAGainCtrl(instru.gain_lv_hstia);
}
break;
}
case 0x71: { // SET_GENERAL_LP_RTIA
instru.gain_lv_lptia = ins[4];
if (instru.gain_lv_lptia != I_GAIN_AUTO) {
instru.LPTIAAutoGainEnable = 0;
} else {
instru.LPTIAAutoGainEnable = 1;
instru.gain_lv_lptia = LPRTIA_200R;
LPTIAGainCtrl(instru.gain_lv_lptia);
}
break;
}
case 0x72 : { //HIGH_Z
SetEISHIGHZ(ins[4]); //0:open CE0, 1:close CE0
break;
}
case 0x73: { // to reset hstia gain when using error gain
instru.HSTIAAutoGainEnable = 1;
instru.gain_lv_hstia = HSRTIA_200R;
HSTIAGainCtrl(instru.gain_lv_hstia);
break;
}
case 0x74: { //roy test
set_ca_volt(ins);
break;
}
case 0x75: { //roy test
static uint16_t user_volt = 0;
user_volt = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
int32_t LPvolt = (user_volt - 25000) * 4 * 4000; //[5nV]
DAC_outputV(LPvolt);
break;
}
case 0x76: { //roy test
setEIS_EIS_cali();
break;
}
case 0x77: { //roy test
setEIS_CV();
break;
}
// 0xF0 ~ 0xF3 are cali mode function
case 0xF0: { //cali DAC, set AC dcbias & acamp & freq //no long use
uint8_t use_cali = ins[12];
instru.gain_lv_hstia = HSRTIA_200R;
instru.dcbias = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
instru.acamp = (uint16_t)ins[6] << 8 | (uint16_t)ins[7];
instru.fset = (uint32_t)ins[8] << 24 | (uint32_t)ins[9] << 16 | (uint32_t)ins[10] << 8 | (uint32_t)ins[11];
instru.fset = User2Freq(instru.fset);
if (use_cali == 0) {
setEIS_EIS_cali();
DAC_outputF(Freq2DAC(instru.fset)); //[10mHz->Reg's]
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE);
SetEISHIGHZ(1);
}
break;
}
case 0xF1: { //cali DAC, set DC offset //no long use
instru.gain_lv_hstia = HSRTIA_200R;
instru.dcbias = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
instru.acamp = 0x0000;
instru.fset = 0x0000;
uint8_t use_cali = ins[6];
if (use_cali == 0) {
setEIS_EIS_cali();
freq_out();
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE);
}
break;
}
case 0xF2: { //change LPTIA gain
instru.gain_lv_lptia = ins[4];
LPTIAGainCtrl(instru.gain_lv_lptia);
break;
}
case 0xF3: { //LPDAC volt output
static uint16_t user_volt = 0;
user_volt = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
int32_t LPvolt = (user_volt - 25000) * 4 * 4000; //[5nV]
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE);
setEIS_CV();
DAC_outputV(LPvolt);
break;
}
case 0xF4: { //read ADCDAT data
uint8_t ctx[BLE_CIS_BUFF_SIZE] = {0};
uint8_t len = BLE_CIS_BUFF_SIZE;
uint32_t rd;
rd = AD5940_SPIReadReg(ADCDAT);
ctx[0] = len-1;
ctx[1] = (uint8_t)((ADCDAT & 0xFF00) >> 8);
ctx[2] = (uint8_t)(ADCDAT & 0x00FF);
ctx[3] = (uint8_t)(rd >> 24);
ctx[4] = (uint8_t)(rd >> 16);
ctx[5] = (uint8_t)(rd >> 8);
ctx[6] = (uint8_t)rd;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ctx);
break;
}
case 0xF7: { //cali DAC: set nzero & nbias & acamp & freq
uint8_t ctx[BLE_CIS_BUFF_SIZE] = {0};
uint8_t len = BLE_CIS_BUFF_SIZE;
uint32_t DACOutCode;
uint16_t n_bias = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
uint16_t n_zero = (uint16_t)ins[6] << 8 | (uint16_t)ins[7];
instru.acamp = (uint16_t)ins[8] << 8 | (uint16_t)ins[9];
instru.fset = (uint32_t)ins[10] << 24 | (uint32_t)ins[11] << 16 | (uint32_t)ins[12] << 8 | (uint32_t)ins[13];
instru.gain_lv_hstia = HSRTIA_200R;
if(n_bias > 4095) n_bias = 4095;
if(n_zero > 63) n_zero = 63;
DACOutCode = (0x0003FFFF & ((n_zero << 12) + n_bias));
set_hs_only();
if (instru.gain_lv_hstia < HSRTIA_MAX) {
instru.HSTIAAutoGainEnable = 0;
HSTIAGainCtrl(instru.gain_lv_hstia);
} else {
instru.HSTIAAutoGainEnable = 1;
instru.gain_lv_hstia = HSRTIA_200R;
HSTIAGainCtrl(instru.gain_lv_hstia);
}
AD5940_SPIWriteReg(LPDACDAT0, DACOutCode);
AD5940_SPIWriteReg(WGFCW, instru.fset);
AD5940_SPIWriteReg(WGCON, 0x0); // 0x0: DC disable ac first
AD5940_SPIWriteReg(WGAMPLITUDE, instru.acamp);
AD5940_SPIWriteReg(WGCON, 0x00000004); //0x4: Sinusoid
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE);
SetEISHIGHZ(1);
ctx[0] = len-1;
ctx[1] = 0xF7;
ctx[2] = ins[4];
ctx[3] = ins[5];
ctx[4] = ins[6];
ctx[5] = ins[7];
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ctx);
break;
}
case 0xF8: { //cali DAC: set dcbias & acamp & freq
uint8_t ctx[BLE_CIS_BUFF_SIZE] = {0};
uint8_t len = BLE_CIS_BUFF_SIZE;
uint8_t cali_amp;
instru.dcbias = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
instru.acamp = (uint16_t)ins[8] << 8 | (uint16_t)ins[9];
instru.fset = (uint32_t)ins[10] << 24 | (uint32_t)ins[11] << 16 | (uint32_t)ins[12] << 8 | (uint32_t)ins[13];
cali_amp = ins[14]; //cali_amp=0:after cali, cali_amp=1:before cali
instru.gain_lv_hstia = HSRTIA_200R;
set_hs_only();
//change gain
if (instru.gain_lv_hstia < HSRTIA_MAX) {
instru.HSTIAAutoGainEnable = 0;
HSTIAGainCtrl(instru.gain_lv_hstia);
} else {
instru.HSTIAAutoGainEnable = 1;
instru.gain_lv_hstia = HSRTIA_200R;
HSTIAGainCtrl(instru.gain_lv_hstia);
}
//set DCbias
HSDAC_outputV((int32_t)instru.dcbias);
//set freq
AD5940_SPIWriteReg(WGFCW, instru.fset);
//set amp
if (cali_amp == 0) {
SetWGAmp(instru.acamp,instru.fset);
} else {
AD5940_SPIWriteReg(WGCON, 0x0); // 0x0: DC disable ac first
AD5940_SPIWriteReg(WGAMPLITUDE, instru.acamp);
AD5940_SPIWriteReg(WGCON, 0x00000004); //0x4: Sinusoid
}
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_PURPLE);
SetEISHIGHZ(1);
ctx[0] = 6;
ctx[1] = 0xF7;
ctx[2] = ins[4];
ctx[3] = ins[5];
ctx[4] = ins[6];
ctx[5] = ins[7];
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ctx);
break;
}
case 0xFD: { // ble write: 0x3000FF 20FFFFFFFFFFFF CTL_WRT //0x20->0xfd
uint8_t ctx[BLE_CIS_BUFF_SIZE] = {0};
uint8_t len = BLE_CIS_BUFF_SIZE;
uint16_t address = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
uint32_t data = (uint32_t)ins[6] << 24 | (uint32_t)ins[7] << 16 |
(uint32_t)ins[8] << 8 | (uint32_t)ins[9];
AD5940_SPIWriteReg(address, data);
ctx[0] = 6;
ctx[1] = (uint8_t)(address >> 8);
ctx[2] = (uint8_t)(address);
ctx[3] = (uint8_t)(data >> 24);
ctx[4] = (uint8_t)(data >> 16);
ctx[5] = (uint8_t)(data >> 8);
ctx[6] = (uint8_t)(data);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ctx);
break;
}
case 0xFE: { // ble write: 0x3000FF 21FFFF CTL_RD //0x21->0xfe
uint8_t ctx[BLE_CIS_BUFF_SIZE] = {0};
uint8_t len = BLE_CIS_BUFF_SIZE;
uint16_t address = (uint16_t)ins[4] << 8 | (uint16_t)ins[5];
uint32_t rd;
rd = AD5940_SPIReadReg(address);
ctx[0] = 6;
ctx[1] = (uint8_t)(address >> 8);
ctx[2] = (uint8_t)(address);
ctx[3] = (uint8_t)(rd >> 24);
ctx[4] = (uint8_t)(rd >> 16);
ctx[5] = (uint8_t)(rd >> 8);
ctx[6] = (uint8_t)rd;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ctx);
break;
}
case 0xFF: { //UI write: 11 CTL_RESET //0x11->0xff
AD5940_HWReset();
AD5940_Initialize();
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_GREEN);
break;
}
// case 0x13: { //HIGH_Z
// SetEISHIGHZ(ins[4]); //0:open highz, CE0 no output
// break;
// }
// case 0x18: {
// uint16_t b;
// uint8_t z;
// z = ins[4];
// b = (uint16_t)ins[5] << 8 | (uint16_t)ins[6];
// set_lpdac_ce_1100mv(z, b);
// break;
// }
// case 0xF4: { //debug function: fixed DC voltage
// instru.Vinit = (int32_t)ins[4] << 8 | (int32_t)ins[5];
// instru.Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
// setEIS_CV();
// DAC_outputV(instru.Vinit);
// led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
// break;
// }
}
break;
}
default:
break;
}
}
static void decode_vis_ins(uint8 *ins)
{
uint8_t oper = ins[1] & 0xF0; // this is don't care in RISASD;//
switch (oper) {
// reset all variables ( Ins = 0xC0F0)
case VIS_RST: {
instru.eliteFxn = VIS_RST;
reset();
break;
}
case VIS_STI: {
for(int i = 0; i < 12; i++) {
FlushNotify();
}
PeriodicEvent = true;
InitPeriodicEvent = true; // need to create a WorkModeData?
mode_init = true;
break;
}
case VIS_INT: {
reset();
for (int i = 0; i < 12; i++) {
FlushNotify();
}
break;
}
case VIS_DEVICE_SHINY: { //detect
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_MAGENTA);
// uint8_t deviceShinySwitch = (ins[2] & 0b11110000) >> 4;//1:open 0:close
// if(deviceShinySwitch == 1){
// led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_MAGENTA);
// }else if(deviceShinySwitch == 0){
// if(PeriodicEvent){
// led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_CYAN);
// }else if(!PeriodicEvent){
// led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_GREEN);
// }
// }
break;
}
case VIS_SHINY_DIS: {
if (PeriodicEvent) {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_CYAN);
} else if (!PeriodicEvent) {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_GREEN);
}
break;
}
default: {
break;
}
}
return;
}
static void decode_cis_ins(uint8 *ins)
{
uint8_t oper = ins[1] & 0xF0;
switch (oper) {
case CIS_VERSION: {
uint8_t ctx[BLE_CIS_BUFF_SIZE] = {0};
uint8_t len = BLE_CIS_BUFF_SIZE;
ctx[0] = 6;
ctx[1] = CIS_VERSION;
ctx[2] = VERSION_DATE_YEAR;
ctx[3] = VERSION_DATE_MONTH;
ctx[4] = VERSION_DATE_DAY;
ctx[5] = VERSION_DATE_HOUR;
ctx[6] = VERSION_DATE_MINUTE;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ctx);
break;
}
case CIS_VOLT: {
uint8_t ctx[BLE_CIS_BUFF_SIZE] = {0};
uint8_t len = BLE_CIS_BUFF_SIZE;
ctx[0] = 3;
ctx[1] = CIS_VOLT;
ctx[2] = NotifyVoltBat[3];
ctx[3] = NotifyVoltBat[2];
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, ctx);
break;
}
case CIS_CALI: {
if (ins[2] == 0) {
send_cali_version();
} else if (ins[2] == 1) {
send_cali_gain0_hstia();
} else if (ins[2] == 2) {
send_cali_gain0_phase_freq0_freq1();
} else if (ins[2] == 3) {
send_cali_gain0_phase_freq2_freq3();
} else if (ins[2] == 4) {
send_cali_gain1_hstia();
} else if (ins[2] == 5) {
send_cali_gain1_phase_freq0_freq1();
} else if (ins[2] == 6) {
send_cali_gain1_phase_freq2_freq3();
} else if (ins[2] == 7) {
send_cali_gain2_hstia();
} else if (ins[2] == 8) {
send_cali_gain2_phase_freq0_freq1();
} else if (ins[2] == 9) {
send_cali_gain2_phase_freq2_freq3();
} else if (ins[2] == 10) {
send_cali_gain3_hstia();
} else if (ins[2] == 11) {
send_cali_gain3_phase_freq0_freq1();
} else if (ins[2] == 12) {
send_cali_gain3_phase_freq2_freq3();
} else if (ins[2] == 13) {
send_cali_gain4_hstia();
} else if (ins[2] == 14) {
send_cali_gain4_phase_freq0_freq1();
} else if (ins[2] == 15) {
send_cali_gain4_phase_freq2_freq3();
} else if (ins[2] == 16) {
send_cali_gain5_hstia();
} else if (ins[2] == 17) {
send_cali_gain5_phase_freq0_freq1();
} else if (ins[2] == 18) {
send_cali_gain5_phase_freq2_freq3();
} else if (ins[2] == 19) {
send_cali_gain6_hstia();
} else if (ins[2] == 20) {
send_cali_gain6_phase_freq0_freq1();
} else if (ins[2] == 21) {
send_cali_gain6_phase_freq2_freq3();
} else if (ins[2] == 22) {
send_cali_gain7_hstia();
} else if (ins[2] == 23) {
send_cali_gain7_phase_freq0_freq1();
} else if (ins[2] == 24) {
send_cali_gain7_phase_freq2_freq3();
}
break;
}
}
}
// update instruction for Z meter
static void update_ZM_instruction(uint8 *ins) {
uint8_t ins_type = ins[0] & 0b11110000;
instru.chip_id = ins[0] & 0b00001111;
switch (ins_type) {
case INS_TYPE_RIS:
decode_ris_ins(ins);
break;
case INS_TYPE_VIS:
decode_vis_ins(ins);
break;
case INS_TYPE_CIS:
decode_cis_ins(ins);
break;
}
return;
}
static void ZM_instruction_update_handle(uint8_t characteristic) {
switch (characteristic) {
case BLE_INS_BUFF_CHAR:
SimpleProfile_GetParameter(SIMPLEPROFILE_CHAR3, ins_buf);
update_ZM_instruction(ins_buf);
break;
default:
break;
}
}
#include "devinfoservice.h"
#include "gapgattserver.h"
#include "gattservapp.h"
struct date_t {
uint8_t year;
uint8_t month;
uint8_t day;
};
struct device_info_t {
struct date_t date;
};
struct device_info_t device_info;
void get_date(struct date_t *date)
{
const char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
struct date_t *d = date;
char year_s[5] = {0};
char month_s[4] = {0};
char day_s[3] = {0};
int i;
char date_now[] = __DATE__;
memcpy(year_s, date_now + 9, 2);
memcpy(month_s, date_now, 3);
memcpy(day_s, date_now + 4, 2);
d->year = atoi(year_s);
d->day = atoi(day_s);
for (i=0; i<12; i++) {
if (!strcmp(month_s, months[i])) {
d->month = i + 1;
break;
}
}
return;
}
static void headstage_init_device_info() {
uint8_t scanRspData[64] = {9};
uint8_t *p = scanRspData;
struct device_info_t *dev = &device_info;
int i;
get_date(&device_info.date);
*p++ = sizeof(DEVICE_NAME); // 10
*p++ = GAP_ADTYPE_LOCAL_NAME_COMPLETE; // 09
for (i=0; i<sizeof(DEVICE_NAME)-1; i++) {
*p++ = DEVICE_NAME[i];
} // 69 108 105 116 101 45 69 73 83
*p++ = 16; // 16
*p++ = GAP_ADTYPE_MANUFACTURER_SPECIFIC; // 255
*p++ = 'B'; // 66
*p++ = 'P'; // 80
*p++ = 'H'; // 72
*p++ = 'S'; // 83
*p++ = MAJOR_PRODUCT_NUMBER; // 0
*p++ = MINOR_PRODUCT_NUMBER; // 4
*p++ = MAJOR_VERSION_NUMBER; // 1
*p++ = MINOR_VERSION_NUMBER; // 0
*p++ = dev->date.year; // 22
*p++ = dev->date.month; // 07
*p++ = 'B'; // 66
*p++ = 'A'; // 65
*p++ = 'T'; // 84
*p++ = NotifyVoltBat[3]; // 44
*p++ = NotifyVoltBat[2]; // 33
GGS_SetParameter(GGS_DEVICE_NAME_ATT, sizeof(DEVICE_NAME), DEVICE_NAME);
GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, p - scanRspData, scanRspData);
}
#endif // HEADSTAGE_H
@@ -0,0 +1,307 @@
/*
* impedance_meter.h
*
* Created on: 2019/01/15
* Author: benny
*/
#ifndef HEADSTAGE_H
#error "headstage.h not include"
#endif
#ifdef HEADSTAGE_H_H
#error "headstage_*.h has be included"
#endif
#ifndef IMPEDANCE_METER_H_
#define HEADSTAGE_H_H
#define IMPEDANCE_METER_H_
// header
#include "EliteWorkData.h"
static bool vscan_flag;
static bool ADC_flag;
static bool notifyFirst_flag;
static bool leadTimeReset;
static bool firstTimeReset;
static bool fset_flag;
static void vscan_ctrl(void);
#define IsPeriodicMode() ( \
instru.eliteFxn == CURVE_EIS || \
instru.eliteFxn == CURVE_CF || \
instru.eliteFxn == CURVE_CV || \
instru.eliteFxn == CURVE_CA || \
instru.eliteFxn == CURVE_VT || \
instru.eliteFxn == CURVE_RT \
)
#define Ve1MatchVe2Mode() ( \
(instru.eliteFxn == CURVE_EIS) || \
(instru.eliteFxn == CURVE_CF) || \
(instru.eliteFxn == CURVE_CV) \
)
/*********************************************************************
* @fn SimpleBLEPeripheral_performPeriodicTask
*
* @brief Control periodic event such as DAC out, ADC read, and send notify.
*
* @param None.
*
* @return None.
*/
static void elite_task()
{
if (IsPeriodicMode()) {
if((instru.eliteFxn == CURVE_EIS) || (instru.eliteFxn == CURVE_CF)){
if (mode_init){
GPT.cnt_adc_rate = 0;
mode_init = false;
gainChange_flag = false;
firstFreq_flag = true;
fset_flag = true;
fout_flag = true;
firstTimeReset = true;
notifyFirst_flag = true;
DACReset = true;
vscanReset = true;
leadTimeReset = true;
if ((instru.f1 == instru.f2) && (instru.eliteFxn == CURVE_EIS)) {
DAC_outputF(instru.f1);
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
SetEISHIGHZ(1);
InitGPT();
}
//vscan counter //fset counter
if (fset_flag) {
vscan_ctrl(); //set
fset_flag = false;
fout_flag = true;
}
//ADC counter
GPT.cnt_adc_rate = GPT.cnt_adc_rate + GPT.cnt_gpt_delta;
if(GPT.cnt_adc_rate >= instru.sampleRate){
GPT.cnt_adc_rate = 0; //To get right data, ADC must be delay 1.5ms
ADC_flag = true;
if(ADC_flag){
EliteADCControl(); //read data
ADC_flag = false;
}
}
//Notify counter(Notify control, check if we need to send notify)
//please don't put Notify counter before ADC counter, maybe get wrong data
if(vscanReset){
notify_flag = false;
}
if(notify_flag){
SendNotify(); //send
notify_flag = false;
fset_flag = true;
}
mode_done(); //finishMode = 1, SendNotify(), reset()
} else {
/** Periodic Event **/
// Default working flow is vscan -> ADC read -> send notify
// We will need a flag to control vscan, ADC and notify
static bool first_highz_flag = false;
if (mode_init) {
GPT.cnt_adc_rate = instru.sampleRate - 10;
GPT.cnt_v_scan_rate = instru.VsetRate - 1;
mode_init = false;
batteryADC_flag = false;
record_flag = true;
fset_flag = true;
firstTimeReset = true;
notifyFirst_flag = true;
first_highz_flag = true;
I_GAIN_100R_counter = 0;
I_GAIN_3K_counter = 0;
I_GAIN_100K_counter = 0;
I_GAIN_3M_counter = 0;
VIN_GAIN_1M_counter = 0;
VIN_GAIN_30K_counter = 0;
VIN_GAIN_1K_counter = 0;
VOUT_GAIN_240K_counter = 0;
VOUT_GAIN_15K_counter = 0;
DACReset = true;
vscanReset = true;
leadTimeReset = true;
if (Ve1MatchVe2Mode()) {
if (instru.Ve1 == instru.Ve2) {
DAC_outputV(instru.Ve1);
PeriodicEvent = false;
SetEISHIGHZ(1);
ModeLED(NO_EVENT);
}
}
InitGPT();
}
GPT.cnt_lead_time = GPT.cnt_lead_time + GPT.cnt_gpt_delta;
if (leadTimeReset && GPT.cnt_lead_time <= 2000) {
vscanReset = true;
if (first_highz_flag && GPT.cnt_lead_time >= 1000) {
SetEISHIGHZ(1); // // High Z | 1 off | 0 on
first_highz_flag = false;
}
} else {
if (notifyFirst_flag) {
GPT.cnt_notify_rate = instru.notifyRate - 20;
notifyFirst_flag = false;
}
vscanReset = false;
leadTimeReset = false;
}
//vscan counter //fset counter
GPT.cnt_v_scan_rate = GPT.cnt_v_scan_rate + GPT.cnt_gpt_delta;
if (GPT.cnt_v_scan_rate >= instru.VsetRate) {
if (GPT.cnt_v_scan_rate >= instru.VsetRate * 2) {
GPT.GptimerMultiple = GPT.cnt_v_scan_rate / instru.VsetRate;
} else {
GPT.GptimerMultiple = 1;
}
GPT.cnt_v_scan_rate -= instru.VsetRate * GPT.GptimerMultiple; //To get right time
vscan_flag = true;
if (vscan_flag) {
vscan_ctrl(); //set
vscan_volt_out();
vscan_flag = false;
}
}
//ADC counter
GPT.cnt_adc_rate = GPT.cnt_adc_rate + GPT.cnt_gpt_delta;
if(GPT.cnt_adc_rate >= instru.sampleRate){
GPT.cnt_adc_rate = 0; //To get right data, ADC must be delay 1.5ms
ADC_flag = true;
if(ADC_flag){
EliteADCControl(); //read data
ADC_flag = false;
}
}
//Notify counter(Notify control, check if we need to send notify)
//please don't put Notify counter before ADC counter, maybe get wrong data
GPT.cnt_notify_rate = GPT.cnt_notify_rate + GPT.cnt_gpt_delta;
if(GPT.cnt_notify_rate >= instru.notifyRate){
GPT.cnt_notify_rate -= instru.notifyRate; //To get right time
notify_flag = true;
if(vscanReset){
notify_flag = false;
}
if(notify_flag){
SendNotify(); //send
notify_flag = false;
}
}
mode_done(); //finishMode = 1, SendNotify(), reset()
}
}
}
static void EliteADCControl(void) //CURVE_IV => CC_Plot() | CURVE_CV => Iin_Vin_Vout_Plot
{
void *wm = wm_get();
switch (instru.eliteFxn) {
case CURVE_EIS:
gain = instru.gain_lv_hstia;
EIS_Plot();
break;
case CURVE_CF:
gain = instru.gain_lv_hstia;
CF_Plot();
break;
case CURVE_CV:
gain = instru.gain_lv_lptia;
CV_Plot();
break;
case CURVE_CA:
gain = instru.gain_lv_lptia;
CA_Plot();
break;
case CURVE_VT:
gain = instru.gain_lv_lptia;
VT_Plot();
break;
case CURVE_RT:
gain = instru.gain_lv_lptia;
RT_Plot();
break;
default:
break;
}
}
static void mode_done(void) //finishMode = 1, SendNotify(), reset()
{
if (instru.eliteFxn == CURVE_CV) {
if (!PeriodicEvent) {
finishMode = 1;
SendNotify();
reset();
}
} else if ((instru.eliteFxn == CURVE_EIS) || (instru.eliteFxn == CURVE_CF)){
if (!PeriodicEvent) {
reset();
}
}
}
static void vscan_ctrl(void)
{
switch (instru.eliteFxn) {
case CURVE_EIS:
eis_fscan();
break;
case CURVE_CF:
cf_fscan();
break;
case CURVE_CV:
cv_vscan();
break;
case CURVE_CA:
ca_vscan();
break;
case CURVE_RT:
rt_vscan();
break;
default:{
break;
}
}
}
#endif /* IMPEDANCE_METER_H_ */
@@ -1,975 +0,0 @@
/*
* Real instruction(RIS)
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | 0011 |Mem id| Payload len | Payload ...
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* ... ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* Bytestream:
* 34 0C 01 61 A8 75 30 03 E8 12 43 21 03 E8
* 34 03 E1 01 03
*
*
* Virtual instruction(VIS)
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | 1100 |Mem id| operation |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* Bytestream:
* C4 C0
* C4 60
*
*
* Control instruction(CIS)
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | 0111 |Mem id| operation |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* Bytestream:
* 74 40
* 74 10
*/
/*
* RIS Payload
* +----------------------------------+-------------------------------+
* | mode(1B) | ... ... |
* +----------------------------------+-------------------------------+
* | CURVE_IV = 0x01 | ... ... |
* | CURVE_IV_CY = 0x02 | ... ... |
* | CURVE_VO = 0x03 | ... ... |
* | CURVE_RT = 0x04 | ... ... |
* | CURVE_VT = 0x05 | ... ... |
* | CURVE_IT = 0x06 | ... ... |
* | CURVE_CC = 0x07 | ... ... |
* | CURVE_OCP = 0x08 | ... ... |
* | CURVE_CV = 0x09 | ... ... |
* | CURVE_LSV = 0x0A | ... ... |
* | CURVE_CA = 0x0B | ... ... |
* | CURVE_PULSE = 0x0C | ... ... |
* | CURVE_UNI_PULSE = 0x0D | ... ... |
* | CURVE_DPV = 0x0E | ... ... |
* | CURVE_DPV_SMPRATE = 0x0F | ... ... |
* | CURVE_DPV_ADVANCE = 0x10 | ... ... |
* | CURVE_DPV_ADVANCE_SMPRATE = 0x11 | ... ... |
* | CURVE_CALI_ADC = 0xF1 | ... ... |
* | MODE_DEV_TOOL = 0xFF | ... ... |
* | SET_SAMPLE_RATE = 0xE0 | ... ... |
* | SET_ADC_DAC_GAIN = 0xE1 | ... ... |
* | SET_PARA = 0xE2 | ... ... |
* +----------------------------------+----------------------------------
*/
static uint32_t OldStep2NewStepTime(uint32_t StepTime){
uint8_t StepTimeLevel = 0;
StepTimeLevel = StepTime / 0x12;
switch (StepTimeLevel) {
case 0: { //0.5 sec
return STEPTIME_HALF_SEC;
}
case 1: { //1 sec
return STEPTIME_ONE_SEC;
}
case 2: { //2 sec
return STEPTIME_TWO_SEC;
}
default: { //1 sec
return STEPTIME_ONE_SEC;
}
}
}
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
static void step2VsetRate(uint32_t step){
/*step = 100 mv, index = 0, n = 2
10 mv, index = 1, n = 10
1 mv, index = 2, n = 100
0.1 mv, index = 3, n = 1000
0.01mv, index = 4, n = 10000 */
if(step >= 10000){
instru.VsetRateIndex = 0;
}else if (step >= 1000){
instru.VsetRateIndex = 1;
}else if (step >= 100){
instru.VsetRateIndex = 2;
}else if (step >= 10){
instru.VsetRateIndex = 3;
}else if (step >= 1){
instru.VsetRateIndex = 4;
}
}
#include "headstage/mode_dev_tool.h"
static void ins_decode_ris(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
uint8_t mode = p[2];
switch (mode) {
case CURVE_IV: {
instru.eliteFxn = CURVE_IV;
instru.Ve1 = ((uint16_t)(p[3]) << 8) | (uint16_t)(p[4]);
instru.Ve2 = ((uint16_t)(p[5]) << 8) | (uint16_t)(p[6]);
instru.Vinit = (int32_t)instru.Ve1;
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
instru.directionInit = VDIRECTION(instru.Ve1,instru.Ve2);
instru.steptime = (uint32_t)(p[9]);
instru.steptime = OldStep2NewStepTime(instru.steptime); //5000;10000;20000;
instru.step = ((uint32_t)(p[7]) << 8) | (uint32_t)(p[8]);//1~1000 = 0.1mv ~ 100mv
instru.step = instru.step * 100000 / instru.steptime;
STEP_TO_VSETRATE(instru.step);
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
instru.cycleNumber = 1;
instru.hign_z_en = ~(p[11] & 0x0F);
instru.notifyRate = ((uint32_t)p[12] << 8) | (uint32_t)p[13];
instru.notifyRate = 10000 / instru.notifyRate * 10;
if ((instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE)
&& (instru.Ve2 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve2 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE)) {
instru.VoutGainLv = VOUT_GAIN_15K;
} else {
instru.VoutGainLv = VOUT_GAIN_240K;
}
ModeLED(WORKING);
break;
}
case CURVE_IV_CY: {
instru.eliteFxn = CURVE_IV_CY;
instru.Ve1 = ((uint16_t)(p[3]) << 8) | (uint16_t)(p[4]);
instru.Ve2 = ((uint16_t)(p[5]) << 8) | (uint16_t)(p[6]);
instru.Vinit = (int32_t)instru.Ve1;
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
instru.directionInit = VDIRECTION(instru.Ve1,instru.Ve2);
instru.steptime = (uint32_t)(p[9]);
instru.steptime = OldStep2NewStepTime(instru.steptime); //5000;10000;20000;
instru.step = ((uint32_t)(p[7]) << 8) | (uint32_t)(p[8]);//1~1000 = 0.1mv ~ 100mv
instru.step = instru.step * 100000 / instru.steptime;
STEP_TO_VSETRATE(instru.step);
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
instru.cycleNumber = ((uint16_t)(p[10]) << 8) | (uint16_t)(p[11]);
instru.hign_z_en = ~(p[13] & 0x0F);
instru.notifyRate = ((uint32_t)p[14] << 8) | (uint32_t)p[15];
instru.notifyRate = 10000 / instru.notifyRate * 10;
if ((instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE)
&& (instru.Ve2 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve2 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE)) {
instru.VoutGainLv = VOUT_GAIN_15K;
} else {
instru.VoutGainLv = VOUT_GAIN_240K;
}
ModeLED(WORKING);
break;
}
case CURVE_VO: {
instru.eliteFxn = CURVE_VO;
instru.Ve1 = ((uint16_t)p[3] << 8) | (uint16_t)p[4];
instru.Vinit = (int32_t)instru.Ve1;
instru.hign_z_en = ~(p[6] & 0x0F);
if (instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
instru.VoutGainLv = VOUT_GAIN_15K;
} else {
instru.VoutGainLv = VOUT_GAIN_240K;
}
instru.notifyRate = ((uint32_t)p[7] << 8) | (uint32_t)p[8];
instru.notifyRate = 10000 / instru.notifyRate * 10;
ModeLED(WORKING);
break;
}
case CURVE_RT: {
instru.eliteFxn = CURVE_RT;
instru.notifyRate = ((uint32_t)p[7] << 8) | (uint32_t)p[8];
instru.notifyRate = 10000 / instru.notifyRate * 10;
instru.VsetRate = 2;
instru.Ve1 = ((uint16_t)p[3] << 8) | (uint16_t)p[4];
instru.Vinit = (int32_t)instru.Ve1;
instru.hign_z_en = ~(p[6] & 0x0F);
if (instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
instru.VoutGainLv = VOUT_GAIN_15K;
} else {
instru.VoutGainLv = VOUT_GAIN_240K;
}
ModeLED(WORKING);
break;
}
case CURVE_VT: {
instru.eliteFxn = CURVE_VT;
instru.notifyRate = ((uint32_t)p[5] << 8) | (uint32_t)p[6];
instru.notifyRate = 10000 / instru.notifyRate * 10;
instru.hign_z_en = ~(p[4] & 0x0F);
ModeLED(WORKING);
break;
}
case CURVE_IT: {
instru.eliteFxn = CURVE_IT;
instru.notifyRate = ((uint32_t)p[7] << 8) | (uint32_t)p[8];
instru.notifyRate = 10000 / instru.notifyRate * 10;
instru.Ve1 = ((uint16_t)p[3] << 8) | (uint16_t)p[4];
instru.Vinit = (int32_t)instru.Ve1;
instru.hign_z_en = ~(p[6] & 0x0F);
if (instru.Ve1 < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && instru.Ve1 > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
instru.VoutGainLv = VOUT_GAIN_15K;
} else {
instru.VoutGainLv = VOUT_GAIN_240K;
}
ModeLED(WORKING);
break;
}
case CURVE_CC: {
instru.eliteFxn = CURVE_CC;
instru.notifyRate = ((uint32_t)p[14] << 8) | (uint32_t)p[15];
instru.notifyRate = 10000 / instru.notifyRate * 10;
instru.charge = p[3]; //0:discharge 1:charge
instru.constantCurrent = (uint32_t)(p[4]) << 24 | (uint32_t)(p[5]) << 16 | (uint32_t)(p[6]) << 8 | (uint32_t)(p[7]);
instru.Vmax = (uint32_t)(p[8]) << 8 | (uint32_t)(p[9]);
instru.Vmin = (uint32_t)(p[10]) << 8 | (uint32_t)(p[11]);
instru.hign_z_en = ~(p[13] & 0x0F);
instru.VoutGainLv = VOUT_GAIN_240K;
ModeLED(WORKING);
/*******************************************************
controller instruction
p[3] -> Charge, 0:discharge 1:charge
p[6:9] -> ConstantCurrent, 0 ~ 15000uA : 0 ~ 1500000
********************************************************/
break;
}
case CURVE_CV: {
if (p[3] == PARA_1) {
instru.Vinit = ((int32_t)(p[4]) << 8) | (int32_t)(p[5]);
instru.Ve1 = ((uint16_t)(p[6]) << 8) | (uint16_t)(p[7]);
instru.Ve2 = ((uint16_t)(p[8]) << 8) | (uint16_t)(p[9]);
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
if (instru.Vinit > instru.Ve1 || instru.Vinit == instru.Vmax) {
instru.directionInit = 0;//0:reverse 1:forward
} else if (instru.Vinit <= instru.Ve1 || instru.Vinit == instru.Vmin) {
instru.directionInit = 1;
}
//controller UI 0.01~1000mv send to Elite 1~100000
instru.step = (uint32_t)(p[10]) << 24 | (uint32_t)(p[11]) << 16 | (uint32_t)(p[12]) << 8 | (uint32_t)(p[13]);
STEP_TO_VSETRATE(instru.step);
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
instru.Currentmax = (int32_t)(p[14]) << 24 | (int32_t)(p[15]) << 16 | (int32_t)(p[16]) << 8 | (int32_t)(p[17]);
} else if (p[3] == PARA_2) {
instru.eliteFxn = CURVE_CV;
instru.cycleNumber = ((uint16_t)(p[4]) << 8) | (uint16_t)(p[5]);
instru.notifyRate = (uint32_t)(p[8]) << 8 | (uint32_t)(p[9]);
instru.notifyRate = 10000 / instru.notifyRate * 10;
instru.hign_z_en = ~(p[7] & 0x0F);
instru.VoutGainLv = VOUT_GAIN_240K;
ModeLED(WORKING);
}
break;
}
case CURVE_LSV: {
if (p[3] == PARA_1) {
instru.Ve1 = ((uint16_t)(p[4]) << 8) | (uint16_t)(p[5]);
instru.Ve2 = ((uint16_t)(p[6]) << 8) | (uint16_t)(p[7]);
instru.Vinit = (int32_t)instru.Ve1;
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
instru.directionInit = VDIRECTION(instru.Ve1,instru.Ve2);
instru.Currentmax = (int32_t)(p[12]) << 24 | (int32_t)(p[13]) << 16 | (int32_t)(p[14]) << 8 | (int32_t)(p[15]);
//controller UI 0.01~1000mv send to Elite 1~100000
instru.step = (uint32_t)(p[8]) << 24 | (uint32_t)(p[9]) << 16 | (uint32_t)(p[10]) << 8 | (uint32_t)(p[11]);
STEP_TO_VSETRATE(instru.step);
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
instru.cycleNumber = 1;//p[16.17];
} else if (p[3] == PARA_2) {
instru.eliteFxn = CURVE_LSV;
instru.notifyRate = (uint32_t)(p[6]) << 8 | (uint32_t)(p[7]);
instru.notifyRate = 10000 / instru.notifyRate * 10;
instru.hign_z_en = ~(p[5] & 0x0F);
instru.VoutGainLv = VOUT_GAIN_240K;
ModeLED(WORKING);
}
break;
}
case CURVE_CA: {
instru.eliteFxn = CURVE_CA;
instru.Vinit = ((int32_t)(p[3]) << 8) | (int32_t)(p[4]);
instru.notifyRate = (uint32_t)(p[7]) << 8 | (uint32_t)(p[8]);
instru.notifyRate = 10000 / instru.notifyRate * 10;
instru.VsetRate = VsetRateTable[0];
instru.hign_z_en = ~(p[6] & 0x0F);
instru.VoutGainLv = VOUT_GAIN_240K;
ModeLED(WORKING);
break;
}
case CURVE_OCP: {
instru.eliteFxn = CURVE_OCP;
instru.notifyRate = ((uint32_t)p[5] << 8) | (uint32_t)p[6];
instru.notifyRate = 10000 / instru.notifyRate * 10;
instru.hign_z_en = 0;
ModeLED(WORKING);
break;
}
case SET_SAMPLE_RATE: {
instru.notifyRate = (uint32_t)(p[3]) << 8 | (uint32_t)(p[4]);
instru.notifyRate = 10000 / instru.notifyRate * 10;
break;
}
case SET_ADC_DAC_GAIN: {
switch (p[3]) {
case RIS_ADC_IIN: {
instru.IinADCGainLv = p[4];
if (instru.IinADCGainLv != I_GAIN_AUTO) {
instru.IinADCAutoGainEn = 0;
} else {
instru.IinADCAutoGainEn = 1;
instru.IinADCGainLv = I_GAIN_100R;
IinADCGainCtrl(instru.IinADCGainLv);
}
break;
}
case RIS_ADC_VIN: {
instru.VinADCGainLv = p[4];
if (instru.VinADCGainLv != VIN_GAIN_AUTO) {
instru.VinADCAutoGainEn = 0;
} else {
instru.VinADCAutoGainEn = 1;
instru.VinADCGainLv = VIN_GAIN_1K;
VinADCGainCtrl(instru.VinADCGainLv);
}
break;
}
case RIS_DAC_VOUT: {
// instru.VoutGainLv = p[4];
// if (instru.VoutGainLv == VOUT_GAIN_AUTO) {
// instru.VoutGainLv = VOUT_GAIN_15K;
// }
instru.VoutGainLv = p[4];
VoutGainControl(instru.VoutGainLv);
break;
}
case RIS_HIGH_Z: {
switch (p[4]) {
case 0x00:
PIN15_setOutputValue(HIGH_Z, 0); // 0 => open high_z mode
break;
case 0x01:
PIN15_setOutputValue(HIGH_Z, 1); // 1 => close high_z mode
break;
default:
break;
}
break;
}
default:
break;
}
break;
}
case CURVE_CALI_ADC: {
switch (p[3]) {
case RIS_ADC_IIN: { // 0x00
instru.eliteFxn = CURVE_CALI_ADC;
instru.AdcChannel = RIS_ADC_IIN;
instru.notifyRate = 1000;
ModeLED(WORKING);
break;
}
case RIS_ADC_VIN: { // 0x01
instru.eliteFxn = CURVE_CALI_ADC;
instru.AdcChannel = RIS_ADC_VIN;
instru.notifyRate = 1000;
ModeLED(WORKING);
break;
}
case RIS_DAC_VOUT: { // 0x02
instru.eliteFxn = CURVE_CALI_ADC;
instru.AdcChannel = RIS_DAC_VOUT;
instru.notifyRate = 1000;
instru.VoltConstant = ( ((uint16_t)(p[4])) << 8) | (uint16_t)(p[5]); // output voltage
DAC_outputV(instru.VoltConstant); //UserCode -> DAC code -> DAC out
ModeLED(WORKING);
break;
}
default:
break;
}
break;
}
case CURVE_PULSE: {
instru.VoutGainLv = VOUT_GAIN_240K;
instru.notifyRate = 100;
if (p[3] == PARA_1) {
instru.sti_t1 = (int32_t)(p[4]) << 24 | (int32_t)(p[5]) << 16 | (int32_t)(p[6]) << 8 | (int32_t)(p[7]);
instru.sti_t2 = (int32_t)(p[8]) << 24 | (int32_t)(p[9]) << 16 | (int32_t)(p[10]) << 8 | (int32_t)(p[11]);
instru.sti_t3 = (int32_t)(p[12]) << 24 | (int32_t)(p[13]) << 16 | (int32_t)(p[14]) << 8 | (int32_t)(p[15]);
instru.sti_t4 = (int32_t)(p[16]) << 24 | (int32_t)(p[17]) << 16 | (int32_t)(p[18]) << 8 | (int32_t)(p[19]);
} else if (p[3] == PARA_2) {
instru.sti_t5 = (int32_t)(p[4]) << 24 | (int32_t)(p[5]) << 16 | (int32_t)(p[6]) << 8 | (int32_t)(p[7]);
instru.sti_v1 = 25000; //8~11
instru.sti_v2 = 50000; //12~15 //41406.43161.
instru.sti_v3 = 25000; //16~19
} else if (p[3] == PARA_3) {
instru.sti_v4 = 25000; //4~7
instru.sti_v5 = 25000; //8~11
instru.sti_cy = (uint16_t)(p[12]); //12
instru.sti_loop = (uint16_t)(p[13]); //13
} else if (p[3] == PARA_4) {
instru.sti_t6 = (int32_t)(p[4]) << 24 | (int32_t)(p[5]) << 16 | (int32_t)(p[6]) << 8 | (int32_t)(p[7]); //4~7
instru.sti_t7 = (int32_t)(p[8]) << 24 | (int32_t)(p[9]) << 16 | (int32_t)(p[10]) << 8 | (int32_t)(p[11]); //8~11
instru.sti_v6 = 25000; //12~15
instru.sti_v7 = 25000; //16~19
instru.sti_t1 = VALUE_ZERO_TO_ONE(instru.sti_t1);
instru.sti_t2 = VALUE_ZERO_TO_ONE(instru.sti_t2);
instru.sti_t3 = VALUE_ZERO_TO_ONE(instru.sti_t3);
instru.sti_t4 = VALUE_ZERO_TO_ONE(instru.sti_t4);
instru.sti_t5 = VALUE_ZERO_TO_ONE(instru.sti_t5);
instru.sti_t6 = VALUE_ZERO_TO_ONE(instru.sti_t6);
instru.sti_t7 = VALUE_ZERO_TO_ONE(instru.sti_t7);
megaStiEnable = true;
} else if (p[3] == PARA_17) {
instru.eliteFxn = CURVE_PULSE;
ModeLED(WORKING);
}
break;
}
case CURVE_UNI_PULSE: {
if (p[3] == PARA_1) {
uint8_t seg_index = p[12];
instru.v_initial[seg_index] = (int32_t)p[4] << 8 | (int32_t)p[5];
instru.v0 = instru.v_initial[0];
instru.t_pulse[seg_index] = (uint32_t)p[6] << 24 | (uint32_t)p[7] << 16 | (uint32_t)p[8] << 8 | (uint32_t)p[9];
instru.t_pulse_min[seg_index] = (uint32_t)p[10];
instru.t_pulse_max[seg_index] = (uint32_t)p[11];
instru.v_slope[seg_index] = 0;
instru.v_step[seg_index] = 0;
} else if (p[3] == PARA_2) {
uint8_t seg_index = p[12];
instru.v_initial[seg_index] = (int32_t)p[4] << 8 | (int32_t)p[5];
instru.t_pulse[seg_index] = (uint32_t)p[6] << 24 | (uint32_t)p[7] << 16 | (uint32_t)p[8] << 8 | (uint32_t)p[9];
instru.t_pulse_min[seg_index] = (uint32_t)p[10];
instru.t_pulse_max[seg_index] = (uint32_t)p[11];
instru.v_slope[seg_index] = 0;
instru.v_step[seg_index] = 0;
} else if (p[3] == PARA_3) {
uint8_t seg_index = p[12];
instru.v_initial[seg_index] = (int32_t)p[4] << 8 | (int32_t)p[5];
instru.t_pulse[seg_index] = (uint32_t)p[6] << 24 | (uint32_t)p[7] << 16 | (uint32_t)p[8] << 8 | (uint32_t)p[9];
instru.t_pulse_min[seg_index] = (uint32_t)p[10];
instru.t_pulse_max[seg_index] = (uint32_t)p[11];
instru.v_slope[seg_index] = 0;
instru.v_step[seg_index] = 0;
} else if (p[3] == PARA_4) {
uint8_t seg_index = p[12];
instru.v_initial[seg_index] = (int32_t)p[4] << 8 | (int32_t)p[5];
instru.t_pulse[seg_index] = (uint32_t)p[6] << 24 | (uint32_t)p[7] << 16 | (uint32_t)p[8] << 8 | (uint32_t)p[9];
instru.t_pulse_min[seg_index] = (uint32_t)p[10];
instru.t_pulse_max[seg_index] = (uint32_t)p[11];
instru.v_slope[seg_index] = 0;
instru.v_step[seg_index] = 0;
} else if (p[3] == PARA_FINAL) {
instru.eliteFxn = CURVE_UNI_PULSE;
instru.VoutGainLv = VOUT_GAIN_240K;
ModeLED(WORKING);
}
break;
}
case CURVE_DPV: {
/*
* DPV mode --auto
* +----------+------------+-------------+-----------------+---------------+---------------+
* | UI | E Initial | E Final | Pulse Amplitude | Pulse Width | Increment |
* | json | DPV_e_init | DPV_e_final | DPV_amp | DPV_pul_width | DPV_increment |
* +----------+------------+-------------+-----------------+---------------+---------------+
* | UI | Step Time | Sample rate | (audio) | (audio) |
* | json | DPV_step_time | DPV_notify_rate | DPV_mode | DPV_engineering_enable |
* +----------+---------------+-----------------+----------+------------------------+
* hide parameter
* +----------+-------------------------------------+
* | UI | Current Recording Period(Slots) |
* | json | DPV_curr_rec_max | DPV_curr_rec_min |
* +----------+------------------+------------------+
*
*/
//--mode
static uint8_t dpv_option;
//--Auto
static int32_t dpv_e_init;
static int32_t dpv_e_final;
static int32_t dpv_amp;
static uint32_t dpv_pul_width;
static int32_t dpv_increment;
static uint32_t dpv_step_time;
static uint32_t dpv_notify_rate;
static uint32_t dpv_curr_rec_percent_min[4];
static uint32_t dpv_curr_rec_percent_max[4];
//--engineering
static uint8_t dpv_engi_advanced_en;
if (p[3] == PARA_1) {
dpv_option = p[4];
dpv_engi_advanced_en = p[5];
} else if (p[3] == PARA_2) {
dpv_e_init = (int32_t)p[4] << 8 | (int32_t)p[5];
dpv_e_final = (int32_t)p[6] << 8 | (int32_t)p[7];
dpv_amp = (int32_t)p[8] << 8 | (int32_t)p[9];
dpv_pul_width = (uint32_t)p[10] << 24 | (uint32_t)p[11] << 16 | (uint32_t)p[12] << 8 | (uint32_t)p[13];
dpv_increment = (int32_t)p[14] << 8 | (int32_t)p[15];
} else if (p[3] == PARA_3) {
dpv_step_time = (uint32_t)p[4] << 24 | (uint32_t)p[5] << 16 | (uint32_t)p[6] << 8 | (uint32_t)p[7];
dpv_notify_rate = (uint32_t)p[8] << 8 | (uint32_t)p[9];
dpv_curr_rec_percent_min[0] = (uint32_t)p[10];
dpv_curr_rec_percent_max[0] = (uint32_t)p[11];
dpv_curr_rec_percent_min[1] = (uint32_t)p[10];
dpv_curr_rec_percent_max[1] = (uint32_t)p[11];
} else if (p[3] == PARA_FINAL) {
dpv_e_init = UC_TO_5NV(dpv_e_init);
dpv_e_final = UC_TO_5NV(dpv_e_final);
dpv_amp = UC_TO_5NV(dpv_amp);
dpv_pul_width = dpv_pul_width * 10;
dpv_increment = UC_TO_5NV(dpv_increment);
dpv_increment = abs(dpv_increment);
dpv_step_time = dpv_step_time * 10;
dpv_notify_rate = 10000 / dpv_notify_rate * 10;
instru.v0 = dpv_e_init;
instru.v_stop = dpv_e_final;
instru.t_pulse[0] = dpv_step_time - dpv_pul_width;
instru.t_pulse[1] = dpv_pul_width;
instru.v_initial[0] = dpv_e_init;
instru.v_initial[1] = dpv_e_init + dpv_amp;
instru.v_step[0] = dpv_increment;
instru.v_step[1] = dpv_increment;
instru.notifyRate = dpv_notify_rate;
instru.v_slope[0] = 0; // 1234 = slop 1.234, same as scanrate
instru.v_slope[1] = 0; // 1234 = slop 1.234
instru.t_pulse_min[0] = dpv_curr_rec_percent_min[0];
instru.t_pulse_max[0] = dpv_curr_rec_percent_max[0];
instru.t_pulse_min[1] = dpv_curr_rec_percent_min[1];
instru.t_pulse_max[1] = dpv_curr_rec_percent_max[1];
if (instru.v0 > instru.v_stop) {
instru.directionInit = 0;//0:reverse 1:forward
instru.v_step[0] = (-1) * instru.v_step[0];
instru.v_step[1] = (-1) * instru.v_step[1];
} else if (instru.v0 < instru.v_stop) {
instru.directionInit = 1;
}
if (dpv_option == 0) {
instru.eliteFxn = CURVE_DPV;
} else if (dpv_option == 2) {
instru.eliteFxn = CURVE_DPV_SMPRATE;
}
instru.VoutGainLv = VOUT_GAIN_240K;
ModeLED(WORKING);
}
break;
}
case CURVE_DPV_ADVANCE: {
/*
* DPV mode --advanced
* +----------+------------+---------+---------+-------------+-----------------+---------------+---------------+
* | UI | E Initial | E 1 | E 2 | E Final | Pulse Amplitude | Pulse Width | Increment |
* | json | DPV_e_init | DPV_e_1 | DPV_e_2 | DPV_e_final | DPV_amp | DPV_pul_width | DPV_increment |
* +----------+------------+---------+---------+-------------+-----------------+---------------+---------------+
* | UI | Step Time | Sample rate | Current Recording Period(Slots) |
* | json | DPV_step_time | DPV_notify_rate | DPV_curr_rec_max | DPV_curr_rec_min |
* +----------+---------------+-----------------+------------------+------------------+
* | UI | (audio) | (audio) |
* | json | DPV_mode | DPV_engineering_enable |
* +----------+----------+------------------------+
*
*/
//--mode
static uint8_t dpv_option;
//--advanced
static int32_t dpv_e_init;
static int32_t dpv_e_final;
static int32_t dpv_amp;
static uint32_t dpv_pul_width;
static int32_t dpv_increment;
static uint32_t dpv_step_time;
static uint32_t dpv_notify_rate;
static uint32_t dpv_curr_rec_percent_min[4];
static uint32_t dpv_curr_rec_percent_max[4];
static int32_t dpv_e_1;
static int32_t dpv_e_2;
static uint8_t dpv_invert_option;
static uint16_t dpv_cycle;
//--engineering
static uint8_t dpv_engi_advanced_en;
if (p[3] == PARA_1) {
dpv_option = p[4];
dpv_engi_advanced_en = p[5];
} else if (p[3] == PARA_2) {
dpv_e_init = (int32_t)p[4] << 8 | (int32_t)p[5];
dpv_e_final = (int32_t)p[6] << 8 | (int32_t)p[7];
dpv_amp = (int32_t)p[8] << 8 | (int32_t)p[9];
dpv_pul_width = (uint32_t)p[10] << 24 | (uint32_t)p[11] << 16 | (uint32_t)p[12] << 8 | (uint32_t)p[13];
dpv_increment = (int32_t)p[14] << 8 | (int32_t)p[15];
} else if (p[3] == PARA_3) {
dpv_step_time = (uint32_t)p[4] << 24 | (uint32_t)p[5] << 16 | (uint32_t)p[6] << 8 | (uint32_t)p[7];
dpv_notify_rate = (uint32_t)p[8] << 8 | (uint32_t)p[9];
dpv_curr_rec_percent_min[0] = (uint32_t)p[10];
dpv_curr_rec_percent_max[0] = (uint32_t)p[11];
dpv_curr_rec_percent_min[1] = (uint32_t)p[10];
dpv_curr_rec_percent_max[1] = (uint32_t)p[11];
} else if (p[3] == PARA_4) {
dpv_e_1 = (int32_t)p[4] << 8 | (int32_t)p[5];
dpv_e_2 = (int32_t)p[6] << 8 | (int32_t)p[7];
dpv_invert_option = p[8];
dpv_cycle = (uint16_t)p[9] << 8 | (uint16_t)p[10];
} else if (p[3] == PARA_FINAL) {
dpv_e_init = UC_TO_5NV(dpv_e_init);
dpv_e_final = UC_TO_5NV(dpv_e_final);
dpv_amp = UC_TO_5NV(dpv_amp);
dpv_pul_width = dpv_pul_width * 10;
dpv_increment = UC_TO_5NV(dpv_increment);
dpv_increment = abs(dpv_increment);
dpv_step_time = dpv_step_time * 10;
dpv_notify_rate = 10000 / dpv_notify_rate * 10;
dpv_e_1 = UC_TO_5NV(dpv_e_1);
dpv_e_2 = UC_TO_5NV(dpv_e_2);
instru.v0 = dpv_e_init;
instru.v_stop = dpv_e_final;
instru.t_pulse[0] = dpv_step_time - dpv_pul_width;
instru.t_pulse[1] = dpv_pul_width;
instru.v_initial[0] = dpv_e_init;
instru.v_initial[1] = dpv_e_init + dpv_amp;
instru.v_step[0] = abs(dpv_increment);
instru.v_step[1] = abs(dpv_increment);
instru.notifyRate = dpv_notify_rate;
instru.v_slope[0] = 0; // 1234 = slop 1.234, same as scanrate
instru.v_slope[1] = 0; // 1234 = slop 1.234
instru.t_pulse_min[0] = dpv_curr_rec_percent_min[0];
instru.t_pulse_max[0] = dpv_curr_rec_percent_max[0];
instru.t_pulse_min[1] = dpv_curr_rec_percent_min[1];
instru.t_pulse_max[1] = dpv_curr_rec_percent_max[1];
instru.v_1 = dpv_e_1;
instru.v_2 = dpv_e_2;
instru.cycleNumber = dpv_cycle;
if (dpv_invert_option == 1) {
instru.v_invert_option = true;
} else {
instru.v_invert_option = false;
}
if (instru.v0 > dpv_e_1) {
instru.directionInit = 0;//0:reverse 1:forward
instru.v_step[0] = (-1) * instru.v_step[0];
instru.v_step[1] = (-1) * instru.v_step[1];
} else if (instru.v0 < dpv_e_1) {
instru.directionInit = 1;
}
if (dpv_e_1 > dpv_e_2) {
instru.v_up = dpv_e_1;
instru.v_low = dpv_e_2;
instru.v_stop_direction = 1;//0:reverse 1:forward
} else if (dpv_e_1 < dpv_e_2) {
instru.v_up = dpv_e_2;
instru.v_low = dpv_e_1;
instru.v_stop_direction = 0;//0:reverse 1:forward
}
if (dpv_option == 1) {
instru.eliteFxn = CURVE_DPV_ADVANCE;
} else if (dpv_option == 2) {
instru.eliteFxn = CURVE_DPV_ADVANCE_SMPRATE;
}
instru.VoutGainLv = VOUT_GAIN_240K;
ModeLED(WORKING);
}
break;
}
case SET_PARA: {
int32_t value;
if (instru.eliteFxn == CURVE_VO) {
switch (p[3]) {
case DAC_VOLT:
value = (p[4] << 8) | p[5]; // usercode
if (value < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && value > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
instru.VoutGainLv = VOUT_GAIN_15K;
} else {
instru.VoutGainLv = VOUT_GAIN_240K;
}
VoutGainControl(instru.VoutGainLv);
value = (value - 25000) * 4 * 10000; //[5nV]
set_para(instru.eliteFxn, DAC_VOLT, value);
break;
default:
break;
}
} else if (instru.eliteFxn == CURVE_IT) {
switch (p[3]) {
case DAC_VOLT:
value = (p[4] << 8) | p[5]; // usercode
if (value < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && value > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
instru.VoutGainLv = VOUT_GAIN_15K;
} else {
instru.VoutGainLv = VOUT_GAIN_240K;
}
VoutGainControl(instru.VoutGainLv);
value = (value - 25000) * 4 * 10000; //[5nV]
set_para(instru.eliteFxn, DAC_VOLT, value);
break;
default:
break;
}
} else if (instru.eliteFxn == CURVE_RT) {
switch (p[3]) {
case DAC_VOLT:
value = (p[4] << 8) | p[5]; // usercode
if (value < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && value > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE) {
instru.VoutGainLv = VOUT_GAIN_15K;
} else {
instru.VoutGainLv = VOUT_GAIN_240K;
}
VoutGainControl(instru.VoutGainLv);
value = (value - 25000) * 4 * 10000; //[5nV]
set_para(instru.eliteFxn, DAC_VOLT, value);
break;
default:
break;
}
}
break;
}
case MODE_DEV_TOOL: { // 0x3000FF
mode_dev_tool(p);
break;
}
default: {
/** **/
break;
}
}
}
static void ins_decode_vis(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
uint8_t oper = p[1]; // this is don't care in RIS
switch (oper) {
// reset all variables ( Ins = 0xC0F0)
case VIS_RST: {
instru.eliteFxn = VIS_RST;
reset();
break;
}
case VIS_ASK: {
not_buf[0] = BLE_DAT_BUFF_SIZE - 1; //data len
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++) {
not_buf[i] = i;
}
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
break;
}
case VIS_STI: {
for(int i = 0; i < 12; i++) {
FlushNotify();
}
PeriodicEvent = true;
InitPeriodicEvent = true; // need to create a WorkModeData?
mode_init = true;
InitGPT();
break;
}
case VIS_FUH: {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_RED);
break;
}
case VIS_INT: {
Eliteinterrupt();
for (int i = 0; i < 12; i++) {
FlushNotify();
}
break;
}
case VIS_DEVICE_SHINY: {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_MAGENTA);
break;
}
case VIS_SHINY_DIS: {
if (PeriodicEvent) {
WORKLED();
} else if (!PeriodicEvent) {
checkFlafLED();
}
break;
}
case VIS_CC_ZERO: {
instru.eliteFxn = CURVE_OCP;
instru.notifyRate = 500;
if (instru.notifyRate > 1000) {
// slow notify rate, < 10sps, auto gain changer only use ADC gain level = 1.2.3.4
instru.gain_switch_on = 0b11110000;
} else {
// fast notify rate, >= 10sps, auto gain changer only use ADC gain level = 1.2.3
instru.gain_switch_on = 0b01110000;
}
ModeLED(PRE_WORK);
break;
}
default: {
break;
}
}
}
static void ins_decode_cis(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
uint8_t oper = p[1]; // this is don't care in RIS
switch (oper) {
case CIS_VERSION: {
initCISBuf();
cis_buf[0] = 6; //data len
cis_buf[1] = CIS_VERSION;
cis_buf[2] = VERSION_DATE_YEAR;
cis_buf[3] = VERSION_DATE_MONTH;
cis_buf[4] = VERSION_DATE_DAY;
cis_buf[5] = VERSION_DATE_HOUR;
cis_buf[6] = VERSION_DATE_MINUTE;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
case CIS_VOLT: {
// uint32_t bat = headstage_battery_volt();
// initCISBuf();
// cis_buf[0] = 5; //data len
// cis_buf[1] = CIS_VOLT;
// memcpy(&cis_buf[2], (uint8_t *)&bat, sizeof(bat));
// SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
case CIS_TEMPERATURE: { //0x7080
int32_t t = headstage_temperature();
initCISBuf();
cis_buf[0] = 5; //data len
cis_buf[1] = CIS_TEMPERATURE;
memcpy(&cis_buf[2], (uint8_t *)&t, sizeof(t));
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
}
}
@@ -0,0 +1,69 @@
#ifndef MODE_CA_H
#define MODE_CA_H
#ifdef __cplusplus
extern "C" {
#endif
static void decode_ca_mode(uint8 *ins)
{
instru.eliteFxn = CURVE_CA;
instru.Vinit = (int32_t)ins[3] << 8 | (int32_t)ins[4]; //37500
instru.notifyRate = (uint32_t)ins[7] << 8 | (uint32_t)ins[8]; //1000
instru.notifyRate = 10000 / instru.notifyRate * 10; //100
instru.VsetRate = VsetRateTable[0]; //2
//instru.hign_z_en = ins[6] & 0x0F;
//instru.VoutGainLv = VOUT_GAIN_240K;
setEIS_CV();
ModeLED(WORKING);
return;
}
static void ca_vscan(void)
{
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
if(vscanReset){
instru.Vset = ca->_Vinit;
}
if(!vscanReset){
instru.Vset = ca->_Vinit;
}
return;
}
static void CA_Plot(void)
{
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
static uint8_t ADC_cnt = 0;
void *wm = wm_get();
if (ADC_cnt == 0) {
LPTIA_change_gain();
ADC_cnt++;
} else if (ADC_cnt == 1) {
read_LPTIA_Iin();
ADC_cnt = 0;
}
return;
}
static void set_ca_volt(uint8 *ins)
{
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
instru.Vinit = (int32_t)ins[4] << 8 | (int32_t)ins[5]; //37500
ca->_Vinit = (instru.Vinit - 25000) * 4 * 4000; //[5nV]
}
#ifdef __cplusplus
}
#endif
#endif // TIMERS_H
@@ -0,0 +1,156 @@
/***
DC Volt 0 mv
AC Amp 100 mv
Freq 200000Hz~0.1Hz
Points per decades 10 points
Point spacing Logarithm
Delay 0 points
Average 2
Current range Auto
[CC2650] att_write 360CD10100CB7355000000070000
[CC2650] att_write 360BD10261A801000004000A00
***/
#define DECODE_INS_1 0x01
#define DECODE_INS_2 0x02
#define DECODE_INS_MODE 0xFF
static void decode_cf_mode(uint8_t *instruction)
{
uint8_t *ins = instruction;
uint8_t ins_step = ins[3];
if (ins_step == DECODE_INS_1) {
instru.f1 = (uint32_t)ins[4] << 24 | (uint32_t)ins[5] << 16 | (uint32_t)ins[6] << 8 | (uint32_t)ins[7]; //FREQ_START //13333333
instru.delay = (uint16_t)ins[12] << 8 | (uint16_t)ins[13]; //DELAY/10 how many periods //0
return;
}
if (ins_step == DECODE_INS_2) {
instru.dcbias = (uint16_t)ins[4] << 8 | (uint16_t)ins[5]; //25000
instru.acamp = (uint16_t)ins[6] << 8 | (uint16_t)ins[7]; //256
instru.avgnum = (uint8_t)ins[8]; //0
instru.gain_lv_hstia = (uint8_t)ins[9]; //4 = HSRTIA_200R //0
return;
}
if (ins_step == DECODE_INS_MODE) {
instru.eliteFxn = CURVE_CF;
set_hs_only();
if (instru.gain_lv_hstia < HSRTIA_MAX) {
instru.HSTIAAutoGainEnable = 0;
HSTIAGainCtrl(instru.gain_lv_hstia);
} else {
instru.HSTIAAutoGainEnable = 1;
instru.gain_lv_hstia = HSRTIA_200R;
HSTIAGainCtrl(instru.gain_lv_hstia);
}
HSDAC_outputV(instru.dcbias);
AD5940_SPIWriteReg(WGFCW, instru.fset);
AD5940_SPIWriteReg(WGCON, 0x0); // 0x0: DC disable ac first
AD5940_SPIWriteReg(WGAMPLITUDE, instru.acamp);
AD5940_SPIWriteReg(WGCON, 0x00000004); //0x4: Sinusoid
ModeLED(WORKING);
return;
}
return;
}
static void cf_fscan(void)
{
struct wm_cf_ctx_t *cf = (struct wm_cf_ctx_t *)wm_get();
if (vscanReset) {
cf->_in_reset_flag = true;
cf->_f1 = User2Freq(cf->_f1);
instru.fset = cf->_f1;
vscanReset = false;
SetWGAmp(instru.acamp,instru.fset);
DAC_outputF(Freq2DAC(instru.fset)); //[10mHz->Reg's]
}
if (!vscanReset) {
instru.fset = cf->_f1;
}
SetSamplingTime(instru.fset);
instru.sampleRate = 2000;
}
static void CF_Plot(void) //real and imag impedance plot
{
static uint8_t avgNumTable[4] = {2, 4, 6, 8};
struct wm_cf_ctx_t *cf = (struct wm_cf_ctx_t *)wm_get();
static uint8_t ADC_cnt = 0;
static int32_t realSum, imagSum = 0;
int32_t avg_real, avg_imag = 0;
static uint8_t avg_count = 0;
void *wm = wm_get();
if (fout_flag){
EnDFTnADC(1);
instru.sampleRate = CalcDelayTime(instru.fset);
fout_flag = false;
if (cf->_in_reset_flag) {
avg_count = 0;
realSum = 0;
imagSum = 0;
ADC_cnt = 0;
cf->_in_reset_flag = false;
}
} else {
if (ADC_cnt == 0){
HSTIA_change_gain(); // ADC measure
if (gainChange_flag) {
gainChange_flag = false;
instru.sampleRate = CalcDelayTime(instru.fset);
instru.real = 0;
instru.imag = 0;
ADC_cnt = 0;
} else {
instru.sampleRate = 15;
ADC_cnt ++;
}
}
else if (ADC_cnt == 1) {
realSum += instru.real;
imagSum += instru.imag;
avg_count++;
instru.sampleRate = 15;
if (avg_count == avgNumTable[instru.avgnum]){
avg_real = realSum / avg_count;
avg_imag = imagSum / avg_count;
InputNotify(NOTIFY_CURRENT, avg_imag);
InputNotify(NOTIFY_VOLT, avg_real);
InputNotify(NOTIFY_IMPEDANCE, instru.fset);
NotifyCh4 = (uint32_t)cf->_amp * 1000 * 800 / 2047; //[uV]
EnDFTnADC(0);
avg_count = 0;
realSum = 0;
imagSum = 0;
notify_flag = true;
}
ADC_cnt = 0;
}
}
return;
}
@@ -0,0 +1,175 @@
static void step2VsetRate(uint32_t step){
/*step = 100 mv, index = 0, n = 2
10 mv, index = 1, n = 10
1 mv, index = 2, n = 100
0.1 mv, index = 3, n = 1000
0.01mv, index = 4, n = 10000 */
if(step >= 10000){
instru.VsetRateIndex = 0;
}else if (step >= 1000){
instru.VsetRateIndex = 1;
}else if (step >= 100){
instru.VsetRateIndex = 2;
}else if (step >= 10){
instru.VsetRateIndex = 3;
}else if (step >= 1){
instru.VsetRateIndex = 4;
}
}
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
static void decode_cv_mode(uint8 *ins)
{
if (ins[3] == PARA_1) {
instru.Vinit = (int32_t)ins[4] << 8 | (int32_t)ins[5];
instru.Ve1 = (uint16_t)ins[6] << 8 | (uint16_t)ins[7];
instru.Ve2 = (uint16_t)ins[8] << 8 | (uint16_t)ins[9];
instru.Vmax = (int32_t)VMAX(instru.Ve1,instru.Ve2);
instru.Vmin = (int32_t)VMIN(instru.Ve1,instru.Ve2);
if (instru.Vinit > instru.Ve1 || instru.Vinit == instru.Vmax){
instru.directionInit = 0;//0:reverse 1:forward
} else if (instru.Vinit <= instru.Ve1 || instru.Vinit == instru.Vmin){
instru.directionInit = 1;
}
} else if (ins[3] == PARA_2) {
instru.eliteFxn = CURVE_CV;
instru.notifyRate = (uint32_t)ins[8] << 8 | (uint32_t)ins[9];
instru.notifyRate = 10000 / instru.notifyRate * 10;
//controller UI 0.01~1000mv send to Elite 1~100000
instru.step = (uint32_t)ins[4] << 24 | (uint32_t)ins[5] << 16 | (uint32_t)ins[6] << 8 | (uint32_t)ins[7];
STEP_TO_VSETRATE(instru.step); //step2VsetRate
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
instru.cycleNumber = (uint16_t)ins[10] << 8 | (uint16_t)ins[11];
setEIS_CV();
ModeLED(WORKING);
}
return;
}
static void cv_vscan(void)
{
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
static bool VminCounter;
static bool VmaxCounter;
NotifyCycleNumber = (instru.cycleNumber - cv->_cycleNumber + 1);
if (vscanReset) {
VmaxCounter = false;
VminCounter = false;
if (instru.directionInit == 1) {
cv->_direction_up = true;
cv->_current_direction_up = true;
} else {
cv->_direction_up = false;
cv->_current_direction_up = false;
}
// Vstep = x * 20 * N, x=xmV ; N=VscanRate Vstep unit [5nV]/[0.1ms]
if (instru.step <= 10) {
cv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
cv->_Vstep = instru.step / 5 * instru.VsetRate;
}
if (cv->_Vmin == cv->_Vinit) {
VminCounter = true;
}
if (cv->_Vmax == cv->_Vinit) {
VmaxCounter = true;
}
instru.Vset = cv->_Vinit;
}
if (!vscanReset) {
if ((instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) ||
(instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2)
) {
if (cv->_current_direction_up) {
instru.Vset += cv->_Vstep; //* GPT.GptimerMultiple;
} else {
instru.Vset -= cv->_Vstep; //* GPT.GptimerMultiple;
}
if (instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) {
if (instru.Vset == cv->_Vmin) {
VminCounter = true;
instru.Vinit = instru.Vmin;
cv->_Vinit = cv->_Vmin;
}
} else if (instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2) {
if (instru.Vset == cv->_Vmax) {
VmaxCounter = true;
instru.Vinit = instru.Vmax;
cv->_Vinit = cv->_Vmax;
}
}
} else {
if (instru.Vset >= cv->_Vmax) {
VmaxCounter = true;
} else if (instru.Vset <= cv->_Vmin) {
VminCounter = true;
}
if (cv->_current_direction_up) {
instru.Vset += cv->_Vstep;// * GPT.GptimerMultiple;
} else {
instru.Vset -= cv->_Vstep;// * GPT.GptimerMultiple;
}
if (VmaxCounter && VminCounter) {
if (cv->_direction_up && cv->_current_direction_up) {
if (instru.Vset >= cv->_Vinit) {
cv->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
if (!cv->_direction_up && !cv->_current_direction_up) {
if (instru.Vset <= cv->_Vinit) {
cv->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
}
if (instru.Vset >= cv->_Vmax) {
cv->_current_direction_up = false;
} else if (instru.Vset <= cv->_Vmin) {
cv->_current_direction_up = true;
}
/*stop condition*/
if (cv->_cycleNumber == 0) {
PeriodicEvent = false;
}
}
}
}
static void CV_Plot(void)
{
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
static uint8_t ADC_cnt = 0;
void *wm = wm_get();
if (ADC_cnt == 0) {
LPTIA_change_gain();
ADC_cnt++;
} else if (ADC_cnt == 1) {
read_LPTIA_Iin();
ADC_cnt = 0;
}
return;
}
@@ -1,396 +0,0 @@
#include "HAL/cc2650_driver/i2c_ctrl.h"
#include "HAL/MAX5136x2.h"
/*
* MODE_DEV_TOOL 0xFF
* DEV_TOOL_VERSION [34 LL FF 01]
*
* DEV_TOOL_BAT [34 LL FF 02]
*
* DEV_TOOL_TEMP [34 LL FF 03]
*
* DEV_TOOL_LED [34 LL FF 04]
* DEV_LED_LIMIT_COLOR [00 NN]
* DEV_LED_DARK_COLOR [01 RR GG BB]
* DEV_LED_LIGHT_COLOR [02 RR GG BB]
* DEV_LED_RAINBOW [03]
*
* DEV_TOOL_SPI [34 LL FF 20 pp RR WW ss ss ss ...]
* DT_CHIP_ADC pp = [00]
* DT_CHIP_DAC pp = [01]
* DT_CHIP_MEM pp = [02]
* DT_CHIP_SWITCH pp = [03]
*
* DEV_TOOL_I2C [34 LL FF 28 qq RR WW ss ss ss ...]
*
* DEV_TOOL_GPIO_EDC20_ADC_CH [34 LL FF 31 cc]
* cc = 07 => all open
* cc = 04 => open A2
* cc = 02 => open A1
* cc = 01 => open A0
*
*/
enum dev_tool_para_e {
DEV_TOOL_VERSION = 0x01,
DEV_TOOL_BAT = 0x02,
DEV_TOOL_TEMP = 0x03,
DEV_TOOL_LED = 0x04,
DEV_TOOL_SPI = 0x20,
DEV_TOOL_I2C = 0x28,
DEV_TOOL_GPIO_EDC20_ADC_CH = 0x31,
DEV_TOOL_MCP23008_PB = 0x32,
DEV_TOOL_MCP23008_PA = 0x33,
DEV_TOOL_MCP23008_RD = 0x34,
DEV_TOOL_OUT0_WRITE_THROUGH = 0x50,
DEV_TOOL_SWITCH_SELECT = 0x60,
};
enum dev_tool_chip_e {
DT_CHIP_ADC = 0,
DT_CHIP_DAC,
DT_CHIP_MEM,
DT_CHIP_SWITCH,
DT_OPEN_SPI1 = 0x11,
DT_CHIP_MAX,
};
enum dev_led_item_e {
DEV_LED_LIMIT_COLOR = 0,
DEV_LED_DARK_COLOR,
DEV_LED_LIGHT_COLOR,
DEV_LED_RAINBOW,
DEV_LED_MAX,
};
static void dev_tool_version()
{
initCISBuf();
cis_buf[0] = 6; //data len
cis_buf[1] = DEV_TOOL_VERSION;
cis_buf[2] = VERSION_DATE_YEAR;
cis_buf[3] = VERSION_DATE_MONTH;
cis_buf[4] = VERSION_DATE_DAY;
cis_buf[5] = VERSION_DATE_HOUR;
cis_buf[6] = VERSION_DATE_MINUTE;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void dev_tool_battery()
{
uint32_t bat;
bat = headstage_battery_volt();
initCISBuf();
cis_buf[0] = 5; //data len
cis_buf[1] = DEV_TOOL_BAT;
memcpy(&cis_buf[2], (uint8_t *)&bat, sizeof(bat));
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void dev_tool_temp()
{
int32_t t;
t = headstage_temperature();
initCISBuf();
cis_buf[0] = 5; //data len
cis_buf[1] = DEV_TOOL_TEMP;
memcpy(&cis_buf[2], (uint8_t *)&t, sizeof(t));
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static int dev_tool_led(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
struct led_color_t led_c;
uint8_t led_item = p[4];
uint8_t c_num = p[5];
led_c.r = p[5];
led_c.g = p[6];
led_c.b = p[7];
if (led_item >= DEV_LED_MAX)
return -1;
if (led_item == DEV_LED_RAINBOW)
return led_rainbow(LED_BR_LV1);
if (led_item == DEV_LED_LIMIT_COLOR)
return led_color_set(LED_NB_MAX, LED_BR_LV1, (enum led_color_e)c_num);
if (led_item == DEV_LED_DARK_COLOR)
return led_color_code_set(LED_NB_MAX, LED_BR_LV1, &led_c);
if (led_item == DEV_LED_LIGHT_COLOR)
return led_color_code_set(LED_NB_MAX, LED_BR_LV8, &led_c);
return 0;
}
static void dev_tool_spi(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
uint8_t chip_sel = p[4];
//ADC、DAC、MEM、SWITCH
uint8_t rxlen = p[5];
uint8_t txlen = p[6];
uint8_t tx[250] = {0};
uint8_t rx[250] = {0};
//set spi config
uint8_t pol = p[5] >> 4;
uint8_t pha = p[5] & 0X0F;
if (chip_sel >= DT_CHIP_MAX)
return;
switch (chip_sel) {
case DT_CHIP_ADC:
pin_set(E_PIN_ADCCS, 0);
memcpy(tx, &p[7], txlen);
spi1_write(rx, tx, txlen);
pin_set(E_PIN_ADCCS, 1);
break;
case DT_CHIP_DAC:
pin_set(E_PIN_DACCS, 0);
memcpy(tx, &p[7], txlen);
spi1_write(rx, tx, txlen);
pin_set(E_PIN_DACCS, 1);
break;
case DT_CHIP_MEM:
pin_set(E_PIN_MEMCS, 0);
memcpy(tx, &p[7], txlen);
spi1_write(rx, tx, txlen);
pin_set(E_PIN_MEMCS, 1);
break;
case DT_CHIP_SWITCH:
pin_set(E_PIN_SWCSBB, 0);
memcpy(tx, &p[7], txlen);
spi1_write(rx, tx, txlen);
pin_set(E_PIN_SWCSBB, 1);
break;
case DT_OPEN_SPI1:
spi1_close();
spi1_open(SPI_CLK_4M, pol, pha);
break;
}
initCISBuf();
cis_buf[0] = rxlen + 1; //data len
cis_buf[1] = DEV_TOOL_SPI;
memcpy(&cis_buf[2], rx, rxlen);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void dev_tool_i2c(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
struct i2c_para_t i2c_send;
struct i2c_para_t *send = &i2c_send;
send->i2c_addr = p[4];
send->i2c_rxlen = p[5];
send->i2c_txlen = p[6];
memcpy(send->i2c_tx, &p[7], send->i2c_txlen);
i2c0_write(send);
initCISBuf();
cis_buf[0] = send->i2c_rxlen + 2; //data len
cis_buf[1] = DEV_TOOL_I2C;
memcpy(&cis_buf[2], send->i2c_rx, send->i2c_rxlen);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void dev_tool_gpio_edc20_adc_ch(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
uint8_t adc_selector = p[4];
adc_sel_set(adc_selector);
}
static void dev_tool_dac_write(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
dac_series_control_g[DAC_NB_0].dac0_enable = (p[4] & 0xf0) >> 4;
dac_series_control_g[DAC_NB_0].dac1_enable = (p[4] & 0x0f);
dac_series_control_g[DAC_NB_0].volts = (uint16_t) p[5] << 8 | (uint16_t) p[6];
dac_series_control_g[DAC_NB_1].dac0_enable = (p[7] & 0xf0) >> 4;
dac_series_control_g[DAC_NB_1].dac1_enable = (p[7] & 0x0f);
dac_series_control_g[DAC_NB_1].volts = (uint16_t) p[8] << 8 | (uint16_t) p[9];
dac_enable_all_output(dac_series_control_g);
}
static void dev_tool_dac_write_single(uint8_t *ins_buf) {
uint8_t *p = ins_buf;
uint8_t dac0_enable = (p[4] & 0xf0) >> 4;
uint8_t dac1_enable = (p[4] & 0x0f);
uint16_t volts = (uint16_t) p[5] << 8 | (uint16_t) p[6];
enum MAX5136_num_e dac_num = (enum MAX5136_num_e) p[7];
dac_enable_single_output(dac0_enable, dac1_enable, volts, dac_num);
}
static void dev_tool_switch_select(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
uint8_t switch_module_number = p[4];
uint8_t enable_type = p[5];
switch_ctrl(switch_module_number, enable_type);
}
static void dev_tool_mcp23008_pb(uint8_t *ins_buf) //3000FF32
{
uint8_t *p = ins_buf;
enum mcp23008_gpio_e pin_n = (enum mcp23008_gpio_e)p[4]; // 0x00~0x07: PBx
uint8_t register_n = p[5]; // 0x00:IODIR 0x09:GPIO
uint8_t _v = p[6]; // 0:low 1:hogh 0:output 1:input
uint8_t re_val = 0;
if (register_n == 9) { // gpio:high/low
chip_MCP23008_set(MCP23008_MODULE_U503, MCP23008_REG_GPIO, pin_n, _v);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U503, MCP23008_REG_GPIO);
} else if (register_n == 0) { // iodir:input-1/output-0
chip_MCP23008_set(MCP23008_MODULE_U503, MCP23008_REG_IODIR, pin_n, _v);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U503, MCP23008_REG_IODIR);
}
initCISBuf();
cis_buf[0] = 2; //data len
cis_buf[1] = DEV_TOOL_MCP23008_PB;
memcpy(&cis_buf[2], &re_val, 1);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void dev_tool_mcp23008_pa(uint8_t *ins_buf) //3000FF33
{
uint8_t *p = ins_buf;
enum mcp23008_gpio_e pin_n = (enum mcp23008_gpio_e)p[4]; // 0x00~0x07: PAx
uint8_t register_n = p[5]; // 0x00:IODIR 0x09:GPIO
uint8_t _v = p[6]; // 0:low 1:hogh 0:output 1:input
uint8_t re_val = 0;
if (register_n == 9) { // gpio:high/low
chip_MCP23008_set(MCP23008_MODULE_U505, MCP23008_REG_GPIO, pin_n, _v);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U505, MCP23008_REG_GPIO);
} else if (register_n == 0) { // iodir:input-1/output-0
chip_MCP23008_set(MCP23008_MODULE_U505, MCP23008_REG_IODIR, pin_n, _v);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U505, MCP23008_REG_IODIR);
}
initCISBuf();
cis_buf[0] = 2; //data len
cis_buf[1] = DEV_TOOL_MCP23008_PA;
memcpy(&cis_buf[2], &re_val, 1);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void dev_tool_mcp23008_rd(uint8_t *ins_buf) //3000FF34
{
uint8_t *p = ins_buf;
uint8_t register_n = p[4]; // 0x00:IODIR 0x09:GPIO
uint8_t re_val = 0;
initCISBuf();
cis_buf[0] = 5; //data len
cis_buf[1] = DEV_TOOL_MCP23008_RD;
if (register_n == 9) { // gpio:high/low
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U505, MCP23008_REG_GPIO);
memcpy(&cis_buf[2], &re_val, 1);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U503, MCP23008_REG_GPIO);
memcpy(&cis_buf[3], &re_val, 1);
} else if (register_n == 0) { // iodir:input-1/output-0
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U505, MCP23008_REG_IODIR);
memcpy(&cis_buf[2], &re_val, 1);
re_val = chip_MCP23008_rd_reg_stat(MCP23008_MODULE_U503, MCP23008_REG_IODIR);
memcpy(&cis_buf[3], &re_val, 1);
}
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
}
static void mode_dev_tool(uint8_t *ins_buf)
{
uint8_t *p = ins_buf;
uint8_t dev_item = p[3];
switch (dev_item) {
case DEV_TOOL_VERSION:
dev_tool_version();
break;
case DEV_TOOL_BAT:
dev_tool_battery();
break;
case DEV_TOOL_TEMP:
dev_tool_temp();
break;
case DEV_TOOL_LED:
dev_tool_led(p);
break;
case DEV_TOOL_SPI:
dev_tool_spi(p);
break;
case DEV_TOOL_I2C:
dev_tool_i2c(p);
break;
case DEV_TOOL_GPIO_EDC20_ADC_CH:
dev_tool_gpio_edc20_adc_ch(p);
break;
case DEV_TOOL_OUT0_WRITE_THROUGH:
dev_tool_dac_write(p);
break;
case DEV_TOOL_SWITCH_SELECT:
dev_tool_switch_select(p);
break;
case DEV_TOOL_MCP23008_PB:
dev_tool_mcp23008_pb(p);
break;
case DEV_TOOL_MCP23008_PA:
dev_tool_mcp23008_pa(p);
break;
case DEV_TOOL_MCP23008_RD:
dev_tool_mcp23008_rd(p);
break;
default:
break;
}
return;
}
@@ -0,0 +1,314 @@
/***
DC Volt 0 mv
AC Amp 100 mv
Freq 200000Hz~0.1Hz
Points per decades 10 points
Point spacing Logarithm
Delay 0 points
Average 2
Current range Auto
[CC2650] att_write 360CD10100CB7355000000070000
[CC2650] att_write 360BD10261A801000004000A00
***/
#define DECODE_INS_1 0x01
#define DECODE_INS_2 0x02
#define DECODE_INS_MODE 0xFF
static void decode_eis_mode(uint8_t *instruction)
{
uint8_t *ins = instruction;
uint8_t ins_step = ins[3];
if (ins_step == DECODE_INS_1) {
instru.f1 = (uint32_t)ins[4] << 24 | (uint32_t)ins[5] << 16 | (uint32_t)ins[6] << 8 | (uint32_t)ins[7]; //FREQ_START //13333333
instru.f2 = (uint32_t)ins[8] << 24 | (uint32_t)ins[9] << 16 | (uint32_t)ins[10] << 8 | (uint32_t)ins[11]; //FREQ_STOP //7
//instru.sampleRate = 15;//CalcDelayTime(User2Freq(instru.f1), true); //ms //read
instru.fmax = (uint32_t)VMAX(instru.f1, instru.f2); //13333333
instru.fmin = (uint32_t)VMIN(instru.f1, instru.f2); //7
instru.delay = (uint16_t)ins[12] << 8 | (uint16_t)ins[13]; //DELAY/10 how many periods //0
if (instru.f1 > instru.f2)
instru.directionInit = 0; //0:reverse 1:forward //instru.directionInit = 0
else if (instru.f1 <= instru.f2)
instru.directionInit = 1;
return;
}
if (ins_step == DECODE_INS_2) {
instru.dcbias = (uint16_t)ins[4] << 8 | (uint16_t)ins[5]; //25000
instru.acamp = (uint16_t)ins[6] << 8 | (uint16_t)ins[7]; //256
instru.avgnum = (uint8_t)ins[8]; //0
instru.gain_lv_hstia = (uint8_t)ins[9]; //4 = HSRTIA_200R
instru.ppd = (uint16_t)ins[10] << 8 | (uint16_t)ins[11]; //10
instru.scale = (uint8_t)ins[12]; //0
return;
}
if (ins_step == DECODE_INS_MODE) {
instru.eliteFxn = CURVE_EIS;
set_hs_only();
if (instru.gain_lv_hstia < HSRTIA_MAX) {
instru.HSTIAAutoGainEnable = 0;
HSTIAGainCtrl(instru.gain_lv_hstia);
} else {
instru.HSTIAAutoGainEnable = 1;
instru.gain_lv_hstia = HSRTIA_200R;
HSTIAGainCtrl(instru.gain_lv_hstia);
}
HSDAC_outputV(instru.dcbias);
AD5940_SPIWriteReg(WGFCW, instru.fset);
AD5940_SPIWriteReg(WGCON, 0x0); // 0x0: DC disable ac first
AD5940_SPIWriteReg(WGAMPLITUDE, instru.acamp);
AD5940_SPIWriteReg(WGCON, 0x00000004); //0x4: Sinusoid
ModeLED(WORKING);
return;
}
return;
}
//////EIS PLOT RELATED FUNCTION START//////
static uint8_t CalcDecade(uint32_t f1, uint32_t f2)
{
uint8_t decades; //max is 7
decades = log10(f2/f1);
return decades;
}
static void eis_fscan(void)
{
struct wm_eis_ctx_t *eis = (struct wm_eis_ctx_t *)wm_get();
static uint16_t LogSpacingTable10[10] = {1000, 1292, 1668, 2154, 2783, 3594, 4642, 5995, 7743, 10000};
static uint16_t LogSpacingTable9[9] = {1000, 1334, 1778, 2371, 3162, 4217, 5623, 7499, 10000};
static uint16_t LogSpacingTable8[8] = {1000, 1389, 1931, 2683, 3728, 5179, 7197, 10000};
static uint16_t LogSpacingTable7[7] = {1000, 1468, 2154, 3162, 4642, 6813, 10000};
static uint16_t LogSpacingTable6[6] = {1000, 1585, 2512, 3981, 6310, 10000};
static uint16_t LogSpacingTable5[5] = {1000, 1778, 3162, 5623, 10000};
static uint16_t LogSpacingTable4[4] = {1000, 2154, 4642, 10000};
static uint16_t LogSpacingTable3[3] = {1000, 3162, 10000};
static uint16_t LogSpacingTable2[2] = {1000, 10000};
static uint32_t TenPowerTable[9] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
if (vscanReset) {
eis->_in_reset_flag = true;
eis->_f1 = User2Freq(eis->_f1);
eis->_f2 = User2Freq(eis->_f2);
eis->_fmax = User2Freq(eis->_fmax);
eis->_fmin = User2Freq(eis->_fmin);
if (instru.directionInit == 1) {
eis->_direction_up = true;
} else if (instru.directionInit == 0) {
eis->_direction_up = false;
}
eis->_decades = CalcDecade(instru.fmin, instru.fmax);
instru.fset = eis->_f1;
vscanReset = false;
}
if (!vscanReset) {
if(eis->_direction_up) {
if(eis->_sweepIndex == 0){
if(eis->_decadeIndex < eis->_decades) {
eis->_fd1 = eis->_f1 * TenPowerTable[eis->_decadeIndex];
eis->_fd2 = eis->_f1 * TenPowerTable[eis->_decadeIndex + 1];
} else if (eis->_decadeIndex == eis->_decades) {
eis->_fd1 = eis->_fd2;//eis->_f1 * TenPowerTable[decadeIndex];
eis->_fd2 = eis->_fmax;
}
}
if(eis->_decadeIndex != 0 && eis->_sweepIndex == 0){
eis->_sweepIndex++;
}
if(instru.scale == 0) { // logarithm
if (eis->_ppd == 10) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable10[eis->_sweepIndex] + 500)/ 1000;
}
else if (eis->_ppd == 9){
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable9[eis->_sweepIndex] + 500)/ 1000;
}
else if (eis->_ppd == 8) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable8[eis->_sweepIndex] + 500)/ 1000;
}
else if (eis->_ppd == 7) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable7[eis->_sweepIndex] + 500)/ 1000;
}
else if (eis->_ppd == 6) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable6[eis->_sweepIndex] + 500)/ 1000;
}
else if (eis->_ppd == 5) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable5[eis->_sweepIndex] + 500)/ 1000;
}
else if (eis->_ppd == 4) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable4[eis->_sweepIndex] + 500)/ 1000;
}
else if (eis->_ppd == 3) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable3[eis->_sweepIndex] + 500)/ 1000;
}
else if (eis->_ppd == 2) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable2[eis->_sweepIndex] + 500)/ 1000;
}
}
else if (instru.scale == 1) { // linear
instru.fset = eis->_fd1 + eis->_sweepIndex * ((eis->_fd2 - eis->_fd1) / (eis->_ppd - 1));
}
if(instru.fset > eis->_fmax){
instru.fset = eis->_fmax;
}
} else { //reverse
if(eis->_sweepIndex == 0){
if(eis->_decadeIndex < eis->_decades){
eis->_fd1 = eis->_f1 / TenPowerTable[eis->_decadeIndex];
eis->_fd2 = eis->_f1 / TenPowerTable[eis->_decadeIndex + 1];
} else if (eis->_decadeIndex == eis->_decades){
eis->_fd1 = eis->_fd2; //eis->_f1 / TenPowerTable[eis->_decadeIndex];
eis->_fd2 = eis->_fmin;
}
}
if(eis->_decadeIndex != 0 && eis->_sweepIndex == 0){
eis->_sweepIndex++;
}
if(instru.scale == 0) { // logarithm
if (eis->_ppd == 10) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable10[9 - eis->_sweepIndex] + 5000)/ 10000;
}
else if (eis->_ppd == 9) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable9[8 - eis->_sweepIndex] + 5000)/ 10000;
}
else if (eis->_ppd == 8) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable8[7 - eis->_sweepIndex] + 5000)/ 10000;
}
else if (eis->_ppd == 7) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable7[6 - eis->_sweepIndex] + 5000)/ 10000;
}
else if (eis->_ppd == 6) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable6[5 - eis->_sweepIndex] + 5000)/ 10000;
}
else if (eis->_ppd == 5) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable5[4 - eis->_sweepIndex] + 5000)/ 10000;
}
else if (eis->_ppd == 4) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable4[3 - eis->_sweepIndex] + 5000)/ 10000;
}
else if (eis->_ppd == 3) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable3[2 - eis->_sweepIndex] + 5000)/ 10000;
}
else if (eis->_ppd == 2) {
instru.fset = ((uint64_t)eis->_fd1 * LogSpacingTable2[1 - eis->_sweepIndex] + 5000)/ 10000;
}
}
else if(instru.scale == 1) { // linear
instru.fset = eis->_fd1 - eis->_sweepIndex * ((eis->_fd1 - eis->_fd2) / (eis->_ppd - 1));
}
if(instru.fset < eis->_fmin){
instru.fset = eis->_fmin;
}
}
if (!gainChange_flag) {
if (++eis->_sweepIndex == eis->_ppd) {
eis->_sweepIndex = 0;
eis->_decadeIndex ++;
}
}
}
SetSamplingTime(instru.fset);
instru.sampleRate = 2000;
}
static void EIS_Plot(void) //real and imag impedance plot
{
static uint8_t avgNumTable[4] = {2, 4, 6, 8};
struct wm_eis_ctx_t *eis = (struct wm_eis_ctx_t *)wm_get();
static uint8_t ADC_cnt = 0;
static int32_t realSum, imagSum = 0;
int32_t avg_real, avg_imag = 0;
static uint8_t avg_count = 0;
void *wm = wm_get();
if (fout_flag){
SetWGAmp(instru.acamp,instru.fset);
DAC_outputF(Freq2DAC(instru.fset)); //[10mHz->Reg's]
EnDFTnADC(1);
instru.sampleRate = CalcDelayTime(instru.fset);
fout_flag = false;
if (eis->_in_reset_flag) {
avg_count = 0;
realSum = 0;
imagSum = 0;
ADC_cnt = 0;
eis->_in_reset_flag = false;
}
} else {
if (ADC_cnt == 0){
HSTIA_change_gain(); // ADC measure
if (gainChange_flag) {
gainChange_flag = false;
instru.sampleRate = CalcDelayTime(instru.fset);
instru.real = 0;
instru.imag = 0;
ADC_cnt = 0;
} else {
instru.sampleRate = 15;
ADC_cnt ++;
}
}
else if (ADC_cnt == 1) {
realSum += instru.real;
imagSum += instru.imag;
avg_count++;
instru.sampleRate = 15;
if (avg_count == avgNumTable[instru.avgnum]){
avg_real = realSum / avg_count;
avg_imag = imagSum / avg_count;
InputNotify(NOTIFY_CURRENT, avg_imag);
InputNotify(NOTIFY_VOLT, avg_real);
InputNotify(NOTIFY_IMPEDANCE, instru.fset);
NotifyCh4 = (uint32_t)eis->_amp * 1000 * 800 / 2047; //[uV]
if(eis->_direction_up){
if (instru.fset >= eis->_fmax) {
PeriodicEvent = false;
finishMode = 1;
}
} else {
if (instru.fset <= eis->_fmin) {
PeriodicEvent = false;
finishMode = 1;
}
}
EnDFTnADC(0);
avg_count = 0;
realSum = 0;
imagSum = 0;
notify_flag = true;
}
ADC_cnt = 0;
}
}
return;
}
@@ -0,0 +1,78 @@
static void decode_rt_mode(uint8 *ins)
{
instru.eliteFxn = CURVE_RT;
instru.notifyRate = (uint32_t)ins[7] << 8 | (uint32_t)ins[8];
instru.notifyRate = 10000 / instru.notifyRate * 10;
// instru.notifyRate = 100;
// instru.measure_vin_range = ins[7];
// instru.measure_vin_range = 0;
setEIS_CV();
instru.Vinit = (uint32_t)ins[3] << 8 | (uint32_t)ins[4];
ModeLED(WORKING);
return;
}
static void CalcuResistance(int32_t Iin)
{
/* Elite 100000 = 100R
Elite 1000000 = 1KR
Elite 10000000 = 10KR
Elite 100000000 = 100KR
Elite 1000000000 = 1MR
*/
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
int64_t resist;
int64_t volt = instru.Vset / 200; // [uV]
int64_t current = Iin;
resist = volt * 1000000 / current; //R = V / Iin; [mOhm]
InputNotify(NOTIFY_IMPEDANCE, resist);
}
static void RT_Plot(void)
{
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
static uint8_t ADC_cnt = 0;
void *wm = wm_get();
if (ADC_cnt == 0) {
LPTIA_change_gain();
ADC_cnt++;
} else if (ADC_cnt == 1) {
int32_t Iin = read_LPTIA_Iin();
CalcuResistance(Iin);
ADC_cnt = 0;
}
return;
}
static void rt_vscan(void)
{
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
if(vscanReset){
instru.Vset = rt->_Vinit;
}
if(!vscanReset){
instru.Vset = rt->_Vinit;
}
return;
}
static void set_rt_volt(int32_t volt)
{
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
volt = (volt - 25000) * 4 * 4000;
rt->_Vinit = volt;
return;
}
@@ -0,0 +1,47 @@
static void decode_vt_mode(uint8 *ins)
{
instru.eliteFxn = CURVE_VT;
instru.notifyRate = (uint32_t)ins[5] << 8 | (uint32_t)ins[6];
instru.notifyRate = 10000 / instru.notifyRate * 10;
instru.measure_vin_range = ins[7];
setEIS_CV();
AD5940_SPIWriteReg(ADCCON, 0x0001080E); //PGA = 1.5 //VT
uint8_t z;
uint16_t b;
if (instru.measure_vin_range == 0) { //measure +volt
z = 0;
b = 0;
} else if (instru.measure_vin_range == 1) { //measure +-1V
z = 32;
b = 2048;
} else if (instru.measure_vin_range == 2) { //measure -volt
z = 62;
b = 3910;
}
set_lpdac_ce_1100mv(z, b);
disconnect_rtia();
ModeLED(WORKING);
return;
}
static void VT_Plot(void)
{
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
static uint8_t ADC_cnt = 0;
void *wm = wm_get();
if (ADC_cnt == 0) {
// LPTIA_change_gain();
ADC_cnt++;
} else if (ADC_cnt == 1) {
read_LPTIA_Vin();
ADC_cnt = 0;
}
return;
}
@@ -0,0 +1,33 @@
# $python .\simplelink\ble_sdk_2_02_02_25\src\examples\simple_peripheral\cc26xx\app\python\update_elite_version.py
import datetime
import os
print(datetime.datetime.now())
# print(datetime.datetime.now().year)
# print(datetime.datetime.now().month)
# print(datetime.datetime.now().day)
# print(datetime.datetime.now().hour)
# print(datetime.datetime.now().minute)
# print(datetime.datetime.now().strftime("%H:%M:%S"))
y = datetime.datetime.now().year % 100
m = datetime.datetime.now().month
d = datetime.datetime.now().day
hour = datetime.datetime.now().hour
minute = datetime.datetime.now().minute
path = os.getcwd()
path += '/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h'
print('save:', path)
with open(path, 'w') as f:
f.write('#ifndef VERSION_DATE\t\t' + '\n')
f.write('#define VERSION_DATE\t\t' + '\n\n')
f.write('#define VERSION_DATE_YEAR\t\t' + str(y) + '\n')
f.write('#define VERSION_DATE_MONTH\t\t' + str(m) + '\n')
f.write('#define VERSION_DATE_DAY\t\t' + str(d) + '\n')
f.write('#define VERSION_DATE_HOUR\t\t' + str(hour) + '\n')
f.write('#define VERSION_DATE_MINUTE\t\t' + str(minute) + '\n')
f.write('#endif' + '\n\n')
@@ -571,163 +571,38 @@ static void SimpleBLEPeripheral_init(void)
*/
}
#include "application/BAT_10_app.h"
#include "application_config/application_config.h"
#include "HAL/cc2650_driver/spi_ctrl.h"
#include "HAL/cc2650_driver/i2c_ctrl.h"
#include "HAL/APA102_2020_256_8x4.h"
#include "HAL/MCP23008x2.h"
#include "HAL/MAX5136x2.h"
#include "unfinished_code.h"
// buffer size
#define BLE_CIS_BUFF_CHAR SIMPLEPROFILE_CHAR2
#define BLE_INS_BUFF_CHAR SIMPLEPROFILE_CHAR3
#define BLE_DAT_BUFF_CHAR SIMPLEPROFILE_CHAR4
#define BLE_CIS_BUFF_SIZE SIMPLEPROFILE_CHAR2_LEN
#define BLE_INS_BUFF_SIZE SIMPLEPROFILE_CHAR3_LEN
#define BLE_DAT_BUFF_SIZE SIMPLEPROFILE_CHAR4_LEN
// define for futher convention usage
//
#define REVERT_2_BYTE(_b) ((_b) >> 8 | (((_b) & 0xFF) << 8))
#define ENABLE 1
#define DISABLE 0
//
#include "driver/spi_ctrl.h"
#include "hardware/led_APA_102.h"
#include "driver/timers.h"
#include "elite_task/elite_GPtimer.h"
#include "devinfoservice.h"
#include "gapgattserver.h"
#include "gattservapp.h"
#if (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
#include "driver/gpio_eis11.h"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
#include "driver/gpio_eis_mini10.h"
#endif
struct date_t {
uint8_t year;
uint8_t month;
uint8_t day;
};
struct device_info_t {
struct date_t date;
};
struct device_info_t device_info;
void get_date(struct date_t *date)
{
const char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
struct date_t *d = date;
char year_s[5] = {0};
char month_s[4] = {0};
char day_s[3] = {0};
int i;
char date_now[] = __DATE__;
memcpy(year_s, date_now + 9, 2);
memcpy(month_s, date_now, 3);
memcpy(day_s, date_now + 4, 2);
d->year = atoi(year_s);
d->day = atoi(day_s);
for (i=0; i<12; i++) {
if (!strcmp(month_s, months[i])) {
d->month = i + 1;
break;
}
}
return;
}
static void headstage_init_device_info() {
uint8_t scan_rsp_data[64] = {9};
uint8_t *p = scan_rsp_data;
struct device_info_t *dev = &device_info;
int i;
get_date(&device_info.date);
*p++ = sizeof(DEVICE_NAME); // 10
*p++ = GAP_ADTYPE_LOCAL_NAME_COMPLETE; // 09
for (i=0; i<sizeof(DEVICE_NAME)-1; i++) {
*p++ = DEVICE_NAME[i];
} // 69 108 105 116 101 45 69 73 83
*p++ = 16; // 16
*p++ = GAP_ADTYPE_MANUFACTURER_SPECIFIC; // 255
*p++ = 'B'; // 66
*p++ = 'P'; // 80
*p++ = 'H'; // 72
*p++ = 'S'; // 83
*p++ = MAJOR_PRODUCT_NUMBER; // 0
*p++ = MINOR_PRODUCT_NUMBER; // 4
*p++ = MAJOR_VERSION_NUMBER; // 1
*p++ = MINOR_VERSION_NUMBER; // 0
*p++ = dev->date.year; // 22
*p++ = dev->date.month; // 07
*p++ = 'B'; // 66
*p++ = 'A'; // 65
*p++ = 'T'; // 84
*p++ = (uint8_t)(NotifyVoltBat); // 44
*p++ = (uint8_t)(NotifyVoltBat >> 8); // 33
GGS_SetParameter(GGS_DEVICE_NAME_ATT, sizeof(DEVICE_NAME), DEVICE_NAME);
GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, p - scan_rsp_data, scan_rsp_data);
}
// #include "EliteGPTimer.h"
#include "hardware/chip_ad5940.h"
#include <Board.h>
#include <ti/drivers/timer/GPTimerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include <xdc/runtime/Types.h>
static GPTimerCC26XX_Handle gptimer_handle;
void elite_gptimer_task(void);
static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask);
#define elite_gptimer_start() GPTimerCC26XX_start(gptimer_handle)
#define elite_gptimer_stop() GPTimerCC26XX_stop(gptimer_handle)
#define elite_gptimer_close() GPTimerCC26XX_close(gptimer_handle)
#define CLOCK_FREQ 4769 // clock freq = 0.1 ms(4800), Measured(4769)
static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {
elite_gptimer_task();
return;
}
#define elite_gptimer_open() \
do { \
GPTimerCC26XX_Params params; \
GPTimerCC26XX_Params_init(&params); \
params.width = GPT_CONFIG_16BIT; \
params.mode = GPT_MODE_PERIODIC_UP; \
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF; \
gptimer_handle = GPTimerCC26XX_open(Board_GPTIMER0A, &params); \
Types_FreqHz freq; \
BIOS_getCpuFreq(&freq); \
GPTimerCC26XX_Value loadVal = freq.lo / 1000 - 1; /*47999*/ \
GPTimerCC26XX_setLoadValue(gptimer_handle, loadVal); \
GPTimerCC26XX_setLoadValue(gptimer_handle, CLOCK_FREQ); /* 0.1 ms*/ \
GPTimerCC26XX_registerInterrupt(gptimer_handle, elite_gptimer_callback, GPT_INT_TIMEOUT); \
} while (0)
struct gptimer0_t GPT;
#define TIMER_SEC(_v) (_v * 10000)
#define TIMER_mSEC(_v) (_v * 10)
static void key_manage(uint32_t delta_time)
{
uint32_t t = delta_time;
static uint32_t keyTimer = 0;
static bool byPass1sec = false;
if (!PUSH_KEY) {
if (keyTimer > 0) {
checkFlafLED();
byPass1sec = false;
}
keyTimer = 0;
return;
}
keyTimer = keyTimer + t;
if (keyTimer >= TIMER_SEC(3)){
chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P0, 0); //close 15V
chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P1, 1);
SET_VLOGIC_EN_GPIO(0);
chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P7, 1); //SET_SHUTDOWN_GPIO
} else if (keyTimer >= TIMER_SEC(1) && !byPass1sec) {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_ORANGE);
byPass1sec = true;
}
return;
}
void elite_gptimer_task(void)
{
@@ -736,39 +611,90 @@ void elite_gptimer_task(void)
GPT.cnt_gpt++;
}
#include "headstage.h"
#include "EliteWorkData.h"
static bool power_on(uint32_t delta_time)
{
{
uint32_t t = delta_time;
bool elite_on = false;
static uint32_t keyTimer = 0;
keyTimer = keyTimer + t;
if (keyTimer >= TIMER_SEC(1)) {
if (keyTimer >= 10000) {
pin_set(E_PIN_5V_ENABLE, 1);
chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_PIN_ALL, 0x22);
chip_MCP23008_set(MCP23008_PB, MCP23008_REG_IODIR, MCP23008_PIN_ALL, 0x58);
chip_MCP23008_set(MCP23008_PA, MCP23008_REG_GPIO, MCP23008_PIN_ALL, 0x74);
chip_MCP23008_set(MCP23008_PA, MCP23008_REG_IODIR, MCP23008_PIN_ALL, 0x00);
SET_VLOGIC_EN_GPIO(1);
SET_VLOGIC_EN_IODIR(P_OUTPUT);
CPUdelay_us(320); // need delay 320us to stablize power
ModeLED(BT_WAIT);
SET_SW_EN_GPIO(0);
chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P0, 1);
chip_MCP23008_set(MCP23008_PB, MCP23008_REG_GPIO, MCP23008_P1, 0);
//chip_MCP23008_set(MCP23008_PA, MCP23008_REG_GPIO, MCP23008_P2, 0); // bat0.1 need
chip_MCP23008_set(MCP23008_PA, MCP23008_REG_GPIO, MCP23008_P2, 0);
keyTimer = 0;
AD5940_Initialize();
// headstage_battery_volt();
headstage_init_device_info();
elite_on = true;
}
return elite_on;
}
/*return the button status*/
uint8_t pin_button_get(void)
{
/*
* if btn = 0: press key
* if btn = 1: release key
*/
uint8_t btn;
btn = PIN_getInputValue(E_PIN_SHUT_DOWN);
return btn;
}
/* manage the button control*/
static void key_manage(uint32_t delta_time)
{
uint32_t t = delta_time;
static uint32_t keyTimer = 0;
static bool byPass1sec = false;
if (pin_button_get()!=0) {
if (keyTimer > 0) {
checkFlafLED();
byPass1sec = false;
}
keyTimer = 0;
return;
}
keyTimer = keyTimer + t;
if (keyTimer >= 30000){
pin_set(E_PIN_5V_ENABLE, 0);
} else if (keyTimer >= 10000 && !byPass1sec) {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_ORANGE);
byPass1sec = true;
}
return;
}
static void device_init(void)
{
gpio_create();
InitEliteInstruction();
Board_initSPI();
spi0_open(SPI_CLK_1M, POL0, PHA1); //SPI 1M: LED
spi1_open(SPI_CLK_4M, POL0, PHA0); //SPI 4M: AD5941
elite_gptimer_open();
InitGPT();
return;
}
/*********************************************************************
* @fn SimpleBLEPeripheral_taskFxn
*
@@ -780,43 +706,21 @@ static bool power_on(uint32_t delta_time)
*/
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
{
bool elite_on = false;
batteryADC_flag = false;
uint32_t check_key_time = 0;
// Initialize application
SimpleBLEPeripheral_init();
gpio_create();
device_init();
spi0_open(SPI_CLK_10M, POL0, PHA1); //10M // SPI0 = LED
spi1_open(SPI_CLK_10M, POL0, PHA1); //10M // SPI1 = ADC. DAC
i2c0_open(I2C_400K);
elite_gptimer_open();
elite_gptimer_start();
InitEliteInstruction();
// headstage_battery_volt();
headstage_init_device_info();
bool elite_on;
uint32_t check_key_time = 0;
InitGPT();
// power on elite
while(1) {
if (events & SBP_PERIODIC_EVT) {
events &= ~SBP_PERIODIC_EVT;
GPT.cnt_gpt_delta = GPT.cnt_gpt - GPT.cnt_gpt0;
GPT.cnt_gpt0 = GPT.cnt_gpt;
GPT_timerIncrement();
elite_on = power_on(GPT.cnt_gpt_delta);
}
if (elite_on)
break;
}
@@ -872,74 +776,34 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
}
}
if (events & SBP_PERIODIC_EVT) {
GPT_timerIncrement();
check_key_time = check_key_time + GPT.cnt_gpt_delta;
if (events & SBP_PERIODIC_EVT) {
events &= ~SBP_PERIODIC_EVT;
GPT.cnt_gpt_delta = GPT.cnt_gpt - GPT.cnt_gpt0;
GPT.cnt_gpt0 = GPT.cnt_gpt;
check_key_time = check_key_time + GPT.cnt_gpt_delta;
if (check_key_time >= TIMER_mSEC(20)) {
key_manage(TIMER_mSEC(20));
/* routinely check the button status*/
if (check_key_time >= 200) {
key_manage(check_key_time);
check_key_time = 0;
}
if (!PeriodicEvent) { // if there is no periodic event
if (Free_Work_Mode) {
wm_deinit();
InitEliteInstruction();
Free_Work_Mode = false;
}
} else { // if there is periodic event
if(InitPeriodicEvent){
wm_init();
InitPeriodicEvent = false;
}
//led_manage(GPT.cnt_gpt_delta);
// GPT.cnt_adc_rate = GPT.cnt_adc_rate + GPT.cnt_gpt_delta;
// if(GPT.cnt_adc_rate >= 10000){
// GPT.cnt_adc_rate = 0; //To get right data, ADC must be delay 1.5ms
// }
}
// if(events & SBP_PERIODIC_EVT){
// events &= ~SBP_PERIODIC_EVT;
// if (!PeriodicEvent) { // if there is no periodic event
// key = PIN_getInputValue(SHUT_DOWN);
// if (EliteOn) {
// if (counter6994 < CLOCK_ONE_SECOND*5) { // counter6994 enable a IC after 35 counts
// counter6994++;
// } else if (counter6994 == CLOCK_ONE_SECOND*5) {
// PIN15_setOutputValue(OFF, 0); // OFF = 1 => turn off 6994
// counter6994++;
// } else if (counter6994 > CLOCK_ONE_SECOND*5) {
// counter6994 = 0;
// }
// EliteKeyPress(key);
//
// GPT.cnt_gpt_delta = GPT.cnt_gpt - GPT.cnt_gpt0;
// GPT.cnt_gpt0 = GPT.cnt_gpt;
//
// GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.cnt_gpt_delta;
// GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.cnt_gpt_delta;
//
// if(key != 0){ //detect Elite battery power when no periodic event
// measureBat();
// }
// if(Free_Work_Mode){
// wm_deinit();
// InitEliteInstruction();
// Free_Work_Mode = false;
// }
// } else {
// EliteOn = TurnOnElite(key);
// }
// }
// else { // if there is periodic event
// if(InitPeriodicEvent){
// wm_init();
// InitPeriodicEvent = false;
// }
//
// // Perform periodic application task
// SimpleBLEPeripheral_performPeriodicTask();
// key = PIN_getInputValue(SHUT_DOWN);
// EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
// }
// }
// Perform periodic application task
SimpleBLEPeripheral_performPeriodicTask();
}
}
#ifdef FEATURE_OAD
while (!Queue_empty(hOadQ)) {
@@ -1499,10 +1363,14 @@ static void SimpleBLEPeripheral_enqueueMsg(uint8_t event, uint8_t state)
/*********************************************************************
*********************************************************************/
#include "application/BAT_10_app_c.h"
#include "HAL/cc2650_driver/spi_ctrl_c.h"
#include "HAL/cc2650_driver/i2c_ctrl_c.h"
#include "HAL/APA102_2020_256_8x4_c.h"
#include "HAL/MCP23008x2_c.h"
#include "HAL/MAX5136x2_c.h"
#include "HAL/ADGS1412x9_c.h"
#include "hardware/led_APA_102_c.h"
#include "driver/spi_ctrl_c.h"
#include "driver/timers_c.h"
#include "elite_task/elite_GPtimer_c.h"
#if (DEF_ELITE_MODEL == DEF_ELITE_EIS_11)
#include "driver/gpio_eis11_c.h"
#elif (DEF_ELITE_MODEL == DEF_ELITE_EIS_MINI_10)
#include "driver/gpio_eis_mini10_c.h"
#endif
#include "hardware/chip_ad5940_c.h"
@@ -9,7 +9,7 @@
Target Device: CC2650, CC2640
******************************************************************************
Copyright (c) 2010-2018, Texas Instruments Incorporated
All rights reserved.
@@ -135,7 +135,6 @@ static simpleProfileCBs_t *simpleProfile_AppCBs = NULL;
// Simple Profile Service attribute
static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE, simpleProfileServUUID };
// Simple Profile Characteristic 1 Properties
// static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE;
/*user insert*/
@@ -144,13 +143,12 @@ static uint8 simpleProfileChar1Props = GATT_PROP_READ;
// Characteristic 1 Value
// static uint8 simpleProfileChar1 = 0;
/*user insert*/
#define SIMPLEPROFILE_CHAR1_LEN 20
static uint8 simpleProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = {0};
// Simple Profile Characteristic 1 User Description
static uint8 simpleProfileChar1UserDesp[17] = "Characteristic 1";
// Simple Profile Characteristic 2 Properties
static uint8 simpleProfileChar2Props = GATT_PROP_READ;
@@ -159,11 +157,9 @@ static uint8 simpleProfileChar2Props = GATT_PROP_READ;
/*user insert*/
static uint8 simpleProfileChar2[SIMPLEPROFILE_CHAR2_LEN] = {0};
// Simple Profile Characteristic 2 User Description
static uint8 simpleProfileChar2UserDesp[17] = "Characteristic 2";
// Simple Profile Characteristic 3 Properties
static uint8 simpleProfileChar3Props = GATT_PROP_WRITE;
@@ -172,11 +168,9 @@ static uint8 simpleProfileChar3Props = GATT_PROP_WRITE;
/*user insert*/
static uint8 simpleProfileChar3[SIMPLEPROFILE_CHAR3_LEN] = {0};
// Simple Profile Characteristic 3 User Description
static uint8 simpleProfileChar3UserDesp[17] = "Characteristic 3";
// Simple Profile Characteristic 4 Properties
static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;
@@ -185,7 +179,6 @@ static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;
/*user insert*/
static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = {0};
// Simple Profile Characteristic 4 Configuration Each client has its own
// instantiation of the Client Characteristic Configuration. Reads of the
// Client Characteristic Configuration only shows the configuration for
@@ -195,7 +188,6 @@ static gattCharCfg_t *simpleProfileChar4Config;
// Simple Profile Characteristic 4 User Description
static uint8 simpleProfileChar4UserDesp[17] = "Characteristic 4";
// Simple Profile Characteristic 5 Properties
static uint8 simpleProfileChar5Props = GATT_PROP_READ;
@@ -230,17 +222,17 @@ static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
// Characteristic Value 1
{
{ ATT_BT_UUID_SIZE, simpleProfilechar1UUID },
GATT_PERMIT_READ,
0,
simpleProfileChar1
GATT_PERMIT_READ,
0,
simpleProfileChar1
},
// Characteristic 1 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar1UserDesp
GATT_PERMIT_READ,
0,
simpleProfileChar1UserDesp
},
// Characteristic 2 Declaration
@@ -254,112 +246,114 @@ static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
// Characteristic Value 2
{
{ ATT_BT_UUID_SIZE, simpleProfilechar2UUID },
GATT_PERMIT_READ,
0,
simpleProfileChar2
},
GATT_PERMIT_READ,
0,
simpleProfileChar2
},
// Characteristic 2 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar2UserDesp
},
// Characteristic 2 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar2UserDesp
},
// Characteristic 3 Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&simpleProfileChar3Props
},
// Characteristic Value 3
{
{ ATT_BT_UUID_SIZE, simpleProfilechar3UUID },
GATT_PERMIT_WRITE,
0,
simpleProfileChar3
},
// Characteristic Value 3
{
{ ATT_BT_UUID_SIZE, simpleProfilechar3UUID },
GATT_PERMIT_WRITE,
0,
simpleProfileChar3
},
// Characteristic 3 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar3UserDesp
},
// Characteristic 3 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar3UserDesp
},
// Characteristic 4 Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&simpleProfileChar4Props
},
// Characteristic Value 4
{
{ ATT_BT_UUID_SIZE, simpleProfilechar4UUID },
0,
0,
simpleProfileChar4
},
// Characteristic Value 4
{
{ ATT_BT_UUID_SIZE, simpleProfilechar4UUID },
0,
0,
simpleProfileChar4
},
// Characteristic 4 configuration
{
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
(uint8 *)&simpleProfileChar4Config
},
// Characteristic 4 configuration
{
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
(uint8 *)&simpleProfileChar4Config
},
// Characteristic 4 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar4UserDesp
},
// Characteristic 4 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar4UserDesp
},
// Characteristic 5 Declaration
{
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
{ ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ,
0,
&simpleProfileChar5Props
},
// Characteristic Value 5
{
{ ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
GATT_PERMIT_AUTHEN_READ,
0,
simpleProfileChar5
},
// Characteristic Value 5
{
{ ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
GATT_PERMIT_AUTHEN_READ,
0,
simpleProfileChar5
},
// Characteristic 5 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar5UserDesp
},
// Characteristic 5 User Description
{
{ ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ,
0,
simpleProfileChar5UserDesp
},
};
/*********************************************************************
* LOCAL FUNCTIONS
*/
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
gattAttribute_t *pAttr,
uint8_t *pValue, uint16_t *pLen,
uint16_t offset, uint16_t maxLen,
uint8_t method);
gattAttribute_t *pAttr,
uint8_t *pValue, uint16_t *pLen,
uint16_t offset, uint16_t maxLen,
uint8_t method);
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
gattAttribute_t *pAttr,
uint8_t *pValue, uint16_t len,
uint16_t offset, uint8_t method);
gattAttribute_t *pAttr,
uint8_t *pValue, uint16_t len,
uint16_t offset, uint8_t method);
/*********************************************************************
* PROFILE CALLBACKS
@@ -401,7 +395,7 @@ bStatus_t SimpleProfile_AddService( uint32 services )
// Allocate Client Characteristic Configuration table
simpleProfileChar4Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
linkDBNumConns );
linkDBNumConns );
if ( simpleProfileChar4Config == NULL )
{
return ( bleMemAllocError );
@@ -414,9 +408,9 @@ bStatus_t SimpleProfile_AddService( uint32 services )
{
// Register GATT attribute list and CBs with GATT Server App
status = GATTServApp_RegisterService( simpleProfileAttrTbl,
GATT_NUM_ATTRS( simpleProfileAttrTbl ),
GATT_MAX_ENCRYPT_KEY_SIZE,
&simpleProfileCBs );
GATT_NUM_ATTRS( simpleProfileAttrTbl ),
GATT_MAX_ENCRYPT_KEY_SIZE,
&simpleProfileCBs );
}
else
{
@@ -474,7 +468,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
{
memcpy(simpleProfileChar1, value, len);
// simpleProfileChar1 = *((uint8*)value);
}
}
else
{
ret = bleInvalidRange;
@@ -488,7 +482,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
// simpleProfileChar2 = *((uint8*)value);
}
else
{
{
ret = bleInvalidRange;
}
break;
@@ -497,8 +491,7 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
if (len <= SIMPLEPROFILE_CHAR3_LEN)
{
memcpy(simpleProfileChar3, value, len);
// simpleProfileChar3 = *((uint8*)value);
}
}
else
{
ret = bleInvalidRange;
@@ -509,12 +502,9 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
if (len <= SIMPLEPROFILE_CHAR4_LEN)
{
memcpy(simpleProfileChar4, value, len);
// simpleProfileChar4 = *((uint8*)value);
// See if Notification has been enabled
GATTServApp_ProcessCharCfg( simpleProfileChar4Config, simpleProfileChar4, FALSE,
simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ),
INVALID_TASK_ID, simpleProfile_ReadAttrCB );
GATTServApp_ProcessCharCfg(simpleProfileChar4Config, simpleProfileChar4, FALSE, simpleProfileAttrTbl, GATT_NUM_ATTRS(simpleProfileAttrTbl), INVALID_TASK_ID, simpleProfile_ReadAttrCB);
}
else
{
@@ -523,9 +513,8 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
break;
case SIMPLEPROFILE_CHAR5:
if ( len == SIMPLEPROFILE_CHAR5_LEN )
{
VOID memcpy( simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN );
if (len == SIMPLEPROFILE_CHAR5_LEN) {
VOID memcpy(simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN);
}
else
{
@@ -554,41 +543,37 @@ bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
*
* @return bStatus_t
*/
bStatus_t SimpleProfile_GetParameter( uint8 param, void *value )
{
bStatus_t ret = SUCCESS;
switch ( param )
{
bStatus_t SimpleProfile_GetParameter(uint8 param, void *value) {
bStatus_t ret = SUCCESS;
switch (param) {
case SIMPLEPROFILE_CHAR1:
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
// *((uint8*)value) = simpleProfileChar1;
break;
memcpy(value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN);
// *((uint8*)value) = simpleProfileChar1;
break;
case SIMPLEPROFILE_CHAR2:
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
// *((uint8*)value) = simpleProfileChar2;
break;
memcpy(value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN);
// *((uint8*)value) = simpleProfileChar2;
break;
case SIMPLEPROFILE_CHAR3:
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
// *((uint8*)value) = simpleProfileChar3;
break;
memcpy(value, simpleProfileChar3, SIMPLEPROFILE_CHAR3_LEN);
break;
case SIMPLEPROFILE_CHAR4:
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
// *((uint8*)value) = simpleProfileChar4;
break;
memcpy(value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN);
break;
case SIMPLEPROFILE_CHAR5:
VOID memcpy( value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN );
break;
VOID memcpy(value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN);
break;
default:
ret = INVALIDPARAMETER;
break;
}
ret = INVALIDPARAMETER;
break;
}
return ( ret );
return (ret);
}
/*********************************************************************
@@ -606,65 +591,62 @@ bStatus_t SimpleProfile_GetParameter( uint8 param, void *value )
*
* @return SUCCESS, blePending or Failure
*/
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
gattAttribute_t *pAttr,
uint8_t *pValue, uint16_t *pLen,
uint16_t offset, uint16_t maxLen,
uint8_t method)
{
bStatus_t status = SUCCESS;
static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t *pLen, uint16_t offset, uint16_t maxLen, uint8_t method) {
bStatus_t status = SUCCESS;
// Make sure it's not a blob operation (no attributes in the profile are long)
if ( offset > 0 )
{
return ( ATT_ERR_ATTR_NOT_LONG );
}
if ( pAttr->type.len == ATT_BT_UUID_SIZE )
{
// 16-bit UUID
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
switch ( uuid )
{
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
// gattserverapp handles those reads
// characteristics 1 and 2 have read permissions
// characteritisc 3 does not have read permissions; therefore it is not
// included here
// characteristic 4 does not have read permissions, but because it
// can be sent as a notification, it is included here
case SIMPLEPROFILE_CHAR1_UUID:
*pLen = SIMPLEPROFILE_CHAR1_LEN;
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN );
case SIMPLEPROFILE_CHAR2_UUID:
*pLen = SIMPLEPROFILE_CHAR2_LEN;
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN );
case SIMPLEPROFILE_CHAR4_UUID:
*pLen = SIMPLEPROFILE_CHAR4_LEN;
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN );
break;
case SIMPLEPROFILE_CHAR5_UUID:
*pLen = SIMPLEPROFILE_CHAR5_LEN;
VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
break;
default:
// Should never get here! (characteristics 3 and 4 do not have read permissions)
*pLen = 0;
status = ATT_ERR_ATTR_NOT_FOUND;
break;
// Make sure it's not a blob operation (no attributes in the profile are long)
if (offset > 0) {
return (ATT_ERR_ATTR_NOT_LONG);
}
}
else
{
// 128-bit UUID
*pLen = 0;
status = ATT_ERR_INVALID_HANDLE;
}
return ( status );
if (pAttr->type.len == ATT_BT_UUID_SIZE) {
// 16-bit UUID
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
switch (uuid) {
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
// gattserverapp handles those reads
// characteristics 1 and 2 have read permissions
// characteritisc 3 does not have read permissions; therefore it is not
// included here
// characteristic 4 does not have read permissions, but because it
// can be sent as a notification, it is included here
case SIMPLEPROFILE_CHAR1_UUID:
*pLen = SIMPLEPROFILE_CHAR1_LEN;
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN);
break;
case SIMPLEPROFILE_CHAR2_UUID:
// *pLen = 1;
// pValue[0] = *pAttr->pValue;
*pLen = SIMPLEPROFILE_CHAR2_LEN;
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN);
break;
case SIMPLEPROFILE_CHAR4_UUID:
*pLen = SIMPLEPROFILE_CHAR4_LEN;
VOID memcpy(pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN);
break;
// case SIMPLEPROFILE_CHAR5_UUID:
// *pLen = SIMPLEPROFILE_CHAR5_LEN;
// VOID memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
// break;
default:
// Should never get here! (characteristics 3 and 4 do not have read permissions)
*pLen = 0;
status = ATT_ERR_ATTR_NOT_FOUND;
break;
}
} else {
// 128-bit UUID
*pLen = 0;
status = ATT_ERR_INVALID_HANDLE;
}
return (status);
}
/*********************************************************************
@@ -681,83 +663,83 @@ static bStatus_t simpleProfile_ReadAttrCB(uint16_t connHandle,
*
* @return SUCCESS, blePending or Failure
*/
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,
gattAttribute_t *pAttr,
uint8_t *pValue, uint16_t len,
uint16_t offset, uint8_t method)
{
bStatus_t status = SUCCESS;
uint8 notifyApp = 0xFF;
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle, gattAttribute_t *pAttr, uint8_t *pValue, uint16_t len, uint16_t offset, uint8_t method) {
bStatus_t status = SUCCESS;
uint8 notifyApp = 0xFF;
if ( pAttr->type.len == ATT_BT_UUID_SIZE )
{
// 16-bit UUID
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
switch ( uuid )
{
case SIMPLEPROFILE_CHAR1_UUID:
case SIMPLEPROFILE_CHAR3_UUID:
if (pAttr->type.len == ATT_BT_UUID_SIZE) {
// 16-bit UUID
uint16 uuid = BUILD_UINT16(pAttr->type.uuid[0], pAttr->type.uuid[1]);
switch (uuid) {
// Validate the value
// Make sure it's not a blob oper
/*
if ( offset == 0 )
{
if ( len != 1 )
{
status = ATT_ERR_INVALID_VALUE_SIZE;
}
}
else
{
status = ATT_ERR_ATTR_NOT_LONG;
}
//Validate the value
// Make sure it's not a blob oper
if ( offset == 0 )
{
if ( len > SIMPLEPROFILE_CHAR3_LEN )
{
status = ATT_ERR_INVALID_VALUE_SIZE;
}
//Write the value
if ( status == SUCCESS )
{
uint8 *pCurValue = (uint8 *)pAttr->pValue;
*pCurValue = pValue[0];
if( pAttr->pValue == &simpleProfileChar1 )
{
notifyApp = SIMPLEPROFILE_CHAR1;
}
}
break;
*/
case SIMPLEPROFILE_CHAR3_UUID:
if (offset == 0) {
if (len > SIMPLEPROFILE_CHAR3_LEN) {
status = ATT_ERR_INVALID_VALUE_SIZE;
}
} else {
status = ATT_ERR_ATTR_NOT_LONG;
}
// Write the value
if (status == SUCCESS) {
// Copy pValue into the variable we point to from the attribute table.
memcpy(pAttr->pValue + offset, pValue, len);
memset(pAttr->pValue + len, 0, SIMPLEPROFILE_CHAR3_LEN - len);
if (pAttr->pValue == simpleProfileChar3) {
notifyApp = SIMPLEPROFILE_CHAR3;
}
}
break;
case GATT_CLIENT_CHAR_CFG_UUID:
status = GATTServApp_ProcessCCCWriteReq(connHandle, pAttr, pValue, len, offset, GATT_CLIENT_CFG_NOTIFY);
break;
default:
// Should never get here! (characteristics 2 and 4 do not have write permissions)
status = ATT_ERR_ATTR_NOT_FOUND;
break;
}
else
{
status = ATT_ERR_ATTR_NOT_LONG;
}
//Write the value
if ( status == SUCCESS )
{
uint8 *pCurValue = (uint8 *)pAttr->pValue;
*pCurValue = pValue[0];
// Copy pValue into the variable we point to from the attribute table.
memcpy(pAttr->pValue + offset, pValue, len);
memset(pAttr->pValue + len, 0, SIMPLEPROFILE_CHAR3_LEN - len);
if( pAttr->pValue == simpleProfileChar1 )
{
notifyApp = SIMPLEPROFILE_CHAR1;
}
else
{
notifyApp = SIMPLEPROFILE_CHAR3;
}
}
break;
case GATT_CLIENT_CHAR_CFG_UUID:
status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
offset, GATT_CLIENT_CFG_NOTIFY );
break;
default:
// Should never get here! (characteristics 2 and 4 do not have write permissions)
status = ATT_ERR_ATTR_NOT_FOUND;
break;
} else {
// 128-bit UUID
status = ATT_ERR_INVALID_HANDLE;
}
}
else
{
// 128-bit UUID
status = ATT_ERR_INVALID_HANDLE;
}
// If a characteristic value changed then callback function to notify application of change
if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
{
simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );
}
// If a characteristic value changed then callback function to notify application of change
if ((notifyApp != 0xFF) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange) {
simpleProfile_AppCBs->pfnSimpleProfileChange(notifyApp);
}
return ( status );
return (status);
}
/*********************************************************************
@@ -56,7 +56,7 @@ extern "C"
/*********************************************************************
* INCLUDES
*/
#include "application_config/application_config.h"
/*********************************************************************
* CONSTANTS
*/
@@ -81,24 +81,12 @@ extern "C"
// Simple Keys Profile Services bit fields
#define SIMPLEPROFILE_SERVICE 0x00000001
#ifndef CUSTOM_GATT_LENGTH
// Length of Characteristic 5 in bytes
#define SIMPLEPROFILE_CHAR5_LEN 5
#define SIMPLEPROFILE_CHAR4_LEN 20
/*user insert*/
#define SIMPLEPROFILE_CHAR4_LEN 40
#define SIMPLEPROFILE_CHAR3_LEN 20
#define SIMPLEPROFILE_CHAR2_LEN 20
#define SIMPLEPROFILE_CHAR1_LEN 20
#else
/*user insert*/
#define SIMPLEPROFILE_CHAR5_LEN 5
#define SIMPLEPROFILE_CHAR4_LEN BLE_DAT_BUFF_SIZE
#define SIMPLEPROFILE_CHAR3_LEN BLE_INS_BUFF_SIZE
#define SIMPLEPROFILE_CHAR2_LEN BLE_CIS_BUFF_SIZE
#define SIMPLEPROFILE_CHAR1_LEN 20
#define BLE_CIS_BUFF_CHAR SIMPLEPROFILE_CHAR2
#define BLE_INS_BUFF_CHAR SIMPLEPROFILE_CHAR3
#define BLE_DAT_BUFF_CHAR SIMPLEPROFILE_CHAR4
#endif
/*********************************************************************
* TYPEDEFS
*/