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

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Wed Dec 25 23:59:52 2019 +0000
Revision:
71:531419862202
Parent:
5:ea7377f3d1af
Changed Mode2 C++ refresh code (graphical errors)

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_SPISLAVE_H
Pokitto 5:ea7377f3d1af 17 #define MBED_SPISLAVE_H
Pokitto 5:ea7377f3d1af 18
Pokitto 5:ea7377f3d1af 19 #include "platform.h"
Pokitto 5:ea7377f3d1af 20
Pokitto 5:ea7377f3d1af 21 #if DEVICE_SPISLAVE
Pokitto 5:ea7377f3d1af 22
Pokitto 5:ea7377f3d1af 23 #include "spi_api.h"
Pokitto 5:ea7377f3d1af 24
Pokitto 5:ea7377f3d1af 25 namespace mbed {
Pokitto 5:ea7377f3d1af 26
Pokitto 5:ea7377f3d1af 27 /** A SPI slave, used for communicating with a SPI Master device
Pokitto 5:ea7377f3d1af 28 *
Pokitto 5:ea7377f3d1af 29 * The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
Pokitto 5:ea7377f3d1af 30 *
Pokitto 5:ea7377f3d1af 31 * Example:
Pokitto 5:ea7377f3d1af 32 * @code
Pokitto 5:ea7377f3d1af 33 * // Reply to a SPI master as slave
Pokitto 5:ea7377f3d1af 34 *
Pokitto 5:ea7377f3d1af 35 * #include "mbed.h"
Pokitto 5:ea7377f3d1af 36 *
Pokitto 5:ea7377f3d1af 37 * SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
Pokitto 5:ea7377f3d1af 38 *
Pokitto 5:ea7377f3d1af 39 * int main() {
Pokitto 5:ea7377f3d1af 40 * device.reply(0x00); // Prime SPI with first reply
Pokitto 5:ea7377f3d1af 41 * while(1) {
Pokitto 5:ea7377f3d1af 42 * if(device.receive()) {
Pokitto 5:ea7377f3d1af 43 * int v = device.read(); // Read byte from master
Pokitto 5:ea7377f3d1af 44 * v = (v + 1) % 0x100; // Add one to it, modulo 256
Pokitto 5:ea7377f3d1af 45 * device.reply(v); // Make this the next reply
Pokitto 5:ea7377f3d1af 46 * }
Pokitto 5:ea7377f3d1af 47 * }
Pokitto 5:ea7377f3d1af 48 * }
Pokitto 5:ea7377f3d1af 49 * @endcode
Pokitto 5:ea7377f3d1af 50 */
Pokitto 5:ea7377f3d1af 51 class SPISlave {
Pokitto 5:ea7377f3d1af 52
Pokitto 5:ea7377f3d1af 53 public:
Pokitto 5:ea7377f3d1af 54
Pokitto 5:ea7377f3d1af 55 /** Create a SPI slave connected to the specified pins
Pokitto 5:ea7377f3d1af 56 *
Pokitto 5:ea7377f3d1af 57 * mosi or miso can be specfied as NC if not used
Pokitto 5:ea7377f3d1af 58 *
Pokitto 5:ea7377f3d1af 59 * @param mosi SPI Master Out, Slave In pin
Pokitto 5:ea7377f3d1af 60 * @param miso SPI Master In, Slave Out pin
Pokitto 5:ea7377f3d1af 61 * @param sclk SPI Clock pin
Pokitto 5:ea7377f3d1af 62 * @param ssel SPI chip select pin
Pokitto 5:ea7377f3d1af 63 */
Pokitto 5:ea7377f3d1af 64 SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel);
Pokitto 5:ea7377f3d1af 65
Pokitto 5:ea7377f3d1af 66 /** Configure the data transmission format
Pokitto 5:ea7377f3d1af 67 *
Pokitto 5:ea7377f3d1af 68 * @param bits Number of bits per SPI frame (4 - 16)
Pokitto 5:ea7377f3d1af 69 * @param mode Clock polarity and phase mode (0 - 3)
Pokitto 5:ea7377f3d1af 70 *
Pokitto 5:ea7377f3d1af 71 * @code
Pokitto 5:ea7377f3d1af 72 * mode | POL PHA
Pokitto 5:ea7377f3d1af 73 * -----+--------
Pokitto 5:ea7377f3d1af 74 * 0 | 0 0
Pokitto 5:ea7377f3d1af 75 * 1 | 0 1
Pokitto 5:ea7377f3d1af 76 * 2 | 1 0
Pokitto 5:ea7377f3d1af 77 * 3 | 1 1
Pokitto 5:ea7377f3d1af 78 * @endcode
Pokitto 5:ea7377f3d1af 79 */
Pokitto 5:ea7377f3d1af 80 void format(int bits, int mode = 0);
Pokitto 5:ea7377f3d1af 81
Pokitto 5:ea7377f3d1af 82 /** Set the spi bus clock frequency
Pokitto 5:ea7377f3d1af 83 *
Pokitto 5:ea7377f3d1af 84 * @param hz SCLK frequency in hz (default = 1MHz)
Pokitto 5:ea7377f3d1af 85 */
Pokitto 5:ea7377f3d1af 86 void frequency(int hz = 1000000);
Pokitto 5:ea7377f3d1af 87
Pokitto 5:ea7377f3d1af 88 /** Polls the SPI to see if data has been received
Pokitto 5:ea7377f3d1af 89 *
Pokitto 5:ea7377f3d1af 90 * @returns
Pokitto 5:ea7377f3d1af 91 * 0 if no data,
Pokitto 5:ea7377f3d1af 92 * 1 otherwise
Pokitto 5:ea7377f3d1af 93 */
Pokitto 5:ea7377f3d1af 94 int receive(void);
Pokitto 5:ea7377f3d1af 95
Pokitto 5:ea7377f3d1af 96 /** Retrieve data from receive buffer as slave
Pokitto 5:ea7377f3d1af 97 *
Pokitto 5:ea7377f3d1af 98 * @returns
Pokitto 5:ea7377f3d1af 99 * the data in the receive buffer
Pokitto 5:ea7377f3d1af 100 */
Pokitto 5:ea7377f3d1af 101 int read(void);
Pokitto 5:ea7377f3d1af 102
Pokitto 5:ea7377f3d1af 103 /** Fill the transmission buffer with the value to be written out
Pokitto 5:ea7377f3d1af 104 * as slave on the next received message from the master.
Pokitto 5:ea7377f3d1af 105 *
Pokitto 5:ea7377f3d1af 106 * @param value the data to be transmitted next
Pokitto 5:ea7377f3d1af 107 */
Pokitto 5:ea7377f3d1af 108 void reply(int value);
Pokitto 5:ea7377f3d1af 109
Pokitto 5:ea7377f3d1af 110 protected:
Pokitto 5:ea7377f3d1af 111 spi_t _spi;
Pokitto 5:ea7377f3d1af 112
Pokitto 5:ea7377f3d1af 113 int _bits;
Pokitto 5:ea7377f3d1af 114 int _mode;
Pokitto 5:ea7377f3d1af 115 int _hz;
Pokitto 5:ea7377f3d1af 116 };
Pokitto 5:ea7377f3d1af 117
Pokitto 5:ea7377f3d1af 118 } // namespace mbed
Pokitto 5:ea7377f3d1af 119
Pokitto 5:ea7377f3d1af 120 #endif
Pokitto 5:ea7377f3d1af 121
Pokitto 5:ea7377f3d1af 122 #endif