Commit Graph

140 Commits

Author SHA1 Message Date
Kevin O'Connor 835ec3513d Kconfig: Add a new CONFIG_HAVE_STRICT_TIMING build definition
Add a new build definition to note micro-controllers that have strict
timing.  The Linux mcu code does not have strict timing - all other
targets currently do.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-05-31 14:57:06 -04:00
Arksine 5fe9dd5a50 avr: implement i2c_read
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-01-13 22:29:50 -05:00
Kevin O'Connor bbf6f87de0 avr: List 20Mhz option below 16Mhz option in Kconfig
When enabling "low level options" in Kconfig, selecting a chip that is
20Mhz capable would result in 20Mhz being the default.  A 16Mhz speed
is the preferred default, so list that first in the menu.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-09-30 10:05:02 -04:00
Kevin O'Connor ab5238317b avr: Simplify spi mode setting
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-05-07 23:02:20 -04:00
Kevin O'Connor 7765653d83 avr: Use enumerations for buses and reserve pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-04-04 18:29:31 -04:00
Kevin O'Connor 2c851e1621 avr: Add enumerations for the atmega168/328 analog only pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-31 21:47:27 -04:00
Kevin O'Connor 8f541d090e avr: Use enumerations for pin mappings
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor b28e95ca1a command: Always pass a string to the DECL_CONSTANT() macro
Make it clear that the name of the constant being defined is a string.
When the value being defined is also a string, use a new
DECL_CONSTANT_STR() macro.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-17 19:38:18 -04:00
Kevin O'Connor 34d32c7823 stepper: Support an optimized step/unstep function on ARM
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-10 10:27:02 -04:00
Kevin O'Connor 399d539969 Makefile: Reduce use of $^ in build rules
It's rare to use all of a target's prerequisites in a recipe - replace
most cases with $< (the target's first prerequisite).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-03-02 12:01:44 -05:00
Kevin O'Connor 796b7ac738 avr: Wrap code to 80 columns
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 14:20:15 -05:00
Kevin O'Connor dddfb681c7 pins: Add support for pull down resistors
Add initial support for selecting pull down resistors (for
micro-controllers that support it).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-27 11:13:21 -05:00
Kevin O'Connor a285668b46 avr: Only prompt for cpu speed and uart port on LOW_LEVEL_OPTIONS
The cpu is almost always 16Mhz and the serial port is almost always
UART0, so no need to prompt in the normal case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-02-16 08:23:00 -05:00
Kevin O'Connor ee86463ed2 avr: Only prompt for CLEAR_PRESCALER and SIMULAVR with LOW_LEVEL_OPTIONS
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-25 18:07:31 -05:00
Kevin O'Connor b6ccd2682c Kconfig: Move SERIAL_BAUD to src/Kconfig and show with LOW_LEVEL_OPTIONS
Move the definition of SERIAL_BAUD to the main src/Kconfig file.  Only
show this as an option if the user selects the ability to configure
low-level options.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-25 18:02:03 -05:00
Kevin O'Connor 4fec225115 avr: Rename AVR_SERIAL and AVR_USBSERIAL to SERIAL and USBSERIAL
Rename the config options to be more consistent with other
architectures.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-25 17:52:09 -05:00
Kevin O'Connor 2ea7c97bbd stepper: Support configuring the stepper pulse length from Kconfig
Allow the stepper pulse length to be configured at compile time from
the Kconfig menu system.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-09 13:16:42 -05:00
Kevin O'Connor e26d1a3567 i2ccmds: Pass the i2c address as a 7-bit number (0-127)
The sam3 i2c code and the linux code use a 7-bit i2c address, while
the avr, lpc176x, and samd21 i2c code uses an 8-bit address with the
least significant bit always zero.  A similar issue occurred in the
host code (sx1509.py and replicape.py use 7-bit addresses while
uc1701.py and mcp4451.py use 8-bit addresses).

Consistently use 7-bit addresses in all the code.  This breaks
compatibility between host and mcu software, so make a change to the
config_i2c command to force users to synchronize software updates.
This also breaks common Smoothieboard configs, so update the mcp4451
code to validate the i2c_address.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2019-01-07 20:00:44 -05:00
Kevin O'Connor b84ecebf8f usb_cdc: Add support for detecting a USB level Arduino bootloader request
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-12-24 11:42:19 -05:00
Kevin O'Connor db4f0c24cd spicmds: Check for an incorrect mode in spicmds.c
Check the mode parameter in spicmds.c so that the mcu code does not
need to check it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-30 11:50:48 -05:00
Kevin O'Connor 729a2e8306 avr: Add support for sending I2C messages
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-23 23:49:26 -05:00
Kevin O'Connor 7bb9ce8436 avr: Minor comment update in hard_pwm.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-20 13:14:53 -05:00
Kevin O'Connor 7c65e76ad0 avr: Rework hardware pwm pin definitions
Simultaneously define the hardware pin and the timer registers.  This
makes the table a little easier to understand.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-20 12:58:33 -05:00
Kevin O'Connor bf92ffb5bf avr: Split gpio.c into gpio.c, adc.c, hard_pwm.c, and spi.c
Split up gpio.c into multiple files in an effort to make the code a
little more understandable.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-20 12:58:33 -05:00
Kevin O'Connor 2cc0313b72 avr: Add initial support for atmega32u4 chips
Signed-off-by: Trevor Jones <trevorjones141@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-20 12:58:33 -05:00
Kevin O'Connor 31687bc009 avr: Minor update to help text in Kconfig
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-11-19 22:05:26 -05:00
Kevin O'Connor 8432f6f40c avr: Add support for atmega328p
The atmega328p is basically the same as the atmega328 - add explicit
support for it so that avrdude doesn't complain while flashing.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-29 11:55:15 -04:00
Kevin O'Connor 978b321f80 avr: Disable usb serial interrupts while processing data
There's no need to keep taking interrupts if the high-level code is
busy processing messages.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-02 22:17:39 -04:00
Kevin O'Connor 7c7573f69f avr: No need to reset ep0 interrupts on a shutdown
The usb_cdc code will arrange to call usb_read_ep0_setup() after a
shutdown, so no need to have an explicit shutdown handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-02 21:41:36 -04:00
Kevin O'Connor d348f0da87 avr: Allow the serial port to be selected on the atmega2560/1280
Allow the serial port to be selected on the atmega2560 and atmega1280
chips in Kconfig.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-01 22:30:58 -04:00
Kevin O'Connor c68c0c6526 avr: Increase stack size to 256 for all AVR targets
Recent code additions have increased the stack usage and it is no
longer clear that everything will fit in 128 bytes.  Increase all
targets to 256 bytes (the atmega2560 was already at 256 bytes).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-01 10:33:18 -04:00
Kevin O'Connor d05aa81927 avr: Use generic usb_cdc code for usb serial support
Use the generic usb_cdc driver code instead of the "pjrc" usb driver
code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:55:21 -04:00
Kevin O'Connor 731236cf20 usb_cdc: Add support for usb_send_ep0_progmem()
Add support for explicitly sending to the ep0 pipe from constant
"progmem" memory on the AVR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:32:19 -04:00
Kevin O'Connor 1ae67441c3 avr: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:40:38 -04:00
Kevin O'Connor 0bce44e1bb avr: Disable HAVE_GPIO_BITBANGING on atmega168
The atmega168 doesn't have enough flash space to fit all features -
disable the "bit banging" interfaces to make room.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 11:20:29 -04:00
Kevin O'Connor 82a542faed Kconfig: Rename HAVE_USER_INTERFACE to HAVE_GPIO_BITBANGING
Rename the HAVE_USER_INTERFACE definition in preparation for other
"bit banging" interfaces.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 11:09:47 -04:00
Pascal Albert 244d0aa65b atmega1284p: Add choice between UART0 or UART1 to Kconfig
Signed-off-by: Pascal Albert <lucky@foxserver.org>
2018-07-13 19:58:04 -04:00
Kevin O'Connor d9f960fb0c avr: Configure spi transfer in spi_prepare()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-11 19:40:21 -04:00
Grigori Goronzy ebd9035325 SPI: introduce spi_prepare function
The SPI interface needs to be enabled and configured to the correct
settings of a given oid before CS is asserted. The new function
spi_prepare() allows ports to do that.

This port only introduces the new function in all ports with no
implementation and adds the call to the Klipper generic firmware code.
That means everything still works as before. Ports need to be changed
to fix the underlying issue.

Discussion about the motivation here:
https://github.com/KevinOConnor/klipper/pull/453#issuecomment-403131149

Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
2018-07-08 09:25:11 -04:00
Kevin O'Connor 7aec52dfb3 avr: Don't set SS high on spi_init()
The AVR requires that the SS pin be an output pin for correct SPI
operation.  Some boards use the SS pin to control devices separate
from SPI, however.  Don't change the output level if the pin is
already an output, and prefer setting it low if it is not already an
output pin.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-27 12:10:25 -04:00
Kevin O'Connor 528f9f7604 command: Add command_find_and_dispatch() helper
Add a helper function that calls command_find_block() followed by
command_dispatch().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor c8af3feee6 command: Add a command_encode_and_frame() helper
Add a helper function that calls command_encodef() followed by
command_add_frame().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor cb4e165071 command: Prefer uint8_t* for buffers; prefer uint8_fast_t for lengths
Prefer using 'uint8_t' buffers as it is too easy to run into C sign
extension problems with 'char' buffers.  Prefer using 'uint_fast8_t'
for buffer lengths as gcc does a better job compiling them on 32bit
mcus.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor 70068985a7 stepper: Introduce and use gpio_out_toggle_noirq()
The gpio_out_toggle() function in the sam3x8e and stm32f1 code was
only valid if it was called with irqs disabled.

Commits 018c5daa and 9c52ad43 enabled the lcd code which called
gpio_out_toggle() with irqs enabled.  This could cause corruption of
the gpio state.

Introduce a gpio_out_toggle_noirq() function that will only be invoked
with irqs disabled, and fix gpio_out_toggle() on sam3x8e and stm32f1
so that it safe to call even if irqs are enabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-15 17:09:11 -04:00
Kevin O'Connor 22487d95e9 spicmds: Rework SPI message transmission
Improve the SPI message transmit system.  Add support for bus speed
and bus mode.  Add support for sending SPI messages on shutdown.

Signed-off-by: Petri Honkala <cruwaller@gmail.com>
Signed-off-by: Douglas Hammond <wizhippo@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 09:10:34 -04:00
Kevin O'Connor 4a8f9407b8 avr: Do not use Idle mode
The AVR chips (bizarrely) start an ADC conversion when entering Idle
mode.  This behavior can cause the ADC to be busy when a sample is
required.  Worse, if a series of events cause the cpu to enter and
leave Idle mode with a timing similar to the ADC checking rate then it
can cause the ADC to show as busy for extended periods.  This could
cause high MCU load and possibly lead to a "Rescheduled timer in the
past" shutdown.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-28 21:26:42 -04:00
Kevin O'Connor 46cf3ef145 avr: Explicitly set ADCSRA on each conversion start
Don't logically or the ADSC bit on the start of a conversion -
explicitly set the full contents of the register.  Also, clear the
ADIF flag on each write.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-25 19:13:44 -04:00
Kevin O'Connor cf475a9a39 avr: Clean up serial port register aliases
Define unique register aliases for all of the hardware serial port
definitions.  This makes it easier to deal with the AVR chips that use
different register names.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-25 10:55:18 -04:00
Kevin O'Connor 6793970198 serial_irq: Add new generic/serial_irq.c code
Extract out common code from avr/serial.c, sam3x8e/serial.c, and
stm32f1/serial.c into a new generic/serial_irq.c file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-20 11:19:37 -04:00
Kevin O'Connor 9140f36d99 lcd_st7920: Add micro-controller code for the ST7920 LCD chip
Add support for passing messages to an ST7920 chip via a SPI
bit-banging interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 11:30:30 -05:00