diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-03-31 23:12:44 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-04-04 18:29:31 -0400 |
commit | 7e8ecfe177945e10a1e4adaac64c1d803e9405ff (patch) | |
tree | 7d9f6436f9ccf5fe7d1496ca8eb9b64aad2ca286 /src/atsam | |
parent | 7765653d83364f266b7f1917b1cd6ab1508e7acf (diff) | |
download | kutter-7e8ecfe177945e10a1e4adaac64c1d803e9405ff.tar.gz kutter-7e8ecfe177945e10a1e4adaac64c1d803e9405ff.tar.xz kutter-7e8ecfe177945e10a1e4adaac64c1d803e9405ff.zip |
atsam: Use enumerations for buses and reserve pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/atsam')
-rw-r--r-- | src/atsam/i2c.c | 7 | ||||
-rw-r--r-- | src/atsam/sam4_usb.c | 3 | ||||
-rw-r--r-- | src/atsam/serial.c | 4 | ||||
-rw-r--r-- | src/atsam/spi.c | 23 |
4 files changed, 35 insertions, 2 deletions
diff --git a/src/atsam/i2c.c b/src/atsam/i2c.c index bbe9de32..f2a5a4c8 100644 --- a/src/atsam/i2c.c +++ b/src/atsam/i2c.c @@ -12,16 +12,21 @@ #include "sched.h" // sched_shutdown // I2C pin definitions +DECL_ENUMERATION_RANGE("i2c_bus", "twi0", 0, 2); #if CONFIG_MACH_SAM3X #define TWI0_SCL_GPIO GPIO('A', 18) #define TWI0_SDA_GPIO GPIO('A', 17) #define TWI1_SCL_GPIO GPIO('B', 13) #define TWI1_SDA_GPIO GPIO('B', 12) +DECL_CONSTANT_STR("BUS_PINS_twi0", "PA18,PA17"); +DECL_CONSTANT_STR("BUS_PINS_twi1", "PB13,PB12"); #elif CONFIG_MACH_SAM4 #define TWI0_SCL_GPIO GPIO('A', 4) #define TWI0_SDA_GPIO GPIO('A', 3) #define TWI1_SCL_GPIO GPIO('B', 5) #define TWI1_SDA_GPIO GPIO('B', 4) +DECL_CONSTANT_STR("BUS_PINS_twi0", "PA4,PA3"); +DECL_CONSTANT_STR("BUS_PINS_twi1", "PB5,PB4"); #endif static void @@ -89,7 +94,7 @@ addr_to_u32(uint8_t addr_len, uint8_t *addr) struct i2c_config i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr) { - if ((bus > 1) | (rate > 400000)) + if (bus > 1 || rate > 400000) shutdown("Invalid i2c_setup parameters!"); Twi *p_twi = (bus == 0) ? TWI0 : TWI1; i2c_init(p_twi, rate); diff --git a/src/atsam/sam4_usb.c b/src/atsam/sam4_usb.c index a615ffa5..0ba85f4b 100644 --- a/src/atsam/sam4_usb.c +++ b/src/atsam/sam4_usb.c @@ -8,6 +8,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" // UDP #include "sched.h" // DECL_INIT @@ -159,6 +160,8 @@ usb_set_configure(void) UDP->UDP_GLB_STAT |= UDP_GLB_STAT_CONFG; } +DECL_CONSTANT_STR("RESERVE_PINS_USB", "PB10,PB11"); + void usbserial_init(void) { diff --git a/src/atsam/serial.c b/src/atsam/serial.c index 6a511122..051256d4 100644 --- a/src/atsam/serial.c +++ b/src/atsam/serial.c @@ -6,6 +6,7 @@ #include "autoconf.h" // CONFIG_SERIAL_BAUD #include "board/serial_irq.h" // serial_rx_data +#include "command.h" // DECL_CONSTANT_STR #include "internal.h" // gpio_peripheral #include "sched.h" // DECL_INIT @@ -16,18 +17,21 @@ static Uart * const Port = UART; static const uint32_t Pmc_id = ID_UART, Irq_id = UART_IRQn; static const uint32_t rx_pin = GPIO('A', 8); static const uint32_t tx_pin = GPIO('A', 9); +DECL_CONSTANT_STR("RESERVE_PINS_serial", "PA8,PA9"); #elif CONFIG_MACH_SAM4S #define Serial_IRQ_Handler UART1_Handler static Uart * const Port = UART1; static const uint32_t Pmc_id = ID_UART1, Irq_id = UART1_IRQn; static const uint32_t rx_pin = GPIO('B', 2); static const uint32_t tx_pin = GPIO('B', 3); +DECL_CONSTANT_STR("RESERVE_PINS_serial", "PB2,PB3"); #elif CONFIG_MACH_SAM4E #define Serial_IRQ_Handler UART0_Handler static Uart * const Port = UART0; static const uint32_t Pmc_id = ID_UART0, Irq_id = UART0_IRQn; static const uint32_t rx_pin = GPIO('A', 9); static const uint32_t tx_pin = GPIO('A', 10); +DECL_CONSTANT_STR("RESERVE_PINS_serial", "PA9,PA10"); #endif void diff --git a/src/atsam/spi.c b/src/atsam/spi.c index 7d304284..d64f0df7 100644 --- a/src/atsam/spi.c +++ b/src/atsam/spi.c @@ -22,6 +22,27 @@ struct spi_info { uint8_t miso_pin, mosi_pin, sck_pin, rxtx_periph, sck_periph; }; +#if CONFIG_MACH_SAM3X +DECL_ENUMERATION("spi_bus", "spi0", 0); +DECL_ENUMERATION_RANGE("spi_bus", "usart0", 1, 3); +DECL_CONSTANT_STR("BUS_PINS_spi0", "PA25,PA26,PA27"); +DECL_CONSTANT_STR("BUS_PINS_usart0", "PA10,PA11,PA17"); +DECL_CONSTANT_STR("BUS_PINS_usart1", "PA12,PA13,PA16"); +DECL_CONSTANT_STR("BUS_PINS_usart2", "PB21,PB20,PB24"); +#elif CONFIG_MACH_SAM4S +DECL_ENUMERATION("spi_bus", "spi", 0); +DECL_ENUMERATION_RANGE("spi_bus", "usart0", 1, 2); +DECL_CONSTANT_STR("BUS_PINS_spi", "PA12,PA13,PA14"); +DECL_CONSTANT_STR("BUS_PINS_usart0", "PA5,PA6,PA2"); +DECL_CONSTANT_STR("BUS_PINS_usart1", "PA21,PA22,PA23"); +#elif CONFIG_MACH_SAM4E +DECL_ENUMERATION("spi_bus", "spi", 0); +DECL_ENUMERATION_RANGE("spi_bus", "usart0", 1, 2); +DECL_CONSTANT_STR("BUS_PINS_spi", "PA12,PA13,PA14"); +DECL_CONSTANT_STR("BUS_PINS_usart0", "PB0,PB1,PB13"); +DECL_CONSTANT_STR("BUS_PINS_usart1", "PA21,PA22,PA23"); +#endif + static const struct spi_info spi_bus[] = { #if CONFIG_MACH_SAM3X { SPI0, ID_SPI0, GPIO('A', 25), GPIO('A', 26), GPIO('A', 27), 'A', 'A' }, @@ -33,9 +54,9 @@ static const struct spi_info spi_bus[] = { { USART0, ID_USART0, GPIO('A', 5), GPIO('A', 6), GPIO('A', 2), 'A', 'B' }, { USART1, ID_USART1, GPIO('A', 21), GPIO('A', 22), GPIO('A', 23), 'A', 'A'}, #elif CONFIG_MACH_SAM4E + { SPI, ID_SPI, GPIO('A', 12), GPIO('A', 13), GPIO('A', 14), 'A', 'A' }, { USART0, ID_USART0, GPIO('B', 0), GPIO('B', 1), GPIO('B', 13), 'C', 'C' }, { USART1, ID_USART1, GPIO('A', 21), GPIO('A', 22), GPIO('A', 23), 'A', 'A'}, - { SPI, ID_SPI, GPIO('A', 12), GPIO('A', 13), GPIO('A', 14), 'A', 'A' }, #endif }; |