/ Repetier / uiconfig.h
uiconfig.h
  1  /*
  2      This file is part of Repetier-Firmware.
  3  
  4      Repetier-Firmware is free software: you can redistribute it and/or modify
  5      it under the terms of the GNU General Public License as published by
  6      the Free Software Foundation, either version 3 of the License, or
  7      (at your option) any later version.
  8  
  9      Repetier-Firmware is distributed in the hope that it will be useful,
 10      but WITHOUT ANY WARRANTY; without even the implied warranty of
 11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12      GNU General Public License for more details.
 13  
 14      You should have received a copy of the GNU General Public License
 15      along with Repetier-Firmware.  If not, see <http://www.gnu.org/licenses/>.
 16  
 17  */
 18  
 19  /* ===================== IMPORTANT ========================
 20  
 21  The LCD and Key support is new. I tested everything as good as possible,
 22  but some combinations may not work as supposed.
 23  The I2C methods rely on a stable I2C connection. Noise may cause wrong signals
 24  which can cause the firmware to freeze.
 25  
 26  The ui adds quite some code, so AVRs with 64kB ram (Sanguino, Gen6) can not handle all features
 27  of the firmware at the same time. You have to disable some features to gain the
 28  ram needed. What should work:
 29  - No sd card - the sd card code is quite large.
 30  - No keys attached - The longest part is the menu handling.
 31  - EEPROM_MODE 0 and USE_OPS 0. 
 32  
 33  Currently supported hardware:
 34  
 35  *** Displays ***
 36  
 37  - direct connected lcd with 4 data lines
 38  - connected via i2c
 39  
 40  *** Keys ***
 41  
 42  - rotary encoder
 43  - push button
 44  - key matrix up to 4x4
 45  - rotary encoder via i2c (only slow turns are captured correct)
 46  - push button via i2c
 47  
 48  *** Buzzer ***
 49  
 50  - directly connected, high = on
 51  - connected via i2c, low = on
 52  
 53  ==============================================================*/
 54  
 55  
 56  /** While the ascii chars are all the same, the driver have different charsets
 57  for special chars used in different countries. The charset allows to fix for 
 58  this problem. If characters look wrong, try a different charset. If nothing
 59  works, use the ascii charset 0 as fallback. Not the nicest for everything but working!
 60  
 61  0 = ASCII fallback
 62  1 = Default works on most displays. This has some japanese chars in charset
 63  2 = Alternative charset with more european chars
 64  
 65  */
 66  #define UI_DISPLAY_CHARSET 1
 67  
 68  /** Select type of beeper
 69  0 = none
 70  1 = Piezo connected to pin
 71  2 = Piezo connected to a pin over I2C 
 72  */
 73  #ifndef BEEPER_TYPE
 74  #define BEEPER_TYPE 1
 75  #endif
 76  
 77  #if BEEPER_TYPE==1 && !defined(BEEPER_PIN)
 78  #define BEEPER_PIN 79
 79  #endif
 80  #if BEEPER_TYPE==2
 81  #define BEEPER_ADDRESS 0x40 // I2C address of the chip with the beeper pin
 82  #define BEEPER_PIN _BV(7)  // Bit value for pin 8
 83  #define COMPILE_I2C_DRIVER  // We need the I2C driver as we are using i2c
 84  #endif
 85  
 86  
 87  /**
 88  What display type do you use?
 89  0 = No display
 90  1 = LCD Display with 4 bit data bus
 91  2 = LCD Display with 8 bit data bus (currently not implemented, fallback to 1)
 92  3 = LCD Display with I2C connection, 4 bit mode
 93  4 = Use the slower LiquiedCrystal library bundled with arduino. 
 94      IMPORTANT: You need to uncomment the LiquidCrystal include in Repetier.pde for it to work.
 95                 If you have Sanguino and want to use the library, you need to have Arduino 023 or older. (13.04.2012)
 96  */
 97  #define UI_DISPLAY_TYPE 1
 98  
 99  /** Number of columns per row
100  
101  Typical values are 16 and 20
102  */
103  #define UI_COLS 20
104  /**
105  Rows of your display. 2 or 4
106  */
107  #define UI_ROWS 4
108  
109  /* What type of chip is used for I2C communication
110  0 : PCF8574 or PCF8574A or compatible chips.
111  1 : MCP23017
112  */
113  #define UI_DISPLAY_I2C_CHIPTYPE 0
114  // 0x40 till 0x4e for PCF8574, 0x40 for the adafruid RGB shield, 0x40 - 0x4e for MCP23017
115  // Official addresses have a value twice as high!
116  #define UI_DISPLAY_I2C_ADDRESS 0x4e
117  // For MCP 23017 define which pins should be output
118  #define UI_DISPLAY_I2C_OUTPUT_PINS 65504
119  // Set the output mask that is or'd over the output data. This is needed to activate
120  // a backlight switched over the I2C. 
121  // The adafruit RGB shields enables a light if the bit is not set. Bits 6-8 are used for backlight.
122  #define UI_DISPLAY_I2C_OUTPUT_START_MASK 0
123  // For MCP which inputs are with pullup. 31 = pins 0-4 for adafruid rgb shield buttons
124  #define UI_DISPLAY_I2C_PULLUP 31
125  /* How fast should the I2C clock go. The PCF8574 work only with the lowest setting 100000.
126  A MCP23017 can run also with 400000 Hz */
127  #define UI_I2C_CLOCKSPEED 100000L
128  /**
129  Define the pin
130  */
131  #if UI_DISPLAY_TYPE==3 // I2C Pin configuration
132  #define UI_DISPLAY_RS_PIN _BV(4)
133  #define UI_DISPLAY_RW_PIN _BV(5)
134  #define UI_DISPLAY_ENABLE_PIN _BV(6)
135  #define UI_DISPLAY_D0_PIN _BV(0)
136  #define UI_DISPLAY_D1_PIN _BV(1)
137  #define UI_DISPLAY_D2_PIN _BV(2)
138  #define UI_DISPLAY_D3_PIN _BV(3)
139  #define UI_DISPLAY_D4_PIN _BV(0)
140  #define UI_DISPLAY_D5_PIN _BV(1)
141  #define UI_DISPLAY_D6_PIN _BV(2)
142  #define UI_DISPLAY_D7_PIN _BV(3)
143  
144  // Pins for adafruid RGB shield
145  /*#define UI_DISPLAY_RS_PIN _BV(15)
146  #define UI_DISPLAY_RW_PIN _BV(14)
147  #define UI_DISPLAY_ENABLE_PIN _BV(13)
148  #define UI_DISPLAY_D0_PIN _BV(12)
149  #define UI_DISPLAY_D1_PIN _BV(11)
150  #define UI_DISPLAY_D2_PIN _BV(10)
151  #define UI_DISPLAY_D3_PIN _BV(9)
152  #define UI_DISPLAY_D4_PIN _BV(12)
153  #define UI_DISPLAY_D5_PIN _BV(11)
154  #define UI_DISPLAY_D6_PIN _BV(10)
155  #define UI_DISPLAY_D7_PIN _BV(9)*/
156  
157  #else // Direct display connections
158  #define UI_DISPLAY_RS_PIN		70//63		// PINK.1, 88, D_RS
159  #define UI_DISPLAY_RW_PIN		-1
160  #define UI_DISPLAY_ENABLE_PIN	        71//		// PINK.3, 86, D_E
161  #define UI_DISPLAY_D0_PIN		72		// PINF.5, 92, D_D4
162  #define UI_DISPLAY_D1_PIN		73		// PINK.2, 87, D_D5
163  #define UI_DISPLAY_D2_PIN		74		// PINL.5, 40, D_D6
164  #define UI_DISPLAY_D3_PIN		75		// PINK.4, 85, D_D7
165  #define UI_DISPLAY_D4_PIN		72		// PINF.5, 92, D_D4
166  #define UI_DISPLAY_D5_PIN		73		// PINK.2, 87, D_D5
167  #define UI_DISPLAY_D6_PIN		74		// PINL.5, 40, D_D6
168  #define UI_DISPLAY_D7_PIN		75		// PINK.4, 85, D_D7
169  #define UI_DELAYPERCHAR		   320
170  
171  #endif
172  
173  
174  /** \brief Are some keys connected?
175  
176  0 = No keys attached - disables also menu
177  1 = Some keys attached
178  */
179  #define UI_HAS_KEYS 1
180  
181  
182  /** \brief Is a back key present.
183  
184  If you have menus enabled, you need a method to leave it. If you have a back key, you can always go one level higher.
185  Without a back key, you need to navigate to the back entry in the menu. Setting this value to 1 removes the back entry.
186  */
187  #define UI_HAS_BACK_KEY 0
188  
189  /* 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.
190  If you set it to true, next will go to previous menu instead of the next menu.
191  
192  */
193  #define UI_INVERT_MENU_DIRECTION false
194  
195  /** Uncomment this, if you have keys connected via i2c to a PCF8574 chip. */
196  //#define UI_HAS_I2C_KEYS
197  
198  // Do you have a I2C connected encoder? 
199  #define UI_HAS_I2C_ENCODER 0
200  
201  // Under which address can the key status requested. This is the address of your PCF8574 where the keys are connected.
202  // If you use a MCP23017 the address from display is used also for keys.
203  #define UI_I2C_KEY_ADDRESS 0x40
204  
205  
206  #ifdef UI_MAIN
207  /* #######################################################################
208                        Key definitions
209  
210  The firmware is very flexible regarding your input methods. You can use one
211  or more of the predefined key macros, to define a mapper. If no matching mapper
212  is available, you can add you c-code for mapping directly into the keyboard
213  routines. The predefined macros do the same, just hiding the code behind it.
214  
215  For each key, two seperate parts must be defined. The first is the initialization
216  which must be added inside ui_init_keys() and the second ist a testing routine.
217  These come into ui_check_keys() or ui_check_slow_keys() depending on the time needed
218  for testing. If you are in doubt, put it in ui_check_slow_keys().
219  ui_init_keys() is called from an interrupt controlling the extruder, so only
220  fast tests should be put there.
221  The detect methods need an action identifier. A list of supported ids is found
222  at the beginning of ui.h It's best to use the symbol name, in case the value changes.
223  
224  1. Simple push button connected to gnd if closed on a free arduino pin
225      init -> UI_KEYS_INIT_BUTTON_LOW(pinNumber);
226      detect -> UI_KEYS_BUTTON_LOW(pinNumber,action);
227      
228  2. Simple push button connected to 5v if closed on a free arduino pin
229      init -> UI_KEYS_INIT_BUTTON_HIGH(pinNumber);
230      detect -> UI_KEYS_BUTTON_HIGH(pinNumber,action);
231      
232  3. Click encoder, A/B connected to gnd if closed.
233      init -> UI_KEYS_INIT_CLICKENCODER_LOW(pinA,pinB);
234      detect -> UI_KEYS_CLICKENCODER_LOW(pinA,pinB);
235           or   UI_KEYS_CLICKENCODER_LOW_REV(pinA,pinB); // reverse direction
236      If you can move the menu cursor without a click, just be adding some force in one direction,
237      toggle the _REV with non _REV and toggle pins.
238      If the direction is wrong, toggle _REV with non _REV version.
239      For the push button of the encoder use 1.
240      
241  4. Click encoder, A/B connected to 5V if closed.
242      init -> UI_KEYS_INIT_CLICKENCODER_HIGH(pinA,pinB);
243      detect -> UI_KEYS_CLICKENCODER_HIGH(pinA,pinB);
244           or   UI_KEYS_CLICKENCODER_HIGH_REV(pinA,pinB); // reverse direction
245      If you can move the menu cursor without a click, just be adding some force in one direction,
246      toggle the _REV with non _REV and toggle pins.
247      If the direction is wrong, toggle _REV with non _REV version.
248      For the push button of the encoder use 2.
249      
250  5. Maxtrix keyboard with 1-4 rows and 1-4 columns.
251      init -> UI_KEYS_INIT_MATRIX(r1,r2,r3,r4,c1,c2,c3,c4);
252      detect -> UI_KEYS_MATRIX(r1,r2,r3,r4,c1,c2,c3,c4);
253      In addition you have to set UI_MATRIX_ACTIONS to match your desired actions.
254      
255  ------- Keys connected via I2C -------------
256  
257  All keys and the buzzer if present must be on a connected to a single PCF8574 chip!
258  As all I2C request take time, they belong all in ui_check_slow_keys.
259  Dont use the pin ids but instead _BV(pinNumber0_7) as pin id. 0 = First pin
260  
261  6. Click encoder, A/B connected to gnd if closed.
262      init -> not needed, but make sure UI_HAS_I2C_KEY is not commented out.
263      detect -> UI_KEYS_I2C_CLICKENCODER_LOW(pinA,pinB);
264           or   UI_KEYS_I2C_CLICKENCODER_LOW_REV(pinA,pinB); // reverse direction
265      If you can move the menu cursor without a click, just be adding some force in one direction,
266      toggle the _REV with non _REV and toggle pins.
267      If the direction is wrong, toggle _REV with non _REV version.
268      For the push button of the encoder use 7.
269      NOTICE: The polling frequency is limited, so only slow turns are captured correct!
270  
271  7. Simple push button connected to gnd if closed via I2C on a PCF8574
272      init -> not needed, but make sure UI_HAS_I2C_KEY is not commented out.
273      detect -> UI_KEYS_I2C_BUTTON_LOW(pinNumber,action);
274  
275  -------- Some notes on actions -------------
276  
277  There are three kinds of actions. 
278  
279  Type 1: Immediate actions - these are execute and forget actions like home/pre-heat
280  Type 2: Parameter change action - these change the mode for next/previous keys. They are valid
281          until a new change action is initiated or the action is finished with ok button.
282  Type 3: Show menu action. These actions have a _MENU_ in their name. If they are executed, a new
283          menu is pushed on the menu stack and you see the menu. If you assign these actions directly
284          to a key, you might not want this pushing behaviour. In this case add UI_ACTION_TOPMENU to the
285          action, like UI_ACTION_TOPMENU+UI_ACTION_MENU_XPOSFAST. That will show the menu as top-menu
286          closing all othe submenus that were open.
287          
288     ####################################################################### */
289  
290  // Use these codes for key detect. The main menu will show the pressed action in the lcd display.
291  // after that assign the desired codes.
292  //#define UI_MATRIX_ACTIONS {2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015}
293  // Define your matrix actions
294  #define UI_MATRIX_ACTIONS {UI_ACTION_HOME_ALL, UI_ACTION_TOP_MENU,       UI_ACTION_SET_ORIGIN,      UI_ACTION_NEXT,\
295                             UI_ACTION_HOME_Z,   UI_ACTION_MENU_ZPOS,      UI_ACTION_COOLDOWN,        UI_ACTION_OK,\
296                             UI_ACTION_HOME_Y,   UI_ACTION_MENU_YPOSFAST,  UI_ACTION_PREHEAT_ABS,     UI_ACTION_PREVIOUS,\
297                             UI_ACTION_HOME_X,   UI_ACTION_MENU_XPOSFAST,  UI_ACTION_DISABLE_STEPPER, UI_ACTION_BACK}
298  #ifdef UI_MATRIX_ACTIONS
299  const int matrixActions[] PROGMEM = UI_MATRIX_ACTIONS;
300  #endif
301  
302  void ui_init_keys() {
303  #if UI_HAS_KEYS!=0
304    UI_KEYS_INIT_CLICKENCODER_LOW(76,77); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
305    UI_KEYS_INIT_BUTTON_LOW(78);
306    UI_KEYS_INIT_BUTTON_LOW(KILL_PIN);
307  
308  //  UI_KEYS_INIT_BUTTON_LOW(4); // push button, connects gnd to pin
309  //  UI_KEYS_INIT_BUTTON_LOW(5);
310  //  UI_KEYS_INIT_BUTTON_LOW(6);
311  //  UI_KEYS_INIT_BUTTON_LOW(11);
312  //  UI_KEYS_INIT_BUTTON_LOW(42);
313  //  UI_KEYS_INIT_CLICKENCODER_LOW(47,45); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
314  //  UI_KEYS_INIT_BUTTON_LOW(43); // push button, connects gnd to pin
315  //  UI_KEYS_INIT_MATRIX(32,47,45,43,41,39,37,35);
316  #endif
317  }
318  void ui_check_keys(int &action) {
319  #if UI_HAS_KEYS!=0
320  
321   UI_KEYS_CLICKENCODER_LOW_REV(76,77); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
322   UI_KEYS_BUTTON_LOW(78,UI_ACTION_OK); // push button, connects gnd to pin
323   UI_KEYS_BUTTON_LOW(KILL_PIN,UI_ACTION_KILL); // push button, connects gnd to pin
324  
325  // UI_KEYS_BUTTON_LOW(5,UI_ACTION_NEXT); // push button, connects gnd to pin
326  // UI_KEYS_BUTTON_LOW(6,UI_ACTION_PREVIOUS); // push button, connects gnd to pin
327  // UI_KEYS_BUTTON_LOW(11,UI_ACTION_BACK); // push button, connects gnd to pin
328  // UI_KEYS_BUTTON_LOW(42,UI_ACTION_SD_PRINT ); // push button, connects gnd to pin
329  //  UI_KEYS_CLICKENCODER_LOW_REV(47,45); // click encoder on pins 47 and 45. Phase is connected with gnd for signals.
330  //  UI_KEYS_BUTTON_LOW(43,UI_ACTION_OK); // push button, connects gnd to pin
331  #endif
332  }
333  inline void ui_check_slow_encoder() {
334  #if defined(UI_HAS_I2C_KEYS) && UI_HAS_KEYS!=0
335  #if UI_DISPLAY_I2C_CHIPTYPE==0
336    i2c_start_wait(UI_I2C_KEY_ADDRESS+I2C_READ);
337    byte keymask = i2c_readNak(); // Read current key mask
338  #endif
339  #if UI_DISPLAY_I2C_CHIPTYPE==1
340      i2c_start_wait(UI_DISPLAY_I2C_ADDRESS+I2C_WRITE);
341      i2c_write(0x12); // GIOA
342      i2c_stop();
343      i2c_start_wait(UI_DISPLAY_I2C_ADDRESS+I2C_READ);
344      unsigned int keymask = i2c_readAck();
345      keymask = keymask + (i2c_readNak()<<8);
346  #endif
347    i2c_stop();
348    // Add I2C click encoder tests here, all other i2c tests and a copy of the encoder test belog in ui_check_slow_keys
349    UI_KEYS_I2C_CLICKENCODER_LOW_REV(_BV(2),_BV(0)); // click encoder on pins 0 and 2. Phase is connected with gnd for signals.
350  #endif
351  }
352  void ui_check_slow_keys(int &action) {
353  #if defined(UI_HAS_I2C_KEYS) && UI_HAS_KEYS!=0
354  #if UI_DISPLAY_I2C_CHIPTYPE==0
355      i2c_start_wait(UI_I2C_KEY_ADDRESS+I2C_READ);
356      byte keymask = i2c_readNak(); // Read current key mask
357  #endif
358  #if UI_DISPLAY_I2C_CHIPTYPE==1
359      i2c_start_wait(UI_DISPLAY_I2C_ADDRESS+I2C_WRITE);
360      i2c_write(0x12); // GPIOA
361      i2c_stop();
362      i2c_start_wait(UI_DISPLAY_I2C_ADDRESS+I2C_READ);
363      unsigned int keymask = i2c_readAck();
364      keymask = keymask + (i2c_readNak()<<8);
365  #endif
366      i2c_stop();
367      // Add I2C key tests here
368      UI_KEYS_I2C_CLICKENCODER_LOW_REV(_BV(2),_BV(0)); // click encoder on pins 0 and 2. Phase is connected with gnd for signals.
369      UI_KEYS_I2C_BUTTON_LOW(_BV(1),UI_ACTION_OK); // push button, connects gnd to pin  
370      UI_KEYS_I2C_BUTTON_LOW(_BV(3),UI_ACTION_BACK); // push button, connects gnd to pin  
371      UI_KEYS_I2C_BUTTON_LOW(_BV(4),UI_ACTION_MENU_QUICKSETTINGS+UI_ACTION_TOPMENU); // push button, connects gnd to pin  
372      UI_KEYS_I2C_BUTTON_LOW(_BV(5),UI_ACTION_MENU_EXTRUDER+UI_ACTION_TOPMENU); // push button, connects gnd to pin  
373      UI_KEYS_I2C_BUTTON_LOW(_BV(6),UI_ACTION_MENU_POSITIONS+UI_ACTION_TOPMENU); // push button, connects gnd to pin  
374  /*
375    // Button handling for the Adafruit RGB shild
376      UI_KEYS_I2C_BUTTON_LOW(4,UI_ACTION_PREVIOUS); // Up button
377      UI_KEYS_I2C_BUTTON_LOW(8,UI_ACTION_NEXT); // down button
378      UI_KEYS_I2C_BUTTON_LOW(16,UI_ACTION_BACK); // left button
379      UI_KEYS_I2C_BUTTON_LOW(2,UI_ACTION_OK); // right button
380      UI_KEYS_I2C_BUTTON_LOW(1,UI_ACTION_MENU_QUICKSETTINGS);  //Select button
381    // ----- End RGB shield ----------
382    */
383  #endif
384  
385    //UI_KEYS_MATRIX(32,47,45,43,41,39,37,35);
386  }
387  
388  #endif