still working on GPIO
This commit is contained in:
parent
780c41b47c
commit
7103c3e0b3
|
@ -60,9 +60,9 @@ typedef struct {
|
|||
REG8 padding1;
|
||||
REG8 DIR; /**< pin direction */
|
||||
REG8 padding2;
|
||||
REG8 PULL; /**< resistor pull config */
|
||||
REG8 REN; /**< resistor pull config */
|
||||
REG8 padding3;
|
||||
REG8 STRENGTH; /**< resistor drive strength */
|
||||
REG8 DS; /**< resistor drive strength */
|
||||
REG8 padding4;
|
||||
REG8 SEL; /**< alternative function select */
|
||||
} msp_port_t;
|
||||
|
@ -77,9 +77,9 @@ typedef struct {
|
|||
REG8 padding1;
|
||||
REG8 DIR; /**< pin direction */
|
||||
REG8 padding2;
|
||||
REG8 PULL; /**< resistor pull config */
|
||||
REG8 REN; /**< resistor pull config */
|
||||
REG8 padding3;
|
||||
REG8 STRENGTH; /**< resistor drive strength */
|
||||
REG8 DS; /**< resistor drive strength */
|
||||
REG8 padding4;
|
||||
REG8 SEL; /**< alternative function select */
|
||||
REG8 padding5[14];
|
||||
|
|
|
@ -88,14 +88,28 @@ int gpio_init(gpio_t pin, gpio_dir_t dir, gpio_pp_t pullup)
|
|||
{
|
||||
msp_port_t *port = _port(pin);
|
||||
/* check if port is valid and pull resistor are valid */
|
||||
if ((port == NULL) || (pullup != GPIO_NOPULL)) {
|
||||
if (port == NULL ||
|
||||
(dir == GPIO_DIR_OUT && pullup != GPIO_NOPULL)) {
|
||||
return -1;
|
||||
}
|
||||
uint8_t pin_bit = _pin(pin);
|
||||
/* set pin direction */
|
||||
port->DIR &= ~(_pin(pin));
|
||||
port->DIR |= (dir & _pin(pin));
|
||||
/* reset output value */
|
||||
port->OD &= ~(_pin(pin));
|
||||
port->DIR &= ~(pin_bit);
|
||||
port->DIR |= (dir & pin_bit);
|
||||
|
||||
if (dir == GPIO_DIR_OUT && pullup != GPIO_NOPULL){
|
||||
port->REN |= 0xff & pin_bit;
|
||||
if (pullup == GPIO_PULLUP){
|
||||
port->OD |= 0xff & pin_bit;
|
||||
} else { /* GPIO_PULLDOWN */
|
||||
port->OD &= ~(pin_bit);
|
||||
}
|
||||
} else {
|
||||
port->REN &= ~(pin_bit);
|
||||
/* reset output value */
|
||||
port->OD &= ~(pin_bit);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue