diff options
| author | Dave Hylands | 2014-07-22 07:57:36 -0700 |
|---|---|---|
| committer | Dave Hylands | 2014-08-07 23:15:41 -0700 |
| commit | 6f418fc1b068c1a41113bb2b019a5803765e1deb (patch) | |
| tree | 79477835459eb424012f58d77a150bdf9a80eed5 /teensy/hal_gpio.c | |
| parent | 3ef911345c94a6d612ab50c1e912e81cb2cc3f71 (diff) | |
Add support for selecting pin alternate functions from python.
Converts generted pins to use qstrs instead of string pointers.
This patch also adds the following functions:
pyb.Pin.names()
pyb.Pin.af_list()
pyb.Pin.gpio()
dir(pyb.Pin.board) and dir(pyb.Pin.cpu) also produce useful results.
pyb.Pin now takes kw args.
pyb.Pin.__str__ now prints more useful information about the pin
configuration.
I found the following functions in my boot.py to be useful:
```python
def pins():
for pin_name in dir(pyb.Pin.board):
pin = pyb.Pin(pin_name)
print('{:10s} {:s}'.format(pin_name, str(pin)))
def af():
for pin_name in dir(pyb.Pin.board):
pin = pyb.Pin(pin_name)
print('{:10s} {:s}'.format(pin_name, str(pin.af_list())))
```
Diffstat (limited to 'teensy/hal_gpio.c')
| -rw-r--r-- | teensy/hal_gpio.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/teensy/hal_gpio.c b/teensy/hal_gpio.c index 0811f76fd..218560e29 100644 --- a/teensy/hal_gpio.c +++ b/teensy/hal_gpio.c @@ -25,12 +25,18 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init) if ((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD)) { /* Check the Alternate function parameter */ assert_param(IS_GPIO_AF(GPIO_Init->Alternate)); - /* Configure Alternate function mapped with the current IO */ - - *port_pcr &= ~PORT_PCR_MUX_MASK; - *port_pcr |= PORT_PCR_MUX(GPIO_Init->Alternate); + } + else if (GPIO_Init->Mode == GPIO_MODE_ANALOG) { + GPIO_Init->Alternate = 0; + } + else { + GPIO_Init->Alternate = 1; } + /* Configure Alternate function mapped with the current IO */ + *port_pcr &= ~PORT_PCR_MUX_MASK; + *port_pcr |= PORT_PCR_MUX(GPIO_Init->Alternate); + /* Configure IO Direction mode (Input, Output, Alternate or Analog) */ if (GPIO_Init->Mode == GPIO_MODE_INPUT || GPIO_Init->Mode == GPIO_MODE_ANALOG) { GPIOx->PDDR &= ~bitmask; @@ -112,4 +118,3 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init) #endif } } - |
