Update digitalio api for other ports

This commit is contained in:
Scott Shawcroft 2020-05-20 09:23:42 -07:00
parent 0543a64dc1
commit fd0420d432
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E
6 changed files with 25 additions and 13 deletions

View File

@ -73,7 +73,7 @@ void common_hal_digitalio_digitalinout_switch_to_input(
common_hal_digitalio_digitalinout_set_pull(self, pull);
}
void common_hal_digitalio_digitalinout_switch_to_output(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
digitalio_digitalinout_obj_t* self, bool value,
digitalio_drive_mode_t drive_mode) {
const uint8_t pin = self->pin->number;
@ -86,6 +86,7 @@ void common_hal_digitalio_digitalinout_switch_to_output(
// Direction is set in set_value. We don't need to do it here.
common_hal_digitalio_digitalinout_set_value(self, value);
return DIGITALINOUT_OK;
}
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
@ -128,7 +129,7 @@ bool common_hal_digitalio_digitalinout_get_value(
}
}
void common_hal_digitalio_digitalinout_set_drive_mode(
digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
digitalio_digitalinout_obj_t* self,
digitalio_drive_mode_t drive_mode) {
bool value = common_hal_digitalio_digitalinout_get_value(self);
@ -138,6 +139,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
if (value) {
common_hal_digitalio_digitalinout_set_value(self, value);
}
return DIGITALINOUT_OK;
}
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(

View File

@ -70,7 +70,7 @@ void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_ob
board_gpio_config(self->pin->number, 0, true, true, pull);
}
void common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_obj_t *self, bool value, digitalio_drive_mode_t drive_mode) {
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_obj_t *self, bool value, digitalio_drive_mode_t drive_mode) {
self->input = false;
self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN;
board_gpio_write(self->pin->number, -1);
@ -80,6 +80,7 @@ void common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_o
board_gpio_write(self->pin->number, 0);
}
common_hal_digitalio_digitalinout_set_value(self, value);
return DIGITALINOUT_OK;
}
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(digitalio_digitalinout_obj_t *self) {
@ -104,7 +105,7 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s
return board_gpio_read(self->pin->number);
}
void common_hal_digitalio_digitalinout_set_drive_mode(digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) {
digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) {
if (drive_mode == DRIVE_MODE_PUSH_PULL) {
board_gpio_write(self->pin->number, -1);
board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT);
@ -115,6 +116,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode(digitalio_digitalinout_obj
board_gpio_write(self->pin->number, 0);
self->open_drain = true;
}
return DIGITALINOUT_OK;
}
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitalio_digitalinout_obj_t *self) {

View File

@ -64,12 +64,13 @@ void common_hal_digitalio_digitalinout_switch_to_input(
touch_oe_write(touch_oe_read() & ~(1 << self->pin->number));
}
void common_hal_digitalio_digitalinout_switch_to_output(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
digitalio_digitalinout_obj_t *self, bool value,
digitalio_drive_mode_t drive_mode) {
(void)drive_mode;
common_hal_digitalio_digitalinout_set_value(self, value);
touch_oe_write(touch_oe_read() | (1 << self->pin->number));
return DIGITALINOUT_OK;
}
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
@ -92,11 +93,12 @@ bool common_hal_digitalio_digitalinout_get_value(
return !!(touch_i_read() & (1 << self->pin->number));
}
void common_hal_digitalio_digitalinout_set_drive_mode(
digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
digitalio_digitalinout_obj_t *self,
digitalio_drive_mode_t drive_mode) {
(void)self;
(void)drive_mode;
return DIGITALINOUT_OK;
}
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(

View File

@ -97,7 +97,7 @@ void common_hal_digitalio_digitalinout_switch_to_input(
common_hal_digitalio_digitalinout_set_pull(self, pull);
}
void common_hal_digitalio_digitalinout_switch_to_output(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
digitalio_digitalinout_obj_t* self, bool value,
digitalio_drive_mode_t drive_mode) {
self->output = true;
@ -108,6 +108,7 @@ void common_hal_digitalio_digitalinout_switch_to_output(
const gpio_pin_config_t config = { kGPIO_DigitalOutput, value, kGPIO_NoIntmode };
GPIO_PinInit(self->pin->gpio, self->pin->number, &config);
return DIGITALINOUT_OK;
}
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
@ -125,7 +126,7 @@ bool common_hal_digitalio_digitalinout_get_value(
return GPIO_PinRead(self->pin->gpio, self->pin->number);
}
void common_hal_digitalio_digitalinout_set_drive_mode(
digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
digitalio_digitalinout_obj_t* self,
digitalio_drive_mode_t drive_mode) {
bool value = common_hal_digitalio_digitalinout_get_value(self);
@ -138,6 +139,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
if (value) {
common_hal_digitalio_digitalinout_set_value(self, value);
}
return DIGITALINOUT_OK;
}
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(

View File

@ -65,12 +65,13 @@ void common_hal_digitalio_digitalinout_switch_to_input(
common_hal_digitalio_digitalinout_set_pull(self, pull);
}
void common_hal_digitalio_digitalinout_switch_to_output(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
digitalio_digitalinout_obj_t *self, bool value,
digitalio_drive_mode_t drive_mode) {
common_hal_digitalio_digitalinout_set_drive_mode(self, drive_mode);
common_hal_digitalio_digitalinout_set_value(self, value);
return DIGITALINOUT_OK;
}
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
@ -92,7 +93,7 @@ bool common_hal_digitalio_digitalinout_get_value(
: nrf_gpio_pin_out_read(self->pin->number);
}
void common_hal_digitalio_digitalinout_set_drive_mode(
digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
digitalio_digitalinout_obj_t *self,
digitalio_drive_mode_t drive_mode) {
nrf_gpio_cfg(self->pin->number,
@ -101,6 +102,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
NRF_GPIO_PIN_NOPULL,
drive_mode == DRIVE_MODE_OPEN_DRAIN ? NRF_GPIO_PIN_H0D1 : NRF_GPIO_PIN_H0H1,
NRF_GPIO_PIN_NOSENSE);
return DIGITALINOUT_OK;
}
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(

View File

@ -29,7 +29,7 @@
#include "py/runtime.h"
#include "supervisor/shared/translate.h"
// The HAL is sparse on obtaining register information, so we use the LLs here.
// The HAL is sparse on obtaining register information, so we use the LLs here.
#if (CPY_STM32H7)
#include "stm32h7xx_ll_gpio.h"
#elif (CPY_STM32F7)
@ -85,12 +85,13 @@ void common_hal_digitalio_digitalinout_switch_to_input(
common_hal_digitalio_digitalinout_set_pull(self, pull);
}
void common_hal_digitalio_digitalinout_switch_to_output(
digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
digitalio_digitalinout_obj_t *self, bool value,
digitalio_drive_mode_t drive_mode) {
common_hal_digitalio_digitalinout_set_drive_mode(self, drive_mode);
common_hal_digitalio_digitalinout_set_value(self, value);
return DIGITALINOUT_OK;
}
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
@ -112,7 +113,7 @@ bool common_hal_digitalio_digitalinout_get_value(
: LL_GPIO_IsOutputPinSet(pin_port(self->pin->port), pin_mask(self->pin->number));
}
void common_hal_digitalio_digitalinout_set_drive_mode(
digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
digitalio_digitalinout_obj_t *self,
digitalio_drive_mode_t drive_mode) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
@ -122,6 +123,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
HAL_GPIO_Init(pin_port(self->pin->port), &GPIO_InitStruct);
return DIGITALINOUT_OK;
}
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(