mirror of https://github.com/Desuuuu/klipper.git
linux: Convert SPI to use enumerations
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
3e71a57f67
commit
f8bde6b1ef
|
@ -7,7 +7,7 @@ import logging
|
||||||
import pins, mcu, bus
|
import pins, mcu, bus
|
||||||
|
|
||||||
REPLICAPE_MAX_CURRENT = 3.84
|
REPLICAPE_MAX_CURRENT = 3.84
|
||||||
REPLICAPE_SHIFT_REGISTER_BUS = 0x0101
|
REPLICAPE_SHIFT_REGISTER_BUS = "spidev1.1"
|
||||||
REPLICAPE_PCA9685_BUS = 2
|
REPLICAPE_PCA9685_BUS = 2
|
||||||
REPLICAPE_PCA9685_ADDRESS = 0x70
|
REPLICAPE_PCA9685_ADDRESS = 0x70
|
||||||
REPLICAPE_PCA9685_CYCLE_TIME = .001
|
REPLICAPE_PCA9685_CYCLE_TIME = .001
|
||||||
|
|
|
@ -15,6 +15,15 @@
|
||||||
#include "internal.h" // report_errno
|
#include "internal.h" // report_errno
|
||||||
#include "sched.h" // shutdown
|
#include "sched.h" // shutdown
|
||||||
|
|
||||||
|
#define SPIBUS(chip, pin) (((chip)<<8) + (pin))
|
||||||
|
#define SPIBUS_TO_BUS(spi_bus) ((spi_bus) >> 8)
|
||||||
|
#define SPIBUS_TO_DEV(spi_bus) ((spi_bus) & 0xff)
|
||||||
|
|
||||||
|
DECL_ENUMERATION_RANGE("spi_bus", "spidev0.0", SPIBUS(0, 0), 16);
|
||||||
|
DECL_ENUMERATION_RANGE("spi_bus", "spidev1.0", SPIBUS(1, 0), 16);
|
||||||
|
DECL_ENUMERATION_RANGE("spi_bus", "spidev2.0", SPIBUS(2, 0), 16);
|
||||||
|
DECL_ENUMERATION_RANGE("spi_bus", "spidev3.0", SPIBUS(3, 0), 16);
|
||||||
|
|
||||||
struct spi_s {
|
struct spi_s {
|
||||||
uint32_t bus, dev;
|
uint32_t bus, dev;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -54,7 +63,7 @@ spi_open(uint32_t bus, uint32_t dev)
|
||||||
struct spi_config
|
struct spi_config
|
||||||
spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
|
spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
|
||||||
{
|
{
|
||||||
int bus_id = (bus >> 8) & 0xff, dev_id = bus & 0xff;
|
int bus_id = SPIBUS_TO_BUS(bus), dev_id = SPIBUS_TO_DEV(bus);
|
||||||
int fd = spi_open(bus_id, dev_id);
|
int fd = spi_open(bus_id, dev_id);
|
||||||
int ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &rate);
|
int ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &rate);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
Loading…
Reference in New Issue