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_ETHERNET_H
Pokitto 5:ea7377f3d1af 17 #define MBED_ETHERNET_H
Pokitto 5:ea7377f3d1af 18
Pokitto 5:ea7377f3d1af 19 #include "platform.h"
Pokitto 5:ea7377f3d1af 20
Pokitto 5:ea7377f3d1af 21 #if DEVICE_ETHERNET
Pokitto 5:ea7377f3d1af 22
Pokitto 5:ea7377f3d1af 23 namespace mbed {
Pokitto 5:ea7377f3d1af 24
Pokitto 5:ea7377f3d1af 25 /** An ethernet interface, to use with the ethernet pins.
Pokitto 5:ea7377f3d1af 26 *
Pokitto 5:ea7377f3d1af 27 * Example:
Pokitto 5:ea7377f3d1af 28 * @code
Pokitto 5:ea7377f3d1af 29 * // Read destination and source from every ethernet packet
Pokitto 5:ea7377f3d1af 30 *
Pokitto 5:ea7377f3d1af 31 * #include "mbed.h"
Pokitto 5:ea7377f3d1af 32 *
Pokitto 5:ea7377f3d1af 33 * Ethernet eth;
Pokitto 5:ea7377f3d1af 34 *
Pokitto 5:ea7377f3d1af 35 * int main() {
Pokitto 5:ea7377f3d1af 36 * char buf[0x600];
Pokitto 5:ea7377f3d1af 37 *
Pokitto 5:ea7377f3d1af 38 * while(1) {
Pokitto 5:ea7377f3d1af 39 * int size = eth.receive();
Pokitto 5:ea7377f3d1af 40 * if(size > 0) {
Pokitto 5:ea7377f3d1af 41 * eth.read(buf, size);
Pokitto 5:ea7377f3d1af 42 * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
Pokitto 5:ea7377f3d1af 43 * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
Pokitto 5:ea7377f3d1af 44 * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
Pokitto 5:ea7377f3d1af 45 * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
Pokitto 5:ea7377f3d1af 46 * }
Pokitto 5:ea7377f3d1af 47 *
Pokitto 5:ea7377f3d1af 48 * wait(1);
Pokitto 5:ea7377f3d1af 49 * }
Pokitto 5:ea7377f3d1af 50 * }
Pokitto 5:ea7377f3d1af 51 * @endcode
Pokitto 5:ea7377f3d1af 52 */
Pokitto 5:ea7377f3d1af 53 class Ethernet {
Pokitto 5:ea7377f3d1af 54
Pokitto 5:ea7377f3d1af 55 public:
Pokitto 5:ea7377f3d1af 56
Pokitto 5:ea7377f3d1af 57 /** Initialise the ethernet interface.
Pokitto 5:ea7377f3d1af 58 */
Pokitto 5:ea7377f3d1af 59 Ethernet();
Pokitto 5:ea7377f3d1af 60
Pokitto 5:ea7377f3d1af 61 /** Powers the hardware down.
Pokitto 5:ea7377f3d1af 62 */
Pokitto 5:ea7377f3d1af 63 virtual ~Ethernet();
Pokitto 5:ea7377f3d1af 64
Pokitto 5:ea7377f3d1af 65 enum Mode {
Pokitto 5:ea7377f3d1af 66 AutoNegotiate,
Pokitto 5:ea7377f3d1af 67 HalfDuplex10,
Pokitto 5:ea7377f3d1af 68 FullDuplex10,
Pokitto 5:ea7377f3d1af 69 HalfDuplex100,
Pokitto 5:ea7377f3d1af 70 FullDuplex100
Pokitto 5:ea7377f3d1af 71 };
Pokitto 5:ea7377f3d1af 72
Pokitto 5:ea7377f3d1af 73 /** Writes into an outgoing ethernet packet.
Pokitto 5:ea7377f3d1af 74 *
Pokitto 5:ea7377f3d1af 75 * It will append size bytes of data to the previously written bytes.
Pokitto 5:ea7377f3d1af 76 *
Pokitto 5:ea7377f3d1af 77 * @param data An array to write.
Pokitto 5:ea7377f3d1af 78 * @param size The size of data.
Pokitto 5:ea7377f3d1af 79 *
Pokitto 5:ea7377f3d1af 80 * @returns
Pokitto 5:ea7377f3d1af 81 * The number of written bytes.
Pokitto 5:ea7377f3d1af 82 */
Pokitto 5:ea7377f3d1af 83 int write(const char *data, int size);
Pokitto 5:ea7377f3d1af 84
Pokitto 5:ea7377f3d1af 85 /** Send an outgoing ethernet packet.
Pokitto 5:ea7377f3d1af 86 *
Pokitto 5:ea7377f3d1af 87 * After filling in the data in an ethernet packet it must be send.
Pokitto 5:ea7377f3d1af 88 * Send will provide a new packet to write to.
Pokitto 5:ea7377f3d1af 89 *
Pokitto 5:ea7377f3d1af 90 * @returns
Pokitto 5:ea7377f3d1af 91 * 0 if the sending was failed,
Pokitto 5:ea7377f3d1af 92 * or the size of the packet successfully sent.
Pokitto 5:ea7377f3d1af 93 */
Pokitto 5:ea7377f3d1af 94 int send();
Pokitto 5:ea7377f3d1af 95
Pokitto 5:ea7377f3d1af 96 /** Recevies an arrived ethernet packet.
Pokitto 5:ea7377f3d1af 97 *
Pokitto 5:ea7377f3d1af 98 * Receiving an ethernet packet will drop the last received ethernet packet
Pokitto 5:ea7377f3d1af 99 * and make a new ethernet packet ready to read.
Pokitto 5:ea7377f3d1af 100 * If no ethernet packet is arrived it will return 0.
Pokitto 5:ea7377f3d1af 101 *
Pokitto 5:ea7377f3d1af 102 * @returns
Pokitto 5:ea7377f3d1af 103 * 0 if no ethernet packet is arrived,
Pokitto 5:ea7377f3d1af 104 * or the size of the arrived packet.
Pokitto 5:ea7377f3d1af 105 */
Pokitto 5:ea7377f3d1af 106 int receive();
Pokitto 5:ea7377f3d1af 107
Pokitto 5:ea7377f3d1af 108 /** Read from an recevied ethernet packet.
Pokitto 5:ea7377f3d1af 109 *
Pokitto 5:ea7377f3d1af 110 * After receive returnd a number bigger than 0it is
Pokitto 5:ea7377f3d1af 111 * possible to read bytes from this packet.
Pokitto 5:ea7377f3d1af 112 * Read will write up to size bytes into data.
Pokitto 5:ea7377f3d1af 113 *
Pokitto 5:ea7377f3d1af 114 * It is possible to use read multible times.
Pokitto 5:ea7377f3d1af 115 * Each time read will start reading after the last read byte before.
Pokitto 5:ea7377f3d1af 116 *
Pokitto 5:ea7377f3d1af 117 * @returns
Pokitto 5:ea7377f3d1af 118 * The number of byte read.
Pokitto 5:ea7377f3d1af 119 */
Pokitto 5:ea7377f3d1af 120 int read(char *data, int size);
Pokitto 5:ea7377f3d1af 121
Pokitto 5:ea7377f3d1af 122 /** Gives the ethernet address of the mbed.
Pokitto 5:ea7377f3d1af 123 *
Pokitto 5:ea7377f3d1af 124 * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
Pokitto 5:ea7377f3d1af 125 */
Pokitto 5:ea7377f3d1af 126 void address(char *mac);
Pokitto 5:ea7377f3d1af 127
Pokitto 5:ea7377f3d1af 128 /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
Pokitto 5:ea7377f3d1af 129 *
Pokitto 5:ea7377f3d1af 130 * @returns
Pokitto 5:ea7377f3d1af 131 * 0 if no ethernet link is pressent,
Pokitto 5:ea7377f3d1af 132 * 1 if an ethernet link is pressent.
Pokitto 5:ea7377f3d1af 133 *
Pokitto 5:ea7377f3d1af 134 * Example:
Pokitto 5:ea7377f3d1af 135 * @code
Pokitto 5:ea7377f3d1af 136 * // Using the Ethernet link function
Pokitto 5:ea7377f3d1af 137 * #include "mbed.h"
Pokitto 5:ea7377f3d1af 138 *
Pokitto 5:ea7377f3d1af 139 * Ethernet eth;
Pokitto 5:ea7377f3d1af 140 *
Pokitto 5:ea7377f3d1af 141 * int main() {
Pokitto 5:ea7377f3d1af 142 * wait(1); // Needed after startup.
Pokitto 5:ea7377f3d1af 143 * if (eth.link()) {
Pokitto 5:ea7377f3d1af 144 * printf("online\n");
Pokitto 5:ea7377f3d1af 145 * } else {
Pokitto 5:ea7377f3d1af 146 * printf("offline\n");
Pokitto 5:ea7377f3d1af 147 * }
Pokitto 5:ea7377f3d1af 148 * }
Pokitto 5:ea7377f3d1af 149 * @endcode
Pokitto 5:ea7377f3d1af 150 */
Pokitto 5:ea7377f3d1af 151 int link();
Pokitto 5:ea7377f3d1af 152
Pokitto 5:ea7377f3d1af 153 /** Sets the speed and duplex parameters of an ethernet link
Pokitto 5:ea7377f3d1af 154 *
Pokitto 5:ea7377f3d1af 155 * - AutoNegotiate Auto negotiate speed and duplex
Pokitto 5:ea7377f3d1af 156 * - HalfDuplex10 10 Mbit, half duplex
Pokitto 5:ea7377f3d1af 157 * - FullDuplex10 10 Mbit, full duplex
Pokitto 5:ea7377f3d1af 158 * - HalfDuplex100 100 Mbit, half duplex
Pokitto 5:ea7377f3d1af 159 * - FullDuplex100 100 Mbit, full duplex
Pokitto 5:ea7377f3d1af 160 *
Pokitto 5:ea7377f3d1af 161 * @param mode the speed and duplex mode to set the link to:
Pokitto 5:ea7377f3d1af 162 */
Pokitto 5:ea7377f3d1af 163 void set_link(Mode mode);
Pokitto 5:ea7377f3d1af 164 };
Pokitto 5:ea7377f3d1af 165
Pokitto 5:ea7377f3d1af 166 } // namespace mbed
Pokitto 5:ea7377f3d1af 167
Pokitto 5:ea7377f3d1af 168 #endif
Pokitto 5:ea7377f3d1af 169
Pokitto 5:ea7377f3d1af 170 #endif