aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-03-31 23:37:17 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-04-04 18:29:31 -0400
commitbc9fd03dabc38ae55fae3151e94cffe7157b95bd (patch)
treebee1984f5afd76e6c4d9e013d8984076dd90e422 /src
parent7e8ecfe177945e10a1e4adaac64c1d803e9405ff (diff)
downloadkutter-bc9fd03dabc38ae55fae3151e94cffe7157b95bd.tar.gz
kutter-bc9fd03dabc38ae55fae3151e94cffe7157b95bd.tar.xz
kutter-bc9fd03dabc38ae55fae3151e94cffe7157b95bd.zip
atsamd: Use enumerations for buses and reserve pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r--src/atsamd/clock.c5
-rw-r--r--src/atsamd/i2c.c6
-rw-r--r--src/atsamd/samd51_clock.c5
-rw-r--r--src/atsamd/sercom.c11
-rw-r--r--src/atsamd/serial.c11
-rw-r--r--src/atsamd/spi.c7
-rw-r--r--src/atsamd/usbserial.c3
7 files changed, 29 insertions, 19 deletions
diff --git a/src/atsamd/clock.c b/src/atsamd/clock.c
index 1a97fe52..a60fc1eb 100644
--- a/src/atsamd/clock.c
+++ b/src/atsamd/clock.c
@@ -4,6 +4,7 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
+#include "command.h" // DECL_CONSTANT_STR
#include "compiler.h" // DIV_ROUND_CLOSEST
#include "internal.h" // enable_pclock
@@ -48,6 +49,10 @@ get_pclock_frequency(uint32_t pclk_id)
return FREQ_MAIN;
}
+#if CONFIG_CLOCK_REF_X32K
+DECL_CONSTANT_STR("RESERVE_PINS_crystal", "PA0,PA1");
+#endif
+
// Initialize the clocks using an external 32K crystal
static void
clock_init_32k(void)
diff --git a/src/atsamd/i2c.c b/src/atsamd/i2c.c
index e5e0a379..a5c128cc 100644
--- a/src/atsamd/i2c.c
+++ b/src/atsamd/i2c.c
@@ -45,12 +45,6 @@ i2c_init(uint32_t bus, SercomI2cm *si)
struct i2c_config
i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr)
{
-#ifdef SERCOM7
- if (bus > 7)
-#else
- if (bus > 5)
-#endif
- shutdown("Unsupported i2c bus");
Sercom *sercom = sercom_enable_pclock(bus);
sercom_i2c_pins(bus);
SercomI2cm *si = &sercom->I2CM;
diff --git a/src/atsamd/samd51_clock.c b/src/atsamd/samd51_clock.c
index 040f29b7..1256ac5f 100644
--- a/src/atsamd/samd51_clock.c
+++ b/src/atsamd/samd51_clock.c
@@ -4,6 +4,7 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
+#include "command.h" // DECL_CONSTANT_STR
#include "compiler.h" // DIV_ROUND_CLOSEST
#include "internal.h" // enable_pclock
@@ -94,6 +95,10 @@ config_dfll(uint32_t dfllmul, uint32_t ctrlb)
;
}
+#if CONFIG_CLOCK_REF_X32K
+DECL_CONSTANT_STR("RESERVE_PINS_crystal", "PA0,PA1");
+#endif
+
// Initialize the clocks using an external 32K crystal
static void
clock_init_32k(void)
diff --git a/src/atsamd/sercom.c b/src/atsamd/sercom.c
index 688a492f..35c6c0dc 100644
--- a/src/atsamd/sercom.c
+++ b/src/atsamd/sercom.c
@@ -15,6 +15,8 @@
* Available sercom blocks
****************************************************************/
+DECL_ENUMERATION_RANGE("bus", "sercom0", 0, 8);
+
struct sercom_bus {
Sercom *sercom;
uint32_t pclk_id, pm_id;
@@ -39,7 +41,7 @@ Sercom *
sercom_enable_pclock(uint32_t sercom_id)
{
if (sercom_id >= ARRAY_SIZE(sercoms))
- shutdown("Invalid sercom bus");
+ shutdown("Invalid SERCOM bus");
const struct sercom_bus *sb = &sercoms[sercom_id];
enable_pclock(sb->pclk_id, sb->pm_id);
return sb->sercom;
@@ -290,6 +292,9 @@ sercom_lookup_pad(uint32_t sercom_id, uint8_t pin)
****************************************************************/
enum { TX_PIN, RX_PIN, CLK_PIN };
+DECL_ENUMERATION("sercom_pin_type", "tx", TX_PIN);
+DECL_ENUMERATION("sercom_pin_type", "rx", RX_PIN);
+DECL_ENUMERATION("sercom_pin_type", "clk", CLK_PIN);
// Runtime configuration
struct sercom_pin {
@@ -308,7 +313,7 @@ command_set_sercom_pin(uint32_t *args)
sercom_pins[sercom_id].pins[pin_type] = pin;
}
DECL_COMMAND(command_set_sercom_pin,
- "set_sercom_pin sercom_id=%u pin_type=%u pin=%u");
+ "set_sercom_pin bus=%u sercom_pin_type=%u pin=%u");
/****************************************************************
@@ -349,6 +354,8 @@ sercom_lookup_spi_dopo(uint8_t tx_pad, uint8_t clk_pad)
uint32_t
sercom_spi_pins(uint32_t sercom_id)
{
+ if (sercom_id >= ARRAY_SIZE(sercom_pins))
+ shutdown("Invalid SERCOM bus");
uint8_t tx_pin = sercom_pins[sercom_id].pins[TX_PIN];
const struct sercom_pad *tx_sp = sercom_lookup_pad(sercom_id, tx_pin);
uint8_t rx_pin = sercom_pins[sercom_id].pins[RX_PIN];
diff --git a/src/atsamd/serial.c b/src/atsamd/serial.c
index 91e85796..fd7dcaac 100644
--- a/src/atsamd/serial.c
+++ b/src/atsamd/serial.c
@@ -5,27 +5,30 @@
// This file may be distributed under the terms of the GNU GPLv3 license.
#include "board/serial_irq.h" // serial_rx_data
+#include "command.h" // DECL_CONSTANT_STR
#include "internal.h" // enable_pclock
#include "sched.h" // DECL_INIT
+DECL_CONSTANT_STR("RESERVE_PINS_serial", "PA11,PA10");
+
void
serial_init(void)
{
// Enable serial clock
enable_pclock(SERCOM0_GCLK_ID_CORE, ID_SERCOM0);
// Enable pins
- gpio_peripheral(GPIO('A', 10), 'C', 0);
gpio_peripheral(GPIO('A', 11), 'C', 0);
+ gpio_peripheral(GPIO('A', 10), 'C', 0);
// Configure serial
SercomUsart *su = &SERCOM0->USART;
su->CTRLA.reg = 0;
uint32_t areg = (SERCOM_USART_CTRLA_MODE(1)
| SERCOM_USART_CTRLA_DORD
| SERCOM_USART_CTRLA_SAMPR(1)
- | SERCOM_USART_CTRLA_TXPO(1)
- | SERCOM_USART_CTRLA_RXPO(3));
+ | SERCOM_USART_CTRLA_RXPO(3)
+ | SERCOM_USART_CTRLA_TXPO(1));
su->CTRLA.reg = areg;
- su->CTRLB.reg = SERCOM_USART_CTRLB_TXEN | SERCOM_USART_CTRLB_RXEN;
+ su->CTRLB.reg = SERCOM_USART_CTRLB_RXEN | SERCOM_USART_CTRLB_TXEN;
uint32_t freq = get_pclock_frequency(SERCOM0_GCLK_ID_CORE);
uint32_t baud8 = freq / (2 * CONFIG_SERIAL_BAUD);
su->BAUD.reg = (SERCOM_USART_BAUD_FRAC_BAUD(baud8 / 8)
diff --git a/src/atsamd/spi.c b/src/atsamd/spi.c
index 96125d5b..67c68cea 100644
--- a/src/atsamd/spi.c
+++ b/src/atsamd/spi.c
@@ -28,13 +28,6 @@ spi_init(uint32_t bus, SercomSpi *ss, uint32_t ctrla, uint32_t baud)
struct spi_config
spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
{
-#ifdef SERCOM7
- if (bus > 7)
-#else
- if (bus > 5)
-#endif
- shutdown("Invalid spi bus");
-
uint32_t dipo_dopo = sercom_spi_pins(bus);
uint32_t ctrla = (SERCOM_SPI_CTRLA_MODE(3)
| (mode << SERCOM_SPI_CTRLA_CPHA_Pos)
diff --git a/src/atsamd/usbserial.c b/src/atsamd/usbserial.c
index 6b7e46b6..5e201d1e 100644
--- a/src/atsamd/usbserial.c
+++ b/src/atsamd/usbserial.c
@@ -10,6 +10,7 @@
#include "board/irq.h" // irq_disable
#include "board/usb_cdc.h" // usb_notify_ep0
#include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
+#include "command.h" // DECL_CONSTANT_STR
#include "internal.h" // enable_pclock
#include "sched.h" // DECL_INIT
@@ -184,6 +185,8 @@ usb_request_bootloader(void)
NVIC_SystemReset();
}
+DECL_CONSTANT_STR("RESERVE_PINS_USB", "PA24,PA25");
+
void
usbserial_init(void)
{