/* These are place-holders to set the SPI chip select low if the SPI driver is not used.
* These dummy functions will be over-ridden by SPI ones if the SPI driver is used.
*/
-#define I2C_CS_GPIO LPC_GPIO_0_15
+static struct pio i2c_eeprom_cs = LPC_GPIO_0_15;
int I2C_CS_Default_Set(void)
{
- struct lpc_gpio* gpio0 = LPC_GPIO_0;
- struct pio i2c_eeprom_cs = I2C_CS_GPIO;
+ struct lpc_gpio* gpio_port_regs = LPC_GPIO_REGS(i2c_eeprom_cs.port);
config_pio(&i2c_eeprom_cs, (LPC_IO_MODE_PULL_UP | LPC_IO_DIGITAL));
/* Configure SPI_CS as output and set it low. */
- gpio0->data_dir |= (1 << i2c_eeprom_cs.pin);
- gpio0->clear = (1 << i2c_eeprom_cs.pin);
+ gpio_port_regs->data_dir |= (1 << i2c_eeprom_cs.pin);
+ gpio_port_regs->clear = (1 << i2c_eeprom_cs.pin);
return 0;
}
void I2C_CS_Default_Release(void)
{
- struct lpc_gpio* gpio0 = LPC_GPIO_0;
- struct pio i2c_eeprom_cs = I2C_CS_GPIO;
- gpio0->set = (1 << i2c_eeprom_cs.pin);
+ struct lpc_gpio* gpio_port_regs = LPC_GPIO_REGS(i2c_eeprom_cs.port);
+ gpio_port_regs->set = (1 << i2c_eeprom_cs.pin);
}
int spi_device_cs_pull_low(void) __attribute__ ((weak, alias ("I2C_CS_Default_Set")));
#include "drivers/gpio.h"
+
/***************************************************************************** */
/* GPIO setup */
-
/* Set all GPIO used in a default state */
extern struct pio gpio_pins[];
int set_gpio_callback(void (*callback) (uint32_t), struct pio* gpio, uint8_t sense)
{
- struct lpc_gpio* gpio_port = NULL;
+ struct lpc_gpio* gpio_port = LPC_GPIO_REGS(gpio->port);
uint32_t irq = 0;
/* Register the callback */
if (gpio->pin >= PORT0_NB_PINS)
return -EINVAL;
gpio_calbacks_port0[gpio->pin] = callback;
- gpio_port = LPC_GPIO_0;
irq = PIO_0_IRQ;
break;
case 1:
if (gpio->pin >= PORT1_NB_PINS)
return -EINVAL;
gpio_calbacks_port1[gpio->pin] = callback;
- gpio_port = LPC_GPIO_1;
irq = PIO_1_IRQ;
break;
case 2:
if (gpio->pin >= PORT2_NB_PINS)
return -EINVAL;
gpio_calbacks_port2[gpio->pin] = callback;
- gpio_port = LPC_GPIO_2;
irq = PIO_2_IRQ;
break;
default:
}
void remove_gpio_callback(struct pio* gpio)
{
- struct lpc_gpio* gpio_port = NULL;
+ struct lpc_gpio* gpio_port = LPC_GPIO_REGS(gpio->port);
uint32_t irq = 0;
/* Remove the handler */
if (gpio->pin >= PORT0_NB_PINS)
return;
gpio_calbacks_port0[gpio->pin] = NULL;
- gpio_port = LPC_GPIO_0;
irq = PIO_0_IRQ;
break;
case 1:
if (gpio->pin >= PORT1_NB_PINS)
return;
gpio_calbacks_port1[gpio->pin] = NULL;
- gpio_port = LPC_GPIO_1;
irq = PIO_1_IRQ;
break;
case 2:
if (gpio->pin >= PORT2_NB_PINS)
return;
gpio_calbacks_port2[gpio->pin] = NULL;
- gpio_port = LPC_GPIO_2;
irq = PIO_2_IRQ;
break;
default:
void status_led_config(void)
{
- struct lpc_gpio* gpio1 = LPC_GPIO_1;
+ struct lpc_gpio* gpio1 = LPC_GPIO_REGS(1);
uint32_t mode = (LPC_IO_MODE_PULL_UP | LPC_IO_DIGITAL | LPC_IO_DRIVE_HIGHCURENT);
struct pio red_led = LPC_GPIO_1_5;
struct pio green_led = LPC_GPIO_1_4;
void status_led(uint32_t val)
{
- struct lpc_gpio* gpio1 = LPC_GPIO_1;
+ struct lpc_gpio* gpio1 = LPC_GPIO_REGS(1);
switch (val) {
case red_only:
#define LPC_GPIO_1 ((struct lpc_gpio *) LPC_GPIO_1_BASE)
#define LPC_GPIO_2 ((struct lpc_gpio *) LPC_GPIO_2_BASE)
+#define LPC_GPIO_REGS(x) ((struct lpc_gpio *) (LPC_AHB_BASE + (0x10000 * (x))))
/***************************************************************************** */