analogIn with DMA
AnaloginDMA.h@4:2844a210bd46, 2015-01-03 (annotated)
- Committer:
- willybayot
- Date:
- Sat Jan 03 15:41:29 2015 +0000
- Revision:
- 4:2844a210bd46
- Parent:
- 2:08779d8f1873
revision 2;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
willybayot | 0:1f6ea9afd585 | 1 | /* mbed Microcontroller Library |
willybayot | 0:1f6ea9afd585 | 2 | * Copyright (c) 2006-2013 ARM Limited |
willybayot | 0:1f6ea9afd585 | 3 | * |
willybayot | 0:1f6ea9afd585 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
willybayot | 0:1f6ea9afd585 | 5 | * you may not use this file except in compliance with the License. |
willybayot | 0:1f6ea9afd585 | 6 | * You may obtain a copy of the License at |
willybayot | 0:1f6ea9afd585 | 7 | * |
willybayot | 0:1f6ea9afd585 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
willybayot | 0:1f6ea9afd585 | 9 | * |
willybayot | 0:1f6ea9afd585 | 10 | * Unless required by applicable law or agreed to in writing, software |
willybayot | 0:1f6ea9afd585 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
willybayot | 0:1f6ea9afd585 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
willybayot | 0:1f6ea9afd585 | 13 | * See the License for the specific language governing permissions and |
willybayot | 0:1f6ea9afd585 | 14 | * limitations under the License. |
willybayot | 0:1f6ea9afd585 | 15 | */ |
willybayot | 0:1f6ea9afd585 | 16 | #ifndef MBED_ANALOGINDMA_H |
willybayot | 0:1f6ea9afd585 | 17 | #define MBED_ANALOGINDMA_H |
willybayot | 0:1f6ea9afd585 | 18 | |
willybayot | 0:1f6ea9afd585 | 19 | #include "platform.h" |
willybayot | 0:1f6ea9afd585 | 20 | |
willybayot | 0:1f6ea9afd585 | 21 | #if DEVICE_ANALOGIN |
willybayot | 0:1f6ea9afd585 | 22 | |
willybayot | 0:1f6ea9afd585 | 23 | #include "analoginDMA_api.h" |
willybayot | 0:1f6ea9afd585 | 24 | |
willybayot | 0:1f6ea9afd585 | 25 | |
willybayot | 0:1f6ea9afd585 | 26 | namespace mbed { |
willybayot | 0:1f6ea9afd585 | 27 | |
willybayot | 0:1f6ea9afd585 | 28 | /** An analog input, used for reading the voltage on a pin |
willybayot | 0:1f6ea9afd585 | 29 | * |
willybayot | 0:1f6ea9afd585 | 30 | * Example: |
willybayot | 0:1f6ea9afd585 | 31 | * @code |
willybayot | 0:1f6ea9afd585 | 32 | * // Print messages when the AnalogIn is greater than 50% |
willybayot | 0:1f6ea9afd585 | 33 | * |
willybayot | 0:1f6ea9afd585 | 34 | * #include "mbed.h" |
willybayot | 0:1f6ea9afd585 | 35 | * |
willybayot | 0:1f6ea9afd585 | 36 | * AnalogIn temperature(p20); |
willybayot | 0:1f6ea9afd585 | 37 | * |
willybayot | 0:1f6ea9afd585 | 38 | * int main() { |
willybayot | 0:1f6ea9afd585 | 39 | * while(1) { |
willybayot | 0:1f6ea9afd585 | 40 | * if(temperature > 0.5) { |
willybayot | 0:1f6ea9afd585 | 41 | * printf("Too hot! (%f)", temperature.read()); |
willybayot | 0:1f6ea9afd585 | 42 | * } |
willybayot | 0:1f6ea9afd585 | 43 | * } |
willybayot | 0:1f6ea9afd585 | 44 | * } |
willybayot | 0:1f6ea9afd585 | 45 | * @endcode |
willybayot | 0:1f6ea9afd585 | 46 | */ |
willybayot | 0:1f6ea9afd585 | 47 | class AnalogInDMA { |
willybayot | 0:1f6ea9afd585 | 48 | |
willybayot | 0:1f6ea9afd585 | 49 | public: |
willybayot | 0:1f6ea9afd585 | 50 | |
willybayot | 0:1f6ea9afd585 | 51 | /** Create an AnalogIn, connected to the specified pin |
willybayot | 0:1f6ea9afd585 | 52 | * |
willybayot | 0:1f6ea9afd585 | 53 | * @param pin AnalogIn pin to connect to |
willybayot | 0:1f6ea9afd585 | 54 | * @param name (optional) A string to identify the object |
willybayot | 0:1f6ea9afd585 | 55 | */ |
willybayot | 0:1f6ea9afd585 | 56 | AnalogInDMA(PinName pin) { |
willybayot | 0:1f6ea9afd585 | 57 | analoginDMA_init(&_adc, pin); |
willybayot | 0:1f6ea9afd585 | 58 | } |
willybayot | 0:1f6ea9afd585 | 59 | |
willybayot | 2:08779d8f1873 | 60 | |
willybayot | 4:2844a210bd46 | 61 | /** Read the 'Length' input voltage(s), represented as an array of unsigned short pData |
willybayot | 0:1f6ea9afd585 | 62 | * |
willybayot | 4:2844a210bd46 | 63 | * @returns status: 0 = OK, 1 = ERROR, 2=BUSY, 3 = TIMEOUT |
willybayot | 0:1f6ea9afd585 | 64 | */ |
willybayot | 4:2844a210bd46 | 65 | HAL_StatusTypeDef read(uint16_t* pData, uint32_t Length) { |
willybayot | 4:2844a210bd46 | 66 | return analoginDMA_read_u16(&_adc, pData, Length); |
willybayot | 0:1f6ea9afd585 | 67 | } |
willybayot | 0:1f6ea9afd585 | 68 | |
willybayot | 0:1f6ea9afd585 | 69 | |
willybayot | 0:1f6ea9afd585 | 70 | protected: |
willybayot | 0:1f6ea9afd585 | 71 | analogin_t _adc; |
willybayot | 0:1f6ea9afd585 | 72 | }; |
willybayot | 0:1f6ea9afd585 | 73 | |
willybayot | 0:1f6ea9afd585 | 74 | } // namespace mbed |
willybayot | 0:1f6ea9afd585 | 75 | |
willybayot | 0:1f6ea9afd585 | 76 | #endif |
willybayot | 0:1f6ea9afd585 | 77 | |
willybayot | 0:1f6ea9afd585 | 78 | #endif |