PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Committer:
Pokitto
Date:
Wed Oct 11 20:35:27 2017 +0000
Revision:
5:ea7377f3d1af
Fixed PokittoLib. Includes a working custom mbed-src

Who changed what in which revision?

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