new pin validation routines; don't use mp_const_none if NULL will do
parent
29e44721d2
commit
ce9a7d7e2a
|
@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -55,7 +55,7 @@ uint8_t stop_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -97,7 +97,7 @@ uint8_t display_init_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB12, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB12, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -73,7 +73,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
|
|||
}
|
||||
|
||||
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
||||
|
@ -81,7 +81,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
|||
return;
|
||||
}
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
void analogin_reset() {
|
||||
|
|
|
@ -204,7 +204,7 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self,
|
|||
}
|
||||
|
||||
bool common_hal_audiobusio_i2sout_deinited(audiobusio_i2sout_obj_t* self) {
|
||||
return self->bit_clock == mp_const_none;
|
||||
return self->bit_clock == NULL;
|
||||
}
|
||||
|
||||
void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) {
|
||||
|
@ -213,11 +213,11 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) {
|
|||
}
|
||||
|
||||
reset_pin_number(self->bit_clock->number);
|
||||
self->bit_clock = mp_const_none;
|
||||
self->bit_clock = NULL;
|
||||
reset_pin_number(self->word_select->number);
|
||||
self->word_select = mp_const_none;
|
||||
self->word_select = NULL;
|
||||
reset_pin_number(self->data->number);
|
||||
self->data = mp_const_none;
|
||||
self->data = NULL;
|
||||
}
|
||||
|
||||
void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
|
||||
|
|
|
@ -219,7 +219,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
|
|||
}
|
||||
|
||||
bool common_hal_audiobusio_pdmin_deinited(audiobusio_pdmin_obj_t* self) {
|
||||
return self->clock_pin == mp_const_none;
|
||||
return self->clock_pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) {
|
||||
|
@ -237,8 +237,8 @@ void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) {
|
|||
|
||||
reset_pin_number(self->clock_pin->number);
|
||||
reset_pin_number(self->data_pin->number);
|
||||
self->clock_pin = mp_const_none;
|
||||
self->data_pin = mp_const_none;
|
||||
self->clock_pin = NULL;
|
||||
self->data_pin = NULL;
|
||||
}
|
||||
|
||||
uint8_t common_hal_audiobusio_pdmin_get_bit_depth(audiobusio_pdmin_obj_t* self) {
|
||||
|
|
|
@ -304,7 +304,7 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
|
|||
}
|
||||
|
||||
bool common_hal_audioio_audioout_deinited(audioio_audioout_obj_t* self) {
|
||||
return self->left_channel == mp_const_none;
|
||||
return self->left_channel == NULL;
|
||||
}
|
||||
|
||||
void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) {
|
||||
|
@ -332,10 +332,10 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) {
|
|||
tc_set_enable(tc_insts[self->tc_index], false);
|
||||
|
||||
reset_pin_number(self->left_channel->number);
|
||||
self->left_channel = mp_const_none;
|
||||
self->left_channel = NULL;
|
||||
#ifdef SAMD51
|
||||
reset_pin_number(self->right_channel->number);
|
||||
self->right_channel = mp_const_none;
|
||||
self->right_channel = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -89,8 +89,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||
Sercom* sercom = NULL;
|
||||
uint8_t sercom_index;
|
||||
uint32_t clock_pinmux = 0;
|
||||
bool mosi_none = mosi == mp_const_none || mosi == NULL;
|
||||
bool miso_none = miso == mp_const_none || miso == NULL;
|
||||
bool mosi_none = mosi == NULL;
|
||||
bool miso_none = miso == NULL;
|
||||
uint32_t mosi_pinmux = 0;
|
||||
uint32_t miso_pinmux = 0;
|
||||
uint8_t clock_pad = 0;
|
||||
|
|
|
@ -65,7 +65,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
uint32_t tx_pinmux = 0;
|
||||
uint8_t tx_pad = 255; // Unset pad
|
||||
|
||||
if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert)) {
|
||||
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
|
||||
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
|
||||
}
|
||||
|
||||
|
@ -73,8 +73,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
mp_raise_NotImplementedError(translate("bytes > 8 bits not supported"));
|
||||
}
|
||||
|
||||
bool have_tx = tx != mp_const_none;
|
||||
bool have_rx = rx != mp_const_none;
|
||||
bool have_tx = tx != NULL;
|
||||
bool have_rx = rx != NULL;
|
||||
if (!have_tx && !have_rx) {
|
||||
mp_raise_ValueError(translate("tx and rx cannot both be None"));
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
#endif
|
||||
tx_pinmux = PINMUX(tx->number, (i == 0) ? MUX_C : MUX_D);
|
||||
tx_pad = tx->sercom[i].pad;
|
||||
if (rx == mp_const_none) {
|
||||
if (rx == NULL) {
|
||||
sercom = potential_sercom;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ void common_hal_digitalio_digitalinout_never_reset(
|
|||
}
|
||||
|
||||
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t* self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self) {
|
||||
|
@ -63,7 +63,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self
|
|||
return;
|
||||
}
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_switch_to_input(
|
||||
|
|
|
@ -292,7 +292,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
|
|||
}
|
||||
|
||||
bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
|
||||
|
@ -319,7 +319,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
|
|||
}
|
||||
}
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) {
|
||||
|
|
|
@ -83,7 +83,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const
|
|||
|
||||
// start ADC
|
||||
ioctl(analogin_dev[self->number].fd, ANIOC_CXD56_START, 0);
|
||||
|
||||
|
||||
self->pin = pin;
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
|||
close(analogin_dev[self->number].fd);
|
||||
analogin_dev[self->number].fd = -1;
|
||||
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
|
||||
|
|
|
@ -60,10 +60,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
mp_float_t timeout, uint16_t receiver_buffer_size) {
|
||||
struct termios tio;
|
||||
|
||||
if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert)) {
|
||||
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
|
||||
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
|
||||
}
|
||||
|
||||
|
||||
if (bits != 8) {
|
||||
mp_raise_ValueError(translate("Could not initialize UART"));
|
||||
}
|
||||
|
|
|
@ -56,11 +56,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
|
|||
board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT);
|
||||
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
|
||||
|
|
|
@ -50,7 +50,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self,
|
|||
const mcu_pin_obj_t *pin, uint16_t duty, uint32_t frequency,
|
||||
bool variable_frequency) {
|
||||
self->number = -1;
|
||||
|
||||
|
||||
for (int i = 0; i < MP_ARRAY_SIZE(pwmout_dev); i++) {
|
||||
if (pin->number == pwmout_dev[i].pin->number) {
|
||||
self->number = i;
|
||||
|
@ -95,7 +95,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) {
|
|||
pwmout_dev[self->number].fd = -1;
|
||||
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t *self) {
|
||||
|
@ -131,11 +131,11 @@ bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t *self
|
|||
void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
|
||||
never_reset_pin_number(self->pin->number);
|
||||
|
||||
pwmout_dev[self->number].reset = false;
|
||||
pwmout_dev[self->number].reset = false;
|
||||
}
|
||||
|
||||
void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
|
||||
pwmout_dev[self->number].reset = true;
|
||||
pwmout_dev[self->number].reset = true;
|
||||
}
|
||||
|
||||
void pwmout_reset(void) {
|
||||
|
|
|
@ -106,7 +106,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
|
|||
|
||||
board_gpio_int(self->pin->number, true);
|
||||
}
|
||||
|
||||
|
||||
void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
|
||||
if (common_hal_pulseio_pulsein_deinited(self)) {
|
||||
return;
|
||||
|
@ -116,18 +116,18 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
|
|||
board_gpio_intconfig(self->pin->number, 0, false, NULL);
|
||||
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
|
||||
void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) {
|
||||
board_gpio_int(self->pin->number, false);
|
||||
self->paused = true;
|
||||
}
|
||||
|
||||
|
||||
void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, uint16_t trigger_duration) {
|
||||
// Make sure we're paused.
|
||||
common_hal_pulseio_pulsein_pause(self);
|
||||
|
@ -147,14 +147,14 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, uint16_t tri
|
|||
pulsein_set_config(self, true);
|
||||
board_gpio_int(self->pin->number, true);
|
||||
}
|
||||
|
||||
|
||||
void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t *self) {
|
||||
common_hal_mcu_disable_interrupts();
|
||||
self->start = 0;
|
||||
self->len = 0;
|
||||
common_hal_mcu_enable_interrupts();
|
||||
}
|
||||
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {
|
||||
if (self->len == 0) {
|
||||
mp_raise_IndexError(translate("pop from an empty PulseIn"));
|
||||
|
@ -167,19 +167,19 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {
|
|||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t *self) {
|
||||
return self->maxlen;
|
||||
}
|
||||
|
||||
|
||||
bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t *self) {
|
||||
return self->paused;
|
||||
}
|
||||
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t *self) {
|
||||
return self->len;
|
||||
}
|
||||
|
||||
|
||||
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_t index) {
|
||||
common_hal_mcu_disable_interrupts();
|
||||
if (index < 0) {
|
||||
|
@ -193,4 +193,3 @@ uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_
|
|||
common_hal_mcu_enable_interrupts();
|
||||
return value;
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
|
|||
}
|
||||
|
||||
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
||||
|
@ -66,7 +66,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
|||
return;
|
||||
}
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
|
||||
|
|
|
@ -80,8 +80,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
|
||||
// TODO: Allow none rx or tx
|
||||
|
||||
bool have_tx = tx != mp_const_none;
|
||||
bool have_rx = rx != mp_const_none;
|
||||
bool have_tx = tx != NULL;
|
||||
bool have_rx = rx != NULL;
|
||||
if (!have_tx && !have_rx) {
|
||||
mp_raise_ValueError(translate("tx and rx cannot both be None"));
|
||||
}
|
||||
|
@ -116,8 +116,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
}
|
||||
|
||||
// Filter for sane settings for RS485
|
||||
if (rs485_dir != mp_const_none) {
|
||||
if ((rts != mp_const_none) || (cts != mp_const_none)) {
|
||||
if (rs485_dir != NULL) {
|
||||
if ((rts != NULL) || (cts != NULL)) {
|
||||
mp_raise_ValueError(translate("Cannot specify RTS or CTS in RS485 mode"));
|
||||
}
|
||||
// For IMXRT the RTS pin is used for RS485 direction
|
||||
|
@ -133,7 +133,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
const uint32_t rts_count = sizeof(mcu_uart_rts_list) / sizeof(mcu_periph_obj_t);
|
||||
const uint32_t cts_count = sizeof(mcu_uart_cts_list) / sizeof(mcu_periph_obj_t);
|
||||
|
||||
if (rts != mp_const_none) {
|
||||
if (rts != NULL) {
|
||||
for (uint32_t i=0; i < rts_count; ++i) {
|
||||
if (mcu_uart_rts_list[i].bank_idx == self->rx_pin->bank_idx) {
|
||||
if (mcu_uart_rts_list[i].pin == rts) {
|
||||
|
@ -146,7 +146,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
mp_raise_ValueError(translate("Selected RTS pin not valid"));
|
||||
}
|
||||
|
||||
if (cts != mp_const_none) {
|
||||
if (cts != NULL) {
|
||||
for (uint32_t i=0; i < cts_count; ++i) {
|
||||
if (mcu_uart_cts_list[i].bank_idx == self->rx_pin->bank_idx) {
|
||||
if (mcu_uart_cts_list[i].pin == cts) {
|
||||
|
@ -158,7 +158,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
if (self->cts_pin == NULL)
|
||||
mp_raise_ValueError(translate("Selected CTS pin not valid"));
|
||||
}
|
||||
|
||||
|
||||
self->uart = mcu_uart_banks[self->tx_pin->bank_idx - 1];
|
||||
|
||||
config_periph_pin(self->rx_pin);
|
||||
|
@ -166,7 +166,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
if (self->rts_pin)
|
||||
config_periph_pin(self->rts_pin);
|
||||
if (self->cts_pin)
|
||||
config_periph_pin(self->cts_pin);
|
||||
config_periph_pin(self->cts_pin);
|
||||
|
||||
lpuart_config_t config = { 0 };
|
||||
LPUART_GetDefaultConfig(&config);
|
||||
|
@ -187,7 +187,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
// Before we init, setup RS485 direction pin
|
||||
// ..unfortunately this isn't done by the driver library
|
||||
uint32_t modir = (self->uart->MODIR) & ~(LPUART_MODIR_TXRTSPOL_MASK | LPUART_MODIR_TXRTSE_MASK);
|
||||
if (rs485_dir != mp_const_none) {
|
||||
if (rs485_dir != NULL) {
|
||||
modir |= LPUART_MODIR_TXRTSE_MASK;
|
||||
if (rs485_invert)
|
||||
modir |= LPUART_MODIR_TXRTSPOL_MASK;
|
||||
|
|
|
@ -78,7 +78,7 @@ void common_hal_digitalio_digitalinout_never_reset(
|
|||
}
|
||||
|
||||
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t* self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self) {
|
||||
|
@ -86,7 +86,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self
|
|||
return;
|
||||
}
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_switch_to_input(
|
||||
|
|
|
@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = {
|
|||
|
||||
void board_init(void) {
|
||||
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
|
||||
common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, mp_const_none);
|
||||
common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL);
|
||||
common_hal_busio_spi_never_reset(spi);
|
||||
|
||||
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
|
||||
|
|
|
@ -55,7 +55,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const
|
|||
}
|
||||
|
||||
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
||||
|
@ -65,7 +65,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
|||
nrf_gpio_cfg_default(self->pin->number);
|
||||
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
|
||||
|
|
|
@ -155,7 +155,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
|
|||
self->clock_pin_number = clock->number;
|
||||
claim_pin(clock);
|
||||
|
||||
if (mosi != mp_const_none) {
|
||||
if (mosi != NULL) {
|
||||
config.mosi_pin = mosi->number;
|
||||
self->MOSI_pin_number = mosi->number;
|
||||
claim_pin(mosi);
|
||||
|
@ -163,7 +163,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
|
|||
self->MOSI_pin_number = NO_PIN;
|
||||
}
|
||||
|
||||
if (miso != mp_const_none) {
|
||||
if (miso != NULL) {
|
||||
config.miso_pin = miso->number;
|
||||
self->MISO_pin_number = mosi->number;
|
||||
claim_pin(miso);
|
||||
|
|
|
@ -135,10 +135,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop,
|
||||
mp_float_t timeout, uint16_t receiver_buffer_size) {
|
||||
|
||||
if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert)) {
|
||||
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
|
||||
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
|
||||
}
|
||||
|
||||
|
||||
// Find a free UART peripheral.
|
||||
self->uarte = NULL;
|
||||
for (size_t i = 0 ; i < MP_ARRAY_SIZE(nrfx_uartes); i++) {
|
||||
|
@ -152,7 +152,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
mp_raise_ValueError(translate("All UART peripherals are in use"));
|
||||
}
|
||||
|
||||
if ( (tx == mp_const_none) && (rx == mp_const_none) ) {
|
||||
if ( (tx == NULL) && (rx == NULL) ) {
|
||||
mp_raise_ValueError(translate("tx and rx cannot both be None"));
|
||||
}
|
||||
|
||||
|
@ -165,8 +165,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
}
|
||||
|
||||
nrfx_uarte_config_t config = {
|
||||
.pseltxd = (tx == mp_const_none) ? NRF_UARTE_PSEL_DISCONNECTED : tx->number,
|
||||
.pselrxd = (rx == mp_const_none) ? NRF_UARTE_PSEL_DISCONNECTED : rx->number,
|
||||
.pseltxd = (tx == NULL) ? NRF_UARTE_PSEL_DISCONNECTED : tx->number,
|
||||
.pselrxd = (rx == NULL) ? NRF_UARTE_PSEL_DISCONNECTED : rx->number,
|
||||
.pselcts = NRF_UARTE_PSEL_DISCONNECTED,
|
||||
.pselrts = NRF_UARTE_PSEL_DISCONNECTED,
|
||||
.p_context = self,
|
||||
|
@ -181,7 +181,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
_VERIFY_ERR(nrfx_uarte_init(self->uarte, &config, uart_callback_irq));
|
||||
|
||||
// Init buffer for rx
|
||||
if ( rx != mp_const_none ) {
|
||||
if ( rx != NULL ) {
|
||||
// Initially allocate the UART's buffer in the long-lived part of the
|
||||
// heap. UARTs are generally long-lived objects, but the "make long-
|
||||
// lived" machinery is incapable of moving internal pointers like
|
||||
|
@ -200,7 +200,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
claim_pin(rx);
|
||||
}
|
||||
|
||||
if ( tx != mp_const_none ) {
|
||||
if ( tx != NULL ) {
|
||||
self->tx_pin_number = tx->number;
|
||||
claim_pin(tx);
|
||||
} else {
|
||||
|
|
|
@ -46,7 +46,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
|
|||
}
|
||||
|
||||
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) {
|
||||
|
@ -56,7 +56,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
|
|||
nrf_gpio_cfg_default(self->pin->number);
|
||||
|
||||
reset_pin_number(self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_switch_to_input(
|
||||
|
|
|
@ -45,11 +45,11 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
|
|||
}
|
||||
// TODO: add ADC traits to structure?
|
||||
|
||||
// Note that ADC2 is always bundled pin-to-pin with ADC1 if it exists, and used only
|
||||
// for dual conversion. For this basic application it is never used.
|
||||
// Note that ADC2 is always bundled pin-to-pin with ADC1 if it exists, and used only
|
||||
// for dual conversion. For this basic application it is never used.
|
||||
LL_GPIO_SetPinMode(pin_port(pin->port), (uint32_t)pin_mask(pin->number), LL_GPIO_MODE_ANALOG);
|
||||
if (pin->adc_unit & 0x01) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
|
||||
} else if (pin->adc_unit == 0x04) {
|
||||
#ifdef LL_APB2_GRP1_PERIPH_ADC3
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC3);
|
||||
|
@ -62,7 +62,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
|
|||
}
|
||||
|
||||
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
||||
|
@ -70,7 +70,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
|
|||
return;
|
||||
}
|
||||
reset_pin_number(self->pin->port,self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
|
||||
|
@ -116,10 +116,10 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
|
|||
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
|
||||
|
||||
HAL_ADC_Start(&AdcHandle);
|
||||
HAL_ADC_PollForConversion(&AdcHandle,1);
|
||||
HAL_ADC_PollForConversion(&AdcHandle,1);
|
||||
uint16_t value = (uint16_t)HAL_ADC_GetValue(&AdcHandle);
|
||||
HAL_ADC_Stop(&AdcHandle);
|
||||
|
||||
|
||||
// // Shift the value to be 16 bit.
|
||||
return value << 4;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
//DAC is shared between both channels.
|
||||
//DAC is shared between both channels.
|
||||
#if HAS_DAC
|
||||
DAC_HandleTypeDef handle;
|
||||
#endif
|
||||
|
@ -97,7 +97,7 @@ bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
|
|||
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
|
||||
#if HAS_DAC
|
||||
reset_pin_number(self->pin->port,self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
dac_on[self->dac_index] = false;
|
||||
|
||||
//turn off the DAC if both channels are off
|
||||
|
|
|
@ -100,14 +100,14 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
|
|||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = self->sda->altfn_index;
|
||||
GPIO_InitStruct.Alternate = self->sda->altfn_index;
|
||||
HAL_GPIO_Init(pin_port(sda->port), &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = pin_mask(scl->number);
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Alternate = self->scl->altfn_index;
|
||||
GPIO_InitStruct.Alternate = self->scl->altfn_index;
|
||||
HAL_GPIO_Init(pin_port(scl->port), &GPIO_InitStruct);
|
||||
|
||||
//Note: due to I2C soft reboot issue, do not relocate clock init.
|
||||
|
@ -144,7 +144,7 @@ void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
|
|||
}
|
||||
|
||||
bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
|
||||
return self->sda->pin == mp_const_none;
|
||||
return self->sda == NULL;
|
||||
}
|
||||
|
||||
void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
|
||||
|
@ -158,8 +158,8 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
|
|||
|
||||
reset_pin_number(self->sda->pin->port,self->sda->pin->number);
|
||||
reset_pin_number(self->scl->pin->port,self->scl->pin->number);
|
||||
self->sda = mp_const_none;
|
||||
self->scl = mp_const_none;
|
||||
self->sda = NULL;
|
||||
self->scl = NULL;
|
||||
}
|
||||
|
||||
bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
|
||||
|
@ -169,7 +169,7 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
|
|||
bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
|
||||
bool grabbed_lock = false;
|
||||
|
||||
//Critical section code that may be required at some point.
|
||||
//Critical section code that may be required at some point.
|
||||
// uint32_t store_primask = __get_PRIMASK();
|
||||
// __disable_irq();
|
||||
// __DMB();
|
||||
|
@ -195,19 +195,19 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
|
|||
|
||||
uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
|
||||
const uint8_t *data, size_t len, bool transmit_stop_bit) {
|
||||
HAL_StatusTypeDef result = HAL_I2C_Master_Transmit(&(self->handle), (uint16_t)(addr << 1),
|
||||
HAL_StatusTypeDef result = HAL_I2C_Master_Transmit(&(self->handle), (uint16_t)(addr << 1),
|
||||
(uint8_t *)data, (uint16_t)len, 500);
|
||||
return result == HAL_OK ? 0 : MP_EIO;
|
||||
}
|
||||
|
||||
uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
|
||||
uint8_t *data, size_t len) {
|
||||
return HAL_I2C_Master_Receive(&(self->handle), (uint16_t)(addr<<1), data, (uint16_t)len, 500)
|
||||
return HAL_I2C_Master_Receive(&(self->handle), (uint16_t)(addr<<1), data, (uint16_t)len, 500)
|
||||
== HAL_OK ? 0 : MP_EIO;
|
||||
}
|
||||
|
||||
STATIC void i2c_clock_enable(uint8_t mask) {
|
||||
//Note: hard reset required due to soft reboot issue.
|
||||
//Note: hard reset required due to soft reboot issue.
|
||||
#ifdef I2C1
|
||||
if (mask & (1 << 0)) {
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
|
|
|
@ -49,7 +49,7 @@ STATIC void spi_clock_enable(uint8_t mask);
|
|||
STATIC void spi_clock_disable(uint8_t mask);
|
||||
|
||||
STATIC uint32_t get_busclock(SPI_TypeDef * instance) {
|
||||
//SPI2 and 3 are on PCLK1, if they exist.
|
||||
//SPI2 and 3 are on PCLK1, if they exist.
|
||||
#ifdef SPI2
|
||||
if (instance == SPI2) return HAL_RCC_GetPCLK1Freq();
|
||||
#endif
|
||||
|
@ -113,7 +113,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||
for (uint i = 0; i < sck_len; i++) {
|
||||
if (mcu_spi_sck_list[i].pin == sck) {
|
||||
//if both MOSI and MISO exist, loop search normally
|
||||
if ((mosi != mp_const_none) && (miso != mp_const_none)) {
|
||||
if ((mosi != NULL) && (miso != NULL)) {
|
||||
//MOSI
|
||||
for (uint j = 0; j < mosi_len; j++) {
|
||||
if (mcu_spi_mosi_list[j].pin == mosi) {
|
||||
|
@ -133,11 +133,11 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||
self->miso = &mcu_spi_miso_list[k];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if just MISO, reduce search
|
||||
} else if (miso != mp_const_none) {
|
||||
} else if (miso != NULL) {
|
||||
for (uint j = 0; j < miso_len; j++) {
|
||||
if ((mcu_spi_miso_list[j].pin == miso) //only SCK and MISO need the same index
|
||||
&& (mcu_spi_sck_list[i].spi_index == mcu_spi_miso_list[j].spi_index)) {
|
||||
|
@ -152,9 +152,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||
self->miso = &mcu_spi_miso_list[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if just MOSI, reduce search
|
||||
} else if (mosi != mp_const_none) {
|
||||
} else if (mosi != NULL) {
|
||||
for (uint j = 0; j < mosi_len; j++) {
|
||||
if ((mcu_spi_mosi_list[j].pin == mosi) //only SCK and MOSI need the same index
|
||||
&& (mcu_spi_sck_list[i].spi_index == mcu_spi_mosi_list[j].spi_index)) {
|
||||
|
@ -169,7 +169,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||
self->miso = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//throw an error immediately
|
||||
mp_raise_ValueError(translate("Must provide MISO or MOSI pin"));
|
||||
|
@ -179,8 +179,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||
|
||||
//handle typedef selection, errors
|
||||
if ( (self->sck != NULL && self->mosi != NULL && self->miso != NULL) ||
|
||||
(self->sck != NULL && self->mosi != NULL && miso == mp_const_none) ||
|
||||
(self->sck != NULL && self->miso != NULL && mosi == mp_const_none)) {
|
||||
(self->sck != NULL && self->mosi != NULL && miso == NULL) ||
|
||||
(self->sck != NULL && self->miso != NULL && mosi == NULL)) {
|
||||
SPIx = mcu_spi_banks[self->sck->spi_index - 1];
|
||||
} else {
|
||||
if (spi_taken) {
|
||||
|
@ -196,7 +196,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = self->sck->altfn_index;
|
||||
GPIO_InitStruct.Alternate = self->sck->altfn_index;
|
||||
HAL_GPIO_Init(pin_port(sck->port), &GPIO_InitStruct);
|
||||
|
||||
if (self->mosi != NULL) {
|
||||
|
@ -204,7 +204,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = self->mosi->altfn_index;
|
||||
GPIO_InitStruct.Alternate = self->mosi->altfn_index;
|
||||
HAL_GPIO_Init(pin_port(mosi->port), &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
|
@ -213,14 +213,14 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
|
|||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = self->miso->altfn_index;
|
||||
GPIO_InitStruct.Alternate = self->miso->altfn_index;
|
||||
HAL_GPIO_Init(pin_port(miso->port), &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
spi_clock_enable(1 << (self->sck->spi_index - 1));
|
||||
reserved_spi[self->sck->spi_index - 1] = true;
|
||||
|
||||
self->handle.Instance = SPIx;
|
||||
|
||||
self->handle.Instance = SPIx;
|
||||
self->handle.Init.Mode = SPI_MODE_MASTER;
|
||||
// Direction change only required for RX-only, see RefMan RM0090:884
|
||||
self->handle.Init.Direction = (self->mosi == NULL) ? SPI_CR1_RXONLY : SPI_DIRECTION_2LINES;
|
||||
|
@ -269,7 +269,7 @@ void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) {
|
|||
}
|
||||
|
||||
bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
|
||||
return self->sck->pin == mp_const_none;
|
||||
return self->sck->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
|
||||
|
@ -287,15 +287,15 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
|
|||
if (self->miso != NULL) {
|
||||
reset_pin_number(self->miso->pin->port,self->miso->pin->number);
|
||||
}
|
||||
self->sck = mp_const_none;
|
||||
self->mosi = mp_const_none;
|
||||
self->miso = mp_const_none;
|
||||
self->sck = NULL;
|
||||
self->mosi = NULL;
|
||||
self->miso = NULL;
|
||||
}
|
||||
|
||||
bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
|
||||
uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
|
||||
//This resets the SPI, so check before updating it redundantly
|
||||
if (baudrate == self->baudrate && polarity== self->polarity
|
||||
if (baudrate == self->baudrate && polarity== self->polarity
|
||||
&& phase == self->phase && bits == self->bits) {
|
||||
return true;
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
|
|||
self->handle.Init.CLKPolarity = (polarity) ? SPI_POLARITY_HIGH : SPI_POLARITY_LOW;
|
||||
self->handle.Init.CLKPhase = (phase) ? SPI_PHASE_2EDGE : SPI_PHASE_1EDGE;
|
||||
|
||||
self->handle.Init.BaudRatePrescaler = stm32_baud_to_spi_div(baudrate, &self->prescaler,
|
||||
self->handle.Init.BaudRatePrescaler = stm32_baud_to_spi_div(baudrate, &self->prescaler,
|
||||
get_busclock(self->handle.Instance));
|
||||
|
||||
if (HAL_SPI_Init(&self->handle) != HAL_OK)
|
||||
|
@ -325,7 +325,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
|
|||
bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
|
||||
bool grabbed_lock = false;
|
||||
|
||||
//Critical section code that may be required at some point.
|
||||
//Critical section code that may be required at some point.
|
||||
// uint32_t store_primask = __get_PRIMASK();
|
||||
// __disable_irq();
|
||||
// __DMB();
|
||||
|
@ -367,7 +367,7 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
|
|||
return result == HAL_OK;
|
||||
}
|
||||
|
||||
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self,
|
||||
bool common_hal_busio_spi_transfer(busio_spi_obj_t *self,
|
||||
uint8_t *data_out, uint8_t *data_in, size_t len) {
|
||||
if (self->miso == NULL || self->mosi == NULL) {
|
||||
mp_raise_ValueError(translate("Missing MISO or MOSI Pin"));
|
||||
|
|
|
@ -86,12 +86,12 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
bool uart_taken = false;
|
||||
uint8_t uart_index = 0; //origin 0 corrected
|
||||
|
||||
if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert == true)) {
|
||||
if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert == true)) {
|
||||
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
|
||||
}
|
||||
|
||||
|
||||
//Can have both pins, or either
|
||||
if ((tx != mp_const_none) && (rx != mp_const_none)) {
|
||||
if ((tx != NULL) && (rx != NULL)) {
|
||||
//normal find loop if both pins exist
|
||||
for (uint i = 0; i < tx_len; i++) {
|
||||
if (mcu_uart_tx_list[i].pin == tx) {
|
||||
|
@ -115,7 +115,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
uart_index = self->tx->uart_index - 1;
|
||||
USARTx = assign_uart_or_throw(self, (self->tx != NULL && self->rx != NULL),
|
||||
uart_index, uart_taken);
|
||||
} else if (tx == mp_const_none) {
|
||||
} else if (tx == NULL) {
|
||||
//If there is no tx, run only rx
|
||||
for (uint i = 0; i < rx_len; i++) {
|
||||
if (mcu_uart_rx_list[i].pin == rx) {
|
||||
|
@ -132,7 +132,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
uart_index = self->rx->uart_index - 1;
|
||||
USARTx = assign_uart_or_throw(self, (self->rx != NULL),
|
||||
uart_index, uart_taken);
|
||||
} else if (rx == mp_const_none) {
|
||||
} else if (rx == NULL) {
|
||||
//If there is no rx, run only tx
|
||||
for (uint i = 0; i < tx_len; i++) {
|
||||
if (mcu_uart_tx_list[i].pin == tx) {
|
||||
|
@ -236,7 +236,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||
}
|
||||
|
||||
bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) {
|
||||
return self->tx->pin == mp_const_none;
|
||||
return self->tx->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
|
||||
|
@ -244,8 +244,8 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
|
|||
|
||||
reset_pin_number(self->tx->pin->port,self->tx->pin->number);
|
||||
reset_pin_number(self->rx->pin->port,self->rx->pin->number);
|
||||
self->tx = mp_const_none;
|
||||
self->rx = mp_const_none;
|
||||
self->tx = NULL;
|
||||
self->rx = NULL;
|
||||
gc_free(self->rbuf.buf);
|
||||
self->rbuf.size = 0;
|
||||
self->rbuf.iput = self->rbuf.iget = 0;
|
||||
|
|
|
@ -54,7 +54,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
|
|||
}
|
||||
|
||||
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) {
|
||||
return self->pin == mp_const_none;
|
||||
return self->pin == NULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) {
|
||||
|
@ -63,7 +63,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
|
|||
}
|
||||
|
||||
reset_pin_number(self->pin->port, self->pin->number);
|
||||
self->pin = mp_const_none;
|
||||
self->pin = NULL;
|
||||
}
|
||||
|
||||
void common_hal_digitalio_digitalinout_switch_to_input(
|
||||
|
@ -90,7 +90,7 @@ void common_hal_digitalio_digitalinout_switch_to_output(
|
|||
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
|
||||
digitalio_digitalinout_obj_t *self) {
|
||||
|
||||
return (LL_GPIO_GetPinMode(pin_port(self->pin->port), pin_mask(self->pin->number))
|
||||
return (LL_GPIO_GetPinMode(pin_port(self->pin->port), pin_mask(self->pin->number))
|
||||
== LL_GPIO_MODE_INPUT) ? DIRECTION_INPUT : DIRECTION_OUTPUT;
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
|
|||
digitalio_drive_mode_t drive_mode) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
GPIO_InitStruct.Pin = pin_mask(self->pin->number);
|
||||
GPIO_InitStruct.Mode = (drive_mode == DRIVE_MODE_OPEN_DRAIN ?
|
||||
GPIO_InitStruct.Mode = (drive_mode == DRIVE_MODE_OPEN_DRAIN ?
|
||||
GPIO_MODE_OUTPUT_OD : GPIO_MODE_OUTPUT_PP);
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
|
@ -121,7 +121,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
|
|||
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
|
||||
digitalio_digitalinout_obj_t *self) {
|
||||
|
||||
return LL_GPIO_GetPinOutputType(pin_port(self->pin->port), pin_mask(self->pin->number))
|
||||
return LL_GPIO_GetPinOutputType(pin_port(self->pin->port), pin_mask(self->pin->number))
|
||||
== LL_GPIO_OUTPUT_OPENDRAIN ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL;
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ void common_hal_digitalio_digitalinout_set_pull(
|
|||
|
||||
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
|
||||
digitalio_digitalinout_obj_t *self) {
|
||||
|
||||
|
||||
|
||||
switch (LL_GPIO_GetPinPull(pin_port(self->pin->port), pin_mask(self->pin->number))) {
|
||||
case LL_GPIO_PULL_UP:
|
||||
|
|
|
@ -72,7 +72,7 @@ STATIC uint32_t timer_get_internal_duty(uint16_t duty, uint32_t period) {
|
|||
return (duty*period) / ((1 << 16) - 1);
|
||||
}
|
||||
|
||||
STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler,
|
||||
STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler,
|
||||
uint32_t frequency, uint32_t source_freq) {
|
||||
//Find the largest possible period supported by this frequency
|
||||
for (int i = 0; i < (1 << 16); i++) {
|
||||
|
@ -139,7 +139,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
|
|||