Repetier-Firmware  0.91
src/ArduinoAVR/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 .
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 #define BEEPER_TYPE_INVERTING false
00076 #endif
00077 
00078 #if BEEPER_TYPE==1 && !defined(BEEPER_PIN)
00079 #define BEEPER_PIN 37
00080 #endif
00081 #if BEEPER_TYPE==2
00082 #define BEEPER_ADDRESS 0x40 // I2C address of the chip with the beeper pin
00083 #define BEEPER_PIN _BV(7)  // Bit value for pin 8
00084 #define COMPILE_I2C_DRIVER  // We need the I2C driver as we are using i2c
00085 #endif
00086 
00087 
00099 #define UI_DISPLAY_TYPE 0
00100 
00105 #define UI_COLS 20
00106 
00109 #define UI_ROWS 4
00110 
00111 /* What type of chip is used for I2C communication
00112 0 : PCF8574 or PCF8574A or compatible chips.
00113 1 : MCP23017
00114 */
00115 #define UI_DISPLAY_I2C_CHIPTYPE 0
00116 // 0x40 till 0x4e for PCF8574, 0x40 for the adafruid RGB shield, 0x40 - 0x4e for MCP23017
00117 // Official addresses have a value half as high!
00118 #define UI_DISPLAY_I2C_ADDRESS 0x4e
00119 // For MCP 23017 define which pins should be output
00120 #define UI_DISPLAY_I2C_OUTPUT_PINS 65504
00121 // Set the output mask that is or'd over the output data. This is needed to activate
00122 // a backlight switched over the I2C.
00123 // The adafruit RGB shields enables a light if the bit is not set. Bits 6-8 are used for backlight.
00124 #define UI_DISPLAY_I2C_OUTPUT_START_MASK 0
00125 // For MCP which inputs are with pullup. 31 = pins 0-4 for adafruid rgb shield buttons
00126 #define UI_DISPLAY_I2C_PULLUP 31
00127 /* How fast should the I2C clock go. The PCF8574 work only with the lowest setting 100000.
00128 A MCP23017 can run also with 400000 Hz */
00129 #define UI_I2C_CLOCKSPEED 100000L
00130 
00133 #if UI_DISPLAY_TYPE==3 // I2C Pin configuration
00134 #define UI_DISPLAY_RS_PIN _BV(4)
00135 #define UI_DISPLAY_RW_PIN _BV(5)
00136 #define UI_DISPLAY_ENABLE_PIN _BV(6)
00137 #define UI_DISPLAY_D0_PIN _BV(0)
00138 #define UI_DISPLAY_D1_PIN _BV(1)
00139 #define UI_DISPLAY_D2_PIN _BV(2)
00140 #define UI_DISPLAY_D3_PIN _BV(3)
00141 #define UI_DISPLAY_D4_PIN _BV(0)
00142 #define UI_DISPLAY_D5_PIN _BV(1)
00143 #define UI_DISPLAY_D6_PIN _BV(2)
00144 #define UI_DISPLAY_D7_PIN _BV(3)
00145 
00146 // Pins for adafruid RGB shield
00147 /*#define UI_DISPLAY_RS_PIN _BV(15)
00148 #define UI_DISPLAY_RW_PIN _BV(14)
00149 #define UI_DISPLAY_ENABLE_PIN _BV(13)
00150 #define UI_DISPLAY_D0_PIN _BV(12)
00151 #define UI_DISPLAY_D1_PIN _BV(11)
00152 #define UI_DISPLAY_D2_PIN _BV(10)
00153 #define UI_DISPLAY_D3_PIN _BV(9)
00154 #define UI_DISPLAY_D4_PIN _BV(12)
00155 #define UI_DISPLAY_D5_PIN _BV(11)
00156 #define UI_DISPLAY_D6_PIN _BV(10)
00157 #define UI_DISPLAY_D7_PIN _BV(9)*/
00158 
00159 #else // Direct display connections
00160 #define UI_DISPLAY_RS_PIN               63              // PINK.1, 88, D_RS
00161 #define UI_DISPLAY_RW_PIN               -1
00162 #define UI_DISPLAY_ENABLE_PIN           65              // PINK.3, 86, D_E
00163 #define UI_DISPLAY_D0_PIN               59              // PINF.5, 92, D_D4
00164 #define UI_DISPLAY_D1_PIN               64              // PINK.2, 87, D_D5
00165 #define UI_DISPLAY_D2_PIN               44              // PINL.5, 40, D_D6
00166 #define UI_DISPLAY_D3_PIN               66              // PINK.4, 85, D_D7
00167 #define UI_DISPLAY_D4_PIN               59              // PINF.5, 92, D_D4
00168 #define UI_DISPLAY_D5_PIN               64              // PINK.2, 87, D_D5
00169 #define UI_DISPLAY_D6_PIN               44              // PINL.5, 40, D_D6
00170 #define UI_DISPLAY_D7_PIN               66              // PINK.4, 85, D_D7
00171 #define UI_DELAYPERCHAR            320
00172 
00173 #endif
00174 
00175 
00181 #define UI_HAS_KEYS 0
00182 
00183 
00189 #define UI_HAS_BACK_KEY 1
00190 
00191 /* 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.
00192 If you set it to true, next will go to previous menu instead of the next menu.
00193 
00194 */
00195 #define UI_INVERT_MENU_DIRECTION false
00196 
00198 //#define UI_HAS_I2C_KEYS
00199 
00200 // Do you have a I2C connected encoder?
00201 #define UI_HAS_I2C_ENCODER 0
00202 
00203 // Under which address can the key status requested. This is the address of your PCF8574 where the keys are connected.
00204 // If you use a MCP23017 the address from display is used also for keys.
00205 #define UI_I2C_KEY_ADDRESS 0x40
00206 
00207 
00208 #ifdef UI_MAIN
00209 /* #######################################################################
00210                       Key definitions
00211 
00212 The firmware is very flexible regarding your input methods. You can use one
00213 or more of the predefined key macros, to define a mapper. If no matching mapper
00214 is available, you can add you c-code for mapping directly into the keyboard
00215 routines. The predefined macros do the same, just hiding the code behind it.
00216 
00217 For each key, two seperate parts must be defined. The first is the initialization
00218 which must be added inside ui_init_keys() and the second ist a testing routine.
00219 These come into ui_check_keys() or ui_check_slow_keys() depending on the time needed
00220 for testing. If you are in doubt, put it in ui_check_slow_keys().
00221 ui_init_keys() is called from an interrupt controlling the extruder, so only
00222 fast tests should be put there.
00223 The detect methods need an action identifier. A list of supported ids is found
00224 at the beginning of ui.h It's best to use the symbol name, in case the value changes.
00225 
00226 1. Simple push button connected to gnd if closed on a free arduino pin
00227     init -> UI_KEYS_INIT_BUTTON_LOW(pinNumber);
00228     detect -> UI_KEYS_BUTTON_LOW(pinNumber,action);
00229 
00230 2. Simple push button connected to 5v if closed on a free arduino pin
00231     init -> UI_KEYS_INIT_BUTTON_HIGH(pinNumber);
00232     detect -> UI_KEYS_BUTTON_HIGH(pinNumber,action);
00233 
00234 3. Click encoder, A/B connected to gnd if closed.
00235     init -> UI_KEYS_INIT_CLICKENCODER_LOW(pinA,pinB);
00236     detect -> UI_KEYS_CLICKENCODER_LOW(pinA,pinB);
00237          or   UI_KEYS_CLICKENCODER_LOW_REV(pinA,pinB); // reverse direction
00238     If you can move the menu cursor without a click, just be adding some force in one direction,
00239     toggle the _REV with non _REV and toggle pins.
00240     If the direction is wrong, toggle _REV with non _REV version.
00241     For the push button of the encoder use 1.
00242 
00243 4. Click encoder, A/B connected to 5V if closed.
00244     init -> UI_KEYS_INIT_CLICKENCODER_HIGH(pinA,pinB);
00245     detect -> UI_KEYS_CLICKENCODER_HIGH(pinA,pinB);
00246          or   UI_KEYS_CLICKENCODER_HIGH_REV(pinA,pinB); // reverse direction
00247     If you can move the menu cursor without a click, just be adding some force in one direction,
00248     toggle the _REV with non _REV and toggle pins.
00249     If the direction is wrong, toggle _REV with non _REV version.
00250     For the push button of the encoder use 2.
00251 
00252 5. Maxtrix keyboard with 1-4 rows and 1-4 columns.
00253     init -> UI_KEYS_INIT_MATRIX(r1,r2,r3,r4,c1,c2,c3,c4);
00254     detect -> UI_KEYS_MATRIX(r1,r2,r3,r4,c1,c2,c3,c4);
00255     In addition you have to set UI_MATRIX_ACTIONS to match your desired actions.
00256 
00257 ------- Keys connected via I2C -------------
00258 
00259 All keys and the buzzer if present must be on a connected to a single PCF8574 chip!
00260 As all I2C request take time, they belong all in ui_check_slow_keys.
00261 Dont use the pin ids but instead _BV(pinNumber0_7) as pin id. 0 = First pin
00262 
00263 6. Click encoder, A/B connected to gnd if closed.
00264     init -> not needed, but make sure UI_HAS_I2C_KEY is not commented out.
00265     detect -> UI_KEYS_I2C_CLICKENCODER_LOW(pinA,pinB);
00266          or   UI_KEYS_I2C_CLICKENCODER_LOW_REV(pinA,pinB); // reverse direction
00267     If you can move the menu cursor without a click, just be adding some force in one direction,
00268     toggle the _REV with non _REV and toggle pins.
00269     If the direction is wrong, toggle _REV with non _REV version.
00270     For the push button of the encoder use 7.
00271     NOTICE: The polling frequency is limited, so only slow turns are captured correct!
00272 
00273 7. Simple push button connected to gnd if closed via I2C on a PCF8574
00274     init -> not needed, but make sure UI_HAS_I2C_KEY is not commented out.
00275     detect -> UI_KEYS_I2C_BUTTON_LOW(pinNumber,action);
00276 
00277 -------- Some notes on actions -------------
00278 
00279 There are three kinds of actions.
00280 
00281 Type 1: Immediate actions - these are execute and forget actions like home/pre-heat
00282 Type 2: Parameter change action - these change the mode for next/previous keys. They are valid
00283         until a new change action is initiated or the action is finished with ok button.
00284 Type 3: Show menu action. These actions have a _MENU_ in their name. If they are executed, a new
00285         menu is pushed on the menu stack and you see the menu. If you assign these actions directly
00286         to a key, you might not want this pushing behaviour. In this case add UI_ACTION_TOPMENU to the
00287         action, like UI_ACTION_TOPMENU+UI_ACTION_MENU_XPOSFAST. That will show the menu as top-menu
00288         closing all othe submenus that were open.
00289 
00290    ####################################################################### */
00291 
00292 // Use these codes for key detect. The main menu will show the pressed action in the lcd display.
00293 // after that assign the desired codes.
00294 //#define UI_MATRIX_ACTIONS {2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015}
00295 // Define your matrix actions
00296 #define UI_MATRIX_ACTIONS {UI_ACTION_HOME_ALL, UI_ACTION_TOP_MENU,       UI_ACTION_SET_ORIGIN,      UI_ACTION_NEXT,\
00297                            UI_ACTION_HOME_Z,   UI_ACTION_MENU_ZPOS,      UI_ACTION_COOLDOWN,        UI_ACTION_OK,\
00298                            UI_ACTION_HOME_Y,   UI_ACTION_MENU_YPOSFAST,  UI_ACTION_PREHEAT_ABS,     UI_ACTION_PREVIOUS,\
00299                            UI_ACTION_HOME_X,   UI_ACTION_MENU_XPOSFAST,  UI_ACTION_DISABLE_STEPPER, UI_ACTION_BACK}
00300 #ifdef UI_MATRIX_ACTIONS
00301 const int matrixActions[] PROGMEM = UI_MATRIX_ACTIONS;
00302 #endif
00303 
00304 void ui_init_keys() {
00305 #if UI_HAS_KEYS!=0
00306   //UI_KEYS_INIT_CLICKENCODER_LOW(33,31); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
00307   UI_KEYS_INIT_BUTTON_LOW(4); // push button, connects gnd to pin
00308   UI_KEYS_INIT_BUTTON_LOW(5);
00309   UI_KEYS_INIT_BUTTON_LOW(6);
00310   UI_KEYS_INIT_BUTTON_LOW(11);
00311   UI_KEYS_INIT_BUTTON_LOW(42);
00312 
00313 //  UI_KEYS_INIT_CLICKENCODER_LOW(47,45); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
00314 //  UI_KEYS_INIT_BUTTON_LOW(43); // push button, connects gnd to pin
00315 //  UI_KEYS_INIT_MATRIX(32,47,45,43,41,39,37,35);
00316 #endif
00317 }
00318 void ui_check_keys(int &action) {
00319 #if UI_HAS_KEYS!=0
00320 
00321  //UI_KEYS_CLICKENCODER_LOW_REV(33,31); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
00322  UI_KEYS_BUTTON_LOW(4,UI_ACTION_OK); // push button, connects gnd to pin
00323  UI_KEYS_BUTTON_LOW(5,UI_ACTION_NEXT); // push button, connects gnd to pin
00324  UI_KEYS_BUTTON_LOW(6,UI_ACTION_PREVIOUS); // push button, connects gnd to pin
00325  UI_KEYS_BUTTON_LOW(11,UI_ACTION_BACK); // push button, connects gnd to pin
00326  UI_KEYS_BUTTON_LOW(42,UI_ACTION_SD_PRINT ); // push button, connects gnd to pin
00327 //  UI_KEYS_CLICKENCODER_LOW_REV(47,45); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
00328 //  UI_KEYS_BUTTON_LOW(43,UI_ACTION_OK); // push button, connects gnd to pin
00329 #endif
00330 }
00331 inline void ui_check_slow_encoder() {
00332 #if defined(UI_HAS_I2C_KEYS) && UI_HAS_KEYS!=0
00333 #if UI_DISPLAY_I2C_CHIPTYPE==0
00334   HAL::i2cStartWait(UI_I2C_KEY_ADDRESS+I2C_READ);
00335   uint8_t keymask = HAL::i2cReadNak(); // Read current key mask
00336 #endif
00337 #if UI_DISPLAY_I2C_CHIPTYPE==1
00338     HAL::i2cStartWait(UI_DISPLAY_I2C_ADDRESS+I2C_WRITE);
00339     HAL::i2cWrite(0x12); // GIOA
00340     HAL::i2cStop();
00341     HAL::i2cStartWait(UI_DISPLAY_I2C_ADDRESS+I2C_READ);
00342     unsigned int keymask = HAL::i2cReadAck();
00343     keymask = keymask + (HAL::i2cReadNak()<<8);
00344 #endif
00345   HAL::i2cStop();
00346   // Add I2C click encoder tests here, all other i2c tests and a copy of the encoder test belog in ui_check_slow_keys
00347   UI_KEYS_I2C_CLICKENCODER_LOW_REV(_BV(2),_BV(0)); // click encoder on pins 0 and 2. Phase is connected with gnd for signals.
00348 #endif
00349 }
00350 void ui_check_slow_keys(int &action) {
00351 #if defined(UI_HAS_I2C_KEYS) && UI_HAS_KEYS!=0
00352 #if UI_DISPLAY_I2C_CHIPTYPE==0
00353     HAL::i2cStartWait(UI_I2C_KEY_ADDRESS+I2C_READ);
00354     uint8_t keymask = HAL::i2cReadNak(); // Read current key mask
00355 #endif
00356 #if UI_DISPLAY_I2C_CHIPTYPE==1
00357     HAL::i2cStartWait(UI_DISPLAY_I2C_ADDRESS+I2C_WRITE);
00358     HAL::i2cWrite(0x12); // GPIOA
00359     HAL::i2cStop();
00360     HAL::i2cStartWait(UI_DISPLAY_I2C_ADDRESS+I2C_READ);
00361     unsigned int keymask = HAL::i2cReadAck();
00362     keymask = keymask + (HAL::i2cReadNak()<<8);
00363 #endif
00364     HAL::i2cStop();
00365     // Add I2C key tests here
00366     UI_KEYS_I2C_CLICKENCODER_LOW_REV(_BV(2),_BV(0)); // click encoder on pins 0 and 2. Phase is connected with gnd for signals.
00367     UI_KEYS_I2C_BUTTON_LOW(_BV(1),UI_ACTION_OK); // push button, connects gnd to pin
00368     UI_KEYS_I2C_BUTTON_LOW(_BV(3),UI_ACTION_BACK); // push button, connects gnd to pin
00369     UI_KEYS_I2C_BUTTON_LOW(_BV(4),UI_ACTION_MENU_QUICKSETTINGS+UI_ACTION_TOPMENU); // push button, connects gnd to pin
00370     UI_KEYS_I2C_BUTTON_LOW(_BV(5),UI_ACTION_MENU_EXTRUDER+UI_ACTION_TOPMENU); // push button, connects gnd to pin
00371     UI_KEYS_I2C_BUTTON_LOW(_BV(6),UI_ACTION_MENU_POSITIONS+UI_ACTION_TOPMENU); // push button, connects gnd to pin
00372 /*
00373   // Button handling for the Adafruit RGB shild
00374     UI_KEYS_I2C_BUTTON_LOW(4,UI_ACTION_PREVIOUS); // Up button
00375     UI_KEYS_I2C_BUTTON_LOW(8,UI_ACTION_NEXT); // down button
00376     UI_KEYS_I2C_BUTTON_LOW(16,UI_ACTION_BACK); // left button
00377     UI_KEYS_I2C_BUTTON_LOW(2,UI_ACTION_OK); // right button
00378     UI_KEYS_I2C_BUTTON_LOW(1,UI_ACTION_MENU_QUICKSETTINGS);  //Select button
00379   // ----- End RGB shield ----------
00380   */
00381 #endif
00382 
00383   //UI_KEYS_MATRIX(32,47,45,43,41,39,37,35);
00384 }
00385 
00386 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Defines