Repetier-Firmware  0.80
Repetier/uiconfig.h
Go to the documentation of this file.
00001 /*
00002     This file is part of Repetier-Firmware.
00003 
00004     Repetier-Firmware is free software: you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation, either version 3 of the License, or
00007     (at your option) any later version.
00008 
00009     Repetier-Firmware is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with Repetier-Firmware.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 */
00018 
00019 /* ===================== IMPORTANT ========================
00020 
00021 The LCD and Key support is new. I tested everything as good as possible,
00022 but some combinations may not work as supposed.
00023 The I2C methods rely on a stable I2C connection. Noise may cause wrong signals
00024 which can cause the firmware to freeze.
00025 
00026 The ui adds quite some code, so AVRs with 64kB ram (Sanguino, Gen6) can not handle all features
00027 of the firmware at the same time. You have to disable some features to gain the
00028 ram needed. What should work:
00029 - No sd card - the sd card code is quite large.
00030 - No keys attached - The longest part is the menu handling.
00031 - EEPROM_MODE 0 and USE_OPS 0. 
00032 
00033 Currently supported hardware:
00034 
00035 *** Displays ***
00036 
00037 - direct connected lcd with 4 data lines
00038 - connected via i2c
00039 
00040 *** Keys ***
00041 
00042 - rotary encoder
00043 - push button
00044 - key matrix up to 4x4
00045 - rotary encoder via i2c (only slow turns are captured correct)
00046 - push button via i2c
00047 
00048 *** Buzzer ***
00049 
00050 - directly connected, high = on
00051 - connected via i2c, low = on
00052 
00053 ==============================================================*/
00054 
00055 
00066 #define UI_DISPLAY_CHARSET 2
00067 
00073 #ifndef BEEPER_TYPE
00074 #define BEEPER_TYPE 1
00075 #endif
00076 
00077 #if BEEPER_TYPE==1 && !defined(BEEPER_PIN)
00078 #define BEEPER_PIN 37
00079 #endif
00080 #if BEEPER_TYPE==2
00081 #define BEEPER_ADDRESS 0x40 // I2C address of the chip with the beeper pin
00082 #define BEEPER_PIN _BV(7)  // Bit value for pin 8
00083 #define COMPILE_I2C_DRIVER  // We need the I2C driver as we are using i2c
00084 #endif
00085 
00086 
00097 #define UI_DISPLAY_TYPE 0
00098 
00103 #define UI_COLS 20
00104 
00107 #define UI_ROWS 4
00108 
00109 /* What type of chip is used for I2C communication
00110 0 : PCF8574 or PCF8574A or compatible chips.
00111 1 : MCP23017
00112 */
00113 #define UI_DISPLAY_I2C_CHIPTYPE 0
00114 // 0x40 till 0x4e for PCF8574, 0x40 for the adafruid RGB shield, 0x40 - 0x4e for MCP23017
00115 // Official addresses have a value twice as high!
00116 #define UI_DISPLAY_I2C_ADDRESS 0x4e
00117 // For MCP 23017 define which pins should be output
00118 #define UI_DISPLAY_I2C_OUTPUT_PINS 65504
00119 // Set the output mask that is or'd over the output data. This is needed to activate
00120 // a backlight switched over the I2C. 
00121 // The adafruit RGB shields enables a light if the bit is not set. Bits 6-8 are used for backlight.
00122 #define UI_DISPLAY_I2C_OUTPUT_START_MASK 0
00123 // For MCP which inputs are with pullup. 31 = pins 0-4 for adafruid rgb shield buttons
00124 #define UI_DISPLAY_I2C_PULLUP 31
00125 /* How fast should the I2C clock go. The PCF8574 work only with the lowest setting 100000.
00126 A MCP23017 can run also with 400000 Hz */
00127 #define UI_I2C_CLOCKSPEED 100000L
00128 
00131 #if UI_DISPLAY_TYPE==3 // I2C Pin configuration
00132 #define UI_DISPLAY_RS_PIN _BV(4)
00133 #define UI_DISPLAY_RW_PIN _BV(5)
00134 #define UI_DISPLAY_ENABLE_PIN _BV(6)
00135 #define UI_DISPLAY_D0_PIN _BV(0)
00136 #define UI_DISPLAY_D1_PIN _BV(1)
00137 #define UI_DISPLAY_D2_PIN _BV(2)
00138 #define UI_DISPLAY_D3_PIN _BV(3)
00139 #define UI_DISPLAY_D4_PIN _BV(0)
00140 #define UI_DISPLAY_D5_PIN _BV(1)
00141 #define UI_DISPLAY_D6_PIN _BV(2)
00142 #define UI_DISPLAY_D7_PIN _BV(3)
00143 
00144 // Pins for adafruid RGB shield
00145 /*#define UI_DISPLAY_RS_PIN _BV(15)
00146 #define UI_DISPLAY_RW_PIN _BV(14)
00147 #define UI_DISPLAY_ENABLE_PIN _BV(13)
00148 #define UI_DISPLAY_D0_PIN _BV(12)
00149 #define UI_DISPLAY_D1_PIN _BV(11)
00150 #define UI_DISPLAY_D2_PIN _BV(10)
00151 #define UI_DISPLAY_D3_PIN _BV(9)
00152 #define UI_DISPLAY_D4_PIN _BV(12)
00153 #define UI_DISPLAY_D5_PIN _BV(11)
00154 #define UI_DISPLAY_D6_PIN _BV(10)
00155 #define UI_DISPLAY_D7_PIN _BV(9)*/
00156 
00157 #else // Direct display connections
00158 #define UI_DISPLAY_RS_PIN               63              // PINK.1, 88, D_RS
00159 #define UI_DISPLAY_RW_PIN               -1
00160 #define UI_DISPLAY_ENABLE_PIN           65              // PINK.3, 86, D_E
00161 #define UI_DISPLAY_D0_PIN               59              // PINF.5, 92, D_D4
00162 #define UI_DISPLAY_D1_PIN               64              // PINK.2, 87, D_D5
00163 #define UI_DISPLAY_D2_PIN               44              // PINL.5, 40, D_D6
00164 #define UI_DISPLAY_D3_PIN               66              // PINK.4, 85, D_D7
00165 #define UI_DISPLAY_D4_PIN               59              // PINF.5, 92, D_D4
00166 #define UI_DISPLAY_D5_PIN               64              // PINK.2, 87, D_D5
00167 #define UI_DISPLAY_D6_PIN               44              // PINL.5, 40, D_D6
00168 #define UI_DISPLAY_D7_PIN               66              // PINK.4, 85, D_D7
00169 #define UI_DELAYPERCHAR            320
00170 
00171 #endif
00172 
00173 
00179 #define UI_HAS_KEYS 0
00180 
00181 
00187 #define UI_HAS_BACK_KEY 1
00188 
00189 /* Then you have the next/previous keys more like up/down keys, it may be more intuitive to change the direction you skip through the menus.
00190 If you set it to true, next will go to previous menu instead of the next menu.
00191 
00192 */
00193 #define UI_INVERT_MENU_DIRECTION false
00194 
00196 //#define UI_HAS_I2C_KEYS
00197 
00198 // Do you have a I2C connected encoder? 
00199 #define UI_HAS_I2C_ENCODER 0
00200 
00201 // Under which address can the key status requested. This is the address of your PCF8574 where the keys are connected.
00202 // If you use a MCP23017 the address from display is used also for keys.
00203 #define UI_I2C_KEY_ADDRESS 0x40
00204 
00205 
00206 #ifdef UI_MAIN
00207 /* #######################################################################
00208                       Key definitions
00209 
00210 The firmware is very flexible regarding your input methods. You can use one
00211 or more of the predefined key macros, to define a mapper. If no matching mapper
00212 is available, you can add you c-code for mapping directly into the keyboard
00213 routines. The predefined macros do the same, just hiding the code behind it.
00214 
00215 For each key, two seperate parts must be defined. The first is the initialization
00216 which must be added inside ui_init_keys() and the second ist a testing routine.
00217 These come into ui_check_keys() or ui_check_slow_keys() depending on the time needed
00218 for testing. If you are in doubt, put it in ui_check_slow_keys().
00219 ui_init_keys() is called from an interrupt controlling the extruder, so only
00220 fast tests should be put there.
00221 The detect methods need an action identifier. A list of supported ids is found
00222 at the beginning of ui.h It's best to use the symbol name, in case the value changes.
00223 
00224 1. Simple push button connected to gnd if closed on a free arduino pin
00225     init -> UI_KEYS_INIT_BUTTON_LOW(pinNumber);
00226     detect -> UI_KEYS_BUTTON_LOW(pinNumber,action);
00227     
00228 2. Simple push button connected to 5v if closed on a free arduino pin
00229     init -> UI_KEYS_INIT_BUTTON_HIGH(pinNumber);
00230     detect -> UI_KEYS_BUTTON_HIGH(pinNumber,action);
00231     
00232 3. Click encoder, A/B connected to gnd if closed.
00233     init -> UI_KEYS_INIT_CLICKENCODER_LOW(pinA,pinB);
00234     detect -> UI_KEYS_CLICKENCODER_LOW(pinA,pinB);
00235          or   UI_KEYS_CLICKENCODER_LOW_REV(pinA,pinB); // reverse direction
00236     If you can move the menu cursor without a click, just be adding some force in one direction,
00237     toggle the _REV with non _REV and toggle pins.
00238     If the direction is wrong, toggle _REV with non _REV version.
00239     For the push button of the encoder use 1.
00240     
00241 4. Click encoder, A/B connected to 5V if closed.
00242     init -> UI_KEYS_INIT_CLICKENCODER_HIGH(pinA,pinB);
00243     detect -> UI_KEYS_CLICKENCODER_HIGH(pinA,pinB);
00244          or   UI_KEYS_CLICKENCODER_HIGH_REV(pinA,pinB); // reverse direction
00245     If you can move the menu cursor without a click, just be adding some force in one direction,
00246     toggle the _REV with non _REV and toggle pins.
00247     If the direction is wrong, toggle _REV with non _REV version.
00248     For the push button of the encoder use 2.
00249     
00250 5. Maxtrix keyboard with 1-4 rows and 1-4 columns.
00251     init -> UI_KEYS_INIT_MATRIX(r1,r2,r3,r4,c1,c2,c3,c4);
00252     detect -> UI_KEYS_MATRIX(r1,r2,r3,r4,c1,c2,c3,c4);
00253     In addition you have to set UI_MATRIX_ACTIONS to match your desired actions.
00254     
00255 ------- Keys connected via I2C -------------
00256 
00257 All keys and the buzzer if present must be on a connected to a single PCF8574 chip!
00258 As all I2C request take time, they belong all in ui_check_slow_keys.
00259 Dont use the pin ids but instead _BV(pinNumber0_7) as pin id. 0 = First pin
00260 
00261 6. Click encoder, A/B connected to gnd if closed.
00262     init -> not needed, but make sure UI_HAS_I2C_KEY is not commented out.
00263     detect -> UI_KEYS_I2C_CLICKENCODER_LOW(pinA,pinB);
00264          or   UI_KEYS_I2C_CLICKENCODER_LOW_REV(pinA,pinB); // reverse direction
00265     If you can move the menu cursor without a click, just be adding some force in one direction,
00266     toggle the _REV with non _REV and toggle pins.
00267     If the direction is wrong, toggle _REV with non _REV version.
00268     For the push button of the encoder use 7.
00269     NOTICE: The polling frequency is limited, so only slow turns are captured correct!
00270 
00271 7. Simple push button connected to gnd if closed via I2C on a PCF8574
00272     init -> not needed, but make sure UI_HAS_I2C_KEY is not commented out.
00273     detect -> UI_KEYS_I2C_BUTTON_LOW(pinNumber,action);
00274 
00275 -------- Some notes on actions -------------
00276 
00277 There are three kinds of actions. 
00278 
00279 Type 1: Immediate actions - these are execute and forget actions like home/pre-heat
00280 Type 2: Parameter change action - these change the mode for next/previous keys. They are valid
00281         until a new change action is initiated or the action is finished with ok button.
00282 Type 3: Show menu action. These actions have a _MENU_ in their name. If they are executed, a new
00283         menu is pushed on the menu stack and you see the menu. If you assign these actions directly
00284         to a key, you might not want this pushing behaviour. In this case add UI_ACTION_TOPMENU to the
00285         action, like UI_ACTION_TOPMENU+UI_ACTION_MENU_XPOSFAST. That will show the menu as top-menu
00286         closing all othe submenus that were open.
00287         
00288    ####################################################################### */
00289 
00290 // Use these codes for key detect. The main menu will show the pressed action in the lcd display.
00291 // after that assign the desired codes.
00292 //#define UI_MATRIX_ACTIONS {2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015}
00293 // Define your matrix actions
00294 #define UI_MATRIX_ACTIONS {UI_ACTION_HOME_ALL, UI_ACTION_TOP_MENU,       UI_ACTION_SET_ORIGIN,      UI_ACTION_NEXT,\
00295                            UI_ACTION_HOME_Z,   UI_ACTION_MENU_ZPOS,      UI_ACTION_COOLDOWN,        UI_ACTION_OK,\
00296                            UI_ACTION_HOME_Y,   UI_ACTION_MENU_YPOSFAST,  UI_ACTION_PREHEAT_ABS,     UI_ACTION_PREVIOUS,\
00297                            UI_ACTION_HOME_X,   UI_ACTION_MENU_XPOSFAST,  UI_ACTION_DISABLE_STEPPER, UI_ACTION_BACK}
00298 #ifdef UI_MATRIX_ACTIONS
00299 const int matrixActions[] PROGMEM = UI_MATRIX_ACTIONS;
00300 #endif
00301 
00302 void ui_init_keys() {
00303 #if UI_HAS_KEYS!=0
00304   //UI_KEYS_INIT_CLICKENCODER_LOW(33,31); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
00305   UI_KEYS_INIT_BUTTON_LOW(4); // push button, connects gnd to pin
00306   UI_KEYS_INIT_BUTTON_LOW(5);
00307   UI_KEYS_INIT_BUTTON_LOW(6);
00308   UI_KEYS_INIT_BUTTON_LOW(11);
00309   UI_KEYS_INIT_BUTTON_LOW(42);
00310 
00311 //  UI_KEYS_INIT_CLICKENCODER_LOW(47,45); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
00312 //  UI_KEYS_INIT_BUTTON_LOW(43); // push button, connects gnd to pin
00313 //  UI_KEYS_INIT_MATRIX(32,47,45,43,41,39,37,35);
00314 #endif
00315 }
00316 void ui_check_keys(int &action) {
00317 #if UI_HAS_KEYS!=0
00318 
00319  //UI_KEYS_CLICKENCODER_LOW_REV(33,31); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
00320  UI_KEYS_BUTTON_LOW(4,UI_ACTION_OK); // push button, connects gnd to pin
00321  UI_KEYS_BUTTON_LOW(5,UI_ACTION_NEXT); // push button, connects gnd to pin
00322  UI_KEYS_BUTTON_LOW(6,UI_ACTION_PREVIOUS); // push button, connects gnd to pin
00323  UI_KEYS_BUTTON_LOW(11,UI_ACTION_BACK); // push button, connects gnd to pin
00324  UI_KEYS_BUTTON_LOW(42,UI_ACTION_SD_PRINT ); // push button, connects gnd to pin
00325 //  UI_KEYS_CLICKENCODER_LOW_REV(47,45); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
00326 //  UI_KEYS_BUTTON_LOW(43,UI_ACTION_OK); // push button, connects gnd to pin
00327 #endif
00328 }
00329 inline void ui_check_slow_encoder() {
00330 #if defined(UI_HAS_I2C_KEYS) && UI_HAS_KEYS!=0
00331 #if UI_DISPLAY_I2C_CHIPTYPE==0
00332   i2c_start_wait(UI_I2C_KEY_ADDRESS+I2C_READ);
00333   byte keymask = i2c_readNak(); // Read current key mask
00334 #endif
00335 #if UI_DISPLAY_I2C_CHIPTYPE==1
00336     i2c_start_wait(UI_DISPLAY_I2C_ADDRESS+I2C_WRITE);
00337     i2c_write(0x12); // GIOA
00338     i2c_stop();
00339     i2c_start_wait(UI_DISPLAY_I2C_ADDRESS+I2C_READ);
00340     unsigned int keymask = i2c_readAck();
00341     keymask = keymask + (i2c_readNak()<<8);
00342 #endif
00343   i2c_stop();
00344   // Add I2C click encoder tests here, all other i2c tests and a copy of the encoder test belog in ui_check_slow_keys
00345   UI_KEYS_I2C_CLICKENCODER_LOW_REV(_BV(2),_BV(0)); // click encoder on pins 0 and 2. Phase is connected with gnd for signals.
00346 #endif
00347 }
00348 void ui_check_slow_keys(int &action) {
00349 #if defined(UI_HAS_I2C_KEYS) && UI_HAS_KEYS!=0
00350 #if UI_DISPLAY_I2C_CHIPTYPE==0
00351     i2c_start_wait(UI_I2C_KEY_ADDRESS+I2C_READ);
00352     byte keymask = i2c_readNak(); // Read current key mask
00353 #endif
00354 #if UI_DISPLAY_I2C_CHIPTYPE==1
00355     i2c_start_wait(UI_DISPLAY_I2C_ADDRESS+I2C_WRITE);
00356     i2c_write(0x12); // GPIOA
00357     i2c_stop();
00358     i2c_start_wait(UI_DISPLAY_I2C_ADDRESS+I2C_READ);
00359     unsigned int keymask = i2c_readAck();
00360     keymask = keymask + (i2c_readNak()<<8);
00361 #endif
00362     i2c_stop();
00363     // Add I2C key tests here
00364     UI_KEYS_I2C_CLICKENCODER_LOW_REV(_BV(2),_BV(0)); // click encoder on pins 0 and 2. Phase is connected with gnd for signals.
00365     UI_KEYS_I2C_BUTTON_LOW(_BV(1),UI_ACTION_OK); // push button, connects gnd to pin  
00366     UI_KEYS_I2C_BUTTON_LOW(_BV(3),UI_ACTION_BACK); // push button, connects gnd to pin  
00367     UI_KEYS_I2C_BUTTON_LOW(_BV(4),UI_ACTION_MENU_QUICKSETTINGS+UI_ACTION_TOPMENU); // push button, connects gnd to pin  
00368     UI_KEYS_I2C_BUTTON_LOW(_BV(5),UI_ACTION_MENU_EXTRUDER+UI_ACTION_TOPMENU); // push button, connects gnd to pin  
00369     UI_KEYS_I2C_BUTTON_LOW(_BV(6),UI_ACTION_MENU_POSITIONS+UI_ACTION_TOPMENU); // push button, connects gnd to pin  
00370 /*
00371   // Button handling for the Adafruit RGB shild
00372     UI_KEYS_I2C_BUTTON_LOW(4,UI_ACTION_PREVIOUS); // Up button
00373     UI_KEYS_I2C_BUTTON_LOW(8,UI_ACTION_NEXT); // down button
00374     UI_KEYS_I2C_BUTTON_LOW(16,UI_ACTION_BACK); // left button
00375     UI_KEYS_I2C_BUTTON_LOW(2,UI_ACTION_OK); // right button
00376     UI_KEYS_I2C_BUTTON_LOW(1,UI_ACTION_MENU_QUICKSETTINGS);  //Select button
00377   // ----- End RGB shield ----------
00378   */
00379 #endif
00380 
00381   //UI_KEYS_MATRIX(32,47,45,43,41,39,37,35);
00382 }
00383 
00384 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Defines