Commit Graph

1413 Commits

Author SHA1 Message Date
Markus Hitter 1d4ebbd7fa Display: queue up display_set_cursor(), too. 2016-05-30 10:59:12 +02:00
Markus Hitter 8d7471d3a4 Display: display_clear() is a common command now.
Before control commands were queued up, this was different for
each display.
2016-05-30 10:50:41 +02:00
Markus Hitter 5b9e123e0e Display: queue up display clear commands. 2016-05-30 10:32:33 +02:00
Markus Hitter da0d5aec2c Display: add support for the HD44780 display.
All in one chunk because the infrastructure is already there.
This also implements the parallel 4-bit bus used by quite some
displays.

For now you have to add quite a number of #defines to your
config.h. First, there are all the pins required, pin names
changed to your actual board/display connection, of course:

  #define DISPLAY_RS_PIN       PC1
  #define DISPLAY_RW_PIN       PC0
  #define DISPLAY_E_PIN        PD2
  #define DISPLAY_D4_PIN       PD3
  #define DISPLAY_D5_PIN       PD4
  #define DISPLAY_D6_PIN       PD5
  #define DISPLAY_D7_PIN       PD6

And then the information about the display actually existing:

  #define DISPLAY_BUS_4BIT
  #define DISPLAY_TYPE_HD44780

Allowing to do all this in Configtool is forthcoming, of course.
2016-05-30 10:31:39 +02:00
Markus Hitter 12dc74fe62 Display: finally get rid of i2c_test.c.
Not without dubbing its remaining functionality in form of a
display_greeting(), of course.
2016-05-28 21:14:37 +02:00
Phil Hord 92a303c607 Add testcase for corexy homing bug 2016-05-26 11:22:12 +02:00
Phil Hord 750acb41bc Simulator: calculate position for corexy correctly
CoreXY turns the X and Y motors to render a target position differently
than straight cartesian printer does.  From the theory page on corexy.com,
where the motors are called A and B instead of X and Y:

    dx = 1/2(dA + dB), dY = 1/2(dA - dB)
    dA = dX + dY
    dB = dX - dY

Accordingly, each step of a single motor results in half of a step in the
X or Y axis.  To simplify this and not lose steps, make the pos[] array
hold 2*steps instead of single steps.  Adjust back to single steps with
/2 where needed.  Store 2*steps whenever writing to pos[] variables
which are not coreXY driven.

Since each step of X or Y (A or B) affects both X and Y position, send
updates to record_pin for all axes instead of only the "affected" axis.
The function record_pin will ignore reports for pins which did not change
from the previous call.  This also helps us keep from reporting duplicate
positions for half-steps in coreXY mode, too.
2016-05-26 11:16:11 +02:00
Phil Hord 59610750dd Simulator: support endstop simulation
Provide a simulated, simplified representation of the action of
mechanical endstop switches which turn on and off at slightly
different amounts of pressure. When any axis moves past -10,
simulate endstop "on" condition. When the axis moves to 0,
simulate the endstop "off" condition.

This support allows the simulation of G28 (home) commands.
2016-05-26 11:09:54 +02:00
Phil Hord 887a4eedd9 Simulator: fix pin numbering consistency
The simulator code is compiled with different definitions than the
rest of the code even when compiling the simulator.  This was done
originally to satisfy the compiler, but it was the wrong way to go.
The result is that the main Teacup code may decide to do things one
way (X_INVERT_DIR, for example) but the simulator code will do
things a different way (no X_INVERT_DIR).

Fix this by including the board and printer definitions also in the
simulator code, and use a simple enum trick to give consistent
definitions to the needed PIN definitions, safely ignoring the ones
the config does not use.

This requires that we include simulator.h after 'config.h' in all cases.
Manage that by moving simulator.h from its previous home in arduino.h
into config_wrapper.h.

After this change we will be able to reliably communicate the expected
state of the endstop pins from the simulator.
2016-05-26 11:04:30 +02:00
Markus Hitter 6e4cd69345 board.ramps-1.3.h: add all four pins from the Servos connector.
Previously there were only two of them, the others missing for
no apparent reason. This should help connecting an external
relay, like described here:
http://www.reprap-diy.com/connect_sevenswitch_to_ramps
2016-05-25 20:29:54 +02:00
Phil Hord 90d519af5f dda_clock(): guard against *dda changes in interrupts
dda_clock() might be interrupted by dda_step(), and dda_step might
use or modify variables also being used in dda_clock().  It is
possible for dda to be modified when a new dda becomes live during
our dda_clock().  Check the dda->id to ensure it has not changed on
us before we actually write new calculated values into the dda.

Note by Traumflug: copied some of the explanation in the commit
message directly into the code.
2016-05-21 15:46:10 +02:00
Phil Hord 1eefb28a19 dda_clock(): modify dda->n only in atomic code
dda_clock() might be interrupted by dda_step(), and dda_step might
use or modify variables also being used in dda_clock. In particular
dda->c is modified in both functions but it is done atomically in
dda_clock() to prevent dda_step() from interrupting during the
write.  But dda->n is also modified in both places and it is not
protected in dda_clock().

Move updates to dda->n to the atomic section along with dda->c.

Note by Traumflug: good catch! It even makes the binary 14 bytes
smaller, so likely faster.
2016-05-21 15:45:49 +02:00
Markus Hitter fe398d84ce displaybus.h: note the different #include strategies.
Yes, these strategies feel a lot like heading into uncharted
territory, because I can't find notable textbook examples on how
to select between various "classes" at compile time. Nevertheless,
it works fine, binaries are small and fast and as such it can't
be _that_ wrong.
2016-05-18 18:03:36 +02:00
Phil Hord 90fbdd314a configtool: Add avrdude flags option to settings
Some target devices need extra avrdude command line switches to
get them to upload successfully.  There are dozens of options which
may be useful to different people. Instead of breaking all the possible
options out into separate fields, provide a generic "Program Flags" text
field which the user can fill in similar to the CFLAGS and LDFLAGS
settings.

The Arduino Mega2560 bootloader was changed[1] to report an error when
asked to erase flash because it has never actually implemented erasing
flash. To program this bootloader with avrdude requires the -D switch
to avoid flash erase. But it seems that every arduino will work fine
with -D, as evidenced by the fact that the Arduino IDE always [2]
includes -D in the avrdude commandline. Presumably the flash is erased
during/before programming anyway and the separate erase step is unneeded.

Perhaps the -D should be always added to avrdude command line in
configtool and in Makefile-AVR.  But I haven't tested any other boards
yet, and I'm being more cautious even though the Arduino IDE does
otherwise.

[1] arduino/Arduino#543
[2] d8e5997328/app/src/processing/app/debug/AvrdudeUploader.java (L168)
2016-05-17 12:57:16 -04:00
Markus Hitter bb56874088 Regressiontests: add a test for ATmega328, I2C, SSD1306. 2016-05-06 20:34:18 +02:00
Markus Hitter 535fa0c171 check_integrity.sh: remove the -c option from awk invocations.
Ubuntu now (16.04) comes with 'mawk', which doesn't recognize the -c
option, so simply remove it. Its meaning was to switch into 'traditional'
mode.
2016-05-06 19:37:56 +02:00
Markus Hitter 3dd430de59 display_ssd1306.c: note current state and missing pieces.
A few days before being done with this display hardware decided
say good bye. Accordingly I can't continue with writing related
code. Writing down what already works and what's still missing is
probably a good idea, to make sure the next fellow doesn't have
to investigate from scratch.
2016-04-28 23:11:39 +02:00
Markus Hitter f091b1e316 display_ssd1306.c: note a possible error recovery strategy.
Currently not implemented because this costs additional binary
size and, well, with I2C being reliable now, it's difficult to
test it. And also because I'm lazy :-)
2016-04-27 23:54:15 +02:00
Markus Hitter d803883cdb i2c.c: review error handling yet again.
- Flag I2C_MODE_FREE was misleading, because one couldn't test
   for it the same way as for I2C_MODE_BUSY. At an error
   condition, 'i2c_mode & I2C_MODE_FREE' would still evaluate
   to true.

 - On error, drop not only the buffer, but the entire
   transmission.

All of a sudden, the display works reliably, even at the
previously shaky speed of 100'000 bits/s!

TBH, probably I didn't understand some parts of Ruslan's code
earlier but tweaked it anyways. Shame on me!
2016-04-27 23:54:15 +02:00
Markus Hitter 6e8067208e i2c.c: simplify error handling.
If all error conditions are handled the same, there's not much
point to use distinct code for each of them.

Also, handle collisions like the other error conditions.

This saves a nice 52 bytes of program memory.

  Program:  24404 bytes
     Data:   1543 bytes
   EEPROM:     32 bytes
2016-04-27 23:54:14 +02:00
Markus Hitter a13312d9a9 Display: introduce display queue.
Now we shouldn't experience wait cycles in i2c_write() during
typical display writes any longer. It should also distribute CPU
load of display writes a lot better.

Previously writing a line of text to the display would take
almost as long as it took to actually send it to the display,
because the I2C queue could hold only one transmission, which
effectively meant only one character. This could hold the main
loop for several milliseconds.

Now we queue characters, send them one by one, and return to the
main loop in between.

This costs 160 bytes program memory. Only 18 bytes RAM, because
the I2C queue was reduced accordingly. Now:

  Program:  24456 bytes
     Data:   1543 bytes
   EEPROM:     32 bytes
2016-04-27 23:54:14 +02:00
Markus Hitter aabce8ed15 usb_serial.h: refine the note.
Thanks for the hint, @phord.
2016-04-27 23:53:42 +02:00
Markus Hitter 9b2c5e61c6 dda_lookahead.c: replace Windows EOL by the usual Unix EOL.
No functional change.
2016-04-26 17:41:21 +02:00
Markus Hitter 0d91b44436 dda_lookahead.c: remove redundant macro.
No functional change.
2016-04-26 17:41:07 +02:00
Markus Hitter c9056e376d dda_lookahead.c: remove two obsolete #includes.
No functional change.
2016-04-26 17:40:57 +02:00
Markus Hitter ea2a10fa76 i2c.c: recover from error conditions.
This is
- clearing 'i2c_should_end', so i2c_write() doesn't hang and
- draining the buffer on errors.

This way we loose the remaining transmission, which is typically
half a character, but we no longer stall the entire firmware main
loop.

Actually, such error conditions are surprisingly frequent, at
least on the test hardware. Now they result in some flickering
of the displayed numbers.
2016-04-26 15:36:11 +02:00
Markus Hitter dcc970d2fd i2c.c: add debugging aid.
No functional change.
2016-04-26 15:36:11 +02:00
Markus Hitter a47c4b40df Display: add a primitive status display.
This isn't pretty at all, but it shows the principle.
Unfortunately it also exploits a bug in the I2C sending mechanism,
I2C sending hangs a few seconds after reset.
2016-04-26 15:36:11 +02:00
Markus Hitter 62190caaa5 USB Serial: note about all the redundant code. 2016-04-26 15:35:40 +02:00
Markus Hitter e633222cd3 Make message/text sending aware of the sending destination.
Point of this change is to allow using these functions for
writing to the display, too, without duplicating all the code.

To reduce confusion, functions were renamed (they're no longer
'serial', after all:

  serwrite_xxx() -> write_xxx()
  sersendf_P()   -> sendf_P()

To avoid changing all the existing code, a couple of macros
with the old names are provided. They might even be handy as
convenience macros.

Nicely, this addition costs no additional RAM. Not surprising, it
costs quite some binary size, 278 bytes. Sizes now:

Program:  24058 bytes      168%       79%       38%       19%
   Data:   1525 bytes      149%       75%       38%       19%
 EEPROM:     32 bytes        4%        2%        2%        1%

Regarding USB Serial: code was adjusted without testing on
hardware.
2016-04-26 15:23:15 +02:00
Markus Hitter 6577578051 Display: introduce display_writechar().
You see where the journey is going? This is the equivalent to the
function to write a character to the serial line, so we can
basically swap these two in other functions.
2016-04-26 14:45:59 +02:00
Markus Hitter bb8d6e0ad2 Display: create and use display_set_cursor().
Having this in a seperate function will be helpful later.
2016-04-26 14:31:56 +02:00
Markus Hitter cec45a2fec Display: create infrastructure for distinct displays.
Dropped all the funtions for specific messages because plans on
how to handle this have changed.
2016-04-26 14:31:47 +02:00
Markus Hitter 9dd53a1722 display_ssd1306.c: support monospaced fonts.
Monospaced fonts require a bit less space, right now it saves a
nice 110 bytes binary size.

Actually, the distinction between monospaced and proportional
fonts was in font.h already, so not supporting them was a bug.
But so far we have no monospaced font, so nobody noticed.
2016-04-26 14:29:39 +02:00
Markus Hitter 455b07eb6e display_ssd1306.c: read symbol index only once.
Saves just 2 bytes, but more than nothing.
2016-04-26 14:29:39 +02:00
Ruslan Popov e3fd9eaea7 Display: first text on OLED.
Note by Traumflug: this code was written by Ruslan Popov a lot
earlier already. I picked it to i2c_test.c to get "something"
visible running. This is the commit finally adjusted to the new
display infrastructure.
2016-04-26 14:29:36 +02:00
Markus Hitter 5f95784c0b Display: introduce font.h, paraphrase handling distinct fonts.
While this could also be done properly now, with a couple of
additional fonts, this would require quite some time. However,
it's more important to have at least one display working now,
rather than having a ton of sophisticated eye-candy, which isn't
even user-visible, because the upper layers are still missing.
2016-04-26 14:13:20 +02:00
Ruslan Popov cb696701f8 Display: add font 8x4 ASCII. 2016-04-26 14:13:20 +02:00
Markus Hitter a97ec8a376 Display: introduce displaybus.h.
This is a broker for mapping display bus calls to the bus actually
in use.
2016-04-26 14:13:15 +02:00
Markus Hitter 8c110da610 Makefile-AVR: correct reported program sizes.
What 'make size' previously reported was misleading, because
it didn't count the .data section as Flash usage. However, this
section is actually written to Flash.

The .data section holds the data needed for inititalising
variables. As such it counts to both, Flash and RAM usage.

Nice verification: reported 'Program' size now matches upload
size reported by avrdude exactly.

There's now the tool 'avr-size', which makes reading such stuff
much easier:

  avr-size -C build/teacup.elf

Example output:

  AVR Memory Usage
  ----------------
  Device: Unknown

  Program:   23704 bytes
  (.text + .data + .bootloader)

  Data:       1543 bytes
  (.data + .bss + .noinit)

  EEPROM:       32 bytes
  (.eeprom)
2016-04-21 19:19:29 +02:00
Markus Hitter 13c76244b6 Configtool: allow and use user friendly names for choices.
So far for choices based on boolean sets, only, because choices
for values typically need no more readable names.

This elegantly removes the somewhat ugly check for '(', too.
2016-04-20 22:02:10 +02:00
Markus Hitter a0fa1bbeb6 displaypage.py: disable display type choice if there is no bus. 2016-04-20 22:02:10 +02:00
Markus Hitter 2541d7a82c Configtool: introduce boolChoices.
This handles sets of booleans "magically" and is now used for
DISPLAY_BUS and DISPLAY_TYPE.
2016-04-20 22:02:10 +02:00
Markus Hitter a95a1c8855 Configtool: record False boolean #defines, too.
This will be helpful for handling sets of booleans better.
2016-04-20 22:02:09 +02:00
Markus Hitter bdacd8c9bc Configtool: remove unused reCommDefBL and reCommDefBoolBL. 2016-04-20 22:02:09 +02:00
Markus Hitter 4645715f18 Configtool: make KINEMATICS a set of booleans, too.
Reasons:

 - Less code, easier handling.

 - An entire case of configuration handling could be removed.

 - Better class-like encapsulation.
2016-04-20 22:02:07 +02:00
Markus Hitter 1fad0036a7 Configtool: replace DISPLAY_TYPE with a set of booleans, too.
Same reason, same procedure as the previous commit.
2016-04-20 22:00:47 +02:00
Markus Hitter 90969978df Configtool: replace DISPLAY_BUS parameter with a set of booleans.
Having a choice with a defined set of options is nice, but it
also requires these options to be #defined somewhere _before_
entering config.h. To keep class-like encapsulation, we'd need
two header files for each code unit, one for the options, another
one for the usual header.

That said, we use other examples of such options, e.g. CPU, F_CPU
or KINEMATICS. For CPU and F_CPU it works fine, because their
options are numbers or other values known by the compiler. For
KINEMATICS it kind of works, because this #define is used in only
one place ... and there it's suboptimal already, because no option-
set.

Anyways, I was unsure about this change and if it turns out to be
a poor decision later, it can be reverted.
2016-04-20 22:00:05 +02:00
Markus Hitter 4d37d35f29 Configtool: add debugging aid.
All comments, no functional change. One unused line of code
removed.
2016-04-20 21:56:54 +02:00
Ruslan Popov 212eca7f8e Configtool: add display page implementation.
Most work by Ruslan Popov, collected from various commits and
made compatible with regression tests by Traumflug.

Display test code is now enabled by #defining DISPLAY_BUS to
i2c_twi.
2016-04-20 21:56:39 +02:00