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:
parent
5c7c8c984b
commit
ebd9035325
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue