aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-06-27 11:36:27 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-06-27 12:10:25 -0400
commit7aec52dfb3743850935d1080e045339c4a766231 (patch)
treedc20a2be7befe827db94402f1d4a043080627ade /src
parentd6518515679b939d1fd5c4af490c4ff9e75f88a9 (diff)
downloadkutter-7aec52dfb3743850935d1080e045339c4a766231.tar.gz
kutter-7aec52dfb3743850935d1080e045339c4a766231.tar.xz
kutter-7aec52dfb3743850935d1080e045339c4a766231.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/avr/gpio.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/avr/gpio.c b/src/avr/gpio.c
index ce89b1be..a6b7aa41 100644
--- a/src/avr/gpio.c
+++ b/src/avr/gpio.c
@@ -371,7 +371,9 @@ static const uint8_t MOSI = GPIO('B', 2), MISO = GPIO('B', 3);
static void
spi_init(void)
{
- gpio_out_setup(SS, 1);
+ if (!(GPIO2REGS(SS)->mode & GPIO2BIT(SS)))
+ // The SS pin must be an output pin (but is otherwise unused)
+ gpio_out_setup(SS, 0);
gpio_out_setup(SCK, 0);
gpio_out_setup(MOSI, 0);
gpio_in_setup(MISO, 0);