From f4a97d4a5e9c5149330f81ba809e3dea5ad5045f Mon Sep 17 00:00:00 2001 From: Cyprien Laplace Date: Sun, 14 Dec 2014 18:11:06 +0100 Subject: [PATCH] Use new set_pins scheme - part 1 Remove individual local set_*_pins functions WARNING : This commit is HARD-LINKED with the next one or pins will not be configured. Otherwise, you must perform the modifications on your code to configure the pins using the new scheme. --- core/system.c | 9 +++--- drivers/adc.c | 15 +--------- drivers/gpio.c | 13 --------- drivers/i2c.c | 15 ---------- drivers/serial.c | 24 --------------- drivers/ssp.c | 21 ------------- drivers/timers.c | 34 ---------------------- drivers/weak_pinout.c | 68 ------------------------------------------- 8 files changed, 5 insertions(+), 194 deletions(-) delete mode 100644 drivers/weak_pinout.c diff --git a/core/system.c b/core/system.c index a11e6ea..5a9744a 100644 --- a/core/system.c +++ b/core/system.c @@ -273,16 +273,15 @@ void io_config_clk_off(void) /***************************************************************************** */ /* This is mainly a debug feature, but can be used to provide a clock to an * external peripheral */ -/* Note that the CLK_Out pin PIO0_12 is multiplexed with ISP mode selection on reset */ -extern struct pio clkout_pin[]; +/* Note that PIO0_12 is the only pin possible for CLK_Out, and is multiplexed + * with ISP mode selection on reset. + * The pin must be enabled using a pio table passed to the set_pins() function. + */ void clkout_on(uint32_t src, uint32_t div) { struct lpc_sys_control* sys_ctrl = LPC_SYS_CONTROL; - /* Only one possible pin, and no specific configuration */ - config_pio(&clkout_pin[0], 0); - /* Select clk_out clock source */ sys_ctrl->clk_out_src_sel = (src & 0x03); /* Activate clk_out */ diff --git a/drivers/adc.c b/drivers/adc.c index 0868688..aa8bb79 100644 --- a/drivers/adc.c +++ b/drivers/adc.c @@ -172,17 +172,7 @@ void adc_prepare_conversion_on_event(uint8_t channels, uint8_t event, int use_in /***************************************************************************** */ -/* ADC Setup : private part : Clocks, Pins, Power and Mode */ -extern const struct pio adc_pins[]; - -static void set_adc_pins(void) -{ - int i = 0; - /* Configure ADC pins */ - for (i = 0; adc_pins[i].port != 0xFF; i++) { - config_pio(&adc_pins[i], LPC_IO_ANALOG); - } -} +/* ADC Setup : private part : Clocks, Power and Mode */ void adc_clk_update(void) { @@ -220,9 +210,6 @@ void adc_on(void) /* Remove the default global interrupt enabled setting */ adc->int_en = 0; - /* Configure ADC pins */ - set_adc_pins(); - /* Enable ADC Interrupt */ NVIC_EnableIRQ(ADC_IRQ); } diff --git a/drivers/gpio.c b/drivers/gpio.c index eae48d2..72b16cc 100644 --- a/drivers/gpio.c +++ b/drivers/gpio.c @@ -36,18 +36,6 @@ /***************************************************************************** */ /* GPIO setup */ -/* Set all GPIO used in a default state */ -extern const struct pio gpio_pins[]; - -static void set_gpio_pins(void) -{ - int i = 0; - /* Set GPIO pins as GPIO */ - for (i = 0; gpio_pins[i].port != 0xFF; i++) { - config_pio(&gpio_pins[i], LPC_IO_MODE_PULL_UP); - } -} - void gpio_on(void) { /* Provide power to GPIO control blocks */ @@ -55,7 +43,6 @@ void gpio_on(void) subsystem_power(LPC_SYS_ABH_CLK_CTRL_GPIO1, 1); /* FIXME : Power this one too if you use LQFP64 or LQFP100 packages */ /* subsystem_power(LPC_SYS_ABH_CLK_CTRL_GPIO2, 1); */ - set_gpio_pins(); } void gpio_off(void) { diff --git a/drivers/i2c.c b/drivers/i2c.c index 93daec5..9031db4 100644 --- a/drivers/i2c.c +++ b/drivers/i2c.c @@ -453,19 +453,6 @@ static void i2c_clock_on(uint32_t i2c_clk_freq) i2c->clk_duty_low = (scl_clk - i2c->clk_duty_high); } -/* I2C Pins configuration */ -extern const struct pio i2c0_pins[]; - - -static void set_i2c_pins(void) -{ - int i = 0; - /* Configure I2C pins */ - for (i = 0; i2c0_pins[i].port != 0xFF; i++) { - config_pio(&i2c0_pins[i], (LPC_IO_ANALOG | LPC_IO_OPEN_DRAIN_ENABLE)); - } -} - void i2c_on(uint32_t i2c_clk_freq) { struct lpc_i2c* i2c = LPC_I2C0; @@ -476,8 +463,6 @@ void i2c_on(uint32_t i2c_clk_freq) /* Set clock */ i2c_clock_on(i2c_clk_freq); mod_i2c.clock = i2c_clk_freq; - /* Set pins function for I2C 0 */ - set_i2c_pins(); /* Initialize i2c_bus struct */ memset(&mod_i2c, 0, sizeof(struct i2c_bus)); mod_i2c.regs = (struct lpc_i2c*)LPC_I2C0; diff --git a/drivers/serial.c b/drivers/serial.c index 2d1603a..a20ce2e 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -231,29 +231,6 @@ static uint32_t uart_setup(uint32_t uart_num) return status; } -/* Pin settings */ -/* Note : We MUST set LPC_IO_DIGITAL for Rx even if the bit is marked as "Reserved" in - * the datasheet ! - */ -extern const struct pio uart0_pins[]; -extern const struct pio uart1_pins[]; - -static void uart_set_pin_func(uint32_t uart_num) -{ - int i = 0; - switch (uart_num) { - case 0: - for (i = 0; uart0_pins[i].port != 0xFF; i++) { - config_pio(&uart0_pins[i], LPC_IO_DIGITAL); - } - break; - case 1: - for (i = 0; uart1_pins[i].port != 0xFF; i++) { - config_pio(&uart1_pins[i], LPC_IO_DIGITAL); - } - break; - } -} struct uart_def { uint32_t irq; @@ -353,7 +330,6 @@ int uart_on(uint32_t uart_num, uint32_t baudrate, void (*rx_callback)(uint8_t)) /* Setup pins, must be done before clock setup and with uart powered off. */ uart_clk_off(uart_num); subsystem_power(uart->power_offset, 0); - uart_set_pin_func(uart_num); /* Turn On power */ subsystem_power(uart->power_offset, 1); /* Setup clock acording to baudrate */ diff --git a/drivers/ssp.c b/drivers/ssp.c index 8ca73ba..638e7bc 100644 --- a/drivers/ssp.c +++ b/drivers/ssp.c @@ -304,22 +304,6 @@ void ssp_clk_update(void) } } -/* Configure all SPI pins. */ -extern const struct pio ssp0_pins[]; -static void ssp_set_pin_func(uint32_t ssp_num) -{ - int i = 0; - switch (ssp_num) { - case 0: - for (i = 0; ssp0_pins[i].port != 0xFF; i++) { - config_pio(&ssp0_pins[i], LPC_IO_DIGITAL); - } - break; - } -} - - - /***************************************************************************** */ /* SSP Setup as master */ @@ -344,9 +328,6 @@ int ssp_master_on(uint8_t ssp_num, uint8_t frame_type, uint8_t data_width, uint3 NVIC_DisableIRQ(ssp->irq); - /* Configure pins first */ - ssp_set_pin_func(ssp_num); /* Only one SPI on the LPC1224 */ - /* Power up the ssp block */ subsystem_power(ssp->clk_ctrl_bit, 1); @@ -393,8 +374,6 @@ int ssp_slave_on(uint8_t ssp_num, uint8_t frame_type, uint8_t data_width, uint8_ /* Enable SSP */ ssp_regs->ctrl_1 |= LPC_SSP_ENABLE; - ssp_set_pin_func(ssp_num); - NVIC_EnableIRQ(ssp->irq); return 0; /* Config OK */ } diff --git a/drivers/timers.c b/drivers/timers.c index d00f915..caf7e96 100644 --- a/drivers/timers.c +++ b/drivers/timers.c @@ -219,38 +219,6 @@ int timer_setup(uint32_t timer_num, struct timer_config* conf) } -/* Setup timer pins to be used as match or capture pin */ -extern const struct pio timer0_pins[]; -extern const struct pio timer1_pins[]; -extern const struct pio timer2_pins[]; -extern const struct pio timer3_pins[]; - -#define LPC_TIMER_PIN_CONFIG (LPC_IO_MODE_PULL_UP | LPC_IO_DIGITAL | LPC_IO_DRIVE_HIGHCURENT) -static void timer_pins_setup(uint32_t timer_num) -{ - int i = 0; - const struct pio* timer_pins = NULL; - switch (timer_num) { - case LPC_TIMER_16B0: - timer_pins = timer0_pins; - break; - case LPC_TIMER_16B1: - timer_pins = timer1_pins; - break; - case LPC_TIMER_32B0: - timer_pins = timer2_pins; - break; - case LPC_TIMER_32B1: - timer_pins = timer3_pins; - break; - default: - return; - } - for (i = 0; timer_pins[i].port != 0xFF; i++) { - config_pio(&timer_pins[i], LPC_TIMER_PIN_CONFIG); - } -} - /* Power up a timer. * Note that clkrate should be a divider of the main clock frequency chosed * for your application as it will be used to divide the main clock to get @@ -283,8 +251,6 @@ void timer_on(uint32_t timer_num, uint32_t clkrate, void (*callback)(uint8_t)) } timer->regs->prescale = prescale; - timer_pins_setup(timer_num); - NVIC_EnableIRQ(timer_devices[timer_num].irq); } diff --git a/drivers/weak_pinout.c b/drivers/weak_pinout.c deleted file mode 100644 index b6bd258..0000000 --- a/drivers/weak_pinout.c +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * driver/weak_pinout.c - * - * Copyright 2013-2014 Nathael Pajani - * - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - *************************************************************************** */ - - -#include "core/pio.h" - -/***************************************************************************** */ -/* Pins configuration */ -/* List of available pin blocks : - * clkout_pin, uart0_pins, uart1_pins, i2c0_pins, ssp0_pins, - * timer0_pins, timer1_pins, timer2_pins, timer3_pins, - * adc_pins, gpio_pins - * - * This files defines "weak" "empty" pio structures for all of the drivers so - * that the drivers can compile even if the user does not define empty pio - * structures for unused drivers. - * - * These will be overridden by the user definitions. - * - */ -const struct pio uart0_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -const struct pio uart1_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -const struct pio i2c0_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -const struct pio ssp0_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -const struct pio timer0_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -const struct pio timer1_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -const struct pio timer2_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -const struct pio timer3_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -const struct pio adc_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -const struct pio gpio_pins[] __attribute__ ((weak)) = { - ARRAY_LAST_PIN, -}; -- 2.43.0