@@ -65,9 +65,12 @@ STATIC const pyb_pin_obj_t pyb_pin_obj[] = {
6565 {{& pyb_pin_type }, 13 , 13 , PERIPHS_IO_MUX_MTCK_U , FUNC_GPIO13 },
6666 {{& pyb_pin_type }, 14 , 14 , PERIPHS_IO_MUX_MTMS_U , FUNC_GPIO14 },
6767 {{& pyb_pin_type }, 15 , 15 , PERIPHS_IO_MUX_MTDO_U , FUNC_GPIO15 },
68+ // GPIO16 is special, belongs to different register set, and
69+ // otherwise handled specially.
70+ {{& pyb_pin_type }, 16 , 16 , -1 , -1 },
6871};
6972
70- STATIC uint8_t pin_mode [16 ];
73+ STATIC uint8_t pin_mode [16 + 1 ];
7174
7275uint mp_obj_get_pin (mp_obj_t pin_in ) {
7376 if (mp_obj_get_type (pin_in ) != & pyb_pin_type ) {
@@ -78,10 +81,22 @@ uint mp_obj_get_pin(mp_obj_t pin_in) {
7881}
7982
8083int pin_get (uint pin ) {
84+ if (pin == 16 ) {
85+ return READ_PERI_REG (RTC_GPIO_IN_DATA ) & 1 ;
86+ }
8187 return GPIO_INPUT_GET (pin );
8288}
8389
8490void pin_set (uint pin , int value ) {
91+ if (pin == 16 ) {
92+ int out_en = (pin_mode [pin ] == GPIO_MODE_OUTPUT );
93+ WRITE_PERI_REG (PAD_XPD_DCDC_CONF , (READ_PERI_REG (PAD_XPD_DCDC_CONF ) & 0xffffffbc ) | 1 );
94+ WRITE_PERI_REG (RTC_GPIO_CONF , READ_PERI_REG (RTC_GPIO_CONF ) & ~1 );
95+ WRITE_PERI_REG (RTC_GPIO_ENABLE , (READ_PERI_REG (RTC_GPIO_ENABLE ) & ~1 ) | out_en );
96+ WRITE_PERI_REG (RTC_GPIO_OUT , (READ_PERI_REG (RTC_GPIO_OUT ) & ~1 ) | value );
97+ return ;
98+ }
99+
85100 uint32_t enable = 0 ;
86101 uint32_t disable = 0 ;
87102 switch (pin_mode [pin ]) {
@@ -155,23 +170,27 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, mp_uint_t n_args, c
155170 pin_mode [self -> phys_port ] = mode ;
156171
157172 // configure the GPIO as requested
158- PIN_FUNC_SELECT (self -> periph , self -> func );
159- #if 0
160- // Removed in SDK 1.1.0
161- if ((pull & GPIO_PULL_DOWN ) == 0 ) {
162- PIN_PULLDWN_DIS (self -> periph );
163- }
164- #endif
165- if ((pull & GPIO_PULL_UP ) == 0 ) {
166- PIN_PULLUP_DIS (self -> periph );
167- }
168- #if 0
169- if ((pull & GPIO_PULL_DOWN ) != 0 ) {
170- PIN_PULLDWN_EN (self -> periph );
171- }
172- #endif
173- if ((pull & GPIO_PULL_UP ) != 0 ) {
174- PIN_PULLUP_EN (self -> periph );
173+ if (self -> phys_port == 16 ) {
174+ // TODO: Set pull up/pull down
175+ } else {
176+ PIN_FUNC_SELECT (self -> periph , self -> func );
177+ #if 0
178+ // Removed in SDK 1.1.0
179+ if ((pull & GPIO_PULL_DOWN ) == 0 ) {
180+ PIN_PULLDWN_DIS (self -> periph );
181+ }
182+ #endif
183+ if ((pull & GPIO_PULL_UP ) == 0 ) {
184+ PIN_PULLUP_DIS (self -> periph );
185+ }
186+ #if 0
187+ if ((pull & GPIO_PULL_DOWN ) != 0 ) {
188+ PIN_PULLDWN_EN (self -> periph );
189+ }
190+ #endif
191+ if ((pull & GPIO_PULL_UP ) != 0 ) {
192+ PIN_PULLUP_EN (self -> periph );
193+ }
175194 }
176195
177196 pin_set (self -> phys_port , value );
0 commit comments