Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 * Echo server 00003 * Listens on TCP and UDP ports 7 for any incoming connections 00004 * Re-transmits any incoming bytes 00005 */ 00006 00007 #include "mbed.h" 00008 #include "EthernetNetIf.h" 00009 00010 #include "EchoServer.h" 00011 00012 #define byte char 00013 00014 #define ScreenWidth 32 00015 #define ScreenHeight 15 00016 00017 #define HTTPChunkSize 1024 00018 00019 #define ScreenBufferSize ScreenWidth*ScreenHeight*3 00020 00021 bool drawReadyFlag = false; 00022 00023 int bytes_received = 0; 00024 00025 00026 00027 00028 00029 typedef struct { 00030 byte blue; 00031 byte green; 00032 byte red; 00033 } color; 00034 00035 unsigned int fileFrameCount; 00036 00037 byte screenBuf[ScreenBufferSize]; 00038 00039 // Our Ethernet interface 00040 EthernetNetIf eth; 00041 // Our Echo server 00042 EchoServer* server = new EchoServer(screenBuf); 00043 00044 Serial pc(USBTX, USBRX); 00045 00046 SPI spi(p5, NC, p7); // mosi, miso, sclk 00047 00048 void writePixel(int x, int y) { 00049 spi.write(screenBuf[(y*ScreenWidth+x)*3]); 00050 spi.write(screenBuf[(y*ScreenWidth+x)*3+1]); 00051 spi.write(screenBuf[(y*ScreenWidth+x)*3+2]); 00052 } 00053 00054 00055 void updateDisplay() { 00056 for (int y = ScreenHeight-1; y >= 0; y--) { 00057 00058 /** 00059 for (int x = 0; x < ScreenWidth; x++) { 00060 writePixel(x,y); 00061 } 00062 **/ 00063 00064 00065 if (y % 2) { 00066 for (int x = 0; x < ScreenWidth; x++) 00067 writePixel(x,y); 00068 } 00069 else { 00070 for (int x = ScreenWidth-1; x >= 0; x--) 00071 writePixel(x,y); 00072 } 00073 00074 } 00075 wait_us(800); 00076 } 00077 00078 00079 00080 void hexDump(byte *buf, unsigned long len, int wid) { 00081 00082 for (unsigned long i = 0; i < len; i++) { 00083 if (!(i % wid)) pc.printf("\r\n"); 00084 else if (!(i % 4)) pc.printf(" "); 00085 00086 pc.printf("%02x", buf[i]); 00087 } 00088 pc.printf("\r\n"); 00089 } 00090 00091 00092 /* 00093 Function: main 00094 00095 Sets up the Ethernet interface using DHCP, reports the assigned 00096 IP address via serial, binds the Echo server to port 7 on 00097 TCP and UDP and then sits in a loop calling Net::poll() to 00098 keep the network stack doing its thing 00099 */ 00100 int main() { 00101 spi.format(8,1); 00102 spi.frequency(1000000); 00103 printf("\r\nSetting up...\r\n"); 00104 //spi.frequency(100000); 00105 EthernetErr ethErr = eth.setup(); 00106 if (ethErr) { 00107 printf("Error %d in setup.\r\n", ethErr); 00108 return -1; 00109 } 00110 IpAddr ip = eth.getIp(); 00111 printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]); 00112 server->bind(); 00113 00114 printf("Entering while loop Net::poll()ing\r\n"); 00115 while (1) { 00116 Net::poll(); 00117 if (drawReadyFlag) { 00118 //printf("updating display\r\n"); 00119 updateDisplay(); 00120 drawReadyFlag = false; 00121 } 00122 } 00123 }
Generated on Wed Jul 13 2022 09:03:52 by
1.7.2