33
33
34
34
void common_hal_digitalio_digitalinout_never_reset (
35
35
digitalio_digitalinout_obj_t * self ) {
36
- never_reset_pin_number (self -> pin -> port_number , self -> pin -> number );
36
+ never_reset_pin_number (self -> pin -> port , self -> pin -> number );
37
37
}
38
38
39
39
digitalinout_result_t common_hal_digitalio_digitalinout_construct (
@@ -43,11 +43,11 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
43
43
self -> pin = pin ;
44
44
45
45
GPIO_InitTypeDef GPIO_InitStruct = {0 };
46
- GPIO_InitStruct .Pin = ( 1 << pin -> number );
46
+ GPIO_InitStruct .Pin = pin_mask ( self -> pin -> number );
47
47
GPIO_InitStruct .Mode = GPIO_MODE_INPUT ;
48
48
GPIO_InitStruct .Pull = GPIO_NOPULL ;
49
49
GPIO_InitStruct .Speed = GPIO_SPEED_FREQ_LOW ;
50
- HAL_GPIO_Init (pin -> port , & GPIO_InitStruct );
50
+ HAL_GPIO_Init (pin_port ( self -> pin -> number ) , & GPIO_InitStruct );
51
51
52
52
return DIGITALINOUT_OK ;
53
53
}
@@ -61,19 +61,19 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
61
61
return ;
62
62
}
63
63
64
- reset_pin_number (self -> pin -> port_number , self -> pin -> number );
64
+ reset_pin_number (self -> pin -> port , self -> pin -> number );
65
65
self -> pin = mp_const_none ;
66
66
}
67
67
68
68
void common_hal_digitalio_digitalinout_switch_to_input (
69
69
digitalio_digitalinout_obj_t * self , digitalio_pull_t pull ) {
70
70
71
71
GPIO_InitTypeDef GPIO_InitStruct = {0 };
72
- GPIO_InitStruct .Pin = ( 1 << self -> pin -> number );
72
+ GPIO_InitStruct .Pin = pin_mask ( self -> pin -> number );
73
73
GPIO_InitStruct .Mode = GPIO_MODE_INPUT ;
74
74
GPIO_InitStruct .Pull = GPIO_NOPULL ;
75
75
GPIO_InitStruct .Speed = GPIO_SPEED_FREQ_LOW ;
76
- HAL_GPIO_Init (self -> pin -> port , & GPIO_InitStruct );
76
+ HAL_GPIO_Init (pin_port ( self -> pin -> number ) , & GPIO_InitStruct );
77
77
78
78
common_hal_digitalio_digitalinout_set_pull (self , pull );
79
79
}
@@ -89,38 +89,38 @@ void common_hal_digitalio_digitalinout_switch_to_output(
89
89
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction (
90
90
digitalio_digitalinout_obj_t * self ) {
91
91
92
- return (LL_GPIO_GetPinMode (self -> pin -> port , ( 1 << self -> pin -> number ))
92
+ return (LL_GPIO_GetPinMode (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number ))
93
93
== LL_GPIO_MODE_INPUT ) ? DIRECTION_INPUT : DIRECTION_OUTPUT ;
94
94
}
95
95
96
96
void common_hal_digitalio_digitalinout_set_value (
97
97
digitalio_digitalinout_obj_t * self , bool value ) {
98
- HAL_GPIO_WritePin (self -> pin -> port , 1 << self -> pin -> number , value );
98
+ HAL_GPIO_WritePin (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number ) , value );
99
99
}
100
100
101
101
bool common_hal_digitalio_digitalinout_get_value (
102
102
digitalio_digitalinout_obj_t * self ) {
103
- return (LL_GPIO_GetPinMode (self -> pin -> port , ( 1 << self -> pin -> number )) == LL_GPIO_MODE_INPUT )
104
- ? HAL_GPIO_ReadPin (self -> pin -> port , ( 1 << self -> pin -> number ))
105
- : LL_GPIO_IsOutputPinSet (self -> pin -> port , ( 1 << self -> pin -> number ));
103
+ return (LL_GPIO_GetPinMode (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number )) == LL_GPIO_MODE_INPUT )
104
+ ? HAL_GPIO_ReadPin (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number ))
105
+ : LL_GPIO_IsOutputPinSet (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number ));
106
106
}
107
107
108
108
void common_hal_digitalio_digitalinout_set_drive_mode (
109
109
digitalio_digitalinout_obj_t * self ,
110
110
digitalio_drive_mode_t drive_mode ) {
111
111
GPIO_InitTypeDef GPIO_InitStruct = {0 };
112
- GPIO_InitStruct .Pin = ( 1 << self -> pin -> number );
112
+ GPIO_InitStruct .Pin = pin_mask ( self -> pin -> number );
113
113
GPIO_InitStruct .Mode = (drive_mode == DRIVE_MODE_OPEN_DRAIN ?
114
114
GPIO_MODE_OUTPUT_OD : GPIO_MODE_OUTPUT_PP );
115
115
GPIO_InitStruct .Pull = GPIO_NOPULL ;
116
116
GPIO_InitStruct .Speed = GPIO_SPEED_FREQ_LOW ;
117
- HAL_GPIO_Init (self -> pin -> port , & GPIO_InitStruct );
117
+ HAL_GPIO_Init (pin_port ( self -> pin -> number ) , & GPIO_InitStruct );
118
118
}
119
119
120
120
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode (
121
121
digitalio_digitalinout_obj_t * self ) {
122
122
123
- return LL_GPIO_GetPinOutputType (self -> pin -> port , ( 1 << self -> pin -> port_number ))
123
+ return LL_GPIO_GetPinOutputType (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number ))
124
124
== LL_GPIO_OUTPUT_OPENDRAIN ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL ;
125
125
}
126
126
@@ -129,13 +129,13 @@ void common_hal_digitalio_digitalinout_set_pull(
129
129
130
130
switch (pull ) {
131
131
case PULL_UP :
132
- LL_GPIO_SetPinPull (self -> pin -> port ,( 1 << self -> pin -> number ),LL_GPIO_PULL_UP );
132
+ LL_GPIO_SetPinPull (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number ),LL_GPIO_PULL_UP );
133
133
break ;
134
134
case PULL_DOWN :
135
- LL_GPIO_SetPinPull (self -> pin -> port ,( 1 << self -> pin -> number ),LL_GPIO_PULL_DOWN );
135
+ LL_GPIO_SetPinPull (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number ),LL_GPIO_PULL_DOWN );
136
136
break ;
137
137
case PULL_NONE :
138
- LL_GPIO_SetPinPull (self -> pin -> port ,( 1 << self -> pin -> number ),LL_GPIO_PULL_NO );
138
+ LL_GPIO_SetPinPull (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number ),LL_GPIO_PULL_NO );
139
139
break ;
140
140
default :
141
141
break ;
@@ -146,7 +146,7 @@ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
146
146
digitalio_digitalinout_obj_t * self ) {
147
147
148
148
149
- switch (LL_GPIO_GetPinPull (self -> pin -> port ,( 1 << self -> pin -> number ))) {
149
+ switch (LL_GPIO_GetPinPull (pin_port ( self -> pin -> number ), pin_mask ( self -> pin -> number ))) {
150
150
case LL_GPIO_PULL_UP :
151
151
return PULL_UP ;
152
152
case LL_GPIO_PULL_DOWN :
0 commit comments