sam4e8e: Move gpio_set_peripheral() definition from gpio.h to internal.h

Use internal.h in a similar way to the internal.h in sam3x8e.  Also,
move the twi pin definitions from internal.h to i2c.c (as they are only
used there).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-12-25 11:12:00 -05:00
parent 9a2160f660
commit f0715de004
6 changed files with 52 additions and 39 deletions

View File

@ -4,22 +4,23 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
#include "gpio.h"
#include "sam4e.h"
#include "autoconf.h" // CONFIG_CLOCK_FREQ
#include "board/irq.h" // irq_save
#include "command.h" // shutdown
#include "gpio.h" // gpio_out_setup
#include "internal.h" // gpio_set_peripheral
#include "sam4e.h" // Pio
#include "sched.h" // sched_shutdown
#define GPIO(PORT, NUM) (((PORT)-'A') * 32 + (NUM))
#define GPIO2PORT(PIN) ((PIN) / 32)
#define GPIO2BIT(PIN) (1<<((PIN) % 32))
static Pio * const digital_regs[] = {
PIOA, PIOB, PIOC, PIOD, PIOE
};
/****************************************************************
* Pin multiplexing
****************************************************************/
void
gpio_set_peripheral(char bank, const uint32_t bit, char ptype, uint32_t pull_up) {
@ -67,6 +68,11 @@ gpio_set_peripheral(char bank, const uint32_t bit, char ptype, uint32_t pull_up)
}
}
/****************************************************************
* General Purpose Input Output (GPIO) pins
****************************************************************/
struct gpio_out
gpio_out_setup(uint8_t pin, uint8_t val)
{

View File

@ -9,7 +9,6 @@ struct gpio_out {
uint32_t bit;
};
void gpio_set_peripheral(char bank, uint32_t bit, char ptype, uint32_t pull_up);
struct gpio_out gpio_out_setup(uint8_t pin, uint8_t val);
void gpio_out_reset(struct gpio_out g, uint8_t val);
void gpio_out_toggle_noirq(struct gpio_out g);

View File

@ -5,12 +5,30 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
#include "gpio.h"
#include "internal.h"
#include "command.h" // shutdown
#include "sched.h" // sched_shutdown
#include "autoconf.h" // CONFIG_CLOCK_FREQ
#include "board/misc.h" //timer_from_us
#include "board/misc.h" // timer_from_us
#include "command.h" // shutdown
#include "gpio.h" // i2c_setup
#include "internal.h" // gpio_peripheral
#include "sam4e.h" // TWI0
#include "sched.h" // sched_shutdown
// I2C pin definitions
#define TWI0_SCL_BANK 'A'
#define TWI0_SCL_PIN PIO_PA4A_TWCK0
#define TWI0_SCL_PERIPH 'A'
#define TWI0_SDA_BANK 'A'
#define TWI0_SDA_PIN PIO_PA3A_TWD0
#define TWI0_SDA_PERIPH 'A'
#define TWI1_SCL_BANK 'B'
#define TWI1_SCL_PIN PIO_PB5A_TWCK1
#define TWI1_SCL_PERIPH 'A'
#define TWI1_SDA_BANK 'B'
#define TWI1_SDA_PIN PIO_PB4A_TWD1
#define TWI1_SDA_PERIPH 'A'
void
i2c_init(Twi *p_twi, uint32_t rate)

View File

@ -1,18 +1,13 @@
#include "sam4e.h"
#ifndef __SAM4_INTERNAL_H
#define __SAM4_INTERNAL_H
// Local definitions for sam4 code
// I2C pin definitions
#define TWI0_SCL_BANK 'A'
#define TWI0_SCL_PIN PIO_PA4A_TWCK0
#define TWI0_SCL_PERIPH 'A'
#include <stdint.h> // uint32_t
#define TWI0_SDA_BANK 'A'
#define TWI0_SDA_PIN PIO_PA3A_TWD0
#define TWI0_SDA_PERIPH 'A'
#define GPIO(PORT, NUM) (((PORT)-'A') * 32 + (NUM))
#define GPIO2PORT(PIN) ((PIN) / 32)
#define GPIO2BIT(PIN) (1<<((PIN) % 32))
#define TWI1_SCL_BANK 'B'
#define TWI1_SCL_PIN PIO_PB5A_TWCK1
#define TWI1_SCL_PERIPH 'A'
void gpio_set_peripheral(char bank, uint32_t bit, char ptype, uint32_t pull_up);
#define TWI1_SDA_BANK 'B'
#define TWI1_SDA_PIN PIO_PB4A_TWD1
#define TWI1_SDA_PERIPH 'A'
#endif // internal.h

View File

@ -4,13 +4,10 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
// CMSIS
#include "sam4e.h" // UART
// Klipper
#include "autoconf.h" // CONFIG_SERIAL_BAUD
#include "board/gpio.h" // gpio_peripheral
#include "board/serial_irq.h" // serial_rx_data
#include "internal.h" // gpio_peripheral
#include "sam4e.h" // UART0
#include "sched.h" // DECL_INIT
void

View File

@ -4,14 +4,12 @@
//
// This file may be distributed under the terms of the GNU GPLv3 license.
// Klipper
#include "command.h" // shutdown
#include "sched.h"
#include "autoconf.h" // CONFIG_CLOCK_FREQ
// SAM4E port
#include "sam4e.h"
#include "gpio.h"
#include "command.h" // shutdown
#include "gpio.h" // spi_setup
#include "internal.h" // gpio_set_peripheral
#include "sam4e.h" // USART0
#include "sched.h" // sched_shutdown
#define SSPI_USART0 0
#define SSPI_USART1 1