spicmds: Check for an incorrect mode in spicmds.c
Check the mode parameter in spicmds.c so that the mcu code does not need to check it. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
6b108aa885
commit
db4f0c24cd
|
@ -39,7 +39,7 @@ spi_init(void)
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (bus || mode > 3)
|
if (bus)
|
||||||
shutdown("Invalid spi_setup parameters");
|
shutdown("Invalid spi_setup parameters");
|
||||||
|
|
||||||
// Make sure the SPI interface is enabled
|
// Make sure the SPI interface is enabled
|
||||||
|
|
|
@ -35,7 +35,7 @@ spi_init(void)
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (bus || mode > 3)
|
if (bus)
|
||||||
shutdown("Invalid spi_setup parameters");
|
shutdown("Invalid spi_setup parameters");
|
||||||
|
|
||||||
// Make sure bus is enabled
|
// Make sure bus is enabled
|
||||||
|
|
|
@ -54,7 +54,7 @@ spi_init(void)
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (bus != CHANNEL || mode > 3)
|
if (bus != CHANNEL)
|
||||||
shutdown("Invalid spi_setup parameters");
|
shutdown("Invalid spi_setup parameters");
|
||||||
|
|
||||||
// Make sure bus is enabled
|
// Make sure bus is enabled
|
||||||
|
|
|
@ -21,7 +21,7 @@ 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)
|
||||||
{
|
{
|
||||||
Usart *p_usart = USART0;
|
Usart *p_usart = USART0;
|
||||||
if (bus > 2 || mode > 3) {
|
if (bus > 2) {
|
||||||
shutdown("Invalid spi_setup parameters");
|
shutdown("Invalid spi_setup parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,14 @@ enum {
|
||||||
void
|
void
|
||||||
command_config_spi(uint32_t *args)
|
command_config_spi(uint32_t *args)
|
||||||
{
|
{
|
||||||
uint8_t shutdown_msg_len = args[5];
|
uint8_t mode = args[3], shutdown_msg_len = args[5];
|
||||||
|
if (mode > 3)
|
||||||
|
shutdown("Invalid spi mode");
|
||||||
struct spidev_s *spi = oid_alloc(args[0], command_config_spi
|
struct spidev_s *spi = oid_alloc(args[0], command_config_spi
|
||||||
, sizeof(*spi) + shutdown_msg_len);
|
, sizeof(*spi) + shutdown_msg_len);
|
||||||
spi->pin = gpio_out_setup(args[2], 1);
|
spi->pin = gpio_out_setup(args[2], 1);
|
||||||
spi->flags = SF_HAVE_PIN;
|
spi->flags = SF_HAVE_PIN;
|
||||||
spi->spi_config = spi_setup(args[1], args[3], args[4]);
|
spi->spi_config = spi_setup(args[1], mode, args[4]);
|
||||||
spi->shutdown_msg_len = shutdown_msg_len;
|
spi->shutdown_msg_len = shutdown_msg_len;
|
||||||
uint8_t *shutdown_msg = (void*)(size_t)args[6];
|
uint8_t *shutdown_msg = (void*)(size_t)args[6];
|
||||||
memcpy(spi->shutdown_msg, shutdown_msg, shutdown_msg_len);
|
memcpy(spi->shutdown_msg, shutdown_msg, shutdown_msg_len);
|
||||||
|
@ -42,10 +44,12 @@ DECL_COMMAND(command_config_spi,
|
||||||
void
|
void
|
||||||
command_config_spi_without_cs(uint32_t *args)
|
command_config_spi_without_cs(uint32_t *args)
|
||||||
{
|
{
|
||||||
uint8_t shutdown_msg_len = args[4];
|
uint8_t mode = args[2], shutdown_msg_len = args[4];
|
||||||
|
if (mode > 3)
|
||||||
|
shutdown("Invalid spi mode");
|
||||||
struct spidev_s *spi = oid_alloc(args[0], command_config_spi
|
struct spidev_s *spi = oid_alloc(args[0], command_config_spi
|
||||||
, sizeof(*spi) + shutdown_msg_len);
|
, sizeof(*spi) + shutdown_msg_len);
|
||||||
spi->spi_config = spi_setup(args[1], args[2], args[3]);
|
spi->spi_config = spi_setup(args[1], mode, args[3]);
|
||||||
spi->shutdown_msg_len = shutdown_msg_len;
|
spi->shutdown_msg_len = shutdown_msg_len;
|
||||||
uint8_t *shutdown_msg = (void*)(size_t)args[5];
|
uint8_t *shutdown_msg = (void*)(size_t)args[5];
|
||||||
memcpy(spi->shutdown_msg, shutdown_msg, shutdown_msg_len);
|
memcpy(spi->shutdown_msg, shutdown_msg, shutdown_msg_len);
|
||||||
|
|
|
@ -30,8 +30,6 @@ static void spi_set_mode(SPI_TypeDef *spi, uint8_t mode)
|
||||||
LL_SPI_SetClockPolarity(spi, LL_SPI_POLARITY_HIGH);
|
LL_SPI_SetClockPolarity(spi, LL_SPI_POLARITY_HIGH);
|
||||||
LL_SPI_SetClockPhase(spi, LL_SPI_PHASE_2EDGE);
|
LL_SPI_SetClockPhase(spi, LL_SPI_PHASE_2EDGE);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
shutdown("Invalid SPI mode");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue