PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
Pokitto
Date:
Sat Oct 07 21:31:12 2017 +0000
Revision:
5:7e5c566b1760
mbed-pokitto integrated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 5:7e5c566b1760 1 /* mbed Microcontroller Library
Pokitto 5:7e5c566b1760 2 * Copyright (c) 2006-2013 ARM Limited
Pokitto 5:7e5c566b1760 3 *
Pokitto 5:7e5c566b1760 4 * Licensed under the Apache License, Version 2.0 (the "License");
Pokitto 5:7e5c566b1760 5 * you may not use this file except in compliance with the License.
Pokitto 5:7e5c566b1760 6 * You may obtain a copy of the License at
Pokitto 5:7e5c566b1760 7 *
Pokitto 5:7e5c566b1760 8 * http://www.apache.org/licenses/LICENSE-2.0
Pokitto 5:7e5c566b1760 9 *
Pokitto 5:7e5c566b1760 10 * Unless required by applicable law or agreed to in writing, software
Pokitto 5:7e5c566b1760 11 * distributed under the License is distributed on an "AS IS" BASIS,
Pokitto 5:7e5c566b1760 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pokitto 5:7e5c566b1760 13 * See the License for the specific language governing permissions and
Pokitto 5:7e5c566b1760 14 * limitations under the License.
Pokitto 5:7e5c566b1760 15 */
Pokitto 5:7e5c566b1760 16 #ifndef MBED_ANALOGOUT_H
Pokitto 5:7e5c566b1760 17 #define MBED_ANALOGOUT_H
Pokitto 5:7e5c566b1760 18
Pokitto 5:7e5c566b1760 19 #include "platform.h"
Pokitto 5:7e5c566b1760 20
Pokitto 5:7e5c566b1760 21 #if DEVICE_ANALOGOUT
Pokitto 5:7e5c566b1760 22
Pokitto 5:7e5c566b1760 23 #include "analogout_api.h"
Pokitto 5:7e5c566b1760 24
Pokitto 5:7e5c566b1760 25 namespace mbed {
Pokitto 5:7e5c566b1760 26
Pokitto 5:7e5c566b1760 27 /** An analog output, used for setting the voltage on a pin
Pokitto 5:7e5c566b1760 28 *
Pokitto 5:7e5c566b1760 29 * Example:
Pokitto 5:7e5c566b1760 30 * @code
Pokitto 5:7e5c566b1760 31 * // Make a sawtooth output
Pokitto 5:7e5c566b1760 32 *
Pokitto 5:7e5c566b1760 33 * #include "mbed.h"
Pokitto 5:7e5c566b1760 34 *
Pokitto 5:7e5c566b1760 35 * AnalogOut tri(p18);
Pokitto 5:7e5c566b1760 36 * int main() {
Pokitto 5:7e5c566b1760 37 * while(1) {
Pokitto 5:7e5c566b1760 38 * tri = tri + 0.01;
Pokitto 5:7e5c566b1760 39 * wait_us(1);
Pokitto 5:7e5c566b1760 40 * if(tri == 1) {
Pokitto 5:7e5c566b1760 41 * tri = 0;
Pokitto 5:7e5c566b1760 42 * }
Pokitto 5:7e5c566b1760 43 * }
Pokitto 5:7e5c566b1760 44 * }
Pokitto 5:7e5c566b1760 45 * @endcode
Pokitto 5:7e5c566b1760 46 */
Pokitto 5:7e5c566b1760 47 class AnalogOut {
Pokitto 5:7e5c566b1760 48
Pokitto 5:7e5c566b1760 49 public:
Pokitto 5:7e5c566b1760 50
Pokitto 5:7e5c566b1760 51 /** Create an AnalogOut connected to the specified pin
Pokitto 5:7e5c566b1760 52 *
Pokitto 5:7e5c566b1760 53 * @param AnalogOut pin to connect to (18)
Pokitto 5:7e5c566b1760 54 */
Pokitto 5:7e5c566b1760 55 AnalogOut(PinName pin) {
Pokitto 5:7e5c566b1760 56 analogout_init(&_dac, pin);
Pokitto 5:7e5c566b1760 57 }
Pokitto 5:7e5c566b1760 58
Pokitto 5:7e5c566b1760 59 /** Set the output voltage, specified as a percentage (float)
Pokitto 5:7e5c566b1760 60 *
Pokitto 5:7e5c566b1760 61 * @param value A floating-point value representing the output voltage,
Pokitto 5:7e5c566b1760 62 * specified as a percentage. The value should lie between
Pokitto 5:7e5c566b1760 63 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
Pokitto 5:7e5c566b1760 64 * Values outside this range will be saturated to 0.0f or 1.0f.
Pokitto 5:7e5c566b1760 65 */
Pokitto 5:7e5c566b1760 66 void write(float value) {
Pokitto 5:7e5c566b1760 67 analogout_write(&_dac, value);
Pokitto 5:7e5c566b1760 68 }
Pokitto 5:7e5c566b1760 69
Pokitto 5:7e5c566b1760 70 /** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
Pokitto 5:7e5c566b1760 71 *
Pokitto 5:7e5c566b1760 72 * @param value 16-bit unsigned short representing the output voltage,
Pokitto 5:7e5c566b1760 73 * normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
Pokitto 5:7e5c566b1760 74 */
Pokitto 5:7e5c566b1760 75 void write_u16(unsigned short value) {
Pokitto 5:7e5c566b1760 76 analogout_write_u16(&_dac, value);
Pokitto 5:7e5c566b1760 77 }
Pokitto 5:7e5c566b1760 78
Pokitto 5:7e5c566b1760 79 /** Return the current output voltage setting, measured as a percentage (float)
Pokitto 5:7e5c566b1760 80 *
Pokitto 5:7e5c566b1760 81 * @returns
Pokitto 5:7e5c566b1760 82 * A floating-point value representing the current voltage being output on the pin,
Pokitto 5:7e5c566b1760 83 * measured as a percentage. The returned value will lie between
Pokitto 5:7e5c566b1760 84 * 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
Pokitto 5:7e5c566b1760 85 *
Pokitto 5:7e5c566b1760 86 * @note
Pokitto 5:7e5c566b1760 87 * This value may not match exactly the value set by a previous write().
Pokitto 5:7e5c566b1760 88 */
Pokitto 5:7e5c566b1760 89 float read() {
Pokitto 5:7e5c566b1760 90 return analogout_read(&_dac);
Pokitto 5:7e5c566b1760 91 }
Pokitto 5:7e5c566b1760 92
Pokitto 5:7e5c566b1760 93 #ifdef MBED_OPERATORS
Pokitto 5:7e5c566b1760 94 /** An operator shorthand for write()
Pokitto 5:7e5c566b1760 95 */
Pokitto 5:7e5c566b1760 96 AnalogOut& operator= (float percent) {
Pokitto 5:7e5c566b1760 97 write(percent);
Pokitto 5:7e5c566b1760 98 return *this;
Pokitto 5:7e5c566b1760 99 }
Pokitto 5:7e5c566b1760 100
Pokitto 5:7e5c566b1760 101 AnalogOut& operator= (AnalogOut& rhs) {
Pokitto 5:7e5c566b1760 102 write(rhs.read());
Pokitto 5:7e5c566b1760 103 return *this;
Pokitto 5:7e5c566b1760 104 }
Pokitto 5:7e5c566b1760 105
Pokitto 5:7e5c566b1760 106 /** An operator shorthand for read()
Pokitto 5:7e5c566b1760 107 */
Pokitto 5:7e5c566b1760 108 operator float() {
Pokitto 5:7e5c566b1760 109 return read();
Pokitto 5:7e5c566b1760 110 }
Pokitto 5:7e5c566b1760 111 #endif
Pokitto 5:7e5c566b1760 112
Pokitto 5:7e5c566b1760 113 protected:
Pokitto 5:7e5c566b1760 114 dac_t _dac;
Pokitto 5:7e5c566b1760 115 };
Pokitto 5:7e5c566b1760 116
Pokitto 5:7e5c566b1760 117 } // namespace mbed
Pokitto 5:7e5c566b1760 118
Pokitto 5:7e5c566b1760 119 #endif
Pokitto 5:7e5c566b1760 120
Pokitto 5:7e5c566b1760 121 #endif