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

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

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

Who changed what in which revision?

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