Commit Graph

102 Commits

Author SHA1 Message Date
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
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 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 8e8946dd37 I2C: remove parameter 'address' from i2c_write().
As we usually talk to one device only, there's not much point in
carrying around the address all the time. Surprise, this saves
only 16 bytes binary size despite of heavy usage.
2016-04-20 21:15:11 +02:00
Markus Hitter 61ab29e6b6 I2C: no need to initialise with an address in master mode. 2016-04-20 21:15:11 +02:00
Markus Hitter 061225f72d I2C: get rid of these unimplemented error handlers.
Naively restarting I2C immediately is certainly not the solution
and just leads to an interrupt flood. As I2C is currently meant
to drive displays, where successful data transmission isn't
crucial, we now simply stop transmission on errors.

This saves another 80 bytes binary size:

    FLASH  : 23094 bytes
    RAM    :  2051 bytes
    EEPROM :    32 bytes
2016-04-20 21:15:11 +02:00
Ruslan Popov 619560c112 I2C: initial support.
This commit squashes in some fixes found after debugging on the
topic branch. Test code by Traumflug, collected from Ruslan's
code on the topic branch.

Before, same as now without I2C:

    FLASH  : 22408 bytes
    RAM    :  1393 bytes
    EEPROM :    32 bytes

Now with I2C:

    FLASH  : 23224 bytes
    RAM    :  2057 bytes
    EEPROM :    32 bytes

This totals to some 800 bytes with a whole lot of test code, so
implementation is pretty small :-)
2016-04-20 21:15:11 +02:00
Markus Hitter 2376242c36 ARM: last not least, enable CANNED_CYCLE.
Was just a matter of removing the wrappers, tests ran fine.
2015-08-13 17:12:13 +02:00
Markus Hitter fb317fef08 ARM: get spi.c, pff.c and pff_diskio.c (SD card handling) in.
Neither is ported for now, but also not essential for printing,
so it's just made sure it's always disabled on ARM.
2015-08-13 17:12:13 +02:00
Markus Hitter d2fcc57ed4 Introduce #ifdef SPI.
It's better to separate this by function than by usage.
2015-08-13 17:12:12 +02:00
Markus Hitter 274f6c954b ARM: get graycode.c and intercom.c in.
Also both used only in unusual setups, so no functional or binary
size change for ARM.
2015-08-13 17:12:12 +02:00
Markus Hitter cc6600ca76 ARM: get debug.c and crc.c in.
Both used only in special cases, so no binary size change.
2015-08-13 17:12:12 +02:00
Markus Hitter d7b59e2d33 ARM: implement heater-arm.c partially.
Currently at a fixed frequency of 1 kHz and with a fixed duty
cycle of 10%, but PWM does work.

As it turns out, PIO0_11 is not usable for PWM, because its timer
is already in use for the Step timer, and had to be disabled for
Gen7-ARM.

Test: define a heater in board.gen7-arm.h and a square signal
of 1 kHz with 10% duty cycle should appear on the heater pin.
2015-08-13 16:41:33 +02:00
Markus Hitter 8f24fbaad4 ARM: get temp.c in.
No code changes, but quite a few removals of __ARMEL_NOTYET__
guards. 20 such guards left.

Test: M105 should work and report plausible temperatures.

Current code size:

    SIZES          ARM...     lpc1114
    FLASH  :  9460 bytes          29%
    RAM    :  1258 bytes          31%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:37 +02:00
Markus Hitter f81000a4b6 ARM: implement analog-arm.c.
Very simple, because the LPC1114 features a hardware scan mode,
which automatically scans a given set of pins in freerunning mode
and stores all the values separately. No need for an interrupt!

Not yet done: configure not PIO1_0 and PIO1_1, but the pins
actually defined in the board file.

For testing, add this to ifclock(clock_flag_1s) in clock.c:
  uint8_t i;

  for (i = 0; i <= 7; i++) {
    sersendf_P(PSTR("%lu "), analog_read(i));
  }
  serial_writechar('\n');

This should print all 8 ADC values repeatedly. Only two pins are
actually set up, these values should change depending on the
thermistor temperature. More precisely: depending on the voltage
on the pin.
2015-08-12 14:26:37 +02:00
Markus Hitter 5a8d51cb19 ARM: get dda_maths.c, dda_kinematics.c and dda.c in.
All in one chunk, because it's all hardware-independent and doing
them one by one would end up on not more than some typing
exercises.

Compiles fine. For testing, remove if (DEBUG... for M114 in
gcode_process.c. Then one can see how the queue fills up when
sending movements and M114 repeatedly. This time with actual
coordinates.

No stepper movements, yet, because set_timer() is still empty.
2015-08-12 14:26:37 +02:00
Markus Hitter 692a6daeb2 ARM: get dda_queue.c in.
Compiles fine. For testing, remove if (DEBUG... for M114 in
gcode_process.c. Then one can see how the queue fills up when
sending movements and M114 repeatedly.

queue_step() isn't called, yet, the stepper timer is still missing.
2015-08-12 14:26:37 +02:00
Markus Hitter c118d00383 ARM: get clock.c in.
No code changes neccessary.

This code in ifclock(clock_flag_1s) in clock.c should give a nice,
accurate clock:

    static uint8_t minutes = 0, seconds = 0;

    seconds++;
    if ( ! (seconds % 60)) {
      seconds = 0;
      minutes++;
    }
    sersendf_P(PSTR("%su:"), minutes);
    if (seconds < 10)
      serial_writechar('0');
    sersendf_P(PSTR("%su\n"), seconds);

Current sizes are:

    SIZES          ARM...     lpc1114
    FLASH  :  4440 bytes          14%
    RAM    :   200 bytes           5%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:36 +02:00
Markus Hitter 137a638658 ARM: get timer.c in, so far only with the system clock.
This test code in SysTickHanlder() should give you a rather
accurate clock with only a few seconds deviation per hour:

  #include "serial.h"
  #include "sersendf.h"
  void SysTick_Handler(void) {
    static uint32_t count = 0;
    static uint8_t minutes = 0, seconds = 0;

    count++;

    if ( ! (count % 500)) {   // A full second.
      seconds++;
      if ( ! (seconds % 60)) {
        seconds = 0;
        minutes++;
      }
      sersendf_P(PSTR("%su:"), minutes);
      if (seconds < 10)
        serial_writechar('0');
      sersendf_P(PSTR("%su\n"), seconds);
    }
  [...]
2015-08-12 14:26:36 +02:00
Markus Hitter 4faa3cbf8f ARM: bring in pinio.c.
This enables pinio_init(), power_on() and power_off(). Now one
can turn on the power supply with M119 and turn it off with M2.

Code changes were neccessary. Setting a pin first, then making
it an output doesn't work on ARM. A pin has to be an output
before it permanently accepts a given state. As I was never
sure the former strategy actually worked on AVR, the order of
these two steps was changed for both, AVR and ARM.
2015-08-12 14:26:36 +02:00
Markus Hitter 7be5212f06 ARM: introduce sei() and cli().
No test, because it's tricky to test, but it compiles and the
firmware still works as before.
2015-08-12 14:26:36 +02:00
Markus Hitter e5729d6743 ARM: get gcode_parse.c in.
Just did it, no code changes neccessary. Except ajusting the
boundaries to not yet ported code.

Successful tests: controller answers with "ok", just like an AVR.

Binary size raised, of course:

    SIZES          ARM...     lpc1114
    FLASH  :  3064 bytes          10%
    RAM    :   194 bytes           5%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:36 +02:00
Markus Hitter 5a8dcf8e97 ARM: add a board configuration for Gen7-ARM.
Wohoo, this is the first ARM board in Configtool. Let's see how
Configtool deals with it :-)
2015-08-12 14:26:36 +02:00
Markus Hitter 66dcde54dc mendel.c: move io_init() to pinio.c.
Also rename it to pinio_init(). Other than that a simple
copy/paste operation, with replacing tabs by spaces. No functional
change.
2015-08-12 14:26:35 +02:00
Markus Hitter d337fd18ad mendel.c: move CPU initialisation to cpu.c (cpu-avr.c).
No functional change, but more code separated by architecture.
2015-08-12 14:26:35 +02:00
Markus Hitter 083f8f9b22 Make use of PULLUP_ON() and PULLUP_OFF().
This should not change behaviour, but later enable proper
operation on ARM.
2015-08-12 14:26:35 +02:00
Markus Hitter 2c90a2dfc7 ARM: get FastIO for writing into place.
Only SET_OUTPUT() and WRITE() for now, reading follows later.

A loop like this:

  SET_OUTPUT(PIO0_1);
  for (;;) {
    WRITE(PIO0_1, 0);
    WRITE(PIO0_1, 1);
  }

toggles a pin at about 5.3 MHz. The low period is 63 ns on the
scope, so 3 clock cycles. With this loop, the binary is 1648
bytes.

Assembly shows four instructions inside the loop, which is about
as good as it can get:

  movs  r2, #0
  str   r2, [r3, #8]
  adds  r2, #2
  str   r2, [r3, #8]

For comparison, using the MBED provided gpio routines give a
toggle frequency of about 300 kHz, with a low period of 72 clock
cycles. Microoptimisation isn't just the last few percent ...

Tested with this code before main():

static void delay(uint32_t delay) {
  while (delay) {
    __ASM volatile ("nop");
    delay--;
  }
}

... and in main():

  SET_OUTPUT(PIO0_1);
  SET_OUTPUT(PIO0_2);
  SET_OUTPUT(PIO0_3);
  SET_OUTPUT(PIO0_4);
  __ASM (".balign 16");
  while (1) {
    // 1 pulse on pin 1, two pulses on pin 2, ...
    WRITE(PIO0_1, 0);
    WRITE(PIO0_1, 1);
    WRITE(PIO0_2, 0);
    WRITE(PIO0_2, 1);
    WRITE(PIO0_2, 0);
    WRITE(PIO0_2, 1);
    WRITE(PIO0_3, 0);
    WRITE(PIO0_3, 1);
    WRITE(PIO0_3, 0);
    WRITE(PIO0_3, 1);
    WRITE(PIO0_3, 0);
    WRITE(PIO0_3, 1);
    // PIO0_4 needs a pullup 10k to 3.3V
    // to show a visible signal.
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(10);
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(10);
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(10);
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(1000);
  }

With a 10k pullup, PIO0_4 has a rise time of about 1 microsecond.
2015-08-12 14:26:34 +02:00
Markus Hitter 43b2ac6e0b ARM: get sersendf.c/.h in.
Needed a bit a tweak to adjust va_arg() to 32 bit. Tests ran fine,
at the end it turned out mendel.c had an obsolete #include.
2015-08-12 14:26:34 +02:00
Markus Hitter 5dec638919 ARM: get sermsg.c/.h in.
Compiled flawlessly, ran all test flawlessly, and at the end it
turned out mendel.c had an obsolete #include. Very nice.
2015-08-12 14:26:34 +02:00
Markus Hitter 4cfeca08e1 ARM: get serial working based on MBED code.
Pretty complex, this MBED system, it requires no less than
24 additional files. This will be fleshd out before too long.

    SIZES          ARM...     lpc1114
    FLASH  :  5956 bytes          19%
    RAM    :   176 bytes           5%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:34 +02:00
Markus Hitter 575174940f ARM: get a minimum amount of Teacup compiled for ARM.
Makefile can't even upload, yet.

    SIZES          ARM...     lpc1114
    FLASH  :   944 bytes           3%
    RAM    :   132 bytes           4%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:33 +02:00
Markus Hitter 77630167e7 Serial: postpone sending "ok" until a slot is free.
Previously acknoledgement was sent as soon as the command was
parsed. Accordingly, the host would send the next command and
this command would wait in the RX buffer without being parsed.

This worked reasonably, unless an incoming line of G-code was
longer than the RX buffer, in which case the line end was dropped
and parsing of the line never completed. With a 64 bytes buffer
on AVR this was rarely the case, with the 16 bytes hardware buffer
on ARM LPC1114 it happens regularly. And there's no recovering
from such a situation.

This should solve issue #52.
2015-08-04 23:03:51 +02:00
Markus Hitter 6b66d7870a mendel.c: remove another three redundant #includes.
No functional change.
2015-07-30 21:46:14 +02:00
Markus Hitter 4fdb2dac9e Remove file fuses.h.
Contents apparently nowhere used. Also not updated for often used
MCUs like ATmega2560 or ATmega1284P, so it can't be that
important.
2015-07-27 16:41:48 +02:00
Markus Hitter 3d005c4d60 mendel.c: remove redundant #include. 2015-07-27 16:34:13 +02:00
Phil Hord 503d2c75a1 Fix typos: "whether" and whitespace. 2015-07-17 16:16:42 +02:00
Markus Hitter 75df5e3a0a SD card: don't read into a buffer, parse directly instead.
Formerly we took efforts to read only small chunks into a
(small) buffer, just to read this buffer byte by byte yet
again for parsing. It's more efficient and requires less
code to parse the character at read time directly. This
way we can read in chunks of exactly one line, making the
buffer obsolete.

First step is to implement this in mendel.c and in sd.c/.h.
This gets rid of the buffer already.

Very inefficient in pff.c and pff_diskio.c so far, more
than 40 minutes / less than 500 bytes/s for reading this
1 MB comments file. Reason is, for every single byte a
whole sector is read. Nevertheless, this attempt appears
to be on the right track.

Binary is 156 bytes smaller, 16 bytes less RAM:
               ATmega...     '168   '328(P)   '644(P)     '1280
   FLASH:   22052 bytes   153.82%    71.78%    34.73%    17.09%
     RAM:    1331 bytes   129.98%    64.99%    32.50%    16.25%
  EEPROM:      32 bytes     3.12%     1.56%     1.56%     0.78%
2015-07-17 13:30:55 +02:00
Markus Hitter c42ccfff38 mendel.c: when to include simulator.h matters.
This partially fixes building the simulator. It was found by
running the new regression tests.
2015-07-13 14:02:39 +02:00
Markus Hitter df451d72fd mendel.c: set SIMINFO serial port only when BAUD is available.
This was found by running the new regression tests.
2015-07-13 14:01:27 +02:00
Markus Hitter 53dfab3be3 G-code parser: check for end of line in the parser.
This raises abstraction and even makes the binary a bit smaller
(2 bytes without SD, 14 bytes with SD).

A G-code file with 16'384 lines of comments, 64 bytes per line
( = 1 MB file size), is read and parsed from SD card in 2:47
minutes, or at a speed of 5924 bytes/second.
2015-07-10 14:19:48 +02:00
Markus Hitter 23be2d1449 SD card: finally(!) implement printing from SD card.
Turned out to be pretty easy with all the more complex bits
already in place.

Strategy is to always parse a full line from one of the sources.
Accordingly, simply sending a character on the serial line stops
reading from SD until the line coming in over serial is completed.
2015-07-07 19:07:35 +02:00
Markus Hitter c7b134bc65 SD card: change demo code for performance measurement.
As we're around here, lets see how fast this implementation is.
All measurements are raw reading performance, without actual
parsing of the G-code.

With SPI_2X disabled (see line 8 in spi.h), performance is
195 seconds per megabyte, equivalent to about 50'000 baud.

With SPI_2X enabled, performance is 159 seconds per megabyte,
or 60'000 baud.

Still, SPI_2X is left disabled to increase reliability. Reading
from SD is faster by design, because there is no checksumming and
also no waiting for the "ok" to be sent back. In case reading
G-code from SD ever becomes a bottleneck, there are even more
opportunities in addition to enabling SPI_2X, like making sdbuffer
bigger, like micro-optimizing spi_rw() and similar stuff.
2015-07-07 14:36:46 +02:00
Markus Hitter d3f548a895 SD card: actually read the characters from the file.
Next to the implementation of sd_read_byte() as well as M24 and
M25, yet another demo: read the file and write it to the serial
line, to show correctness of the implementation.
2015-07-07 14:36:44 +02:00
Markus Hitter 30ce8eb1b4 SD card: remove the demonstration code.
We're about to do some real stuff ...
2015-07-05 23:32:48 +02:00
Markus Hitter 9de0c65460 SD card: add the layer between hardware and Petit FatFs.
This is all the commands to read from and write to SPI,
initializing the card, read in blocks and so on. This should
make Petit FatFs actually usable.

So far read-only and no M-codes to let end users play with
this stuff.

The demonstration code was changed to list the SD card's
top level directory over and over again.
2015-07-05 23:32:48 +02:00
Markus Hitter 63c4dbaea9 mendel.c: do module enabling differently.
Same result, but 8 bytes less binary size. With SD card disabled,
binary size is now the same as before getting SPI running.
2015-07-05 23:32:48 +02:00
Markus Hitter 1fb3ece31e SD card: establish spi.c/.h and sd.c/.h and get SPI running.
For now this is just a nice demonstration on how to send bytes
over SPI. Add SD_CARD_SELECT_PIN to your configuration board
file manually to see data signals on MOSI dancing on the scope.

The TODO's about SS in arduino*.h were wrong, SS does have a
chip-specific special meaning (used in SPI multi-master or SPI
slave mode). Still, a #define MAX6675_SELECT_PIN is missing.

Squashed in this commit from the SPI development topic branch to
get this first step working:

Author: jbernardis <jeff.bernardis@gmail.com>
2015-02-04 22:35:07
mendel.c: disable SPI in power management only when not needed.

If we want to talk to a SD card connected to SPI, we need SPI
powered, of course.

From Traumflug: nice catch, Jeff!
2015-07-05 23:32:46 +02:00
Markus Hitter a217465e65 SIMINFO: fetch device name from Makefile / compile parameters.
It's also possible to do this by stringifying MCU, but this
requires double redirection, which isn't easily readable in a .c
file. For stringification, see the bottom example at
https://gcc.gnu.org/onlinedocs/cpp/Stringification.html
2015-04-21 02:51:31 +02:00
Markus Hitter f6115688c5 Move Intercom temp sensor initialisation from mendel.c to temp.c. 2014-12-26 19:41:38 +01:00
Markus Hitter a9f1d00865 Move MAX6675 initialisation from mendel.c to temp.c.
Also note a misplaced and misnamed pin.
2014-12-26 19:41:38 +01:00