/***************************************************************************** */
/* 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 */
/***************************************************************************** */
-/* 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)
{
/* Remove the default global interrupt enabled setting */
adc->int_en = 0;
- /* Configure ADC pins */
- set_adc_pins();
-
/* Enable ADC Interrupt */
NVIC_EnableIRQ(ADC_IRQ);
}
/***************************************************************************** */
/* 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 */
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)
{
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;
/* 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;
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;
/* 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 */
}
}
-/* 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 */
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);
/* Enable SSP */
ssp_regs->ctrl_1 |= LPC_SSP_ENABLE;
- ssp_set_pin_func(ssp_num);
-
NVIC_EnableIRQ(ssp->irq);
return 0; /* Config OK */
}
}
-/* 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
}
timer->regs->prescale = prescale;
- timer_pins_setup(timer_num);
-
NVIC_EnableIRQ(timer_devices[timer_num].irq);
}
+++ /dev/null
-/****************************************************************************
- * driver/weak_pinout.c
- *
- * Copyright 2013-2014 Nathael Pajani <nathael.pajani@ed3l.fr>
- *
- *
- * 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 <http://www.gnu.org/licenses/>.
- *
- *************************************************************************** */
-
-
-#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,
-};