aboutsummaryrefslogtreecommitdiffstats
path: root/src/avr/gpio.c
Commit message (Collapse)AuthorAgeFilesLines
* avr: Switch to input state prior to enabling pullup in gpio_in_reset()Kevin O'Connor2025-07-221-4/+8
| | | | | | | | | | | | | | If switching a pin from output low to input with pullup, there is an intermediate state of either driven high or high impedance without a pullup. Similarly, when switching from output high to input without a pullup, there is an intermediate state of either driven low or high impedence with a pullup. In both cases it is preferable for the latter transition. Also, calculate the final setting prior to making any changes to reduce the time in that intermediate state. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Fix typo causing broken gpio mappingsKevin O'Connor2021-08-151-2/+2
| | | | | | | Commit 070fac07 had a typo causing two PINE definitions to be added to the list of available GPIOs. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Define PORTE on atmega328pKevin O'Connor2021-08-141-0/+6
| | | | | | | | The atmega328pb supports PORTE, but the current avr-libc toolchain doesn't support the atmega328pb. So, for now, add support for PORTE to atmega328p. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Use enumerations for pin mappingsKevin O'Connor2019-03-171-0/+18
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* pins: Add support for pull down resistorsKevin O'Connor2019-02-271-2/+2
| | | | | | | Add initial support for selecting pull down resistors (for micro-controllers that support it). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Split gpio.c into gpio.c, adc.c, hard_pwm.c, and spi.cKevin O'Connor2018-11-201-390/+4
| | | | | | | 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>
* avr: Add initial support for atmega32u4 chipsKevin O'Connor2018-11-201-2/+12
| | | | | Signed-off-by: Trevor Jones <trevorjones141@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Add support for atmega328pKevin O'Connor2018-10-291-3/+3
| | | | | | | 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>
* avr: Add support for gpio_x_reset()Kevin O'Connor2018-08-271-12/+24
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Configure spi transfer in spi_prepare()Kevin O'Connor2018-07-111-4/+4
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* SPI: introduce spi_prepare functionGrigori Goronzy2018-07-081-0/+4
| | | | | | | | | | | | | | | | 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>
* avr: Don't set SS high on spi_init()Kevin O'Connor2018-06-271-1/+3
| | | | | | | | | | 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>
* stepper: Introduce and use gpio_out_toggle_noirq()Kevin O'Connor2018-05-151-1/+7
| | | | | | | | | | | | | | | 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>
* spicmds: Rework SPI message transmissionKevin O'Connor2018-05-071-11/+85
| | | | | | | | | 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>
* avr: Explicitly set ADCSRA on each conversion startKevin O'Connor2018-04-251-7/+10
| | | | | | | | 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>
* avr: Add at90usb646 supportDouglas Hammond2018-02-251-3/+3
| | | | Signed-off-by: Douglas Hammond wizhippo@gmail.com
* avr: Round hardware pwm clock ticks to nearest divisorKevin O'Connor2018-01-291-12/+12
| | | | | | | Instead of rounding down to the nearest supported pwm divisor, round to the nearest divisor. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Clear the ADCSRA/ADCSRB registers on ADC initKevin O'Connor2018-01-071-2/+2
| | | | | | | When initializing the ADC, explicitly clear the registers (instead of logically or'ing them with their previous values). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Add support for atmega1284pKevin O'Connor2017-10-051-3/+8
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Add support for atmega328 chipKevin O'Connor2017-05-281-3/+3
| | | | | | | | The atmega328 is basically the same as the atmega168 - it just adds some additional memory. Allow the chip to be selected during the build. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* pwmcmds: Export the maximum PWM valueKevin O'Connor2017-05-151-0/+2
| | | | | | | Instead of assuming the maximum PWM value is 255, export a constant from the firmware to the host with the maximum value. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gpio: Fix off-by-one in declaration of ADC_MAXKevin O'Connor2017-05-151-1/+1
| | | | | | | The maximum value for the ADC is 1023 for 10bit samples and 4095 for 12bit samples. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Rework adc and pwm pin search to be more clearKevin O'Connor2017-04-111-59/+65
| | | | | | Rework the pin search loop. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Move code around in gpio.cKevin O'Connor2017-04-111-102/+110
| | | | | | | Move the PWM, ADC, and SPI pin tables closer to their corresponding code. This is code movement only - no code changes. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Fix irqstatus_t typo in gpio_pwm_setupKevin O'Connor2017-04-111-1/+1
| | | | | | The flags and cs variables should be uint8_t not irqstatus_t. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* mcu: Obtain the maximum adc value from the firmwareKevin O'Connor2016-12-231-0/+2
| | | | | | | Don't assume the hardware ADC has 10bit resultion - instead have the firmware define a constant and read that constant in the host. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gpio: Merge gpio_adc_sample_time() into gpio_adc_sample()Kevin O'Connor2016-11-021-17/+17
| | | | | | | Return the number of clock ticks to wait directly from gpio_adc_sample(). This simplifies the ADC interface. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* irq: Allow boards to define the return type of irq_save()Kevin O'Connor2016-06-131-6/+6
| | | | | | | | The AVR wants a uint8_t return type for irq_save(), but other architectures will generally prefer int. Allow the board to configure the size of the flag by introducing an irqstatus_t typedef. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* gpio: Fix off-by-one bug in check for the maximum gpio portKevin O'Connor2016-06-131-2/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Separate out gpio pwm pin definitions from pwm register definitionsKevin O'Connor2016-06-051-41/+44
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Eliminate gpio_adc_info struct in gpio adc pin definitionsKevin O'Connor2016-06-051-17/+12
| | | | | | | The gpio_adc_info only contains a single uint8_t field - it's simpler to use an array of uint8_t instead. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Define timer1 timers and prevent their use as PWM at runtimeKevin O'Connor2016-06-051-10/+12
| | | | | | | Instead of commenting out the timer1 pwm definitions, detect them at runtime. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* avr: Initial support for Atmel AT90USB1286 mcuKevin O'Connor2016-06-051-2/+19
| | | | | | | Add GPIO definitions for the AT90USB1286. Add code for communicating over USB port on AT90USB1286. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* Initial commit of source code.Kevin O'Connor2016-05-251-0/+337
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>