Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Wed Oct 10 00:33:53 2018 +0000
Revision:
0:8fdf9a60065b
how to make mbed librry

Who changed what in which revision?

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