You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

555 lines
18 KiB

5 years ago
  1. /* --COPYRIGHT--,BSD
  2. * Copyright (c) 2013, Texas Instruments Incorporated
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of Texas Instruments Incorporated nor the names of
  17. * its contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. * --/COPYRIGHT--*/
  32. /*
  33. * structure.h
  34. */
  35. //******************************************************************************
  36. // 430BOOST-SHARP96 example with the MSP430G2553 on a MSP-EXP430G2 LaunchPad
  37. //******************************************************************************
  38. #ifndef CTS_STRUCTURE_H_
  39. #define CTS_STRUCTURE_H_
  40. #include "msp430.h"
  41. #include <stdint.h>
  42. /* Public Globals */
  43. extern const struct Element leftSlider_Element0;
  44. extern const struct Element leftSlider_Element1;
  45. extern const struct Element leftSlider_Element2;
  46. extern const struct Element rightSlider_Element0;
  47. extern const struct Element rightSlider_Element1;
  48. extern const struct Element rightSlider_Element2;
  49. extern const struct Sensor leftSlider;
  50. extern const struct Sensor rightSlider;
  51. //****** RAM ALLOCATION ********************************************************
  52. // TOTAL_NUMBER_OF_ELEMENTS represents the total number of elements used, even if
  53. // they are going to be segmented into seperate groups. This defines the
  54. // RAM allocation for the baseline tracking. If only the TI_CAPT_Raw function
  55. // is used, then this definition should be removed to conserve RAM space.
  56. #define TOTAL_NUMBER_OF_ELEMENTS 6
  57. // If the RAM_FOR_FLASH definition is removed, then the appropriate HEAP size
  58. // must be allocated. 2 bytes * MAXIMUM_NUMBER_OF_ELEMENTS_PER_SENSOR + 2 bytes
  59. // of overhead.
  60. #define RAM_FOR_FLASH
  61. //****** Structure Array Definition ********************************************
  62. // This defines the array size in the sensor strucure. In the event that
  63. // RAM_FOR_FLASH is defined, then this also defines the amount of RAM space
  64. // allocated (global variable) for computations.
  65. #define MAXIMUM_NUMBER_OF_ELEMENTS_PER_SENSOR 3
  66. //****** Choosing a Measurement Method ****************************************
  67. // These variables are references to the definitions found in structure.c and
  68. // must be generated per the application.
  69. // possible values for the method field
  70. // OSCILLATOR DEFINITIONS
  71. //#define RO_COMPAp_TA0_WDTp 64
  72. #define RO_PINOSC_TA0_WDTp 65
  73. //#define RO_PINOSC_TA0 66
  74. //#define RO_COMPAp_TA1_WDTp 67
  75. //#define RO_COMPB_TA0_WDTA 68
  76. //#define RO_COMPB_TA1_WDTA 69
  77. //#define RO_COMPB_TB0_WDTA 70
  78. //#define RO_COMPB_TA1_TA0 71
  79. //#define RO_PINOSC_TA0_TA1 72
  80. //#define RO_CSIO_TA2_WDTA 73
  81. //#define RO_CSIO_TA2_TA3 74
  82. //#define RO_PINOSC_TA1_WDTp 75
  83. //#define RO_PINOSC_TA1_TB0 76
  84. // RC DEFINITIONS
  85. //#define RC_PAIR_TA0 01
  86. // FAST RO DEFINITIONS
  87. //#define fRO_CSIO_TA2_TA3 23
  88. //#define fRO_PINOSC_TA0_TA1 24
  89. //#define fRO_PINOSC_TA0_SW 25
  90. //#define fRO_COMPB_TA0_SW 26
  91. //#define fRO_COMPB_TA1_SW 27
  92. //#define fRO_COMPAp_TA0_SW 28
  93. //#define fRO_COMPAp_SW_TA0 29
  94. //#define fRO_COMPAp_TA1_SW 30
  95. //#define fRO_COMPB_TA1_TA0 31
  96. //#define fRO_PINOSC_TA1_TA0 32
  97. //#define fRO_PINOSC_TA1_TB0 33
  98. //****** WHEEL and SLIDER ******************************************************
  99. // Are wheel or slider representations used?
  100. //#define SLIDER
  101. #define ILLEGAL_SLIDER_WHEEL_POSITION 0xFFFF
  102. #define WHEEL
  103. //******************************************************************************
  104. // End of user configuration section.
  105. //******************************************************************************
  106. //******************************************************************************
  107. //******************************************************************************
  108. //possible timer source clock dividers, different from clock module dividers
  109. #define TIMER_TxCLK 0x0000 // TxSSEL
  110. #define TIMER_ACLK 0x0100
  111. #define TIMER_SMCLK 0x0200
  112. #define TIMER_INCLK 0x0300
  113. #define TIMER_SOURCE_DIV_0 0x0000 // ID_0, IDX_0
  114. #define TIMER_SOURCE_DIV_1 0x0040
  115. #define TIMER_SOURCE_DIV_2 0x0080
  116. #define TIMER_SOURCE_DIV_3 0x00C0
  117. #define GATE_WDT_ACLK 0x0004
  118. #define GATE_WDT_SMCLK 0x0000
  119. #define GATE_WDTp_ACLK 0x0004
  120. #define GATE_WDTp_SMCLK 0x0000
  121. #define WDTp_GATE_32768 0x0000 // watchdog source/32768
  122. #define WDTp_GATE_8192 0x0001 // watchdog source/8192
  123. #define WDTp_GATE_512 0x0002 // watchdog source/512
  124. #define WDTp_GATE_64 0x0003 // watchdog source/64
  125. #define GATE_WDTA_SMCLK 0x0000
  126. #define GATE_WDTA_ACLK 0x0020
  127. #define GATE_WDTA_VLO 0x0040
  128. #define GATE_WDTA_XCLK 0x0060
  129. #define WDTA_GATE_2G 0x0000 // watchdog source/2G
  130. #define WDTA_GATE_128M 0x0001 // watchdog source/128M
  131. #define WDTA_GATE_8192K 0x0002 // watchdog source/8192K
  132. #define WDTA_GATE_512K 0x0003 // watchdog source/512K
  133. #define WDTA_GATE_32768 0x0004 // watchdog source/32768
  134. #define WDTA_GATE_8192 0x0005 // watchdog source/8192
  135. #define WDTA_GATE_512 0x0006 // watchdog source/512
  136. #define WDTA_GATE_64 0x0007 // watchdog source/64
  137. // The below variables are used to excluded portions of code not needed by
  138. // the method chosen by the user. Uncomment the type used prior to compilation.
  139. // Multiple types can be chosen as needed.
  140. // What Method(s) are used in this application?
  141. #ifdef RO_COMPAp_TA0_WDTp
  142. #define RO_TYPE
  143. #define RO_COMPAp_TYPE
  144. #define WDT_GATE
  145. #define HAL_DEFINITION
  146. //what devices have Pxsel2 ??
  147. // msp430f2112, 2122, 2132
  148. // msp430G2112, G2212, G2312, G2412, G2152, G2252, G2352, G2452
  149. // SEL2REGISTER
  150. #ifdef __MSP430F2112
  151. #define SEL2REGISTER
  152. #endif
  153. #ifdef __MSP430F2122
  154. #define SEL2REGISTER
  155. #endif
  156. #ifdef __MSP430F2132
  157. #define SEL2REGISTER
  158. #endif
  159. #ifdef __MSP430G2112
  160. #define SEL2REGISTER
  161. #endif
  162. #ifdef __MSP430G2212
  163. #define SEL2REGISTER
  164. #endif
  165. #ifdef __MSP430G2312
  166. #define SEL2REGISTER
  167. #endif
  168. #ifdef __MSP430G2412
  169. #define SEL2REGISTER
  170. #endif
  171. #ifdef __MSP430G2152
  172. #define SEL2REGISTER
  173. #endif
  174. #ifdef __MSP430G2252
  175. #define SEL2REGISTER
  176. #endif
  177. #ifdef __MSP430G2352
  178. #define SEL2REGISTER
  179. #endif
  180. #ifdef __MSP430G2452
  181. #define SEL2REGISTER
  182. #endif
  183. #endif
  184. #ifdef RO_PINOSC_TA0_WDTp
  185. #define RO_TYPE
  186. #define RO_PINOSC_TYPE
  187. #define WDT_GATE
  188. #define HAL_DEFINITION
  189. #endif
  190. #ifdef RO_PINOSC_TA0
  191. #define RO_TYPE
  192. #define RO_PINOSC_TYPE
  193. #define ACCUMULATE_TYPE
  194. #define HAL_DEFINITION
  195. #endif
  196. #ifdef RO_COMPAp_TA1_WDTp
  197. #define RO_TYPE
  198. #define RO_COMPAp_TYPE
  199. #define WDT_GATE
  200. #define HAL_DEFINITION
  201. #endif
  202. #ifdef RO_COMPB_TA0_WDTA
  203. #define RO_TYPE
  204. #define RO_COMPB_TYPE
  205. #define WDT_GATE
  206. #define HAL_DEFINITION
  207. #endif
  208. #ifdef RO_COMPB_TA1_WDTA
  209. #define RO_TYPE
  210. #define RO_COMPB_TYPE
  211. #define WDT_GATE
  212. #define HAL_DEFINITION
  213. #endif
  214. #ifdef RO_COMPB_TB0_WDTA
  215. #define RO_TYPE
  216. #define RO_COMPB_TYPE
  217. #define WDT_GATE
  218. #define HAL_DEFINITION
  219. #endif
  220. #ifdef RC_PAIR_TA0
  221. #define RC_TYPE
  222. #define RC_PAIR_TYPE
  223. #define ACCUMULATE_TYPE
  224. #define HAL_DEFINITION
  225. #endif
  226. #ifdef fRO_PINOSC_TA0_SW
  227. #define RO_TYPE
  228. #define RO_PINOSC_TYPE
  229. #define TIMER_SCALE
  230. #define HAL_DEFINITION
  231. #endif
  232. #ifdef fRO_COMPB_TA0_SW
  233. #define RO_TYPE
  234. #define RO_COMPB_TYPE
  235. #define TIMER_SCALE
  236. #define HAL_DEFINITION
  237. #endif
  238. #ifdef fRO_COMPB_TA1_SW
  239. #define RO_TYPE
  240. #define RO_COMPB_TYPE
  241. #define TIMER_SCALE
  242. #define HAL_DEFINITION
  243. #endif
  244. #ifdef fRO_COMPAp_TA0_SW
  245. #define RO_TYPE
  246. #define RO_COMPAp_TYPE
  247. #define TIMER_SCALE
  248. #define HAL_DEFINITION
  249. #endif
  250. #ifdef fRO_COMPAp_TA1_SW
  251. #define RO_TYPE
  252. #define RO_COMPAp_TYPE
  253. #define TIMER_SCALE
  254. #define HAL_DEFINITION
  255. #endif
  256. #ifdef fRO_COMPAp_SW_TA0
  257. #define RO_TYPE
  258. #define RO_COMPAp_TYPE
  259. #define HAL_DEFINITION
  260. #endif
  261. #ifdef RO_COMPB_TA1_TA0
  262. #define RO_TYPE
  263. #define RO_COMPB_TYPE
  264. #define TIMER_SCALE
  265. #define TIMER0A0_GATE
  266. #define HAL_DEFINITION
  267. #endif
  268. #ifdef fRO_COMPB_TA1_TA0
  269. #define RO_TYPE
  270. #define RO_COMPB_TYPE
  271. #define TIMER_SCALE
  272. #define TIMER1A0_GATE
  273. #define HAL_DEFINITION
  274. #endif
  275. #ifdef RO_PINOSC_TA0_TA1
  276. #define RO_TYPE
  277. #define RO_PINOSC_TYPE
  278. #define TIMER_SCALE
  279. #define TIMER1A0_GATE
  280. #define HAL_DEFINITION
  281. #endif
  282. #ifdef fRO_PINOSC_TA0_TA1
  283. #define RO_TYPE
  284. #define RO_PINOSC_TYPE
  285. #define TIMER_SCALE
  286. #define TIMER0A0_GATE
  287. #define HAL_DEFINITION
  288. #endif
  289. #ifdef RO_CSIO_TA2_WDTA
  290. #define RO_TYPE
  291. #define RO_CSIO_TYPE
  292. #define WDT_GATE
  293. #define HAL_DEFINITION
  294. #endif
  295. #ifdef RO_CSIO_TA2_TA3
  296. #define RO_TYPE
  297. #define RO_CSIO_TYPE
  298. #define TIMER_SCALE
  299. #define TIMER3A0_GATE
  300. #define HAL_DEFINITION
  301. #endif
  302. #ifdef fRO_CSIO_TA2_TA3
  303. #define RO_TYPE
  304. #define RO_CSIO_TYPE
  305. #define TIMER_SCALE
  306. #define TIMER2A0_GATE
  307. #define HAL_DEFINITION
  308. #endif
  309. #ifdef RO_PINOSC_TA1_WDTp
  310. #define RO_TYPE
  311. #define RO_PINOSC_TYPE
  312. #define WDT_GATE
  313. #define HAL_DEFINITION
  314. #endif
  315. #ifdef RO_PINOSC_TA1_TB0
  316. #define RO_TYPE
  317. #define RO_PINOSC_TYPE
  318. #define TIMER_SCALE
  319. #define TIMERB0_GATE
  320. #define HAL_DEFINITION
  321. #endif
  322. #ifdef fRO_PINOSC_TA1_TA0
  323. #define RO_TYPE
  324. #define RO_PINOSC_TYPE
  325. #define TIMER_SCALE
  326. #define TIMER1A0_GATE
  327. #define HAL_DEFINITION
  328. #endif
  329. #ifdef fRO_PINOSC_TA1_TB0
  330. #define RO_TYPE
  331. #define RO_PINOSC_TYPE
  332. #define TIMER_SCALE
  333. #define TIMER1A0_GATE
  334. #define HAL_DEFINITION
  335. #endif
  336. #ifdef SLIDER
  337. #define SLIDER_WHEEL
  338. #endif
  339. #ifdef WHEEL
  340. #define SLIDER_WHEEL
  341. #endif
  342. #define RO_MASK 0xC0 // 1100 0000
  343. #define RC_FRO_MASK 0x3F // 0011 1111
  344. /*
  345. * The element structure identifies port or comparator input definitions for
  346. * each element.
  347. */
  348. struct Element{
  349. #ifdef RO_PINOSC_TYPE
  350. // These register address definitions are needed for each sensor only
  351. // when using the PinOsc method
  352. uint8_t *inputPxselRegister; // PinOsc: port selection address
  353. uint8_t *inputPxsel2Register; // PinOsc: port selection 2 address
  354. #endif
  355. #ifdef RC_PAIR_TYPE
  356. // these fields are specific to the RC type.
  357. uint8_t *inputPxoutRegister; // RC: port output address: PxOUT
  358. volatile uint8_t *inputPxinRegister; // RC: port input address: PxIN
  359. uint8_t *inputPxdirRegister; // RC+PinOsc: port direction address
  360. uint8_t *referencePxoutRegister;// RC: port output address: PxOUT
  361. uint8_t *referencePxdirRegister;// RC: port direction address: PxDIR
  362. uint8_t referenceBits; // RC: port bit definition
  363. #endif
  364. uint16_t inputBits; // Comp_RO+FastRO+RC+PinOsc: bit
  365. // definition
  366. //
  367. // for comparator input bit
  368. // location in CACTL2 or CBCTL0
  369. uint16_t threshold; // specific threshold for each button
  370. uint16_t maxResponse; // Special Case: Slider max counts
  371. };
  372. /*
  373. * The sensor structure identifies HAL and timing definitions for
  374. * each sensor.
  375. */
  376. struct Sensor{
  377. // the method acts as the switch to determine which HAL is called
  378. uint8_t halDefinition; // COMPARATOR_TYPE (RO), RC, etc
  379. // RO_COMPA, RO_COMPB, RO_PINOSC
  380. // RC_GPIO, RC_COMPA, RC_COMPB
  381. // FAST_SCAN_RO
  382. #ifdef RO_CSIO_TYPE
  383. /*
  384. * This register address definition is needed to indicate which CSIOxCTL
  385. * register is associated with the Timer identified in the HAL.
  386. */
  387. uint16_t *inputCapsioctlRegister;
  388. #endif
  389. uint8_t numElements; // number of elements within group
  390. uint8_t baseOffset; // the offset within the global
  391. // base_cnt array
  392. struct Element const *arrayPtr[MAXIMUM_NUMBER_OF_ELEMENTS_PER_SENSOR];
  393. // an array of pointers
  394. //******************************************************************************
  395. // Reference structure definitions for comparator types, for the RC method the
  396. // reference is defined within the element.
  397. #ifdef RO_COMPAp_TYPE
  398. uint8_t * refPxoutRegister; // RO+FastRO: port output address
  399. uint8_t * refPxdirRegister; // RO+FastRO: port direction address
  400. uint8_t refBits; // RO+FastRO: port bit definition
  401. uint8_t * txclkDirRegister; // PxDIR
  402. uint8_t * txclkSelRegister; // PxSEL
  403. uint8_t txclkBits; // Bit field for register
  404. uint8_t *caoutDirRegister; // PxDIR
  405. uint8_t *caoutSelRegister; // PxSEL
  406. uint8_t caoutBits; // Bit field for register
  407. // This is only applicable to the RO_COMPAp_TYPE
  408. #ifdef SEL2REGISTER
  409. uint8_t *caoutSel2Register;
  410. uint8_t *txclkSel2Register;
  411. #endif
  412. uint8_t refCactl2Bits; // RO: CACTL2 input definition,
  413. // CA0 (P2CA0),CA1(P2CA4),
  414. // CA2(P2CA0+P2CA4)
  415. uint8_t capdBits;
  416. #endif
  417. #ifdef RO_COMPB_TYPE
  418. uint8_t *cboutTAxDirRegister; // CBOUT_TA0CLK
  419. uint8_t *cboutTAxSelRegister; // CBOUT_TA0CLK
  420. uint8_t cboutTAxBits; // Bit field for register
  421. uint16_t cbpdBits;
  422. #endif
  423. //*****************************************************************************
  424. // Timer definitions
  425. // The basic premise is to count a number of clock cycles within a time
  426. // period, where either the clock source or the timer period is a function
  427. // of the element capacitance.
  428. //
  429. // RC Method:
  430. // Period: accumulationCycles * charge and discharge time of RC
  431. // circuit where C is capacitive touch element
  432. //
  433. // clock source: measGateSource/sourceScale
  434. // RO Method:
  435. // Period: accumulationCycles*measGateSource/sourceScale
  436. // (with WDT sourceScale = 1, accumulationCycles is WDT control
  437. // register settings)
  438. //
  439. // clock source: relaxation oscillator where freq is a function of C
  440. //
  441. // fRO Method:
  442. // Period: accumulationCycles * 1/freq, freq is a function of C
  443. //
  444. // clock source: measGateSource/sourceScale
  445. uint16_t measGateSource; // RC+FastRO: measurement timer source,
  446. // {ACLK, TACLK, SMCLK}
  447. // Comp_RO+PinOsc: gate timer source,
  448. // {ACLK, TACLK, SMCLK}
  449. #ifdef TIMER_SCALE
  450. uint16_t sourceScale; // RO+FastRO: gate timer,
  451. // TA/TB, scale: 1,1/2,1/4,1/8
  452. // RC+FastRO: measurement timer, TA/TB/TD
  453. // scale: 16, 8, 4, 2, 1, ?, ?, 1/8
  454. // Not used for WDTp/WDTA
  455. #endif
  456. uint16_t accumulationCycles;
  457. //*****************************************************************************
  458. // Other definitions
  459. #ifdef SLIDER_WHEEL
  460. uint8_t points; // Special Case: Number of points
  461. // along slider or wheel
  462. uint8_t sensorThreshold;
  463. #endif
  464. };
  465. /*
  466. * The GCC language extension within CCS is needed, otherwise a warning will
  467. * be generated during compilation when no problems exist or an error will be
  468. * generated (instead of a warning) when a problem does exist.
  469. */
  470. #ifndef TOTAL_NUMBER_OF_ELEMENTS
  471. #warning "WARNING: TOTAL_NUMBER_OF_ELEMENTS is not defined in structure.h. Only TI_CAPT_RAW function is enabled."
  472. #endif
  473. #ifndef RAM_FOR_FLASH
  474. #warning "WARNING: The HEAP must be set appropriately. Please refer to SLAA490 for details."
  475. #endif
  476. #ifndef HAL_DEFINITION
  477. #warning "WARNING: At least one HAL definition must be made in structure.h."
  478. #endif
  479. #endif /* CTS_STRUCTURE_H_ */