Minor fixes

This commit is contained in:
Hierophect 2019-09-06 17:40:45 -04:00
parent 8c0be5fbe2
commit a932d2c4a1
2 changed files with 17 additions and 17 deletions

View File

@ -43,11 +43,11 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
self->pin = pin; self->pin = pin;
GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = (pin_mask(pin->number)); GPIO_InitStruct.Pin = (pin_mask(self->pin->number));
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(pin_port(pin->number), &GPIO_InitStruct); HAL_GPIO_Init(pin_port(self->pin->number), &GPIO_InitStruct);
return DIGITALINOUT_OK; return DIGITALINOUT_OK;
} }
@ -69,11 +69,11 @@ void common_hal_digitalio_digitalinout_switch_to_input(
digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = pin_mask(pin->number); GPIO_InitStruct.Pin = pin_mask(self->pin->number);
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(pin_port(pin->number), &GPIO_InitStruct); HAL_GPIO_Init(pin_port(self->pin->number), &GPIO_InitStruct);
common_hal_digitalio_digitalinout_set_pull(self, pull); common_hal_digitalio_digitalinout_set_pull(self, pull);
} }
@ -89,38 +89,38 @@ void common_hal_digitalio_digitalinout_switch_to_output(
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
digitalio_digitalinout_obj_t *self) { digitalio_digitalinout_obj_t *self) {
return (LL_GPIO_GetPinMode(pin_port(pin->number), pin_mask(pin->number)) return (LL_GPIO_GetPinMode(pin_port(self->pin->number), pin_mask(self->pin->number))
== LL_GPIO_MODE_INPUT) ? DIRECTION_INPUT : DIRECTION_OUTPUT; == LL_GPIO_MODE_INPUT) ? DIRECTION_INPUT : DIRECTION_OUTPUT;
} }
void common_hal_digitalio_digitalinout_set_value( void common_hal_digitalio_digitalinout_set_value(
digitalio_digitalinout_obj_t *self, bool value) { digitalio_digitalinout_obj_t *self, bool value) {
HAL_GPIO_WritePin(pin_port(pin->number), 1 << self->pin->number, value); HAL_GPIO_WritePin(pin_port(self->pin->number), 1 << self->pin->number, value);
} }
bool common_hal_digitalio_digitalinout_get_value( bool common_hal_digitalio_digitalinout_get_value(
digitalio_digitalinout_obj_t *self) { digitalio_digitalinout_obj_t *self) {
return (LL_GPIO_GetPinMode(pin_port(pin->number), pin_mask(pin->number)) == LL_GPIO_MODE_INPUT) return (LL_GPIO_GetPinMode(pin_port(self->pin->number), pin_mask(self->pin->number)) == LL_GPIO_MODE_INPUT)
? HAL_GPIO_ReadPin(pin_port(pin->number), pin_mask(pin->number)) ? HAL_GPIO_ReadPin(pin_port(self->pin->number), pin_mask(self->pin->number))
: LL_GPIO_IsOutputPinSet(pin_port(pin->number), pin_mask(pin->number)); : LL_GPIO_IsOutputPinSet(pin_port(self->pin->number), pin_mask(self->pin->number));
} }
void common_hal_digitalio_digitalinout_set_drive_mode( void common_hal_digitalio_digitalinout_set_drive_mode(
digitalio_digitalinout_obj_t *self, digitalio_digitalinout_obj_t *self,
digitalio_drive_mode_t drive_mode) { digitalio_drive_mode_t drive_mode) {
GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = pin_mask(pin->number); 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_MODE_OUTPUT_OD : GPIO_MODE_OUTPUT_PP);
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(pin_port(pin->number), &GPIO_InitStruct); HAL_GPIO_Init(pin_port(self->pin->number), &GPIO_InitStruct);
} }
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
digitalio_digitalinout_obj_t *self) { digitalio_digitalinout_obj_t *self) {
return LL_GPIO_GetPinOutputType(pin_port(pin->number),pin_mask(pin->number)) return LL_GPIO_GetPinOutputType(pin_port(self->pin->number), pin_mask(self->pin->number))
== LL_GPIO_OUTPUT_OPENDRAIN ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL; == LL_GPIO_OUTPUT_OPENDRAIN ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL;
} }
@ -129,13 +129,13 @@ void common_hal_digitalio_digitalinout_set_pull(
switch (pull) { switch (pull) {
case PULL_UP: case PULL_UP:
LL_GPIO_SetPinPull(pin_port(pin->number),pin_mask(pin->number),LL_GPIO_PULL_UP); LL_GPIO_SetPinPull(pin_port(self->pin->number), pin_mask(self->pin->number),LL_GPIO_PULL_UP);
break; break;
case PULL_DOWN: case PULL_DOWN:
LL_GPIO_SetPinPull(pin_port(pin->number),pin_mask(pin->number),LL_GPIO_PULL_DOWN); LL_GPIO_SetPinPull(pin_port(self->pin->number), pin_mask(self->pin->number),LL_GPIO_PULL_DOWN);
break; break;
case PULL_NONE: case PULL_NONE:
LL_GPIO_SetPinPull(pin_port(pin->number),pin_mask(pin->number),LL_GPIO_PULL_NO); LL_GPIO_SetPinPull(pin_port(self->pin->number), pin_mask(self->pin->number),LL_GPIO_PULL_NO);
break; break;
default: default:
break; break;
@ -146,7 +146,7 @@ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
digitalio_digitalinout_obj_t *self) { digitalio_digitalinout_obj_t *self) {
switch (LL_GPIO_GetPinPull(pin_port(pin->number),pin_mask(pin->number))) { switch (LL_GPIO_GetPinPull(pin_port(self->pin->number), pin_mask(self->pin->number))) {
case LL_GPIO_PULL_UP: case LL_GPIO_PULL_UP:
return PULL_UP; return PULL_UP;
case LL_GPIO_PULL_DOWN: case LL_GPIO_PULL_DOWN:

View File

@ -66,7 +66,7 @@ extern const mp_obj_type_t mcu_pin_type;
#define PIN(p_port, p_number, p_adc) \ #define PIN(p_port, p_number, p_adc) \
{ \ { \
{ &mcu_pin_type }, \ { &mcu_pin_type }, \
.number = (((mask) << 4) | ((number) & 0x0F)), \ .number = (((p_port) << 4) | ((p_number) & 0x0F)), \
p_adc \ p_adc \
} }