A simple 128x32 graphical LCD program to quickstart with LCD on ARM mbed IoT Starter Kit. This requires mbed Applciation Shield with FRDM-K64F platform.
mbed/Ethernet.h@0:60d829a0353a, 2015-04-11 (annotated)
- Committer:
- tushki7
- Date:
- Sat Apr 11 04:08:13 2015 +0000
- Revision:
- 0:60d829a0353a
A simple 128x32 LCD program to quickstart with LCD on ARM mbed IoT Starter kit. Mbed Application Shield is required if using FRDM-K64F platform.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tushki7 | 0:60d829a0353a | 1 | /* mbed Microcontroller Library |
tushki7 | 0:60d829a0353a | 2 | * Copyright (c) 2006-2013 ARM Limited |
tushki7 | 0:60d829a0353a | 3 | * |
tushki7 | 0:60d829a0353a | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
tushki7 | 0:60d829a0353a | 5 | * you may not use this file except in compliance with the License. |
tushki7 | 0:60d829a0353a | 6 | * You may obtain a copy of the License at |
tushki7 | 0:60d829a0353a | 7 | * |
tushki7 | 0:60d829a0353a | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
tushki7 | 0:60d829a0353a | 9 | * |
tushki7 | 0:60d829a0353a | 10 | * Unless required by applicable law or agreed to in writing, software |
tushki7 | 0:60d829a0353a | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
tushki7 | 0:60d829a0353a | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
tushki7 | 0:60d829a0353a | 13 | * See the License for the specific language governing permissions and |
tushki7 | 0:60d829a0353a | 14 | * limitations under the License. |
tushki7 | 0:60d829a0353a | 15 | */ |
tushki7 | 0:60d829a0353a | 16 | #ifndef MBED_ETHERNET_H |
tushki7 | 0:60d829a0353a | 17 | #define MBED_ETHERNET_H |
tushki7 | 0:60d829a0353a | 18 | |
tushki7 | 0:60d829a0353a | 19 | #include "platform.h" |
tushki7 | 0:60d829a0353a | 20 | |
tushki7 | 0:60d829a0353a | 21 | #if DEVICE_ETHERNET |
tushki7 | 0:60d829a0353a | 22 | |
tushki7 | 0:60d829a0353a | 23 | namespace mbed { |
tushki7 | 0:60d829a0353a | 24 | |
tushki7 | 0:60d829a0353a | 25 | /** An ethernet interface, to use with the ethernet pins. |
tushki7 | 0:60d829a0353a | 26 | * |
tushki7 | 0:60d829a0353a | 27 | * Example: |
tushki7 | 0:60d829a0353a | 28 | * @code |
tushki7 | 0:60d829a0353a | 29 | * // Read destination and source from every ethernet packet |
tushki7 | 0:60d829a0353a | 30 | * |
tushki7 | 0:60d829a0353a | 31 | * #include "mbed.h" |
tushki7 | 0:60d829a0353a | 32 | * |
tushki7 | 0:60d829a0353a | 33 | * Ethernet eth; |
tushki7 | 0:60d829a0353a | 34 | * |
tushki7 | 0:60d829a0353a | 35 | * int main() { |
tushki7 | 0:60d829a0353a | 36 | * char buf[0x600]; |
tushki7 | 0:60d829a0353a | 37 | * |
tushki7 | 0:60d829a0353a | 38 | * while(1) { |
tushki7 | 0:60d829a0353a | 39 | * int size = eth.receive(); |
tushki7 | 0:60d829a0353a | 40 | * if(size > 0) { |
tushki7 | 0:60d829a0353a | 41 | * eth.read(buf, size); |
tushki7 | 0:60d829a0353a | 42 | * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n", |
tushki7 | 0:60d829a0353a | 43 | * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); |
tushki7 | 0:60d829a0353a | 44 | * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n", |
tushki7 | 0:60d829a0353a | 45 | * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); |
tushki7 | 0:60d829a0353a | 46 | * } |
tushki7 | 0:60d829a0353a | 47 | * |
tushki7 | 0:60d829a0353a | 48 | * wait(1); |
tushki7 | 0:60d829a0353a | 49 | * } |
tushki7 | 0:60d829a0353a | 50 | * } |
tushki7 | 0:60d829a0353a | 51 | * @endcode |
tushki7 | 0:60d829a0353a | 52 | */ |
tushki7 | 0:60d829a0353a | 53 | class Ethernet { |
tushki7 | 0:60d829a0353a | 54 | |
tushki7 | 0:60d829a0353a | 55 | public: |
tushki7 | 0:60d829a0353a | 56 | |
tushki7 | 0:60d829a0353a | 57 | /** Initialise the ethernet interface. |
tushki7 | 0:60d829a0353a | 58 | */ |
tushki7 | 0:60d829a0353a | 59 | Ethernet(); |
tushki7 | 0:60d829a0353a | 60 | |
tushki7 | 0:60d829a0353a | 61 | /** Powers the hardware down. |
tushki7 | 0:60d829a0353a | 62 | */ |
tushki7 | 0:60d829a0353a | 63 | virtual ~Ethernet(); |
tushki7 | 0:60d829a0353a | 64 | |
tushki7 | 0:60d829a0353a | 65 | enum Mode { |
tushki7 | 0:60d829a0353a | 66 | AutoNegotiate, |
tushki7 | 0:60d829a0353a | 67 | HalfDuplex10, |
tushki7 | 0:60d829a0353a | 68 | FullDuplex10, |
tushki7 | 0:60d829a0353a | 69 | HalfDuplex100, |
tushki7 | 0:60d829a0353a | 70 | FullDuplex100 |
tushki7 | 0:60d829a0353a | 71 | }; |
tushki7 | 0:60d829a0353a | 72 | |
tushki7 | 0:60d829a0353a | 73 | /** Writes into an outgoing ethernet packet. |
tushki7 | 0:60d829a0353a | 74 | * |
tushki7 | 0:60d829a0353a | 75 | * It will append size bytes of data to the previously written bytes. |
tushki7 | 0:60d829a0353a | 76 | * |
tushki7 | 0:60d829a0353a | 77 | * @param data An array to write. |
tushki7 | 0:60d829a0353a | 78 | * @param size The size of data. |
tushki7 | 0:60d829a0353a | 79 | * |
tushki7 | 0:60d829a0353a | 80 | * @returns |
tushki7 | 0:60d829a0353a | 81 | * The number of written bytes. |
tushki7 | 0:60d829a0353a | 82 | */ |
tushki7 | 0:60d829a0353a | 83 | int write(const char *data, int size); |
tushki7 | 0:60d829a0353a | 84 | |
tushki7 | 0:60d829a0353a | 85 | /** Send an outgoing ethernet packet. |
tushki7 | 0:60d829a0353a | 86 | * |
tushki7 | 0:60d829a0353a | 87 | * After filling in the data in an ethernet packet it must be send. |
tushki7 | 0:60d829a0353a | 88 | * Send will provide a new packet to write to. |
tushki7 | 0:60d829a0353a | 89 | * |
tushki7 | 0:60d829a0353a | 90 | * @returns |
tushki7 | 0:60d829a0353a | 91 | * 0 if the sending was failed, |
tushki7 | 0:60d829a0353a | 92 | * or the size of the packet successfully sent. |
tushki7 | 0:60d829a0353a | 93 | */ |
tushki7 | 0:60d829a0353a | 94 | int send(); |
tushki7 | 0:60d829a0353a | 95 | |
tushki7 | 0:60d829a0353a | 96 | /** Recevies an arrived ethernet packet. |
tushki7 | 0:60d829a0353a | 97 | * |
tushki7 | 0:60d829a0353a | 98 | * Receiving an ethernet packet will drop the last received ethernet packet |
tushki7 | 0:60d829a0353a | 99 | * and make a new ethernet packet ready to read. |
tushki7 | 0:60d829a0353a | 100 | * If no ethernet packet is arrived it will return 0. |
tushki7 | 0:60d829a0353a | 101 | * |
tushki7 | 0:60d829a0353a | 102 | * @returns |
tushki7 | 0:60d829a0353a | 103 | * 0 if no ethernet packet is arrived, |
tushki7 | 0:60d829a0353a | 104 | * or the size of the arrived packet. |
tushki7 | 0:60d829a0353a | 105 | */ |
tushki7 | 0:60d829a0353a | 106 | int receive(); |
tushki7 | 0:60d829a0353a | 107 | |
tushki7 | 0:60d829a0353a | 108 | /** Read from an recevied ethernet packet. |
tushki7 | 0:60d829a0353a | 109 | * |
tushki7 | 0:60d829a0353a | 110 | * After receive returnd a number bigger than 0it is |
tushki7 | 0:60d829a0353a | 111 | * possible to read bytes from this packet. |
tushki7 | 0:60d829a0353a | 112 | * Read will write up to size bytes into data. |
tushki7 | 0:60d829a0353a | 113 | * |
tushki7 | 0:60d829a0353a | 114 | * It is possible to use read multible times. |
tushki7 | 0:60d829a0353a | 115 | * Each time read will start reading after the last read byte before. |
tushki7 | 0:60d829a0353a | 116 | * |
tushki7 | 0:60d829a0353a | 117 | * @returns |
tushki7 | 0:60d829a0353a | 118 | * The number of byte read. |
tushki7 | 0:60d829a0353a | 119 | */ |
tushki7 | 0:60d829a0353a | 120 | int read(char *data, int size); |
tushki7 | 0:60d829a0353a | 121 | |
tushki7 | 0:60d829a0353a | 122 | /** Gives the ethernet address of the mbed. |
tushki7 | 0:60d829a0353a | 123 | * |
tushki7 | 0:60d829a0353a | 124 | * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in. |
tushki7 | 0:60d829a0353a | 125 | */ |
tushki7 | 0:60d829a0353a | 126 | void address(char *mac); |
tushki7 | 0:60d829a0353a | 127 | |
tushki7 | 0:60d829a0353a | 128 | /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up. |
tushki7 | 0:60d829a0353a | 129 | * |
tushki7 | 0:60d829a0353a | 130 | * @returns |
tushki7 | 0:60d829a0353a | 131 | * 0 if no ethernet link is pressent, |
tushki7 | 0:60d829a0353a | 132 | * 1 if an ethernet link is pressent. |
tushki7 | 0:60d829a0353a | 133 | * |
tushki7 | 0:60d829a0353a | 134 | * Example: |
tushki7 | 0:60d829a0353a | 135 | * @code |
tushki7 | 0:60d829a0353a | 136 | * // Using the Ethernet link function |
tushki7 | 0:60d829a0353a | 137 | * #include "mbed.h" |
tushki7 | 0:60d829a0353a | 138 | * |
tushki7 | 0:60d829a0353a | 139 | * Ethernet eth; |
tushki7 | 0:60d829a0353a | 140 | * |
tushki7 | 0:60d829a0353a | 141 | * int main() { |
tushki7 | 0:60d829a0353a | 142 | * wait(1); // Needed after startup. |
tushki7 | 0:60d829a0353a | 143 | * if (eth.link()) { |
tushki7 | 0:60d829a0353a | 144 | * printf("online\n"); |
tushki7 | 0:60d829a0353a | 145 | * } else { |
tushki7 | 0:60d829a0353a | 146 | * printf("offline\n"); |
tushki7 | 0:60d829a0353a | 147 | * } |
tushki7 | 0:60d829a0353a | 148 | * } |
tushki7 | 0:60d829a0353a | 149 | * @endcode |
tushki7 | 0:60d829a0353a | 150 | */ |
tushki7 | 0:60d829a0353a | 151 | int link(); |
tushki7 | 0:60d829a0353a | 152 | |
tushki7 | 0:60d829a0353a | 153 | /** Sets the speed and duplex parameters of an ethernet link |
tushki7 | 0:60d829a0353a | 154 | * |
tushki7 | 0:60d829a0353a | 155 | * - AutoNegotiate Auto negotiate speed and duplex |
tushki7 | 0:60d829a0353a | 156 | * - HalfDuplex10 10 Mbit, half duplex |
tushki7 | 0:60d829a0353a | 157 | * - FullDuplex10 10 Mbit, full duplex |
tushki7 | 0:60d829a0353a | 158 | * - HalfDuplex100 100 Mbit, half duplex |
tushki7 | 0:60d829a0353a | 159 | * - FullDuplex100 100 Mbit, full duplex |
tushki7 | 0:60d829a0353a | 160 | * |
tushki7 | 0:60d829a0353a | 161 | * @param mode the speed and duplex mode to set the link to: |
tushki7 | 0:60d829a0353a | 162 | */ |
tushki7 | 0:60d829a0353a | 163 | void set_link(Mode mode); |
tushki7 | 0:60d829a0353a | 164 | }; |
tushki7 | 0:60d829a0353a | 165 | |
tushki7 | 0:60d829a0353a | 166 | } // namespace mbed |
tushki7 | 0:60d829a0353a | 167 | |
tushki7 | 0:60d829a0353a | 168 | #endif |
tushki7 | 0:60d829a0353a | 169 | |
tushki7 | 0:60d829a0353a | 170 | #endif |