mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_STM/analogin_api.c@181:57724642e740, 2018-02-16 (annotated)
- Committer:
- AnnaBridge
- Date:
- Fri Feb 16 16:09:33 2018 +0000
- Revision:
- 181:57724642e740
- Parent:
- 180:96ed750bd169
- Child:
- 189:f392fc9709a3
mbed-dev library. Release version 159.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anna Bridge |
180:96ed750bd169 | 1 | /* mbed Microcontroller Library |
Anna Bridge |
180:96ed750bd169 | 2 | * Copyright (c) 2017, STMicroelectronics |
Anna Bridge |
180:96ed750bd169 | 3 | * All rights reserved. |
Anna Bridge |
180:96ed750bd169 | 4 | * |
Anna Bridge |
180:96ed750bd169 | 5 | * Redistribution and use in source and binary forms, with or without |
Anna Bridge |
180:96ed750bd169 | 6 | * modification, are permitted provided that the following conditions are met: |
Anna Bridge |
180:96ed750bd169 | 7 | * |
Anna Bridge |
180:96ed750bd169 | 8 | * 1. Redistributions of source code must retain the above copyright notice, |
Anna Bridge |
180:96ed750bd169 | 9 | * this list of conditions and the following disclaimer. |
Anna Bridge |
180:96ed750bd169 | 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Anna Bridge |
180:96ed750bd169 | 11 | * this list of conditions and the following disclaimer in the documentation |
Anna Bridge |
180:96ed750bd169 | 12 | * and/or other materials provided with the distribution. |
Anna Bridge |
180:96ed750bd169 | 13 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Anna Bridge |
180:96ed750bd169 | 14 | * may be used to endorse or promote products derived from this software |
Anna Bridge |
180:96ed750bd169 | 15 | * without specific prior written permission. |
Anna Bridge |
180:96ed750bd169 | 16 | * |
Anna Bridge |
180:96ed750bd169 | 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Anna Bridge |
180:96ed750bd169 | 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Anna Bridge |
180:96ed750bd169 | 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Anna Bridge |
180:96ed750bd169 | 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Anna Bridge |
180:96ed750bd169 | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Anna Bridge |
180:96ed750bd169 | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Anna Bridge |
180:96ed750bd169 | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Anna Bridge |
180:96ed750bd169 | 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Anna Bridge |
180:96ed750bd169 | 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Anna Bridge |
180:96ed750bd169 | 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Anna Bridge |
180:96ed750bd169 | 27 | */ |
Anna Bridge |
180:96ed750bd169 | 28 | #include "analogin_api.h" |
Anna Bridge |
180:96ed750bd169 | 29 | |
Anna Bridge |
180:96ed750bd169 | 30 | #if DEVICE_ANALOGIN |
Anna Bridge |
180:96ed750bd169 | 31 | |
Anna Bridge |
180:96ed750bd169 | 32 | uint16_t adc_read(analogin_t *obj); |
Anna Bridge |
180:96ed750bd169 | 33 | |
Anna Bridge |
180:96ed750bd169 | 34 | uint16_t analogin_read_u16(analogin_t *obj) |
Anna Bridge |
180:96ed750bd169 | 35 | { |
Anna Bridge |
180:96ed750bd169 | 36 | uint16_t value = adc_read(obj); |
Anna Bridge |
180:96ed750bd169 | 37 | // 12-bit to 16-bit conversion |
Anna Bridge |
180:96ed750bd169 | 38 | value = ((value << 4) & (uint16_t)0xFFF0) | ((value >> 8) & (uint16_t)0x000F); |
Anna Bridge |
180:96ed750bd169 | 39 | return value; |
Anna Bridge |
180:96ed750bd169 | 40 | } |
Anna Bridge |
180:96ed750bd169 | 41 | |
Anna Bridge |
180:96ed750bd169 | 42 | float analogin_read(analogin_t *obj) |
Anna Bridge |
180:96ed750bd169 | 43 | { |
Anna Bridge |
180:96ed750bd169 | 44 | uint16_t value = adc_read(obj); |
Anna Bridge |
180:96ed750bd169 | 45 | return (float)value * (1.0f / (float)0xFFF); // 12 bits range |
Anna Bridge |
180:96ed750bd169 | 46 | } |
Anna Bridge |
180:96ed750bd169 | 47 | |
Anna Bridge |
180:96ed750bd169 | 48 | #endif |