Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Committer:
Bigcheese
Date:
Sun Mar 02 06:33:08 2014 +0000
Revision:
3:f151d08d335c
Parent:
2:1df0b61d3b5a
Bunch of stuff. Need to locally merge in updated USB changes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Michael J. Spencer 2:1df0b61d3b5a 1 /*
scachat 0:31e91bb0ef3c 2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
scachat 0:31e91bb0ef3c 3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
scachat 0:31e91bb0ef3c 4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Michael J. Spencer 2:1df0b61d3b5a 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
scachat 0:31e91bb0ef3c 6 */
scachat 0:31e91bb0ef3c 7
scachat 0:31e91bb0ef3c 8 #include "libs/Kernel.h"
scachat 0:31e91bb0ef3c 9 #include "modules/tools/laser/Laser.h"
Michael J. Spencer 2:1df0b61d3b5a 10 #include "modules/tools/extruder/ExtruderMaker.h"
scachat 0:31e91bb0ef3c 11 #include "modules/tools/temperaturecontrol/TemperatureControlPool.h"
Michael J. Spencer 2:1df0b61d3b5a 12 #include "modules/tools/endstops/Endstops.h"
Michael J. Spencer 2:1df0b61d3b5a 13 #include "modules/tools/touchprobe/Touchprobe.h"
Michael J. Spencer 2:1df0b61d3b5a 14 #include "modules/tools/switch/SwitchPool.h"
Michael J. Spencer 2:1df0b61d3b5a 15 #include "modules/robot/Conveyor.h"
scachat 0:31e91bb0ef3c 16 #include "modules/utils/simpleshell/SimpleShell.h"
scachat 0:31e91bb0ef3c 17 #include "modules/utils/configurator/Configurator.h"
scachat 0:31e91bb0ef3c 18 #include "modules/utils/currentcontrol/CurrentControl.h"
Michael J. Spencer 2:1df0b61d3b5a 19 #include "modules/utils/player/Player.h"
scachat 0:31e91bb0ef3c 20 #include "modules/utils/pausebutton/PauseButton.h"
Michael J. Spencer 2:1df0b61d3b5a 21 #include "modules/utils/PlayLed/PlayLed.h"
Michael J. Spencer 2:1df0b61d3b5a 22 #include "modules/utils/panel/Panel.h"
Michael J. Spencer 2:1df0b61d3b5a 23 #include "libs/Network/uip/Network.h"
Michael J. Spencer 2:1df0b61d3b5a 24
Michael J. Spencer 2:1df0b61d3b5a 25 // #include "libs/ChaNFSSD/SDFileSystem.h"
scachat 0:31e91bb0ef3c 26 #include "libs/Config.h"
scachat 0:31e91bb0ef3c 27 #include "libs/nuts_bolts.h"
scachat 0:31e91bb0ef3c 28 #include "libs/utils.h"
scachat 0:31e91bb0ef3c 29
Michael J. Spencer 2:1df0b61d3b5a 30 // Debug
Michael J. Spencer 2:1df0b61d3b5a 31 #include "libs/SerialMessage.h"
Michael J. Spencer 2:1df0b61d3b5a 32
Michael J. Spencer 2:1df0b61d3b5a 33 #include "libs/USBDevice/USB.h"
Michael J. Spencer 2:1df0b61d3b5a 34 #include "libs/USBDevice/USBMSD/USBMSD.h"
Michael J. Spencer 2:1df0b61d3b5a 35 #include "libs/USBDevice/USBMSD/SDCard.h"
Michael J. Spencer 2:1df0b61d3b5a 36 #include "libs/USBDevice/USBSerial/USBSerial.h"
Michael J. Spencer 2:1df0b61d3b5a 37 #include "libs/USBDevice/DFU.h"
Michael J. Spencer 2:1df0b61d3b5a 38 #include "libs/SDFAT.h"
Michael J. Spencer 2:1df0b61d3b5a 39
Michael J. Spencer 2:1df0b61d3b5a 40 #include "libs/Watchdog.h"
Michael J. Spencer 2:1df0b61d3b5a 41
Michael J. Spencer 2:1df0b61d3b5a 42 #include "version.h"
Michael J. Spencer 2:1df0b61d3b5a 43
Michael J. Spencer 2:1df0b61d3b5a 44 #define second_usb_serial_enable_checksum CHECKSUM("second_usb_serial_enable")
Michael J. Spencer 2:1df0b61d3b5a 45 #define disable_msd_checksum CHECKSUM("msd_disable")
Michael J. Spencer 2:1df0b61d3b5a 46 #define disable_leds_checksum CHECKSUM("leds_disable")
Michael J. Spencer 2:1df0b61d3b5a 47
Michael J. Spencer 2:1df0b61d3b5a 48 // Watchdog wd(5000000, WDT_MRI);
Michael J. Spencer 2:1df0b61d3b5a 49
Michael J. Spencer 2:1df0b61d3b5a 50 // USB Stuff
Michael J. Spencer 2:1df0b61d3b5a 51 SDCard sd(P0_9, P0_8, P0_7, P0_6); // this selects SPI1 as the sdcard as it is on Smoothieboard
Michael J. Spencer 2:1df0b61d3b5a 52 //SDCard sd(P0_18, P0_17, P0_15, P0_16); // this selects SPI0 as the sdcard
Michael J. Spencer 2:1df0b61d3b5a 53
Michael J. Spencer 2:1df0b61d3b5a 54 USB u;
Michael J. Spencer 2:1df0b61d3b5a 55 USBSerial usbserial(&u);
Michael J. Spencer 2:1df0b61d3b5a 56 USBMSD msc(&u, &sd);
Michael J. Spencer 2:1df0b61d3b5a 57 //USBMSD *msc= NULL;
Michael J. Spencer 2:1df0b61d3b5a 58 DFU dfu(&u);
Michael J. Spencer 2:1df0b61d3b5a 59
Michael J. Spencer 2:1df0b61d3b5a 60 SDFAT mounter("sd", &sd);
Michael J. Spencer 2:1df0b61d3b5a 61
Michael J. Spencer 2:1df0b61d3b5a 62 GPIO leds[5] = {
Michael J. Spencer 2:1df0b61d3b5a 63 GPIO(P1_18),
Michael J. Spencer 2:1df0b61d3b5a 64 GPIO(P1_19),
Michael J. Spencer 2:1df0b61d3b5a 65 GPIO(P1_20),
Michael J. Spencer 2:1df0b61d3b5a 66 GPIO(P1_21),
Michael J. Spencer 2:1df0b61d3b5a 67 GPIO(P4_28)
Michael J. Spencer 2:1df0b61d3b5a 68 };
scachat 0:31e91bb0ef3c 69
scachat 0:31e91bb0ef3c 70 int main() {
scachat 0:31e91bb0ef3c 71
Michael J. Spencer 2:1df0b61d3b5a 72 // Default pins to low status
Michael J. Spencer 2:1df0b61d3b5a 73 for (int i = 0; i < 5; i++){
Michael J. Spencer 2:1df0b61d3b5a 74 leds[i].output();
Michael J. Spencer 2:1df0b61d3b5a 75 leds[i]= 0;
Michael J. Spencer 2:1df0b61d3b5a 76 }
Michael J. Spencer 2:1df0b61d3b5a 77
scachat 0:31e91bb0ef3c 78 Kernel* kernel = new Kernel();
scachat 0:31e91bb0ef3c 79
Michael J. Spencer 2:1df0b61d3b5a 80 kernel->streams->printf("Smoothie ( grbl port ) version 0.7.2 with new accel @%ldMHz\r\n", SystemCoreClock / 1000000);
Michael J. Spencer 2:1df0b61d3b5a 81 Version version;
Michael J. Spencer 2:1df0b61d3b5a 82 kernel->streams->printf(" Build version %s, Build date %s\r\n", version.get_build(), version.get_build_date());
scachat 0:31e91bb0ef3c 83
Michael J. Spencer 2:1df0b61d3b5a 84 //some boards don't have leds.. TOO BAD!
Michael J. Spencer 2:1df0b61d3b5a 85 kernel->use_leds= !kernel->config->value( disable_leds_checksum )->by_default(false)->as_bool();
scachat 0:31e91bb0ef3c 86
Michael J. Spencer 2:1df0b61d3b5a 87 // attempt to be able to disable msd in config
Michael J. Spencer 2:1df0b61d3b5a 88 // if(!kernel->config->value( disable_msd_checksum )->by_default(false)->as_bool()){
Michael J. Spencer 2:1df0b61d3b5a 89 // msc= new USBMSD(&u, &sd);
Michael J. Spencer 2:1df0b61d3b5a 90 // }else{
Michael J. Spencer 2:1df0b61d3b5a 91 // msc= NULL;
Michael J. Spencer 2:1df0b61d3b5a 92 // kernel->streams->printf("MSD is disabled\r\n");
Michael J. Spencer 2:1df0b61d3b5a 93 // }
Michael J. Spencer 2:1df0b61d3b5a 94
Michael J. Spencer 2:1df0b61d3b5a 95 bool sdok= (sd.disk_initialize() == 0);
Michael J. Spencer 2:1df0b61d3b5a 96
Michael J. Spencer 2:1df0b61d3b5a 97 // Create and add main modules
scachat 0:31e91bb0ef3c 98 kernel->add_module( new SimpleShell() );
scachat 0:31e91bb0ef3c 99 kernel->add_module( new Configurator() );
scachat 0:31e91bb0ef3c 100 kernel->add_module( new CurrentControl() );
Michael J. Spencer 2:1df0b61d3b5a 101 kernel->add_module( new SwitchPool() );
Michael J. Spencer 2:1df0b61d3b5a 102 kernel->add_module( new PauseButton() );
Michael J. Spencer 2:1df0b61d3b5a 103 kernel->add_module( new PlayLed() );
Michael J. Spencer 2:1df0b61d3b5a 104 kernel->add_module( new Endstops() );
Michael J. Spencer 2:1df0b61d3b5a 105 kernel->add_module( new Player() );
Michael J. Spencer 2:1df0b61d3b5a 106
Michael J. Spencer 2:1df0b61d3b5a 107 // these modules can be completely disabled in the Makefile by adding to EXCLUDE_MODULES
Michael J. Spencer 2:1df0b61d3b5a 108 #ifndef NO_TOOLS_TEMPERATURECONTROL
scachat 0:31e91bb0ef3c 109 kernel->add_module( new TemperatureControlPool() );
Michael J. Spencer 2:1df0b61d3b5a 110 #endif
Michael J. Spencer 2:1df0b61d3b5a 111 #ifndef NO_TOOLS_EXTRUDER
Michael J. Spencer 2:1df0b61d3b5a 112 kernel->add_module( new ExtruderMaker() );
Michael J. Spencer 2:1df0b61d3b5a 113 #endif
Michael J. Spencer 2:1df0b61d3b5a 114 #ifndef NO_TOOLS_LASER
Michael J. Spencer 2:1df0b61d3b5a 115 kernel->add_module( new Laser() );
Michael J. Spencer 2:1df0b61d3b5a 116 #endif
Michael J. Spencer 2:1df0b61d3b5a 117 #ifndef NO_UTILS_PANEL
Michael J. Spencer 2:1df0b61d3b5a 118 kernel->add_module( new Panel() );
Michael J. Spencer 2:1df0b61d3b5a 119 #endif
Michael J. Spencer 2:1df0b61d3b5a 120 #ifndef NO_TOOLS_TOUCHPROBE
Michael J. Spencer 2:1df0b61d3b5a 121 kernel->add_module( new Touchprobe() );
Michael J. Spencer 2:1df0b61d3b5a 122 #endif
Michael J. Spencer 2:1df0b61d3b5a 123 #ifndef NONETWORK
Michael J. Spencer 2:1df0b61d3b5a 124 kernel->add_module( new Network() );
Michael J. Spencer 2:1df0b61d3b5a 125 #endif
Michael J. Spencer 2:1df0b61d3b5a 126
Michael J. Spencer 2:1df0b61d3b5a 127 // Create and initialize USB stuff
Michael J. Spencer 2:1df0b61d3b5a 128 u.init();
Michael J. Spencer 2:1df0b61d3b5a 129 //if(sdok) { // only do this if there is an sd disk
Michael J. Spencer 2:1df0b61d3b5a 130 // msc= new USBMSD(&u, &sd);
Michael J. Spencer 2:1df0b61d3b5a 131 // kernel->add_module( msc );
Michael J. Spencer 2:1df0b61d3b5a 132 //}
Michael J. Spencer 2:1df0b61d3b5a 133
Michael J. Spencer 2:1df0b61d3b5a 134 // if(msc != NULL){
Michael J. Spencer 2:1df0b61d3b5a 135 // kernel->add_module( msc );
Michael J. Spencer 2:1df0b61d3b5a 136 // }
scachat 0:31e91bb0ef3c 137
Michael J. Spencer 2:1df0b61d3b5a 138 kernel->add_module( &msc );
Michael J. Spencer 2:1df0b61d3b5a 139 kernel->add_module( &usbserial );
Michael J. Spencer 2:1df0b61d3b5a 140 if( kernel->config->value( second_usb_serial_enable_checksum )->by_default(false)->as_bool() ){
Michael J. Spencer 2:1df0b61d3b5a 141 kernel->add_module( new USBSerial(&u) );
Michael J. Spencer 2:1df0b61d3b5a 142 }
Michael J. Spencer 2:1df0b61d3b5a 143 kernel->add_module( &dfu );
Michael J. Spencer 2:1df0b61d3b5a 144 kernel->add_module( &u );
Michael J. Spencer 2:1df0b61d3b5a 145
Michael J. Spencer 2:1df0b61d3b5a 146 // clear up the config cache to save some memory
Michael J. Spencer 2:1df0b61d3b5a 147 kernel->config->config_cache_clear();
Michael J. Spencer 2:1df0b61d3b5a 148
Michael J. Spencer 2:1df0b61d3b5a 149 if(kernel->use_leds) {
Michael J. Spencer 2:1df0b61d3b5a 150 // set some leds to indicate status... led0 init doe, led1 mainloop running, led2 idle loop running, led3 sdcard ok
Michael J. Spencer 2:1df0b61d3b5a 151 leds[0]= 1; // indicate we are done with init
Michael J. Spencer 2:1df0b61d3b5a 152 leds[3]= sdok?1:0; // 4th led inidicates sdcard is available (TODO maye should indicate config was found)
Michael J. Spencer 2:1df0b61d3b5a 153 }
scachat 0:31e91bb0ef3c 154
Michael J. Spencer 2:1df0b61d3b5a 155 if(sdok) {
Michael J. Spencer 2:1df0b61d3b5a 156 // load config override file if present
Michael J. Spencer 2:1df0b61d3b5a 157 // NOTE only Mxxx commands that set values should be put in this file. The file is generated by M500
Michael J. Spencer 2:1df0b61d3b5a 158 FILE *fp= fopen(kernel->config_override_filename(), "r");
Michael J. Spencer 2:1df0b61d3b5a 159 if(fp != NULL) {
Michael J. Spencer 2:1df0b61d3b5a 160 char buf[132];
Michael J. Spencer 2:1df0b61d3b5a 161 kernel->streams->printf("Loading config override file: %s...\n", kernel->config_override_filename());
Michael J. Spencer 2:1df0b61d3b5a 162 while(fgets(buf, sizeof buf, fp) != NULL) {
Michael J. Spencer 2:1df0b61d3b5a 163 kernel->streams->printf(" %s", buf);
Michael J. Spencer 2:1df0b61d3b5a 164 if(buf[0] == ';') continue; // skip the comments
Michael J. Spencer 2:1df0b61d3b5a 165 struct SerialMessage message= {&(StreamOutput::NullStream), buf};
Michael J. Spencer 2:1df0b61d3b5a 166 kernel->call_event(ON_CONSOLE_LINE_RECEIVED, &message);
Michael J. Spencer 2:1df0b61d3b5a 167 }
Michael J. Spencer 2:1df0b61d3b5a 168 kernel->streams->printf("config override file executed\n");
Michael J. Spencer 2:1df0b61d3b5a 169 fclose(fp);
Michael J. Spencer 2:1df0b61d3b5a 170 }
Michael J. Spencer 2:1df0b61d3b5a 171 }
Michael J. Spencer 2:1df0b61d3b5a 172
Michael J. Spencer 2:1df0b61d3b5a 173 uint16_t cnt= 0;
Michael J. Spencer 2:1df0b61d3b5a 174 // Main loop
scachat 0:31e91bb0ef3c 175 while(1){
Michael J. Spencer 2:1df0b61d3b5a 176 if(kernel->use_leds) {
Michael J. Spencer 2:1df0b61d3b5a 177 // flash led 2 to show we are alive
Michael J. Spencer 2:1df0b61d3b5a 178 leds[1]= (cnt++ & 0x1000) ? 1 : 0;
Michael J. Spencer 2:1df0b61d3b5a 179 }
scachat 0:31e91bb0ef3c 180 kernel->call_event(ON_MAIN_LOOP);
scachat 0:31e91bb0ef3c 181 kernel->call_event(ON_IDLE);
scachat 0:31e91bb0ef3c 182 }
scachat 0:31e91bb0ef3c 183 }