Fix out of date HAL inputs in DigitalIO

This commit is contained in:
Hierophect 2019-09-17 16:15:39 -04:00
parent 7c713b9e3b
commit 71531dd4d1
2 changed files with 13 additions and 14 deletions

View File

@ -119,7 +119,6 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
HAL_ADC_Start(&AdcHandle); HAL_ADC_Start(&AdcHandle);
HAL_ADC_PollForConversion(&AdcHandle,1); //doesn't work as HAL_GetTick always returns 0 HAL_ADC_PollForConversion(&AdcHandle,1); //doesn't work as HAL_GetTick always returns 0
//uint32_t tickstart = ticks_ms;
uint16_t uhADCxConvertedData = (uint16_t)HAL_ADC_GetValue(&AdcHandle); uint16_t uhADCxConvertedData = (uint16_t)HAL_ADC_GetValue(&AdcHandle);
HAL_ADC_Stop(&AdcHandle); HAL_ADC_Stop(&AdcHandle);

View File

@ -48,7 +48,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
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(self->pin->number), &GPIO_InitStruct); HAL_GPIO_Init(pin_port(self->pin->port), &GPIO_InitStruct);
return DIGITALINOUT_OK; return DIGITALINOUT_OK;
} }
@ -74,7 +74,7 @@ void common_hal_digitalio_digitalinout_switch_to_input(
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(self->pin->number), &GPIO_InitStruct); HAL_GPIO_Init(pin_port(self->pin->port), &GPIO_InitStruct);
common_hal_digitalio_digitalinout_set_pull(self, pull); common_hal_digitalio_digitalinout_set_pull(self, pull);
} }
@ -90,20 +90,20 @@ 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(self->pin->number), 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; == 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(self->pin->number), pin_mask(self->pin->number), value); HAL_GPIO_WritePin(pin_port(self->pin->port), pin_mask(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(self->pin->number), pin_mask(self->pin->number)) == LL_GPIO_MODE_INPUT) return (LL_GPIO_GetPinMode(pin_port(self->pin->port), pin_mask(self->pin->number)) == LL_GPIO_MODE_INPUT)
? HAL_GPIO_ReadPin(pin_port(self->pin->number), pin_mask(self->pin->number)) ? HAL_GPIO_ReadPin(pin_port(self->pin->port), pin_mask(self->pin->number))
: LL_GPIO_IsOutputPinSet(pin_port(self->pin->number), pin_mask(self->pin->number)); : LL_GPIO_IsOutputPinSet(pin_port(self->pin->port), pin_mask(self->pin->number));
} }
void common_hal_digitalio_digitalinout_set_drive_mode( void common_hal_digitalio_digitalinout_set_drive_mode(
@ -115,13 +115,13 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
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(self->pin->number), &GPIO_InitStruct); HAL_GPIO_Init(pin_port(self->pin->port), &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(self->pin->number), 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; == LL_GPIO_OUTPUT_OPENDRAIN ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL;
} }
@ -130,13 +130,13 @@ void common_hal_digitalio_digitalinout_set_pull(
switch (pull) { switch (pull) {
case PULL_UP: case PULL_UP:
LL_GPIO_SetPinPull(pin_port(self->pin->number), pin_mask(self->pin->number),LL_GPIO_PULL_UP); LL_GPIO_SetPinPull(pin_port(self->pin->port), pin_mask(self->pin->number),LL_GPIO_PULL_UP);
break; break;
case PULL_DOWN: case PULL_DOWN:
LL_GPIO_SetPinPull(pin_port(self->pin->number), pin_mask(self->pin->number),LL_GPIO_PULL_DOWN); LL_GPIO_SetPinPull(pin_port(self->pin->port), pin_mask(self->pin->number),LL_GPIO_PULL_DOWN);
break; break;
case PULL_NONE: case PULL_NONE:
LL_GPIO_SetPinPull(pin_port(self->pin->number), pin_mask(self->pin->number),LL_GPIO_PULL_NO); LL_GPIO_SetPinPull(pin_port(self->pin->port), pin_mask(self->pin->number),LL_GPIO_PULL_NO);
break; break;
default: default:
break; break;
@ -147,7 +147,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(self->pin->number), pin_mask(self->pin->number))) { switch (LL_GPIO_GetPinPull(pin_port(self->pin->port), 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: