samd21: Use GPIO() macro when calling gpio_peripheral()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
0af0bc946e
commit
6d90ebe6f8
|
@ -18,10 +18,10 @@
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
void
|
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;
|
uint32_t bank = GPIO2PORT(gpio), bit = gpio % 32;
|
||||||
PortGroup *pg = &PORT->Group[group];
|
PortGroup *pg = &PORT->Group[bank];
|
||||||
if (ptype) {
|
if (ptype) {
|
||||||
volatile uint8_t *pmux = &pg->PMUX[bit/2].reg;
|
volatile uint8_t *pmux = &pg->PMUX[bit/2].reg;
|
||||||
uint8_t shift = (bit & 1) ? 4 : 0, mask = ~(0xf << shift);
|
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
|
* 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
|
#define NUM_PORT 2
|
||||||
|
|
||||||
struct gpio_out
|
struct gpio_out
|
||||||
|
|
|
@ -4,7 +4,11 @@
|
||||||
|
|
||||||
#include <stdint.h> // uint32_t
|
#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 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
|
#endif // internal.h
|
||||||
|
|
|
@ -16,8 +16,8 @@ serial_init(void)
|
||||||
// Enable serial clock
|
// Enable serial clock
|
||||||
enable_pclock(SERCOM0_GCLK_ID_CORE, PM_APBCMASK_SERCOM0);
|
enable_pclock(SERCOM0_GCLK_ID_CORE, PM_APBCMASK_SERCOM0);
|
||||||
// Enable pins
|
// Enable pins
|
||||||
gpio_peripheral('A', 10, 'C', 0);
|
gpio_peripheral(GPIO('A', 10), 'C', 0);
|
||||||
gpio_peripheral('A', 11, 'C', 0);
|
gpio_peripheral(GPIO('A', 11), 'C', 0);
|
||||||
// Configure serial
|
// Configure serial
|
||||||
SercomUsart *su = &SERCOM0->USART;
|
SercomUsart *su = &SERCOM0->USART;
|
||||||
su->CTRLA.reg = 0;
|
su->CTRLA.reg = 0;
|
||||||
|
|
|
@ -174,8 +174,8 @@ usbserial_init(void)
|
||||||
// configure usb clock
|
// configure usb clock
|
||||||
enable_pclock(USB_GCLK_ID, 0);
|
enable_pclock(USB_GCLK_ID, 0);
|
||||||
// configure USBD+ and USBD- pins
|
// configure USBD+ and USBD- pins
|
||||||
gpio_peripheral('A', 24, 'G', 0);
|
gpio_peripheral(GPIO('A', 24), 'G', 0);
|
||||||
gpio_peripheral('A', 25, 'G', 0);
|
gpio_peripheral(GPIO('A', 25), 'G', 0);
|
||||||
uint16_t trim = (readl((void*)USB_FUSES_TRIM_ADDR)
|
uint16_t trim = (readl((void*)USB_FUSES_TRIM_ADDR)
|
||||||
& USB_FUSES_TRIM_Msk) >> USB_FUSES_TRIM_Pos;
|
& USB_FUSES_TRIM_Msk) >> USB_FUSES_TRIM_Pos;
|
||||||
uint16_t transp = (readl((void*)USB_FUSES_TRANSP_ADDR)
|
uint16_t transp = (readl((void*)USB_FUSES_TRANSP_ADDR)
|
||||||
|
|
Loading…
Reference in New Issue