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>
This commit is contained in:
Grigori Goronzy 2018-07-08 00:03:00 +02:00 committed by KevinOConnor
parent 5c7c8c984b
commit ebd9035325
11 changed files with 30 additions and 0 deletions

View File

@ -438,6 +438,10 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
return config;
}
void spi_prepare(struct spi_config config)
{
}
void
spi_transfer(struct spi_config config, uint8_t receive_data
, uint8_t len, uint8_t *data)

View File

@ -39,6 +39,7 @@ struct spi_config {
uint8_t spcr, spsr;
};
struct spi_config spi_setup(uint32_t bus, uint8_t mode, uint32_t rate);
void spi_prepare(struct spi_config config);
void spi_transfer(struct spi_config config, uint8_t receive_data
, uint8_t len, uint8_t *data);

View File

@ -35,6 +35,7 @@ struct spi_config {
uint32_t cfg;
};
struct spi_config spi_setup(uint32_t bus, uint8_t mode, uint32_t rate);
void spi_prepare(struct spi_config config);
void spi_transfer(struct spi_config config, uint8_t receive_data
, uint8_t len, uint8_t *data);

View File

@ -23,6 +23,7 @@ struct spi_config {
int fd;
};
struct spi_config spi_setup(uint32_t bus, uint8_t mode, uint32_t rate);
void spi_prepare(struct spi_config config);
void spi_transfer(struct spi_config config, uint8_t receive_data
, uint8_t len, uint8_t *data);

View File

@ -56,6 +56,11 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
return (struct spi_config) { fd };
}
void
spi_prepare(struct spi_config config)
{
}
void
spi_transfer(struct spi_config config, uint8_t receive_data
, uint8_t len, uint8_t *data)

View File

@ -33,6 +33,7 @@ struct spi_config {
uint32_t cfg;
};
struct spi_config spi_setup(uint32_t bus, uint8_t mode, uint32_t rate);
void spi_prepare(struct spi_config config);
void spi_transfer(struct spi_config config, uint8_t receive_data
, uint8_t len, uint8_t *data);

View File

@ -95,6 +95,11 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
return (struct spi_config){.cfg = config};
}
void
spi_prepare(struct spi_config config)
{
}
void
spi_transfer(struct spi_config config, uint8_t receive_data
, uint8_t len, uint8_t *data)

View File

@ -44,6 +44,10 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
return (struct spi_config){ };
}
void
spi_prepare(struct spi_config config)
{
}
void
spi_transfer(struct spi_config config, uint8_t receive_data
, uint8_t len, uint8_t *data)
{

View File

@ -58,10 +58,12 @@ spidev_transfer(struct spidev_s *spi, uint8_t receive_data
, uint8_t data_len, uint8_t *data)
{
if (spi->flags & SF_HAVE_PIN) {
spi_prepare(spi->spi_config);
gpio_out_write(spi->pin, 0);
spi_transfer(spi->spi_config, receive_data, data_len, data);
gpio_out_write(spi->pin, 1);
} else {
spi_prepare(spi->spi_config);
spi_transfer(spi->spi_config, receive_data, data_len, data);
}
}

View File

@ -300,6 +300,11 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
return config;
}
void
spi_prepare(struct spi_config config)
{
}
void
spi_transfer(struct spi_config config, uint8_t receive_data,
uint8_t len, uint8_t *data)

View File

@ -34,6 +34,7 @@ struct spi_config {
SPI_TypeDef config;
};
struct spi_config spi_setup(uint32_t bus, uint8_t mode, uint32_t rate);
void spi_prepare(struct spi_config config);
void spi_transfer(struct spi_config config, uint8_t receive_data,
uint8_t len, uint8_t *data);