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