cc3200: Simplify SPI polarity and phase checks in constructor.

This commit is contained in:
Daniel Campora 2015-05-27 09:42:32 +02:00
parent 95104b0fbd
commit c754d8011d
1 changed files with 3 additions and 18 deletions

View File

@ -224,23 +224,8 @@ STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, mp_uint_t n_args, const
uint polarity = args[3].u_int;
uint phase = args[4].u_int;
uint submode;
if (polarity) {
if (phase) {
// polarity = 1, phase = 1
submode = 3;
} else {
// polarity = 1, phase = 0
submode = 2;
}
} else {
if (phase) {
// polarity = 0, phase = 1
submode = 1;
} else {
// polarity = 0, phase = 0
submode = 0;
}
if (polarity > 1 || phase > 1) {
goto invalid_args;
}
uint nss = args[5].u_int;
@ -254,7 +239,7 @@ STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, mp_uint_t n_args, const
self->config = bits | nss | SPI_SW_CTRL_CS | SPI_4PIN_MODE | SPI_TURBO_OFF;
self->polarity = polarity;
self->phase = phase;
self->submode = submode;
self->submode = (polarity << 1) | phase;
// init the bus
pybspi_init((const pyb_spi_obj_t *)self);