aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/samd21/gpio.c9
-rw-r--r--src/samd21/internal.h6
-rw-r--r--src/samd21/serial.c4
-rw-r--r--src/samd21/usbserial.c4
4 files changed, 12 insertions, 11 deletions
diff --git a/src/samd21/gpio.c b/src/samd21/gpio.c
index 24fe59bc..a38dd63d 100644
--- a/src/samd21/gpio.c
+++ b/src/samd21/gpio.c
@@ -18,10 +18,10 @@
****************************************************************/
void
-gpio_peripheral(char bank, uint32_t bit, char ptype, uint32_t pull_up)
+gpio_peripheral(uint32_t gpio, char ptype, uint32_t pull_up)
{
- int group = bank == 'A' ? 0 : 1;
- PortGroup *pg = &PORT->Group[group];
+ uint32_t bank = GPIO2PORT(gpio), bit = gpio % 32;
+ PortGroup *pg = &PORT->Group[bank];
if (ptype) {
volatile uint8_t *pmux = &pg->PMUX[bit/2].reg;
uint8_t shift = (bit & 1) ? 4 : 0, mask = ~(0xf << shift);
@@ -36,9 +36,6 @@ gpio_peripheral(char bank, uint32_t bit, char ptype, uint32_t pull_up)
* General Purpose Input Output (GPIO) pins
****************************************************************/
-#define GPIO(PORT, NUM) (((PORT)-'A') * 32 + (NUM))
-#define GPIO2PORT(PIN) ((PIN) / 32)
-#define GPIO2BIT(PIN) (1<<((PIN) % 32))
#define NUM_PORT 2
struct gpio_out
diff --git a/src/samd21/internal.h b/src/samd21/internal.h
index 34c74815..b03fae30 100644
--- a/src/samd21/internal.h
+++ b/src/samd21/internal.h
@@ -4,7 +4,11 @@
#include <stdint.h> // uint32_t
+#define GPIO(PORT, NUM) (((PORT)-'A') * 32 + (NUM))
+#define GPIO2PORT(PIN) ((PIN) / 32)
+#define GPIO2BIT(PIN) (1<<((PIN) % 32))
+
void enable_pclock(uint32_t clock_id, uint32_t pmask);
-void gpio_peripheral(char bank, uint32_t bit, char ptype, uint32_t pull_up);
+void gpio_peripheral(uint32_t gpio, char ptype, uint32_t pull_up);
#endif // internal.h
diff --git a/src/samd21/serial.c b/src/samd21/serial.c
index 3c321e47..895ffb27 100644
--- a/src/samd21/serial.c
+++ b/src/samd21/serial.c
@@ -16,8 +16,8 @@ serial_init(void)
// Enable serial clock
enable_pclock(SERCOM0_GCLK_ID_CORE, PM_APBCMASK_SERCOM0);
// Enable pins
- gpio_peripheral('A', 10, 'C', 0);
- gpio_peripheral('A', 11, 'C', 0);
+ gpio_peripheral(GPIO('A', 10), 'C', 0);
+ gpio_peripheral(GPIO('A', 11), 'C', 0);
// Configure serial
SercomUsart *su = &SERCOM0->USART;
su->CTRLA.reg = 0;
diff --git a/src/samd21/usbserial.c b/src/samd21/usbserial.c
index bac75853..2db22ae6 100644
--- a/src/samd21/usbserial.c
+++ b/src/samd21/usbserial.c
@@ -174,8 +174,8 @@ usbserial_init(void)
// configure usb clock
enable_pclock(USB_GCLK_ID, 0);
// configure USBD+ and USBD- pins
- gpio_peripheral('A', 24, 'G', 0);
- gpio_peripheral('A', 25, 'G', 0);
+ gpio_peripheral(GPIO('A', 24), 'G', 0);
+ gpio_peripheral(GPIO('A', 25), 'G', 0);
uint16_t trim = (readl((void*)USB_FUSES_TRIM_ADDR)
& USB_FUSES_TRIM_Msk) >> USB_FUSES_TRIM_Pos;
uint16_t transp = (readl((void*)USB_FUSES_TRANSP_ADDR)