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.

421 lines
15 KiB

5 years ago
  1. #ifndef CAP_TOUCH_STRUCTURE
  2. #define CAP_TOUCH_STRUCTURE
  3. //******************************************************************************
  4. // structure.h
  5. //
  6. // Launch Pad MSP430G2452
  7. // 4 element wheel
  8. // middle button
  9. // proximity sensor
  10. //
  11. //
  12. // This file contains both application dependent and independent pieces. The
  13. // dependent piece must be updated along with structure.c, and carries the
  14. // naming conventions found in structure.c to the rest of the library.
  15. //
  16. //
  17. //
  18. //
  19. // Revision 0.06 Updated with case and format from Stye Guide
  20. //
  21. //******************************************************************************
  22. //******************************************************************************
  23. //******************************************************************************
  24. // The following elements need to be configured by the user.
  25. //******************************************************************************
  26. //#include "msp430.h"
  27. #include "msp430g2452.h"
  28. #include <stdint.h>
  29. /* Public Globals */
  30. extern const struct Element volume_down; // structure containing elements for
  31. extern const struct Element volume_up; //
  32. extern const struct Element right; //
  33. extern const struct Element left; //
  34. extern const struct Element middle_element; //
  35. extern const struct Element proximity_element; //
  36. extern const struct Sensor wheel;
  37. extern const struct Sensor middle_button; // structure of info for a given
  38. extern const struct Sensor proximity_sensor; // structure of info for a given
  39. //****** RAM ALLOCATION ********************************************************
  40. // TOTAL_NUMBER_OF_ELEMENTS defines the total number of elements used, even if
  41. // they are going to be segmented into seperate groups.
  42. // If the RAM_FOR_FLASH definition is removed, then the appropriate HEAP size
  43. // must be allocated. 2 bytes * MAXIMUM_NUMBER_OF_ELEMENTS_PER_SENSOR + 2 bytes
  44. // of overhead.
  45. #define TOTAL_NUMBER_OF_ELEMENTS 6
  46. #define RAM_FOR_FLASH
  47. //****** Structure Array Definition ********************************************
  48. // This defines the array size in the sensor strucure. In the event that
  49. // RAM_FOR_FLASH is defined, then this also defines the amount of RAM space
  50. // allocated (global variable) for computations.
  51. #define MAXIMUM_NUMBER_OF_ELEMENTS_PER_SENSOR 4
  52. //****** Choosing a Measurement Method ****************************************
  53. // These variables are references to the definitions found in structure.c and
  54. // must be generated per the application.
  55. // possible values for the method field
  56. // OSCILLATOR DEFINITIONS
  57. //#define RO_COMPAp_TA0_WDTp 64
  58. #define RO_PINOSC_TA0_WDTp 65
  59. //#define RO_PINOSC_TA0 66
  60. //#define RO_COMPAp_TA1_WDTp 67
  61. //#define RO_COMPB_TA0_WDTA 68
  62. //#define RO_COMPB_TA1_WDTA 69
  63. //#define RO_COMPAp_TA0_SW 70
  64. //#define RO_PINOSC_TA0_SW 71
  65. // RC DEFINITIONS
  66. //#define RC_PAIR_TA0 01
  67. //#define RC_PAIR_TA1 02
  68. //#define RC_PAIR_TD0 03
  69. // FAST RO DEFINITIONS
  70. //#define fRO_PINOSC_TA0_SW 25
  71. //#define fRO_COMPB_TA0_TA1 26
  72. //#define fRO_COMPB_TA0_TD0 27
  73. //****** WHEEL and SLIDER ******************************************************
  74. // Are wheel or slider representations used?
  75. //#define SLIDER
  76. #define ILLEGAL_SLIDER_WHEEL_POSITION 0xFFFF
  77. #define WHEEL
  78. //******************************************************************************
  79. // End of user configuration section.
  80. //******************************************************************************
  81. //******************************************************************************
  82. //******************************************************************************
  83. //possible timer source clock dividers, different from clock module dividers
  84. #define TIMER_TxCLK 0x0000 // ID_0, IDX_0
  85. #define TIMER_ACLK 0x0100
  86. #define TIMER_SMCLK 0x0200
  87. #define TIMER_INCLK 0x0300
  88. #define TIMER_SOURCE_DIV_0 0x0000
  89. #define TIMER_SOURCE_DIV_1 0x0040
  90. #define TIMER_SOURCE_DIV_2 0x0080
  91. #define TIMER_SOURCE_DIV_3 0x00C0
  92. #define GATE_WDT_ACLK 0x0004
  93. #define GATE_WDT_SMCLK 0x0000
  94. #define WDTp_GATE_32768 0x0000 // watchdog source/32768
  95. #define WDTp_GATE_8192 0x0001 // watchdog source/8192
  96. #define WDTp_GATE_512 0x0002 // watchdog source/512
  97. #define WDTp_GATE_64 0x0003 // watchdog source/64
  98. #define WDTA_GATE_2G 0x0000 // watchdog source/2G
  99. #define WDTA_GATE_128M 0x0001 // watchdog source/128M
  100. #define WDTA_GATE_8192K 0x0002 // watchdog source/8192K
  101. #define WDTA_GATE_512K 0x0003 // watchdog source/512K
  102. #define WDTA_GATE_32768 0x0004 // watchdog source/32768
  103. #define WDTA_GATE_8192 0x0005 // watchdog source/8192
  104. #define WDTA_GATE_512 0x0006 // watchdog source/512
  105. #define WDTA_GATE_64 0x0007 // watchdog source/64
  106. // The below variables are used to excluded portions of code not needed by
  107. // the method chosen by the user. Uncomment the type used prior to compilation.
  108. // Multiple types can be chosen as needed.
  109. // What Method(s) are used in this application?
  110. #ifdef RO_COMPAp_TA0_WDTp
  111. #define RO_TYPE
  112. #define RO_COMPAp_TYPE
  113. #define WDT_GATE
  114. //what devices have Pxsel2 ??
  115. // msp430f2112, 2122, 2132
  116. // msp430G2112, G2212, G2312, G2412, G2152, G2252, G2352, G2452
  117. // SEL2REGISTER
  118. #ifdef __MSP430F2112
  119. #define SEL2REGISTER
  120. #endif
  121. #ifdef __MSP430F2122
  122. #define SEL2REGISTER
  123. #endif
  124. #ifdef __MSP430F2132
  125. #define SEL2REGISTER
  126. #endif
  127. #ifdef __MSP430G2112
  128. #define SEL2REGISTER
  129. #endif
  130. #ifdef __MSP430G2212
  131. #define SEL2REGISTER
  132. #endif
  133. #ifdef __MSP430G2312
  134. #define SEL2REGISTER
  135. #endif
  136. #ifdef __MSP430G2412
  137. #define SEL2REGISTER
  138. #endif
  139. #ifdef __MSP430G2152
  140. #define SEL2REGISTER
  141. #endif
  142. #ifdef __MSP430G2252
  143. #define SEL2REGISTER
  144. #endif
  145. #ifdef __MSP430G2352
  146. #define SEL2REGISTER
  147. #endif
  148. #ifdef __MSP430G2452
  149. #define SEL2REGISTER
  150. #endif
  151. #endif
  152. #ifdef RO_PINOSC_TA0_WDTp
  153. #define RO_TYPE
  154. #define RO_PINOSC_TYPE
  155. #define WDT_GATE
  156. #endif
  157. #ifdef RO_PINOSC_TA0
  158. #define RO_TYPE
  159. #define RO_PINOSC_TYPE
  160. #define ACCUMULATE_TYPE
  161. #endif
  162. #ifdef RO_COMPAp_TA1_WDTp
  163. #define RO_TYPE
  164. #define RO_COMPAp_TYPE
  165. #define WDT_GATE
  166. #endif
  167. #ifdef RO_COMPB_TA0_WDTA
  168. #define RO_TYPE
  169. #define RO_COMPB_TYPE
  170. #define WDT_GATE
  171. #endif
  172. #ifdef RO_COMPB_TA1_WDTA
  173. #define RO_TYPE
  174. #define RO_COMPB_TYPE
  175. #define WDT_GATE
  176. #endif
  177. #ifdef RO_COMPAp_TA0_SW
  178. #define RO_TYPE
  179. #define RO_COMPAp_TYPE
  180. #endif
  181. #ifdef RO_PINOSC_TA0_SW
  182. #define RO_TYPE
  183. #define RO_PINOSC_TYPE
  184. #endif
  185. #ifdef RC_PAIR_TA0
  186. #define RC_TYPE
  187. #define RC_PAIR_TYPE
  188. #define ACCUMULATE_TYPE
  189. #endif
  190. #ifdef RC_PAIR_TA1
  191. #define RC_TYPE
  192. #define RC_PAIR_TYPE
  193. #endif
  194. #ifdef RC_PAIR_TD0
  195. #define RC_TYPE
  196. #define RC_PAIR_TYPE
  197. #endif
  198. #ifdef fRO_PINOSC_TA0_SW
  199. #define RO_TYPE
  200. #define RO_PINOSC_TYPE
  201. #define ACCUMULATE_TYPE
  202. #endif
  203. #ifdef fRO_COMPB_TA0_TA1
  204. #define RO_TYPE
  205. #define FAST_SCAN_RO_COMP_TYPE
  206. #endif
  207. #ifdef fRO_COMPB_TA0_TD0
  208. #define RO_TYPE
  209. #define FAST_SCAN_RO_COMP_TYPE
  210. #endif
  211. #ifdef SLIDER
  212. #define SLIDER_WHEEL
  213. #endif
  214. #ifdef WHEEL
  215. #define SLIDER_WHEEL
  216. #endif
  217. #define RO_MASK 0xC0 // 1100 0000
  218. #define RC_FRO_MASK 0x3F // 0011 1111
  219. //******************************************************************************
  220. // The sensor structure identifies port or comparator input definitions for each
  221. // sensor.
  222. //******************************************************************************
  223. struct Element{
  224. #ifdef RO_PINOSC_TYPE
  225. // These register address definitions are needed for each sensor only
  226. // when using the PinOsc method
  227. volatile uint8_t *inputPxselRegister; // PinOsc: port selection address
  228. volatile uint8_t *inputPxsel2Register; // PinOsc: port selection 2 address
  229. #endif
  230. #ifdef RC_PAIR_TYPE
  231. // these fields are specific to the RC type.
  232. uint8_t *inputPxoutRegister; // RC: port output address: PxOUT
  233. volatile uint8_t *inputPxinRegister; // RC: port input address: PxIN
  234. uint8_t *inputPxdirRegister; // RC+PinOsc: port direction address
  235. uint8_t *referencePxoutRegister;// RC: port output address: PxOUT
  236. uint8_t *referencePxdirRegister;// RC: port direction address: PxDIR
  237. uint8_t referenceBits; // RC: port bit definition
  238. #endif
  239. uint16_t inputBits; // Comp_RO+FastRO+RC+PinOsc: bit
  240. // definition
  241. //
  242. // for comparator input bit
  243. // location in CACTL2 or CBCTL0
  244. uint16_t threshold; // specific threshold for each button
  245. uint16_t maxResponse; // Special Case: Slider max counts
  246. };
  247. //******************************************************************************
  248. // The following structure definitons are application independent and are not
  249. // intended to be modified.
  250. //
  251. // The CT_handler 'groups' the sensor based upon function and capacitive
  252. // measurement method.
  253. //******************************************************************************
  254. struct Sensor{
  255. // the method acts as the switch to determine which HAL is called
  256. uint8_t halDefinition; // COMPARATOR_TYPE (RO), RC, etc
  257. // RO_COMPA, RO_COMPB, RO_PINOSC
  258. // RC_GPIO, RC_COMPA, RC_COMPB
  259. // FAST_SCAN_RO
  260. uint8_t numElements; // number of elements within group
  261. uint8_t baseOffset; // the offset within the global
  262. // base_cnt array
  263. struct Element const *arrayPtr[MAXIMUM_NUMBER_OF_ELEMENTS_PER_SENSOR];
  264. // an array of pointers
  265. //******************************************************************************
  266. // Reference structure definitions for comparator types, for the RC method the
  267. // reference is defined within the element.
  268. #ifdef RO_COMPAp_TYPE
  269. uint8_t * refPxoutRegister; // RO+FastRO: port output address
  270. uint8_t * refPxdirRegister; // RO+FastRO: port direction address
  271. uint8_t refBits; // RO+FastRO: port bit definition
  272. uint8_t * txclkDirRegister; // PxDIR
  273. uint8_t * txclkSelRegister; // PxSEL
  274. uint8_t txclkBits; // Bit field for register
  275. uint8_t *caoutDirRegister; // PxDIR
  276. uint8_t *caoutSelRegister; // PxSEL
  277. uint8_t caoutBits; // Bit field for register
  278. // This is only applicable to the RO_COMPAp_TYPE
  279. #ifdef SEL2REGISTER
  280. uint8_t *caoutSel2Register;
  281. uint8_t *txclkSel2Register;
  282. #endif
  283. uint8_t refCactl2Bits; // RO: CACTL2 input definition,
  284. // CA0 (P2CA0),CA1(P2CA4),
  285. // CA2(P2CA0+P2CA4)
  286. uint8_t capdBits;
  287. #endif
  288. #ifdef RO_COMPB_TYPE
  289. uint8_t *cboutTAxDirRegister; // CBOUT_TA0CLK
  290. uint8_t *cboutTAxSelRegister; // CBOUT_TA0CLK
  291. uint8_t cboutTAxBits; // Bit field for register
  292. uint16_t cbpdBits;
  293. #endif
  294. //*****************************************************************************
  295. // Timer definitions
  296. // The basic premise is to count a number of clock cycles within a time
  297. // period, where either the clock source or the timer period is a function
  298. // of the element capacitance.
  299. //
  300. // RC Method:
  301. // Period: accumulationCycles * charge and discharge time of RC
  302. // circuit where C is captouch element
  303. //
  304. // clock source: measGateSource/sourceScale
  305. // RO Method:
  306. // Period: accumulationCycles*measGateSource/sourceScale
  307. // (with WDT sourceScale = 1, accumulationCycles is WDT control
  308. // register settings)
  309. //
  310. // clock source: relaxation oscillator where freq is a function of C
  311. //
  312. // fRO Method:
  313. // Period: accumulationCycles * 1/freq, freq is a function of C
  314. //
  315. // clock source: measGateSource/sourceScale
  316. uint16_t measGateSource; // RC+FastRO: measurement timer source,
  317. // {ACLK, TACLK, SMCLK}
  318. // Comp_RO+PinOsc: gate timer source,
  319. // {ACLK, TACLK, SMCLK}
  320. uint16_t sourceScale; // Comp_RO+FastRO+PinOsc: gate timer,
  321. // TA/TB/TD, scale: 1,1/2,1/4,1/8
  322. // RC+FastRO: measurement timer, TA/TB/TD
  323. // scale: 16, 8, 4, 2, 1, �, �, 1/8
  324. uint16_t accumulationCycles;
  325. //*****************************************************************************
  326. // Other definitions
  327. #ifdef SLIDER_WHEEL
  328. uint8_t points; // Special Case: Number of points
  329. // along slider or wheel
  330. uint8_t sensorThreshold;
  331. #endif
  332. };
  333. //******************************************************************************
  334. // The scheduler structure manages each handler group (CT_Handler object) using
  335. // one timer resource.
  336. // TBD
  337. //******************************************************************************
  338. struct CT_scheduler{
  339. void *callBacks;
  340. // pointer to function in the main application (can be an array of functions
  341. // if multiple groups). The order is important! The pointer here must point
  342. // to the first CT_Handler object!
  343. struct CT_Handler *handler; // order of this and *call_backs
  344. // must be the same.
  345. uint8_t Enable; // Each bit in this value will show
  346. // if the given group element
  347. // is being sheduled & measured.
  348. uint8_t delayTimer; // delay timer, {SW,WDT, TimerA,
  349. // TimerB, TimerD}
  350. uint8_t delayTimerSrc; // delay timer source,
  351. // {ACLK, TACLK, SMCLK}
  352. uint8_t delayTimerScale; // delay time scale (/1,/2,/4,/8)
  353. uint8_t delayTime; // wdt: delay {32768,8192,512,64}
  354. // RO+FastRO+PinOsc(TimerA,B,D):
  355. // delay time {257+x*256}
  356. };
  357. #endif