msp430fxyz: Disable GPIO ISRs when periph_gpio_irq is not selected
This commit is contained in:
parent
ace717ee27
commit
efc5f2a95c
@ -33,12 +33,6 @@
|
||||
*/
|
||||
#define PINS_PER_PORT (8U)
|
||||
|
||||
/**
|
||||
* @brief Interrupt context for each interrupt line
|
||||
*/
|
||||
static gpio_isr_ctx_t isr_ctx[ISR_NUMOF];
|
||||
|
||||
|
||||
static msp_port_t *_port(gpio_t pin)
|
||||
{
|
||||
switch (pin >> 8) {
|
||||
@ -59,6 +53,11 @@ static msp_port_t *_port(gpio_t pin)
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint8_t _pin(gpio_t pin)
|
||||
{
|
||||
return (uint8_t)(pin & 0xff);
|
||||
}
|
||||
|
||||
static inline msp_port_isr_t *_isr_port(gpio_t pin)
|
||||
{
|
||||
msp_port_t *p = _port(pin);
|
||||
@ -68,17 +67,6 @@ static inline msp_port_isr_t *_isr_port(gpio_t pin)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline uint8_t _pin(gpio_t pin)
|
||||
{
|
||||
return (uint8_t)(pin & 0xff);
|
||||
}
|
||||
|
||||
static int _ctx(gpio_t pin)
|
||||
{
|
||||
int i = bitarithm_lsb(_pin(pin));
|
||||
return (_port(pin) == PORT_1) ? i : (i + 8);
|
||||
}
|
||||
|
||||
int gpio_init(gpio_t pin, gpio_mode_t mode)
|
||||
{
|
||||
msp_port_t *port = _port(pin);
|
||||
@ -99,34 +87,6 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
|
||||
gpio_cb_t cb, void *arg)
|
||||
{
|
||||
msp_port_isr_t *port = _isr_port(pin);
|
||||
|
||||
/* check if port, pull resistor and flank configuration are valid */
|
||||
if ((port == NULL) || (flank == GPIO_BOTH)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* disable any activated interrupt */
|
||||
port->IE &= ~(_pin(pin));
|
||||
/* configure as input */
|
||||
if (gpio_init(pin, mode) < 0) {
|
||||
return -1;
|
||||
}
|
||||
/* save ISR context */
|
||||
isr_ctx[_ctx(pin)].cb = cb;
|
||||
isr_ctx[_ctx(pin)].arg = arg;
|
||||
/* configure flank */
|
||||
port->IES &= ~(_pin(pin));
|
||||
port->IES |= (flank & _pin(pin));
|
||||
/* clear pending interrupts and enable the IRQ */
|
||||
port->IFG &= ~(_pin(pin));
|
||||
gpio_irq_enable(pin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gpio_periph_mode(gpio_t pin, bool enable)
|
||||
{
|
||||
REG8 *sel;
|
||||
@ -151,22 +111,6 @@ void gpio_periph_mode(gpio_t pin, bool enable)
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_irq_enable(gpio_t pin)
|
||||
{
|
||||
msp_port_isr_t *port = _isr_port(pin);
|
||||
if (port) {
|
||||
port->IE |= _pin(pin);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_irq_disable(gpio_t pin)
|
||||
{
|
||||
msp_port_isr_t *port = _isr_port(pin);
|
||||
if (port) {
|
||||
port->IE &= ~(_pin(pin));
|
||||
}
|
||||
}
|
||||
|
||||
int gpio_read(gpio_t pin)
|
||||
{
|
||||
msp_port_t *port = _port(pin);
|
||||
@ -203,6 +147,62 @@ void gpio_write(gpio_t pin, int value)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MODULE_PERIPH_GPIO_IRQ
|
||||
/**
|
||||
* @brief Interrupt context for each interrupt line
|
||||
*/
|
||||
static gpio_isr_ctx_t isr_ctx[ISR_NUMOF];
|
||||
|
||||
static int _ctx(gpio_t pin)
|
||||
{
|
||||
int i = bitarithm_lsb(_pin(pin));
|
||||
return (_port(pin) == PORT_1) ? i : (i + 8);
|
||||
}
|
||||
|
||||
int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
|
||||
gpio_cb_t cb, void *arg)
|
||||
{
|
||||
msp_port_isr_t *port = _isr_port(pin);
|
||||
|
||||
/* check if port, pull resistor and flank configuration are valid */
|
||||
if ((port == NULL) || (flank == GPIO_BOTH)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* disable any activated interrupt */
|
||||
port->IE &= ~(_pin(pin));
|
||||
/* configure as input */
|
||||
if (gpio_init(pin, mode) < 0) {
|
||||
return -1;
|
||||
}
|
||||
/* save ISR context */
|
||||
isr_ctx[_ctx(pin)].cb = cb;
|
||||
isr_ctx[_ctx(pin)].arg = arg;
|
||||
/* configure flank */
|
||||
port->IES &= ~(_pin(pin));
|
||||
port->IES |= (flank & _pin(pin));
|
||||
/* clear pending interrupts and enable the IRQ */
|
||||
port->IFG &= ~(_pin(pin));
|
||||
gpio_irq_enable(pin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gpio_irq_enable(gpio_t pin)
|
||||
{
|
||||
msp_port_isr_t *port = _isr_port(pin);
|
||||
if (port) {
|
||||
port->IE |= _pin(pin);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_irq_disable(gpio_t pin)
|
||||
{
|
||||
msp_port_isr_t *port = _isr_port(pin);
|
||||
if (port) {
|
||||
port->IE &= ~(_pin(pin));
|
||||
}
|
||||
}
|
||||
|
||||
static inline void isr_handler(msp_port_isr_t *port, int ctx)
|
||||
{
|
||||
for (unsigned i = 0; i < PINS_PER_PORT; i++) {
|
||||
@ -226,3 +226,4 @@ ISR(PORT2_VECTOR, isr_port2)
|
||||
isr_handler((msp_port_isr_t *)PORT_2, 8);
|
||||
__exit_isr();
|
||||
}
|
||||
#endif /* MODULE_PERIPH_GPIO_IRQ */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user