My fork of the blinky project to support ethernet and twitter
Dependencies: EthernetInterface HTTPClient HTU21D OAuth4Tw SDFileSystem SPI_TFT_ILI9341 SerialShell mbed-rtos mbed-src
Fork of mbed_blinky by
Revision 7:aafb9225f866, committed 2015-04-29
- Comitter:
- vpcola
- Date:
- Wed Apr 29 14:55:06 2015 +0000
- Parent:
- 6:e8cd76f38fa9
- Child:
- 8:e3fb74a4772c
- Commit message:
- Updated added SerialShell;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Wed Apr 29 14:55:06 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTU21D.lib Wed Apr 29 14:55:06 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/hwing91/code/HTU21D/#db86ad1b4459
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Wed Apr 29 14:55:06 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/neilt6/code/SDFileSystem/#c2c1f0b16380
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SPI_TFT_ILI9341.lib Wed Apr 29 14:55:06 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/dreschpe/code/SPI_TFT_ILI9341/#b2b3e5430f81
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialShell.lib Wed Apr 29 14:55:06 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/vpcola/code/SerialShell/#3db531afe4fc
--- a/main.cpp Fri May 09 19:58:03 2014 +0300 +++ b/main.cpp Wed Apr 29 14:55:06 2015 +0000 @@ -1,12 +1,181 @@ #include "mbed.h" +#include "rtos.h" +#include "EthernetInterface.h" +#include "Arial12x12.h" +#include "Arial24x23.h" +#include "SPI_TFT_ILI9341.h" +#include "SDFileSystem.h" +#include "Shell.h" DigitalOut myled(LED1); +//EthernetInterface eth; +Serial pc(p9,p10); + +SDFileSystem sd(p5,p6,p7,p8,"sd"); // mosi, miso, sck, cs +SPI_TFT_ILI9341 TFT(p11,p12,p13,p15, p16, p17 ); // mosi, miso, sck, cs, eset, dc +DigitalOut lcdOn(p14); + +#define SHELL_STACK_SIZ 1024 +// Pre-allocate the shell's stack (on global mem) +unsigned char shellStack[SHELL_STACK_SIZ]; +Shell shell(&pc); + +// Local Commands +/** + * \brief Gets the amount of free memory + * \param none + * \return none + **/ +static void cmd_mem(Stream * chp, int argc, char * argv[]) +{ + // In order to get free mem within RTOS + // we need to get the main thread's stack pointer + // and subtract it with the top of the heap + // ------+-------------------+ Last Address of RAM (INITIAL_SP) + // | Scheduler Stack | + // +-------------------+ + // | Main Thread Stack | + // | | | + // | v | + // +-------------------+ <- bottom_of_stack/__get_MSP() + // RAM | | + // | Available RAM | + // | | + // +-------------------+ <- top_of_heap + // | ^ | + // | | | + // | Heap | + // +-------------------+ <- __end__ / HEAP_START (linker defined var) + // | ZI | + // +-------------------+ + // | ZI: Shell Stack | + // +-------------------+ + // | ZI: Idle Stack | + // +-------------------+ + // | ZI: Timer Stack | + // +-------------------+ + // | RW | + // ------+===================+ First Address of RAM + // | | + // Flash | | + // + + uint32_t bottom_of_stack = __get_MSP(); + char * top_of_heap = (char *) malloc(sizeof(char)); + uint32_t diff = bottom_of_stack - (uint32_t) top_of_heap; + + free((void *) top_of_heap); + chp->printf("Available Memory : %d bytes\r\n", + diff); +} + +/** + * \brief List Directories and files + * \param none + * \return int + **/ +static void cmd_ls(Stream * chp, int argc, char * argv[]) +{ + DIR * dp; + struct dirent * dirp; + char dirroot[256]; + + if (argc >= 1) + sprintf(dirroot, "/sd/%s", argv[0]); + else + sprintf(dirroot, "/sd"); + + chp->printf("Listing directory [%s]\r\n", dirroot); + + dp = opendir(dirroot); + while((dirp = readdir(dp)) != NULL) + { + chp->printf("\t%s\r\n", dirp->d_name); + } + closedir(dp); +} + +static void cmd_load(Stream * chp, int argc, char * argv[]) +{ + char filename[256]; + + if (argc != 1) + { + chp->printf("load <bitmapfile>\r\n"); + return; + } + + sprintf(filename, "/sd/%s", argv[0]); + // Load a bitmap startup file + int err = TFT.BMP_16(0,0, filename); + if (err != 1) TFT.printf(" - Err: %d", err); +} + + +/** + * \brief Initialize LCD + * \param none + * \return void + **/ +void init_LCD() +{ + pc.printf("Initializing LCD Screen ...\r\n"); + + // Turn on the LCD + lcdOn = 1; + + TFT.claim(stdout); + TFT.set_orientation(1); + TFT.background(Black); // set background to black + TFT.foreground(White); // set chars to white + TFT.cls(); // clear the screen + + + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(0,0); + + printf("Hello World of EMBED!\n"); + +} + + +void led1_thread(void const *args) { + while (true) { + myled = !myled; + Thread::wait(1000); + } +} int main() { + Thread * thread; + pc.baud(115200); + + pc.printf("\r\nStarting Mbed ...\r\n"); + // pc.printf("Inititalizing ethernet ....\r\n"); + // eth.init(); // Use DHCP + // eth.connect(); + // pc.printf("IP Address is %s\n", eth.getIPAddress()); + + // Initialize the LCD + init_LCD(); + + // After initializing the ethernet interface + // run it in its own thread + thread = new Thread(led1_thread); + + // Start the shell + pc.printf("Starting debug shell ...\r\n"); + shell.addCommand("ls", cmd_ls); + //shell.addCommand("load", cmd_load); + shell.addCommand("mem", cmd_mem); + shell.start(osPriorityNormal, SHELL_STACK_SIZ, shellStack); + + // Do something logical here + // other than looping while(1) { - myled = 1; - wait(0.2); - myled = 0; wait(0.2); } + + thread->terminate(); + delete thread; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed Apr 29 14:55:06 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#34292fba723c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-src.lib Wed Apr 29 14:55:06 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-src/#0334fb94f264
--- a/mbed.bld Fri May 09 19:58:03 2014 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/ \ No newline at end of file