Subversion Repositories svn.mios32

Rev

Rev 1643 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
90 tk 1
// $Id: mios32_ain.h 1960 2014-02-09 20:21:24Z tk $
2
/*
3
 * Header file for AIN Driver
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2008 Thorsten Klose (tk@midibox.org)
8
 *  Licensed for personal non-commercial use only.
9
 *  All other rights reserved.
10
 *
11
 * ==========================================================================
12
 */
13
 
14
#ifndef _MIOS32_AIN_H
15
#define _MIOS32_AIN_H
16
 
17
/////////////////////////////////////////////////////////////////////////////
18
// Global definitions
19
/////////////////////////////////////////////////////////////////////////////
20
 
21
// bit mask to enable channels
22
//
23
// Pin mapping on MBHP_CORE_STM32 module:
24
//   15       14      13     12     11     10      9      8   
25
// J16.SO  J16.SI  J16.SC J16.RC J5C.A11 J5C.A10 J5C.A9 J5C.A8
26
//   7        6       5      4      3      2      1       0
27
// J5B.A7  J5B.A6  J5B.A5 J5B.A4 J5A.A3 J5A.A2 J5A.A1  J5A.A0
28
//
29
// Examples:
30
//   mask 0x000f will enable all J5A channels
31
//   mask 0x00f0 will enable all J5B channels
32
//   mask 0x0f00 will enable all J5C channels
33
//   mask 0x0fff will enable all J5A/B/C channels
34
// (all channels are disabled by default)
35
#ifndef MIOS32_AIN_CHANNEL_MASK
36
#define MIOS32_AIN_CHANNEL_MASK 0
37
#endif
38
 
39
 
1960 tk 40
//! Normally the ADC channels are converted each mS from the programming
41
//! model (main.c) - optionally this can be skipped with
42
//! #define MIOS32_DONT_SERVICE_AIN 1 in mios32_config.h
43
//! 
44
//! In this case, the MIOS32_AIN_StartConversions() function has to be called
45
//! periodically from the application (e.g. from a timer), and conversion values
46
//! can be retrieved with MIOS32_AIN_PinGet()
47
#ifndef MIOS32_DONT_SERVICE_AIN
48
#define MIOS32_DONT_SERVICE_AIN 0
49
#endif
50
 
51
 
90 tk 52
// define the desired oversampling rate (1..16)
53
#ifndef MIOS32_AIN_OVERSAMPLING_RATE
54
#define MIOS32_AIN_OVERSAMPLING_RATE  1
55
#endif
56
 
57
 
58
// define the deadband (min. difference to report a change to the application hook)
59
// 31 is enough for 7bit resolution at 12bit sampling resolution (1x oversampling)
60
#ifndef MIOS32_AIN_DEADBAND
61
#define MIOS32_AIN_DEADBAND 31
62
#endif
63
 
64
 
731 tk 65
// define the deadband which is used when an AIN pin is in "idle" state
66
// this helps to avoid sporadical jittering values
67
// Set this value to 0 to disable the feature (it's enabled by default)
68
#ifndef MIOS32_AIN_DEADBAND_IDLE
69
#define MIOS32_AIN_DEADBAND_IDLE 127
70
#endif
71
 
72
// define after how many conversions the AIN pin should go into "idle" state
73
// - "idle" state is left once MIOS32_AIN_DEADBAND_IDLE is exceeded.
74
// - "idle" state is entered once MIOS32_AIN_DEADBAND hasn't been exceeded for 
75
//   MIOS32_AIN_IDLE_CTR conversions
76
// 3000 conversions are done in ca. 3 seconds (depends on number of pins!)
77
// allowed range: 1..65535
78
#ifndef MIOS32_AIN_IDLE_CTR
79
#define MIOS32_AIN_IDLE_CTR 3000
80
#endif
81
 
82
 
90 tk 83
// muxed or unmuxed mode (0..3)?
84
// 0 == unmuxed mode
85
// 1 == 1 mux control line -> *2 channels
86
// 2 == 2 mux control line -> *4 channels
87
// 3 == 3 mux control line -> *8 channels
88
#ifndef MIOS32_AIN_MUX_PINS
89
#define MIOS32_AIN_MUX_PINS 0
90
#endif
91
 
92
 
93
// control pins to select the muxed channel
385 tk 94
// only relevant if MIOS32_AIN_MUX_PINS > 0
90 tk 95
#ifndef MIOS32_AIN_MUX0_PIN
96
#define MIOS32_AIN_MUX0_PIN   GPIO_Pin_4 // J5C.A8
97
#endif
98
#ifndef MIOS32_AIN_MUX0_PORT
99
#define MIOS32_AIN_MUX0_PORT  GPIOC
100
#endif
101
 
102
#ifndef MIOS32_AIN_MUX1_PIN
103
#define MIOS32_AIN_MUX1_PIN   GPIO_Pin_5 // J5C.A9
104
#endif
105
#ifndef MIOS32_AIN_MUX1_PORT
106
#define MIOS32_AIN_MUX1_PORT  GPIOC
107
#endif
108
 
109
#ifndef MIOS32_AIN_MUX2_PIN
110
#define MIOS32_AIN_MUX2_PIN   GPIO_Pin_0 // J5C.A10
111
#endif
112
#ifndef MIOS32_AIN_MUX2_PORT
113
#define MIOS32_AIN_MUX2_PORT  GPIOB
114
#endif
115
 
116
 
117
/////////////////////////////////////////////////////////////////////////////
118
// Global Types
119
/////////////////////////////////////////////////////////////////////////////
120
 
121
 
122
/////////////////////////////////////////////////////////////////////////////
123
// Prototypes
124
/////////////////////////////////////////////////////////////////////////////
125
 
126
extern s32 MIOS32_AIN_Init(u32 mode);
127
 
347 tk 128
extern s32 MIOS32_AIN_ServicePrepareCallback_Init(void *_service_prepare_callback);
129
 
92 tk 130
extern s32 MIOS32_AIN_PinGet(u32 pin);
90 tk 131
 
1373 tk 132
extern s32 MIOS32_AIN_DeadbandGet(void);
1643 tk 133
extern s32 MIOS32_AIN_DeadbandSet(u16 deadband);
1373 tk 134
 
90 tk 135
extern s32 MIOS32_AIN_Handler(void *callback);
136
 
1960 tk 137
extern s32 MIOS32_AIN_StartConversions(void);
90 tk 138
 
1960 tk 139
 
90 tk 140
/////////////////////////////////////////////////////////////////////////////
141
// Export global variables
142
/////////////////////////////////////////////////////////////////////////////
143
 
144
 
145
#endif /* _MIOS32_AIN_H */