Skip to content

Commit

Permalink
Merge branch 'cc2538-gpio' into qidevices
Browse files Browse the repository at this point in the history
Signed-off-by: Benoît Thébaudeau <[email protected]>
  • Loading branch information
bthebaudeau committed Nov 15, 2013
2 parents e6352ad + 6800508 commit ab7067c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 30 deletions.
8 changes: 4 additions & 4 deletions cpu/cc2538/dev/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ gpio_port_a_isr()

notify(REG(GPIO_A_BASE | GPIO_MIS), GPIO_A_NUM);

REG(GPIO_A_BASE | GPIO_IC) = 0xFF;
GPIO_CLEAR_INTERRUPT(GPIO_A_BASE, 0xFF);

ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Expand All @@ -104,7 +104,7 @@ gpio_port_b_isr()

notify(REG(GPIO_B_BASE | GPIO_MIS), GPIO_B_NUM);

REG(GPIO_B_BASE | GPIO_IC) = 0xFF;
GPIO_CLEAR_INTERRUPT(GPIO_B_BASE, 0xFF);

ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Expand All @@ -119,7 +119,7 @@ gpio_port_c_isr()

notify(REG(GPIO_C_BASE | GPIO_MIS), GPIO_C_NUM);

REG(GPIO_C_BASE | GPIO_IC) = 0xFF;
GPIO_CLEAR_INTERRUPT(GPIO_C_BASE, 0xFF);

ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Expand All @@ -134,7 +134,7 @@ gpio_port_d_isr()

notify(REG(GPIO_D_BASE | GPIO_MIS), GPIO_D_NUM);

REG(GPIO_D_BASE | GPIO_IC) = 0xFF;
GPIO_CLEAR_INTERRUPT(GPIO_D_BASE, 0xFF);

ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Expand Down
54 changes: 38 additions & 16 deletions cpu/cc2538/dev/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,122 +91,144 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_DIR) &= ~PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_DIR) &= ~(PIN_MASK); } while(0)

/** \brief Set pins with PIN_MASK of port with PORT_BASE to output.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_DIR) |= PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_DIR) |= (PIN_MASK); } while(0)

/** \brief Set pins with PIN_MASK of port with PORT_BASE high.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_SET_PIN(PORT_BASE, PIN_MASK) \
do { REG((PORT_BASE | GPIO_DATA) + (PIN_MASK << 2)) = 0xFF; } while(0)
do { REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2)) = 0xFF; } while(0)

/** \brief Set pins with PIN_MASK of port with PORT_BASE low.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_CLR_PIN(PORT_BASE, PIN_MASK) \
do { REG((PORT_BASE | GPIO_DATA) + (PIN_MASK << 2)) = 0x00; } while(0)
do { REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2)) = 0x00; } while(0)

/** \brief Set pins with PIN_MASK of port with PORT_BASE to value.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_WRITE_PIN(PORT_BASE, PIN_MASK, value) \
do { REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2)) = (value); } while(0)

/** \brief Read pins with PIN_MASK of port with PORT_BASE.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_READ_PIN(PORT_BASE, PIN_MASK) \
REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2))

/** \brief Set pins with PIN_MASK of port with PORT_BASE to detect edge.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_DETECT_EDGE(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_IS) &= ~PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_IS) &= ~(PIN_MASK); } while(0)

/** \brief Set pins with PIN_MASK of port with PORT_BASE to detect level.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_DETECT_LEVEL(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_IS) |= PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_IS) |= (PIN_MASK); } while(0)

/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
* interrupt on both edges.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_TRIGGER_BOTH_EDGES(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_IBE) |= PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_IBE) |= (PIN_MASK); } while(0)

/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
* interrupt on single edge (controlled by GPIO_IEV).
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_TRIGGER_SINGLE_EDGE(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_IBE) &= ~PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_IBE) &= ~(PIN_MASK); } while(0)

/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
* interrupt on rising edge.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_DETECT_RISING(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_IEV) |= PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_IEV) |= (PIN_MASK); } while(0)

/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
* interrupt on falling edge.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_DETECT_FALLING(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_IEV) &= ~PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_IEV) &= ~(PIN_MASK); } while(0)

/** \brief Enable interrupt triggering for pins with PIN_MASK of port with
* PORT_BASE.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_ENABLE_INTERRUPT(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_IE) |= PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_IE) |= (PIN_MASK); } while(0)

/** \brief Disable interrupt triggering for pins with PIN_MASK of port with
* PORT_BASE.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_DISABLE_INTERRUPT(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_IE) &= ~PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_IE) &= ~(PIN_MASK); } while(0)

/** \brief Clear interrupt triggering for pins with PIN_MASK of port with
* PORT_BASE.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_CLEAR_INTERRUPT(PORT_BASE, PIN_MASK) \
do { REG((PORT_BASE) | GPIO_IC) = (PIN_MASK); } while(0)

/** \brief Configure the pin to be under peripheral control with PIN_MASK of
* port with PORT_BASE.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_PERIPHERAL_CONTROL(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_AFSEL) |= PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_AFSEL) |= (PIN_MASK); } while(0)

/** \brief Configure the pin to be software controlled with PIN_MASK of port
* with PORT_BASE.
* \param PORT_BASE GPIO Port register offset
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
*/
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK) \
do { REG(PORT_BASE | GPIO_AFSEL) &= ~PIN_MASK; } while(0)
do { REG((PORT_BASE) | GPIO_AFSEL) &= ~(PIN_MASK); } while(0)

/**
* \brief Converts a pin number to a pin mask
* \param The pin number in the range [0..7]
* \return A pin mask which can be used as the PIN_MASK argument of the macros
* in this category
*/
#define GPIO_PIN_MASK(PIN) (1 << PIN)
#define GPIO_PIN_MASK(PIN) (1 << (PIN))

/**
* \brief Converts a port number to the port base address
* \param The port number in the range 0 - 3. Likely GPIO_X_NUM.
* \return The base address for the registers corresponding to that port
* number.
*/
#define GPIO_PORT_TO_BASE(PORT) (GPIO_A_BASE + (PORT << 12))
#define GPIO_PORT_TO_BASE(PORT) (GPIO_A_BASE + ((PORT) << 12))
/** @} */
/*---------------------------------------------------------------------------*/
/** \name GPIO Register offset declarations
Expand Down
2 changes: 1 addition & 1 deletion cpu/cc2538/usb/usb-arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ usb_arch_setup(void)

/* Enable pull-up on usb port */
GPIO_SET_OUTPUT(USB_PULLUP_PORT, USB_PULLUP_PIN_MASK);
REG((USB_PULLUP_PORT | GPIO_DATA) + (USB_PULLUP_PIN_MASK << 2)) = 1;
GPIO_SET_PIN(USB_PULLUP_PORT, USB_PULLUP_PIN_MASK);

for(i = 0; i < USB_MAX_ENDPOINTS; i++) {
usb_endpoints[i].flags = 0;
Expand Down
12 changes: 6 additions & 6 deletions platform/cc2538dk/dev/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
*/
#define USB_PULLUP_PORT GPIO_C_BASE
#define USB_PULLUP_PIN 0
#define USB_PULLUP_PIN_MASK (1 << USB_PULLUP_PIN)
#define USB_PULLUP_PIN_MASK GPIO_PIN_MASK(USB_PULLUP_PIN)
/** @} */
/*---------------------------------------------------------------------------*/
/** \name UART configuration
Expand Down Expand Up @@ -143,35 +143,35 @@
#define BUTTON_SELECT_PORT_NO GPIO_A_NUM
#define BUTTON_SELECT_PIN 3
#define BUTTON_SELECT_PORT GPIO_A_BASE
#define BUTTON_SELECT_PIN_MASK (1 << BUTTON_SELECT_PIN)
#define BUTTON_SELECT_PIN_MASK GPIO_PIN_MASK(BUTTON_SELECT_PIN)
#define BUTTON_SELECT_VECTOR NVIC_INT_GPIO_PORT_A

/** BUTTON_LEFT -> PC4 */
#define BUTTON_LEFT_PORT_NO GPIO_C_NUM
#define BUTTON_LEFT_PIN 4
#define BUTTON_LEFT_PORT GPIO_C_BASE
#define BUTTON_LEFT_PIN_MASK (1 << BUTTON_LEFT_PIN)
#define BUTTON_LEFT_PIN_MASK GPIO_PIN_MASK(BUTTON_LEFT_PIN)
#define BUTTON_LEFT_VECTOR NVIC_INT_GPIO_PORT_C

/** BUTTON_RIGHT -> PC5 */
#define BUTTON_RIGHT_PORT_NO GPIO_C_NUM
#define BUTTON_RIGHT_PIN 5
#define BUTTON_RIGHT_PORT GPIO_C_BASE
#define BUTTON_RIGHT_PIN_MASK (1 << BUTTON_RIGHT_PIN)
#define BUTTON_RIGHT_PIN_MASK GPIO_PIN_MASK(BUTTON_RIGHT_PIN)
#define BUTTON_RIGHT_VECTOR NVIC_INT_GPIO_PORT_C

/** BUTTON_UP -> PC6 */
#define BUTTON_UP_PORT_NO GPIO_C_NUM
#define BUTTON_UP_PIN 6
#define BUTTON_UP_PORT GPIO_C_BASE
#define BUTTON_UP_PIN_MASK (1 << BUTTON_UP_PIN)
#define BUTTON_UP_PIN_MASK GPIO_PIN_MASK(BUTTON_UP_PIN)
#define BUTTON_UP_VECTOR NVIC_INT_GPIO_PORT_C

/** BUTTON_DOWN -> PC7 */
#define BUTTON_DOWN_PORT_NO GPIO_C_NUM
#define BUTTON_DOWN_PIN 7
#define BUTTON_DOWN_PORT GPIO_C_BASE
#define BUTTON_DOWN_PIN_MASK (1 << BUTTON_DOWN_PIN)
#define BUTTON_DOWN_PIN_MASK GPIO_PIN_MASK(BUTTON_DOWN_PIN)
#define BUTTON_DOWN_VECTOR NVIC_INT_GPIO_PORT_C

/* Notify various examples that we have Buttons */
Expand Down
5 changes: 2 additions & 3 deletions platform/cc2538dk/dev/leds-arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "dev/leds.h"
#include "dev/gpio.h"

#define LEDS_GPIO_DATA_MASK (LEDS_ALL << 2)
#define LEDS_GPIO_PIN_MASK LEDS_ALL
/*---------------------------------------------------------------------------*/
void
Expand All @@ -57,13 +56,13 @@ leds_arch_init(void)
unsigned char
leds_arch_get(void)
{
return REG((GPIO_C_BASE | GPIO_DATA) + LEDS_GPIO_DATA_MASK);
return GPIO_READ_PIN(GPIO_C_BASE, LEDS_GPIO_PIN_MASK);
}
/*---------------------------------------------------------------------------*/
void
leds_arch_set(unsigned char leds)
{
REG((GPIO_C_BASE | GPIO_DATA) + LEDS_GPIO_DATA_MASK) = leds;
GPIO_WRITE_PIN(GPIO_C_BASE, LEDS_GPIO_PIN_MASK, leds);
}
/*---------------------------------------------------------------------------*/

Expand Down

0 comments on commit ab7067c

Please sign in to comment.