aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-05-04 20:23:58 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-05-07 09:10:34 -0400
commitf70fefa06f9fe1aaca8c6303f0ee9e904a6f3623 (patch)
treed806c232bef22284960c8d9911cd6b8cc8306b30 /src
parent31ae74c56c9663fdbcc8f332efd0e331d2e024ff (diff)
downloadkutter-f70fefa06f9fe1aaca8c6303f0ee9e904a6f3623.tar.gz
kutter-f70fefa06f9fe1aaca8c6303f0ee9e904a6f3623.tar.xz
kutter-f70fefa06f9fe1aaca8c6303f0ee9e904a6f3623.zip
linux: Convert linux SPI code to use the generic spicmds.c code
Use the generic spi send/receive code on Linux. Update the replicape code to use the updated command format. Also, update the replicape code to turn off the stepper motors on a shutdown event. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/linux/Kconfig1
-rw-r--r--src/linux/gpio.h14
-rw-r--r--src/linux/spidev.c34
3 files changed, 38 insertions, 11 deletions
diff --git a/src/linux/Kconfig b/src/linux/Kconfig
index 651f0874..1647ef91 100644
--- a/src/linux/Kconfig
+++ b/src/linux/Kconfig
@@ -7,6 +7,7 @@ config LINUX_SELECT
bool
default y
select HAVE_GPIO_ADC
+ select HAVE_GPIO_SPI
config BOARD_DIRECTORY
string
diff --git a/src/linux/gpio.h b/src/linux/gpio.h
index a2c92520..74d9db37 100644
--- a/src/linux/gpio.h
+++ b/src/linux/gpio.h
@@ -3,6 +3,13 @@
#include <stdint.h> // uint8_t
+struct gpio_out {
+ uint32_t pin;
+};
+struct gpio_out gpio_out_setup(uint8_t pin, uint8_t val);
+void gpio_out_toggle(struct gpio_out g);
+void gpio_out_write(struct gpio_out g, uint8_t val);
+
struct gpio_adc {
int fd;
};
@@ -11,4 +18,11 @@ uint32_t gpio_adc_sample(struct gpio_adc g);
uint16_t gpio_adc_read(struct gpio_adc g);
void gpio_adc_cancel_sample(struct gpio_adc g);
+struct spi_config {
+ int fd;
+};
+struct spi_config spi_setup(uint32_t bus, uint8_t mode, uint32_t rate);
+void spi_transfer(struct spi_config config, uint8_t receive_data
+ , uint8_t len, uint8_t *data);
+
#endif // gpio.h
diff --git a/src/linux/spidev.c b/src/linux/spidev.c
index d68f9861..cb511205 100644
--- a/src/linux/spidev.c
+++ b/src/linux/spidev.c
@@ -1,6 +1,6 @@
-// Communicating with an SPI device via linux spidev
+// Very basic shift-register support via a Linux SPI device
//
-// Copyright (C) 2017 Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2017-2018 Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU GPLv3 license.
@@ -8,6 +8,7 @@
#include <stdio.h> // snprintf
#include <unistd.h> // write
#include "command.h" // DECL_COMMAND
+#include "gpio.h" // spi_setup
#include "internal.h" // report_errno
#include "sched.h" // shutdown
@@ -47,22 +48,33 @@ spi_open(uint32_t bus, uint32_t dev)
return fd;
}
-static void
-spi_write(int fd, char *data, int len)
+struct spi_config
+spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
{
- int ret = write(fd, data, len);
+ int bus_id = (bus >> 8) & 0xff, dev_id = bus & 0xff;
+ int fd = spi_open(bus_id, dev_id);
+ return (struct spi_config) { fd };
+}
+
+void
+spi_transfer(struct spi_config config, uint8_t receive_data
+ , uint8_t len, uint8_t *data)
+{
+ int ret = write(config.fd, data, len);
if (ret < 0) {
report_errno("write spi", ret);
shutdown("Unable to write to spi");
}
}
+// Dummy versions of gpio_out functions
+struct gpio_out
+gpio_out_setup(uint8_t pin, uint8_t val)
+{
+ shutdown("gpio_out_setup not supported");
+}
+
void
-command_send_spi(uint32_t *args)
+gpio_out_write(struct gpio_out g, uint8_t val)
{
- int fd = spi_open(args[0], args[1]);
- uint8_t len = args[2];
- char *msg = (void*)(size_t)args[3];
- spi_write(fd, msg, len);
}
-DECL_COMMAND(command_send_spi, "send_spi bus=%u dev=%u msg=%*s");